@pasosdejesus/m 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (324) hide show
  1. package/dist/blockchain/deployments.d.ts +40 -0
  2. package/dist/blockchain/deployments.d.ts.map +1 -0
  3. package/dist/blockchain/deployments.js +64 -0
  4. package/dist/debug/DebugConsole.d.ts +22 -0
  5. package/dist/debug/DebugConsole.d.ts.map +1 -0
  6. package/dist/debug/DebugConsole.js +79 -0
  7. package/dist/debug/Logger.d.ts +38 -0
  8. package/dist/debug/Logger.d.ts.map +1 -0
  9. package/dist/debug/Logger.js +94 -0
  10. package/dist/debug/index.d.ts +6 -0
  11. package/dist/debug/index.d.ts.map +1 -0
  12. package/dist/debug/index.js +4 -0
  13. package/dist/debug/useLogger.d.ts +14 -0
  14. package/dist/debug/useLogger.d.ts.map +1 -0
  15. package/dist/debug/useLogger.js +23 -0
  16. package/dist/debug/utils.d.ts +10 -0
  17. package/dist/debug/utils.d.ts.map +1 -0
  18. package/dist/debug/utils.js +53 -0
  19. package/dist/e2e/assertions.d.ts +5 -0
  20. package/dist/e2e/assertions.d.ts.map +1 -0
  21. package/dist/e2e/assertions.js +18 -0
  22. package/dist/e2e/browser.d.ts +37 -0
  23. package/dist/e2e/browser.d.ts.map +1 -0
  24. package/dist/e2e/browser.js +97 -0
  25. package/dist/e2e/env.d.ts +18 -0
  26. package/dist/e2e/env.d.ts.map +1 -0
  27. package/dist/e2e/env.js +57 -0
  28. package/dist/e2e/index.d.ts +11 -0
  29. package/dist/e2e/index.d.ts.map +1 -0
  30. package/dist/e2e/index.js +8 -0
  31. package/dist/e2e/navigation.d.ts +4 -0
  32. package/dist/e2e/navigation.d.ts.map +1 -0
  33. package/dist/e2e/navigation.js +32 -0
  34. package/dist/e2e/siwe-mock.d.ts +11 -0
  35. package/dist/e2e/siwe-mock.d.ts.map +1 -0
  36. package/dist/e2e/siwe-mock.js +112 -0
  37. package/dist/e2e/siwe.d.ts +15 -0
  38. package/dist/e2e/siwe.d.ts.map +1 -0
  39. package/dist/e2e/siwe.js +85 -0
  40. package/dist/e2e/wallet-mock.d.ts +13 -0
  41. package/dist/e2e/wallet-mock.d.ts.map +1 -0
  42. package/dist/e2e/wallet-mock.js +91 -0
  43. package/dist/i18n/common-cli.d.ts +11 -0
  44. package/dist/i18n/common-cli.d.ts.map +1 -0
  45. package/dist/i18n/common-cli.js +22 -0
  46. package/dist/i18n/createTranslator.d.ts +28 -0
  47. package/dist/i18n/createTranslator.d.ts.map +1 -0
  48. package/dist/i18n/createTranslator.js +48 -0
  49. package/dist/i18n/index.d.ts +4 -0
  50. package/dist/i18n/index.d.ts.map +1 -0
  51. package/dist/i18n/index.js +2 -0
  52. package/dist/i18n/locales/cli.d.ts +3 -0
  53. package/dist/i18n/locales/cli.d.ts.map +1 -0
  54. package/dist/i18n/locales/cli.js +180 -0
  55. package/dist/i18n/types.d.ts +3 -0
  56. package/dist/i18n/types.d.ts.map +1 -0
  57. package/dist/i18n/types.js +1 -0
  58. package/dist/index.d.ts +2 -0
  59. package/dist/index.d.ts.map +1 -0
  60. package/dist/index.js +15 -0
  61. package/dist/index.test.d.ts +2 -0
  62. package/dist/index.test.d.ts.map +1 -0
  63. package/dist/index.test.js +10 -0
  64. package/dist/m.d.ts +2 -0
  65. package/dist/m.d.ts.map +1 -0
  66. package/dist/m.js +334 -0
  67. package/dist/plugin.d.ts +10 -0
  68. package/dist/plugin.d.ts.map +1 -0
  69. package/dist/plugin.js +7 -0
  70. package/dist/shadcn_components/cn.d.ts +13 -0
  71. package/dist/shadcn_components/cn.d.ts.map +1 -0
  72. package/dist/shadcn_components/cn.js +15 -0
  73. package/dist/shadcn_components/ui/accordion.d.ts +8 -0
  74. package/dist/shadcn_components/ui/accordion.d.ts.map +1 -0
  75. package/dist/shadcn_components/ui/accordion.js +14 -0
  76. package/dist/shadcn_components/ui/alert-dialog.d.ts +21 -0
  77. package/dist/shadcn_components/ui/alert-dialog.d.ts.map +1 -0
  78. package/dist/shadcn_components/ui/alert-dialog.js +27 -0
  79. package/dist/shadcn_components/ui/alert.d.ts +9 -0
  80. package/dist/shadcn_components/ui/alert.d.ts.map +1 -0
  81. package/dist/shadcn_components/ui/alert.js +22 -0
  82. package/dist/shadcn_components/ui/avatar.d.ts +7 -0
  83. package/dist/shadcn_components/ui/avatar.d.ts.map +1 -0
  84. package/dist/shadcn_components/ui/avatar.js +12 -0
  85. package/dist/shadcn_components/ui/badge.d.ts +10 -0
  86. package/dist/shadcn_components/ui/badge.d.ts.map +1 -0
  87. package/dist/shadcn_components/ui/badge.js +22 -0
  88. package/dist/shadcn_components/ui/button.d.ts +11 -0
  89. package/dist/shadcn_components/ui/button.d.ts.map +1 -0
  90. package/dist/shadcn_components/ui/button.js +31 -0
  91. package/dist/shadcn_components/ui/card.d.ts +10 -0
  92. package/dist/shadcn_components/ui/card.d.ts.map +1 -0
  93. package/dist/shadcn_components/ui/card.js +24 -0
  94. package/dist/shadcn_components/ui/checkbox.d.ts +5 -0
  95. package/dist/shadcn_components/ui/checkbox.d.ts.map +1 -0
  96. package/dist/shadcn_components/ui/checkbox.js +9 -0
  97. package/dist/shadcn_components/ui/dialog.d.ts +20 -0
  98. package/dist/shadcn_components/ui/dialog.d.ts.map +1 -0
  99. package/dist/shadcn_components/ui/dialog.js +23 -0
  100. package/dist/shadcn_components/ui/dropdown-menu.d.ts +28 -0
  101. package/dist/shadcn_components/ui/dropdown-menu.d.ts.map +1 -0
  102. package/dist/shadcn_components/ui/dropdown-menu.js +36 -0
  103. package/dist/shadcn_components/ui/form.d.ts +24 -0
  104. package/dist/shadcn_components/ui/form.d.ts.map +1 -0
  105. package/dist/shadcn_components/ui/form.js +63 -0
  106. package/dist/shadcn_components/ui/input.d.ts +4 -0
  107. package/dist/shadcn_components/ui/input.d.ts.map +1 -0
  108. package/dist/shadcn_components/ui/input.js +6 -0
  109. package/dist/shadcn_components/ui/label.d.ts +6 -0
  110. package/dist/shadcn_components/ui/label.d.ts.map +1 -0
  111. package/dist/shadcn_components/ui/label.js +10 -0
  112. package/dist/shadcn_components/ui/menubar.d.ts +29 -0
  113. package/dist/shadcn_components/ui/menubar.d.ts.map +1 -0
  114. package/dist/shadcn_components/ui/menubar.js +46 -0
  115. package/dist/shadcn_components/ui/popover.d.ts +7 -0
  116. package/dist/shadcn_components/ui/popover.d.ts.map +1 -0
  117. package/dist/shadcn_components/ui/popover.js +10 -0
  118. package/dist/shadcn_components/ui/progress.d.ts +5 -0
  119. package/dist/shadcn_components/ui/progress.d.ts.map +1 -0
  120. package/dist/shadcn_components/ui/progress.js +8 -0
  121. package/dist/shadcn_components/ui/radio-group.d.ts +6 -0
  122. package/dist/shadcn_components/ui/radio-group.d.ts.map +1 -0
  123. package/dist/shadcn_components/ui/radio-group.js +15 -0
  124. package/dist/shadcn_components/ui/scroll-area.d.ts +6 -0
  125. package/dist/shadcn_components/ui/scroll-area.d.ts.map +1 -0
  126. package/dist/shadcn_components/ui/scroll-area.js +12 -0
  127. package/dist/shadcn_components/ui/select.d.ts +14 -0
  128. package/dist/shadcn_components/ui/select.d.ts.map +1 -0
  129. package/dist/shadcn_components/ui/select.js +27 -0
  130. package/dist/shadcn_components/ui/separator.d.ts +5 -0
  131. package/dist/shadcn_components/ui/separator.d.ts.map +1 -0
  132. package/dist/shadcn_components/ui/separator.js +8 -0
  133. package/dist/shadcn_components/ui/sheet.d.ts +26 -0
  134. package/dist/shadcn_components/ui/sheet.d.ts.map +1 -0
  135. package/dist/shadcn_components/ui/sheet.js +37 -0
  136. package/dist/shadcn_components/ui/skeleton.d.ts +3 -0
  137. package/dist/shadcn_components/ui/skeleton.d.ts.map +1 -0
  138. package/dist/shadcn_components/ui/skeleton.js +6 -0
  139. package/dist/shadcn_components/ui/slider.d.ts +5 -0
  140. package/dist/shadcn_components/ui/slider.d.ts.map +1 -0
  141. package/dist/shadcn_components/ui/slider.js +8 -0
  142. package/dist/shadcn_components/ui/switch.d.ts +5 -0
  143. package/dist/shadcn_components/ui/switch.d.ts.map +1 -0
  144. package/dist/shadcn_components/ui/switch.js +8 -0
  145. package/dist/shadcn_components/ui/table.d.ts +11 -0
  146. package/dist/shadcn_components/ui/table.d.ts.map +1 -0
  147. package/dist/shadcn_components/ui/table.js +20 -0
  148. package/dist/shadcn_components/ui/tabs.d.ts +8 -0
  149. package/dist/shadcn_components/ui/tabs.d.ts.map +1 -0
  150. package/dist/shadcn_components/ui/tabs.js +13 -0
  151. package/dist/shadcn_components/ui/textarea.d.ts +4 -0
  152. package/dist/shadcn_components/ui/textarea.d.ts.map +1 -0
  153. package/dist/shadcn_components/ui/textarea.js +8 -0
  154. package/dist/shadcn_components/ui/toast.d.ts +16 -0
  155. package/dist/shadcn_components/ui/toast.d.ts.map +1 -0
  156. package/dist/shadcn_components/ui/toast.js +34 -0
  157. package/dist/shadcn_components/ui/toaster.d.ts +2 -0
  158. package/dist/shadcn_components/ui/toaster.d.ts.map +1 -0
  159. package/dist/shadcn_components/ui/toaster.js +10 -0
  160. package/dist/shadcn_components/ui/tooltip.d.ts +8 -0
  161. package/dist/shadcn_components/ui/tooltip.d.ts.map +1 -0
  162. package/dist/shadcn_components/ui/tooltip.js +11 -0
  163. package/dist/shadcn_components/ui/use-toast.d.ts +45 -0
  164. package/dist/shadcn_components/ui/use-toast.d.ts.map +1 -0
  165. package/dist/shadcn_components/ui/use-toast.js +126 -0
  166. package/dist/tasks/context.d.ts +13 -0
  167. package/dist/tasks/context.d.ts.map +1 -0
  168. package/dist/tasks/context.js +310 -0
  169. package/dist/tasks/create.d.ts +2 -0
  170. package/dist/tasks/create.d.ts.map +1 -0
  171. package/dist/tasks/create.js +91 -0
  172. package/dist/tasks/db.d.ts +19 -0
  173. package/dist/tasks/db.d.ts.map +1 -0
  174. package/dist/tasks/db.js +791 -0
  175. package/dist/tasks/e2e.d.ts +2 -0
  176. package/dist/tasks/e2e.d.ts.map +1 -0
  177. package/dist/tasks/e2e.js +124 -0
  178. package/dist/tasks/edit.d.ts +7 -0
  179. package/dist/tasks/edit.d.ts.map +1 -0
  180. package/dist/tasks/edit.js +471 -0
  181. package/dist/tasks/engine.d.ts +2 -0
  182. package/dist/tasks/engine.d.ts.map +1 -0
  183. package/dist/tasks/engine.js +149 -0
  184. package/dist/tasks/env-diff.d.ts +2 -0
  185. package/dist/tasks/env-diff.d.ts.map +1 -0
  186. package/dist/tasks/env-diff.js +140 -0
  187. package/dist/tasks/fuzzy.d.ts +9 -0
  188. package/dist/tasks/fuzzy.d.ts.map +1 -0
  189. package/dist/tasks/fuzzy.js +153 -0
  190. package/dist/tasks/glob.d.ts +5 -0
  191. package/dist/tasks/glob.d.ts.map +1 -0
  192. package/dist/tasks/glob.js +57 -0
  193. package/dist/tasks/grep.d.ts +9 -0
  194. package/dist/tasks/grep.d.ts.map +1 -0
  195. package/dist/tasks/grep.js +93 -0
  196. package/dist/tasks/readfile.d.ts +2 -0
  197. package/dist/tasks/readfile.d.ts.map +1 -0
  198. package/dist/tasks/readfile.js +177 -0
  199. package/dist/tasks/update.d.ts +5 -0
  200. package/dist/tasks/update.d.ts.map +1 -0
  201. package/dist/tasks/update.js +200 -0
  202. package/dist/tasks/util.d.ts +12 -0
  203. package/dist/tasks/util.d.ts.map +1 -0
  204. package/dist/tasks/util.js +42 -0
  205. package/dist/tasks/wallet.d.ts +2 -0
  206. package/dist/tasks/wallet.d.ts.map +1 -0
  207. package/dist/tasks/wallet.js +697 -0
  208. package/dist/tasks/writefile.d.ts +2 -0
  209. package/dist/tasks/writefile.d.ts.map +1 -0
  210. package/dist/tasks/writefile.js +66 -0
  211. package/dist/templates/AGENTS.md.hbs +81 -0
  212. package/dist/templates/ARCHITECTURE.md.hbs +146 -0
  213. package/dist/templates/CONTRIBUTING.md.hbs +83 -0
  214. package/dist/templates/LICENCIA.md +21 -0
  215. package/dist/templates/LICENSE.md +15 -0
  216. package/dist/templates/Makefile +16 -0
  217. package/dist/templates/README.md.hbs +111 -0
  218. package/dist/templates/apps/.env.example.hbs +75 -0
  219. package/dist/templates/apps/hardhat/.prettierrc +16 -0
  220. package/dist/templates/apps/hardhat/MOCK_USDT_README.md +20 -0
  221. package/dist/templates/apps/hardhat/Makefile +13 -0
  222. package/dist/templates/apps/hardhat/README.md +129 -0
  223. package/dist/templates/apps/hardhat/bin/MusdtVerification +4 -0
  224. package/dist/templates/apps/hardhat/bin/approveDepositOwner +7 -0
  225. package/dist/templates/apps/hardhat/bin/contractVerification +9 -0
  226. package/dist/templates/apps/hardhat/bin/deployMockUSDT +7 -0
  227. package/dist/templates/apps/hardhat/bin/prepadJ.sh +14 -0
  228. package/dist/templates/apps/hardhat/bin/verifyMockUSDT +7 -0
  229. package/dist/templates/apps/hardhat/contracts/MockUSDT.sol +47 -0
  230. package/dist/templates/apps/hardhat/hardhat.config.ts +102 -0
  231. package/dist/templates/apps/hardhat/package.json +55 -0
  232. package/dist/templates/apps/hardhat/scripts/approveDepositOwner.ts +22 -0
  233. package/dist/templates/apps/hardhat/scripts/deployMockUSDT.ts +49 -0
  234. package/dist/templates/apps/hardhat/scripts/verifyDeployment.ts +93 -0
  235. package/dist/templates/apps/hardhat/scripts/verifyMockUSDT.ts +52 -0
  236. package/dist/templates/apps/hardhat/sync-abis.mjs +58 -0
  237. package/dist/templates/apps/hardhat/test/MockUSDT.test.ts +40 -0
  238. package/dist/templates/apps/hardhat/tsconfig.json +27 -0
  239. package/dist/templates/apps/nextjs/.config/kysely.config.ts +36 -0
  240. package/dist/templates/apps/nextjs/Makefile +24 -0
  241. package/dist/templates/apps/nextjs/README.md.hbs +76 -0
  242. package/dist/templates/apps/nextjs/abis/IERC20.json +74 -0
  243. package/dist/templates/apps/nextjs/abis/MockUSDT.json +242 -0
  244. package/dist/templates/apps/nextjs/abis/ReentrancyGuard.json +1 -0
  245. package/dist/templates/apps/nextjs/app/globals.css +3 -0
  246. package/dist/templates/apps/nextjs/app/layout.tsx.hbs +26 -0
  247. package/dist/templates/apps/nextjs/app/page.tsx.hbs +225 -0
  248. package/dist/templates/apps/nextjs/app/testui/page.tsx +371 -0
  249. package/dist/templates/apps/nextjs/bin/m +8 -0
  250. package/dist/templates/apps/nextjs/components.json +21 -0
  251. package/dist/templates/apps/nextjs/next-env.d.ts +5 -0
  252. package/dist/templates/apps/nextjs/next.config.ts +10 -0
  253. package/dist/templates/apps/nextjs/package.json.hbs +48 -0
  254. package/dist/templates/apps/nextjs/pnpm-workspace.yaml +13 -0
  255. package/dist/templates/apps/nextjs/postcss.config.mjs +6 -0
  256. package/dist/templates/apps/nextjs/tailwind.config.js +11 -0
  257. package/dist/templates/apps/nextjs/tests/helpers.ts +31 -0
  258. package/dist/templates/apps/nextjs/tests/index.test.ts +7 -0
  259. package/dist/templates/apps/nextjs/tests/setup-env.ts.hbs +8 -0
  260. package/dist/templates/apps/nextjs/tests/test-utils.example.test.ts +168 -0
  261. package/dist/templates/apps/nextjs/tsconfig.json +44 -0
  262. package/dist/templates/apps/nextjs/tsconfig.test.json +38 -0
  263. package/dist/templates/apps/nextjs/vitest.config.ts +13 -0
  264. package/dist/test-utils/fs-mocks.d.ts +32 -0
  265. package/dist/test-utils/fs-mocks.d.ts.map +1 -0
  266. package/dist/test-utils/fs-mocks.js +63 -0
  267. package/dist/test-utils/i18n-mock.d.ts +21 -0
  268. package/dist/test-utils/i18n-mock.d.ts.map +1 -0
  269. package/dist/test-utils/i18n-mock.js +29 -0
  270. package/dist/test-utils/index.d.ts +12 -0
  271. package/dist/test-utils/index.d.ts.map +1 -0
  272. package/dist/test-utils/index.js +11 -0
  273. package/dist/test-utils/kysely-mocks.d.ts +298 -0
  274. package/dist/test-utils/kysely-mocks.d.ts.map +1 -0
  275. package/dist/test-utils/kysely-mocks.js +173 -0
  276. package/dist/test-utils/radix-mocks.d.ts +134 -0
  277. package/dist/test-utils/radix-mocks.d.ts.map +1 -0
  278. package/dist/test-utils/radix-mocks.js +175 -0
  279. package/dist/test-utils/rainbowkit-mocks.d.ts +80 -0
  280. package/dist/test-utils/rainbowkit-mocks.d.ts.map +1 -0
  281. package/dist/test-utils/rainbowkit-mocks.js +247 -0
  282. package/dist/test-utils/viem-mocks.d.ts +86 -0
  283. package/dist/test-utils/viem-mocks.d.ts.map +1 -0
  284. package/dist/test-utils/viem-mocks.js +54 -0
  285. package/dist/util/cli-parser.d.ts +20 -0
  286. package/dist/util/cli-parser.d.ts.map +1 -0
  287. package/dist/util/cli-parser.js +38 -0
  288. package/dist/util/colors.d.ts +5 -0
  289. package/dist/util/colors.d.ts.map +1 -0
  290. package/dist/util/colors.js +5 -0
  291. package/dist/util/locale.d.ts +3 -0
  292. package/dist/util/locale.d.ts.map +1 -0
  293. package/dist/util/locale.js +10 -0
  294. package/dist/wba/client.d.ts +19 -0
  295. package/dist/wba/client.d.ts.map +1 -0
  296. package/dist/wba/client.js +31 -0
  297. package/dist/wba/index.d.ts +4 -0
  298. package/dist/wba/index.d.ts.map +1 -0
  299. package/dist/wba/index.js +2 -0
  300. package/dist/wba/routes/event.d.ts +32 -0
  301. package/dist/wba/routes/event.d.ts.map +1 -0
  302. package/dist/wba/routes/event.js +42 -0
  303. package/dist/wba/routes/index.d.ts +3 -0
  304. package/dist/wba/routes/index.d.ts.map +1 -0
  305. package/dist/wba/routes/index.js +2 -0
  306. package/dist/wba/routes/summary.d.ts +44 -0
  307. package/dist/wba/routes/summary.d.ts.map +1 -0
  308. package/dist/wba/routes/summary.js +146 -0
  309. package/dist/wba/server.d.ts +18 -0
  310. package/dist/wba/server.d.ts.map +1 -0
  311. package/dist/wba/server.js +29 -0
  312. package/dist/wba/types.d.ts +68 -0
  313. package/dist/wba/types.d.ts.map +1 -0
  314. package/dist/wba/types.js +6 -0
  315. package/package.json +223 -0
  316. package/src/blockchain/README.md +80 -0
  317. package/src/debug/README.md +94 -0
  318. package/src/e2e/README.md +105 -0
  319. package/src/i18n/README.md +143 -0
  320. package/src/shadcn_components/README.md +125 -0
  321. package/src/tasks/README.md +69 -0
  322. package/src/test-utils/README.md +638 -0
  323. package/src/util/README.md +18 -0
  324. package/src/wba/README.md +175 -0
@@ -0,0 +1,149 @@
1
+ // src/tasks/engine.ts
2
+ // Engine management: setup, list, check for shared modules (WBA, credentials, etc.)
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { success, info, problem } from '../util/colors.js';
6
+ import { createTranslator } from '../i18n/createTranslator.js';
7
+ import { detectLocale } from '../util/locale.js';
8
+ import commonCli from '../i18n/common-cli.js';
9
+ const t = createTranslator(detectLocale(), {
10
+ en: {
11
+ 'engine.unknown': 'Unknown engine command: {{0}}. Use: wba:setup, credentials:setup, list, check',
12
+ },
13
+ es: {
14
+ 'engine.unknown': 'Comando de motor desconocido: {{0}}. Use: wba:setup, credentials:setup, list, check',
15
+ },
16
+ }, commonCli);
17
+ function getArg(args, name) {
18
+ const idx = args.indexOf(name);
19
+ return idx >= 0 && idx + 1 < args.length ? args[idx + 1] : null;
20
+ }
21
+ function nextMigrationNumber(dir) {
22
+ if (!fs.existsSync(dir))
23
+ fs.mkdirSync(dir, { recursive: true });
24
+ const files = fs.readdirSync(dir).filter(f => f.endsWith('.sql'));
25
+ const timestamp = new Date().toISOString().replace(/[-:T]/g, '').slice(0, 14);
26
+ return `${timestamp}${String(files.length + 1).padStart(3, '0')}`;
27
+ }
28
+ async function cmdWbaSetup() {
29
+ const migrateDir = path.join(process.cwd(), 'db', 'migrate');
30
+ const num = nextMigrationNumber(migrateDir);
31
+ const webEventPath = path.join(migrateDir, `${num}_create_web_event.sql`);
32
+ fs.writeFileSync(webEventPath, `-- Migration: create web_event table for WBA analytics
33
+ CREATE TABLE IF NOT EXISTS web_event (
34
+ id SERIAL PRIMARY KEY,
35
+ session_id VARCHAR(64),
36
+ event_type VARCHAR(40) NOT NULL,
37
+ pathname VARCHAR(200),
38
+ locale VARCHAR(5),
39
+ referrer VARCHAR(500),
40
+ user_agent VARCHAR(500),
41
+ ip VARCHAR(45),
42
+ wallet VARCHAR(42),
43
+ metadata JSONB,
44
+ created_at TIMESTAMP DEFAULT NOW()
45
+ );
46
+ `);
47
+ const num2 = nextMigrationNumber(migrateDir);
48
+ const txPath = path.join(migrateDir, `${num2}_create_transaction.sql`);
49
+ fs.writeFileSync(txPath, `-- Migration: create transaction table for WBA analytics
50
+ -- Required columns: crypto, amount, wallet
51
+ -- Run: bin/m db:migrate
52
+ CREATE TABLE IF NOT EXISTS transaction (
53
+ id SERIAL PRIMARY KEY,
54
+ crypto VARCHAR(10) NOT NULL,
55
+ amount NUMERIC NOT NULL,
56
+ wallet VARCHAR(42) NOT NULL,
57
+ created_at TIMESTAMP DEFAULT NOW()
58
+ );
59
+ `);
60
+ success(`✅ WBA migrations created:`);
61
+ console.log(` ${webEventPath}`);
62
+ console.log(` ${txPath}`);
63
+ console.log(` Run: bin/m db:migrate`);
64
+ }
65
+ async function cmdCredentialsSetup() {
66
+ const migrateDir = path.join(process.cwd(), 'db', 'migrate');
67
+ const num = nextMigrationNumber(migrateDir);
68
+ const metaPath = path.join(migrateDir, `${num}_create_credential_metadata.sql`);
69
+ fs.writeFileSync(metaPath, `-- Migration: create credential_metadata cache table
70
+ CREATE TABLE IF NOT EXISTS credential_metadata (
71
+ token_id INTEGER NOT NULL,
72
+ chain_id VARCHAR(20) NOT NULL DEFAULT 'celo',
73
+ name VARCHAR(255) NOT NULL,
74
+ type VARCHAR(50) NOT NULL,
75
+ site VARCHAR(50) NOT NULL,
76
+ is_premium BOOLEAN DEFAULT false,
77
+ is_soulbound BOOLEAN DEFAULT true,
78
+ image_url TEXT NOT NULL,
79
+ updated_at TIMESTAMP NOT NULL DEFAULT NOW(),
80
+ PRIMARY KEY (token_id, chain_id)
81
+ );
82
+ `);
83
+ const num2 = nextMigrationNumber(migrateDir);
84
+ const emissionPath = path.join(migrateDir, `${num2}_create_credential_emission.sql`);
85
+ fs.writeFileSync(emissionPath, `-- Migration: create credential_emission tracking table
86
+ -- Adjust wallet_address or usuario_id per project needs
87
+ CREATE TABLE IF NOT EXISTS credential_emission (
88
+ id BIGSERIAL PRIMARY KEY,
89
+ wallet_address VARCHAR(42) NOT NULL,
90
+ token_id INTEGER NOT NULL,
91
+ chain_id VARCHAR(20) NOT NULL DEFAULT 'celo',
92
+ emitted_at TIMESTAMP NOT NULL DEFAULT NOW(),
93
+ UNIQUE(wallet_address, token_id, chain_id)
94
+ );
95
+ `);
96
+ success(`✅ Credential migrations created:`);
97
+ console.log(` ${metaPath}`);
98
+ console.log(` ${emissionPath}`);
99
+ console.log(` Run: bin/m db:migrate`);
100
+ }
101
+ async function cmdList() {
102
+ console.log('Available engines:');
103
+ console.log(' wba — Web analytics (web_event + transaction)');
104
+ console.log(' credentials — Blockchain credentials (credential_metadata + credential_emission)');
105
+ console.log();
106
+ console.log('Install: bin/m eng:<name>:setup');
107
+ console.log('Verify: bin/m eng:check');
108
+ }
109
+ async function cmdCheck() {
110
+ info('Verifying engine schemas...');
111
+ const { runDbCheck } = await import('./db.js');
112
+ await runDbCheck();
113
+ }
114
+ export async function runEngine(args) {
115
+ if (args.length === 0 || args.includes('--help') || args.includes('-h')) {
116
+ console.log('Engine commands:');
117
+ console.log(' eng:wba:setup — Create WBA migration files');
118
+ console.log(' eng:credentials:setup — Create credential migration files');
119
+ console.log(' eng:list — List available engines');
120
+ console.log(' eng:check — Verify engine schemas');
121
+ }
122
+ const command = args[0];
123
+ const rest = args.slice(1);
124
+ try {
125
+ if (command === 'wba' && rest[0] === 'setup') {
126
+ await cmdWbaSetup();
127
+ }
128
+ else if (command === 'credentials' && rest[0] === 'setup') {
129
+ await cmdCredentialsSetup();
130
+ }
131
+ else {
132
+ switch (command) {
133
+ case 'list':
134
+ await cmdList();
135
+ break;
136
+ case 'check':
137
+ await cmdCheck();
138
+ break;
139
+ default:
140
+ problem(t('engine.unknown', command));
141
+ throw new Error(t('engine.unknown', command));
142
+ }
143
+ }
144
+ }
145
+ catch (err) {
146
+ problem(err.message || String(err));
147
+ throw err;
148
+ }
149
+ }
@@ -0,0 +1,2 @@
1
+ export declare function runEnvDiff(baseFile?: string, targetFile?: string): Promise<void>;
2
+ //# sourceMappingURL=env-diff.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"env-diff.d.ts","sourceRoot":"","sources":["../../src/tasks/env-diff.ts"],"names":[],"mappings":"AA0DA,wBAAsB,UAAU,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,iBA2FtE"}
@@ -0,0 +1,140 @@
1
+ /**
2
+ * env:diff — Compares two .env files.
3
+ *
4
+ * Without arguments: compares ../.env.example against ../.env.
5
+ * With arguments: env:diff <base> <target>
6
+ *
7
+ * Reports four categories:
8
+ * 1. Variables only in base (missing in target) — most prominent
9
+ * 2. Variables only in target (not in base)
10
+ * 3. Variables with different values — horizontal list
11
+ * 4. Variables with equal values — horizontal list
12
+ */
13
+ import * as fs from 'fs';
14
+ import * as path from 'path';
15
+ import { problem, success, info, warn } from '../util/colors.js';
16
+ function parseEnvFile(filePath) {
17
+ try {
18
+ const content = fs.readFileSync(filePath, 'utf-8');
19
+ const vars = {};
20
+ for (const line of content.split('\n')) {
21
+ const trimmed = line.trim();
22
+ if (!trimmed || trimmed.startsWith('#'))
23
+ continue;
24
+ const eqIdx = trimmed.indexOf('=');
25
+ if (eqIdx === -1)
26
+ continue;
27
+ const key = trimmed.substring(0, eqIdx).trim();
28
+ const value = trimmed.substring(eqIdx + 1);
29
+ if (key)
30
+ vars[key] = value;
31
+ }
32
+ return vars;
33
+ }
34
+ catch {
35
+ return null;
36
+ }
37
+ }
38
+ function formatHorizontalList(items, maxWidth = 78) {
39
+ if (items.length === 0)
40
+ return '';
41
+ let line = '';
42
+ const lines = [];
43
+ for (let i = 0; i < items.length; i++) {
44
+ const sep = i < items.length - 1 ? ', ' : '';
45
+ const candidate = line + items[i] + sep;
46
+ if (candidate.length > maxWidth && line.length > 0) {
47
+ lines.push(line.trimEnd());
48
+ line = ' ' + items[i] + sep;
49
+ }
50
+ else {
51
+ line = candidate;
52
+ }
53
+ }
54
+ if (line.trim())
55
+ lines.push(line.trimEnd());
56
+ return lines.join('\n');
57
+ }
58
+ export async function runEnvDiff(baseFile, targetFile) {
59
+ if (baseFile === '--help' || baseFile === '-h'
60
+ || targetFile === '--help' || targetFile === '-h') {
61
+ info('Uso: m env:diff [base] [target]');
62
+ info(' Sin argumentos: compara ../.env.example vs ../.env');
63
+ info(' Con 1 argumento: compara ../.env.example vs el archivo dado');
64
+ info(' Con 2 argumentos: compara base vs target');
65
+ return;
66
+ }
67
+ if (!baseFile && !targetFile) {
68
+ baseFile = path.join(process.cwd(), '..', '.env.example');
69
+ targetFile = path.join(process.cwd(), '..', '.env');
70
+ }
71
+ else if (baseFile && !targetFile) {
72
+ targetFile = baseFile;
73
+ baseFile = path.join(process.cwd(), '..', '.env.example');
74
+ }
75
+ const baseVars = parseEnvFile(baseFile);
76
+ const targetVars = parseEnvFile(targetFile);
77
+ if (baseVars === null) {
78
+ problem(`No se pudo leer: ${baseFile}`);
79
+ process.exit(2);
80
+ }
81
+ if (targetVars === null) {
82
+ problem(`No se pudo leer: ${targetFile}`);
83
+ process.exit(2);
84
+ }
85
+ const baseKeys = new Set(Object.keys(baseVars));
86
+ const targetKeys = new Set(Object.keys(targetVars));
87
+ const onlyBase = [...baseKeys].filter(k => !targetKeys.has(k)).sort();
88
+ const onlyTarget = [...targetKeys].filter(k => !baseKeys.has(k)).sort();
89
+ const common = [...baseKeys].filter(k => targetKeys.has(k)).sort();
90
+ const different = [];
91
+ const equal = [];
92
+ for (const key of common) {
93
+ if (baseVars[key] === targetVars[key]) {
94
+ equal.push(key);
95
+ }
96
+ else {
97
+ different.push(key);
98
+ }
99
+ }
100
+ console.log();
101
+ info(` Base: ${baseFile} (${baseKeys.size} variables)`);
102
+ info(` Target: ${targetFile} (${targetKeys.size} variables)`);
103
+ console.log();
104
+ let hasDiff = false;
105
+ if (onlyBase.length > 0) {
106
+ hasDiff = true;
107
+ warn('⚠ Solo en .env.example (faltan en .env):');
108
+ for (const k of onlyBase)
109
+ console.log(` ${k}`);
110
+ console.log();
111
+ }
112
+ if (onlyTarget.length > 0) {
113
+ hasDiff = true;
114
+ warn('⚠ Solo en .env (no están en .env.example):');
115
+ for (const k of onlyTarget)
116
+ console.log(` ${k}`);
117
+ console.log();
118
+ }
119
+ if (different.length > 0) {
120
+ hasDiff = true;
121
+ warn('≠ Diferentes:');
122
+ console.log(formatHorizontalList(different));
123
+ console.log();
124
+ }
125
+ if (!hasDiff) {
126
+ success('✓ .env.example y .env son idénticos.');
127
+ process.exit(0);
128
+ }
129
+ if (equal.length > 0) {
130
+ if (equal.length > 10) {
131
+ success(`= Iguales: ${equal.length} variables`);
132
+ }
133
+ else {
134
+ success('= Iguales:');
135
+ console.log(formatHorizontalList(equal));
136
+ }
137
+ console.log();
138
+ }
139
+ process.exit(1);
140
+ }
@@ -0,0 +1,9 @@
1
+ export declare function similarity(a: string, b: string, maxDistance?: number): number;
2
+ export declare function findBestMatch(search: string, content: string, threshold?: number, fileExt?: string): {
3
+ found: boolean;
4
+ text: string;
5
+ similarity: number;
6
+ startIndex: number;
7
+ endIndex: number;
8
+ };
9
+ //# sourceMappingURL=fuzzy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fuzzy.d.ts","sourceRoot":"","sources":["../../src/tasks/fuzzy.ts"],"names":[],"mappings":"AA2GA,wBAAgB,UAAU,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAM7E;AAGD,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,SAAS,GAAE,MAAa,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG;IAC1G,KAAK,EAAE,OAAO,CAAA;IACd,IAAI,EAAE,MAAM,CAAA;IACZ,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;CACjB,CAmEA"}
@@ -0,0 +1,153 @@
1
+ // Funciones de fuzzy matching optimizadas para ai:edit
2
+ // Reglas de normalización por extensión de archivo
3
+ const rulesByExtension = {
4
+ // Lenguajes donde es SEGURO normalizar comillas
5
+ 'js': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
6
+ 'ts': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
7
+ 'jsx': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
8
+ 'tsx': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
9
+ // Archivos de texto plano
10
+ 'md': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
11
+ 'txt': { normalizeWhitespace: true, normalizePunctuationSpacing: true, normalizeQuotes: true, normalizeQuoteType: 'unify' },
12
+ // Por defecto: NO normalizar nada (seguro)
13
+ 'default': { normalizeWhitespace: false, normalizePunctuationSpacing: false, normalizeQuotes: false, normalizeQuoteType: 'preserve' }
14
+ };
15
+ function getNormalizationRules(fileExt) {
16
+ if (!fileExt)
17
+ return rulesByExtension.default;
18
+ return rulesByExtension[fileExt] || rulesByExtension.default;
19
+ }
20
+ // Normalizar texto para comparación rápida (fingerprint)
21
+ function quickFingerprint(str) {
22
+ return str
23
+ .replace(/\s+/g, ' ') // espacios múltiples → uno
24
+ .replace(/\t/g, ' ') // tabs → espacios
25
+ .replace(/[“”]/g, '"') // comillas curvas → rectas
26
+ .replace(/[‘’]/g, "'") // comillas simples curvas → rectas
27
+ .slice(0, 200); // solo primeros 200 caracteres para fingerprint
28
+ }
29
+ // Normalización completa para fuzzy matching (configurable por tipo de archivo)
30
+ function normalizeForFuzzy(str, rules) {
31
+ let result = str;
32
+ if (rules.normalizeWhitespace) {
33
+ result = result
34
+ .replace(/\s+/g, ' ')
35
+ .replace(/\t/g, ' ');
36
+ }
37
+ if (rules.normalizeQuotes) {
38
+ result = result
39
+ .replace(/[“”]/g, '"')
40
+ .replace(/[‘’]/g, "'");
41
+ if (rules.normalizeQuoteType === 'unify') {
42
+ result = result.replace(/['"]/g, '"');
43
+ }
44
+ }
45
+ else {
46
+ // Solo normalizar comillas curvas a rectas, pero mantener diferencia
47
+ result = result
48
+ .replace(/[“”]/g, '"')
49
+ .replace(/[‘’]/g, "'");
50
+ }
51
+ if (rules.normalizePunctuationSpacing) {
52
+ result = result.replace(/\s*([;:,.!?])\s*/g, '$1');
53
+ }
54
+ return result.trim();
55
+ }
56
+ // Distancia de Levenshtein optimizada (solo calcular si es necesario)
57
+ function levenshtein(a, b, maxDistance) {
58
+ // Si se especifica distancia máxima, podemos abortar temprano
59
+ const m = a.length;
60
+ const n = b.length;
61
+ if (Math.abs(m - n) > (maxDistance || 100)) {
62
+ return (maxDistance || 100) + 1;
63
+ }
64
+ let prev = new Array(n + 1).fill(0);
65
+ let curr = new Array(n + 1).fill(0);
66
+ for (let j = 0; j <= n; j++)
67
+ prev[j] = j;
68
+ for (let i = 1; i <= m; i++) {
69
+ curr[0] = i;
70
+ const minPossible = Math.min(...prev);
71
+ if (maxDistance !== undefined && minPossible > maxDistance) {
72
+ return maxDistance + 1;
73
+ }
74
+ for (let j = 1; j <= n; j++) {
75
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
76
+ curr[j] = Math.min(prev[j] + 1, curr[j - 1] + 1, prev[j - 1] + cost);
77
+ }
78
+ ;
79
+ [prev, curr] = [curr, prev];
80
+ }
81
+ return prev[n];
82
+ }
83
+ // Calcular similitud (0 a 1) con límite de tiempo
84
+ export function similarity(a, b, maxDistance) {
85
+ if (a.length === 0 && b.length === 0)
86
+ return 1;
87
+ const maxLen = Math.max(a.length, b.length);
88
+ const distance = levenshtein(a, b, maxDistance);
89
+ if (maxDistance !== undefined && distance > maxDistance)
90
+ return 0;
91
+ return 1 - distance / maxLen;
92
+ }
93
+ // Buscar la mejor coincidencia en el contenido (optimizado)
94
+ export function findBestMatch(search, content, threshold = 0.85, fileExt) {
95
+ // 1. Exact match (rápido)
96
+ const exactIndex = content.indexOf(search);
97
+ if (exactIndex !== -1) {
98
+ return {
99
+ found: true,
100
+ text: search,
101
+ similarity: 1,
102
+ startIndex: exactIndex,
103
+ endIndex: exactIndex + search.length
104
+ };
105
+ }
106
+ // Obtener reglas según extensión
107
+ const rules = getNormalizationRules(fileExt);
108
+ // 2. Normalized exact match (ignorar diferencias de formato)
109
+ const normalizedSearch = normalizeForFuzzy(search, rules);
110
+ const normalizedContent = normalizeForFuzzy(content, rules);
111
+ const normalizedIndex = normalizedContent.indexOf(normalizedSearch);
112
+ if (normalizedIndex !== -1) {
113
+ // Encontrar la posición original en content que corresponde a normalizedIndex
114
+ let originalStart = 0;
115
+ let normalizedPos = 0;
116
+ // Avanzar hasta la posición normalizada
117
+ for (let i = 0; i < content.length && normalizedPos < normalizedIndex; i++) {
118
+ const chunk = content[i];
119
+ const normalizedChunk = normalizeForFuzzy(chunk, rules);
120
+ if (normalizedChunk.length > 0) {
121
+ normalizedPos += normalizedChunk.length;
122
+ }
123
+ originalStart = i + 1;
124
+ }
125
+ // Extraer la subcadena original que coincide
126
+ let originalEnd = originalStart;
127
+ let matchedNormalized = '';
128
+ for (let i = originalStart; i < content.length && matchedNormalized.length < normalizedSearch.length; i++) {
129
+ const chunk = content[i];
130
+ const normalizedChunk = normalizeForFuzzy(chunk, rules);
131
+ if (normalizedChunk.length > 0) {
132
+ matchedNormalized += normalizedChunk;
133
+ }
134
+ originalEnd = i + 1;
135
+ }
136
+ const originalText = content.substring(originalStart, originalEnd);
137
+ return {
138
+ found: true,
139
+ text: originalText,
140
+ similarity: 0.95,
141
+ startIndex: originalStart,
142
+ endIndex: originalEnd
143
+ };
144
+ }
145
+ // 3. Si no, no hay match (por ahora, para no complicar)
146
+ return {
147
+ found: false,
148
+ text: '',
149
+ similarity: 0,
150
+ startIndex: -1,
151
+ endIndex: -1
152
+ };
153
+ }
@@ -0,0 +1,5 @@
1
+ export declare function runAiGlob(pattern: string, options?: {
2
+ path?: string;
3
+ ignore?: string[];
4
+ }): Promise<void>;
5
+ //# sourceMappingURL=glob.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"glob.d.ts","sourceRoot":"","sources":["../../src/tasks/glob.ts"],"names":[],"mappings":"AAqBA,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE;IAAE,IAAI,CAAC,EAAE,MAAM,CAAC;IAAC,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,iBAyChG"}
@@ -0,0 +1,57 @@
1
+ import { glob } from 'glob';
2
+ import { resolve } from 'node:path';
3
+ import { info, success, problem } from '../util/colors.js';
4
+ import { setClipboard } from './edit.js';
5
+ import { createTranslator } from '../i18n/createTranslator.js';
6
+ import { detectLocale } from '../util/locale.js';
7
+ import commonCli from '../i18n/common-cli.js';
8
+ const t = createTranslator(detectLocale(), {
9
+ en: {
10
+ 'glob.no_files': 'No files found. Diagnostic copied to clipboard.',
11
+ 'glob.done': '✅ Search completed ({{0}}KB copied to clipboard)',
12
+ 'glob.error': '❌ Error: {{0}}. Diagnostic copied to clipboard.',
13
+ },
14
+ es: {
15
+ 'glob.no_files': 'No se encontraron archivos. Diagnóstico copiado al portapapeles.',
16
+ 'glob.done': '✅ Búsqueda completada ({{0}}KB copiados al portapapeles)',
17
+ 'glob.error': '❌ Error: {{0}}. Diagnóstico copiado al portapapeles.',
18
+ },
19
+ }, commonCli);
20
+ export async function runAiGlob(pattern, options = {}) {
21
+ const searchPath = options.path ? resolve(process.cwd(), options.path) : process.cwd();
22
+ const ignore = options.ignore || ['node_modules/**', 'dist/**', '.git/**'];
23
+ try {
24
+ const files = await glob(pattern, { cwd: searchPath, ignore, absolute: false });
25
+ if (files.length === 0) {
26
+ const diagnostic = `🔍 No se encontraron archivos para el patrón: "${pattern}"
27
+
28
+ Ruta buscada: ${searchPath}
29
+ Ignorados: ${ignore.join(', ')}
30
+
31
+ Sugerencias:
32
+ 1. Verifica que el patrón sea correcto (ej: "*.ts", "src/**/*.tsx").
33
+ 2. Usa --path para especificar una ruta diferente.
34
+ 3. Usa --ignore para excluir patrones adicionales.
35
+ 4. Ejecuta: ls -la ${searchPath} para confirmar que hay archivos.`;
36
+ await setClipboard(diagnostic);
37
+ info(t('glob.no_files'));
38
+ }
39
+ const output = files.join('\n');
40
+ console.log(output);
41
+ await setClipboard(output);
42
+ success(t('glob.done', Math.round(output.length / 1024).toString()));
43
+ }
44
+ catch (err) {
45
+ const diagnostic = `❌ Error en glob: ${err.message}
46
+
47
+ Patrón: "${pattern}"
48
+ Ruta: ${searchPath}
49
+
50
+ Sugerencias:
51
+ 1. Verifica la sintaxis del patrón glob.
52
+ 2. Asegura que la ruta sea correcta y exista.
53
+ 3. Si el patrón es complejo, simplifícalo (ej: "*.ts" en lugar de "**/*.ts").`;
54
+ await setClipboard(diagnostic);
55
+ problem(t('glob.error', err.message));
56
+ }
57
+ }
@@ -0,0 +1,9 @@
1
+ interface GrepOptions {
2
+ path?: string;
3
+ type?: string;
4
+ context?: number;
5
+ ignoreCase?: boolean;
6
+ }
7
+ export declare function runAiGrep(pattern: string, options?: GrepOptions): Promise<void>;
8
+ export {};
9
+ //# sourceMappingURL=grep.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"grep.d.ts","sourceRoot":"","sources":["../../src/tasks/grep.ts"],"names":[],"mappings":"AAyBA,UAAU,WAAW;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAsB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,GAAE,WAAgB,iBAuEvE"}
@@ -0,0 +1,93 @@
1
+ import { spawnSync } from 'node:child_process';
2
+ import { resolve } from 'node:path';
3
+ import { info, success, problem } from '../util/colors.js';
4
+ import { setClipboard, getClipboard } from './edit.js';
5
+ import { createTranslator } from '../i18n/createTranslator.js';
6
+ import { detectLocale } from '../util/locale.js';
7
+ import commonCli from '../i18n/common-cli.js';
8
+ const t = createTranslator(detectLocale(), {
9
+ en: {
10
+ 'grep.empty_clipboard': '❌ Empty clipboard',
11
+ 'grep.done': '✅ Search completed ({{0}}KB copied to clipboard)',
12
+ 'grep.no_matches': 'No matches found in clipboard',
13
+ 'grep.error': '❌ Error: {{0}}. Diagnostic copied to clipboard.',
14
+ 'grep.no_files': 'No matches found. Diagnostic copied to clipboard.',
15
+ },
16
+ es: {
17
+ 'grep.empty_clipboard': '❌ Portapapeles vacío',
18
+ 'grep.done': '✅ Búsqueda completada ({{0}}KB copiados al portapapeles)',
19
+ 'grep.no_matches': 'No se encontraron coincidencias en el portapapeles',
20
+ 'grep.error': '❌ Error: {{0}}. Diagnóstico copiado al portapapeles.',
21
+ 'grep.no_files': 'No se encontraron coincidencias. Diagnóstico copiado al portapapeles.',
22
+ },
23
+ }, commonCli);
24
+ export async function runAiGrep(pattern, options = {}) {
25
+ if (!options.path) {
26
+ const clipboardContent = await getClipboard();
27
+ if (!clipboardContent) {
28
+ problem(t('grep.empty_clipboard'));
29
+ return;
30
+ }
31
+ const lines = clipboardContent.split('\n');
32
+ const matches = [];
33
+ for (let i = 0; i < lines.length; i++) {
34
+ if (lines[i].includes(pattern)) {
35
+ matches.push(`${i + 1}: ${lines[i]}`);
36
+ }
37
+ }
38
+ if (matches.length > 0) {
39
+ const output = matches.join('\n');
40
+ console.log(output);
41
+ await setClipboard(output);
42
+ success(t('grep.done', Math.round(output.length / 1024).toString()));
43
+ }
44
+ else {
45
+ info(t('grep.no_matches'));
46
+ await setClipboard('');
47
+ }
48
+ return;
49
+ }
50
+ const searchPath = resolve(process.cwd(), options.path);
51
+ const args = ['-r', '-n'];
52
+ if (options.context)
53
+ args.push('-C', String(options.context));
54
+ if (options.ignoreCase)
55
+ args.push('-i');
56
+ args.push(pattern, searchPath);
57
+ const result = spawnSync('grep', args, { encoding: 'utf-8' });
58
+ if (result.error) {
59
+ const diagnostic = `❌ Error en la búsqueda: ${result.error.message}
60
+
61
+ Patrón: "${pattern}"
62
+ Ruta: ${searchPath}
63
+ Comando: grep ${args.join(' ')}
64
+
65
+ Sugerencias:
66
+ 1. Verifica que la ruta exista.
67
+ 2. Verifica los permisos de los archivos.`;
68
+ await setClipboard(diagnostic);
69
+ problem(t('grep.error', result.error.message));
70
+ }
71
+ const output = (result.stdout || '').trim();
72
+ const errOutput = (result.stderr || '').trim();
73
+ if (output) {
74
+ console.log(output);
75
+ await setClipboard(output);
76
+ success(t('grep.done', Math.round(output.length / 1024).toString()));
77
+ }
78
+ else if (errOutput) {
79
+ problem(`❌ ${errOutput}`);
80
+ }
81
+ else {
82
+ const diagnostic = `🔍 No se encontraron coincidencias para: "${pattern}"
83
+
84
+ Ruta buscada: ${searchPath}
85
+
86
+ Sugerencias:
87
+ 1. Verifica que el patrón sea correcto.
88
+ 2. Usa --ignore-case si el caso podría ser diferente.
89
+ 3. Verifica que haya archivos en: ${searchPath}`;
90
+ await setClipboard(diagnostic);
91
+ info(t('grep.no_files'));
92
+ }
93
+ }
@@ -0,0 +1,2 @@
1
+ export declare function runAiReadFile(args: string[]): Promise<void>;
2
+ //# sourceMappingURL=readfile.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readfile.d.ts","sourceRoot":"","sources":["../../src/tasks/readfile.ts"],"names":[],"mappings":"AA6DA,wBAAsB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,iBAmG/C"}