@edihasaj/recall 2.0.11 → 2.0.12
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/README.md +8 -1
- package/dist/{chunk-NRBUIOXH.js → chunk-2ZZ2A636.js} +414 -148
- package/dist/chunk-2ZZ2A636.js.map +1 -0
- package/dist/{chunk-UWWUH2WI.js → chunk-7CJRDV4G.js} +2 -2
- package/dist/{chunk-WZOHW5TL.js → chunk-ARNICYOL.js} +2 -2
- package/dist/{chunk-WZOHW5TL.js.map → chunk-ARNICYOL.js.map} +1 -1
- package/dist/{chunk-BB56EBUB.js → chunk-B7UC56WN.js} +25 -3
- package/dist/{chunk-BB56EBUB.js.map → chunk-B7UC56WN.js.map} +1 -1
- package/dist/{chunk-OFVI5NTJ.js → chunk-CX2IMCMJ.js} +3 -3
- package/dist/{chunk-TKI5MM35.js → chunk-DB23X3KP.js} +9 -9
- package/dist/{chunk-QTD2CINM.js → chunk-E47AHOCU.js} +2 -2
- package/dist/{chunk-FPD6Z63C.js → chunk-EA4S57YN.js} +2 -2
- package/dist/{chunk-DVG3F533.js → chunk-GJNLPH5L.js} +4 -4
- package/dist/{chunk-TXTUPXMI.js → chunk-GWRKFPZU.js} +5 -5
- package/dist/{chunk-NSJ5E7UL.js → chunk-PKCKAOPM.js} +7 -7
- package/dist/{chunk-4OFTCJ3A.js → chunk-R2DYQD7T.js} +13 -13
- package/dist/{chunk-7MSBS6FR.js → chunk-S332RJUU.js} +2 -2
- package/dist/{chunk-I5SACSGQ.js → chunk-UMMXIUS7.js} +5 -5
- package/dist/{chunk-T46O2YNU.js → chunk-VCFG46VR.js} +3 -3
- package/dist/{chunk-XITENPDF.js → chunk-W3BOHDM3.js} +351 -22
- package/dist/chunk-W3BOHDM3.js.map +1 -0
- package/dist/{chunk-6PJ6ULQW.js → chunk-WSELVF32.js} +7 -7
- package/dist/{chunk-LP3Z5MGU.js → chunk-YKEYX6CH.js} +3 -3
- package/dist/{cleanup-43KCWJTT.js → cleanup-WFDLQAZ6.js} +11 -11
- package/dist/cli.js +36 -36
- package/dist/{codex-trust-RWQPEUNN.js → codex-trust-3WSCTMBG.js} +4 -4
- package/dist/daemon.js +18 -18
- package/dist/dispatcher-MFTS5LC6.js +22 -0
- package/dist/{embeddings-OKGDZ2G7.js → embeddings-7Z6XPE2L.js} +5 -5
- package/dist/ingest-NBPKQQS5.js +20 -0
- package/dist/{keychain-BWP7257A.js → keychain-W5QUEHH3.js} +3 -3
- package/dist/mcp.js +15 -15
- package/dist/{memory-value-ALNH7ORV.js → memory-value-JIZ5FHIS.js} +11 -11
- package/dist/{provenance-IXJ3XYBP.js → provenance-T55DY5YL.js} +9 -9
- package/dist/quality-NBJK53WG.js +25 -0
- package/dist/retrieval-EODXQIZG.js +15 -0
- package/dist/{store-AADECMHC.js → store-36I5AX3E.js} +4 -4
- package/dist/sync-server.js +2 -2
- package/dist/{tasks-GOVBFGEJ.js → tasks-OOUOTOYU.js} +11 -11
- package/dist/{usage-PDPAFEAU.js → usage-UGYR77FW.js} +4 -4
- package/drizzle/0013_damp_zarda.sql +22 -0
- package/drizzle/meta/0013_snapshot.json +2874 -0
- package/drizzle/meta/_journal.json +7 -0
- package/package.json +1 -1
- package/dist/chunk-NRBUIOXH.js.map +0 -1
- package/dist/chunk-XITENPDF.js.map +0 -1
- package/dist/dispatcher-NUODV2I2.js +0 -22
- package/dist/ingest-KUO4E5L5.js +0 -20
- package/dist/quality-Z74GVWJS.js +0 -25
- package/dist/retrieval-VUAMO7AC.js +0 -15
- /package/dist/{chunk-UWWUH2WI.js.map → chunk-7CJRDV4G.js.map} +0 -0
- /package/dist/{chunk-OFVI5NTJ.js.map → chunk-CX2IMCMJ.js.map} +0 -0
- /package/dist/{chunk-TKI5MM35.js.map → chunk-DB23X3KP.js.map} +0 -0
- /package/dist/{chunk-QTD2CINM.js.map → chunk-E47AHOCU.js.map} +0 -0
- /package/dist/{chunk-FPD6Z63C.js.map → chunk-EA4S57YN.js.map} +0 -0
- /package/dist/{chunk-DVG3F533.js.map → chunk-GJNLPH5L.js.map} +0 -0
- /package/dist/{chunk-TXTUPXMI.js.map → chunk-GWRKFPZU.js.map} +0 -0
- /package/dist/{chunk-NSJ5E7UL.js.map → chunk-PKCKAOPM.js.map} +0 -0
- /package/dist/{chunk-4OFTCJ3A.js.map → chunk-R2DYQD7T.js.map} +0 -0
- /package/dist/{chunk-7MSBS6FR.js.map → chunk-S332RJUU.js.map} +0 -0
- /package/dist/{chunk-I5SACSGQ.js.map → chunk-UMMXIUS7.js.map} +0 -0
- /package/dist/{chunk-T46O2YNU.js.map → chunk-VCFG46VR.js.map} +0 -0
- /package/dist/{chunk-6PJ6ULQW.js.map → chunk-WSELVF32.js.map} +0 -0
- /package/dist/{chunk-LP3Z5MGU.js.map → chunk-YKEYX6CH.js.map} +0 -0
- /package/dist/{cleanup-43KCWJTT.js.map → cleanup-WFDLQAZ6.js.map} +0 -0
- /package/dist/{codex-trust-RWQPEUNN.js.map → codex-trust-3WSCTMBG.js.map} +0 -0
- /package/dist/{dispatcher-NUODV2I2.js.map → dispatcher-MFTS5LC6.js.map} +0 -0
- /package/dist/{embeddings-OKGDZ2G7.js.map → embeddings-7Z6XPE2L.js.map} +0 -0
- /package/dist/{ingest-KUO4E5L5.js.map → ingest-NBPKQQS5.js.map} +0 -0
- /package/dist/{keychain-BWP7257A.js.map → keychain-W5QUEHH3.js.map} +0 -0
- /package/dist/{memory-value-ALNH7ORV.js.map → memory-value-JIZ5FHIS.js.map} +0 -0
- /package/dist/{provenance-IXJ3XYBP.js.map → provenance-T55DY5YL.js.map} +0 -0
- /package/dist/{quality-Z74GVWJS.js.map → quality-NBJK53WG.js.map} +0 -0
- /package/dist/{retrieval-VUAMO7AC.js.map → retrieval-EODXQIZG.js.map} +0 -0
- /package/dist/{store-AADECMHC.js.map → store-36I5AX3E.js.map} +0 -0
- /package/dist/{tasks-GOVBFGEJ.js.map → tasks-OOUOTOYU.js.map} +0 -0
- /package/dist/{usage-PDPAFEAU.js.map → usage-UGYR77FW.js.map} +0 -0
|
@@ -9,16 +9,17 @@ import {
|
|
|
9
9
|
processCorrection,
|
|
10
10
|
redactSensitiveValue,
|
|
11
11
|
seedScannedConfidence
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-DB23X3KP.js";
|
|
13
13
|
import {
|
|
14
14
|
recordInjectionValueEvents,
|
|
15
15
|
recordMemoryInjections,
|
|
16
16
|
recordOutcomeValueEvent,
|
|
17
17
|
resolveMemoryInjectionOutcome
|
|
18
|
-
} from "./chunk-
|
|
18
|
+
} from "./chunk-WSELVF32.js";
|
|
19
19
|
import {
|
|
20
|
+
matchTokens,
|
|
20
21
|
textMatchScore
|
|
21
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-EA4S57YN.js";
|
|
22
23
|
import {
|
|
23
24
|
activityEventDedupeKey,
|
|
24
25
|
confirmMemory,
|
|
@@ -38,11 +39,11 @@ import {
|
|
|
38
39
|
rejectMemory,
|
|
39
40
|
setMemoryNote,
|
|
40
41
|
statusFromConfidence
|
|
41
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-PKCKAOPM.js";
|
|
42
43
|
import {
|
|
43
44
|
asc,
|
|
44
45
|
desc
|
|
45
|
-
} from "./chunk-
|
|
46
|
+
} from "./chunk-VCFG46VR.js";
|
|
46
47
|
import {
|
|
47
48
|
BACKGROUND_INDEX_BATCH_SIZE,
|
|
48
49
|
CONFIDENCE,
|
|
@@ -67,11 +68,11 @@ import {
|
|
|
67
68
|
resolveProvider,
|
|
68
69
|
retrievalText,
|
|
69
70
|
tagActivitySource
|
|
70
|
-
} from "./chunk-
|
|
71
|
+
} from "./chunk-GJNLPH5L.js";
|
|
71
72
|
import {
|
|
72
73
|
hasProviderConfigured,
|
|
73
74
|
init_keychain
|
|
74
|
-
} from "./chunk-
|
|
75
|
+
} from "./chunk-S332RJUU.js";
|
|
75
76
|
import {
|
|
76
77
|
Column,
|
|
77
78
|
Columns,
|
|
@@ -136,10 +137,10 @@ import {
|
|
|
136
137
|
policyRules,
|
|
137
138
|
schema_exports,
|
|
138
139
|
sql
|
|
139
|
-
} from "./chunk-
|
|
140
|
+
} from "./chunk-B7UC56WN.js";
|
|
140
141
|
import {
|
|
141
142
|
init_define_RECALL_BUILD_INFO
|
|
142
|
-
} from "./chunk-
|
|
143
|
+
} from "./chunk-ARNICYOL.js";
|
|
143
144
|
|
|
144
145
|
// src/db/client.ts
|
|
145
146
|
init_define_RECALL_BUILD_INFO();
|
|
@@ -3643,7 +3644,7 @@ import { join, dirname } from "path";
|
|
|
3643
3644
|
import { mkdirSync, existsSync, rmSync, statSync } from "fs";
|
|
3644
3645
|
import { fileURLToPath } from "url";
|
|
3645
3646
|
var __dirname = dirname(fileURLToPath(import.meta.url));
|
|
3646
|
-
var RECALL_DB_USER_VERSION =
|
|
3647
|
+
var RECALL_DB_USER_VERSION = 14;
|
|
3647
3648
|
function getDbPath() {
|
|
3648
3649
|
const dataDir = process.env.RECALL_DATA_DIR ?? join(
|
|
3649
3650
|
process.env.HOME ?? process.env.USERPROFILE ?? ".",
|
|
@@ -5597,6 +5598,306 @@ function memoryRepoAliases(db, repo) {
|
|
|
5597
5598
|
return [.../* @__PURE__ */ new Set([repo, basename2, qualified[0]])];
|
|
5598
5599
|
}
|
|
5599
5600
|
|
|
5601
|
+
// src/history/evidence.ts
|
|
5602
|
+
init_define_RECALL_BUILD_INFO();
|
|
5603
|
+
var ELLIPSIS = "\u2026";
|
|
5604
|
+
var GENERIC_QUERY_TOKENS = /* @__PURE__ */ new Set([
|
|
5605
|
+
"am",
|
|
5606
|
+
"are",
|
|
5607
|
+
"can",
|
|
5608
|
+
"could",
|
|
5609
|
+
"did",
|
|
5610
|
+
"doe",
|
|
5611
|
+
"does",
|
|
5612
|
+
"had",
|
|
5613
|
+
"has",
|
|
5614
|
+
"have",
|
|
5615
|
+
"how",
|
|
5616
|
+
"me",
|
|
5617
|
+
"mine",
|
|
5618
|
+
"my",
|
|
5619
|
+
"our",
|
|
5620
|
+
"please",
|
|
5621
|
+
"should",
|
|
5622
|
+
"tell",
|
|
5623
|
+
"the",
|
|
5624
|
+
"us",
|
|
5625
|
+
"what",
|
|
5626
|
+
"when",
|
|
5627
|
+
"where",
|
|
5628
|
+
"which",
|
|
5629
|
+
"who",
|
|
5630
|
+
"why",
|
|
5631
|
+
"was",
|
|
5632
|
+
"were",
|
|
5633
|
+
"will",
|
|
5634
|
+
"would",
|
|
5635
|
+
"you",
|
|
5636
|
+
"your",
|
|
5637
|
+
"yours"
|
|
5638
|
+
]);
|
|
5639
|
+
function preferredEvidenceSpeaker(query) {
|
|
5640
|
+
const normalized = query.toLowerCase();
|
|
5641
|
+
const assistantPastVerb = "(?:recommended|suggested|advised|told|said|proposed|provided|listed|gave|shared|mentioned|offered)";
|
|
5642
|
+
const assistantBaseVerb = "(?:recommend|suggest|advise|tell|say|propose|provide|list|give|share|mention|offer)";
|
|
5643
|
+
const recallsAssistantAction = new RegExp(
|
|
5644
|
+
`\\b(?:what|which|who|where|when|how)\\b[\\s\\S]{0,80}\\b(?:did|have|had)\\s+you\\b[\\s\\S]{0,80}\\b${assistantBaseVerb}\\w*\\b`
|
|
5645
|
+
).test(normalized);
|
|
5646
|
+
const explicitPastAttribution = new RegExp(
|
|
5647
|
+
`\\byou\\s+(?:(?:have|had)\\s+)?${assistantPastVerb}\\b`
|
|
5648
|
+
).test(normalized) || new RegExp(`\\b(?:have|had)\\s+you\\s+${assistantPastVerb}\\b`).test(normalized);
|
|
5649
|
+
const asksForPastAdvice = /\byour\s+(?:earlier|previous|prior|past)\s+(?:advice|recommendation|suggestion|guidance|answer|response)\b/.test(normalized);
|
|
5650
|
+
const recallsNamedAdvice = /\b(?:earlier|previous|prior|past)\s+(?:advice|recommendation|suggestion|guidance)\b[\s\S]{0,80}\byou\b/.test(normalized);
|
|
5651
|
+
return recallsAssistantAction || explicitPastAttribution || asksForPastAdvice || recallsNamedAdvice ? "assistant" : "user";
|
|
5652
|
+
}
|
|
5653
|
+
function renderEvidenceSources(sources, options) {
|
|
5654
|
+
const perSourceChars = validateOptions(options);
|
|
5655
|
+
if (sources.length === 0) return { text: "", sources: [] };
|
|
5656
|
+
const states = sources.map((source, sourceIndex) => ({
|
|
5657
|
+
source,
|
|
5658
|
+
sourceIndex,
|
|
5659
|
+
date: parseEvidenceDate(source.observed_at)
|
|
5660
|
+
}));
|
|
5661
|
+
const metadata = sources.map((source, sourceIndex) => ({
|
|
5662
|
+
source_index: sourceIndex,
|
|
5663
|
+
ranges: [],
|
|
5664
|
+
full_chars: source.text.length,
|
|
5665
|
+
used_chars: 0,
|
|
5666
|
+
truncated: source.text.length > 0
|
|
5667
|
+
}));
|
|
5668
|
+
const candidates = states.filter((state) => state.source.text.length > 0).map((state) => makeCandidate(state, options.query, perSourceChars, options.preferred_speaker)).filter((candidate) => candidate !== void 0);
|
|
5669
|
+
if (candidates.length === 0) return { text: "", sources: metadata };
|
|
5670
|
+
const included = selectCandidates(candidates, options.max_chars);
|
|
5671
|
+
if (included.length === 0) {
|
|
5672
|
+
throw new RangeError("max_chars is too small to render an evidence label and a complete source unit");
|
|
5673
|
+
}
|
|
5674
|
+
const ordered = [...included].sort((left, right) => compareSourceState(left.state, right.state));
|
|
5675
|
+
const text = renderCandidates(ordered);
|
|
5676
|
+
for (const candidate of ordered) {
|
|
5677
|
+
const metadataEntry = metadata[candidate.state.sourceIndex];
|
|
5678
|
+
metadataEntry.ranges = candidate.ranges;
|
|
5679
|
+
metadataEntry.used_chars = candidate.ranges.reduce((total, range) => total + range.end - range.start, 0);
|
|
5680
|
+
metadataEntry.truncated = !isWholeSource(candidate.ranges, candidate.state.source.text.length);
|
|
5681
|
+
}
|
|
5682
|
+
if (text.length > options.max_chars) {
|
|
5683
|
+
throw new Error("Evidence renderer exceeded its character budget");
|
|
5684
|
+
}
|
|
5685
|
+
return { text, sources: metadata };
|
|
5686
|
+
}
|
|
5687
|
+
function validateOptions(options) {
|
|
5688
|
+
if (!Number.isSafeInteger(options.max_chars) || options.max_chars <= 0) {
|
|
5689
|
+
throw new RangeError("max_chars must be a positive safe integer");
|
|
5690
|
+
}
|
|
5691
|
+
if (options.per_source_chars !== void 0 && (!Number.isSafeInteger(options.per_source_chars) || options.per_source_chars <= 0)) {
|
|
5692
|
+
throw new RangeError("per_source_chars must be a positive safe integer");
|
|
5693
|
+
}
|
|
5694
|
+
return options.per_source_chars ?? options.max_chars;
|
|
5695
|
+
}
|
|
5696
|
+
function compareSourceState(left, right) {
|
|
5697
|
+
if (left.date && right.date) {
|
|
5698
|
+
return left.date.time - right.date.time || left.sourceIndex - right.sourceIndex;
|
|
5699
|
+
}
|
|
5700
|
+
if (left.date) return -1;
|
|
5701
|
+
if (right.date) return 1;
|
|
5702
|
+
return left.sourceIndex - right.sourceIndex;
|
|
5703
|
+
}
|
|
5704
|
+
function headerFor(state, number) {
|
|
5705
|
+
const title = `## Memory ${number}
|
|
5706
|
+
`;
|
|
5707
|
+
if (!state.date) return title;
|
|
5708
|
+
const label = state.source.date_kind === "record_updated" ? "Record updated" : "Observed";
|
|
5709
|
+
return `${title}${label}: ${state.date.text}
|
|
5710
|
+
`;
|
|
5711
|
+
}
|
|
5712
|
+
function makeCandidate(state, query, sourceCap, preferredSpeaker) {
|
|
5713
|
+
const ranges = chooseSemanticRanges(state.source.text, query, sourceCap, preferredSpeaker);
|
|
5714
|
+
if (ranges.length === 0) return void 0;
|
|
5715
|
+
return { state, ranges, text: renderRanges(state.source.text, ranges) };
|
|
5716
|
+
}
|
|
5717
|
+
function selectCandidates(candidates, maxChars) {
|
|
5718
|
+
const included = [];
|
|
5719
|
+
const priority = [...candidates].sort(
|
|
5720
|
+
(left, right) => left.text.length - right.text.length || left.state.sourceIndex - right.state.sourceIndex
|
|
5721
|
+
);
|
|
5722
|
+
for (const candidate of priority) {
|
|
5723
|
+
const prospective = [...included, candidate].sort(
|
|
5724
|
+
(left, right) => compareSourceState(left.state, right.state)
|
|
5725
|
+
);
|
|
5726
|
+
if (renderCandidates(prospective).length <= maxChars) included.push(candidate);
|
|
5727
|
+
}
|
|
5728
|
+
return included;
|
|
5729
|
+
}
|
|
5730
|
+
function renderCandidates(candidates) {
|
|
5731
|
+
return candidates.map(
|
|
5732
|
+
(candidate, index) => `${headerFor(candidate.state, index + 1)}${candidate.text}`
|
|
5733
|
+
).join("\n\n");
|
|
5734
|
+
}
|
|
5735
|
+
function chooseSemanticRanges(text, query, charCap, preferredSpeaker) {
|
|
5736
|
+
if (text.length <= charCap) return [{ start: 0, end: text.length }];
|
|
5737
|
+
const queryTokens = informativeQueryTokens(query ?? "");
|
|
5738
|
+
const units = semanticUnits(text, queryTokens);
|
|
5739
|
+
const ranked = units.filter((unit) => unit.score > 0).sort((left, right) => speakerRank(left, preferredSpeaker) - speakerRank(right, preferredSpeaker) || right.score - left.score || right.index - left.index);
|
|
5740
|
+
if (ranked.length === 0) {
|
|
5741
|
+
for (const unit of units) {
|
|
5742
|
+
if (fitsIndexes(/* @__PURE__ */ new Set(), [...unit.context, unit.index], units, charCap)) {
|
|
5743
|
+
return mergeRanges([...unit.context, unit.index].map((candidate) => units[candidate].range));
|
|
5744
|
+
}
|
|
5745
|
+
}
|
|
5746
|
+
return [];
|
|
5747
|
+
}
|
|
5748
|
+
const selected = /* @__PURE__ */ new Set();
|
|
5749
|
+
const primary = /* @__PURE__ */ new Set();
|
|
5750
|
+
for (const unit of ranked) {
|
|
5751
|
+
if (fitsIndexes(selected, [...unit.context, unit.index], units, charCap)) {
|
|
5752
|
+
for (const index of unit.context) selected.add(index);
|
|
5753
|
+
selected.add(unit.index);
|
|
5754
|
+
primary.add(unit.index);
|
|
5755
|
+
}
|
|
5756
|
+
}
|
|
5757
|
+
for (const index of [...primary].sort((left, right) => left - right)) {
|
|
5758
|
+
for (const adjacent of [index - 1, index + 1]) {
|
|
5759
|
+
const adjacentUnit = units[adjacent];
|
|
5760
|
+
if (!adjacentUnit || selected.has(adjacent)) continue;
|
|
5761
|
+
if (fitsIndexes(selected, [...adjacentUnit.context, adjacent], units, charCap)) {
|
|
5762
|
+
for (const context of adjacentUnit.context) selected.add(context);
|
|
5763
|
+
selected.add(adjacent);
|
|
5764
|
+
}
|
|
5765
|
+
}
|
|
5766
|
+
}
|
|
5767
|
+
return mergeRanges([...selected].map((index) => units[index].range));
|
|
5768
|
+
}
|
|
5769
|
+
function semanticUnits(text, queryTokens) {
|
|
5770
|
+
const ranges = [];
|
|
5771
|
+
let lineStart = 0;
|
|
5772
|
+
while (lineStart < text.length) {
|
|
5773
|
+
const newline = text.indexOf("\n", lineStart);
|
|
5774
|
+
const lineEnd = newline === -1 ? text.length : newline;
|
|
5775
|
+
if (lineStart < lineEnd) {
|
|
5776
|
+
ranges.push({ start: lineStart, end: lineEnd });
|
|
5777
|
+
}
|
|
5778
|
+
lineStart = newline === -1 ? text.length : newline + 1;
|
|
5779
|
+
}
|
|
5780
|
+
const windows = ranges.length > 0 ? ranges : [{ start: 0, end: text.length }];
|
|
5781
|
+
const units = [];
|
|
5782
|
+
let activeRole = -1;
|
|
5783
|
+
let activeSpeaker;
|
|
5784
|
+
let activeHeading = -1;
|
|
5785
|
+
let previousNegatingScope = -1;
|
|
5786
|
+
for (const [index, range] of windows.entries()) {
|
|
5787
|
+
const unitText = text.slice(range.start, range.end).trim();
|
|
5788
|
+
const explicitSpeaker = roleSpeaker(unitText);
|
|
5789
|
+
const isRole = explicitSpeaker !== void 0;
|
|
5790
|
+
const context = isRole ? [] : [activeRole, activeHeading, previousNegatingScope].flatMap(
|
|
5791
|
+
(candidate) => candidate >= 0 ? [candidate, ...units[candidate].context] : []
|
|
5792
|
+
).filter((candidate) => candidate !== index);
|
|
5793
|
+
units.push({
|
|
5794
|
+
index,
|
|
5795
|
+
range,
|
|
5796
|
+
score: overlapScore(unitText, queryTokens),
|
|
5797
|
+
context: [...new Set(context)],
|
|
5798
|
+
speaker: explicitSpeaker ?? activeSpeaker
|
|
5799
|
+
});
|
|
5800
|
+
if (isRole) {
|
|
5801
|
+
activeRole = index;
|
|
5802
|
+
activeSpeaker = explicitSpeaker;
|
|
5803
|
+
activeHeading = -1;
|
|
5804
|
+
} else if (unitText.endsWith(":")) {
|
|
5805
|
+
activeHeading = index;
|
|
5806
|
+
}
|
|
5807
|
+
previousNegatingScope = isNegatingScope(unitText) ? index : -1;
|
|
5808
|
+
}
|
|
5809
|
+
return units;
|
|
5810
|
+
}
|
|
5811
|
+
function roleSpeaker(text) {
|
|
5812
|
+
return /^(user|assistant|system|tool):\s*/i.exec(text)?.[1]?.toLowerCase();
|
|
5813
|
+
}
|
|
5814
|
+
function isNegatingScope(text) {
|
|
5815
|
+
return /\b(?:not|never|reject(?:ed|ion)?|avoid|deprecated|obsolete|do\s+not|don['’]?t)\b/i.test(text);
|
|
5816
|
+
}
|
|
5817
|
+
function fitsIndexes(selected, additions, units, charCap) {
|
|
5818
|
+
const ranges = mergeRanges([
|
|
5819
|
+
...[...selected].map((index) => units[index].range),
|
|
5820
|
+
...additions.map((index) => units[index].range)
|
|
5821
|
+
]);
|
|
5822
|
+
return ranges.reduce((total, range) => total + range.end - range.start, 0) <= charCap;
|
|
5823
|
+
}
|
|
5824
|
+
function overlapScore(text, queryTokens) {
|
|
5825
|
+
if (queryTokens.size === 0) return 0;
|
|
5826
|
+
const tokens = new Set(matchTokens(text));
|
|
5827
|
+
let overlap = 0;
|
|
5828
|
+
for (const token of tokens) if (queryTokens.has(token)) overlap++;
|
|
5829
|
+
return overlap * 1e3 + (overlap > 0 ? Math.min(tokens.size, 999) : 0);
|
|
5830
|
+
}
|
|
5831
|
+
function informativeQueryTokens(query) {
|
|
5832
|
+
return new Set(matchTokens(query).filter((token) => !GENERIC_QUERY_TOKENS.has(token)));
|
|
5833
|
+
}
|
|
5834
|
+
function speakerRank(unit, preferredSpeaker) {
|
|
5835
|
+
return preferredSpeaker && unit.speaker === preferredSpeaker ? 0 : 1;
|
|
5836
|
+
}
|
|
5837
|
+
function mergeRanges(ranges) {
|
|
5838
|
+
return [...ranges].sort((left, right) => left.start - right.start).reduce((merged, range) => {
|
|
5839
|
+
const previous = merged.at(-1);
|
|
5840
|
+
if (previous && range.start <= previous.end + 1) {
|
|
5841
|
+
previous.end = Math.max(previous.end, range.end);
|
|
5842
|
+
} else {
|
|
5843
|
+
merged.push({ ...range });
|
|
5844
|
+
}
|
|
5845
|
+
return merged;
|
|
5846
|
+
}, []);
|
|
5847
|
+
}
|
|
5848
|
+
function renderRanges(text, ranges) {
|
|
5849
|
+
return ranges.map((range, index) => {
|
|
5850
|
+
const prefix = range.start > 0 && index === 0 ? `${ELLIPSIS}
|
|
5851
|
+
` : "";
|
|
5852
|
+
const gap = index > 0 ? `
|
|
5853
|
+
${ELLIPSIS}
|
|
5854
|
+
` : "";
|
|
5855
|
+
const suffix = range.end < text.length && index === ranges.length - 1 ? `
|
|
5856
|
+
${ELLIPSIS}` : "";
|
|
5857
|
+
return `${gap}${prefix}${text.slice(range.start, range.end)}${suffix}`;
|
|
5858
|
+
}).join("");
|
|
5859
|
+
}
|
|
5860
|
+
function isWholeSource(ranges, length) {
|
|
5861
|
+
return ranges.length === 1 && ranges[0].start === 0 && ranges[0].end === length;
|
|
5862
|
+
}
|
|
5863
|
+
function parseEvidenceDate(value) {
|
|
5864
|
+
if (!value) return void 0;
|
|
5865
|
+
const match = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?(Z|[+-]\d{2}:\d{2}))?$/.exec(value);
|
|
5866
|
+
if (!match) return void 0;
|
|
5867
|
+
const [, year, month, day, hour, minute, second, , zone] = match;
|
|
5868
|
+
if (!isRealCalendarDate(Number(year), Number(month), Number(day))) return void 0;
|
|
5869
|
+
const dateTime = Date.parse(`${year}-${month}-${day}T00:00:00Z`);
|
|
5870
|
+
if (!Number.isFinite(dateTime)) return void 0;
|
|
5871
|
+
if (hour === void 0) return { text: value, time: dateTime };
|
|
5872
|
+
if (!zone || Number(hour) > 23 || Number(minute) > 59 || second !== void 0 && Number(second) > 59) {
|
|
5873
|
+
return void 0;
|
|
5874
|
+
}
|
|
5875
|
+
if (zone !== "Z") {
|
|
5876
|
+
const [offsetHour, offsetMinute] = zone.slice(1).split(":").map(Number);
|
|
5877
|
+
if (offsetHour > 23 || offsetMinute > 59) return void 0;
|
|
5878
|
+
}
|
|
5879
|
+
const time = Date.parse(value);
|
|
5880
|
+
return Number.isFinite(time) ? { text: value, time } : void 0;
|
|
5881
|
+
}
|
|
5882
|
+
function isRealCalendarDate(year, month, day) {
|
|
5883
|
+
if (month < 1 || month > 12 || day < 1) return false;
|
|
5884
|
+
const monthLengths = [
|
|
5885
|
+
31,
|
|
5886
|
+
year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0) ? 29 : 28,
|
|
5887
|
+
31,
|
|
5888
|
+
30,
|
|
5889
|
+
31,
|
|
5890
|
+
30,
|
|
5891
|
+
31,
|
|
5892
|
+
31,
|
|
5893
|
+
30,
|
|
5894
|
+
31,
|
|
5895
|
+
30,
|
|
5896
|
+
31
|
|
5897
|
+
];
|
|
5898
|
+
return day <= monthLengths[month - 1];
|
|
5899
|
+
}
|
|
5900
|
+
|
|
5600
5901
|
// src/compiler/context.ts
|
|
5601
5902
|
var DEFAULT_CONFIG = {
|
|
5602
5903
|
confidence_threshold: CONFIDENCE.ACTIVE_MIN,
|
|
@@ -5808,7 +6109,13 @@ async function compileContextHybrid(db, req) {
|
|
|
5808
6109
|
};
|
|
5809
6110
|
const normalizedQuery = req.query_text ? normalizeQueryForRetrieval(req.query_text) : "";
|
|
5810
6111
|
const effectiveQuery = normalizedQuery.length > 0 ? normalizedQuery : void 0;
|
|
5811
|
-
const
|
|
6112
|
+
const retrievedHistory = effectiveQuery ? await selectRelevantHistory(db, req.repo, effectiveQuery, config.max_history_snippets) : selectRepoHistory(db, req.repo, config.max_history_snippets);
|
|
6113
|
+
const omittedHistory = [];
|
|
6114
|
+
const selectedHistory = retrievedHistory.filter((snippet) => {
|
|
6115
|
+
if (!effectiveQuery || renderHistorySnippet(snippet, effectiveQuery)) return true;
|
|
6116
|
+
omittedHistory.push(snippet.id);
|
|
6117
|
+
return false;
|
|
6118
|
+
});
|
|
5812
6119
|
const repoMemories = memoryRepoAliases(db, req.repo).flatMap((repo) => queryMemories(db, { repo }));
|
|
5813
6120
|
const globalMemories = queryMemories(db, { scope: "global" });
|
|
5814
6121
|
const eligibleCandidate = (memory) => {
|
|
@@ -5843,14 +6150,16 @@ async function compileContextHybrid(db, req) {
|
|
|
5843
6150
|
config.confidence_threshold
|
|
5844
6151
|
);
|
|
5845
6152
|
if (passing.length === 0 && selectedHistory.length === 0) {
|
|
6153
|
+
const omissionText = renderPack([], req.repo, [], effectiveQuery, omittedHistory.length);
|
|
5846
6154
|
return {
|
|
5847
6155
|
confidence_threshold: config.confidence_threshold,
|
|
5848
6156
|
near_misses: hybridNearMisses,
|
|
5849
|
-
text:
|
|
6157
|
+
text: omissionText,
|
|
5850
6158
|
memories_included: [],
|
|
5851
6159
|
memories_dropped: dropped.map((m) => m.id),
|
|
5852
6160
|
history_included: [],
|
|
5853
|
-
|
|
6161
|
+
history_omitted: omittedHistory,
|
|
6162
|
+
token_estimate: Math.ceil(omissionText.length / 4)
|
|
5854
6163
|
};
|
|
5855
6164
|
}
|
|
5856
6165
|
const retrieval = effectiveQuery ? await hybridSearch(db, effectiveQuery, embeddingConfig, {
|
|
@@ -5934,7 +6243,7 @@ async function compileContextHybrid(db, req) {
|
|
|
5934
6243
|
if (memory.type === "gotcha") gotchaCount++;
|
|
5935
6244
|
}
|
|
5936
6245
|
if (selected.length === 0) {
|
|
5937
|
-
const historyOnlyText = renderPack([], req.repo, selectedHistory);
|
|
6246
|
+
const historyOnlyText = renderPack([], req.repo, selectedHistory, effectiveQuery, omittedHistory.length);
|
|
5938
6247
|
if (historyOnlyText) {
|
|
5939
6248
|
recordHistoryInjections(db, {
|
|
5940
6249
|
snippet_ids: selectedHistory.map((snippet) => snippet.id),
|
|
@@ -5948,6 +6257,7 @@ async function compileContextHybrid(db, req) {
|
|
|
5948
6257
|
memories_included: [],
|
|
5949
6258
|
memories_dropped: [...dropped, ...passing].map((m) => m.id),
|
|
5950
6259
|
history_included: selectedHistory.map((snippet) => snippet.id),
|
|
6260
|
+
history_omitted: omittedHistory,
|
|
5951
6261
|
token_estimate: Math.ceil(historyOnlyText.length / 4)
|
|
5952
6262
|
};
|
|
5953
6263
|
}
|
|
@@ -5958,13 +6268,14 @@ async function compileContextHybrid(db, req) {
|
|
|
5958
6268
|
memories_included: [],
|
|
5959
6269
|
memories_dropped: [...dropped, ...passing].map((m) => m.id),
|
|
5960
6270
|
history_included: [],
|
|
6271
|
+
history_omitted: omittedHistory,
|
|
5961
6272
|
token_estimate: 0
|
|
5962
6273
|
};
|
|
5963
6274
|
}
|
|
5964
|
-
while (selected.length > 1 && Math.ceil(renderPack(selected, req.repo, selectedHistory).length / 4) > config.token_budget) {
|
|
6275
|
+
while (selected.length > 1 && Math.ceil(renderPack(selected, req.repo, selectedHistory, effectiveQuery, omittedHistory.length).length / 4) > config.token_budget) {
|
|
5965
6276
|
selected.pop();
|
|
5966
6277
|
}
|
|
5967
|
-
const finalText = renderPack(selected, req.repo, selectedHistory);
|
|
6278
|
+
const finalText = renderPack(selected, req.repo, selectedHistory, effectiveQuery, omittedHistory.length);
|
|
5968
6279
|
const finalTokenEstimate = Math.ceil(finalText.length / 4);
|
|
5969
6280
|
recordMemoryInjections(db, {
|
|
5970
6281
|
memory_ids: selected.map((memory) => memory.id),
|
|
@@ -5992,11 +6303,12 @@ async function compileContextHybrid(db, req) {
|
|
|
5992
6303
|
...ranked.map((item) => item.memory).filter((memory) => !selected.includes(memory)).map((memory) => memory.id)
|
|
5993
6304
|
],
|
|
5994
6305
|
history_included: selectedHistory.map((snippet) => snippet.id),
|
|
6306
|
+
history_omitted: omittedHistory,
|
|
5995
6307
|
token_estimate: finalTokenEstimate
|
|
5996
6308
|
};
|
|
5997
6309
|
}
|
|
5998
|
-
function renderPack(items, repo, history = []) {
|
|
5999
|
-
if (items.length === 0 && history.length === 0) return "";
|
|
6310
|
+
function renderPack(items, repo, history = [], historyQuery, omittedHistoryCount = 0) {
|
|
6311
|
+
if (items.length === 0 && history.length === 0 && omittedHistoryCount === 0) return "";
|
|
6000
6312
|
const rules = items.filter((m) => m.type === "rule" || m.type === "decision");
|
|
6001
6313
|
const commands = items.filter((m) => m.type === "command");
|
|
6002
6314
|
const gotchas = items.filter(
|
|
@@ -6018,9 +6330,13 @@ function renderPack(items, repo, history = []) {
|
|
|
6018
6330
|
"## Gotchas\n" + gotchas.map(renderMemoryBullet).join("\n")
|
|
6019
6331
|
);
|
|
6020
6332
|
}
|
|
6021
|
-
if (history.length > 0) {
|
|
6333
|
+
if (history.length > 0 || omittedHistoryCount > 0) {
|
|
6334
|
+
const historyText = history.map((snippet) => renderHistorySnippet(snippet, historyQuery)).filter(Boolean);
|
|
6335
|
+
if (omittedHistoryCount > 0) {
|
|
6336
|
+
historyText.push(`[${omittedHistoryCount} matching history summaries omitted: no complete passage fit the excerpt budget.]`);
|
|
6337
|
+
}
|
|
6022
6338
|
sections.push(
|
|
6023
|
-
"## History\n" +
|
|
6339
|
+
"## History\n" + historyText.join("\n")
|
|
6024
6340
|
);
|
|
6025
6341
|
}
|
|
6026
6342
|
return `# Recall: ${repo}
|
|
@@ -6097,7 +6413,20 @@ async function selectRelevantHistory(db, repo, query, limit) {
|
|
|
6097
6413
|
}
|
|
6098
6414
|
var HISTORY_ENTRY_MAX_CHARS = 120;
|
|
6099
6415
|
var HISTORY_MAX_ENTRIES_PER_SNIPPET = 2;
|
|
6100
|
-
function renderHistorySnippet(snippet) {
|
|
6416
|
+
function renderHistorySnippet(snippet, query) {
|
|
6417
|
+
if (query) {
|
|
6418
|
+
const evidence = renderEvidenceSources([{
|
|
6419
|
+
text: snippet.text,
|
|
6420
|
+
observed_at: snippet.updated_at,
|
|
6421
|
+
date_kind: "record_updated"
|
|
6422
|
+
}], {
|
|
6423
|
+
query,
|
|
6424
|
+
max_chars: 520,
|
|
6425
|
+
per_source_chars: 420,
|
|
6426
|
+
preferred_speaker: preferredEvidenceSpeaker(query)
|
|
6427
|
+
});
|
|
6428
|
+
return evidence.sources.some((source) => source.used_chars > 0) ? `- [${snippet.kind}] ${evidence.text}` : "";
|
|
6429
|
+
}
|
|
6101
6430
|
const lines = snippet.text.split("\n").map((line) => line.trim()).filter(Boolean).filter((line) => !line.startsWith("Repo: ") && !line.endsWith(":"));
|
|
6102
6431
|
const entries = lines.slice(0, HISTORY_MAX_ENTRIES_PER_SNIPPET).map(
|
|
6103
6432
|
(line) => line.length > HISTORY_ENTRY_MAX_CHARS ? line.slice(0, HISTORY_ENTRY_MAX_CHARS - 1).trimEnd() + "\u2026" : line
|
|
@@ -7228,4 +7557,4 @@ export {
|
|
|
7228
7557
|
pruneMemories,
|
|
7229
7558
|
formatPruneReport
|
|
7230
7559
|
};
|
|
7231
|
-
//# sourceMappingURL=chunk-
|
|
7560
|
+
//# sourceMappingURL=chunk-W3BOHDM3.js.map
|