renor-engine 1.2.0 → 1.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (215) hide show
  1. package/README.md +21 -1
  2. package/THIRD-PARTY-NOTICES +2661 -0
  3. package/dist/BUILD.json +6 -0
  4. package/dist/cli.js +1656 -516
  5. package/package.json +16 -80
  6. package/dist/.tsbuildinfo +0 -1
  7. package/dist/api/apiAuth.js +0 -43
  8. package/dist/api/server.js +0 -174
  9. package/dist/buildIdentity.js +0 -149
  10. package/dist/callPhases.js +0 -82
  11. package/dist/cli-extractors.js +0 -46
  12. package/dist/config.js +0 -65
  13. package/dist/context/composer.js +0 -320
  14. package/dist/context/readHonesty.js +0 -478
  15. package/dist/context/rowStore.js +0 -238
  16. package/dist/conversation/formatter.js +0 -81
  17. package/dist/conversation/parser.js +0 -193
  18. package/dist/conversation/types.js +0 -2
  19. package/dist/conversation/writer.js +0 -42
  20. package/dist/db/client.js +0 -149
  21. package/dist/db/handoffTable.js +0 -31
  22. package/dist/db/indexSalvage.js +0 -101
  23. package/dist/db/migrations.js +0 -670
  24. package/dist/db/readCache.js +0 -109
  25. package/dist/db/schema.js +0 -5
  26. package/dist/db/sqlite.js +0 -396
  27. package/dist/db/statements.js +0 -89
  28. package/dist/digests/digestCache.js +0 -146
  29. package/dist/digests/digests.js +0 -597
  30. package/dist/digests/worker.js +0 -350
  31. package/dist/embeddings/caching.js +0 -337
  32. package/dist/embeddings/coalescing.js +0 -177
  33. package/dist/embeddings/interactive.js +0 -103
  34. package/dist/embeddings/local.js +0 -70
  35. package/dist/embeddings/openai.js +0 -106
  36. package/dist/embeddings/rebuild.js +0 -166
  37. package/dist/embeddings/simdScan.js +0 -260
  38. package/dist/embeddings/space.js +0 -21
  39. package/dist/embeddings/types.js +0 -14
  40. package/dist/embeddings/vectorIndex.js +0 -674
  41. package/dist/embeddings/vertex.js +0 -334
  42. package/dist/eval/artifacts.js +0 -42
  43. package/dist/eval/cacheReport.js +0 -146
  44. package/dist/eval/comparison.js +0 -182
  45. package/dist/eval/context700-candidate.js +0 -145
  46. package/dist/eval/evalCache.js +0 -568
  47. package/dist/eval/hashEmbedding.js +0 -35
  48. package/dist/eval/indexSnapshots.js +0 -549
  49. package/dist/eval/longmemeval.js +0 -56
  50. package/dist/eval/metrics.js +0 -181
  51. package/dist/eval/pageDump.js +0 -67
  52. package/dist/eval/renorbenchBaseline.js +0 -486
  53. package/dist/eval/renorbenchDocuments.js +0 -134
  54. package/dist/eval/renorbenchProduct.js +0 -182
  55. package/dist/eval/runLedger.js +0 -279
  56. package/dist/eval/runManifest.js +0 -485
  57. package/dist/eval/scoring.js +0 -197
  58. package/dist/eval/textTokens.js +0 -17
  59. package/dist/evidence/attach.js +0 -264
  60. package/dist/evidence/background.js +0 -147
  61. package/dist/evidence/evidenceCache.js +0 -182
  62. package/dist/evidence/gate.js +0 -37
  63. package/dist/evidence/keyPool.js +0 -85
  64. package/dist/evidence/ollamaChat.js +0 -84
  65. package/dist/evidence/optin.js +0 -165
  66. package/dist/evidence/options.js +0 -151
  67. package/dist/evidence/secondPass.js +0 -294
  68. package/dist/extraction/classifyCapture.js +0 -34
  69. package/dist/extraction/decision-model.js +0 -174
  70. package/dist/extraction/eventExtractor.js +0 -113
  71. package/dist/extraction/extractionClient.js +0 -122
  72. package/dist/extraction/factExtractor.js +0 -46
  73. package/dist/extraction/factsWritePath.js +0 -179
  74. package/dist/extraction/jevDecisionModel.js +0 -307
  75. package/dist/extraction/preferenceExtractor.js +0 -150
  76. package/dist/extraction/secretGuard.js +0 -180
  77. package/dist/extraction/secretScanner.js +0 -665
  78. package/dist/extraction/typedFacts.js +0 -224
  79. package/dist/extraction/writePathAdjudication.js +0 -110
  80. package/dist/importing/apply.js +0 -672
  81. package/dist/importing/bundle-write.js +0 -80
  82. package/dist/importing/cli.js +0 -408
  83. package/dist/importing/existing.js +0 -51
  84. package/dist/importing/facts.js +0 -121
  85. package/dist/importing/forgetImported.js +0 -79
  86. package/dist/importing/hosted.js +0 -467
  87. package/dist/importing/journalLog.js +0 -96
  88. package/dist/importing/markdown.js +0 -98
  89. package/dist/importing/plan.js +0 -201
  90. package/dist/importing/secretScreen.js +0 -113
  91. package/dist/importing/serialize.js +0 -188
  92. package/dist/importing/source.js +0 -463
  93. package/dist/importing/types.js +0 -6
  94. package/dist/indexer/chunker.js +0 -319
  95. package/dist/indexer/dailyEntries.js +0 -63
  96. package/dist/indexer/hasher.js +0 -10
  97. package/dist/indexer/laneRuns.js +0 -48
  98. package/dist/indexer/o200k.js +0 -481
  99. package/dist/indexer/outsideRoot.js +0 -77
  100. package/dist/indexer/parser.js +0 -170
  101. package/dist/indexer/pipeline.js +0 -988
  102. package/dist/indexer/staleness.js +0 -201
  103. package/dist/indexer/tokenizer.js +0 -77
  104. package/dist/indexer/walker.js +0 -170
  105. package/dist/learning/cli.js +0 -113
  106. package/dist/learning/schema.js +0 -144
  107. package/dist/learning/settings.js +0 -45
  108. package/dist/learning/store.js +0 -267
  109. package/dist/learning/tap.js +0 -401
  110. package/dist/mcp/hive.js +0 -88
  111. package/dist/mcp/requestErrors.js +0 -47
  112. package/dist/mcp/server.js +0 -426
  113. package/dist/memory/agentLease.js +0 -43
  114. package/dist/memory/confinedWrite.js +0 -315
  115. package/dist/memory/controls.js +0 -73
  116. package/dist/memory/dailyNote.js +0 -265
  117. package/dist/memory/dreamer/adjudicate.js +0 -215
  118. package/dist/memory/dreamer/apply.js +0 -120
  119. package/dist/memory/dreamer/budget.js +0 -64
  120. package/dist/memory/dreamer/candidates.js +0 -149
  121. package/dist/memory/dreamer/collection.js +0 -104
  122. package/dist/memory/dreamer/dreamer.js +0 -352
  123. package/dist/memory/dreamer/review.js +0 -111
  124. package/dist/memory/durableAppend.js +0 -57
  125. package/dist/memory/factConflicts.js +0 -205
  126. package/dist/memory/factTerms.js +0 -321
  127. package/dist/memory/handoff.js +0 -363
  128. package/dist/memory/hiveNameHeader.cjs +0 -10
  129. package/dist/memory/inventory.js +0 -55
  130. package/dist/memory/invisibleText.js +0 -20
  131. package/dist/memory/lifecycle.js +0 -2014
  132. package/dist/memory/limits.js +0 -13
  133. package/dist/memory/requests.js +0 -183
  134. package/dist/memory/sourceName.js +0 -276
  135. package/dist/memory/statusFacts.js +0 -61
  136. package/dist/memory/whatsNew.js +0 -158
  137. package/dist/memory/writer.js +0 -176
  138. package/dist/memory/writerConflicts.js +0 -85
  139. package/dist/memorymap/memoryMap.js +0 -1594
  140. package/dist/memorymap/replacedJournal.js +0 -58
  141. package/dist/memorymap/replacements.js +0 -410
  142. package/dist/mvp/activity.js +0 -86
  143. package/dist/mvp/agentMemory.js +0 -1803
  144. package/dist/mvp/answerCheck.js +0 -211
  145. package/dist/mvp/auth.js +0 -531
  146. package/dist/mvp/cli.js +0 -86
  147. package/dist/mvp/client-store.js +0 -462
  148. package/dist/mvp/compileCache.js +0 -242
  149. package/dist/mvp/compileSeed.js +0 -33
  150. package/dist/mvp/config.js +0 -292
  151. package/dist/mvp/connectionStatus.js +0 -80
  152. package/dist/mvp/contextDistinct.js +0 -53
  153. package/dist/mvp/contextProfile.js +0 -87
  154. package/dist/mvp/contextRelevance.js +0 -413
  155. package/dist/mvp/directorySurface.js +0 -68
  156. package/dist/mvp/engine.js +0 -1078
  157. package/dist/mvp/exportAll.js +0 -393
  158. package/dist/mvp/factLanePack.js +0 -77
  159. package/dist/mvp/factMarkers.js +0 -65
  160. package/dist/mvp/factsLane.js +0 -203
  161. package/dist/mvp/hiddenSpans.js +0 -585
  162. package/dist/mvp/history.js +0 -414
  163. package/dist/mvp/hitDates.js +0 -31
  164. package/dist/mvp/hitFloor.js +0 -36
  165. package/dist/mvp/identity.js +0 -18
  166. package/dist/mvp/idle.js +0 -113
  167. package/dist/mvp/log.js +0 -118
  168. package/dist/mvp/memoryDir.js +0 -98
  169. package/dist/mvp/posthogMcp.js +0 -210
  170. package/dist/mvp/readScope.js +0 -104
  171. package/dist/mvp/readUsefulness.js +0 -222
  172. package/dist/mvp/sanitize.js +0 -48
  173. package/dist/mvp/schemaRejections.js +0 -91
  174. package/dist/mvp/scope.js +0 -127
  175. package/dist/mvp/server.js +0 -2712
  176. package/dist/mvp/serverCard.js +0 -38
  177. package/dist/mvp/storedSize.js +0 -139
  178. package/dist/mvp/telemetry.js +0 -474
  179. package/dist/net/poolFetch.js +0 -174
  180. package/dist/recall/actionRecall.js +0 -282
  181. package/dist/recall/autoRecall.js +0 -447
  182. package/dist/recall/searchRecall.js +0 -189
  183. package/dist/retrieval/adviceLines.js +0 -195
  184. package/dist/retrieval/adviceQuestion.js +0 -44
  185. package/dist/retrieval/conversationShape.js +0 -44
  186. package/dist/retrieval/dailyEntryTime.js +0 -55
  187. package/dist/retrieval/entityLookup.js +0 -162
  188. package/dist/retrieval/factsFirst.js +0 -188
  189. package/dist/retrieval/keyword.js +0 -84
  190. package/dist/retrieval/ledgerEventTime.js +0 -51
  191. package/dist/retrieval/ledgerLiveness.js +0 -83
  192. package/dist/retrieval/ledgerPresentation.js +0 -161
  193. package/dist/retrieval/noteIdentity.js +0 -57
  194. package/dist/retrieval/orchestrator.js +0 -1224
  195. package/dist/retrieval/plainWording.js +0 -236
  196. package/dist/retrieval/queryHelpers.js +0 -142
  197. package/dist/retrieval/questionSpan.js +0 -475
  198. package/dist/retrieval/rankingTrace.js +0 -184
  199. package/dist/retrieval/readerEvents.js +0 -690
  200. package/dist/retrieval/readerLayout.js +0 -422
  201. package/dist/retrieval/relativeTimeHints.js +0 -113
  202. package/dist/retrieval/semantic.js +0 -67
  203. package/dist/router/routerCache.js +0 -106
  204. package/dist/router/sessionRouter.js +0 -726
  205. package/dist/sharing/cli.js +0 -181
  206. package/dist/sharing/examples.js +0 -136
  207. package/dist/sharing/fields.js +0 -225
  208. package/dist/sharing/loop.js +0 -80
  209. package/dist/sharing/project.js +0 -327
  210. package/dist/sharing/send.js +0 -466
  211. package/dist/sharing/state.js +0 -222
  212. package/dist/sharing/wording.js +0 -48
  213. package/dist/toolRefusal.js +0 -120
  214. package/dist/watcher/watcher.js +0 -77
  215. /package/dist/{indexer/o200k.json → o200k.json} +0 -0
@@ -1,327 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LABEL_WINDOW_MS = void 0;
4
- exports.hourOf = hourOf;
5
- exports.projectRows = projectRows;
6
- const fields_1 = require("./fields");
7
- /**
8
- * The join, done inside the user's own folder: the learning log says what was served, saved, cited and retired; this turns
9
- * it into finished, labelled rows. Only these rows can ever leave. They carry no key, no memory id, no query and no text
10
- * (text only at `data`, from the example store), and every time is coarsened to the hour.
11
- *
12
- * A row is sent only once its label is final: the window (default 24 hours) after the event has closed. Until then the event
13
- * waits, and the sender's watermark says how far it has got.
14
- */
15
- exports.LABEL_WINDOW_MS = 24 * 3_600_000;
16
- const asString = (value) => (typeof value === 'string' ? value : null);
17
- const asNumber = (value) => (typeof value === 'number' && Number.isFinite(value) ? value : null);
18
- const asBool = (value) => (value === 1 || value === true ? true : value === 0 || value === false ? false : null);
19
- /** `2026-10-21T14`: the hour a row happened in, in UTC. */
20
- function hourOf(ms) {
21
- return new Date(ms).toISOString().slice(0, 13);
22
- }
23
- function delayBucket(ms) {
24
- if (ms < 60_000)
25
- return '<1m';
26
- if (ms < 600_000)
27
- return '<10m';
28
- if (ms < 3_600_000)
29
- return '<1h';
30
- if (ms < 86_400_000)
31
- return '<1d';
32
- return '>=1d';
33
- }
34
- function lengthBucket(ms) {
35
- if (ms < 60_000)
36
- return '<1m';
37
- if (ms < 600_000)
38
- return '<10m';
39
- if (ms < 3_600_000)
40
- return '<1h';
41
- if (ms < 21_600_000)
42
- return '<6h';
43
- return '>=6h';
44
- }
45
- function countBucket(n) {
46
- if (n <= 0)
47
- return '0';
48
- if (n === 1)
49
- return '1';
50
- if (n <= 3)
51
- return '2-3';
52
- if (n <= 7)
53
- return '4-7';
54
- return '8+';
55
- }
56
- /** The smallest power of two at or above `tokens`: a size class, not a size. */
57
- function tokenBucket(tokens) {
58
- if (tokens === null || tokens < 0)
59
- return null;
60
- let bucket = 1;
61
- while (bucket < tokens)
62
- bucket *= 2;
63
- return bucket;
64
- }
65
- const round = (value) => (value === null ? null : Math.round(value * 10_000) / 10_000);
66
- /** Events about a memory, by its key, in time order. */
67
- function indexEvents(tables) {
68
- const byMemory = new Map();
69
- const bySubject = new Map();
70
- const add = (map, key, event) => {
71
- if (key === null)
72
- return;
73
- const list = map.get(key);
74
- if (list)
75
- list.push(event);
76
- else
77
- map.set(key, [event]);
78
- };
79
- for (const op of tables.memory_ops) {
80
- const at = asNumber(op.at);
81
- const kind = op.op;
82
- if (at === null)
83
- continue;
84
- const key = asString(op.memory_key);
85
- if (kind === 'retrieve')
86
- add(byMemory, key, { at, kind: 'retrieve' });
87
- else if (kind === 'delete')
88
- add(byMemory, key, { at, kind: 'delete' });
89
- else if (kind === 'supersede') {
90
- // A supersede changes the memory it replaces; it is also the save of the new value (its own key).
91
- add(byMemory, asString(op.replaced_key), { at, kind: 'supersede' });
92
- if (asString(op.replaced_key) !== key)
93
- add(byMemory, key, { at, kind: 'supersede' });
94
- }
95
- }
96
- for (const row of tables.feedback) {
97
- const at = asNumber(row.at);
98
- if (at === null)
99
- continue;
100
- add(byMemory, asString(row.memory_key), { at, kind: 'cite' });
101
- add(bySubject, asString(row.subject_key), { at, kind: 'cite' });
102
- }
103
- for (const list of [...byMemory.values(), ...bySubject.values()])
104
- list.sort((a, b) => a.at - b.at);
105
- return { byMemory, bySubject };
106
- }
107
- function labelOf(lists, from, until, skipSupersedeAt = null) {
108
- const label = { opened: false, cited: false, updated: false, retired: false, firstAt: null };
109
- for (const list of lists) {
110
- for (const event of list ?? []) {
111
- if (event.at <= from || event.at > until)
112
- continue;
113
- if (skipSupersedeAt !== null && event.kind === 'supersede' && event.at === skipSupersedeAt)
114
- continue;
115
- if (event.kind === 'retrieve')
116
- label.opened = true;
117
- else if (event.kind === 'cite')
118
- label.cited = true;
119
- else if (event.kind === 'supersede')
120
- label.updated = true;
121
- else
122
- label.retired = true;
123
- label.firstAt = label.firstAt === null ? event.at : Math.min(label.firstAt, event.at);
124
- }
125
- }
126
- return label;
127
- }
128
- /** A candidate the reply served (rank set). The log also keeps the ones the ranker scored and the reply did not serve: never shared. */
129
- function servedRow(candidate) {
130
- return asNumber(candidate.rank) !== null;
131
- }
132
- function retrievalRows(log, options, windowMs) {
133
- const { tables } = log;
134
- const events = indexEvents(tables);
135
- const cutoff = options.now - windowMs;
136
- const candidatesBy = new Map();
137
- for (const candidate of tables.candidates) {
138
- const id = asNumber(candidate.retrieval_id);
139
- if (id === null || !servedRow(candidate))
140
- continue;
141
- const list = candidatesBy.get(id);
142
- if (list)
143
- list.push(candidate);
144
- else
145
- candidatesBy.set(id, [candidate]);
146
- }
147
- const rows = [];
148
- const retrievals = [...tables.retrievals].sort((a, b) => (asNumber(a.at) ?? 0) - (asNumber(b.at) ?? 0) || (asNumber(a.id) ?? 0) - (asNumber(b.id) ?? 0));
149
- for (const retrieval of retrievals) {
150
- const at = asNumber(retrieval.at);
151
- const id = asNumber(retrieval.id);
152
- const tool = asString(retrieval.tool);
153
- if (at === null || id === null || tool === null || !fields_1.RETRIEVAL_TOOL_NAMES.includes(tool))
154
- continue;
155
- if (at <= options.watermarks.retrieval || at > cutoff)
156
- continue;
157
- const queryKey = asString(retrieval.query_key);
158
- const candidates = (candidatesBy.get(id) ?? []).slice(0, 200).map(candidate => {
159
- const kind = asString(candidate.kind) ?? 'unkeyed';
160
- const memoryKey = asString(candidate.memory_key);
161
- const joinable = memoryKey !== null && kind !== 'unkeyed';
162
- const label = joinable
163
- ? labelOf([events.byMemory.get(memoryKey), kind === 'fact' ? events.bySubject.get(asString(candidate.subject_key) ?? '') : undefined], at, at + windowMs)
164
- : null;
165
- const out = {
166
- rank: asNumber(candidate.rank) ?? 0,
167
- kind,
168
- lane: asString(candidate.reason),
169
- score: round(asNumber(candidate.score)),
170
- matched: asBool(candidate.matched),
171
- current: asBool(candidate.current),
172
- opened: label === null ? null : label.opened,
173
- cited: label === null ? null : label.cited,
174
- updated: label === null ? null : label.updated,
175
- retired: label === null ? null : label.retired,
176
- delay_bucket: label === null || label.firstAt === null ? null : delayBucket(label.firstAt - at),
177
- };
178
- if (options.level === 'data')
179
- out.text = memoryKey === null ? null : options.examples?.memory(memoryKey) ?? null;
180
- return out;
181
- });
182
- const row = {
183
- kind: 'retrieval-labelled/1',
184
- hour: hourOf(at),
185
- tool,
186
- ranker: asString(retrieval.ranker) ?? 'baseline',
187
- build: asString(retrieval.build),
188
- model: (0, fields_1.modelIdentifier)(asString(retrieval.model)),
189
- retrieval: asString(retrieval.retrieval),
190
- served: asNumber(retrieval.served) ?? candidates.length,
191
- reply_tokens_bucket: tokenBucket(asNumber(retrieval.reply_tokens)),
192
- relevant: asBool(retrieval.relevant),
193
- truncated: asBool(retrieval.truncated),
194
- candidates,
195
- };
196
- if (options.level === 'data')
197
- row.query = queryKey === null ? null : options.examples?.query(queryKey) ?? null;
198
- rows.push({ kind: 'retrieval', at, row });
199
- }
200
- return rows;
201
- }
202
- function saveRows(log, options, windowMs) {
203
- const { tables } = log;
204
- const events = indexEvents(tables);
205
- const cutoff = options.now - windowMs;
206
- // How many times each memory was served after a given time: candidates by key, with the retrieval's time.
207
- const retrievalAt = new Map();
208
- for (const retrieval of tables.retrievals) {
209
- const id = asNumber(retrieval.id);
210
- const at = asNumber(retrieval.at);
211
- if (id !== null && at !== null)
212
- retrievalAt.set(id, at);
213
- }
214
- const servedBy = new Map();
215
- for (const candidate of tables.candidates) {
216
- const key = asString(candidate.memory_key);
217
- const id = asNumber(candidate.retrieval_id);
218
- const at = id === null ? undefined : retrievalAt.get(id);
219
- if (key === null || at === undefined || !servedRow(candidate))
220
- continue;
221
- const list = servedBy.get(key);
222
- if (list)
223
- list.push(at);
224
- else
225
- servedBy.set(key, [at]);
226
- }
227
- const rows = [];
228
- const ops = [...tables.memory_ops].sort((a, b) => (asNumber(a.at) ?? 0) - (asNumber(b.at) ?? 0) || (asNumber(a.id) ?? 0) - (asNumber(b.id) ?? 0));
229
- for (const op of ops) {
230
- const at = asNumber(op.at);
231
- const tool = asString(op.tool);
232
- const kind = asString(op.op);
233
- if (at === null || tool === null || !fields_1.SAVE_TOOL_NAMES.includes(tool))
234
- continue;
235
- if (kind !== 'create' && kind !== 'supersede')
236
- continue;
237
- if (at <= options.watermarks.save || at > cutoff)
238
- continue;
239
- const memoryKey = asString(op.memory_key);
240
- const item = asString(op.kind) ?? 'unkeyed';
241
- const joinable = memoryKey !== null && item !== 'unkeyed';
242
- const label = joinable
243
- ? labelOf([events.byMemory.get(memoryKey), item === 'fact' ? events.bySubject.get(asString(op.subject_key) ?? '') : undefined], at, at + windowMs, at)
244
- : labelOf([], at, at + windowMs);
245
- const reads = joinable ? (servedBy.get(memoryKey) ?? []).filter(time => time > at && time <= at + windowMs).length : 0;
246
- const hasCites = tables.feedback.some(cite => cite.tool === tool && Math.abs((asNumber(cite.at) ?? Number.NaN) - at) <= 2000
247
- && cite.agent_key === op.agent_key && cite.session_key === op.session_key);
248
- const row = {
249
- kind: 'save-outcome/1',
250
- hour: hourOf(at),
251
- tool,
252
- op: kind,
253
- item,
254
- has_cites: hasCites,
255
- reads_bucket: countBucket(reads),
256
- opened: label.opened,
257
- cited: label.cited,
258
- superseded: label.updated,
259
- retired: label.retired,
260
- };
261
- if (options.level === 'data')
262
- row.text = memoryKey === null ? null : options.examples?.memory(memoryKey) ?? null;
263
- rows.push({ kind: 'save', at, row });
264
- }
265
- return rows;
266
- }
267
- function sessionRows(log, options, windowMs) {
268
- const { tables } = log;
269
- const cutoff = options.now - windowMs;
270
- const sessions = new Map();
271
- const touch = (key, at, tool, apply) => {
272
- if (key === null || at === null || tool === null)
273
- return;
274
- let seen = sessions.get(key);
275
- if (!seen) {
276
- seen = { first: at, last: at, tool, reads: 0, saves: 0, empty: 0 };
277
- sessions.set(key, seen);
278
- }
279
- if (at < seen.first) {
280
- seen.first = at;
281
- seen.tool = tool;
282
- }
283
- seen.last = Math.max(seen.last, at);
284
- apply(seen);
285
- };
286
- for (const retrieval of tables.retrievals) {
287
- touch(asString(retrieval.session_key), asNumber(retrieval.at), asString(retrieval.tool), seen => {
288
- seen.reads += 1;
289
- if ((asNumber(retrieval.served) ?? 0) === 0)
290
- seen.empty += 1;
291
- });
292
- }
293
- for (const op of tables.memory_ops) {
294
- const tool = asString(op.tool);
295
- touch(asString(op.session_key), asNumber(op.at), tool, seen => {
296
- if (tool !== null && fields_1.SAVE_TOOL_NAMES.includes(tool) && (op.op === 'create' || op.op === 'supersede'))
297
- seen.saves += 1;
298
- });
299
- }
300
- const rows = [];
301
- for (const seen of [...sessions.values()].sort((a, b) => a.last - b.last)) {
302
- if (seen.last <= options.watermarks.session || seen.last > cutoff)
303
- continue;
304
- const firstCall = fields_1.RETRIEVAL_TOOL_NAMES.includes(seen.tool) || fields_1.SAVE_TOOL_NAMES.includes(seen.tool)
305
- ? seen.tool
306
- : 'other';
307
- rows.push({
308
- kind: 'session',
309
- at: seen.last,
310
- row: {
311
- kind: 'session-aggregate/1',
312
- hour: hourOf(seen.first),
313
- length_bucket: lengthBucket(seen.last - seen.first),
314
- reads_bucket: countBucket(seen.reads),
315
- saves_bucket: countBucket(seen.saves),
316
- empty_reads_bucket: countBucket(seen.empty),
317
- first_call: firstCall,
318
- },
319
- });
320
- }
321
- return rows;
322
- }
323
- /** The finished rows the log holds that are final and not yet sent, oldest first within each kind. */
324
- function projectRows(log, options) {
325
- const windowMs = options.windowMs ?? exports.LABEL_WINDOW_MS;
326
- return [...retrievalRows(log, options, windowMs), ...saveRows(log, options, windowMs), ...sessionRows(log, options, windowMs)];
327
- }