@wirecat/cli-core 0.617.0 → 0.619.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 (306) hide show
  1. package/CHANGELOG.md +406 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/backfill.d.ts +21 -0
  5. package/dist/background/backfill.js +41 -0
  6. package/dist/background/daily-archive-timer.d.ts +1 -1
  7. package/dist/background/deliver.d.ts +5 -2
  8. package/dist/background/deliver.js +30 -12
  9. package/dist/background/report/messages.js +4 -1
  10. package/dist/background/report/render.d.ts +3 -1
  11. package/dist/background/report/render.js +3 -1
  12. package/dist/background/report/view.js +4 -1
  13. package/dist/background/schedules.d.ts +17 -0
  14. package/dist/background/schedules.js +21 -8
  15. package/dist/calendar/cli/answers.d.ts +1 -0
  16. package/dist/calendar/cli/answers.js +6 -1
  17. package/dist/calendar/cli/index.js +2 -14
  18. package/dist/calendar/cli/people-link.d.ts +3 -0
  19. package/dist/calendar/cli/people-link.js +23 -0
  20. package/dist/calendar/index.d.ts +1 -1
  21. package/dist/calendar/index.js +1 -1
  22. package/dist/calendar/mcp/index.d.ts +12 -12
  23. package/dist/cli/base-stages-command.d.ts +22 -0
  24. package/dist/cli/base-stages-command.js +174 -0
  25. package/dist/cli/command-runs.d.ts +2 -0
  26. package/dist/cli/command-runs.js +3 -1
  27. package/dist/cli/config-command.js +6 -1
  28. package/dist/cli/context.d.ts +5 -0
  29. package/dist/cli/context.js +1 -0
  30. package/dist/cli/group-lock.d.ts +42 -0
  31. package/dist/cli/group-lock.js +130 -0
  32. package/dist/cli/index.d.ts +10 -4
  33. package/dist/cli/index.js +10 -4
  34. package/dist/cli/messenger/backfill-command.js +27 -15
  35. package/dist/cli/messenger/contacts-command.js +10 -3
  36. package/dist/cli/messenger/context.js +1 -0
  37. package/dist/cli/messenger/doctor-command.js +3 -1
  38. package/dist/cli/messenger/models-command.js +1 -1
  39. package/dist/cli/messenger/serve-command.js +24 -2
  40. package/dist/cli/messenger/serve-outdated.d.ts +22 -0
  41. package/dist/cli/messenger/serve-outdated.js +100 -0
  42. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  43. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  44. package/dist/cli/model-catalogue-command.d.ts +3 -1
  45. package/dist/cli/model-catalogue-command.js +46 -2
  46. package/dist/cli/profile.d.ts +8 -0
  47. package/dist/cli/profile.js +25 -0
  48. package/dist/cli/program.js +2 -0
  49. package/dist/cli/runs/search-query.d.ts +1 -1
  50. package/dist/cli/runs/search-query.js +4 -0
  51. package/dist/cli/runs/search.d.ts +5 -1
  52. package/dist/cli/runs/search.js +12 -1
  53. package/dist/cli/schedule/schedule-command.d.ts +9 -0
  54. package/dist/cli/schedule/schedule-command.js +13 -0
  55. package/dist/cli/search-left-out.d.ts +6 -1
  56. package/dist/cli/search-left-out.js +9 -4
  57. package/dist/cli/settings.d.ts +8 -0
  58. package/dist/cli/settings.js +17 -2
  59. package/dist/cli/shared-command-exports.d.ts +16 -0
  60. package/dist/cli/store-recover.d.ts +3 -3
  61. package/dist/cli/store-recover.js +47 -23
  62. package/dist/cli/store-settings.d.ts +2 -0
  63. package/dist/cli/store-settings.js +37 -9
  64. package/dist/crm/cli/index.js +38 -6
  65. package/dist/crm/group-hint.d.ts +8 -0
  66. package/dist/crm/group-hint.js +13 -0
  67. package/dist/crm/source.d.ts +12 -1
  68. package/dist/crm/sync.d.ts +31 -2
  69. package/dist/crm/sync.js +110 -3
  70. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  71. package/dist/crm/testing/acme-scenario.js +170 -0
  72. package/dist/crm/testing/index.d.ts +1 -0
  73. package/dist/crm/testing/index.js +1 -0
  74. package/dist/crm/testing/source-contract.js +12 -0
  75. package/dist/crm/testing/source.d.ts +2 -0
  76. package/dist/crm/testing/source.js +1 -0
  77. package/dist/domain/addresses.d.ts +13 -0
  78. package/dist/domain/addresses.js +63 -0
  79. package/dist/domain/categories.d.ts +3 -0
  80. package/dist/domain/categories.js +2 -0
  81. package/dist/domain/crm.d.ts +23 -0
  82. package/dist/domain/crm.js +7 -0
  83. package/dist/domain/links.d.ts +17 -4
  84. package/dist/domain/links.js +20 -7
  85. package/dist/domain/mentions.d.ts +2 -12
  86. package/dist/domain/mentions.js +2 -19
  87. package/dist/domain/orders.d.ts +8 -1
  88. package/dist/domain/orders.js +6 -2
  89. package/dist/domain/phones.d.ts +26 -0
  90. package/dist/domain/phones.js +48 -0
  91. package/dist/domain/record-types.d.ts +1 -1
  92. package/dist/domain/record-types.js +1 -0
  93. package/dist/domain/records.d.ts +5 -0
  94. package/dist/domain/ref-summaries.d.ts +39 -0
  95. package/dist/domain/ref-summaries.js +51 -3
  96. package/dist/domain/relations.d.ts +27 -2
  97. package/dist/domain/relations.js +37 -3
  98. package/dist/domain/vcard.d.ts +2 -2
  99. package/dist/domain/vcard.js +4 -10
  100. package/dist/embeddings/models.d.ts +11 -3
  101. package/dist/embeddings/models.js +28 -4
  102. package/dist/entities/business-context.d.ts +149 -0
  103. package/dist/entities/business-context.js +192 -0
  104. package/dist/entities/contact-activity.d.ts +2 -0
  105. package/dist/entities/contact-activity.js +7 -1
  106. package/dist/entities/contact-context.d.ts +157 -0
  107. package/dist/entities/contact-context.js +2 -0
  108. package/dist/entities/deal.d.ts +10 -0
  109. package/dist/entities/deal.js +2 -0
  110. package/dist/entities/index.d.ts +23 -3
  111. package/dist/entities/index.js +5 -0
  112. package/dist/entities/mention.d.ts +4 -3
  113. package/dist/entities/mention.js +2 -1
  114. package/dist/entities/message-transfer.d.ts +4 -2
  115. package/dist/entities/message-transfer.js +2 -2
  116. package/dist/entities/model.d.ts +2 -2
  117. package/dist/entities/model.js +1 -1
  118. package/dist/entities/relationship.d.ts +4 -0
  119. package/dist/entities/relationship.js +4 -0
  120. package/dist/errors/reasons.js +44 -4
  121. package/dist/fetch/page.js +2 -1
  122. package/dist/index.d.ts +4 -3
  123. package/dist/index.js +4 -3
  124. package/dist/meetings/context-store.d.ts +2 -0
  125. package/dist/meetings/findings-rules.d.ts +4 -0
  126. package/dist/meetings/findings-rules.js +5 -2
  127. package/dist/meetings/mcp/index.d.ts +15 -15
  128. package/dist/meetings/result-items.d.ts +1 -0
  129. package/dist/meetings/result-items.js +1 -0
  130. package/dist/models/index.js +22 -5
  131. package/dist/runs/events.d.ts +11 -1
  132. package/dist/runs/events.js +3 -1
  133. package/dist/runs/log-attributes.js +4 -0
  134. package/dist/runs/log-events.js +2 -0
  135. package/dist/runs/recording.d.ts +3 -0
  136. package/dist/runs/recording.js +36 -12
  137. package/dist/runs/run.d.ts +12 -3
  138. package/dist/runs/run.js +32 -13
  139. package/dist/search/account-list.d.ts +6 -0
  140. package/dist/search/account-list.js +9 -3
  141. package/dist/search/groups.d.ts +68 -0
  142. package/dist/search/groups.js +172 -0
  143. package/dist/services/account-groups.d.ts +28 -0
  144. package/dist/services/account-groups.js +89 -0
  145. package/dist/services/archive.d.ts +7 -1
  146. package/dist/services/archive.js +19 -3
  147. package/dist/services/business-context.d.ts +113 -0
  148. package/dist/services/business-context.js +156 -0
  149. package/dist/services/communications.d.ts +50 -0
  150. package/dist/services/communications.js +140 -0
  151. package/dist/services/deal-context.d.ts +90 -0
  152. package/dist/services/deal-context.js +131 -0
  153. package/dist/services/deps.d.ts +2 -0
  154. package/dist/services/enrichment.d.ts +7 -2
  155. package/dist/services/enrichment.js +46 -5
  156. package/dist/services/events-search.js +2 -1
  157. package/dist/services/group-guard.d.ts +28 -0
  158. package/dist/services/group-guard.js +131 -0
  159. package/dist/services/index.d.ts +15 -2
  160. package/dist/services/index.js +9 -2
  161. package/dist/services/ingest.d.ts +12 -0
  162. package/dist/services/ingest.js +4 -0
  163. package/dist/services/link-scorers/chat-senders.js +39 -29
  164. package/dist/services/link-scorers/member-chats.js +4 -3
  165. package/dist/services/link-scorers/member-dialog.js +5 -7
  166. package/dist/services/link-scorers/scan.js +17 -8
  167. package/dist/services/link-scorers/shared.d.ts +6 -2
  168. package/dist/services/link-scorers/shared.js +6 -2
  169. package/dist/services/link-scorers/types.d.ts +2 -0
  170. package/dist/services/meaning-model.d.ts +7 -0
  171. package/dist/services/meaning-model.js +20 -0
  172. package/dist/services/meeting-context.d.ts +6 -1
  173. package/dist/services/meeting-context.js +12 -5
  174. package/dist/services/message-resolution.js +2 -3
  175. package/dist/services/messages-meaning.js +4 -5
  176. package/dist/services/messages-search.d.ts +5 -1
  177. package/dist/services/messages-search.js +1 -1
  178. package/dist/services/model-downloads.d.ts +1 -1
  179. package/dist/services/model-downloads.js +6 -4
  180. package/dist/services/money-context.d.ts +73 -0
  181. package/dist/services/money-context.js +77 -0
  182. package/dist/services/notes-search.d.ts +4 -1
  183. package/dist/services/notes-search.js +19 -7
  184. package/dist/services/organization-context.d.ts +80 -0
  185. package/dist/services/organization-context.js +154 -0
  186. package/dist/services/people.d.ts +22 -6
  187. package/dist/services/people.js +38 -8
  188. package/dist/services/person-business.d.ts +43 -0
  189. package/dist/services/person-business.js +67 -0
  190. package/dist/services/person-context.d.ts +9 -1
  191. package/dist/services/person-context.js +5 -3
  192. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  193. package/dist/services/proposals/kinds/identity-link.js +48 -0
  194. package/dist/services/proposals/kinds/orders.js +1 -1
  195. package/dist/services/proposals/registry.js +2 -0
  196. package/dist/services/search-kind.d.ts +12 -5
  197. package/dist/services/search-kind.js +49 -10
  198. package/dist/services/text-model-choice.js +1 -1
  199. package/dist/store/accounts.d.ts +18 -0
  200. package/dist/store/accounts.js +18 -3
  201. package/dist/store/damage.d.ts +43 -10
  202. package/dist/store/damage.js +119 -36
  203. package/dist/store/decisions.js +3 -1
  204. package/dist/store/evidence-findings.d.ts +14 -0
  205. package/dist/store/evidence-findings.js +2 -0
  206. package/dist/store/exports.d.ts +2 -1
  207. package/dist/store/identity-links.d.ts +92 -0
  208. package/dist/store/identity-links.js +6 -0
  209. package/dist/store/index.d.ts +11 -5
  210. package/dist/store/index.js +5 -2
  211. package/dist/store/journal.d.ts +10 -0
  212. package/dist/store/journal.js +33 -0
  213. package/dist/store/marks.d.ts +19 -1
  214. package/dist/store/marks.js +23 -1
  215. package/dist/store/migrations.d.ts +1 -1
  216. package/dist/store/migrations.js +35 -12
  217. package/dist/store/people.d.ts +22 -0
  218. package/dist/store/people.js +15 -1
  219. package/dist/store/recover.d.ts +34 -0
  220. package/dist/store/recover.js +188 -6
  221. package/dist/store/refill.d.ts +28 -0
  222. package/dist/store/refill.js +120 -0
  223. package/dist/store/sqlite/accounts.js +2 -0
  224. package/dist/store/sqlite/base-stages.d.ts +122 -0
  225. package/dist/store/sqlite/base-stages.js +443 -0
  226. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  227. package/dist/store/sqlite/base-suggest.js +62 -0
  228. package/dist/store/sqlite/business-contracts.js +10 -1
  229. package/dist/store/sqlite/clients.d.ts +7 -3
  230. package/dist/store/sqlite/clients.js +11 -7
  231. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  232. package/dist/store/sqlite/crm-settings.js +56 -13
  233. package/dist/store/sqlite/crm.d.ts +13 -1
  234. package/dist/store/sqlite/crm.js +20 -4
  235. package/dist/store/sqlite/deals.d.ts +33 -0
  236. package/dist/store/sqlite/deals.js +42 -4
  237. package/dist/store/sqlite/decision-requests.js +7 -3
  238. package/dist/store/sqlite/email-index.js +17 -15
  239. package/dist/store/sqlite/evidence-findings.js +29 -5
  240. package/dist/store/sqlite/findings-core.js +4 -2
  241. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  242. package/dist/store/sqlite/identity-link-rows.js +146 -0
  243. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  244. package/dist/store/sqlite/identity-proposals.js +234 -0
  245. package/dist/store/sqlite/knowledge.js +5 -3
  246. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  247. package/dist/store/sqlite/link-kinds.js +1 -0
  248. package/dist/store/sqlite/link-row.d.ts +6 -0
  249. package/dist/store/sqlite/link-row.js +35 -0
  250. package/dist/store/sqlite/link-source.d.ts +10 -0
  251. package/dist/store/sqlite/link-source.js +16 -0
  252. package/dist/store/sqlite/manifest.js +1 -0
  253. package/dist/store/sqlite/meeting-context-links.js +9 -6
  254. package/dist/store/sqlite/memories.js +9 -7
  255. package/dist/store/sqlite/mentions.d.ts +4 -1
  256. package/dist/store/sqlite/mentions.js +14 -9
  257. package/dist/store/sqlite/migrations.generated.js +8 -0
  258. package/dist/store/sqlite/note-index.js +9 -7
  259. package/dist/store/sqlite/notes.d.ts +2 -3
  260. package/dist/store/sqlite/notes.js +6 -29
  261. package/dist/store/sqlite/open-store.js +3 -0
  262. package/dist/store/sqlite/open.js +11 -2
  263. package/dist/store/sqlite/orders.d.ts +2 -0
  264. package/dist/store/sqlite/orders.js +9 -3
  265. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  266. package/dist/store/sqlite/organization-categories.js +34 -0
  267. package/dist/store/sqlite/organizations.d.ts +5 -1
  268. package/dist/store/sqlite/organizations.js +14 -4
  269. package/dist/store/sqlite/person-links.d.ts +19 -4
  270. package/dist/store/sqlite/person-links.js +49 -11
  271. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  272. package/dist/store/sqlite/person-match-scan.js +251 -0
  273. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  274. package/dist/store/sqlite/person-matcher.js +32 -0
  275. package/dist/store/sqlite/proposed-actions.js +6 -0
  276. package/dist/store/sqlite/record-matching.d.ts +2 -8
  277. package/dist/store/sqlite/record-matching.js +8 -40
  278. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  279. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  280. package/dist/store/sqlite/record-relationships.js +243 -0
  281. package/dist/store/sqlite/record-run.d.ts +5 -0
  282. package/dist/store/sqlite/record-run.js +62 -2
  283. package/dist/store/sqlite/record-writes.d.ts +1 -1
  284. package/dist/store/sqlite/record-writes.js +4 -2
  285. package/dist/store/sqlite/records.js +27 -2
  286. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  287. package/dist/store/sqlite/ref-accounts.js +117 -0
  288. package/dist/store/sqlite/ref-summaries.js +5 -1
  289. package/dist/store/sqlite/relation-list.d.ts +4 -1
  290. package/dist/store/sqlite/relation-list.js +20 -2
  291. package/dist/store/sqlite/relation-proposals.d.ts +18 -1
  292. package/dist/store/sqlite/relation-proposals.js +53 -11
  293. package/dist/store/sqlite/relation-roles.js +12 -6
  294. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  295. package/dist/store/sqlite/reported-relations.js +59 -18
  296. package/dist/store/sqlite/schema.d.ts +32 -0
  297. package/dist/store/sqlite/schema.js +3 -0
  298. package/dist/store/sqlite/transaction.d.ts +13 -0
  299. package/dist/store/sqlite/transaction.js +33 -15
  300. package/dist/store/store.d.ts +3 -0
  301. package/dist/store/store.js +5 -0
  302. package/dist/store/write-events.d.ts +18 -0
  303. package/dist/store/write-events.js +88 -0
  304. package/package.json +3 -3
  305. package/parity.json +11 -4
  306. package/schemas/records-envelope.v1.schema.json +3 -0
@@ -1,4 +1,5 @@
1
1
  import type { ChatKind, Id, Message, Provider } from "../domain/models.js";
2
+ import type { Event, EventFilter } from "../meetings/index.js";
2
3
  import type { AccountKey, IdentityRef, LinkedIdentity, MessageStore, PersonRecord, StoredAccount } from "../store/store.js";
3
4
  export declare const CONTEXT_MESSAGES = 10;
4
5
  export declare const CONTEXT_BYTES: number;
@@ -88,8 +89,15 @@ export interface ContextOptions {
88
89
  * and a work contact into one person, so a personal account must not read that person's work mail by default.
89
90
  */
90
91
  scopes?: readonly AccountScope[];
92
+ /** The calendar accounts' store ids whose events are read; left out, every calendar's. */
93
+ calendarIds?: readonly number[];
91
94
  }
92
95
  export declare const toContext: (key: AccountKey, message: Message, chatTitle: string | null) => ContextMessage;
96
+ /** Up to `limit` events of `filter`, in its order, the first occurrence of each series only and none cancelled. */
97
+ export declare const eventsOnce: (store: MessageStore, filter: EventFilter, limit: number) => Promise<{
98
+ items: Event[];
99
+ cut: boolean;
100
+ }>;
93
101
  /** The stored accounts of `scopes`, or of the asked account's own scope; the asked account must be stored. */
94
102
  export declare const readableAccounts: (store: MessageStore, asked: AccountKey, scopes?: readonly AccountScope[]) => Promise<StoredAccount[]>;
95
103
  /**
@@ -115,7 +123,7 @@ export declare const recordContext: (store: MessageStore, record: PersonRecord,
115
123
  key: AccountKey;
116
124
  scope: AccountScope;
117
125
  identity: LinkedIdentity;
118
- }[], readable: readonly StoredAccount[], { messages, bytes, since, now }?: ContextOptions) => Promise<Omit<PersonContext, "person">>;
126
+ }[], readable: readonly StoredAccount[], { messages, bytes, since, now, calendarIds }?: ContextOptions) => Promise<Omit<PersonContext, "person">>;
119
127
  /** `max:Ana` names a person in another messenger of this store; a reference with no prefix, this one. */
120
128
  export declare const identityIn: (store: MessageStore, asked: AccountKey, reference: string) => Promise<IdentityRef>;
121
129
  export declare const CHAT_MESSAGES = 20;
@@ -58,7 +58,7 @@ const EVENT_PAGE = 100;
58
58
  /** A weekly meeting held for years is hundreds of occurrences; past this many rows the list stops, cut. */
59
59
  const EVENT_ROWS = 1000;
60
60
  /** Up to `limit` events of `filter`, in its order, the first occurrence of each series only and none cancelled. */
61
- const eventsOnce = async (store, filter, limit) => {
61
+ export const eventsOnce = async (store, filter, limit) => {
62
62
  const items = [];
63
63
  const series = new Set();
64
64
  for (let offset = 0; offset < EVENT_ROWS; offset += EVENT_PAGE) {
@@ -123,7 +123,7 @@ export const personContext = async (store, asked, reference, options = {}) => {
123
123
  * `personContext` of a person already found, read in the identities and accounts `reads` names; their calendar
124
124
  * events in every calendar account of `readable`.
125
125
  */
126
- export const recordContext = async (store, record, reads, readable, { messages = CONTEXT_MESSAGES, bytes = CONTEXT_BYTES, since, now = Date.now() } = {}) => {
126
+ export const recordContext = async (store, record, reads, readable, { messages = CONTEXT_MESSAGES, bytes = CONTEXT_BYTES, since, now = Date.now(), calendarIds } = {}) => {
127
127
  const recent = (message) => since === undefined || Date.parse(message.timestamp) >= since;
128
128
  const shared = [];
129
129
  const notRead = [];
@@ -189,7 +189,9 @@ export const recordContext = async (store, record, reads, readable, { messages =
189
189
  for (const one of readable)
190
190
  if ((await store.calendar.calendars(one.id)).length)
191
191
  calendars.push(one);
192
- const accountIds = calendars.map(({ id }) => id);
192
+ const readableIds = calendars.map(({ id }) => id);
193
+ // Only the calendars asked for, and never one outside the read scope.
194
+ const accountIds = calendarIds === undefined ? readableIds : readableIds.filter((id) => calendarIds.includes(id));
193
195
  const nothing = { items: [], cut: false };
194
196
  const upcoming = accountIds.length ? await eventsOnce(store, { personId, accountIds, from: now }, messages) : nothing;
195
197
  const upcomingIds = new Set(upcoming.items.map(({ id }) => id));
@@ -0,0 +1,4 @@
1
+ import type { MessageStore } from "../../../store/index.js";
2
+ import type { ProposalKind } from "../types.js";
3
+ /** Two identities' people that may be one; only the owner says whether they are. */
4
+ export declare const identityLinkKind: (store: Pick<MessageStore, "people" | "proposedActions">) => ProposalKind;
@@ -0,0 +1,48 @@
1
+ import { IDENTITY_LINK_KIND, proposerOfAction } from "../../../store/index.js";
2
+ import { actionStatus, kept, pushed, storedStatus } from "./shared.js";
3
+ const rowOf = (action) => {
4
+ const payload = action.payload;
5
+ const [from, to] = payload.persons;
6
+ return {
7
+ id: action.id,
8
+ kind: IDENTITY_LINK_KIND,
9
+ status: actionStatus(action.status),
10
+ project: null,
11
+ subject: `person:${from}`,
12
+ object: `person:${to}`,
13
+ summary: `${payload.identity} may be the same person as ${payload.with ?? `person:${to}`} (${payload.signal})`,
14
+ proposedBy: proposerOfAction(action),
15
+ reason: action.reason,
16
+ evidence: payload.evidence.slice(0, 5),
17
+ score: payload.score,
18
+ signals: null,
19
+ parts: null,
20
+ createdAt: action.createdAt,
21
+ };
22
+ };
23
+ /** Two identities' people that may be one; only the owner says whether they are. */
24
+ export const identityLinkKind = (store) => ({
25
+ kind: IDENTITY_LINK_KIND,
26
+ stored: [IDENTITY_LINK_KIND],
27
+ ownerOnly: true,
28
+ list: async (filter) => {
29
+ const status = storedStatus(filter);
30
+ const stored = await store.proposedActions.list({
31
+ kinds: [IDENTITY_LINK_KIND],
32
+ ...(status === undefined ? {} : { status }),
33
+ ...pushed(filter),
34
+ });
35
+ return kept(stored.map(rowOf), filter);
36
+ },
37
+ get: async (id) => rowOf(await store.proposedActions.get(id)),
38
+ decide: async (id, { confirm, by, reason }) => {
39
+ const decided = await store.people.decideLink(id, { confirm, by, ...(reason === undefined ? {} : { reason }) });
40
+ const person = decided.result?.person;
41
+ return {
42
+ id,
43
+ kind: IDENTITY_LINK_KIND,
44
+ status: confirm ? "confirmed" : "rejected",
45
+ made: person === undefined ? [] : [`person:${person}`],
46
+ };
47
+ },
48
+ });
@@ -4,6 +4,6 @@ export const orderKind = (store) => reviewedKind({
4
4
  type: "order",
5
5
  list: (options) => store.orders.list(options),
6
6
  get: (id) => store.orders.get(id),
7
- row: (order) => reviewedRow("order", order, order.supplier?.ref ?? null),
7
+ row: (order) => reviewedRow("order", order, (order.direction === "sale" ? order.customer : order.supplier)?.ref ?? null),
8
8
  decide: async (id, confirm, { by, reason }) => (confirm ? await store.orders.confirm(id, by, reason) : await store.orders.reject(id, by, reason)).ref,
9
9
  });
@@ -5,6 +5,7 @@ import { contractKind } from "./kinds/contracts.js";
5
5
  import { factKind } from "./kinds/fact.js";
6
6
  import { invoiceKind, paymentKind } from "./kinds/finance.js";
7
7
  import { findingsKind } from "./kinds/findings.js";
8
+ import { identityLinkKind } from "./kinds/identity-link.js";
8
9
  import { keyDocumentKind } from "./kinds/key-document.js";
9
10
  import { mailFindingsKind } from "./kinds/mail-findings.js";
10
11
  import { meetingFindingsKind } from "./kinds/meeting-findings.js";
@@ -152,6 +153,7 @@ export const proposalRegistry = (store) => {
152
153
  meetingFindingsKind(store),
153
154
  taskCloseKind(store),
154
155
  sourceReviewKind(store),
156
+ identityLinkKind(store),
155
157
  ])
156
158
  registry.register(kind);
157
159
  registry.register(actionKind(store, registry.claimed));
@@ -1,16 +1,23 @@
1
- import type { AppIdentity } from "../ports/app.js";
2
- import { type ListContext, type SkippedSource } from "../search/account-list.js";
1
+ import { type AppIdentity } from "../ports/app.js";
2
+ import { type SkippedSource } from "../search/account-list.js";
3
+ import { type GroupContext } from "../search/groups.js";
3
4
  import type { AccountKey, MessageStore, StoredAccount } from "../store/store.js";
4
5
  export type SearchKind = "messages" | "mail";
5
6
  export declare const NO_MAIL = "no_mail";
6
7
  export declare const MAIL = "email";
7
- /** What a `--source` list is resolved against: the store's accounts, groups and profiles, and the app running. */
8
- export declare const listContextOf: (store: MessageStore, account: AccountKey, app: AppIdentity | undefined, stored?: StoredAccount[]) => Promise<ListContext>;
8
+ /** The group `<PREFIX>_GROUP_LOCK` pins this process to; `all`, every account, locks nothing. */
9
+ export declare const groupLockOf: (app: AppIdentity | undefined, env: NodeJS.ProcessEnv | undefined) => string | undefined;
10
+ /**
11
+ * What a `--source` list is resolved against: the store's accounts, profiles and groups — the saved ones and `all`
12
+ * (WC-ACCT-13) — and the app running. Under a group lock in the run's `env` it holds only that group's
13
+ * accounts, so a reader that never scoped its run to the group still cannot name an account outside it.
14
+ */
15
+ export declare const listContextOf: (store: MessageStore, account: AccountKey, app: AppIdentity | undefined, stored?: StoredAccount[], env?: NodeJS.ProcessEnv) => Promise<GroupContext>;
9
16
  /**
10
17
  * `--source` as a list of accounts and groups: `undefined` when it is a bare word like `all` or `telegram`. The
11
18
  * accounts are those of `kind` the list names; an entry naming none of them is in `skipped`.
12
19
  */
13
- export declare const listedAccounts: (store: MessageStore, account: AccountKey, source: string | undefined, app: AppIdentity | undefined, kind?: SearchKind) => Promise<{
20
+ export declare const listedAccounts: (store: MessageStore, account: AccountKey, source: string | undefined, app: AppIdentity | undefined, kind?: SearchKind, env?: NodeJS.ProcessEnv) => Promise<{
14
21
  accounts: AccountKey[];
15
22
  skipped: SkippedSource[];
16
23
  } | undefined>;
@@ -1,35 +1,74 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
- import { holdsKindOf, isKind, providerNamed } from "../domain/providers.js";
3
- import { entriesOfList, fitting, isAccountList } from "../search/account-list.js";
2
+ import { holdsKindOf, isDocumentAccountProvider, isFolderProvider, isKind, providerNamed } from "../domain/providers.js";
3
+ import { envName } from "../ports/app.js";
4
+ import { entriesOfList, fitting, isAccountList, keyOf, } from "../search/account-list.js";
5
+ import { ALL, groupEntries, groupMembership, hasGroup, OWNER_NOTES } from "../search/groups.js";
4
6
  export const NO_MAIL = "no_mail";
5
7
  export const MAIL = "email";
6
- /** What a `--source` list is resolved against: the store's accounts, groups and profiles, and the app running. */
7
- export const listContextOf = async (store, account, app, stored) => {
8
+ /** The group `<PREFIX>_GROUP_LOCK` pins this process to; `all`, every account, locks nothing. */
9
+ export const groupLockOf = (app, env) => {
10
+ const lock = app === undefined || env === undefined ? undefined : env[envName(app, "GROUP_LOCK")]?.trim();
11
+ return lock && lock.toLowerCase() !== ALL ? lock : undefined;
12
+ };
13
+ /**
14
+ * What a `--source` list is resolved against: the store's accounts, profiles and groups — the saved ones and `all`
15
+ * (WC-ACCT-13) — and the app running. Under a group lock in the run's `env` it holds only that group's
16
+ * accounts, so a reader that never scoped its run to the group still cannot name an account outside it.
17
+ */
18
+ export const listContextOf = async (store, account, app, stored, env) => {
8
19
  const all = stored ?? (await store.accounts.storedAccounts());
9
20
  // A fresh store has no row yet for the account it runs as.
10
21
  const held = all.some((one) => one.provider === account.provider && one.account === account.account)
11
22
  ? all
12
23
  : [...all, { id: 0, ...account, name: null, scope: "personal" }];
13
- return {
24
+ const context = {
14
25
  held,
15
26
  groups: await store.accounts.accountGroups(),
16
27
  profiles: await store.accounts.profiles(),
17
28
  running: { provider: account.provider, ...(app ? { command: app.command } : {}) },
18
29
  };
30
+ const membership = groupMembership(context);
31
+ const groups = groupEntries(context.groups);
32
+ const lock = groupLockOf(app, env);
33
+ if (lock === undefined)
34
+ return { ...context, groups, membership };
35
+ const members = hasGroup(membership.groups, lock) ? membership.groups[lock] : undefined;
36
+ if (!members)
37
+ throw new CliError("permission_error", `this process is locked to group ${lock} (${envName(app, "GROUP_LOCK")}), which does not exist`);
38
+ const only = new Set([...members, OWNER_NOTES].map(keyOf));
39
+ // A notes folder or a documents account is held under its own key but listed as `notes:<store id>`.
40
+ const listedAs = (one) => isFolderProvider(one.provider) || isDocumentAccountProvider(one.provider)
41
+ ? { provider: "notes", account: String(one.id) }
42
+ : one;
43
+ return {
44
+ ...context,
45
+ held: held.filter((one) => only.has(keyOf(listedAs(one)))),
46
+ groups: { [lock]: groups[lock] ?? [] },
47
+ membership: {
48
+ groups: { [lock]: members },
49
+ duplicates: membership.duplicates.filter(({ groups: names }) => names.includes(lock)),
50
+ suggested: membership.suggested.filter(({ group }) => group === lock),
51
+ unresolved: membership.unresolved,
52
+ },
53
+ only,
54
+ };
19
55
  };
20
56
  /**
21
57
  * `--source` as a list of accounts and groups: `undefined` when it is a bare word like `all` or `telegram`. The
22
58
  * accounts are those of `kind` the list names; an entry naming none of them is in `skipped`.
23
59
  */
24
- export const listedAccounts = async (store, account, source, app, kind) => {
25
- if (source === undefined)
60
+ export const listedAccounts = async (store, account, source, app, kind, env) => {
61
+ const lock = groupLockOf(app, env);
62
+ if (source === undefined && lock === undefined)
26
63
  return undefined;
27
64
  const stored = await store.accounts.storedAccounts();
28
65
  // A provider the store holds by that very name, and all, personal and bots, keep their old path.
29
- const registered = isKind(source) || (providerNamed(source) !== undefined && !stored.some(({ provider }) => provider === source));
30
- if (!isAccountList(source) && !registered)
66
+ const registered = source !== undefined &&
67
+ (isKind(source) || (providerNamed(source) !== undefined && !stored.some(({ provider }) => provider === source)));
68
+ // Under a lock every read goes through the list, which holds only the group's accounts.
69
+ if (lock === undefined && source !== undefined && !isAccountList(source) && !registered)
31
70
  return undefined;
32
- const entries = entriesOfList(source, await listContextOf(store, account, app, stored));
71
+ const entries = entriesOfList(source ?? `group:${lock}`, await listContextOf(store, account, app, stored, env));
33
72
  return fitting(entries, kind ? [kind] : ["messages", "mail"], `${app ? `${app.command} ` : ""}search ${kind ?? "messages"}`);
34
73
  };
35
74
  /**
@@ -14,7 +14,7 @@ import { openStore } from "../store/store.js";
14
14
  export const useTextModel = async (id, { env, command }) => {
15
15
  const model = textModel(id, env);
16
16
  if (!isTextModelInstalled(model, textModelsDirectory(env)))
17
- throw new CliError("not_found", `${model.id} is not downloaded — \`${command} models download ${model.id}${model.terms ? " --accept-terms" : ""}\` first`, { reason: "model.not-downloaded", model: model.id });
17
+ throw new CliError("not_found", `${model.id} is not downloaded — \`${command} models download ${model.id}\` first`, { reason: "model.not-downloaded", model: model.id });
18
18
  const previous = chosenTextModel(env).id;
19
19
  const before = textModels(env).find((one) => one.id === previous);
20
20
  const toEmbed = previous === model.id ? 0 : before ? await missingVectors(before, model, env) : null;
@@ -17,6 +17,17 @@ export interface AccountAccounts {
17
17
  */
18
18
  purge(key: AccountKey): Promise<void>;
19
19
  }
20
+ export interface AccountGroupChange {
21
+ /** Read against the group's entries inside the write, so a move sees what is saved at that moment. */
22
+ remove?: {
23
+ group: string;
24
+ drop: (entry: string) => boolean;
25
+ };
26
+ add?: {
27
+ group: string;
28
+ entry: string;
29
+ };
30
+ }
20
31
  export interface AccountsStore extends AccountAccounts {
21
32
  /** Every account of every messenger the file holds, by messenger then id. */
22
33
  accounts(): Promise<AccountKey[]>;
@@ -26,6 +37,13 @@ export interface AccountsStore extends AccountAccounts {
26
37
  accountGroups(): Promise<AccountGroups>;
27
38
  /** Saves one group's entries; `undefined` removes the group. */
28
39
  saveAccountGroup(name: string, members: string[] | undefined): Promise<void>;
40
+ /**
41
+ * Takes entries out of one group and puts an entry into another in one write, so a move is never half done. A
42
+ * group left empty stays, to be filled again; an entry already there is not added twice.
43
+ */
44
+ changeAccountGroups(change: AccountGroupChange): Promise<{
45
+ removed: string[];
46
+ }>;
29
47
  /** Per app command, each profile's account: how `--source max:default` finds a profile of another app. */
30
48
  profiles(): Promise<Profiles>;
31
49
  /** Records which account a profile of `app` is; a no-op when the store already says so. */
@@ -31,6 +31,9 @@ export const accountAccountsOver = (context) => {
31
31
  };
32
32
  export const accountsStoreOver = (context, keyed) => {
33
33
  const { database } = context;
34
+ const saveGroups = (groups) => database
35
+ .prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
36
+ .run(ACCOUNT_GROUPS, JSON.stringify(groups), context.now());
34
37
  return {
35
38
  ...keyed,
36
39
  accounts: async () => accounts.heldAccounts(context),
@@ -46,9 +49,21 @@ export const accountsStoreOver = (context, keyed) => {
46
49
  delete groups[name];
47
50
  else
48
51
  groups[name] = members;
49
- database
50
- .prepare("INSERT OR REPLACE INTO store_settings (key, value, at) VALUES (?, ?, ?)")
51
- .run(ACCOUNT_GROUPS, JSON.stringify(groups), context.now());
52
+ saveGroups(groups);
53
+ }),
54
+ changeAccountGroups: async ({ remove, add }) => write(database, () => {
55
+ const groups = accountGroupsOf(database);
56
+ const saved = remove && Object.hasOwn(groups, remove.group) ? (groups[remove.group] ?? []) : [];
57
+ const removed = remove ? saved.filter(remove.drop) : [];
58
+ if (remove && removed.length)
59
+ groups[remove.group] = saved.filter((entry) => !removed.includes(entry));
60
+ if (add) {
61
+ const entries = Object.hasOwn(groups, add.group) ? (groups[add.group] ?? []) : [];
62
+ groups[add.group] = entries.includes(add.entry) ? entries : [...entries, add.entry];
63
+ }
64
+ if (removed.length || add)
65
+ saveGroups(groups);
66
+ return { removed };
52
67
  }),
53
68
  };
54
69
  };
@@ -1,21 +1,54 @@
1
1
  import type { StoreHealth } from "./health.js";
2
- import type { DamageMark } from "./marks.js";
2
+ import type { DamageMark, JournalMark } from "./marks.js";
3
+ /** One cause the evidence allows, and the one command that tells more about it. */
4
+ export interface DamageCause {
5
+ cause: string;
6
+ check: string;
7
+ }
8
+ export interface RecoveryStep {
9
+ command: string;
10
+ why: string;
11
+ /** Replaces the store or stops a process: an app copies it for the owner to run rather than running it. */
12
+ destructive: boolean;
13
+ }
3
14
  /**
4
15
  * What a damaged store means, in the owner's words: one structure the CLIs render and the desktop app can show as it
5
- * is. Built from a health check only, so it never reads the damaged file again.
16
+ * is. Built from what was already found, so it never reads the damaged file again.
6
17
  */
7
- export interface DamageExplanation {
8
- what: string;
9
- causes: string[];
10
- investigate: string[];
18
+ export interface StoreDamageReport {
19
+ whatHappened: string;
20
+ likelyCauses: DamageCause[];
11
21
  impact: string[];
12
- externalUnaffected: string;
13
- steps: string[];
22
+ externalDataSafe: string;
23
+ lastOkAt: string | null;
24
+ loss: string;
25
+ /** The first stops the writers, the last is the deep check. */
26
+ steps: RecoveryStep[];
27
+ }
28
+ export interface DamageFindings {
29
+ health: StoreHealth;
30
+ /** The CLI's command, which the steps name: `mail`. */
31
+ command: string;
32
+ mark?: DamageMark | null;
33
+ journal?: JournalMark | null;
34
+ lastOkAt?: string | null;
35
+ holders?: {
36
+ pid: number;
37
+ name: string;
38
+ }[] | null;
39
+ timers?: string[] | null;
40
+ sqlite3Usable?: boolean;
14
41
  }
15
42
  /**
16
43
  * Tables a recovery rebuilds from the others: search indexes, the vector index, what the indexing finds, and the
17
44
  * vectors, which a search by meaning computes again for any text that has none.
18
45
  */
19
46
  export declare const isDerivedTable: (table: string, searchIndexes: readonly string[]) => boolean;
20
- /** `mark`: a run saw the damage; the quick check reads too little to see it, so it alone can make a store damaged. */
21
- export declare const explainDamage: (health: StoreHealth, command: string, mark?: DamageMark | null) => DamageExplanation | null;
47
+ /** How much may be gone and since when: nothing records a row that damage takes (BUG-627). */
48
+ export declare const lossUnknown: (lastOkAt: string | null | undefined, gone?: boolean) => string;
49
+ /**
50
+ * The report for whatever was found, or null when the store is healthy and nothing was seen. `mark`: a run saw the
51
+ * damage; the quick check reads too little to see it, so it alone can make a store damaged. `journal`: the store's
52
+ * journal file went away under a run, which can lose writes even when every page still reads.
53
+ */
54
+ export declare const storeDamageReport: ({ health, command, mark, journal, lastOkAt, holders, timers, sqlite3Usable, }: DamageFindings) => StoreDamageReport | null;
@@ -9,9 +9,34 @@ export const isDerivedTable = (table, searchIndexes) => DERIVED.has(table) ||
9
9
  searchIndexes.some((index) => table === index || table.startsWith(`${index}_`));
10
10
  const WIRECAT_UNITS = ["memo-*", "mail-*", "tg-*", "max-*", "wirecat-*"];
11
11
  const seen = (mark) => `\`${mark.command}\` found the store damaged at ${mark.at} (${mark.error})`;
12
- /** `mark`: a run saw the damage; the quick check reads too little to see it, so it alone can make a store damaged. */
13
- export const explainDamage = (health, command, mark = null) => {
14
- if (health.ok && !mark)
12
+ const journalSeen = (store, { seen, command, at }) => {
13
+ const wal = `${store.replace(/^.*\//, "")}-wal`;
14
+ return seen === "shm-without-wal"
15
+ ? `the store's journal file (${wal}) was missing when \`${command}\` opened the store at ${at}: another program deleted it, or a tool crashed while closing`
16
+ : `the store's journal file (${wal}) was deleted or replaced by another program while \`${command}\` had the store open (${at})`;
17
+ };
18
+ /** How much may be gone and since when: nothing records a row that damage takes (BUG-627). */
19
+ export const lossUnknown = (lastOkAt, gone = false) => {
20
+ const since = lastOkAt
21
+ ? `since the last deep check that passed (${lastOkAt})`
22
+ : "since the store was made (no deep check that passed is on record)";
23
+ return (`${gone ? "more rows may be gone" : "how many rows were lost is unknown"}: ` +
24
+ `damage can take rows written ${since} without leaving a trace; a sync fetches again what the servers still hold`);
25
+ };
26
+ const stopWriters = (timers) => ({
27
+ command: timers?.length
28
+ ? `systemctl --user stop ${timers.join(" ")}`
29
+ : `systemctl --user stop ${WIRECAT_UNITS.map((unit) => `'${unit}'`).join(" ")}`,
30
+ why: "a tool that writes while the store is recovered damages the new file too",
31
+ destructive: false,
32
+ });
33
+ /**
34
+ * The report for whatever was found, or null when the store is healthy and nothing was seen. `mark`: a run saw the
35
+ * damage; the quick check reads too little to see it, so it alone can make a store damaged. `journal`: the store's
36
+ * journal file went away under a run, which can lose writes even when every page still reads.
37
+ */
38
+ export const storeDamageReport = ({ health, command, mark = null, journal = null, lastOkAt = null, holders = null, timers = null, sqlite3Usable = true, }) => {
39
+ if (health.ok && !mark && !journal)
15
40
  return null;
16
41
  const indexNames = (health.searchIndexes ?? []).map((index) => index.name);
17
42
  const badIndexes = (health.searchIndexes ?? []).filter((index) => !index.ok).map((index) => index.name);
@@ -20,17 +45,21 @@ export const explainDamage = (health, command, mark = null) => {
20
45
  const derived = [...new Set([...tables.filter((table) => isDerivedTable(table, indexNames)), ...badIndexes])];
21
46
  const unopened = health.error !== undefined;
22
47
  const json = (health.invalidJson ?? []).map(({ table, column }) => `${table}.${column}`);
23
- const checked = health.ok
24
- ? `${seen(mark)}; the quick check reads too little to see it, and a deep check that passes clears it`
25
- : unopened
26
- ? `the store file cannot be opened: ${health.error}`
27
- : health.checked === "quick"
28
- ? "the store file's header or schema is damaged"
29
- : `the store file is damaged: ${health.problems ?? 0} problems` +
30
- (sources.length ? ` in the data of ${named(sources)}` : "") +
31
- (derived.length ? `${sources.length ? ", and" : " in"} the search data of ${named(derived)}` : "") +
32
- (json.length ? `; values that are not valid JSON in ${named(json)}` : "");
33
- const what = mark && !health.ok ? `${checked}; ${seen(mark)}` : checked;
48
+ const damaged = !health.ok || mark !== null;
49
+ const folder = health.path.replace(/\/[^/]*$/, "");
50
+ const checked = !damaged
51
+ ? `every page of the store reads, but ${journalSeen(health.path, journal)}; what was written into it may be lost`
52
+ : health.ok
53
+ ? `${seen(mark)}; the quick check reads too little to see it, and a deep check that passes clears it`
54
+ : unopened
55
+ ? `the store file cannot be opened: ${health.error}`
56
+ : health.checked === "quick"
57
+ ? "the store file's header or schema is damaged"
58
+ : `the store file is damaged: ${health.problems ?? 0} problems` +
59
+ (sources.length ? ` in the data of ${named(sources)}` : "") +
60
+ (derived.length ? `${sources.length ? ", and" : " in"} the search data of ${named(derived)}` : "") +
61
+ (json.length ? `; values that are not valid JSON in ${named(json)}` : "");
62
+ const whatHappened = mark && !health.ok ? `${checked}; ${seen(mark)}` : checked;
34
63
  const impact = [
35
64
  ...(sources.length
36
65
  ? [`some rows of ${named(sources)} cannot be read; a recovery keeps every row it can read and names the rest`]
@@ -41,30 +70,84 @@ export const explainDamage = (health, command, mark = null) => {
41
70
  ...(json.length
42
71
  ? [`a read of a row with a broken JSON value fails ("malformed JSON"); a recovery clears those values`]
43
72
  : []),
44
- mark
45
- ? "reads that do not touch a damaged page work; every command that writes the store refuses until it is recovered"
46
- : "reads that do not touch a damaged page work; a write that touches one fails until the store is recovered",
73
+ ...(!damaged
74
+ ? ["everything works; rows written while the journal was gone may be missing, and a sync fetches them again"]
75
+ : mark
76
+ ? [
77
+ "reads that do not touch a damaged page work; every command that writes the store refuses until it is recovered",
78
+ ]
79
+ : ["reads that do not touch a damaged page work; a write that touches one fails until the store is recovered"]),
80
+ ];
81
+ const likelyCauses = [
82
+ ...(journal
83
+ ? [{ cause: journalSeen(health.path, journal), check: `ls -li --time-style=full-iso ${folder}/` }]
84
+ : []),
85
+ ...(holders?.length
86
+ ? [
87
+ {
88
+ cause: `two programs wrote the file without seeing each other: ${holders.map(({ name, pid }) => `${name} (process ${pid})`).join(", ")} still ${holders.length === 1 ? "has" : "have"} it open`,
89
+ check: `fuser -v ${health.path}`,
90
+ },
91
+ ]
92
+ : []),
93
+ ...(damaged
94
+ ? [
95
+ {
96
+ cause: "the computer lost power or crashed while a tool was writing",
97
+ check: `journalctl --user ${WIRECAT_UNITS.map((unit) => `-u '${unit}'`).join(" ")} --since -14d | grep -i -e malformed -e corrupt -e 'disk full'`,
98
+ },
99
+ { cause: "the disk filled up while a tool was writing", check: `df -h ${folder}` },
100
+ {
101
+ cause: "the file was copied, restored or synced while a tool had it open, or it sits in a synced or network folder",
102
+ check: `findmnt -T ${folder}`,
103
+ },
104
+ {
105
+ cause: "a fault of the disk itself",
106
+ check: "journalctl -k --since -14d | grep -i -e 'I/O error' -e nvme -e ata",
107
+ },
108
+ ]
109
+ : []),
110
+ ];
111
+ const steps = [
112
+ stopWriters(timers),
113
+ ...(holders ?? []).map(({ pid, name }) => ({
114
+ command: `kill ${pid}`,
115
+ why: `${name} (process ${pid}) has the store open`,
116
+ destructive: true,
117
+ })),
118
+ ...(damaged && !sqlite3Usable
119
+ ? [
120
+ {
121
+ command: "sudo apt install sqlite3",
122
+ why: "the recovery copies rows with the sqlite3 program, 3.43 or newer (on macOS: brew install sqlite)",
123
+ destructive: false,
124
+ },
125
+ ]
126
+ : []),
127
+ ...(damaged
128
+ ? [
129
+ {
130
+ command: `${command} store recover run`,
131
+ why: "copies every readable row into a new file and puts it in place of the store; the damaged file is " +
132
+ "kept beside it, and it prints the syncs that fetch again what was lost",
133
+ destructive: true,
134
+ },
135
+ ]
136
+ : []),
137
+ {
138
+ command: `${command} store recover`,
139
+ why: "checks every page again; a check that passes lifts the damage mark",
140
+ destructive: false,
141
+ },
47
142
  ];
48
143
  return {
49
- what,
50
- causes: [
51
- "the computer lost power or crashed, or the disk filled up, while a tool was writing",
52
- "the file was copied, restored or synced while a tool had it open, or it sits in a synced or network folder",
53
- "a fault of the disk itself",
54
- ],
55
- investigate: [
56
- `journalctl --user ${WIRECAT_UNITS.map((unit) => `-u '${unit}'`).join(" ")} --since -14d | grep -i -e malformed -e corrupt -e 'disk full'`,
57
- "journalctl -k --since -14d | grep -i -e 'I/O error' -e nvme -e ata",
58
- `df -h ${health.path.replace(/\/[^/]*$/, "")}`,
59
- ...(health.checked === "quick" || health.ok ? [`${command} store recover`] : []),
60
- ],
144
+ whatHappened,
145
+ likelyCauses,
61
146
  impact,
62
- externalUnaffected: "only this computer's copy is damaged: Telegram, MAX, the mail servers and Google Drive keep their own data, " +
63
- "so whatever is lost here can be fetched again by a sync",
64
- steps: [
65
- "stop every timer and server of the WireCat tools; `store recover run` lists the ones still running",
66
- `${command} store recover run`,
67
- "run the fetch commands it prints, then start the timers again",
68
- ],
147
+ externalDataSafe: "only this computer's copy is damaged: Telegram, MAX, WhatsApp, the mail servers and Google Drive keep their " +
148
+ "own data, so whatever is lost here can be fetched again by a sync",
149
+ lastOkAt,
150
+ loss: lossUnknown(lastOkAt),
151
+ steps,
69
152
  };
70
153
  };
@@ -1,5 +1,6 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { MEETING_FINDINGS_KIND } from "../meetings/index.js";
3
+ import { IDENTITY_LINK_KIND } from "./identity-links.js";
3
4
  import { MAIL_FINDINGS_KIND } from "./mail-findings.js";
4
5
  import { SOURCE_REVIEW_KIND } from "./source-review.js";
5
6
  /** An agent's suggested close of a task: kept on the task, not in `proposed_actions`. */
@@ -12,7 +13,8 @@ export const DEFAULT_DECISION_POLICY = { agentDecisions: false, ruleProposalsOwn
12
13
  export const isOwnerOnlyKind = (kind) => kind === MAIL_FINDINGS_KIND ||
13
14
  kind === MEETING_FINDINGS_KIND ||
14
15
  kind === TASK_CLOSE_KIND ||
15
- kind === SOURCE_REVIEW_KIND;
16
+ kind === SOURCE_REVIEW_KIND ||
17
+ kind === IDENTITY_LINK_KIND;
16
18
  /**
17
19
  * The one check every decide path runs before it confirms or rejects a proposal. `null` means allowed. Every Claude
18
20
  * Code session is the bot `claude-code`, so comparing bot names keeps one session from deciding another's proposal.
@@ -25,6 +25,8 @@ export interface EvidenceFindingsBatch {
25
25
  input: FindingsInput;
26
26
  fingerprint: string;
27
27
  status: "proposed" | "reviewed";
28
+ /** Only the owner decides it, whatever `agent_decisions` says: it was staged so, or it records a payment. */
29
+ ownerOnly: boolean;
28
30
  author: {
29
31
  type: "person" | "bot";
30
32
  id: string;
@@ -43,11 +45,23 @@ export interface EvidenceFindingsBatch {
43
45
  * Cited facts and follow-ups about one project from stored messages, mail and documents, staged by an agent for
44
46
  * review. A sibling of meeting findings: the same rules, evidence checked against the current stored text.
45
47
  */
48
+ /** A stored record as a findings batch cites it: the text a quote must be in, and the fingerprint staging checks. */
49
+ export interface CitableRecord {
50
+ reference: string;
51
+ fingerprint: string;
52
+ title: string | null;
53
+ text: string;
54
+ }
46
55
  export interface EvidenceFindingsStore {
56
+ /** `ownerOnly` keeps every agent from deciding the batch, whatever `agent_decisions` says. */
47
57
  stage(input: FindingsInput, agent: {
48
58
  bot: string;
49
59
  model?: string;
60
+ }, options?: {
61
+ ownerOnly?: boolean;
50
62
  }): Promise<EvidenceFindingsBatch>;
63
+ /** A `msg:`, `document:` or `note:` record as staging reads it; `null` when it is not stored. */
64
+ citable(reference: string): Promise<CitableRecord | null>;
51
65
  get(id: string): Promise<EvidenceFindingsBatch>;
52
66
  list(options?: {
53
67
  project?: string;