@wirecat/cli-core 0.605.0 → 0.607.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 (260) hide show
  1. package/CHANGELOG.md +284 -1
  2. package/dist/calendar/index.d.ts +1 -0
  3. package/dist/calendar/index.js +1 -0
  4. package/dist/calendar/reads.js +5 -0
  5. package/dist/cli/app-mcp-command.d.ts +6 -2
  6. package/dist/cli/app-mcp-command.js +11 -2
  7. package/dist/cli/csv.d.ts +10 -0
  8. package/dist/cli/csv.js +22 -0
  9. package/dist/cli/early-refusal.d.ts +10 -0
  10. package/dist/cli/early-refusal.js +19 -0
  11. package/dist/cli/index.d.ts +4 -1
  12. package/dist/cli/index.js +4 -0
  13. package/dist/cli/profile-token.d.ts +29 -0
  14. package/dist/cli/profile-token.js +65 -0
  15. package/dist/cli/program.js +4 -2
  16. package/dist/cli/store-settings.js +38 -4
  17. package/dist/crm/cli/csv.d.ts +23 -0
  18. package/dist/crm/cli/csv.js +135 -0
  19. package/dist/crm/cli/index.d.ts +1 -1
  20. package/dist/crm/cli/index.js +36 -22
  21. package/dist/crm/cli/pipeline-view.d.ts +3 -0
  22. package/dist/crm/cli/pipeline-view.js +36 -0
  23. package/dist/crm/index.d.ts +2 -2
  24. package/dist/crm/index.js +1 -1
  25. package/dist/crm/source.d.ts +35 -5
  26. package/dist/crm/sync.d.ts +15 -7
  27. package/dist/crm/sync.js +169 -11
  28. package/dist/crm/writes.d.ts +6 -4
  29. package/dist/crm/writes.js +17 -13
  30. package/dist/documents.d.ts +2 -0
  31. package/dist/documents.js +2 -0
  32. package/dist/domain/business.d.ts +79 -0
  33. package/dist/domain/business.js +42 -0
  34. package/dist/domain/crm.d.ts +41 -2
  35. package/dist/domain/deals.d.ts +5 -2
  36. package/dist/domain/deals.js +5 -2
  37. package/dist/domain/finance.d.ts +2 -0
  38. package/dist/domain/finance.js +2 -2
  39. package/dist/domain/google-documents.d.ts +2 -0
  40. package/dist/domain/google-documents.js +3 -1
  41. package/dist/domain/money.d.ts +2 -0
  42. package/dist/domain/money.js +11 -3
  43. package/dist/domain/providers.d.ts +36 -1
  44. package/dist/domain/providers.js +69 -7
  45. package/dist/domain/record-fields.d.ts +42 -0
  46. package/dist/domain/record-fields.js +122 -0
  47. package/dist/domain/record-types.d.ts +489 -16
  48. package/dist/domain/record-types.js +374 -7
  49. package/dist/domain/records.d.ts +96 -5
  50. package/dist/domain/records.js +178 -32
  51. package/dist/domain/ref-summaries.js +5 -0
  52. package/dist/domain/references.d.ts +1 -1
  53. package/dist/domain/references.js +5 -0
  54. package/dist/domain/relations.d.ts +125 -0
  55. package/dist/domain/relations.js +107 -0
  56. package/dist/domain/vcard.d.ts +25 -0
  57. package/dist/domain/vcard.js +267 -0
  58. package/dist/entities/deal.d.ts +16 -2
  59. package/dist/entities/deal.js +5 -1
  60. package/dist/entities/index.d.ts +29 -13
  61. package/dist/entities/relationship.d.ts +8 -2
  62. package/dist/entities/relationship.js +8 -2
  63. package/dist/entities/task-results.d.ts +10 -10
  64. package/dist/errors/reasons.js +73 -2
  65. package/dist/fetch/addresses.d.ts +5 -0
  66. package/dist/fetch/addresses.js +76 -0
  67. package/dist/fetch/page.d.ts +64 -0
  68. package/dist/fetch/page.js +256 -0
  69. package/dist/index.d.ts +7 -4
  70. package/dist/index.js +6 -3
  71. package/dist/mail/cli/review.js +20 -6
  72. package/dist/mail/index.d.ts +1 -1
  73. package/dist/mail/marks.d.ts +10 -5
  74. package/dist/mail/marks.js +16 -8
  75. package/dist/mail/review.d.ts +5 -0
  76. package/dist/meetings/calendar-text.d.ts +1 -1
  77. package/dist/meetings/calendar-text.js +4 -0
  78. package/dist/meetings/event-store.d.ts +2 -2
  79. package/dist/search/account-list.d.ts +4 -0
  80. package/dist/search/account-list.js +19 -8
  81. package/dist/search/query.js +2 -2
  82. package/dist/services/events-search.js +2 -2
  83. package/dist/services/index.d.ts +1 -1
  84. package/dist/services/index.js +1 -1
  85. package/dist/services/ingest.d.ts +56 -8
  86. package/dist/services/ingest.js +95 -61
  87. package/dist/services/link-scorers/scan.js +2 -1
  88. package/dist/services/link-scorers/shared.js +2 -1
  89. package/dist/services/messages-search.js +3 -2
  90. package/dist/services/metadata.d.ts +1 -1
  91. package/dist/services/notes-search.js +1 -0
  92. package/dist/services/project-status/index.js +2 -1
  93. package/dist/services/proposals/kinds/contracts.d.ts +4 -0
  94. package/dist/services/proposals/kinds/contracts.js +9 -0
  95. package/dist/services/proposals/kinds/finance.d.ts +4 -0
  96. package/dist/services/proposals/kinds/finance.js +14 -35
  97. package/dist/services/proposals/kinds/orders.js +7 -30
  98. package/dist/services/proposals/kinds/shared.d.ts +27 -1
  99. package/dist/services/proposals/kinds/shared.js +34 -0
  100. package/dist/services/proposals/kinds/source-review.d.ts +4 -0
  101. package/dist/services/proposals/kinds/source-review.js +45 -0
  102. package/dist/services/proposals/kinds/subscriptions.d.ts +9 -0
  103. package/dist/services/proposals/kinds/subscriptions.js +24 -0
  104. package/dist/services/proposals/kinds/transactions.d.ts +4 -0
  105. package/dist/services/proposals/kinds/transactions.js +10 -0
  106. package/dist/services/proposals/registry.js +9 -0
  107. package/dist/services/search-all-meetings.js +2 -2
  108. package/dist/services/search-all.js +4 -3
  109. package/dist/services/search-kind.js +3 -3
  110. package/dist/services/stored-project-gathering.js +4 -3
  111. package/dist/store/decisions.js +5 -1
  112. package/dist/store/exports.d.ts +1 -0
  113. package/dist/store/exports.js +1 -0
  114. package/dist/store/index.d.ts +20 -4
  115. package/dist/store/index.js +4 -0
  116. package/dist/store/people.js +1 -1
  117. package/dist/store/project-transfer/request.d.ts +4 -1
  118. package/dist/store/project-transfer/schema.d.ts +9 -2
  119. package/dist/store/project-transfer/schema.js +4 -0
  120. package/dist/store/project-transfer/snapshot-model.d.ts +8 -2
  121. package/dist/store/source-review.d.ts +64 -0
  122. package/dist/store/source-review.js +7 -0
  123. package/dist/store/sqlite/accounts.d.ts +1 -1
  124. package/dist/store/sqlite/accounts.js +24 -1
  125. package/dist/store/sqlite/added-sources.d.ts +82 -0
  126. package/dist/store/sqlite/added-sources.js +237 -0
  127. package/dist/store/sqlite/business-contracts.d.ts +90 -0
  128. package/dist/store/sqlite/business-contracts.js +182 -0
  129. package/dist/store/sqlite/calendar-events.js +7 -3
  130. package/dist/store/sqlite/calendar-forget.js +3 -0
  131. package/dist/store/sqlite/calendar.d.ts +21 -1
  132. package/dist/store/sqlite/calendar.js +27 -7
  133. package/dist/store/sqlite/chat-rekey.js +7 -0
  134. package/dist/store/sqlite/chats.d.ts +3 -1
  135. package/dist/store/sqlite/chats.js +15 -1
  136. package/dist/store/sqlite/crm-rows.d.ts +44 -0
  137. package/dist/store/sqlite/crm-rows.js +195 -0
  138. package/dist/store/sqlite/crm-settings.d.ts +28 -0
  139. package/dist/store/sqlite/crm-settings.js +80 -0
  140. package/dist/store/sqlite/crm.d.ts +42 -11
  141. package/dist/store/sqlite/crm.js +402 -196
  142. package/dist/store/sqlite/deals.d.ts +4 -8
  143. package/dist/store/sqlite/deals.js +8 -5
  144. package/dist/store/sqlite/document-transfer/snapshot.js +2 -2
  145. package/dist/store/sqlite/emails.js +2 -0
  146. package/dist/store/sqlite/entity-types.d.ts +14 -9
  147. package/dist/store/sqlite/entity-types.js +4 -10
  148. package/dist/store/sqlite/evidence-signature.d.ts +114 -0
  149. package/dist/store/sqlite/evidence-signature.js +349 -0
  150. package/dist/store/sqlite/evidence-sources.d.ts +2 -1
  151. package/dist/store/sqlite/evidence-sources.js +7 -3
  152. package/dist/store/sqlite/facts.d.ts +7 -2
  153. package/dist/store/sqlite/facts.js +21 -5
  154. package/dist/store/sqlite/finance.d.ts +18 -105
  155. package/dist/store/sqlite/finance.js +100 -219
  156. package/dist/store/sqlite/involvement-queue.js +4 -3
  157. package/dist/store/sqlite/knowledge.d.ts +14 -4
  158. package/dist/store/sqlite/knowledge.js +108 -102
  159. package/dist/store/sqlite/labelled.d.ts +3 -0
  160. package/dist/store/sqlite/labelled.js +11 -0
  161. package/dist/store/sqlite/link-kinds.d.ts +4 -3
  162. package/dist/store/sqlite/link-kinds.js +6 -2
  163. package/dist/store/sqlite/manifest.js +7 -0
  164. package/dist/store/sqlite/memories.d.ts +24 -10
  165. package/dist/store/sqlite/memories.js +73 -19
  166. package/dist/store/sqlite/messages.js +2 -0
  167. package/dist/store/sqlite/migrations.generated.js +134 -0
  168. package/dist/store/sqlite/money-lines.d.ts +48 -0
  169. package/dist/store/sqlite/money-lines.js +76 -0
  170. package/dist/store/sqlite/money-transactions.d.ts +132 -0
  171. package/dist/store/sqlite/money-transactions.js +295 -0
  172. package/dist/store/sqlite/notes.d.ts +14 -4
  173. package/dist/store/sqlite/notes.js +43 -31
  174. package/dist/store/sqlite/orders.d.ts +36 -6
  175. package/dist/store/sqlite/orders.js +126 -46
  176. package/dist/store/sqlite/organizations.d.ts +8 -0
  177. package/dist/store/sqlite/organizations.js +14 -0
  178. package/dist/store/sqlite/payment-facts.js +1 -1
  179. package/dist/store/sqlite/person-preparation.d.ts +1 -1
  180. package/dist/store/sqlite/person-preparation.js +3 -2
  181. package/dist/store/sqlite/private-people.js +2 -0
  182. package/dist/store/sqlite/products.d.ts +78 -0
  183. package/dist/store/sqlite/products.js +131 -0
  184. package/dist/store/sqlite/project-transfer/records.js +39 -3
  185. package/dist/store/sqlite/project-transfer/snapshot.d.ts +4 -1
  186. package/dist/store/sqlite/project-transfer/snapshot.js +11 -3
  187. package/dist/store/sqlite/proposed-actions.d.ts +1 -1
  188. package/dist/store/sqlite/proposed-actions.js +24 -7
  189. package/dist/store/sqlite/providers.d.ts +0 -4
  190. package/dist/store/sqlite/providers.js +20 -2
  191. package/dist/store/sqlite/record-matching.d.ts +80 -0
  192. package/dist/store/sqlite/record-matching.js +264 -0
  193. package/dist/store/sqlite/record-projection.d.ts +89 -0
  194. package/dist/store/sqlite/record-projection.js +50 -0
  195. package/dist/store/sqlite/record-projectors-direct.d.ts +17 -0
  196. package/dist/store/sqlite/record-projectors-direct.js +125 -0
  197. package/dist/store/sqlite/record-projectors-money.d.ts +26 -0
  198. package/dist/store/sqlite/record-projectors-money.js +214 -0
  199. package/dist/store/sqlite/record-projectors-phone.d.ts +28 -0
  200. package/dist/store/sqlite/record-projectors-phone.js +212 -0
  201. package/dist/store/sqlite/record-projectors.d.ts +3 -44
  202. package/dist/store/sqlite/record-projectors.js +7 -67
  203. package/dist/store/sqlite/record-relations.d.ts +24 -0
  204. package/dist/store/sqlite/record-relations.js +92 -0
  205. package/dist/store/sqlite/record-remap.d.ts +12 -0
  206. package/dist/store/sqlite/record-remap.js +92 -0
  207. package/dist/store/sqlite/record-run.d.ts +71 -0
  208. package/dist/store/sqlite/record-run.js +179 -0
  209. package/dist/store/sqlite/record-settling.d.ts +9 -0
  210. package/dist/store/sqlite/record-settling.js +74 -0
  211. package/dist/store/sqlite/record-stamps.d.ts +13 -0
  212. package/dist/store/sqlite/record-stamps.js +30 -0
  213. package/dist/store/sqlite/record-writes.d.ts +43 -0
  214. package/dist/store/sqlite/record-writes.js +307 -0
  215. package/dist/store/sqlite/records.d.ts +52 -42
  216. package/dist/store/sqlite/records.js +123 -353
  217. package/dist/store/sqlite/ref-summaries.d.ts +6 -5
  218. package/dist/store/sqlite/ref-summaries.js +60 -8
  219. package/dist/store/sqlite/refunds.d.ts +31 -0
  220. package/dist/store/sqlite/refunds.js +112 -0
  221. package/dist/store/sqlite/relation-list.d.ts +43 -0
  222. package/dist/store/sqlite/relation-list.js +133 -0
  223. package/dist/store/sqlite/relation-proposals.d.ts +28 -6
  224. package/dist/store/sqlite/relation-proposals.js +134 -10
  225. package/dist/store/sqlite/relation-reads.d.ts +8 -0
  226. package/dist/store/sqlite/relation-reads.js +7 -0
  227. package/dist/store/sqlite/relation-roles.d.ts +26 -0
  228. package/dist/store/sqlite/relation-roles.js +91 -0
  229. package/dist/store/sqlite/reported-relations.d.ts +63 -0
  230. package/dist/store/sqlite/reported-relations.js +132 -0
  231. package/dist/store/sqlite/reviewed.d.ts +109 -0
  232. package/dist/store/sqlite/reviewed.js +173 -0
  233. package/dist/store/sqlite/schema/link-revisions.d.ts +136 -0
  234. package/dist/store/sqlite/schema/link-revisions.js +11 -0
  235. package/dist/store/sqlite/schema/links.d.ts +360 -0
  236. package/dist/store/sqlite/schema/links.js +32 -0
  237. package/dist/store/sqlite/schema.d.ts +2769 -306
  238. package/dist/store/sqlite/schema.js +258 -25
  239. package/dist/store/sqlite/source-review-marks.d.ts +54 -0
  240. package/dist/store/sqlite/source-review-marks.js +143 -0
  241. package/dist/store/sqlite/source-review.d.ts +54 -0
  242. package/dist/store/sqlite/source-review.js +221 -0
  243. package/dist/store/sqlite/stage-amounts.d.ts +14 -0
  244. package/dist/store/sqlite/stage-amounts.js +23 -0
  245. package/dist/store/sqlite/subscriptions.d.ts +135 -0
  246. package/dist/store/sqlite/subscriptions.js +294 -0
  247. package/dist/store/sqlite/text-input.d.ts +3 -0
  248. package/dist/store/sqlite/text-input.js +13 -0
  249. package/dist/store/sqlite/things.js +2 -9
  250. package/dist/store/sqlite/transaction.d.ts +15 -0
  251. package/dist/store/sqlite/transaction.js +57 -0
  252. package/dist/store/sqlite/wallets.d.ts +88 -0
  253. package/dist/store/sqlite/wallets.js +143 -0
  254. package/dist/store/store-errors.d.ts +1 -0
  255. package/dist/store/store-errors.js +45 -0
  256. package/dist/store/store.d.ts +19 -1
  257. package/dist/store/store.js +35 -6
  258. package/package.json +6 -3
  259. package/schemas/examples/records-business.jsonl +11 -0
  260. package/schemas/records-envelope.v1.schema.json +1160 -5
@@ -1,6 +1,7 @@
1
1
  import { type QueryAst } from "@wirecat/cli-base/query";
2
2
  import { type Decider } from "../decisions.js";
3
3
  import type { AccountKey } from "../types.js";
4
+ import { type LabelledType } from "./labelled.js";
4
5
  import { type MeetingProjectsStore } from "./meeting-projects.js";
5
6
  import type { Author } from "./memories.js";
6
7
  import { type Link } from "./notes.js";
@@ -8,6 +9,8 @@ import type { StoreContext } from "./open.js";
8
9
  import { type OrganizationsStore } from "./organizations.js";
9
10
  import type { ProposedAction } from "./proposed-actions.js";
10
11
  import { type KnowledgeRelation, type LinkDecision, type RelateInput, type RelationUpdate, type Scored } from "./relation-proposals.js";
12
+ import { type RelationReads } from "./relation-reads.js";
13
+ import { type SourceReviewStore } from "./source-review.js";
11
14
  import type { TagCreationOptions } from "./tag-creation.js";
12
15
  import { type Label, type TagKind, type TagRow } from "./tags.js";
13
16
  import { type ThingState } from "./things.js";
@@ -100,8 +103,8 @@ export interface Reminder {
100
103
  revision: number;
101
104
  receipt: string | null;
102
105
  }
103
- export type LabelledType = "note" | "document" | "person" | "organization" | "project" | "task" | "meeting" | "folder";
104
- export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore, OrganizationsStore {
106
+ export type { LabelledType } from "./labelled.js";
107
+ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore, OrganizationsStore, RelationReads, SourceReviewStore {
105
108
  taskIds(key: AccountKey, options?: {
106
109
  state?: "open" | "done" | "dismissed";
107
110
  limit?: number;
@@ -214,6 +217,9 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore, O
214
217
  by: Exclude<Author, "owner">;
215
218
  reason?: string;
216
219
  }): Promise<ProposedAction>;
220
+ /** Ends it at `at` (UTC ms) without removing it; an agent's end is a `relationship_update` proposal. */
221
+ endRelation(key: KnowledgeScope, id: string, at: number, by: "owner"): Promise<KnowledgeRelation>;
222
+ endRelation(key: KnowledgeScope, id: string, at: number, by: Exclude<Author, "owner">): Promise<ProposedAction>;
217
223
  /** Decides a `relationship_update` proposal; a confirmed one changes the relationship in the same transaction. */
218
224
  decideRelationUpdate(id: string, decision: LinkDecision): Promise<{
219
225
  proposal: ProposedAction;
@@ -228,8 +234,8 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore, O
228
234
  decideSuggestedLink(id: string, decision: LinkDecision): Promise<Link | null>;
229
235
  relations(key: KnowledgeScope, reference?: string): Promise<KnowledgeRelation[]>;
230
236
  /**
231
- * Removing an unconfirmed relationship rejects it, so `by` must be allowed to decide it. Removing a link to a
232
- * project, or rejecting any suggestion, leaves a rejected `relationship` proposal so a scan never proposes it again.
237
+ * Removing an unconfirmed relationship rejects it, so `by` must be allowed to decide it. Every removal leaves a
238
+ * rejected `relationship` proposal, so neither a scan nor a source's sync brings the pair back.
233
239
  */
234
240
  removeRelation(key: KnowledgeScope, id: string, by: Decider): Promise<{
235
241
  id: string;
@@ -246,4 +252,8 @@ export interface KnowledgeStore extends VocabularyStore, MeetingProjectsStore, O
246
252
  }): Promise<Reminder[]>;
247
253
  acknowledgeReminder(key: AccountKey, id: string, receipt: string): Promise<Reminder>;
248
254
  }
255
+ type Row = Record<string, unknown>;
249
256
  export declare const knowledgeStoreOver: (context: StoreContext) => KnowledgeStore;
257
+ type ProjectInput = Parameters<KnowledgeStore["addProject"]>[0];
258
+ /** A new project row, its key made from the name when none is given; inside the caller's write. */
259
+ export declare const insertProject: ({ database, now }: StoreContext, { name, key, type, organization, scope, description }: ProjectInput) => Row;
@@ -1,7 +1,9 @@
1
1
  import { CliError } from "@wirecat/cli-base";
2
2
  import { walkQuery } from "@wirecat/cli-base/query";
3
3
  import { parseLocator } from "../../domain/locator.js";
4
+ import { isBusinessType } from "../../domain/record-types.js";
4
5
  import { formatReference, parseReference } from "../../domain/references.js";
6
+ import { checkEnds, isSymmetric, notOverriddenSql } from "../../domain/relations.js";
5
7
  import { normalizeTag } from "../../domain/tags.js";
6
8
  import { normalizeVocabularyName } from "../../domain/vocabulary.js";
7
9
  import { formatMeetingReference } from "../../meetings/index.js";
@@ -10,13 +12,17 @@ import { assertMayDecide } from "../decisions.js";
10
12
  import { fold } from "../normalize.js";
11
13
  import { ulid } from "../ulid.js";
12
14
  import { ownerPerson } from "./actors.js";
15
+ import { forgetEvidenceToRow } from "./evidence-signature.js";
16
+ import { LABELLED } from "./labelled.js";
13
17
  import { linkKind, RELATION_KINDS } from "./link-kinds.js";
14
18
  import { meetingProjectsStoreOver } from "./meeting-projects.js";
15
19
  import { holdingText } from "./note-index.js";
16
20
  import { insertLink, linkOf } from "./notes.js";
17
21
  import { organizationOf, organizationsStoreOver } from "./organizations.js";
18
22
  import { queryFilter } from "./query-filter.js";
19
- import { relationOf, relationProposalsOver, } from "./relation-proposals.js";
23
+ import { relationOf as relationAt, relationProposalsOver, } from "./relation-proposals.js";
24
+ import { checkStoredRole, relationReadsOver } from "./relation-reads.js";
25
+ import { sourceReviewStoreOver } from "./source-review.js";
20
26
  import { addTags as addThingTags, canonicalTagNamed, createTag, labelsOf, liveTagging, removeTags as removeThingTags, setMainTopic, } from "./tags.js";
21
27
  import { INBOX_KEY_LENGTH, TASK_KEY_PREFIXES } from "./task-keys.js";
22
28
  import { inboxKey, taskAccountOf, taskIdOf, taskRowOf } from "./tasks.js";
@@ -54,19 +60,9 @@ const oneOf = (value, allowed, what) => {
54
60
  throw new CliError("validation_error", `${what} is one of ${allowed.join(", ")}`);
55
61
  return value;
56
62
  };
57
- /** What a relationship may connect. */
63
+ /** What a relationship may connect; a deal or a lead only as the end its people hang from. */
58
64
  const RELATED = ["person", "organization", "project", "task"];
59
- /** What a label without an account may sit on; a chat, contact or message is the messenger's tag. */
60
- const LABELLED = {
61
- note: "note",
62
- document: "document",
63
- person: "person",
64
- organization: "organization",
65
- project: "project",
66
- task: "task",
67
- meeting: "meeting",
68
- account: "folder",
69
- };
65
+ const DEALS = ["deal", "lead"];
70
66
  export const knowledgeStoreOver = (context) => {
71
67
  const { database, now } = context;
72
68
  const account = (key) => {
@@ -150,12 +146,7 @@ export const knowledgeStoreOver = (context) => {
150
146
  parsed.type === "bot" ||
151
147
  parsed.type === "event" ||
152
148
  parsed.type === "meeting" ||
153
- parsed.type === "invoice" ||
154
- parsed.type === "payment" ||
155
- parsed.type === "order" ||
156
- parsed.type === "deal" ||
157
- parsed.type === "lead" ||
158
- parsed.type === "pipeline")
149
+ isBusinessType(parsed.type))
159
150
  return undefined;
160
151
  return { type: parsed.type, id: parsed.id };
161
152
  };
@@ -221,6 +212,7 @@ export const knowledgeStoreOver = (context) => {
221
212
  createdAt: iso(row.created_at),
222
213
  });
223
214
  const proposals = relationProposalsOver(context);
215
+ const relationOf = (link) => relationAt(link, now());
224
216
  const RELATIONS = `SELECT * FROM links WHERE kind IN (${RELATION_KINDS.map(linkKind).join(",")}) AND to_id IS NOT NULL`;
225
217
  const relation = (id) => {
226
218
  const row = /^\d+$/.test(id) ? database.prepare(`${RELATIONS} AND id = ?`).get(Number(id)) : undefined;
@@ -228,26 +220,33 @@ export const knowledgeStoreOver = (context) => {
228
220
  throw new CliError("not_found", "no relationship with that id");
229
221
  return row;
230
222
  };
231
- /** The two ends of a relationship, checked, and the link that already joins them. */
223
+ /** The two ends, checked by the registry, in stored order (a symmetric pair's lower id first), and their link. */
232
224
  const pair = (key, input) => {
233
- const from = related(key, input.from, true);
234
- const to = related(key, input.to);
235
- if ((from.type === to.type && from.id === to.id) || !RELATION_KINDS.includes(input.kind))
236
- throw new CliError("validation_error", "a relationship needs distinct references and a supported kind");
237
- if ((from.type === "chat" || from.type === "email_thread") && (input.kind !== "member-of" || to.type !== "project"))
238
- throw new CliError("validation_error", "a chat is related only as member-of a project");
225
+ let from = related(key, input.from, true);
226
+ let to = related(key, input.to);
227
+ if (from.type === to.type && from.id === to.id)
228
+ throw new CliError("validation_error", "a relationship needs two distinct references");
229
+ checkEnds(input.kind, from.type, to.type);
230
+ if (input.role !== undefined)
231
+ checkStoredRole(database, input.kind, from.type, to.type, input.role.trim());
232
+ let ends = { from: input.from, to: input.to };
233
+ if (isSymmetric(input.kind) && to.id < from.id)
234
+ [from, to, ends] = [to, from, { from: input.to, to: input.from }];
235
+ const role = input.role === undefined ? null : input.role.trim();
239
236
  const existing = database
240
- .prepare(`${RELATIONS} AND from_type=? AND from_id=? AND to_type=? AND to_id=? AND kind=?`)
241
- .get(from.type, from.id, to.type, to.id, input.kind);
242
- return { from, to, existing };
237
+ .prepare(`${RELATIONS} AND from_type=? AND from_id=? AND to_type=? AND to_id=? AND kind=? AND account_id IS NULL ` +
238
+ "AND (? IS NULL OR ifnull(role, '') = ?)")
239
+ .get(from.type, from.id, to.type, to.id, input.kind, role, role);
240
+ return { from, to, existing, ends };
243
241
  };
244
242
  /** A chat may only be the member: its reference names its own account, so it is never another account's. */
245
243
  const related = (key, reference, member = false) => {
246
244
  checked(key);
247
245
  const thing = thingOf(database, reference);
248
246
  const chat = member && (thing?.type === "chat" || thing?.type === "email_thread");
249
- if (!thing || !(RELATED.includes(thing.type) || chat) || stateOfThing(database, thing) !== "available")
250
- throw new CliError("not_found", `reference needs a stored person:, organization:, project:${member ? ", task: or chat:" : " or task:"}`);
247
+ const end = thing && (RELATED.includes(thing.type) || chat || (member && DEALS.includes(thing.type)));
248
+ if (!thing || !end || stateOfThing(database, thing) !== "available")
249
+ throw new CliError("not_found", `reference needs a stored person:, organization:, project:${member ? ", task:, deal:, lead: or chat:" : " or task:"}`);
251
250
  if (chat && key !== null) {
252
251
  const parsed = parseReference(reference);
253
252
  if (parsed.provider !== key.provider || parsed.account !== key.account)
@@ -292,6 +291,7 @@ export const knowledgeStoreOver = (context) => {
292
291
  ...vocabularyStoreOver(context),
293
292
  ...organizationsStoreOver(context),
294
293
  ...meetingProjectsStoreOver(context),
294
+ ...relationReadsOver(context),
295
295
  taskIds: async (key, options = {}) => {
296
296
  const { limit, offset } = bounded(options.limit, options.offset);
297
297
  if (options.state !== undefined && !["open", "done", "dismissed"].includes(options.state))
@@ -353,7 +353,10 @@ export const knowledgeStoreOver = (context) => {
353
353
  },
354
354
  removeAnnotation: async (key, id) => {
355
355
  annotation(key, id);
356
- database.prepare("DELETE FROM notes WHERE id=?").run(Number(id));
356
+ write(database, () => {
357
+ forgetEvidenceToRow(database, { type: "note", id: Number(id) }, now());
358
+ database.prepare("DELETE FROM notes WHERE id=?").run(Number(id));
359
+ });
357
360
  return { id, removed: true };
358
361
  },
359
362
  tags: async (key, target, tag) => {
@@ -442,59 +445,7 @@ export const knowledgeStoreOver = (context) => {
442
445
  .get(oneOf(kind, ORGANIZATION_KINDS, "an organization's kind"), textOf(name, 200), oneOf(scope, SCOPES, "a scope"), at, at);
443
446
  return organizationOf(row);
444
447
  },
445
- addProject: async ({ name, key, type = "other", organization, scope = "personal", description }) => write(database, () => {
446
- const title = textOf(name, 200);
447
- const organizationId = organization === undefined
448
- ? null
449
- : (() => {
450
- const thing = thingOf(database, organization);
451
- if (thing?.type !== "organization")
452
- throw new CliError("not_found", `no organization ${organization}`);
453
- return thing.id;
454
- })();
455
- const wanted = key === undefined ? projectKey(title) : key.trim().toUpperCase();
456
- if (!/^[A-Z][A-Z0-9]{2,3}$/.test(wanted))
457
- throw new CliError("validation_error", "a new project key is 3–4 letters and digits, starting with a letter");
458
- const aliasName = (() => {
459
- try {
460
- return normalizeVocabularyName(title);
461
- }
462
- catch {
463
- return null;
464
- }
465
- })();
466
- const alias = database
467
- .prepare("SELECT DISTINCT p.id,p.name FROM aliases a JOIN projects p ON p.id=a.aliasable_id " +
468
- "WHERE a.aliasable_type='project' AND a.account_id IS NULL AND p.account_id IS NULL AND p.deleted_at IS NULL " +
469
- "AND a.name_folded IN (?,?) LIMIT 2")
470
- .all(aliasName, normalizeVocabularyName(wanted));
471
- if (alias.length)
472
- throw new CliError("configuration_error", "the project name or key already aliases an existing project", {
473
- reason: "vocabulary.alias-conflict",
474
- candidates: alias.map((row) => ({ kind: "project", id: String(row.id), name: String(row.name) })),
475
- });
476
- if (key !== undefined && TYPED_KEY_PREFIXES.has(wanted))
477
- throw new CliError("validation_error", `the project key ${wanted} is kept for the keys of tasks found in messages`);
478
- let chosen = wanted;
479
- for (let n = 2; TYPED_KEY_PREFIXES.has(chosen) ||
480
- database.prepare("SELECT 1 FROM projects WHERE key = ?").get(chosen) ||
481
- database
482
- .prepare("SELECT 1 FROM aliases a JOIN projects p ON p.id=a.aliasable_id WHERE a.aliasable_type='project' AND a.account_id IS NULL AND p.account_id IS NULL AND p.deleted_at IS NULL AND a.name_folded=? LIMIT 1")
483
- .get(normalizeVocabularyName(chosen)); n++) {
484
- if (key !== undefined)
485
- throw new CliError("validation_error", `the project key ${wanted} is taken`);
486
- const suffix = String(n);
487
- if (suffix.length > 3)
488
- throw new CliError("validation_error", "no short project key is available; choose an explicit key");
489
- chosen = `${wanted.slice(0, 4 - suffix.length)}${suffix}`;
490
- }
491
- const at = now();
492
- const row = database
493
- .prepare("INSERT INTO projects (key, name, name_folded, description, type, organization_id, scope, tasks_count, status, created_at, updated_at) " +
494
- "VALUES (?, ?, ?, ?, ?, ?, ?, 0, 'active', ?, ?) RETURNING *")
495
- .get(chosen, title, fold(title), description === undefined ? null : textOf(description, 2000), oneOf(type, PROJECT_TYPES, "a project's type"), organizationId, oneOf(scope, SCOPES, "a scope"), at, at);
496
- return projectOf(row);
497
- }),
448
+ addProject: async (input) => write(database, () => projectOf(insertProject(context, input))),
498
449
  projects: async (query) => {
499
450
  const asksKind = query !== undefined && walkQuery(query.root).some((node) => node.field === "kind");
500
451
  const where = query &&
@@ -518,36 +469,26 @@ export const knowledgeStoreOver = (context) => {
518
469
  throw new CliError("validation_error", "a relationship names who writes it: the owner or an agent", {
519
470
  reason: "proposal.decider-required",
520
471
  });
521
- const { from, existing } = pair(key, input);
472
+ const { from, existing, ends } = pair(key, input);
522
473
  if (input.by !== "owner") {
523
474
  if (existing)
524
475
  throw new CliError("validation_error", `relationship ${String(existing.id)} already links them`, {
525
476
  reason: "relationship.exists",
526
477
  });
527
- return proposals.propose(from, { ...input, ...(input.evidence === undefined ? {} : { reason: input.evidence }), evidence: [] }, input.by);
478
+ return proposals.propose(from, { ...input, ...ends, ...(input.evidence === undefined ? {} : { reason: input.evidence }), evidence: [] }, input.by);
528
479
  }
529
480
  if (existing)
530
481
  return relationOf(linkOf(database, existing));
531
482
  const confirmed = input.confirmed !== false;
532
- return relationOf(write(database, () => insertLink(context, {
533
- from: input.from,
534
- to: input.to,
535
- kind: input.kind,
536
- origin: confirmed ? "owner" : "suggested",
537
- confirmed,
538
- ...(input.role === undefined ? {} : { role: input.role }),
539
- ...(input.purpose === undefined ? {} : { purpose: input.purpose }),
540
- ...(input.evidence === undefined ? {} : { evidence: input.evidence }),
541
- ...(input.provenance === undefined ? {} : { provenance: input.provenance }),
542
- })));
483
+ return relationOf(write(database, () => insertLink(context, { ...input, ...ends, by: "owner", origin: confirmed ? "owner" : "suggested", confirmed })));
543
484
  }),
544
485
  proposeRelation: async (key, input, by) => {
545
- const { from, existing } = pair(key, input);
486
+ const { from, existing, ends } = pair(key, input);
546
487
  if (existing)
547
488
  throw new CliError("validation_error", `relationship ${String(existing.id)} already links them`, {
548
489
  reason: "relationship.exists",
549
490
  });
550
- return proposals.propose(from, input, by);
491
+ return proposals.propose(from, { ...input, ...ends }, by);
551
492
  },
552
493
  relationState: async (key, input) => proposals.state(() => pair(key, input), input),
553
494
  updateRelation: (async (key, id, input) => {
@@ -557,11 +498,19 @@ export const knowledgeStoreOver = (context) => {
557
498
  return relationOf(proposals.update(link, input));
558
499
  return proposals.proposeUpdate(link, input, input.by);
559
500
  }),
501
+ endRelation: (async (key, id, at, by) => {
502
+ checked(key);
503
+ const link = linkOf(database, relation(id));
504
+ if (by === "owner")
505
+ return relationOf(proposals.update(link, { endsAt: at }));
506
+ return proposals.proposeUpdate(link, { endsAt: at }, by);
507
+ }),
560
508
  decideRelationUpdate: async (id, decision) => {
561
509
  const { proposal, link } = proposals.decideUpdate(id, decision);
562
510
  return { proposal, relation: link && relationOf(link) };
563
511
  },
564
512
  decideLinkProposal: async (id, decision) => proposals.decideProposal(id, decision),
513
+ ...sourceReviewStoreOver(context),
565
514
  decideSuggestedLink: async (id, decision) => proposals.decideLink(id, decision),
566
515
  relations: async (key, reference) => {
567
516
  checked(key);
@@ -569,7 +518,9 @@ export const knowledgeStoreOver = (context) => {
569
518
  if (reference !== undefined && !thing)
570
519
  return [];
571
520
  return database
572
- .prepare(`${RELATIONS} AND (? IS NULL OR (from_type=? AND from_id=?) OR (to_type=? AND to_id=?)) ORDER BY created_at, id LIMIT 500`)
521
+ .prepare(
522
+ // Live ones first: a long history of withdrawn links never pushes them past the cap.
523
+ `${RELATIONS} AND ${notOverriddenSql("links")} AND (? IS NULL OR (from_type=? AND from_id=?) OR (to_type=? AND to_id=?)) ORDER BY deleted_at IS NOT NULL, created_at, id LIMIT 500`)
573
524
  .all(thing?.type ?? null, thing?.type ?? null, thing?.id ?? null, thing?.type ?? null, thing?.id ?? null)
574
525
  .map((row) => relationOf(linkOf(database, row)));
575
526
  },
@@ -579,8 +530,9 @@ export const knowledgeStoreOver = (context) => {
579
530
  const link = linkOf(database, row);
580
531
  assertMayDecide({ id: `link:${id}`, proposedBy: UNVERIFIED }, by, context.decisions);
581
532
  write(database, () => {
582
- if (!link.confirmed || String(row.to_type) === "project")
533
+ if (link.overrides === undefined)
583
534
  proposals.rejected(link, by);
535
+ database.prepare("UPDATE links SET updated_at = ? WHERE id = ?").run(now(), Number(id));
584
536
  database.prepare("DELETE FROM links WHERE id = ?").run(Number(id));
585
537
  });
586
538
  return { id, removed: true };
@@ -684,6 +636,60 @@ export const knowledgeStoreOver = (context) => {
684
636
  },
685
637
  };
686
638
  };
639
+ /** A new project row, its key made from the name when none is given; inside the caller's write. */
640
+ export const insertProject = ({ database, now }, { name, key, type = "other", organization, scope = "personal", description }) => {
641
+ const title = textOf(name, 200);
642
+ const organizationId = organization === undefined
643
+ ? null
644
+ : (() => {
645
+ const thing = thingOf(database, organization);
646
+ if (thing?.type !== "organization")
647
+ throw new CliError("not_found", `no organization ${organization}`);
648
+ return thing.id;
649
+ })();
650
+ const wanted = key === undefined ? projectKey(title) : key.trim().toUpperCase();
651
+ if (!/^[A-Z][A-Z0-9]{2,3}$/.test(wanted))
652
+ throw new CliError("validation_error", "a new project key is 3–4 letters and digits, starting with a letter");
653
+ const aliasName = (() => {
654
+ try {
655
+ return normalizeVocabularyName(title);
656
+ }
657
+ catch {
658
+ return null;
659
+ }
660
+ })();
661
+ const alias = database
662
+ .prepare("SELECT DISTINCT p.id,p.name FROM aliases a JOIN projects p ON p.id=a.aliasable_id " +
663
+ "WHERE a.aliasable_type='project' AND a.account_id IS NULL AND p.account_id IS NULL AND p.deleted_at IS NULL " +
664
+ "AND a.name_folded IN (?,?) LIMIT 2")
665
+ .all(aliasName, normalizeVocabularyName(wanted));
666
+ if (alias.length)
667
+ throw new CliError("configuration_error", "the project name or key already aliases an existing project", {
668
+ reason: "vocabulary.alias-conflict",
669
+ candidates: alias.map((row) => ({ kind: "project", id: String(row.id), name: String(row.name) })),
670
+ });
671
+ if (key !== undefined && TYPED_KEY_PREFIXES.has(wanted))
672
+ throw new CliError("validation_error", `the project key ${wanted} is kept for the keys of tasks found in messages`);
673
+ let chosen = wanted;
674
+ for (let n = 2; TYPED_KEY_PREFIXES.has(chosen) ||
675
+ database.prepare("SELECT 1 FROM projects WHERE key = ?").get(chosen) ||
676
+ database
677
+ .prepare("SELECT 1 FROM aliases a JOIN projects p ON p.id=a.aliasable_id WHERE a.aliasable_type='project' AND a.account_id IS NULL AND p.account_id IS NULL AND p.deleted_at IS NULL AND a.name_folded=? LIMIT 1")
678
+ .get(normalizeVocabularyName(chosen)); n++) {
679
+ if (key !== undefined)
680
+ throw new CliError("validation_error", `the project key ${wanted} is taken`);
681
+ const suffix = String(n);
682
+ if (suffix.length > 3)
683
+ throw new CliError("validation_error", "no short project key is available; choose an explicit key");
684
+ chosen = `${wanted.slice(0, 4 - suffix.length)}${suffix}`;
685
+ }
686
+ const at = now();
687
+ const row = database
688
+ .prepare("INSERT INTO projects (key, name, name_folded, description, type, organization_id, scope, tasks_count, status, created_at, updated_at) " +
689
+ "VALUES (?, ?, ?, ?, ?, ?, ?, 0, 'active', ?, ?) RETURNING *")
690
+ .get(chosen, title, fold(title), description === undefined ? null : textOf(description, 2000), oneOf(type, PROJECT_TYPES, "a project's type"), organizationId, oneOf(scope, SCOPES, "a scope"), at, at);
691
+ return row;
692
+ };
687
693
  /** Existing project keys stay stable; only new projects receive the short-key convention. */
688
694
  const projectKey = (name) => {
689
695
  const letters = name
@@ -0,0 +1,3 @@
1
+ export type LabelledType = "note" | "document" | "person" | "organization" | "project" | "task" | "meeting" | "folder";
2
+ /** What a label without an account may sit on; a chat, contact or message is the messenger's tag. */
3
+ export declare const LABELLED: Record<string, LabelledType>;
@@ -0,0 +1,11 @@
1
+ /** What a label without an account may sit on; a chat, contact or message is the messenger's tag. */
2
+ export const LABELLED = {
3
+ note: "note",
4
+ document: "document",
5
+ person: "person",
6
+ organization: "organization",
7
+ project: "project",
8
+ task: "task",
9
+ meeting: "meeting",
10
+ account: "folder",
11
+ };
@@ -2,13 +2,14 @@
2
2
  * Every kind a `links` row may have. The schema doc's description of `links` names exactly these
3
3
  * (`schema.test.ts` checks it); a writer that needs a new kind adds it here first.
4
4
  */
5
- export declare const LINK_KINDS: readonly ["links-to", "blocked-by", "follow-up-of", "about", "member-of", "labelled", "answered-by", "evidence", "created-from", "duplicate-of", "related-to", "assigned-to", "attached"];
5
+ export declare const LINK_KINDS: readonly ["links-to", "blocked-by", "follow-up-of", "about", "member-of", "labelled", "answered-by", "evidence", "created-from", "duplicate-of", "related-to", "reports-to", "customer-of", "partner-of", "assigned-to", "attached"];
6
6
  export type LinkKind = (typeof LINK_KINDS)[number];
7
7
  /** Where a caller may say a link came from. */
8
8
  export declare const LINK_ORIGINS: readonly ["file", "owner", "suggested", "message"];
9
9
  /** Where a stored link came from: an origin a caller gives, or `calendar`, which only the store writes. */
10
10
  export declare const LINK_SOURCES: readonly ["file", "owner", "suggested", "message", "calendar"];
11
- /** The kinds `knowledge.relate` makes between people, organizations and projects. */
12
- export declare const RELATION_KINDS: readonly ["member-of", "related-to"];
11
+ export { RELATION_KINDS } from "../../domain/relations.js";
13
12
  /** A kind as an SQL literal, so a kind written into a query is checked against the list. */
14
13
  export declare const linkKind: (kind: LinkKind) => string;
14
+ /** The `role` of the `related-to` link from a phone call's event to the person on the other end. */
15
+ export declare const COUNTERPART_ROLE = "counterpart";
@@ -14,6 +14,9 @@ export const LINK_KINDS = [
14
14
  "created-from",
15
15
  "duplicate-of",
16
16
  "related-to",
17
+ "reports-to",
18
+ "customer-of",
19
+ "partner-of",
17
20
  "assigned-to",
18
21
  "attached",
19
22
  ];
@@ -21,7 +24,8 @@ export const LINK_KINDS = [
21
24
  export const LINK_ORIGINS = ["file", "owner", "suggested", "message"];
22
25
  /** Where a stored link came from: an origin a caller gives, or `calendar`, which only the store writes. */
23
26
  export const LINK_SOURCES = [...LINK_ORIGINS, "calendar"];
24
- /** The kinds `knowledge.relate` makes between people, organizations and projects. */
25
- export const RELATION_KINDS = ["member-of", "related-to"];
27
+ export { RELATION_KINDS } from "../../domain/relations.js";
26
28
  /** A kind as an SQL literal, so a kind written into a query is checked against the list. */
27
29
  export const linkKind = (kind) => `'${kind}'`;
30
+ /** The `role` of the `related-to` link from a phone call's event to the person on the other end. */
31
+ export const COUNTERPART_ROLE = "counterpart";
@@ -28,6 +28,8 @@ const V31_TABLES = [
28
28
  "syncs",
29
29
  "taggings",
30
30
  ];
31
+ /** Version 56 rewrites CRM links and folds duplicates, which an older build would write again. */
32
+ const V56_TABLES = ["links", "proposed_actions"];
31
33
  /** One migration creates the whole schema; every later one is added as the next version. */
32
34
  export const MANIFEST = [
33
35
  { name: "20261010184427_initial", version: 1, minCompatible: 1 },
@@ -113,6 +115,11 @@ export const MANIFEST = [
113
115
  { name: "20261106225547_version-54-crm-fields", version: 54, minCompatible: 34 },
114
116
  { name: "20261107032742_version-55-decision-requests", version: 55, minCompatible: 34 },
115
117
  { name: "20261107043407_version-55-decision-requests-index", version: 55, minCompatible: 34 },
118
+ { name: "20261107162427_version-56-relationship-links", version: 56, minCompatible: 56, tables: V56_TABLES },
119
+ { name: "20261107162448_version-56-relationship-links-history", version: 56, minCompatible: 56, tables: V56_TABLES },
120
+ { name: "20261107163245_version-56-relationship-links-key", version: 56, minCompatible: 56, tables: V56_TABLES },
121
+ { name: "20261108010753_version-57-business", version: 57, minCompatible: 56 },
122
+ { name: "20261108010754_version-57-business-rules", version: 57, minCompatible: 56 },
116
123
  ];
117
124
  export const generatedMigrations = (manifest = MANIFEST, generated = GENERATED) => {
118
125
  const migrations = [];
@@ -1,6 +1,8 @@
1
1
  import { MEMORY_KINDS, MEMORY_SCOPES, type MEMORY_STATUSES } from "../../domain/knowledge.js";
2
2
  import { type Decider } from "../decisions.js";
3
+ import type { SourceReviewMarker } from "../source-review.js";
3
4
  import { type Actor, type ProposedByFilter } from "./actors.js";
5
+ import { type EvidenceInput } from "./evidence-signature.js";
4
6
  import { type EvidenceSource } from "./evidence-sources.js";
5
7
  import { type NoteIndexState } from "./note-index.js";
6
8
  import type { StoreContext } from "./open.js";
@@ -38,6 +40,8 @@ export interface Memory {
38
40
  supersedes: string | null;
39
41
  /** The references it rests on: `links` of kind `evidence`. */
40
42
  evidence: string[];
43
+ /** The open review of its sources (`memory_source_review`), when one waits for the owner. */
44
+ sourceReview: SourceReviewMarker | null;
41
45
  lastVerifiedAt: string | null;
42
46
  createdAt: string;
43
47
  updatedAt: string;
@@ -47,14 +51,14 @@ export interface MemoryInput {
47
51
  body: string;
48
52
  /** Required, with no default: a memory read for the wrong purpose leaks, so its writer says which. */
49
53
  scope: Memory["scope"];
50
- /** At least one reference the memory rests on. */
51
- evidence: string[];
54
+ /** At least one reference the memory rests on, each with the words of it the memory rests on if given. */
55
+ evidence: EvidenceInput[];
52
56
  author: Author;
53
57
  subject?: string;
54
58
  project?: string;
55
59
  confidence?: number;
56
60
  status?: "proposed" | "confirmed";
57
- /** The memory this one replaces; it becomes `superseded`. */
61
+ /** The memory this one replaces; it becomes `superseded` once this one is confirmed. */
58
62
  supersedes?: string;
59
63
  }
60
64
  export interface MemoriesStore {
@@ -75,11 +79,15 @@ export interface MemoriesStore {
75
79
  }): Promise<Memory>;
76
80
  /** The owner, or an agent for the owner, stands behind it; its evidence was checked now. */
77
81
  confirm(reference: string, by: Decider): Promise<Memory>;
78
- /** Its evidence no longer holds; for an agent's memory this is how it is turned down, so `by` must be allowed. */
82
+ /**
83
+ * Its evidence no longer holds; for an agent's memory this is how it is turned down, so `by` must be allowed. A
84
+ * confirmed memory is the owner's to retire: an agent challenges it instead (`knowledge.challenge`).
85
+ */
79
86
  markStale(reference: string, by: Decider): Promise<Memory>;
80
87
  /**
81
- * Erases the memory: its row, its text in the search and meaning indexes, and every link from or to it. A memory
82
- * that replaced it no longer names it. A backup made before keeps it.
88
+ * Erases the memory: its row, its text in the search and meaning indexes, and every link from or to it, except the
89
+ * evidence of memories and facts that cited it, which stays with no pointer and shows as a missing source. A memory
90
+ * that replaced it no longer names it. `links` counts the links erased. A backup made before keeps it.
83
91
  */
84
92
  remove(reference: string, by: Decider): Promise<{
85
93
  ref: string;
@@ -102,11 +110,14 @@ export declare const authorActor: (context: StoreContext, author: Author) => {
102
110
  model: string | null;
103
111
  };
104
112
  export declare const authorOf: (row: Row) => Memory["author"];
105
- /** Writes `evidence` links from a row to each reference, refusing one the store does not hold. */
113
+ /**
114
+ * Writes `evidence` links from a row to each reference, refusing one the store does not hold. Each link keeps the
115
+ * source's signature and the quote it was given, so a later check sees whether the source still says it.
116
+ */
106
117
  export declare const linkEvidence: (context: StoreContext, from: {
107
118
  type: string;
108
119
  id: number;
109
- }, references: string[], author: "owner" | "agent") => void;
120
+ }, references: readonly EvidenceInput[], author: "owner" | "agent") => void;
110
121
  export declare const evidenceOf: (context: StoreContext, from: {
111
122
  type: string;
112
123
  id: number;
@@ -131,11 +142,14 @@ type Numbered = "memories" | "facts";
131
142
  export declare const nextId: (database: StoreContext["database"], table: Numbered) => number;
132
143
  /** Before a delete: remembers the highest id handed out, which the delete may be about to free. */
133
144
  export declare const keepHighestId: (database: StoreContext["database"], table: Numbered, at: number) => void;
134
- /** Counts every link from or to a row and drops the ones its delete trigger does not: those pointing at it. */
145
+ /**
146
+ * Counts every link from or to a row and drops the ones its delete trigger does not: those pointing at it. Evidence
147
+ * that cites it stays, with no pointer, so a memory or fact that rested on it still shows a source that went.
148
+ */
135
149
  export declare const dropLinksOf: (database: StoreContext["database"], thing: {
136
150
  type: string;
137
151
  id: number;
138
- }) => number;
152
+ }, at: number) => number;
139
153
  /**
140
154
  * Runs a delete so the text does not linger in the file: freed pages are zeroed, the words indexes merged so no
141
155
  * segment still holds the erased words, and the write-ahead log emptied when no reader holds it.