@kapishdima/ai-ledger 0.0.8 → 0.0.9

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 (3) hide show
  1. package/dist/cli.js +497 -226
  2. package/dist/plugin.js +25 -25
  3. package/package.json +1 -1
package/dist/cli.js CHANGED
@@ -151,15 +151,26 @@ import fs2 from "fs";
151
151
  import path2 from "path";
152
152
  import os2 from "os";
153
153
 
154
+ // ../../node_modules/.bun/@clack+prompts@0.9.1/node_modules/@clack/prompts/dist/index.mjs
155
+ import { stripVTControlCharacters as T2 } from "util";
156
+
154
157
  // ../../node_modules/.bun/@clack+core@0.4.1/node_modules/@clack/core/dist/index.mjs
155
158
  var import_sisteransi = __toESM(require_src(), 1);
159
+ var import_picocolors = __toESM(require_picocolors(), 1);
156
160
  import { stdin as $, stdout as j } from "process";
157
161
  import * as f from "readline";
162
+ import M from "readline";
163
+ import { WriteStream as U } from "tty";
158
164
  function J({ onlyFirst: t = false } = {}) {
159
165
  const F = ["[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))", "(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))"].join("|");
160
166
  return new RegExp(F, t ? undefined : "g");
161
167
  }
162
168
  var Q = J();
169
+ function T(t) {
170
+ if (typeof t != "string")
171
+ throw new TypeError(`Expected a \`string\`, got \`${typeof t}\``);
172
+ return t.replace(Q, "");
173
+ }
163
174
  function O(t) {
164
175
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
165
176
  }
@@ -200,6 +211,30 @@ var uD = function() {
200
211
  return /\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g;
201
212
  };
202
213
  var FD = O(uD);
214
+ function A(t, u = {}) {
215
+ if (typeof t != "string" || t.length === 0 || (u = { ambiguousIsNarrow: true, ...u }, t = T(t), t.length === 0))
216
+ return 0;
217
+ t = t.replace(FD(), " ");
218
+ const F = u.ambiguousIsNarrow ? 1 : 2;
219
+ let e = 0;
220
+ for (const s of t) {
221
+ const i = s.codePointAt(0);
222
+ if (i <= 31 || i >= 127 && i <= 159 || i >= 768 && i <= 879)
223
+ continue;
224
+ switch (DD.eastAsianWidth(s)) {
225
+ case "F":
226
+ case "W":
227
+ e += 2;
228
+ break;
229
+ case "A":
230
+ e += F;
231
+ break;
232
+ default:
233
+ e += 1;
234
+ }
235
+ }
236
+ return e;
237
+ }
203
238
  var m = 10;
204
239
  var L = (t = 0) => (u) => `\x1B[${u + t}m`;
205
240
  var N = (t = 0) => (u) => `\x1B[${38 + t};5;${u}m`;
@@ -246,8 +281,87 @@ function sD() {
246
281
  }
247
282
  var iD = sD();
248
283
  var v = new Set(["\x1B", "\x9B"]);
284
+ var CD = 39;
285
+ var w = "\x07";
286
+ var W = "[";
249
287
  var rD = "]";
288
+ var R = "m";
250
289
  var y = `${rD}8;;`;
290
+ var V = (t) => `${v.values().next().value}${W}${t}${R}`;
291
+ var z = (t) => `${v.values().next().value}${y}${t}${w}`;
292
+ var ED = (t) => t.split(" ").map((u) => A(u));
293
+ var _ = (t, u, F) => {
294
+ const e = [...u];
295
+ let s = false, i = false, D = A(T(t[t.length - 1]));
296
+ for (const [C, o] of e.entries()) {
297
+ const E = A(o);
298
+ if (D + E <= F ? t[t.length - 1] += o : (t.push(o), D = 0), v.has(o) && (s = true, i = e.slice(C + 1).join("").startsWith(y)), s) {
299
+ i ? o === w && (s = false, i = false) : o === R && (s = false);
300
+ continue;
301
+ }
302
+ D += E, D === F && C < e.length - 1 && (t.push(""), D = 0);
303
+ }
304
+ !D && t[t.length - 1].length > 0 && t.length > 1 && (t[t.length - 2] += t.pop());
305
+ };
306
+ var nD = (t) => {
307
+ const u = t.split(" ");
308
+ let F = u.length;
309
+ for (;F > 0 && !(A(u[F - 1]) > 0); )
310
+ F--;
311
+ return F === u.length ? t : u.slice(0, F).join(" ") + u.slice(F).join("");
312
+ };
313
+ var oD = (t, u, F = {}) => {
314
+ if (F.trim !== false && t.trim() === "")
315
+ return "";
316
+ let e = "", s, i;
317
+ const D = ED(t);
318
+ let C = [""];
319
+ for (const [E, a] of t.split(" ").entries()) {
320
+ F.trim !== false && (C[C.length - 1] = C[C.length - 1].trimStart());
321
+ let n = A(C[C.length - 1]);
322
+ if (E !== 0 && (n >= u && (F.wordWrap === false || F.trim === false) && (C.push(""), n = 0), (n > 0 || F.trim === false) && (C[C.length - 1] += " ", n++)), F.hard && D[E] > u) {
323
+ const B = u - n, p = 1 + Math.floor((D[E] - B - 1) / u);
324
+ Math.floor((D[E] - 1) / u) < p && C.push(""), _(C, a, u);
325
+ continue;
326
+ }
327
+ if (n + D[E] > u && n > 0 && D[E] > 0) {
328
+ if (F.wordWrap === false && n < u) {
329
+ _(C, a, u);
330
+ continue;
331
+ }
332
+ C.push("");
333
+ }
334
+ if (n + D[E] > u && F.wordWrap === false) {
335
+ _(C, a, u);
336
+ continue;
337
+ }
338
+ C[C.length - 1] += a;
339
+ }
340
+ F.trim !== false && (C = C.map((E) => nD(E)));
341
+ const o = [...C.join(`
342
+ `)];
343
+ for (const [E, a] of o.entries()) {
344
+ if (e += a, v.has(a)) {
345
+ const { groups: B } = new RegExp(`(?:\\${W}(?<code>\\d+)m|\\${y}(?<uri>.*)${w})`).exec(o.slice(E).join("")) || { groups: {} };
346
+ if (B.code !== undefined) {
347
+ const p = Number.parseFloat(B.code);
348
+ s = p === CD ? undefined : p;
349
+ } else
350
+ B.uri !== undefined && (i = B.uri.length === 0 ? undefined : B.uri);
351
+ }
352
+ const n = iD.codes.get(Number(s));
353
+ o[E + 1] === `
354
+ ` ? (i && (e += z("")), s && n && (e += V(n))) : a === `
355
+ ` && (s && n && (e += V(s)), i && (e += z(i)));
356
+ }
357
+ return e;
358
+ };
359
+ function G(t, u, F) {
360
+ return String(t).normalize().replace(/\r\n/g, `
361
+ `).split(`
362
+ `).map((e) => oD(e, u, F)).join(`
363
+ `);
364
+ }
251
365
  var aD = ["up", "down", "left", "right", "space", "enter", "cancel"];
252
366
  var c = { actions: new Set(aD), aliases: new Map([["k", "up"], ["j", "down"], ["h", "left"], ["l", "right"], ["\x03", "cancel"], ["escape", "cancel"]]) };
253
367
  function k(t, u) {
@@ -258,8 +372,25 @@ function k(t, u) {
258
372
  return true;
259
373
  return false;
260
374
  }
375
+ function lD(t, u) {
376
+ if (t === u)
377
+ return;
378
+ const F = t.split(`
379
+ `), e = u.split(`
380
+ `), s = [];
381
+ for (let i = 0;i < Math.max(F.length, e.length); i++)
382
+ F[i] !== e[i] && s.push(i);
383
+ return s;
384
+ }
261
385
  var xD = globalThis.process.platform.startsWith("win");
262
386
  var S = Symbol("clack:cancel");
387
+ function BD(t) {
388
+ return t === S;
389
+ }
390
+ function d(t, u) {
391
+ const F = t;
392
+ F.isTTY && F.setRawMode(u);
393
+ }
263
394
  function cD({ input: t = $, output: u = j, overwrite: F = true, hideCursor: e = true } = {}) {
264
395
  const s = f.createInterface({ input: t, output: u, prompt: "", tabSize: 1 });
265
396
  f.emitKeypressEvents(t, s), t.isTTY && t.setRawMode(true);
@@ -282,9 +413,125 @@ function cD({ input: t = $, output: u = j, overwrite: F = true, hideCursor: e =
282
413
  t.off("keypress", i), e && u.write(import_sisteransi.cursor.show), t.isTTY && !xD && t.setRawMode(false), s.terminal = false, s.close();
283
414
  };
284
415
  }
416
+ var AD = Object.defineProperty;
417
+ var pD = (t, u, F) => (u in t) ? AD(t, u, { enumerable: true, configurable: true, writable: true, value: F }) : t[u] = F;
418
+ var h = (t, u, F) => (pD(t, typeof u != "symbol" ? u + "" : u, F), F);
419
+
420
+ class x {
421
+ constructor(u, F = true) {
422
+ h(this, "input"), h(this, "output"), h(this, "_abortSignal"), h(this, "rl"), h(this, "opts"), h(this, "_render"), h(this, "_track", false), h(this, "_prevFrame", ""), h(this, "_subscribers", new Map), h(this, "_cursor", 0), h(this, "state", "initial"), h(this, "error", ""), h(this, "value");
423
+ const { input: e = $, output: s = j, render: i, signal: D, ...C } = u;
424
+ this.opts = C, this.onKeypress = this.onKeypress.bind(this), this.close = this.close.bind(this), this.render = this.render.bind(this), this._render = i.bind(this), this._track = F, this._abortSignal = D, this.input = e, this.output = s;
425
+ }
426
+ unsubscribe() {
427
+ this._subscribers.clear();
428
+ }
429
+ setSubscriber(u, F) {
430
+ const e = this._subscribers.get(u) ?? [];
431
+ e.push(F), this._subscribers.set(u, e);
432
+ }
433
+ on(u, F) {
434
+ this.setSubscriber(u, { cb: F });
435
+ }
436
+ once(u, F) {
437
+ this.setSubscriber(u, { cb: F, once: true });
438
+ }
439
+ emit(u, ...F) {
440
+ const e = this._subscribers.get(u) ?? [], s = [];
441
+ for (const i of e)
442
+ i.cb(...F), i.once && s.push(() => e.splice(e.indexOf(i), 1));
443
+ for (const i of s)
444
+ i();
445
+ }
446
+ prompt() {
447
+ return new Promise((u, F) => {
448
+ if (this._abortSignal) {
449
+ if (this._abortSignal.aborted)
450
+ return this.state = "cancel", this.close(), u(S);
451
+ this._abortSignal.addEventListener("abort", () => {
452
+ this.state = "cancel", this.close();
453
+ }, { once: true });
454
+ }
455
+ const e = new U(0);
456
+ e._write = (s, i, D) => {
457
+ this._track && (this.value = this.rl?.line.replace(/\t/g, ""), this._cursor = this.rl?.cursor ?? 0, this.emit("value", this.value)), D();
458
+ }, this.input.pipe(e), this.rl = M.createInterface({ input: this.input, output: e, tabSize: 2, prompt: "", escapeCodeTimeout: 50 }), M.emitKeypressEvents(this.input, this.rl), this.rl.prompt(), this.opts.initialValue !== undefined && this._track && this.rl.write(this.opts.initialValue), this.input.on("keypress", this.onKeypress), d(this.input, true), this.output.on("resize", this.render), this.render(), this.once("submit", () => {
459
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), d(this.input, false), u(this.value);
460
+ }), this.once("cancel", () => {
461
+ this.output.write(import_sisteransi.cursor.show), this.output.off("resize", this.render), d(this.input, false), u(S);
462
+ });
463
+ });
464
+ }
465
+ onKeypress(u, F) {
466
+ if (this.state === "error" && (this.state = "active"), F?.name && (!this._track && c.aliases.has(F.name) && this.emit("cursor", c.aliases.get(F.name)), c.actions.has(F.name) && this.emit("cursor", F.name)), u && (u.toLowerCase() === "y" || u.toLowerCase() === "n") && this.emit("confirm", u.toLowerCase() === "y"), u === "\t" && this.opts.placeholder && (this.value || (this.rl?.write(this.opts.placeholder), this.emit("value", this.opts.placeholder))), u && this.emit("key", u.toLowerCase()), F?.name === "return") {
467
+ if (this.opts.validate) {
468
+ const e = this.opts.validate(this.value);
469
+ e && (this.error = e instanceof Error ? e.message : e, this.state = "error", this.rl?.write(this.value));
470
+ }
471
+ this.state !== "error" && (this.state = "submit");
472
+ }
473
+ k([u, F?.name, F?.sequence], "cancel") && (this.state = "cancel"), (this.state === "submit" || this.state === "cancel") && this.emit("finalize"), this.render(), (this.state === "submit" || this.state === "cancel") && this.close();
474
+ }
475
+ close() {
476
+ this.input.unpipe(), this.input.removeListener("keypress", this.onKeypress), this.output.write(`
477
+ `), d(this.input, false), this.rl?.close(), this.rl = undefined, this.emit(`${this.state}`, this.value), this.unsubscribe();
478
+ }
479
+ restoreCursor() {
480
+ const u = G(this._prevFrame, process.stdout.columns, { hard: true }).split(`
481
+ `).length - 1;
482
+ this.output.write(import_sisteransi.cursor.move(-999, u * -1));
483
+ }
484
+ render() {
485
+ const u = G(this._render(this) ?? "", process.stdout.columns, { hard: true });
486
+ if (u !== this._prevFrame) {
487
+ if (this.state === "initial")
488
+ this.output.write(import_sisteransi.cursor.hide);
489
+ else {
490
+ const F = lD(this._prevFrame, u);
491
+ if (this.restoreCursor(), F && F?.length === 1) {
492
+ const e = F[0];
493
+ this.output.write(import_sisteransi.cursor.move(0, e)), this.output.write(import_sisteransi.erase.lines(1));
494
+ const s = u.split(`
495
+ `);
496
+ this.output.write(s[e]), this._prevFrame = u, this.output.write(import_sisteransi.cursor.move(0, s.length - e - 1));
497
+ return;
498
+ }
499
+ if (F && F?.length > 1) {
500
+ const e = F[0];
501
+ this.output.write(import_sisteransi.cursor.move(0, e)), this.output.write(import_sisteransi.erase.down());
502
+ const s = u.split(`
503
+ `).slice(e);
504
+ this.output.write(s.join(`
505
+ `)), this._prevFrame = u;
506
+ return;
507
+ }
508
+ this.output.write(import_sisteransi.erase.down());
509
+ }
510
+ this.output.write(u), this.state === "initial" && (this.state = "active"), this._prevFrame = u;
511
+ }
512
+ }
513
+ }
514
+ class PD extends x {
515
+ get valueWithCursor() {
516
+ if (this.state === "submit")
517
+ return this.value;
518
+ if (this.cursor >= this.value.length)
519
+ return `${this.value}\u2588`;
520
+ const u = this.value.slice(0, this.cursor), [F, ...e] = this.value.slice(this.cursor);
521
+ return `${u}${import_picocolors.default.inverse(F)}${e.join("")}`;
522
+ }
523
+ get cursor() {
524
+ return this._cursor;
525
+ }
526
+ constructor(u) {
527
+ super(u), this.on("finalize", () => {
528
+ this.value || (this.value = u.defaultValue);
529
+ });
530
+ }
531
+ }
285
532
 
286
533
  // ../../node_modules/.bun/@clack+prompts@0.9.1/node_modules/@clack/prompts/dist/index.mjs
287
- var import_picocolors = __toESM(require_picocolors(), 1);
534
+ var import_picocolors2 = __toESM(require_picocolors(), 1);
288
535
  var import_sisteransi2 = __toESM(require_src(), 1);
289
536
  import p from "process";
290
537
  function X2() {
@@ -293,17 +540,17 @@ function X2() {
293
540
  var E = X2();
294
541
  var u = (s, n) => E ? s : n;
295
542
  var ee = u("\u25C6", "*");
296
- var A = u("\u25A0", "x");
543
+ var A2 = u("\u25A0", "x");
297
544
  var B = u("\u25B2", "x");
298
545
  var S2 = u("\u25C7", "o");
299
546
  var te = u("\u250C", "T");
300
547
  var a = u("\u2502", "|");
301
548
  var m2 = u("\u2514", "\u2014");
302
549
  var j2 = u("\u25CF", ">");
303
- var R = u("\u25CB", " ");
304
- var V = u("\u25FB", "[\u2022]");
305
- var M = u("\u25FC", "[+]");
306
- var G = u("\u25FB", "[ ]");
550
+ var R2 = u("\u25CB", " ");
551
+ var V2 = u("\u25FB", "[\u2022]");
552
+ var M2 = u("\u25FC", "[+]");
553
+ var G2 = u("\u25FB", "[ ]");
307
554
  var se = u("\u25AA", "\u2022");
308
555
  var N2 = u("\u2500", "-");
309
556
  var re = u("\u256E", "+");
@@ -313,76 +560,125 @@ var ae = u("\u25CF", "\u2022");
313
560
  var oe = u("\u25C6", "*");
314
561
  var ce = u("\u25B2", "!");
315
562
  var le = u("\u25A0", "x");
563
+ var y2 = (s) => {
564
+ switch (s) {
565
+ case "initial":
566
+ case "active":
567
+ return import_picocolors2.default.cyan(ee);
568
+ case "cancel":
569
+ return import_picocolors2.default.red(A2);
570
+ case "error":
571
+ return import_picocolors2.default.yellow(B);
572
+ case "submit":
573
+ return import_picocolors2.default.green(S2);
574
+ }
575
+ };
576
+ var ue = (s) => new PD({ validate: s.validate, placeholder: s.placeholder, defaultValue: s.defaultValue, initialValue: s.initialValue, render() {
577
+ const n = `${import_picocolors2.default.gray(a)}
578
+ ${y2(this.state)} ${s.message}
579
+ `, t = s.placeholder ? import_picocolors2.default.inverse(s.placeholder[0]) + import_picocolors2.default.dim(s.placeholder.slice(1)) : import_picocolors2.default.inverse(import_picocolors2.default.hidden("_")), i = this.value ? this.valueWithCursor : t;
580
+ switch (this.state) {
581
+ case "error":
582
+ return `${n.trim()}
583
+ ${import_picocolors2.default.yellow(a)} ${i}
584
+ ${import_picocolors2.default.yellow(m2)} ${import_picocolors2.default.yellow(this.error)}
585
+ `;
586
+ case "submit":
587
+ return `${n}${import_picocolors2.default.gray(a)} ${import_picocolors2.default.dim(this.value || s.placeholder)}`;
588
+ case "cancel":
589
+ return `${n}${import_picocolors2.default.gray(a)} ${import_picocolors2.default.strikethrough(import_picocolors2.default.dim(this.value ?? ""))}${this.value?.trim() ? `
590
+ ${import_picocolors2.default.gray(a)}` : ""}`;
591
+ default:
592
+ return `${n}${import_picocolors2.default.cyan(a)} ${i}
593
+ ${import_picocolors2.default.cyan(m2)}
594
+ `;
595
+ }
596
+ } }).prompt();
597
+ var ye = (s = "", n = "") => {
598
+ const t = `
599
+ ${s}
600
+ `.split(`
601
+ `), i = T2(n).length, r2 = Math.max(t.reduce((o, l2) => {
602
+ const $2 = T2(l2);
603
+ return $2.length > o ? $2.length : o;
604
+ }, 0), i) + 2, c2 = t.map((o) => `${import_picocolors2.default.gray(a)} ${import_picocolors2.default.dim(o)}${" ".repeat(r2 - T2(o).length)}${import_picocolors2.default.gray(a)}`).join(`
605
+ `);
606
+ process.stdout.write(`${import_picocolors2.default.gray(a)}
607
+ ${import_picocolors2.default.green(S2)} ${import_picocolors2.default.reset(n)} ${import_picocolors2.default.gray(N2.repeat(Math.max(r2 - i - 1, 1)) + re)}
608
+ ${c2}
609
+ ${import_picocolors2.default.gray(ie + N2.repeat(r2 + 2) + ne)}
610
+ `);
611
+ };
316
612
  var we = (s = "") => {
317
- process.stdout.write(`${import_picocolors.default.gray(te)} ${s}
613
+ process.stdout.write(`${import_picocolors2.default.gray(te)} ${s}
318
614
  `);
319
615
  };
320
616
  var fe = (s = "") => {
321
- process.stdout.write(`${import_picocolors.default.gray(a)}
322
- ${import_picocolors.default.gray(m2)} ${s}
617
+ process.stdout.write(`${import_picocolors2.default.gray(a)}
618
+ ${import_picocolors2.default.gray(m2)} ${s}
323
619
 
324
620
  `);
325
621
  };
326
- var v2 = { message: (s = "", { symbol: n = import_picocolors.default.gray(a) } = {}) => {
327
- const t = [`${import_picocolors.default.gray(a)}`];
622
+ var v2 = { message: (s = "", { symbol: n = import_picocolors2.default.gray(a) } = {}) => {
623
+ const t = [`${import_picocolors2.default.gray(a)}`];
328
624
  if (s) {
329
625
  const [i, ...r2] = s.split(`
330
626
  `);
331
- t.push(`${n} ${i}`, ...r2.map((c2) => `${import_picocolors.default.gray(a)} ${c2}`));
627
+ t.push(`${n} ${i}`, ...r2.map((c2) => `${import_picocolors2.default.gray(a)} ${c2}`));
332
628
  }
333
629
  process.stdout.write(`${t.join(`
334
630
  `)}
335
631
  `);
336
632
  }, info: (s) => {
337
- v2.message(s, { symbol: import_picocolors.default.blue(ae) });
633
+ v2.message(s, { symbol: import_picocolors2.default.blue(ae) });
338
634
  }, success: (s) => {
339
- v2.message(s, { symbol: import_picocolors.default.green(oe) });
635
+ v2.message(s, { symbol: import_picocolors2.default.green(oe) });
340
636
  }, step: (s) => {
341
- v2.message(s, { symbol: import_picocolors.default.green(S2) });
637
+ v2.message(s, { symbol: import_picocolors2.default.green(S2) });
342
638
  }, warn: (s) => {
343
- v2.message(s, { symbol: import_picocolors.default.yellow(ce) });
639
+ v2.message(s, { symbol: import_picocolors2.default.yellow(ce) });
344
640
  }, warning: (s) => {
345
641
  v2.warn(s);
346
642
  }, error: (s) => {
347
- v2.message(s, { symbol: import_picocolors.default.red(le) });
643
+ v2.message(s, { symbol: import_picocolors2.default.red(le) });
348
644
  } };
349
645
  var L2 = () => {
350
646
  const s = E ? ["\u25D2", "\u25D0", "\u25D3", "\u25D1"] : ["\u2022", "o", "O", "0"], n = E ? 80 : 120, t = process.env.CI === "true";
351
647
  let i, r2, c2 = false, o = "", l2;
352
- const $2 = (h) => {
353
- const g = h > 1 ? "Something went wrong" : "Canceled";
354
- c2 && P2(g, h);
355
- }, d = () => $2(2), w = () => $2(1), b2 = () => {
356
- process.on("uncaughtExceptionMonitor", d), process.on("unhandledRejection", d), process.on("SIGINT", w), process.on("SIGTERM", w), process.on("exit", $2);
648
+ const $2 = (h2) => {
649
+ const g2 = h2 > 1 ? "Something went wrong" : "Canceled";
650
+ c2 && P2(g2, h2);
651
+ }, d2 = () => $2(2), w2 = () => $2(1), b2 = () => {
652
+ process.on("uncaughtExceptionMonitor", d2), process.on("unhandledRejection", d2), process.on("SIGINT", w2), process.on("SIGTERM", w2), process.on("exit", $2);
357
653
  }, C = () => {
358
- process.removeListener("uncaughtExceptionMonitor", d), process.removeListener("unhandledRejection", d), process.removeListener("SIGINT", w), process.removeListener("SIGTERM", w), process.removeListener("exit", $2);
654
+ process.removeListener("uncaughtExceptionMonitor", d2), process.removeListener("unhandledRejection", d2), process.removeListener("SIGINT", w2), process.removeListener("SIGTERM", w2), process.removeListener("exit", $2);
359
655
  }, I2 = () => {
360
656
  if (l2 === undefined)
361
657
  return;
362
658
  t && process.stdout.write(`
363
659
  `);
364
- const h = l2.split(`
660
+ const h2 = l2.split(`
365
661
  `);
366
- process.stdout.write(import_sisteransi2.cursor.move(-999, h.length - 1)), process.stdout.write(import_sisteransi2.erase.down(h.length));
367
- }, x = (h) => h.replace(/\.+$/, ""), O2 = (h = "") => {
368
- c2 = true, i = cD(), o = x(h), process.stdout.write(`${import_picocolors.default.gray(a)}
662
+ process.stdout.write(import_sisteransi2.cursor.move(-999, h2.length - 1)), process.stdout.write(import_sisteransi2.erase.down(h2.length));
663
+ }, x2 = (h2) => h2.replace(/\.+$/, ""), O2 = (h2 = "") => {
664
+ c2 = true, i = cD(), o = x2(h2), process.stdout.write(`${import_picocolors2.default.gray(a)}
369
665
  `);
370
- let g = 0, f2 = 0;
666
+ let g2 = 0, f2 = 0;
371
667
  b2(), r2 = setInterval(() => {
372
668
  if (t && o === l2)
373
669
  return;
374
670
  I2(), l2 = o;
375
- const W = import_picocolors.default.magenta(s[g]), _ = t ? "..." : ".".repeat(Math.floor(f2)).slice(0, 3);
376
- process.stdout.write(`${W} ${o}${_}`), g = g + 1 < s.length ? g + 1 : 0, f2 = f2 < s.length ? f2 + 0.125 : 0;
671
+ const W2 = import_picocolors2.default.magenta(s[g2]), _2 = t ? "..." : ".".repeat(Math.floor(f2)).slice(0, 3);
672
+ process.stdout.write(`${W2} ${o}${_2}`), g2 = g2 + 1 < s.length ? g2 + 1 : 0, f2 = f2 < s.length ? f2 + 0.125 : 0;
377
673
  }, n);
378
- }, P2 = (h = "", g = 0) => {
674
+ }, P2 = (h2 = "", g2 = 0) => {
379
675
  c2 = false, clearInterval(r2), I2();
380
- const f2 = g === 0 ? import_picocolors.default.green(S2) : g === 1 ? import_picocolors.default.red(A) : import_picocolors.default.red(B);
381
- o = x(h ?? o), process.stdout.write(`${f2} ${o}
676
+ const f2 = g2 === 0 ? import_picocolors2.default.green(S2) : g2 === 1 ? import_picocolors2.default.red(A2) : import_picocolors2.default.red(B);
677
+ o = x2(h2 ?? o), process.stdout.write(`${f2} ${o}
382
678
  `), C(), i();
383
679
  };
384
- return { start: O2, stop: P2, message: (h = "") => {
385
- o = x(h ?? o);
680
+ return { start: O2, stop: P2, message: (h2 = "") => {
681
+ o = x2(h2 ?? o);
386
682
  } };
387
683
  };
388
684
 
@@ -2428,8 +2724,8 @@ class SQLiteDialect {
2428
2724
  if (!queries?.length)
2429
2725
  return;
2430
2726
  const withSqlChunks = [sql`with `];
2431
- for (const [i, w] of queries.entries()) {
2432
- withSqlChunks.push(sql`${sql.identifier(w._.alias)} as (${w._.sql})`);
2727
+ for (const [i, w2] of queries.entries()) {
2728
+ withSqlChunks.push(sql`${sql.identifier(w2._.alias)} as (${w2._.sql})`);
2433
2729
  if (i < queries.length - 1) {
2434
2730
  withSqlChunks.push(sql`, `);
2435
2731
  }
@@ -2647,7 +2943,7 @@ class SQLiteDialect {
2647
2943
  buildInsertQuery({ table, values: valuesOrSelect, onConflict, returning, withList, select }) {
2648
2944
  const valuesSqlList = [];
2649
2945
  const columns = table[Table.Symbol.Columns];
2650
- const colEntries = Object.entries(columns).filter(([_, col]) => !col.shouldDisableInsert());
2946
+ const colEntries = Object.entries(columns).filter(([_2, col]) => !col.shouldDisableInsert());
2651
2947
  const insertOrder = colEntries.map(([, column]) => sql.identifier(this.casing.getColumnCasing(column)));
2652
2948
  if (select) {
2653
2949
  const select2 = valuesOrSelect;
@@ -4135,143 +4431,6 @@ function formatCurrency(amount) {
4135
4431
  const sign = amount < 0 ? "-" : "";
4136
4432
  return `${sign}$${Math.abs(amount).toFixed(2)}`;
4137
4433
  }
4138
- function formatProgressBar(spent, initial) {
4139
- if (initial === 0)
4140
- return "\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591\u2591";
4141
- const percentage = spent / initial * 100;
4142
- const filledCount = Math.min(20, Math.max(0, Math.round(percentage / 100 * 20)));
4143
- const emptyCount = 20 - filledCount;
4144
- return "\u2588".repeat(filledCount) + "\u2591".repeat(emptyCount);
4145
- }
4146
- function formatBalanceTable(wallets2) {
4147
- if (wallets2.length === 0) {
4148
- return "No wallets configured. Run: ai-ledger setup";
4149
- }
4150
- const header = ["Provider", "Balance", "Spent", "Progress"];
4151
- const rows = [];
4152
- for (const wallet of wallets2) {
4153
- const spent = wallet.initial_balance - wallet.balance;
4154
- const progressBar = formatProgressBar(spent, wallet.initial_balance);
4155
- rows.push([
4156
- wallet.name,
4157
- formatCurrency(wallet.balance),
4158
- formatCurrency(spent),
4159
- progressBar
4160
- ]);
4161
- }
4162
- const colWidths = header.map((h, i) => {
4163
- const maxContentWidth = Math.max(h.length, ...rows.map((row) => row[i]?.length || 0));
4164
- return maxContentWidth + 2;
4165
- });
4166
- let table = "\u250C";
4167
- for (let i = 0;i < header.length; i++) {
4168
- table += "\u2500".repeat(colWidths[i] ?? 0);
4169
- if (i < header.length - 1)
4170
- table += "\u252C";
4171
- }
4172
- table += `\u2510
4173
- `;
4174
- table += "\u2502";
4175
- for (let i = 0;i < header.length; i++) {
4176
- const padding = " ".repeat(Math.floor(((colWidths[i] ?? 0) - (header[i]?.length || 0)) / 2));
4177
- table += padding + (header[i] || "") + padding;
4178
- if ((colWidths[i] ?? 0) - (header[i]?.length || 0) - padding.length * 2 > 0) {
4179
- table += " ";
4180
- }
4181
- table += "\u2502";
4182
- }
4183
- table += `
4184
- `;
4185
- table += "\u251C";
4186
- for (let i = 0;i < header.length; i++) {
4187
- table += "\u2500".repeat(colWidths[i] ?? 0);
4188
- if (i < header.length - 1)
4189
- table += "\u253C";
4190
- }
4191
- table += `\u2524
4192
- `;
4193
- for (const row of rows) {
4194
- table += "\u2502";
4195
- for (let i = 0;i < row.length; i++) {
4196
- const cell = row[i] || "";
4197
- table += " " + cell.padEnd((colWidths[i] ?? 0) - 1);
4198
- table += "\u2502";
4199
- }
4200
- table += `
4201
- `;
4202
- }
4203
- table += "\u2514";
4204
- for (let i = 0;i < header.length; i++) {
4205
- table += "\u2500".repeat(colWidths[i] ?? 0);
4206
- if (i < header.length - 1)
4207
- table += "\u2534";
4208
- }
4209
- table += "\u2518";
4210
- return table;
4211
- }
4212
- function formatTransactionHistory(txs) {
4213
- if (txs.length === 0) {
4214
- return "No transactions recorded yet.";
4215
- }
4216
- const header = ["Date", "Provider", "Model", "Cost", "Tokens In", "Tokens Out"];
4217
- const rows = txs.map((tx) => [
4218
- new Date(tx.created_at).toLocaleString(),
4219
- tx.provider,
4220
- tx.model,
4221
- formatCurrency(tx.cost),
4222
- tx.input_tokens?.toString() ?? "-",
4223
- tx.output_tokens?.toString() ?? "-"
4224
- ]);
4225
- const colWidths = header.map((h, i) => {
4226
- const maxContentWidth = Math.max(h.length, ...rows.map((row) => row[i]?.length || 0));
4227
- return maxContentWidth + 2;
4228
- });
4229
- let table = "\u250C";
4230
- for (let i = 0;i < header.length; i++) {
4231
- table += "\u2500".repeat(colWidths[i] ?? 0);
4232
- if (i < header.length - 1)
4233
- table += "\u252C";
4234
- }
4235
- table += `\u2510
4236
- `;
4237
- table += "\u2502";
4238
- for (let i = 0;i < header.length; i++) {
4239
- const padding = " ".repeat(Math.floor(((colWidths[i] ?? 0) - (header[i]?.length || 0)) / 2));
4240
- table += padding + (header[i] || "") + padding;
4241
- if ((colWidths[i] ?? 0) - (header[i]?.length || 0) - padding.length * 2 > 0) {
4242
- table += " ";
4243
- }
4244
- table += "\u2502";
4245
- }
4246
- table += `
4247
- `;
4248
- table += "\u251C";
4249
- for (let i = 0;i < header.length; i++) {
4250
- table += "\u2500".repeat(colWidths[i] ?? 0);
4251
- if (i < header.length - 1)
4252
- table += "\u253C";
4253
- }
4254
- table += `\u2524
4255
- `;
4256
- for (const row of rows) {
4257
- table += "\u2502";
4258
- for (let i = 0;i < row.length; i++) {
4259
- const cell = row[i] || "";
4260
- table += " " + cell.padEnd((colWidths[i] ?? 0) - 1);
4261
- table += "\u2502";
4262
- }
4263
- table += `
4264
- `;
4265
- }
4266
- table += "\u2514";
4267
- for (let i = 0;i < header.length; i++) {
4268
- table += "\u2500".repeat(colWidths[i] ?? 0);
4269
- if (i < header.length - 1)
4270
- table += "\u2534";
4271
- }
4272
- table += "\u2518";
4273
- return table;
4274
- }
4275
4434
 
4276
4435
  // lib/providers.ts
4277
4436
  var PROVIDER_ENV = {
@@ -4285,7 +4444,7 @@ var PROVIDER_ENV = {
4285
4444
  minimax: { envVar: "MINIMAX_API_KEY", name: "MiniMax", currency: "USD" }
4286
4445
  };
4287
4446
  function detectProviders() {
4288
- return Object.entries(PROVIDER_ENV).filter(([_, { envVar }]) => !!process.env[envVar]).map(([id]) => id);
4447
+ return Object.entries(PROVIDER_ENV).filter(([_2, { envVar }]) => !!process.env[envVar]).map(([id]) => id);
4289
4448
  }
4290
4449
  function getProviderName(providerId) {
4291
4450
  return PROVIDER_ENV[providerId]?.name || providerId;
@@ -4295,6 +4454,87 @@ function getProviderCurrency(providerId) {
4295
4454
  }
4296
4455
 
4297
4456
  // cli.ts
4457
+ var R3 = "\x1B[0m";
4458
+ var bold = (s) => `\x1B[1m${s}${R3}`;
4459
+ var dim = (s) => `\x1B[2m${s}${R3}`;
4460
+ var green = (s) => `\x1B[32m${s}${R3}`;
4461
+ var yellow = (s) => `\x1B[33m${s}${R3}`;
4462
+ var red = (s) => `\x1B[31m${s}${R3}`;
4463
+ var cyan = (s) => `\x1B[36m${s}${R3}`;
4464
+ var gray = (s) => `\x1B[90m${s}${R3}`;
4465
+ function colorBalance(balance, initial) {
4466
+ const ratio = initial > 0 ? balance / initial : 1;
4467
+ const str = formatCurrency(balance);
4468
+ if (balance < 0)
4469
+ return bold(red(str));
4470
+ if (ratio < 0.1)
4471
+ return bold(yellow(str));
4472
+ return bold(green(str));
4473
+ }
4474
+ function colorBar(spent, initial, width = 20) {
4475
+ if (initial <= 0)
4476
+ return gray("\u2591".repeat(width));
4477
+ const filled = Math.min(width, Math.max(0, Math.round(spent / initial * width)));
4478
+ const empty = width - filled;
4479
+ const bar = "\u2588".repeat(filled) + "\u2591".repeat(empty);
4480
+ const pct = Math.min(100, Math.round(spent / initial * 100));
4481
+ if (pct > 90)
4482
+ return red(bar);
4483
+ if (pct > 70)
4484
+ return yellow(bar);
4485
+ return green(bar);
4486
+ }
4487
+ function printBalanceTable(wallets2) {
4488
+ if (wallets2.length === 0) {
4489
+ v2.warn("No wallets configured. Run: " + cyan("ai-ledger setup"));
4490
+ return;
4491
+ }
4492
+ const rows = wallets2.map((w2) => {
4493
+ const spent = w2.initial_balance - w2.balance;
4494
+ const pct = w2.initial_balance > 0 ? Math.min(100, Math.round(spent / w2.initial_balance * 100)) : 0;
4495
+ const bar = colorBar(spent, w2.initial_balance);
4496
+ return {
4497
+ name: w2.name,
4498
+ balance: colorBalance(w2.balance, w2.initial_balance),
4499
+ spent: dim(formatCurrency(spent)),
4500
+ bar,
4501
+ pct: dim(`${pct}%`)
4502
+ };
4503
+ });
4504
+ const nameW = Math.max(8, ...wallets2.map((w2) => w2.name.length)) + 2;
4505
+ const sep = gray("\u2500".repeat(nameW + 44));
4506
+ console.log();
4507
+ console.log(` ${bold(cyan("Provider".padEnd(nameW)))}${bold(cyan("Balance".padStart(10)))} ${bold(cyan("Spent".padStart(8)))} ${bold(cyan("Usage"))}`);
4508
+ console.log(` ${sep}`);
4509
+ for (const r2 of rows) {
4510
+ const rawBalance = r2.balance.replace(/\x1b\[[0-9;]*m/g, "");
4511
+ const rawSpent = r2.spent.replace(/\x1b\[[0-9;]*m/g, "");
4512
+ const balPad = 10 + (r2.balance.length - rawBalance.length);
4513
+ const spentPad = 8 + (r2.spent.length - rawSpent.length);
4514
+ console.log(` ${r2.name.padEnd(nameW)}${r2.balance.padStart(balPad)} ${r2.spent.padStart(spentPad)} ${r2.bar} ${r2.pct}`);
4515
+ }
4516
+ console.log();
4517
+ }
4518
+ function printHistoryTable(txs) {
4519
+ if (txs.length === 0) {
4520
+ v2.warn("No transactions recorded yet.");
4521
+ return;
4522
+ }
4523
+ console.log();
4524
+ const header = ` ${bold(cyan("Date".padEnd(22)))}${bold(cyan("Provider".padEnd(14)))}${bold(cyan("Model".padEnd(22)))}${bold(cyan("Cost".padStart(8)))} ${bold(cyan("In".padStart(8)))} ${bold(cyan("Out".padStart(8)))}`;
4525
+ console.log(header);
4526
+ console.log(` ${gray("\u2500".repeat(90))}`);
4527
+ for (const tx of txs) {
4528
+ const date = dim(new Date(tx.created_at).toLocaleString().padEnd(22));
4529
+ const provider = tx.provider.padEnd(14);
4530
+ const model = dim(tx.model.padEnd(22));
4531
+ const cost = yellow(formatCurrency(tx.cost).padStart(8));
4532
+ const inTok = gray((tx.input_tokens?.toString() ?? "-").padStart(8));
4533
+ const outTok = gray((tx.output_tokens?.toString() ?? "-").padStart(8));
4534
+ console.log(` ${date}${provider}${model}${cost} ${inTok} ${outTok}`);
4535
+ }
4536
+ console.log();
4537
+ }
4298
4538
  function expandHome(p2) {
4299
4539
  if (p2.startsWith("~"))
4300
4540
  return path2.join(os2.homedir(), p2.slice(1));
@@ -4316,13 +4556,10 @@ async function detectProvidersFromOpenCode() {
4316
4556
  return detectProviders();
4317
4557
  }
4318
4558
  function getProviderInfo(id) {
4319
- return {
4320
- name: getProviderName(id),
4321
- currency: getProviderCurrency(id)
4322
- };
4559
+ return { name: getProviderName(id), currency: getProviderCurrency(id) };
4323
4560
  }
4324
4561
  async function cmdSetup() {
4325
- we("ai-ledger setup");
4562
+ we(bold("ai-ledger") + " " + dim("balance tracker for OpenCode"));
4326
4563
  const s = L2();
4327
4564
  s.start("Detecting AI providers\u2026");
4328
4565
  let providers;
@@ -4331,10 +4568,10 @@ async function cmdSetup() {
4331
4568
  } catch {
4332
4569
  providers = detectProviders();
4333
4570
  }
4334
- s.stop(providers.length > 0 ? `Found ${providers.length} provider(s): ${providers.join(", ")}` : "No providers detected");
4571
+ s.stop(providers.length > 0 ? green(`\u2713`) + ` Found ${bold(String(providers.length))} provider(s): ${providers.map((p2) => cyan(p2)).join(", ")}` : "No providers detected");
4335
4572
  if (providers.length === 0) {
4336
4573
  v2.warn("Set at least one API key (OPENAI_API_KEY, ANTHROPIC_API_KEY, \u2026) and re-run setup.");
4337
- fe("Setup incomplete");
4574
+ fe(red("Setup incomplete"));
4338
4575
  return;
4339
4576
  }
4340
4577
  await initializeDatabase();
@@ -4343,7 +4580,33 @@ async function cmdSetup() {
4343
4580
  const { name, currency } = getProviderInfo(id);
4344
4581
  await upsertWallet({ id, name, currency });
4345
4582
  }
4346
- s.stop("Wallets ready");
4583
+ s.stop(green("\u2713") + " Wallets created");
4584
+ ye(providers.map((p2) => ` ${cyan(p2.padEnd(20))} ${dim("\u2192 set balance below")}`).join(`
4585
+ `), "Set initial balances");
4586
+ for (const id of providers) {
4587
+ const name = getProviderName(id);
4588
+ const result = await ue({
4589
+ message: `${bold(name)} balance (USD):`,
4590
+ placeholder: "0.00 \u2014 press Enter to skip",
4591
+ validate: (v3) => {
4592
+ if (!v3.trim())
4593
+ return;
4594
+ if (isNaN(parseFloat(v3)) || parseFloat(v3) < 0)
4595
+ return "Enter a positive number";
4596
+ }
4597
+ });
4598
+ if (BD(result)) {
4599
+ fe(yellow("Cancelled"));
4600
+ process.exit(0);
4601
+ }
4602
+ const amount = parseFloat(result.trim());
4603
+ if (!isNaN(amount) && amount > 0) {
4604
+ await setWalletBalance(id, amount);
4605
+ v2.success(`${name}: ${bold(green("$" + amount.toFixed(2)))}`);
4606
+ } else {
4607
+ v2.info(`${name}: skipped ${dim("\u2014 ai-ledger set " + id + " <amount>")}`);
4608
+ }
4609
+ }
4347
4610
  const configPath = expandHome("~/.config/opencode/opencode.json");
4348
4611
  if (fs2.existsSync(configPath)) {
4349
4612
  s.start("Registering plugin in opencode.json\u2026");
@@ -4352,84 +4615,92 @@ async function cmdSetup() {
4352
4615
  const existing = config.plugin ?? [];
4353
4616
  config.plugin = [...new Set([...existing, "@kapishdima/ai-ledger"])];
4354
4617
  fs2.writeFileSync(configPath, JSON.stringify(config, null, 2));
4355
- s.stop("Plugin registered in opencode.json");
4618
+ s.stop(green("\u2713") + " Plugin registered in opencode.json");
4356
4619
  } catch (err) {
4357
- s.stop(`Could not update opencode.json: ${err.message}`);
4620
+ s.stop(yellow("\u26A0") + ` Could not update opencode.json: ${err.message}`);
4358
4621
  }
4359
4622
  } else {
4360
- v2.warn(`opencode.json not found at ${configPath}. Add "@kapishdima/ai-ledger" to the plugin array manually.`);
4623
+ v2.warn(`opencode.json not found. Add ${cyan('"@kapishdima/ai-ledger"')} to the plugin array manually.`);
4361
4624
  }
4362
- v2.info(`Set initial balances with: ai-ledger set <provider> <amount>`);
4363
- fe("Setup complete!");
4625
+ fe(green("\u2713") + " " + bold("Setup complete!") + " Restart OpenCode to activate the plugin.");
4364
4626
  }
4365
4627
  async function cmdBalance() {
4366
4628
  await initializeDatabase();
4367
4629
  const wallets2 = await getAllWallets();
4368
- console.log(formatBalanceTable(wallets2));
4630
+ printBalanceTable(wallets2);
4369
4631
  }
4370
4632
  async function cmdSet(provider, amount) {
4371
4633
  if (!provider) {
4372
- console.error("Usage: ai-ledger set <provider> <amount>");
4634
+ v2.error("Usage: " + cyan("ai-ledger set <provider> <amount>"));
4373
4635
  process.exit(1);
4374
4636
  }
4375
4637
  if (isNaN(amount) || amount < 0) {
4376
- console.error("Amount must be a non-negative number");
4638
+ v2.error("Amount must be a non-negative number");
4377
4639
  process.exit(1);
4378
4640
  }
4379
4641
  await initializeDatabase();
4380
- const existing = await getWallet(provider);
4381
- if (!existing) {
4382
- const { name, currency } = getProviderInfo(provider);
4383
- await upsertWallet({ id: provider, name, currency });
4642
+ const allWallets = await getAllWallets();
4643
+ const known = allWallets.find((w2) => w2.id === provider);
4644
+ if (!known) {
4645
+ v2.error(`Provider ${bold(red(provider))} not found.`);
4646
+ if (allWallets.length > 0) {
4647
+ v2.info(`Known providers: ${allWallets.map((w2) => cyan(w2.id)).join(", ")}`);
4648
+ } else {
4649
+ v2.info(`No providers configured. Run: ${cyan("ai-ledger setup")}`);
4650
+ }
4651
+ process.exit(1);
4384
4652
  }
4385
4653
  await setWalletBalance(provider, amount);
4386
- console.log(`${getProviderName(provider)}: balance set to ${formatCurrency(amount)}`);
4654
+ v2.success(`${bold(known.name)}: balance set to ${bold(green(formatCurrency(amount)))}`);
4387
4655
  }
4388
4656
  async function cmdAdd(provider, amount) {
4389
4657
  if (!provider) {
4390
- console.error("Usage: ai-ledger add <provider> <amount>");
4658
+ v2.error("Usage: " + cyan("ai-ledger add <provider> <amount>"));
4391
4659
  process.exit(1);
4392
4660
  }
4393
4661
  if (isNaN(amount) || amount <= 0) {
4394
- console.error("Amount must be a positive number");
4662
+ v2.error("Amount must be a positive number");
4395
4663
  process.exit(1);
4396
4664
  }
4397
4665
  await initializeDatabase();
4398
4666
  const wallet = await getWallet(provider);
4399
4667
  if (!wallet) {
4400
- const { name, currency } = getProviderInfo(provider);
4401
- await upsertWallet({ id: provider, name, currency });
4402
- await setWalletBalance(provider, amount);
4403
- console.log(`${getProviderName(provider)}: created with balance ${formatCurrency(amount)}`);
4404
- } else {
4405
- const newBalance = await addBalance(provider, amount);
4406
- console.log(`${getProviderName(provider)}: ${formatCurrency(amount)} added \u2192 ${formatCurrency(newBalance)}`);
4668
+ const allWallets = await getAllWallets();
4669
+ v2.error(`Provider ${bold(red(provider))} not found.`);
4670
+ if (allWallets.length > 0) {
4671
+ v2.info(`Known providers: ${allWallets.map((w2) => cyan(w2.id)).join(", ")}`);
4672
+ } else {
4673
+ v2.info(`No providers configured. Run: ${cyan("ai-ledger setup")}`);
4674
+ }
4675
+ process.exit(1);
4407
4676
  }
4677
+ const newBalance = await addBalance(provider, amount);
4678
+ v2.success(`${bold(wallet.name)}: ${bold(green("+" + formatCurrency(amount)))} \u2192 ${bold(green(formatCurrency(newBalance)))}`);
4408
4679
  }
4409
4680
  async function cmdHistory(limit = 50) {
4410
4681
  await initializeDatabase();
4411
4682
  const txs = await getAllTransactions(limit);
4412
- console.log(formatTransactionHistory(txs));
4683
+ printHistoryTable(txs);
4413
4684
  }
4414
4685
  function cmdHelp() {
4415
- console.log(`
4416
- ai-ledger \u2014 AI provider balance tracker for OpenCode
4417
-
4418
- Commands:
4419
- setup Detect providers, create wallets, register plugin
4420
- balance Show current balances with progress bars
4421
- set <provider> <amt> Set (reset) wallet balance
4422
- add <provider> <amt> Add funds to a wallet
4423
- history [limit] Show recent transactions (default: 50)
4424
- help Show this help
4425
-
4426
- Examples:
4427
- ai-ledger setup
4428
- ai-ledger balance
4429
- ai-ledger set anthropic 20
4430
- ai-ledger add openai 10
4431
- ai-ledger history 20
4432
- `.trim());
4686
+ console.log();
4687
+ console.log(` ${bold(cyan("ai-ledger"))} ${dim("\u2014 AI provider balance tracker for OpenCode")}`);
4688
+ console.log();
4689
+ console.log(` ${bold("Commands:")}`);
4690
+ console.log(` ${cyan("setup")} Detect providers, set balances, register plugin`);
4691
+ console.log(` ${cyan("balance")} Show current balances with progress bars`);
4692
+ console.log(` ${cyan("set")} ${dim("<provider> <amt>")} Reset wallet balance`);
4693
+ console.log(` ${cyan("add")} ${dim("<provider> <amt>")} Add funds to a wallet`);
4694
+ console.log(` ${cyan("history")} ${dim("[limit]")} Show recent transactions (default: 50)`);
4695
+ console.log(` ${cyan("help")} Show this help`);
4696
+ console.log();
4697
+ console.log(` ${bold("Examples:")}`);
4698
+ console.log(` ${dim("$")} ai-ledger setup`);
4699
+ console.log(` ${dim("$")} ai-ledger balance`);
4700
+ console.log(` ${dim("$")} ai-ledger set anthropic 20`);
4701
+ console.log(` ${dim("$")} ai-ledger add openai 10`);
4702
+ console.log(` ${dim("$")} ai-ledger history 20`);
4703
+ console.log();
4433
4704
  }
4434
4705
  var args = process.argv.slice(2);
4435
4706
  var cmd = args[0];
@@ -4456,7 +4727,7 @@ switch (cmd) {
4456
4727
  cmdHelp();
4457
4728
  break;
4458
4729
  default:
4459
- console.error(`Unknown command: ${cmd}`);
4730
+ v2.error(`Unknown command: ${bold(cmd ?? "")}`);
4460
4731
  cmdHelp();
4461
4732
  process.exit(1);
4462
4733
  }
package/dist/plugin.js CHANGED
@@ -1,9 +1,4 @@
1
1
  // @bun
2
- // plugin.ts
3
- import fs2 from "fs";
4
- import os2 from "os";
5
- import path2 from "path";
6
-
7
2
  // lib/db.ts
8
3
  import { Database as Database2 } from "bun:sqlite";
9
4
 
@@ -3718,6 +3713,10 @@ async function getWallet(provider) {
3718
3713
  const result = await db.select().from(wallets).where(eq(wallets.id, provider)).limit(1);
3719
3714
  return result[0] || null;
3720
3715
  }
3716
+ async function getAllWallets() {
3717
+ const db = getDb();
3718
+ return await db.select().from(wallets).orderBy(wallets.name);
3719
+ }
3721
3720
  async function insertTransaction(data) {
3722
3721
  const db = getDb();
3723
3722
  await db.insert(transactions).values({
@@ -3744,40 +3743,44 @@ async function deductBalance(provider, cost) {
3744
3743
  }
3745
3744
 
3746
3745
  // plugin.ts
3747
- var DEBUG_LOG = path2.join(os2.homedir(), ".config", "opencode", "ai-ledger", "debug.log");
3748
- function dbg(msg) {
3749
- const line = `[${new Date().toISOString()}] ${msg}
3750
- `;
3751
- fs2.appendFileSync(DEBUG_LOG, line);
3752
- }
3753
3746
  var sessions = new Map;
3747
+ function buildBar(spent, initial, width = 16) {
3748
+ if (initial <= 0)
3749
+ return "\u2591".repeat(width);
3750
+ const filled = Math.min(width, Math.max(0, Math.round(spent / initial * width)));
3751
+ return "\u2588".repeat(filled) + "\u2591".repeat(width - filled);
3752
+ }
3754
3753
  var plugin_default = async (input) => {
3755
3754
  await initializeDatabase();
3756
- dbg("plugin initialized");
3757
3755
  async function flushTurn(sessionID, state) {
3758
3756
  sessions.delete(sessionID);
3759
- const text2 = `ai-ledger \xB7 ${state.providerID} \xB7 -$${state.totalCost.toFixed(4)} spent | $${state.lastBalance.toFixed(2)} remaining`;
3760
- dbg(`flushing turn for ${sessionID}: ${text2}`);
3757
+ const wallets2 = await getAllWallets();
3758
+ const lines = [];
3759
+ lines.push(`\u2500\u2500\u2500 ai-ledger \u2500\u2500\u2500 turn: -$${state.totalCost.toFixed(4)} (${state.providerID})`);
3760
+ for (const w of wallets2) {
3761
+ const spent = w.initial_balance - w.balance;
3762
+ const pct = w.initial_balance > 0 ? Math.min(100, Math.round(spent / w.initial_balance * 100)) : 0;
3763
+ const bar = buildBar(spent, w.initial_balance);
3764
+ const low = w.initial_balance > 0 && w.balance / w.initial_balance < 0.1;
3765
+ const balStr = (low ? "\u26A0 " : "") + `$${w.balance.toFixed(2)}`;
3766
+ lines.push(` ${w.name.padEnd(14)} ${balStr.padStart(10)} ${bar} ${pct}%`);
3767
+ }
3761
3768
  try {
3762
- const res = await input.client.session.prompt({
3769
+ await input.client.session.prompt({
3763
3770
  path: { id: sessionID },
3764
3771
  query: { directory: input.directory },
3765
3772
  body: {
3766
3773
  noReply: true,
3767
- parts: [{ type: "text", text: text2 }]
3774
+ parts: [{ type: "text", text: lines.join(`
3775
+ `) }]
3768
3776
  }
3769
3777
  });
3770
- dbg(`session.prompt result: ${JSON.stringify(res)}`);
3771
- } catch (e) {
3772
- dbg(`session.prompt error: ${e?.message}`);
3773
- }
3778
+ } catch {}
3774
3779
  }
3775
3780
  return {
3776
3781
  event: async ({ event }) => {
3777
- dbg(`event: ${event.type}`);
3778
3782
  if (event.type === "session.idle") {
3779
3783
  const sessionID = event.properties?.sessionID;
3780
- dbg(`session.idle for ${sessionID}, accumulated: ${sessions.has(sessionID)}`);
3781
3784
  const state = sessions.get(sessionID);
3782
3785
  if (state)
3783
3786
  await flushTurn(sessionID, state);
@@ -3790,11 +3793,9 @@ var plugin_default = async (input) => {
3790
3793
  return;
3791
3794
  if (msg.role !== "assistant")
3792
3795
  return;
3793
- dbg(`assistant message: cost=${msg.cost} provider=${msg.providerID}`);
3794
3796
  if (!msg.cost || msg.cost === 0)
3795
3797
  return;
3796
3798
  const wallet = await getWallet(msg.providerID);
3797
- dbg(`wallet for ${msg.providerID}: ${wallet ? "found" : "NOT FOUND"}`);
3798
3799
  if (!wallet)
3799
3800
  return;
3800
3801
  const newBalance = await deductBalance(msg.providerID, msg.cost);
@@ -3812,7 +3813,6 @@ var plugin_default = async (input) => {
3812
3813
  const existing = sessions.get(msg.sessionID);
3813
3814
  const totalCost = (existing?.totalCost ?? 0) + msg.cost;
3814
3815
  sessions.set(msg.sessionID, { totalCost, lastBalance: newBalance, providerID: msg.providerID });
3815
- dbg(`accumulated for session ${msg.sessionID}: totalCost=${totalCost}`);
3816
3816
  }
3817
3817
  };
3818
3818
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kapishdima/ai-ledger",
3
- "version": "0.0.8",
3
+ "version": "0.0.9",
4
4
  "description": "AI provider balance and spending tracker for OpenCode",
5
5
  "type": "module",
6
6
  "main": "dist/plugin.js",