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,151 +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.resolveEvidenceBounds = resolveEvidenceBounds;
7
- exports.resolveEvidenceProvider = resolveEvidenceProvider;
8
- exports.evidenceCachePath = evidenceCachePath;
9
- exports.resolveEvidenceChat = resolveEvidenceChat;
10
- exports.resolveEvidenceToolOptions = resolveEvidenceToolOptions;
11
- exports.createEvidenceExtractor = createEvidenceExtractor;
12
- const node_path_1 = __importDefault(require("node:path"));
13
- const ollamaChat_1 = require("./ollamaChat");
14
- const keyPool_1 = require("./keyPool");
15
- const evidenceCache_1 = require("./evidenceCache");
16
- const optin_1 = require("./optin");
17
- const gate_1 = require("./gate");
18
- const secondPass_1 = require("./secondPass");
19
- /**
20
- * RENOR_EVIDENCE_MAX_TOKENS (a positive integer) and
21
- * RENOR_EVIDENCE_REASONING_EFFORT (none | minimal | low | medium | high).
22
- * Unset or blank means no bound, which is the shipped request. A value that
23
- * does not parse throws, like an invalid RENOR_EVIDENCE_MODE: an operator who
24
- * set a bound must not get an unbounded extractor because of a typo.
25
- */
26
- function resolveEvidenceBounds(env = process.env) {
27
- const bounds = {};
28
- const maxTokens = (env.RENOR_EVIDENCE_MAX_TOKENS ?? '').trim();
29
- if (maxTokens !== '') {
30
- const value = Number(maxTokens);
31
- if (!/^[1-9][0-9]*$/.test(maxTokens) || !Number.isSafeInteger(value)) {
32
- throw new Error(`Invalid RENOR_EVIDENCE_MAX_TOKENS "${maxTokens}": must be a positive integer`);
33
- }
34
- bounds.maxTokens = value;
35
- }
36
- const effort = (env.RENOR_EVIDENCE_REASONING_EFFORT ?? '').trim().toLowerCase();
37
- if (effort !== '') {
38
- if (!secondPass_1.EVIDENCE_REASONING_EFFORTS.includes(effort)) {
39
- throw new Error(`Invalid RENOR_EVIDENCE_REASONING_EFFORT "${effort}": must be ${secondPass_1.EVIDENCE_REASONING_EFFORTS.join(' | ')}`);
40
- }
41
- bounds.reasoningEffort = effort;
42
- }
43
- return bounds;
44
- }
45
- /**
46
- * The OpenAI-compatible provider the query-time model passes call: RENOR_EVIDENCE_BASE_URL (unset or blank: the
47
- * transport's Ollama Cloud default) and the key pool. Shared by the evidence pass and the session router
48
- * (src/router/sessionRouter.ts), so the two can never disagree about which keys exist, and the URL returned is the
49
- * one the Ollama keys were judged against. Values are never logged.
50
- */
51
- function resolveEvidenceProvider(env = process.env) {
52
- // Blank is the default endpoint (Ollama Cloud), like an unset variable.
53
- const baseUrl = env.RENOR_EVIDENCE_BASE_URL?.trim() || undefined;
54
- const keys = [
55
- ...(env.RENOR_EVIDENCE_API_KEYS ?? '').split(','),
56
- env.RENOR_EVIDENCE_API_KEY ?? '',
57
- // The Ollama pool is collected by the shared helper, never re-listed here:
58
- // this module used to name `OLLAMA_CLOUD_KEY_1..3` while the write-path
59
- // extractor named six, so with the first three keys at their monthly
60
- // ceiling the evidence layer vanished for 77 of 500 cases with no signal in
61
- // the manifest (issue #222). One list, two readers. And only for an Ollama
62
- // Cloud endpoint: another provider never receives an Ollama key.
63
- ...(0, keyPool_1.ollamaKeysForEndpoint)(baseUrl, env).keys,
64
- ].map(k => k.trim()).filter(Boolean);
65
- return { baseUrl, keys };
66
- }
67
- /** Where the evidence pass caches, and where an opted-in workspace's daily allowance is counted: RENOR_EVIDENCE_CACHE, else beside the index. */
68
- function evidenceCachePath(config, env = process.env) {
69
- return env.RENOR_EVIDENCE_CACHE?.trim() || node_path_1.default.join(node_path_1.default.dirname(config.dbPath), 'evidence-cache.db');
70
- }
71
- /**
72
- * The evidence pass's model and transport. A workspace that opted in (RENOR_EVIDENCE_OPTIN, see optin.ts) reaches Ollama
73
- * Cloud with the key file's key alone, on gemma4:31b, and spends its daily allowance per HTTP attempt; otherwise the
74
- * configured endpoint and keys (resolveEvidenceProvider) with RENOR_EVIDENCE_MODEL. No chat when no key is configured.
75
- * `transport` bounds each call; unset, the transport's own defaults. Another reader of notes at query time (the answer
76
- * check, mvp/answerCheck.ts) builds its chat here, so it sends them only where the evidence pass would.
77
- */
78
- function resolveEvidenceChat(config, env = process.env, transport = {}) {
79
- const optin = (0, optin_1.resolveEvidenceOptin)(env);
80
- const { baseUrl, keys } = resolveEvidenceProvider(env);
81
- const bounds = {
82
- ...(transport.timeoutMs !== undefined ? { timeoutMs: transport.timeoutMs } : {}),
83
- ...(transport.maxRetries !== undefined ? { maxRetries: transport.maxRetries } : {}),
84
- };
85
- let chat;
86
- if (optin) {
87
- const optinKey = (0, optin_1.optinEndpointAllowed)(baseUrl) ? (0, optin_1.readOptinKey)(optin.keyFile) : null;
88
- if (optinKey) {
89
- const dailyCap = optin.dailyCap;
90
- const cachePath = evidenceCachePath(config, env);
91
- // The allowance is spent per HTTP attempt (a retried 429 or 5xx is another request to the provider), so it
92
- // sits inside the transport rather than around it.
93
- chat = (0, ollamaChat_1.createOllamaChat)({
94
- keys: [optinKey],
95
- beforeAttempt: (0, optin_1.dailyBudgetGate)(() => new optin_1.EvidenceDailyBudget(cachePath, dailyCap)),
96
- ...bounds,
97
- });
98
- }
99
- }
100
- else if (keys.length > 0) {
101
- chat = (0, ollamaChat_1.createOllamaChat)({ baseUrl, keys, ...bounds });
102
- }
103
- // The opt-in is the gemma4:31b decision: a stray RENOR_EVIDENCE_MODEL does not change what the privacy page names.
104
- const model = optin ? secondPass_1.EVIDENCE_MODEL_DEFAULT : env.RENOR_EVIDENCE_MODEL?.trim() || secondPass_1.EVIDENCE_MODEL_DEFAULT;
105
- return { model, ...(chat ? { chat } : {}), optin };
106
- }
107
- function resolveEvidenceToolOptions(config, env = process.env) {
108
- const mode = (0, gate_1.resolveEvidenceMode)(env);
109
- const cachePath = evidenceCachePath(config, env);
110
- const bounds = resolveEvidenceBounds(env);
111
- // The model, the transport and the opt-in (key file, endpoint, gemma4:31b, daily allowance): resolveEvidenceChat.
112
- const { model, chat, optin } = resolveEvidenceChat(config, env);
113
- // Coverage knob (RENOR_EVIDENCE_SESSIONS). Default 20 matches the
114
- // promotion-grade full-500 arm. One model call per uncached search,
115
- // regardless of session count; explicit values remain bounded.
116
- // A value that floors below 1 is treated as UNSET, not as "0 sessions". A
117
- // fractional setting is finite and positive, so a bare `> 0` test let it
118
- // through and `Math.floor` turned it into 0 — and 0 is not a silent no-op:
119
- // `loadEvidenceSessionsFromVault` rejects it (`maxSessions must be > 0`),
120
- // which the `evidence` MCP tool surfaces as a thrown error and the search path
121
- // swallows as `extractor-error`. Floor first, then require >= 1.
122
- const requested = Number(env.RENOR_EVIDENCE_SESSIONS ?? '');
123
- const requestedSessions = Number.isFinite(requested) ? Math.floor(requested) : Number.NaN;
124
- const maxSessions = Number.isFinite(requestedSessions) && requestedSessions >= 1
125
- ? Math.min(requestedSessions, 50)
126
- : secondPass_1.MAX_EVIDENCE_SESSIONS;
127
- return {
128
- mode,
129
- model,
130
- maxSessions,
131
- charCap: secondPass_1.EVIDENCE_SESSION_CHAR_CAP,
132
- cachePath,
133
- ...(chat ? { chat } : {}),
134
- ...(optin ? { dailyCap: optin.dailyCap } : {}),
135
- ...(bounds.maxTokens !== undefined || bounds.reasoningEffort !== undefined ? { bounds } : {}),
136
- };
137
- }
138
- function createEvidenceExtractor(evidence) {
139
- if (!evidence.chat)
140
- return null;
141
- let cache = null;
142
- if (evidence.cachePath) {
143
- try {
144
- cache = new evidenceCache_1.EvidenceCache(evidence.cachePath);
145
- }
146
- catch (err) {
147
- process.stderr.write(`[evidence] cache unavailable: ${err instanceof Error ? err.message : String(err)}\n`);
148
- }
149
- }
150
- return new secondPass_1.EvidenceExtractor({ chat: evidence.chat, cache, model: evidence.model, bounds: evidence.bounds });
151
- }
@@ -1,294 +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.EvidenceExtractor = exports.EvidenceReplyError = exports.EVIDENCE_REASONING_EFFORTS = exports.EVIDENCE_SESSION_CHAR_CAP = exports.MAX_EVIDENCE_SESSIONS = exports.EVIDENCE_MODEL_DEFAULT = exports.EVIDENCE_PROMPT_TEMPLATE = void 0;
7
- exports.loadEvidenceSessionsFromVault = loadEvidenceSessionsFromVault;
8
- exports.renderEvidencePrompt = renderEvidencePrompt;
9
- exports.parseEvidenceItems = parseEvidenceItems;
10
- const promises_1 = __importDefault(require("node:fs/promises"));
11
- const node_path_1 = __importDefault(require("node:path"));
12
- const parser_1 = require("../indexer/parser");
13
- const evidenceCache_1 = require("./evidenceCache");
14
- /**
15
- * H10-v4 second-pass, question-conditioned evidence extraction (product path).
16
- *
17
- * Frozen mechanism (champion = 453/500 = 90.6%, docs/evals/results/
18
- * H10-V4-FULL500-20260919.md): given a question and the sessions retrieval
19
- * already selected, the extractor (gemma4:31b) lists every distinct relevant
20
- * item/event/amount with dates. It never computes totals and never sees gold.
21
- *
22
- * Productization adds:
23
- * - content-addressed caching (exact rendered prompt -> parsed items, and,
24
- * for a day, a reply that was not a table: EVIDENCE_FAILURE_TTL_MS);
25
- * - session selection matching the promoted arm (20 sessions, 6,000 chars/session);
26
- * - gating (off | auto | always), default off (src/evidence/gate.ts).
27
- */
28
- exports.EVIDENCE_PROMPT_TEMPLATE = `You extract evidence items from a user's dated conversation history.
29
-
30
- QUESTION: {question}
31
-
32
- Below are the sessions (with dates) that a memory system retrieved for this question.
33
-
34
- TASK: List EVERY distinct item, event, or amount mentioned in the sessions that could be
35
- relevant to answering the question. Rules:
36
- - One entry per distinct item (e.g., each product, each trip, each device, each course, each amount).
37
- - "action" = what happened (bought / visited / completed / raised / inherited / ...).
38
- - "amount" = numeric value + unit when stated (e.g., "3 days", "$120", "100 points"); else "".
39
- - "date" = the session/mention date when available; else "".
40
- - Do NOT compute any totals. Do NOT merge different items. Include every candidate even if uncertain.
41
- - Include items the question might count, even when the sessions mention them in passing.
42
-
43
- SESSIONS:
44
- {sessions}
45
-
46
- Respond with ONLY minified JSON, no markdown:
47
- {{"items":[{{"item":"...","action":"...","amount":"...","date":"..."}}]}}`;
48
- exports.EVIDENCE_MODEL_DEFAULT = 'gemma4:31b';
49
- exports.MAX_EVIDENCE_SESSIONS = 20;
50
- exports.EVIDENCE_SESSION_CHAR_CAP = 6000;
51
- /** The `reasoning_effort` values OpenAI-compatible providers share. Which ones a model accepts is the provider's call. */
52
- exports.EVIDENCE_REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high'];
53
- /**
54
- * Walk ranked hits as session identities, then hydrate each selected session
55
- * from the complete source note. Retrieved chunk text is never extractor input.
56
- * Unreadable/virtual/out-of-vault paths are skipped and later hits backfill.
57
- * The first maxSessions unique notes by encounter rank are selected.
58
- */
59
- async function loadEvidenceSessionsFromVault(hits, vaultPath, opts = {}) {
60
- const maxSessions = opts.maxSessions ?? exports.MAX_EVIDENCE_SESSIONS;
61
- const charCap = opts.charCap ?? exports.EVIDENCE_SESSION_CHAR_CAP;
62
- if (maxSessions <= 0)
63
- throw new Error('maxSessions must be > 0');
64
- if (charCap <= 0)
65
- throw new Error('charCap must be > 0');
66
- const root = node_path_1.default.resolve(vaultPath);
67
- const seen = new Set();
68
- const sessions = [];
69
- for (const hit of hits) {
70
- if (!hit.notePath || seen.has(hit.notePath))
71
- continue;
72
- seen.add(hit.notePath);
73
- const candidate = node_path_1.default.isAbsolute(hit.notePath)
74
- ? node_path_1.default.resolve(hit.notePath)
75
- : node_path_1.default.resolve(root, hit.notePath);
76
- const rel = node_path_1.default.relative(root, candidate);
77
- if (rel === '..' || rel.startsWith(`..${node_path_1.default.sep}`) || node_path_1.default.isAbsolute(rel))
78
- continue;
79
- let raw;
80
- try {
81
- raw = await promises_1.default.readFile(candidate, 'utf8');
82
- }
83
- catch {
84
- continue;
85
- }
86
- const parsedBody = (0, parser_1.parseNote)(candidate, raw).body;
87
- const body = opts.transformBody ? opts.transformBody(parsedBody) : parsedBody;
88
- if (!body)
89
- continue;
90
- const text = body.length > charCap ? `${body.slice(0, charCap)} …[truncated]` : body;
91
- sessions.push({ stem: hit.notePath, date: hit.session_date, text });
92
- if (sessions.length >= maxSessions)
93
- break;
94
- }
95
- return sessions;
96
- }
97
- function sessionBlock(session) {
98
- const date = session.date ?? '';
99
- return `--- Session dated ${date} ---\n${session.text}`;
100
- }
101
- /** Exact prompt the extractor receives; the cache keys on this string. */
102
- function renderEvidencePrompt(query, sessions) {
103
- return exports.EVIDENCE_PROMPT_TEMPLATE
104
- .replace('{question}', query)
105
- .replace('{sessions}', sessions.map(sessionBlock).join('\n\n'));
106
- }
107
- /**
108
- * The extractor answered, and its answer is not a table: it did not parse, or it stopped at the token limit. This is
109
- * the one failure a search remembers (EVIDENCE_FAILURE_TTL_MS); an error before any answer is not. The message is the
110
- * parse error's, so a caller that reads messages reads what it read before.
111
- */
112
- class EvidenceReplyError extends Error {
113
- }
114
- exports.EvidenceReplyError = EvidenceReplyError;
115
- /**
116
- * Fail-fast parse: malformed items JSON throws; it is never cached.
117
- *
118
- * A reply the strict parse rejects is repaired for each malformed shape extractors were seen to write (2026-10-03
119
- * benchmark runs; tests/fixtures/evidence-replies.json), and the first repair whose result is, whole, a JSON object
120
- * with an items list gives the table. A well-formed object is found inside surrounding text, as it always was; a
121
- * repaired one is not, because a sentence that only quotes malformed JSON (a note's copy of the prompt's example) is no
122
- * table. A repair changes structure only, never a character inside a string, so no value is guessed. Any other reply
123
- * still throws the strict parse's own error.
124
- */
125
- function parseEvidenceItems(raw) {
126
- const s = raw.trim().replace(/^```(?:json)?|```$/gm, '').trim();
127
- try {
128
- return parseItemsObject(s);
129
- }
130
- catch (err) {
131
- for (const repaired of repairedReplies(s)) {
132
- try {
133
- return itemsFromPayload(JSON.parse(repaired));
134
- }
135
- catch {
136
- // Not this shape.
137
- }
138
- }
139
- throw err;
140
- }
141
- }
142
- /** A JSON string (or the one the reply ends inside), a run of `{` or a run of `}`: a brace inside a string is text. */
143
- const STRING_OR_BRACE_RUN = /"(?:[^"\\]|\\[\s\S])*(?:"|$)|\{+|\}+/g;
144
- function* repairedReplies(s) {
145
- // The rows without the object around them: [{"item":...},...].
146
- if (s.startsWith('['))
147
- yield `{"items":${s}}`;
148
- // The prompt's own example has doubled braces ({{"items":[{{...}}]}}), and models copy them, on every object or on
149
- // the outer one only: a run of 2n braces outside strings stands for n.
150
- const halved = s.replace(STRING_OR_BRACE_RUN, run => (run[0] === '"' || run.length % 2 === 1 ? run : run.slice(run.length / 2)));
151
- if (halved !== s)
152
- yield halved;
153
- // A reply cut off inside the list (at the token limit): the rows before the cut, then the list and object closed.
154
- // The cut row is dropped, never completed.
155
- let end = -1;
156
- for (const run of s.matchAll(STRING_OR_BRACE_RUN))
157
- if (run[0][0] === '}')
158
- end = run.index + run[0].length;
159
- if (end > 0)
160
- yield `${s.slice(0, end)}]}`;
161
- }
162
- function parseItemsObject(s) {
163
- const m = s.match(/\{[\s\S]*\}/);
164
- if (!m)
165
- throw new Error('extractor response did not contain a JSON object');
166
- let payload;
167
- try {
168
- payload = JSON.parse(m[0]);
169
- }
170
- catch (err) {
171
- const detail = err instanceof Error ? err.message : String(err);
172
- throw new Error(`extractor returned malformed JSON: ${detail}`);
173
- }
174
- return itemsFromPayload(payload);
175
- }
176
- function itemsFromPayload(payload) {
177
- const items = payload.items;
178
- if (!Array.isArray(items))
179
- throw new Error('extractor JSON must contain an items list');
180
- return items.map((rawItem, index) => {
181
- if (!rawItem || typeof rawItem !== 'object' || Array.isArray(rawItem)) {
182
- throw new Error(`extractor item ${index} must be an object`);
183
- }
184
- const it = rawItem;
185
- const item = typeof it.item === 'string' ? it.item.trim() : '';
186
- if (!item)
187
- throw new Error(`extractor item ${index} must contain a non-empty item string`);
188
- return {
189
- item,
190
- ...(it.action !== undefined ? { action: String(it.action) } : {}),
191
- ...(it.amount !== undefined ? { amount: String(it.amount) } : {}),
192
- ...(it.date !== undefined ? { date: String(it.date) } : {}),
193
- };
194
- });
195
- }
196
- /**
197
- * Runs (or replays) the second pass. A cache hit performs no model call.
198
- */
199
- class EvidenceExtractor {
200
- chat;
201
- cache;
202
- model;
203
- bounds;
204
- constructor(opts) {
205
- this.chat = opts.chat;
206
- this.cache = opts.cache ?? null;
207
- this.model = opts.model ?? exports.EVIDENCE_MODEL_DEFAULT;
208
- this.bounds = opts.bounds ?? {};
209
- }
210
- /** The exact prompt the extractor receives for `query` over `sessions`, and the key its table is cached under. */
211
- promptAndKey(query, sessions) {
212
- const prompt = renderEvidencePrompt(query, sessions);
213
- // A bound changes what the provider returns, so it is part of the cache
214
- // identity: a bounded arm never replays an unbounded arm's table.
215
- return { prompt, key: evidenceCache_1.EvidenceCache.computeKey(this.model, prompt, this.bounds) };
216
- }
217
- /** The key extract() caches `query` over `sessions` under, computed the one way extract() computes it. */
218
- cacheKey(query, sessions) {
219
- return this.promptAndKey(query, sessions).key;
220
- }
221
- /** The failure remembered under `key` (EVIDENCE_FAILURE_TTL_MS), or null. Never calls the model. */
222
- replayFailure(key) {
223
- return this.cache?.getFailure(key) ?? null;
224
- }
225
- /**
226
- * Remembers that the extraction under `key` failed with `error`, so the same request does not pay for it again.
227
- * A failure the cache cannot store is still reported, as it always was; only the next search pays again.
228
- */
229
- rememberFailure(key, error) {
230
- try {
231
- this.cache?.putFailure(key, { model: this.model, error, failedAt: Date.now() });
232
- }
233
- catch (err) {
234
- process.stderr.write(`[evidence] could not remember a failed extraction: ${err instanceof Error ? err.message : String(err)}\n`);
235
- }
236
- }
237
- /** The extraction cached under `key`, or null. Never calls the model. */
238
- replay(key) {
239
- const cached = this.cache?.get(key) ?? null;
240
- if (!cached)
241
- return null;
242
- return {
243
- items: cached.items,
244
- sessions: cached.sessions,
245
- fromCache: true,
246
- model: cached.model,
247
- usage: { promptTokens: cached.promptTokens, completionTokens: cached.completionTokens },
248
- latencyMs: 0,
249
- };
250
- }
251
- async extract(query, sessions) {
252
- if (sessions.length === 0)
253
- throw new Error('evidence extraction requires at least one session');
254
- const { prompt, key } = this.promptAndKey(query, sessions);
255
- const cached = this.replay(key);
256
- if (cached)
257
- return cached;
258
- const res = await this.chat({
259
- model: this.model,
260
- messages: [{ role: 'user', content: prompt }],
261
- temperature: 0,
262
- ...(this.bounds.maxTokens !== undefined ? { max_tokens: this.bounds.maxTokens } : {}),
263
- ...(this.bounds.reasoningEffort !== undefined ? { reasoning_effort: this.bounds.reasoningEffort } : {}),
264
- });
265
- let items;
266
- try {
267
- items = parseEvidenceItems(res.content);
268
- }
269
- catch (err) {
270
- const detail = err instanceof Error ? err.message : String(err);
271
- // Same parse failure (same retry policy), but a reply cut at a token
272
- // limit says so rather than reading as malformed by the model.
273
- throw new EvidenceReplyError(res.finishReason === 'length'
274
- ? `extractor reply stopped at the token limit (finish_reason=length): ${detail}`
275
- : detail);
276
- }
277
- const sessionMeta = sessions.map(s => ({ stem: s.stem, ...(s.date ? { date: s.date } : {}), chars: s.text.length }));
278
- const usage = {
279
- promptTokens: res.promptTokens ?? Math.ceil(prompt.length / 4),
280
- completionTokens: res.completionTokens ?? Math.ceil(res.content.length / 4),
281
- };
282
- this.cache?.put(key, {
283
- items,
284
- sessions: sessionMeta,
285
- model: this.model,
286
- question: query,
287
- promptTokens: usage.promptTokens,
288
- completionTokens: usage.completionTokens,
289
- createdAt: new Date().toISOString(),
290
- });
291
- return { items, sessions: sessionMeta, fromCache: false, model: this.model, usage, latencyMs: res.latencyMs };
292
- }
293
- }
294
- exports.EvidenceExtractor = EvidenceExtractor;
@@ -1,34 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.classifyCaptureEnabled = classifyCaptureEnabled;
4
- exports.planCapture = planCapture;
5
- /**
6
- * What to do with a saved note, from the local-rules classifier only.
7
- *
8
- * RENOR_CLASSIFY_CAPTURE defaults OFF. Off means the live save path is unchanged: the note
9
- * stays a raw note and nothing is classified. There is no model call, no new provider, and
10
- * no API key. The local rules cannot honestly name a subject, predicate and object, so even
11
- * when the flag is on this module only returns a draft. It does not write a fact.
12
- */
13
- const decision_model_1 = require("./decision-model");
14
- const DURABLE = new Set(['decision', 'preference', 'fact', 'result']);
15
- function classifyCaptureEnabled(env = process.env) {
16
- const raw = (env.RENOR_CLASSIFY_CAPTURE ?? '').trim().toLowerCase();
17
- return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on';
18
- }
19
- /** A draft only. `author` is the connection name plus "-auto", and nothing is written. */
20
- function planCapture(text, author, env = process.env) {
21
- if (!classifyCaptureEnabled(env))
22
- return { disposition: 'off' };
23
- const kind = (0, decision_model_1.classifyNote)(text);
24
- if (kind === 'sensitive')
25
- return { disposition: 'drop', kind };
26
- if (!DURABLE.has(kind))
27
- return { disposition: 'raw', kind: kind === 'request' ? 'request' : 'noise' };
28
- return {
29
- disposition: 'structured',
30
- kind: kind,
31
- statement: text.trim(),
32
- author: `${author}-auto`,
33
- };
34
- }
@@ -1,174 +0,0 @@
1
- "use strict";
2
- /**
3
- * DecisionModel adapter (Lane Jev write-path plan §3): the single seam for
4
- * extraction-time typed decisions — capture-gate classification and dedupe
5
- * adjudication. The ledger never depends on a vendor: the default TODAY is the
6
- * deterministic local-rules implementation (`LocalRulesDecisionModel`, zero
7
- * model calls, zero cost); a model-backed adapter (gemma4:31b, jev, ...) plugs
8
- * in later by implementing this interface. No vendor is hardcoded anywhere in
9
- * the write path.
10
- *
11
- * Contract shape (docs/evals/LANE-JEV-WRITE-PATH.md §3):
12
- * decide(task, input) -> { decision: TypedEnum, confidence, latencyMs, costUSDCents }
13
- *
14
- * Privacy mode is part of the interface: the local implementation never sends
15
- * text off-host, and costUSDCents is 0 for every local decision.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.LocalRulesDecisionModel = exports.STATIVE_CUE_RE = exports.NUMERIC_FACT_RE = void 0;
19
- exports.classifyNote = classifyNote;
20
- exports.defaultDecisionModel = defaultDecisionModel;
21
- const secretScanner_1 = require("./secretScanner");
22
- const rowStore_1 = require("../context/rowStore");
23
- /**
24
- * Lexical identity normalization for the dedupe verdict, shared with the
25
- * rowStore dedupe key — this must be the SAME function the key is built from.
26
- * It used to be a byte-copy of `normDedupeValue`, which is how it drifted into
27
- * deleting every non-Latin character independently of the key pipeline; the two
28
- * are now one import so a key and its adjudication verdict cannot disagree.
29
- */
30
- const norm = rowStore_1.normDedupeValue;
31
- /**
32
- * v1 numeric-fact capture cues: a number (with optional unit) anchored to a
33
- * stative or eventive predicate. Conservative and gold-blind — the rules are
34
- * the current-baseline classification, not a quality claim (the Lane Jev
35
- * adapter is the seam where a stronger classifier plugs in). Exported so the
36
- * capture-gate rules and the candidate extractor share one definition.
37
- */
38
- exports.NUMERIC_FACT_RE = /\b(\d+:\d{2}(?::\d{2})?|\d+(?:[.,]\d+)?)\s*(km|kg|mi|miles?|minutes?|mins?|hours?|hrs?|days?|weeks?|years?|%|percent|dollars?|usd|\$|€|£|reps?|lbs?|pounds?)?\b/i;
39
- exports.STATIVE_CUE_RE = /\b(is|are|was|were|has|have|had|weighs?|costs?|paid|earned|runs?|ran|completed|finished|measures?|lasted|took|scored|deadline|birthday|anniversary|scheduled|due)\b/i;
40
- /**
41
- * Local rules DecisionModel — the default TODAY. Deterministic (same input →
42
- * same decision), zero network, zero cost. Capture gate: a span is offered to
43
- * fact extraction only when it carries a numeric value anchored by a cue
44
- * verb/phrase; everything else gates to `none` in v1 (events/preferences are
45
- * C3/C4 lanes). Dedupe: exact normalized (value, object) equality is
46
- * `identical`; same object with a changed value is `updated`; otherwise
47
- * `distinct`. Supersede is identity-keyed only — never blanket newest-wins
48
- * (N18 KILL).
49
- *
50
- * Harmonization: the same adjudication semantics generalize per lane on the
51
- * lane's own payload identity — event: same event + same `when` is
52
- * `identical`, same event with a changed `when` is `updated`; preference:
53
- * same normalized statement is `identical` (statement IS the identity),
54
- * anything else `distinct`. The rowKind default keeps the v1 fact-lane
55
- * callers (and their tests) byte-identical.
56
- */
57
- const DECISION_RE = /\b(decided|decision|we will|we'll|going with|chose|chosen|the call is|agreed to)\b/i;
58
- const PREFERENCE_RE = /\b(prefer|preference|rather|always use|never use|don't use|do not use|instead of)\b/i;
59
- const RESULT_RE = /\b(passed|failed|shipped|the result|finished|deployed|merged)\b/i;
60
- const REQUEST_RE = /\b(please|can you|could you|would you|need you to|let me know|ask [a-z0-9_-]+ to)\b/i;
61
- const NOISE_LEAD_RE = /^(ok|okay|thanks|thank you|lol|hey|on it|looking|got it|sure|yep|nope)\b/i;
62
- const NOISE_CHATTER_RE = /\b(thanks|thank you|lol)\b/i;
63
- const COPULA_RE = /\b(is|are|was|were)\b/i;
64
- /**
65
- * Cue order is fixed: a decision, preference or result is named before a question mark can
66
- * steal it, and a numeric fact (the existing capture gate) is named before a broad "is".
67
- * Anything else is noise. Sensitive text is refused before any of those.
68
- */
69
- function classifyNote(text) {
70
- const trimmed = text.trim();
71
- if (!trimmed)
72
- return 'noise';
73
- if ((0, secretScanner_1.scanSecrets)(trimmed))
74
- return 'sensitive';
75
- if (DECISION_RE.test(trimmed))
76
- return 'decision';
77
- if (PREFERENCE_RE.test(trimmed))
78
- return 'preference';
79
- if (RESULT_RE.test(trimmed))
80
- return 'result';
81
- if (LocalRulesDecisionModel.captureGate(trimmed) === 'fact')
82
- return 'fact';
83
- if (REQUEST_RE.test(trimmed) || /\?\s*$/.test(trimmed))
84
- return 'request';
85
- if (NOISE_LEAD_RE.test(trimmed) || NOISE_CHATTER_RE.test(trimmed))
86
- return 'noise';
87
- const words = trimmed.split(/\s+/).length;
88
- if (COPULA_RE.test(trimmed) && words >= 4)
89
- return 'fact';
90
- return 'noise';
91
- }
92
- class LocalRulesDecisionModel {
93
- async decide(request) {
94
- const start = Date.now();
95
- let result;
96
- if (request.task === 'capture_gate') {
97
- result = {
98
- task: 'capture_gate',
99
- decision: LocalRulesDecisionModel.captureGate(request.text),
100
- confidence: 1,
101
- latencyMs: 0,
102
- costUSDCents: 0,
103
- };
104
- }
105
- else if (request.task === 'classify_capture') {
106
- result = {
107
- task: 'classify_capture',
108
- decision: LocalRulesDecisionModel.classifyNote(request.text),
109
- confidence: 1,
110
- latencyMs: 0,
111
- costUSDCents: 0,
112
- };
113
- }
114
- else {
115
- result = {
116
- task: 'dedupe_adjudication',
117
- decision: LocalRulesDecisionModel.adjudicate(request.candidate, request.existing, request.rowKind ?? 'fact'),
118
- confidence: 1,
119
- latencyMs: 0,
120
- costUSDCents: 0,
121
- };
122
- }
123
- // latencyMs is reported (measured wall time), never simulated.
124
- const latencyMs = Date.now() - start;
125
- return { ...result, latencyMs };
126
- }
127
- static captureGate(text) {
128
- if (!text || !text.trim())
129
- return 'none';
130
- const hasValue = exports.NUMERIC_FACT_RE.test(text);
131
- const hasCue = exports.STATIVE_CUE_RE.test(text);
132
- if (hasValue && hasCue)
133
- return 'fact';
134
- return 'none';
135
- }
136
- /**
137
- * Local rules for a saved note. Same constraints as the rest of this class: deterministic,
138
- * no network, no key, cost 0. This is not a model. It does not invent a subject, predicate
139
- * or object, and nothing here writes a memory.
140
- */
141
- static classifyNote(text) {
142
- return classifyNote(text);
143
- }
144
- static adjudicate(candidate, existing, rowKind = 'fact') {
145
- if (!existing)
146
- return 'distinct';
147
- if (rowKind === 'event') {
148
- const c = candidate;
149
- const e = existing;
150
- if (norm(c.event) !== norm(e.event))
151
- return 'distinct';
152
- return norm(c.when) === norm(e.when) ? 'identical' : 'updated';
153
- }
154
- if (rowKind === 'preference') {
155
- const c = candidate;
156
- const e = existing;
157
- return norm(c.statement) === norm(e.statement) ? 'identical' : 'distinct';
158
- }
159
- const c = candidate;
160
- const e = existing;
161
- const sameObject = norm(c.object) === norm(e.object);
162
- const sameValue = norm(c.value) === norm(e.value);
163
- if (sameObject && sameValue)
164
- return 'identical';
165
- if (sameObject && !sameValue)
166
- return 'updated';
167
- return 'distinct';
168
- }
169
- }
170
- exports.LocalRulesDecisionModel = LocalRulesDecisionModel;
171
- /** The write path's default decision point — local rules today, vendor later. */
172
- function defaultDecisionModel() {
173
- return new LocalRulesDecisionModel();
174
- }