@wirecat/cli-core 0.618.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 (274) hide show
  1. package/CHANGELOG.md +339 -1
  2. package/README.md +1 -1
  3. package/THIRD_PARTY_NOTICES +3 -0
  4. package/dist/background/daily-archive-timer.d.ts +1 -1
  5. package/dist/background/deliver.d.ts +5 -2
  6. package/dist/background/deliver.js +30 -12
  7. package/dist/background/report/render.d.ts +3 -1
  8. package/dist/background/report/render.js +3 -1
  9. package/dist/calendar/cli/answers.d.ts +1 -0
  10. package/dist/calendar/cli/answers.js +6 -1
  11. package/dist/calendar/cli/index.js +2 -14
  12. package/dist/calendar/cli/people-link.d.ts +3 -0
  13. package/dist/calendar/cli/people-link.js +23 -0
  14. package/dist/calendar/index.d.ts +1 -1
  15. package/dist/calendar/index.js +1 -1
  16. package/dist/calendar/mcp/index.d.ts +12 -12
  17. package/dist/cli/base-stages-command.d.ts +22 -0
  18. package/dist/cli/base-stages-command.js +174 -0
  19. package/dist/cli/command-runs.d.ts +2 -0
  20. package/dist/cli/command-runs.js +3 -1
  21. package/dist/cli/config-command.js +6 -1
  22. package/dist/cli/context.js +1 -0
  23. package/dist/cli/group-lock.d.ts +42 -0
  24. package/dist/cli/group-lock.js +130 -0
  25. package/dist/cli/index.d.ts +7 -2
  26. package/dist/cli/index.js +7 -2
  27. package/dist/cli/messenger/backfill-command.js +27 -15
  28. package/dist/cli/messenger/contacts-command.js +10 -3
  29. package/dist/cli/messenger/context.js +1 -0
  30. package/dist/cli/messenger/doctor-command.js +3 -1
  31. package/dist/cli/messenger/models-command.js +1 -1
  32. package/dist/cli/messenger/store-maintenance-command.d.ts +22 -2
  33. package/dist/cli/messenger/store-maintenance-command.js +9 -4
  34. package/dist/cli/model-catalogue-command.d.ts +3 -1
  35. package/dist/cli/model-catalogue-command.js +46 -2
  36. package/dist/cli/profile.d.ts +8 -0
  37. package/dist/cli/profile.js +25 -0
  38. package/dist/cli/program.js +2 -0
  39. package/dist/cli/runs/search-query.d.ts +1 -1
  40. package/dist/cli/runs/search-query.js +4 -0
  41. package/dist/cli/runs/search.d.ts +5 -1
  42. package/dist/cli/runs/search.js +12 -1
  43. package/dist/cli/search-left-out.d.ts +6 -1
  44. package/dist/cli/search-left-out.js +9 -4
  45. package/dist/cli/settings.d.ts +8 -0
  46. package/dist/cli/settings.js +17 -2
  47. package/dist/cli/shared-command-exports.d.ts +16 -0
  48. package/dist/cli/store-recover.d.ts +3 -3
  49. package/dist/cli/store-recover.js +26 -26
  50. package/dist/cli/store-settings.d.ts +2 -0
  51. package/dist/cli/store-settings.js +37 -9
  52. package/dist/crm/cli/index.js +38 -6
  53. package/dist/crm/group-hint.d.ts +8 -0
  54. package/dist/crm/group-hint.js +13 -0
  55. package/dist/crm/source.d.ts +12 -1
  56. package/dist/crm/sync.d.ts +31 -2
  57. package/dist/crm/sync.js +110 -3
  58. package/dist/crm/testing/acme-scenario.d.ts +40 -0
  59. package/dist/crm/testing/acme-scenario.js +170 -0
  60. package/dist/crm/testing/index.d.ts +1 -0
  61. package/dist/crm/testing/index.js +1 -0
  62. package/dist/crm/testing/source-contract.js +12 -0
  63. package/dist/crm/testing/source.d.ts +2 -0
  64. package/dist/crm/testing/source.js +1 -0
  65. package/dist/domain/addresses.d.ts +13 -0
  66. package/dist/domain/addresses.js +63 -0
  67. package/dist/domain/categories.d.ts +3 -0
  68. package/dist/domain/categories.js +2 -0
  69. package/dist/domain/crm.d.ts +23 -0
  70. package/dist/domain/crm.js +7 -0
  71. package/dist/domain/mentions.d.ts +2 -12
  72. package/dist/domain/mentions.js +2 -19
  73. package/dist/domain/orders.d.ts +8 -1
  74. package/dist/domain/orders.js +6 -2
  75. package/dist/domain/phones.d.ts +26 -0
  76. package/dist/domain/phones.js +48 -0
  77. package/dist/domain/record-types.d.ts +1 -1
  78. package/dist/domain/record-types.js +1 -0
  79. package/dist/domain/records.d.ts +5 -0
  80. package/dist/domain/ref-summaries.d.ts +39 -0
  81. package/dist/domain/ref-summaries.js +51 -3
  82. package/dist/domain/relations.d.ts +12 -2
  83. package/dist/domain/relations.js +14 -3
  84. package/dist/domain/vcard.d.ts +2 -2
  85. package/dist/domain/vcard.js +4 -10
  86. package/dist/embeddings/models.d.ts +11 -3
  87. package/dist/embeddings/models.js +28 -4
  88. package/dist/entities/business-context.d.ts +149 -0
  89. package/dist/entities/business-context.js +192 -0
  90. package/dist/entities/contact-activity.d.ts +2 -0
  91. package/dist/entities/contact-activity.js +7 -1
  92. package/dist/entities/contact-context.d.ts +157 -0
  93. package/dist/entities/contact-context.js +2 -0
  94. package/dist/entities/deal.d.ts +10 -0
  95. package/dist/entities/deal.js +2 -0
  96. package/dist/entities/index.d.ts +23 -3
  97. package/dist/entities/index.js +5 -0
  98. package/dist/entities/mention.d.ts +4 -3
  99. package/dist/entities/mention.js +2 -1
  100. package/dist/entities/message-transfer.d.ts +4 -2
  101. package/dist/entities/message-transfer.js +2 -2
  102. package/dist/entities/model.d.ts +2 -2
  103. package/dist/entities/model.js +1 -1
  104. package/dist/entities/relationship.d.ts +4 -0
  105. package/dist/entities/relationship.js +4 -0
  106. package/dist/errors/reasons.js +37 -4
  107. package/dist/fetch/page.js +2 -1
  108. package/dist/index.d.ts +3 -2
  109. package/dist/index.js +3 -2
  110. package/dist/meetings/context-store.d.ts +2 -0
  111. package/dist/meetings/findings-rules.d.ts +4 -0
  112. package/dist/meetings/findings-rules.js +5 -2
  113. package/dist/meetings/result-items.d.ts +1 -0
  114. package/dist/meetings/result-items.js +1 -0
  115. package/dist/models/index.js +22 -5
  116. package/dist/runs/events.d.ts +11 -1
  117. package/dist/runs/events.js +3 -1
  118. package/dist/runs/log-attributes.js +4 -0
  119. package/dist/runs/log-events.js +2 -0
  120. package/dist/runs/recording.d.ts +3 -0
  121. package/dist/runs/recording.js +36 -12
  122. package/dist/runs/run.d.ts +12 -3
  123. package/dist/runs/run.js +32 -13
  124. package/dist/search/account-list.d.ts +6 -0
  125. package/dist/search/account-list.js +9 -3
  126. package/dist/search/groups.d.ts +68 -0
  127. package/dist/search/groups.js +172 -0
  128. package/dist/services/account-groups.d.ts +28 -0
  129. package/dist/services/account-groups.js +89 -0
  130. package/dist/services/archive.d.ts +7 -1
  131. package/dist/services/archive.js +19 -3
  132. package/dist/services/business-context.d.ts +113 -0
  133. package/dist/services/business-context.js +156 -0
  134. package/dist/services/communications.d.ts +50 -0
  135. package/dist/services/communications.js +140 -0
  136. package/dist/services/deal-context.d.ts +90 -0
  137. package/dist/services/deal-context.js +131 -0
  138. package/dist/services/deps.d.ts +2 -0
  139. package/dist/services/enrichment.d.ts +7 -2
  140. package/dist/services/enrichment.js +46 -5
  141. package/dist/services/events-search.js +2 -1
  142. package/dist/services/group-guard.d.ts +28 -0
  143. package/dist/services/group-guard.js +131 -0
  144. package/dist/services/index.d.ts +15 -2
  145. package/dist/services/index.js +9 -2
  146. package/dist/services/ingest.d.ts +12 -0
  147. package/dist/services/ingest.js +4 -0
  148. package/dist/services/meaning-model.d.ts +7 -0
  149. package/dist/services/meaning-model.js +20 -0
  150. package/dist/services/meeting-context.d.ts +6 -1
  151. package/dist/services/meeting-context.js +12 -5
  152. package/dist/services/message-resolution.js +2 -3
  153. package/dist/services/messages-meaning.js +4 -5
  154. package/dist/services/messages-search.d.ts +5 -1
  155. package/dist/services/messages-search.js +1 -1
  156. package/dist/services/model-downloads.d.ts +1 -1
  157. package/dist/services/model-downloads.js +6 -4
  158. package/dist/services/money-context.d.ts +73 -0
  159. package/dist/services/money-context.js +77 -0
  160. package/dist/services/notes-search.d.ts +4 -1
  161. package/dist/services/notes-search.js +19 -7
  162. package/dist/services/organization-context.d.ts +80 -0
  163. package/dist/services/organization-context.js +154 -0
  164. package/dist/services/people.d.ts +22 -6
  165. package/dist/services/people.js +38 -8
  166. package/dist/services/person-business.d.ts +43 -0
  167. package/dist/services/person-business.js +67 -0
  168. package/dist/services/person-context.d.ts +9 -1
  169. package/dist/services/person-context.js +5 -3
  170. package/dist/services/proposals/kinds/identity-link.d.ts +4 -0
  171. package/dist/services/proposals/kinds/identity-link.js +48 -0
  172. package/dist/services/proposals/kinds/orders.js +1 -1
  173. package/dist/services/proposals/registry.js +2 -0
  174. package/dist/services/search-kind.d.ts +12 -5
  175. package/dist/services/search-kind.js +49 -10
  176. package/dist/services/text-model-choice.js +1 -1
  177. package/dist/store/accounts.d.ts +18 -0
  178. package/dist/store/accounts.js +18 -3
  179. package/dist/store/damage.d.ts +43 -10
  180. package/dist/store/damage.js +119 -36
  181. package/dist/store/decisions.js +3 -1
  182. package/dist/store/evidence-findings.d.ts +14 -0
  183. package/dist/store/evidence-findings.js +2 -0
  184. package/dist/store/exports.d.ts +2 -1
  185. package/dist/store/identity-links.d.ts +92 -0
  186. package/dist/store/identity-links.js +6 -0
  187. package/dist/store/index.d.ts +11 -5
  188. package/dist/store/index.js +5 -2
  189. package/dist/store/journal.d.ts +10 -0
  190. package/dist/store/journal.js +33 -0
  191. package/dist/store/marks.d.ts +19 -1
  192. package/dist/store/marks.js +23 -1
  193. package/dist/store/people.d.ts +22 -0
  194. package/dist/store/people.js +15 -1
  195. package/dist/store/sqlite/accounts.js +2 -0
  196. package/dist/store/sqlite/base-stages.d.ts +122 -0
  197. package/dist/store/sqlite/base-stages.js +443 -0
  198. package/dist/store/sqlite/base-suggest.d.ts +13 -0
  199. package/dist/store/sqlite/base-suggest.js +62 -0
  200. package/dist/store/sqlite/business-contracts.js +10 -1
  201. package/dist/store/sqlite/crm-settings.d.ts +12 -2
  202. package/dist/store/sqlite/crm-settings.js +56 -13
  203. package/dist/store/sqlite/crm.d.ts +13 -1
  204. package/dist/store/sqlite/crm.js +20 -4
  205. package/dist/store/sqlite/deals.d.ts +33 -0
  206. package/dist/store/sqlite/deals.js +42 -4
  207. package/dist/store/sqlite/decision-requests.js +7 -3
  208. package/dist/store/sqlite/email-index.js +8 -4
  209. package/dist/store/sqlite/evidence-findings.js +29 -5
  210. package/dist/store/sqlite/findings-core.js +4 -2
  211. package/dist/store/sqlite/identity-link-rows.d.ts +50 -0
  212. package/dist/store/sqlite/identity-link-rows.js +146 -0
  213. package/dist/store/sqlite/identity-proposals.d.ts +53 -0
  214. package/dist/store/sqlite/identity-proposals.js +234 -0
  215. package/dist/store/sqlite/knowledge.js +2 -2
  216. package/dist/store/sqlite/link-kinds.d.ts +1 -0
  217. package/dist/store/sqlite/link-kinds.js +1 -0
  218. package/dist/store/sqlite/link-row.d.ts +6 -0
  219. package/dist/store/sqlite/link-row.js +35 -0
  220. package/dist/store/sqlite/link-source.d.ts +10 -0
  221. package/dist/store/sqlite/link-source.js +16 -0
  222. package/dist/store/sqlite/manifest.js +1 -0
  223. package/dist/store/sqlite/meeting-context-links.js +9 -6
  224. package/dist/store/sqlite/memories.js +9 -7
  225. package/dist/store/sqlite/mentions.d.ts +4 -1
  226. package/dist/store/sqlite/mentions.js +14 -9
  227. package/dist/store/sqlite/migrations.generated.js +8 -0
  228. package/dist/store/sqlite/notes.d.ts +1 -2
  229. package/dist/store/sqlite/notes.js +4 -29
  230. package/dist/store/sqlite/open-store.js +3 -0
  231. package/dist/store/sqlite/open.js +11 -2
  232. package/dist/store/sqlite/orders.d.ts +2 -0
  233. package/dist/store/sqlite/orders.js +9 -3
  234. package/dist/store/sqlite/organization-categories.d.ts +18 -0
  235. package/dist/store/sqlite/organization-categories.js +34 -0
  236. package/dist/store/sqlite/organizations.d.ts +5 -1
  237. package/dist/store/sqlite/organizations.js +14 -4
  238. package/dist/store/sqlite/person-links.d.ts +19 -4
  239. package/dist/store/sqlite/person-links.js +49 -11
  240. package/dist/store/sqlite/person-match-scan.d.ts +13 -0
  241. package/dist/store/sqlite/person-match-scan.js +251 -0
  242. package/dist/store/sqlite/person-matcher.d.ts +16 -0
  243. package/dist/store/sqlite/person-matcher.js +32 -0
  244. package/dist/store/sqlite/proposed-actions.js +6 -0
  245. package/dist/store/sqlite/record-matching.d.ts +2 -8
  246. package/dist/store/sqlite/record-matching.js +8 -40
  247. package/dist/store/sqlite/record-projectors-phone.js +2 -1
  248. package/dist/store/sqlite/record-relationships.d.ts +52 -0
  249. package/dist/store/sqlite/record-relationships.js +243 -0
  250. package/dist/store/sqlite/record-run.d.ts +5 -0
  251. package/dist/store/sqlite/record-run.js +62 -2
  252. package/dist/store/sqlite/record-writes.d.ts +1 -1
  253. package/dist/store/sqlite/record-writes.js +4 -2
  254. package/dist/store/sqlite/records.js +27 -2
  255. package/dist/store/sqlite/ref-accounts.d.ts +13 -0
  256. package/dist/store/sqlite/ref-accounts.js +117 -0
  257. package/dist/store/sqlite/ref-summaries.js +5 -1
  258. package/dist/store/sqlite/relation-list.d.ts +4 -1
  259. package/dist/store/sqlite/relation-list.js +18 -2
  260. package/dist/store/sqlite/relation-proposals.d.ts +6 -0
  261. package/dist/store/sqlite/relation-proposals.js +3 -0
  262. package/dist/store/sqlite/relation-roles.js +12 -6
  263. package/dist/store/sqlite/reported-relations.d.ts +11 -1
  264. package/dist/store/sqlite/reported-relations.js +59 -18
  265. package/dist/store/sqlite/schema.d.ts +32 -0
  266. package/dist/store/sqlite/schema.js +3 -0
  267. package/dist/store/sqlite/transaction.js +11 -1
  268. package/dist/store/store.d.ts +3 -0
  269. package/dist/store/store.js +5 -0
  270. package/dist/store/write-events.d.ts +18 -0
  271. package/dist/store/write-events.js +88 -0
  272. package/package.json +3 -3
  273. package/parity.json +11 -4
  274. package/schemas/records-envelope.v1.schema.json +3 -0
@@ -254,10 +254,11 @@ export declare const messageSyncAll: v.StrictObjectSchema<{
254
254
  }, v.UnknownSchema, undefined>, undefined>;
255
255
  readonly limited: v.OptionalSchema<v.PicklistSchema<["group_too_large", "older_than_window"], undefined>, undefined>;
256
256
  }, undefined>, undefined>;
257
- /** How many chats the history limits left unread (big groups) or read only to the window's start. */
257
+ /** How many chats the history limits left unread (big groups) or read only to the window's start; muted, unread. */
258
258
  readonly limited: v.OptionalSchema<v.StrictObjectSchema<{
259
259
  readonly group_too_large: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
260
260
  readonly older_than_window: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
261
+ readonly muted: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
261
262
  }, undefined>, undefined>;
262
263
  readonly tasks: v.OptionalSchema<v.StrictObjectSchema<{
263
264
  readonly added: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -387,10 +388,11 @@ export declare const messageSync: v.UnionSchema<[v.StrictObjectSchema<{
387
388
  }, v.UnknownSchema, undefined>, undefined>;
388
389
  readonly limited: v.OptionalSchema<v.PicklistSchema<["group_too_large", "older_than_window"], undefined>, undefined>;
389
390
  }, undefined>, undefined>;
390
- /** How many chats the history limits left unread (big groups) or read only to the window's start. */
391
+ /** How many chats the history limits left unread (big groups) or read only to the window's start; muted, unread. */
391
392
  readonly limited: v.OptionalSchema<v.StrictObjectSchema<{
392
393
  readonly group_too_large: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
393
394
  readonly older_than_window: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
395
+ readonly muted: v.OptionalSchema<v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>, undefined>;
394
396
  }, undefined>, undefined>;
395
397
  readonly tasks: v.OptionalSchema<v.StrictObjectSchema<{
396
398
  readonly added: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.IntegerAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
@@ -83,8 +83,8 @@ export const messageSyncAll = v.strictObject({
83
83
  issue: v.optional(actionableError),
84
84
  limited: v.optional(historyLimited),
85
85
  })),
86
- /** How many chats the history limits left unread (big groups) or read only to the window's start. */
87
- limited: v.optional(v.strictObject({ group_too_large: count, older_than_window: count })),
86
+ /** How many chats the history limits left unread (big groups) or read only to the window's start; muted, unread. */
87
+ limited: v.optional(v.strictObject({ group_too_large: count, older_than_window: count, muted: v.optional(count) })),
88
88
  tasks,
89
89
  });
90
90
  export const messageSyncStarted = v.strictObject({ job: id, pid: count, chat: text, log: text });
@@ -10,7 +10,7 @@ export declare const model: v.StrictObjectSchema<{
10
10
  /** Which languages it reads, in words. */
11
11
  readonly languages: v.StringSchema<undefined>;
12
12
  readonly licence: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
13
- /** A text model's licence terms to accept with `models download --accept-terms`. */
13
+ /** A text model's licence page, for a model under conditions of its own (`NOTICE` beside its files says the same). */
14
14
  readonly terms: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
15
15
  /** A text model's size next to the others: small is fastest, large reads best. */
16
16
  readonly size: v.OptionalSchema<v.PicklistSchema<["small", "medium", "large"], undefined>, undefined>;
@@ -36,7 +36,7 @@ export declare const chosenModel: v.StrictObjectSchema<{
36
36
  /** Which languages it reads, in words. */
37
37
  readonly languages: v.StringSchema<undefined>;
38
38
  readonly licence: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
39
- /** A text model's licence terms to accept with `models download --accept-terms`. */
39
+ /** A text model's licence page, for a model under conditions of its own (`NOTICE` beside its files says the same). */
40
40
  readonly terms: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
41
41
  /** A text model's size next to the others: small is fastest, large reads best. */
42
42
  readonly size: v.OptionalSchema<v.PicklistSchema<["small", "medium", "large"], undefined>, undefined>;
@@ -11,7 +11,7 @@ export const model = v.strictObject({
11
11
  /** Which languages it reads, in words. */
12
12
  languages: text,
13
13
  licence: v.optional(text),
14
- /** A text model's licence terms to accept with `models download --accept-terms`. */
14
+ /** A text model's licence page, for a model under conditions of its own (`NOTICE` beside its files says the same). */
15
15
  terms: v.optional(text),
16
16
  /** A text model's size next to the others: small is fastest, large reads best. */
17
17
  size: v.optional(v.picklist(["small", "medium", "large"])),
@@ -19,5 +19,9 @@ export declare const relationship: v.StrictObjectSchema<{
19
19
  readonly position: v.NullableSchema<v.StringSchema<undefined>, undefined>;
20
20
  readonly starts_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
21
21
  readonly ends_at: v.NullableSchema<v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>, undefined>;
22
+ /** The source account that reported it, `<provider>:<account>`. */
23
+ readonly account: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
24
+ /** How a source made it when it stated none, such as `department-head`. */
25
+ readonly derived: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
22
26
  readonly created_at: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.IsoTimestampAction<string, "an ISO 8601 time in UTC">, v.EndsWithAction<string, "Z", "an ISO 8601 time in UTC, ending in `Z`">]>;
23
27
  }, undefined>;
@@ -21,5 +21,9 @@ export const relationship = v.strictObject({
21
21
  position: v.nullable(text),
22
22
  starts_at: v.nullable(time),
23
23
  ends_at: v.nullable(time),
24
+ /** The source account that reported it, `<provider>:<account>`. */
25
+ account: v.optional(text),
26
+ /** How a source made it when it stated none, such as `department-head`. */
27
+ derived: v.optional(text),
24
28
  created_at: time,
25
29
  });
@@ -60,6 +60,8 @@ const OTHERS = [
60
60
  ["query.time-limit", "timeout", "the search took longer than its time limit; the query itself is valid"],
61
61
  ["enrichment.owner-only", "permission_error", "only the owner turns enrichment on, not an agent"],
62
62
  ["model.offline", "permission_error", "downloading a model needs the network; --offline was requested"],
63
+ ["model.key-rejected", "invalid_response", "the model provider refused the API key (401 or 403)"],
64
+ ["model.unreachable", "invalid_response", "the model provider could not be reached over the network"],
63
65
  [
64
66
  "contract.unacknowledged-override",
65
67
  "configuration_error",
@@ -82,6 +84,7 @@ const OTHERS = [
82
84
  validation("mail-findings.invalid", "a checked mail findings batch would be refused; details.problems names why, finding by finding"),
83
85
  validation("mail-findings.key-used", "the findings batch key was already used for different input"),
84
86
  validation("finding.unknown-field", "a finding has a field its kind does not take"),
87
+ validation("finding.quote-not-found", "a finding's quote is not in the text it cites, word for word"),
85
88
  validation("finding.missing-field", "a finding leaves out a field its kind needs"),
86
89
  validation("document.changed", "the document changed while it was read; nothing was saved"),
87
90
  ["document.not-imported", "not_found", "the document is not imported in this source account"],
@@ -153,7 +156,7 @@ const OTHERS = [
153
156
  [
154
157
  "source.needs-sign-in",
155
158
  "authentication_error",
156
- "the page asks for a sign-in; a private Google document is read through Drive",
159
+ "the page asks for a sign-in; add a private Google document with drive documents add <url> --profiles <names|all>",
157
160
  ],
158
161
  validation("source.too-large", "the source is larger than one read takes"),
159
162
  validation("source.unsupported", "no reader takes this kind of source"),
@@ -194,6 +197,11 @@ const OTHERS = [
194
197
  "configuration_error",
195
198
  "the store file is damaged; store recover says what is lost and recovers it",
196
199
  ],
200
+ [
201
+ "store.journal-replaced",
202
+ "conflict",
203
+ "another program deleted or replaced the store's journal file while it was open; store recover says what to do",
204
+ ],
197
205
  validation("store.file-damaged", "the named store file is damaged or not a database"),
198
206
  [
199
207
  "store.unreadable",
@@ -282,8 +290,18 @@ const OTHERS = [
282
290
  validation("deal.closed", "a deleted deal or lead does not move or close"),
283
291
  validation("deal.copy", "a CRM's copy changes in the CRM; its next sync brings the change here"),
284
292
  validation("deal.field", "a field of the deal or lead is not valid"),
293
+ ["deal.denied", "permission_error", "the profile denies listing deals or leads, so none is answered"],
294
+ ["deal.out-of-scope", "not_found", "the deal or lead is a copy from an account outside the accounts asked for"],
285
295
  validation("deal.ref", "the reference names no deal or lead"),
286
296
  validation("deal.stage", "no stage of that name, or a stage name more than one pipeline has"),
297
+ validation("stage.base-field", "a base stage needs a name its set has once and a position within the set"),
298
+ validation("stage.base-outcome", "a base set keeps at least one stage of each outcome: open, won and lost"),
299
+ validation("stage.base-in-use", "the owner's own deals or leads stand or stood in that base stage"),
300
+ validation("stage.choice-required", "more than one stage of the row's pipeline maps to that base stage; move to one of the candidates"),
301
+ validation("stage.ref", "a stage is named by its stage:<id> reference"),
302
+ ["stage.owner-only", "permission_error", "only the owner confirms mappings and edits a base set, not an agent"],
303
+ validation("stage.unmapped", "no stage of the row's pipeline maps to that base stage; map one first"),
304
+ ["stage.not-found", "not_found", "no stored stage has that reference or name"],
287
305
  validation("pipeline.ambiguous", "more than one pipeline has that name; name it by its pipeline: reference"),
288
306
  validation("pipeline.duplicate", "a pipeline of that name and kind is already stored"),
289
307
  validation("pipeline.field", "a pipeline needs a name and at least one stage, each named once"),
@@ -297,6 +315,7 @@ const OTHERS = [
297
315
  validation("field.unknown-kind", "fields are listed for deals, leads, people and organizations only"),
298
316
  validation("crm.write-unsupported", "the CRM does not take this write, or does not recognise a repeated one"),
299
317
  validation("crm.unlisted-held", "a list of every id would mark most of a kind deleted; nothing was, until --rescan"),
318
+ validation("crm.narrowing-held", "the default scope mine would mark most of a kind's stored rows deleted; none is, until the owner sets the scope"),
300
319
  validation("crm.not-reported", "the CRM did not list users or departments; what they would say is unknown, nothing withdrawn"),
301
320
  validation("crm.reference-unknown", "a CRM row names a contact, company or user the store does not hold; that link was not made"),
302
321
  validation("crm.pending-dropped", "relationships waited too long for an end that never came; they were dropped"),
@@ -343,12 +362,25 @@ const OTHERS = [
343
362
  "conflict",
344
363
  "the owner separated this identity from that person; only the owner links it again",
345
364
  ],
346
- ["identity.owner-only", "permission_error", "only the owner undoes a merge or splits a person"],
365
+ [
366
+ "identity.owner-only",
367
+ "permission_error",
368
+ "only the owner undoes a merge, splits a person, confirms or undoes a link, or links an identity to themselves",
369
+ ],
347
370
  [
348
371
  "identity.stale",
349
372
  "conflict",
350
- "an identity of the merge was merged on into another person since; undo that merge first",
373
+ "the people a merge or a proposed link names changed since; undo the later merge, or propose the link again",
374
+ ],
375
+ [
376
+ "identity.rejected",
377
+ "conflict",
378
+ "the owner rejected linking these people on this evidence; only a new signal or identity proposes them again",
351
379
  ],
380
+ validation("identity.same", "the two identities are one person already"),
381
+ validation("identity.shared-phone", "more than six people share the phone number, so it proposes no one"),
382
+ validation("identity.shared-email", "more than six people share the address, so it proposes no one"),
383
+ validation("identity-link.dedicated-review", "an identity link is staged and decided through the people review"),
352
384
  ["transcription.no-key", "authentication_error", "no OpenAI key is set for transcription"],
353
385
  validation("transcription.too-large", "the audio is over the transcription provider's size limit"),
354
386
  [
@@ -364,7 +396,7 @@ const OTHERS = [
364
396
  validation("name.taken", "the name is already used"),
365
397
  validation("period.ambiguous", "the period can be read more than one way"),
366
398
  validation("proposal.wrong-state", "the proposal is not in a state that allows this"),
367
- validation("proposal.reason-required", "an agent deciding for the owner gives a reason"),
399
+ validation("proposal.reason-required", "an agent deciding for the owner, or proposing a link, gives a reason"),
368
400
  validation("decision.request-invalid", "a decision request needs its batch, message, owner and distinct known actions"),
369
401
  ["decision.token-unknown", "not_found", "no button has this token"],
370
402
  ["decision.token-used", "permission_error", "this button was already pressed"],
@@ -381,6 +413,7 @@ const OTHERS = [
381
413
  ],
382
414
  validation("proposal.decider-required", "a decision names who decides: the owner or an agent with a reason"),
383
415
  validation("proposal.ids", "the proposal ids cannot be read"),
416
+ ["group.outside", "permission_error", "the process is locked to a group, and this belongs to accounts outside it"],
384
417
  ["proposal.own", "permission_error", "an agent never decides its own proposal"],
385
418
  ["proposal.owner-only", "permission_error", "only the owner decides this proposal"],
386
419
  ["proposals.agent-decisions-off", "permission_error", "agent decisions are turned off; the owner decides"],
@@ -106,7 +106,8 @@ const readBody = async (response, limit) => {
106
106
  }
107
107
  return bytes;
108
108
  };
109
- const needsSignIn = (url) => new CliError("authentication_error", `${url.hostname} asks for a sign-in: read a private Google document through Drive`, {
109
+ const needsSignIn = (url) => new CliError("authentication_error", `${url.hostname} asks for a sign-in: add a private Google document through Drive, with ` +
110
+ "drive documents add <url> --profiles <names|all>", {
110
111
  reason: "source.needs-sign-in",
111
112
  });
112
113
  /**
package/dist/index.d.ts CHANGED
@@ -1,8 +1,9 @@
1
+ export { isNoReplyAddress, isRoleAddress, ROLE_ADDRESS_WORDS } from "./domain/addresses.js";
1
2
  export { CATALOG_KINDS, type CatalogKind, CONTRACT_KINDS, CONTRACT_STATUSES, type ContractKind, type ContractStatus, type Interval, intervalOf, intervalText, ORDER_DIRECTIONS, type OrderDirection, PERIOD_UNITS, type PeriodUnit, SUBSCRIPTION_STATUSES, type SubscriptionStatus, TRANSACTION_STATUSES, type TransactionStatus, WALLET_KINDS, type WalletKind, } from "./domain/business.js";
2
3
  export { bareCheck, type CheckWords, checkWords } from "./domain/checks.js";
3
4
  export type { CounterField, CounterObservation, CounterObservations, CounterState } from "./domain/counters.js";
4
5
  export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
5
- export { CRM_KINDS, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmRecords, type CrmStage, type CrmUser, type CrmValue, isItemKind, } from "./domain/crm.js";
6
+ export { CRM_KINDS, type CrmDepartment, type CrmField, type CrmItem, type CrmKind, type CrmOrganization, type CrmPerson, type CrmPipeline, type CrmRecords, type CrmScope, type CrmScopeSetting, type CrmStage, type CrmUser, type CrmValue, isCrmUserId, isItemKind, normalCrmUserId, } from "./domain/crm.js";
6
7
  export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, type DealKind, type DealRole, type DealStatus, STAGE_OUTCOMES, type StageOutcome, } from "./domain/deals.js";
7
8
  export { FINANCE_REVIEWS, type FinanceReview, INVOICE_DIRECTIONS, INVOICE_STATUSES, type InvoiceDirection, type InvoiceStatus, MONEY_DIRECTIONS, type MoneyDirection, } from "./domain/finance.js";
8
9
  export { type FormattedText, type HtmlFormatting, type MarkdownFormatting, type TextSpan, validateFormattedText, } from "./domain/formatting.js";
@@ -21,7 +22,7 @@ export type { RankingComponent, RankingInput, RankingMeasure, RankingOptions, Ra
21
22
  export { rankingOptions } from "./domain/rankings-options.js";
22
23
  export { type EnvelopeOptions, type EnvelopeRecord, type EnvelopeSource, envelopeOfJsonl, envelopeOfText, type IngestError, RECORD_ENTITY_TYPES, RECORD_OPERATIONS, RECORDS_ENVELOPE_SCHEMA, RECORDS_SCHEMA_VERSION, type RecordEntityType, type RecordOperation, type RecordRelation, type RecordsEnvelope, } from "./domain/records.js";
23
24
  export { canonicalReference, formatReference, looksLikeReference, parseReference, REF_KINDS, type Reference, type RefKindName, type RefKindSpec, } from "./domain/references.js";
24
- export { byEngagement, ENGAGEMENT_LEVELS, type Engagement, engagementRank, inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, type RelationKind, ROLE_LISTS, type RoleList, rolesOf, STANDINGS, type Standing, standingOf, usableLink, } from "./domain/relations.js";
25
+ export { byEngagement, CONTRACT_ROLES, ENGAGEMENT_LEVELS, type Engagement, engagementRank, inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, type RelationKind, ROLE_LISTS, type RoleList, rolesOf, STANDINGS, type Standing, standingOf, usableLink, } from "./domain/relations.js";
25
26
  export { normalizeTag, TAG_TYPES, type TagType } from "./domain/tags.js";
26
27
  export { envelopeOfVcard, isVcard, type VcardIssue, type VcardOptions } from "./domain/vcard.js";
27
28
  export { type AppErrors, DETAILS as CORE_DETAILS, failureContext, REASONS as CORE_REASONS } from "./errors/reasons.js";
package/dist/index.js CHANGED
@@ -1,7 +1,8 @@
1
+ export { isNoReplyAddress, isRoleAddress, ROLE_ADDRESS_WORDS } from "./domain/addresses.js";
1
2
  export { CATALOG_KINDS, CONTRACT_KINDS, CONTRACT_STATUSES, intervalOf, intervalText, ORDER_DIRECTIONS, PERIOD_UNITS, SUBSCRIPTION_STATUSES, TRANSACTION_STATUSES, WALLET_KINDS, } from "./domain/business.js";
2
3
  export { bareCheck, checkWords } from "./domain/checks.js";
3
4
  export { COUNTER_FIELDS, counterValue, observedCounters } from "./domain/counters.js";
4
- export { CRM_KINDS, isItemKind, } from "./domain/crm.js";
5
+ export { CRM_KINDS, isCrmUserId, isItemKind, normalCrmUserId, } from "./domain/crm.js";
5
6
  export { DEAL_KINDS, DEAL_ROLES, DEAL_STATUSES, STAGE_OUTCOMES, } from "./domain/deals.js";
6
7
  export { FINANCE_REVIEWS, INVOICE_DIRECTIONS, INVOICE_STATUSES, MONEY_DIRECTIONS, } from "./domain/finance.js";
7
8
  export { validateFormattedText, } from "./domain/formatting.js";
@@ -16,7 +17,7 @@ export { ADDED_ACCOUNT, ADDED_PROVIDER, CRM_OPENS, FOLDER_PROVIDERS, holdsKind,
16
17
  export { rankingOptions } from "./domain/rankings-options.js";
17
18
  export { envelopeOfJsonl, envelopeOfText, RECORD_ENTITY_TYPES, RECORD_OPERATIONS, RECORDS_ENVELOPE_SCHEMA, RECORDS_SCHEMA_VERSION, } from "./domain/records.js";
18
19
  export { canonicalReference, formatReference, looksLikeReference, parseReference, REF_KINDS, } from "./domain/references.js";
19
- export { byEngagement, ENGAGEMENT_LEVELS, engagementRank, inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, ROLE_LISTS, rolesOf, STANDINGS, standingOf, usableLink, } from "./domain/relations.js";
20
+ export { byEngagement, CONTRACT_ROLES, ENGAGEMENT_LEVELS, engagementRank, inverseOf, isUsable, ORGANIZATION_ROLES, PROJECT_ROLES, RELATION_KINDS, RELATIONS, ROLE_LISTS, rolesOf, STANDINGS, standingOf, usableLink, } from "./domain/relations.js";
20
21
  export { normalizeTag, TAG_TYPES } from "./domain/tags.js";
21
22
  export { envelopeOfVcard, isVcard } from "./domain/vcard.js";
22
23
  export { DETAILS as CORE_DETAILS, failureContext, REASONS as CORE_REASONS } from "./errors/reasons.js";
@@ -36,6 +36,8 @@ export interface ParticipantPersonLinkReceipt extends ParticipantPerson {
36
36
  personUid: string;
37
37
  previousPersonUid: string | null;
38
38
  changed: boolean;
39
+ /** An agent's association waits for the owner as this `identity_link` proposal; nothing moved. */
40
+ proposal?: string;
39
41
  }
40
42
  /** Mutations must check live scoped ownership, preconditions and targets in the same transaction. */
41
43
  export interface MeetingContextStore {
@@ -3,6 +3,8 @@ declare const TASK_TYPES: readonly ["bug", "feature", "chore"];
3
3
  export interface FindingEvidence {
4
4
  reference: string;
5
5
  fingerprint: string;
6
+ /** The words of the cited text the finding rests on, checked word for word when it is staged. */
7
+ quote?: string;
6
8
  }
7
9
  interface FindingBase {
8
10
  id: string;
@@ -91,6 +93,8 @@ export interface FindingsRules {
91
93
  payments?: boolean;
92
94
  /** A task finding may name no project: it goes in its account's inbox. */
93
95
  inboxTasks?: boolean;
96
+ /** Evidence may carry a quote of at most this many characters. */
97
+ quotes?: number;
94
98
  }
95
99
  /** A finding's cited evidence: 1–8 distinct references in `rules`' form, each with a 64-hex fingerprint. */
96
100
  export declare const validEvidence: (raw: unknown, rules: FindingsRules) => FindingEvidence[];
@@ -53,13 +53,16 @@ export const validEvidence = (raw, rules) => {
53
53
  .map((item) => {
54
54
  if (!item || typeof item !== "object")
55
55
  return invalid("finding evidence is a reference and fingerprint");
56
- findingFields(item, ["reference", "fingerprint"], rules.singular);
56
+ findingFields(item, rules.quotes ? ["reference", "fingerprint", "quote"] : ["reference", "fingerprint"], rules.singular);
57
57
  if (typeof item.reference !== "string" || typeof item.fingerprint !== "string")
58
58
  return invalid("evidence requires a reference and fingerprint");
59
59
  const reference = rules.reference(item.reference);
60
60
  if (!/^[a-f0-9]{64}$/.test(item.fingerprint))
61
61
  return invalid(`finding evidence requires exact ${rules.cited} references and fingerprints`);
62
- return { reference, fingerprint: item.fingerprint };
62
+ // Absent, not empty: a finding without a quote keeps the fingerprint it had before quotes existed.
63
+ if (item.quote === undefined)
64
+ return { reference, fingerprint: item.fingerprint };
65
+ return { reference, fingerprint: item.fingerprint, quote: findingText(item.quote, rules.quotes ?? 0) };
63
66
  })
64
67
  .sort((a, b) => a.reference.localeCompare(b.reference));
65
68
  if (new Set(evidence.map((item) => item.reference)).size !== evidence.length)
@@ -51,6 +51,7 @@ export declare const MEETING_RESULT_ENTITIES: {
51
51
  readonly person_uid: v.StringSchema<undefined>;
52
52
  readonly previous_person_uid: v.NullableSchema<v.StringSchema<undefined>, undefined>;
53
53
  readonly changed: v.BooleanSchema<undefined>;
54
+ readonly proposal: v.OptionalSchema<v.StringSchema<undefined>, undefined>;
54
55
  }, undefined>], undefined>, undefined>;
55
56
  }, undefined>;
56
57
  readonly meeting_transcription: v.UnionSchema<[v.StrictObjectSchema<{
@@ -41,6 +41,7 @@ const personResult = v.strictObject({
41
41
  person_uid: text,
42
42
  previous_person_uid: nullableText,
43
43
  changed: flag,
44
+ proposal: v.optional(text),
44
45
  });
45
46
  const meetingChange = v.strictObject({
46
47
  scope,
@@ -36,14 +36,25 @@ export const modelGateway = (deps) => ({
36
36
  throw new CliError("cancelled", "model request cancelled");
37
37
  const fetcher = deps.fetch ?? fetch;
38
38
  let limited = false;
39
+ let unreachable = false;
40
+ let refused = false;
39
41
  const cancellable = async (input, init) => {
40
42
  const signal = init?.signal ?? (input instanceof Request ? input.signal : undefined);
41
- const response = await fetcher(input, {
42
- ...init,
43
- signal: deps.signal ? AbortSignal.any([deps.signal, ...(signal ? [signal] : [])]) : signal,
44
- });
43
+ let response;
44
+ try {
45
+ response = await fetcher(input, {
46
+ ...init,
47
+ signal: deps.signal ? AbortSignal.any([deps.signal, ...(signal ? [signal] : [])]) : signal,
48
+ });
49
+ }
50
+ catch (error) {
51
+ unreachable = true;
52
+ throw error;
53
+ }
45
54
  if (response.status === 429)
46
55
  limited = true;
56
+ if (response.status === 401 || response.status === 403)
57
+ refused = true;
47
58
  return response;
48
59
  };
49
60
  try {
@@ -57,7 +68,13 @@ export const modelGateway = (deps) => ({
57
68
  catch {
58
69
  if (limited)
59
70
  throw new CliError("rate_limited", `${request.purpose} provider rate limit reached; no result was stored`);
60
- throw new CliError("invalid_response", `${request.purpose} provider failed or returned an incomplete response; no result was stored`);
71
+ // The message stays one for every failure; the reason tells a refused key and a network failure apart.
72
+ const reason = refused
73
+ ? "model.key-rejected"
74
+ : unreachable && !deps.signal?.aborted
75
+ ? "model.unreachable"
76
+ : undefined;
77
+ throw new CliError("invalid_response", `${request.purpose} provider failed or returned an incomplete response; no result was stored`, reason === undefined ? undefined : { reason });
61
78
  }
62
79
  },
63
80
  });
@@ -63,7 +63,17 @@ export interface CacheEvent {
63
63
  /** How old the kept answer was. */
64
64
  ageMs?: number;
65
65
  }
66
- export type DiagnosticEvent = RequestEvent | CacheEvent | WarningEvent;
66
+ /** Rows one committed write transaction changed in one table: a count, never a row. */
67
+ export interface StoreEvent {
68
+ event: "store";
69
+ /** Always `store.write`; typed wide so an object spread into a request event still narrows by `event`. */
70
+ operation: string;
71
+ kind: "store";
72
+ table: string;
73
+ op: "insert" | "update" | "delete";
74
+ n: number;
75
+ }
76
+ export type DiagnosticEvent = RequestEvent | CacheEvent | WarningEvent | StoreEvent;
67
77
  export type EventSink = (event: DiagnosticEvent) => void;
68
78
  /** A sentence for a person, and the warning event it stands for when there is one: a log record keeps only the event. */
69
79
  export type Warn = (message: string, warning?: WarningEvent) => void;
@@ -9,6 +9,8 @@ export const providerErrorKey = (value) => typeof value === "string" && /^[A-Za-
9
9
  * ```
10
10
  */
11
11
  export const renderEvent = (event) => {
12
+ if (event.event === "store")
13
+ return `${MARK.store} ${event.operation.padEnd(16)} ${event.table} ${event.op} ${event.n}`;
12
14
  if (event.event === "warning") {
13
15
  const counts = Object.entries(event.counts ?? {}).map(([field, count]) => `${count} ${field}`);
14
16
  return [`${MARK.warning} ${(event.operation ?? "").padEnd(16)} ${event.code}`, ...counts, event.detail]
@@ -53,6 +55,6 @@ export const renderEvent = (event) => {
53
55
  }
54
56
  return `${MARK[event.event]} ${event.operation.padEnd(16)} ${parts.join(" ")}`.trimEnd();
55
57
  };
56
- const MARK = { request: "→", response: "←", cache: "•", warning: "!" };
58
+ const MARK = { request: "→", response: "←", cache: "•", warning: "!", store: "+" };
57
59
  const age = (ms) => (ms < 1000 ? `${ms}ms` : `${Math.round(ms / 1000)}s`);
58
60
  const size = (bytes) => (bytes < 1000 ? `${bytes} B` : `${(bytes / 1000).toFixed(1)} kB`);
@@ -24,6 +24,10 @@ const diagnostic = {
24
24
  detail: true,
25
25
  reason: true,
26
26
  ageMs: true,
27
+ kind: true,
28
+ table: true,
29
+ op: true,
30
+ n: true,
27
31
  };
28
32
  const send = {
29
33
  profile: true,
@@ -9,6 +9,7 @@ export const CORE_LOG_EVENTS = defineLogEvents([
9
9
  meaning: "a read was answered from what was kept, without asking the messenger",
10
10
  keys: ["operation", "reason"],
11
11
  },
12
+ { id: "store.write", meaning: "a committed write changed rows of one store table", keys: ["table", "op", "n"] },
12
13
  { id: "command.crashed", meaning: "a command failed on a bug; where, never what", keys: ["error_class", "frames"] },
13
14
  {
14
15
  id: "events.dropped",
@@ -32,4 +33,5 @@ export const DIAGNOSTIC_LOG_EVENTS = {
32
33
  response: "provider.response",
33
34
  warning: "client.warning",
34
35
  cache: "cache.answered",
36
+ store: "store.write",
35
37
  };
@@ -19,6 +19,7 @@ export interface RecordingOptions {
19
19
  runsDir?: string;
20
20
  keepDays?: number;
21
21
  keepSuccessDays?: number;
22
+ keepStoreDays?: number;
22
23
  maxBytes?: number;
23
24
  now?: () => Date;
24
25
  /** The caller's trace; otherwise the enclosing run's, otherwise `TRACEPARENT` from `env`. */
@@ -56,6 +57,8 @@ export declare const wasSettled: (error: unknown) => boolean;
56
57
  /** A run of a loop that never ends must not fill the disk: past these, events are counted by operation instead. */
57
58
  export declare const EVENTS_AT_MOST = 2000;
58
59
  export declare const EVENT_BYTES_AT_MOST: number;
60
+ /** Past this many, store events are summed by table and change and written as one each when the run ends. */
61
+ export declare const STORE_EVENTS_AT_MOST = 100;
59
62
  /**
60
63
  * Where a crash happened, not what it said: the class and up to ten frames as `function file:line`,
61
64
  * paths cut to the package's own (`framesOf`). **Never `message`** in an event — it can hold whatever the
@@ -3,7 +3,7 @@ import { isCliFailure, storeDamaged } from "../errors/failures.js";
3
3
  import { markStoreDamaged } from "../store/marks.js";
4
4
  import { storePath } from "../store/path.js";
5
5
  import { endpointTemplate, errorDetailOf, framesOf } from "./error-detail.js";
6
- import { providerErrorKey, renderEvent } from "./events.js";
6
+ import { providerErrorKey, renderEvent, } from "./events.js";
7
7
  import { DIAGNOSTIC_LOG_EVENTS } from "./log-events.js";
8
8
  import { logAttributes } from "./log-keys.js";
9
9
  import { newRunId, runsDirFor, startRun } from "./run.js";
@@ -62,6 +62,7 @@ export const startRecording = (options) => {
62
62
  },
63
63
  ...(options.keepDays === undefined ? {} : { keepDays: options.keepDays }),
64
64
  ...(options.keepSuccessDays === undefined ? {} : { keepSuccessDays: options.keepSuccessDays }),
65
+ ...(options.keepStoreDays === undefined ? {} : { keepStoreDays: options.keepStoreDays }),
65
66
  ...(options.maxBytes === undefined ? {} : { maxBytes: options.maxBytes }),
66
67
  now,
67
68
  ...extra,
@@ -71,6 +72,7 @@ export const startRecording = (options) => {
71
72
  const held = !run && options.keepFailed ? [] : undefined;
72
73
  const counted = { wire: 0, operation: 0 };
73
74
  let refused;
75
+ let wroteStore = false;
74
76
  const cap = capped();
75
77
  const requests = () => (counted.wire > 0 ? counted.wire : counted.operation);
76
78
  const events = (event) => {
@@ -78,6 +80,8 @@ export const startRecording = (options) => {
78
80
  counted[event.level === "wire" ? "wire" : "operation"] += 1;
79
81
  if (event.event === "response" && event.outcome === "error")
80
82
  refused = event;
83
+ if (event.event === "store")
84
+ wroteStore = true;
81
85
  if (options.trace)
82
86
  streams.diagnostic(options.format === "pretty" ? renderEvent(event) : JSON.stringify(logAttributes(event)));
83
87
  if (run)
@@ -99,13 +103,14 @@ export const startRecording = (options) => {
99
103
  events,
100
104
  succeed: async (answer) => {
101
105
  const partial = partialOutcome(answer);
102
- const kept = run ?? (partial && held ? keep(open({ startedAt })) : undefined);
106
+ const kept = run ?? ((partial || wroteStore) && held ? keep(open({ startedAt })) : undefined);
103
107
  if (kept)
104
108
  cap.close(kept);
105
109
  await kept?.finish(partial ? "partial" : "success", {
106
110
  requests: requests(),
107
111
  ...cap.dropped(),
108
112
  ...(partial ? { partial } : {}),
113
+ ...(!run && !partial && wroteStore ? { keptBecauseStore: true } : {}),
109
114
  });
110
115
  },
111
116
  fail: async (thrown) => {
@@ -142,26 +147,45 @@ const HELD_AT_MOST = 500;
142
147
  /** A run of a loop that never ends must not fill the disk: past these, events are counted by operation instead. */
143
148
  export const EVENTS_AT_MOST = 2000;
144
149
  export const EVENT_BYTES_AT_MOST = 1024 * 1024;
150
+ /** Past this many, store events are summed by table and change and written as one each when the run ends. */
151
+ export const STORE_EVENTS_AT_MOST = 100;
145
152
  const capped = () => {
146
153
  let lines = 0;
147
154
  let bytes = 0;
148
155
  let dropped = 0;
156
+ let stores = 0;
149
157
  const byOperation = {};
158
+ const summed = new Map();
159
+ const write = (run, event) => {
160
+ // The record's own envelope (time, ids of the run, resource) is about 200 bytes on top of its attributes.
161
+ const size = JSON.stringify(logAttributes(event)).length + 200;
162
+ if (lines >= EVENTS_AT_MOST || bytes + size > EVENT_BYTES_AT_MOST) {
163
+ dropped += 1;
164
+ const operation = "operation" in event && event.operation ? event.operation : event.event;
165
+ byOperation[operation] = (byOperation[operation] ?? 0) + 1;
166
+ return;
167
+ }
168
+ lines += 1;
169
+ bytes += size;
170
+ logEvent(run, event);
171
+ };
150
172
  return {
151
173
  log: (run, event) => {
152
- // The record's own envelope (time, ids of the run, resource) is about 200 bytes on top of its attributes.
153
- const size = JSON.stringify(logAttributes(event)).length + 200;
154
- if (lines >= EVENTS_AT_MOST || bytes + size > EVENT_BYTES_AT_MOST) {
155
- dropped += 1;
156
- const operation = "operation" in event && event.operation ? event.operation : event.event;
157
- byOperation[operation] = (byOperation[operation] ?? 0) + 1;
174
+ if (event.event === "store" && ++stores > STORE_EVENTS_AT_MOST) {
175
+ const key = `${event.table} ${event.op}`;
176
+ const sum = summed.get(key);
177
+ if (sum)
178
+ sum.n += event.n;
179
+ else
180
+ summed.set(key, { ...event });
158
181
  return;
159
182
  }
160
- lines += 1;
161
- bytes += size;
162
- logEvent(run, event);
183
+ write(run, event);
163
184
  },
164
185
  close: (run) => {
186
+ for (const sum of summed.values())
187
+ write(run, sum);
188
+ summed.clear();
165
189
  if (dropped > 0)
166
190
  run.logger.warn({ event: "events.dropped", dropped, counts: byOperation });
167
191
  },
@@ -178,7 +202,7 @@ const logEvent = (run, event) => {
178
202
  };
179
203
  if (event.event === "warning")
180
204
  run.logger.warn(record);
181
- else if (event.event !== "cache" && event.outcome === "error")
205
+ else if ((event.event === "request" || event.event === "response") && event.outcome === "error")
182
206
  run.logger.error(record);
183
207
  else
184
208
  run.logger.info(record);
@@ -43,10 +43,14 @@ export interface RunMetadata {
43
43
  providerError?: string;
44
44
  /** Written only because it failed: recording was not asked for. */
45
45
  keptBecauseFailed?: boolean;
46
+ /** Written only because it wrote the store, so its counts say what to fetch again after a damage. */
47
+ keptBecauseStore?: boolean;
46
48
  /** Every operation its events named, so a search by operation need not open them. */
47
49
  operations?: string[];
48
50
  /** Every `errorCode` and warning `code` its events carried, for the same reason. */
49
51
  codes?: string[];
52
+ /** Every table its store events wrote, for the same reason. */
53
+ tables?: string[];
50
54
  /** The caller's trace: the MCP client's, or the schedule's or job's that started it. */
51
55
  traceId?: string;
52
56
  /** The whole command with the program's name, `max messages list`; `command` stays the run's short name. */
@@ -77,6 +81,8 @@ export interface StartRunOptions {
77
81
  keepDays?: number;
78
82
  /** Successful runs older than this are removed sooner than the failures `keepDays` keeps. */
79
83
  keepSuccessDays?: number;
84
+ /** A successful run that wrote the store is kept this long, whatever `keepSuccessDays` says. */
85
+ keepStoreDays?: number;
80
86
  /** The runs folder's size limit in bytes: past it, the oldest successful runs go first, then the oldest days. */
81
87
  maxBytes?: number;
82
88
  /**
@@ -106,6 +112,7 @@ export interface Run {
106
112
  }
107
113
  export declare const KEEP_RUNS_FOR_DAYS = 30;
108
114
  export declare const KEEP_SUCCESSFUL_RUNS_FOR_DAYS = 7;
115
+ export declare const KEEP_STORE_RUNS_FOR_DAYS = 3;
109
116
  export declare const RUNS_SIZE_LIMIT_MB = 200;
110
117
  /** `<state dir>/runs` — never the cache directory: a cache is deleted to fix a cache, and a run cannot be rebuilt. */
111
118
  export declare const runsDirFor: (app: AppIdentity, env?: NodeJS.ProcessEnv) => string;
@@ -161,15 +168,17 @@ export declare const findRun: (runsDir: string, id: string) => {
161
168
  export declare const readEvents: (dir: string) => Record<string, unknown>[];
162
169
  /**
163
170
  * Removes every day older than `keepDays`, then the successful runs of every day older than `keepSuccessDays`, and
164
- * answers how many days went. Then, once a day, the folder is measured against `maxBytes`: successful runs go first,
165
- * oldest day first, then whole days, until it fits.
171
+ * answers how many days went. A success that wrote the store is kept for `keepStoreDays` instead when that is longer,
172
+ * and one kept only because it wrote the store goes after `keepStoreDays`. Then, once a day, the folder is measured
173
+ * against `maxBytes`: successful runs go first, oldest day first, then whole days, until it fits.
166
174
  *
167
175
  * A day at a time, by the directory name and the day's index, so no run has to be opened to decide — and a directory
168
176
  * that is not a date is left alone rather than guessed at.
169
177
  */
170
- export declare const pruneRuns: (runsDir: string, { keepDays, keepSuccessDays, maxBytes, now, }: {
178
+ export declare const pruneRuns: (runsDir: string, { keepDays, keepSuccessDays, keepStoreDays, maxBytes, now, }: {
171
179
  keepDays: number;
172
180
  keepSuccessDays?: number;
181
+ keepStoreDays?: number;
173
182
  maxBytes?: number;
174
183
  now: Date;
175
184
  }) => number;