@wirecat/tg-cli 0.125.0 → 0.127.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 (97) hide show
  1. package/dist/bin/tg.js +2 -2
  2. package/dist/bundle/{adapter-H2LTOLOA.js → adapter-EZFS2UR6.js} +43 -43
  3. package/dist/bundle/{all-profiles-75HGEFL7.js → all-profiles-TNIUBQK6.js} +6 -6
  4. package/dist/bundle/{anthropic-N54MKE4C.js → anthropic-NGIS5LTL.js} +2 -2
  5. package/dist/bundle/{app-server-3N5INKKI.js → app-server-RPU76G7D.js} +42 -38
  6. package/dist/bundle/{bot-api-V65KTEAH.js → bot-api-QJ6U6BLG.js} +44 -44
  7. package/dist/bundle/{bot-history-TT2EAHEE.js → bot-history-THULK2C6.js} +12 -12
  8. package/dist/bundle/{bun-LN4J7PA7.js → bun-QLSLLP27.js} +2 -2
  9. package/dist/bundle/{bun-sqlite-6PDBFBUI.js → bun-sqlite-SH5245ZY.js} +3 -3
  10. package/dist/bundle/{chunk-RZ7KBWDQ.js → chunk-2R6ZSE3O.js} +2 -2
  11. package/dist/bundle/{chunk-E4HDE5DN.js → chunk-3CV5TBBR.js} +2 -2
  12. package/dist/bundle/{chunk-PCC7GWOS.js → chunk-3I3TGKVG.js} +3 -3
  13. package/dist/bundle/{chunk-6Y6SSZ34.js → chunk-3WI53AA4.js} +129 -83
  14. package/dist/bundle/{chunk-DYOZ7CUV.js → chunk-45URY64S.js} +1 -1
  15. package/dist/bundle/{chunk-S4SOS27T.js → chunk-4CQ3PV3V.js} +7 -7
  16. package/dist/bundle/{chunk-OG2ONSH6.js → chunk-4FFKCC7Y.js} +16 -16
  17. package/dist/bundle/{chunk-UTNK2PFE.js → chunk-4MKRKW6V.js} +12 -12
  18. package/dist/bundle/{chunk-FSP74THJ.js → chunk-5AOFOJQA.js} +4 -4
  19. package/dist/bundle/{chunk-7OBSIDBJ.js → chunk-5FDYMMEQ.js} +2 -2
  20. package/dist/bundle/{chunk-4TCBRKWQ.js → chunk-5KZKVKWU.js} +6 -6
  21. package/dist/bundle/{chunk-37SZHAEA.js → chunk-5SN6KFPC.js} +51 -50
  22. package/dist/bundle/{chunk-CNEJQQMD.js → chunk-7GE6KMLB.js} +11 -11
  23. package/dist/bundle/{chunk-77Z3OGAT.js → chunk-APSMQIA4.js} +2 -2
  24. package/dist/bundle/{chunk-BLNMM3AX.js → chunk-BNM6KNUQ.js} +1 -1
  25. package/dist/bundle/{chunk-GUPMDMFM.js → chunk-BWHVHPAQ.js} +5 -5
  26. package/dist/bundle/{chunk-VZDAVZYX.js → chunk-CXWAKV2O.js} +5 -5
  27. package/dist/bundle/{chunk-AMPHPP4P.js → chunk-DNNYE6PS.js} +13 -13
  28. package/dist/bundle/{chunk-X6436BYW.js → chunk-EGNQSWPH.js} +1 -1
  29. package/dist/bundle/{chunk-FUYCAROL.js → chunk-ERUB3KU3.js} +322 -11
  30. package/dist/bundle/{chunk-TVQBOIWC.js → chunk-FD44T7HC.js} +1 -1
  31. package/dist/bundle/{chunk-SGHF75RQ.js → chunk-FSDLSEZA.js} +1 -1
  32. package/dist/bundle/{chunk-WH4T44L3.js → chunk-GHVRCLJI.js} +1 -1
  33. package/dist/bundle/{chunk-JB4BO5XZ.js → chunk-H7GAFD4N.js} +1 -1
  34. package/dist/bundle/{chunk-JC6HMPL7.js → chunk-HPM47WO3.js} +4686 -3968
  35. package/dist/bundle/{chunk-3GILMKQ2.js → chunk-IWJ5OLU6.js} +2 -2
  36. package/dist/bundle/{chunk-QVK7NF3A.js → chunk-J6FHZXNS.js} +32 -28
  37. package/dist/bundle/{chunk-RX5GU7GQ.js → chunk-JF7D2Y4K.js} +1129 -879
  38. package/dist/bundle/{chunk-JCNKGZQG.js → chunk-JFQZ6BWI.js} +16 -16
  39. package/dist/bundle/{chunk-ZX5OSZHH.js → chunk-JWEKUAVZ.js} +10 -10
  40. package/dist/bundle/{chunk-QYT6HDCL.js → chunk-K4VO7S6Q.js} +1 -1
  41. package/dist/bundle/{chunk-DNCOELTM.js → chunk-LOG65WHO.js} +1 -1
  42. package/dist/bundle/{chunk-GRDVBJCR.js → chunk-MTU3UP5U.js} +1 -1
  43. package/dist/bundle/{chunk-DI3RJ3MJ.js → chunk-NBN5OYXH.js} +3 -3
  44. package/dist/bundle/{chunk-TAFH5K5D.js → chunk-P5NJECXX.js} +411 -295
  45. package/dist/bundle/{chunk-JKF7LZBU.js → chunk-QPVCFSVU.js} +5 -5
  46. package/dist/bundle/{chunk-UG66U2T7.js → chunk-R52ZZZKZ.js} +23 -13
  47. package/dist/bundle/{chunk-INZAZMUF.js → chunk-S3XUJPPL.js} +9 -4
  48. package/dist/bundle/{chunk-6HLB73UN.js → chunk-SN52ZGFN.js} +2 -2
  49. package/dist/bundle/{chunk-FHPEUAHQ.js → chunk-TGKTIDYS.js} +168 -399
  50. package/dist/bundle/{chunk-VG3EQJYV.js → chunk-UIQMBOXU.js} +31 -2
  51. package/dist/bundle/{chunk-EIGV2JKX.js → chunk-UW34Z7J3.js} +1 -1
  52. package/dist/bundle/{chunk-XTNOBJRP.js → chunk-UY2TRFYN.js} +10 -10
  53. package/dist/bundle/{chunk-VHD4V64E.js → chunk-VMV5CMLH.js} +1 -1
  54. package/dist/bundle/{chunk-MK4IKICN.js → chunk-X4ECHJNG.js} +2 -2
  55. package/dist/bundle/{chunk-IN3NAFUN.js → chunk-XUAVZ6YX.js} +7 -7
  56. package/dist/bundle/{chunk-NTHALPDT.js → chunk-Y62I2T36.js} +2 -1
  57. package/dist/bundle/{chunk-B252D7V4.js → chunk-Y65BQJOY.js} +4 -6
  58. package/dist/bundle/{chunk-4KIOWSDL.js → chunk-Y7UA7HGL.js} +2 -2
  59. package/dist/bundle/{chunk-HHG5FR5H.js → chunk-YIPOWJPN.js} +1 -1
  60. package/dist/bundle/{chunk-VUBSGQ2O.js → chunk-YZGIQY2R.js} +24 -22
  61. package/dist/bundle/{chunk-AI2J3WJT.js → chunk-ZIPUVOGT.js} +1 -1
  62. package/dist/bundle/{chunk-LU2CHHPC.js → chunk-ZSS3BH6Z.js} +2 -2
  63. package/dist/bundle/{command-contract-JP6SCP7U.js → command-contract-DY6Y4TES.js} +13 -13
  64. package/dist/bundle/{command-server-entry-BLSFT3T6.js → command-server-entry-UG2CLYXI.js} +20 -20
  65. package/dist/bundle/{decode-NNLEQU7B.js → decode-3NEUZJ2N.js} +2 -2
  66. package/dist/bundle/{echarts-XAZHGDOM.js → echarts-CN6ZVAJZ.js} +2 -2
  67. package/dist/bundle/{embed-Q7ZCVSCO.js → embed-M4EHIKA5.js} +3 -3
  68. package/dist/bundle/{embedder-MVS3PVWQ.js → embedder-K2XL2UB4.js} +6 -6
  69. package/dist/bundle/{entry-XN3ZZAOK.js → entry-6M55YL2H.js} +6 -6
  70. package/dist/bundle/{first-run-G4EFTONI.js → first-run-TLJILIOF.js} +5 -5
  71. package/dist/bundle/{first-screen-RIDJEPC3.js → first-screen-WME7ILW2.js} +14 -14
  72. package/dist/bundle/{instructions-QDHYYZBU.js → instructions-QLC2AXAB.js} +1 -1
  73. package/dist/bundle/{node-3Y7OVY2U.js → node-BAA3T4CH.js} +2 -2
  74. package/dist/bundle/{node-sqlite-R2SBROJM.js → node-sqlite-FNYVHQCO.js} +4 -4
  75. package/dist/bundle/{oauth-WSPWMWTV.js → oauth-32T5KL5E.js} +4 -4
  76. package/dist/bundle/{open-VFLF4HRQ.js → open-4VQ6FUEI.js} +2 -2
  77. package/dist/bundle/{openai-DFCKZZDV.js → openai-HDOKCN3Z.js} +12 -12
  78. package/dist/bundle/{process-VZKFAGNP.js → process-GOUBIWKC.js} +1 -1
  79. package/dist/bundle/{program-2LB3CUZX.js → program-QFXJL2R5.js} +46 -46
  80. package/dist/bundle/{prompt-RVLA2PEY.js → prompt-YYODWYFO.js} +2 -2
  81. package/dist/bundle/{recognize-LEKNA3G5.js → recognize-7ZULX5HL.js} +1 -1
  82. package/dist/bundle/{remote-WG5V2I2G.js → remote-TUG7M5Y5.js} +6 -6
  83. package/dist/bundle/{rerank-ONAEQVJ6.js → rerank-D2EZWG66.js} +4 -4
  84. package/dist/bundle/{serve-BL2X6FZG.js → serve-MP3GA2XX.js} +6 -6
  85. package/dist/bundle/{server-3LSC4BMK.js → server-D277L3H3.js} +31 -29
  86. package/dist/bundle/server-GEP7QXGI.js +62 -0
  87. package/dist/bundle/{sqlite-runtime-RQXPRH6C.js → sqlite-runtime-XHZXEOLY.js} +3 -3
  88. package/dist/bundle/{state-O7LRA526.js → state-YI3W6HGO.js} +3 -3
  89. package/dist/bundle/{store-HMJUPK45.js → store-C4RFPYPK.js} +9 -9
  90. package/dist/bundle/{store-7C4UAND2.js → store-CIZPJFWE.js} +15 -11
  91. package/dist/bundle/store-maintenance-command-JNDYWFD2.js +52 -0
  92. package/dist/bundle/tg.js +3 -3
  93. package/dist/version.d.ts +1 -1
  94. package/dist/version.js +1 -1
  95. package/package.json +2 -2
  96. package/dist/bundle/server-7EYEEGJT.js +0 -62
  97. package/dist/bundle/store-maintenance-command-I7PSA3SZ.js +0 -52
@@ -16,10 +16,10 @@ import {
16
16
  servicesFor,
17
17
  throughWrapper,
18
18
  withFileLockAsync
19
- } from "./chunk-TAFH5K5D.js";
19
+ } from "./chunk-P5NJECXX.js";
20
20
  import {
21
21
  servingProfiles
22
- } from "./chunk-6HLB73UN.js";
22
+ } from "./chunk-SN52ZGFN.js";
23
23
  import {
24
24
  chatReferenceOf,
25
25
  ensureAccount,
@@ -27,7 +27,7 @@ import {
27
27
  isId,
28
28
  openStore,
29
29
  pickPerson
30
- } from "./chunk-JC6HMPL7.js";
30
+ } from "./chunk-HPM47WO3.js";
31
31
  import {
32
32
  CEILING_KEY,
33
33
  WRITE_KEYS,
@@ -47,13 +47,13 @@ import {
47
47
  rememberAccount,
48
48
  rootOf2 as rootOf,
49
49
  skipFlagFor
50
- } from "./chunk-FHPEUAHQ.js";
50
+ } from "./chunk-TGKTIDYS.js";
51
51
  import {
52
52
  providerErrorKey
53
- } from "./chunk-4TCBRKWQ.js";
53
+ } from "./chunk-5KZKVKWU.js";
54
54
  import {
55
55
  isCliFailure
56
- } from "./chunk-77Z3OGAT.js";
56
+ } from "./chunk-APSMQIA4.js";
57
57
  import {
58
58
  resolvePaths
59
59
  } from "./chunk-NM5GBJME.js";
@@ -64,7 +64,7 @@ import {
64
64
  __name
65
65
  } from "./chunk-ZVVMGPBJ.js";
66
66
 
67
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
67
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/messenger/ask.js
68
68
  import { openSync } from "node:fs";
69
69
  import { createInterface } from "node:readline";
70
70
  import { ReadStream } from "node:tty";
@@ -119,7 +119,7 @@ var terminalAsker = /* @__PURE__ */ __name((command) => async (key, request) =>
119
119
  throw new CliError("cancelled", `${key}: not done \u2014 the answer was no`);
120
120
  }, "terminalAsker");
121
121
 
122
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/sends/pace.js
122
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/sends/pace.js
123
123
  import { readFileSync, renameSync, writeFileSync } from "node:fs";
124
124
  import { join } from "node:path";
125
125
  var DEFAULT_PACE = { perMinute: 60, burst: 20 };
@@ -214,7 +214,7 @@ var waitForTurn = /* @__PURE__ */ __name(async (pacer, options) => {
214
214
  await (options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms))))(waitMs);
215
215
  }, "waitForTurn");
216
216
 
217
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
217
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/permission-keys.js
218
218
  var pathOf = /* @__PURE__ */ __name((command) => {
219
219
  const words = [];
220
220
  for (let at = command; at?.parent; at = at.parent)
@@ -274,7 +274,7 @@ var refuseUnknownPermissionKeys = /* @__PURE__ */ __name((command, settings, too
274
274
  throw new CliError("validation_error", `--permission ${key} names no command`, { permission: key });
275
275
  }, "refuseUnknownPermissionKeys");
276
276
 
277
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
277
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/messenger/flooded.js
278
278
  var LONG_LIVED = /* @__PURE__ */ new Set(["self", "newSendId", "close", "formatMarkdown", "formatHtml", "storedChats"]);
279
279
  var LISTENING = /* @__PURE__ */ new Set(["watch", "feed", "listen", "listenHistory"]);
280
280
  var BLOCKING = /* @__PURE__ */ new Set(["frozen", "limited", "banned"]);
@@ -371,7 +371,7 @@ var flooded = /* @__PURE__ */ __name((messenger, memory, { name, warn, pacer })
371
371
  });
372
372
  }, "flooded");
373
373
 
374
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
374
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/messenger/observed.js
375
375
  var observed = /* @__PURE__ */ __name((messenger, events) => {
376
376
  const timed = /* @__PURE__ */ __name(async (operation, named, work, after) => {
377
377
  const write = currentOperation();
@@ -470,7 +470,7 @@ var byPart = /* @__PURE__ */ __name((batch, counts) => {
470
470
  counts[part] = (counts[part] ?? 0) + items.length;
471
471
  }, "byPart");
472
472
 
473
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
473
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/messenger/stored.js
474
474
  var REKEY_PACING = { lockMs: 50, pauseMs: 25 };
475
475
  var stored = /* @__PURE__ */ __name((messenger, { account, store, warn, events, pending, announcing, deletedWithoutChat, profile, rekeyed, rekeyPacing = REKEY_PACING, closing, namesFromStore, recipientIds, countsUnread = false, historyLimits, command = "cli" }) => {
476
476
  let warned = false;
@@ -1046,7 +1046,7 @@ var keep = /* @__PURE__ */ __name(async (store, account, event, seenAt, among, c
1046
1046
  }
1047
1047
  }, "keep");
1048
1048
 
1049
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
1049
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/messenger/context.js
1050
1050
  var lazyStore = /* @__PURE__ */ __name((env, command, version) => {
1051
1051
  let opened;
1052
1052
  return {
@@ -10,7 +10,7 @@ import {
10
10
  __name
11
11
  } from "./chunk-ZVVMGPBJ.js";
12
12
 
13
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
13
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/store/vector-extension.js
14
14
  import { readFileSync } from "node:fs";
15
15
  var musl = /* @__PURE__ */ __name(() => {
16
16
  if (process.platform !== "linux")
@@ -2,9 +2,10 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  storePath
5
- } from "./chunk-NTHALPDT.js";
5
+ } from "./chunk-Y62I2T36.js";
6
6
  import {
7
- resolvePaths
7
+ resolvePaths,
8
+ writeSecurely
8
9
  } from "./chunk-NM5GBJME.js";
9
10
  import {
10
11
  CliError,
@@ -14,11 +15,295 @@ import {
14
15
  __name
15
16
  } from "./chunk-ZVVMGPBJ.js";
16
17
 
17
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/store/shared-config.js
18
- import { mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
18
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/store/shared-config.js
19
+ import { existsSync, mkdirSync, readFileSync, renameSync, statSync, writeFileSync } from "node:fs";
19
20
  import { dirname, join, resolve } from "node:path";
20
21
 
21
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/domain/task-categories.js
22
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/domain/config-repair.js
23
+ var REPAIR_WORDS = {
24
+ byte_order_mark: "an invisible byte-order mark at the start",
25
+ comment: "a comment, which JSON does not allow",
26
+ trailing_comma: "a comma before a closing bracket",
27
+ missing_comma: "a missing comma",
28
+ unquoted_key: "a key without double quotes",
29
+ single_quotes: "text in single quotes",
30
+ missing_closer: "the file stops before its closing brackets \u2014 whatever followed this line was already lost"
31
+ };
32
+ var GiveUp = class {
33
+ static {
34
+ __name(this, "GiveUp");
35
+ }
36
+ at;
37
+ why;
38
+ constructor(at, why) {
39
+ this.at = at;
40
+ this.why = why;
41
+ }
42
+ };
43
+ var NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/;
44
+ var LITERAL = /^(true|false|null)/;
45
+ var KEY = /^[A-Za-z_$][\w$.-]*/;
46
+ var ENDS_VALUE = /^[\s,\]}/]?$/;
47
+ var repairConfigText = /* @__PURE__ */ __name((text) => {
48
+ try {
49
+ JSON.parse(text);
50
+ return { state: "valid" };
51
+ } catch {
52
+ }
53
+ const fixes = [];
54
+ const lineAt = /* @__PURE__ */ __name((offset) => text.slice(0, offset).split("\n").length, "lineAt");
55
+ const fix = /* @__PURE__ */ __name((kind, offset) => fixes.push({ kind, line: lineAt(offset) }), "fix");
56
+ const giveUp = /* @__PURE__ */ __name((why, offset = at) => {
57
+ throw new GiveUp(offset, why);
58
+ }, "giveUp");
59
+ let at = 0;
60
+ let truncated = false;
61
+ let last = "open";
62
+ let lastEnd = 0;
63
+ const previous = /* @__PURE__ */ __name(() => last, "previous");
64
+ const skip = /* @__PURE__ */ __name(() => {
65
+ for (; ; ) {
66
+ while (/\s/.test(text[at] ?? ""))
67
+ at++;
68
+ if (text.startsWith("//", at)) {
69
+ fix("comment", at);
70
+ while (at < text.length && text[at] !== "\n")
71
+ at++;
72
+ } else if (text.startsWith("/*", at)) {
73
+ const end = text.indexOf("*/", at + 2);
74
+ if (end < 0)
75
+ giveUp("a /* comment is never closed");
76
+ fix("comment", at);
77
+ at = end + 2;
78
+ } else
79
+ return;
80
+ }
81
+ }, "skip");
82
+ const string = /* @__PURE__ */ __name(() => {
83
+ const quote = text[at];
84
+ const start = at;
85
+ if (quote === "'")
86
+ fix("single_quotes", at);
87
+ at++;
88
+ let body = "";
89
+ for (; ; ) {
90
+ if (at >= text.length)
91
+ giveUp("the file stops inside a quoted text", start);
92
+ const char = text[at];
93
+ if (char === quote)
94
+ break;
95
+ if (text.charCodeAt(at) < 32)
96
+ giveUp("a line break inside a quoted text");
97
+ if (char === "\\") {
98
+ const next = text[at + 1] ?? "";
99
+ if (quote === "'" && next === "'")
100
+ body += "'";
101
+ else if (/^["\\/bfnrt]$/.test(next))
102
+ body += `\\${next}`;
103
+ else if (next === "u" && /^[0-9a-fA-F]{4}$/.test(text.slice(at + 2, at + 6))) {
104
+ body += text.slice(at, at + 6);
105
+ at += 4;
106
+ } else
107
+ giveUp("an escape JSON has no meaning for");
108
+ at += 2;
109
+ continue;
110
+ }
111
+ body += char === '"' ? '\\"' : char;
112
+ at++;
113
+ }
114
+ at++;
115
+ return JSON.parse(`"${body}"`);
116
+ }, "string");
117
+ const key = /* @__PURE__ */ __name(() => {
118
+ const char = text[at] ?? "";
119
+ if (char === '"' || char === "'")
120
+ return string();
121
+ const word = KEY.exec(text.slice(at))?.[0];
122
+ if (!word)
123
+ return giveUp("something other than a key where a key should be");
124
+ fix("unquoted_key", at);
125
+ at += word.length;
126
+ return word;
127
+ }, "key");
128
+ const scalar = /* @__PURE__ */ __name(() => {
129
+ const char = text[at] ?? "";
130
+ if (char === '"' || char === "'")
131
+ return { json: JSON.stringify(string()) };
132
+ const word = (NUMBER.exec(text.slice(at)) ?? LITERAL.exec(text.slice(at)))?.[0];
133
+ if (!word || !ENDS_VALUE.test(text[at + word.length] ?? ""))
134
+ return giveUp("a value that is not JSON \u2014 text needs quotes, and only true, false and null go without");
135
+ if (at + word.length === text.length && NUMBER.test(word))
136
+ giveUp("the file stops inside a number");
137
+ at += word.length;
138
+ return { json: word };
139
+ }, "scalar");
140
+ const members = /* @__PURE__ */ __name((close, one) => {
141
+ const out = [];
142
+ at++;
143
+ last = "open";
144
+ let comma = -1;
145
+ for (; ; ) {
146
+ skip();
147
+ if (truncated)
148
+ return out;
149
+ if (at >= text.length) {
150
+ if (previous() === "close")
151
+ giveUp("the file stops after a closing bracket, so which brackets are missing has two readings");
152
+ if (previous() === "comma")
153
+ fix("trailing_comma", comma);
154
+ fix("missing_closer", text.length);
155
+ truncated = true;
156
+ return out;
157
+ }
158
+ const char = text[at];
159
+ if (char === close) {
160
+ if (previous() === "comma")
161
+ fix("trailing_comma", comma);
162
+ at++;
163
+ last = "close";
164
+ return out;
165
+ }
166
+ if (char === "}" || char === "]")
167
+ giveUp(`a ${char} where ${close} should close`);
168
+ if (char === ",") {
169
+ if (previous() !== "value" && previous() !== "close")
170
+ giveUp("a comma with nothing before it");
171
+ comma = at;
172
+ at++;
173
+ last = "comma";
174
+ continue;
175
+ }
176
+ if (previous() === "value" || previous() === "close") {
177
+ if (lineAt(at) === lineAt(lastEnd))
178
+ giveUp("two entries on one line with no comma between them");
179
+ fix("missing_comma", lastEnd);
180
+ }
181
+ out.push(one());
182
+ }
183
+ }, "members");
184
+ const value = /* @__PURE__ */ __name(() => {
185
+ const char = text[at] ?? "";
186
+ let node;
187
+ if (char === "{") {
188
+ const seen = /* @__PURE__ */ new Set();
189
+ node = {
190
+ object: members("}", () => {
191
+ const start = at;
192
+ const name = key();
193
+ if (seen.has(name))
194
+ giveUp("a key appears twice in one object", start);
195
+ seen.add(name);
196
+ skip();
197
+ if (at >= text.length)
198
+ giveUp("the file stops after a key, before its value");
199
+ if (text[at] !== ":")
200
+ giveUp("a key with no colon after it");
201
+ at++;
202
+ skip();
203
+ if (at >= text.length)
204
+ giveUp("the file stops after a key, before its value");
205
+ return [name, value()];
206
+ })
207
+ };
208
+ } else if (char === "[") {
209
+ node = {
210
+ array: members("]", () => {
211
+ return value();
212
+ })
213
+ };
214
+ } else
215
+ node = scalar();
216
+ if (!truncated) {
217
+ last = "json" in node ? "value" : "close";
218
+ lastEnd = at;
219
+ }
220
+ return node;
221
+ }, "value");
222
+ try {
223
+ if (text.includes("\0") || text.includes(String.fromCharCode(65533)))
224
+ giveUp("the file is not text", 0);
225
+ if (text.charCodeAt(0) === 65279) {
226
+ fix("byte_order_mark", 0);
227
+ at = 1;
228
+ }
229
+ skip();
230
+ if (text[at] !== "{")
231
+ giveUp(at >= text.length ? "the file is empty" : "the file does not start with {");
232
+ const root = value();
233
+ skip();
234
+ if (at < text.length)
235
+ giveUp("more text after the closing }");
236
+ const repaired = `${serialise(root, "")}
237
+ `;
238
+ JSON.parse(repaired);
239
+ return { state: "repaired", text: repaired, fixes };
240
+ } catch (error) {
241
+ if (!(error instanceof GiveUp))
242
+ throw error;
243
+ const before = text.slice(0, error.at).split("\n");
244
+ return {
245
+ state: "refused",
246
+ line: before.length,
247
+ column: (before.at(-1)?.length ?? 0) + 1,
248
+ why: error.why
249
+ };
250
+ }
251
+ }, "repairConfigText");
252
+ var serialise = /* @__PURE__ */ __name((node, indent) => {
253
+ if ("json" in node)
254
+ return node.json;
255
+ const inner = `${indent} `;
256
+ const parts = "object" in node ? node.object.map(([name, item]) => `${inner}${JSON.stringify(name)}: ${serialise(item, inner)}`) : node.array.map((item) => `${inner}${serialise(item, inner)}`);
257
+ const [open, close] = "object" in node ? ["{", "}"] : ["[", "]"];
258
+ return parts.length === 0 ? `${open}${close}` : `${open}
259
+ ${parts.join(",\n")}
260
+ ${indent}${close}`;
261
+ }, "serialise");
262
+ var SAFE_REPAIRS = /* @__PURE__ */ new Set([
263
+ "byte_order_mark",
264
+ "comment",
265
+ "trailing_comma",
266
+ "missing_comma"
267
+ ]);
268
+ var FIX_FOR = {
269
+ unquoted_key: /* @__PURE__ */ __name((line) => `put the key on line ${line} in double quotes`, "unquoted_key"),
270
+ single_quotes: /* @__PURE__ */ __name((line) => `use double quotes for the text on line ${line}`, "single_quotes"),
271
+ missing_closer: /* @__PURE__ */ __name((line) => `add the closing } or ] the file lacks after line ${line}, and check that nothing after it was lost`, "missing_closer")
272
+ };
273
+ var FIX_FOR_REFUSAL = [
274
+ [/no comma between/, (line, before) => `add a comma after ${before} on line ${line}`],
275
+ [/no colon after/, (line) => `add a colon after the key on line ${line}`],
276
+ [/comma with nothing before/, (line) => `remove the extra comma on line ${line}`],
277
+ [/inside a quoted text/, (line) => `close the quotes on line ${line}`],
278
+ [/value that is not JSON/, (line) => `put the value on line ${line} in double quotes`],
279
+ [/key appears twice/, (line) => `keep one of the two keys named on line ${line}; the file holds both`]
280
+ ];
281
+ var shown = /* @__PURE__ */ __name((line) => line.trim().replace(/("(?:[^"\\]|\\.)*"|'(?:[^'\\]|\\.)*'|[^\s"',:{}[\]]+)(\s*:)?/g, (token, _value, key) => key || /^(true|false|null)$/.test(token) ? token : '"\u2026"'), "shown");
282
+ var explainBrokenJson = /* @__PURE__ */ __name((text, result) => {
283
+ const lines = text.replace(/^\uFEFF/u, "").split(/\r?\n/);
284
+ const around = /* @__PURE__ */ __name((line2) => {
285
+ const near = lines[line2 - 1]?.trim() ? lines[line2 - 1] : lines[line2 - 2];
286
+ return near ? ` \u2014 near \`${shown(near)}\`` : "";
287
+ }, "around");
288
+ if (result.state === "repaired") {
289
+ const asked = result.fixes.find((one) => !SAFE_REPAIRS.has(one.kind)) ?? result.fixes[0];
290
+ if (!asked)
291
+ return "it is not valid JSON";
292
+ const fix2 = FIX_FOR[asked.kind]?.(asked.line);
293
+ return `line ${asked.line} has ${REPAIR_WORDS[asked.kind]}${around(asked.line)}${fix2 ? `; likely fix: ${fix2}` : ""}`;
294
+ }
295
+ if (result.state === "valid")
296
+ return "it is valid JSON";
297
+ const { line, why } = result;
298
+ const column = line === 1 && text.charCodeAt(0) === 65279 ? result.column - 1 : result.column;
299
+ const head = (lines[line - 1] ?? "").slice(0, column - 1);
300
+ const entry = head.slice(Math.max(head.lastIndexOf(","), head.lastIndexOf("{"), head.lastIndexOf("[")) + 1);
301
+ const before = shown(entry) || shown(lines[line - 2] ?? "");
302
+ const fix = FIX_FOR_REFUSAL.find(([pattern]) => pattern.test(why))?.[1](line, `\`${before}\``);
303
+ return `line ${line}, column ${column}: ${why}${around(line)}; likely fix: ${fix ?? "correct that part by hand"}`;
304
+ }, "explainBrokenJson");
305
+
306
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/domain/task-categories.js
22
307
  var DEFAULT_TASK_CATEGORIES = [
23
308
  {
24
309
  name: "taxes",
@@ -773,7 +1058,7 @@ var storedTaskCategories = /* @__PURE__ */ __name((json) => {
773
1058
  }
774
1059
  }, "storedTaskCategories");
775
1060
 
776
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/store/shared-config.js
1061
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/store/shared-config.js
777
1062
  var SECTION = "task_categories";
778
1063
  var sharedConfigPath = /* @__PURE__ */ __name((store, env = process.env) => {
779
1064
  const paths = resolvePaths({ appName: "WireCat", prefix: "WIRECAT", env });
@@ -781,10 +1066,33 @@ var sharedConfigPath = /* @__PURE__ */ __name((store, env = process.env) => {
781
1066
  return join(paths.config, "config.json");
782
1067
  return resolve(store) === resolve(storePath({ ...env, MESSAGING_STORE: void 0 })) ? join(paths.config, "config.json") : join(dirname(store), "config.json");
783
1068
  }, "sharedConfigPath");
1069
+ var backupPathFor = /* @__PURE__ */ __name((file) => {
1070
+ const stamp = (/* @__PURE__ */ new Date()).toISOString().replace(/[:.]/g, "-");
1071
+ let path = `${file}.bak-${stamp}`;
1072
+ for (let n = 2; existsSync(path); n++)
1073
+ path = `${file}.bak-${stamp}-${n}`;
1074
+ return path;
1075
+ }, "backupPathFor");
1076
+ var mended = /* @__PURE__ */ __name((path, bytes) => {
1077
+ const text = bytes.toString("utf8");
1078
+ const result = repairConfigText(text);
1079
+ if (result.state === "repaired" && result.fixes.every((one) => SAFE_REPAIRS.has(one.kind))) {
1080
+ try {
1081
+ writeSecurely(backupPathFor(path), bytes, statSync(path).mode & 511);
1082
+ writeSecurely(path, result.text, 384);
1083
+ } catch {
1084
+ }
1085
+ return JSON.parse(result.text);
1086
+ }
1087
+ throw new CliError("configuration_error", `${path} is not valid JSON, ${explainBrokenJson(text, result)}`, {
1088
+ reason: "config.invalid_json",
1089
+ file: path
1090
+ });
1091
+ }, "mended");
784
1092
  var readJson = /* @__PURE__ */ __name((path) => {
785
- let text;
1093
+ let bytes;
786
1094
  try {
787
- text = readFileSync(path, "utf8");
1095
+ bytes = readFileSync(path);
788
1096
  } catch (error) {
789
1097
  if (error.code === "ENOENT")
790
1098
  return void 0;
@@ -792,9 +1100,9 @@ var readJson = /* @__PURE__ */ __name((path) => {
792
1100
  }
793
1101
  let parsed;
794
1102
  try {
795
- parsed = JSON.parse(text);
796
- } catch (error) {
797
- throw new CliError("configuration_error", `${path} is not valid JSON: ${error.message}`);
1103
+ parsed = JSON.parse(bytes.toString("utf8"));
1104
+ } catch {
1105
+ parsed = mended(path, bytes);
798
1106
  }
799
1107
  if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed))
800
1108
  throw new CliError("configuration_error", `${path} must hold a JSON object`);
@@ -869,6 +1177,8 @@ var taskCategoriesReader = /* @__PURE__ */ __name((path) => {
869
1177
  }, "taskCategoriesReader");
870
1178
 
871
1179
  export {
1180
+ REPAIR_WORDS,
1181
+ repairConfigText,
872
1182
  DEFAULT_TASK_CATEGORIES,
873
1183
  FALLBACK_CATEGORY,
874
1184
  unlistedNote,
@@ -876,6 +1186,7 @@ export {
876
1186
  taskCategoryValue,
877
1187
  storedTaskCategories,
878
1188
  sharedConfigPath,
1189
+ backupPathFor,
879
1190
  readTaskCategoryEdits,
880
1191
  applyTaskCategoryEdits,
881
1192
  editsFrom,
@@ -4,7 +4,7 @@ import {
4
4
  __name
5
5
  } from "./chunk-ZVVMGPBJ.js";
6
6
 
7
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/background/processes.js
7
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/background/processes.js
8
8
  import { execFileSync } from "node:child_process";
9
9
  import { readdirSync, readFileSync, readlinkSync } from "node:fs";
10
10
  var alive = /* @__PURE__ */ __name((pid) => {
@@ -7,7 +7,7 @@ import {
7
7
  __name
8
8
  } from "./chunk-ZVVMGPBJ.js";
9
9
 
10
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/input-policy.js
10
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/input-policy.js
11
11
  var MAX_BUFFERED_INPUT = 16 * 1024 * 1024;
12
12
  var MAX_SECRET_INPUT = 64 * 1024;
13
13
  var policies = /* @__PURE__ */ new WeakMap();
@@ -4,7 +4,7 @@ import {
4
4
  __name
5
5
  } from "./chunk-ZVVMGPBJ.js";
6
6
 
7
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/cli/stdin-field.js
7
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/cli/stdin-field.js
8
8
  var fields = /* @__PURE__ */ new WeakMap();
9
9
  var readsStdin = /* @__PURE__ */ __name((command, field) => {
10
10
  fields.set(command, field);
@@ -4,7 +4,7 @@ import {
4
4
  __name
5
5
  } from "./chunk-ZVVMGPBJ.js";
6
6
 
7
- // node_modules/.pnpm/@wirecat+cli-core@0.650.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._f55ccfac747d9da64edfb69ea8dcc45a/node_modules/@wirecat/cli-core/dist/http/listen.js
7
+ // node_modules/.pnpm/@wirecat+cli-core@0.659.0_@napi-rs+canvas@1.0.13_@wirecat+cli-base@0.99.0_commander@15._7ae9f69690019eb17dc9f8442c19cb73/node_modules/@wirecat/cli-core/dist/http/listen.js
8
8
  import { createServer } from "node:http";
9
9
  import { Readable } from "node:stream";
10
10
  var MAX_BODY = 4 * 1024 * 1024;