renor-engine 1.2.0 → 1.4.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 (216) hide show
  1. package/README.md +34 -2
  2. package/THIRD-PARTY-NOTICES +2661 -0
  3. package/bin/renor-engine.cjs +38 -0
  4. package/dist/BUILD.json +6 -0
  5. package/dist/cli.js +1674 -516
  6. package/package.json +17 -80
  7. package/dist/.tsbuildinfo +0 -1
  8. package/dist/api/apiAuth.js +0 -43
  9. package/dist/api/server.js +0 -174
  10. package/dist/buildIdentity.js +0 -149
  11. package/dist/callPhases.js +0 -82
  12. package/dist/cli-extractors.js +0 -46
  13. package/dist/config.js +0 -65
  14. package/dist/context/composer.js +0 -320
  15. package/dist/context/readHonesty.js +0 -478
  16. package/dist/context/rowStore.js +0 -238
  17. package/dist/conversation/formatter.js +0 -81
  18. package/dist/conversation/parser.js +0 -193
  19. package/dist/conversation/types.js +0 -2
  20. package/dist/conversation/writer.js +0 -42
  21. package/dist/db/client.js +0 -149
  22. package/dist/db/handoffTable.js +0 -31
  23. package/dist/db/indexSalvage.js +0 -101
  24. package/dist/db/migrations.js +0 -670
  25. package/dist/db/readCache.js +0 -109
  26. package/dist/db/schema.js +0 -5
  27. package/dist/db/sqlite.js +0 -396
  28. package/dist/db/statements.js +0 -89
  29. package/dist/digests/digestCache.js +0 -146
  30. package/dist/digests/digests.js +0 -597
  31. package/dist/digests/worker.js +0 -350
  32. package/dist/embeddings/caching.js +0 -337
  33. package/dist/embeddings/coalescing.js +0 -177
  34. package/dist/embeddings/interactive.js +0 -103
  35. package/dist/embeddings/local.js +0 -70
  36. package/dist/embeddings/openai.js +0 -106
  37. package/dist/embeddings/rebuild.js +0 -166
  38. package/dist/embeddings/simdScan.js +0 -260
  39. package/dist/embeddings/space.js +0 -21
  40. package/dist/embeddings/types.js +0 -14
  41. package/dist/embeddings/vectorIndex.js +0 -674
  42. package/dist/embeddings/vertex.js +0 -334
  43. package/dist/eval/artifacts.js +0 -42
  44. package/dist/eval/cacheReport.js +0 -146
  45. package/dist/eval/comparison.js +0 -182
  46. package/dist/eval/context700-candidate.js +0 -145
  47. package/dist/eval/evalCache.js +0 -568
  48. package/dist/eval/hashEmbedding.js +0 -35
  49. package/dist/eval/indexSnapshots.js +0 -549
  50. package/dist/eval/longmemeval.js +0 -56
  51. package/dist/eval/metrics.js +0 -181
  52. package/dist/eval/pageDump.js +0 -67
  53. package/dist/eval/renorbenchBaseline.js +0 -486
  54. package/dist/eval/renorbenchDocuments.js +0 -134
  55. package/dist/eval/renorbenchProduct.js +0 -182
  56. package/dist/eval/runLedger.js +0 -279
  57. package/dist/eval/runManifest.js +0 -485
  58. package/dist/eval/scoring.js +0 -197
  59. package/dist/eval/textTokens.js +0 -17
  60. package/dist/evidence/attach.js +0 -264
  61. package/dist/evidence/background.js +0 -147
  62. package/dist/evidence/evidenceCache.js +0 -182
  63. package/dist/evidence/gate.js +0 -37
  64. package/dist/evidence/keyPool.js +0 -85
  65. package/dist/evidence/ollamaChat.js +0 -84
  66. package/dist/evidence/optin.js +0 -165
  67. package/dist/evidence/options.js +0 -151
  68. package/dist/evidence/secondPass.js +0 -294
  69. package/dist/extraction/classifyCapture.js +0 -34
  70. package/dist/extraction/decision-model.js +0 -174
  71. package/dist/extraction/eventExtractor.js +0 -113
  72. package/dist/extraction/extractionClient.js +0 -122
  73. package/dist/extraction/factExtractor.js +0 -46
  74. package/dist/extraction/factsWritePath.js +0 -179
  75. package/dist/extraction/jevDecisionModel.js +0 -307
  76. package/dist/extraction/preferenceExtractor.js +0 -150
  77. package/dist/extraction/secretGuard.js +0 -180
  78. package/dist/extraction/secretScanner.js +0 -665
  79. package/dist/extraction/typedFacts.js +0 -224
  80. package/dist/extraction/writePathAdjudication.js +0 -110
  81. package/dist/importing/apply.js +0 -672
  82. package/dist/importing/bundle-write.js +0 -80
  83. package/dist/importing/cli.js +0 -408
  84. package/dist/importing/existing.js +0 -51
  85. package/dist/importing/facts.js +0 -121
  86. package/dist/importing/forgetImported.js +0 -79
  87. package/dist/importing/hosted.js +0 -467
  88. package/dist/importing/journalLog.js +0 -96
  89. package/dist/importing/markdown.js +0 -98
  90. package/dist/importing/plan.js +0 -201
  91. package/dist/importing/secretScreen.js +0 -113
  92. package/dist/importing/serialize.js +0 -188
  93. package/dist/importing/source.js +0 -463
  94. package/dist/importing/types.js +0 -6
  95. package/dist/indexer/chunker.js +0 -319
  96. package/dist/indexer/dailyEntries.js +0 -63
  97. package/dist/indexer/hasher.js +0 -10
  98. package/dist/indexer/laneRuns.js +0 -48
  99. package/dist/indexer/o200k.js +0 -481
  100. package/dist/indexer/outsideRoot.js +0 -77
  101. package/dist/indexer/parser.js +0 -170
  102. package/dist/indexer/pipeline.js +0 -988
  103. package/dist/indexer/staleness.js +0 -201
  104. package/dist/indexer/tokenizer.js +0 -77
  105. package/dist/indexer/walker.js +0 -170
  106. package/dist/learning/cli.js +0 -113
  107. package/dist/learning/schema.js +0 -144
  108. package/dist/learning/settings.js +0 -45
  109. package/dist/learning/store.js +0 -267
  110. package/dist/learning/tap.js +0 -401
  111. package/dist/mcp/hive.js +0 -88
  112. package/dist/mcp/requestErrors.js +0 -47
  113. package/dist/mcp/server.js +0 -426
  114. package/dist/memory/agentLease.js +0 -43
  115. package/dist/memory/confinedWrite.js +0 -315
  116. package/dist/memory/controls.js +0 -73
  117. package/dist/memory/dailyNote.js +0 -265
  118. package/dist/memory/dreamer/adjudicate.js +0 -215
  119. package/dist/memory/dreamer/apply.js +0 -120
  120. package/dist/memory/dreamer/budget.js +0 -64
  121. package/dist/memory/dreamer/candidates.js +0 -149
  122. package/dist/memory/dreamer/collection.js +0 -104
  123. package/dist/memory/dreamer/dreamer.js +0 -352
  124. package/dist/memory/dreamer/review.js +0 -111
  125. package/dist/memory/durableAppend.js +0 -57
  126. package/dist/memory/factConflicts.js +0 -205
  127. package/dist/memory/factTerms.js +0 -321
  128. package/dist/memory/handoff.js +0 -363
  129. package/dist/memory/hiveNameHeader.cjs +0 -10
  130. package/dist/memory/inventory.js +0 -55
  131. package/dist/memory/invisibleText.js +0 -20
  132. package/dist/memory/lifecycle.js +0 -2014
  133. package/dist/memory/limits.js +0 -13
  134. package/dist/memory/requests.js +0 -183
  135. package/dist/memory/sourceName.js +0 -276
  136. package/dist/memory/statusFacts.js +0 -61
  137. package/dist/memory/whatsNew.js +0 -158
  138. package/dist/memory/writer.js +0 -176
  139. package/dist/memory/writerConflicts.js +0 -85
  140. package/dist/memorymap/memoryMap.js +0 -1594
  141. package/dist/memorymap/replacedJournal.js +0 -58
  142. package/dist/memorymap/replacements.js +0 -410
  143. package/dist/mvp/activity.js +0 -86
  144. package/dist/mvp/agentMemory.js +0 -1803
  145. package/dist/mvp/answerCheck.js +0 -211
  146. package/dist/mvp/auth.js +0 -531
  147. package/dist/mvp/cli.js +0 -86
  148. package/dist/mvp/client-store.js +0 -462
  149. package/dist/mvp/compileCache.js +0 -242
  150. package/dist/mvp/compileSeed.js +0 -33
  151. package/dist/mvp/config.js +0 -292
  152. package/dist/mvp/connectionStatus.js +0 -80
  153. package/dist/mvp/contextDistinct.js +0 -53
  154. package/dist/mvp/contextProfile.js +0 -87
  155. package/dist/mvp/contextRelevance.js +0 -413
  156. package/dist/mvp/directorySurface.js +0 -68
  157. package/dist/mvp/engine.js +0 -1078
  158. package/dist/mvp/exportAll.js +0 -393
  159. package/dist/mvp/factLanePack.js +0 -77
  160. package/dist/mvp/factMarkers.js +0 -65
  161. package/dist/mvp/factsLane.js +0 -203
  162. package/dist/mvp/hiddenSpans.js +0 -585
  163. package/dist/mvp/history.js +0 -414
  164. package/dist/mvp/hitDates.js +0 -31
  165. package/dist/mvp/hitFloor.js +0 -36
  166. package/dist/mvp/identity.js +0 -18
  167. package/dist/mvp/idle.js +0 -113
  168. package/dist/mvp/log.js +0 -118
  169. package/dist/mvp/memoryDir.js +0 -98
  170. package/dist/mvp/posthogMcp.js +0 -210
  171. package/dist/mvp/readScope.js +0 -104
  172. package/dist/mvp/readUsefulness.js +0 -222
  173. package/dist/mvp/sanitize.js +0 -48
  174. package/dist/mvp/schemaRejections.js +0 -91
  175. package/dist/mvp/scope.js +0 -127
  176. package/dist/mvp/server.js +0 -2712
  177. package/dist/mvp/serverCard.js +0 -38
  178. package/dist/mvp/storedSize.js +0 -139
  179. package/dist/mvp/telemetry.js +0 -474
  180. package/dist/net/poolFetch.js +0 -174
  181. package/dist/recall/actionRecall.js +0 -282
  182. package/dist/recall/autoRecall.js +0 -447
  183. package/dist/recall/searchRecall.js +0 -189
  184. package/dist/retrieval/adviceLines.js +0 -195
  185. package/dist/retrieval/adviceQuestion.js +0 -44
  186. package/dist/retrieval/conversationShape.js +0 -44
  187. package/dist/retrieval/dailyEntryTime.js +0 -55
  188. package/dist/retrieval/entityLookup.js +0 -162
  189. package/dist/retrieval/factsFirst.js +0 -188
  190. package/dist/retrieval/keyword.js +0 -84
  191. package/dist/retrieval/ledgerEventTime.js +0 -51
  192. package/dist/retrieval/ledgerLiveness.js +0 -83
  193. package/dist/retrieval/ledgerPresentation.js +0 -161
  194. package/dist/retrieval/noteIdentity.js +0 -57
  195. package/dist/retrieval/orchestrator.js +0 -1224
  196. package/dist/retrieval/plainWording.js +0 -236
  197. package/dist/retrieval/queryHelpers.js +0 -142
  198. package/dist/retrieval/questionSpan.js +0 -475
  199. package/dist/retrieval/rankingTrace.js +0 -184
  200. package/dist/retrieval/readerEvents.js +0 -690
  201. package/dist/retrieval/readerLayout.js +0 -422
  202. package/dist/retrieval/relativeTimeHints.js +0 -113
  203. package/dist/retrieval/semantic.js +0 -67
  204. package/dist/router/routerCache.js +0 -106
  205. package/dist/router/sessionRouter.js +0 -726
  206. package/dist/sharing/cli.js +0 -181
  207. package/dist/sharing/examples.js +0 -136
  208. package/dist/sharing/fields.js +0 -225
  209. package/dist/sharing/loop.js +0 -80
  210. package/dist/sharing/project.js +0 -327
  211. package/dist/sharing/send.js +0 -466
  212. package/dist/sharing/state.js +0 -222
  213. package/dist/sharing/wording.js +0 -48
  214. package/dist/toolRefusal.js +0 -120
  215. package/dist/watcher/watcher.js +0 -77
  216. /package/dist/{indexer/o200k.json → o200k.json} +0 -0
@@ -1,43 +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.LOCAL_API_HOSTNAMES = exports.API_TOKEN_ENV = void 0;
7
- exports.requireApiToken = requireApiToken;
8
- exports.bearerTokenGuard = bearerTokenGuard;
9
- const crypto_1 = __importDefault(require("crypto"));
10
- /** Environment variable holding the bearer token every `renor serve` route requires. */
11
- exports.API_TOKEN_ENV = 'RENOR_API_TOKEN';
12
- /** Host names the local API answers to. Anything else is a page rebinding its own domain to loopback. */
13
- exports.LOCAL_API_HOSTNAMES = ['localhost', '127.0.0.1', '[::1]'];
14
- function digest(value) {
15
- return crypto_1.default.createHash('sha256').update(value, 'utf8').digest();
16
- }
17
- /**
18
- * The token `renor serve` was started with, or a refusal naming the variable. A local API with no
19
- * credential is open to every user of the machine (loopback is shared), so there is no default and no
20
- * "open" mode: an unset or blank token is a start failure.
21
- */
22
- function requireApiToken(env = process.env) {
23
- const token = env[exports.API_TOKEN_ENV]?.trim();
24
- if (!token) {
25
- throw new Error(`${exports.API_TOKEN_ENV} is not set. The HTTP API (renor serve) has no other protection: any user on this machine `
26
- + 'can reach 127.0.0.1. Refusing to start without a bearer token (fail closed). '
27
- + `Set ${exports.API_TOKEN_ENV} to a long random value (for example: export ${exports.API_TOKEN_ENV}=$(openssl rand -hex 32)) `
28
- + 'and send it as "Authorization: Bearer <token>" on every request.');
29
- }
30
- return token;
31
- }
32
- /** Express middleware: `Authorization: Bearer <token>` is required, compared in constant time. */
33
- function bearerTokenGuard(token) {
34
- const expected = digest(token);
35
- return (req, res, next) => {
36
- const header = req.headers.authorization;
37
- const match = typeof header === 'string' ? /^Bearer +(.+)$/i.exec(header) : null;
38
- if (match && crypto_1.default.timingSafeEqual(digest(match[1].trim()), expected))
39
- return next();
40
- res.set('WWW-Authenticate', 'Bearer');
41
- res.status(401).json({ error: 'unauthorized' });
42
- };
43
- }
@@ -1,174 +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.createServer = createServer;
7
- const express_1 = __importDefault(require("express"));
8
- const hostHeaderValidation_js_1 = require("@modelcontextprotocol/sdk/server/middleware/hostHeaderValidation.js");
9
- const apiAuth_1 = require("./apiAuth");
10
- const orchestrator_1 = require("../retrieval/orchestrator");
11
- const ledgerPresentation_1 = require("../retrieval/ledgerPresentation");
12
- const entityLookup_1 = require("../retrieval/entityLookup");
13
- const writer_1 = require("../memory/writer");
14
- const lifecycle_1 = require("../memory/lifecycle");
15
- const attach_1 = require("../evidence/attach");
16
- const options_1 = require("../evidence/options");
17
- const composer_1 = require("../context/composer");
18
- const readHonesty_1 = require("../context/readHonesty");
19
- const buildIdentity_1 = require("../buildIdentity");
20
- const log_1 = require("../mvp/log");
21
- const log = (0, log_1.createLogger)('engine');
22
- function createServer(db, vectorIndex, provider, vaultPath, priorityPaths, memoryDir, ledgerPath, options) {
23
- // Fail closed: there is no unauthenticated way to build this server.
24
- const apiToken = options?.apiToken?.trim();
25
- if (!apiToken)
26
- throw new Error('createServer needs options.apiToken: the HTTP API does not run without a bearer token');
27
- const app = (0, express_1.default)();
28
- // DNS-rebinding guard first: a page that rebinds its own domain to 127.0.0.1 sends its own Host, and is refused
29
- // before any route (or the token check) runs. Then the credential every other local user lacks.
30
- app.use((0, hostHeaderValidation_js_1.hostHeaderValidation)(apiAuth_1.LOCAL_API_HOSTNAMES));
31
- app.use((0, apiAuth_1.bearerTokenGuard)(apiToken));
32
- app.use(express_1.default.json());
33
- // Resolve the optional evidence path once per server, not once per request.
34
- // This avoids opening a new SQLite evidence-cache connection on every search.
35
- const productEvidenceEnabled = (0, attach_1.searchEvidenceEnabled)();
36
- const productEvidenceOptions = productEvidenceEnabled
37
- ? (0, options_1.resolveEvidenceToolOptions)({ dbPath: db.name })
38
- : null;
39
- const productEvidenceExtractor = productEvidenceOptions
40
- ? (0, options_1.createEvidenceExtractor)(productEvidenceOptions)
41
- : null;
42
- // C0 shared composer (ADR-0003 §5): opt-in via RENOR_STRUCTURED_CONTEXT,
43
- // default OFF — when off, responses are byte-identical to the pre-C0 contract.
44
- const structuredOn = (0, composer_1.structuredContextEnabled)();
45
- // Relative to the vault root — remember() joins it onto vaultPath.
46
- const config_ledgerPath = ledgerPath ?? lifecycle_1.DEFAULT_LEDGER_REL;
47
- // The ledger is the engine's own record, not a memory: this route returns neither its header nor the markup of its records.
48
- const isLedger = (0, ledgerPresentation_1.ledgerNoteMatcher)({ memoryDir: vaultPath, ledgerRelPath: config_ledgerPath });
49
- // Build/deploy identity: which source commit is this process running? Written
50
- // at build time by scripts/ci/stamp-build.mjs and read through the shared,
51
- // non-throwing helper (src/buildIdentity.ts) that the MVP's GET /version also
52
- // uses. Deploy drift must be observable; the manifest never throws.
53
- app.get('/api/health', (_req, res) => {
54
- res.json({ ok: true, name: 'renor', version: buildIdentity_1.ENGINE_VERSION, ...(0, buildIdentity_1.readBuildIdentity)() });
55
- });
56
- app.post('/retrieve-context', async (req, res) => {
57
- const { query, topK: rawTopK = 20 } = req.body;
58
- if (!query)
59
- return void res.status(400).json({ error: 'query required' });
60
- const topK = Math.min(100, Math.max(1, Math.floor(Number(rawTopK) || 20)));
61
- // LANE 3 read-time honesty (RENOR_READ_HONESTY, default OFF): provenance +
62
- // contradiction + abstention alongside the unchanged hits array.
63
- const readHonesty = (hits) => (0, readHonesty_1.readHonestyEnabled)()
64
- ? {
65
- readHonesty: (0, readHonesty_1.readHonestyForItems)({
66
- db, query, items: hits, ledgerRelPath: config_ledgerPath,
67
- }),
68
- }
69
- : {};
70
- try {
71
- const retrieved = await (0, orchestrator_1.retrieveContext)(db, vectorIndex, provider, query, topK, priorityPaths, {}, { isLedgerNote: isLedger });
72
- if (!productEvidenceEnabled || !productEvidenceOptions) {
73
- // Preserve the pre-evidence response contract exactly when the feature is off.
74
- const plain = (0, ledgerPresentation_1.presentLedgerEvents)(retrieved.hits, isLedger);
75
- return void res.json({
76
- query: retrieved.query,
77
- hits: plain,
78
- ...(structuredOn
79
- ? { composedContext: (0, composer_1.composeQueryContextFromDb)(db, { query: retrieved.query, hits: plain }) }
80
- : {}),
81
- ...readHonesty(plain),
82
- });
83
- }
84
- const attached = await (0, attach_1.attachSearchEvidence)({
85
- query,
86
- hits: retrieved.hits,
87
- vaultPath,
88
- options: productEvidenceOptions,
89
- extractor: productEvidenceExtractor,
90
- enabled: true,
91
- });
92
- // The evidence pass read the sources as stored; what the caller is shown is what the user said.
93
- const shown = (0, ledgerPresentation_1.presentLedgerEvents)(attached.hits, isLedger);
94
- res.json({
95
- query: retrieved.query,
96
- hits: shown,
97
- evidence: attached.evidence,
98
- ...(structuredOn
99
- ? { composedContext: (0, composer_1.composeQueryContextFromDb)(db, { query: retrieved.query, hits: shown.filter((h) => h.notePath !== attach_1.EVIDENCE_HIT_PATH), evidence: attached.evidence }) }
100
- : {}),
101
- ...readHonesty(shown),
102
- });
103
- }
104
- catch (e) {
105
- res.status(500).json({ error: e instanceof Error ? e.message : String(e) });
106
- }
107
- });
108
- app.get('/entity/:name', (req, res) => {
109
- const entity = (0, entityLookup_1.lookupEntity)(db, req.params.name);
110
- if (!entity)
111
- return void res.status(404).json({ error: 'not found' });
112
- res.json(entity);
113
- });
114
- app.get('/facts/:entityId', (req, res) => {
115
- // Current-only by default (temporal-memory contract): superseded facts carry
116
- // valid_to and are opt-in via history/asOf endpoints, never the ID route.
117
- const rows = db.prepare('SELECT * FROM facts WHERE subject_entity_id = ? AND valid_to IS NULL ORDER BY updated_at DESC').all(Number(req.params.entityId));
118
- res.json(rows);
119
- });
120
- app.post('/memory/daily', async (req, res) => {
121
- const { date, text, source = 'api' } = req.body;
122
- if (!date || !text)
123
- return void res.status(400).json({ error: 'date and text required' });
124
- try {
125
- await (0, writer_1.appendDailyMemory)(vaultPath, date, { text, source }, memoryDir);
126
- res.json({ ok: true });
127
- }
128
- catch (e) {
129
- res.status(500).json({ error: e instanceof Error ? e.message : String(e) });
130
- }
131
- });
132
- // Lifecycle-backed durable memory (ledger-first, supersedes, idempotent, returns receipt).
133
- app.post('/memory/fact', async (req, res) => {
134
- const { subject, predicate, object, source } = req.body;
135
- if (!subject || !predicate || !object)
136
- return void res.status(400).json({ error: 'subject, predicate, object required' });
137
- try {
138
- res.json(await (0, lifecycle_1.remember)(db, vaultPath, config_ledgerPath, { subject, predicate, object, source }));
139
- }
140
- catch (e) {
141
- // A rejected lifecycle FIELD is the caller's mistake, not an engine fault: remember()
142
- // validates every field before touching the ledger, so this is a bad request and must
143
- // answer 4xx. Answering 500 made a client-side type bug (a non-string `object`) look like
144
- // a server outage. Engine faults — unreadable ledger, reused event id, clock regression,
145
- // an escaping ledger path — still throw plain Errors and stay 500.
146
- if (e instanceof lifecycle_1.LifecycleInputError)
147
- return void res.status(400).json({ error: e.message });
148
- res.status(500).json({ error: e instanceof Error ? e.message : String(e) });
149
- }
150
- });
151
- // Facts by entity NAME (agents don't know DB ids). ?asOf=ISO&history=1
152
- app.get('/facts-for/:name', (req, res) => {
153
- try {
154
- res.json((0, lifecycle_1.factsFor)(db, req.params.name, {
155
- asOf: req.query.asOf,
156
- includeHistory: req.query.history === '1' || req.query.history === 'true',
157
- }));
158
- }
159
- catch (e) {
160
- res.status(500).json({ error: e instanceof Error ? e.message : String(e) });
161
- }
162
- });
163
- // One generic answer for anything a route did not handle: Express's own error page names the absolute path of the
164
- // file that threw. The cause stays in this process's log.
165
- app.use((err, _req, res, next) => {
166
- if (res.headersSent)
167
- return next(err);
168
- const status = typeof err?.status === 'number' && Number.isInteger(err.status) && err.status >= 400 && err.status < 500 ? err.status : 500;
169
- if (status >= 500)
170
- log.error('serve_request_failed', { status }, err);
171
- res.status(status).json({ error: status >= 500 ? 'internal error' : 'bad request' });
172
- });
173
- return app;
174
- }
@@ -1,149 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.BUILD_MANIFEST_PATH = exports.ENGINE_VERSION = exports.MAX_BUILD_MANIFEST_BYTES = void 0;
4
- exports.readBuildIdentity = readBuildIdentity;
5
- const node_fs_1 = require("node:fs");
6
- const node_path_1 = require("node:path");
7
- const UNKNOWN_BUILD_IDENTITY = Object.freeze({
8
- commit: 'unknown',
9
- branch: 'unknown',
10
- dirty: null,
11
- builtAt: null,
12
- });
13
- /**
14
- * Manifest size gate. A stamp written by scripts/ci/stamp-build.mjs is ~200
15
- * bytes, so anything in the KiB range is not a build stamp this project wrote.
16
- * Refusing it by size (before the contents are even parsed) bounds the work and
17
- * the memory the reader can be forced into, and keeps a giant file from ever
18
- * becoming the input to a response.
19
- */
20
- exports.MAX_BUILD_MANIFEST_BYTES = 4096;
21
- /** A git revision id as printed by `git rev-parse HEAD`, shortened or full. */
22
- const COMMIT_PATTERN = /^[0-9a-fA-F]{7,40}$/;
23
- /**
24
- * ISO-8601 instant: calendar date, time to the second, optional fractional
25
- * seconds, and either `Z` or a numeric offset — the shapes `Date#toISOString`
26
- * and ordinary ISO producers emit. Anything else (partial dates, prose,
27
- * dates with embedded whitespace) is not a build timestamp.
28
- */
29
- const BUILT_AT_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,6})?(?:Z|[+-]\d{2}:\d{2})$/;
30
- /** Longest ISO instant worth accepting (offset + 6 fractional digits). */
31
- const MAX_BUILT_AT_LENGTH = 35;
32
- /** Git ref names are ASCII: letters, digits, `.`, `_`, `-` and `/` separators. */
33
- const BRANCH_PATTERN = /^[A-Za-z0-9._/-]+$/;
34
- /** git's own per-ref-component cap is 255 bytes; nothing legitimate is longer. */
35
- const MAX_BRANCH_LENGTH = 255;
36
- /** The engine package root: nearest ancestor of this module holding package.json. */
37
- function resolveEngineRoot() {
38
- let dir = __dirname;
39
- for (let up = 0; up < 3; up += 1) {
40
- if ((0, node_fs_1.existsSync)((0, node_path_1.join)(dir, 'package.json')))
41
- return dir;
42
- const parent = (0, node_path_1.dirname)(dir);
43
- if (parent === dir)
44
- break;
45
- dir = parent;
46
- }
47
- return null;
48
- }
49
- /**
50
- * The engine package's version, read from its package.json. Every surface that announces a version (the MCP
51
- * initialize reply, GET /api/health, `renor --version`) takes it from here, so none can drift from the package.
52
- * "unknown" when the file cannot be read or holds no semver-shaped version, never a guess.
53
- */
54
- exports.ENGINE_VERSION = (() => {
55
- const root = resolveEngineRoot();
56
- if (!root)
57
- return 'unknown';
58
- try {
59
- const version = JSON.parse((0, node_fs_1.readFileSync)((0, node_path_1.join)(root, 'package.json'), 'utf8')).version;
60
- return typeof version === 'string' && /^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/.test(version) ? version : 'unknown';
61
- }
62
- catch {
63
- return 'unknown';
64
- }
65
- })();
66
- /**
67
- * Absolute path of the stamped manifest, or null when the package root cannot
68
- * be located (then identity is simply unknown — never a guess).
69
- *
70
- * Resolved from the package root rather than a fixed relative hop because the
71
- * two layouts differ: a compiled deployment loads this module from dist/ while
72
- * a source run (tsx: `npm run mvp`, `renor serve`) loads it from src/, and both
73
- * must find <engine>/dist/BUILD.json.
74
- */
75
- exports.BUILD_MANIFEST_PATH = (() => {
76
- const root = resolveEngineRoot();
77
- return root === null ? null : (0, node_path_1.join)(root, 'dist', 'BUILD.json');
78
- })();
79
- /** Hex revision id, or the unknown placeholder. */
80
- function validatedCommit(value) {
81
- return typeof value === 'string' && COMMIT_PATTERN.test(value)
82
- ? value
83
- : UNKNOWN_BUILD_IDENTITY.commit;
84
- }
85
- /**
86
- * Plausible git ref name, or the unknown placeholder. Enforces the
87
- * `git check-ref-format` rules a charset check alone would miss (`..`, `@{`,
88
- * leading dot, `.lock` suffix, empty component), so a filesystem path, a tenant
89
- * slug, a URL or a ref-shaped injection cannot pass as a branch.
90
- */
91
- function validatedBranch(value) {
92
- const unknown = UNKNOWN_BUILD_IDENTITY.branch;
93
- if (typeof value !== 'string' || value.length > MAX_BRANCH_LENGTH)
94
- return unknown;
95
- if (!BRANCH_PATTERN.test(value))
96
- return unknown;
97
- if (value.includes('..') || value.includes('@{'))
98
- return unknown;
99
- for (const component of value.split('/')) {
100
- if (component === '' || component.startsWith('.'))
101
- return unknown;
102
- if (component.endsWith('.lock'))
103
- return unknown;
104
- }
105
- return value;
106
- }
107
- /** Parsable ISO-8601 instant, or null. */
108
- function validatedBuiltAt(value) {
109
- if (typeof value !== 'string' || value.length > MAX_BUILT_AT_LENGTH)
110
- return null;
111
- if (!BUILT_AT_PATTERN.test(value))
112
- return null;
113
- return Number.isFinite(Date.parse(value)) ? value : null;
114
- }
115
- /**
116
- * Reads the build manifest. Returns the unknown identity — never throws — when
117
- * the manifest is absent, unreadable, oversized, not JSON, not an object, or
118
- * carries a value that fails its field's shape check.
119
- */
120
- function readBuildIdentity(manifestPath = exports.BUILD_MANIFEST_PATH) {
121
- if (manifestPath === null)
122
- return { ...UNKNOWN_BUILD_IDENTITY };
123
- let raw;
124
- try {
125
- if ((0, node_fs_1.statSync)(manifestPath).size > exports.MAX_BUILD_MANIFEST_BYTES) {
126
- return { ...UNKNOWN_BUILD_IDENTITY }; // not a stamp we wrote
127
- }
128
- raw = (0, node_fs_1.readFileSync)(manifestPath, 'utf8');
129
- }
130
- catch {
131
- return { ...UNKNOWN_BUILD_IDENTITY }; // pre-stamp / snapshot deployment
132
- }
133
- try {
134
- const parsed = JSON.parse(raw);
135
- if (parsed === null || typeof parsed !== 'object' || Array.isArray(parsed)) {
136
- return { ...UNKNOWN_BUILD_IDENTITY };
137
- }
138
- const manifest = parsed;
139
- return {
140
- commit: validatedCommit(manifest.commit),
141
- branch: validatedBranch(manifest.branch),
142
- dirty: typeof manifest.dirty === 'boolean' ? manifest.dirty : null,
143
- builtAt: validatedBuiltAt(manifest.builtAt),
144
- };
145
- }
146
- catch {
147
- return { ...UNKNOWN_BUILD_IDENTITY };
148
- }
149
- }
@@ -1,82 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CallPhases = exports.PHASE_NAMES = void 0;
4
- exports.isPhasedTool = isPhasedTool;
5
- exports.recordPhase = recordPhase;
6
- exports.recordedPhase = recordedPhase;
7
- exports.markRetrieved = markRetrieved;
8
- const node_async_hooks_1 = require("node:async_hooks");
9
- /**
10
- * Where the time of one read call went, for the engine's log (telemetry.ts `phases` on a `get_context` or `search_memory` line).
11
- * Milliseconds, a number per phase and nothing else: no text of the call, its query or its result ever goes through here.
12
- *
13
- * embed the embedding provider's whole call for the query (token, requests, waits between retries); absent when the
14
- * query's vector came from the query cache, so a missing `embed` says that no call to the service was made
15
- * token of embed: waiting for an access token (about 0 when one was in hand)
16
- * connect of embed: opening a connection to the service (TCP, TLS, address lookup); absent when a connection was reused
17
- * call of embed: the requests themselves once connected (send, the service's own time, receive)
18
- * retrieve the matches and facts: from the start of the call to the point they are in hand, less embed
19
- * reply the answer built from them: from that point to the end of the call
20
- *
21
- * A call's phases are collected in an `AsyncLocalStorage` scope that the tool wrapper opens (server.ts), so the provider that
22
- * measures the embedding needs no argument for it, and a call made outside a scope (a CLI, an eval, a test) records nothing.
23
- * Requests made together add up, so the phases of such a call can sum to more than its wall time.
24
- */
25
- exports.PHASE_NAMES = ['embed', 'token', 'connect', 'call', 'retrieve', 'reply'];
26
- /** The tools that report their phases: the two reads whose latency the product is judged on. */
27
- const PHASED_TOOLS = ['get_context', 'search_memory'];
28
- function isPhasedTool(tool) {
29
- return PHASED_TOOLS.includes(tool);
30
- }
31
- const scope = new node_async_hooks_1.AsyncLocalStorage();
32
- class CallPhases {
33
- totals = new Map();
34
- startedAt = performance.now();
35
- retrievedAt;
36
- embedAtRetrieved = 0;
37
- /** Runs `work` with this as the call whose phases are recorded. */
38
- run(work) {
39
- return scope.run(this, work);
40
- }
41
- add(phase, ms) {
42
- if (Number.isFinite(ms) && ms >= 0)
43
- this.totals.set(phase, (this.totals.get(phase) ?? 0) + ms);
44
- }
45
- total(phase) {
46
- return this.totals.get(phase) ?? 0;
47
- }
48
- /** The matches and facts are in hand: what is left of the call is the answer being built. The first mark counts. */
49
- markRetrieved() {
50
- if (this.retrievedAt !== undefined)
51
- return;
52
- this.retrievedAt = performance.now();
53
- this.embedAtRetrieved = this.total('embed');
54
- }
55
- /** What the call recorded, rounded to a tenth of a millisecond; `retrieve` and `reply` only for a call that reached the mark. */
56
- report() {
57
- const out = {};
58
- for (const [phase, ms] of this.totals)
59
- out[phase] = ms;
60
- if (this.retrievedAt !== undefined) {
61
- out.retrieve = Math.max(0, this.retrievedAt - this.startedAt - this.embedAtRetrieved);
62
- out.reply = Math.max(0, performance.now() - this.retrievedAt);
63
- }
64
- for (const phase of exports.PHASE_NAMES)
65
- if (out[phase] !== undefined)
66
- out[phase] = Math.round(out[phase] * 10) / 10;
67
- return out;
68
- }
69
- }
70
- exports.CallPhases = CallPhases;
71
- /** Adds to the current call's phase, if a call is being recorded. */
72
- function recordPhase(phase, ms) {
73
- scope.getStore()?.add(phase, ms);
74
- }
75
- /** What the current call has recorded so far for a phase (0 when no call is being recorded). */
76
- function recordedPhase(phase) {
77
- return scope.getStore()?.total(phase) ?? 0;
78
- }
79
- /** The matches and facts of the current call are in hand (see CallPhases.markRetrieved). */
80
- function markRetrieved() {
81
- scope.getStore()?.markRetrieved();
82
- }
@@ -1,46 +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.buildWritePathExtractors = buildWritePathExtractors;
7
- const openai_1 = __importDefault(require("openai"));
8
- const factExtractor_1 = require("./extraction/factExtractor");
9
- const extractionClient_1 = require("./extraction/extractionClient");
10
- const typedFacts_1 = require("./extraction/typedFacts");
11
- const eventExtractor_1 = require("./extraction/eventExtractor");
12
- const preferenceExtractor_1 = require("./extraction/preferenceExtractor");
13
- /**
14
- * Structured-row lanes use only a named extractor provider. A bare
15
- * OPENAI_API_KEY does not arm them. LLM_EXTRACTION is the older fact path:
16
- * when that flag is on and no named provider exists, it keeps the OpenAI
17
- * client main already built from that key.
18
- *
19
- * The legacy fact path asks for `FACTS_MODEL` only when the resolved provider is
20
- * one of the extractor-specific providers. On the generic OPENAI_API_KEY +
21
- * OPENAI_BASE_URL fallback it keeps the fact extractor's own `gpt-4o-mini`
22
- * default, which is the model `main` sent there. See
23
- * `isExtractorSpecificProvider`.
24
- */
25
- function buildWritePathExtractors(config, env = process.env) {
26
- const resolved = (0, extractionClient_1.openExtractorClient)(typedFacts_1.FACTS_MODEL, env);
27
- const extractorClient = resolved?.client ?? null;
28
- const legacyFactClient = config.llmExtraction && !extractorClient && config.openaiApiKey
29
- ? new openai_1.default({ apiKey: config.openaiApiKey })
30
- : null;
31
- const factClient = (extractorClient ?? legacyFactClient);
32
- return {
33
- factExtractor: config.llmExtraction && factClient
34
- ? (title, body) => (0, factExtractor_1.extractFacts)(factClient, title, body, (0, extractionClient_1.isExtractorSpecificProvider)(resolved?.config ?? null) ? typedFacts_1.FACTS_MODEL : 'gpt-4o-mini')
35
- : undefined,
36
- numericFactExtractor: (0, typedFacts_1.typedFactsEnabled)(env) && extractorClient
37
- ? (title, body) => (0, typedFacts_1.extractNumericFacts)(extractorClient, title, body)
38
- : undefined,
39
- eventExtractor: (0, eventExtractor_1.chronicleEnabled)(env) && extractorClient
40
- ? (title, body) => (0, eventExtractor_1.extractEvents)(extractorClient, title, body)
41
- : undefined,
42
- preferenceExtractor: (0, preferenceExtractor_1.prefsEnabled)(env) && extractorClient
43
- ? (title, body) => (0, preferenceExtractor_1.extractPreferences)(extractorClient, title, body)
44
- : undefined,
45
- };
46
- }
package/dist/config.js DELETED
@@ -1,65 +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.defaultVaultPath = defaultVaultPath;
7
- exports.loadConfig = loadConfig;
8
- const node_os_1 = __importDefault(require("node:os"));
9
- const node_path_1 = __importDefault(require("node:path"));
10
- /** The notes folder when VAULT_PATH is unset or empty. */
11
- function defaultVaultPath() {
12
- return node_path_1.default.join(node_os_1.default.homedir(), '.renor');
13
- }
14
- function loadConfig() {
15
- // No setting is needed for a first run (`npx -y renor-engine mcp`): notes live in ~/.renor. A hidden name, so it can never be
16
- // an existing folder of the user's (a clone named renor, say) that the first save would write notes and an index into.
17
- const vaultPath = process.env.VAULT_PATH || defaultVaultPath();
18
- const rawProvider = process.env.EMBEDDING_PROVIDER ?? 'none';
19
- if (rawProvider !== 'none' && rawProvider !== 'openai' && rawProvider !== 'local' && rawProvider !== 'eval-hash') {
20
- throw new Error(`Invalid EMBEDDING_PROVIDER "${rawProvider}": must be "none", "openai", "local", or "eval-hash"`);
21
- }
22
- // eval-hash: deterministic lexical embeddings for evaluation smoke/contract
23
- // runs through the public CLI surface (offline, no model download, no
24
- // semantic-quality claim). Same provider CI already uses for RenorBench smoke.
25
- const embeddingProvider = rawProvider;
26
- if (embeddingProvider === 'openai') {
27
- const key = process.env.OPENAI_API_KEY;
28
- if (!key || key.trim() === '') {
29
- throw new Error('OPENAI_API_KEY is required when EMBEDDING_PROVIDER is "openai"');
30
- }
31
- }
32
- const chunkMaxTokens = Number(process.env.CHUNK_MAX_TOKENS ?? 400);
33
- if (!Number.isFinite(chunkMaxTokens) || chunkMaxTokens <= 0) {
34
- throw new Error('CHUNK_MAX_TOKENS must be a positive number');
35
- }
36
- const chunkOverlapTokens = Number(process.env.CHUNK_OVERLAP_TOKENS ?? 50);
37
- if (!Number.isFinite(chunkOverlapTokens) || chunkOverlapTokens < 0) {
38
- throw new Error('CHUNK_OVERLAP_TOKENS must be a non-negative number');
39
- }
40
- if (chunkOverlapTokens >= chunkMaxTokens) {
41
- throw new Error('CHUNK_OVERLAP_TOKENS must be less than CHUNK_MAX_TOKENS');
42
- }
43
- const indexConcurrency = Number(process.env.INDEX_CONCURRENCY ?? 5);
44
- if (!Number.isInteger(indexConcurrency) || indexConcurrency < 1 || indexConcurrency > 20) {
45
- throw new Error('INDEX_CONCURRENCY must be an integer between 1 and 20');
46
- }
47
- const rawPriorityPaths = process.env.PRIORITY_PATHS ?? '';
48
- const priorityPaths = rawPriorityPaths ? rawPriorityPaths.split(',').map(p => p.trim()).filter(Boolean) : [];
49
- return {
50
- vaultPath,
51
- dbPath: process.env.DB_PATH ?? `${vaultPath}/.semantic-memory/index.db`,
52
- embeddingProvider,
53
- openaiApiKey: process.env.OPENAI_API_KEY,
54
- embeddingModel: process.env.EMBEDDING_MODEL,
55
- embeddingBaseURL: process.env.EMBEDDING_BASE_URL,
56
- embeddingDims: process.env.EMBEDDING_DIMS ? parseInt(process.env.EMBEDDING_DIMS, 10) : undefined,
57
- chunkMaxTokens,
58
- chunkOverlapTokens,
59
- priorityPaths,
60
- memoryDir: process.env.MEMORY_DIR ?? 'Memory/Daily',
61
- memoryLedger: process.env.MEMORY_LEDGER ?? 'System/Memory Events Ledger.md',
62
- llmExtraction: process.env.LLM_EXTRACTION === 'true',
63
- indexConcurrency,
64
- };
65
- }