dsh-memu-memory 1.2.4 → 1.2.6
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/AGENTS.md +3 -1
- package/README.md +9 -9
- package/README.zh.md +6 -6
- package/docs/binding-lifecycle.md +1 -1
- package/docs/env-and-commands.md +4 -1
- package/docs/host-adaptation.md +318 -0
- package/docs/host-api.md +29 -5
- package/docs/memory-semantics.md +45 -9
- package/docs/troubleshooting.md +27 -8
- package/lib/binding-diagnostics.js +2 -2
- package/lib/client.js +246 -56
- package/lib/consolidation-ledger.js +46 -1
- package/lib/consolidation-worker.js +1 -0
- package/lib/cycle.js +51 -17
- package/lib/embedding-catalog.js +14 -0
- package/lib/embedding-runtime.js +202 -25
- package/lib/global-graph.js +99 -1
- package/lib/index.js +8 -0
- package/lib/inject.js +71 -33
- package/lib/lexicon-scope.js +143 -0
- package/lib/lexicon.js +31 -4
- package/lib/local-vector-service.js +82 -6
- package/lib/memory.js +186 -12
- package/lib/memu.js +318 -3
- package/lib/private.js +310 -67
- package/lib/rpc.js +183 -23
- package/lib/salient-wake.js +38 -2
- package/lib/state.js +7 -5
- package/lib/tools.js +40 -17
- package/lib/vector-migration.js +13 -1
- package/lib/webui/graph-view.bundle.js +1 -1
- package/lib/webui/graph-view.js +4 -1
- package/package.json +1 -1
- package/tests/absorb-review.test.mjs +2 -1
- package/tests/backend-compensation.test.mjs +1 -1
- package/tests/browser.test.mjs +58 -1
- package/tests/client-render.test.mjs +39 -0
- package/tests/consolidation-fork.test.mjs +81 -6
- package/tests/cross-library-recall.test.mjs +113 -0
- package/tests/curator-absorb.test.mjs +2 -1
- package/tests/curator-clusters.test.mjs +2 -1
- package/tests/curator-commit.test.mjs +2 -1
- package/tests/curator-link.test.mjs +2 -1
- package/tests/curator-review-mode.test.mjs +2 -1
- package/tests/cycle.test.mjs +2 -2
- package/tests/embedding-runtime.test.mjs +53 -1
- package/tests/global-graph.test.mjs +90 -0
- package/tests/lexicon-scope.test.mjs +256 -0
- package/tests/lexicon-ui.test.mjs +23 -0
- package/tests/managed-memory.test.mjs +1 -1
- package/tests/recall-dedup.test.mjs +1 -1
- package/tests/salient-wake.test.mjs +28 -1
- package/tests/settings-plumbing.test.mjs +1 -0
- package/tests/stubs/dsh-schedule.js +35 -0
- package/tests/ui-defaults.test.mjs +1 -1
- package/tests/vector-migration.test.mjs +20 -0
- package/tests/webui-auth.test.mjs +28 -0
|
@@ -18,6 +18,7 @@ const runtimeRoot = path.join(root, 'runtime')
|
|
|
18
18
|
let downloader
|
|
19
19
|
let migrator
|
|
20
20
|
let installer
|
|
21
|
+
let runtimeJob = null
|
|
21
22
|
|
|
22
23
|
function getDownloader() {
|
|
23
24
|
return downloader ||= createEmbeddingDownloadManager({ root })
|
|
@@ -61,16 +62,91 @@ export function localVectorRuntimeStatus(options = {}) {
|
|
|
61
62
|
return { ...status, source: status.status === 'installed' ? 'managed' : null, ...(env ? { envIgnored: true } : {}) }
|
|
62
63
|
}
|
|
63
64
|
|
|
64
|
-
|
|
65
|
+
// The installer owns the live job; pause/stop must survive the moment after the
|
|
66
|
+
// abort (when that job is already gone) so the UI can still show the partial bytes
|
|
67
|
+
// and let the user switch source before resuming.
|
|
68
|
+
export function runtimeStateView() {
|
|
69
|
+
const base = localVectorRuntimeStatus()
|
|
70
|
+
if (!runtimeJob) return base
|
|
71
|
+
const progress = runtimeJob.progress || base.progress || null
|
|
72
|
+
if (runtimeJob.status === 'downloading') {
|
|
73
|
+
return {
|
|
74
|
+
...base,
|
|
75
|
+
status: 'downloading',
|
|
76
|
+
ready: false,
|
|
77
|
+
path: null,
|
|
78
|
+
downloadSource: runtimeJob.source || base.downloadSource || null,
|
|
79
|
+
progress: progress ? { ...progress, speedBps: Number(progress.speedBps) || 0 } : null,
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
...base,
|
|
84
|
+
status: runtimeJob.status,
|
|
85
|
+
ready: false,
|
|
86
|
+
path: null,
|
|
87
|
+
downloadSource: runtimeJob.source || null,
|
|
88
|
+
progress: progress ? { ...progress, speedBps: 0 } : null,
|
|
89
|
+
error: runtimeJob.error || null,
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* 受管安装:只有 confirmed === true 才会联网下载 catalog 里 pin 住的制品。
|
|
95
|
+
* action=pause/stop 只中断当前下载并保留 .part;再次 start 会从稳定缓存续传。
|
|
96
|
+
*/
|
|
65
97
|
export async function installLocalVectorRuntime(options = {}) {
|
|
66
|
-
const
|
|
98
|
+
const action = String(options.action || 'start')
|
|
99
|
+
const installer = getInstaller()
|
|
100
|
+
if (action === 'pause' || action === 'stop') {
|
|
101
|
+
if (runtimeJob && runtimeJob.status === 'downloading') {
|
|
102
|
+
runtimeJob.stopRequested = action === 'stop'
|
|
103
|
+
runtimeJob.status = action === 'stop' ? 'stopped' : 'paused'
|
|
104
|
+
runtimeJob.progress = runtimeJob.progress ? { ...runtimeJob.progress, speedBps: 0 } : runtimeJob.progress
|
|
105
|
+
try { runtimeJob.controller.abort() } catch {}
|
|
106
|
+
}
|
|
107
|
+
return { runtime: runtimeStateView(), action }
|
|
108
|
+
}
|
|
109
|
+
if (runtimeJob?.status === 'downloading') {
|
|
110
|
+
throw Object.assign(new Error('a managed runtime install is already running'), { code: 'LOCAL_VECTOR_RUNTIME_BUSY' })
|
|
111
|
+
}
|
|
112
|
+
if (runtimeJob?.run) {
|
|
113
|
+
try { await runtimeJob.run } catch {}
|
|
114
|
+
}
|
|
115
|
+
runtimeJob = null
|
|
116
|
+
const controller = new AbortController()
|
|
117
|
+
const onExternalAbort = () => controller.abort()
|
|
118
|
+
options.signal?.addEventListener?.('abort', onExternalAbort, { once: true })
|
|
119
|
+
const job = { status: 'downloading', source: options.source || null, progress: null, controller, stopRequested: false, run: null, error: null }
|
|
120
|
+
runtimeJob = job
|
|
121
|
+
const run = installer.ensure({
|
|
67
122
|
modelId: options.modelId || null,
|
|
68
123
|
confirmed: options.confirmed === true,
|
|
69
124
|
reuseOnly: options.reuseOnly === true,
|
|
70
|
-
|
|
71
|
-
|
|
125
|
+
source: options.source || null,
|
|
126
|
+
signal: controller.signal,
|
|
127
|
+
onProgress: (progress) => {
|
|
128
|
+
if (runtimeJob === job) job.progress = { ...progress }
|
|
129
|
+
try { options.onProgress?.(progress) } catch {}
|
|
130
|
+
},
|
|
72
131
|
})
|
|
73
|
-
|
|
132
|
+
job.run = run
|
|
133
|
+
try {
|
|
134
|
+
const result = await run
|
|
135
|
+
job.status = 'installed'
|
|
136
|
+
return { runtime: result, state: getLocalVectorState() }
|
|
137
|
+
} catch (error) {
|
|
138
|
+
if (controller.signal.aborted || error?.code === 'LOCAL_VECTOR_RUNTIME_ABORTED' || error?.name === 'AbortError') {
|
|
139
|
+
job.status = job.stopRequested ? 'stopped' : 'paused'
|
|
140
|
+
job.progress = job.progress ? { ...job.progress, speedBps: 0 } : job.progress
|
|
141
|
+
return { runtime: runtimeStateView(), paused: job.status === 'paused', stopped: job.status === 'stopped' }
|
|
142
|
+
}
|
|
143
|
+
job.status = 'failed'
|
|
144
|
+
job.error = { code: String(error?.code || 'LOCAL_VECTOR_RUNTIME_INSTALL_FAILED'), message: String(error?.message || error) }
|
|
145
|
+
throw error
|
|
146
|
+
} finally {
|
|
147
|
+
options.signal?.removeEventListener?.('abort', onExternalAbort)
|
|
148
|
+
if (runtimeJob === job && job.status !== 'paused' && job.status !== 'stopped') runtimeJob = null
|
|
149
|
+
}
|
|
74
150
|
}
|
|
75
151
|
|
|
76
152
|
/** 生效的运行时目录:用户显式 env > 已核实的受管目录 > profile 里记录的旧值。 */
|
|
@@ -161,7 +237,7 @@ export function getLocalVectorState() {
|
|
|
161
237
|
}))
|
|
162
238
|
let indexed = null
|
|
163
239
|
try { indexed = migratorFor().membership() } catch { indexed = null }
|
|
164
|
-
const runtime =
|
|
240
|
+
const runtime = runtimeStateView()
|
|
165
241
|
return {
|
|
166
242
|
catalog,
|
|
167
243
|
installations: Object.fromEntries(catalog.map(entry => [entry.id, installationFor(entry.id, runtime)])),
|
package/lib/memory.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
updatePrivateIndex, updateGlobalIndex,
|
|
9
9
|
newMemoryId, getSettings, effectiveVectorRoute, getActiveCue, consumeCue,
|
|
10
10
|
getLibrary, setSessionBinding, setRecallError, effectiveScope, listLibrariesAll,
|
|
11
|
+
listLibraries, listSessionBindings, getWorkspacePolicy,
|
|
11
12
|
} from './state.js'
|
|
12
13
|
import { stamp, redactSecrets, retryStoreWrite, warn } from './paths.js'
|
|
13
14
|
import { scopeGenerationOf } from './consolidation-ledger.js'
|
|
@@ -1339,6 +1340,10 @@ async function privateRememberImpl({
|
|
|
1339
1340
|
const entry = {
|
|
1340
1341
|
...(previousHabit?.[1] || {}),
|
|
1341
1342
|
track,
|
|
1343
|
+
// Domain stamps what kind of conversation wrote this entry, so cross-library
|
|
1344
|
+
// recall can keep "same domain only" true for new memories. Entries written
|
|
1345
|
+
// before this field existed fall back to their library's bound-session domain.
|
|
1346
|
+
...(binding ? { domain: domainOf(binding) } : {}),
|
|
1342
1347
|
attachments: media,
|
|
1343
1348
|
context: memoryContext,
|
|
1344
1349
|
layer,
|
|
@@ -1709,6 +1714,101 @@ async function importMemoriesImpl({ libraryId, memories, maxFiles = 2000, now =
|
|
|
1709
1714
|
bumpStats(libraryId, 'written', entries.length)
|
|
1710
1715
|
return { imported: entries.length, ids: entries.map((item) => item.id), idMap, counts, examples, engineWarning }
|
|
1711
1716
|
}
|
|
1717
|
+
// Cross-library recall (same domain only). A library qualifies when at least one
|
|
1718
|
+
// non-fork conversation bound to it uses the current domain and the folder policy
|
|
1719
|
+
// did not turn private memory off. The bound library is always included and keeps
|
|
1720
|
+
// its existing unfiltered behavior; other libraries only contribute entries whose
|
|
1721
|
+
// own domain matches (entries written before the domain stamp have none).
|
|
1722
|
+
// Exported because the lexicon reads the same scope (lib/lexicon-scope.js): one
|
|
1723
|
+
// switch must not make memory cross-folder while the lexicon stays in one folder.
|
|
1724
|
+
export function crossLibrarySources(binding, domain) {
|
|
1725
|
+
const domains = new Map()
|
|
1726
|
+
for (const item of listSessionBindings()) {
|
|
1727
|
+
if (!item?.libraryId || item.consolidationFork) continue
|
|
1728
|
+
if (!domains.has(item.libraryId)) domains.set(item.libraryId, new Set())
|
|
1729
|
+
domains.get(item.libraryId).add(item.domainOverride || item.domain || 'general')
|
|
1730
|
+
}
|
|
1731
|
+
const sources = [{ libraryId: binding.libraryId, primary: true }]
|
|
1732
|
+
for (const library of listLibraries()) {
|
|
1733
|
+
if (library.id === binding.libraryId) continue
|
|
1734
|
+
if (!domains.get(library.id)?.has(domain)) continue
|
|
1735
|
+
try {
|
|
1736
|
+
if (getWorkspacePolicy(library.scopeKey).useLibrary === false) continue
|
|
1737
|
+
} catch {}
|
|
1738
|
+
sources.push({ libraryId: library.id, primary: false })
|
|
1739
|
+
}
|
|
1740
|
+
return sources
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
function domainScopedIndex(index, domain) {
|
|
1744
|
+
return {
|
|
1745
|
+
...index,
|
|
1746
|
+
entries: Object.fromEntries(Object.entries(index.entries || {})
|
|
1747
|
+
.filter(([, entry]) => !entry?.domain || entry.domain === domain)),
|
|
1748
|
+
}
|
|
1749
|
+
}
|
|
1750
|
+
|
|
1751
|
+
// Merge per-library candidate lists with reciprocal-rank fusion. `privateWeighted`
|
|
1752
|
+
// consumes `retrievalScore`, so the cross-library rank survives the later mood /
|
|
1753
|
+
// decay re-ordering instead of being collapsed into one library's order.
|
|
1754
|
+
async function recallCrossLibrary({ exec, sources, query, topK, route, byId, automatic, intent, retrieveImpl, domain }) {
|
|
1755
|
+
const lists = []
|
|
1756
|
+
for (const source of sources) {
|
|
1757
|
+
const scoped = source.primary ? source.index : domainScopedIndex(source.index, domain)
|
|
1758
|
+
if (route === 'lexical' || byId) {
|
|
1759
|
+
lists.push({ libraryId: source.libraryId, files: localRecall(scoped, query).files })
|
|
1760
|
+
continue
|
|
1761
|
+
}
|
|
1762
|
+
const managed = await managedRecall({
|
|
1763
|
+
exec, index: scoped, query, topK, libraryId: source.libraryId,
|
|
1764
|
+
automatic, intent, retrieveImpl, byId,
|
|
1765
|
+
})
|
|
1766
|
+
lists.push({ libraryId: source.libraryId, files: managed.files || [], errors: managed.errors || [] })
|
|
1767
|
+
}
|
|
1768
|
+
const RRF_K = 60
|
|
1769
|
+
const rows = new Map()
|
|
1770
|
+
for (const list of lists) {
|
|
1771
|
+
list.files.forEach((file, position) => {
|
|
1772
|
+
const key = list.libraryId + '\u0000' + file.name
|
|
1773
|
+
const row = rows.get(key) || { file: { ...file, libraryId: list.libraryId }, rrf: 0, bestRank: Infinity }
|
|
1774
|
+
row.rrf += 1 / (RRF_K + position + 1)
|
|
1775
|
+
row.bestRank = Math.min(row.bestRank, position + 1)
|
|
1776
|
+
rows.set(key, row)
|
|
1777
|
+
})
|
|
1778
|
+
}
|
|
1779
|
+
const maxRrf = [...rows.values()].reduce((max, row) => Math.max(max, row.rrf), 0) || 1
|
|
1780
|
+
const primaryId = sources.find((source) => source.primary)?.libraryId || null
|
|
1781
|
+
const ordered = [...rows.values()]
|
|
1782
|
+
.map((row) => ({
|
|
1783
|
+
...row.file,
|
|
1784
|
+
entry: row.file.entry || null,
|
|
1785
|
+
content: String(row.file.content ?? row.file.entry?.content ?? ''),
|
|
1786
|
+
strength: Number.isFinite(Number(row.file.strength)) ? Number(row.file.strength) : decayStrength(row.file.entry),
|
|
1787
|
+
createdAtIdentity: row.file.createdAtIdentity ?? row.file.entry?.createdAt ?? null,
|
|
1788
|
+
retrievalScore: row.rrf / maxRrf,
|
|
1789
|
+
fusion: { ...(row.file.fusion || {}), crossLibraryRrf: row.rrf, bestRank: row.bestRank },
|
|
1790
|
+
}))
|
|
1791
|
+
.sort((a, b) => b.retrievalScore - a.retrievalScore
|
|
1792
|
+
|| String(b.entry?.updatedAt || b.entry?.createdAt || '').localeCompare(String(a.entry?.updatedAt || a.entry?.createdAt || '')))
|
|
1793
|
+
// The same id can exist in two libraries (ids are generated per library). Keep
|
|
1794
|
+
// the bound library's copy so an id shown by recall resolves there first.
|
|
1795
|
+
const chosen = new Map()
|
|
1796
|
+
for (const file of ordered) {
|
|
1797
|
+
const current = chosen.get(file.name)
|
|
1798
|
+
if (!current || (file.libraryId === primaryId && current.libraryId !== primaryId)) chosen.set(file.name, file)
|
|
1799
|
+
}
|
|
1800
|
+
return {
|
|
1801
|
+
files: [...chosen.values()],
|
|
1802
|
+
segments: [],
|
|
1803
|
+
resources: [],
|
|
1804
|
+
raw: null,
|
|
1805
|
+
parseWarning: null,
|
|
1806
|
+
recallRoute: 'cross-library',
|
|
1807
|
+
libraries: sources.map((source) => source.libraryId),
|
|
1808
|
+
errors: lists.flatMap((list) => (list.errors || []).map((error) => `${list.libraryId}: ${error}`)),
|
|
1809
|
+
}
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1712
1812
|
export async function privateRecall({ exec, query, topK, relevanceThreshold, purpose = 'explicit', retrieveImpl = retrieve }) {
|
|
1713
1813
|
const binding = peekBinding(exec)
|
|
1714
1814
|
if (!binding) throw new Error('no bound session')
|
|
@@ -1716,24 +1816,47 @@ export async function privateRecall({ exec, query, topK, relevanceThreshold, pur
|
|
|
1716
1816
|
assertScopeEnabled(binding)
|
|
1717
1817
|
const settings = getSettings()
|
|
1718
1818
|
const threshold = relevanceThreshold === undefined ? settings.relevanceThreshold : relevanceThreshold
|
|
1719
|
-
let index = loadPrivateIndex(binding.libraryId)
|
|
1720
1819
|
const byId = /^(?:g?mem)[-_][a-z0-9_-]+(?:\.md)?$/i.test(String(query || '').trim())
|
|
1721
1820
|
const route = effectiveVectorRoute(settings)
|
|
1722
1821
|
const wanted = Number(topK || settings.privateTopK || 4)
|
|
1723
|
-
const
|
|
1724
|
-
|
|
1725
|
-
|
|
1822
|
+
const domain = domainOf(binding)
|
|
1823
|
+
const sources = (settings.crossLibraryRecall === true
|
|
1824
|
+
? crossLibrarySources(binding, domain)
|
|
1825
|
+
: [{ libraryId: binding.libraryId, primary: true }])
|
|
1826
|
+
.map((source) => ({ ...source, index: loadPrivateIndex(source.libraryId) }))
|
|
1827
|
+
// Single source keeps the old path byte-for-byte; the cross-library merge only
|
|
1828
|
+
// exists when another qualifying library is actually present.
|
|
1829
|
+
const result = sources.length === 1
|
|
1830
|
+
? (route === 'lexical' || byId
|
|
1831
|
+
? { ...localRecall(sources[0].index, query), recallRoute: 'local' }
|
|
1832
|
+
: await managedRecall({ exec, index: sources[0].index, query, topK: wanted, libraryId: sources[0].libraryId, automatic: purpose === 'automatic', intent: managedVectorIntent(), retrieveImpl, byId }))
|
|
1833
|
+
: await recallCrossLibrary({ exec, sources, query, topK: wanted, route, byId, automatic: purpose === 'automatic', intent: managedVectorIntent(), retrieveImpl, domain })
|
|
1726
1834
|
const current = peekBinding(exec)
|
|
1727
1835
|
if (!current || current.libraryId !== binding.libraryId) throw new Error('memory scope changed during recall; retry')
|
|
1728
1836
|
assertScopeEnabled(current)
|
|
1729
|
-
index = loadPrivateIndex(binding.libraryId)
|
|
1730
|
-
const
|
|
1837
|
+
const index = loadPrivateIndex(binding.libraryId)
|
|
1838
|
+
const indexByLibrary = new Map(sources.map((source) => [source.libraryId, source.libraryId === binding.libraryId ? index : source.index]))
|
|
1839
|
+
// enrichFiles fills body/strength from one index; doing that against the bound
|
|
1840
|
+
// library would blank every foreign hit. Cross-library files already carry
|
|
1841
|
+
// their entry from the library that produced them.
|
|
1842
|
+
const enriched = sources.length === 1
|
|
1843
|
+
? enrichFiles(result, index)
|
|
1844
|
+
: {
|
|
1845
|
+
files: result.files || [],
|
|
1846
|
+
segments: result.segments || [],
|
|
1847
|
+
resources: result.resources || [],
|
|
1848
|
+
raw: result.raw,
|
|
1849
|
+
parseWarning: result.parseWarning,
|
|
1850
|
+
}
|
|
1731
1851
|
// enrichFiles rebuilds the result object; carry the route/error metadata across
|
|
1732
1852
|
// so buildRecall can report a degraded semantic leg and the tool can warn.
|
|
1733
1853
|
if (result?.recallRoute) enriched.recallRoute = result.recallRoute
|
|
1734
1854
|
if (result?.errors) enriched.errors = result.errors.slice()
|
|
1735
1855
|
if (result?.fusion) enriched.fusion = result.fusion
|
|
1736
|
-
|
|
1856
|
+
if (result?.libraries) enriched.libraries = result.libraries.slice()
|
|
1857
|
+
const span = createdAtSpan(sources.flatMap((source) => Object.values(
|
|
1858
|
+
(source.libraryId === binding.libraryId ? index : source.index).entries || {},
|
|
1859
|
+
).map((entry) => ({ entry }))))
|
|
1737
1860
|
const mood = moodDecay(binding.mood)
|
|
1738
1861
|
const scored = privateWeighted(enriched, Number(topK || settings.privateTopK || 4), {
|
|
1739
1862
|
// Three independent legs: a clear composition, an arousal away from rest, or a
|
|
@@ -1753,9 +1876,18 @@ export async function privateRecall({ exec, query, topK, relevanceThreshold, pur
|
|
|
1753
1876
|
automatic: purpose === 'automatic',
|
|
1754
1877
|
})
|
|
1755
1878
|
// Being recalled is being used, and a memory that keeps being used should not fade
|
|
1756
|
-
// like one nobody ever touches.
|
|
1757
|
-
|
|
1758
|
-
|
|
1879
|
+
// like one nobody ever touches. Group by the library each hit came from so a
|
|
1880
|
+
// cross-library recall touches the owning index, not the bound one.
|
|
1881
|
+
const recalledByLibrary = new Map()
|
|
1882
|
+
for (const file of scored.files || []) {
|
|
1883
|
+
const libraryId = file.libraryId || binding.libraryId
|
|
1884
|
+
if (!recalledByLibrary.has(libraryId)) recalledByLibrary.set(libraryId, [])
|
|
1885
|
+
recalledByLibrary.get(libraryId).push(file.name)
|
|
1886
|
+
}
|
|
1887
|
+
if (purpose !== 'automatic') {
|
|
1888
|
+
for (const [libraryId, ids] of recalledByLibrary) touchAccessMany({ libraryId, ids })
|
|
1889
|
+
}
|
|
1890
|
+
for (const [libraryId, ids] of recalledByLibrary) bumpStats(libraryId, 'recalled', ids.length)
|
|
1759
1891
|
// Fact-level dedup observation . Fail-open signal, not
|
|
1760
1892
|
// bookkeeping: without it a mistuned DUP_DICE silently eats real memories and
|
|
1761
1893
|
// nobody can tell "recalled N" from "recalled N members of one fact".
|
|
@@ -1772,13 +1904,16 @@ export async function privateRecall({ exec, query, topK, relevanceThreshold, pur
|
|
|
1772
1904
|
})
|
|
1773
1905
|
}
|
|
1774
1906
|
for (const file of scored.files || []) {
|
|
1907
|
+
const fileLibraryId = file.libraryId || binding.libraryId
|
|
1908
|
+
const fileIndex = indexByLibrary.get(fileLibraryId) || index
|
|
1775
1909
|
if (file.entry?.attachments?.length) {
|
|
1776
1910
|
file.entry = { ...file.entry, attachments: file.entry.attachments.map(item => {
|
|
1777
|
-
try { return { ...item, ...attachmentRefs(
|
|
1911
|
+
try { return { ...item, ...attachmentRefs(fileLibraryId, [{ sha256: item.sha256 }])[0] } } catch { return { ...item, missing: true } }
|
|
1778
1912
|
}) }
|
|
1779
1913
|
}
|
|
1780
|
-
try { file.related = recallRelations(
|
|
1914
|
+
try { file.related = recallRelations(fileLibraryId, fileIndex, file.name, memorySessionId(exec)) } catch { file.related = [] }
|
|
1781
1915
|
}
|
|
1916
|
+
if (sources.length > 1) scored.libraries = sources.map((source) => source.libraryId)
|
|
1782
1917
|
return scored
|
|
1783
1918
|
}
|
|
1784
1919
|
|
|
@@ -1787,6 +1922,45 @@ export async function privateList({ exec, libraryId, preferIndex = false }) {
|
|
|
1787
1922
|
if (scope.binding) assertScopeEnabled(scope.binding)
|
|
1788
1923
|
const index = loadPrivateIndex(scope.libraryId)
|
|
1789
1924
|
const allowed = (entry) => !!entry && (!sessionIdOf(exec) || (isMemoryEligible(entry) && visibleToSession(entry, memorySessionId(exec))))
|
|
1925
|
+
const settings = getSettings()
|
|
1926
|
+
// The sidebar list follows the same scope as recall when the setting is on.
|
|
1927
|
+
// An explicit libraryId is the browser's library selector and must stay
|
|
1928
|
+
// single-library, or "which library am I looking at" stops having an answer.
|
|
1929
|
+
const crossSources = !libraryId && scope.binding && settings.crossLibraryRecall === true
|
|
1930
|
+
? crossLibrarySources(scope.binding, domainOf(scope.binding))
|
|
1931
|
+
: null
|
|
1932
|
+
if (crossSources && crossSources.length > 1) {
|
|
1933
|
+
const libraries = []
|
|
1934
|
+
const files = []
|
|
1935
|
+
for (const source of crossSources) {
|
|
1936
|
+
const sourceIndex = source.libraryId === scope.libraryId ? index : loadPrivateIndex(source.libraryId)
|
|
1937
|
+
const scoped = source.primary ? sourceIndex : domainScopedIndex(sourceIndex, domainOf(scope.binding))
|
|
1938
|
+
for (const file of localIndexFiles(scoped)) {
|
|
1939
|
+
if (!allowed(file.entry)) continue
|
|
1940
|
+
const library = getLibrary(source.libraryId)
|
|
1941
|
+
files.push({
|
|
1942
|
+
name: file.name,
|
|
1943
|
+
description: file.description,
|
|
1944
|
+
content: file.content,
|
|
1945
|
+
entry: file.entry,
|
|
1946
|
+
libraryId: source.libraryId,
|
|
1947
|
+
libraryName: library?.name || source.libraryId,
|
|
1948
|
+
})
|
|
1949
|
+
}
|
|
1950
|
+
libraries.push({ id: source.libraryId, name: getLibrary(source.libraryId)?.name || source.libraryId })
|
|
1951
|
+
}
|
|
1952
|
+
files.sort((a, b) => String(b.entry?.updatedAt || b.entry?.createdAt || '').localeCompare(String(a.entry?.updatedAt || a.entry?.createdAt || ''))
|
|
1953
|
+
|| a.name.localeCompare(b.name))
|
|
1954
|
+
return {
|
|
1955
|
+
libraryId: scope.libraryId,
|
|
1956
|
+
libraries,
|
|
1957
|
+
source: 'index',
|
|
1958
|
+
warning: null,
|
|
1959
|
+
files,
|
|
1960
|
+
raw: null,
|
|
1961
|
+
parseWarning: null,
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1790
1964
|
// UI 列表直接读索引:索引是权威,引擎只是一面镜子。走引擎意味着起 Python 和
|
|
1791
1965
|
// embedding worker(秒级),归档/还原后刷新一下就卡住,这就是 2026-10-30 的现场。
|
|
1792
1966
|
const route = preferIndex ? 'lexical' : engineRoute()
|