@wirecat/mail-cli 0.24.0 → 0.25.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 (106) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/bin/mail.js +2 -2
  3. package/dist/bundle/{all-profiles-VS7P6DJY.js → all-profiles-QEV2PSOR.js} +9 -9
  4. package/dist/bundle/{anthropic-C5JXKGBS.js → anthropic-5NKQXIHM.js} +16 -9
  5. package/dist/bundle/{app-server-HU3LVU42.js → app-server-G2CJNT4R.js} +56 -45
  6. package/dist/bundle/{bun-QLFX47WZ.js → bun-6HBYWQIX.js} +2 -2
  7. package/dist/bundle/{bun-sqlite-W4PGAKVY.js → bun-sqlite-DXIQ7BVR.js} +8 -4
  8. package/dist/bundle/{chunk-U6MMQNNK.js → chunk-37F6QYTO.js} +5 -5
  9. package/dist/bundle/{chunk-5NLHDK7P.js → chunk-3XVR2ROR.js} +30 -30
  10. package/dist/bundle/{chunk-TI7ZIPA2.js → chunk-434YOD6A.js} +3 -3
  11. package/dist/bundle/{chunk-NCRSE647.js → chunk-5QYK3LWS.js} +57 -25
  12. package/dist/bundle/{chunk-WOX7FZJP.js → chunk-5ZYFV6FD.js} +82 -61
  13. package/dist/bundle/chunk-7GLJSJ7M.js +16 -0
  14. package/dist/bundle/{chunk-XBEO472U.js → chunk-A6BPOX5O.js} +11804 -10024
  15. package/dist/bundle/{chunk-VVL4MKYH.js → chunk-ADKMBXY4.js} +1 -1
  16. package/dist/bundle/{chunk-PRQ2U7HF.js → chunk-B7SWTH5O.js} +2 -2
  17. package/dist/bundle/{chunk-64ZG5ERD.js → chunk-BC7PFQL7.js} +2 -2
  18. package/dist/bundle/{chunk-Q6K2XUGU.js → chunk-CBYBZCQP.js} +1 -1
  19. package/dist/bundle/{chunk-ZO4MQWIK.js → chunk-CIWWNBVW.js} +7 -7
  20. package/dist/bundle/{chunk-Q4OKEN3B.js → chunk-DIA56CS7.js} +7 -6
  21. package/dist/bundle/{chunk-QI3PXUOJ.js → chunk-EXVY76VO.js} +36 -30
  22. package/dist/bundle/{chunk-RNZKQMFY.js → chunk-FZZD4AFY.js} +11 -11
  23. package/dist/bundle/{chunk-5X3GU5LI.js → chunk-G5LHHAW2.js} +5 -5
  24. package/dist/bundle/{chunk-YI544LHI.js → chunk-GJRYZXBN.js} +8 -8
  25. package/dist/bundle/{chunk-NSIN5IM4.js → chunk-GY4XCLCO.js} +9 -14
  26. package/dist/bundle/{chunk-IRUN4XOV.js → chunk-HEIDAHRC.js} +2 -2
  27. package/dist/bundle/{chunk-4QNHAM3J.js → chunk-HEYVMAAQ.js} +1 -1
  28. package/dist/bundle/{chunk-RLQZFZLK.js → chunk-HJSJBNCJ.js} +61 -6
  29. package/dist/bundle/{chunk-H5FJTHVA.js → chunk-HLXVUMZJ.js} +2 -2
  30. package/dist/bundle/{chunk-DW3F6DUW.js → chunk-IACWKZWS.js} +1 -1
  31. package/dist/bundle/{chunk-JOQGJUFT.js → chunk-IXO4SCKE.js} +1 -1
  32. package/dist/bundle/{chunk-X7J3TTDO.js → chunk-IZOYW4Z4.js} +24 -0
  33. package/dist/bundle/{chunk-6PWCQKMD.js → chunk-J4OYK4WL.js} +13 -13
  34. package/dist/bundle/{chunk-ZR2BDNGG.js → chunk-JG4MNYG2.js} +1 -1
  35. package/dist/bundle/{chunk-JMLIKXFO.js → chunk-K2OGF7KC.js} +1 -1
  36. package/dist/bundle/chunk-K6HR6HCO.js +32 -0
  37. package/dist/bundle/{chunk-FKWUUCX2.js → chunk-KFB2X6KE.js} +385 -178
  38. package/dist/bundle/{chunk-3FD3IATT.js → chunk-KK4HD3SI.js} +5 -5
  39. package/dist/bundle/{chunk-HBZAJINU.js → chunk-L4QVOEOB.js} +2 -2
  40. package/dist/bundle/chunk-LGZPKKBN.js +53 -0
  41. package/dist/bundle/{chunk-O373QEAJ.js → chunk-MBFPFWCO.js} +25 -25
  42. package/dist/bundle/{chunk-SWKQ6IAR.js → chunk-MWGH3M46.js} +2 -2
  43. package/dist/bundle/{chunk-C5BMCLCQ.js → chunk-ND5H5ADM.js} +3 -3
  44. package/dist/bundle/{chunk-EKGRNFYQ.js → chunk-NMZQTYKJ.js} +1 -1
  45. package/dist/bundle/{chunk-RUASZW3M.js → chunk-OLKCJBZY.js} +4 -4
  46. package/dist/bundle/{chunk-MTO6YVMN.js → chunk-OLLIWNFG.js} +3 -3
  47. package/dist/bundle/{chunk-X47BL4M5.js → chunk-P6GXNT7Z.js} +12 -12
  48. package/dist/bundle/{chunk-YBQ5AYLZ.js → chunk-PGC5TRH6.js} +3 -3
  49. package/dist/bundle/{chunk-RN7OI5KL.js → chunk-PHHH2NQP.js} +14 -8
  50. package/dist/bundle/{chunk-KGOVFEWZ.js → chunk-PP3YOAWG.js} +2 -2
  51. package/dist/bundle/{chunk-YA45XV6G.js → chunk-PQMJ5BXH.js} +4 -4
  52. package/dist/bundle/{chunk-NWKKPDZV.js → chunk-QB3DP2TN.js} +1 -1
  53. package/dist/bundle/{chunk-BFQQV22T.js → chunk-QQUY4MZY.js} +1 -1
  54. package/dist/bundle/{chunk-VNKWSCN7.js → chunk-S2QRAKQI.js} +16 -16
  55. package/dist/bundle/{chunk-6VV7J2TN.js → chunk-SMTBV62X.js} +31 -26
  56. package/dist/bundle/{chunk-A6J4MPTI.js → chunk-T27IMG6X.js} +1 -1
  57. package/dist/bundle/{chunk-FNLUKODV.js → chunk-TY644DKQ.js} +1 -1
  58. package/dist/bundle/{chunk-3KSK5BBB.js → chunk-U6IQ6YQ2.js} +1 -1
  59. package/dist/bundle/{chunk-PT6MF2VU.js → chunk-VFU7PVPQ.js} +336 -106
  60. package/dist/bundle/{chunk-QVMOEB3I.js → chunk-VL6H2BND.js} +13 -13
  61. package/dist/bundle/{chunk-OQW6GHUA.js → chunk-WOAYHCM2.js} +1 -1
  62. package/dist/bundle/{chunk-TLEBSMC7.js → chunk-WX6OYVCH.js} +3968 -3527
  63. package/dist/bundle/{chunk-C3NYJW6B.js → chunk-XMDEM6BZ.js} +631 -79
  64. package/dist/bundle/{chunk-AUTX2MLF.js → chunk-XQYKIZMG.js} +11 -9
  65. package/dist/bundle/{chunk-KV4VTKF3.js → chunk-YNS2YVUR.js} +68 -5
  66. package/dist/bundle/{chunk-JWMLMAHP.js → chunk-Z5T6OW3V.js} +13 -4
  67. package/dist/bundle/command-contract-XSW2Q33S.js +36 -0
  68. package/dist/bundle/{command-server-entry-5E3PPDE5.js → command-server-entry-XMSSY5ID.js} +23 -22
  69. package/dist/bundle/{decode-AVWV7SVZ.js → decode-RYGB4PGT.js} +4 -4
  70. package/dist/bundle/{dispatch-BXPHSNK5.js → dispatch-PLQOIZG5.js} +1 -1
  71. package/dist/bundle/{dist-PIOOKBWT.js → dist-GY2AQETI.js} +23 -16
  72. package/dist/bundle/{echarts-7K6YQV52.js → echarts-7CM2MCMW.js} +2 -2
  73. package/dist/bundle/{embed-4NT76GJK.js → embed-FTBDPOPT.js} +5 -5
  74. package/dist/bundle/{embedder-ITQFF7EN.js → embedder-B43WGNBD.js} +8 -8
  75. package/dist/bundle/{failure-3Q65JOPD.js → failure-XP5QYV2T.js} +1 -1
  76. package/dist/bundle/{first-run-PM74YU4X.js → first-run-XIIUARNM.js} +9 -8
  77. package/dist/bundle/first-screen-Z7HC6PQU.js +34 -0
  78. package/dist/bundle/{instructions-JDSITYHV.js → instructions-R7OHVAWH.js} +1 -1
  79. package/dist/bundle/mail.js +5 -5
  80. package/dist/bundle/{node-D6YIJOJI.js → node-3N2JGZ7V.js} +2 -2
  81. package/dist/bundle/{node-sqlite-PJOHHB4X.js → node-sqlite-WFJXW3CZ.js} +9 -5
  82. package/dist/bundle/{oauth-BOWJ3IBT.js → oauth-SVJLQTWV.js} +6 -6
  83. package/dist/bundle/{open-FIAKKZMW.js → open-ZDONVKSX.js} +4 -4
  84. package/dist/bundle/{openai-QL54VVLC.js → openai-XVEW6XOU.js} +17 -13
  85. package/dist/bundle/{process-AYHK7WRC.js → process-YAHHUFR5.js} +1 -1
  86. package/dist/bundle/{program-6FKWOTBK.js → program-HU2UVMJE.js} +5742 -5008
  87. package/dist/bundle/{prompt-XJZCBELC.js → prompt-JAJ2CUJI.js} +4 -4
  88. package/dist/bundle/{recognize-OQKWAHBY.js → recognize-UFBWUNFR.js} +3 -3
  89. package/dist/bundle/{remote-NLVUZ5WK.js → remote-2GFOVLCR.js} +8 -6
  90. package/dist/bundle/{rerank-NRPZDTJ7.js → rerank-BGPSMXTL.js} +6 -6
  91. package/dist/bundle/{serve-O4YUI7F6.js → serve-CB3XJTH3.js} +8 -8
  92. package/dist/bundle/server-34GEF22R.js +68 -0
  93. package/dist/bundle/{server-WAL3M4OO.js → server-M7FQY7TX.js} +38 -36
  94. package/dist/bundle/{sqlite-runtime-5YHGI4D4.js → sqlite-runtime-AEV6PGDR.js} +5 -5
  95. package/dist/bundle/{state-WYYOJ7KK.js → state-YLBEQLBI.js} +5 -5
  96. package/dist/bundle/{store-6BJO3F2J.js → store-CDUL3HKK.js} +17 -14
  97. package/dist/bundle/{store-X72GOJHD.js → store-EKWKY6GG.js} +22 -17
  98. package/dist/bundle/store-maintenance-command-XH2JUM5F.js +58 -0
  99. package/dist/version.d.ts +1 -1
  100. package/dist/version.js +1 -1
  101. package/package.json +2 -2
  102. package/dist/bundle/chunk-B72343TK.js +0 -35
  103. package/dist/bundle/command-contract-ERYYPAD2.js +0 -35
  104. package/dist/bundle/first-screen-WBVGVSMY.js +0 -33
  105. package/dist/bundle/server-6OT5ZEWL.js +0 -66
  106. package/dist/bundle/store-maintenance-command-ASS7RBYC.js +0 -54
@@ -2,11 +2,11 @@ import { createRequire as __bundleRequire } from "node:module";
2
2
  const require = __bundleRequire(import.meta.url);
3
3
  import {
4
4
  renderMessages
5
- } from "./chunk-4QNHAM3J.js";
5
+ } from "./chunk-HEYVMAAQ.js";
6
6
  import {
7
7
  answerOf,
8
8
  messengerContext
9
- } from "./chunk-QI3PXUOJ.js";
9
+ } from "./chunk-EXVY76VO.js";
10
10
  import {
11
11
  FETCHING,
12
12
  RULES_VERSION,
@@ -23,6 +23,7 @@ import {
23
23
  patiently,
24
24
  pollVoteAnswer,
25
25
  queryTerms,
26
+ refuseLockedOutput,
26
27
  senderIsMe,
27
28
  serveRelay,
28
29
  servicesFor,
@@ -30,17 +31,17 @@ import {
30
31
  typedQuery,
31
32
  withQuery,
32
33
  withTimeLimit
33
- } from "./chunk-TLEBSMC7.js";
34
+ } from "./chunk-WX6OYVCH.js";
34
35
  import {
35
36
  holdLock,
36
37
  lockPath,
37
38
  releaseLock,
38
39
  servingProfiles,
39
40
  takeLock
40
- } from "./chunk-YBQ5AYLZ.js";
41
+ } from "./chunk-PGC5TRH6.js";
41
42
  import {
42
43
  readSecret
43
- } from "./chunk-KGOVFEWZ.js";
44
+ } from "./chunk-PP3YOAWG.js";
44
45
  import {
45
46
  Command,
46
47
  LOCAL_READ,
@@ -49,6 +50,7 @@ import {
49
50
  REMOTE_WRITE,
50
51
  annotate,
51
52
  codeOf,
53
+ commandAt,
52
54
  destroysNothing,
53
55
  environmentOf,
54
56
  itemOf,
@@ -65,13 +67,13 @@ import {
65
67
  snakeKeys,
66
68
  storeTable,
67
69
  withoutProviderRefs
68
- } from "./chunk-FKWUUCX2.js";
70
+ } from "./chunk-KFB2X6KE.js";
69
71
  import {
70
72
  levelFor
71
- } from "./chunk-Q4OKEN3B.js";
73
+ } from "./chunk-DIA56CS7.js";
72
74
  import {
73
75
  holdersOf
74
- } from "./chunk-DW3F6DUW.js";
76
+ } from "./chunk-IACWKZWS.js";
75
77
  import {
76
78
  QUICK_HEALTH_CHECKS,
77
79
  fts5Tables,
@@ -79,7 +81,7 @@ import {
79
81
  lossUnknown,
80
82
  storeDamageReport,
81
83
  storeHealth
82
- } from "./chunk-VNKWSCN7.js";
84
+ } from "./chunk-S2QRAKQI.js";
83
85
  import {
84
86
  CORPORA,
85
87
  MIGRATIONS,
@@ -114,39 +116,51 @@ import {
114
116
  storeClients,
115
117
  storeContents,
116
118
  vectorIndexCounts
117
- } from "./chunk-XBEO472U.js";
119
+ } from "./chunk-A6BPOX5O.js";
118
120
  import {
119
121
  currentRun,
120
122
  readDamageMark,
121
123
  readHealthMark,
122
124
  readJournalMark,
123
125
  recordDeepCheck
124
- } from "./chunk-O373QEAJ.js";
126
+ } from "./chunk-MBFPFWCO.js";
125
127
  import {
126
128
  formatLocator,
127
129
  parseLocator,
128
130
  queryFieldsOf
129
- } from "./chunk-WOX7FZJP.js";
131
+ } from "./chunk-5ZYFV6FD.js";
130
132
  import {
131
133
  failureKey,
132
134
  isStoreDamage
133
- } from "./chunk-3KSK5BBB.js";
135
+ } from "./chunk-U6IQ6YQ2.js";
136
+ import {
137
+ modelAddressAllowed,
138
+ onThisComputer
139
+ } from "./chunk-K6HR6HCO.js";
140
+ import {
141
+ readSharedSection,
142
+ sharedConfigPath,
143
+ writeSharedSection
144
+ } from "./chunk-KK4HD3SI.js";
134
145
  import {
135
146
  storePath
136
- } from "./chunk-B72343TK.js";
147
+ } from "./chunk-LGZPKKBN.js";
137
148
  import {
138
149
  openCache
139
- } from "./chunk-U6MMQNNK.js";
150
+ } from "./chunk-37F6QYTO.js";
140
151
  import {
152
+ Credentials,
153
+ isMovedRun,
141
154
  resolvePaths,
142
155
  writeSecurely
143
- } from "./chunk-FNLUKODV.js";
156
+ } from "./chunk-TY644DKQ.js";
144
157
  import {
145
158
  array,
146
159
  boolean,
147
160
  check,
148
161
  forward,
149
162
  getDotPath,
163
+ maxLength,
150
164
  minLength,
151
165
  nullable,
152
166
  object,
@@ -161,7 +175,7 @@ import {
161
175
  string,
162
176
  transform,
163
177
  trim
164
- } from "./chunk-X7J3TTDO.js";
178
+ } from "./chunk-IZOYW4Z4.js";
165
179
  import {
166
180
  CliError
167
181
  } from "./chunk-VUBZFMGP.js";
@@ -5504,11 +5518,11 @@ var require_liquid_node = __commonJS({
5504
5518
  }
5505
5519
  });
5506
5520
 
5507
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5521
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
5508
5522
  import { chmodSync, constants, copyFileSync, existsSync as existsSync10, mkdirSync, realpathSync as realpathSync3, renameSync as renameSync3, rmSync as rmSync3, statfsSync as statfsSync2, statSync as statSync4, writeFileSync as writeFileSync2 } from "node:fs";
5509
5523
  import { dirname as dirname3, resolve } from "node:path";
5510
5524
 
5511
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/sealed.js
5525
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/sealed.js
5512
5526
  import { createCipheriv, createDecipheriv, createHash, randomBytes, scrypt, timingSafeEqual } from "node:crypto";
5513
5527
  import { closeSync, createReadStream, createWriteStream, existsSync, openSync, readSync, renameSync, rmSync, statSync } from "node:fs";
5514
5528
  import { Transform } from "node:stream";
@@ -5615,7 +5629,7 @@ var unsealFile = /* @__PURE__ */ __name(async (from, to, password) => {
5615
5629
  renameSync(pending, to);
5616
5630
  }, "unsealFile");
5617
5631
 
5618
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5632
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/compatibility.js
5619
5633
  var SPEAKS = MIGRATIONS.at(-1)?.version ?? 0;
5620
5634
  var fileSchemaOf = /* @__PURE__ */ __name((database) => {
5621
5635
  const tracked = database.prepare("SELECT 1 FROM sqlite_master WHERE name = 'schema_migrations'").get();
@@ -5639,7 +5653,7 @@ var compatibilityOf = /* @__PURE__ */ __name((file2, migrations = MIGRATIONS) =>
5639
5653
  };
5640
5654
  }, "compatibilityOf");
5641
5655
 
5642
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/repair.js
5656
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/repair.js
5643
5657
  import { createHash as createHash2 } from "node:crypto";
5644
5658
  var COPY_MARK = "__repair_";
5645
5659
  var COPY_NAME = /__repair_[0-9a-f]{8}(_\d+)?$/;
@@ -5893,19 +5907,19 @@ var deleteCopy = /* @__PURE__ */ __name((database, name) => {
5893
5907
  return found;
5894
5908
  }, "deleteCopy");
5895
5909
 
5896
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5910
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/store-info.js
5897
5911
  import { existsSync as existsSync4, statSync as statSync3 } from "node:fs";
5898
5912
 
5899
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5913
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
5900
5914
  import { existsSync as existsSync3 } from "node:fs";
5901
5915
 
5902
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/recover.js
5916
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/recover.js
5903
5917
  import { execFileSync, spawn } from "node:child_process";
5904
5918
  import { existsSync as existsSync2, readFileSync, realpathSync, renameSync as renameSync2, rmSync as rmSync2, statfsSync, statSync as statSync2, writeFileSync } from "node:fs";
5905
5919
  import { basename, dirname, join } from "node:path";
5906
5920
  import { Transform as Transform2 } from "node:stream";
5907
5921
 
5908
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/refill.js
5922
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/refill.js
5909
5923
  var REFILL_MARGIN_MS = 864e5;
5910
5924
  var TIME_KEYS = 1e12;
5911
5925
  var integerId = `external_id GLOB '[0-9]*' AND NOT external_id GLOB '*[^0-9]*'`;
@@ -5985,7 +5999,7 @@ var forgetMail = /* @__PURE__ */ __name((database, cutoff, now) => {
5985
5999
  return [...folders].map(([account, count3]) => ({ account, folders: count3 }));
5986
6000
  }, "forgetMail");
5987
6001
 
5988
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/store/recover.js
6002
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/store/recover.js
5989
6003
  var SQLITE3_MINIMUM = [3, 43, 0];
5990
6004
  var STORE_PARTS = ["", "-wal", "-shm"];
5991
6005
  var RECOVER_LOCK = ".recover-lock";
@@ -6513,7 +6527,7 @@ var recoverLocked = /* @__PURE__ */ __name(async ({ path, command, version, sqli
6513
6527
  }
6514
6528
  }, "recoverLocked");
6515
6529
 
6516
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6530
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/store-recover.js
6517
6531
  var COUNTED = [
6518
6532
  "accounts",
6519
6533
  "chats",
@@ -6669,7 +6683,7 @@ var storeRecoverCommand = /* @__PURE__ */ __name(({ command, version }) => {
6669
6683
  return recover;
6670
6684
  }, "storeRecoverCommand");
6671
6685
 
6672
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6686
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/store-info.js
6673
6687
  var pendingIfKnown = /* @__PURE__ */ __name((database) => database.prepare("SELECT 1 FROM pragma_table_info('messages') WHERE name = 'normalized_text'").get() ? pendingNormalization(database) : null, "pendingIfKnown");
6674
6688
  var bytesOf = /* @__PURE__ */ __name((path) => existsSync4(path) ? statSync3(path).size : 0, "bytesOf");
6675
6689
  var messageOf = /* @__PURE__ */ __name((error) => error instanceof Error ? error.message : String(error), "messageOf");
@@ -6715,7 +6729,7 @@ var storeInfoCommand = /* @__PURE__ */ __name(() => annotate(new Command("info")
6715
6729
  renderAnswer(this, outputFor(this), itemOf(answer));
6716
6730
  }), "storeInfoCommand");
6717
6731
 
6718
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6732
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/password.js
6719
6733
  var ENCRYPT_OPTION = [
6720
6734
  "--encrypt",
6721
6735
  "compress and encrypt with a password, typed at a hidden prompt or piped on stdin; it is never kept \u2014 lose it and the file cannot be opened"
@@ -6734,7 +6748,7 @@ var passwordOf = /* @__PURE__ */ __name(async (command, { twice }) => {
6734
6748
  return password;
6735
6749
  }, "passwordOf");
6736
6750
 
6737
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/rules.js
6751
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/rules.js
6738
6752
  import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
6739
6753
  import { join as join2 } from "node:path";
6740
6754
  var REPLY_ACTIONS = ["reply", "task"];
@@ -6905,7 +6919,7 @@ var problem = /* @__PURE__ */ __name((issue) => {
6905
6919
  }, "problem");
6906
6920
  var broken = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply rules ${path} cannot be read (${why}) \u2014 fix the file`), "broken");
6907
6921
 
6908
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/state.js
6922
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/state.js
6909
6923
  import { existsSync as existsSync6, readFileSync as readFileSync3 } from "node:fs";
6910
6924
  import { join as join3 } from "node:path";
6911
6925
  var ANSWERED_KEPT = 1e3;
@@ -6958,7 +6972,7 @@ var recordReply = /* @__PURE__ */ __name((state, rule2, message, now) => {
6958
6972
  }, "recordReply");
6959
6973
  var broken2 = /* @__PURE__ */ __name((path, why) => new CliError("configuration_error", `the reply state ${path} cannot be read (${why}) \u2014 fix or move the file`), "broken");
6960
6974
 
6961
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/decide.js
6975
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/decide.js
6962
6976
  var skip = /* @__PURE__ */ __name((why) => ({ skip: why }), "skip");
6963
6977
  var decide = /* @__PURE__ */ __name((rule2, incoming, state, now) => {
6964
6978
  const { message, chat, owner, sender } = incoming;
@@ -7064,10 +7078,10 @@ var filled = /* @__PURE__ */ __name((template2, senderName) => {
7064
7078
  return template2.replaceAll("{firstName}", name.split(/\s+/)[0] ?? name).replaceAll("{name}", name);
7065
7079
  }, "filled");
7066
7080
 
7067
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/template.js
7081
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/template.js
7068
7082
  var import_liquidjs2 = __toESM(require_liquid_node(), 1);
7069
7083
 
7070
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/render/liquid.js
7084
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/render/liquid.js
7071
7085
  var import_liquidjs = __toESM(require_liquid_node(), 1);
7072
7086
  var safeLiquid = /* @__PURE__ */ __name((limits) => {
7073
7087
  const engine = new import_liquidjs.Liquid({
@@ -7094,7 +7108,7 @@ var safeLiquid = /* @__PURE__ */ __name((limits) => {
7094
7108
  return engine;
7095
7109
  }, "safeLiquid");
7096
7110
 
7097
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/template.js
7111
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/template.js
7098
7112
  var TEMPLATE_LIMITS = {
7099
7113
  parse: 32768,
7100
7114
  renders: 2e3,
@@ -7233,7 +7247,7 @@ var renderReplyTemplate = /* @__PURE__ */ __name(async (reply, input) => {
7233
7247
  }
7234
7248
  }, "renderReplyTemplate");
7235
7249
 
7236
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
7250
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/dry-run.js
7237
7251
  var DRY_RUN_DAYS = 7;
7238
7252
  var PAGE = 500;
7239
7253
  var dryRun = /* @__PURE__ */ __name(async (store, account, rules, { since, until = Date.now(), only, audience, render }) => {
@@ -7347,7 +7361,178 @@ var storedSince = /* @__PURE__ */ __name(async (store, account, chat, since) =>
7347
7361
  }
7348
7362
  }, "storedSince");
7349
7363
 
7350
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/consents.js
7364
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/models/ai.js
7365
+ var AI_PROVIDERS = ["anthropic", "openai", "ollama"];
7366
+ var DEFAULT_BASE_URL = {
7367
+ anthropic: "https://api.anthropic.com",
7368
+ openai: "https://api.openai.com/v1",
7369
+ ollama: "http://127.0.0.1:11434/v1"
7370
+ };
7371
+ var OFFICIAL = {
7372
+ "https://api.openai.com": "openai",
7373
+ "https://api.anthropic.com": "anthropic"
7374
+ };
7375
+ var SECTION = "ai";
7376
+ var aiAddressAllowed = modelAddressAllowed;
7377
+ var consentShape = strictObject({
7378
+ origin: string(),
7379
+ model: string(),
7380
+ at: string()
7381
+ });
7382
+ var settingShape = strictObject({
7383
+ provider: picklist(AI_PROVIDERS),
7384
+ model: pipe(string(), trim(), minLength(1), maxLength(200)),
7385
+ base_url: optional(pipe(string(), check(aiAddressAllowed, "use https, or http only on this computer"))),
7386
+ images: optional(consentShape)
7387
+ });
7388
+ var aiSettingPath = /* @__PURE__ */ __name((env) => sharedConfigPath(storePath(env), env), "aiSettingPath");
7389
+ var readAiSetting = /* @__PURE__ */ __name((path) => {
7390
+ const section = readSharedSection(path, SECTION);
7391
+ if (section === void 0)
7392
+ return void 0;
7393
+ const checked = safeParse(settingShape, section);
7394
+ if (!checked.success)
7395
+ throw new CliError("configuration_error", `${path}: ai.${getDotPath(checked.issues[0]) ?? "setting"} is invalid`, {
7396
+ reason: "ai.setting-invalid"
7397
+ });
7398
+ return checked.output;
7399
+ }, "readAiSetting");
7400
+ var writeAiSetting = /* @__PURE__ */ __name((path, setting) => writeSharedSection(path, SECTION, setting), "writeAiSetting");
7401
+ var aiSettingOf = /* @__PURE__ */ __name((given) => {
7402
+ const draft = {
7403
+ provider: given.provider,
7404
+ model: given.model,
7405
+ ...given.baseUrl?.trim() ? { base_url: given.baseUrl.trim().replace(/\/+$/, "") } : {}
7406
+ };
7407
+ const checked = safeParse(settingShape, draft);
7408
+ if (!checked.success) {
7409
+ const field = getDotPath(checked.issues[0]);
7410
+ throw new CliError("validation_error", field === "provider" ? `the provider is one of ${AI_PROVIDERS.join(", ")}` : field === "base_url" ? "this address is not allowed: use https, or http only on this computer" : "name the model, 1 to 200 characters", { reason: field === "base_url" ? "ai.address-refused" : "ai.setting-invalid" });
7411
+ }
7412
+ if (checked.output.provider === "ollama" && !onThisComputer(aiBaseUrl(checked.output)))
7413
+ throw new CliError("validation_error", "Ollama is read only on this computer", { reason: "ai.address-refused" });
7414
+ return given.allowImages ? {
7415
+ ...checked.output,
7416
+ images: { origin: aiOrigin(checked.output), model: checked.output.model, at: (/* @__PURE__ */ new Date()).toISOString() }
7417
+ } : checked.output;
7418
+ }, "aiSettingOf");
7419
+ var aiBaseUrl = /* @__PURE__ */ __name((setting) => setting.base_url ?? DEFAULT_BASE_URL[setting.provider], "aiBaseUrl");
7420
+ var aiOrigin = /* @__PURE__ */ __name((setting) => new URL(aiBaseUrl(setting)).origin, "aiOrigin");
7421
+ var aiTarget = /* @__PURE__ */ __name((setting) => ({
7422
+ provider: setting.provider === "anthropic" ? "anthropic" : "openai",
7423
+ model: setting.model,
7424
+ baseUrl: aiBaseUrl(setting)
7425
+ }), "aiTarget");
7426
+ var aiImagesAllowed = /* @__PURE__ */ __name((setting) => setting.images?.origin === aiOrigin(setting) && setting.images.model === setting.model, "aiImagesAllowed");
7427
+ var aiKeys = /* @__PURE__ */ __name((app, env, keyring) => {
7428
+ const where = { appName: "WireCat", prefix: "WIRECAT", env };
7429
+ const credentials = new Credentials({
7430
+ configDir: resolvePaths(where).config,
7431
+ service: "WireCat",
7432
+ // A tool run with its own folders moved (MEMO_CONFIG_DIR…) is a test or a sandbox, not the owner.
7433
+ isolated: isMovedRun(where) || isMovedRun({ appName: app.appName, prefix: app.envPrefix, env }),
7434
+ env,
7435
+ ...keyring ? { keyring } : {},
7436
+ warn: /* @__PURE__ */ __name((message) => process.stderr.write(`${message}
7437
+ `), "warn")
7438
+ });
7439
+ const account = /* @__PURE__ */ __name((origin) => `ai:${origin}`, "account");
7440
+ return {
7441
+ read: /* @__PURE__ */ __name((origin) => {
7442
+ const stored = credentials.read(account(origin));
7443
+ if (stored)
7444
+ return { key: stored.secret, source: stored.source };
7445
+ const official = OFFICIAL[origin];
7446
+ const legacy = official ?? (origin.startsWith("https://") ? endpointKeyName(origin) : void 0);
7447
+ const found = legacy === void 0 ? void 0 : embeddingKeys(app, env, keyring).read(legacy);
7448
+ return found ? { key: found.key, source: found.source === "env" ? "environment" : found.source } : void 0;
7449
+ }, "read"),
7450
+ write: /* @__PURE__ */ __name((origin, key) => credentials.write(account(origin), key, { signIn: true }), "write"),
7451
+ remove: /* @__PURE__ */ __name((origin) => credentials.remove(account(origin)), "remove")
7452
+ };
7453
+ }, "aiKeys");
7454
+ var aiNeedsKey = /* @__PURE__ */ __name((setting) => aiLeavesComputer(setting), "aiNeedsKey");
7455
+ var aiTakesKey = /* @__PURE__ */ __name((setting) => setting.provider !== "ollama", "aiTakesKey");
7456
+ var keyFor = /* @__PURE__ */ __name((setting, deps) => aiTakesKey(setting) ? aiKeys(deps.app, deps.env, deps.keyring).read(aiOrigin(setting))?.key : void 0, "keyFor");
7457
+ var gatewayFor = /* @__PURE__ */ __name((setting, deps, key) => modelGateway({
7458
+ resolve: /* @__PURE__ */ __name(() => aiTarget(setting), "resolve"),
7459
+ consent: /* @__PURE__ */ __name(() => true, "consent"),
7460
+ key: /* @__PURE__ */ __name(() => key, "key"),
7461
+ env: deps.env,
7462
+ ...deps.fetch ? { fetch: deps.fetch } : {},
7463
+ ...deps.signal ? { signal: deps.signal } : {}
7464
+ }), "gatewayFor");
7465
+ var aiLeavesComputer = /* @__PURE__ */ __name((setting) => !onThisComputer(aiBaseUrl(setting)), "aiLeavesComputer");
7466
+ var sharedModel = /* @__PURE__ */ __name((deps) => {
7467
+ const setting = readAiSetting(aiSettingPath(deps.env));
7468
+ if (!setting)
7469
+ return void 0;
7470
+ return { target: { ...aiTarget(setting), baseUrl: aiBaseUrl(setting) }, key: keyFor(setting, deps), setting };
7471
+ }, "sharedModel");
7472
+ var reasonOf = /* @__PURE__ */ __name((error) => {
7473
+ if (!(error instanceof CliError))
7474
+ return "ai.failed";
7475
+ if (error.code === "rate_limited")
7476
+ return "ai.rate-limited";
7477
+ const { reason, status } = error.details;
7478
+ if (reason === "model.key-rejected")
7479
+ return "ai.key-rejected";
7480
+ if (reason === "model.unreachable")
7481
+ return "ai.unreachable";
7482
+ if (reason === "model.empty-answer")
7483
+ return "ai.empty-answer";
7484
+ if (status === 402)
7485
+ return "ai.no-credit";
7486
+ if (status === 404)
7487
+ return "ai.model-unknown";
7488
+ if (typeof status === "number" && status >= 500)
7489
+ return "ai.provider-error";
7490
+ return "ai.failed";
7491
+ }, "reasonOf");
7492
+ var checkAi = /* @__PURE__ */ __name(async (deps) => {
7493
+ const setting = readAiSetting(aiSettingPath(deps.env));
7494
+ if (!setting)
7495
+ return { ok: false, reason: "ai.not-set", ms: null };
7496
+ const key = keyFor(setting, deps);
7497
+ if (aiNeedsKey(setting) && !key)
7498
+ return { ok: false, reason: "ai.key-missing", ms: null };
7499
+ const started = Date.now();
7500
+ try {
7501
+ await gatewayFor(setting, deps, key).complete({
7502
+ purpose: "check",
7503
+ system: "Reply with the word OK.",
7504
+ prompt: "OK?",
7505
+ // Reasoning models spend tokens before they answer; too low a cap reads as a broken setup.
7506
+ maxTokens: 2048
7507
+ });
7508
+ return { ok: true, reason: "ai.ok", ms: Date.now() - started };
7509
+ } catch (error) {
7510
+ return { ok: false, reason: reasonOf(error), ms: null };
7511
+ }
7512
+ }, "checkAi");
7513
+
7514
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/models/purpose.js
7515
+ var HOSTED = {
7516
+ openai: "https://api.openai.com/v1",
7517
+ anthropic: "https://api.anthropic.com"
7518
+ };
7519
+ var purposeModel = /* @__PURE__ */ __name((settings, purpose, deps) => {
7520
+ const configured = modelTarget(settings, purpose);
7521
+ if (configured) {
7522
+ const baseUrl = configured.baseUrl ?? HOSTED[configured.provider] ?? "";
7523
+ return {
7524
+ target: { ...configured, baseUrl },
7525
+ key: /* @__PURE__ */ __name(() => embeddingKeys(deps.app, deps.env, deps.keyring).read(configured.baseUrl === void 0 ? configured.provider : endpointKeyName(configured.baseUrl))?.key, "key")
7526
+ };
7527
+ }
7528
+ const provider = settings.models?.[purpose]?.provider ?? settings.models?.default?.provider;
7529
+ if (provider === "off")
7530
+ return void 0;
7531
+ const shared = sharedModel(deps);
7532
+ return shared ? { target: shared.target, key: /* @__PURE__ */ __name(() => shared.key, "key"), shared: shared.setting } : void 0;
7533
+ }, "purposeModel");
7534
+
7535
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/consents.js
7351
7536
  import { existsSync as existsSync7, readFileSync as readFileSync4 } from "node:fs";
7352
7537
  import { join as join4 } from "node:path";
7353
7538
  var shape = strictObject({
@@ -7372,19 +7557,21 @@ var mayModelReply = /* @__PURE__ */ __name((path, provider, chat) => {
7372
7557
  return consent.provider === provider && !consent.deniedChats.includes(chat);
7373
7558
  }, "mayModelReply");
7374
7559
 
7375
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7560
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/rendering.js
7376
7561
  var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, options = {
7377
7562
  ai: true
7378
7563
  }) => async (rule2, message, chat, now) => {
7564
+ const deps = { app, env, keyring: options.keyring };
7379
7565
  let called;
7380
7566
  const gateway = modelGateway({
7381
7567
  signal: options.signal,
7568
+ env,
7382
7569
  resolve: /* @__PURE__ */ __name((purpose) => {
7383
- called = modelTarget(settings(), purpose);
7384
- return called;
7570
+ called = purposeModel(settings(), purpose, deps);
7571
+ return called?.target;
7385
7572
  }, "resolve"),
7386
7573
  consent: /* @__PURE__ */ __name((_request, target) => mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(target.provider, target.baseUrl ?? ""), message.chatId), "consent"),
7387
- key: /* @__PURE__ */ __name((provider, target) => embeddingKeys(app, env, options.keyring).read(target.baseUrl === void 0 ? provider : endpointKeyName(target.baseUrl))?.key, "key")
7574
+ key: /* @__PURE__ */ __name(() => called?.key(), "key")
7388
7575
  });
7389
7576
  if (options.signal?.aborted)
7390
7577
  throw new CliError("cancelled", "reply rendering cancelled");
@@ -7406,9 +7593,8 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7406
7593
  });
7407
7594
  if (options.signal?.aborted)
7408
7595
  throw new CliError("cancelled", "reply rendering cancelled");
7409
- const current = modelTarget(settings(), "replies");
7410
- const baseUrl = called?.baseUrl ?? (called?.provider === "anthropic" ? "https://api.anthropic.com" : "https://api.openai.com/v1");
7411
- if (!called || JSON.stringify(current) !== JSON.stringify(called) || !mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(called.provider, baseUrl), message.chatId)) {
7596
+ const current = purposeModel(settings(), "replies", deps)?.target;
7597
+ if (!called || JSON.stringify(current) !== JSON.stringify(called.target) || !mayModelReply(replyConsentPathFor(app, profile, env), replyModelIdentity(called.target.provider, called.target.baseUrl), message.chatId)) {
7412
7598
  throw new CliError("permission_error", "reply model consent or configuration changed during rendering");
7413
7599
  }
7414
7600
  return result3;
@@ -7419,7 +7605,7 @@ var replyRenderer = /* @__PURE__ */ __name((app, profile, settings, env, warn, o
7419
7605
  return result2;
7420
7606
  }, "replyRenderer");
7421
7607
 
7422
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/replies/serve.js
7608
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/replies/serve.js
7423
7609
  var NOT_ALLOWED = "replies.send is not allow";
7424
7610
  var NO_RULES = "no rules";
7425
7611
  var ONLY_TASK = "opened a task, sent nothing";
@@ -7512,7 +7698,7 @@ var replyTo = /* @__PURE__ */ __name(async (deps, message) => {
7512
7698
  return { skip: why };
7513
7699
  }, "replyTo");
7514
7700
 
7515
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7701
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-catch-up.js
7516
7702
  var START_SYNC_DELAY_MS = 3e4;
7517
7703
  var START_SYNC_BUDGET_MS = 5 * 6e4;
7518
7704
  var START_SYNC_WINDOW_MS = 7 * 864e5;
@@ -7589,7 +7775,7 @@ var startSync = /* @__PURE__ */ __name(({ chats, newestHeld, fetch, note, warn,
7589
7775
  };
7590
7776
  }, "startSync");
7591
7777
 
7592
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7778
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-members.js
7593
7779
  var FIRST_FETCH_MS = 6e4;
7594
7780
  var DAY_MS = 864e5;
7595
7781
  var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs = FIRST_FETCH_MS, everyMs = DAY_MS }) => {
@@ -7643,7 +7829,7 @@ var memberFetches = /* @__PURE__ */ __name(({ withStore, fetch, warn, firstMs =
7643
7829
  };
7644
7830
  }, "memberFetches");
7645
7831
 
7646
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7832
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-notice.js
7647
7833
  var record2 = /* @__PURE__ */ __name((context, app, severity, attributes) => recordLogFor(context.streams.diagnostic, app, { command: currentRun().command || "serve" })[severity](attributes), "record");
7648
7834
  var noticeFor = /* @__PURE__ */ __name((context, app, severity = "warn") => ({ text, ...attributes }) => {
7649
7835
  if (context.format === "pretty") {
@@ -7676,7 +7862,7 @@ var recordDiagnostics = /* @__PURE__ */ __name((context, app) => {
7676
7862
  return context;
7677
7863
  }, "recordDiagnostics");
7678
7864
 
7679
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-outdated.js
7865
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-outdated.js
7680
7866
  import { existsSync as existsSync8, readFileSync as readFileSync5, realpathSync as realpathSync2 } from "node:fs";
7681
7867
  import { dirname as dirname2, join as join5 } from "node:path";
7682
7868
  var OUTDATED_CHECK_MS = 6e4;
@@ -7762,7 +7948,7 @@ var watchOutdated = /* @__PURE__ */ __name(({ check: check2, onOutdated, everyMs
7762
7948
  };
7763
7949
  }, "watchOutdated");
7764
7950
 
7765
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7951
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-stems.js
7766
7952
  var STEMS_EVERY_MS = 3e4;
7767
7953
  var STEMS_SLICE_MS = 2e3;
7768
7954
  var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY_MS, sliceMs = STEMS_SLICE_MS }) => {
@@ -7802,7 +7988,7 @@ var stemFills = /* @__PURE__ */ __name(({ withStore, warn, everyMs = STEMS_EVERY
7802
7988
  };
7803
7989
  }, "stemFills");
7804
7990
 
7805
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7991
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/message-items.js
7806
7992
  var defined = /* @__PURE__ */ __name((value) => Object.fromEntries(Object.entries(value).filter(([, one]) => one !== void 0)), "defined");
7807
7993
  var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7808
7994
  kind: attachment.kind,
@@ -7814,6 +8000,7 @@ var attachmentItem = /* @__PURE__ */ __name((attachment) => defined({
7814
8000
  width: attachment.width,
7815
8001
  height: attachment.height,
7816
8002
  duration: attachment.duration,
8003
+ local_path: attachment.localPath,
7817
8004
  contact: attachment.contact && defined({
7818
8005
  name: attachment.contact.name,
7819
8006
  first_name: attachment.contact.firstName,
@@ -7897,7 +8084,7 @@ var viewOf = /* @__PURE__ */ __name((context, messenger) => ({
7897
8084
  locale: messenger.app.locale
7898
8085
  }), "viewOf");
7899
8086
 
7900
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
8087
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-answers.js
7901
8088
  var observed = /* @__PURE__ */ __name((value) => ({
7902
8089
  value: value.value,
7903
8090
  observed_at: value.observedAt,
@@ -7964,7 +8151,7 @@ var watchEventItem = /* @__PURE__ */ __name((value, account) => {
7964
8151
  }
7965
8152
  }, "watchEventItem");
7966
8153
 
7967
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
8154
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/watch-command.js
7968
8155
  var watchCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("watch"), {
7969
8156
  output: { entity: "watch_item" },
7970
8157
  effects: REMOTE_READ,
@@ -8119,7 +8306,7 @@ var describe = /* @__PURE__ */ __name((event, render) => {
8119
8306
  }
8120
8307
  }, "describe");
8121
8308
 
8122
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8309
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/serve-command.js
8123
8310
  var serveCommand = /* @__PURE__ */ __name((messenger) => {
8124
8311
  const command = annotate(new Command("serve"), {
8125
8312
  output: { entity: "serve_summary" },
@@ -8402,7 +8589,7 @@ var tasking = /* @__PURE__ */ __name((context, warn) => {
8402
8589
  };
8403
8590
  }, "tasking");
8404
8591
 
8405
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8592
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/store-tables-command.js
8406
8593
  import { existsSync as existsSync9 } from "node:fs";
8407
8594
  var PATH = "store tables list";
8408
8595
  var STORE_TABLES_QUERY = {
@@ -8419,14 +8606,14 @@ var filterOf = /* @__PURE__ */ __name((words) => {
8419
8606
  const kind = terms.get("kind");
8420
8607
  return { ...name === void 0 ? {} : { name }, ...kind === void 0 ? {} : { kind } };
8421
8608
  }, "filterOf");
8422
- var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8423
- const tables = new Command("tables").description("the tables of the local archive");
8609
+ var storeTablesCommand = /* @__PURE__ */ __name((owner) => {
8610
+ const tables = new Command("tables").description("the tables of the local store");
8424
8611
  withQuery(annotate(tables.command("list"), {
8425
8612
  effects: LOCAL_READ,
8426
8613
  examples: [
8427
- `${messenger.app.command} store tables list`,
8428
- `${messenger.app.command} store tables list kind:data`,
8429
- `${messenger.app.command} store tables list --full --json`
8614
+ `${owner.app.command} store tables list`,
8615
+ `${owner.app.command} store tables list kind:data`,
8616
+ `${owner.app.command} store tables list --full --json`
8430
8617
  ]
8431
8618
  }), STORE_TABLES_QUERY).summary("every table of the local archive, with its kind and row count").description("every table of the local archive: its kind (data, search index, part of a search index, internal) and its rows, a search index's rows not counted; --full adds each table's size on disk, which reads the whole file (about ten seconds for 3 GB); changes nothing").action(async function(words) {
8432
8619
  const filter = filterOf(words);
@@ -8445,7 +8632,7 @@ var storeTablesCommand = /* @__PURE__ */ __name((messenger) => {
8445
8632
  return tables;
8446
8633
  }, "storeTablesCommand");
8447
8634
 
8448
- // node_modules/.pnpm/@wirecat+cli-core@0.630.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_4dc2b7e09a64a37f199c7e635efe1b87/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8635
+ // node_modules/.pnpm/@wirecat+cli-core@0.647.0_@wirecat+cli-base@0.93.0_commander@15.0.0_esbuild@0.28.2_type_a46df5420a4458268e3f15f3e8c41b99/node_modules/@wirecat/cli-core/dist/cli/messenger/store-maintenance-command.js
8449
8636
  var SEARCH_INDEXES = ["messages_fts", "chats_fts", "identities_fts"];
8450
8637
  var WORD_INDEX = "message_words";
8451
8638
  var schemaOf = /* @__PURE__ */ __name((database) => {
@@ -8530,27 +8717,52 @@ var storeSummary = /* @__PURE__ */ __name(async (env, { deep = false, command, v
8530
8717
  }
8531
8718
  }, "storeSummary");
8532
8719
  var result = /* @__PURE__ */ __name((command, value, next = []) => renderAnswer(command, outputFor(command), itemOf(snakeKeys(value), { next })), "result");
8533
- var storeMaintenanceCommands = /* @__PURE__ */ __name((messenger) => [
8720
+ var chatty = /* @__PURE__ */ __name((owner) => owner.provider !== void 0, "chatty");
8721
+ var archive = /* @__PURE__ */ __name((owner) => chatty(owner) ? "local archive" : "local store", "archive");
8722
+ var createdBy = /* @__PURE__ */ __name((owner) => chatty(owner) ? `the first \`${owner.app.command}\` command that reads a chat creates it` : `the first \`${owner.app.command}\` command that saves anything creates it`, "createdBy");
8723
+ var storeMaintenanceCommands = /* @__PURE__ */ __name((owner) => [
8534
8724
  storeInfoCommand(),
8535
- checkCommand(messenger),
8536
- migrateCommand(messenger),
8537
- reindexCommand(messenger),
8725
+ checkCommand(owner),
8726
+ migrateCommand(owner),
8727
+ reindexCommand(owner),
8538
8728
  backupCommand(),
8539
- restoreCommand(messenger),
8729
+ restoreCommand(owner),
8540
8730
  decryptCommand(),
8541
- repairCommand(messenger),
8542
- resetCommand(messenger),
8731
+ repairCommand(owner),
8732
+ resetCommand(owner),
8543
8733
  copiesCommand(),
8544
- storeTablesCommand(messenger),
8545
- storeRecoverCommand({ command: messenger.app.command, version: messenger.app.version })
8734
+ storeTablesCommand(owner),
8735
+ storeRecoverCommand({ command: owner.app.command, version: owner.app.version })
8546
8736
  ], "storeMaintenanceCommands");
8547
- var refuseWhileServing = /* @__PURE__ */ __name((command, messenger) => {
8548
- const serving = servingProfiles(messenger.app, environmentOf(command).env ?? process.env);
8737
+ var EXAMPLES = {
8738
+ backup: "./backup.db",
8739
+ check: "",
8740
+ "copies delete": "messages_copy_1",
8741
+ decrypt: "./backup.enc --output ./restored.db",
8742
+ info: "",
8743
+ migrate: "",
8744
+ rebuild: "",
8745
+ repair: "--dry-run",
8746
+ reset: "",
8747
+ restore: "./backup.db"
8748
+ };
8749
+ var addStoreMaintenanceCommands = /* @__PURE__ */ __name((store, owner, profile) => {
8750
+ for (const command of storeMaintenanceCommands(owner))
8751
+ store.addCommand(command);
8752
+ for (const [path, args] of Object.entries(EXAMPLES)) {
8753
+ const command = commandAt(store, path);
8754
+ if (command)
8755
+ annotate(command, { examples: [`${owner.app.command} ${profile} store ${path} ${args}`.trimEnd()] });
8756
+ }
8757
+ return store;
8758
+ }, "addStoreMaintenanceCommands");
8759
+ var refuseWhileServing = /* @__PURE__ */ __name((command, owner) => {
8760
+ const serving = servingProfiles(owner.app, environmentOf(command).env ?? process.env);
8549
8761
  if (serving.length > 0) {
8550
- throw new CliError("validation_error", `${messenger.app.command} serve is running for ${serving.join(", ")} \u2014 ${serving.map((profile) => `\`${messenger.app.command} ${profile} server stop\``).join(", ")} first`);
8762
+ throw new CliError("validation_error", `${owner.app.command} serve is running for ${serving.join(", ")} \u2014 ${serving.map((profile) => `\`${owner.app.command} ${profile} server stop\``).join(", ")} first`);
8551
8763
  }
8552
8764
  }, "refuseWhileServing");
8553
- var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("repair"), { output: { entity: "store_repair" }, effects: LOCAL_WRITE }).summary("repair table shapes while keeping the old tables").description("bring every table to this build's shape, deleting nothing: a table of the wrong shape is kept as a copy beside a new one").option("--dry-run", "say what it would do, and change nothing").action(async function() {
8765
+ var repairCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("repair"), { output: { entity: "store_repair" }, effects: LOCAL_WRITE }).summary("repair table shapes while keeping the old tables").description("bring every table to this build's shape, deleting nothing: a table of the wrong shape is kept as a copy beside a new one").option("--dry-run", "say what it would do, and change nothing").action(async function() {
8554
8766
  const { renderer, format } = outputFor(this);
8555
8767
  const { dryRun: dryRun2 } = this.opts();
8556
8768
  const path = storePath(environmentOf(this).env ?? process.env);
@@ -8559,13 +8771,13 @@ var repairCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("
8559
8771
  return;
8560
8772
  }
8561
8773
  if (!dryRun2)
8562
- refuseWhileServing(this, messenger);
8774
+ refuseWhileServing(this, owner);
8563
8775
  const fresh = await openCache(":memory:");
8564
8776
  try {
8565
8777
  const report = await reading(path, (database) => repairStore(database, fresh, { dryRun: dryRun2 === true }));
8566
8778
  result(this, { path, ...report });
8567
8779
  if (format === "pretty")
8568
- for (const note of notesOf(report, messenger.app.command))
8780
+ for (const note of notesOf(report, owner.app.command))
8569
8781
  renderer.note(note);
8570
8782
  } finally {
8571
8783
  fresh.close();
@@ -8599,7 +8811,7 @@ var copiesCommand = /* @__PURE__ */ __name(() => new Command("copies").descripti
8599
8811
  const deleted = await reading(path, (database) => deleteCopy(database, name));
8600
8812
  result(this, { path, deleted });
8601
8813
  })), "copiesCommand");
8602
- var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("check"), { output: { entity: "store_check" }, effects: LOCAL_READ }).summary("check the local archive for problems").description("whether the store is healthy \u2014 integrity, search indexes, disk, and which chats are behind").action(async function() {
8814
+ var checkCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("check"), { output: { entity: "store_check" }, effects: LOCAL_READ }).summary(`check the ${archive(owner)} for problems`).description(`whether the store is healthy \u2014 integrity, search indexes, disk${chatty(owner) ? ", and which chats are behind" : ""}`).action(async function() {
8603
8815
  const { renderer } = outputFor(this);
8604
8816
  const path = storePath(environmentOf(this).env ?? process.env);
8605
8817
  if (!existsSync10(path)) {
@@ -8613,7 +8825,7 @@ var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("c
8613
8825
  result(this, { path, exists: true, ok: false, opens: false, error: messageOf2(error) });
8614
8826
  return;
8615
8827
  }
8616
- const { command } = messenger.app;
8828
+ const { command } = owner.app;
8617
8829
  const next = /* @__PURE__ */ new Map();
8618
8830
  const step = /* @__PURE__ */ __name((id, args = {}) => {
8619
8831
  if (!next.has(id))
@@ -8629,10 +8841,10 @@ var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("c
8629
8841
  step("store.reindex");
8630
8842
  else if (stems && !stems.ready)
8631
8843
  step("store.migrate");
8632
- const behind = answer.chatsBehind.find((chat) => chat.provider === messenger.provider);
8633
- if (behind && messenger.history !== "store")
8844
+ const behind = answer.chatsBehind.find((chat) => chat.provider === owner.provider);
8845
+ if (behind && owner.history !== "store")
8634
8846
  step("messages.sync");
8635
- else if (behind && syncsOneChat(messenger))
8847
+ else if (behind && syncsOneChat(owner))
8636
8848
  step("messages.sync", { chat: behind.chat });
8637
8849
  result(this, answer, [...next.values()]);
8638
8850
  if (answer.schema.version < SPEAKS) {
@@ -8647,7 +8859,7 @@ var checkCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("c
8647
8859
  renderer.note(`${orphans} pointers name a row that is gone or a type the store does not know \u2014 see orphan_pointers`);
8648
8860
  if (answer.vectors && answer.vectors.unused > 0)
8649
8861
  renderer.note(`${answer.vectors.unused} vectors belong to no text the store still holds \u2014 \`${command} store rebuild\` drops them`);
8650
- const older = answer.conversations.filter((chat) => chat.provider === messenger.provider && !chat.current).length;
8862
+ const older = answer.conversations.filter((chat) => chat.provider === owner.provider && !chat.current).length;
8651
8863
  if (older > 0) {
8652
8864
  renderer.note(`${older} chats' conversations were built by older rules \u2014 \`${command} conversations links rebuild --chat <chat>\``);
8653
8865
  }
@@ -8750,19 +8962,19 @@ var chatsBehind = /* @__PURE__ */ __name((database) => database.prepare(`SELECT
8750
8962
  held: row.held === null ? null : isoOf(row.held),
8751
8963
  refreshed: isoOf(row.refreshed)
8752
8964
  })), "chatsBehind");
8753
- var migrateCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("migrate"), { output: { entity: "store_migration" }, effects: LOCAL_WRITE }).summary("migrate an older local archive").description("bring the store up to this build's schema, then normalize, index and stem the messages and notes stored before it").action(async function() {
8965
+ var migrateCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("migrate"), { output: { entity: "store_migration" }, effects: LOCAL_WRITE }).summary(`migrate an older ${archive(owner)}`).description("bring the store up to this build's schema, then normalize, index and stem the messages and notes stored before it").action(async function() {
8754
8966
  const { renderer } = outputFor(this);
8755
8967
  const path = storePath(environmentOf(this).env ?? process.env);
8756
8968
  if (!existsSync10(path)) {
8757
8969
  result(this, { path, exists: false });
8758
- renderer.note(`no store yet \u2014 the first \`${messenger.app.command}\` command that reads a chat creates it`);
8970
+ renderer.note(`no store yet \u2014 ${createdBy(owner)}`);
8759
8971
  return;
8760
8972
  }
8761
8973
  const answer = await reading(path, (database) => {
8762
8974
  const from = schemaOf(database).version;
8763
8975
  migrate(database, {
8764
- command: messenger.app.command,
8765
- version: messenger.app.version,
8976
+ command: owner.app.command,
8977
+ version: owner.app.version,
8766
8978
  rollback: { store: path, warn: /* @__PURE__ */ __name((line) => renderer.warn(line), "warn") }
8767
8979
  });
8768
8980
  const { normalized, indexed, terms } = buildWordIndex(database, (note) => renderer.note(note));
@@ -8814,7 +9026,7 @@ var buildNoteIndex = /* @__PURE__ */ __name((database, note, { reset = false } =
8814
9026
  note(`indexing ${pending} notes`);
8815
9027
  return { notesIndexed: drainNoteIndex(database, stemmerCache()) };
8816
9028
  }, "buildNoteIndex");
8817
- var reindexCommand = /* @__PURE__ */ __name((messenger) => destroysNothing(annotate(new Command("rebuild"), { output: { entity: "store_reindex" }, effects: LOCAL_WRITE })).summary("rebuild the local archive's search indexes").description("rebuild the word index, its typo vocabulary, the stems, the files' word index, the notes' indexes and who took part in what, from what is stored, and drop the vectors no stored text uses; loses nothing").action(async function() {
9029
+ var reindexCommand = /* @__PURE__ */ __name((owner) => destroysNothing(annotate(new Command("rebuild"), { output: { entity: "store_reindex" }, effects: LOCAL_WRITE })).summary(`rebuild the ${archive(owner)}'s search indexes`).description("rebuild the word index, its typo vocabulary, the stems, the files' word index, the notes' indexes and who took part in what, from what is stored, and drop the vectors no stored text uses; loses nothing").action(async function() {
8818
9030
  const { renderer } = outputFor(this);
8819
9031
  const path = storePath(environmentOf(this).env ?? process.env);
8820
9032
  if (!existsSync10(path)) {
@@ -8859,6 +9071,9 @@ var backupCommand = /* @__PURE__ */ __name(() => destroysNothing(annotate(new Co
8859
9071
  const { encrypt } = this.opts();
8860
9072
  const path = storePath(environmentOf(this).env ?? process.env);
8861
9073
  const target = resolve(file2);
9074
+ const { app, env } = environmentOf(this);
9075
+ if (app)
9076
+ refuseLockedOutput(target, app, env ?? process.env, "<file>");
8862
9077
  if (!existsSync10(path))
8863
9078
  throw new CliError("not_found", `no store at ${path} to back up`);
8864
9079
  if (existsSync10(target))
@@ -8903,37 +9118,37 @@ var decryptCommand = /* @__PURE__ */ __name(() => annotate(new Command("decrypt"
8903
9118
  await unsealFile(from, to, await passwordOf(this, { twice: false }));
8904
9119
  result(this, { path: to, from, bytes: bytesOf2(to) });
8905
9120
  }), "decryptCommand");
8906
- var restoreCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }).summary("restore a backup and keep the current store, or roll back a breaking upgrade").description("put a backup in place of the store; the store it replaces is kept beside it, never deleted. Given a rollback copy (backups/<store>-rollback-schema-<version>-<time>.db, kept for a day before an upgrade older tools cannot open), put its tables back in the store and return it to that version instead").argument("<file>", "a file `store backup` wrote, or a rollback copy; one written with --encrypt asks for its password").action(async function(file2) {
9121
+ var restoreCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("restore"), { output: { entity: "store_restore" }, effects: LOCAL_WRITE }).summary("restore a backup and keep the current store, or roll back a breaking upgrade").description("put a backup in place of the store; the store it replaces is kept beside it, never deleted. Given a rollback copy (backups/<store>-rollback-schema-<version>-<time>.db, kept for a day before an upgrade older tools cannot open), put its tables back in the store and return it to that version instead").argument("<file>", "a file `store backup` wrote, or a rollback copy; one written with --encrypt asks for its password").action(async function(file2) {
8907
9122
  const path = storePath(environmentOf(this).env ?? process.env);
8908
9123
  const given = resolve(file2);
8909
9124
  if (!existsSync10(given))
8910
9125
  throw new CliError("not_found", `no file at ${given}`);
8911
- refuseWhileServing(this, messenger);
9126
+ refuseWhileServing(this, owner);
8912
9127
  if (!isSealed(given))
8913
- return restoreFrom(this, messenger, given, given);
9128
+ return restoreFrom(this, owner, given, given);
8914
9129
  const opened = `${path}.unsealing-${process.pid}`;
8915
9130
  mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8916
9131
  try {
8917
9132
  await unsealFile(given, opened, await passwordOf(this, { twice: false }));
8918
- await restoreFrom(this, messenger, opened, given);
9133
+ await restoreFrom(this, owner, opened, given);
8919
9134
  } finally {
8920
9135
  rmSync3(opened, { force: true });
8921
9136
  }
8922
9137
  }), "restoreCommand");
8923
- var restoreFrom = /* @__PURE__ */ __name(async (command, messenger, backup, given) => {
9138
+ var restoreFrom = /* @__PURE__ */ __name(async (command, owner, backup, given) => {
8924
9139
  const { renderer } = outputFor(command);
8925
9140
  const path = storePath(environmentOf(command).env ?? process.env);
8926
9141
  if (existsSync10(path) && realpathSync3(backup) === realpathSync3(path)) {
8927
9142
  throw new CliError("validation_error", `${backup} is the store itself`);
8928
9143
  }
8929
9144
  if (await isRollbackCopy(backup))
8930
- return rollBackFrom(command, messenger, backup);
9145
+ return rollBackFrom(command, owner, backup);
8931
9146
  const schema = await backupSchema(backup);
8932
9147
  const stamp = stampNow();
8933
9148
  const kept = existsSync10(path) ? `${path}.before-restore-${stamp}` : null;
8934
9149
  if (kept) {
8935
9150
  const waitMs = environmentOf(command).storeLockWaitMs;
8936
- await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
9151
+ await quiesce(path, owner, "restore", (message) => renderer.warn(message), waitMs);
8937
9152
  } else
8938
9153
  mkdirSync(dirname3(path), { recursive: true, mode: 448 });
8939
9154
  const incoming = `${path}.restoring-${stamp}`;
@@ -8961,13 +9176,13 @@ var isRollbackCopy = /* @__PURE__ */ __name(async (file2) => {
8961
9176
  return false;
8962
9177
  }
8963
9178
  }, "isRollbackCopy");
8964
- var rollBackFrom = /* @__PURE__ */ __name(async (command, messenger, copy) => {
9179
+ var rollBackFrom = /* @__PURE__ */ __name(async (command, owner, copy) => {
8965
9180
  const { renderer } = outputFor(command);
8966
9181
  const path = storePath(environmentOf(command).env ?? process.env);
8967
9182
  if (!existsSync10(path))
8968
9183
  throw new CliError("not_found", `no store at ${path} to roll back`);
8969
9184
  const waitMs = environmentOf(command).storeLockWaitMs;
8970
- await quiesce(path, messenger, "restore", (message) => renderer.warn(message), waitMs);
9185
+ await quiesce(path, owner, "restore", (message) => renderer.warn(message), waitMs);
8971
9186
  const { database } = await openSqlite(path);
8972
9187
  let rolled;
8973
9188
  try {
@@ -9012,8 +9227,8 @@ var backupSchema = /* @__PURE__ */ __name(async (backup) => {
9012
9227
  return schema;
9013
9228
  }, "backupSchema");
9014
9229
  var STORE_LOCK_WAIT_MS = 1e3;
9015
- var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
9016
- const { command } = messenger.app;
9230
+ var quiesce = /* @__PURE__ */ __name(async (path, owner, then, warn, waitMs = STORE_LOCK_WAIT_MS) => {
9231
+ const { command } = owner.app;
9017
9232
  const files = [path, `${path}-wal`, `${path}-shm`].filter((file2) => existsSync10(file2)).map((file2) => realpathSync3(file2));
9018
9233
  const holders = holdersOf(files);
9019
9234
  if (holders === void 0) {
@@ -9035,21 +9250,21 @@ var quiesce = /* @__PURE__ */ __name(async (path, messenger, then, warn, waitMs
9035
9250
  database.close();
9036
9251
  }
9037
9252
  }, "quiesce");
9038
- var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE }).summary("back up the local archive and replace it with an empty one").description("back the store up beside itself, then delete it and start an empty one at this build's schema; asks first, or --yes").option("--no-backup", "delete the store without backing it up first").option("--dry-run", "list every table it would empty, with its rows, and delete nothing").action(async function({ backup: keep, dryRun: dryRun2 }) {
9253
+ var resetCommand = /* @__PURE__ */ __name((owner) => annotate(new Command("reset"), { output: { entity: "store_reset" }, effects: LOCAL_WRITE }).summary(`back up the ${archive(owner)} and replace it with an empty one`).description("back the store up beside itself, then delete it and start an empty one at this build's schema; asks first, or --yes").option("--no-backup", "delete the store without backing it up first").option("--dry-run", "list every table it would empty, with its rows, and delete nothing").action(async function({ backup: keep, dryRun: dryRun2 }) {
9039
9254
  const { renderer } = outputFor(this);
9040
- const { command } = messenger.app;
9255
+ const { command } = owner.app;
9041
9256
  const env = environmentOf(this).env ?? process.env;
9042
9257
  const path = storePath(env);
9043
9258
  if (!existsSync10(path)) {
9044
9259
  result(this, { path, exists: false, reset: false });
9045
- renderer.note(`no store at ${path} \u2014 nothing to reset; the first \`${command}\` command that reads a chat creates it`);
9260
+ renderer.note(`no store at ${path} \u2014 nothing to reset; ${createdBy(owner)}`);
9046
9261
  return;
9047
9262
  }
9048
9263
  if (dryRun2) {
9049
- result(this, await resetPreview(path, messenger, env, keep));
9264
+ result(this, await resetPreview(path, owner, env, keep));
9050
9265
  return;
9051
9266
  }
9052
- refuseWhileServing(this, messenger);
9267
+ refuseWhileServing(this, owner);
9053
9268
  if (this.optsWithGlobals().yes !== true) {
9054
9269
  const what = `this deletes the store at ${path} and starts an empty one, ${keep ? "after a backup beside it" : "with no backup"}`;
9055
9270
  const answer = await answerOf(this, `${what}. Go ahead? [y/N] `);
@@ -9058,7 +9273,7 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
9058
9273
  if (!/^\s*y(es)?\s*$/i.test(answer))
9059
9274
  throw new CliError("cancelled", "cancelled \u2014 the store is unchanged");
9060
9275
  }
9061
- await quiesce(path, messenger, "reset", (message) => renderer.warn(message), environmentOf(this).storeLockWaitMs);
9276
+ await quiesce(path, owner, "reset", (message) => renderer.warn(message), environmentOf(this).storeLockWaitMs);
9062
9277
  const backup = keep ? `${path}.backup-${stampNow()}` : null;
9063
9278
  let backedUp = null;
9064
9279
  if (backup) {
@@ -9084,10 +9299,10 @@ var resetCommand = /* @__PURE__ */ __name((messenger) => annotate(new Command("r
9084
9299
  renderer.note(backup ? `the store is empty at schema ${schema}; \`${command} store restore ${backup}\` puts the old one back once a build can read it` : `the store is empty at schema ${schema}; there is no backup`);
9085
9300
  }), "resetCommand");
9086
9301
  var STORE_PARTS2 = ["", "-wal", "-shm"];
9087
- var resetPreview = /* @__PURE__ */ __name(async (path, messenger, env, keep) => {
9302
+ var resetPreview = /* @__PURE__ */ __name(async (path, owner, env, keep) => {
9088
9303
  const files = STORE_PARTS2.map((suffix) => `${path}${suffix}`).filter((file2) => existsSync10(file2));
9089
9304
  const holders = holdersOf(files.map((file2) => realpathSync3(file2)));
9090
- const serving = servingProfiles(messenger.app, env).length > 0;
9305
+ const serving = servingProfiles(owner.app, env).length > 0;
9091
9306
  const read = await readingOnly(path, (database) => ({
9092
9307
  schema: schemaOf(database).version,
9093
9308
  tables: emptiedTables(database)
@@ -9130,6 +9345,20 @@ export {
9130
9345
  paused,
9131
9346
  DRY_RUN_DAYS,
9132
9347
  dryRun,
9348
+ AI_PROVIDERS,
9349
+ aiSettingPath,
9350
+ readAiSetting,
9351
+ writeAiSetting,
9352
+ aiSettingOf,
9353
+ aiBaseUrl,
9354
+ aiOrigin,
9355
+ aiImagesAllowed,
9356
+ aiKeys,
9357
+ aiTakesKey,
9358
+ aiLeavesComputer,
9359
+ sharedModel,
9360
+ checkAi,
9361
+ purposeModel,
9133
9362
  replyConsentPathFor,
9134
9363
  readReplyConsent,
9135
9364
  writeReplyConsent,
@@ -9149,5 +9378,6 @@ export {
9149
9378
  serveCommand,
9150
9379
  storeSummary,
9151
9380
  storeMaintenanceCommands,
9381
+ addStoreMaintenanceCommands,
9152
9382
  buildStems
9153
9383
  };