@wirecat/cli-core 0.752.0 → 1.0.0-rc.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 (679) hide show
  1. package/CHANGELOG.md +162 -0
  2. package/README.md +9 -6
  3. package/dist/analysis/settings.d.ts +3 -1
  4. package/dist/analysis/settings.js +2 -1
  5. package/dist/attachments/extract.d.ts +1 -1
  6. package/dist/attachments/extract.js +1 -1
  7. package/dist/background/deliver.d.ts +3 -0
  8. package/dist/background/deliver.js +3 -0
  9. package/dist/background/lock.d.ts +1 -1
  10. package/dist/background/lock.js +1 -1
  11. package/dist/background/schedules.d.ts +13 -3
  12. package/dist/background/schedules.js +13 -3
  13. package/dist/background/when.d.ts +19 -5
  14. package/dist/background/when.js +17 -5
  15. package/dist/calendar/cli/answers.d.ts +1 -0
  16. package/dist/calendar/cli/answers.js +1 -0
  17. package/dist/calendar/cli/index.js +3 -1
  18. package/dist/calendar/feeds.d.ts +2 -0
  19. package/dist/calendar/feeds.js +10 -1
  20. package/dist/calendar/source.d.ts +5 -0
  21. package/dist/calendar/sync.d.ts +7 -1
  22. package/dist/calendar/sync.js +37 -7
  23. package/dist/calendar/testing/memory.js +7 -2
  24. package/dist/calendar/testing/sync-contract.js +2 -1
  25. package/dist/cli/account-rename.d.ts +3 -0
  26. package/dist/cli/account-rename.js +1 -0
  27. package/dist/cli/after-dashes.d.ts +1 -0
  28. package/dist/cli/after-dashes.js +1 -0
  29. package/dist/cli/agent-evaluation.d.ts +8 -1
  30. package/dist/cli/agent-evaluation.js +4 -1
  31. package/dist/cli/app-doctor-command.d.ts +1 -0
  32. package/dist/cli/app-doctor-command.js +1 -0
  33. package/dist/cli/ask-before-write.d.ts +1 -0
  34. package/dist/cli/ask-before-write.js +1 -0
  35. package/dist/cli/author.d.ts +1 -1
  36. package/dist/cli/author.js +1 -1
  37. package/dist/cli/base-stages-command.d.ts +2 -0
  38. package/dist/cli/base-stages-command.js +1 -0
  39. package/dist/cli/bot/api-http.d.ts +9 -3
  40. package/dist/cli/bot/api-http.js +7 -3
  41. package/dist/cli/bot/api-input.d.ts +3 -2
  42. package/dist/cli/bot/api-input.js +3 -2
  43. package/dist/cli/bot/api-rpc.d.ts +3 -1
  44. package/dist/cli/bot/api-rpc.js +2 -1
  45. package/dist/cli/bot/api.d.ts +1 -1
  46. package/dist/cli/bot/context.d.ts +3 -2
  47. package/dist/cli/bot/context.js +1 -1
  48. package/dist/cli/bot/copy.d.ts +1 -0
  49. package/dist/cli/bot/messages.d.ts +5 -2
  50. package/dist/cli/bot/messages.js +5 -2
  51. package/dist/cli/bot/port.d.ts +10 -6
  52. package/dist/cli/bot/port.js +1 -1
  53. package/dist/cli/bot/registry.d.ts +6 -3
  54. package/dist/cli/bot/registry.js +6 -3
  55. package/dist/cli/bot/updates.d.ts +2 -1
  56. package/dist/cli/bot/updates.js +2 -1
  57. package/dist/cli/call-stats-command.d.ts +3 -0
  58. package/dist/cli/call-stats-command.js +1 -0
  59. package/dist/cli/command-contract.d.ts +3 -0
  60. package/dist/cli/command-contract.js +2 -0
  61. package/dist/cli/command-runs.d.ts +3 -1
  62. package/dist/cli/command-runs.js +2 -1
  63. package/dist/cli/commander-internals.d.ts +16 -0
  64. package/dist/cli/commander-internals.js +17 -0
  65. package/dist/cli/commands-command.d.ts +1 -0
  66. package/dist/cli/commands-command.js +3 -1
  67. package/dist/cli/compact.d.ts +13 -8
  68. package/dist/cli/compact.js +9 -6
  69. package/dist/cli/config-command.d.ts +3 -3
  70. package/dist/cli/config-command.js +4 -4
  71. package/dist/cli/config-issues.d.ts +7 -3
  72. package/dist/cli/config-issues.js +7 -3
  73. package/dist/cli/config-keys.d.ts +4 -1
  74. package/dist/cli/config-keys.js +4 -1
  75. package/dist/cli/context.d.ts +6 -2
  76. package/dist/cli/context.js +5 -1
  77. package/dist/cli/contract-evidence.d.ts +1 -0
  78. package/dist/cli/contract-evidence.js +1 -0
  79. package/dist/cli/csv.d.ts +3 -2
  80. package/dist/cli/csv.js +3 -2
  81. package/dist/cli/default-config.d.ts +2 -0
  82. package/dist/cli/default-config.js +2 -0
  83. package/dist/cli/doctor-reports-command.d.ts +5 -1
  84. package/dist/cli/doctor-reports-command.js +4 -1
  85. package/dist/cli/documents/catalog.js +2 -1
  86. package/dist/cli/documents/file-conflicts.js +2 -1
  87. package/dist/cli/documents/file-edit.js +5 -4
  88. package/dist/cli/documents/file-mirrors.js +4 -3
  89. package/dist/cli/documents/file-update.js +2 -1
  90. package/dist/cli/documents/folders.js +2 -1
  91. package/dist/cli/early-refusal.d.ts +4 -4
  92. package/dist/cli/early-refusal.js +4 -4
  93. package/dist/cli/effects.d.ts +41 -11
  94. package/dist/cli/effects.js +48 -13
  95. package/dist/cli/entry.d.ts +4 -1
  96. package/dist/cli/entry.js +4 -1
  97. package/dist/cli/envelope.d.ts +14 -4
  98. package/dist/cli/envelope.js +14 -4
  99. package/dist/cli/execution.d.ts +1 -0
  100. package/dist/cli/execution.js +1 -0
  101. package/dist/cli/findings-input.d.ts +10 -2
  102. package/dist/cli/findings-input.js +10 -2
  103. package/dist/cli/first-run.d.ts +9 -2
  104. package/dist/cli/first-run.js +7 -1
  105. package/dist/cli/group-lock.d.ts +6 -0
  106. package/dist/cli/group-lock.js +5 -0
  107. package/dist/cli/guide.d.ts +5 -2
  108. package/dist/cli/guide.js +8 -4
  109. package/dist/cli/help/command-help.d.ts +12 -4
  110. package/dist/cli/help/command-help.js +13 -6
  111. package/dist/cli/help/first-screen.d.ts +2 -0
  112. package/dist/cli/help/first-screen.js +2 -0
  113. package/dist/cli/help/sections.d.ts +1 -0
  114. package/dist/cli/help/sections.js +1 -0
  115. package/dist/cli/index.d.ts +2 -1
  116. package/dist/cli/index.js +2 -1
  117. package/dist/cli/input-policy.d.ts +3 -0
  118. package/dist/cli/input-policy.js +3 -0
  119. package/dist/cli/json-fields.d.ts +1 -0
  120. package/dist/cli/json-fields.js +1 -0
  121. package/dist/cli/list-query.d.ts +11 -5
  122. package/dist/cli/list-query.js +11 -5
  123. package/dist/cli/listings.d.ts +13 -5
  124. package/dist/cli/listings.js +12 -5
  125. package/dist/cli/local-times.d.ts +3 -2
  126. package/dist/cli/local-times.js +2 -1
  127. package/dist/cli/mcp-server-command.d.ts +4 -1
  128. package/dist/cli/mcp-server-command.js +2 -0
  129. package/dist/cli/meeting-batch.d.ts +2 -1
  130. package/dist/cli/meeting-batch.js +2 -1
  131. package/dist/cli/meeting-evidence-answer.d.ts +2 -2
  132. package/dist/cli/meeting-evidence-answer.js +2 -2
  133. package/dist/cli/meeting-meaning-command.d.ts +5 -0
  134. package/dist/cli/meeting-meaning-command.js +2 -0
  135. package/dist/cli/meeting-passage-text.d.ts +1 -0
  136. package/dist/cli/meeting-passage-text.js +1 -0
  137. package/dist/cli/meeting-preparation-answer.d.ts +1 -0
  138. package/dist/cli/meeting-preparation-answer.js +1 -0
  139. package/dist/cli/meeting-preparation-read.d.ts +2 -0
  140. package/dist/cli/meeting-preparation-read.js +2 -0
  141. package/dist/cli/meeting-project-candidates-read.d.ts +1 -0
  142. package/dist/cli/meeting-project-candidates-read.js +1 -0
  143. package/dist/cli/meeting-results.d.ts +4 -1
  144. package/dist/cli/meeting-results.js +4 -1
  145. package/dist/cli/meeting-series-inventory-read.d.ts +2 -0
  146. package/dist/cli/meeting-series-inventory-read.js +1 -0
  147. package/dist/cli/meeting-tags-command.d.ts +2 -0
  148. package/dist/cli/meeting-tags-command.js +1 -0
  149. package/dist/cli/messenger/admin-folders-command.js +2 -1
  150. package/dist/cli/messenger/admin-moderation-command.d.ts +1 -1
  151. package/dist/cli/messenger/admin-moderation-command.js +1 -1
  152. package/dist/cli/messenger/ask.d.ts +1 -1
  153. package/dist/cli/messenger/ask.js +1 -1
  154. package/dist/cli/messenger/context.d.ts +2 -1
  155. package/dist/cli/messenger/context.js +1 -0
  156. package/dist/cli/messenger/doctor-command.d.ts +2 -1
  157. package/dist/cli/messenger/doctor-command.js +2 -1
  158. package/dist/cli/messenger/inbox.d.ts +2 -2
  159. package/dist/cli/messenger/inbox.js +2 -2
  160. package/dist/cli/messenger/lacks.d.ts +1 -0
  161. package/dist/cli/messenger/lacks.js +5 -3
  162. package/dist/cli/messenger/mcp-command.d.ts +8 -3
  163. package/dist/cli/messenger/mcp-command.js +6 -2
  164. package/dist/cli/messenger/message-items.d.ts +3 -1
  165. package/dist/cli/messenger/message-items.js +1 -0
  166. package/dist/cli/messenger/messages-delete-command.d.ts +1 -1
  167. package/dist/cli/messenger/messages-delete-command.js +1 -1
  168. package/dist/cli/messenger/report.d.ts +4 -1
  169. package/dist/cli/messenger/report.js +2 -0
  170. package/dist/cli/messenger/search-answers.d.ts +10 -4
  171. package/dist/cli/messenger/search-answers.js +6 -2
  172. package/dist/cli/messenger/searches-command.d.ts +4 -1
  173. package/dist/cli/messenger/searches-command.js +4 -1
  174. package/dist/cli/messenger/serve-command.d.ts +1 -1
  175. package/dist/cli/messenger/serve-command.js +1 -1
  176. package/dist/cli/messenger/serve-members.d.ts +4 -1
  177. package/dist/cli/messenger/serve-members.js +3 -1
  178. package/dist/cli/messenger/serve-outdated.d.ts +8 -3
  179. package/dist/cli/messenger/serve-outdated.js +8 -3
  180. package/dist/cli/messenger/serve-relay.d.ts +1 -1
  181. package/dist/cli/messenger/serve-relay.js +1 -1
  182. package/dist/cli/messenger/serve-stems.d.ts +4 -0
  183. package/dist/cli/messenger/serve-stems.js +3 -0
  184. package/dist/cli/messenger/server-command.d.ts +1 -1
  185. package/dist/cli/messenger/server-command.js +1 -1
  186. package/dist/cli/messenger/store-maintenance-command.d.ts +1 -0
  187. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  188. package/dist/cli/messenger/stored.d.ts +2 -0
  189. package/dist/cli/messenger/stored.js +1 -0
  190. package/dist/cli/messenger/tasks-command.d.ts +1 -0
  191. package/dist/cli/messenger/tasks-command.js +1 -0
  192. package/dist/cli/model-catalogue-command.d.ts +1 -0
  193. package/dist/cli/model-catalogue-command.js +1 -0
  194. package/dist/cli/oauth-session.d.ts +14 -4
  195. package/dist/cli/oauth-session.js +9 -2
  196. package/dist/cli/option-hints.js +3 -4
  197. package/dist/cli/paging.d.ts +1 -0
  198. package/dist/cli/paging.js +1 -0
  199. package/dist/cli/path-options.d.ts +37 -0
  200. package/dist/cli/path-options.js +85 -0
  201. package/dist/cli/permission-keys.d.ts +10 -4
  202. package/dist/cli/permission-keys.js +9 -3
  203. package/dist/cli/profile.d.ts +5 -1
  204. package/dist/cli/profile.js +5 -1
  205. package/dist/cli/program.js +3 -0
  206. package/dist/cli/project-evidence.d.ts +9 -1
  207. package/dist/cli/project-evidence.js +8 -1
  208. package/dist/cli/project-status-rows.d.ts +2 -1
  209. package/dist/cli/project-status-rows.js +2 -1
  210. package/dist/cli/project-status.d.ts +12 -4
  211. package/dist/cli/project-status.js +10 -4
  212. package/dist/cli/provider-refs.d.ts +1 -1
  213. package/dist/cli/provider-refs.js +1 -1
  214. package/dist/cli/relay-route.js +5 -14
  215. package/dist/cli/result-fields.d.ts +2 -0
  216. package/dist/cli/result-fields.js +2 -0
  217. package/dist/cli/schedule/harnesses.d.ts +10 -5
  218. package/dist/cli/schedule/harnesses.js +9 -5
  219. package/dist/cli/schedule/schedule-command.d.ts +16 -6
  220. package/dist/cli/schedule/schedule-command.js +11 -4
  221. package/dist/cli/search-left-out.d.ts +5 -1
  222. package/dist/cli/search-left-out.js +3 -1
  223. package/dist/cli/service-api-call.d.ts +1 -1
  224. package/dist/cli/service-api-manifest.d.ts +9 -2
  225. package/dist/cli/service-api-manifest.js +5 -1
  226. package/dist/cli/service-api.d.ts +5 -2
  227. package/dist/cli/service-api.js +4 -1
  228. package/dist/cli/settings.d.ts +9 -3
  229. package/dist/cli/settings.js +7 -2
  230. package/dist/cli/setup-answers.d.ts +3 -0
  231. package/dist/cli/setup-answers.js +1 -0
  232. package/dist/cli/shadowed-options.d.ts +1 -1
  233. package/dist/cli/shadowed-options.js +1 -1
  234. package/dist/cli/shared-command-exports.d.ts +22 -0
  235. package/dist/cli/shared-command-exports.js +22 -0
  236. package/dist/cli/steps.d.ts +5 -1
  237. package/dist/cli/steps.js +5 -1
  238. package/dist/cli/store-info.d.ts +2 -0
  239. package/dist/cli/store-info.js +1 -0
  240. package/dist/cli/store-recover.d.ts +9 -3
  241. package/dist/cli/store-recover.js +7 -3
  242. package/dist/cli/store-settings.d.ts +7 -2
  243. package/dist/cli/store-settings.js +7 -2
  244. package/dist/cli/templates-command.d.ts +1 -0
  245. package/dist/cli/unknown-profile.d.ts +1 -1
  246. package/dist/cli/unknown-profile.js +1 -1
  247. package/dist/content/cli/index.js +3 -1
  248. package/dist/content/sync.d.ts +2 -0
  249. package/dist/content/sync.js +8 -3
  250. package/dist/content/testing/sync-contract.js +6 -2
  251. package/dist/content/writer.d.ts +1 -1
  252. package/dist/content/writer.js +1 -1
  253. package/dist/context/evidence.d.ts +4 -0
  254. package/dist/crm/cli/files.d.ts +1 -1
  255. package/dist/crm/cli/files.js +3 -2
  256. package/dist/crm/cli/index.d.ts +1 -1
  257. package/dist/crm/cli/index.js +5 -4
  258. package/dist/crm/cli/records.d.ts +1 -1
  259. package/dist/crm/cli/records.js +1 -1
  260. package/dist/crm/digest.d.ts +1 -1
  261. package/dist/crm/foreign-contacts.d.ts +2 -2
  262. package/dist/crm/foreign-contacts.js +2 -2
  263. package/dist/crm/index.d.ts +1 -1
  264. package/dist/crm/index.js +1 -1
  265. package/dist/crm/manifest/paths.d.ts +1 -1
  266. package/dist/crm/manifest/writer.d.ts +23 -4
  267. package/dist/crm/manifest/writer.js +46 -8
  268. package/dist/crm/source.d.ts +2 -2
  269. package/dist/crm/sync.d.ts +6 -2
  270. package/dist/crm/sync.js +16 -6
  271. package/dist/crm/testing/manifest-fake.d.ts +2 -1
  272. package/dist/crm/testing/manifest-fake.js +1 -1
  273. package/dist/crm/testing/sync-contract.js +7 -2
  274. package/dist/crm/viewer.d.ts +2 -2
  275. package/dist/crm/viewer.js +2 -2
  276. package/dist/crm/writer.d.ts +3 -2
  277. package/dist/crm/writer.js +9 -3
  278. package/dist/crm/writes.d.ts +4 -2
  279. package/dist/crm/writes.js +8 -5
  280. package/dist/domain/addresses.d.ts +7 -3
  281. package/dist/domain/addresses.js +7 -3
  282. package/dist/domain/business.d.ts +21 -4
  283. package/dist/domain/business.js +11 -4
  284. package/dist/domain/categories.d.ts +1 -1
  285. package/dist/domain/categories.js +1 -1
  286. package/dist/domain/config-repair.d.ts +1 -1
  287. package/dist/domain/config-repair.js +1 -1
  288. package/dist/domain/counters.d.ts +4 -0
  289. package/dist/domain/counters.js +2 -0
  290. package/dist/domain/crm.d.ts +18 -7
  291. package/dist/domain/crm.js +11 -4
  292. package/dist/domain/deals.d.ts +6 -3
  293. package/dist/domain/deals.js +4 -3
  294. package/dist/domain/display-names.d.ts +3 -1
  295. package/dist/domain/display-names.js +2 -0
  296. package/dist/domain/finance.d.ts +8 -2
  297. package/dist/domain/finance.js +4 -2
  298. package/dist/domain/formatting.d.ts +1 -0
  299. package/dist/domain/knowledge.d.ts +6 -1
  300. package/dist/domain/knowledge.js +6 -1
  301. package/dist/domain/links.d.ts +14 -2
  302. package/dist/domain/links.js +11 -2
  303. package/dist/domain/locator.d.ts +4 -1
  304. package/dist/domain/locator.js +3 -1
  305. package/dist/domain/markdown.d.ts +1 -0
  306. package/dist/domain/markdown.js +1 -0
  307. package/dist/domain/models.d.ts +38 -15
  308. package/dist/domain/models.js +6 -3
  309. package/dist/domain/money.d.ts +14 -4
  310. package/dist/domain/money.js +10 -3
  311. package/dist/domain/orders.d.ts +4 -1
  312. package/dist/domain/orders.js +2 -1
  313. package/dist/domain/person-kinds.d.ts +4 -2
  314. package/dist/domain/person-kinds.js +1 -0
  315. package/dist/domain/phones.d.ts +2 -0
  316. package/dist/domain/phones.js +1 -0
  317. package/dist/domain/polls.d.ts +1 -0
  318. package/dist/domain/polls.js +1 -0
  319. package/dist/domain/providers.d.ts +22 -7
  320. package/dist/domain/providers.js +22 -7
  321. package/dist/domain/rankings-graph.d.ts +2 -0
  322. package/dist/domain/rankings-options.d.ts +5 -0
  323. package/dist/domain/rankings-options.js +1 -0
  324. package/dist/domain/record-types.d.ts +5 -1
  325. package/dist/domain/record-types.js +1 -0
  326. package/dist/domain/records-table.d.ts +18 -3
  327. package/dist/domain/records-table.js +11 -2
  328. package/dist/domain/records.d.ts +18 -2
  329. package/dist/domain/records.js +8 -1
  330. package/dist/domain/ref-summaries.d.ts +22 -5
  331. package/dist/domain/ref-summaries.js +9 -2
  332. package/dist/domain/references.d.ts +4 -2
  333. package/dist/domain/references.js +3 -2
  334. package/dist/domain/relation-role-labels.d.ts +5 -1
  335. package/dist/domain/relation-role-labels.js +4 -1
  336. package/dist/domain/relations.d.ts +32 -8
  337. package/dist/domain/relations.js +28 -8
  338. package/dist/domain/send-time.d.ts +1 -2
  339. package/dist/domain/send-time.js +1 -2
  340. package/dist/domain/tag-consolidation.d.ts +5 -0
  341. package/dist/domain/tag-redirects.d.ts +4 -1
  342. package/dist/domain/tag-redirects.js +1 -1
  343. package/dist/domain/tags.d.ts +2 -0
  344. package/dist/domain/tags.js +1 -0
  345. package/dist/domain/vcard.d.ts +4 -1
  346. package/dist/domain/vcard.js +2 -1
  347. package/dist/entities/business-context.d.ts +10 -4
  348. package/dist/entities/business-context.js +10 -4
  349. package/dist/entities/knowledge-lists.d.ts +3 -0
  350. package/dist/entities/knowledge-lists.js +3 -0
  351. package/dist/entities/list-results.d.ts +1 -0
  352. package/dist/entities/list-results.js +1 -0
  353. package/dist/entities/listings.d.ts +12 -5
  354. package/dist/entities/listings.js +12 -5
  355. package/dist/entities/note.d.ts +1 -0
  356. package/dist/entities/note.js +1 -0
  357. package/dist/entities/store-records.d.ts +1 -0
  358. package/dist/entities/store-records.js +1 -0
  359. package/dist/errors/failures.d.ts +3 -1
  360. package/dist/errors/failures.js +3 -1
  361. package/dist/errors/reasons.d.ts +1 -0
  362. package/dist/errors/reasons.js +5 -38
  363. package/dist/errors/store-reasons.d.ts +5 -0
  364. package/dist/errors/store-reasons.js +62 -0
  365. package/dist/http/link-fetch.d.ts +1 -0
  366. package/dist/http/link-fetch.js +1 -0
  367. package/dist/http/public-url.d.ts +6 -2
  368. package/dist/http/public-url.js +6 -2
  369. package/dist/kit/contract.d.ts +1 -1
  370. package/dist/kit/contract.js +1 -1
  371. package/dist/kit/fake.d.ts +2 -1
  372. package/dist/kit/fake.js +1 -0
  373. package/dist/kit/run-scope.js +2 -1
  374. package/dist/kit/search-recipes.d.ts +2 -0
  375. package/dist/kit/search-recipes.js +1 -0
  376. package/dist/kit/seed.d.ts +3 -2
  377. package/dist/kit/seed.js +3 -2
  378. package/dist/mail/findings.d.ts +1 -1
  379. package/dist/mail/findings.js +1 -1
  380. package/dist/mail/headers.d.ts +9 -5
  381. package/dist/mail/headers.js +63 -5
  382. package/dist/mail/sync.js +18 -9
  383. package/dist/mcp/agent.d.ts +4 -1
  384. package/dist/mcp/agent.js +2 -1
  385. package/dist/mcp/all-profiles.d.ts +12 -4
  386. package/dist/mcp/all-profiles.js +10 -3
  387. package/dist/mcp/bot/instructions.d.ts +4 -1
  388. package/dist/mcp/bot/instructions.js +4 -1
  389. package/dist/mcp/caller.d.ts +1 -0
  390. package/dist/mcp/caller.js +1 -0
  391. package/dist/mcp/http/oauth.d.ts +2 -1
  392. package/dist/mcp/http/oauth.js +2 -1
  393. package/dist/mcp/http/serve.d.ts +4 -1
  394. package/dist/mcp/http/serve.js +3 -1
  395. package/dist/mcp/http/state.d.ts +1 -1
  396. package/dist/mcp/http/state.js +1 -1
  397. package/dist/mcp/meeting-preparation.d.ts +5 -1
  398. package/dist/mcp/meeting-preparation.js +5 -1
  399. package/dist/mcp/meeting-project-candidates.d.ts +2 -0
  400. package/dist/mcp/meeting-project-candidates.js +2 -0
  401. package/dist/mcp/meeting-series-inventory.d.ts +2 -0
  402. package/dist/mcp/meeting-series-inventory.js +2 -0
  403. package/dist/mcp/prompts.d.ts +1 -0
  404. package/dist/mcp/prompts.js +1 -0
  405. package/dist/mcp/server.d.ts +1 -1
  406. package/dist/mcp/server.js +1 -1
  407. package/dist/mcp/session.d.ts +2 -2
  408. package/dist/mcp/session.js +2 -2
  409. package/dist/mcp/surface.d.ts +3 -2
  410. package/dist/mcp/surface.js +2 -1
  411. package/dist/meetings/cli/query-options.js +3 -2
  412. package/dist/meetings/event-store.d.ts +7 -2
  413. package/dist/meetings/findings-rules.d.ts +2 -0
  414. package/dist/meetings/findings.d.ts +5 -0
  415. package/dist/meetings/mcp/agent-text.d.ts +12 -4
  416. package/dist/meetings/mcp/agent-text.js +12 -4
  417. package/dist/meetings/mcp/index.d.ts +24 -24
  418. package/dist/meetings/payment.d.ts +15 -3
  419. package/dist/meetings/payment.js +14 -3
  420. package/dist/meetings/read-store.d.ts +8 -0
  421. package/dist/meetings/reference.d.ts +3 -0
  422. package/dist/meetings/reference.js +3 -0
  423. package/dist/meetings/result-items.d.ts +1 -0
  424. package/dist/meetings/result-items.js +1 -0
  425. package/dist/meetings/transcript-store.d.ts +0 -1
  426. package/dist/moderation/check.d.ts +3 -1
  427. package/dist/moderation/check.js +2 -0
  428. package/dist/moderation/rules.d.ts +5 -2
  429. package/dist/moderation/rules.js +5 -3
  430. package/dist/ports/app.d.ts +1 -0
  431. package/dist/ports/app.js +1 -0
  432. package/dist/ports/messenger.d.ts +55 -27
  433. package/dist/ports/traits.d.ts +4 -1
  434. package/dist/ports/wirecat-tools.d.ts +1 -1
  435. package/dist/ports/wirecat-tools.js +1 -1
  436. package/dist/readers/engine.d.ts +2 -2
  437. package/dist/readers/engine.js +2 -2
  438. package/dist/render/messages.d.ts +7 -1
  439. package/dist/render/messages.js +6 -1
  440. package/dist/replies/dry-run.d.ts +1 -0
  441. package/dist/replies/dry-run.js +1 -0
  442. package/dist/replies/rendering.d.ts +2 -0
  443. package/dist/replies/rendering.js +1 -0
  444. package/dist/replies/rules.d.ts +1 -2
  445. package/dist/replies/rules.js +1 -2
  446. package/dist/replies/serve.d.ts +8 -2
  447. package/dist/replies/serve.js +6 -1
  448. package/dist/replies/state.d.ts +1 -0
  449. package/dist/replies/state.js +1 -0
  450. package/dist/resolve.d.ts +5 -1
  451. package/dist/resolve.js +5 -1
  452. package/dist/runs/events.d.ts +3 -2
  453. package/dist/runs/events.js +2 -1
  454. package/dist/runs/log-events.d.ts +4 -1
  455. package/dist/runs/log-events.js +4 -1
  456. package/dist/runs/provider-log.d.ts +9 -1
  457. package/dist/runs/provider-log.js +8 -1
  458. package/dist/runs/recording.d.ts +9 -1
  459. package/dist/runs/recording.js +7 -1
  460. package/dist/runs/run-context.d.ts +1 -0
  461. package/dist/runs/run-context.js +1 -0
  462. package/dist/runs/run.d.ts +1 -0
  463. package/dist/runs/run.js +1 -0
  464. package/dist/runs/scope.d.ts +1 -0
  465. package/dist/runs/scope.js +1 -0
  466. package/dist/search/languages.d.ts +4 -1
  467. package/dist/search/languages.js +4 -1
  468. package/dist/search/question-plan.d.ts +3 -3
  469. package/dist/search/question-plan.js +3 -3
  470. package/dist/search/service-query.d.ts +7 -2
  471. package/dist/search/service-query.js +2 -0
  472. package/dist/sends/buttons.d.ts +7 -3
  473. package/dist/sends/buttons.js +6 -3
  474. package/dist/sends/flood.d.ts +3 -1
  475. package/dist/sends/flood.js +3 -1
  476. package/dist/sends/guard.d.ts +1 -0
  477. package/dist/sends/guard.js +1 -0
  478. package/dist/sends/guarded.d.ts +4 -1
  479. package/dist/sends/guarded.js +4 -1
  480. package/dist/sends/journal.d.ts +2 -2
  481. package/dist/sends/pace.d.ts +6 -1
  482. package/dist/sends/pace.js +5 -1
  483. package/dist/sends/permissions.d.ts +14 -9
  484. package/dist/sends/permissions.js +13 -8
  485. package/dist/sends/polls.d.ts +6 -3
  486. package/dist/sends/polls.js +6 -3
  487. package/dist/sends/recipients.d.ts +1 -0
  488. package/dist/sends/recipients.js +1 -0
  489. package/dist/sends/send-as.d.ts +1 -1
  490. package/dist/sends/send-as.js +1 -1
  491. package/dist/sends/upload.d.ts +6 -2
  492. package/dist/sends/upload.js +6 -2
  493. package/dist/services/business-context.d.ts +2 -2
  494. package/dist/services/business-context.js +1 -1
  495. package/dist/services/deal-context.d.ts +1 -1
  496. package/dist/services/documents/ports.d.ts +0 -2
  497. package/dist/services/embeddings.d.ts +3 -3
  498. package/dist/services/inbox.d.ts +6 -2
  499. package/dist/services/inbox.js +5 -1
  500. package/dist/services/index.d.ts +0 -1
  501. package/dist/services/index.js +0 -1
  502. package/dist/services/moderation.d.ts +1 -1
  503. package/dist/services/moment.d.ts +1 -0
  504. package/dist/services/moment.js +1 -0
  505. package/dist/services/organization-context.d.ts +1 -1
  506. package/dist/services/people.d.ts +2 -2
  507. package/dist/services/people.js +1 -1
  508. package/dist/services/person-business.d.ts +1 -1
  509. package/dist/services/questions.d.ts +1 -0
  510. package/dist/services/questions.js +1 -0
  511. package/dist/services/search-all.d.ts +1 -1
  512. package/dist/services/search-all.js +2 -2
  513. package/dist/services/task-rules.d.ts +1 -0
  514. package/dist/services/task-rules.js +1 -0
  515. package/dist/services/tasks.d.ts +2 -0
  516. package/dist/services/tasks.js +2 -0
  517. package/dist/setup/document.d.ts +20 -4
  518. package/dist/setup/document.js +20 -4
  519. package/dist/setup/plain.d.ts +1 -0
  520. package/dist/setup/plain.js +1 -0
  521. package/dist/speech/hearing.d.ts +1 -1
  522. package/dist/speech/hearing.js +1 -1
  523. package/dist/speech/models.d.ts +1 -1
  524. package/dist/sqlite-runtime.d.ts +2 -0
  525. package/dist/sqlite-runtime.js +2 -0
  526. package/dist/store/account-store.d.ts +3 -2
  527. package/dist/store/accounts.d.ts +1 -0
  528. package/dist/store/areas.d.ts +40 -0
  529. package/dist/store/areas.js +17 -0
  530. package/dist/store/attachments.d.ts +2 -0
  531. package/dist/store/conversations.d.ts +1 -0
  532. package/dist/store/counters.d.ts +2 -0
  533. package/dist/store/damage.d.ts +4 -1
  534. package/dist/store/damage.js +2 -1
  535. package/dist/store/decision-requests.d.ts +10 -3
  536. package/dist/store/decision-requests.js +9 -3
  537. package/dist/store/decisions.d.ts +5 -1
  538. package/dist/store/decisions.js +4 -1
  539. package/dist/store/document-transfer/index.d.ts +2 -0
  540. package/dist/store/document-transfer/index.js +2 -0
  541. package/dist/store/document-transfer/model.d.ts +3 -0
  542. package/dist/store/driver.d.ts +2 -0
  543. package/dist/store/driver.js +1 -0
  544. package/dist/store/evidence-findings.d.ts +10 -2
  545. package/dist/store/evidence-findings.js +2 -0
  546. package/dist/store/health.d.ts +4 -1
  547. package/dist/store/health.js +2 -1
  548. package/dist/store/identity-links.d.ts +13 -4
  549. package/dist/store/identity-links.js +4 -1
  550. package/dist/store/identity-splits.d.ts +2 -1
  551. package/dist/store/identity-splits.js +1 -0
  552. package/dist/store/index.d.ts +2 -1
  553. package/dist/store/index.js +1 -0
  554. package/dist/store/knowledge-query.d.ts +3 -0
  555. package/dist/store/knowledge-query.js +3 -0
  556. package/dist/store/mail-findings.d.ts +4 -1
  557. package/dist/store/mail-findings.js +1 -0
  558. package/dist/store/marks.d.ts +20 -3
  559. package/dist/store/marks.js +12 -1
  560. package/dist/store/meeting-findings.d.ts +2 -0
  561. package/dist/store/mentions.d.ts +2 -0
  562. package/dist/store/message-store.d.ts +219 -0
  563. package/dist/store/message-store.js +1 -0
  564. package/dist/store/messages.d.ts +1 -0
  565. package/dist/store/messages.js +1 -0
  566. package/dist/store/migrations.d.ts +8 -0
  567. package/dist/store/migrations.js +59 -6
  568. package/dist/store/open.d.ts +1 -1
  569. package/dist/store/open.js +1 -1
  570. package/dist/store/people.d.ts +5 -4
  571. package/dist/store/project-transfer/manifest.d.ts +3 -1
  572. package/dist/store/project-transfer/manifest.js +3 -1
  573. package/dist/store/project-transfer/plan.d.ts +3 -1
  574. package/dist/store/project-transfer/plan.js +1 -1
  575. package/dist/store/project-transfer/preview.d.ts +2 -0
  576. package/dist/store/project-transfer/preview.js +1 -0
  577. package/dist/store/project-transfer/schema.d.ts +1 -0
  578. package/dist/store/project-transfer/snapshot-model.d.ts +4 -0
  579. package/dist/store/project-transfer/snapshot-model.js +3 -0
  580. package/dist/store/project-transfer/snapshot-plan.d.ts +2 -1
  581. package/dist/store/project-transfer/snapshot-plan.js +1 -1
  582. package/dist/store/project-transfer/snapshot.d.ts +3 -1
  583. package/dist/store/project-transfer/snapshot.js +1 -1
  584. package/dist/store/project-transfer/store.d.ts +4 -1
  585. package/dist/store/providers.d.ts +1 -0
  586. package/dist/store/providers.js +1 -0
  587. package/dist/store/public.d.ts +40 -0
  588. package/dist/store/public.js +30 -0
  589. package/dist/store/queries.d.ts +1 -1
  590. package/dist/store/repair.d.ts +2 -2
  591. package/dist/store/repair.js +2 -2
  592. package/dist/store/roster.d.ts +1 -0
  593. package/dist/store/search-index.d.ts +1 -0
  594. package/dist/store/searches.d.ts +1 -0
  595. package/dist/store/source-review.d.ts +13 -6
  596. package/dist/store/source-review.js +2 -1
  597. package/dist/store/sqlite/calendar.js +7 -2
  598. package/dist/store/sqlite/completeness.d.ts +1 -1
  599. package/dist/store/sqlite/completeness.js +1 -1
  600. package/dist/store/sqlite/conversations.d.ts +1 -1
  601. package/dist/store/sqlite/conversations.js +1 -1
  602. package/dist/store/sqlite/copy-viewer.d.ts +1 -1
  603. package/dist/store/sqlite/crm-activities.d.ts +1 -1
  604. package/dist/store/sqlite/crm-activity-chunks.d.ts +3 -2
  605. package/dist/store/sqlite/crm-activity-chunks.js +3 -2
  606. package/dist/store/sqlite/crm-changes.d.ts +1 -1
  607. package/dist/store/sqlite/crm-files.d.ts +1 -1
  608. package/dist/store/sqlite/crm-settings.d.ts +1 -1
  609. package/dist/store/sqlite/crm-settings.js +1 -1
  610. package/dist/store/sqlite/crm.d.ts +2 -2
  611. package/dist/store/sqlite/drizzle/core.d.ts +1 -1
  612. package/dist/store/sqlite/drizzle/core.js +36 -0
  613. package/dist/store/sqlite/drizzle/core.js.map +4 -4
  614. package/dist/store/sqlite/email-activity.d.ts +1 -1
  615. package/dist/store/sqlite/email-activity.js +4 -1
  616. package/dist/store/sqlite/identity-link-rows.d.ts +1 -1
  617. package/dist/store/sqlite/identity-link-rows.js +1 -1
  618. package/dist/store/sqlite/manifest.js +105 -0
  619. package/dist/store/sqlite/meeting-documents.js +0 -6
  620. package/dist/store/sqlite/messages.d.ts +6 -1
  621. package/dist/store/sqlite/messages.js +14 -4
  622. package/dist/store/sqlite/migrations.generated.js +652 -0
  623. package/dist/store/sqlite/name-traces.d.ts +1 -1
  624. package/dist/store/sqlite/name-traces.js +1 -1
  625. package/dist/store/sqlite/organization-categories.d.ts +1 -1
  626. package/dist/store/sqlite/organization-categories.js +1 -1
  627. package/dist/store/sqlite/people-list.d.ts +5 -0
  628. package/dist/store/sqlite/people-list.js +28 -5
  629. package/dist/store/sqlite/person-links.d.ts +2 -2
  630. package/dist/store/sqlite/person-links.js +3 -3
  631. package/dist/store/sqlite/person-match-scan.d.ts +5 -5
  632. package/dist/store/sqlite/person-match-scan.js +17 -17
  633. package/dist/store/sqlite/pipeline-period.d.ts +1 -1
  634. package/dist/store/sqlite/pipeline-period.js +1 -1
  635. package/dist/store/sqlite/rebuild.d.ts +52 -0
  636. package/dist/store/sqlite/rebuild.js +176 -0
  637. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  638. package/dist/store/sqlite/relation-list.d.ts +1 -1
  639. package/dist/store/sqlite/rollback-copy.d.ts +7 -3
  640. package/dist/store/sqlite/rollback-copy.js +43 -6
  641. package/dist/store/sqlite/schema/canonical-tags.js +1 -1
  642. package/dist/store/sqlite/schema/decision-requests.js +1 -1
  643. package/dist/store/sqlite/schema/document-changes.js +1 -1
  644. package/dist/store/sqlite/schema/link-revisions.js +6 -3
  645. package/dist/store/sqlite/schema/links.js +3 -2
  646. package/dist/store/sqlite/schema/tag-consolidations.js +5 -2
  647. package/dist/store/sqlite/schema/templates.js +1 -1
  648. package/dist/store/sqlite/schema.js +243 -108
  649. package/dist/store/sqlite/sender-signals.d.ts +42 -0
  650. package/dist/store/sqlite/sender-signals.js +106 -0
  651. package/dist/store/sqlite/vectors.d.ts +1 -1
  652. package/dist/store/sqlite/vectors.js +1 -1
  653. package/dist/store/sqlite/version-73.d.ts +12 -0
  654. package/dist/store/sqlite/version-73.js +114 -0
  655. package/dist/store/sqlite-warning.d.ts +1 -1
  656. package/dist/store/sqlite-warning.js +1 -1
  657. package/dist/store/store.d.ts +2 -176
  658. package/dist/store/store.js +1 -1
  659. package/dist/store/sync.d.ts +1 -0
  660. package/dist/store/types.d.ts +5 -3
  661. package/dist/store/vectors.d.ts +2 -0
  662. package/dist/tasks/model.d.ts +7 -1
  663. package/dist/tasks/model.js +6 -1
  664. package/dist/tasks/priority.d.ts +11 -2
  665. package/dist/tasks/priority.js +10 -2
  666. package/dist/terminal/qr.d.ts +1 -0
  667. package/dist/terminal/qr.js +1 -0
  668. package/dist/tracker/cli/index.js +3 -1
  669. package/dist/tracker/manifest/manifest.d.ts +1 -1
  670. package/dist/tracker/manifest/manifest.js +1 -1
  671. package/dist/tracker/sync.d.ts +2 -0
  672. package/dist/tracker/sync.js +12 -5
  673. package/dist/tracker/testing/manifest-fake.d.ts +2 -1
  674. package/dist/update/index.d.ts +5 -1
  675. package/dist/update/index.js +4 -1
  676. package/package.json +29 -9
  677. package/parity.json +4 -1
  678. package/dist/services/search-all-deprecated.d.ts +0 -40
  679. package/dist/services/search-all-deprecated.js +0 -10
@@ -1,7 +1,7 @@
1
1
  import type { CacheDatabase } from "../driver.js";
2
2
  /**
3
3
  * People, owner aside, by the name they share once case, quotes, word order, script and spelling are set aside:
4
- * `Светлана Кузнецова` and `Svetlana Kuznetsova` are one name here (BUG-678).
4
+ * `Светлана Кузнецова` and `Svetlana Kuznetsova` are one name here.
5
5
  */
6
6
  export declare const peopleByNameKey: (database: CacheDatabase) => Map<string, {
7
7
  people: number[];
@@ -6,7 +6,7 @@ import { FREE_MAIL } from "../../mail/score.js";
6
6
  import { referenceOfThing } from "./things.js";
7
7
  /**
8
8
  * People, owner aside, by the name they share once case, quotes, word order, script and spelling are set aside:
9
- * `Светлана Кузнецова` and `Svetlana Kuznetsova` are one name here (BUG-678).
9
+ * `Светлана Кузнецова` and `Svetlana Kuznetsova` are one name here.
10
10
  */
11
11
  export const peopleByNameKey = (database) => {
12
12
  const found = new Map();
@@ -7,7 +7,7 @@ export interface OrganizationFilter {
7
7
  accounts?: AccountKey[];
8
8
  }
9
9
  /**
10
- * The category as SQL over `organizations o`, derived from usable relationships at `now` (NEED-2377), as
10
+ * The category as SQL over `organizations o`, derived from usable relationships at `now`, as
11
11
  * `organizationCategories` derives it: `client` is `customer-of` an own organization, `supplier` one an own
12
12
  * organization is `customer-of`, `partner` `partner-of` one, `employer` one the owner's person is `member-of` as
13
13
  * employee, contractor or founder.
@@ -5,7 +5,7 @@ import { linkKind } from "./link-kinds.js";
5
5
  const OWN = "(SELECT id FROM organizations WHERE deleted_at IS NULL AND json_extract(metadata, '$.own') = 1)";
6
6
  const EMPLOYED = "('employee', 'contractor', 'founder')";
7
7
  /**
8
- * The category as SQL over `organizations o`, derived from usable relationships at `now` (NEED-2377), as
8
+ * The category as SQL over `organizations o`, derived from usable relationships at `now`, as
9
9
  * `organizationCategories` derives it: `client` is `customer-of` an own organization, `supplier` one an own
10
10
  * organization is `customer-of`, `partner` `partner-of` one, `employer` one the owner's person is `member-of` as
11
11
  * employee, contractor or founder.
@@ -1,6 +1,7 @@
1
1
  import { type KindSignal, type PersonKind } from "../../domain/person-kinds.js";
2
2
  import { type CacheDatabase } from "../driver.js";
3
3
  import { type ShownBecause } from "./person-ties.js";
4
+ import { type Reach, type SenderSignal } from "./sender-signals.js";
4
5
  export declare const PEOPLE_SORTS: readonly ["interactions", "recent", "name", "tasks"];
5
6
  export type PeopleSort = (typeof PEOPLE_SORTS)[number];
6
7
  export interface PeopleListOptions {
@@ -39,6 +40,10 @@ export interface ListedPerson {
39
40
  lastContact: string | null;
40
41
  /** Why they are shown; empty for someone hidden by default. */
41
42
  ties: ShownBecause[];
43
+ /** How their messages reached the owner (`senderSignalsOf`); `null` when nothing says. Worked out for the page. */
44
+ reach: Reach | null;
45
+ /** What their mail and addresses show about who writes and how it reached the owner. Worked out for the page. */
46
+ signals: SenderSignal[];
42
47
  }
43
48
  export interface PeopleList {
44
49
  items: ListedPerson[];
@@ -7,6 +7,7 @@ import { isQueryOnly } from "../driver.js";
7
7
  import { fold } from "../normalize.js";
8
8
  import { mergedAwaySql } from "./merged-persons.js";
9
9
  import { ALWAYS_SHOWN, shownReasons } from "./person-ties.js";
10
+ import { senderSignalsOf, sentMailOf } from "./sender-signals.js";
10
11
  import { mergedAssignees } from "./task-board.js";
11
12
  import { hiddenTestPeople } from "./test-people.js";
12
13
  import { read, writeBatch } from "./transaction.js";
@@ -48,7 +49,9 @@ const TWO_WAY = "SELECT DISTINCT s.sender_identity_id AS identity_id FROM messag
48
49
  "AND s.sender_identity_id IS NOT NULL AND s.chat_id IN (SELECT c.id FROM chats c WHERE c.kind = 'dialog' " +
49
50
  "AND EXISTS (SELECT 1 FROM messages o WHERE o.chat_id = c.id AND o.outgoing = 1))";
50
51
  const MAIL_COUNTS = (scope) => "SELECT l.person_id AS person, count(*) AS n, sum(EXISTS (SELECT 1 FROM email_mailboxes m " +
51
- "JOIN mailboxes b ON b.id = m.mailbox_id WHERE m.email_id = e.id AND b.kind = 'bulk')) AS bulk " +
52
+ "JOIN mailboxes b ON b.id = m.mailbox_id WHERE m.email_id = e.id AND b.kind = 'bulk')) AS bulk, " +
53
+ "sum(json_extract(e.headers, '$.\"auto-submitted\"') IS NOT NULL) AS auto, " +
54
+ "sum(json_extract(e.headers, '$.\"null-return-path\"') IS 1) AS null_return " +
52
55
  "FROM emails e JOIN identity_links l ON l.identity_id = e.from_identity_id " +
53
56
  `WHERE e.outgoing IS NOT 1 AND e.deleted_at IS NULL AND ${IN_SCOPE(scope, "l.person_id")} GROUP BY 1`;
54
57
  const IDENTITIES = (scope) => "SELECT l.person_id AS person, i.id, i.provider, i.external_id, i.name, i.username, i.phone, i.email, i.bot " +
@@ -168,6 +171,11 @@ const kindOf = (shown, facts, ties, mail, test) => {
168
171
  ...(mail !== undefined && mail.n >= BULK_MIN && mail.bulk * 2 > mail.n ? ["bulk-mail"] : []),
169
172
  ...(facts?.neverReplied ? ["bulk-never-replied"] : []),
170
173
  ...(isAutomatedName(shown) ? ["automated-name"] : []),
174
+ // A guess from headers never outweighs mail the owner wrote them.
175
+ ...(mail !== undefined && !ties.includes("mail") && mail.auto * 2 > mail.n ? ["auto-submitted"] : []),
176
+ ...(mail !== undefined && !ties.includes("mail") && mail.nullReturn * 2 > mail.n
177
+ ? ["null-return-path"]
178
+ : []),
171
179
  ];
172
180
  // One mailbox's newsletter signal must not hide someone the owner talks to in a private chat.
173
181
  if (automated.length > 0 && (facts?.bot || !facts?.twoWay))
@@ -195,7 +203,10 @@ const classified = (database, people, scope, reasons = shownReasons(database, sc
195
203
  const mail = new Map(database
196
204
  .prepare(MAIL_COUNTS(scope))
197
205
  .all(...scopeParams(scope))
198
- .map((row) => [Number(row.person), { n: Number(row.n), bulk: Number(row.bulk) }]));
206
+ .map((row) => [
207
+ Number(row.person),
208
+ { n: Number(row.n), bulk: Number(row.bulk), auto: Number(row.auto), nullReturn: Number(row.null_return) },
209
+ ]));
199
210
  return people.map(({ id, name, owner }) => {
200
211
  const own = facts.get(id);
201
212
  const contact = { username: own?.username ?? null, phone: own?.phone ?? null, email: own?.email ?? null };
@@ -217,15 +228,27 @@ const classified = (database, people, scope, reasons = shownReasons(database, sc
217
228
  usernameSource: own?.usernameSource ?? null,
218
229
  messagesFrom: (own?.messages ?? 0) + (mail.get(id)?.n ?? 0),
219
230
  ties,
231
+ emails: own?.emails ?? [],
232
+ twoWay: own?.twoWay ?? false,
220
233
  };
221
234
  });
222
235
  };
223
236
  const withLastContact = (database, people, known) => {
224
237
  const at = known ??
225
238
  lastContacts(database, people.map(({ id }) => id));
226
- return people.map(({ id, nameOrder: _, ...person }) => {
239
+ const sent = sentMailOf(database, people.map(({ id }) => id));
240
+ return people.map(({ id, nameOrder: _, emails, twoWay, ...person }) => {
227
241
  const time = at.get(id);
228
- return { ...person, lastContact: time === undefined ? null : new Date(time).toISOString() };
242
+ const { ties } = person;
243
+ return {
244
+ ...person,
245
+ lastContact: time === undefined ? null : new Date(time).toISOString(),
246
+ ...senderSignalsOf(sent.get(id) ?? [], {
247
+ addresses: emails,
248
+ ownerWrote: twoWay || ties.includes("mail"),
249
+ chatted: ties.includes("chat") || ties.includes("small-group"),
250
+ }),
251
+ };
229
252
  });
230
253
  };
231
254
  /** Sorted as read, case and accents aside; a name with nothing to read goes last. */
@@ -235,7 +258,7 @@ const byName = (a, b) => a.nameOrder < b.nameOrder ? -1 : a.nameOrder > b.nameOr
235
258
  * Bump when what decides a kind, a name's order or a count changes in code (the word lists, `BULK_MIN`, the ties):
236
259
  * every stored one is worked out again on the next list.
237
260
  */
238
- const KIND_RULES = "5";
261
+ const KIND_RULES = "6";
239
262
  const RULES_KEY = "people.kind_rules";
240
263
  /** Past this many people to work out, one pass over everyone beats a lookup per person. */
241
264
  const WHOLE_PASS = 20_000;
@@ -42,7 +42,7 @@ export declare const noteAddress: (context: StoreContext, ref: IdentityRef, addr
42
42
  * as `info@` and a company's mailbox join no one, here or in the scan. A pair the owner rejected is not joined either: it is
43
43
  * given back, so the caller proposes it when the evidence is new to the owner. Nothing joins the owner, or is
44
44
  * proposed to them, from an address: a mailbox the owner reads may be someone else's, and only the owner joins anyone
45
- * to themselves (SEC-177). A bot or service account joins no one.
45
+ * to themselves. A bot or service account joins no one.
46
46
  */
47
47
  export declare const joinByAddress: (context: StoreContext, ref: IdentityRef, address: string, by: string) => {
48
48
  identity: number;
@@ -52,7 +52,7 @@ export declare const joinByAddress: (context: StoreContext, ref: IdentityRef, ad
52
52
  } | undefined;
53
53
  /**
54
54
  * A person named after an identity that left them takes the name of the oldest identity they still have, or none: the
55
- * owner merged with a partner's CRM contact kept the partner's name after the split (BUG-677).
55
+ * owner merged with a partner's CRM contact kept the partner's name after the split.
56
56
  */
57
57
  export declare const renameAfterLeaving: (context: StoreContext, person: number, left: readonly number[]) => void;
58
58
  /**
@@ -193,7 +193,7 @@ export const mergePerson = (context, one, other, options) => {
193
193
  return to;
194
194
  };
195
195
  /**
196
- * A company's mailbox joins no one at import: two or more other people hold it (NEED-2446), an organization holds it,
196
+ * A company's mailbox joins no one at import: two or more other people hold it, an organization holds it,
197
197
  * or another person of the identity's own list has it, such as a second CRM contact (`sharedLine` in the scan).
198
198
  */
199
199
  const sharedAddress = ({ database }, key, found) => {
@@ -230,7 +230,7 @@ export const noteAddress = (context, ref, address) => {
230
230
  * as `info@` and a company's mailbox join no one, here or in the scan. A pair the owner rejected is not joined either: it is
231
231
  * given back, so the caller proposes it when the evidence is new to the owner. Nothing joins the owner, or is
232
232
  * proposed to them, from an address: a mailbox the owner reads may be someone else's, and only the owner joins anyone
233
- * to themselves (SEC-177). A bot or service account joins no one.
233
+ * to themselves. A bot or service account joins no one.
234
234
  */
235
235
  export const joinByAddress = (context, ref, address, by) => {
236
236
  const key = address.trim().toLowerCase();
@@ -261,7 +261,7 @@ export const joinByAddress = (context, ref, address, by) => {
261
261
  };
262
262
  /**
263
263
  * A person named after an identity that left them takes the name of the oldest identity they still have, or none: the
264
- * owner merged with a partner's CRM contact kept the partner's name after the split (BUG-677).
264
+ * owner merged with a partner's CRM contact kept the partner's name after the split.
265
265
  */
266
266
  export const renameAfterLeaving = (context, person, left) => {
267
267
  const { database } = context;
@@ -4,7 +4,7 @@ import type { Author } from "./memories.js";
4
4
  import type { StoreContext } from "./open.js";
5
5
  export declare const RULE: Author;
6
6
  /**
7
- * NEED-2529: every rule's proposal on the scale of `SHARED_SCORE`, so the review lists the strongest first. A phone two
7
+ * Every rule's proposal on the scale of `SHARED_SCORE`, so the review lists the strongest first. A phone two
8
8
  * people alone have but that does not join (a CRM's or a card's), one name with a phone or an address only these two
9
9
  * hold, and a pair the owner rejected that meets new evidence of that kind are 0.7; one name with a chat or a company
10
10
  * domain in one source, and a meeting guest's typed address, 0.5; a phone or personal address 3–6 people share, 0.4;
@@ -20,14 +20,14 @@ export declare const PROPOSAL_SCORE: {
20
20
  nameInChats: number;
21
21
  };
22
22
  /**
23
- * NEED-2445, safe option until the owner rules: a number two people share joins them only when a messenger, which
23
+ * Safe option until the owner rules: a number two people share joins them only when a messenger, which
24
24
  * keeps its user's own number, holds it; a CRM's or a card's number is someone's word and waits as a proposal.
25
- * NEED-2600: a call's other side, kept as `phone:<number>`, is that number as the phone network gave it, as strong
25
+ * A call's other side, kept as `phone:<number>`, is that number as the phone network gave it, as strong
26
26
  * as a messenger's; it joins only on a mobile number, since an office's landline is everyone's who works there.
27
27
  */
28
28
  export declare const phonePairJoins: (phone: string, holders: Holder[]) => boolean;
29
29
  /**
30
- * BUG-774: holders that each come from a different source are one human seen by each of them (their CRM card, their
30
+ * Holders that each come from a different source are one human seen by each of them (their CRM card, their
31
31
  * WhatsApp, their call), not people on one line, however many person rows they still are.
32
32
  */
33
33
  export declare const oneHolderPerSource: (holders: Holder[]) => boolean;
@@ -41,7 +41,7 @@ export interface Holder {
41
41
  company: boolean;
42
42
  }
43
43
  /**
44
- * SEC-177: a company's line or mailbox is everyone's who works there, so it never says two people are one. It is one
44
+ * A company's line or mailbox is everyone's who works there, so it never says two people are one. It is one
45
45
  * when an organization holds it, or when two people of one list have it, such as two CRM contacts with one number. A
46
46
  * CRM's contact and its user may be one person, so they are two lists. A messenger keeps one account per number, so
47
47
  * two of its accounts on one number are a number that changed hands, not a company's line.
@@ -22,12 +22,12 @@ const CURSOR = "people.scan";
22
22
  /** Raised when a rule changes what a pass finds in values nobody touched: the next pass then reads everything once. */
23
23
  const RULES = 7;
24
24
  /**
25
- * NEED-2526: a shared mailbox says little alone, so its proposal is scored by what else the two people have in common.
25
+ * A shared mailbox says little alone, so its proposal is scored by what else the two people have in common.
26
26
  * The owner's word (2026-11-11): `hr@` is often one person's, so it starts below `info@`.
27
27
  */
28
28
  const SHARED_SCORE = { alone: 0.1, personLike: 0.05, name: 0.4, trace: 0.3, weakTrace: 0.2 };
29
29
  /**
30
- * NEED-2529: every rule's proposal on the scale of `SHARED_SCORE`, so the review lists the strongest first. A phone two
30
+ * Every rule's proposal on the scale of `SHARED_SCORE`, so the review lists the strongest first. A phone two
31
31
  * people alone have but that does not join (a CRM's or a card's), one name with a phone or an address only these two
32
32
  * hold, and a pair the owner rejected that meets new evidence of that kind are 0.7; one name with a chat or a company
33
33
  * domain in one source, and a meeting guest's typed address, 0.5; a phone or personal address 3–6 people share, 0.4;
@@ -43,25 +43,25 @@ export const PROPOSAL_SCORE = {
43
43
  nameInChats: 0.3,
44
44
  };
45
45
  /**
46
- * NEED-2445, safe option until the owner rules: a number two people share joins them only when a messenger, which
46
+ * Safe option until the owner rules: a number two people share joins them only when a messenger, which
47
47
  * keeps its user's own number, holds it; a CRM's or a card's number is someone's word and waits as a proposal.
48
- * NEED-2600: a call's other side, kept as `phone:<number>`, is that number as the phone network gave it, as strong
48
+ * A call's other side, kept as `phone:<number>`, is that number as the phone network gave it, as strong
49
49
  * as a messenger's; it joins only on a mobile number, since an office's landline is everyone's who works there.
50
50
  */
51
51
  export const phonePairJoins = (phone, holders) => holders.some(({ provider }) => BARE_INTERNATIONAL_PROVIDERS.includes(provider)) ||
52
52
  (holders.some(({ externalId }) => externalId === `phone:${phone}`) && isMobilePhone(phone));
53
53
  /**
54
- * BUG-774: holders that each come from a different source are one human seen by each of them (their CRM card, their
54
+ * Holders that each come from a different source are one human seen by each of them (their CRM card, their
55
55
  * WhatsApp, their call), not people on one line, however many person rows they still are.
56
56
  */
57
57
  export const oneHolderPerSource = (holders) => new Set(holders.map(({ list }) => list)).size === holders.length;
58
- /** NEED-2446, safe option until the owner rules: an address more than two people have is shared, so it proposes. */
58
+ /** Safe option until the owner rules: an address more than two people have is shared, so it proposes. */
59
59
  const addressGroupJoins = (people) => people <= 2;
60
60
  /** A bot or a service account shares its number or address with whoever runs it; it is nobody's person. */
61
61
  const NOT_A_BOT = "i.bot IS NOT 1 AND i.provider NOT LIKE '%-bot'";
62
62
  const COMPANY = "EXISTS (SELECT 1 FROM organization_identities o WHERE o.identity_id = i.id) AS company";
63
63
  /**
64
- * SEC-177: a company's line or mailbox is everyone's who works there, so it never says two people are one. It is one
64
+ * A company's line or mailbox is everyone's who works there, so it never says two people are one. It is one
65
65
  * when an organization holds it, or when two people of one list have it, such as two CRM contacts with one number. A
66
66
  * CRM's contact and its user may be one person, so they are two lists. A messenger keeps one account per number, so
67
67
  * two of its accounts on one number are a number that changed hands, not a company's line.
@@ -123,7 +123,7 @@ const add = (found, key, holder) => {
123
123
  found.set(key, held);
124
124
  };
125
125
  /**
126
- * NEED-2600: a CRM keeps a number as someone typed it, `8 (912) 345-67-89`; without a `+` it is read in the store's
126
+ * A CRM keeps a number as someone typed it, `8 (912) 345-67-89`; without a `+` it is read in the store's
127
127
  * `phone_countries` (Russian by default), so a call from that number finds the contact. A messenger's bare digits stay
128
128
  * international (`storedPhone`).
129
129
  */
@@ -192,7 +192,7 @@ const resolveNames = (context, person) => resolvePersonLinks(context.database, c
192
192
  .all(person)
193
193
  .flatMap((row) => [row.name, row.username]));
194
194
  /**
195
- * Joins two people unless the owner separated them, or rejected the pair (NEED-2444): then the pair is proposed when
195
+ * Joins two people unless the owner separated them, or rejected the pair: then the pair is proposed when
196
196
  * this evidence is new to the owner. Gives the person that stays.
197
197
  */
198
198
  const join = (pass, sides, signal) => {
@@ -224,7 +224,7 @@ const join = (pass, sides, signal) => {
224
224
  return kept;
225
225
  };
226
226
  /**
227
- * SEC-177: the scan never joins the owner or proposes anyone to them; a mailbox or number the owner reads may be
227
+ * The scan never joins the owner or proposes anyone to them; a mailbox or number the owner reads may be
228
228
  * someone else's, and only the owner joins anyone to themselves.
229
229
  */
230
230
  const touchesOwner = ({ context, result }, from, to, signal) => {
@@ -270,9 +270,9 @@ const tooMany = (pass, people, reason, signal) => {
270
270
  };
271
271
  const skipShared = (pass, people, signal) => pass.result.skipped.push({ persons: [...people.keys()].map(String), signal, reason: `identity.shared-${signal}` });
272
272
  /**
273
- * A number two people have joins them (NEED-2445), and so does one each source has once (BUG-774); one that more
274
- * share proposes. A company's line does neither. A proposal still open for the pair never keeps it from joining
275
- * (BUG-775): the join settles it.
273
+ * A number two people have joins them, and so does one each source has once; one that more
274
+ * share proposes. A company's line does neither. A proposal still open for the pair never keeps it from joining:
275
+ * the join settles it.
276
276
  */
277
277
  const samePhone = (pass, phone, holders) => {
278
278
  const people = peopleOf(pass.context, holders);
@@ -319,7 +319,7 @@ const sharedMailboxCase = (context, address, from, to) => {
319
319
  return { score: Math.round(score * 100) / 100, reason: reasons.join("; "), evidence };
320
320
  };
321
321
  /**
322
- * NEED-2526: a shared mailbox never joins anyone (SEC-177), but each pair on it is proposed to the owner, scored by
322
+ * A shared mailbox never joins anyone, but each pair on it is proposed to the owner, scored by
323
323
  * what else they share.
324
324
  */
325
325
  const proposeShared = (pass, { address, holders, shared }) => {
@@ -343,8 +343,8 @@ const proposeShared = (pass, { address, holders, shared }) => {
343
343
  });
344
344
  };
345
345
  /**
346
- * One address is one person in any scope (NEED-2382), unless more than two people have it (NEED-2446). A no-reply
347
- * address is no one's. A role address such as `info@` and a company's mailbox only propose (NEED-2526).
346
+ * One address is one person in any scope, unless more than two people have it. A no-reply
347
+ * address is no one's. A role address such as `info@` and a company's mailbox only propose.
348
348
  */
349
349
  const sameEmail = (pass, address, holders) => {
350
350
  if (isNoReplyAddress(address))
@@ -374,7 +374,7 @@ const providersOf = ({ database }, person) => new Set(database
374
374
  .all(person)
375
375
  .map(({ provider }) => String(provider)));
376
376
  /**
377
- * SEC-177: a phone or address proves only when it is these two people's alone. A chat or a company's domain is weaker,
377
+ * A phone or address proves only when it is these two people's alone. A chat or a company's domain is weaker,
378
378
  * and is enough only between people of one source, whose names come from one place.
379
379
  */
380
380
  const strongEnough = (context, from, to, trace) => {
@@ -13,7 +13,7 @@ export declare const bounded: (column: string, bounds: {
13
13
  }[];
14
14
  /** A window's bound, a `YYYY-MM-DD` day in `zone` (its start, or its end for `end`) or an ISO time, as epoch ms. */
15
15
  export declare const boundOf: (value: string | undefined, what: string, zone: string, end?: boolean) => number | null;
16
- /** A stage the CRM removed stays in a pipeline only while a row stands in it (BUG-7). */
16
+ /** A stage the CRM removed stays in a pipeline only while a row stands in it. */
17
17
  export declare const SHOWN_STAGE: string;
18
18
  /** Each stage of these pipelines that is shown, with how many open deals and leads the viewer may read stand in it. */
19
19
  export declare const openPerStage: (database: CacheDatabase, pipelineIds: number[], viewer?: CopyViewer) => Record<string, unknown>[];
@@ -25,7 +25,7 @@ export const boundOf = (value, what, zone, end = false) => {
25
25
  return refuse(`${what} is a YYYY-MM-DD day or an ISO time, not ${value}`, "deal.field");
26
26
  }
27
27
  };
28
- /** A stage the CRM removed stays in a pipeline only while a row stands in it (BUG-7). */
28
+ /** A stage the CRM removed stays in a pipeline only while a row stands in it. */
29
29
  export const SHOWN_STAGE = "(s.deleted_at IS NULL OR EXISTS (SELECT 1 FROM deals d WHERE d.stage_id = s.id AND d.deleted_at IS NULL) " +
30
30
  "OR EXISTS (SELECT 1 FROM leads l WHERE l.stage_id = s.id AND l.deleted_at IS NULL))";
31
31
  /** Each stage of these pipelines that is shown, with how many open deals and leads the viewer may read stand in it. */
@@ -0,0 +1,52 @@
1
+ import type { CacheDatabase } from "../driver.js";
2
+ /**
3
+ * A migration drizzle-kit wrote as table copies (`CREATE TABLE __new_x`, copy, `DROP TABLE x`, rename). SQLite drops a
4
+ * table's triggers and indexes with it, and fires `ON DELETE` actions on the drop unless foreign keys are off, which
5
+ * they can only be outside a transaction. So the runner turns them off before `BEGIN` and this keeps the rest whole:
6
+ * it refuses a table whose columns the copy would lose, settles the rows the new `CHECK`s would refuse, puts back
7
+ * every trigger and index of the copied tables (other tools' included) and checks their foreign keys before `COMMIT`.
8
+ */
9
+ export interface Rebuild {
10
+ tables: {
11
+ name: string;
12
+ columns: string[];
13
+ }[];
14
+ checks: {
15
+ table: string;
16
+ name: string;
17
+ expression: string;
18
+ }[];
19
+ }
20
+ export declare const rebuildOf: (statements: string[]) => Rebuild | undefined;
21
+ export declare const rebuilds: (statements: string[]) => boolean;
22
+ /**
23
+ * The same migration with each empty copied table dropped and created under its own name, with no copy and no
24
+ * rename; a table with rows is copied as drizzle-kit wrote it. A hundred renames were most of a new store's first open.
25
+ */
26
+ export declare const withoutEmptyCopies: (statements: string[], rows: ReadonlyMap<string, number>) => string[];
27
+ export interface Saved {
28
+ objects: {
29
+ name: string;
30
+ sql: string;
31
+ }[];
32
+ notes: string[];
33
+ /** References that already pointed at missing rows before the copy, by `referenceKey`. */
34
+ broken: Set<string>;
35
+ /** Rows in each copied table before the copy. */
36
+ rows: Map<string, number>;
37
+ }
38
+ /**
39
+ * Inside the transaction, before the statements. Invalid JSON is kept whole as a JSON string (`json_quote`), and the
40
+ * repair is reported and kept in `store_settings`; any other row a new `CHECK` refuses stops the migration, naming it.
41
+ */
42
+ export declare const beforeRebuild: (database: CacheDatabase, rebuild: Rebuild, version: number, now: number) => Saved;
43
+ /** After the statements, still inside the transaction. */
44
+ export declare const afterRebuild: (database: CacheDatabase, rebuild: Rebuild, saved: Saved, version: number) => void;
45
+ /** Outside any transaction: SQLite ignores `foreign_keys` inside one. */
46
+ export declare const pauseForeignKeys: (database: CacheDatabase) => (() => void);
47
+ /**
48
+ * Around the copies only: a rename must not rewrite, or fail on, the triggers and views of other tables that name the
49
+ * copied one. An earlier migration in the same run renames tables and relies on exactly that rewrite.
50
+ */
51
+ export declare const legacyRenames: (database: CacheDatabase, on: boolean) => void;
52
+ export declare const foreignKeysOff: (database: CacheDatabase) => boolean;
@@ -0,0 +1,176 @@
1
+ import { CliError } from "@wirecat/cli-base";
2
+ const quote = (name) => `"${name.replaceAll('"', '""')}"`;
3
+ const unquote = (name) => name.replace(/^[`"]|[`"]$/g, "");
4
+ export const rebuildOf = (statements) => {
5
+ const tables = [];
6
+ const checks = [];
7
+ for (const statement of statements) {
8
+ const created = /^CREATE TABLE `__new_(\w+)`/.exec(statement);
9
+ if (created?.[1]) {
10
+ const table = created[1];
11
+ for (const found of statement.matchAll(/CONSTRAINT "(\w+)" CHECK\((.*)\)(?:,|\n\))/g))
12
+ checks.push({ table, name: String(found[1]), expression: String(found[2]) });
13
+ }
14
+ const copied = /^INSERT INTO `__new_(\w+)`\(([^)]*)\) SELECT/.exec(statement);
15
+ if (copied?.[1] && copied[2])
16
+ tables.push({ name: copied[1], columns: copied[2].split(",").map((column) => unquote(column.trim())) });
17
+ }
18
+ return tables.length > 0 ? { tables, checks } : undefined;
19
+ };
20
+ export const rebuilds = (statements) => rebuildOf(statements) !== undefined;
21
+ /**
22
+ * The same migration with each empty copied table dropped and created under its own name, with no copy and no
23
+ * rename; a table with rows is copied as drizzle-kit wrote it. A hundred renames were most of a new store's first open.
24
+ */
25
+ export const withoutEmptyCopies = (statements, rows) => {
26
+ const copied = new Set(statements
27
+ .flatMap((statement) => /^CREATE TABLE `__new_(\w+)`/.exec(statement)?.[1] ?? [])
28
+ .filter((table) => rows.get(table) === 0));
29
+ const skipped = (statement) => {
30
+ const name = /^INSERT INTO `__new_(\w+)`/.exec(statement)?.[1] ??
31
+ /^DROP TABLE `(\w+)`;$/.exec(statement.trim())?.[1] ??
32
+ /^ALTER TABLE `__new_(\w+)` RENAME TO `\w+`;$/.exec(statement.trim())?.[1];
33
+ return name !== undefined && copied.has(name);
34
+ };
35
+ return statements.flatMap((statement) => {
36
+ const created = /^CREATE TABLE `__new_(\w+)`/.exec(statement)?.[1];
37
+ if (created && copied.has(created))
38
+ return [`DROP TABLE IF EXISTS \`${created}\`;`, statement.replace(`\`__new_${created}\``, `\`${created}\``)];
39
+ return skipped(statement) ? [] : [statement];
40
+ });
41
+ };
42
+ /**
43
+ * By the referring columns, not `fkid`: the copy may list the foreign keys in another order. Each copied table has an
44
+ * integer `id`, so its rowid survives the copy.
45
+ */
46
+ const referenceKey = ({ table, rowid, parent, column }) => `${table}\u0000${rowid}\u0000${parent}\u0000${column}`;
47
+ const rowsOf = (database, tables) => new Map(tables.map((table) => [table, Number(database.prepare(`SELECT count(*) AS n FROM ${quote(table)}`).get()?.n)]));
48
+ const danglingIn = (database, tables) => tables.flatMap((table) => {
49
+ const rows = database.prepare(`PRAGMA foreign_key_check(${quote(table)})`).all();
50
+ if (rows.length === 0)
51
+ return [];
52
+ const columns = new Map();
53
+ for (const fk of database.prepare('SELECT id, "from" FROM pragma_foreign_key_list(?) ORDER BY id, seq').all(table))
54
+ columns.set(Number(fk.id), [...(columns.get(Number(fk.id)) ?? []), String(fk.from)]);
55
+ return rows.map((row) => ({
56
+ table,
57
+ rowid: Number(row.rowid),
58
+ parent: String(row.parent),
59
+ column: (columns.get(Number(row.fkid)) ?? []).join(", "),
60
+ }));
61
+ });
62
+ const grouped = (dangling) => {
63
+ const groups = new Map();
64
+ for (const { table, rowid, parent, column } of dangling) {
65
+ const key = `${table}\u0000${column}\u0000${parent}`;
66
+ const group = groups.get(key) ?? { table, column, parent, rows: 0, ids: [] };
67
+ group.rows += 1;
68
+ if (group.ids.length < KEPT_IDS)
69
+ group.ids.push(rowid);
70
+ groups.set(key, group);
71
+ }
72
+ return [...groups.values()];
73
+ };
74
+ const described = ({ table, column, parent, rows, ids }) => `${table}.${column} in ${rows === 1 ? "1 row" : `${rows} rows`} (${listed(ids)}) → ${parent}`;
75
+ const columnsOf = (database, table) => database
76
+ .prepare("SELECT name FROM pragma_table_info(?)")
77
+ .all(table)
78
+ .map((row) => String(row.name));
79
+ const idsOf = (database, table, where) => database
80
+ .prepare(`SELECT id FROM ${quote(table)} WHERE ${where} ORDER BY id`)
81
+ .all()
82
+ .map((row) => Number(row.id));
83
+ const listed = (ids) => ids.length > 20 ? `${ids.slice(0, 20).join(", ")} and ${ids.length - 20} more` : ids.join(", ");
84
+ const KEPT_IDS = 1000;
85
+ const JSON_RULE = /^"(\w+)" IS NULL OR json_valid\("\1"\)$/;
86
+ /**
87
+ * Inside the transaction, before the statements. Invalid JSON is kept whole as a JSON string (`json_quote`), and the
88
+ * repair is reported and kept in `store_settings`; any other row a new `CHECK` refuses stops the migration, naming it.
89
+ */
90
+ export const beforeRebuild = (database, rebuild, version, now) => {
91
+ const names = rebuild.tables.map(({ name }) => name);
92
+ for (const { name, columns } of rebuild.tables) {
93
+ const kept = new Set(columns);
94
+ const lost = columnsOf(database, name).filter((column) => !kept.has(column));
95
+ if (lost.length > 0)
96
+ throw new CliError("configuration_error", `schema ${version} copies ${name} without its columns ${lost.join(", ")}, which this store has and this build does not know — nothing was changed`, { reason: "store.unknown-columns" });
97
+ }
98
+ const objects = database
99
+ .prepare(`SELECT type, name, sql FROM sqlite_master WHERE type IN ('index', 'trigger') AND sql IS NOT NULL
100
+ AND tbl_name IN (${names.map(() => "?").join(", ")}) ORDER BY rowid`)
101
+ .all(...names)
102
+ .map((row) => ({ type: String(row.type), name: String(row.name), sql: String(row.sql) }));
103
+ // The repairs below must not fire them; they come back after the copy.
104
+ for (const { type, name } of objects)
105
+ if (type === "trigger")
106
+ database.exec(`DROP TRIGGER ${quote(name)}`);
107
+ const repaired = [];
108
+ const refused = [];
109
+ for (const { table, name, expression } of rebuild.checks) {
110
+ const ids = idsOf(database, table, `NOT (${expression})`);
111
+ if (ids.length === 0)
112
+ continue;
113
+ const column = JSON_RULE.exec(expression)?.[1];
114
+ if (column) {
115
+ database.exec(`UPDATE ${quote(table)} SET ${quote(column)} = json_quote(${quote(column)}) WHERE NOT (${expression})`);
116
+ repaired.push({ table, column, rows: ids.length, ids: ids.slice(0, KEPT_IDS) });
117
+ }
118
+ else {
119
+ refused.push(`${table} rows ${listed(ids)} break ${name} (${expression})`);
120
+ }
121
+ }
122
+ if (refused.length > 0)
123
+ throw new CliError("configuration_error", `the store holds rows schema ${version} refuses, so it was not migrated and nothing was changed: ${refused.join("; ")}. ` +
124
+ "Correct or delete those rows (an older tool still opens the store, and so does sqlite3), then open it again", { reason: "store.rows-break-checks" });
125
+ const notes = repaired.map(({ table, column, rows, ids }) => `${table}.${column} held text that is not JSON in ${rows === 1 ? "1 row" : `${rows} rows`} (${listed(ids)}); each is kept whole as a JSON string`);
126
+ if (repaired.length > 0)
127
+ database
128
+ .prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
129
+ .run(`migration:${version}:repaired`, JSON.stringify(repaired), now);
130
+ // Rows a sync or an older tool left pointing at deleted rows: the copy keeps them as they are, and says so.
131
+ const dangling = danglingIn(database, names);
132
+ if (dangling.length > 0) {
133
+ const groups = grouped(dangling);
134
+ notes.push(`these references already pointed at rows that do not exist, and are kept as they were: ${groups.map(described).join("; ")}`);
135
+ database
136
+ .prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
137
+ .run(`migration:${version}:broken-references`, JSON.stringify(groups), now);
138
+ }
139
+ return { objects, notes, broken: new Set(dangling.map(referenceKey)), rows: rowsOf(database, names) };
140
+ };
141
+ /** After the statements, still inside the transaction. */
142
+ export const afterRebuild = (database, rebuild, saved, version) => {
143
+ const present = new Set(database
144
+ .prepare("SELECT name FROM sqlite_master")
145
+ .all()
146
+ .map((row) => String(row.name)));
147
+ for (const { name, sql } of saved.objects)
148
+ if (!present.has(name))
149
+ database.exec(sql);
150
+ // A copy that drops rows breaks the references other tables hold to them, which the check below does not see.
151
+ const after = rowsOf(database, [...saved.rows.keys()]);
152
+ const changed = [...saved.rows].filter(([table, rows]) => after.get(table) !== rows);
153
+ if (changed.length > 0)
154
+ throw new CliError("configuration_error", `the migration to schema ${version} would change how many rows these tables hold, so it was not run and nothing ` +
155
+ `was changed: ${changed.map(([table, rows]) => `${table} ${rows} → ${after.get(table)}`).join("; ")}. The ` +
156
+ "store is whole and the tool you used before still opens it; keep using that one and report this at " +
157
+ "https://github.com/WireCatLabs/cli-core/issues", { reason: "store.rows-lost" });
158
+ const broken = danglingIn(database, rebuild.tables.map(({ name }) => name)).filter((reference) => !saved.broken.has(referenceKey(reference)));
159
+ if (broken.length > 0)
160
+ throw new CliError("configuration_error", `the migration to schema ${version} would break these references, so it was not run and nothing was changed: ` +
161
+ `${grouped(broken).map(described).join("; ")}. The store is whole and the tool you used before still opens ` +
162
+ "it; keep using that one and report this at https://github.com/WireCatLabs/cli-core/issues", { reason: "store.foreign-keys" });
163
+ };
164
+ /** Outside any transaction: SQLite ignores `foreign_keys` inside one. */
165
+ export const pauseForeignKeys = (database) => {
166
+ database.exec("PRAGMA foreign_keys = OFF");
167
+ return () => database.exec("PRAGMA foreign_keys = ON");
168
+ };
169
+ /**
170
+ * Around the copies only: a rename must not rewrite, or fail on, the triggers and views of other tables that name the
171
+ * copied one. An earlier migration in the same run renames tables and relies on exactly that rewrite.
172
+ */
173
+ export const legacyRenames = (database, on) => {
174
+ database.exec(`PRAGMA legacy_alter_table = ${on ? "ON" : "OFF"}`);
175
+ };
176
+ export const foreignKeysOff = (database) => Number(database.prepare("PRAGMA foreign_keys").get()?.foreign_keys) === 0;
@@ -5,7 +5,7 @@ import { calendarWritesOver } from "./calendar.js";
5
5
  import { chatPkFor, findChatPk, raiseLastMessageAt, upsertChat, writeMembers } from "./chats.js";
6
6
  import { seenIdentity } from "./identities.js";
7
7
  import { COUNTERPART_ROLE, linkKind } from "./link-kinds.js";
8
- import { tombstone, upsertMessage } from "./messages.js";
8
+ import { linkThreadChildren, tombstone, upsertMessage } from "./messages.js";
9
9
  import { requiredThing } from "./notes.js";
10
10
  import { e164Of } from "./person-matcher.js";
11
11
  import { importedIdentity, linkToPerson } from "./record-matching.js";
@@ -88,6 +88,7 @@ const saveSms = (projection, tools, revive = false) => {
88
88
  };
89
89
  // Seen after its tombstone, the messenger path takes a deleted message back, its text with it.
90
90
  upsertMessage(context, account, account.pk, chatKey, message, importedBy(source).source, revive ? context.now() + 1 : undefined);
91
+ linkThreadChildren(context, chatKey, [message.id]);
91
92
  raiseLastMessageAt(context, chatKey, sentAt);
92
93
  return formatReference({
93
94
  type: "message",
@@ -23,7 +23,7 @@ export interface RelationFilter {
23
23
  accounts?: AccountKey[];
24
24
  /** No row with an end of these types, such as `deal` and `lead` a profile denies. */
25
25
  deniedKinds?: string[];
26
- /** No row with a deal or lead end that one of these may not read (SEC-197); each limits only its own account. */
26
+ /** No row with a deal or lead end that one of these may not read; each limits only its own account. */
27
27
  viewers?: readonly CopyViewer[];
28
28
  limit?: number;
29
29
  /** 1-based. */