@oscharko-dev/keiko-contracts 0.2.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 (227) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/bff-wire.d.ts +661 -0
  3. package/dist/bff-wire.d.ts.map +1 -0
  4. package/dist/bff-wire.js +102 -0
  5. package/dist/bug-investigation-events.d.ts +92 -0
  6. package/dist/bug-investigation-events.d.ts.map +1 -0
  7. package/dist/bug-investigation-events.js +18 -0
  8. package/dist/coding-context.d.ts +76 -0
  9. package/dist/coding-context.d.ts.map +1 -0
  10. package/dist/coding-context.js +158 -0
  11. package/dist/connected-context.d.ts +174 -0
  12. package/dist/connected-context.d.ts.map +1 -0
  13. package/dist/connected-context.js +636 -0
  14. package/dist/conversation-budget.d.ts +37 -0
  15. package/dist/conversation-budget.d.ts.map +1 -0
  16. package/dist/conversation-budget.js +97 -0
  17. package/dist/editor-agent.d.ts +131 -0
  18. package/dist/editor-agent.d.ts.map +1 -0
  19. package/dist/editor-agent.js +197 -0
  20. package/dist/editor-completion.d.ts +62 -0
  21. package/dist/editor-completion.d.ts.map +1 -0
  22. package/dist/editor-completion.js +147 -0
  23. package/dist/editor-dirty-close.d.ts +17 -0
  24. package/dist/editor-dirty-close.d.ts.map +1 -0
  25. package/dist/editor-dirty-close.js +8 -0
  26. package/dist/editor-hot-exit.d.ts +18 -0
  27. package/dist/editor-hot-exit.d.ts.map +1 -0
  28. package/dist/editor-hot-exit.js +42 -0
  29. package/dist/editor-inline-completion.d.ts +70 -0
  30. package/dist/editor-inline-completion.d.ts.map +1 -0
  31. package/dist/editor-inline-completion.js +215 -0
  32. package/dist/editor-layout.d.ts +105 -0
  33. package/dist/editor-layout.d.ts.map +1 -0
  34. package/dist/editor-layout.js +479 -0
  35. package/dist/editor-patch-apply.d.ts +77 -0
  36. package/dist/editor-patch-apply.d.ts.map +1 -0
  37. package/dist/editor-patch-apply.js +122 -0
  38. package/dist/editor-session.d.ts +31 -0
  39. package/dist/editor-session.d.ts.map +1 -0
  40. package/dist/editor-session.js +75 -0
  41. package/dist/editor-test-generation.d.ts +104 -0
  42. package/dist/editor-test-generation.d.ts.map +1 -0
  43. package/dist/editor-test-generation.js +211 -0
  44. package/dist/evaluations.d.ts +75 -0
  45. package/dist/evaluations.d.ts.map +1 -0
  46. package/dist/evaluations.js +16 -0
  47. package/dist/evidence.d.ts +297 -0
  48. package/dist/evidence.d.ts.map +1 -0
  49. package/dist/evidence.js +9 -0
  50. package/dist/gateway.d.ts +129 -0
  51. package/dist/gateway.d.ts.map +1 -0
  52. package/dist/gateway.js +66 -0
  53. package/dist/harness.d.ts +274 -0
  54. package/dist/harness.d.ts.map +1 -0
  55. package/dist/harness.js +38 -0
  56. package/dist/index.d.ts +101 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +83 -0
  59. package/dist/language-service.d.ts +145 -0
  60. package/dist/language-service.d.ts.map +1 -0
  61. package/dist/language-service.js +161 -0
  62. package/dist/local-knowledge-large-document-validation.d.ts +7 -0
  63. package/dist/local-knowledge-large-document-validation.d.ts.map +1 -0
  64. package/dist/local-knowledge-large-document-validation.js +161 -0
  65. package/dist/local-knowledge-large-document.d.ts +113 -0
  66. package/dist/local-knowledge-large-document.d.ts.map +1 -0
  67. package/dist/local-knowledge-large-document.js +142 -0
  68. package/dist/local-knowledge-paths.d.ts +3 -0
  69. package/dist/local-knowledge-paths.d.ts.map +1 -0
  70. package/dist/local-knowledge-paths.js +65 -0
  71. package/dist/local-knowledge-records.d.ts +190 -0
  72. package/dist/local-knowledge-records.d.ts.map +1 -0
  73. package/dist/local-knowledge-records.js +36 -0
  74. package/dist/local-knowledge-schema-validation.d.ts +19 -0
  75. package/dist/local-knowledge-schema-validation.d.ts.map +1 -0
  76. package/dist/local-knowledge-schema-validation.js +115 -0
  77. package/dist/local-knowledge-schema.d.ts +14 -0
  78. package/dist/local-knowledge-schema.d.ts.map +1 -0
  79. package/dist/local-knowledge-schema.js +715 -0
  80. package/dist/local-knowledge-validation.d.ts +20 -0
  81. package/dist/local-knowledge-validation.d.ts.map +1 -0
  82. package/dist/local-knowledge-validation.js +487 -0
  83. package/dist/local-knowledge.d.ts +158 -0
  84. package/dist/local-knowledge.d.ts.map +1 -0
  85. package/dist/local-knowledge.js +63 -0
  86. package/dist/memory-audit-events.d.ts +73 -0
  87. package/dist/memory-audit-events.d.ts.map +1 -0
  88. package/dist/memory-audit-events.js +44 -0
  89. package/dist/memory-audit-validation.d.ts +4 -0
  90. package/dist/memory-audit-validation.d.ts.map +1 -0
  91. package/dist/memory-audit-validation.js +151 -0
  92. package/dist/memory-barrel.d.ts +15 -0
  93. package/dist/memory-barrel.d.ts.map +1 -0
  94. package/dist/memory-barrel.js +20 -0
  95. package/dist/memory-internal.d.ts +26 -0
  96. package/dist/memory-internal.d.ts.map +1 -0
  97. package/dist/memory-internal.js +104 -0
  98. package/dist/memory-operations-validation.d.ts +12 -0
  99. package/dist/memory-operations-validation.d.ts.map +1 -0
  100. package/dist/memory-operations-validation.js +267 -0
  101. package/dist/memory-operations.d.ts +156 -0
  102. package/dist/memory-operations.d.ts.map +1 -0
  103. package/dist/memory-operations.js +29 -0
  104. package/dist/memory-record-validation.d.ts +10 -0
  105. package/dist/memory-record-validation.d.ts.map +1 -0
  106. package/dist/memory-record-validation.js +101 -0
  107. package/dist/memory-records.d.ts +66 -0
  108. package/dist/memory-records.d.ts.map +1 -0
  109. package/dist/memory-records.js +22 -0
  110. package/dist/memory-retrieval-validation.d.ts +6 -0
  111. package/dist/memory-retrieval-validation.d.ts.map +1 -0
  112. package/dist/memory-retrieval-validation.js +108 -0
  113. package/dist/memory-validation.d.ts +31 -0
  114. package/dist/memory-validation.d.ts.map +1 -0
  115. package/dist/memory-validation.js +318 -0
  116. package/dist/memory-workflow-port.d.ts +26 -0
  117. package/dist/memory-workflow-port.d.ts.map +1 -0
  118. package/dist/memory-workflow-port.js +13 -0
  119. package/dist/memory.d.ts +81 -0
  120. package/dist/memory.d.ts.map +1 -0
  121. package/dist/memory.js +104 -0
  122. package/dist/prompt-enhancer-analyzer.d.ts +7 -0
  123. package/dist/prompt-enhancer-analyzer.d.ts.map +1 -0
  124. package/dist/prompt-enhancer-analyzer.js +745 -0
  125. package/dist/prompt-enhancer-bff.d.ts +67 -0
  126. package/dist/prompt-enhancer-bff.d.ts.map +1 -0
  127. package/dist/prompt-enhancer-bff.js +156 -0
  128. package/dist/prompt-enhancer-critic.d.ts +46 -0
  129. package/dist/prompt-enhancer-critic.d.ts.map +1 -0
  130. package/dist/prompt-enhancer-critic.js +35 -0
  131. package/dist/prompt-enhancer-grounding.d.ts +19 -0
  132. package/dist/prompt-enhancer-grounding.d.ts.map +1 -0
  133. package/dist/prompt-enhancer-grounding.js +235 -0
  134. package/dist/prompt-enhancer-safety.d.ts +66 -0
  135. package/dist/prompt-enhancer-safety.d.ts.map +1 -0
  136. package/dist/prompt-enhancer-safety.js +446 -0
  137. package/dist/prompt-enhancer-validation.d.ts +28 -0
  138. package/dist/prompt-enhancer-validation.d.ts.map +1 -0
  139. package/dist/prompt-enhancer-validation.js +931 -0
  140. package/dist/prompt-enhancer.d.ts +184 -0
  141. package/dist/prompt-enhancer.d.ts.map +1 -0
  142. package/dist/prompt-enhancer.js +350 -0
  143. package/dist/qualityIntelligence/assertNever.d.ts +2 -0
  144. package/dist/qualityIntelligence/assertNever.d.ts.map +1 -0
  145. package/dist/qualityIntelligence/assertNever.js +7 -0
  146. package/dist/qualityIntelligence/auditSummary.d.ts +25 -0
  147. package/dist/qualityIntelligence/auditSummary.d.ts.map +1 -0
  148. package/dist/qualityIntelligence/auditSummary.js +7 -0
  149. package/dist/qualityIntelligence/bffWire.d.ts +356 -0
  150. package/dist/qualityIntelligence/bffWire.d.ts.map +1 -0
  151. package/dist/qualityIntelligence/bffWire.js +22 -0
  152. package/dist/qualityIntelligence/coverageMap.d.ts +21 -0
  153. package/dist/qualityIntelligence/coverageMap.d.ts.map +1 -0
  154. package/dist/qualityIntelligence/coverageMap.js +29 -0
  155. package/dist/qualityIntelligence/editableRevision.d.ts +21 -0
  156. package/dist/qualityIntelligence/editableRevision.d.ts.map +1 -0
  157. package/dist/qualityIntelligence/editableRevision.js +8 -0
  158. package/dist/qualityIntelligence/evidenceAtom.d.ts +35 -0
  159. package/dist/qualityIntelligence/evidenceAtom.d.ts.map +1 -0
  160. package/dist/qualityIntelligence/evidenceAtom.js +29 -0
  161. package/dist/qualityIntelligence/exportBundle.d.ts +28 -0
  162. package/dist/qualityIntelligence/exportBundle.d.ts.map +1 -0
  163. package/dist/qualityIntelligence/exportBundle.js +46 -0
  164. package/dist/qualityIntelligence/handoffEnvelope.d.ts +23 -0
  165. package/dist/qualityIntelligence/handoffEnvelope.d.ts.map +1 -0
  166. package/dist/qualityIntelligence/handoffEnvelope.js +8 -0
  167. package/dist/qualityIntelligence/ids.d.ts +58 -0
  168. package/dist/qualityIntelligence/ids.d.ts.map +1 -0
  169. package/dist/qualityIntelligence/ids.js +93 -0
  170. package/dist/qualityIntelligence/index.d.ts +29 -0
  171. package/dist/qualityIntelligence/index.d.ts.map +1 -0
  172. package/dist/qualityIntelligence/index.js +20 -0
  173. package/dist/qualityIntelligence/reviewRecord.d.ts +19 -0
  174. package/dist/qualityIntelligence/reviewRecord.d.ts.map +1 -0
  175. package/dist/qualityIntelligence/reviewRecord.js +20 -0
  176. package/dist/qualityIntelligence/runPlanAndEvents.d.ts +84 -0
  177. package/dist/qualityIntelligence/runPlanAndEvents.d.ts.map +1 -0
  178. package/dist/qualityIntelligence/runPlanAndEvents.js +51 -0
  179. package/dist/qualityIntelligence/sourceEnvelope.d.ts +77 -0
  180. package/dist/qualityIntelligence/sourceEnvelope.d.ts.map +1 -0
  181. package/dist/qualityIntelligence/sourceEnvelope.js +118 -0
  182. package/dist/qualityIntelligence/testCaseCandidate.d.ts +21 -0
  183. package/dist/qualityIntelligence/testCaseCandidate.d.ts.map +1 -0
  184. package/dist/qualityIntelligence/testCaseCandidate.js +21 -0
  185. package/dist/qualityIntelligence/testQualityRubric.d.ts +17 -0
  186. package/dist/qualityIntelligence/testQualityRubric.d.ts.map +1 -0
  187. package/dist/qualityIntelligence/testQualityRubric.js +32 -0
  188. package/dist/qualityIntelligence/validationFinding.d.ts +48 -0
  189. package/dist/qualityIntelligence/validationFinding.d.ts.map +1 -0
  190. package/dist/qualityIntelligence/validationFinding.js +36 -0
  191. package/dist/relationships-validation.d.ts +13 -0
  192. package/dist/relationships-validation.d.ts.map +1 -0
  193. package/dist/relationships-validation.js +422 -0
  194. package/dist/relationships.d.ts +79 -0
  195. package/dist/relationships.d.ts.map +1 -0
  196. package/dist/relationships.js +307 -0
  197. package/dist/text-safety.d.ts +7 -0
  198. package/dist/text-safety.d.ts.map +1 -0
  199. package/dist/text-safety.js +58 -0
  200. package/dist/tools.d.ts +153 -0
  201. package/dist/tools.d.ts.map +1 -0
  202. package/dist/tools.js +118 -0
  203. package/dist/unit-test-events.d.ts +87 -0
  204. package/dist/unit-test-events.d.ts.map +1 -0
  205. package/dist/unit-test-events.js +14 -0
  206. package/dist/verification-summary.d.ts +38 -0
  207. package/dist/verification-summary.d.ts.map +1 -0
  208. package/dist/verification-summary.js +5 -0
  209. package/dist/verification.d.ts +64 -0
  210. package/dist/verification.d.ts.map +1 -0
  211. package/dist/verification.js +13 -0
  212. package/dist/workflow-descriptor.d.ts +21 -0
  213. package/dist/workflow-descriptor.d.ts.map +1 -0
  214. package/dist/workflow-descriptor.js +8 -0
  215. package/dist/workflow-handoff.d.ts +69 -0
  216. package/dist/workflow-handoff.d.ts.map +1 -0
  217. package/dist/workflow-handoff.js +381 -0
  218. package/dist/workspace-descriptors.d.ts +21 -0
  219. package/dist/workspace-descriptors.d.ts.map +1 -0
  220. package/dist/workspace-descriptors.js +180 -0
  221. package/dist/workspace-ui.d.ts +119 -0
  222. package/dist/workspace-ui.d.ts.map +1 -0
  223. package/dist/workspace-ui.js +105 -0
  224. package/dist/workspace.d.ts +104 -0
  225. package/dist/workspace.d.ts.map +1 -0
  226. package/dist/workspace.js +27 -0
  227. package/package.json +71 -0
@@ -0,0 +1,267 @@
1
+ // Pure validators for memory operation envelopes (Epic #204, Issue #205). Sibling of
2
+ // `memory-validation.ts`. Retrieval and audit validators live in
3
+ // `memory-retrieval-validation.ts` and `memory-audit-validation.ts` so each file stays
4
+ // under the 400-LOC budget. No IO, no clock, no randomness.
5
+ import { MEMORY_SENSITIVITIES, MEMORY_TYPES } from "./memory.js";
6
+ import { validateMemoryProvenance, validateMemoryScope, validateMemoryStructuredPayload, validateMemoryValidityInterval, } from "./memory-validation.js";
7
+ import { MEMORY_BODY_MAX_CHARS, MEMORY_RATIONALE_MAX_CHARS, MEMORY_REASON_MAX_CHARS, isFiniteNonNegativeNumber, isMember, isNonEmptyTrimmedString, isRecord, isSafeText, pushNestedErrors, validateMemoryIdString, validateRetentionHint, validateSchemaVersionLiteral, validateTags, } from "./memory-internal.js";
8
+ // ─── Proposal ─────────────────────────────────────────────────────────────────
9
+ function validateProposalOptionalFields(input, errors) {
10
+ if (input.payload !== undefined) {
11
+ pushNestedErrors("proposal", validateMemoryStructuredPayload(input.payload), errors);
12
+ }
13
+ validateTags("proposal.tags", input.tags, errors);
14
+ pushNestedErrors("proposal", validateMemoryProvenance(input.provenance), errors);
15
+ pushNestedErrors("proposal", validateMemoryValidityInterval(input.validity), errors);
16
+ if (input.retentionHint !== undefined) {
17
+ validateRetentionHint("proposal.retentionHint", input.retentionHint, errors);
18
+ }
19
+ if (input.captureReason !== undefined &&
20
+ !isSafeText(input.captureReason, MEMORY_RATIONALE_MAX_CHARS)) {
21
+ errors.push("proposal.captureReason must be a bounded control-free string when set");
22
+ }
23
+ }
24
+ export function validateMemoryProposal(input) {
25
+ if (!isRecord(input)) {
26
+ return { ok: false, errors: ["proposal must be an object"] };
27
+ }
28
+ const errors = [];
29
+ validateSchemaVersionLiteral(input, errors);
30
+ validateMemoryIdString("proposal.proposalId", input.proposalId, errors);
31
+ if (!isFiniteNonNegativeNumber(input.proposedAt)) {
32
+ errors.push("proposal.proposedAt must be a finite non-negative number");
33
+ }
34
+ pushNestedErrors("proposal", validateMemoryScope(input.scope), errors);
35
+ if (!isMember(input.type, MEMORY_TYPES)) {
36
+ errors.push(`proposal.type must be one of ${MEMORY_TYPES.join("|")}`);
37
+ }
38
+ if (!isSafeText(input.body, MEMORY_BODY_MAX_CHARS)) {
39
+ errors.push("proposal.body must be a bounded control-free non-empty string");
40
+ }
41
+ validateProposalOptionalFields(input, errors);
42
+ if (input.initialStatus !== "proposed") {
43
+ errors.push('proposal.initialStatus must be the literal "proposed"');
44
+ }
45
+ if (errors.length > 0) {
46
+ return { ok: false, errors };
47
+ }
48
+ return { ok: true, value: input };
49
+ }
50
+ // ─── Acceptance ───────────────────────────────────────────────────────────────
51
+ function validateAcceptanceOverrides(input, errors) {
52
+ if (input.bodyOverride !== undefined && !isSafeText(input.bodyOverride, MEMORY_BODY_MAX_CHARS)) {
53
+ errors.push("acceptance.bodyOverride must be a bounded control-free string when set");
54
+ }
55
+ if (input.sensitivityOverride !== undefined &&
56
+ !isMember(input.sensitivityOverride, MEMORY_SENSITIVITIES)) {
57
+ errors.push(`acceptance.sensitivityOverride must be one of ${MEMORY_SENSITIVITIES.join("|")} when set`);
58
+ }
59
+ if (input.validityOverride !== undefined) {
60
+ pushNestedErrors("acceptance", validateMemoryValidityInterval(input.validityOverride), errors);
61
+ }
62
+ if (input.reviewerNote !== undefined &&
63
+ !isSafeText(input.reviewerNote, MEMORY_RATIONALE_MAX_CHARS)) {
64
+ errors.push("acceptance.reviewerNote must be a bounded control-free string when set");
65
+ }
66
+ }
67
+ export function validateMemoryAcceptance(input) {
68
+ if (!isRecord(input)) {
69
+ return { ok: false, errors: ["acceptance must be an object"] };
70
+ }
71
+ const errors = [];
72
+ validateSchemaVersionLiteral(input, errors);
73
+ validateMemoryIdString("acceptance.proposalId", input.proposalId, errors);
74
+ validateMemoryIdString("acceptance.mintedMemoryId", input.mintedMemoryId, errors);
75
+ validateMemoryIdString("acceptance.reviewerId", input.reviewerId, errors);
76
+ if (!isFiniteNonNegativeNumber(input.acceptedAt)) {
77
+ errors.push("acceptance.acceptedAt must be a finite non-negative number");
78
+ }
79
+ validateAcceptanceOverrides(input, errors);
80
+ if (errors.length > 0) {
81
+ return { ok: false, errors };
82
+ }
83
+ return { ok: true, value: input };
84
+ }
85
+ // ─── Rejection ────────────────────────────────────────────────────────────────
86
+ export function validateMemoryRejection(input) {
87
+ if (!isRecord(input)) {
88
+ return { ok: false, errors: ["rejection must be an object"] };
89
+ }
90
+ const errors = [];
91
+ validateSchemaVersionLiteral(input, errors);
92
+ validateMemoryIdString("rejection.proposalId", input.proposalId, errors);
93
+ validateMemoryIdString("rejection.reviewerId", input.reviewerId, errors);
94
+ if (!isFiniteNonNegativeNumber(input.rejectedAt)) {
95
+ errors.push("rejection.rejectedAt must be a finite non-negative number");
96
+ }
97
+ if (!isSafeText(input.reason, MEMORY_REASON_MAX_CHARS)) {
98
+ errors.push("rejection.reason must be a bounded control-free non-empty string");
99
+ }
100
+ if (errors.length > 0) {
101
+ return { ok: false, errors };
102
+ }
103
+ return { ok: true, value: input };
104
+ }
105
+ // ─── Update ───────────────────────────────────────────────────────────────────
106
+ const UPDATE_OPTIONAL_FIELDS = [
107
+ "bodyPatch",
108
+ "payloadPatch",
109
+ "tagsPatch",
110
+ "validityPatch",
111
+ "sensitivityPatch",
112
+ "retentionHintPatch",
113
+ ];
114
+ function countUpdatePatches(input) {
115
+ let count = 0;
116
+ for (const field of UPDATE_OPTIONAL_FIELDS) {
117
+ if (input[field] !== undefined) {
118
+ count += 1;
119
+ }
120
+ }
121
+ return count;
122
+ }
123
+ function validateUpdatePatchFields(input, errors) {
124
+ if (input.bodyPatch !== undefined && !isSafeText(input.bodyPatch, MEMORY_BODY_MAX_CHARS)) {
125
+ errors.push("update.bodyPatch must be a bounded control-free string when set");
126
+ }
127
+ if (input.payloadPatch !== undefined) {
128
+ pushNestedErrors("update", validateMemoryStructuredPayload(input.payloadPatch), errors);
129
+ }
130
+ if (input.tagsPatch !== undefined) {
131
+ validateTags("update.tagsPatch", input.tagsPatch, errors);
132
+ }
133
+ if (input.validityPatch !== undefined) {
134
+ pushNestedErrors("update", validateMemoryValidityInterval(input.validityPatch), errors);
135
+ }
136
+ if (input.sensitivityPatch !== undefined &&
137
+ !isMember(input.sensitivityPatch, MEMORY_SENSITIVITIES)) {
138
+ errors.push(`update.sensitivityPatch must be one of ${MEMORY_SENSITIVITIES.join("|")} when set`);
139
+ }
140
+ if (input.retentionHintPatch !== undefined) {
141
+ validateRetentionHint("update.retentionHintPatch", input.retentionHintPatch, errors);
142
+ }
143
+ }
144
+ export function validateMemoryUpdate(input) {
145
+ if (!isRecord(input)) {
146
+ return { ok: false, errors: ["update must be an object"] };
147
+ }
148
+ const errors = [];
149
+ validateSchemaVersionLiteral(input, errors);
150
+ validateMemoryIdString("update.memoryId", input.memoryId, errors);
151
+ validateMemoryIdString("update.reviewerId", input.reviewerId, errors);
152
+ if (!isFiniteNonNegativeNumber(input.updatedAt)) {
153
+ errors.push("update.updatedAt must be a finite non-negative number");
154
+ }
155
+ validateUpdatePatchFields(input, errors);
156
+ if (countUpdatePatches(input) === 0) {
157
+ errors.push("update must change at least one field");
158
+ }
159
+ if (input.reviewerNote !== undefined &&
160
+ !isSafeText(input.reviewerNote, MEMORY_RATIONALE_MAX_CHARS)) {
161
+ errors.push("update.reviewerNote must be a bounded control-free string when set");
162
+ }
163
+ if (errors.length > 0) {
164
+ return { ok: false, errors };
165
+ }
166
+ return { ok: true, value: input };
167
+ }
168
+ // ─── Supersession ─────────────────────────────────────────────────────────────
169
+ export function validateMemorySupersession(input) {
170
+ if (!isRecord(input)) {
171
+ return { ok: false, errors: ["supersession must be an object"] };
172
+ }
173
+ const errors = [];
174
+ validateSchemaVersionLiteral(input, errors);
175
+ validateMemoryIdString("supersession.oldMemoryId", input.oldMemoryId, errors);
176
+ validateMemoryIdString("supersession.newMemoryId", input.newMemoryId, errors);
177
+ if (isNonEmptyTrimmedString(input.oldMemoryId) &&
178
+ isNonEmptyTrimmedString(input.newMemoryId) &&
179
+ input.oldMemoryId === input.newMemoryId) {
180
+ errors.push("supersession.oldMemoryId and supersession.newMemoryId must differ");
181
+ }
182
+ validateMemoryIdString("supersession.reviewerId", input.reviewerId, errors);
183
+ if (!isFiniteNonNegativeNumber(input.supersededAt)) {
184
+ errors.push("supersession.supersededAt must be a finite non-negative number");
185
+ }
186
+ if (!isSafeText(input.reason, MEMORY_REASON_MAX_CHARS)) {
187
+ errors.push("supersession.reason must be a bounded control-free non-empty string");
188
+ }
189
+ if (input.edgeKind !== "supersedes") {
190
+ errors.push('supersession.edgeKind must be the literal "supersedes"');
191
+ }
192
+ if (errors.length > 0) {
193
+ return { ok: false, errors };
194
+ }
195
+ return { ok: true, value: input };
196
+ }
197
+ // ─── Pin / unpin / archive ────────────────────────────────────────────────────
198
+ function validatePinOrUnpinShape(noun, timestampField, input) {
199
+ if (!isRecord(input)) {
200
+ return { ok: false, errors: [`${noun} must be an object`] };
201
+ }
202
+ const errors = [];
203
+ validateSchemaVersionLiteral(input, errors);
204
+ validateMemoryIdString(`${noun}.memoryId`, input.memoryId, errors);
205
+ validateMemoryIdString(`${noun}.reviewerId`, input.reviewerId, errors);
206
+ if (!isFiniteNonNegativeNumber(input[timestampField])) {
207
+ errors.push(`${noun}.${timestampField} must be a finite non-negative number`);
208
+ }
209
+ if (input.reason !== undefined && !isSafeText(input.reason, MEMORY_REASON_MAX_CHARS)) {
210
+ errors.push(`${noun}.reason must be a bounded control-free string when set`);
211
+ }
212
+ if (errors.length > 0) {
213
+ return { ok: false, errors };
214
+ }
215
+ return { ok: true, value: input };
216
+ }
217
+ export function validateMemoryPin(input) {
218
+ return validatePinOrUnpinShape("pin", "pinnedAt", input);
219
+ }
220
+ export function validateMemoryUnpin(input) {
221
+ return validatePinOrUnpinShape("unpin", "unpinnedAt", input);
222
+ }
223
+ export function validateMemoryArchive(input) {
224
+ if (!isRecord(input)) {
225
+ return { ok: false, errors: ["archive must be an object"] };
226
+ }
227
+ const errors = [];
228
+ validateSchemaVersionLiteral(input, errors);
229
+ validateMemoryIdString("archive.memoryId", input.memoryId, errors);
230
+ validateMemoryIdString("archive.reviewerId", input.reviewerId, errors);
231
+ if (!isFiniteNonNegativeNumber(input.archivedAt)) {
232
+ errors.push("archive.archivedAt must be a finite non-negative number");
233
+ }
234
+ if (input.reason !== undefined && !isSafeText(input.reason, MEMORY_REASON_MAX_CHARS)) {
235
+ errors.push("archive.reason must be a bounded control-free string when set");
236
+ }
237
+ if (errors.length > 0) {
238
+ return { ok: false, errors };
239
+ }
240
+ return { ok: true, value: input };
241
+ }
242
+ // ─── Forget ───────────────────────────────────────────────────────────────────
243
+ // The destructive-acknowledgement flag is pinned to the literal `true` at the type level,
244
+ // so structural success is also semantic acknowledgement: a caller cannot ship a forget
245
+ // envelope without explicit acknowledgement.
246
+ export function validateMemoryForget(input) {
247
+ if (!isRecord(input)) {
248
+ return { ok: false, errors: ["forget must be an object"] };
249
+ }
250
+ const errors = [];
251
+ validateSchemaVersionLiteral(input, errors);
252
+ validateMemoryIdString("forget.memoryId", input.memoryId, errors);
253
+ validateMemoryIdString("forget.reviewerId", input.reviewerId, errors);
254
+ if (!isFiniteNonNegativeNumber(input.forgottenAt)) {
255
+ errors.push("forget.forgottenAt must be a finite non-negative number");
256
+ }
257
+ if (!isSafeText(input.reason, MEMORY_REASON_MAX_CHARS)) {
258
+ errors.push("forget.reason must be a bounded control-free non-empty string");
259
+ }
260
+ if (input.userAcknowledgedDestructive !== true) {
261
+ errors.push("forget.userAcknowledgedDestructive must be the literal true");
262
+ }
263
+ if (errors.length > 0) {
264
+ return { ok: false, errors };
265
+ }
266
+ return { ok: true, value: input };
267
+ }
@@ -0,0 +1,156 @@
1
+ import type { MemoryAuditActionKind, MemoryAuditRecordId, MemoryEdgeId, MemoryEdgeKind, MemoryId, MemoryProposalId, MemoryReviewerId, MemoryScope, MemorySensitivity, MemoryStatus, MemoryType } from "./memory.js";
2
+ import type { MemoryProvenance, MemoryRetentionHint, MemoryStructuredPayload, MemoryValidityInterval } from "./memory-records.js";
3
+ export interface MemoryProposal {
4
+ readonly schemaVersion: "1";
5
+ readonly proposalId: MemoryProposalId;
6
+ readonly proposedAt: number;
7
+ readonly scope: MemoryScope;
8
+ readonly type: MemoryType;
9
+ readonly body: string;
10
+ readonly payload?: MemoryStructuredPayload;
11
+ readonly tags: readonly string[];
12
+ readonly provenance: MemoryProvenance;
13
+ readonly validity: MemoryValidityInterval;
14
+ readonly retentionHint?: MemoryRetentionHint;
15
+ readonly initialStatus: "proposed";
16
+ readonly captureReason?: string;
17
+ }
18
+ export interface MemoryAcceptance {
19
+ readonly schemaVersion: "1";
20
+ readonly proposalId: MemoryProposalId;
21
+ readonly mintedMemoryId: MemoryId;
22
+ readonly reviewerId: MemoryReviewerId;
23
+ readonly acceptedAt: number;
24
+ readonly bodyOverride?: string;
25
+ readonly sensitivityOverride?: MemorySensitivity;
26
+ readonly validityOverride?: MemoryValidityInterval;
27
+ readonly reviewerNote?: string;
28
+ }
29
+ export interface MemoryRejection {
30
+ readonly schemaVersion: "1";
31
+ readonly proposalId: MemoryProposalId;
32
+ readonly reviewerId: MemoryReviewerId;
33
+ readonly rejectedAt: number;
34
+ readonly reason: string;
35
+ }
36
+ export interface MemoryUpdate {
37
+ readonly schemaVersion: "1";
38
+ readonly memoryId: MemoryId;
39
+ readonly reviewerId: MemoryReviewerId;
40
+ readonly updatedAt: number;
41
+ readonly bodyPatch?: string;
42
+ readonly payloadPatch?: MemoryStructuredPayload;
43
+ readonly tagsPatch?: readonly string[];
44
+ readonly validityPatch?: MemoryValidityInterval;
45
+ readonly sensitivityPatch?: MemorySensitivity;
46
+ readonly retentionHintPatch?: MemoryRetentionHint;
47
+ readonly reviewerNote?: string;
48
+ }
49
+ export interface MemorySupersession {
50
+ readonly schemaVersion: "1";
51
+ readonly oldMemoryId: MemoryId;
52
+ readonly newMemoryId: MemoryId;
53
+ readonly reviewerId: MemoryReviewerId;
54
+ readonly supersededAt: number;
55
+ readonly reason: string;
56
+ readonly edgeKind: "supersedes";
57
+ }
58
+ export interface MemoryPin {
59
+ readonly schemaVersion: "1";
60
+ readonly memoryId: MemoryId;
61
+ readonly reviewerId: MemoryReviewerId;
62
+ readonly pinnedAt: number;
63
+ readonly reason?: string;
64
+ }
65
+ export interface MemoryUnpin {
66
+ readonly schemaVersion: "1";
67
+ readonly memoryId: MemoryId;
68
+ readonly reviewerId: MemoryReviewerId;
69
+ readonly unpinnedAt: number;
70
+ readonly reason?: string;
71
+ }
72
+ export interface MemoryArchive {
73
+ readonly schemaVersion: "1";
74
+ readonly memoryId: MemoryId;
75
+ readonly reviewerId: MemoryReviewerId;
76
+ readonly archivedAt: number;
77
+ readonly reason?: string;
78
+ }
79
+ export interface MemoryForget {
80
+ readonly schemaVersion: "1";
81
+ readonly memoryId: MemoryId;
82
+ readonly reviewerId: MemoryReviewerId;
83
+ readonly forgottenAt: number;
84
+ readonly reason: string;
85
+ readonly userAcknowledgedDestructive: true;
86
+ }
87
+ export interface MemoryRetrievalRequest {
88
+ readonly schemaVersion: "1";
89
+ readonly requestedAt: number;
90
+ readonly scopes: readonly MemoryScope[];
91
+ readonly typeFilter?: readonly MemoryType[];
92
+ readonly statusFilter?: readonly MemoryStatus[];
93
+ readonly textQuery?: string;
94
+ readonly tagsFilter?: readonly string[];
95
+ readonly maxResults?: number;
96
+ readonly maxBodyChars?: number;
97
+ readonly includeArchived?: boolean;
98
+ readonly includeSuperseded?: boolean;
99
+ }
100
+ export type MemoryAuditAction = {
101
+ readonly kind: "proposed";
102
+ readonly proposalId: MemoryProposalId;
103
+ readonly scope: MemoryScope;
104
+ } | {
105
+ readonly kind: "accepted";
106
+ readonly proposalId: MemoryProposalId;
107
+ readonly memoryId: MemoryId;
108
+ readonly scope: MemoryScope;
109
+ } | {
110
+ readonly kind: "rejected";
111
+ readonly proposalId: MemoryProposalId;
112
+ readonly reason: string;
113
+ } | {
114
+ readonly kind: "updated";
115
+ readonly memoryId: MemoryId;
116
+ readonly fieldsChanged: readonly MemoryUpdateField[];
117
+ } | {
118
+ readonly kind: "superseded";
119
+ readonly oldMemoryId: MemoryId;
120
+ readonly newMemoryId: MemoryId;
121
+ readonly edgeId: MemoryEdgeId;
122
+ readonly edgeKind: MemoryEdgeKind;
123
+ } | {
124
+ readonly kind: "pinned";
125
+ readonly memoryId: MemoryId;
126
+ } | {
127
+ readonly kind: "unpinned";
128
+ readonly memoryId: MemoryId;
129
+ } | {
130
+ readonly kind: "archived";
131
+ readonly memoryId: MemoryId;
132
+ } | {
133
+ readonly kind: "forgotten";
134
+ readonly memoryId: MemoryId;
135
+ readonly scope: MemoryScope;
136
+ readonly reason: string;
137
+ } | {
138
+ readonly kind: "retrieved";
139
+ readonly scopes: readonly MemoryScope[];
140
+ readonly matchedMemoryIds: readonly MemoryId[];
141
+ };
142
+ export type MemoryUpdateField = "body" | "payload" | "tags" | "validity" | "sensitivity" | "retentionHint";
143
+ export declare const MEMORY_UPDATE_FIELDS: readonly MemoryUpdateField[];
144
+ export type MemoryAuditInitiatorSurface = "memory-center" | "conversation-center" | "workflow" | "consolidation" | "retention" | "system";
145
+ export declare const MEMORY_AUDIT_INITIATOR_SURFACES: readonly MemoryAuditInitiatorSurface[];
146
+ export interface MemoryAuditRecord {
147
+ readonly id: MemoryAuditRecordId;
148
+ readonly schemaVersion: "1";
149
+ readonly actionKind: MemoryAuditActionKind;
150
+ readonly action: MemoryAuditAction;
151
+ readonly initiatorSurface: MemoryAuditInitiatorSurface;
152
+ readonly initiatorReviewerId?: MemoryReviewerId;
153
+ readonly occurredAt: number;
154
+ readonly summary: string;
155
+ }
156
+ //# sourceMappingURL=memory-operations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-operations.d.ts","sourceRoot":"","sources":["../src/memory-operations.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,qBAAq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C;AAEX,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE,EAAE,mBAAmB,CAAC;IACjC,QAAQ,CAAC,aAAa,EAAE,GAAG,CAAC;IAC5B,QAAQ,CAAC,UAAU,EAAE,qBAAqB,CAAC;IAC3C,QAAQ,CAAC,MAAM,EAAE,iBAAiB,CAAC;IACnC,QAAQ,CAAC,gBAAgB,EAAE,2BAA2B,CAAC;IACvD,QAAQ,CAAC,mBAAmB,CAAC,EAAE,gBAAgB,CAAC;IAChD,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;IAG5B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;CAC1B"}
@@ -0,0 +1,29 @@
1
+ // Operation envelopes for the Governed Enterprise Memory Vault (Epic #204, Issue #205).
2
+ // Pure types only — no IO, no clock, no randomness. Leaf-package rule (ADR-0019 direction
3
+ // 1): no `@oscharko-dev/keiko-*` imports.
4
+ //
5
+ // Each operation carries the minimum data the next layer needs to evaluate it. The
6
+ // validation layer (memory-validation.ts) checks structural well-formedness, status
7
+ // transition legality, and provenance presence; authorization, persistence, and
8
+ // side-effects belong to downstream packages and are explicitly out of scope here.
9
+ //
10
+ // Audit invariant: `MemoryAuditRecord` MUST NOT carry raw memory content. It references
11
+ // affected memories by ID and pins a short, non-secret rationale string. This keeps the
12
+ // audit ledger redaction-safe and lets the audit boundary (#214) ship audit summaries
13
+ // across the wire without re-redacting.
14
+ export const MEMORY_UPDATE_FIELDS = [
15
+ "body",
16
+ "payload",
17
+ "tags",
18
+ "validity",
19
+ "sensitivity",
20
+ "retentionHint",
21
+ ];
22
+ export const MEMORY_AUDIT_INITIATOR_SURFACES = [
23
+ "memory-center",
24
+ "conversation-center",
25
+ "workflow",
26
+ "consolidation",
27
+ "retention",
28
+ "system",
29
+ ];
@@ -0,0 +1,10 @@
1
+ import type { MemoryEdge, MemoryRecord, MemoryStructuredPayload, MemoryValidityInterval } from "./memory-records.js";
2
+ import type { MemoryProvenance } from "./memory-records.js";
3
+ import type { MemoryScope, MemoryType } from "./memory.js";
4
+ import { type MemoryValidation } from "./memory-validation.js";
5
+ export declare function validateMemoryRecord(input: unknown): MemoryValidation<MemoryRecord>;
6
+ export declare function isMemoryRecord(value: unknown): value is MemoryRecord;
7
+ export declare function isMemoryEdge(value: unknown): value is MemoryEdge;
8
+ export declare function assertNeverMemoryType(value: never): never;
9
+ export type { MemoryEdge, MemoryProvenance, MemoryRecord, MemoryScope, MemoryStructuredPayload, MemoryType, MemoryValidityInterval, };
10
+ //# sourceMappingURL=memory-record-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-record-validation.d.ts","sourceRoot":"","sources":["../src/memory-record-validation.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EACV,UAAU,EACV,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE3D,OAAO,EAML,KAAK,gBAAgB,EACtB,MAAM,wBAAwB,CAAC;AAuEhC,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,YAAY,CAAC,CAmBnF;AAOD,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,YAAY,CAEpE;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,UAAU,CAEhE;AAKD,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAEzD;AAKD,YAAY,EACV,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,WAAW,EACX,uBAAuB,EACvB,UAAU,EACV,sBAAsB,GACvB,CAAC"}
@@ -0,0 +1,101 @@
1
+ // Record-level schema validators and discriminator helpers for the Governed Enterprise
2
+ // Memory Vault (Epic #204, Issue #205). Mirrors the `local-knowledge-schema-validation.ts`
3
+ // pattern: takes an `unknown`, walks the structural shape, returns either a narrowed
4
+ // `MemoryRecord` or a list of failed invariants.
5
+ //
6
+ // Also exports `isMemoryRecord`, `isMemoryEdge`, and `assertNeverMemoryType` — the three
7
+ // helpers that prove the contract distinguishes durable memory from chat history,
8
+ // connected-context KnowledgeCapsules, and local-knowledge records. The discriminator
9
+ // surface is small and load-bearing: downstream packages call these at every trust
10
+ // boundary so the four "things that look like text with provenance" do not collapse into
11
+ // each other.
12
+ import { MEMORY_SCHEMA_VERSION, MEMORY_STATUSES, MEMORY_TYPES } from "./memory.js";
13
+ import { validateMemoryEdge, validateMemoryProvenance, validateMemoryScope, validateMemoryStructuredPayload, validateMemoryValidityInterval, } from "./memory-validation.js";
14
+ import { MEMORY_BODY_MAX_CHARS, MEMORY_REASON_MAX_CHARS, isFiniteNonNegativeNumber, isMember, isNonEmptyTrimmedString, isRecord, isSafeText, pushNestedErrors, validateRetentionHint, validateTags, } from "./memory-internal.js";
15
+ function validateRecordSchemaVersion(input, errors) {
16
+ if (input.schemaVersion !== MEMORY_SCHEMA_VERSION) {
17
+ errors.push(`record.schemaVersion must be the literal "${MEMORY_SCHEMA_VERSION}"`);
18
+ }
19
+ }
20
+ function validateRecordEnums(input, errors) {
21
+ if (!isMember(input.type, MEMORY_TYPES)) {
22
+ errors.push(`record.type must be one of ${MEMORY_TYPES.join("|")}`);
23
+ }
24
+ if (!isMember(input.status, MEMORY_STATUSES)) {
25
+ errors.push(`record.status must be one of ${MEMORY_STATUSES.join("|")}`);
26
+ }
27
+ }
28
+ function validateRecordTimestamps(input, errors) {
29
+ if (!isFiniteNonNegativeNumber(input.createdAt)) {
30
+ errors.push("record.createdAt must be a finite non-negative number");
31
+ }
32
+ if (!isFiniteNonNegativeNumber(input.updatedAt)) {
33
+ errors.push("record.updatedAt must be a finite non-negative number");
34
+ }
35
+ if (isFiniteNonNegativeNumber(input.createdAt) &&
36
+ isFiniteNonNegativeNumber(input.updatedAt) &&
37
+ input.updatedAt < input.createdAt) {
38
+ errors.push("record.updatedAt must be greater than or equal to record.createdAt");
39
+ }
40
+ }
41
+ function validateRecordCoreShape(input, errors) {
42
+ if (!isNonEmptyTrimmedString(input.id)) {
43
+ errors.push("record.id must be a non-empty string");
44
+ }
45
+ if (!isSafeText(input.body, MEMORY_BODY_MAX_CHARS)) {
46
+ errors.push("record.body must be a bounded control-free non-empty string");
47
+ }
48
+ if (typeof input.pinned !== "boolean") {
49
+ errors.push("record.pinned must be a boolean");
50
+ }
51
+ if (input.staleReason !== undefined && !isSafeText(input.staleReason, MEMORY_REASON_MAX_CHARS)) {
52
+ errors.push("record.staleReason must be a bounded control-free string when set");
53
+ }
54
+ validateRecordEnums(input, errors);
55
+ validateRecordTimestamps(input, errors);
56
+ }
57
+ function validateRecordRetentionHint(input, errors) {
58
+ const hint = input.retentionHint;
59
+ if (hint === undefined) {
60
+ return;
61
+ }
62
+ validateRetentionHint("record.retentionHint", hint, errors);
63
+ }
64
+ // ─── validateMemoryRecord ─────────────────────────────────────────────────────
65
+ export function validateMemoryRecord(input) {
66
+ if (!isRecord(input)) {
67
+ return { ok: false, errors: ["record must be an object"] };
68
+ }
69
+ const errors = [];
70
+ validateRecordSchemaVersion(input, errors);
71
+ pushNestedErrors("record", validateMemoryScope(input.scope), errors);
72
+ validateRecordCoreShape(input, errors);
73
+ if (input.payload !== undefined) {
74
+ pushNestedErrors("record", validateMemoryStructuredPayload(input.payload), errors);
75
+ }
76
+ pushNestedErrors("record", validateMemoryProvenance(input.provenance), errors);
77
+ pushNestedErrors("record", validateMemoryValidityInterval(input.validity), errors);
78
+ validateTags("record.tags", input.tags, errors);
79
+ validateRecordRetentionHint(input, errors);
80
+ if (errors.length > 0) {
81
+ return { ok: false, errors };
82
+ }
83
+ return { ok: true, value: input };
84
+ }
85
+ // ─── Predicates ───────────────────────────────────────────────────────────────
86
+ // `isMemoryRecord` returns true only for values that pass the full record validator. The
87
+ // distinction matters at the trust boundary: a chat message, a KnowledgeCapsule, or a
88
+ // local-knowledge ChunkRecord may share some structural fields with a MemoryRecord but
89
+ // none of them carries the (scope coordinate + provenance + status) triple together.
90
+ export function isMemoryRecord(value) {
91
+ return validateMemoryRecord(value).ok;
92
+ }
93
+ export function isMemoryEdge(value) {
94
+ return validateMemoryEdge(value).ok;
95
+ }
96
+ // `assertNeverMemoryType` proves the type union is exhausted at compile time. Call this
97
+ // in the default branch of a switch over `MemoryType`; a future contract version that
98
+ // adds a new type produces a compile error here, not a silent runtime fall-through.
99
+ export function assertNeverMemoryType(value) {
100
+ throw new Error(`unhandled MemoryType: ${String(value)}`);
101
+ }
@@ -0,0 +1,66 @@
1
+ import type { ConversationId, EvidenceManifestId, MemoryEdgeId, MemoryEdgeKind, MemoryId, MemoryScope, MemorySensitivity, MemorySourceKind, MemoryStatus, MemoryType, WorkflowRunId } from "./memory.js";
2
+ export interface MemoryModelIdentity {
3
+ readonly provider: string;
4
+ readonly modelId: string;
5
+ readonly modelRevision?: string;
6
+ }
7
+ export interface MemoryProvenance {
8
+ readonly sourceKind: MemorySourceKind;
9
+ readonly sourceConversationId?: ConversationId;
10
+ readonly sourceWorkflowRunId?: WorkflowRunId;
11
+ readonly sourceEvidenceManifestId?: EvidenceManifestId;
12
+ readonly capturedAt: number;
13
+ readonly modelIdentity?: MemoryModelIdentity;
14
+ readonly confidence: number;
15
+ readonly sensitivity: MemorySensitivity;
16
+ readonly captureRationale?: string;
17
+ }
18
+ export interface MemoryValidityInterval {
19
+ readonly validFrom: number;
20
+ readonly validUntil?: number;
21
+ }
22
+ export interface MemoryRetentionHint {
23
+ readonly policyKey: string;
24
+ readonly retainUntil?: number;
25
+ readonly notes?: string;
26
+ }
27
+ export interface MemoryRecord {
28
+ readonly id: MemoryId;
29
+ readonly schemaVersion: "1";
30
+ readonly scope: MemoryScope;
31
+ readonly type: MemoryType;
32
+ readonly body: string;
33
+ readonly payload?: MemoryStructuredPayload;
34
+ readonly provenance: MemoryProvenance;
35
+ readonly validity: MemoryValidityInterval;
36
+ readonly status: MemoryStatus;
37
+ readonly pinned: boolean;
38
+ readonly staleReason?: string;
39
+ readonly retentionHint?: MemoryRetentionHint;
40
+ readonly tags: readonly string[];
41
+ readonly createdAt: number;
42
+ readonly updatedAt: number;
43
+ }
44
+ export type MemoryStructuredPayload = {
45
+ readonly kind: "string-list";
46
+ readonly items: readonly string[];
47
+ } | {
48
+ readonly kind: "key-value";
49
+ readonly entries: readonly {
50
+ readonly key: string;
51
+ readonly value: string;
52
+ }[];
53
+ };
54
+ export type MemoryStructuredPayloadKind = MemoryStructuredPayload["kind"];
55
+ export declare const MEMORY_STRUCTURED_PAYLOAD_KINDS: readonly MemoryStructuredPayloadKind[];
56
+ export interface MemoryEdge {
57
+ readonly id: MemoryEdgeId;
58
+ readonly schemaVersion: "1";
59
+ readonly fromMemoryId: MemoryId;
60
+ readonly toMemoryId: MemoryId;
61
+ readonly kind: MemoryEdgeKind;
62
+ readonly createdAt: number;
63
+ readonly confidence?: number;
64
+ readonly provenanceSummary?: string;
65
+ }
66
+ //# sourceMappingURL=memory-records.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-records.d.ts","sourceRoot":"","sources":["../src/memory-records.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EACV,cAAc,EACd,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,QAAQ,EACR,WAAW,EACX,iBAAiB,EACjB,gBAAgB,EAChB,YAAY,EACZ,UAAU,EACV,aAAa,EACd,MAAM,aAAa,CAAC;AAUrB,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAC;CACjC;AAaD,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,UAAU,EAAE,gBAAgB,CAAC;IACtC,QAAQ,CAAC,oBAAoB,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