@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,22 @@
1
+ // Memory record contracts for the Governed Enterprise Memory Vault (Epic #204, Issue
2
+ // #205). Split from `memory.ts` to keep each file under the 400-LOC budget. Pure types
3
+ // only — no IO, no clock reads, no randomness. Leaf-package rule (ADR-0019 direction 1):
4
+ // no `@oscharko-dev/keiko-*` imports.
5
+ //
6
+ // Foundational invariants encoded structurally:
7
+ // 1. `MemoryRecord.scope` is the discriminated scope coordinate from `MemoryScope`.
8
+ // A record without a concrete scope coordinate cannot be constructed, so two records
9
+ // at "different scopes" are NEVER structurally equal — the discriminator owns identity.
10
+ // 2. `MemoryRecord.provenance` is REQUIRED on every durable memory. There is no optional
11
+ // escape hatch. The capture layer (#207) MUST attach provenance before the record can
12
+ // be persisted.
13
+ // 3. `MemoryRecord.sensitivity` lives on the provenance envelope because sensitivity is
14
+ // intrinsic to the SOURCE of the memory, not a downstream label. A record cannot be
15
+ // re-classified by mutating a separate field; sensitivity changes require a
16
+ // supersession.
17
+ // 4. Timestamps are epoch milliseconds (number). JSON-friendly and Date-free so the type
18
+ // surface is browser-safe and round-trip-stable.
19
+ export const MEMORY_STRUCTURED_PAYLOAD_KINDS = [
20
+ "string-list",
21
+ "key-value",
22
+ ];
@@ -0,0 +1,6 @@
1
+ import type { MemoryRetrievalRequest } from "./memory-operations.js";
2
+ import type { MemoryScope } from "./memory.js";
3
+ import { type MemoryValidation } from "./memory-validation.js";
4
+ export declare function validateMemoryRetrievalRequest(input: unknown): MemoryValidation<MemoryRetrievalRequest>;
5
+ export declare function isScopeReachable(candidate: MemoryScope, authorized: readonly MemoryScope[]): boolean;
6
+ //# sourceMappingURL=memory-retrieval-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-retrieval-validation.d.ts","sourceRoot":"","sources":["../src/memory-retrieval-validation.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,OAAO,EAAuB,KAAK,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AA2EpF,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,GACb,gBAAgB,CAAC,sBAAsB,CAAC,CAgB1C;AAsBD,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,WAAW,EACtB,UAAU,EAAE,SAAS,WAAW,EAAE,GACjC,OAAO,CAQT"}
@@ -0,0 +1,108 @@
1
+ // Pure validators for memory retrieval (Epic #204, Issue #205). Sibling of
2
+ // `memory-operations-validation.ts`. Split into its own module so each file stays under
3
+ // the 400-LOC budget, and so the retrieval surface — which downstream packages (#210)
4
+ // will iterate on more aggressively than the rest — has a stable, narrow import path.
5
+ //
6
+ // `isScopeReachable` lives here next to the retrieval-request validator because the same
7
+ // caller that constructs the request needs to verify, before issuing it, that each scope
8
+ // it intends to query is in the authorized set. Both helpers are pure and clock-free.
9
+ import { MEMORY_STATUSES, MEMORY_TYPES } from "./memory.js";
10
+ import { validateMemoryScope } from "./memory-validation.js";
11
+ import { MEMORY_BODY_MAX_CHARS, isFiniteNonNegativeNumber, isFinitePositiveInteger, isMember, isRecord, isSafeText, pushNestedErrors, validateSchemaVersionLiteral, validateTags, } from "./memory-internal.js";
12
+ function validateRetrievalScopes(input, errors) {
13
+ if (!Array.isArray(input) || input.length === 0) {
14
+ errors.push("retrieval.scopes must be a non-empty array");
15
+ return;
16
+ }
17
+ for (const candidate of input) {
18
+ pushNestedErrors("retrieval", validateMemoryScope(candidate), errors);
19
+ }
20
+ }
21
+ function validateRetrievalEnumFilter(field, values, allowed, errors) {
22
+ if (values === undefined) {
23
+ return;
24
+ }
25
+ if (!Array.isArray(values) || values.length === 0) {
26
+ errors.push(`retrieval.${field} must be a non-empty array when set`);
27
+ return;
28
+ }
29
+ for (const value of values) {
30
+ if (!isMember(value, allowed)) {
31
+ errors.push(`retrieval.${field} entry must be one of ${allowed.join("|")}`);
32
+ return;
33
+ }
34
+ }
35
+ }
36
+ function validateRetrievalNumericLimit(field, value, errors) {
37
+ if (value === undefined) {
38
+ return;
39
+ }
40
+ if (!isFinitePositiveInteger(value)) {
41
+ errors.push(`retrieval.${field} must be a positive integer when set`);
42
+ }
43
+ }
44
+ function validateRetrievalFilters(input, errors) {
45
+ validateRetrievalEnumFilter("typeFilter", input.typeFilter, MEMORY_TYPES, errors);
46
+ validateRetrievalEnumFilter("statusFilter", input.statusFilter, MEMORY_STATUSES, errors);
47
+ if (input.textQuery !== undefined && !isSafeText(input.textQuery, MEMORY_BODY_MAX_CHARS)) {
48
+ errors.push("retrieval.textQuery must be a bounded control-free string when set");
49
+ }
50
+ if (input.tagsFilter !== undefined) {
51
+ validateTags("retrieval.tagsFilter", input.tagsFilter, errors);
52
+ }
53
+ }
54
+ function validateRetrievalBudgetAndToggles(input, errors) {
55
+ validateRetrievalNumericLimit("maxResults", input.maxResults, errors);
56
+ validateRetrievalNumericLimit("maxBodyChars", input.maxBodyChars, errors);
57
+ if (input.includeArchived !== undefined && typeof input.includeArchived !== "boolean") {
58
+ errors.push("retrieval.includeArchived must be a boolean when set");
59
+ }
60
+ if (input.includeSuperseded !== undefined && typeof input.includeSuperseded !== "boolean") {
61
+ errors.push("retrieval.includeSuperseded must be a boolean when set");
62
+ }
63
+ }
64
+ export function validateMemoryRetrievalRequest(input) {
65
+ if (!isRecord(input)) {
66
+ return { ok: false, errors: ["retrieval must be an object"] };
67
+ }
68
+ const errors = [];
69
+ validateSchemaVersionLiteral(input, errors);
70
+ if (!isFiniteNonNegativeNumber(input.requestedAt)) {
71
+ errors.push("retrieval.requestedAt must be a finite non-negative number");
72
+ }
73
+ validateRetrievalScopes(input.scopes, errors);
74
+ validateRetrievalFilters(input, errors);
75
+ validateRetrievalBudgetAndToggles(input, errors);
76
+ if (errors.length > 0) {
77
+ return { ok: false, errors };
78
+ }
79
+ return { ok: true, value: input };
80
+ }
81
+ // A canonical coordinate string per scope. Distinct scope kinds always produce strings
82
+ // with distinct kind prefixes, so a `userId` equal to a `workspaceId` cannot collide.
83
+ // `global` carries a fixed coordinate so set membership remains a pure string compare.
84
+ function scopeCoordinateKey(scope) {
85
+ switch (scope.kind) {
86
+ case "global":
87
+ return "global:";
88
+ case "user":
89
+ return `user:${scope.userId}`;
90
+ case "workspace":
91
+ return `workspace:${scope.workspaceId}`;
92
+ case "project":
93
+ return `project:${scope.projectId}`;
94
+ case "workflow":
95
+ return `workflow:${scope.workflowDefinitionId}`;
96
+ }
97
+ }
98
+ // A candidate scope is reachable when an authorized scope shares the same canonical
99
+ // coordinate. This is the type-level anchor for the no-cross-scope-visibility invariant.
100
+ export function isScopeReachable(candidate, authorized) {
101
+ const target = scopeCoordinateKey(candidate);
102
+ for (const scope of authorized) {
103
+ if (scopeCoordinateKey(scope) === target) {
104
+ return true;
105
+ }
106
+ }
107
+ return false;
108
+ }
@@ -0,0 +1,31 @@
1
+ import type { MemoryEdge, MemoryProvenance, MemoryRecord, MemoryStructuredPayload, MemoryValidityInterval } from "./memory-records.js";
2
+ import type { MemoryScope, MemoryStatus } from "./memory.js";
3
+ export interface MemoryValidationOk<T> {
4
+ readonly ok: true;
5
+ readonly value: T;
6
+ }
7
+ export interface MemoryValidationFail {
8
+ readonly ok: false;
9
+ readonly errors: readonly string[];
10
+ }
11
+ export type MemoryValidation<T> = MemoryValidationOk<T> | MemoryValidationFail;
12
+ export declare function looksLikeSecretShape(value: string): boolean;
13
+ export interface StatusTransitionCheck {
14
+ readonly ok: boolean;
15
+ readonly reason?: string;
16
+ }
17
+ export declare function checkStatusTransition(from: MemoryStatus, to: MemoryStatus): StatusTransitionCheck;
18
+ export declare function validateMemoryScope(input: unknown): MemoryValidation<MemoryScope>;
19
+ export declare function validateMemoryValidityInterval(input: unknown): MemoryValidation<MemoryValidityInterval>;
20
+ export declare function validateMemoryProvenance(input: unknown): MemoryValidation<MemoryProvenance>;
21
+ export declare function validateMemoryStructuredPayload(input: unknown): MemoryValidation<MemoryStructuredPayload>;
22
+ export declare function validateMemoryEdge(input: unknown): MemoryValidation<MemoryEdge>;
23
+ export interface StaleModelMetadataInput {
24
+ readonly record: Pick<MemoryRecord, "provenance">;
25
+ readonly activeIdentitiesByProvider: ReadonlyMap<string, {
26
+ readonly modelId: string;
27
+ readonly modelRevision?: string;
28
+ }>;
29
+ }
30
+ export declare function hasStaleModelMetadata(input: StaleModelMetadataInput): boolean;
31
+ //# sourceMappingURL=memory-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-validation.d.ts","sourceRoot":"","sources":["../src/memory-validation.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,EACV,UAAU,EACV,gBAAgB,EAChB,YAAY,EACZ,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAuB7D,MAAM,WAAW,kBAAkB,CAAC,CAAC;IACnC,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAClB,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAC;CACnB;AACD,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAC;IACnB,QAAQ,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,CAAC;CACpC;AACD,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAAI,kBAAkB,CAAC,CAAC,CAAC,GAAG,oBAAoB,CAAC;AA2D/E,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAO3D;AAKD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,EAAE,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC;CAC1B;AAED,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,YAAY,GAAG,qBAAqB,CAejG;AA0BD,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,WAAW,CAAC,CAajF;AAGD,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,OAAO,GACb,gBAAgB,CAAC,sBAAsB,CAAC,CAmB1C;AAuBD,wBAAgB,wBAAwB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,CAmC3F;AAoCD,wBAAgB,+BAA+B,CAC7C,KAAK,EAAE,OAAO,GACb,gBAAgB,CAAC,uBAAuB,CAAC,CAoB3C;AA+BD,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAuB/E;AAMD,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;IAClD,QAAQ,CAAC,0BAA0B,EAAE,WAAW,CAC9C,MAAM,EACN;QAAE,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,CAC9D,CAAC;CACH;AAED,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,uBAAuB,GAAG,OAAO,CAoB7E"}
@@ -0,0 +1,318 @@
1
+ // Pure validators for the Governed Enterprise Memory Vault contracts (Epic #204, Issue
2
+ // #205). No filesystem, no clock, no crypto, no randomness — every helper inspects the
3
+ // structure of an `unknown` payload and reports which invariants failed. Producers and
4
+ // consumers wire these at trust-boundary edges (BFF, audit, capture, retrieval).
5
+ //
6
+ // Result envelopes follow the local-knowledge convention: a discriminated
7
+ // `{ ok: true; value } | { ok: false; errors }` so branches stay throw-free. Errors are
8
+ // short, machine-readable strings — one per failed invariant — for deterministic
9
+ // evaluation-harness diffs.
10
+ //
11
+ // Operation envelope validators (proposal/acceptance/rejection/update/etc.) live in the
12
+ // sibling module `memory-operations-validation.ts` to keep both files under the 400-LOC
13
+ // budget.
14
+ import { MEMORY_EDGE_KINDS, MEMORY_SCOPE_KINDS, MEMORY_SENSITIVITIES, MEMORY_SOURCE_KINDS, MEMORY_STATUSES, MEMORY_STATUS_TRANSITIONS, } from "./memory.js";
15
+ import { MEMORY_STRUCTURED_PAYLOAD_KINDS } from "./memory-records.js";
16
+ import { FORBIDDEN_CONTROL_RE, MEMORY_RATIONALE_MAX_CHARS, isFiniteNonNegativeNumber, isMember, isNonEmptyTrimmedString, isRecord, isSafeText, isUnitInterval, validateOptionalReference, } from "./memory-internal.js";
17
+ // ─── Unsafe-content heuristics (secret-shape only, no allow/block list) ──────
18
+ // Audit-record defence-in-depth: rejects credential-shaped strings on the AUDIT SUMMARY
19
+ // path (validateMemoryAuditRecord). The PRIMARY secret-prevention gate is the capture
20
+ // layer (#207), which scans candidate memory body/payload before construction. This
21
+ // helper is intentionally NOT applied to record.body or proposal.body — body scanning is
22
+ // owned end-to-end by the capture layer so callers cannot route around the policy by
23
+ // constructing records directly. Shape-based: we test the SHAPE of the string, not a
24
+ // list of providers, so the heuristic stays useful across vendor changes.
25
+ //
26
+ // Pattern coverage — intentionally narrow (high precision over high recall):
27
+ // COVERED: sk- (OpenAI-style), AKIA (AWS), gh[pousr]_ (GitHub tokens),
28
+ // xox[abporsu]- (Slack), three-part JWTs, PEM private keys,
29
+ // long contiguous digit runs that resemble a payment-card PAN.
30
+ // EXCLUDED: opaque "Bearer <token>" (catches only JWT-encoded bearers),
31
+ // URL-embedded credentials (https://user:pass@host),
32
+ // generic password=, secret=, key= form-encoded values.
33
+ // These classes are intentionally deferred to the capture layer
34
+ // (#207), where context-aware redaction can avoid false positives
35
+ // on legitimate non-secret strings.
36
+ const SECRET_SHAPE_PATTERNS = [
37
+ /\bsk-[A-Za-z0-9_-]{20,}\b/,
38
+ /\bAKIA[0-9A-Z]{16}\b/,
39
+ /\bgh[pousr]_[A-Za-z0-9]{36,}\b/,
40
+ /\bxox[abporsu]-[A-Za-z0-9-]{10,}\b/,
41
+ /\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/,
42
+ /-----BEGIN [A-Z ]*PRIVATE KEY-----/,
43
+ ];
44
+ const PAN_SHAPE_RE = /\b(?:\d[ -]?){13,19}\b/g;
45
+ function passesLuhn(value) {
46
+ let sum = 0;
47
+ let shouldDouble = false;
48
+ for (let index = value.length - 1; index >= 0; index -= 1) {
49
+ let digit = Number(value[index]);
50
+ if (shouldDouble) {
51
+ digit *= 2;
52
+ if (digit > 9) {
53
+ digit -= 9;
54
+ }
55
+ }
56
+ sum += digit;
57
+ shouldDouble = !shouldDouble;
58
+ }
59
+ return sum % 10 === 0;
60
+ }
61
+ function hasPaymentCardPanShape(value) {
62
+ for (const match of value.matchAll(PAN_SHAPE_RE)) {
63
+ const candidate = match[0].replaceAll(/[ -]/g, "");
64
+ if (candidate.length >= 13 && candidate.length <= 19 && passesLuhn(candidate)) {
65
+ return true;
66
+ }
67
+ }
68
+ return false;
69
+ }
70
+ export function looksLikeSecretShape(value) {
71
+ for (const re of SECRET_SHAPE_PATTERNS) {
72
+ if (re.test(value)) {
73
+ return true;
74
+ }
75
+ }
76
+ return hasPaymentCardPanShape(value);
77
+ }
78
+ export function checkStatusTransition(from, to) {
79
+ if (!isMember(from, MEMORY_STATUSES)) {
80
+ return { ok: false, reason: `unknown from-status: ${String(from)}` };
81
+ }
82
+ if (!isMember(to, MEMORY_STATUSES)) {
83
+ return { ok: false, reason: `unknown to-status: ${String(to)}` };
84
+ }
85
+ if (from === to) {
86
+ return { ok: false, reason: `no-op transition: ${from} → ${to}` };
87
+ }
88
+ const allowed = MEMORY_STATUS_TRANSITIONS[from];
89
+ if (!allowed.includes(to)) {
90
+ return { ok: false, reason: `illegal transition: ${from} → ${to}` };
91
+ }
92
+ return { ok: true };
93
+ }
94
+ // ─── Scope ────────────────────────────────────────────────────────────────────
95
+ // The validator checks that the coordinate field that MUST be present for the given kind
96
+ // is a non-empty string. Scope-CROSSING legality (i.e. "can a request at scope X read a
97
+ // record at scope Y") is an authorization decision belonging to downstream layers; this
98
+ // validator only proves the scope itself is well-formed.
99
+ function validateScopeCoordinate(input, errors) {
100
+ const kind = input.kind;
101
+ if (kind === "global") {
102
+ return;
103
+ }
104
+ if (kind === "user" && !isNonEmptyTrimmedString(input.userId)) {
105
+ errors.push("scope.userId must be a non-empty string for kind=user");
106
+ }
107
+ if (kind === "workspace" && !isNonEmptyTrimmedString(input.workspaceId)) {
108
+ errors.push("scope.workspaceId must be a non-empty string for kind=workspace");
109
+ }
110
+ if (kind === "project" && !isNonEmptyTrimmedString(input.projectId)) {
111
+ errors.push("scope.projectId must be a non-empty string for kind=project");
112
+ }
113
+ if (kind === "workflow" && !isNonEmptyTrimmedString(input.workflowDefinitionId)) {
114
+ errors.push("scope.workflowDefinitionId must be a non-empty string for kind=workflow");
115
+ }
116
+ }
117
+ export function validateMemoryScope(input) {
118
+ if (!isRecord(input)) {
119
+ return { ok: false, errors: ["scope must be an object"] };
120
+ }
121
+ if (!isMember(input.kind, MEMORY_SCOPE_KINDS)) {
122
+ return { ok: false, errors: [`scope.kind must be one of ${MEMORY_SCOPE_KINDS.join("|")}`] };
123
+ }
124
+ const errors = [];
125
+ validateScopeCoordinate(input, errors);
126
+ if (errors.length > 0) {
127
+ return { ok: false, errors };
128
+ }
129
+ return { ok: true, value: input };
130
+ }
131
+ // ─── Validity interval ────────────────────────────────────────────────────────
132
+ export function validateMemoryValidityInterval(input) {
133
+ if (!isRecord(input)) {
134
+ return { ok: false, errors: ["validity must be an object"] };
135
+ }
136
+ const errors = [];
137
+ if (!isFiniteNonNegativeNumber(input.validFrom)) {
138
+ errors.push("validity.validFrom must be a finite non-negative number");
139
+ }
140
+ if (input.validUntil !== undefined) {
141
+ if (!isFiniteNonNegativeNumber(input.validUntil)) {
142
+ errors.push("validity.validUntil must be a finite non-negative number when set");
143
+ }
144
+ else if (isFiniteNonNegativeNumber(input.validFrom) && input.validUntil < input.validFrom) {
145
+ errors.push("validity.validUntil must be greater than or equal to validFrom");
146
+ }
147
+ }
148
+ if (errors.length > 0) {
149
+ return { ok: false, errors };
150
+ }
151
+ return { ok: true, value: input };
152
+ }
153
+ // ─── Provenance ───────────────────────────────────────────────────────────────
154
+ function validateModelIdentity(input, errors) {
155
+ const identity = input.modelIdentity;
156
+ if (identity === undefined) {
157
+ return;
158
+ }
159
+ if (!isRecord(identity)) {
160
+ errors.push("provenance.modelIdentity must be an object when set");
161
+ return;
162
+ }
163
+ if (!isNonEmptyTrimmedString(identity.provider)) {
164
+ errors.push("provenance.modelIdentity.provider must be a non-empty string");
165
+ }
166
+ if (!isNonEmptyTrimmedString(identity.modelId)) {
167
+ errors.push("provenance.modelIdentity.modelId must be a non-empty string");
168
+ }
169
+ if (identity.modelRevision !== undefined && !isNonEmptyTrimmedString(identity.modelRevision)) {
170
+ errors.push("provenance.modelIdentity.modelRevision must be a non-empty string when set");
171
+ }
172
+ }
173
+ export function validateMemoryProvenance(input) {
174
+ if (!isRecord(input)) {
175
+ return { ok: false, errors: ["provenance must be an object"] };
176
+ }
177
+ const errors = [];
178
+ if (!isMember(input.sourceKind, MEMORY_SOURCE_KINDS)) {
179
+ errors.push(`provenance.sourceKind must be one of ${MEMORY_SOURCE_KINDS.join("|")}`);
180
+ }
181
+ validateOptionalReference("provenance.sourceConversationId", input.sourceConversationId, errors);
182
+ validateOptionalReference("provenance.sourceWorkflowRunId", input.sourceWorkflowRunId, errors);
183
+ validateOptionalReference("provenance.sourceEvidenceManifestId", input.sourceEvidenceManifestId, errors);
184
+ if (!isFiniteNonNegativeNumber(input.capturedAt)) {
185
+ errors.push("provenance.capturedAt must be a finite non-negative number");
186
+ }
187
+ validateModelIdentity(input, errors);
188
+ if (!isUnitInterval(input.confidence)) {
189
+ errors.push("provenance.confidence must be a finite number in [0, 1]");
190
+ }
191
+ if (!isMember(input.sensitivity, MEMORY_SENSITIVITIES)) {
192
+ errors.push(`provenance.sensitivity must be one of ${MEMORY_SENSITIVITIES.join("|")}`);
193
+ }
194
+ if (input.captureRationale !== undefined &&
195
+ !isSafeText(input.captureRationale, MEMORY_RATIONALE_MAX_CHARS)) {
196
+ errors.push("provenance.captureRationale must be a bounded control-free string when set");
197
+ }
198
+ if (errors.length > 0) {
199
+ return { ok: false, errors };
200
+ }
201
+ return { ok: true, value: input };
202
+ }
203
+ // ─── Structured payload ───────────────────────────────────────────────────────
204
+ function validateStringListPayload(input, errors) {
205
+ if (!Array.isArray(input.items)) {
206
+ errors.push("payload.items must be an array for kind=string-list");
207
+ return;
208
+ }
209
+ for (const item of input.items) {
210
+ if (typeof item !== "string" || item.length === 0 || FORBIDDEN_CONTROL_RE.test(item)) {
211
+ errors.push("payload.items entry must be a non-empty control-free string");
212
+ return;
213
+ }
214
+ }
215
+ }
216
+ function validateKeyValuePayload(input, errors) {
217
+ if (!Array.isArray(input.entries)) {
218
+ errors.push("payload.entries must be an array for kind=key-value");
219
+ return;
220
+ }
221
+ for (const entry of input.entries) {
222
+ if (!isRecord(entry) ||
223
+ !isNonEmptyTrimmedString(entry.key) ||
224
+ typeof entry.value !== "string" ||
225
+ FORBIDDEN_CONTROL_RE.test(entry.value)) {
226
+ errors.push("payload.entries entry must have a non-empty key and a control-free string value");
227
+ return;
228
+ }
229
+ }
230
+ }
231
+ export function validateMemoryStructuredPayload(input) {
232
+ if (!isRecord(input)) {
233
+ return { ok: false, errors: ["payload must be an object"] };
234
+ }
235
+ if (!isMember(input.kind, MEMORY_STRUCTURED_PAYLOAD_KINDS)) {
236
+ return {
237
+ ok: false,
238
+ errors: [`payload.kind must be one of ${MEMORY_STRUCTURED_PAYLOAD_KINDS.join("|")}`],
239
+ };
240
+ }
241
+ const errors = [];
242
+ if (input.kind === "string-list") {
243
+ validateStringListPayload(input, errors);
244
+ }
245
+ else {
246
+ validateKeyValuePayload(input, errors);
247
+ }
248
+ if (errors.length > 0) {
249
+ return { ok: false, errors };
250
+ }
251
+ return { ok: true, value: input };
252
+ }
253
+ // ─── Edge ─────────────────────────────────────────────────────────────────────
254
+ function validateEdgeEndpoints(input, errors) {
255
+ if (!isNonEmptyTrimmedString(input.fromMemoryId)) {
256
+ errors.push("edge.fromMemoryId must be a non-empty string");
257
+ }
258
+ if (!isNonEmptyTrimmedString(input.toMemoryId)) {
259
+ errors.push("edge.toMemoryId must be a non-empty string");
260
+ }
261
+ if (isNonEmptyTrimmedString(input.fromMemoryId) &&
262
+ isNonEmptyTrimmedString(input.toMemoryId) &&
263
+ input.fromMemoryId === input.toMemoryId) {
264
+ errors.push("edge.fromMemoryId and edge.toMemoryId must differ");
265
+ }
266
+ }
267
+ function validateEdgeOptionalFields(input, errors) {
268
+ if (input.confidence !== undefined && !isUnitInterval(input.confidence)) {
269
+ errors.push("edge.confidence must be a finite number in [0, 1] when set");
270
+ }
271
+ if (input.provenanceSummary !== undefined &&
272
+ !isSafeText(input.provenanceSummary, MEMORY_RATIONALE_MAX_CHARS)) {
273
+ errors.push("edge.provenanceSummary must be a bounded control-free string when set");
274
+ }
275
+ }
276
+ export function validateMemoryEdge(input) {
277
+ if (!isRecord(input)) {
278
+ return { ok: false, errors: ["edge must be an object"] };
279
+ }
280
+ const errors = [];
281
+ if (input.schemaVersion !== "1") {
282
+ errors.push('edge.schemaVersion must be the literal "1"');
283
+ }
284
+ if (!isNonEmptyTrimmedString(input.id)) {
285
+ errors.push("edge.id must be a non-empty string");
286
+ }
287
+ validateEdgeEndpoints(input, errors);
288
+ if (!isMember(input.kind, MEMORY_EDGE_KINDS)) {
289
+ errors.push(`edge.kind must be one of ${MEMORY_EDGE_KINDS.join("|")}`);
290
+ }
291
+ if (!isFiniteNonNegativeNumber(input.createdAt)) {
292
+ errors.push("edge.createdAt must be a finite non-negative number");
293
+ }
294
+ validateEdgeOptionalFields(input, errors);
295
+ if (errors.length > 0) {
296
+ return { ok: false, errors };
297
+ }
298
+ return { ok: true, value: input };
299
+ }
300
+ export function hasStaleModelMetadata(input) {
301
+ const identity = input.record.provenance.modelIdentity;
302
+ if (identity === undefined) {
303
+ return false;
304
+ }
305
+ const active = input.activeIdentitiesByProvider.get(identity.provider);
306
+ if (active === undefined) {
307
+ return true;
308
+ }
309
+ if (active.modelId !== identity.modelId) {
310
+ return true;
311
+ }
312
+ if (identity.modelRevision !== undefined &&
313
+ active.modelRevision !== undefined &&
314
+ identity.modelRevision !== active.modelRevision) {
315
+ return true;
316
+ }
317
+ return false;
318
+ }
@@ -0,0 +1,26 @@
1
+ import type { MemoryId, MemoryScope } from "./memory.js";
2
+ export interface MemoryWorkflowContext {
3
+ readonly text: string;
4
+ readonly includedMemoryIds: readonly MemoryId[];
5
+ }
6
+ export interface MemoryUsedEvent {
7
+ readonly memoryIds: readonly MemoryId[];
8
+ readonly scopes: readonly MemoryScope[];
9
+ readonly reason: string;
10
+ }
11
+ export interface MemoryOmittedEvent {
12
+ readonly memoryId: MemoryId;
13
+ readonly reason: string;
14
+ }
15
+ export interface MemoryWriteCandidateEvent {
16
+ readonly proposalSummary: string;
17
+ readonly scope: MemoryScope;
18
+ readonly source: "workflow-success" | "workflow-correction";
19
+ }
20
+ export interface MemoryWorkflowPort {
21
+ readonly getContextForWorkflow: (scopes: readonly MemoryScope[], queryText?: string, budgetTokens?: number) => Promise<MemoryWorkflowContext>;
22
+ readonly onMemoryUsed?: (event: MemoryUsedEvent) => void;
23
+ readonly onMemoryOmitted?: (event: MemoryOmittedEvent) => void;
24
+ readonly onMemoryWriteCandidate?: (event: MemoryWriteCandidateEvent) => void;
25
+ }
26
+ //# sourceMappingURL=memory-workflow-port.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory-workflow-port.d.ts","sourceRoot":"","sources":["../src/memory-workflow-port.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAOzD,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,iBAAiB,EAAE,SAAS,QAAQ,EAAE,CAAC;CACjD;AAKD,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,SAAS,EAAE,SAAS,QAAQ,EAAE,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,SAAS,WAAW,EAAE,CAAC;IACxC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAOD,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,QAAQ,EAAE,QAAQ,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;CACzB;AAOD,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,eAAe,EAAE,MAAM,CAAC;IACjC,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;IAC5B,QAAQ,CAAC,MAAM,EAAE,kBAAkB,GAAG,qBAAqB,CAAC;CAC7D;AAED,MAAM,WAAW,kBAAkB;IAIjC,QAAQ,CAAC,qBAAqB,EAAE,CAC9B,MAAM,EAAE,SAAS,WAAW,EAAE,EAC9B,SAAS,CAAC,EAAE,MAAM,EAClB,YAAY,CAAC,EAAE,MAAM,KAClB,OAAO,CAAC,qBAAqB,CAAC,CAAC;IAIpC,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,CAAC;IAKzD,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAG/D,QAAQ,CAAC,sBAAsB,CAAC,EAAE,CAAC,KAAK,EAAE,yBAAyB,KAAK,IAAI,CAAC;CAC9E"}
@@ -0,0 +1,13 @@
1
+ // Workflow-facing port for the Governed Enterprise Memory Vault (Epic #204, Issue #213).
2
+ // Pure type contract — no runtime logic, no IO, no clock, no randomness. Leaf-package rule
3
+ // (ADR-0019 direction 1): no `@oscharko-dev/keiko-*` imports may appear in this module; all
4
+ // referenced types come from sibling modules inside @oscharko-dev/keiko-contracts.
5
+ //
6
+ // Boundary intent: workflow packages (`keiko-workflows`, future `keiko-evaluations`) accept
7
+ // an OPTIONAL `MemoryWorkflowPort` so they can compose pre-run memory context and emit
8
+ // post-run lifecycle events for the audit ledger and MemoriaViva UI. Memory is READ-ONLY
9
+ // from the workflow's perspective — the port cannot grant write/execution authority. Apply
10
+ // gates (#6 applyEnabled, patch limits, scope guards) remain the sole write surface
11
+ // (epic §Architecture Invariants 1+2). The workflow remains fully backward-compatible when
12
+ // the port is absent: the field is optional and every callback is optional.
13
+ export {};
@@ -0,0 +1,81 @@
1
+ export declare const MEMORY_SCHEMA_VERSION: "1";
2
+ declare const MemoryIdBrand: unique symbol;
3
+ declare const MemoryProposalIdBrand: unique symbol;
4
+ declare const MemoryEdgeIdBrand: unique symbol;
5
+ declare const MemoryAuditRecordIdBrand: unique symbol;
6
+ declare const MemoryReviewerIdBrand: unique symbol;
7
+ declare const UserIdBrand: unique symbol;
8
+ declare const WorkspaceIdBrand: unique symbol;
9
+ declare const ProjectIdBrand: unique symbol;
10
+ declare const WorkflowDefinitionIdBrand: unique symbol;
11
+ declare const ConversationIdBrand: unique symbol;
12
+ declare const WorkflowRunIdBrand: unique symbol;
13
+ declare const EvidenceManifestIdBrand: unique symbol;
14
+ export type MemoryId = string & {
15
+ readonly [MemoryIdBrand]: true;
16
+ };
17
+ export type MemoryProposalId = string & {
18
+ readonly [MemoryProposalIdBrand]: true;
19
+ };
20
+ export type MemoryEdgeId = string & {
21
+ readonly [MemoryEdgeIdBrand]: true;
22
+ };
23
+ export type MemoryAuditRecordId = string & {
24
+ readonly [MemoryAuditRecordIdBrand]: true;
25
+ };
26
+ export type MemoryReviewerId = string & {
27
+ readonly [MemoryReviewerIdBrand]: true;
28
+ };
29
+ export type UserId = string & {
30
+ readonly [UserIdBrand]: true;
31
+ };
32
+ export type WorkspaceId = string & {
33
+ readonly [WorkspaceIdBrand]: true;
34
+ };
35
+ export type ProjectId = string & {
36
+ readonly [ProjectIdBrand]: true;
37
+ };
38
+ export type WorkflowDefinitionId = string & {
39
+ readonly [WorkflowDefinitionIdBrand]: true;
40
+ };
41
+ export type ConversationId = string & {
42
+ readonly [ConversationIdBrand]: true;
43
+ };
44
+ export type WorkflowRunId = string & {
45
+ readonly [WorkflowRunIdBrand]: true;
46
+ };
47
+ export type EvidenceManifestId = string & {
48
+ readonly [EvidenceManifestIdBrand]: true;
49
+ };
50
+ export type MemoryScopeKind = "user" | "workspace" | "project" | "workflow" | "global";
51
+ export declare const MEMORY_SCOPE_KINDS: readonly MemoryScopeKind[];
52
+ export type MemoryScope = {
53
+ readonly kind: "user";
54
+ readonly userId: UserId;
55
+ } | {
56
+ readonly kind: "workspace";
57
+ readonly workspaceId: WorkspaceId;
58
+ } | {
59
+ readonly kind: "project";
60
+ readonly projectId: ProjectId;
61
+ } | {
62
+ readonly kind: "workflow";
63
+ readonly workflowDefinitionId: WorkflowDefinitionId;
64
+ } | {
65
+ readonly kind: "global";
66
+ };
67
+ export type MemoryType = "episodic" | "semantic-fact" | "procedural" | "preference" | "correction" | "decision" | "negative" | "pinned";
68
+ export declare const MEMORY_TYPES: readonly MemoryType[];
69
+ export type MemorySensitivity = "public" | "confidential" | "restricted";
70
+ export declare const MEMORY_SENSITIVITIES: readonly MemorySensitivity[];
71
+ export type MemoryStatus = "proposed" | "accepted" | "rejected" | "superseded" | "archived" | "forgotten" | "conflicted" | "expired";
72
+ export declare const MEMORY_STATUSES: readonly MemoryStatus[];
73
+ export declare const MEMORY_STATUS_TRANSITIONS: Readonly<Record<MemoryStatus, readonly MemoryStatus[]>>;
74
+ export type MemorySourceKind = "explicit-user-instruction" | "accepted-correction" | "workflow-outcome" | "consolidation" | "system-default";
75
+ export declare const MEMORY_SOURCE_KINDS: readonly MemorySourceKind[];
76
+ export type MemoryEdgeKind = "related" | "derived-from" | "supersedes" | "corrects" | "conflicts-with" | "temporal-precedes";
77
+ export declare const MEMORY_EDGE_KINDS: readonly MemoryEdgeKind[];
78
+ export type MemoryAuditActionKind = "proposed" | "accepted" | "rejected" | "updated" | "superseded" | "pinned" | "unpinned" | "archived" | "forgotten" | "retrieved";
79
+ export declare const MEMORY_AUDIT_ACTION_KINDS: readonly MemoryAuditActionKind[];
80
+ export {};
81
+ //# sourceMappingURL=memory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memory.d.ts","sourceRoot":"","sources":["../src/memory.ts"],"names":[],"mappings":"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"}