hiveagents-runtime 0.0.0-stage → 0.1.0-beta.3

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 (115) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +89 -2
  3. package/dist/adapter-kit.d.ts +37 -0
  4. package/dist/adapter-kit.js +34 -0
  5. package/dist/adapter-kit.js.map +1 -0
  6. package/dist/agent-Bj5YPrO7.d.ts +169 -0
  7. package/dist/agent-D6OXR7UF.js +24 -0
  8. package/dist/agent-D6OXR7UF.js.map +1 -0
  9. package/dist/agent-readiness-KSGNKTGK.js +19 -0
  10. package/dist/agent-readiness-KSGNKTGK.js.map +1 -0
  11. package/dist/capture-runtime-GP6NZ2ee.d.ts +54 -0
  12. package/dist/chunk-2RK74GCA.js +2397 -0
  13. package/dist/chunk-2RK74GCA.js.map +1 -0
  14. package/dist/chunk-3TIYA3K5.js +55 -0
  15. package/dist/chunk-3TIYA3K5.js.map +1 -0
  16. package/dist/chunk-6FIXXWNM.js +1 -0
  17. package/dist/chunk-6FIXXWNM.js.map +1 -0
  18. package/dist/chunk-6XIJW65Q.js +52 -0
  19. package/dist/chunk-6XIJW65Q.js.map +1 -0
  20. package/dist/chunk-7LDQKJKI.js +248 -0
  21. package/dist/chunk-7LDQKJKI.js.map +1 -0
  22. package/dist/chunk-CPN4DOXH.js +115 -0
  23. package/dist/chunk-CPN4DOXH.js.map +1 -0
  24. package/dist/chunk-DAXPAV2L.js +810 -0
  25. package/dist/chunk-DAXPAV2L.js.map +1 -0
  26. package/dist/chunk-DQEMIGKC.js +291 -0
  27. package/dist/chunk-DQEMIGKC.js.map +1 -0
  28. package/dist/chunk-DZFFGUIA.js +81 -0
  29. package/dist/chunk-DZFFGUIA.js.map +1 -0
  30. package/dist/chunk-EEUYQFCP.js +106 -0
  31. package/dist/chunk-EEUYQFCP.js.map +1 -0
  32. package/dist/chunk-G6JV7WV6.js +521 -0
  33. package/dist/chunk-G6JV7WV6.js.map +1 -0
  34. package/dist/chunk-GFVYNPLS.js +118 -0
  35. package/dist/chunk-GFVYNPLS.js.map +1 -0
  36. package/dist/chunk-GS5U3KUN.js +201 -0
  37. package/dist/chunk-GS5U3KUN.js.map +1 -0
  38. package/dist/chunk-HB7FBSH2.js +960 -0
  39. package/dist/chunk-HB7FBSH2.js.map +1 -0
  40. package/dist/chunk-HZFZX5A3.js +21 -0
  41. package/dist/chunk-HZFZX5A3.js.map +1 -0
  42. package/dist/chunk-J7VAYJKM.js +595 -0
  43. package/dist/chunk-J7VAYJKM.js.map +1 -0
  44. package/dist/chunk-NCNSHOF7.js +52 -0
  45. package/dist/chunk-NCNSHOF7.js.map +1 -0
  46. package/dist/chunk-RH5A5U7G.js +202 -0
  47. package/dist/chunk-RH5A5U7G.js.map +1 -0
  48. package/dist/chunk-RX3XZENU.js +385 -0
  49. package/dist/chunk-RX3XZENU.js.map +1 -0
  50. package/dist/chunk-RXU2Q2HF.js +49 -0
  51. package/dist/chunk-RXU2Q2HF.js.map +1 -0
  52. package/dist/chunk-TG7NTMTR.js +208 -0
  53. package/dist/chunk-TG7NTMTR.js.map +1 -0
  54. package/dist/chunk-TWGEYWMO.js +1217 -0
  55. package/dist/chunk-TWGEYWMO.js.map +1 -0
  56. package/dist/chunk-UZPDDQVJ.js +2910 -0
  57. package/dist/chunk-UZPDDQVJ.js.map +1 -0
  58. package/dist/chunk-WMKO5XOE.js +601 -0
  59. package/dist/chunk-WMKO5XOE.js.map +1 -0
  60. package/dist/chunk-WOQBVJH5.js +175 -0
  61. package/dist/chunk-WOQBVJH5.js.map +1 -0
  62. package/dist/chunk-WVT5SEKC.js +581 -0
  63. package/dist/chunk-WVT5SEKC.js.map +1 -0
  64. package/dist/cli.d.ts +1 -0
  65. package/dist/cli.js +26 -0
  66. package/dist/cli.js.map +1 -0
  67. package/dist/errors-BNHvvjn9.d.ts +98 -0
  68. package/dist/execution-halt-B8G0fOKS.d.ts +12 -0
  69. package/dist/execution-types-ClYYqPQP.d.ts +239 -0
  70. package/dist/host-ledger-VPRWVVOS.js +25 -0
  71. package/dist/host-ledger-VPRWVVOS.js.map +1 -0
  72. package/dist/hosted-runtime.d.ts +168 -0
  73. package/dist/hosted-runtime.js +858 -0
  74. package/dist/hosted-runtime.js.map +1 -0
  75. package/dist/index-B86C6VAD.d.ts +41 -0
  76. package/dist/index.d.ts +344 -0
  77. package/dist/index.js +8825 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/memory-items-BSTC0_R0.d.ts +28 -0
  80. package/dist/memory-tools.d.ts +222 -0
  81. package/dist/memory-tools.js +923 -0
  82. package/dist/memory-tools.js.map +1 -0
  83. package/dist/orchestration/dynamic.d.ts +854 -0
  84. package/dist/orchestration/dynamic.js +3150 -0
  85. package/dist/orchestration/dynamic.js.map +1 -0
  86. package/dist/orchestration/graph.d.ts +11 -0
  87. package/dist/orchestration/graph.js +9 -0
  88. package/dist/orchestration/graph.js.map +1 -0
  89. package/dist/orchestration/index.d.ts +2385 -0
  90. package/dist/orchestration/index.js +6409 -0
  91. package/dist/orchestration/index.js.map +1 -0
  92. package/dist/orchestration/log.d.ts +301 -0
  93. package/dist/orchestration/log.js +3058 -0
  94. package/dist/orchestration/log.js.map +1 -0
  95. package/dist/orchestration/memory.d.ts +711 -0
  96. package/dist/orchestration/memory.js +27 -0
  97. package/dist/orchestration/memory.js.map +1 -0
  98. package/dist/provider-DX5Mf0uq.d.ts +151 -0
  99. package/dist/routing/index.d.ts +29 -0
  100. package/dist/routing/index.js +386 -0
  101. package/dist/routing/index.js.map +1 -0
  102. package/dist/routing/learning/index.d.ts +433 -0
  103. package/dist/routing/learning/index.js +2502 -0
  104. package/dist/routing/learning/index.js.map +1 -0
  105. package/dist/runtime-BSjrnxeF.d.ts +283 -0
  106. package/dist/runtime-OISPXS4I.js +19 -0
  107. package/dist/runtime-OISPXS4I.js.map +1 -0
  108. package/dist/store-types-2YdceOMy.d.ts +78 -0
  109. package/dist/types-BB7KqceP.d.ts +52 -0
  110. package/dist/types-CIqkKXix.d.ts +86 -0
  111. package/dist/types-DTFc1qO6.d.ts +1065 -0
  112. package/dist/types-DYex3p7_.d.ts +88 -0
  113. package/docs/licenses/ruflo-memory-MIT.txt +21 -0
  114. package/docs/releases/0.1.0-beta.3.md +13 -0
  115. package/package.json +114 -4
@@ -0,0 +1,711 @@
1
+ import { L as LogPosition } from '../types-BB7KqceP.js';
2
+ import { J as JsonValue } from '../types-DYex3p7_.js';
3
+ import { e as LogEntry, d as LogCursor, L as LogSourceDescriptor, b as LogQuery, c as LogPage } from '../store-types-2YdceOMy.js';
4
+ import { af as MemoryCaptureRequest, ah as MemoryProfileRequest, g as AgentMemoryProvider } from '../types-DTFc1qO6.js';
5
+ export { M as MEMORY_LABEL_MAX, a as MEMORY_OBSERVED_AT_MAX, i as isMemoryLabel, r as recallableMemory } from '../memory-items-BSTC0_R0.js';
6
+
7
+ /**
8
+ * BM25/cosine/MMR retrieval adapted from Ruflo's hybrid-retrieval.ts at
9
+ * 0a96fb8857dabd343d71d76c3ca703100a2923bc (MIT, copyright 2024-2026 ruvnet).
10
+ * The upstream notice is in docs/licenses/ruflo-memory-MIT.txt.
11
+ */
12
+ /** A caller-owned record. No store is opened, retained, or searched implicitly. */
13
+ interface MemoryDocument {
14
+ id: string;
15
+ text: string;
16
+ embedding?: readonly number[];
17
+ }
18
+ interface MemoryRankingOptions {
19
+ /** Maximum results; a nonnegative safe integer. Default: 5. */
20
+ limit?: number;
21
+ /** Weight in [0, 1]. Default: 1. At least one retrieval weight must be positive. */
22
+ lexicalWeight?: number;
23
+ /** Weight in [0, 1]. Default: 0. A positive value requires queryEmbedding. */
24
+ semanticWeight?: number;
25
+ /** Supplied by the caller, from the same model as document embeddings. */
26
+ queryEmbedding?: readonly number[];
27
+ /**
28
+ * MMR penalty in [0, 1]; 0 disables reranking. Default: 0.
29
+ * Uses cosine between nonzero vectors, otherwise token-set Jaccard similarity.
30
+ * Seeds the most relevant record even when diversity=1.
31
+ */
32
+ diversity?: number;
33
+ }
34
+ interface MemoryScores {
35
+ /** Unbounded nonnegative BM25 score (k1=1.2, b=0.75). */
36
+ lexical: number;
37
+ /** lexical / (1 + lexical); a zero match stays zero. */
38
+ lexicalNormalized: number;
39
+ /** Cosine similarity clamped to [0, 1]; missing/zero vectors score zero. */
40
+ semantic: number;
41
+ /** Weighted mean of lexicalNormalized and semantic. Not a probability. */
42
+ relevance: number;
43
+ /** Maximum similarity to an earlier MMR selection; 0 when MMR is disabled. */
44
+ redundancy: number;
45
+ /** (1 - diversity) * relevance - diversity * redundancy; may be negative. */
46
+ mmr: number;
47
+ }
48
+ interface RankedMemory<T extends MemoryDocument> {
49
+ /** The exact input object; all caller payload and provenance remain intact. */
50
+ record: T;
51
+ scores: MemoryScores;
52
+ }
53
+ /**
54
+ * Rank only the supplied records. Pure, synchronous, browser-safe, and stateless:
55
+ * it never fetches embeddings, opens a store, or retains provider memory.
56
+ *
57
+ * The default is lexical BM25 with accent-folded Unicode tokens. There is no
58
+ * stemming, stop-word removal, or synonym expansion. Scores depend on the
59
+ * supplied corpus. Semantic retrieval and diversity are explicit opt-ins.
60
+ * All supplied vectors are validated, including when unused or limit=0.
61
+ * Equal scores retain input order. The caller owns filtering/authorization,
62
+ * forgetting, persistence, and ensuring embeddings share a model/version.
63
+ */
64
+ declare function rankMemories<T extends MemoryDocument>(query: string, documents: readonly T[], options?: MemoryRankingOptions): RankedMemory<T>[];
65
+
66
+ /** Scope and persistence belong to the application; no global store or implicit cross-scope recall. */
67
+ interface MemoryScope {
68
+ tenant: string;
69
+ namespace: string;
70
+ subject?: string;
71
+ }
72
+ interface MemoryProvenance {
73
+ source: string;
74
+ sourceVersion: string;
75
+ observedAt: string;
76
+ inputHash?: string;
77
+ /** The run-log entry this record was taken from, when it came from a system's own log. */
78
+ logPosition?: LogPosition;
79
+ }
80
+ /** Vectors from another identity must never be compared as if they shared a space. */
81
+ interface EmbeddingIdentity {
82
+ provider: string;
83
+ model: string;
84
+ revision: string;
85
+ dimensions: number;
86
+ }
87
+ /**
88
+ * Temporal validity: a newer fact retires an older one instead of both being recalled.
89
+ *
90
+ * - `supersedes` names lessons of the SAME scope that this record replaces (ids only: a record
91
+ * never reaches into another scope). It takes effect when this record is PROMOTED, never when
92
+ * it is put: an unpromoted episode cannot retire anything, so an injected episode cannot
93
+ * suppress good memory. On promotion every superseded lesson is marked invalidated by this
94
+ * record's id at the promotion time, in the same commit. That is a final, auditable state like
95
+ * a rollback, not a deletion: the lesson stays listed, is never recalled again, and rolling back
96
+ * the newer record does not restore it. A store refuses the promotion, with a typed error and
97
+ * changing nothing, when any named id is not a live, promoted, not yet invalidated lesson of
98
+ * this scope (unknown, an episode, withdrawn, already invalidated, or only present in another
99
+ * scope).
100
+ * - `validUntil` is a strict ISO-8601 instant (`YYYY-MM-DDTHH:MM[:SS[.fraction]]` then `Z` or
101
+ * `±HH:MM`) after which the record must not be recalled. Stores keep it in UTC as
102
+ * `Date.prototype.toISOString()` gives it. An expired record cannot be promoted.
103
+ *
104
+ * Both are part of the record's content: they count in its content digest when present.
105
+ */
106
+ interface ScopedMemoryRecord {
107
+ id: string;
108
+ scope: MemoryScope;
109
+ text: string;
110
+ provenance: MemoryProvenance;
111
+ metadata?: JsonValue;
112
+ embedding?: {
113
+ identity: EmbeddingIdentity;
114
+ values: readonly number[];
115
+ };
116
+ revokedAt?: string;
117
+ /** Ids of lessons in the same scope this record replaces once it is promoted. Nonempty, no repeats. */
118
+ supersedes?: readonly string[];
119
+ /** Strict ISO-8601 instant after which the record is never recalled. */
120
+ validUntil?: string;
121
+ }
122
+ interface MemoryQuery {
123
+ scope: MemoryScope;
124
+ text: string;
125
+ limit: number;
126
+ /** A store must reject mismatched embedding spaces rather than silently comparing them. */
127
+ embedding?: {
128
+ identity: EmbeddingIdentity;
129
+ values: readonly number[];
130
+ };
131
+ signal?: AbortSignal;
132
+ }
133
+ interface MemoryRevocation {
134
+ scope: MemoryScope;
135
+ id: string;
136
+ revokedAt: string;
137
+ reason: string;
138
+ }
139
+ interface MemoryRecordLookup {
140
+ scope: MemoryScope;
141
+ id: string;
142
+ signal?: AbortSignal;
143
+ }
144
+ interface MemoryPersistencePort {
145
+ /** Must retain scope/provenance and reject embedding identity/dimension mismatches. */
146
+ put(record: ScopedMemoryRecord, signal?: AbortSignal): Promise<void>;
147
+ /** Atomic tombstone; implementations must exclude revoked records from query results. */
148
+ revoke(revocation: MemoryRevocation, signal?: AbortSignal): Promise<void>;
149
+ /**
150
+ * Optional read-back for a writer, never recall: the record stored under this id in this exact
151
+ * scope, episode or lesson, as stored; undefined when there is none, it is withdrawn, or the
152
+ * caller may not read that scope. `memoryProviderFromPorts` uses it to tell a proposal made
153
+ * again (same text, a CONFLICT on `put`) from another record under the same id; without it,
154
+ * that CONFLICT is passed on.
155
+ */
156
+ get?(lookup: MemoryRecordLookup): Promise<ScopedMemoryRecord | undefined>;
157
+ }
158
+ interface MemoryQueryPort {
159
+ /**
160
+ * Exact scope only; excludes revoked, invalidated (superseded) and expired (`validUntil` passed)
161
+ * records. Ranking policy remains application-owned.
162
+ */
163
+ query(query: MemoryQuery): Promise<readonly ScopedMemoryRecord[]>;
164
+ }
165
+ interface MemoryPorts {
166
+ persistence?: MemoryPersistencePort;
167
+ recall?: MemoryQueryPort;
168
+ }
169
+ /**
170
+ * The application's embedding model, behind one call. The SDK ships none and
171
+ * downloads none: an embedder is always supplied by the caller.
172
+ *
173
+ * `embed` returns one vector per text, in the same order. Every vector must
174
+ * have exactly `identity.dimensions` entries, all finite numbers; a consumer
175
+ * rejects anything else instead of padding or truncating it. `identity` names
176
+ * the vector space: records and queries embedded under another identity are
177
+ * never compared with these. It must not change for the lifetime of the
178
+ * embedder; a new model or revision is a new embedder.
179
+ */
180
+ interface MemoryEmbedder {
181
+ readonly identity: EmbeddingIdentity;
182
+ /** Must observe `signal`; an aborted call rejects. */
183
+ embed(texts: readonly string[], signal?: AbortSignal): Promise<ReadonlyArray<readonly number[]>>;
184
+ }
185
+
186
+ /**
187
+ * The promotion gate: a measured comparison, supplied by the caller, between the
188
+ * same task set run without memory, with memory, and with the full history.
189
+ *
190
+ * This file is pure (no Node imports) so a renderer can show a gate verdict.
191
+ */
192
+ /** How many tasks of the shared task set passed under one condition. */
193
+ interface MemoryConditionTally {
194
+ passed: number;
195
+ total: number;
196
+ }
197
+ /**
198
+ * What a promotion must carry. Both controls are mandatory: a claim about memory
199
+ * that was not measured against no-memory AND full-history is not evidence.
200
+ */
201
+ interface MemoryGateEvidence {
202
+ /** Caller's id for the measurement that produced these numbers. */
203
+ measurementId: string;
204
+ /** SHA-256 of the measurement report, so the numbers can be traced to it. */
205
+ digest: string;
206
+ /**
207
+ * Content digests (`MemoryRecordView.contentDigest`) of the records that were
208
+ * in the memory condition. A digest binds scope, id and content, so evidence
209
+ * for one record cannot promote another one that merely shares its id.
210
+ */
211
+ candidateDigests: readonly string[];
212
+ noMemory: MemoryConditionTally;
213
+ memory: MemoryConditionTally;
214
+ fullHistory: MemoryConditionTally;
215
+ }
216
+ type MemoryGateRefusal = 'NO_GAIN_OVER_NO_MEMORY' | 'CANDIDATE_NOT_MEASURED';
217
+ type MemoryGateVerdict = {
218
+ passed: true;
219
+ } | {
220
+ passed: false;
221
+ reason: 'NO_GAIN_OVER_NO_MEMORY';
222
+ };
223
+ /**
224
+ * The rule the store applies before a lesson becomes recallable: memory must pass
225
+ * strictly more tasks than the no-memory control. Full history is the ceiling
226
+ * reference; it must have been measured, but memory is not required to beat it,
227
+ * because its point is to get close to that ceiling with far less context.
228
+ *
229
+ * Throws on incomplete evidence; a missing control is never a pass.
230
+ */
231
+ declare function evaluateMemoryGate(evidence: MemoryGateEvidence): MemoryGateVerdict;
232
+
233
+ /** Default and hard ceiling for lessons delivered by one recall. */
234
+ declare const MAX_LESSONS_PER_RECALL = 3;
235
+ declare const MAX_LESSONS_CEILING = 8;
236
+ interface SystemMemoryOptions {
237
+ /** Absolute path of the shared memory database. Created on first use, never reset. */
238
+ databasePath: string;
239
+ /**
240
+ * The system this handle acts as. The store trusts the id its host binds here:
241
+ * it scopes and audits, it does not authenticate the caller.
242
+ */
243
+ systemId: string;
244
+ /** SQLite busy timeout in milliseconds. Default: 5000. */
245
+ busyTimeoutMs?: number;
246
+ /** Lessons delivered per recall, 1 to 8. Default: 3. */
247
+ maxLessonsPerRecall?: number;
248
+ /** ISO-8601 clock, injectable for tests. Default: the system clock. */
249
+ now?: () => string;
250
+ }
251
+ /** Who performed an administrative change. Recorded, not authenticated. */
252
+ interface MemoryActor {
253
+ by: string;
254
+ }
255
+ interface MemoryStatus {
256
+ systemId: string;
257
+ /** False until the system enables memory; while false every read is empty and writes are refused. */
258
+ enabled: boolean;
259
+ changedBy?: string;
260
+ changedAt?: string;
261
+ }
262
+ interface MemoryListQuery {
263
+ scope: MemoryScope;
264
+ /** 1 to 256. Default: 64. */
265
+ limit?: number;
266
+ }
267
+ /**
268
+ * What recall does with a stored record right now:
269
+ * - `episode`: stored, never promoted; not recalled until a measured gate promotes it.
270
+ * - `lesson`: promoted; recalled.
271
+ * - `invalidated`: was a lesson, retired by a promoted record that supersedes it (`invalidation`
272
+ * says which and when). Final.
273
+ * - `expired`: its `validUntil` had passed when it was listed; never recalled, never promoted.
274
+ * `promotion` says whether it had been a lesson.
275
+ */
276
+ type MemoryRecordState = 'episode' | 'lesson' | 'invalidated' | 'expired';
277
+ /** A stored observation as its owner sees it. Withdrawn (revoked, rolled back) records are not listed. */
278
+ interface MemoryRecordView {
279
+ record: ScopedMemoryRecord;
280
+ state: MemoryRecordState;
281
+ /**
282
+ * SHA-256 over scope, id, text, provenance, metadata and embedding, and also over
283
+ * `supersedes` and `validUntil` when the record has them (a record without them keeps
284
+ * the digest it had before they existed). It is what a measurement names as its
285
+ * candidate, and what `promote` looks for in the gate: evidence for a record binds
286
+ * what it names to retire, though the measurement does not measure that retirement.
287
+ */
288
+ contentDigest: string;
289
+ recordedAt: string;
290
+ promotion?: {
291
+ promotedAt: string;
292
+ promotedBy: string;
293
+ gate: MemoryGateEvidence;
294
+ };
295
+ /** Set when a promoted record of the same scope that supersedes this lesson retired it. */
296
+ invalidation?: {
297
+ invalidatedAt: string;
298
+ supersededBy: string;
299
+ };
300
+ }
301
+ interface MemoryPromotion {
302
+ scope: MemoryScope;
303
+ id: string;
304
+ /** The measured comparison that justifies recalling this record; it must name the record's content digest. */
305
+ gate: MemoryGateEvidence;
306
+ by: string;
307
+ }
308
+ type MemoryPromotionResult = {
309
+ promoted: true;
310
+ promotedAt: string;
311
+ } | {
312
+ promoted: false;
313
+ reason: MemoryGateRefusal;
314
+ };
315
+ interface MemoryRollback {
316
+ scope: MemoryScope;
317
+ id: string;
318
+ by: string;
319
+ reason: string;
320
+ }
321
+ interface MemoryGrantRequest {
322
+ /** The system that may recall the owner's lessons in this exact scope. */
323
+ to: string;
324
+ namespace: string;
325
+ subject?: string;
326
+ by: string;
327
+ }
328
+ interface MemoryGrant {
329
+ id: string;
330
+ owner: string;
331
+ grantee: string;
332
+ namespace: string;
333
+ subject?: string;
334
+ grantedBy: string;
335
+ grantedAt: string;
336
+ revokedBy?: string;
337
+ revokedAt?: string;
338
+ }
339
+ interface MemoryGrantRevocation {
340
+ id: string;
341
+ by: string;
342
+ }
343
+ interface MemoryLogSearch {
344
+ text: string;
345
+ /** Matches returned per window, 1 to 50. Default: 5. A window with more is reported as `truncated`. */
346
+ limit?: number;
347
+ /** Width of the window: log entries read by this call, 1 to 8192. Default: 2048. */
348
+ maxScanned?: number;
349
+ runId?: string;
350
+ agentId?: string;
351
+ generation?: number;
352
+ /** `nextCursor` of an earlier call with the same filters, to continue its scan. */
353
+ cursor?: LogCursor;
354
+ }
355
+ interface MemoryLogMatch {
356
+ /** Where the entry lives in the log; use it as `provenance.logPosition`. */
357
+ position: LogPosition;
358
+ entry: LogEntry;
359
+ /** The text that was matched: the entry type and the strings of its inline payload. */
360
+ text: string;
361
+ /** BM25 score among the matches of this call. Not comparable across calls. */
362
+ score: number;
363
+ }
364
+ /**
365
+ * One window of a log search: the entries read by this call, best matches first.
366
+ *
367
+ * A window can hold more matches than `limit`. Then `truncated` is true and
368
+ * `found - matches.length` matches of this window were NOT returned; `nextCursor`
369
+ * continues after the whole window and will not bring them back. To get them,
370
+ * repeat the same call (same cursor) with a larger `limit` or a smaller
371
+ * `maxScanned`: a window no wider than `limit` is never truncated.
372
+ */
373
+ interface MemoryLogSearchResult {
374
+ matches: readonly MemoryLogMatch[];
375
+ /** Readable matches in this window, returned or not. Withdrawn entries are not counted. */
376
+ found: number;
377
+ /** True when this window held more matches than it returned. */
378
+ truncated: boolean;
379
+ /** Log entries read by this call. */
380
+ scanned: number;
381
+ /** True only when the scan reached the head of the log. It says nothing about `truncated`. */
382
+ complete: boolean;
383
+ nextCursor?: LogCursor;
384
+ }
385
+ /**
386
+ * `INVALID_SUPERSESSION`: a promotion named in `supersedes` an id that is not a live, promoted,
387
+ * not yet invalidated lesson of the record's own scope. `EXPIRED`: a promotion of a record whose
388
+ * `validUntil` has passed. Both refuse the promotion and change nothing.
389
+ */
390
+ type MemoryStoreErrorCode = 'INVALID_INPUT' | 'DISABLED' | 'NOT_OWNER' | 'NOT_FOUND' | 'CONFLICT' | 'WITHDRAWN' | 'NOT_PROMOTED' | 'EMBEDDING_MISMATCH' | 'UNSUPPORTED_DATABASE' | 'STORAGE' | 'CLOSED' | 'INVALID_SUPERSESSION' | 'EXPIRED';
391
+ /** The message carries only the code, never stored text or caller input. */
392
+ declare class MemoryStoreError extends Error {
393
+ readonly code: MemoryStoreErrorCode;
394
+ constructor(code: MemoryStoreErrorCode, options?: {
395
+ cause?: unknown;
396
+ });
397
+ }
398
+ declare function isMemoryStoreError(value: unknown): value is MemoryStoreError;
399
+
400
+ /** The three conditions every task runs under, always in this order. */
401
+ type MemoryCondition = 'no-memory' | 'memory' | 'full-history';
402
+ interface MemoryMeasurementTask {
403
+ id: string;
404
+ input: JsonValue;
405
+ }
406
+ interface MemoryRunContext {
407
+ condition: MemoryCondition;
408
+ /** Empty under no-memory; the recalled items under memory; the whole history under full-history. */
409
+ context: readonly string[];
410
+ signal?: AbortSignal;
411
+ }
412
+ /** What the caller's runner reports for one task under one condition. */
413
+ interface MemoryRunOutcome {
414
+ passed: boolean;
415
+ score?: number;
416
+ }
417
+ type MaybePromise<T> = T | Promise<T>;
418
+ interface MeasureMemoryOptions {
419
+ id: string;
420
+ tasks: readonly MemoryMeasurementTask[];
421
+ /**
422
+ * Content digests (`MemoryRecordView.contentDigest`) of the memory records
423
+ * under test; copied into the gate evidence, which then promotes only them.
424
+ */
425
+ candidateDigests: readonly string[];
426
+ /** Context of the memory condition: what recall would deliver for this task. */
427
+ recall(task: MemoryMeasurementTask, signal?: AbortSignal): MaybePromise<readonly string[]>;
428
+ /** Context of the full-history control: everything, unfiltered. */
429
+ history(task: MemoryMeasurementTask, signal?: AbortSignal): MaybePromise<readonly string[]>;
430
+ /** Runs one task with the given context. The harness makes no model call of its own. */
431
+ run(task: MemoryMeasurementTask, context: MemoryRunContext): MaybePromise<MemoryRunOutcome>;
432
+ signal?: AbortSignal;
433
+ }
434
+ interface MemoryTaskOutcome {
435
+ passed: boolean;
436
+ score?: number;
437
+ /** The context provider or the runner threw, or returned something unusable. Counted as not passed. */
438
+ error?: true;
439
+ contextItems: number;
440
+ contextChars: number;
441
+ }
442
+ interface MemoryConditionSummary extends MemoryConditionTally {
443
+ passRate: number;
444
+ errors: number;
445
+ /** Context handed to the runner across the task set: the cost side of the comparison. */
446
+ contextItems: number;
447
+ contextChars: number;
448
+ }
449
+ interface MemoryMeasurementReport {
450
+ format: 1;
451
+ id: string;
452
+ candidateDigests: readonly string[];
453
+ conditions: Readonly<Record<MemoryCondition, MemoryConditionSummary>>;
454
+ tasks: readonly {
455
+ id: string;
456
+ outcomes: Readonly<Record<MemoryCondition, MemoryTaskOutcome>>;
457
+ }[];
458
+ /** Pass-rate differences. Memory is judged against both controls, never alone. */
459
+ deltas: {
460
+ memoryVsNoMemory: number;
461
+ memoryVsFullHistory: number;
462
+ };
463
+ /** The rule a promotion applies: memory must beat the no-memory control. */
464
+ verdict: MemoryGateVerdict;
465
+ /** Ready to hand to `promote`; its digest is this report's digest. */
466
+ gate: MemoryGateEvidence;
467
+ digest: string;
468
+ }
469
+ /**
470
+ * Runs the same task set under three conditions — no memory, memory, full
471
+ * history — through the caller's runner, and reports the three outcomes side by
472
+ * side. This is the only shape a claim about memory may take: a comparison
473
+ * against both controls.
474
+ *
475
+ * A caller can rely on:
476
+ * - Every task runs under all three conditions, in a fixed order; there is no
477
+ * partial report. An abort rejects instead.
478
+ * - The no-memory context is always empty; the harness builds it, not the caller.
479
+ * - A failing context provider or runner counts as a task that did not pass and
480
+ * is flagged, so one broken run cannot make a condition look better.
481
+ * - The report is deterministic for the same outcomes and carries its own digest.
482
+ *
483
+ * It does not judge honesty: the runner and both context functions are the
484
+ * caller's, and the result is only as good as they are.
485
+ */
486
+ declare function measureMemory(input: MeasureMemoryOptions): Promise<MemoryMeasurementReport>;
487
+
488
+ /** The part of the run-log store this search needs. `SqliteRunLogStore` satisfies it. */
489
+ interface RunLogReader {
490
+ readonly descriptor: LogSourceDescriptor;
491
+ readPage(query?: LogQuery): Promise<LogPage>;
492
+ }
493
+
494
+ /**
495
+ * Agent memory over the memory ports: the adapter an `Agent`'s `memory` option
496
+ * takes. Pure (no Node imports): digests use Web Crypto, so it bundles for a
497
+ * browser like the rest of this entry.
498
+ *
499
+ * Recall asks the query port for at most `limit` records in the exact scope of
500
+ * the request and hands them to the agent as reference data. Capture is opt-in
501
+ * twice: the application must pass a persistence port here AND set
502
+ * `memory.capture: true` on the agent.
503
+ *
504
+ * Captured turns are episodes, not lessons. With `SqliteSystemMemory`, `query`
505
+ * returns only lessons that passed the promotion gate, so a captured turn is NOT
506
+ * recallable until the application measures it (`measureMemory`, with this
507
+ * episode as the only candidate) and promotes it (`promote`) with that evidence.
508
+ * Capture never promotes anything by itself. A proposal (`propose`, what an agent
509
+ * asks to remember through a memory tool) is stored the same way: an episode.
510
+ *
511
+ * `propose` is offered only where a proposal is sure to stay out of recall until it is
512
+ * promoted: when there is no `recall` port (this provider never reads what it stores), or when
513
+ * `captureGate` is `'store-promotes'`. With `'none-acknowledged'` recall may return what
514
+ * `persistence` stored, unreviewed, on the next turn: acceptable for the application's own
515
+ * captured turns if it says so, but a proposal is model output that the tool tells the agent
516
+ * is "not recallable until promoted", so the provider has no `propose` there.
517
+ *
518
+ * A store that returned what it was just given would recall a captured turn on
519
+ * the very next turn: whatever a model was induced to write once would be read
520
+ * back as memory on every later turn. So when both ports are given, the caller
521
+ * must say how recall is gated (`captureGate`); the adapter refuses to guess.
522
+ */
523
+ type MemoryCaptureGate =
524
+ /**
525
+ * The recall port returns only records promoted through a measured gate, never a
526
+ * stored episode as it is: `SqliteSystemMemory`, and the vector stores of
527
+ * `hiveagents-runtime-agentdb-memory`.
528
+ */
529
+ 'store-promotes'
530
+ /**
531
+ * The caller accepts that recall may return what capture stored, on the next
532
+ * turn, unreviewed: for example when `recall` reads a curated store that
533
+ * `persistence` never writes to. Never the right choice for one store that
534
+ * returns everything it holds. Covers captured turns only: the provider then
535
+ * has no `propose`, since a proposal must never be recalled before promotion.
536
+ */
537
+ | 'none-acknowledged';
538
+ interface MemoryPortsProviderOptions {
539
+ /** Recorded on every turn note. Default: `memory-ports`. */
540
+ id?: string;
541
+ /** Recall source. Without it the provider has no `recall`. */
542
+ recall?: MemoryQueryPort;
543
+ /** Capture target. Without it the provider has no `capture`. */
544
+ persistence?: MemoryPersistencePort;
545
+ /** Embeds the query text and, on capture, the stored text. Without it, recall is lexical only. */
546
+ embedder?: MemoryEmbedder;
547
+ /**
548
+ * Builds the record to store for a completed turn, replacing the default
549
+ * one-episode-per-turn record. Return undefined to store nothing. The record's
550
+ * scope must be the request's scope.
551
+ */
552
+ toRecord?: (request: MemoryCaptureRequest) => ScopedMemoryRecord | undefined | Promise<ScopedMemoryRecord | undefined>;
553
+ /** Clock for `provenance.observedAt`. Default: the system clock. */
554
+ now?: () => Date;
555
+ /**
556
+ * Required when both `recall` and `persistence` are given, refused otherwise:
557
+ * how a captured or proposed episode is kept out of recall until it is measured and promoted.
558
+ */
559
+ captureGate?: MemoryCaptureGate;
560
+ /**
561
+ * The scope's fixed profile, handed through as the provider's `profile` unchanged: the
562
+ * application maintains it, nothing an agent does reaches it. Without it the provider has no
563
+ * `profile`.
564
+ */
565
+ profile?: (request: MemoryProfileRequest) => Promise<string | undefined>;
566
+ }
567
+ /**
568
+ * Builds an `AgentMemoryProvider` from memory ports.
569
+ *
570
+ * ```ts
571
+ * const store = new SqliteSystemMemory({ databasePath, systemId: 'acme' });
572
+ * new Agent({ model, memory: {
573
+ * provider: memoryProviderFromPorts({ recall: store, persistence: store, captureGate: 'store-promotes' }),
574
+ * scope: { tenant: 'acme', namespace: 'support', subject: 'customer-42' },
575
+ * } });
576
+ * ```
577
+ *
578
+ * A caller can rely on:
579
+ * - recall never returns more than `limit` items, nor a record of another scope,
580
+ * a revoked one or one whose `validUntil` has passed (by `now`), whatever the
581
+ * port returns; a record the agent would drop (`recallableMemory`) is dropped
582
+ * here and does not count against `limit`;
583
+ * - both ports together are refused unless `captureGate` says how recall is gated;
584
+ * - an embedder whose vectors do not match its identity is refused, never
585
+ * padded or compared;
586
+ * - an aborted `signal` rejects recall and capture with its reason;
587
+ * - the default capture stores one episode per completed turn under an id
588
+ * derived from the session and turn (from the session, the exchange and
589
+ * `completedAt` when the turn has no id), so capturing the same request again
590
+ * is a no-op for an idempotent store, and an exchange repeated later in the
591
+ * session is an episode of its own;
592
+ * - recalled text is returned as data; this adapter adds no instruction to it;
593
+ * - `propose` exists with `persistence` and either no `recall` or `captureGate:
594
+ * 'store-promotes'`; it stores the agent's proposal, whole, as an episode under an id
595
+ * derived from the scope and the digest of the full text, so it is recallable only once
596
+ * promoted; a text that does not fit `EPISODE_MAX_BYTES` as rendered is refused (a
597
+ * TypeError), never cut; proposing the same text again in the scope names the same
598
+ * candidate, when the store can confirm it holds that text (`MemoryPersistencePort.get`);
599
+ * - `profile` is the caller's function, called as given.
600
+ */
601
+ declare function memoryProviderFromPorts(options: MemoryPortsProviderOptions): AgentMemoryProvider;
602
+
603
+ /**
604
+ * MCP server recipes for agent memory tools. Pure (no Node imports): a recipe
605
+ * is data the application hands to a provider, the SDK neither installs nor
606
+ * runs the package, and nothing here reads or writes the memory store.
607
+ *
608
+ * {@link claudeMcpConfig} turns recipes into one inline config for
609
+ * `providerOptions.claude.mcpConfigs` (Claude exec). Codex exec also takes MCP
610
+ * servers, as `mcp_servers.<name>` entries of `providerOptions.codex.config`,
611
+ * but the field layout of those entries is not verified against the Codex CLI
612
+ * in this repository, so no Codex helper is offered. Claude control rejects
613
+ * provider options and Codex control refuses `mcp_servers`, so a recipe reaches
614
+ * neither control transport.
615
+ *
616
+ * Two launch forms:
617
+ * - `executable`: an absolute path to a binary installed beforehand from a
618
+ * lockfile (`npm ci` in a directory the agent cannot write, then
619
+ * `<dir>/node_modules/.bin/agentdb`). The whole dependency tree is the one
620
+ * the lockfile pinned. This is the recommended form.
621
+ * - `version`: `npx -y <package>@<version>`. Only the top-level package is
622
+ * pinned: npm resolves its dependencies from their declared ranges when it
623
+ * installs into its cache, npx runs a package of the same name and version
624
+ * found in the launch directory's own project instead of fetching it, and
625
+ * that project's `.npmrc` can point the registry, scoped registries included,
626
+ * elsewhere. An untrusted workspace can therefore substitute the server. The
627
+ * SDK sets no `npm_config_*` variable: a registry override would outrank only
628
+ * the unscoped registry of a project `.npmrc`, would not stop the local
629
+ * substitution, and would override an owner's mirror.
630
+ *
631
+ * Both packages are published by a single maintainer and move fast, so the npx
632
+ * form pins an exact version: ranges, dist-tags and `latest` are refused.
633
+ * Arguments and environment names below were read from the published
634
+ * `agentdb@3.10.1` and `ruvector@0.3.27` sources; another version may differ.
635
+ */
636
+ interface McpServerRecipe {
637
+ readonly name: string;
638
+ /** `npx`, or the absolute path given as `executable`. */
639
+ readonly command: string;
640
+ readonly args: readonly string[];
641
+ readonly env: Readonly<Record<string, string>>;
642
+ }
643
+ /** Exactly one launch form: an exact npm version (npx) or a pre-installed binary. */
644
+ type McpRecipeLaunch = {
645
+ readonly version: string;
646
+ readonly executable?: undefined;
647
+ } | {
648
+ readonly executable: string;
649
+ readonly version?: undefined;
650
+ };
651
+ /**
652
+ * `AGENTDB_MCP_PROFILE` values, read-only first. `readonly` and `retrieval`
653
+ * expose the same read tools in 3.10.1; `learning` (the server's default when
654
+ * the variable is unset) adds store, update and feedback tools. `admin`, which
655
+ * unlocks delete and reset tools, is deliberately not offered here.
656
+ */
657
+ type AgentDbMcpProfile = 'readonly' | 'retrieval' | 'learning';
658
+ type AgentDbMcpServerOptions = McpRecipeLaunch & {
659
+ /** Absolute path of this agent's database file (`AGENTDB_PATH`); one file per agent. */
660
+ readonly databasePath: string;
661
+ readonly profile: AgentDbMcpProfile;
662
+ /** MCP server name, default `agentdb`; Claude names its tools `mcp__<name>__<tool>`. */
663
+ readonly name?: string;
664
+ };
665
+ /**
666
+ * RuVector policy, read-only first. `readonly` sets `RUVECTOR_MCP_PROFILE=readonly`,
667
+ * the only profile 0.3.27 defines. `unrestricted` sets no policy, which in
668
+ * 0.3.27 exposes every registered tool, memory writes included.
669
+ */
670
+ type RuvectorMcpProfile = 'readonly' | 'unrestricted';
671
+ type RuvectorMcpServerOptions = McpRecipeLaunch & {
672
+ /** MCP server name, default `ruvector`. */
673
+ readonly name?: string;
674
+ } & ({
675
+ readonly profile: 'readonly';
676
+ readonly sharedStoreAcknowledged?: boolean;
677
+ } | {
678
+ readonly profile: 'unrestricted';
679
+ /**
680
+ * Required for `unrestricted`: the server's store is shared by every agent
681
+ * launched from the same directory (or home), whatever its memory scope, so
682
+ * a write here is readable by another tenant's agent. The SDK cannot scope it.
683
+ */
684
+ readonly sharedStoreAcknowledged: true;
685
+ });
686
+ /**
687
+ * `agentdb mcp start` (through `npx -y agentdb@<version>` or the given
688
+ * executable) with `AGENTDB_PATH` and an explicit `AGENTDB_MCP_PROFILE`, so the
689
+ * server never falls back to its write-enabled default. The stdio server takes
690
+ * no flags; the database is set only by env.
691
+ */
692
+ declare function agentDbMcpServer(options: AgentDbMcpServerOptions): McpServerRecipe;
693
+ /**
694
+ * `ruvector mcp start` (through `npx -y ruvector@<version>` or the given
695
+ * executable). The 0.3.27 server keeps its memory in
696
+ * `.ruvector/intelligence.json` under the directory it is launched from (or the
697
+ * home directory when that already holds one) and reads no environment variable
698
+ * or flag for it, so this recipe offers no storage path option. That store is
699
+ * shared by every agent launched from the same directory or home and is not
700
+ * scoped by the SDK: `readonly` agents read whatever any writer put there, and
701
+ * `unrestricted` is refused unless `sharedStoreAcknowledged: true` is passed.
702
+ */
703
+ declare function ruvectorMcpServer(options: RuvectorMcpServerOptions): McpServerRecipe;
704
+ /**
705
+ * One inline config for `providerOptions.claude.mcpConfigs`:
706
+ * `{"mcpServers":{"<name>":{"command","args","env"}}}`. Duplicate names are
707
+ * refused rather than letting the later server silently replace the earlier.
708
+ */
709
+ declare function claudeMcpConfig(recipes: readonly McpServerRecipe[]): string;
710
+
711
+ export { type AgentDbMcpProfile, type AgentDbMcpServerOptions, type EmbeddingIdentity, MAX_LESSONS_CEILING, MAX_LESSONS_PER_RECALL, type McpRecipeLaunch, type McpServerRecipe, type MeasureMemoryOptions, type MemoryActor, type MemoryCaptureGate, type MemoryCondition, type MemoryConditionSummary, type MemoryConditionTally, type MemoryDocument, type MemoryEmbedder, type MemoryGateEvidence, type MemoryGateRefusal, type MemoryGateVerdict, type MemoryGrant, type MemoryGrantRequest, type MemoryGrantRevocation, type MemoryListQuery, type MemoryLogMatch, type MemoryLogSearch, type MemoryLogSearchResult, type MemoryMeasurementReport, type MemoryMeasurementTask, type MemoryPersistencePort, type MemoryPorts, type MemoryPortsProviderOptions, type MemoryPromotion, type MemoryPromotionResult, type MemoryProvenance, type MemoryQuery, type MemoryQueryPort, type MemoryRankingOptions, type MemoryRecordLookup, type MemoryRecordState, type MemoryRecordView, type MemoryRevocation, type MemoryRollback, type MemoryRunContext, type MemoryRunOutcome, type MemoryScope, type MemoryScores, type MemoryStatus, MemoryStoreError, type MemoryStoreErrorCode, type MemoryTaskOutcome, type RankedMemory, type RunLogReader, type RuvectorMcpProfile, type RuvectorMcpServerOptions, type ScopedMemoryRecord, type SystemMemoryOptions, agentDbMcpServer, claudeMcpConfig, evaluateMemoryGate, isMemoryStoreError, measureMemory, memoryProviderFromPorts, rankMemories, ruvectorMcpServer };