renor-engine 1.0.0 → 1.2.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.
- package/LICENSE +202 -661
- package/NOTICE +8 -6
- package/README.md +13 -8
- package/dist/.tsbuildinfo +1 -0
- package/dist/api/server.js +10 -8
- package/dist/buildIdentity.js +18 -1
- package/dist/callPhases.js +82 -0
- package/dist/cli.js +36 -1
- package/dist/context/rowStore.js +1 -1
- package/dist/conversation/parser.js +40 -36
- package/dist/db/client.js +6 -4
- package/dist/db/handoffTable.js +31 -0
- package/dist/db/indexSalvage.js +24 -4
- package/dist/db/migrations.js +30 -2
- package/dist/db/sqlite.js +396 -0
- package/dist/digests/digestCache.js +6 -2
- package/dist/digests/digests.js +3 -3
- package/dist/digests/worker.js +3 -1
- package/dist/embeddings/caching.js +5 -5
- package/dist/embeddings/local.js +5 -3
- package/dist/embeddings/openai.js +4 -3
- package/dist/embeddings/simdScan.js +3 -1
- package/dist/embeddings/vectorIndex.js +0 -1
- package/dist/embeddings/vertex.js +123 -13
- package/dist/eval/cacheReport.js +7 -0
- package/dist/eval/context700-candidate.js +5 -5
- package/dist/eval/evalCache.js +46 -3
- package/dist/eval/indexSnapshots.js +549 -0
- package/dist/eval/pageDump.js +67 -0
- package/dist/eval/runManifest.js +6 -0
- package/dist/eval/textTokens.js +17 -0
- package/dist/evidence/attach.js +0 -3
- package/dist/evidence/evidenceCache.js +3 -3
- package/dist/evidence/ollamaChat.js +1 -1
- package/dist/evidence/options.js +46 -25
- package/dist/evidence/secondPass.js +8 -170
- package/dist/extraction/factExtractor.js +1 -1
- package/dist/extraction/jevDecisionModel.js +307 -0
- package/dist/extraction/preferenceExtractor.js +1 -4
- package/dist/extraction/secretGuard.js +7 -3
- package/dist/extraction/typedFacts.js +1 -1
- package/dist/importing/apply.js +42 -14
- package/dist/importing/cli.js +9 -8
- package/dist/importing/existing.js +2 -0
- package/dist/importing/facts.js +0 -2
- package/dist/importing/plan.js +0 -5
- package/dist/importing/source.js +1 -1
- package/dist/indexer/parser.js +4 -1
- package/dist/indexer/pipeline.js +99 -279
- package/dist/indexer/walker.js +11 -25
- package/dist/learning/cli.js +113 -0
- package/dist/learning/schema.js +144 -0
- package/dist/learning/settings.js +45 -0
- package/dist/learning/store.js +267 -0
- package/dist/learning/tap.js +401 -0
- package/dist/mcp/server.js +36 -6
- package/dist/memory/dreamer/adjudicate.js +215 -0
- package/dist/memory/dreamer/apply.js +120 -0
- package/dist/memory/dreamer/budget.js +64 -0
- package/dist/memory/dreamer/candidates.js +149 -0
- package/dist/memory/dreamer/collection.js +104 -0
- package/dist/memory/dreamer/dreamer.js +352 -0
- package/dist/memory/dreamer/review.js +111 -0
- package/dist/memory/factConflicts.js +2 -0
- package/dist/memory/handoff.js +363 -0
- package/dist/memory/lifecycle.js +338 -80
- package/dist/memory/sourceName.js +77 -1
- package/dist/memory/statusFacts.js +61 -0
- package/dist/memory/writer.js +3 -2
- package/dist/memorymap/memoryMap.js +39 -13
- package/dist/memorymap/replacements.js +8 -3
- package/dist/mvp/agentMemory.js +109 -50
- package/dist/mvp/answerCheck.js +211 -0
- package/dist/mvp/cli.js +14 -1
- package/dist/mvp/compileCache.js +3 -10
- package/dist/mvp/compileSeed.js +9 -3
- package/dist/mvp/config.js +4 -0
- package/dist/mvp/contextDistinct.js +53 -0
- package/dist/mvp/contextProfile.js +87 -0
- package/dist/mvp/directorySurface.js +68 -0
- package/dist/mvp/engine.js +39 -26
- package/dist/mvp/exportAll.js +36 -2
- package/dist/mvp/factMarkers.js +18 -2
- package/dist/mvp/history.js +5 -4
- package/dist/mvp/log.js +118 -0
- package/dist/mvp/server.js +759 -136
- package/dist/mvp/serverCard.js +12 -3
- package/dist/mvp/telemetry.js +35 -2
- package/dist/net/poolFetch.js +174 -0
- package/dist/recall/actionRecall.js +282 -0
- package/dist/recall/autoRecall.js +447 -0
- package/dist/recall/searchRecall.js +189 -0
- package/dist/retrieval/entityLookup.js +53 -4
- package/dist/retrieval/orchestrator.js +148 -10
- package/dist/retrieval/plainWording.js +236 -0
- package/dist/retrieval/rankingTrace.js +184 -0
- package/dist/retrieval/readerLayout.js +143 -224
- package/dist/router/routerCache.js +2 -2
- package/dist/sharing/cli.js +181 -0
- package/dist/sharing/examples.js +136 -0
- package/dist/sharing/fields.js +225 -0
- package/dist/sharing/loop.js +80 -0
- package/dist/sharing/project.js +327 -0
- package/dist/sharing/send.js +466 -0
- package/dist/sharing/state.js +222 -0
- package/dist/sharing/wording.js +48 -0
- package/dist/watcher/watcher.js +5 -3
- package/package.json +5 -7
- package/dist/BUILD.json +0 -6
- package/dist/importing/index.js +0 -29
|
@@ -8,7 +8,7 @@ exports.dropEvidenceForStems = dropEvidenceForStems;
|
|
|
8
8
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
9
9
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
10
10
|
const node_path_1 = __importDefault(require("node:path"));
|
|
11
|
-
const
|
|
11
|
+
const sqlite_1 = __importDefault(require("../db/sqlite"));
|
|
12
12
|
/**
|
|
13
13
|
* Content-addressed cache for the H10 second-pass evidence extraction.
|
|
14
14
|
*
|
|
@@ -58,7 +58,7 @@ class EvidenceCache {
|
|
|
58
58
|
failurePutStmt;
|
|
59
59
|
constructor(dbPath) {
|
|
60
60
|
node_fs_1.default.mkdirSync(node_path_1.default.dirname(dbPath), { recursive: true });
|
|
61
|
-
this.db = new
|
|
61
|
+
this.db = new sqlite_1.default(dbPath);
|
|
62
62
|
this.db.pragma('journal_mode = WAL');
|
|
63
63
|
this.db.pragma('busy_timeout = 10000');
|
|
64
64
|
this.db.exec(`
|
|
@@ -166,7 +166,7 @@ exports.EvidenceCache = EvidenceCache;
|
|
|
166
166
|
function dropEvidenceForStems(cachePath, stems) {
|
|
167
167
|
if (stems.length === 0 || !node_fs_1.default.existsSync(cachePath))
|
|
168
168
|
return;
|
|
169
|
-
const db = new
|
|
169
|
+
const db = new sqlite_1.default(cachePath);
|
|
170
170
|
try {
|
|
171
171
|
db.pragma('busy_timeout = 10000');
|
|
172
172
|
if (!db.prepare(`SELECT 1 FROM sqlite_master WHERE type = 'table' AND name = 'evidence_cache'`).get())
|
|
@@ -37,7 +37,7 @@ function createOllamaChat(opts) {
|
|
|
37
37
|
try {
|
|
38
38
|
const resp = await fetch(`${baseUrl}/chat/completions`, {
|
|
39
39
|
method: 'POST',
|
|
40
|
-
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json' },
|
|
40
|
+
headers: { Authorization: `Bearer ${key}`, 'Content-Type': 'application/json', ...opts.headers },
|
|
41
41
|
body,
|
|
42
42
|
signal: controller.signal,
|
|
43
43
|
});
|
package/dist/evidence/options.js
CHANGED
|
@@ -5,6 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.resolveEvidenceBounds = resolveEvidenceBounds;
|
|
7
7
|
exports.resolveEvidenceProvider = resolveEvidenceProvider;
|
|
8
|
+
exports.evidenceCachePath = evidenceCachePath;
|
|
9
|
+
exports.resolveEvidenceChat = resolveEvidenceChat;
|
|
8
10
|
exports.resolveEvidenceToolOptions = resolveEvidenceToolOptions;
|
|
9
11
|
exports.createEvidenceExtractor = createEvidenceExtractor;
|
|
10
12
|
const node_path_1 = __importDefault(require("node:path"));
|
|
@@ -62,50 +64,69 @@ function resolveEvidenceProvider(env = process.env) {
|
|
|
62
64
|
].map(k => k.trim()).filter(Boolean);
|
|
63
65
|
return { baseUrl, keys };
|
|
64
66
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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 = {}) {
|
|
73
79
|
const optin = (0, optin_1.resolveEvidenceOptin)(env);
|
|
74
80
|
const { baseUrl, keys } = resolveEvidenceProvider(env);
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
// fractional setting is finite and positive, so a bare `> 0` test let it
|
|
80
|
-
// through and `Math.floor` turned it into 0 — and 0 is not a silent no-op:
|
|
81
|
-
// `loadEvidenceSessionsFromVault` rejects it (`maxSessions must be > 0`),
|
|
82
|
-
// which the `evidence` MCP tool surfaces as a thrown error and the search path
|
|
83
|
-
// swallows as `extractor-error`. Floor first, then require >= 1.
|
|
84
|
-
const requested = Number(env.RENOR_EVIDENCE_SESSIONS ?? '');
|
|
85
|
-
const requestedSessions = Number.isFinite(requested) ? Math.floor(requested) : Number.NaN;
|
|
86
|
-
const maxSessions = Number.isFinite(requestedSessions) && requestedSessions >= 1
|
|
87
|
-
? Math.min(requestedSessions, 50)
|
|
88
|
-
: secondPass_1.MAX_EVIDENCE_SESSIONS;
|
|
81
|
+
const bounds = {
|
|
82
|
+
...(transport.timeoutMs !== undefined ? { timeoutMs: transport.timeoutMs } : {}),
|
|
83
|
+
...(transport.maxRetries !== undefined ? { maxRetries: transport.maxRetries } : {}),
|
|
84
|
+
};
|
|
89
85
|
let chat;
|
|
90
86
|
if (optin) {
|
|
91
87
|
const optinKey = (0, optin_1.optinEndpointAllowed)(baseUrl) ? (0, optin_1.readOptinKey)(optin.keyFile) : null;
|
|
92
88
|
if (optinKey) {
|
|
93
89
|
const dailyCap = optin.dailyCap;
|
|
90
|
+
const cachePath = evidenceCachePath(config, env);
|
|
94
91
|
// The allowance is spent per HTTP attempt (a retried 429 or 5xx is another request to the provider), so it
|
|
95
92
|
// sits inside the transport rather than around it.
|
|
96
93
|
chat = (0, ollamaChat_1.createOllamaChat)({
|
|
97
94
|
keys: [optinKey],
|
|
98
95
|
beforeAttempt: (0, optin_1.dailyBudgetGate)(() => new optin_1.EvidenceDailyBudget(cachePath, dailyCap)),
|
|
96
|
+
...bounds,
|
|
99
97
|
});
|
|
100
98
|
}
|
|
101
99
|
}
|
|
102
100
|
else if (keys.length > 0) {
|
|
103
|
-
chat = (0, ollamaChat_1.createOllamaChat)({ baseUrl, keys });
|
|
101
|
+
chat = (0, ollamaChat_1.createOllamaChat)({ baseUrl, keys, ...bounds });
|
|
104
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;
|
|
105
127
|
return {
|
|
106
128
|
mode,
|
|
107
|
-
|
|
108
|
-
model: optin ? secondPass_1.EVIDENCE_MODEL_DEFAULT : model,
|
|
129
|
+
model,
|
|
109
130
|
maxSessions,
|
|
110
131
|
charCap: secondPass_1.EVIDENCE_SESSION_CHAR_CAP,
|
|
111
132
|
cachePath,
|
|
@@ -3,11 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
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.
|
|
7
|
-
exports.evidenceEnumerateMode = evidenceEnumerateMode;
|
|
8
|
-
exports.evidenceEnumerateEnabled = evidenceEnumerateEnabled;
|
|
9
|
-
exports.scoreBodyOverlap = scoreBodyOverlap;
|
|
10
|
-
exports.bodyRankEnabled = bodyRankEnabled;
|
|
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;
|
|
11
7
|
exports.loadEvidenceSessionsFromVault = loadEvidenceSessionsFromVault;
|
|
12
8
|
exports.renderEvidencePrompt = renderEvidencePrompt;
|
|
13
9
|
exports.parseEvidenceItems = parseEvidenceItems;
|
|
@@ -47,95 +43,6 @@ relevant to answering the question. Rules:
|
|
|
47
43
|
SESSIONS:
|
|
48
44
|
{sessions}
|
|
49
45
|
|
|
50
|
-
Respond with ONLY minified JSON, no markdown:
|
|
51
|
-
{{"items":[{{"item":"...","action":"...","amount":"...","date":"..."}}]}}`;
|
|
52
|
-
/**
|
|
53
|
-
* EXHAUSTIVE enumeration variant of the evidence prompt (RENOR_EVIDENCE_ENUMERATE,
|
|
54
|
-
* default OFF — opt in with 1/true/yes/on).
|
|
55
|
-
*
|
|
56
|
-
* Why this exists, measured: the shipped prompt asks for items "that could be
|
|
57
|
-
* relevant to answering the question" — a relevance FILTER applied to an
|
|
58
|
-
* enumeration task. On the champion's 23 count/aggregate wrongs that filter is
|
|
59
|
-
* the binding constraint: the evidence table holds a mean of 5.3 items, and 13 of
|
|
60
|
-
* the 23 have FEWER items than the gold count requires. The count-contract arm
|
|
61
|
-
* proved the reader's arithmetic is correct — it lists 2 items and answers "2"
|
|
62
|
-
* for gold 3 — so the items are simply absent from the table it counts.
|
|
63
|
-
*
|
|
64
|
-
* Prompt-variant A/B on one case (gpt4_31ff4165, "How many health-related devices
|
|
65
|
-
* do I use in a day?", gold 4) at temperature 0:
|
|
66
|
-
*
|
|
67
|
-
* shipped prompt : 4 items, 134 completion tokens
|
|
68
|
-
* this variant : 27 items, 936 completion tokens
|
|
69
|
-
*
|
|
70
|
-
* The variant asks for everything mentioned and states that completeness is the
|
|
71
|
-
* only goal, that missing an item is a failure, and that including an irrelevant
|
|
72
|
-
* item is NOT a failure — the exact inverse of the shipped relevance filter.
|
|
73
|
-
*
|
|
74
|
-
* Scope discipline: this changes the EVIDENCE prompt only. The frozen
|
|
75
|
-
* judge/extractor model, the retrieval ranking, the schema, the item payload and
|
|
76
|
-
* the fact/chronicle/preference lanes are untouched. Default OFF, so shipped
|
|
77
|
-
* behaviour is byte-identical unless an eval arm opts in.
|
|
78
|
-
*/
|
|
79
|
-
exports.EVIDENCE_PROMPT_TEMPLATE_EXHAUSTIVE = `You extract a COMPLETE inventory of items from a user's dated conversation history.
|
|
80
|
-
|
|
81
|
-
QUESTION: {question}
|
|
82
|
-
|
|
83
|
-
Below are the sessions (with dates) that a memory system retrieved for this question.
|
|
84
|
-
|
|
85
|
-
TASK: List EVERY distinct item, device, object, purchase, place, person, activity, event or amount mentioned ANYWHERE in the sessions below — whether or not it appears relevant to the question. Completeness is the ONLY goal.
|
|
86
|
-
Rules:
|
|
87
|
-
- COMPLETENESS OVER BREVITY. If the sessions mention ten things, list all ten. Do not summarise, do not select, do not rank, do not judge relevance.
|
|
88
|
-
- Missing an item is a failure. Including an item that turns out to be irrelevant is NOT a failure.
|
|
89
|
-
- One entry per distinct item (e.g., each product, each device, each trip, each course, each amount).
|
|
90
|
-
- Do NOT merge different items. Do NOT compute any totals.
|
|
91
|
-
- "action" = what happened (bought / visited / completed / raised / inherited / used / ...).
|
|
92
|
-
- "amount" = numeric value + unit when stated (e.g., "3 days", "$120", "100 points"); else "".
|
|
93
|
-
- "date" = the session/mention date when available; else "".
|
|
94
|
-
|
|
95
|
-
SESSIONS:
|
|
96
|
-
{sessions}
|
|
97
|
-
|
|
98
|
-
Respond with ONLY minified JSON, no markdown:
|
|
99
|
-
{{"items":[{{"item":"...","action":"...","amount":"...","date":"..."}}]}}`;
|
|
100
|
-
function evidenceEnumerateMode(env = process.env) {
|
|
101
|
-
const raw = (env.RENOR_EVIDENCE_ENUMERATE ?? '').trim().toLowerCase();
|
|
102
|
-
if (raw === 'scoped')
|
|
103
|
-
return 'scoped';
|
|
104
|
-
if (raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on')
|
|
105
|
-
return 'all';
|
|
106
|
-
return 'off';
|
|
107
|
-
}
|
|
108
|
-
/** Back-compat boolean form (true for either enumeration mode). */
|
|
109
|
-
function evidenceEnumerateEnabled(env = process.env) {
|
|
110
|
-
return evidenceEnumerateMode(env) !== 'off';
|
|
111
|
-
}
|
|
112
|
-
/**
|
|
113
|
-
* SCOPED enumeration template: the model first names the entity type the question
|
|
114
|
-
* counts, then lists every instance of that type. Deliberately instructs the model
|
|
115
|
-
* to EXCLUDE the incidental magnitudes it is not being asked to count (steps per
|
|
116
|
-
* day, hours of sleep, battery pack sizes) — the exact mass that made `all`
|
|
117
|
-
* unusable. Gold-blind: the only input is the user's question and the retrieved
|
|
118
|
-
* sessions.
|
|
119
|
-
*/
|
|
120
|
-
exports.EVIDENCE_PROMPT_TEMPLATE_SCOPED = `You extract a COMPLETE inventory of one specific kind of entity from a user's dated conversation history.
|
|
121
|
-
|
|
122
|
-
QUESTION: {question}
|
|
123
|
-
|
|
124
|
-
Below are the sessions (with dates) that a memory system retrieved for this question.
|
|
125
|
-
|
|
126
|
-
STEP 1 — From the QUESTION, decide the single kind of thing being counted or totalled. Examples: "how many items of clothing" -> garments; "how many devices do I use" -> devices; "how many albums did I buy" -> albums; "how much did I spend in total" -> purchases with an amount; "how many properties did I view" -> properties.
|
|
127
|
-
|
|
128
|
-
STEP 2 — List EVERY instance of THAT kind found ANYWHERE in the sessions below. Completeness is the only goal.
|
|
129
|
-
Rules:
|
|
130
|
-
- Do NOT list incidental magnitudes of the same sentences. If counting devices, do NOT list "10,000 steps", "7-9 hours of sleep", "size 13 batteries" or "8-10 glasses of fluid" — those are not devices.
|
|
131
|
-
- Do NOT summarise, do NOT select, do NOT rank, do NOT judge relevance.
|
|
132
|
-
- Missing an instance of the counted kind is a failure. Including one that turns out to be irrelevant is NOT a failure.
|
|
133
|
-
- Keep each entry short: the entity itself, plus the amount/detail if the question is about an amount.
|
|
134
|
-
- Do NOT merge different instances. Do NOT compute any totals.
|
|
135
|
-
|
|
136
|
-
SESSIONS:
|
|
137
|
-
{sessions}
|
|
138
|
-
|
|
139
46
|
Respond with ONLY minified JSON, no markdown:
|
|
140
47
|
{{"items":[{{"item":"...","action":"...","amount":"...","date":"..."}}]}}`;
|
|
141
48
|
exports.EVIDENCE_MODEL_DEFAULT = 'gemma4:31b';
|
|
@@ -143,52 +50,11 @@ exports.MAX_EVIDENCE_SESSIONS = 20;
|
|
|
143
50
|
exports.EVIDENCE_SESSION_CHAR_CAP = 6000;
|
|
144
51
|
/** The `reasoning_effort` values OpenAI-compatible providers share. Which ones a model accepts is the provider's call. */
|
|
145
52
|
exports.EVIDENCE_REASONING_EFFORTS = ['none', 'minimal', 'low', 'medium', 'high'];
|
|
146
|
-
/**
|
|
147
|
-
* H9-family stop list (same shape as mvp/agentMemory.ts FTS_STOP_WORDS).
|
|
148
|
-
*/
|
|
149
|
-
const BODY_RANK_STOP_WORDS = new Set([
|
|
150
|
-
'the', 'a', 'an', 'is', 'are', 'was', 'were', 'what', 'which', 'who', 'where', 'when',
|
|
151
|
-
'why', 'how', 'do', 'does', 'did', 'to', 'for', 'of', 'in', 'on', 'at', 'with', 'and',
|
|
152
|
-
'or', 'my', 'your', 'our', 'their', 'his', 'her', 'it', 'this', 'that', 'about',
|
|
153
|
-
]);
|
|
154
|
-
/** Unicode-aware lexical tokens: letter/number runs, 2..64 chars (H9 family). */
|
|
155
|
-
function bodyRankTokens(text) {
|
|
156
|
-
return (text.toLowerCase().match(/[\p{L}\p{N}]{2,64}/gu) ?? []).slice(0, 20000);
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Deterministic, gold-blind lexical query-term overlap between a query and a
|
|
160
|
-
* candidate note body: total frequency of each distinct non-stop query term in
|
|
161
|
-
* the body. Zero model calls and zero embeddings at query time.
|
|
162
|
-
*/
|
|
163
|
-
function scoreBodyOverlap(query, body) {
|
|
164
|
-
const queryTerms = new Set(bodyRankTokens(query).filter(term => !BODY_RANK_STOP_WORDS.has(term)));
|
|
165
|
-
if (queryTerms.size === 0)
|
|
166
|
-
return 0;
|
|
167
|
-
const counts = new Map();
|
|
168
|
-
for (const token of bodyRankTokens(body))
|
|
169
|
-
counts.set(token, (counts.get(token) ?? 0) + 1);
|
|
170
|
-
let score = 0;
|
|
171
|
-
for (const term of queryTerms)
|
|
172
|
-
score += counts.get(term) ?? 0;
|
|
173
|
-
return score;
|
|
174
|
-
}
|
|
175
|
-
/** Opt-in kill-switch for body-relevance selection; default off. */
|
|
176
|
-
function bodyRankEnabled(env = process.env) {
|
|
177
|
-
const raw = (env.RENOR_EVIDENCE_BODY_RANK ?? '').trim().toLowerCase();
|
|
178
|
-
return raw === '1' || raw === 'true' || raw === 'yes' || raw === 'on';
|
|
179
|
-
}
|
|
180
53
|
/**
|
|
181
54
|
* Walk ranked hits as session identities, then hydrate each selected session
|
|
182
55
|
* from the complete source note. Retrieved chunk text is never extractor input.
|
|
183
56
|
* Unreadable/virtual/out-of-vault paths are skipped and later hits backfill.
|
|
184
|
-
*
|
|
185
|
-
* Default (RENOR_EVIDENCE_BODY_RANK off): the first maxSessions unique notes by
|
|
186
|
-
* encounter rank. With RENOR_EVIDENCE_BODY_RANK=1: every unique candidate note
|
|
187
|
-
* among the hits is hydrated (same ≤charCap truncation), scored by
|
|
188
|
-
* `scoreBodyOverlap`, and the top maxSessions are selected by
|
|
189
|
-
* (score desc, hit rank asc, notePath asc). Deterministic and gold-blind;
|
|
190
|
-
* per-session hydrated text and therefore extraction prompt bytes are
|
|
191
|
-
* unchanged, so the evidence content-addressed cache stays valid.
|
|
57
|
+
* The first maxSessions unique notes by encounter rank are selected.
|
|
192
58
|
*/
|
|
193
59
|
async function loadEvidenceSessionsFromVault(hits, vaultPath, opts = {}) {
|
|
194
60
|
const maxSessions = opts.maxSessions ?? exports.MAX_EVIDENCE_SESSIONS;
|
|
@@ -197,12 +63,10 @@ async function loadEvidenceSessionsFromVault(hits, vaultPath, opts = {}) {
|
|
|
197
63
|
throw new Error('maxSessions must be > 0');
|
|
198
64
|
if (charCap <= 0)
|
|
199
65
|
throw new Error('charCap must be > 0');
|
|
200
|
-
const bodyRank = opts.bodyRank ?? bodyRankEnabled();
|
|
201
66
|
const root = node_path_1.default.resolve(vaultPath);
|
|
202
67
|
const seen = new Set();
|
|
203
|
-
const
|
|
204
|
-
for (
|
|
205
|
-
const hit = hits[hitRank];
|
|
68
|
+
const sessions = [];
|
|
69
|
+
for (const hit of hits) {
|
|
206
70
|
if (!hit.notePath || seen.has(hit.notePath))
|
|
207
71
|
continue;
|
|
208
72
|
seen.add(hit.notePath);
|
|
@@ -224,33 +88,11 @@ async function loadEvidenceSessionsFromVault(hits, vaultPath, opts = {}) {
|
|
|
224
88
|
if (!body)
|
|
225
89
|
continue;
|
|
226
90
|
const text = body.length > charCap ? `${body.slice(0, charCap)} …[truncated]` : body;
|
|
227
|
-
|
|
228
|
-
if (
|
|
91
|
+
sessions.push({ stem: hit.notePath, date: hit.session_date, text });
|
|
92
|
+
if (sessions.length >= maxSessions)
|
|
229
93
|
break;
|
|
230
94
|
}
|
|
231
|
-
|
|
232
|
-
// internal hitRank before returning (review finding P2-1).
|
|
233
|
-
if (!bodyRank)
|
|
234
|
-
return candidates.map(({ hitRank, ...session }) => session);
|
|
235
|
-
return selectSessionsByBodyOverlap(opts.query ?? '', candidates).slice(0, maxSessions);
|
|
236
|
-
}
|
|
237
|
-
/**
|
|
238
|
-
* Body-relevance selection: score desc, then hit rank asc, then notePath asc.
|
|
239
|
-
* Fully deterministic; a zero-score query degrades to encounter order.
|
|
240
|
-
*/
|
|
241
|
-
function selectSessionsByBodyOverlap(query, candidates) {
|
|
242
|
-
const scored = candidates.map(candidate => ({
|
|
243
|
-
candidate,
|
|
244
|
-
score: scoreBodyOverlap(query, candidate.text),
|
|
245
|
-
}));
|
|
246
|
-
scored.sort((a, b) => b.score - a.score
|
|
247
|
-
|| a.candidate.hitRank - b.candidate.hitRank
|
|
248
|
-
|| (a.candidate.stem < b.candidate.stem ? -1 : a.candidate.stem > b.candidate.stem ? 1 : 0));
|
|
249
|
-
return scored.map(({ candidate }) => ({
|
|
250
|
-
stem: candidate.stem,
|
|
251
|
-
date: candidate.date,
|
|
252
|
-
text: candidate.text,
|
|
253
|
-
}));
|
|
95
|
+
return sessions;
|
|
254
96
|
}
|
|
255
97
|
function sessionBlock(session) {
|
|
256
98
|
const date = session.date ?? '';
|
|
@@ -258,11 +100,7 @@ function sessionBlock(session) {
|
|
|
258
100
|
}
|
|
259
101
|
/** Exact prompt the extractor receives; the cache keys on this string. */
|
|
260
102
|
function renderEvidencePrompt(query, sessions) {
|
|
261
|
-
|
|
262
|
-
const template = mode === 'scoped' ? exports.EVIDENCE_PROMPT_TEMPLATE_SCOPED
|
|
263
|
-
: mode === 'all' ? exports.EVIDENCE_PROMPT_TEMPLATE_EXHAUSTIVE
|
|
264
|
-
: exports.EVIDENCE_PROMPT_TEMPLATE;
|
|
265
|
-
return template
|
|
103
|
+
return exports.EVIDENCE_PROMPT_TEMPLATE
|
|
266
104
|
.replace('{question}', query)
|
|
267
105
|
.replace('{sessions}', sessions.map(sessionBlock).join('\n\n'));
|
|
268
106
|
}
|
|
@@ -42,5 +42,5 @@ Rules:
|
|
|
42
42
|
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.facts)) {
|
|
43
43
|
throw new Error('Fact extraction response is missing a facts array');
|
|
44
44
|
}
|
|
45
|
-
return parsed.facts.filter((f) => f.subject && f.predicate && f.object && typeof f.confidence === 'number');
|
|
45
|
+
return parsed.facts.filter((f) => Boolean(f.subject && f.predicate && f.object && typeof f.confidence === 'number'));
|
|
46
46
|
}
|