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
|
@@ -0,0 +1,184 @@
|
|
|
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.RankingTrace = exports.RANKING_TERMS = void 0;
|
|
7
|
+
exports.rankingTermIndex = rankingTermIndex;
|
|
8
|
+
exports.newRankingTerms = newRankingTerms;
|
|
9
|
+
exports.attachRankingTerms = attachRankingTerms;
|
|
10
|
+
exports.addRankingTerm = addRankingTerm;
|
|
11
|
+
exports.clientNotePath = clientNotePath;
|
|
12
|
+
exports.traceKey = traceKey;
|
|
13
|
+
exports.currentRankingTrace = currentRankingTrace;
|
|
14
|
+
exports.withRankingTrace = withRankingTrace;
|
|
15
|
+
const node_crypto_1 = require("node:crypto");
|
|
16
|
+
const node_async_hooks_1 = require("node:async_hooks");
|
|
17
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
18
|
+
const hiddenSpans_1 = require("../mvp/hiddenSpans");
|
|
19
|
+
/**
|
|
20
|
+
* What the ranker added up for each candidate of one read, for the learning log (src/learning, schema version 2).
|
|
21
|
+
*
|
|
22
|
+
* rankWindow (orchestrator.ts) gives every candidate a base score (a cosine for a semantic hit, 0.3 for a graph hit, the fact
|
|
23
|
+
* lane's own score for a fact hit, 0 for a session-expansion statement) and then adds or subtracts named terms. A trace keeps
|
|
24
|
+
* each term as it is applied, so base + the sum of the terms is the score the candidate was ranked by, and a learner can refit
|
|
25
|
+
* the weights from the log.
|
|
26
|
+
*
|
|
27
|
+
* Nothing here changes a score, an order or a reply. A trace is only written to while a read runs inside `withRankingTrace`,
|
|
28
|
+
* and only the learning log's tool wrapper opens that scope (server.ts), and only when the log is on. With the log off no scope
|
|
29
|
+
* is opened and every call here returns at once, so the ranking runs as it always did.
|
|
30
|
+
*
|
|
31
|
+
* Identity. A candidate is keyed by the note path the reply shows, its heading path and the text as the reply shows it
|
|
32
|
+
* (labelled by mvp/hiddenSpans.ts): the chunk id is not in the reply. The note path the reply shows is the path relative to the
|
|
33
|
+
* memory folder when the note is inside it (engine.ts clientPath); the ranker holds the stored path, so a trace made for a memory
|
|
34
|
+
* folder shows the same path the reply does. The key is hashed, so no text is kept in a map longer than the read that made it.
|
|
35
|
+
*/
|
|
36
|
+
/** The named additive terms rankWindow applies, in the order it applies them. Each is a signed number added to a score. */
|
|
37
|
+
exports.RANKING_TERMS = [
|
|
38
|
+
'stub', // a speaker's stub line: -0.5 (orchestrator.ts isSpeakerStub)
|
|
39
|
+
'content', // a contentful chunk: up to +0.12 (contentBoost)
|
|
40
|
+
'priority', // a path the caller prioritises: +0.1
|
|
41
|
+
'entity', // the query names the entity this note is the source of: +0.2
|
|
42
|
+
'entity_lane', // the optional entity lane's lexical coverage lift: up to +0.12
|
|
43
|
+
'recency', // time decay: up to +0.1 for a note written today, 0 after 30 days
|
|
44
|
+
'fact', // the note's own entity has a fact the query names: +0.15
|
|
45
|
+
'asof_year', // an explicit past-date query, and the text names its year: +0.08
|
|
46
|
+
'asof_month', // the same, and the text names its month: +0.04
|
|
47
|
+
'historical_intent', // past intent: a historical note sharing two of the query's words: +0.3
|
|
48
|
+
'stale_fact', // present query: the text carries a value the lifecycle has superseded: -0.15
|
|
49
|
+
'past_fact', // past intent: the same text is lifted instead: +0.1
|
|
50
|
+
'current_fact', // the text carries the current value of a superseded predicate: +0.1
|
|
51
|
+
];
|
|
52
|
+
function rankingTermIndex(term) {
|
|
53
|
+
return exports.RANKING_TERMS.indexOf(term);
|
|
54
|
+
}
|
|
55
|
+
// The terms and the pool rank travel with a candidate object as symbol-keyed properties: a spread copies them, JSON does not
|
|
56
|
+
// show them, and a reply never carries them (the reply copies named fields only).
|
|
57
|
+
const TERMS = Symbol('renor.rankingTerms');
|
|
58
|
+
const POOL_RANK = Symbol('renor.poolRank');
|
|
59
|
+
const zeros = () => new Array(exports.RANKING_TERMS.length).fill(0);
|
|
60
|
+
/** A fresh row of zeros for a candidate about to be scored. */
|
|
61
|
+
function newRankingTerms() {
|
|
62
|
+
return zeros();
|
|
63
|
+
}
|
|
64
|
+
/** Attaches a candidate's term row (the row rankWindow filled while it scored the candidate). */
|
|
65
|
+
function attachRankingTerms(hit, terms) {
|
|
66
|
+
hit[TERMS] = terms;
|
|
67
|
+
return hit;
|
|
68
|
+
}
|
|
69
|
+
/** Adds one term's delta to a candidate that is already scored; the score itself is changed by the caller, as before. */
|
|
70
|
+
function addRankingTerm(hit, term, delta) {
|
|
71
|
+
const carried = hit;
|
|
72
|
+
const row = carried[TERMS] ?? (carried[TERMS] = zeros());
|
|
73
|
+
row[rankingTermIndex(term)] += delta;
|
|
74
|
+
}
|
|
75
|
+
function termsOf(hit) {
|
|
76
|
+
return hit[TERMS];
|
|
77
|
+
}
|
|
78
|
+
function poolRankOf(hit) {
|
|
79
|
+
return hit[POOL_RANK] ?? null;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The note path the reply shows for a stored path: relative to the memory folder when the note is inside it, else its file name.
|
|
83
|
+
* This is engine.ts `clientPath` without its cache, repeated here so the ranker does not import the engine (which imports it).
|
|
84
|
+
* A path that is not absolute is already in the form the reply shows (a candidate the engine's search has listed), so it is
|
|
85
|
+
* returned as it is; with no memory folder every path is.
|
|
86
|
+
*/
|
|
87
|
+
function clientNotePath(memoryDir, stored) {
|
|
88
|
+
if (memoryDir === undefined || !node_path_1.default.isAbsolute(stored))
|
|
89
|
+
return stored;
|
|
90
|
+
const resolved = node_path_1.default.resolve(stored);
|
|
91
|
+
const root = node_path_1.default.resolve(memoryDir);
|
|
92
|
+
return resolved === root || resolved.startsWith(root + node_path_1.default.sep) ? node_path_1.default.relative(root, resolved) || stored : node_path_1.default.basename(stored);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* The key of a candidate, given the note path as the reply shows it. Hashed, over the path, the heading path and the text as the
|
|
96
|
+
* reply labels it (mvp/hiddenSpans.ts), so a candidate the ranker holds and the same candidate in a reply have one key.
|
|
97
|
+
*/
|
|
98
|
+
function traceKey(shownNotePath, headingPath, text) {
|
|
99
|
+
const labelled = (0, hiddenSpans_1.labelMemoryText)({ text }).text;
|
|
100
|
+
return (0, node_crypto_1.createHash)('sha256').update(JSON.stringify([shownNotePath, headingPath ?? '', labelled])).digest('hex');
|
|
101
|
+
}
|
|
102
|
+
class RankingTrace {
|
|
103
|
+
memoryDir;
|
|
104
|
+
entries = new Map();
|
|
105
|
+
/** `memoryDir`: the memory folder the reply's note paths are relative to. Without one, the stored paths are the shown ones. */
|
|
106
|
+
constructor(memoryDir) {
|
|
107
|
+
this.memoryDir = memoryDir;
|
|
108
|
+
}
|
|
109
|
+
/** Records a candidate as the ranker holds it now. Its terms are the ones addRankingTerm and attachRankingTerms put on it. */
|
|
110
|
+
touch(hit) {
|
|
111
|
+
const notePath = clientNotePath(this.memoryDir, hit.notePath);
|
|
112
|
+
const key = traceKey(notePath, hit.headingPath, hit.text);
|
|
113
|
+
const known = this.entries.get(key);
|
|
114
|
+
if (known)
|
|
115
|
+
return known;
|
|
116
|
+
const terms = termsOf(hit) ?? zeros();
|
|
117
|
+
const score = hit.score ?? 0;
|
|
118
|
+
const entry = {
|
|
119
|
+
key,
|
|
120
|
+
notePath,
|
|
121
|
+
headingPath: hit.headingPath ?? null,
|
|
122
|
+
reason: hit.reason ?? '',
|
|
123
|
+
base: score - terms.reduce((sum, term) => sum + term, 0),
|
|
124
|
+
terms: [...terms],
|
|
125
|
+
poolRank: poolRankOf(hit),
|
|
126
|
+
windowPos: null,
|
|
127
|
+
budgetKept: null,
|
|
128
|
+
};
|
|
129
|
+
this.entries.set(key, entry);
|
|
130
|
+
return entry;
|
|
131
|
+
}
|
|
132
|
+
/** Records a candidate's place in the scored pool (1 is the best score). */
|
|
133
|
+
pool(hit, rank) {
|
|
134
|
+
hit[POOL_RANK] = rank;
|
|
135
|
+
this.touch(hit);
|
|
136
|
+
}
|
|
137
|
+
/** Records the candidates in the order the reply's window presents them, 1-based, before any budget cut. */
|
|
138
|
+
presented(hits) {
|
|
139
|
+
hits.forEach((hit, index) => {
|
|
140
|
+
this.touch(hit).windowPos = index + 1;
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Records which candidates the budget kept. `considered` are the candidates it weighed and `kept` the ones it kept; a candidate
|
|
145
|
+
* considered and not kept is false. A ledger memory is listed with its note path and heading blanked (agentMemory.ts), so it
|
|
146
|
+
* cannot be told from the candidate the ranker scored: it gets no entry rather than a second, unmatched one.
|
|
147
|
+
*/
|
|
148
|
+
budgeted(considered, kept) {
|
|
149
|
+
const keptKeys = new Set(kept.filter(hit => hit.notePath !== '').map(hit => this.keyOfHit(hit)));
|
|
150
|
+
for (const hit of considered) {
|
|
151
|
+
if (hit.notePath === '')
|
|
152
|
+
continue;
|
|
153
|
+
const key = this.keyOfHit(hit);
|
|
154
|
+
const entry = this.entries.get(key) ?? this.touch(hit);
|
|
155
|
+
entry.budgetKept = keptKeys.has(key);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/** The entry under a key from `traceKey`, when the trace has one. */
|
|
159
|
+
byKey(key) {
|
|
160
|
+
return this.entries.get(key);
|
|
161
|
+
}
|
|
162
|
+
/** Finds a unique chunk by fields that reply decoration preserves even when it changes the displayed text. */
|
|
163
|
+
byLocation(notePath, headingPath) {
|
|
164
|
+
const matches = [...this.entries.values()].filter(entry => entry.notePath === notePath && entry.headingPath === (headingPath ?? null));
|
|
165
|
+
return matches.length === 1 ? matches[0] : undefined;
|
|
166
|
+
}
|
|
167
|
+
/** Every candidate of the read, in the order it was first recorded. */
|
|
168
|
+
all() {
|
|
169
|
+
return [...this.entries.values()];
|
|
170
|
+
}
|
|
171
|
+
keyOfHit(hit) {
|
|
172
|
+
return traceKey(clientNotePath(this.memoryDir, hit.notePath), hit.headingPath, hit.text);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
exports.RankingTrace = RankingTrace;
|
|
176
|
+
const scope = new node_async_hooks_1.AsyncLocalStorage();
|
|
177
|
+
/** The trace of the read in progress, when one is being collected. */
|
|
178
|
+
function currentRankingTrace() {
|
|
179
|
+
return scope.getStore();
|
|
180
|
+
}
|
|
181
|
+
/** Runs `work` with `trace` collecting the terms of every read it makes. */
|
|
182
|
+
function withRankingTrace(trace, work) {
|
|
183
|
+
return scope.run(trace, work);
|
|
184
|
+
}
|
|
@@ -1,39 +1,50 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.READER_SESSION_CAP = exports.LAYOUT_MIN_TURNS = void 0;
|
|
4
4
|
exports.readerLayoutEnabled = readerLayoutEnabled;
|
|
5
5
|
exports.readerLayoutSkipsAdvice = readerLayoutSkipsAdvice;
|
|
6
6
|
exports.readerLayoutEnabledFor = readerLayoutEnabledFor;
|
|
7
7
|
exports.readerTimelineEnabled = readerTimelineEnabled;
|
|
8
|
-
exports.roleAwarePageEnabled = roleAwarePageEnabled;
|
|
9
|
-
exports.refersToAssistant = refersToAssistant;
|
|
10
|
-
exports.clipWords = clipWords;
|
|
11
|
-
exports.clipAssistantTurns = clipAssistantTurns;
|
|
12
|
-
exports.clipAssistantHit = clipAssistantHit;
|
|
13
|
-
exports.clipAssistantChunks = clipAssistantChunks;
|
|
14
8
|
exports.isCurrentValueQuestion = isCurrentValueQuestion;
|
|
15
9
|
exports.currentValueTimeline = currentValueTimeline;
|
|
16
10
|
exports.isConversation = isConversation;
|
|
17
11
|
exports.conversationNoteMatcher = conversationNoteMatcher;
|
|
12
|
+
exports.readerSessionCap = readerSessionCap;
|
|
13
|
+
exports.readerBlockOrder = readerBlockOrder;
|
|
14
|
+
exports.isHeaderOnly = isHeaderOnly;
|
|
18
15
|
exports.layoutHitsForReader = layoutHitsForReader;
|
|
16
|
+
exports.layoutPage = layoutPage;
|
|
17
|
+
exports.readerLayoutPage = readerLayoutPage;
|
|
19
18
|
exports.readerLayoutOf = readerLayoutOf;
|
|
20
19
|
const relativeTimeHints_1 = require("./relativeTimeHints");
|
|
20
|
+
const orchestrator_1 = require("./orchestrator");
|
|
21
21
|
const questionSpan_1 = require("./questionSpan");
|
|
22
22
|
const readerEvents_1 = require("./readerEvents");
|
|
23
23
|
const conversationShape_1 = require("./conversationShape");
|
|
24
24
|
const adviceQuestion_1 = require("./adviceQuestion");
|
|
25
25
|
/**
|
|
26
26
|
* How a search reply is laid out for the model that reads it. Retrieval picks the window and orders it; this only
|
|
27
|
-
* changes how what it picked is handed over, and it never
|
|
27
|
+
* changes how what it picked is handed over, and it never cuts or rewrites a word of an excerpt it shows:
|
|
28
28
|
*
|
|
29
29
|
* - one hit per session: the chunks of a note on one date, which the newest-first layout left apart (a session's header,
|
|
30
30
|
* which carries its date, could come after the turns it dates, and turns of other sessions in between), come as one hit,
|
|
31
31
|
* in the note's own order, so every turn sits under the date of its session;
|
|
32
|
+
* - a session whose only chunk is its header (`# Session x` and a `Timestamp:` line) is no hit: it dated nothing the reader
|
|
33
|
+
* can see and took a place in the reply (a third of the hits of the 2026-10-16 LongMemEval-S run);
|
|
34
|
+
* - the blocks stand where the page had them (newest first by default). RENOR_READER_ORDER=relevance puts them best match
|
|
35
|
+
* first instead (a block's score is its best chunk's, ties newest first) and the reply says so (`rankedBy: score`,
|
|
36
|
+
* readerLayoutPage; only a page whose ordinary notes are all conversations). It is off by default: on RenorBench v2 it puts a
|
|
37
|
+
* superseded value ahead of the current one (tests/eval/renorbench-v2.test.ts);
|
|
38
|
+
* - RENOR_READER_SESSION_CAP=N lets a session show at most N chunks besides its header, except that every chunk the query
|
|
39
|
+
* matched stays: the cap only stops the statements the session expansion added. Off by default (0): on RenorBench v2 a cap
|
|
40
|
+
* of 10 drops the remark a question asks about, which only the expansion delivers;
|
|
32
41
|
* - a session that reaches the reader without its header (the date line is its first chunk) opens with
|
|
33
42
|
* `[Session date: <date>]`;
|
|
34
43
|
* - each time phrase that names one point in time ("three weeks ago", "last Thursday") is resolved to its date below
|
|
35
44
|
* the excerpt (relativeTimeHints.ts).
|
|
36
45
|
*
|
|
46
|
+
* Whole chunks leave (a header stub, a statement over the cap); no chunk is cut or reworded.
|
|
47
|
+
*
|
|
37
48
|
* Only notes shaped like a conversation (conversationShape.ts) are laid out: a session is one conversation, and merging
|
|
38
49
|
* the chunks of a document or the entries of a daily note would break "a hit is one memory".
|
|
39
50
|
*
|
|
@@ -51,10 +62,6 @@ const adviceQuestion_1 = require("./adviceQuestion");
|
|
|
51
62
|
* Oldest first, the latest line marked, earlier lines kept. It quotes those turns and does not cut or reword an excerpt,
|
|
52
63
|
* invent a value, or do arithmetic on a session header (a header date orders two different calendar days only; a shared
|
|
53
64
|
* day is not a clock). A duration question or an order question is left untouched.
|
|
54
|
-
*
|
|
55
|
-
* Experimental, opt-in, and only on top of this layout (`RENOR_ROLE_AWARE_PAGE=1`; default off, so a layout-on page is
|
|
56
|
-
* byte-identical): a role-aware page. Unless the question refers to what the assistant said, each assistant turn on the
|
|
57
|
-
* page is clipped to its first 60 words; user turns, headings and dates are never touched (see roleAwarePage below).
|
|
58
65
|
*/
|
|
59
66
|
function readerLayoutEnabled() {
|
|
60
67
|
const v = (process.env.RENOR_READER_LAYOUT ?? '').trim().toLowerCase();
|
|
@@ -78,149 +85,6 @@ function readerTimelineEnabled(env = process.env) {
|
|
|
78
85
|
const v = (env.RENOR_READER_TIMELINE ?? '').trim().toLowerCase();
|
|
79
86
|
return v === '1' || v === 'true' || v === 'yes' || v === 'on';
|
|
80
87
|
}
|
|
81
|
-
/**
|
|
82
|
-
* RENOR_ROLE_AWARE_PAGE (default off, experimental; `1` / `true` / `yes` / `on` turns it on): a role-aware page. When the
|
|
83
|
-
* question does not refer to what the assistant said, each assistant turn of a conversation on the page is clipped to its
|
|
84
|
-
* first `ROLE_AWARE_ASSISTANT_WORDS` words, cut at a word boundary and marked "…". User turns, every heading, a session's
|
|
85
|
-
* header and `Timestamp:` line, the `[Session date: …]` and `[Counted from this session's date …]` lines and the hit's
|
|
86
|
-
* `session_date` are never touched. Off, the page is not looked at, so it is byte for byte the former one.
|
|
87
|
-
*
|
|
88
|
-
* Why (evidence analysis of the 2026-10-18 official LongMemEval run, not yet an answer measurement): in the multi-session,
|
|
89
|
-
* temporal, knowledge-update and preference questions the evidence is always a user turn, while assistant text is 28-39%
|
|
90
|
-
* of the page's words; clipping assistant turns to 60 words on those questions removes 21% of them. A question whose
|
|
91
|
-
* evidence is what the assistant said is kept whole by `refersToAssistant`.
|
|
92
|
-
*
|
|
93
|
-
* The speaker comes only from the turn heading (`### Turn N — Assistant`), never from a benchmark label. A hit that starts
|
|
94
|
-
* inside an assistant turn (the later chunk of a long answer, with no heading of its own) is known by its heading path.
|
|
95
|
-
*/
|
|
96
|
-
exports.ROLE_AWARE_ASSISTANT_WORDS = 60;
|
|
97
|
-
function roleAwarePageEnabled(env = process.env) {
|
|
98
|
-
const v = (env.RENOR_ROLE_AWARE_PAGE ?? '').trim().toLowerCase();
|
|
99
|
-
return v === '1' || v === 'true' || v === 'yes' || v === 'on';
|
|
100
|
-
}
|
|
101
|
-
/** Phrasing that asks about what the assistant said; such a question keeps assistant turns whole. */
|
|
102
|
-
const ASSISTANT_REFERENCE = new RegExp([
|
|
103
|
-
String.raw `\byou (?:had |just |once )?(?:recommended|suggested|told me|said|mentioned|gave me|provided|listed)\b`,
|
|
104
|
-
String.raw `\bdid you (?:recommend|suggest|tell me|say|mention|give me|provide|list)\b`,
|
|
105
|
-
String.raw `\bour (?:previous|last|earlier|past|prior) (?:conversation|chat|discussion)s?\b`,
|
|
106
|
-
String.raw `\bremind me (?:again )?(?:what|which|of what|how|where|who) you\b`,
|
|
107
|
-
String.raw `\bearlier,? you\b`,
|
|
108
|
-
].join('|'), 'i');
|
|
109
|
-
function refersToAssistant(query) {
|
|
110
|
-
return ASSISTANT_REFERENCE.test(query.replace(/[\u2018\u2019]/g, "'"));
|
|
111
|
-
}
|
|
112
|
-
const LAYOUT_HEADING = /^(#{1,6})[ \t]+(.*?)[ \t]*\r?$/;
|
|
113
|
-
const TURN_ROLE = /^Turn[ \t]+\d+[ \t]+[—–-][ \t]+(\S.*)$/i;
|
|
114
|
-
/** Lines the layout itself writes, which date what is around them: kept whole, and their words are not the turn's. */
|
|
115
|
-
const DATE_LINE = /^\[(?:Session date: |Counted from this session's date)/;
|
|
116
|
-
/** For a heading's text: 'assistant' or 'other' when it is a turn heading, null when it is not one. */
|
|
117
|
-
function turnRole(heading) {
|
|
118
|
-
const role = TURN_ROLE.exec(heading.trim())?.[1];
|
|
119
|
-
if (role === undefined)
|
|
120
|
-
return null;
|
|
121
|
-
return /^assistant$/i.test(role.trim()) ? 'assistant' : 'other';
|
|
122
|
-
}
|
|
123
|
-
/** At most `budget` words of `body`, cut at a word boundary and marked "…"; its leading and trailing whitespace is kept. */
|
|
124
|
-
function takeWords(body, budget) {
|
|
125
|
-
const words = [...body.matchAll(/\S+/g)];
|
|
126
|
-
if (words.length <= budget)
|
|
127
|
-
return { text: body, used: words.length };
|
|
128
|
-
const end = budget === 0 ? (/^\s*/.exec(body)?.[0].length ?? 0) : (words[budget - 1].index ?? 0) + words[budget - 1][0].length;
|
|
129
|
-
const trailing = /\s*$/.exec(body)?.[0] ?? '';
|
|
130
|
-
return { text: `${body.slice(0, end)}${budget === 0 ? '' : ' '}…${trailing}`, used: budget };
|
|
131
|
-
}
|
|
132
|
-
/** The first `limit` words of `body`, cut at a word boundary and marked " …"; a body that fits is returned as is. */
|
|
133
|
-
function clipWords(body, limit = exports.ROLE_AWARE_ASSISTANT_WORDS) {
|
|
134
|
-
return takeWords(body, limit).text;
|
|
135
|
-
}
|
|
136
|
-
/** What is left of an assistant turn's words at the end of a text: null when the text ends outside an assistant turn. */
|
|
137
|
-
function clipFrom(text, limit, start) {
|
|
138
|
-
const out = [];
|
|
139
|
-
let budget = start;
|
|
140
|
-
let body = [];
|
|
141
|
-
const flush = () => {
|
|
142
|
-
if (body.length === 0)
|
|
143
|
-
return;
|
|
144
|
-
const joined = body.join('\n');
|
|
145
|
-
if (budget === null)
|
|
146
|
-
out.push(joined);
|
|
147
|
-
else {
|
|
148
|
-
const taken = takeWords(joined, budget);
|
|
149
|
-
budget -= taken.used;
|
|
150
|
-
out.push(taken.text);
|
|
151
|
-
}
|
|
152
|
-
body = [];
|
|
153
|
-
};
|
|
154
|
-
for (const line of text.split('\n')) {
|
|
155
|
-
if (DATE_LINE.test(line)) {
|
|
156
|
-
flush();
|
|
157
|
-
out.push(line);
|
|
158
|
-
continue;
|
|
159
|
-
}
|
|
160
|
-
const heading = LAYOUT_HEADING.exec(line);
|
|
161
|
-
if (!heading) {
|
|
162
|
-
body.push(line);
|
|
163
|
-
continue;
|
|
164
|
-
}
|
|
165
|
-
flush();
|
|
166
|
-
const role = turnRole(heading[2]);
|
|
167
|
-
if (role !== null)
|
|
168
|
-
budget = role === 'assistant' ? limit : null;
|
|
169
|
-
else if (heading[1].length <= 2)
|
|
170
|
-
budget = null;
|
|
171
|
-
out.push(line);
|
|
172
|
-
}
|
|
173
|
-
flush();
|
|
174
|
-
// Each piece was one or more whole lines; joining them with '\n' restores the line breaks between them.
|
|
175
|
-
return { text: out.join('\n'), budget };
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Clip each assistant turn of `text` to its first `limit` words. A turn runs from its `### Turn N — Assistant` heading to
|
|
179
|
-
* the next turn heading (or the next `#`/`##` heading); a smaller heading inside it is kept and its words count toward
|
|
180
|
-
* the same turn. Every heading line, every date line and everything outside an assistant turn (a user turn, a session
|
|
181
|
-
* header) is left byte for byte. `inAssistant`: the text starts inside an assistant turn.
|
|
182
|
-
*/
|
|
183
|
-
function clipAssistantTurns(text, limit = exports.ROLE_AWARE_ASSISTANT_WORDS, inAssistant = false) {
|
|
184
|
-
return clipFrom(text, limit, inAssistant ? limit : null).text;
|
|
185
|
-
}
|
|
186
|
-
function headingPathOf(hit) {
|
|
187
|
-
const value = hit.headingPath;
|
|
188
|
-
return typeof value === 'string' ? value : '';
|
|
189
|
-
}
|
|
190
|
-
function startsInAssistantTurn(headingPath) {
|
|
191
|
-
return headingPath.split(' > ').map(turnRole).filter(role => role !== null).pop() === 'assistant';
|
|
192
|
-
}
|
|
193
|
-
/** One hit on its own: its assistant turns clipped (its heading path says whether it starts inside one), every other field as it was. */
|
|
194
|
-
function clipAssistantHit(hit, limit = exports.ROLE_AWARE_ASSISTANT_WORDS) {
|
|
195
|
-
const text = clipAssistantTurns(hit.text, limit, startsInAssistantTurn(headingPathOf(hit)));
|
|
196
|
-
return text === hit.text ? hit : { ...hit, text };
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* The chunks of a page with their assistant turns clipped, before the layout joins them. A long answer is stored as several
|
|
200
|
-
* chunks and its heading as one more, which may not reach the page; so each chunk is read with its own heading path, in
|
|
201
|
-
* its note's order, and a turn that runs on into the next chunk carries the words it has left: the turn, not each chunk,
|
|
202
|
-
* keeps its first `limit` words. Hits that are no chunk, and their order, are untouched.
|
|
203
|
-
*/
|
|
204
|
-
function clipAssistantChunks(hits, chunk, limit = exports.ROLE_AWARE_ASSISTANT_WORDS) {
|
|
205
|
-
const order = hits.map((_, i) => i).filter(i => chunk(hits[i]))
|
|
206
|
-
.sort((a, b) => (hits[a].notePath < hits[b].notePath ? -1 : hits[a].notePath > hits[b].notePath ? 1 : (hits[a].chunkId ?? 0) - (hits[b].chunkId ?? 0)));
|
|
207
|
-
const left = new Map();
|
|
208
|
-
const out = hits.slice();
|
|
209
|
-
for (const i of order) {
|
|
210
|
-
const hit = hits[i];
|
|
211
|
-
const headingPath = headingPathOf(hit);
|
|
212
|
-
const key = `${hit.notePath}\u0000${headingPath}`;
|
|
213
|
-
const start = startsInAssistantTurn(headingPath) ? (left.get(key) ?? limit) : null;
|
|
214
|
-
const clipped = clipFrom(hit.text, limit, start);
|
|
215
|
-
if (clipped.budget === null)
|
|
216
|
-
left.delete(key);
|
|
217
|
-
else
|
|
218
|
-
left.set(key, clipped.budget);
|
|
219
|
-
if (clipped.text !== hit.text)
|
|
220
|
-
out[i] = { ...hit, text: clipped.text };
|
|
221
|
-
}
|
|
222
|
-
return out;
|
|
223
|
-
}
|
|
224
88
|
// A duration or an order stays byte-identical. "Ago" and "last Tuesday" are a point in the past, not a changed value.
|
|
225
89
|
const DURATION_QUESTION = /\b(?:how (?:many|much) (?:days|weeks|months|years)|how long|how much time|how old)\b|\b(?:days|weeks|months|years)\b[^?]{0,24}\b(?:ago|passed)\b|\bago\b|\bpassed between\b|\blast (?:week|month|year|weekend|monday|tuesday|wednesday|thursday|friday|saturday|sunday)\b/i;
|
|
226
90
|
const ORDER_QUESTION = /\border\b|\b(?:first to last|earliest to latest|happened first|came first)\b|\b(?:which|who)\b[^?]{0,80}\bfirst\b/i;
|
|
@@ -408,96 +272,151 @@ function conversationNoteMatcher(db) {
|
|
|
408
272
|
function isNoteChunk(hit, isLedger) {
|
|
409
273
|
return (hit.chunkId ?? 0) > 0 && hit.notePath !== '' && !isLedger(hit.notePath) && hit.author === undefined && hit.replaced === undefined;
|
|
410
274
|
}
|
|
275
|
+
/** The most chunks of one session's block (its header aside); RENOR_READER_SESSION_CAP, 0 (the default) is no cap. */
|
|
276
|
+
exports.READER_SESSION_CAP = 0;
|
|
277
|
+
function readerSessionCap(env = process.env) {
|
|
278
|
+
const raw = (env.RENOR_READER_SESSION_CAP ?? '').trim();
|
|
279
|
+
if (raw === '')
|
|
280
|
+
return exports.READER_SESSION_CAP;
|
|
281
|
+
const n = Number(raw);
|
|
282
|
+
return Number.isInteger(n) && n >= 0 ? n : exports.READER_SESSION_CAP;
|
|
283
|
+
}
|
|
284
|
+
/** Blocks keep the page's own (newest-first) order; RENOR_READER_ORDER=relevance puts them best match first. */
|
|
285
|
+
function readerBlockOrder(env = process.env) {
|
|
286
|
+
return (env.RENOR_READER_ORDER ?? '').trim().toLowerCase() === 'relevance' ? 'relevance' : 'date';
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* A chunk that is only a session's header: headings and `Timestamp:` lines, no turn. It dates the turns under it and says
|
|
290
|
+
* nothing itself; on its own it is a stub that takes a place in the reply (a third of the hits of the 2026-10-16 run).
|
|
291
|
+
*/
|
|
292
|
+
function isHeaderOnly(text) {
|
|
293
|
+
const lines = text.split(/\r?\n/).map(line => line.trim()).filter(line => line !== '' && !/^#{1,6}\s/.test(line));
|
|
294
|
+
return lines.length > 0 && lines.every(line => /^Timestamp:/i.test(line));
|
|
295
|
+
}
|
|
296
|
+
/** A hit of an ordinary note (a chunk the layout could place, a daily entry, a document paragraph): not a fact, a ledger event, a correction or the evidence and digest tables (`_renor/…`). */
|
|
297
|
+
function isOrdinaryNoteHit(hit, isLedger) {
|
|
298
|
+
return hit.notePath !== '' && !hit.notePath.startsWith('_renor/') && !isLedger(hit.notePath) && hit.author === undefined && hit.replaced === undefined;
|
|
299
|
+
}
|
|
411
300
|
function layoutHitsForReader(hits, opts) {
|
|
301
|
+
return layoutPage(hits, opts).hits;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* `byRelevance` is true when the blocks were placed best match first, which the reply then says (`rankedBy: score`). It is
|
|
305
|
+
* done only to a page whose every chunk of an ordinary note is a conversation's: a daily note's entries or a document's
|
|
306
|
+
* paragraphs on the same page keep the order the page gave them, and a page that is half one order and half the other must
|
|
307
|
+
* not claim either key.
|
|
308
|
+
*/
|
|
309
|
+
function layoutPage(hits, opts) {
|
|
412
310
|
const chunk = (hit) => isNoteChunk(hit, opts.isLedger) && (opts.isConversation?.(hit.notePath) ?? true);
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
const
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
311
|
+
const cap = opts.sessionCap ?? readerSessionCap();
|
|
312
|
+
const order = opts.order ?? readerBlockOrder();
|
|
313
|
+
const laid = hits.map(hit => (chunk(hit) ? { ...hit, text: (0, relativeTimeHints_1.withRelativeTimeHints)(hit.text, hit.session_date) } : hit));
|
|
314
|
+
// One block per conversation on one date: every chunk of it under that date, wherever the page had put it.
|
|
315
|
+
const keyOf = (hit) => (chunk(hit) ? `${hit.notePath}\0${hit.session_date ?? ''}` : null);
|
|
316
|
+
const blocks = new Map();
|
|
317
|
+
laid.forEach((hit, index) => {
|
|
318
|
+
const key = keyOf(hit);
|
|
319
|
+
if (key === null)
|
|
320
|
+
return;
|
|
321
|
+
const block = blocks.get(key) ?? { header: [], body: [], first: index };
|
|
322
|
+
(isHeaderOnly(hit.text) ? block.header : block.body).push(hit);
|
|
323
|
+
blocks.set(key, block);
|
|
324
|
+
});
|
|
325
|
+
const made = new Map();
|
|
326
|
+
for (const [key, block] of blocks)
|
|
327
|
+
made.set(key, blockHit(block, cap));
|
|
328
|
+
// The blocks stand in the places the page gave its chunks; anything else keeps its place.
|
|
329
|
+
const slots = new Set(laid.flatMap((hit, index) => (keyOf(hit) !== null && blocks.get(keyOf(hit)).first === index ? [index] : [])));
|
|
330
|
+
let placed = [...slots].map(index => keyOf(laid[index])).filter(key => made.get(key) !== null);
|
|
331
|
+
const byRelevance = order === 'relevance' && placed.length > 0 && hits.every(hit => !isOrdinaryNoteHit(hit, opts.isLedger) || chunk(hit));
|
|
332
|
+
if (byRelevance) {
|
|
333
|
+
const at = new Map(placed.map((key, i) => [key, i]));
|
|
334
|
+
placed = [...placed].sort((a, b) => made.get(b).score - made.get(a).score
|
|
335
|
+
|| ((0, orchestrator_1.sessionDateMs)(made.get(b).session_date) || 0) - ((0, orchestrator_1.sessionDateMs)(made.get(a).session_date) || 0)
|
|
336
|
+
|| at.get(a) - at.get(b));
|
|
337
|
+
}
|
|
338
|
+
const out = [];
|
|
339
|
+
let next = 0;
|
|
340
|
+
laid.forEach((hit, index) => {
|
|
341
|
+
const key = keyOf(hit);
|
|
342
|
+
if (key === null)
|
|
343
|
+
out.push(hit);
|
|
344
|
+
else if (slots.has(index) && made.get(key) !== null)
|
|
345
|
+
out.push(made.get(placed[next++]));
|
|
346
|
+
});
|
|
347
|
+
const dated = out.map(hit => (chunk(hit) && hit.session_date && !/Timestamp:/i.test(hit.text)
|
|
421
348
|
? { ...hit, text: `[Session date: ${hit.session_date}]\n${hit.text}` }
|
|
422
349
|
: hit));
|
|
423
350
|
// RENOR_READER_DURATION (default on; `0` switches it off): one line of dates the user wrote, first, for a "how many days between" question (questionSpan.ts).
|
|
424
351
|
// It reads the chunks as they were found: joined, a turn's continuation would sit under the speaker before it.
|
|
425
352
|
// RENOR_READER_EVENTS (default on; `0` switches it off) adds event lines for an order or a date question; its gate leaves a duration question alone, so at most one of the two lines is added.
|
|
426
353
|
// RENOR_READER_TIMELINE (default off): a current-value timeline for a "what is it now" question; a duration or an order question is left alone.
|
|
427
|
-
|
|
354
|
+
// Each such line comes first, outside the order rankedBy names, as the evidence hit does. The event lines too read the
|
|
355
|
+
// conversations as the page found them: a session that came as its header alone is no hit, but its turns are still read.
|
|
356
|
+
return {
|
|
357
|
+
hits: withCurrentValueTimeline(withEventLines((0, questionSpan_1.withQuestionSpan)(dated, opts.query, { source: hits }), hits.filter(chunk), opts), opts.query),
|
|
358
|
+
byRelevance,
|
|
359
|
+
};
|
|
428
360
|
}
|
|
429
|
-
/** The event lines, as the first hit (reason "events"), when the flag is on and the question asks for an order or a date. */
|
|
430
|
-
function withEventLines(hits,
|
|
361
|
+
/** The event lines, as the first hit (reason "events"), when the flag is on and the question asks for an order or a date. `sources` are the conversation chunks they read. */
|
|
362
|
+
function withEventLines(hits, sources, opts) {
|
|
431
363
|
if (!(0, readerEvents_1.readerEventsEnabled)() || opts.query === undefined || opts.turnsOf === undefined || opts.query.trim() === '')
|
|
432
364
|
return hits;
|
|
433
|
-
const text = (0, readerEvents_1.eventLines)(
|
|
365
|
+
const text = (0, readerEvents_1.eventLines)(sources, opts.query, opts.turnsOf, { scoreTurns: opts.scoreTurns });
|
|
434
366
|
if (text === null)
|
|
435
367
|
return hits;
|
|
436
368
|
return [{ notePath: '', text, score: 0, reason: 'events' }, ...hits];
|
|
437
369
|
}
|
|
438
|
-
/**
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
const
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
}
|
|
455
|
-
if (placed.has(key))
|
|
456
|
-
continue;
|
|
457
|
-
placed.add(key);
|
|
458
|
-
out.push(...groups.get(key).sort((a, b) => (a.chunkId ?? 0) - (b.chunkId ?? 0)));
|
|
459
|
-
}
|
|
460
|
-
return out;
|
|
461
|
-
}
|
|
462
|
-
/** Neighbouring hits of one note and date become one: the texts in order, the score and reason of the best match. */
|
|
463
|
-
function mergeRuns(hits, chunk) {
|
|
464
|
-
const out = [];
|
|
465
|
-
let i = 0;
|
|
466
|
-
while (i < hits.length) {
|
|
467
|
-
const first = hits[i];
|
|
468
|
-
let j = i + 1;
|
|
469
|
-
if (chunk(first))
|
|
470
|
-
while (j < hits.length && chunk(hits[j]) && hits[j].notePath === first.notePath && hits[j].session_date === first.session_date)
|
|
471
|
-
j++;
|
|
472
|
-
const run = hits.slice(i, j);
|
|
473
|
-
if (run.length === 1)
|
|
474
|
-
out.push(first);
|
|
475
|
-
else {
|
|
476
|
-
const best = run.reduce((a, b) => (b.score > a.score ? b : a));
|
|
477
|
-
const similarities = run.flatMap(h => (typeof h.similarity === 'number' ? [h.similarity] : []));
|
|
478
|
-
out.push({
|
|
479
|
-
...first,
|
|
480
|
-
text: run.map(h => h.text).join('\n\n'),
|
|
481
|
-
score: best.score,
|
|
482
|
-
reason: best.reason,
|
|
483
|
-
...(similarities.length > 0 ? { similarity: Math.max(...similarities) } : {}),
|
|
484
|
-
});
|
|
485
|
-
}
|
|
486
|
-
i = j;
|
|
370
|
+
/**
|
|
371
|
+
* One conversation's hit: its header first when it came, then its turns in the conversation's own order, with the best
|
|
372
|
+
* score and reason of its chunks. A session that came as a header and nothing else is no hit. Over the cap, every chunk the
|
|
373
|
+
* query matched stays and the statements the session expansion added are taken in the order they came, as many as the cap leaves room for.
|
|
374
|
+
*/
|
|
375
|
+
function blockHit(block, cap) {
|
|
376
|
+
if (block.body.length === 0)
|
|
377
|
+
return null;
|
|
378
|
+
const byPlace = (a, b) => (a.chunkId ?? 0) - (b.chunkId ?? 0);
|
|
379
|
+
let body = block.body;
|
|
380
|
+
if (cap > 0 && body.length > cap) {
|
|
381
|
+
// What the query matched always stays; the cap only limits the statements the session expansion added.
|
|
382
|
+
const expanded = body.filter(h => h.reason === orchestrator_1.SESSION_EXPAND_REASON);
|
|
383
|
+
const room = Math.max(0, cap - (body.length - expanded.length));
|
|
384
|
+
const kept = new Set([...body.filter(h => h.reason !== orchestrator_1.SESSION_EXPAND_REASON), ...expanded.slice(0, room)]);
|
|
385
|
+
body = body.filter(h => kept.has(h));
|
|
487
386
|
}
|
|
488
|
-
|
|
387
|
+
const run = [...block.header, ...body].sort(byPlace);
|
|
388
|
+
if (run.length === 1)
|
|
389
|
+
return run[0];
|
|
390
|
+
const best = run.reduce((a, b) => (b.score > a.score ? b : a));
|
|
391
|
+
const similarities = run.flatMap(h => (typeof h.similarity === 'number' ? [h.similarity] : []));
|
|
392
|
+
return {
|
|
393
|
+
...run[0],
|
|
394
|
+
text: run.map(h => h.text).join('\n\n'),
|
|
395
|
+
score: best.score,
|
|
396
|
+
reason: best.reason,
|
|
397
|
+
...(similarities.length > 0 ? { similarity: Math.max(...similarities) } : {}),
|
|
398
|
+
};
|
|
489
399
|
}
|
|
490
400
|
/**
|
|
491
401
|
* The page search_memory shows, laid out for its reader when RENOR_READER_LAYOUT is on (the chunk ids the layout needed
|
|
492
|
-
* leave with it); otherwise the page as it was. `
|
|
402
|
+
* leave with it); otherwise the page as it was. `rankedBy` is the key the returned page is in order of. `enabled` is the
|
|
403
|
+
* answer for this query (readerLayoutEnabledFor).
|
|
493
404
|
*/
|
|
494
|
-
function
|
|
405
|
+
function readerLayoutPage(rankedBy, hits, isLedger, events = {}, enabled = readerLayoutEnabled()) {
|
|
495
406
|
if (!enabled)
|
|
496
|
-
return hits;
|
|
407
|
+
return { hits, rankedBy };
|
|
497
408
|
// A bare string is the question alone (the duration line's form); the object also carries what the event lines read.
|
|
498
409
|
const input = typeof events === 'string' ? { query: events } : events;
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
410
|
+
const laid = layoutPage(hits, { rankedBy, isLedger, ...input });
|
|
411
|
+
return {
|
|
412
|
+
hits: laid.hits.map(hit => {
|
|
413
|
+
const { chunkId: _chunkId, ...rest } = hit;
|
|
414
|
+
return rest;
|
|
415
|
+
}),
|
|
416
|
+
rankedBy: laid.byRelevance ? 'score' : rankedBy,
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
/** The hits of readerLayoutPage alone. */
|
|
420
|
+
function readerLayoutOf(rankedBy, hits, isLedger, events = {}, enabled = readerLayoutEnabled()) {
|
|
421
|
+
return readerLayoutPage(rankedBy, hits, isLedger, events, enabled).hits;
|
|
503
422
|
}
|
|
@@ -7,7 +7,7 @@ exports.RouterCache = exports.ROUTER_CACHE_SCHEMA_VERSION = void 0;
|
|
|
7
7
|
const node_fs_1 = __importDefault(require("node:fs"));
|
|
8
8
|
const node_crypto_1 = __importDefault(require("node:crypto"));
|
|
9
9
|
const node_path_1 = __importDefault(require("node:path"));
|
|
10
|
-
const
|
|
10
|
+
const sqlite_1 = __importDefault(require("../db/sqlite"));
|
|
11
11
|
/**
|
|
12
12
|
* Content-addressed cache for the session router (RENOR_SESSION_ROUTER, src/router/sessionRouter.ts): the
|
|
13
13
|
* per-note summaries the router reads, and the router's own answers.
|
|
@@ -34,7 +34,7 @@ class RouterCache {
|
|
|
34
34
|
touchRouteStmt;
|
|
35
35
|
constructor(dbPath) {
|
|
36
36
|
node_fs_1.default.mkdirSync(node_path_1.default.dirname(dbPath), { recursive: true });
|
|
37
|
-
this.db = new
|
|
37
|
+
this.db = new sqlite_1.default(dbPath);
|
|
38
38
|
this.db.pragma('journal_mode = WAL');
|
|
39
39
|
this.db.pragma('busy_timeout = 10000');
|
|
40
40
|
this.db.exec(`
|