@fgv/ts-agent-memory 5.1.0-37 → 5.1.0-39

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 (197) hide show
  1. package/.rush/temp/{6dfc331ddf74dc2db0d4483d0c96ea971f351c83.tar.log → b82cf6bdece20481260e6bab946179eeec9d7b46.tar.log} +116 -2
  2. package/.rush/temp/chunked-rush-logs/ts-agent-memory.build.chunks.jsonl +4 -4
  3. package/.rush/temp/operation/build/all.log +4 -4
  4. package/.rush/temp/operation/build/log-chunks.jsonl +4 -4
  5. package/.rush/temp/operation/build/state.json +1 -1
  6. package/.rush/temp/shrinkwrap-deps.json +222 -221
  7. package/config/jest.config.json +1 -1
  8. package/dist/index.js +2 -0
  9. package/dist/index.js.map +1 -1
  10. package/dist/packlets/ingest/cycleGuard.js +111 -0
  11. package/dist/packlets/ingest/cycleGuard.js.map +1 -0
  12. package/dist/packlets/ingest/hostStages.js +6 -0
  13. package/dist/packlets/ingest/hostStages.js.map +1 -0
  14. package/dist/packlets/ingest/index.js +9 -0
  15. package/dist/packlets/ingest/index.js.map +1 -0
  16. package/dist/packlets/ingest/model.js +6 -0
  17. package/dist/packlets/ingest/model.js.map +1 -0
  18. package/dist/packlets/ingest/orchestrator.js +438 -0
  19. package/dist/packlets/ingest/orchestrator.js.map +1 -0
  20. package/dist/packlets/retrieve/index.js +1 -0
  21. package/dist/packlets/retrieve/index.js.map +1 -1
  22. package/dist/packlets/retrieve/temporalRetrievers.js +172 -0
  23. package/dist/packlets/retrieve/temporalRetrievers.js.map +1 -0
  24. package/dist/packlets/store/fileTreeMemoryStore.js +323 -41
  25. package/dist/packlets/store/fileTreeMemoryStore.js.map +1 -1
  26. package/dist/packlets/tools/index.js +6 -0
  27. package/dist/packlets/tools/index.js.map +1 -0
  28. package/dist/packlets/tools/memoryTools.js +337 -0
  29. package/dist/packlets/tools/memoryTools.js.map +1 -0
  30. package/dist/packlets/types/identityCodec.js +115 -0
  31. package/dist/packlets/types/identityCodec.js.map +1 -1
  32. package/dist/packlets/types/index.js +1 -0
  33. package/dist/packlets/types/index.js.map +1 -1
  34. package/dist/packlets/types/temporal.js +85 -0
  35. package/dist/packlets/types/temporal.js.map +1 -0
  36. package/dist/packlets/types/writePolicy.js +96 -0
  37. package/dist/packlets/types/writePolicy.js.map +1 -1
  38. package/dist/test/unit/converters/antagonistRoundTrip.test.js +95 -0
  39. package/dist/test/unit/converters/antagonistRoundTrip.test.js.map +1 -0
  40. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js +273 -0
  41. package/dist/test/unit/ingest/antagonistCycleAndParity.test.js.map +1 -0
  42. package/dist/test/unit/ingest/cycleGuard.test.js +54 -0
  43. package/dist/test/unit/ingest/cycleGuard.test.js.map +1 -0
  44. package/dist/test/unit/ingest/orchestrator.test.js +913 -0
  45. package/dist/test/unit/ingest/orchestrator.test.js.map +1 -0
  46. package/dist/test/unit/retrieve/temporalRetrievers.test.js +182 -0
  47. package/dist/test/unit/retrieve/temporalRetrievers.test.js.map +1 -0
  48. package/dist/test/unit/store/antagonistTemporalBoundary.test.js +120 -0
  49. package/dist/test/unit/store/antagonistTemporalBoundary.test.js.map +1 -0
  50. package/dist/test/unit/store/fileTreeMemoryStore.test.js +74 -7
  51. package/dist/test/unit/store/fileTreeMemoryStore.test.js.map +1 -1
  52. package/dist/test/unit/store/temporalStore.test.js +398 -0
  53. package/dist/test/unit/store/temporalStore.test.js.map +1 -0
  54. package/dist/test/unit/tools/memoryTools.test.js +572 -0
  55. package/dist/test/unit/tools/memoryTools.test.js.map +1 -0
  56. package/dist/test/unit/types/temporalCodec.test.js +203 -0
  57. package/dist/test/unit/types/temporalCodec.test.js.map +1 -0
  58. package/dist/test/unit/types/temporalPolicy.test.js +62 -0
  59. package/dist/test/unit/types/temporalPolicy.test.js.map +1 -0
  60. package/dist/ts-agent-memory.d.ts +1042 -10
  61. package/dist/tsdoc-metadata.json +1 -1
  62. package/etc/ts-agent-memory.api.md +284 -0
  63. package/lib/index.d.ts +2 -0
  64. package/lib/index.d.ts.map +1 -1
  65. package/lib/index.js +2 -0
  66. package/lib/index.js.map +1 -1
  67. package/lib/packlets/ingest/cycleGuard.d.ts +41 -0
  68. package/lib/packlets/ingest/cycleGuard.d.ts.map +1 -0
  69. package/lib/packlets/ingest/cycleGuard.js +115 -0
  70. package/lib/packlets/ingest/cycleGuard.js.map +1 -0
  71. package/lib/packlets/ingest/hostStages.d.ts +88 -0
  72. package/lib/packlets/ingest/hostStages.d.ts.map +1 -0
  73. package/lib/packlets/ingest/hostStages.js +7 -0
  74. package/lib/packlets/ingest/hostStages.js.map +1 -0
  75. package/lib/packlets/ingest/index.d.ts +5 -0
  76. package/lib/packlets/ingest/index.d.ts.map +1 -0
  77. package/lib/packlets/ingest/index.js +25 -0
  78. package/lib/packlets/ingest/index.js.map +1 -0
  79. package/lib/packlets/ingest/model.d.ts +177 -0
  80. package/lib/packlets/ingest/model.d.ts.map +1 -0
  81. package/lib/packlets/ingest/model.js +7 -0
  82. package/lib/packlets/ingest/model.js.map +1 -0
  83. package/lib/packlets/ingest/orchestrator.d.ts +206 -0
  84. package/lib/packlets/ingest/orchestrator.d.ts.map +1 -0
  85. package/lib/packlets/ingest/orchestrator.js +442 -0
  86. package/lib/packlets/ingest/orchestrator.js.map +1 -0
  87. package/lib/packlets/retrieve/index.d.ts +1 -0
  88. package/lib/packlets/retrieve/index.d.ts.map +1 -1
  89. package/lib/packlets/retrieve/index.js +1 -0
  90. package/lib/packlets/retrieve/index.js.map +1 -1
  91. package/lib/packlets/retrieve/temporalRetrievers.d.ts +78 -0
  92. package/lib/packlets/retrieve/temporalRetrievers.d.ts.map +1 -0
  93. package/lib/packlets/retrieve/temporalRetrievers.js +178 -0
  94. package/lib/packlets/retrieve/temporalRetrievers.js.map +1 -0
  95. package/lib/packlets/store/fileTreeMemoryStore.d.ts +118 -9
  96. package/lib/packlets/store/fileTreeMemoryStore.d.ts.map +1 -1
  97. package/lib/packlets/store/fileTreeMemoryStore.js +322 -40
  98. package/lib/packlets/store/fileTreeMemoryStore.js.map +1 -1
  99. package/lib/packlets/tools/index.d.ts +2 -0
  100. package/lib/packlets/tools/index.d.ts.map +1 -0
  101. package/lib/packlets/tools/index.js +22 -0
  102. package/lib/packlets/tools/index.js.map +1 -0
  103. package/lib/packlets/tools/memoryTools.d.ts +139 -0
  104. package/lib/packlets/tools/memoryTools.d.ts.map +1 -0
  105. package/lib/packlets/tools/memoryTools.js +341 -0
  106. package/lib/packlets/tools/memoryTools.js.map +1 -0
  107. package/lib/packlets/types/identityCodec.d.ts +86 -0
  108. package/lib/packlets/types/identityCodec.d.ts.map +1 -1
  109. package/lib/packlets/types/identityCodec.js +118 -1
  110. package/lib/packlets/types/identityCodec.js.map +1 -1
  111. package/lib/packlets/types/index.d.ts +1 -0
  112. package/lib/packlets/types/index.d.ts.map +1 -1
  113. package/lib/packlets/types/index.js +1 -0
  114. package/lib/packlets/types/index.js.map +1 -1
  115. package/lib/packlets/types/temporal.d.ts +40 -0
  116. package/lib/packlets/types/temporal.d.ts.map +1 -0
  117. package/lib/packlets/types/temporal.js +92 -0
  118. package/lib/packlets/types/temporal.js.map +1 -0
  119. package/lib/packlets/types/writePolicy.d.ts +49 -0
  120. package/lib/packlets/types/writePolicy.d.ts.map +1 -1
  121. package/lib/packlets/types/writePolicy.js +98 -1
  122. package/lib/packlets/types/writePolicy.js.map +1 -1
  123. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts +10 -0
  124. package/lib/test/unit/converters/antagonistRoundTrip.test.d.ts.map +1 -0
  125. package/lib/test/unit/converters/antagonistRoundTrip.test.js +97 -0
  126. package/lib/test/unit/converters/antagonistRoundTrip.test.js.map +1 -0
  127. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts +9 -0
  128. package/lib/test/unit/ingest/antagonistCycleAndParity.test.d.ts.map +1 -0
  129. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js +275 -0
  130. package/lib/test/unit/ingest/antagonistCycleAndParity.test.js.map +1 -0
  131. package/lib/test/unit/ingest/cycleGuard.test.d.ts +2 -0
  132. package/lib/test/unit/ingest/cycleGuard.test.d.ts.map +1 -0
  133. package/lib/test/unit/ingest/cycleGuard.test.js +56 -0
  134. package/lib/test/unit/ingest/cycleGuard.test.js.map +1 -0
  135. package/lib/test/unit/ingest/orchestrator.test.d.ts +2 -0
  136. package/lib/test/unit/ingest/orchestrator.test.d.ts.map +1 -0
  137. package/lib/test/unit/ingest/orchestrator.test.js +915 -0
  138. package/lib/test/unit/ingest/orchestrator.test.js.map +1 -0
  139. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts +2 -0
  140. package/lib/test/unit/retrieve/temporalRetrievers.test.d.ts.map +1 -0
  141. package/lib/test/unit/retrieve/temporalRetrievers.test.js +184 -0
  142. package/lib/test/unit/retrieve/temporalRetrievers.test.js.map +1 -0
  143. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts +9 -0
  144. package/lib/test/unit/store/antagonistTemporalBoundary.test.d.ts.map +1 -0
  145. package/lib/test/unit/store/antagonistTemporalBoundary.test.js +122 -0
  146. package/lib/test/unit/store/antagonistTemporalBoundary.test.js.map +1 -0
  147. package/lib/test/unit/store/fileTreeMemoryStore.test.js +74 -7
  148. package/lib/test/unit/store/fileTreeMemoryStore.test.js.map +1 -1
  149. package/lib/test/unit/store/temporalStore.test.d.ts +2 -0
  150. package/lib/test/unit/store/temporalStore.test.d.ts.map +1 -0
  151. package/lib/test/unit/store/temporalStore.test.js +400 -0
  152. package/lib/test/unit/store/temporalStore.test.js.map +1 -0
  153. package/lib/test/unit/tools/memoryTools.test.d.ts +2 -0
  154. package/lib/test/unit/tools/memoryTools.test.d.ts.map +1 -0
  155. package/lib/test/unit/tools/memoryTools.test.js +574 -0
  156. package/lib/test/unit/tools/memoryTools.test.js.map +1 -0
  157. package/lib/test/unit/types/temporalCodec.test.d.ts +2 -0
  158. package/lib/test/unit/types/temporalCodec.test.d.ts.map +1 -0
  159. package/lib/test/unit/types/temporalCodec.test.js +205 -0
  160. package/lib/test/unit/types/temporalCodec.test.js.map +1 -0
  161. package/lib/test/unit/types/temporalPolicy.test.d.ts +2 -0
  162. package/lib/test/unit/types/temporalPolicy.test.d.ts.map +1 -0
  163. package/lib/test/unit/types/temporalPolicy.test.js +64 -0
  164. package/lib/test/unit/types/temporalPolicy.test.js.map +1 -0
  165. package/package.json +7 -7
  166. package/rush-logs/ts-agent-memory.build.cache.log +1 -1
  167. package/rush-logs/ts-agent-memory.build.log +4 -4
  168. package/src/index.ts +2 -0
  169. package/src/packlets/ingest/cycleGuard.ts +142 -0
  170. package/src/packlets/ingest/hostStages.ts +111 -0
  171. package/src/packlets/ingest/index.ts +9 -0
  172. package/src/packlets/ingest/model.ts +184 -0
  173. package/src/packlets/ingest/orchestrator.ts +797 -0
  174. package/src/packlets/retrieve/index.ts +1 -0
  175. package/src/packlets/retrieve/temporalRetrievers.ts +210 -0
  176. package/src/packlets/store/fileTreeMemoryStore.ts +460 -66
  177. package/src/packlets/tools/index.ts +6 -0
  178. package/src/packlets/tools/memoryTools.ts +579 -0
  179. package/src/packlets/types/identityCodec.ts +184 -0
  180. package/src/packlets/types/index.ts +1 -0
  181. package/src/packlets/types/temporal.ts +96 -0
  182. package/src/packlets/types/writePolicy.ts +127 -0
  183. package/src/test/unit/converters/antagonistRoundTrip.test.ts +110 -0
  184. package/src/test/unit/ingest/antagonistCycleAndParity.test.ts +362 -0
  185. package/src/test/unit/ingest/cycleGuard.test.ts +68 -0
  186. package/src/test/unit/ingest/orchestrator.test.ts +1158 -0
  187. package/src/test/unit/retrieve/temporalRetrievers.test.ts +226 -0
  188. package/src/test/unit/store/antagonistTemporalBoundary.test.ts +158 -0
  189. package/src/test/unit/store/fileTreeMemoryStore.test.ts +98 -7
  190. package/src/test/unit/store/temporalStore.test.ts +469 -0
  191. package/src/test/unit/tools/memoryTools.test.ts +771 -0
  192. package/src/test/unit/types/temporalCodec.test.ts +259 -0
  193. package/src/test/unit/types/temporalPolicy.test.ts +96 -0
  194. package/temp/build/lint/_eslint-5eVG3S6w.json +85 -9
  195. package/temp/build/typescript/ts_8nwakTlr.json +1 -1
  196. package/temp/ts-agent-memory.api.json +11984 -6314
  197. package/temp/ts-agent-memory.api.md +284 -0
@@ -0,0 +1,341 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2026 Erik Fortune
4
+ * SPDX-License-Identifier: MIT
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.DEFAULT_MEMORY_TOOLS = void 0;
8
+ exports.createMemoryTools = createMemoryTools;
9
+ const ts_utils_1 = require("@fgv/ts-utils");
10
+ const ts_json_base_1 = require("@fgv/ts-json-base");
11
+ const types_1 = require("../types");
12
+ const converters_1 = require("../converters");
13
+ /**
14
+ * The default tool subset when {@link ICreateMemoryToolsParams.tools | tools} is
15
+ * omitted: the read-only set. Mutating tools (`memory_write` / `memory_delete`)
16
+ * are **off by default** and must be named explicitly — writes stay
17
+ * curation-mediated unless the host opts in.
18
+ * @public
19
+ */
20
+ exports.DEFAULT_MEMORY_TOOLS = ['memory_search', 'memory_context'];
21
+ // ---------------------------------------------------------------------------
22
+ // Parameter schemas — authored once via JsonSchema.object(...); the schema IS
23
+ // both the wire schema (.toJson()) and the runtime validator (.convert()).
24
+ // NONE of these declare a `scope` (or scope-widening) property — the adoption
25
+ // gate is enforced structurally and asserted in the tests.
26
+ // ---------------------------------------------------------------------------
27
+ /** A single attributed link edge as authored by the agent on a write. */
28
+ // eslint-disable-next-line @rushstack/typedef-var
29
+ const linkEdgeSchema = ts_json_base_1.JsonSchema.object({
30
+ type: ts_json_base_1.JsonSchema.string({ description: 'The relation type of the link.' }),
31
+ target: ts_json_base_1.JsonSchema.string({ description: 'The MemoryId this edge points at.' }),
32
+ confidence: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.number({ description: 'Optional confidence in [0, 1].' }))
33
+ });
34
+ // eslint-disable-next-line @rushstack/typedef-var
35
+ const writeSchema = ts_json_base_1.JsonSchema.object({
36
+ kind: ts_json_base_1.JsonSchema.string({ description: 'The record kind (must be an enabled, registered kind).' }),
37
+ entityId: ts_json_base_1.JsonSchema.string({
38
+ description: 'The domain entity id. For composite (e.g. medium-term) kinds this is the full composite key.'
39
+ }),
40
+ body: ts_json_base_1.JsonSchema.string({ description: "The serialized record body; validated by the kind's converter." }),
41
+ tags: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.array(ts_json_base_1.JsonSchema.string({ description: 'A tag label.' }))),
42
+ links: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.array(linkEdgeSchema))
43
+ });
44
+ // eslint-disable-next-line @rushstack/typedef-var
45
+ const readSchema = ts_json_base_1.JsonSchema.object({
46
+ kind: ts_json_base_1.JsonSchema.string({ description: 'The record kind.' }),
47
+ entityId: ts_json_base_1.JsonSchema.string({ description: 'The domain entity id to read.' })
48
+ });
49
+ // eslint-disable-next-line @rushstack/typedef-var
50
+ const deleteSchema = ts_json_base_1.JsonSchema.object({
51
+ kind: ts_json_base_1.JsonSchema.string({ description: 'The record kind.' }),
52
+ entityId: ts_json_base_1.JsonSchema.string({ description: 'The domain entity id to delete.' })
53
+ });
54
+ // eslint-disable-next-line @rushstack/typedef-var
55
+ const searchSchema = ts_json_base_1.JsonSchema.object({
56
+ kind: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.string({ description: 'Restrict to this kind.' })),
57
+ tag: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.string({ description: 'Restrict to records carrying this tag.' })),
58
+ semantic: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.string({ description: 'Semantic query text (requires a semantic-capable retriever).' })),
59
+ limit: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.integer({ description: 'Maximum number of results to return.' }))
60
+ });
61
+ // eslint-disable-next-line @rushstack/typedef-var
62
+ const contextSchema = ts_json_base_1.JsonSchema.object({
63
+ from: ts_json_base_1.JsonSchema.string({ description: 'The seed MemoryId to traverse links from.' }),
64
+ kind: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.string({ description: 'Restrict reached records to this kind.' })),
65
+ tag: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.string({ description: 'Restrict reached records carrying this tag.' })),
66
+ hops: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.integer({ description: 'BFS hop count (default 1).' })),
67
+ limit: ts_json_base_1.JsonSchema.optional(ts_json_base_1.JsonSchema.integer({ description: 'Maximum number of results to return.' }))
68
+ });
69
+ // ---------------------------------------------------------------------------
70
+ // Behavior annotations (Component 4) — host-advisory hints; never serialized to
71
+ // the model. openWorldHint is false throughout (a closed, local store).
72
+ // ---------------------------------------------------------------------------
73
+ const READ_ONLY_ANNOTATIONS = {
74
+ readOnlyHint: true,
75
+ openWorldHint: false
76
+ };
77
+ const WRITE_ANNOTATIONS = {
78
+ destructiveHint: false,
79
+ idempotentHint: false,
80
+ openWorldHint: false
81
+ };
82
+ const DELETE_ANNOTATIONS = {
83
+ destructiveHint: true,
84
+ idempotentHint: true,
85
+ openWorldHint: false
86
+ };
87
+ // ---------------------------------------------------------------------------
88
+ // Shared validation / projection helpers
89
+ // ---------------------------------------------------------------------------
90
+ /** Validate a `kind` string and assert it is an enabled, registered toolable kind. */
91
+ function assertKindEnabled(ctx, kindStr) {
92
+ return types_1.Convert.kind.convert(kindStr).onSuccess((kind) => {
93
+ if (!ctx.registry.has(kind)) {
94
+ return (0, ts_utils_1.fail)(`memory tools: kind '${kind}' has no registered body converter`);
95
+ }
96
+ if (ctx.kinds !== undefined && !ctx.kinds.includes(kind)) {
97
+ return (0, ts_utils_1.fail)(`memory tools: kind '${kind}' is not enabled for memory tools`);
98
+ }
99
+ return (0, ts_utils_1.succeed)(kind);
100
+ });
101
+ }
102
+ /** Validate an optional `kind` string (enabled when present; `undefined` passes through). */
103
+ function resolveOptionalKind(ctx, kindStr) {
104
+ if (kindStr === undefined) {
105
+ return (0, ts_utils_1.succeed)(undefined);
106
+ }
107
+ return assertKindEnabled(ctx, kindStr);
108
+ }
109
+ /** Project a record into an agent-visible result item, applying the host handle hook when present. */
110
+ function projectItem(ctx, record) {
111
+ // `handleFor` is a host callback; guard it so a throw degrades to the raw id rather than
112
+ // escaping the Result chain (and crashing the whole search/context call).
113
+ const handle = ctx.handleFor !== undefined
114
+ ? (0, ts_utils_1.captureResult)(() => ctx.handleFor(record)).orDefault(record.envelope.id)
115
+ : record.envelope.id;
116
+ return {
117
+ handle,
118
+ kind: record.envelope.kind,
119
+ entityId: record.envelope.entityId,
120
+ tags: record.envelope.tags,
121
+ body: record.body
122
+ };
123
+ }
124
+ /** Resolve the identity codec used by `memory_write` to derive the storage id. */
125
+ function codecForWrite(ctx, kind) {
126
+ var _a, _b;
127
+ const codec = (_b = (_a = ctx.codecs) === null || _a === void 0 ? void 0 : _a.get(kind)) !== null && _b !== void 0 ? _b : ctx.defaultCodec;
128
+ if (codec === undefined) {
129
+ return (0, ts_utils_1.fail)(`memory_write: no identity codec available for kind '${kind}'`);
130
+ }
131
+ return (0, ts_utils_1.succeed)(codec);
132
+ }
133
+ /** Build the record to persist from validated write args (store stamps txn-time metadata). */
134
+ function buildWriteRecord(typed, kind, entityId, idStem) {
135
+ var _a, _b;
136
+ // Plain shapes handed to `envelopeConverter`, which validates each field
137
+ // (type → LinkType, target → MemoryId) and produces the branded IEdge[].
138
+ const links = ((_a = typed.links) !== null && _a !== void 0 ? _a : []).map((link) => (Object.assign({ type: link.type, target: link.target }, (link.confidence !== undefined ? { confidence: link.confidence } : {}))));
139
+ return converters_1.envelopeConverter
140
+ .convert({
141
+ id: idStem,
142
+ entityId,
143
+ kind,
144
+ tags: (_b = typed.tags) !== null && _b !== void 0 ? _b : [],
145
+ links,
146
+ created: 0,
147
+ updated: 0,
148
+ seq: 0,
149
+ contentHash: '',
150
+ provenance: { source: 'agent' }
151
+ })
152
+ .withErrorFormat((msg) => `memory_write: invalid record: ${msg}`)
153
+ .onSuccess((envelope) => (0, ts_utils_1.succeed)({ envelope, body: typed.body }));
154
+ }
155
+ /** Resolve the validated write args into the storage id + record (all synchronous). */
156
+ function prepareWrite(ctx, typed) {
157
+ return assertKindEnabled(ctx, typed.kind).onSuccess((kind) => types_1.Convert.entityId.convert(typed.entityId).onSuccess((entityId) => codecForWrite(ctx, kind).onSuccess((codec) => codec.encode(entityId).onSuccess((addr) => {
158
+ if (addr.isVersioned) {
159
+ return (0, ts_utils_1.fail)(`memory_write: versioned/temporal kind '${kind}' is not supported`);
160
+ }
161
+ return buildWriteRecord(typed, kind, entityId, addr.idStem).onSuccess((record) => (0, ts_utils_1.succeed)({ kind, entityId, record }));
162
+ }))));
163
+ }
164
+ /**
165
+ * Discriminate the write outcome from a pre-put snapshot and the returned record.
166
+ * A dedup no-op returns either a different entity (content-scope dedup) or the
167
+ * same-id record with an unchanged `seq` (entity-scope re-put); a fresh write or
168
+ * update advances `seq`.
169
+ */
170
+ function writeOutcome(before, written, entityId) {
171
+ if (written.envelope.entityId !== entityId) {
172
+ return 'deduped';
173
+ }
174
+ if (before !== undefined && written.envelope.seq === before.envelope.seq) {
175
+ return 'deduped';
176
+ }
177
+ return 'written';
178
+ }
179
+ // ---------------------------------------------------------------------------
180
+ // Tool builders — config with a JsonSchema.object(...) parametersSchema; execute
181
+ // validates/narrows → delegates to store/retriever → returns the Result (never
182
+ // swallowed), following the ts-extras-mcp adapter shape.
183
+ //
184
+ // Each `execute` re-runs its own `parametersSchema.convert(args)` even though the
185
+ // `executeClientToolTurn` harness already validates against the same schema. This
186
+ // is deliberate: the factory returns a heterogeneous `ReadonlyArray<IAiClientTool>`
187
+ // (TParams erased to `unknown`, since the members carry different param shapes), so
188
+ // `execute` receives `unknown` and must narrow it back to the typed args. The
189
+ // re-validation is also the narrowing step exercised by the direct-call tests (which
190
+ // invoke `execute` with raw args, bypassing the harness). Re-validating an
191
+ // already-conforming shape is a cheap, side-effect-free identity.
192
+ // ---------------------------------------------------------------------------
193
+ function buildWriteTool(ctx) {
194
+ return {
195
+ config: {
196
+ type: 'client_tool',
197
+ name: 'memory_write',
198
+ description: 'Store a new memory record or update an existing one by (kind, entityId). ' +
199
+ 'Identical content is a no-op that returns the existing record.',
200
+ parametersSchema: writeSchema,
201
+ annotations: WRITE_ANNOTATIONS
202
+ },
203
+ execute: async (args) => writeSchema
204
+ .convert(args)
205
+ .withErrorFormat((msg) => `memory_write: invalid arguments: ${msg}`)
206
+ .onSuccess((typed) => prepareWrite(ctx, typed))
207
+ .thenOnSuccess(async ({ kind, entityId, record }) =>
208
+ // Read the prior record to discriminate written-vs-deduped. A `Failure`
209
+ // here (corrupt file, I/O error, codec round-trip failure) is a real
210
+ // condition distinct from the "not found" success (`undefined`); propagate
211
+ // it rather than defaulting it away, so a genuine store fault surfaces
212
+ // instead of being masked as a normal write.
213
+ (await ctx.store.get(kind, entityId)).thenOnSuccess(async (before) => (await ctx.store.put(record)).onSuccess((persisted) => (0, ts_utils_1.succeed)({
214
+ outcome: writeOutcome(before, persisted, entityId),
215
+ id: persisted.envelope.id,
216
+ entityId,
217
+ kind
218
+ }))))
219
+ };
220
+ }
221
+ function buildReadTool(ctx) {
222
+ return {
223
+ config: {
224
+ type: 'client_tool',
225
+ name: 'memory_read',
226
+ description: 'Read a specific memory record by (kind, entityId).',
227
+ parametersSchema: readSchema,
228
+ annotations: READ_ONLY_ANNOTATIONS
229
+ },
230
+ execute: async (args) => readSchema
231
+ .convert(args)
232
+ .withErrorFormat((msg) => `memory_read: invalid arguments: ${msg}`)
233
+ .onSuccess((typed) => assertKindEnabled(ctx, typed.kind).onSuccess((kind) => types_1.Convert.entityId.convert(typed.entityId).onSuccess((entityId) => (0, ts_utils_1.succeed)({ kind, entityId }))))
234
+ .thenOnSuccess(async ({ kind, entityId }) => (await ctx.store.get(kind, entityId)).onSuccess((record) => record === undefined
235
+ ? (0, ts_utils_1.succeed)({ found: false })
236
+ : (0, ts_utils_1.succeed)({ found: true, item: projectItem(ctx, record) })))
237
+ };
238
+ }
239
+ function buildSearchTool(ctx) {
240
+ return {
241
+ config: {
242
+ type: 'client_tool',
243
+ name: 'memory_search',
244
+ description: 'Search memories by tag, kind, or semantic text. Returns ranked results.',
245
+ parametersSchema: searchSchema,
246
+ annotations: READ_ONLY_ANNOTATIONS
247
+ },
248
+ execute: async (args) => searchSchema
249
+ .convert(args)
250
+ .withErrorFormat((msg) => `memory_search: invalid arguments: ${msg}`)
251
+ .onSuccess((typed) => resolveOptionalKind(ctx, typed.kind).onSuccess((kind) => resolveOptionalTag(typed.tag).onSuccess((tag) => (0, ts_utils_1.succeed)({ typed, kind, tag }))))
252
+ .thenOnSuccess(async ({ typed, kind, tag }) => {
253
+ const query = Object.assign(Object.assign(Object.assign(Object.assign({}, (kind !== undefined ? { kind } : {})), (tag !== undefined ? { tag } : {})), (typed.semantic !== undefined ? { semantic: typed.semantic } : {})), (typed.limit !== undefined ? { limit: typed.limit } : {}));
254
+ return (await ctx.retriever.retrieve(query)).onSuccess((records) => (0, ts_utils_1.succeed)({ count: records.length, results: records.map((r) => projectItem(ctx, r)) }));
255
+ })
256
+ };
257
+ }
258
+ function buildContextTool(ctx) {
259
+ return {
260
+ config: {
261
+ type: 'client_tool',
262
+ name: 'memory_context',
263
+ description: 'Build a context graph from a seed memory: returns the records linked from the seed, up to `hops` hops.',
264
+ parametersSchema: contextSchema,
265
+ annotations: READ_ONLY_ANNOTATIONS
266
+ },
267
+ execute: async (args) => contextSchema
268
+ .convert(args)
269
+ .withErrorFormat((msg) => `memory_context: invalid arguments: ${msg}`)
270
+ .onSuccess((typed) => types_1.Convert.memoryId
271
+ .convert(typed.from)
272
+ .onSuccess((from) => resolveOptionalKind(ctx, typed.kind).onSuccess((kind) => resolveOptionalTag(typed.tag).onSuccess((tag) => (0, ts_utils_1.succeed)({ typed, from, kind, tag })))))
273
+ .thenOnSuccess(async ({ typed, from, kind, tag }) => {
274
+ const query = Object.assign(Object.assign(Object.assign(Object.assign({ linkedFrom: from }, (kind !== undefined ? { kind } : {})), (tag !== undefined ? { tag } : {})), (typed.hops !== undefined ? { hops: typed.hops } : {})), (typed.limit !== undefined ? { limit: typed.limit } : {}));
275
+ return (await ctx.retriever.retrieve(query)).onSuccess((records) => (0, ts_utils_1.succeed)({ seed: from, count: records.length, results: records.map((r) => projectItem(ctx, r)) }));
276
+ })
277
+ };
278
+ }
279
+ function buildDeleteTool(ctx) {
280
+ return {
281
+ config: {
282
+ type: 'client_tool',
283
+ name: 'memory_delete',
284
+ description: 'Delete a memory record by (kind, entityId). Destructive for non-temporal kinds.',
285
+ parametersSchema: deleteSchema,
286
+ annotations: DELETE_ANNOTATIONS
287
+ },
288
+ execute: async (args) => deleteSchema
289
+ .convert(args)
290
+ .withErrorFormat((msg) => `memory_delete: invalid arguments: ${msg}`)
291
+ .onSuccess((typed) => assertKindEnabled(ctx, typed.kind).onSuccess((kind) => types_1.Convert.entityId.convert(typed.entityId).onSuccess((entityId) => (0, ts_utils_1.succeed)({ kind, entityId }))))
292
+ .thenOnSuccess(async ({ kind, entityId }) => (await ctx.store.delete(kind, entityId)).onSuccess((id) => (0, ts_utils_1.succeed)({ deleted: true, id, entityId, kind })))
293
+ };
294
+ }
295
+ /** Validate an optional `tag` string (`undefined` passes through). */
296
+ function resolveOptionalTag(tagStr) {
297
+ if (tagStr === undefined) {
298
+ return (0, ts_utils_1.succeed)(undefined);
299
+ }
300
+ return types_1.Convert.tag.convert(tagStr);
301
+ }
302
+ /** Ordered registry of the five tool builders, keyed by name. */
303
+ const TOOL_BUILDERS = [
304
+ { name: 'memory_write', build: buildWriteTool },
305
+ { name: 'memory_read', build: buildReadTool },
306
+ { name: 'memory_search', build: buildSearchTool },
307
+ { name: 'memory_context', build: buildContextTool },
308
+ { name: 'memory_delete', build: buildDeleteTool }
309
+ ];
310
+ /**
311
+ * Build the selected suite of memory `AiAssist.IAiClientTool`s over a
312
+ * pre-scoped store — ready to hand to `AiAssist.executeClientToolTurn` (and, via
313
+ * the shared `JsonSchema.object(...)` schemas, `@fgv/ts-extras-mcp`).
314
+ *
315
+ * @remarks
316
+ * **Scope isolation is make-or-break.** The returned tools close over the
317
+ * pre-scoped {@link ICreateMemoryToolsParams.store | store}; no tool's
318
+ * `parametersSchema` declares a `scope` (or any scope-widening) property, so an
319
+ * LLM cannot steer a tool at another actor's memory. The store instance is the
320
+ * sole scope authority.
321
+ *
322
+ * The default selection is {@link DEFAULT_MEMORY_TOOLS} (the read-only set) —
323
+ * `memory_write` / `memory_delete` are included only when named in
324
+ * {@link ICreateMemoryToolsParams.tools | tools}.
325
+ * @public
326
+ */
327
+ function createMemoryTools(params) {
328
+ var _a;
329
+ const ctx = {
330
+ store: params.store,
331
+ retriever: params.retriever,
332
+ registry: params.registry,
333
+ kinds: params.kinds,
334
+ codecs: params.codecs,
335
+ defaultCodec: params.defaultCodec,
336
+ handleFor: params.handleFor
337
+ };
338
+ const selected = new Set((_a = params.tools) !== null && _a !== void 0 ? _a : exports.DEFAULT_MEMORY_TOOLS);
339
+ return TOOL_BUILDERS.filter((builder) => selected.has(builder.name)).map((builder) => builder.build(ctx));
340
+ }
341
+ //# sourceMappingURL=memoryTools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"memoryTools.js","sourceRoot":"","sources":["../../../src/packlets/tools/memoryTools.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAmjBH,8CAYC;AA7jBD,4CAAqE;AACrE,oDAA+C;AAE/C,oCAAiG;AACjG,8CAA0E;AAgB1E;;;;;;GAMG;AACU,QAAA,oBAAoB,GAAkC,CAAC,eAAe,EAAE,gBAAgB,CAAC,CAAC;AAsHvG,8EAA8E;AAC9E,8EAA8E;AAC9E,2EAA2E;AAC3E,8EAA8E;AAC9E,2DAA2D;AAC3D,8EAA8E;AAE9E,yEAAyE;AACzE,kDAAkD;AAClD,MAAM,cAAc,GAAG,yBAAU,CAAC,MAAM,CAAC;IACvC,IAAI,EAAE,yBAAU,CAAC,MAAM,CAA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O,aAAa,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC;AAC5G,CAAC","sourcesContent":["/*\n * Copyright (c) 2026 Erik Fortune\n * SPDX-License-Identifier: MIT\n */\n\nimport { Result, captureResult, fail, succeed } from '@fgv/ts-utils';\nimport { JsonSchema } from '@fgv/ts-json-base';\nimport { AiAssist } from '@fgv/ts-extras';\nimport { Convert, EntityId, IIdentityCodec, IMemoryRecord, Kind, MemoryId, Tag } from '../types';\nimport { IBodyConverterRegistry, envelopeConverter } from '../converters';\nimport { IMemoryStore } from '../store';\nimport { IMemoryQuery, IMemoryRetriever } from '../retrieve';\n\n/**\n * The names of the five proof-set memory tools. A caller selects a subset via\n * {@link ICreateMemoryToolsParams.tools | tools}.\n * @public\n */\nexport type MemoryToolName =\n | 'memory_write'\n | 'memory_read'\n | 'memory_search'\n | 'memory_context'\n | 'memory_delete';\n\n/**\n * The default tool subset when {@link ICreateMemoryToolsParams.tools | tools} is\n * omitted: the read-only set. Mutating tools (`memory_write` / `memory_delete`)\n * are **off by default** and must be named explicitly — writes stay\n * curation-mediated unless the host opts in.\n * @public\n */\nexport const DEFAULT_MEMORY_TOOLS: ReadonlyArray<MemoryToolName> = ['memory_search', 'memory_context'];\n\n/**\n * Discriminates the outcome of a {@link createMemoryTools | memory_write} call so\n * the agent can reason about what its write actually did.\n *\n * @remarks\n * - `written` — a new record was persisted, or an existing entity was updated.\n * - `deduped` — the content already existed (content-hash dedup no-op); the\n * store returned the existing record unchanged.\n *\n * The store's public `put` return does not surface cap-cull evictions, so a\n * `culled` outcome is not distinguishable at this layer without an L1 change or\n * observer wiring (both out of scope for L2). The writer's own record is always\n * `written` even when the write triggers a cull of older siblings.\n * @public\n */\nexport type MemoryWriteOutcome = 'written' | 'deduped';\n\n/**\n * The success value returned by `memory_write.execute`.\n * @public\n */\nexport interface IMemoryWriteResult {\n /** What the write did — see {@link MemoryWriteOutcome}. */\n readonly outcome: MemoryWriteOutcome;\n /** The stored record's {@link MemoryId}. */\n readonly id: MemoryId;\n /** The domain {@link EntityId} the write targeted. */\n readonly entityId: EntityId;\n /** The record's {@link Kind}. */\n readonly kind: Kind;\n}\n\n/**\n * A single agent-visible search / context result item. The agent-facing key is\n * {@link IMemoryToolResultItem.handle | handle}: the host mnemonic when a\n * {@link ICreateMemoryToolsParams.handleFor | handleFor} hook is supplied, else\n * the raw {@link MemoryId}.\n * @public\n */\nexport interface IMemoryToolResultItem {\n /** The agent-visible key (host handle when supplied, raw {@link MemoryId} otherwise). */\n readonly handle: string;\n /** The record's {@link Kind}. */\n readonly kind: Kind;\n /** The record's domain {@link EntityId}. */\n readonly entityId: EntityId;\n /** The record's tags. */\n readonly tags: ReadonlyArray<string>;\n /** The record body (a markdown string in B1). */\n readonly body: unknown;\n}\n\n/**\n * Parameters for {@link createMemoryTools}.\n *\n * @remarks\n * **Scope isolation is constructor-fixed.** The {@link\n * ICreateMemoryToolsParams.store | store} is the sole scope authority — it is the\n * actor's own, pre-scoped memory root. No tool's `parametersSchema` declares a\n * `scope` (or any scope-widening) property, so an LLM cannot steer a tool at\n * another actor's memory.\n * @public\n */\nexport interface ICreateMemoryToolsParams {\n /**\n * The pre-scoped memory store (the actor's own memory root). Sole scope\n * authority — backs `memory_write` / `memory_read` / `memory_delete`.\n */\n readonly store: IMemoryStore;\n /** Retriever backing `memory_search` (and `memory_context` via link traversal). */\n readonly retriever: IMemoryRetriever;\n /** Body converter registry — gates the toolable kinds via `has(kind)`. */\n readonly registry: IBodyConverterRegistry;\n /**\n * The per-tool enable subset. Defaults to {@link DEFAULT_MEMORY_TOOLS} (the\n * read-only set). Name `memory_write` / `memory_delete` here to opt into the\n * mutating tools.\n */\n readonly tools?: ReadonlyArray<MemoryToolName>;\n /**\n * Optional whitelist of toolable kinds. When present, a tool `kind` argument\n * outside this set is rejected. When absent, {@link\n * IBodyConverterRegistry.has | registry.has} is the sole kind gate.\n */\n readonly kinds?: ReadonlyArray<Kind>;\n /**\n * Per-kind identity codecs, used by `memory_write` to map the domain\n * {@link EntityId} to the record's storage id (the store resolves codecs\n * internally for `get` / `delete`, so read / delete do not need them). Absent\n * → `memory_write` uses {@link ICreateMemoryToolsParams.defaultCodec |\n * defaultCodec}, and fails loudly for a kind with no resolvable codec. The\n * read-only default tool set needs no codecs.\n */\n readonly codecs?: ReadonlyMap<Kind, IIdentityCodec>;\n /** Default identity codec for kinds without an explicit {@link ICreateMemoryToolsParams.codecs | codecs} entry. */\n readonly defaultCodec?: IIdentityCodec;\n /**\n * Optional host hook mapping a record to its agent-visible handle (an evocative\n * mnemonic tag). When supplied, `memory_search` / `memory_context` results use\n * the returned handle as the agent-visible key; when absent the raw\n * {@link MemoryId} is used.\n */\n readonly handleFor?: (record: IMemoryRecord<unknown>) => string;\n}\n\n/** The resolved factory context threaded into each tool's `execute`. */\ninterface IToolContext {\n readonly store: IMemoryStore;\n readonly retriever: IMemoryRetriever;\n readonly registry: IBodyConverterRegistry;\n readonly kinds?: ReadonlyArray<Kind>;\n readonly codecs?: ReadonlyMap<Kind, IIdentityCodec>;\n readonly defaultCodec?: IIdentityCodec;\n readonly handleFor?: (record: IMemoryRecord<unknown>) => string;\n}\n\n// ---------------------------------------------------------------------------\n// Parameter schemas — authored once via JsonSchema.object(...); the schema IS\n// both the wire schema (.toJson()) and the runtime validator (.convert()).\n// NONE of these declare a `scope` (or scope-widening) property — the adoption\n// gate is enforced structurally and asserted in the tests.\n// ---------------------------------------------------------------------------\n\n/** A single attributed link edge as authored by the agent on a write. */\n// eslint-disable-next-line @rushstack/typedef-var\nconst linkEdgeSchema = JsonSchema.object({\n type: JsonSchema.string({ description: 'The relation type of the link.' }),\n target: JsonSchema.string({ description: 'The MemoryId this edge points at.' }),\n confidence: JsonSchema.optional(JsonSchema.number({ description: 'Optional confidence in [0, 1].' }))\n});\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst writeSchema = JsonSchema.object({\n kind: JsonSchema.string({ description: 'The record kind (must be an enabled, registered kind).' }),\n entityId: JsonSchema.string({\n description:\n 'The domain entity id. For composite (e.g. medium-term) kinds this is the full composite key.'\n }),\n body: JsonSchema.string({ description: \"The serialized record body; validated by the kind's converter.\" }),\n tags: JsonSchema.optional(JsonSchema.array(JsonSchema.string({ description: 'A tag label.' }))),\n links: JsonSchema.optional(JsonSchema.array(linkEdgeSchema))\n});\ntype WriteArgs = JsonSchema.Static<typeof writeSchema>;\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst readSchema = JsonSchema.object({\n kind: JsonSchema.string({ description: 'The record kind.' }),\n entityId: JsonSchema.string({ description: 'The domain entity id to read.' })\n});\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst deleteSchema = JsonSchema.object({\n kind: JsonSchema.string({ description: 'The record kind.' }),\n entityId: JsonSchema.string({ description: 'The domain entity id to delete.' })\n});\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst searchSchema = JsonSchema.object({\n kind: JsonSchema.optional(JsonSchema.string({ description: 'Restrict to this kind.' })),\n tag: JsonSchema.optional(JsonSchema.string({ description: 'Restrict to records carrying this tag.' })),\n semantic: JsonSchema.optional(\n JsonSchema.string({ description: 'Semantic query text (requires a semantic-capable retriever).' })\n ),\n limit: JsonSchema.optional(JsonSchema.integer({ description: 'Maximum number of results to return.' }))\n});\n\n// eslint-disable-next-line @rushstack/typedef-var\nconst contextSchema = JsonSchema.object({\n from: JsonSchema.string({ description: 'The seed MemoryId to traverse links from.' }),\n kind: JsonSchema.optional(JsonSchema.string({ description: 'Restrict reached records to this kind.' })),\n tag: JsonSchema.optional(JsonSchema.string({ description: 'Restrict reached records carrying this tag.' })),\n hops: JsonSchema.optional(JsonSchema.integer({ description: 'BFS hop count (default 1).' })),\n limit: JsonSchema.optional(JsonSchema.integer({ description: 'Maximum number of results to return.' }))\n});\n\n// ---------------------------------------------------------------------------\n// Behavior annotations (Component 4) — host-advisory hints; never serialized to\n// the model. openWorldHint is false throughout (a closed, local store).\n// ---------------------------------------------------------------------------\n\nconst READ_ONLY_ANNOTATIONS: AiAssist.IAiToolAnnotations = {\n readOnlyHint: true,\n openWorldHint: false\n};\n\nconst WRITE_ANNOTATIONS: AiAssist.IAiToolAnnotations = {\n destructiveHint: false,\n idempotentHint: false,\n openWorldHint: false\n};\n\nconst DELETE_ANNOTATIONS: AiAssist.IAiToolAnnotations = {\n destructiveHint: true,\n idempotentHint: true,\n openWorldHint: false\n};\n\n// ---------------------------------------------------------------------------\n// Shared validation / projection helpers\n// ---------------------------------------------------------------------------\n\n/** Validate a `kind` string and assert it is an enabled, registered toolable kind. */\nfunction assertKindEnabled(ctx: IToolContext, kindStr: string): Result<Kind> {\n return Convert.kind.convert(kindStr).onSuccess((kind) => {\n if (!ctx.registry.has(kind)) {\n return fail(`memory tools: kind '${kind}' has no registered body converter`);\n }\n if (ctx.kinds !== undefined && !ctx.kinds.includes(kind)) {\n return fail(`memory tools: kind '${kind}' is not enabled for memory tools`);\n }\n return succeed(kind);\n });\n}\n\n/** Validate an optional `kind` string (enabled when present; `undefined` passes through). */\nfunction resolveOptionalKind(ctx: IToolContext, kindStr?: string): Result<Kind | undefined> {\n if (kindStr === undefined) {\n return succeed(undefined);\n }\n return assertKindEnabled(ctx, kindStr);\n}\n\n/** Project a record into an agent-visible result item, applying the host handle hook when present. */\nfunction projectItem(ctx: IToolContext, record: IMemoryRecord<unknown>): IMemoryToolResultItem {\n // `handleFor` is a host callback; guard it so a throw degrades to the raw id rather than\n // escaping the Result chain (and crashing the whole search/context call).\n const handle =\n ctx.handleFor !== undefined\n ? captureResult(() => ctx.handleFor!(record)).orDefault(record.envelope.id)\n : record.envelope.id;\n return {\n handle,\n kind: record.envelope.kind,\n entityId: record.envelope.entityId,\n tags: record.envelope.tags,\n body: record.body\n };\n}\n\n/** Resolve the identity codec used by `memory_write` to derive the storage id. */\nfunction codecForWrite(ctx: IToolContext, kind: Kind): Result<IIdentityCodec> {\n const codec: IIdentityCodec | undefined = ctx.codecs?.get(kind) ?? ctx.defaultCodec;\n if (codec === undefined) {\n return fail(`memory_write: no identity codec available for kind '${kind}'`);\n }\n return succeed(codec);\n}\n\n/** Build the record to persist from validated write args (store stamps txn-time metadata). */\nfunction buildWriteRecord(\n typed: WriteArgs,\n kind: Kind,\n entityId: EntityId,\n idStem: string\n): Result<IMemoryRecord<unknown>> {\n // Plain shapes handed to `envelopeConverter`, which validates each field\n // (type → LinkType, target → MemoryId) and produces the branded IEdge[].\n const links: ReadonlyArray<Record<string, unknown>> = (typed.links ?? []).map((link) => ({\n type: link.type,\n target: link.target,\n ...(link.confidence !== undefined ? { confidence: link.confidence } : {})\n }));\n return envelopeConverter\n .convert({\n id: idStem,\n entityId,\n kind,\n tags: typed.tags ?? [],\n links,\n created: 0,\n updated: 0,\n seq: 0,\n contentHash: '',\n provenance: { source: 'agent' }\n })\n .withErrorFormat((msg) => `memory_write: invalid record: ${msg}`)\n .onSuccess((envelope) => succeed({ envelope, body: typed.body }));\n}\n\n/** Resolve the validated write args into the storage id + record (all synchronous). */\nfunction prepareWrite(\n ctx: IToolContext,\n typed: WriteArgs\n): Result<{ readonly kind: Kind; readonly entityId: EntityId; readonly record: IMemoryRecord<unknown> }> {\n return assertKindEnabled(ctx, typed.kind).onSuccess((kind) =>\n Convert.entityId.convert(typed.entityId).onSuccess((entityId) =>\n codecForWrite(ctx, kind).onSuccess((codec) =>\n codec.encode(entityId).onSuccess((addr) => {\n if (addr.isVersioned) {\n return fail(`memory_write: versioned/temporal kind '${kind}' is not supported`);\n }\n return buildWriteRecord(typed, kind, entityId, addr.idStem).onSuccess((record) =>\n succeed({ kind, entityId, record })\n );\n })\n )\n )\n );\n}\n\n/**\n * Discriminate the write outcome from a pre-put snapshot and the returned record.\n * A dedup no-op returns either a different entity (content-scope dedup) or the\n * same-id record with an unchanged `seq` (entity-scope re-put); a fresh write or\n * update advances `seq`.\n */\nfunction writeOutcome(\n before: IMemoryRecord<unknown> | undefined,\n written: IMemoryRecord<unknown>,\n entityId: EntityId\n): MemoryWriteOutcome {\n if (written.envelope.entityId !== entityId) {\n return 'deduped';\n }\n if (before !== undefined && written.envelope.seq === before.envelope.seq) {\n return 'deduped';\n }\n return 'written';\n}\n\n// ---------------------------------------------------------------------------\n// Tool builders — config with a JsonSchema.object(...) parametersSchema; execute\n// validates/narrows → delegates to store/retriever → returns the Result (never\n// swallowed), following the ts-extras-mcp adapter shape.\n//\n// Each `execute` re-runs its own `parametersSchema.convert(args)` even though the\n// `executeClientToolTurn` harness already validates against the same schema. This\n// is deliberate: the factory returns a heterogeneous `ReadonlyArray<IAiClientTool>`\n// (TParams erased to `unknown`, since the members carry different param shapes), so\n// `execute` receives `unknown` and must narrow it back to the typed args. The\n// re-validation is also the narrowing step exercised by the direct-call tests (which\n// invoke `execute` with raw args, bypassing the harness). Re-validating an\n// already-conforming shape is a cheap, side-effect-free identity.\n// ---------------------------------------------------------------------------\n\nfunction buildWriteTool(ctx: IToolContext): AiAssist.IAiClientTool {\n return {\n config: {\n type: 'client_tool',\n name: 'memory_write',\n description:\n 'Store a new memory record or update an existing one by (kind, entityId). ' +\n 'Identical content is a no-op that returns the existing record.',\n parametersSchema: writeSchema,\n annotations: WRITE_ANNOTATIONS\n },\n execute: async (args: unknown): Promise<Result<unknown>> =>\n writeSchema\n .convert(args)\n .withErrorFormat((msg) => `memory_write: invalid arguments: ${msg}`)\n .onSuccess((typed) => prepareWrite(ctx, typed))\n .thenOnSuccess(async ({ kind, entityId, record }) =>\n // Read the prior record to discriminate written-vs-deduped. A `Failure`\n // here (corrupt file, I/O error, codec round-trip failure) is a real\n // condition distinct from the \"not found\" success (`undefined`); propagate\n // it rather than defaulting it away, so a genuine store fault surfaces\n // instead of being masked as a normal write.\n (await ctx.store.get(kind, entityId)).thenOnSuccess(async (before) =>\n (await ctx.store.put(record)).onSuccess((persisted) =>\n succeed<IMemoryWriteResult>({\n outcome: writeOutcome(before, persisted, entityId),\n id: persisted.envelope.id,\n entityId,\n kind\n })\n )\n )\n )\n };\n}\n\nfunction buildReadTool(ctx: IToolContext): AiAssist.IAiClientTool {\n return {\n config: {\n type: 'client_tool',\n name: 'memory_read',\n description: 'Read a specific memory record by (kind, entityId).',\n parametersSchema: readSchema,\n annotations: READ_ONLY_ANNOTATIONS\n },\n execute: async (args: unknown): Promise<Result<unknown>> =>\n readSchema\n .convert(args)\n .withErrorFormat((msg) => `memory_read: invalid arguments: ${msg}`)\n .onSuccess((typed) =>\n assertKindEnabled(ctx, typed.kind).onSuccess((kind) =>\n Convert.entityId.convert(typed.entityId).onSuccess((entityId) => succeed({ kind, entityId }))\n )\n )\n .thenOnSuccess(async ({ kind, entityId }) =>\n (await ctx.store.get(kind, entityId)).onSuccess((record) =>\n record === undefined\n ? succeed({ found: false })\n : succeed({ found: true, item: projectItem(ctx, record) })\n )\n )\n };\n}\n\nfunction buildSearchTool(ctx: IToolContext): AiAssist.IAiClientTool {\n return {\n config: {\n type: 'client_tool',\n name: 'memory_search',\n description: 'Search memories by tag, kind, or semantic text. Returns ranked results.',\n parametersSchema: searchSchema,\n annotations: READ_ONLY_ANNOTATIONS\n },\n execute: async (args: unknown): Promise<Result<unknown>> =>\n searchSchema\n .convert(args)\n .withErrorFormat((msg) => `memory_search: invalid arguments: ${msg}`)\n .onSuccess((typed) =>\n resolveOptionalKind(ctx, typed.kind).onSuccess((kind) =>\n resolveOptionalTag(typed.tag).onSuccess((tag) => succeed({ typed, kind, tag }))\n )\n )\n .thenOnSuccess(async ({ typed, kind, tag }) => {\n const query: IMemoryQuery = {\n ...(kind !== undefined ? { kind } : {}),\n ...(tag !== undefined ? { tag } : {}),\n ...(typed.semantic !== undefined ? { semantic: typed.semantic } : {}),\n ...(typed.limit !== undefined ? { limit: typed.limit } : {})\n };\n return (await ctx.retriever.retrieve(query)).onSuccess((records) =>\n succeed({ count: records.length, results: records.map((r) => projectItem(ctx, r)) })\n );\n })\n };\n}\n\nfunction buildContextTool(ctx: IToolContext): AiAssist.IAiClientTool {\n return {\n config: {\n type: 'client_tool',\n name: 'memory_context',\n description:\n 'Build a context graph from a seed memory: returns the records linked from the seed, up to `hops` hops.',\n parametersSchema: contextSchema,\n annotations: READ_ONLY_ANNOTATIONS\n },\n execute: async (args: unknown): Promise<Result<unknown>> =>\n contextSchema\n .convert(args)\n .withErrorFormat((msg) => `memory_context: invalid arguments: ${msg}`)\n .onSuccess((typed) =>\n Convert.memoryId\n .convert(typed.from)\n .onSuccess((from) =>\n resolveOptionalKind(ctx, typed.kind).onSuccess((kind) =>\n resolveOptionalTag(typed.tag).onSuccess((tag) => succeed({ typed, from, kind, tag }))\n )\n )\n )\n .thenOnSuccess(async ({ typed, from, kind, tag }) => {\n const query: IMemoryQuery = {\n linkedFrom: from,\n ...(kind !== undefined ? { kind } : {}),\n ...(tag !== undefined ? { tag } : {}),\n ...(typed.hops !== undefined ? { hops: typed.hops } : {}),\n ...(typed.limit !== undefined ? { limit: typed.limit } : {})\n };\n return (await ctx.retriever.retrieve(query)).onSuccess((records) =>\n succeed({ seed: from, count: records.length, results: records.map((r) => projectItem(ctx, r)) })\n );\n })\n };\n}\n\nfunction buildDeleteTool(ctx: IToolContext): AiAssist.IAiClientTool {\n return {\n config: {\n type: 'client_tool',\n name: 'memory_delete',\n description: 'Delete a memory record by (kind, entityId). Destructive for non-temporal kinds.',\n parametersSchema: deleteSchema,\n annotations: DELETE_ANNOTATIONS\n },\n execute: async (args: unknown): Promise<Result<unknown>> =>\n deleteSchema\n .convert(args)\n .withErrorFormat((msg) => `memory_delete: invalid arguments: ${msg}`)\n .onSuccess((typed) =>\n assertKindEnabled(ctx, typed.kind).onSuccess((kind) =>\n Convert.entityId.convert(typed.entityId).onSuccess((entityId) => succeed({ kind, entityId }))\n )\n )\n .thenOnSuccess(async ({ kind, entityId }) =>\n (await ctx.store.delete(kind, entityId)).onSuccess((id) =>\n succeed({ deleted: true, id, entityId, kind })\n )\n )\n };\n}\n\n/** Validate an optional `tag` string (`undefined` passes through). */\nfunction resolveOptionalTag(tagStr?: string): Result<Tag | undefined> {\n if (tagStr === undefined) {\n return succeed(undefined);\n }\n return Convert.tag.convert(tagStr);\n}\n\n/** Ordered registry of the five tool builders, keyed by name. */\nconst TOOL_BUILDERS: ReadonlyArray<{\n readonly name: MemoryToolName;\n readonly build: (ctx: IToolContext) => AiAssist.IAiClientTool;\n}> = [\n { name: 'memory_write', build: buildWriteTool },\n { name: 'memory_read', build: buildReadTool },\n { name: 'memory_search', build: buildSearchTool },\n { name: 'memory_context', build: buildContextTool },\n { name: 'memory_delete', build: buildDeleteTool }\n];\n\n/**\n * Build the selected suite of memory `AiAssist.IAiClientTool`s over a\n * pre-scoped store — ready to hand to `AiAssist.executeClientToolTurn` (and, via\n * the shared `JsonSchema.object(...)` schemas, `@fgv/ts-extras-mcp`).\n *\n * @remarks\n * **Scope isolation is make-or-break.** The returned tools close over the\n * pre-scoped {@link ICreateMemoryToolsParams.store | store}; no tool's\n * `parametersSchema` declares a `scope` (or any scope-widening) property, so an\n * LLM cannot steer a tool at another actor's memory. The store instance is the\n * sole scope authority.\n *\n * The default selection is {@link DEFAULT_MEMORY_TOOLS} (the read-only set) —\n * `memory_write` / `memory_delete` are included only when named in\n * {@link ICreateMemoryToolsParams.tools | tools}.\n * @public\n */\nexport function createMemoryTools(params: ICreateMemoryToolsParams): ReadonlyArray<AiAssist.IAiClientTool> {\n const ctx: IToolContext = {\n store: params.store,\n retriever: params.retriever,\n registry: params.registry,\n kinds: params.kinds,\n codecs: params.codecs,\n defaultCodec: params.defaultCodec,\n handleFor: params.handleFor\n };\n const selected: ReadonlySet<MemoryToolName> = new Set<MemoryToolName>(params.tools ?? DEFAULT_MEMORY_TOOLS);\n return TOOL_BUILDERS.filter((builder) => selected.has(builder.name)).map((builder) => builder.build(ctx));\n}\n"]}
@@ -40,6 +40,92 @@ export interface IIdentityCodec {
40
40
  verifyRoundTrip(scope: MemoryScopeKey, stem: string): Result<true>;
41
41
  }
42
42
  /**
43
+ * The `(entityId, version seq)` an {@link ITemporalIdentityCodec.decodeVersion}
44
+ * recovers from a version file address.
45
+ * @public
46
+ */
47
+ export interface ITemporalVersionAddress {
48
+ /** The stable consumer-supplied domain key. */
49
+ readonly entityId: EntityId;
50
+ /** The version's monotonic `seq` (the `v<seq>` component of the file stem). */
51
+ readonly seq: number;
52
+ }
53
+ /**
54
+ * Additive extension of {@link IIdentityCodec} for versioned (temporal) kinds. A
55
+ * codec whose {@link IIdentityCodec.encode | encode} reports `isVersioned: true`
56
+ * implements this so the store can form and parse per-version filenames without
57
+ * knowing the layout. Non-versioned codecs do NOT implement it (probe with
58
+ * {@link isTemporalIdentityCodec}).
59
+ * @public
60
+ */
61
+ export interface ITemporalIdentityCodec extends IIdentityCodec {
62
+ /**
63
+ * Form the version filename stem for a specific `(entityId, seq)`. The store
64
+ * appends the extension and writes it under the entity subtree returned by
65
+ * {@link IIdentityCodec.encode | encode}.
66
+ */
67
+ encodeVersion(entityId: EntityId, seq: number): Result<string>;
68
+ /**
69
+ * Parse a `(subtree scope, version stem)` back to its
70
+ * {@link ITemporalVersionAddress}. The subtree scope is authoritative for the
71
+ * `entityId`, disambiguating a stem whose `entityId` itself ends in
72
+ * `-v<digits>`.
73
+ */
74
+ decodeVersion(scope: MemoryScopeKey, stem: string): Result<ITemporalVersionAddress>;
75
+ }
76
+ /**
77
+ * Narrow an {@link IIdentityCodec} to {@link ITemporalIdentityCodec} by probing
78
+ * for the versioned methods. Used by the store when an `encode` result reports
79
+ * `isVersioned: true`.
80
+ * @public
81
+ */
82
+ export declare function isTemporalIdentityCodec(codec: IIdentityCodec): codec is ITemporalIdentityCodec;
83
+ /**
84
+ * Identity codec for a versioned (temporal) kind family, resolving OQ-11 to the
85
+ * subtree-per-entity layout: every version of an entity is a distinct file under
86
+ * a per-entity subtree.
87
+ *
88
+ * @remarks
89
+ * - `encode`: scope = `<baseScope>/entities/<entityId>`, idStem = `<entityId>`,
90
+ * `isVersioned = true`. The idStem is the stable entity prefix; the store forms
91
+ * each version's filename via {@link TemporalIdentityCodec.encodeVersion}.
92
+ * - `encodeVersion`: version stem = `<entityId>-v<seq>`.
93
+ * - `decode` / `decodeVersion`: recover `entityId` (and `seq`) from a
94
+ * `(subtree scope, version stem)` pair; the scope is authoritative for the
95
+ * `entityId`.
96
+ * - Escaping: `baseScope` and `entityId` must each match the POSIX portable
97
+ * filename set (they become path segments); `seq` is a non-negative integer.
98
+ * - Layout: `vault/<baseScope>/entities/<entityId>/<entityId>-v<seq>.md`.
99
+ * @public
100
+ */
101
+ export declare class TemporalIdentityCodec implements ITemporalIdentityCodec {
102
+ /** The fixed subtree segment separating an entity's versions from its scope. */
103
+ static readonly entitiesSegment: string;
104
+ /** The version-stem infix: `<entityId>` + this + `<seq>`. */
105
+ static readonly versionInfix: string;
106
+ /** A non-negative integer string (the version seq). */
107
+ private static readonly _versionSeqRe;
108
+ /** The base scope segment this codec's entities live under. */
109
+ readonly baseScope: string;
110
+ private constructor();
111
+ /**
112
+ * Family-convention factory. Validates that `baseScope` is a single portable
113
+ * filename segment (it becomes the top-level path component).
114
+ */
115
+ static create(baseScope: string): Result<TemporalIdentityCodec>;
116
+ /** {@inheritDoc IIdentityCodec.encode} */
117
+ encode(entityId: EntityId): Result<IIdentityCodecResult>;
118
+ /** {@inheritDoc ITemporalIdentityCodec.encodeVersion} */
119
+ encodeVersion(entityId: EntityId, seq: number): Result<string>;
120
+ /** {@inheritDoc IIdentityCodec.decode} */
121
+ decode(scope: MemoryScopeKey, encodedStem: string): Result<EntityId>;
122
+ /** {@inheritDoc ITemporalIdentityCodec.decodeVersion} */
123
+ decodeVersion(scope: MemoryScopeKey, stem: string): Result<ITemporalVersionAddress>;
124
+ /** {@inheritDoc IIdentityCodec.verifyRoundTrip} */
125
+ verifyRoundTrip(scope: MemoryScopeKey, stem: string): Result<true>;
126
+ /** Validate and extract the `entityId` from a `<baseScope>/entities/<entityId>` scope. */
127
+ private _entityIdFromScope;
128
+ }
43
129
  /**
44
130
  * Identity codec for the knowledge kind family. A knowledge entity is keyed
45
131
  * by its consumer-supplied `docId`, which is used verbatim as the filename
@@ -1 +1 @@
1
- {"version":3,"file":"identityCodec.d.ts","sourceRoot":"","sources":["../../../src/packlets/types/identityCodec.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAiB,MAAM,eAAe,CAAC;AACtD,OAAO,EAAW,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAG1D;;;GAGG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,QAAQ,CAAC,KAAK,EAAE,cAAc,CAAC;IAC/B,2EAA2E;IAC3E,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB;;;;OAIG;IACH,QAAQ,CAAC,WAAW,EAAE,OAAO,CAAC;CAC/B;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;IAEzD;;;OAGG;IACH,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;IAErE;;;OAGG;IACH,eAAe,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;CACpE;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,sBAAuB,YAAW,cAAc;IAC3D,kDAAkD;IAClD,gBAAuB,KAAK,EAAE,cAAc,CAAiC;IAE7E,0CAA0C;IACnC,MAAM,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAAC,oBAAoB,CAAC;IAM/D,0CAA0C;IACnC,MAAM,CAAC,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,GAAG,MAAM,CAAC,QAAQ,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