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,414 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.HISTORY_CACHE_CHARS = exports.HistoryUnavailableError = exports.HISTORY_DISCLAIMER = void 0;
7
- exports.tokenize = tokenize;
8
- exports.historyCacheChars = historyCacheChars;
9
- exports.searchHistory = searchHistory;
10
- const crypto_1 = __importDefault(require("crypto"));
11
- const fs_1 = __importDefault(require("fs"));
12
- const path_1 = __importDefault(require("path"));
13
- /**
14
- * Local history search for the single-owner ChatGPT MVP.
15
- *
16
- * Searches the owner's PROMOTED ChatGPT history (the explicit additive
17
- * directory filled by the reviewed promotion command) — never arbitrary vault
18
- * trees, never the fact memory directory, never raw exports or staging.
19
- *
20
- * Deterministic lexical search only: no embeddings, no semantic/vector
21
- * pipeline, no remote calls. There is NO derived/persistent index to corrupt:
22
- * every query re-derives eligibility from the authoritative promotion
23
- * ownership manifest and re-verifies each candidate note's sha256, so
24
- * restarts reproduce results exactly, and newly added / removed / withdrawn
25
- * (carried) / tampered / human-edited notes are picked up or excluded on the
26
- * very next query. The source Markdown and manifest are read-only.
27
- *
28
- * Eligibility (manifest is the authority, mirroring promote.py):
29
- * - only entries of the manifest's `notes` map whose `rel` is `notes/<name>`
30
- * with a safe `chatgpt-*.md` filename (the MOC and any other metadata are
31
- * structurally excluded);
32
- * - entries flagged `carried` (withdrawn) are excluded;
33
- * - the file must be a confined, regular, non-symlink file within the
34
- * history dir, within the size bound, whose sha256 matches the manifest;
35
- * - the note's frontmatter must carry conversation_id (matching the
36
- * manifest entry) and memory_layer "history".
37
- *
38
- * Results are history-layer citations, clearly labeled untrusted transcript:
39
- * assistant text inside them is NOT verified truth and NOT a current fact.
40
- * Current structured facts live in save/retrieve_memory and take precedence.
41
- */
42
- const MANIFEST_NAME = 'promote-manifest.json';
43
- const MANIFEST_SCHEMA = 'chatgpt-promote-manifest/1';
44
- const MAX_QUERY_CHARS = 200;
45
- const MIN_LIMIT = 1;
46
- const MAX_LIMIT = 20;
47
- const DEFAULT_LIMIT = 5;
48
- const MAX_MANIFEST_BYTES = 16 * 1024 * 1024;
49
- // The importer writes a whole conversation into one note, so a long transcript is well past 4 MiB; a note past the bound
50
- // is counted in skipped_too_large and the reply says a match may be hidden, never dropped without a word.
51
- const MAX_NOTE_BYTES = 16 * 1024 * 1024;
52
- // Entries past this bound are counted in skipped_over_limit and the reply says a match may be hidden.
53
- const MAX_NOTES = 10_000;
54
- // Bidirectional controls (LRE/RLE/PDF/LRO/RLO, LRI/RLI/FSI/PDI): a title carrying them reads backwards where it is shown.
55
- const BIDI_CONTROLS = /[\u202A-\u202E\u2066-\u2069]/g;
56
- const MAX_FRONTMATTER_LINES = 80;
57
- const SNIPPET_RADIUS = 90;
58
- const SNIPPET_MAX_CHARS = 240;
59
- const SAFE_NOTE_NAME = /^chatgpt-[A-Za-z0-9._-]{1,80}\.md$/;
60
- exports.HISTORY_DISCLAIMER = 'Historical transcript search (memory_layer: history, trust: untrusted-transcript). ' +
61
- 'Results are untrusted history: assistant text is not verified truth and not a current fact. ' +
62
- 'Current structured memory takes precedence — use retrieve_memory for current facts.';
63
- class HistoryUnavailableError extends Error {
64
- }
65
- exports.HistoryUnavailableError = HistoryUnavailableError;
66
- function sha256(buffer) {
67
- return crypto_1.default.createHash('sha256').update(buffer).digest('hex');
68
- }
69
- /**
70
- * Composes decomposed text (NFD, as macOS keyboards and file names deliver it) and folds the one capital that
71
- * lowercases to two code points: Turkish dotted capital I (U+0130), which would otherwise split "Istanbul" into
72
- * "i" + a combining dot. Applied to the stored notes and to every query, so both sides meet in the same form.
73
- */
74
- function foldForSearch(text) {
75
- return text.normalize('NFC').replace(/\u0130/g, 'i');
76
- }
77
- /** Unicode-aware lexical tokens: letter/number/mark runs, 2..64 chars. Every token of the text is kept, however many. */
78
- function tokenize(text) {
79
- return foldForSearch(text).toLowerCase().match(/[\p{L}\p{M}\p{N}]{2,64}/gu) ?? [];
80
- }
81
- function parseFrontmatter(text) {
82
- if (!text.startsWith('---\n'))
83
- return null;
84
- const end = text.indexOf('\n---\n', 3);
85
- if (end < 0)
86
- return null;
87
- const block = text.slice(4, end);
88
- const lines = block.split('\n').slice(0, MAX_FRONTMATTER_LINES);
89
- const fields = {};
90
- for (const line of lines) {
91
- if (!line.trim())
92
- continue;
93
- const idx = line.indexOf(': ');
94
- if (idx <= 0)
95
- continue;
96
- const key = line.slice(0, idx).trim();
97
- const raw = line.slice(idx + 2);
98
- if (raw.startsWith('"') && raw.endsWith('"')) {
99
- try {
100
- fields[key] = JSON.parse(raw);
101
- }
102
- catch {
103
- return null; // malformed quoting: ineligible, fail closed
104
- }
105
- }
106
- else if (raw === 'true' || raw === 'false') {
107
- fields[key] = raw === 'true';
108
- }
109
- else if (/^-?\d+$/.test(raw)) {
110
- fields[key] = Number(raw);
111
- }
112
- else {
113
- fields[key] = raw;
114
- }
115
- }
116
- return { fields, body: text.slice(end + 5) };
117
- }
118
- /** Per history directory, the notes of the last pass: a note that left the manifest drops out with its entry. */
119
- const noteCache = new Map();
120
- /**
121
- * The most body characters the cache keeps, across the directory's notes (about 2x in memory once tokenized). A note
122
- * past the bound is still searched, read and tokenized on each query as before, so memory stays bounded however large the
123
- * history grows: the cache is a speed-up for the notes it holds, not a copy of the corpus.
124
- */
125
- exports.HISTORY_CACHE_CHARS = 16_000_000;
126
- /** Body characters the cache holds right now, across every history directory (for tests and diagnostics). */
127
- function historyCacheChars() {
128
- let total = 0;
129
- for (const entries of noteCache.values())
130
- for (const { note } of entries.values())
131
- total += note.body.length;
132
- return total;
133
- }
134
- /**
135
- * Re-derive the eligible set from the authoritative manifest + notes.
136
- * Everything ineligible is counted, never thrown (bounded, fail-closed).
137
- */
138
- function collectEligible(historyDir) {
139
- const notes = [];
140
- const cached = noteCache.get(historyDir) ?? new Map();
141
- const nextCache = new Map();
142
- let cachedChars = 0;
143
- // Kept only within HISTORY_CACHE_CHARS. A hit is kept on the same terms, so the bound holds whichever pass a note is in.
144
- const keep = (name, entry) => {
145
- const size = entry.note.body.length;
146
- if (cachedChars + size > exports.HISTORY_CACHE_CHARS)
147
- return;
148
- cachedChars += size;
149
- nextCache.set(name, entry);
150
- };
151
- let skipped = 0;
152
- let tooLarge = 0;
153
- let overLimit = 0;
154
- const manifestPath = path_1.default.join(historyDir, MANIFEST_NAME);
155
- let manifestStat;
156
- try {
157
- manifestStat = fs_1.default.lstatSync(manifestPath);
158
- }
159
- catch {
160
- throw new HistoryUnavailableError(`${MANIFEST_NAME} not found in the configured history directory`);
161
- }
162
- if (!manifestStat.isFile()) {
163
- throw new HistoryUnavailableError(`${MANIFEST_NAME} is not a regular file`);
164
- }
165
- if (manifestStat.size > MAX_MANIFEST_BYTES) {
166
- throw new HistoryUnavailableError(`${MANIFEST_NAME} exceeds the size bound`);
167
- }
168
- let manifest;
169
- try {
170
- manifest = JSON.parse(fs_1.default.readFileSync(manifestPath, 'utf-8'));
171
- }
172
- catch {
173
- throw new HistoryUnavailableError(`${MANIFEST_NAME} is not valid JSON`);
174
- }
175
- if (manifest?.schema !== MANIFEST_SCHEMA) {
176
- throw new HistoryUnavailableError(`${MANIFEST_NAME} has an unexpected schema`);
177
- }
178
- const entries = manifest?.notes;
179
- if (typeof entries !== 'object' || entries === null || Array.isArray(entries)) {
180
- throw new HistoryUnavailableError(`${MANIFEST_NAME} notes map is malformed`);
181
- }
182
- for (const [name, entry] of Object.entries(entries)) {
183
- if (notes.length + skipped >= MAX_NOTES) {
184
- skipped++;
185
- overLimit++;
186
- continue;
187
- }
188
- // structural eligibility: only promoted note filenames, never the MOC or
189
- // any other metadata; never a path.
190
- if (!SAFE_NOTE_NAME.test(name)) {
191
- skipped++;
192
- continue;
193
- }
194
- if (typeof entry !== 'object' || entry === null) {
195
- skipped++;
196
- continue;
197
- }
198
- const record = entry;
199
- if (record.carried === true) {
200
- skipped++;
201
- continue;
202
- } // withdrawn: excluded
203
- const rel = record.rel;
204
- if (typeof rel !== 'string' || rel !== `notes/${name}`) {
205
- skipped++;
206
- continue;
207
- }
208
- const expectedSha = record.note_sha256;
209
- const convId = record.conversation_id;
210
- if (typeof expectedSha !== 'string' || !/^[0-9a-f]{64}$/.test(expectedSha)) {
211
- skipped++;
212
- continue;
213
- }
214
- if (typeof convId !== 'string' || convId.length === 0 || convId.length > 200) {
215
- skipped++;
216
- continue;
217
- }
218
- const notePath = path_1.default.join(historyDir, name);
219
- let stat;
220
- try {
221
- stat = fs_1.default.lstatSync(notePath);
222
- }
223
- catch {
224
- skipped++;
225
- continue;
226
- }
227
- // confined, regular, non-symlink file only (no subdirectories, no links)
228
- if (stat.isSymbolicLink() || !stat.isFile()) {
229
- skipped++;
230
- continue;
231
- }
232
- if (stat.size > MAX_NOTE_BYTES) {
233
- skipped++;
234
- tooLarge++;
235
- continue;
236
- }
237
- const key = `${stat.mtimeMs}:${stat.size}:${expectedSha}:${convId}`;
238
- const hit = cached.get(name);
239
- // The cache is trusted for a file whose mtime and size are unchanged: its hash is not checked again on a hit.
240
- if (hit !== undefined && hit.key === key) {
241
- keep(name, hit);
242
- notes.push(hit.note);
243
- continue;
244
- }
245
- let data;
246
- try {
247
- data = fs_1.default.readFileSync(notePath);
248
- }
249
- catch {
250
- skipped++;
251
- continue;
252
- }
253
- if (sha256(data) !== expectedSha) {
254
- skipped++;
255
- continue;
256
- } // tampered/human-edited: fail closed
257
- const parsed = parseFrontmatter(data.toString('utf-8'));
258
- if (!parsed) {
259
- skipped++;
260
- continue;
261
- }
262
- const { fields, body } = parsed;
263
- if (fields.memory_layer !== 'history') {
264
- skipped++;
265
- continue;
266
- }
267
- if (typeof fields.conversation_id !== 'string' || fields.conversation_id !== convId) {
268
- skipped++;
269
- continue;
270
- }
271
- const title = typeof fields.title === 'string' ? fields.title.replace(BIDI_CONTROLS, '') : '(untitled conversation)';
272
- // Index ONLY the visible-transcript section: never frontmatter, never the
273
- // warning callout, never the importer boilerplate/omission footer.
274
- const SECTION_MARKER = '## Visible active branch';
275
- const FOOTER_MARKER = '*(Omitted from this note:';
276
- let searchable = body;
277
- const sectionAt = body.indexOf(SECTION_MARKER);
278
- if (sectionAt >= 0)
279
- searchable = body.slice(sectionAt + SECTION_MARKER.length);
280
- // The importer writes its footer as the last line of the note, so the real one is the LAST line-initial marker.
281
- // A transcript message that quotes the marker mid-line, or earlier in the note, is searched, not cut at.
282
- searchable = foldForSearch(searchable);
283
- const footerAt = searchable.lastIndexOf(`\n${FOOTER_MARKER}`);
284
- if (footerAt >= 0)
285
- searchable = searchable.slice(0, footerAt);
286
- const counts = new Map();
287
- for (const token of tokenize(searchable))
288
- counts.set(token, (counts.get(token) ?? 0) + 1);
289
- const note = {
290
- name,
291
- conversationId: convId,
292
- title: title.slice(0, 300),
293
- created: typeof fields.created === 'string' ? fields.created : null,
294
- updated: typeof fields.updated === 'string' ? fields.updated : null,
295
- body: searchable,
296
- counts,
297
- };
298
- keep(name, { key, note });
299
- notes.push(note);
300
- }
301
- noteCache.set(historyDir, nextCache);
302
- return { notes, skipped, tooLarge, overLimit };
303
- }
304
- function buildSnippet(body, terms) {
305
- const lower = body.toLowerCase();
306
- let best = -1;
307
- let bestLen = 0;
308
- for (const term of terms) {
309
- const at = lower.indexOf(term);
310
- if (at >= 0 && (best < 0 || at < best)) {
311
- best = at;
312
- bestLen = term.length;
313
- }
314
- }
315
- if (best < 0)
316
- return '';
317
- const start = Math.max(0, best - SNIPPET_RADIUS);
318
- const end = Math.min(body.length, best + bestLen + SNIPPET_RADIUS);
319
- let snippet = body.slice(start, end);
320
- snippet = snippet.replace(/\s+/g, ' ').trim();
321
- if (start > 0)
322
- snippet = '…' + snippet;
323
- if (end < body.length)
324
- snippet = snippet + '…';
325
- return snippet.slice(0, SNIPPET_MAX_CHARS);
326
- }
327
- /** Said in the reply when notes were not searched, so a caller never reads a short list as the whole history. */
328
- function unsearchedNote(tooLarge, overLimit) {
329
- if (tooLarge === 0 && overLimit === 0)
330
- return undefined;
331
- return `${tooLarge} note(s) over the ${MAX_NOTE_BYTES / (1024 * 1024)} MiB search bound and ${overLimit} `
332
- + `entr(ies) past the ${MAX_NOTES}-note bound were not searched; a match may be hidden in them.`;
333
- }
334
- function searchHistory(historyDir, rawQuery, rawLimit) {
335
- if (historyDir === null) {
336
- return {
337
- ok: true,
338
- configured: false,
339
- results: [],
340
- note: 'history search is not configured (MVP_HISTORY_DIR is not set). '
341
- + 'Fact memory (save_memory/retrieve_memory/export_memory) is unaffected.',
342
- disclaimer: exports.HISTORY_DISCLAIMER,
343
- };
344
- }
345
- const query = rawQuery.trim();
346
- // A query the schema admits (1..200 characters) can still hold no searchable character: trim() strips whitespace
347
- // (spaces, tabs, newlines, U+2028/U+2029, U+FEFF), so a whitespace-only query trims to empty. It is answered as a
348
- // search that found nothing — the same reply a punctuation-only query already gets when `terms` comes back empty —
349
- // instead of throwing, so a schema-valid argument never reaches a raw error and search_history matches search_text,
350
- // which answers a whitespace query with ok and no results. Only over-length is a real violation here, reachable
351
- // from a direct caller (the tool caps the query at MAX_QUERY_CHARS).
352
- if (query.length > MAX_QUERY_CHARS) {
353
- throw new Error(`query must be 1..${MAX_QUERY_CHARS} characters`);
354
- }
355
- const limit = rawLimit === undefined ? DEFAULT_LIMIT : rawLimit;
356
- if (!Number.isInteger(limit) || limit < MIN_LIMIT || limit > MAX_LIMIT) {
357
- throw new Error(`limit must be an integer between ${MIN_LIMIT} and ${MAX_LIMIT}`);
358
- }
359
- const { notes, skipped, tooLarge, overLimit } = collectEligible(historyDir);
360
- const unsearched = unsearchedNote(tooLarge, overLimit);
361
- const terms = Array.from(new Set(tokenize(query)));
362
- if (terms.length === 0) {
363
- return {
364
- ok: true, configured: true, query, total_matches: 0, returned: 0,
365
- skipped_ineligible: skipped, skipped_too_large: tooLarge, skipped_over_limit: overLimit,
366
- ...(unsearched ? { note: unsearched } : {}), results: [], disclaimer: exports.HISTORY_DISCLAIMER,
367
- };
368
- }
369
- const termSet = new Set(terms);
370
- const scored = [];
371
- for (const note of notes) {
372
- const counts = new Map();
373
- for (const [token, count] of note.counts) {
374
- if (termSet.has(token))
375
- counts.set(token, count);
376
- }
377
- if (counts.size === 0)
378
- continue;
379
- let score = 0;
380
- for (const count of counts.values())
381
- score += count;
382
- score += counts.size; // coverage bonus: more distinct matched terms first
383
- scored.push({ note, score, counts });
384
- }
385
- // Deterministic order: score desc, then conversation id asc, then name.
386
- scored.sort((a, b) => b.score - a.score ||
387
- a.note.conversationId.localeCompare(b.note.conversationId) ||
388
- a.note.name.localeCompare(b.note.name));
389
- const hits = scored.slice(0, limit).map(({ note, score, counts }) => ({
390
- conversation_id: note.conversationId,
391
- title: note.title,
392
- created: note.created,
393
- updated: note.updated,
394
- source_path: note.name,
395
- snippet: buildSnippet(note.body, Array.from(counts.keys())),
396
- matched_terms: Array.from(counts.keys()).sort(),
397
- score,
398
- memory_layer: 'history',
399
- trust: 'untrusted-transcript',
400
- }));
401
- return {
402
- ok: true,
403
- configured: true,
404
- query,
405
- total_matches: scored.length,
406
- returned: hits.length,
407
- skipped_ineligible: skipped,
408
- skipped_too_large: tooLarge,
409
- skipped_over_limit: overLimit,
410
- ...(unsearched ? { note: unsearched } : {}),
411
- results: hits,
412
- disclaimer: exports.HISTORY_DISCLAIMER,
413
- };
414
- }
@@ -1,31 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.withHitDates = withHitDates;
7
- const path_1 = __importDefault(require("path"));
8
- const orchestrator_1 = require("../retrieval/orchestrator");
9
- const dailyEntryTime_1 = require("../retrieval/dailyEntryTime");
10
- /**
11
- * The date of a keyword hit, the one search_memory and get_context give the same excerpt: the moment a daily-log entry
12
- * was saved, otherwise its note's date (front-matter session_date or date, capped at the file's write time, else that
13
- * time). search_text found a note or an entry by its words and said nothing of when it was written, so an agent could not
14
- * tell a note from last week from one a year old. A hit that already has a date (a remembered fact, a ledger event) keeps it,
15
- * and a hit whose note is not in the index stays undated: unknown is never `now`.
16
- */
17
- async function withHitDates(db, memoryDir, hits) {
18
- if (!hits.some(h => h.session_date === undefined && h.notePath !== ''))
19
- return hits;
20
- const noteDate = (0, orchestrator_1.createNoteDater)(db);
21
- const boundTime = (0, orchestrator_1.createNoteTimeBound)(db);
22
- const entryTime = (0, dailyEntryTime_1.createDailyEntryClock)();
23
- return Promise.all(hits.map(async (hit) => {
24
- if (hit.session_date !== undefined || hit.notePath === '')
25
- return hit;
26
- const stored = path_1.default.resolve(memoryDir, hit.notePath);
27
- const entryAt = await entryTime({ notePath: stored, text: hit.text });
28
- const session_date = entryAt === undefined ? noteDate(stored) : boundTime(stored, entryAt);
29
- return session_date === undefined ? hit : { ...hit, session_date };
30
- }));
31
- }
@@ -1,36 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SEARCH_HIT_FLOOR_ENV = exports.SEARCH_HIT_FLOOR_MODEL_KEY = exports.SEARCH_HIT_FLOOR_DEFAULT = void 0;
4
- exports.searchHitFloor = searchHitFloor;
5
- exports.applyHitFloor = applyHitFloor;
6
- const orchestrator_1 = require("../retrieval/orchestrator");
7
- /**
8
- * MCP search_memory removes note hits below a raw-cosine floor after the facts lane fills the page.
9
- * The default is 0.63 only for Vertex gemini-embedding-001 at 768 dimensions; every other model defaults off.
10
- * Operator setting RENOR_SEARCH_HIT_FLOOR overrides either default; 0 restores the old response.
11
- * Facts, evidence, digests, ledger events and graph hits have no own cosine and stay. Session expansion
12
- * stays only while a matched hit from its note survives. Nothing is added, reordered or backfilled.
13
- * get_context, HTTP API and CLI searches do not use this floor.
14
- */
15
- exports.SEARCH_HIT_FLOOR_DEFAULT = 0.63;
16
- exports.SEARCH_HIT_FLOOR_MODEL_KEY = 'vertex:gemini-embedding-001:768';
17
- exports.SEARCH_HIT_FLOOR_ENV = 'RENOR_SEARCH_HIT_FLOOR';
18
- /** A cosine threshold never transfers between models or dimensions. Invalid settings use this model's default. */
19
- function searchHitFloor(modelKey, env = process.env) {
20
- const defaultFloor = modelKey === exports.SEARCH_HIT_FLOOR_MODEL_KEY ? exports.SEARCH_HIT_FLOOR_DEFAULT : 0;
21
- const value = env[exports.SEARCH_HIT_FLOOR_ENV];
22
- if (value === undefined || value.trim() === '')
23
- return defaultFloor;
24
- const floor = Number(value);
25
- return Number.isFinite(floor) && floor >= 0 && floor <= 1 ? floor : defaultFloor;
26
- }
27
- /**
28
- * `hits` without the ones found by meaning whose similarity is below `floor`, and without the statements the session
29
- * expansion added to a note none of whose matched hits is left. `withheld` counts every hit taken out. Order is kept.
30
- */
31
- function applyHitFloor(hits, floor) {
32
- const below = new Set(hits.filter(hit => typeof hit.similarity === 'number' && hit.similarity < floor));
33
- const matched = new Set(hits.filter(hit => hit.reason !== orchestrator_1.SESSION_EXPAND_REASON && !below.has(hit)).map(hit => hit.notePath));
34
- const kept = hits.filter(hit => !below.has(hit) && (hit.reason !== orchestrator_1.SESSION_EXPAND_REASON || matched.has(hit.notePath)));
35
- return { hits: kept, withheld: hits.length - kept.length };
36
- }
@@ -1,18 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.identityLine = identityLine;
4
- /**
5
- * The one line every get_context and memory_status reply carries, so an agent connected to the wrong server, or to a
6
- * Renor it did not expect, can tell (agent survey P1 and improvement 2, "Absence is silent"). The workspace name is the
7
- * one the gateway passes in `x-renor-workspace` (it deletes any client-sent copy first); an engine reached without the
8
- * gateway, or a control plane that does not return the name yet, gets none, and the line says so instead of guessing.
9
- */
10
- const NO_NAME = 'hosted Renor, no workspace name passed';
11
- function identityLine(headers) {
12
- const raw = headers?.['x-renor-workspace'];
13
- const value = Array.isArray(raw) ? raw[0] : raw;
14
- if (typeof value !== 'string')
15
- return NO_NAME;
16
- const name = value.replace(/[\u0000-\u001f\u007f"]/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 80).trim();
17
- return name === '' ? NO_NAME : `hosted Renor, workspace "${name}"`;
18
- }
package/dist/mvp/idle.js DELETED
@@ -1,113 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.IdleMonitor = exports.DRAINING_HEADER = void 0;
4
- const activity_1 = require("./activity");
5
- /**
6
- * On-demand idle exit (RENOR_ON_DEMAND=1, see config.ts). Off by default: without the
7
- * switch no monitor is created and the engine runs until it is stopped, as before.
8
- *
9
- * Work holds the engine awake: every HTTP request while it is open (an SSE stream
10
- * included) and every MCP tool call until it returns, even one whose client has gone,
11
- * because a write or index job outlives its connection. The idle clock restarts when a
12
- * request ends below 400, so a scanner's 401/404 or a readiness probe on /version does
13
- * not keep a sleeping workspace resident (nor does the release's look at /internal/activity).
14
- *
15
- * With nothing in flight for the whole idle period the monitor starts draining: every
16
- * later request is answered 503 with the draining header before it does anything, so
17
- * the gateway knows the engine is stopping (not broken) and can start it again without
18
- * ever replaying a request that might have been committed.
19
- */
20
- /** Response header on a draining engine's 503. The gateway reads it. */
21
- exports.DRAINING_HEADER = 'x-renor-draining';
22
- class IdleMonitor {
23
- idleMs;
24
- now;
25
- inFlight = 0;
26
- lastActivity;
27
- timer = null;
28
- started = false;
29
- draining = false;
30
- resolveIdle;
31
- idle = new Promise(resolve => { this.resolveIdle = resolve; });
32
- constructor(idleMs, now = Date.now) {
33
- this.idleMs = idleMs;
34
- this.now = now;
35
- this.lastActivity = now();
36
- }
37
- /** Start the idle clock once the engine listens; resolves when draining begins. */
38
- start() {
39
- this.started = true;
40
- this.lastActivity = this.now();
41
- this.arm();
42
- return this.idle;
43
- }
44
- get isDraining() {
45
- return this.draining;
46
- }
47
- /** Express middleware: counts each request while it is open; refuses while draining. */
48
- middleware = (req, res, next) => {
49
- if (this.draining) {
50
- res.setHeader('Connection', 'close');
51
- res.setHeader('Retry-After', '1');
52
- res.setHeader(exports.DRAINING_HEADER, '1');
53
- res.status(503).json({ error: 'draining' });
54
- return;
55
- }
56
- const probe = req.method === 'GET' && (req.path === '/version' || req.path === activity_1.ACTIVITY_PATH);
57
- const end = this.begin();
58
- let ended = false;
59
- const finish = () => {
60
- if (ended)
61
- return;
62
- ended = true;
63
- end(!probe && res.statusCode < 400);
64
- };
65
- res.once('finish', finish);
66
- res.once('close', finish);
67
- next();
68
- };
69
- /** Holds the engine awake for one unit of work, such as an MCP tool call. */
70
- async track(work) {
71
- const end = this.begin();
72
- try {
73
- return await work();
74
- }
75
- finally {
76
- end(true);
77
- }
78
- }
79
- begin() {
80
- this.inFlight++;
81
- if (this.timer) {
82
- clearTimeout(this.timer);
83
- this.timer = null;
84
- }
85
- return (activity) => {
86
- this.inFlight--;
87
- if (activity)
88
- this.lastActivity = this.now();
89
- this.arm();
90
- };
91
- }
92
- arm() {
93
- if (!this.started || this.draining || this.inFlight > 0)
94
- return;
95
- if (this.timer)
96
- clearTimeout(this.timer);
97
- const wait = Math.max(0, this.lastActivity + this.idleMs - this.now());
98
- this.timer = setTimeout(() => this.check(), wait);
99
- this.timer.unref();
100
- }
101
- check() {
102
- this.timer = null;
103
- if (this.draining || this.inFlight > 0)
104
- return;
105
- if (this.now() - this.lastActivity < this.idleMs) {
106
- this.arm();
107
- return;
108
- }
109
- this.draining = true;
110
- this.resolveIdle();
111
- }
112
- }
113
- exports.IdleMonitor = IdleMonitor;