@wirecat/cli-core 0.641.0 → 0.643.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 (287) hide show
  1. package/CHANGELOG.md +218 -0
  2. package/dist/analysis/provider.d.ts +1 -1
  3. package/dist/analysis/provider.js +2 -1
  4. package/dist/attachments/gateway-ocr.js +13 -8
  5. package/dist/attachments/ocr.js +27 -18
  6. package/dist/attachments/picture-reading.d.ts +51 -0
  7. package/dist/attachments/picture-reading.js +207 -0
  8. package/dist/background/backfill.d.ts +4 -2
  9. package/dist/background/backfill.js +3 -3
  10. package/dist/background/schedules.d.ts +28 -2
  11. package/dist/background/schedules.js +73 -20
  12. package/dist/background/units.d.ts +2 -0
  13. package/dist/background/units.js +8 -9
  14. package/dist/calendar/cli/index.js +10 -2
  15. package/dist/calendar/feeds.js +2 -2
  16. package/dist/calendar/mcp/index.d.ts +12 -12
  17. package/dist/calendar/server-search.js +2 -2
  18. package/dist/calendar/source.d.ts +4 -3
  19. package/dist/calendar/sync.js +12 -10
  20. package/dist/calendar/testing/source-contract.js +5 -4
  21. package/dist/calendar/testing/source.js +3 -2
  22. package/dist/cli/ai-model-command.js +6 -3
  23. package/dist/cli/analysis-choice.js +20 -4
  24. package/dist/cli/complete-command.d.ts +23 -0
  25. package/dist/cli/complete-command.js +80 -0
  26. package/dist/cli/context.js +7 -1
  27. package/dist/cli/effects.d.ts +2 -0
  28. package/dist/cli/effects.js +2 -0
  29. package/dist/cli/enrichment-consents-command.js +2 -0
  30. package/dist/cli/envelope.js +6 -1
  31. package/dist/cli/help/first-screen.js +5 -0
  32. package/dist/cli/index.d.ts +4 -2
  33. package/dist/cli/index.js +2 -1
  34. package/dist/cli/list-query.d.ts +3 -1
  35. package/dist/cli/list-query.js +5 -3
  36. package/dist/cli/local-only-command.d.ts +10 -0
  37. package/dist/cli/local-only-command.js +112 -0
  38. package/dist/cli/messenger/backfill-command.js +1 -1
  39. package/dist/cli/messenger/chat-queries.js +2 -1
  40. package/dist/cli/messenger/complete-command.d.ts +4 -7
  41. package/dist/cli/messenger/complete-command.js +31 -98
  42. package/dist/cli/messenger/contacts-command.js +4 -0
  43. package/dist/cli/messenger/conversations-command.js +1 -1
  44. package/dist/cli/messenger/guard-commands.js +1 -1
  45. package/dist/cli/messenger/images-command.js +32 -0
  46. package/dist/cli/messenger/list-result-queries.d.ts +1 -0
  47. package/dist/cli/messenger/list-result-queries.js +2 -1
  48. package/dist/cli/messenger/mentions-command.js +3 -3
  49. package/dist/cli/messenger/message-items.js +1 -0
  50. package/dist/cli/messenger/messages-command.js +7 -6
  51. package/dist/cli/messenger/people-queries.d.ts +2 -2
  52. package/dist/cli/messenger/people-queries.js +4 -4
  53. package/dist/cli/messenger/replies-consents-command.js +12 -6
  54. package/dist/cli/messenger/search-answers.js +2 -2
  55. package/dist/cli/messenger/search-command.js +3 -3
  56. package/dist/cli/messenger/searches-command.js +1 -1
  57. package/dist/cli/messenger/store-maintenance-command.js +4 -0
  58. package/dist/cli/messenger/tasks-analysis-command.js +1 -1
  59. package/dist/cli/messenger/tasks-command.js +2 -2
  60. package/dist/cli/model-catalogue-command.js +4 -0
  61. package/dist/cli/picture-reading-command.d.ts +12 -0
  62. package/dist/cli/picture-reading-command.js +82 -0
  63. package/dist/cli/program.d.ts +6 -0
  64. package/dist/cli/program.js +28 -2
  65. package/dist/cli/schedule/agent-start.d.ts +23 -0
  66. package/dist/cli/schedule/agent-start.js +115 -0
  67. package/dist/cli/schedule/harnesses.d.ts +203 -0
  68. package/dist/cli/schedule/harnesses.js +278 -0
  69. package/dist/cli/schedule/schedule-command.d.ts +9 -5
  70. package/dist/cli/schedule/schedule-command.js +89 -79
  71. package/dist/cli/search-harder-consents-command.js +16 -1
  72. package/dist/cli/shared-command-exports.d.ts +186 -0
  73. package/dist/cli/shared-command-exports.js +2 -0
  74. package/dist/cli/untrusted-marks.d.ts +25 -0
  75. package/dist/cli/untrusted-marks.js +102 -0
  76. package/dist/crm/cli/index.d.ts +1 -0
  77. package/dist/crm/cli/index.js +6 -5
  78. package/dist/crm/cli/store.d.ts +30 -0
  79. package/dist/crm/cli/store.js +63 -0
  80. package/dist/crm/source.d.ts +6 -4
  81. package/dist/crm/sync.js +10 -6
  82. package/dist/crm/testing/source-contract.js +9 -7
  83. package/dist/crm/testing/source.js +6 -2
  84. package/dist/crm/testing/sync-contract.js +4 -4
  85. package/dist/crm/writes.d.ts +5 -2
  86. package/dist/crm/writes.js +1 -1
  87. package/dist/documents.d.ts +2 -1
  88. package/dist/documents.js +2 -1
  89. package/dist/domain/addresses.d.ts +2 -0
  90. package/dist/domain/addresses.js +7 -0
  91. package/dist/domain/attachments.d.ts +2 -0
  92. package/dist/domain/attachments.js +2 -1
  93. package/dist/domain/models.d.ts +2 -0
  94. package/dist/embeddings/remote.d.ts +2 -1
  95. package/dist/embeddings/remote.js +5 -3
  96. package/dist/entities/attachment-results.d.ts +3 -0
  97. package/dist/entities/attachment-results.js +3 -0
  98. package/dist/entities/attachment.d.ts +2 -0
  99. package/dist/entities/attachment.js +8 -1
  100. package/dist/entities/hit.d.ts +1 -0
  101. package/dist/entities/index.d.ts +21 -4
  102. package/dist/entities/index.js +3 -2
  103. package/dist/entities/list-results.d.ts +33 -5
  104. package/dist/entities/list-results.js +33 -5
  105. package/dist/errors/reasons.js +38 -1
  106. package/dist/mail/cli/index.js +7 -6
  107. package/dist/mcp/agent.d.ts +2 -1
  108. package/dist/mcp/agent.js +5 -0
  109. package/dist/mcp/app-server.js +10 -0
  110. package/dist/mcp/surface.d.ts +7 -2
  111. package/dist/mcp/surface.js +49 -10
  112. package/dist/meetings/cli/index.js +6 -1
  113. package/dist/meetings/mcp/index.js +6 -3
  114. package/dist/meetings/participant-search.d.ts +2 -2
  115. package/dist/meetings/project-discovery.d.ts +1 -1
  116. package/dist/meetings/project-evidence-answer.js +2 -2
  117. package/dist/meetings/reads.d.ts +2 -2
  118. package/dist/meetings/reads.js +6 -6
  119. package/dist/meetings/store.d.ts +2 -1
  120. package/dist/meetings/testing/contract.js +6 -6
  121. package/dist/meetings/testing/memory.js +7 -2
  122. package/dist/models/ai.d.ts +17 -4
  123. package/dist/models/ai.js +22 -14
  124. package/dist/models/anthropic.js +15 -9
  125. package/dist/models/endpoint.d.ts +5 -0
  126. package/dist/models/endpoint.js +13 -0
  127. package/dist/models/index.d.ts +4 -0
  128. package/dist/models/index.js +14 -4
  129. package/dist/models/local-only.d.ts +17 -0
  130. package/dist/models/local-only.js +42 -0
  131. package/dist/models/openai.js +24 -11
  132. package/dist/models/purpose.d.ts +24 -0
  133. package/dist/models/purpose.js +26 -0
  134. package/dist/models/types.d.ts +8 -0
  135. package/dist/models/types.js +11 -1
  136. package/dist/ports/app.d.ts +17 -1
  137. package/dist/ports/app.js +63 -3
  138. package/dist/replies/rendering.js +10 -10
  139. package/dist/search/lucene/plain.js +45 -3
  140. package/dist/search/lucene/registry.d.ts +15 -4
  141. package/dist/search/lucene/registry.js +70 -12
  142. package/dist/search/lucene/types.d.ts +2 -0
  143. package/dist/search/lucene/types.js +12 -0
  144. package/dist/sends/upload.d.ts +8 -1
  145. package/dist/sends/upload.js +35 -14
  146. package/dist/services/account-groups.d.ts +11 -0
  147. package/dist/services/account-groups.js +29 -0
  148. package/dist/services/agenda.js +1 -0
  149. package/dist/services/attachments.d.ts +18 -4
  150. package/dist/services/attachments.js +66 -15
  151. package/dist/services/conversations.d.ts +2 -4
  152. package/dist/services/conversations.js +1 -1
  153. package/dist/services/deal-context.js +5 -5
  154. package/dist/services/documents/ingestion.js +3 -3
  155. package/dist/services/documents/knowledge.d.ts +6 -6
  156. package/dist/services/documents/knowledge.js +1 -2
  157. package/dist/services/embeddings-maintenance.js +4 -1
  158. package/dist/services/enrichment.d.ts +1 -1
  159. package/dist/services/enrichment.js +27 -0
  160. package/dist/services/events-search.d.ts +3 -3
  161. package/dist/services/events-search.js +7 -7
  162. package/dist/services/index.d.ts +1 -1
  163. package/dist/services/index.js +1 -1
  164. package/dist/services/meeting-model.js +1 -1
  165. package/dist/services/meeting-project-discovery.js +1 -1
  166. package/dist/services/message-resolution.js +10 -3
  167. package/dist/services/messages-search.js +6 -4
  168. package/dist/services/metadata.d.ts +1 -1
  169. package/dist/services/notes-search.d.ts +3 -3
  170. package/dist/services/notes-search.js +3 -3
  171. package/dist/services/organization-context.js +12 -9
  172. package/dist/services/people.d.ts +2 -0
  173. package/dist/services/people.js +4 -2
  174. package/dist/services/pictures.d.ts +9 -0
  175. package/dist/services/pictures.js +34 -28
  176. package/dist/services/project-status/index.js +1 -1
  177. package/dist/services/project-status/signals/payments.js +4 -2
  178. package/dist/services/project-status/signals/promises.js +5 -2
  179. package/dist/services/proposals/kinds/action.js +1 -1
  180. package/dist/services/proposals/kinds/fact.js +1 -1
  181. package/dist/services/proposals/kinds/findings.d.ts +2 -1
  182. package/dist/services/proposals/kinds/findings.js +12 -5
  183. package/dist/services/proposals/kinds/identity-link.js +1 -1
  184. package/dist/services/proposals/kinds/identity-split.js +1 -1
  185. package/dist/services/proposals/kinds/key-document.js +1 -1
  186. package/dist/services/proposals/kinds/mail-findings.d.ts +1 -1
  187. package/dist/services/proposals/kinds/mail-findings.js +11 -5
  188. package/dist/services/proposals/kinds/meeting-findings.js +10 -4
  189. package/dist/services/proposals/kinds/memory.js +1 -1
  190. package/dist/services/proposals/kinds/organization.js +1 -1
  191. package/dist/services/proposals/kinds/relationship-update.js +1 -1
  192. package/dist/services/proposals/kinds/relationship.js +1 -1
  193. package/dist/services/proposals/kinds/shared.d.ts +3 -2
  194. package/dist/services/proposals/kinds/shared.js +4 -4
  195. package/dist/services/proposals/kinds/source-review.js +1 -1
  196. package/dist/services/proposals/kinds/task-close.js +2 -2
  197. package/dist/services/proposals/registry.js +1 -1
  198. package/dist/services/proposals/types.d.ts +2 -1
  199. package/dist/services/search-all-business.js +3 -4
  200. package/dist/services/search-all.js +13 -14
  201. package/dist/services/search-harder.d.ts +11 -1
  202. package/dist/services/search-harder.js +38 -5
  203. package/dist/services/searches.d.ts +2 -4
  204. package/dist/services/searches.js +1 -4
  205. package/dist/services/stored-project-gathering.js +6 -1
  206. package/dist/services/tags.d.ts +2 -4
  207. package/dist/services/tags.js +1 -1
  208. package/dist/services/tasks.d.ts +1 -1
  209. package/dist/services/tasks.js +4 -3
  210. package/dist/speech/openai.js +2 -0
  211. package/dist/speech/transcribe.d.ts +5 -2
  212. package/dist/speech/transcribe.js +14 -5
  213. package/dist/store/account-store.d.ts +2 -1
  214. package/dist/store/account-store.js +3 -1
  215. package/dist/store/accounts.d.ts +2 -0
  216. package/dist/store/accounts.js +8 -0
  217. package/dist/store/chats.d.ts +5 -0
  218. package/dist/store/chats.js +4 -0
  219. package/dist/store/evidence-findings.d.ts +9 -0
  220. package/dist/store/exports.d.ts +1 -1
  221. package/dist/store/exports.js +1 -1
  222. package/dist/store/identity-links.d.ts +3 -1
  223. package/dist/store/mail-findings.d.ts +9 -0
  224. package/dist/store/meeting-findings.d.ts +9 -0
  225. package/dist/store/searches.d.ts +3 -2
  226. package/dist/store/sqlite/accounts.js +37 -0
  227. package/dist/store/sqlite/agent-actions.d.ts +2 -1
  228. package/dist/store/sqlite/agent-actions.js +10 -4
  229. package/dist/store/sqlite/business-contracts.d.ts +3 -1
  230. package/dist/store/sqlite/business-contracts.js +7 -3
  231. package/dist/store/sqlite/business-search.d.ts +2 -1
  232. package/dist/store/sqlite/business-search.js +6 -4
  233. package/dist/store/sqlite/deals.d.ts +6 -4
  234. package/dist/store/sqlite/deals.js +12 -7
  235. package/dist/store/sqlite/evidence-findings.js +78 -9
  236. package/dist/store/sqlite/facts.d.ts +2 -1
  237. package/dist/store/sqlite/facts.js +6 -2
  238. package/dist/store/sqlite/finance.d.ts +4 -2
  239. package/dist/store/sqlite/finance.js +13 -6
  240. package/dist/store/sqlite/findings-core.d.ts +56 -2
  241. package/dist/store/sqlite/findings-core.js +109 -22
  242. package/dist/store/sqlite/identities.d.ts +4 -0
  243. package/dist/store/sqlite/identities.js +12 -3
  244. package/dist/store/sqlite/identity-proposals.js +34 -4
  245. package/dist/store/sqlite/lucene-fields.d.ts +2 -0
  246. package/dist/store/sqlite/lucene-fields.js +28 -2
  247. package/dist/store/sqlite/lucene.js +21 -10
  248. package/dist/store/sqlite/mail-findings.js +60 -22
  249. package/dist/store/sqlite/meeting-findings.js +53 -7
  250. package/dist/store/sqlite/meeting-participant-search.js +4 -5
  251. package/dist/store/sqlite/meetings.js +7 -3
  252. package/dist/store/sqlite/memories.d.ts +4 -2
  253. package/dist/store/sqlite/memories.js +13 -6
  254. package/dist/store/sqlite/money-transactions.d.ts +3 -1
  255. package/dist/store/sqlite/money-transactions.js +7 -3
  256. package/dist/store/sqlite/name-traces.d.ts +3 -3
  257. package/dist/store/sqlite/name-traces.js +29 -2
  258. package/dist/store/sqlite/orders.d.ts +3 -1
  259. package/dist/store/sqlite/orders.js +5 -2
  260. package/dist/store/sqlite/people-list.js +67 -22
  261. package/dist/store/sqlite/person-match-scan.d.ts +3 -1
  262. package/dist/store/sqlite/person-match-scan.js +97 -7
  263. package/dist/store/sqlite/products.d.ts +3 -1
  264. package/dist/store/sqlite/products.js +5 -2
  265. package/dist/store/sqlite/proposed-actions.d.ts +2 -1
  266. package/dist/store/sqlite/proposed-actions.js +7 -3
  267. package/dist/store/sqlite/query-filter.d.ts +4 -0
  268. package/dist/store/sqlite/query-filter.js +14 -0
  269. package/dist/store/sqlite/reads.d.ts +1 -0
  270. package/dist/store/sqlite/reads.js +14 -0
  271. package/dist/store/sqlite/records.d.ts +3 -1
  272. package/dist/store/sqlite/records.js +7 -5
  273. package/dist/store/sqlite/rows-page.d.ts +3 -0
  274. package/dist/store/sqlite/rows-page.js +4 -0
  275. package/dist/store/sqlite/searches.d.ts +2 -1
  276. package/dist/store/sqlite/searches.js +3 -1
  277. package/dist/store/sqlite/subscriptions.d.ts +5 -2
  278. package/dist/store/sqlite/subscriptions.js +13 -6
  279. package/dist/store/sqlite/task-board.js +27 -0
  280. package/dist/store/sqlite/task-find.d.ts +15 -0
  281. package/dist/store/sqlite/task-find.js +1 -0
  282. package/dist/store/sqlite/wallets.d.ts +3 -1
  283. package/dist/store/sqlite/wallets.js +7 -3
  284. package/dist/store/sqlite/work-tasks.d.ts +3 -11
  285. package/dist/store/sqlite/work-tasks.js +8 -4
  286. package/package.json +2 -2
  287. package/parity.json +24 -0
@@ -1,7 +1,9 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import * as v from "valibot";
3
3
  import { embeddingKeys, endpointKeyName } from "../embeddings/keys.js";
4
+ import { modelAddressAllowed, onThisComputer } from "../models/endpoint.js";
4
5
  import { modelGateway } from "../models/index.js";
6
+ import { localOnly } from "../models/local-only.js";
5
7
  import { costOf, DEFAULT_OFFER, enrichmentEndpoint, enrichmentPrice, estimateEnrichment, offeredModels, readEnrichmentSetting, } from "./enrichment-setting.js";
6
8
  /** One sync's share, as embedding is bounded per run; the next sync goes on where it stopped. */
7
9
  export const ENRICH_PER_RUN = 600;
@@ -62,6 +64,8 @@ export const ENRICHMENT_REASON_IDS = [
62
64
  "enrichment.rate-limited",
63
65
  "enrichment.bad-replies",
64
66
  "enrichment.cancelled",
67
+ "enrichment.local-only",
68
+ "enrichment.address-refused",
65
69
  "enrichment.error",
66
70
  ];
67
71
  const REASON_TEXT = {
@@ -76,6 +80,8 @@ const reasonIdOf = (error) => {
76
80
  return "enrichment.key-rejected";
77
81
  if (error.details.reason === "model.unreachable")
78
82
  return "enrichment.unreachable";
83
+ if (error.details.reason === "local-only.refused")
84
+ return "enrichment.local-only";
79
85
  if (error.code === "rate_limited")
80
86
  return "enrichment.rate-limited";
81
87
  if (error.code === "cancelled")
@@ -126,6 +132,26 @@ export const enrichRecords = async (store, options) => {
126
132
  const target = { provider: setting.provider, model: setting.model, baseUrl };
127
133
  const apiKey = keyLookup(options, setting)?.key;
128
134
  const maxRecords = options.maxRecords ?? ENRICH_PER_RUN;
135
+ const refused = !modelAddressAllowed(baseUrl)
136
+ ? "enrichment.address-refused"
137
+ : !onThisComputer(baseUrl) && localOnly(options.env)
138
+ ? "enrichment.local-only"
139
+ : undefined;
140
+ if (refused)
141
+ return {
142
+ status: "stopped",
143
+ provider: setting.provider,
144
+ model: setting.model,
145
+ enriched: 0,
146
+ failed: 0,
147
+ left: (await enrichment.pending(Number.MAX_SAFE_INTEGER, options.narrow)).length,
148
+ usage: { input: 0, output: 0 },
149
+ cost_usd: 0,
150
+ reason: refused === "enrichment.local-only"
151
+ ? "local only is on and the model is not on this computer; nothing was sent"
152
+ : "the address is plain http to another computer: use https, or http only on this computer; nothing was sent",
153
+ reason_id: refused,
154
+ };
129
155
  // Without a key the public API answers 401 only after the records' text has left; a custom server may need none.
130
156
  if (apiKey === undefined && setting.base_url === undefined)
131
157
  return {
@@ -145,6 +171,7 @@ export const enrichRecords = async (store, options) => {
145
171
  // The setting exists only with the owner's yes for this provider and endpoint; the endpoint is checked again.
146
172
  consent: (_request, chosen) => chosen.provider === setting.provider && chosen.baseUrl === baseUrl,
147
173
  key: () => apiKey,
174
+ env: options.env,
148
175
  ...(options.adapters ? { adapters: options.adapters } : {}),
149
176
  ...(options.fetch ? { fetch: options.fetch } : {}),
150
177
  ...(options.signal ? { signal: options.signal } : {}),
@@ -54,11 +54,11 @@ export interface EventsFound {
54
54
  by: "words" | "words and meaning";
55
55
  /** Why meaning was not searched, when it was not. */
56
56
  meaning_skipped?: string;
57
- hits: FoundEvent[];
58
- has_more: boolean;
57
+ items: FoundEvent[];
58
+ hasMore: boolean;
59
59
  /** More events matched than one search reads (50,000); the later ones were not read — narrow the query. */
60
60
  truncated?: true;
61
- next_offset?: number;
61
+ nextOffset?: number;
62
62
  }
63
63
  /** The calendar accounts the store holds: every account whose provider is of the `events` kind. */
64
64
  export declare const calendarAccounts: (store: MessageStore) => Promise<AccountKey[]>;
@@ -65,7 +65,7 @@ export const searchEvents = async (store, query, { limit = 20, offset = 0, accou
65
65
  });
66
66
  const accountIds = accounts === undefined ? undefined : await accountIdsOf(store, accounts);
67
67
  if (accountIds?.length === 0)
68
- return { query, by: "words", hits: [], has_more: false };
68
+ return { query, by: "words", items: [], hasMore: false };
69
69
  const words = plainQueryWords(asked === undefined ? query : questionText(query));
70
70
  const window = offset + limit;
71
71
  let meaningSkipped;
@@ -109,9 +109,9 @@ export const searchEvents = async (store, query, { limit = 20, offset = 0, accou
109
109
  query,
110
110
  by,
111
111
  ...skipped,
112
- hits: found.items.map((hit) => foundEvent(hit, query, ["words"])),
113
- has_more: found.hasMore,
114
- ...(found.hasMore && window <= MAX_EVENTS_OFFSET ? { next_offset: window } : {}),
112
+ items: found.items.map((hit) => foundEvent(hit, query, ["words"])),
113
+ hasMore: found.hasMore,
114
+ ...(found.hasMore && window <= MAX_EVENTS_OFFSET ? { nextOffset: window } : {}),
115
115
  ...truncated,
116
116
  };
117
117
  const ranked = new Map();
@@ -129,12 +129,12 @@ export const searchEvents = async (store, query, { limit = 20, offset = 0, accou
129
129
  return {
130
130
  query,
131
131
  by,
132
- hits: ordered.slice(offset, window).map(({ hit, by: halves }) => {
132
+ items: ordered.slice(offset, window).map(({ hit, by: halves }) => {
133
133
  const cosine = cosines.get(keyOf(hit));
134
134
  return { ...foundEvent(hit, query, halves), ...(cosine === undefined ? {} : { meaning_score: cosine }) };
135
135
  }),
136
- has_more: hasMore,
137
- ...(hasMore && window <= MAX_EVENTS_OFFSET ? { next_offset: window } : {}),
136
+ hasMore: hasMore,
137
+ ...(hasMore && window <= MAX_EVENTS_OFFSET ? { nextOffset: window } : {}),
138
138
  ...truncated,
139
139
  };
140
140
  };
@@ -174,7 +174,7 @@ export { QUERY_LIMITS, QUERY_VERSION } from "../search/lucene/types.js";
174
174
  export { questionLookup } from "../search/question-plan.js";
175
175
  export { type SearchTotal, TOTAL_CAP } from "../search/total.js";
176
176
  export { TASK_KINDS, TASK_ORIGINS, type TaskKind, type TaskOrigin } from "../tasks/index.js";
177
- export { type AccountScopeChange, addGroupMember, type ChatScope, type ChatScopeChange, type GroupMemberChange, type GroupMemberMove, type GroupStore, listAccountGroups, moveGroupMember, removeGroupMember, setAccountScope, setChatScope, } from "./account-groups.js";
177
+ export { type AccountScopeChange, addGroupMember, type ChatScope, type ChatScopeChange, deleteAccountGroup, type GroupMemberChange, type GroupMemberMove, type GroupStore, listAccountGroups, moveGroupMember, removeGroupMember, renameAccountGroup, setAccountScope, setChatScope, } from "./account-groups.js";
178
178
  export type { AdminFound, AdminQuery, AdminSelection, AdminStatisticsService } from "./admin-statistics.js";
179
179
  export { adminStatisticsService } from "./admin-statistics.js";
180
180
  export { GAP_BOUNDS, type GapPlan, type GapRepair, gapsService, type RepairOptions } from "./archive-gaps.js";
@@ -133,7 +133,7 @@ export { QUERY_LIMITS, QUERY_VERSION } from "../search/lucene/types.js";
133
133
  export { questionLookup } from "../search/question-plan.js";
134
134
  export { TOTAL_CAP } from "../search/total.js";
135
135
  export { TASK_KINDS, TASK_ORIGINS } from "../tasks/index.js";
136
- export { addGroupMember, listAccountGroups, moveGroupMember, removeGroupMember, setAccountScope, setChatScope, } from "./account-groups.js";
136
+ export { addGroupMember, deleteAccountGroup, listAccountGroups, moveGroupMember, removeGroupMember, renameAccountGroup, setAccountScope, setChatScope, } from "./account-groups.js";
137
137
  export { adminStatisticsService } from "./admin-statistics.js";
138
138
  export { GAP_BOUNDS, gapsService } from "./archive-gaps.js";
139
139
  export { countersService } from "./counters.js";
@@ -179,7 +179,7 @@ export const openMeetingEmbedder = async (choice, options = {}) => {
179
179
  throw error;
180
180
  }
181
181
  };
182
- engine = openRemote(remote, key, { concurrency: 1, fetch: guarded, tries: 1 });
182
+ engine = openRemote(remote, key, { concurrency: 1, fetch: guarded, tries: 1, env: options.env ?? process.env });
183
183
  }
184
184
  if (signal?.aborted) {
185
185
  await engine.close();
@@ -159,7 +159,7 @@ export const readMeetingProjectDiscovery = async (ports, projectName, original)
159
159
  limits: { limit: input.limit, maxReadBytes: input.maxReadBytes, maxVocabularyReadBytes, maxTerms },
160
160
  project,
161
161
  term,
162
- hits: result.items.map((hit) => cited(hit, input.accountId)),
162
+ items: result.items.map((hit) => cited(hit, input.accountId)),
163
163
  association: "unconfirmed-word-evidence",
164
164
  vocabularyFingerprint: found.fingerprint,
165
165
  hasMore,
@@ -175,7 +175,9 @@ export const senderAmong = async (store, accounts, reference, field = "from") =>
175
175
  }
176
176
  catch (error) {
177
177
  if (error instanceof CliError && error.code === "not_found") {
178
- throw new CliError("not_found", `${field}:${reference} — ${error.message}`);
178
+ throw new CliError("not_found", `${field}:${reference} — ${error.message}; a part of the name: ${field}:*${reference}*`, {
179
+ reason: "query.no-match",
180
+ });
179
181
  }
180
182
  throw error;
181
183
  }
@@ -184,8 +186,13 @@ export const senderAmong = async (store, accounts, reference, field = "from") =>
184
186
  export const MOST_NAME_MATCHES = 50;
185
187
  /** `candidates` are shaped as an ambiguous name's are: `{id, name, username}` for people, `{id, title}` for chats. */
186
188
  const patternRefused = (field, pattern, what, found, near) => {
187
- if (found === 0)
188
- throw new CliError("not_found", `${field}:${pattern} — no ${what} fits${near.length ? `; near: ${near.map(({ label }) => label).join(", ")}` : ""}`, { candidates: near.map(({ candidate }) => candidate) });
189
+ if (found === 0) {
190
+ const inside = `*${pattern.replace(/^\*+|\*+$/gu, "")}*`;
191
+ const [closest] = near;
192
+ throw new CliError("not_found", `${field}:${pattern} — no ${what} fits${near.length ? `; near: ${near.map(({ label }) => label).join(", ")}` : ""}` +
193
+ ` — a pattern matches the whole name: ${pattern === inside ? "" : `write ${field}:${inside} for a part of it, or `}` +
194
+ `the name: ${field}:${JSON.stringify(closest?.label ?? pattern.replace(/[*?]/gu, ""))}`, { reason: "query.no-match", candidates: near.map(({ candidate }) => candidate) });
195
+ }
189
196
  throw new CliError("validation_error", `${field}:${pattern} fits ${found} ${what}, more than ${MOST_NAME_MATCHES} — write more of the name`, { reason: "query.too-large", budget: "name matches", limit: MOST_NAME_MATCHES, complete: false });
190
197
  };
191
198
  /** Every sender a name pattern (`from:Ярослав*`) fits, through the names each messenger's accounts have seen. */
@@ -4,7 +4,7 @@ import { parseLocator } from "../domain/locator.js";
4
4
  import { isImportedProvider, kindIn, UNKNOWN_PROVIDER } from "../domain/providers.js";
5
5
  import { syncsOneChat } from "../ports/traits.js";
6
6
  import { PRESET_VERSION } from "../search/lucene/presets.js";
7
- import { FIELD_VERSION, validateAst, validateFields } from "../search/lucene/registry.js";
7
+ import { FIELD_VERSION, isPresence, validateAst, validateFields } from "../search/lucene/registry.js";
8
8
  import { hasStems, hasText, isStemmed, } from "../search/lucene/resolved.js";
9
9
  import { inSource, sourceOf } from "../search/query.js";
10
10
  import { createStemmer, DEFAULT_STEMMERS } from "../search/stem.js";
@@ -33,7 +33,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
33
33
  if (request.ast !== undefined && request.exact)
34
34
  searchError("query.conflict", { start: 0, end: 0 }, "an AST names its fields — use field exact instead of exact");
35
35
  const ast = request.ast !== undefined
36
- ? validateAst(request.ast)
36
+ ? validateAst(request.ast, { presence: true })
37
37
  : request.text === undefined
38
38
  ? {
39
39
  version: 1,
@@ -49,7 +49,7 @@ export const prepareLucene = async (store, account, request, messenger) => {
49
49
  span: { start: 0, end: 0 },
50
50
  },
51
51
  }
52
- : validateFields(parseLucene(request.text, { ...MESSAGE_PARSING, defaultField: request.exact ? "exact" : "text" }));
52
+ : validateFields(parseLucene(request.text, { ...MESSAGE_PARSING, defaultField: request.exact ? "exact" : "text" }), { presence: true });
53
53
  const timezone = timezoneOf(request.timezone);
54
54
  const stored = await store.accounts.accounts();
55
55
  // A fresh store has no row yet for the account it runs as; "every account" still means that one.
@@ -102,6 +102,8 @@ export const prepareLucene = async (store, account, request, messenger) => {
102
102
  ...node,
103
103
  clauses: await Promise.all(node.clauses.map(async ({ occur, node }) => ({ occur, node: await resolve(node) }))),
104
104
  };
105
+ if (isPresence(node))
106
+ return node;
105
107
  if (node.field === "chat" && node.operator === "wildcard")
106
108
  return anyOf(node, await chatsMatchingIn(chatLookup, scopeAccounts, node.value), (chat) => ({ chat }));
107
109
  if (node.field === "chat")
@@ -254,7 +256,7 @@ export const coverageOf = async (store, { scopeAccounts, selectedChat }, messeng
254
256
  for (const chat of await store.chats.chatCompleteness(selected, chatIds))
255
257
  completeness.push({ ...chat, ...selected });
256
258
  const wanted = new Set(chatIds);
257
- for (const one of await store.chats.chatStats(selected))
259
+ for (const one of await store.chats.chatsNewest(selected))
258
260
  if (wanted.has(one.chatId))
259
261
  stats.set(statKey(selected, one.chatId), one);
260
262
  }
@@ -14,12 +14,12 @@ export declare const metadataService: (deps: ServiceDeps) => {
14
14
  dryRun?: boolean;
15
15
  }) => Promise<{
16
16
  items: ({
17
+ error?: undefined;
17
18
  chatId: string;
18
19
  tags: import("../domain/channel-tags.js").ChannelTagMatch[];
19
20
  algorithm: string;
20
21
  fetchedAt: string | null;
21
22
  source: string;
22
- error?: undefined;
23
23
  } | {
24
24
  tags?: undefined;
25
25
  algorithm?: undefined;
@@ -139,11 +139,11 @@ export interface NotesFound {
139
139
  by: "words" | "words and meaning";
140
140
  /** Why meaning was not searched, when it was not. */
141
141
  meaning_skipped?: string;
142
- hits: FoundNote[];
142
+ items: FoundNote[];
143
143
  /** How many notes match the query, every page together, as Elasticsearch's `hits.total`. */
144
144
  total?: SearchTotal;
145
- has_more: boolean;
146
- next_offset?: number;
145
+ hasMore: boolean;
146
+ nextOffset?: number;
147
147
  /** What the notes found link to, most linked first. */
148
148
  linked: LinkedRecord[];
149
149
  /** Documents whose picture is nearest the words, best first; only when `pictures` was asked for. Never in `hits`. */
@@ -543,10 +543,10 @@ export const searchNotes = async (store, query, { limit = 20, offset = 0, tag, f
543
543
  ...(filter === undefined ? {} : { filter }),
544
544
  by: meaning === undefined ? "words" : "words and meaning",
545
545
  ...(meaningSkipped === undefined ? {} : { meaning_skipped: meaningSkipped }),
546
- hits,
546
+ items: hits,
547
547
  total,
548
- has_more: hasMore,
549
- ...(hasMore && window <= MAX_NOTES_OFFSET ? { next_offset: window } : {}),
548
+ hasMore: hasMore,
549
+ ...(hasMore && window <= MAX_NOTES_OFFSET ? { nextOffset: window } : {}),
550
550
  linked: [...counts.values()].sort((a, b) => b.notes - a.notes || (a.name ?? a.ref ?? "").localeCompare(b.name ?? b.ref ?? "")),
551
551
  ...lane,
552
552
  };
@@ -23,8 +23,8 @@ export const openTasksOf = async (store, projects) => {
23
23
  const tasks = [];
24
24
  let full = false;
25
25
  for (const project of projects) {
26
- const found = await store.tasks.find({ project: project.ref, limit: STORE_PAGE });
27
- full ||= found.length >= STORE_PAGE;
26
+ const { items: found, hasMore } = await store.tasks.find({ project: project.ref, limit: STORE_PAGE });
27
+ full ||= hasMore;
28
28
  for (const task of found)
29
29
  if (!isClosedState(task.status))
30
30
  tasks.push({
@@ -78,8 +78,8 @@ export const organizationContext = async (store, reference, { accounts, limit =
78
78
  limit: STORE_PAGE,
79
79
  ...(accounts === undefined ? {} : { accounts }),
80
80
  });
81
- dealsFull ||= found.length >= STORE_PAGE;
82
- for (const deal of found)
81
+ dealsFull ||= found.hasMore;
82
+ for (const deal of found.items)
83
83
  deals.push(deal);
84
84
  }
85
85
  const catalog = new Map((await store.knowledge.projects()).map((project) => [project.ref, project]));
@@ -96,14 +96,17 @@ export const organizationContext = async (store, reference, { accounts, limit =
96
96
  }
97
97
  const invoiceRows = await store.finance.invoices({ counterparty: ref, limit: STORE_PAGE });
98
98
  const paymentRows = await store.finance.payments({ party: ref, limit: STORE_PAGE });
99
- const invoices = notRejected(invoiceRows).map((invoice) => [invoice, "counterparty"]);
100
- const payments = notRejected(paymentRows).map((payment) => [payment, "counterparty"]);
99
+ const invoices = notRejected(invoiceRows.items).map((invoice) => [invoice, "counterparty"]);
100
+ const payments = notRejected(paymentRows.items).map((payment) => [
101
+ payment,
102
+ "counterparty",
103
+ ]);
101
104
  const orders = [];
102
105
  let ordersFull = false;
103
106
  for (const side of ["customer", "supplier"]) {
104
107
  const found = await store.orders.list({ [side]: ref, limit: STORE_PAGE });
105
- ordersFull ||= found.length >= STORE_PAGE;
106
- for (const order of notRejected(found))
108
+ ordersFull ||= found.hasMore;
109
+ for (const order of notRejected(found.items))
107
110
  orders.push({
108
111
  ref: order.ref,
109
112
  title: order.title,
@@ -114,7 +117,7 @@ export const organizationContext = async (store, reference, { accounts, limit =
114
117
  side,
115
118
  });
116
119
  }
117
- const financeComplete = invoiceRows.length < STORE_PAGE && paymentRows.length < STORE_PAGE && !ordersFull;
120
+ const financeComplete = !invoiceRows.hasMore && !paymentRows.hasMore && !ordersFull;
118
121
  const members = [];
119
122
  for (const person of people)
120
123
  if (person.roles.some((role) => isUsable(role.standing))) {
@@ -26,6 +26,8 @@ export interface PeopleService {
26
26
  order: "recent" | "name";
27
27
  name?: Predicate;
28
28
  notes?: Predicate;
29
+ email?: Predicate;
30
+ phone?: Predicate;
29
31
  } & PageWindow): Promise<Page<Contact>>;
30
32
  show(person: string, options?: {
31
33
  notes?: boolean;
@@ -58,7 +58,7 @@ export const peopleService = (deps) => {
58
58
  const held = stored ? { store: await deps.store(), account: await deps.account() } : await storeIfOpen(deps);
59
59
  if (held && (await held.store.people.countContacts(held.account)) > 0)
60
60
  return storedContacts(held.store, held.account, options);
61
- for (const term of [options.name, options.notes])
61
+ for (const term of [options.name, options.notes, options.email, options.phone])
62
62
  if (term)
63
63
  queryError("query.unsupported-field", term.span, `${term.field}: reads the contacts kept in the local store, and it keeps none yet; \`contacts sync\` fills it`, { command: "contacts list" }, { supported: [] });
64
64
  return contactsIn(chats ?? (await (await deps.store()).chats.chats(await deps.account(), {})).items, options, deps.messenger.partnerOf);
@@ -252,7 +252,7 @@ export const phoneOf = (typed) => {
252
252
  }
253
253
  return digits;
254
254
  };
255
- const storedContacts = async (store, account, { order, name, notes, limit, offset }) => {
255
+ const storedContacts = async (store, account, { order, name, notes, email, phone, limit, offset, }) => {
256
256
  // Chats saved since the last refresh may have moved someone up; the order is worked out again here.
257
257
  if (order === "recent")
258
258
  await store.people.refreshRecency(account);
@@ -260,6 +260,8 @@ const storedContacts = async (store, account, { order, name, notes, limit, offse
260
260
  const filter = {
261
261
  ...(query === undefined ? {} : { query }),
262
262
  ...(notes ? { notes: notes.value.replace(/^\*+|\*+$/g, "") } : {}),
263
+ ...(email ? { email: email.value.replace(/^\*+|\*+$/g, "") } : {}),
264
+ ...(phone ? { phone: phone.value.replace(/^\*+|\*+$/g, "") } : {}),
263
265
  };
264
266
  return store.people.contacts(account, {
265
267
  order,
@@ -1,4 +1,5 @@
1
1
  import { type Id } from "../domain/models.js";
2
+ import { type RemoteFile } from "../ports/messenger.js";
2
3
  import type { ServiceDeps } from "./deps.js";
3
4
  import type { MessagesService } from "./messages.js";
4
5
  /** A bigger file is no photo a chat sends: skipping it costs a vector, reading it costs memory. */
@@ -33,6 +34,14 @@ export interface PictureLane {
33
34
  export declare const PICTURES_OFF = "picture search is off for this profile \u2014 set pictureSearch to true in its config to turn it on";
34
35
  /** What CLIP's text side can use of a Lucene query: the words, without fields, operators and quotes. */
35
36
  export declare const plainWords: (query: string) => string;
37
+ /**
38
+ * A picture's bytes: the saved copy when it is a regular file small enough, else a fresh download through the
39
+ * messenger. `read` is told which file was downloaded, so its refreshed reference can be kept.
40
+ */
41
+ export declare const pictureBytes: (picture: {
42
+ localPath: string | null;
43
+ position: number;
44
+ }, files: () => Promise<RemoteFile[]>, read: (file: RemoteFile) => Promise<void>) => Promise<Uint8Array | undefined>;
36
45
  export declare const picturesService: (deps: ServiceDeps) => {
37
46
  /**
38
47
  * Gives the images no vector yet one, reading each through the messenger's own download and keeping nothing
@@ -1,5 +1,5 @@
1
1
  import { createHash } from "node:crypto";
2
- import { readFile, stat } from "node:fs/promises";
2
+ import { lstat, readFile } from "node:fs/promises";
3
3
  import { setTimeout as sleep } from "node:timers/promises";
4
4
  import { CliError } from "@wirecat/cli-base";
5
5
  import { formatLocator } from "../domain/locator.js";
@@ -24,6 +24,38 @@ export const plainWords = (query) => query
24
24
  .replace(/[()"+\-~^*?\\[\]{}!|&]/g, " ")
25
25
  .replace(/\s+/g, " ")
26
26
  .trim();
27
+ /**
28
+ * A picture's bytes: the saved copy when it is a regular file small enough, else a fresh download through the
29
+ * messenger. `read` is told which file was downloaded, so its refreshed reference can be kept.
30
+ */
31
+ export const pictureBytes = async (picture, files, read) => {
32
+ if (picture.localPath) {
33
+ try {
34
+ // A link could point the read at another file; a saved copy is never one.
35
+ const found = await lstat(picture.localPath);
36
+ if (found.isFile() && found.size <= PICTURE_MAX_BYTES)
37
+ return await readFile(picture.localPath);
38
+ }
39
+ catch {
40
+ // The saved copy is gone; the messenger still has the picture.
41
+ }
42
+ }
43
+ const images = (await files()).filter(({ kind, mime }) => kind === "photo" || mime?.startsWith("image/"));
44
+ const file = images.find(({ position }) => position === picture.position) ??
45
+ (images.every(({ position }) => position === undefined) ? images[0] : undefined);
46
+ if (!file || (file.size !== undefined && file.size > PICTURE_MAX_BYTES))
47
+ return undefined;
48
+ const parts = [];
49
+ let total = 0;
50
+ for await (const part of file.bytes()) {
51
+ total += part.length;
52
+ if (total > PICTURE_MAX_BYTES)
53
+ return undefined;
54
+ parts.push(part);
55
+ }
56
+ await read(file);
57
+ return Buffer.concat(parts);
58
+ };
27
59
  export const picturesService = (deps) => {
28
60
  let opened;
29
61
  const open = async () => {
@@ -44,32 +76,6 @@ export const picturesService = (deps) => {
44
76
  return opened;
45
77
  };
46
78
  const model = imageModel(DEFAULT_IMAGE_MODEL);
47
- const bytesOf = async (picture, files, read) => {
48
- if (picture.localPath) {
49
- try {
50
- if ((await stat(picture.localPath)).size <= PICTURE_MAX_BYTES)
51
- return await readFile(picture.localPath);
52
- }
53
- catch {
54
- // The saved copy is gone; the messenger still has the picture.
55
- }
56
- }
57
- const images = (await files()).filter(({ kind, mime }) => kind === "photo" || mime?.startsWith("image/"));
58
- const file = images.find(({ position }) => position === picture.position) ??
59
- (images.every(({ position }) => position === undefined) ? images[0] : undefined);
60
- if (!file || (file.size !== undefined && file.size > PICTURE_MAX_BYTES))
61
- return undefined;
62
- const parts = [];
63
- let total = 0;
64
- for await (const part of file.bytes()) {
65
- total += part.length;
66
- if (total > PICTURE_MAX_BYTES)
67
- return undefined;
68
- parts.push(part);
69
- }
70
- await read(file);
71
- return Buffer.concat(parts);
72
- };
73
79
  return {
74
80
  /**
75
81
  * Gives the images no vector yet one, reading each through the messenger's own download and keeping nothing
@@ -120,7 +126,7 @@ export const picturesService = (deps) => {
120
126
  return downloaded.files;
121
127
  };
122
128
  try {
123
- const bytes = await bytesOf(picture, files, async (file) => {
129
+ const bytes = await pictureBytes(picture, files, async (file) => {
124
130
  const refreshed = refreshedFiles([file]);
125
131
  if (refreshed.length === 0)
126
132
  return;
@@ -61,7 +61,7 @@ const owed = (item) => {
61
61
  const keepsBooks = async (store, projects) => {
62
62
  for (const project of projects) {
63
63
  const filter = { project, review: "confirmed", limit: 1 };
64
- if ((await store.finance.invoices(filter)).length || (await store.finance.payments(filter)).length)
64
+ if ((await store.finance.invoices(filter)).items.length || (await store.finance.payments(filter)).items.length)
65
65
  return true;
66
66
  }
67
67
  return false;
@@ -42,8 +42,10 @@ export const payments = {
42
42
  read: async (context) => {
43
43
  const projects = [context.project.ref, ...context.project.children.map((child) => child.ref)];
44
44
  const rows = await Promise.all(projects.map(async (project) => [
45
- ...(await context.store.finance.payments({ project, limit: 500 })).filter(holding).map(paid),
46
- ...(await context.store.finance.invoices({ project, open: true, limit: 500 })).filter(holding).map(expected),
45
+ ...(await context.store.finance.payments({ project, limit: 500 })).items.filter(holding).map(paid),
46
+ ...(await context.store.finance.invoices({ project, open: true, limit: 500 })).items
47
+ .filter(holding)
48
+ .map(expected),
47
49
  ]));
48
50
  return rows.flat();
49
51
  },
@@ -26,7 +26,10 @@ const tasksOf = async (context) => {
26
26
  const projects = [context.project.ref, ...context.project.children.map((child) => child.ref)];
27
27
  const accounts = new Map(context.chats.map((chat) => [taskAccount(chat.account), chat.account]));
28
28
  const inboxes = [...accounts.keys()].map(inboxKey);
29
- const found = await Promise.all([...projects, ...inboxes].map((project) => context.store.tasks.find({ project, limit: 500 }).catch(orNone)));
29
+ const found = await Promise.all([...projects, ...inboxes].map((project) => context.store.tasks
30
+ .find({ project, limit: 500 })
31
+ .then(({ items }) => items)
32
+ .catch(orNone)));
30
33
  const projectRefs = new Set(projects);
31
34
  return found
32
35
  .flat()
@@ -82,7 +85,7 @@ export const promises = {
82
85
  scope: "project",
83
86
  read: async (context) => {
84
87
  const projects = [context.project.ref, ...context.project.children.map((child) => child.ref)];
85
- const facts = (await Promise.all(projects.map((project) => context.store.facts.list({ type: "promise", project }))))
88
+ const facts = (await Promise.all(projects.map(async (project) => (await context.store.facts.list({ type: "promise", project })).items)))
86
89
  .flat()
87
90
  .filter((fact) => fact.status === "proposed" || fact.status === "accepted");
88
91
  return [
@@ -27,7 +27,7 @@ export const actionKind = (store, claimed) => ({
27
27
  kind: "action",
28
28
  list: async (filter) => {
29
29
  const status = storedStatus(filter);
30
- const actions = await store.proposedActions.list({
30
+ const { items: actions } = await store.proposedActions.list({
31
31
  except: [...claimed(), MEETING_FINDINGS_KIND, EVIDENCE_FINDINGS_KIND, MAIL_FINDINGS_KIND],
32
32
  ...(status === undefined ? {} : { status }),
33
33
  ...pushed(filter),
@@ -28,7 +28,7 @@ export const factKind = (store) => ({
28
28
  prefix: "fact",
29
29
  list: async (filter) => {
30
30
  const status = filter.status ?? "proposed";
31
- const facts = await store.facts.list({
31
+ const { items: facts } = await store.facts.list({
32
32
  ...pushed(filter),
33
33
  ...(status === "all" ? {} : { status: status === "confirmed" ? "accepted" : status }),
34
34
  order: "created",
@@ -5,6 +5,7 @@ import type { ProposalKind } from "../types.js";
5
5
  export declare const FACT_SUMMARIES: Record<string, (finding: Finding) => string>;
6
6
  /**
7
7
  * An agent's batch of cited facts and tasks from stored messages, mail and documents. Confirming accepts the parts
8
- * named, or every finding not rejected before; the rest are rejected. Meeting findings have their own kind.
8
+ * named, or every finding not rejected before; the rest wait. Rejecting turns down what still waits. Meeting findings
9
+ * have their own kind.
9
10
  */
10
11
  export declare const findingsKind: (store: Pick<MessageStore, "evidenceFindings" | "proposedActions">) => ProposalKind;
@@ -10,7 +10,7 @@ export const FACT_SUMMARIES = {
10
10
  const statusOf = (batch) => batch.status === "proposed" ? "proposed" : batch.receipt?.accepted.length ? "confirmed" : "rejected";
11
11
  const rowOf = (batch, createdAt) => {
12
12
  const findings = batch.input.findings;
13
- const outcome = (id) => batch.receipt?.items.find((item) => item.id === id)?.status ?? null;
13
+ const outcome = (id) => (batch.receipt?.items ?? batch.decided).find((item) => item.id === id)?.status ?? null;
14
14
  return {
15
15
  id: batch.id,
16
16
  kind: "findings",
@@ -35,7 +35,8 @@ const rowOf = (batch, createdAt) => {
35
35
  };
36
36
  /**
37
37
  * An agent's batch of cited facts and tasks from stored messages, mail and documents. Confirming accepts the parts
38
- * named, or every finding not rejected before; the rest are rejected. Meeting findings have their own kind.
38
+ * named, or every finding not rejected before; the rest wait. Rejecting turns down what still waits. Meeting findings
39
+ * have their own kind.
39
40
  */
40
41
  export const findingsKind = (store) => {
41
42
  // The batch view carries no staging time; its stored proposal does.
@@ -56,7 +57,7 @@ export const findingsKind = (store) => {
56
57
  limit: 50,
57
58
  offset,
58
59
  });
59
- rows.push(...kept(await Promise.all(page.items.map(created)), { ...filter, limit: 50 }));
60
+ rows.push(...kept(await Promise.all(page.items.map(created)), { ...filter, limit: 50 }).items);
60
61
  if (!page.hasMore)
61
62
  break;
62
63
  }
@@ -65,7 +66,11 @@ export const findingsKind = (store) => {
65
66
  get: async (id) => created(await store.evidenceFindings.get(id)),
66
67
  decide: async (id, { confirm, by, parts, reason }) => {
67
68
  const batch = await store.evidenceFindings.get(id);
68
- const turnedDown = new Set(batch.previous.filter((one) => one.status === "rejected").map((one) => one.id));
69
+ // A finding this batch already decided keeps its outcome; a confirm with no names takes what still waits.
70
+ const turnedDown = new Set([
71
+ ...batch.previous.filter((one) => one.status === "rejected").map((one) => one.id),
72
+ ...batch.decided.map((one) => one.id),
73
+ ]);
69
74
  const accept = !confirm
70
75
  ? []
71
76
  : (parts ?? batch.input.findings.map((finding) => finding.id).filter((one) => !turnedDown.has(one)));
@@ -75,7 +80,9 @@ export const findingsKind = (store) => {
75
80
  by,
76
81
  ...(reason === undefined ? {} : { reason }),
77
82
  });
78
- const made = (reviewed.receipt?.items ?? []).flatMap((item) => item.status === "accepted" && item.reference && !item.reused ? [item.reference] : []);
83
+ const made = (reviewed.receipt?.items ?? reviewed.decided).flatMap((item) => item.status === "accepted" && item.reference && !item.reused && accept.includes(item.id)
84
+ ? [item.reference]
85
+ : []);
79
86
  return { id, kind: "findings", status: accept.length ? "confirmed" : "rejected", made };
80
87
  },
81
88
  };
@@ -27,7 +27,7 @@ export const identityLinkKind = (store) => ({
27
27
  ownerOnly: true,
28
28
  list: async (filter) => {
29
29
  const status = storedStatus(filter);
30
- const stored = await store.proposedActions.list({
30
+ const { items: stored } = await store.proposedActions.list({
31
31
  kinds: [IDENTITY_LINK_KIND],
32
32
  ...(status === undefined ? {} : { status }),
33
33
  ...pushed(filter),
@@ -44,7 +44,7 @@ export const identitySplitKind = (store) => ({
44
44
  ownerOnly: true,
45
45
  list: async (filter) => {
46
46
  const status = storedStatus(filter);
47
- const stored = await store.proposedActions.list({
47
+ const { items: stored } = await store.proposedActions.list({
48
48
  kinds: [IDENTITY_SPLIT_KIND],
49
49
  ...(status === undefined ? {} : { status }),
50
50
  ...pushed(filter),