@a9i5k4/dsh-auto-memory 0.1.36 → 0.1.37
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/lib/client.js +72 -5
- package/lib/index.js +52 -24
- package/lib/semantic-js.js +102 -3
- package/package.json +1 -1
package/lib/client.js
CHANGED
|
@@ -495,6 +495,8 @@ window.__ModuleLoader__.load({
|
|
|
495
495
|
'补丁 0.1.32:「记忆唤起」开关与设置页双向联动(导览与设置走同一 semantic-emit 接口);语义引擎分级引导(无引擎自动装 JS 档,发烧友可选 Python)。',
|
|
496
496
|
'补丁 0.1.33:修复语义引擎下载 404(镜像 URL 重复前缀);transformers 推理库声明为可选依赖并随包分发。',
|
|
497
497
|
'补丁 0.1.34:修复推理库检测——pnpm 把 transformers 提升到 profile 根 node_modules,检测补该路径,新用户装完即用,无需手动操作。',
|
|
498
|
+
'补丁 0.1.37:修复「弹窗关不掉」(#13,感谢 @eclgo 报告)——暂离回归面板只在 away→active 翻转时弹一次;0.1.36 起回归检测全局化后,回归前(尚未发消息)面板会被每 30 秒强制重开,现已根治。',
|
|
499
|
+
'补丁 0.1.37:修复语义引擎「推理库缺失」误报 (#14,感谢 @moonltppt 报告)——推理库探测改用 Node 真实解析,覆盖 npm/pnpm(hoisted/isolated)全部安装布局;并新增「打开即自动检测」:检测不到自动深度扫描(~/.dsh/profiles 全家 + pnpm 虚拟存储),命中即热接入(无需重启),仍缺才推荐安装/一键下载,推荐卡 24 小时免打扰。',
|
|
498
500
|
], en: [
|
|
499
501
|
'★ MAJOR: Brand-new Welcome Tour — after first launch or upgrade, every feature is introduced step by step with per-feature switches right in the tour (association / snapshot / greeting / night unattended / reflection / summaries / external memory / skill promotion…); engine detection, download, self-test and live external-source scanning are all inline.',
|
|
500
502
|
'★ New brand visuals: an Office/Fluent-style liquid-glass app icon family — each step gets its own colored glass squircle icon (cyan inject / amber greeting / green calendar / violet engine / sky radar / coral finish) with dedicated looping motion (bell sway, page flip, linked rings, prism spin, radar sweep, rising spark); the signature three-slab frosted-glass logo stays on the Core step.',
|
|
@@ -508,6 +510,8 @@ window.__ModuleLoader__.load({
|
|
|
508
510
|
'Patch 0.1.32: the "Memory recall" switch now syncs bidirectionally with Settings (tour and settings share the semantic-emit endpoint); tiered engine onboarding (auto-install JS tier, Python optional for enthusiasts).',
|
|
509
511
|
'Patch 0.1.33: fixed semantic-engine download 404 (duplicate prefix in mirror URL); transformers inference lib declared as an optional dependency and shipped with the package.',
|
|
510
512
|
'Patch 0.1.34: fixed inference-lib detection — pnpm hoists transformers to the profile-root node_modules; detection now covers that path, so fresh installs work out of the box.',
|
|
513
|
+
'Patch 0.1.37: fixed the "popup cannot be closed" loop (#13, thanks @eclgo) — the welcome-back panel now opens only on the away→active transition; since 0.1.36 globalised away detection, the panel was force-reopened every 30s until the first message after returning. Root-caused and fixed.',
|
|
514
|
+
'Patch 0.1.37: fixed the false "inference runtime missing" state (#14, thanks @moonltppt) — runtime detection now uses real Node resolution, covering npm/pnpm (hoisted/isolated) layouts; plus a new check-on-open flow: when not detected, a deep scan (~/.dsh/profiles + pnpm virtual store) runs automatically and hot-wires hits with no restart; only if still missing does it recommend installing / one-click download, with a 24h snooze.',
|
|
511
515
|
] },
|
|
512
516
|
'0.1.29': { zh: [
|
|
513
517
|
'修复:工作区总览一直显示「未发现带记忆的工作区」——DSH 新版会话持久化改为 session.jsonl.zstd 压缩帧,旧逻辑只认 .jsonl 扫描不到任何会话;现已用 zstd 解压读取首行提取 cwd,并让空的 summary 缓存短时失效,避免空结果被永久固化。',
|
|
@@ -654,6 +658,7 @@ window.__ModuleLoader__.load({
|
|
|
654
658
|
if (d.kind === 'notice') return d.notice && d.notice.level === 'urgent' ? 80 : 70
|
|
655
659
|
if (d.kind === 'summary') return 60
|
|
656
660
|
if (d.kind === 'welcomeBack') return 50
|
|
661
|
+
if (d.kind === 'semSetup') return 45
|
|
657
662
|
return 10
|
|
658
663
|
}
|
|
659
664
|
function dialogKey(d) {
|
|
@@ -721,6 +726,8 @@ window.__ModuleLoader__.load({
|
|
|
721
726
|
greet: '/api/dsh-auto-memory/greet',
|
|
722
727
|
notices: '/api/dsh-auto-memory/notices',
|
|
723
728
|
models: '/api/dsh-auto-memory/models',
|
|
729
|
+
semanticDeepDetect: '/api/dsh-auto-memory/semantic-deep-detect',
|
|
730
|
+
semanticDownload: '/api/dsh-auto-memory/semantic-download',
|
|
724
731
|
}
|
|
725
732
|
function query(params) {
|
|
726
733
|
var search = new URLSearchParams()
|
|
@@ -2961,6 +2968,50 @@ window.__ModuleLoader__.load({
|
|
|
2961
2968
|
h('div', { style: { display: 'flex', justifyContent: 'flex-end', marginTop: '6px' } },
|
|
2962
2969
|
h('button', { 'data-dam-btn': '', style: close, onClick: closeDialog }, t('gotIt')))))
|
|
2963
2970
|
}
|
|
2971
|
+
if (dialogState.kind === 'semSetup') {
|
|
2972
|
+
// 打开即自动检测引导卡(0.1.37,#14 后续):快检+深扫仍未就绪时推荐补装/一键下载;
|
|
2973
|
+
// 深扫命中已热接入则报喜(即时生效)。关闭 = 24h 免打扰,不反复打扰。
|
|
2974
|
+
var sd = dialogState.result || {}
|
|
2975
|
+
var sdZh = locale === 'zh'
|
|
2976
|
+
var sdBody = { fontSize: 'calc(12px * var(--dam-scale))', lineHeight: 1.6, opacity: .92, whiteSpace: 'pre-wrap', marginTop: '4px' }
|
|
2977
|
+
var sdRows = []
|
|
2978
|
+
var sdActions = []
|
|
2979
|
+
var sdCmd = 'pnpm approve-builds\npnpm add @huggingface/transformers\n# 然后重启 dsh web'
|
|
2980
|
+
var sdSnooze = function () {
|
|
2981
|
+
try { localStorage.setItem('dsh-auto-memory.semDetectSnoozeUntil', String(Date.now() + 24 * 3600 * 1000)) } catch (eSn) {}
|
|
2982
|
+
closeDialog()
|
|
2983
|
+
}
|
|
2984
|
+
if (sd.deep && sd.deep.integrated) {
|
|
2985
|
+
sdRows.push(h('div', { style: sdBody }, sdZh
|
|
2986
|
+
? '检测到你已安装推理库 @huggingface/transformers(常规路径此前未识别,深度扫描已命中并自动接入)。语义检索 C2 现在即可用,无需重启。'
|
|
2987
|
+
: 'Your installed @huggingface/transformers was found by the deep scan and hot-wired automatically. The C2 semantic tier is ready now — no restart needed.'))
|
|
2988
|
+
} else {
|
|
2989
|
+
if (sd.recommendation === 'install-peer' || sd.recommendation === 'setup-both') {
|
|
2990
|
+
sdRows.push(h('div', { style: sdBody }, sdZh
|
|
2991
|
+
? (sd.recommendation === 'setup-both' ? '语义模型与推理库都未检测到。推理库请在安装 dsh-auto-memory 的同一目录(dsh profile)执行:' : '语义模型已下载,但推理库缺失(已含深度扫描)。请在安装 dsh-auto-memory 的同一目录(dsh profile)执行:')
|
|
2992
|
+
: (sd.recommendation === 'setup-both' ? 'Neither the model assets nor the inference runtime were found. For the runtime, run in the directory where dsh-auto-memory is installed (the dsh profile):' : 'Model assets found, but the inference runtime is missing (deep scan included). Run in the directory where dsh-auto-memory is installed (the dsh profile):')))
|
|
2993
|
+
sdActions.push(h('button', { 'data-dam-btn': '', style: close, onClick: function () {
|
|
2994
|
+
try { if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(sdCmd) } catch (eCp) {}
|
|
2995
|
+
} }, sdZh ? '复制命令' : 'Copy commands'))
|
|
2996
|
+
}
|
|
2997
|
+
if (sd.recommendation === 'download-model' || sd.recommendation === 'setup-both') {
|
|
2998
|
+
sdRows.push(h('div', { style: sdBody }, sdZh
|
|
2999
|
+
? '语义模型(内置 JS 档,约 135MB,一次即可)可一键后台下载,下载完成后语义检索自动启用:'
|
|
3000
|
+
: 'The built-in JS semantic model (~135MB, one-time) can be downloaded in the background; the semantic tier enables itself once done:'))
|
|
3001
|
+
sdActions.push(h('button', { 'data-dam-btn': '', 'data-primary': 'true', style: close, onClick: function () {
|
|
3002
|
+
apiPost(API.semanticDownload, { action: 'start', mirror: 'auto' }).catch(function () {})
|
|
3003
|
+
closeDialog()
|
|
3004
|
+
} }, sdZh ? '立即下载' : 'Download now'))
|
|
3005
|
+
}
|
|
3006
|
+
}
|
|
3007
|
+
return h('div', { style: overlay },
|
|
3008
|
+
h('div', { style: box },
|
|
3009
|
+
h('div', { style: head }, sdZh ? '自动记忆引擎检测' : 'Memory engine check'),
|
|
3010
|
+
sdRows,
|
|
3011
|
+
h('div', { style: { display: 'flex', gap: '8px', justifyContent: 'flex-end', marginTop: '6px' } },
|
|
3012
|
+
sdActions,
|
|
3013
|
+
h('button', { 'data-dam-btn': '', style: close, onClick: (sd.deep && sd.deep.integrated) ? closeDialog : sdSnooze }, t('gotIt')))))
|
|
3014
|
+
}
|
|
2964
3015
|
var versions = dialogState.versions || []
|
|
2965
3016
|
var lastV = versions.length ? versions[versions.length - 1].version : ''
|
|
2966
3017
|
return h('div', { style: overlay },
|
|
@@ -3505,8 +3556,10 @@ window.__ModuleLoader__.load({
|
|
|
3505
3556
|
})
|
|
3506
3557
|
// 语言切换时通知所有订阅者重渲染
|
|
3507
3558
|
onLocale(function () { emit() })
|
|
3508
|
-
// 暂离回来自动弹开记忆窗口:host 判定暂离(阈值可配 awayMinutes)
|
|
3509
|
-
//
|
|
3559
|
+
// 暂离回来自动弹开记忆窗口:host 判定暂离(阈值可配 awayMinutes),轮询发现回归(true→false)时自动打开。
|
|
3560
|
+
// v0.1.37 修复(#13):本函数不得做「away 且面板关着就再弹开」——≤0.1.35 host 侧 away 无写入点恒 false
|
|
3561
|
+
// 掩盖了旧行,0.1.36 全局 away 激活后它变成 30s 重开死循环:用户回到机器但还没发消息时 host 恒判 away,
|
|
3562
|
+
// 关掉即被重弹(=「弹窗关不掉」)。契约以设置页文案为准:回归(away true→false)才弹,away 挂着绝不强弹。
|
|
3510
3563
|
var prevAwayState = null
|
|
3511
3564
|
function autoOpenOnReturn() {
|
|
3512
3565
|
try {
|
|
@@ -3517,11 +3570,8 @@ window.__ModuleLoader__.load({
|
|
|
3517
3570
|
var pend = lastPendingSummary
|
|
3518
3571
|
if (pend) { openDialog({ kind: 'summary', summary: pend }); lastPendingSummary = null }
|
|
3519
3572
|
else if (!document.hidden) openDialog({ kind: 'welcomeBack' })
|
|
3520
|
-
prevAwayState = hostAway
|
|
3521
|
-
return
|
|
3522
3573
|
}
|
|
3523
3574
|
prevAwayState = hostAwayReady ? hostAway : prevAwayState
|
|
3524
|
-
if (isAway() && !controller.isOpen()) controller.open()
|
|
3525
3575
|
} catch (e) {}
|
|
3526
3576
|
}
|
|
3527
3577
|
autoOpenOnReturn()
|
|
@@ -3595,6 +3645,23 @@ window.__ModuleLoader__.load({
|
|
|
3595
3645
|
checkNotices()
|
|
3596
3646
|
var noticesTimer = setInterval(checkNotices, 3600 * 1000)
|
|
3597
3647
|
|
|
3648
|
+
// 打开即自动检测语义引擎(0.1.37,#14 后续):每次打开页面一次「快检 → 失败自动深扫
|
|
3649
|
+
// (~/.dsh/profiles 全家 + pnpm 虚拟存储) → 仍缺才推荐」。深扫命中即热接入(即时生效);
|
|
3650
|
+
// 推荐卡关闭 = 24h 免打扰。延迟 12s 错开开屏的向导/changelog 弹窗(优先级本身也压它一头)。
|
|
3651
|
+
setTimeout(function () {
|
|
3652
|
+
apiGet(API.semanticDeepDetect).then(function (d) {
|
|
3653
|
+
try {
|
|
3654
|
+
if (!d || d.ready) return
|
|
3655
|
+
if (!(d.deep && d.deep.integrated)) {
|
|
3656
|
+
var sdUntil = 0
|
|
3657
|
+
try { sdUntil = Number(localStorage.getItem('dsh-auto-memory.semDetectSnoozeUntil') || 0) } catch (eSn) {}
|
|
3658
|
+
if (Date.now() < sdUntil) return
|
|
3659
|
+
}
|
|
3660
|
+
openDialog({ kind: 'semSetup', result: d })
|
|
3661
|
+
} catch (eSD) {}
|
|
3662
|
+
}).catch(function () {})
|
|
3663
|
+
}, 12000)
|
|
3664
|
+
|
|
3598
3665
|
// 时间检测轮询(30s):拉 host 的暂离状态/待展示总结,检测暂离回归并自动弹窗
|
|
3599
3666
|
var lastPendingSummary = null
|
|
3600
3667
|
var awayPollTimer = null
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,7 @@ import { createContextHost } from './context-host.js'
|
|
|
32
32
|
import { createSuccessEvidencePre } from './context-bridge.js'
|
|
33
33
|
import { createIndexSyncHostPre } from './m7-index-sync-host.js'
|
|
34
34
|
import { createActivationHost } from './activation-host.js'
|
|
35
|
-
import { createJsSemanticEnginePre, createSemanticDownloaderPre, fuseD6Pre, E5_SMALL_Q8_MANIFEST_V1 } from './semantic-js.js'
|
|
35
|
+
import { createJsSemanticEnginePre, createSemanticDownloaderPre, fuseD6Pre, probeJsSemanticAssets, deepScanPeerTransformers, E5_SMALL_Q8_MANIFEST_V1 } from './semantic-js.js'
|
|
36
36
|
import { loadAndVerifyPolicy, decideActivationV2, lexicalContainment } from './semantic-decide.js'
|
|
37
37
|
import { createPythonSidecarClientPre, defaultWorkerScriptPathPre } from './python-sidecar-client.js'
|
|
38
38
|
import { createEpisodicStorePre } from './episodic-store.js'
|
|
@@ -93,6 +93,7 @@ export const API = {
|
|
|
93
93
|
notices: '/api/dsh-auto-memory/notices',
|
|
94
94
|
'activation-inbox': '/api/dsh-auto-memory/activation-inbox',
|
|
95
95
|
'semantic-status': '/api/dsh-auto-memory/semantic-status',
|
|
96
|
+
'semantic-deep-detect': '/api/dsh-auto-memory/semantic-deep-detect',
|
|
96
97
|
'semantic-download': '/api/dsh-auto-memory/semantic-download',
|
|
97
98
|
'semantic-emit': '/api/dsh-auto-memory/semantic-emit',
|
|
98
99
|
'shadow-recent': '/api/dsh-auto-memory/shadow-recent',
|
|
@@ -4352,28 +4353,45 @@ export function apply(ctx, config) {
|
|
|
4352
4353
|
const pluginDir = path.dirname(fileURLToPath(import.meta.url))
|
|
4353
4354
|
engine._jsSemantic = createJsSemanticEnginePre({ pluginDir })
|
|
4354
4355
|
engine._jsDownload = createSemanticDownloaderPre({ modelsRoot: path.join(pluginDir, 'models') })
|
|
4355
|
-
// 资产探测(semantic-status / 档位解析 / 引导卡共用)
|
|
4356
|
-
|
|
4357
|
-
|
|
4358
|
-
|
|
4359
|
-
|
|
4360
|
-
|
|
4361
|
-
|
|
4362
|
-
|
|
4363
|
-
|
|
4364
|
-
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
|
|
4356
|
+
// 资产探测(semantic-status / 档位解析 / 引导卡共用):共享实现见 semantic-js-pre 的
|
|
4357
|
+
// probeJsSemanticAssets —— peer 探测与引擎加载走同一套 Node 解析(2026-09-02 issue 修正)。
|
|
4358
|
+
// _peerExtraDirs = 深度扫描热接入位(semanticDeepDetect 命中后 probe/加载/档位即时生效)。
|
|
4359
|
+
engine._peerExtraDirs = []
|
|
4360
|
+
engine.semanticAssetProbe = async () => probeJsSemanticAssets(pluginDir, engine._peerExtraDirs)
|
|
4361
|
+
// 打开即自动检测(0.1.37,#14 后续):快检 → 模型在场但推理库缺失时深度扫描
|
|
4362
|
+
// (~/.dsh/profiles/* 全家 + pnpm 虚拟存储) → 命中即热接入(probe/加载双注入,无需重启),
|
|
4363
|
+
// 并给出 recommendation 供引导卡分流(none/setup-both/download-model/install-peer)。
|
|
4364
|
+
engine.semanticDeepDetect = async () => {
|
|
4365
|
+
const quick = await engine.semanticAssetProbe()
|
|
4366
|
+
const deep = { scanned: false, foundDirs: [], integrated: false }
|
|
4367
|
+
if (!quick.ready && quick.assetPresent) {
|
|
4368
|
+
deep.scanned = true
|
|
4369
|
+
try {
|
|
4370
|
+
const osMod = await import('node:os')
|
|
4371
|
+
const profilesRoot = path.join(osMod.homedir(), '.dsh', 'profiles')
|
|
4372
|
+
const found = deepScanPeerTransformers([path.join(pluginDir, '..'), profilesRoot])
|
|
4373
|
+
deep.foundDirs = found
|
|
4374
|
+
for (const d of found) {
|
|
4375
|
+
deep.integrated = true
|
|
4376
|
+
if (!engine._peerExtraDirs.includes(d)) engine._peerExtraDirs.push(d)
|
|
4377
|
+
try { if (engine._jsSemantic && engine._jsSemantic.addPeerDirCandidates) engine._jsSemantic.addPeerDirCandidates([d]) } catch (_) {}
|
|
4378
|
+
}
|
|
4379
|
+
} catch (_) { /* 扫描失败按未命中处理 */ }
|
|
4380
|
+
}
|
|
4381
|
+
const after = await engine.semanticAssetProbe()
|
|
4382
|
+
const recommendation = after.ready ? 'none'
|
|
4383
|
+
: (!after.assetPresent && !after.peerPresent) ? 'setup-both'
|
|
4384
|
+
: (!after.peerPresent) ? 'install-peer'
|
|
4385
|
+
: 'download-model'
|
|
4371
4386
|
return {
|
|
4372
|
-
assetPresent,
|
|
4373
|
-
peerPresent:
|
|
4374
|
-
ready:
|
|
4375
|
-
assetBytes:
|
|
4376
|
-
assetPath:
|
|
4387
|
+
assetPresent: after.assetPresent,
|
|
4388
|
+
peerPresent: after.peerPresent,
|
|
4389
|
+
ready: after.ready,
|
|
4390
|
+
assetBytes: after.assetBytes,
|
|
4391
|
+
assetPath: after.assetPath,
|
|
4392
|
+
resolvedTier: await engine.resolveSemanticTier(),
|
|
4393
|
+
deep,
|
|
4394
|
+
recommendation,
|
|
4377
4395
|
}
|
|
4378
4396
|
}
|
|
4379
4397
|
// 档位解析:lexical→C1 强制保底;其余(auto/js/python)在资产就绪时启用 C2 臂
|
|
@@ -4552,12 +4570,13 @@ export function apply(ctx, config) {
|
|
|
4552
4570
|
// 审查修复轮3:有效性判断必须是严格 session 身份 —— !!agent.session 会放行无身份对象
|
|
4553
4571
|
const hasAgent = !!(agent && engine.hasReliableSessionIdentity(agent))
|
|
4554
4572
|
if (hasAgent) {
|
|
4573
|
+
// 套娃防护(问题②):本插件 spawn 的子代理事件零处理——其 turn 结束不得再触发沉淀/路由,
|
|
4574
|
+
// 也不得刷新活动戳(v0.1.37 修正:后台沉淀/定时总结若刷新活动戳,会把真暂离误翻成「回归」)
|
|
4575
|
+
try { if (engine._ownSubagents && engine._ownSubagents.has(agent)) return } catch (e) {}
|
|
4555
4576
|
// 最后活动时间写入该 agent 自己的 runtime(不再落到 currentRuntime()/default)
|
|
4556
4577
|
try { engine.runtimeFor(agent).lastActiveAt = Date.now() } catch (e) {}
|
|
4557
4578
|
// 全局活动戳同步更新(暂离检测统揽全局,见 tickTime)
|
|
4558
4579
|
engine._globalLastActiveAt = Date.now()
|
|
4559
|
-
// 套娃防护(问题②):本插件 spawn 的子代理事件零处理——其 turn 结束不得再触发沉淀/路由
|
|
4560
|
-
try { if (engine._ownSubagents && engine._ownSubagents.has(agent)) return } catch (e) {}
|
|
4561
4580
|
try { engine.ingestAgentLifecycle(agent, 'agent/turn-stopping', { turn: payload && payload.turn, payload: { turn: payload && payload.turn } }) } catch (e) {}
|
|
4562
4581
|
}
|
|
4563
4582
|
diag('turn-stopping fired: turn=' + JSON.stringify(payload && payload.turn) + ' hasAgent=' + hasAgent + ' payloadKeys=' + (payload ? Object.keys(payload).join(',') : 'null'))
|
|
@@ -4946,6 +4965,15 @@ export function apply(ctx, config) {
|
|
|
4946
4965
|
} catch (e) { return writeJson(res, 500, { error: String(e && e.message ? e.message : e) }) }
|
|
4947
4966
|
},
|
|
4948
4967
|
},
|
|
4968
|
+
{
|
|
4969
|
+
kind: 'exact',
|
|
4970
|
+
path: API['semantic-deep-detect'],
|
|
4971
|
+
handler: async (req, res) => {
|
|
4972
|
+
// 打开即自动检测(0.1.37;GET 只读;loopback):快检+失败自动深扫+命中热接入+引导分流。
|
|
4973
|
+
if (!isLoopbackRequest(req)) return writeJson(res, 403, { error: 'forbidden: loopback-only' })
|
|
4974
|
+
try { return writeJson(res, 200, await engine.semanticDeepDetect()) } catch (e) { return writeJson(res, 500, { error: String(e && e.message ? e.message : e) }) }
|
|
4975
|
+
},
|
|
4976
|
+
},
|
|
4949
4977
|
{
|
|
4950
4978
|
kind: 'exact',
|
|
4951
4979
|
path: API['semantic-download'],
|
package/lib/semantic-js.js
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* 「要不要打断」仍属两车道策略(Python sidecar 在场时)。全部函数对非法输入 fail closed。
|
|
14
14
|
*/
|
|
15
15
|
import { createHash } from 'node:crypto'
|
|
16
|
-
import { existsSync, readFileSync, mkdirSync, renameSync, unlinkSync, writeFileSync, rmSync } from 'node:fs'
|
|
16
|
+
import { existsSync, readFileSync, mkdirSync, readdirSync, renameSync, statSync, unlinkSync, writeFileSync, rmSync } from 'node:fs'
|
|
17
17
|
import { fileURLToPath, pathToFileURL } from 'node:url'
|
|
18
|
+
import { createRequire } from 'node:module'
|
|
18
19
|
import path from 'node:path'
|
|
19
20
|
|
|
20
21
|
export const JS_SEMANTIC_ENGINE_VERSION = 'js_semantic_engine_v1'
|
|
@@ -74,14 +75,106 @@ function defaultModelsDirCandidates(pluginDir) {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
function defaultPeerDirCandidates(pluginDir) {
|
|
78
|
+
// pluginDir = <pkg>/lib(2026-09-02 issue 复核修正:此前上溯层级错位 → peerPresent 恒 false)。
|
|
79
|
+
// 静态候选仅作兜底,主路径是 resolvePeerTransformersDir 的真实解析:
|
|
80
|
+
// 1) lib/node_modules —— issue 临时 junction 绕过位(向后兼容)
|
|
81
|
+
// 2) <pkg>/node_modules —— 包内邻接位(lib 上 1 级再进 node_modules)
|
|
82
|
+
// 3) lib 上 3 级直拼 @huggingface —— 标准布局即 <root>/node_modules(pnpm hoisted/npm 提升),
|
|
83
|
+
// pnpm isolated 下即虚拟存储包内位 .pnpm/<hash>/node_modules
|
|
84
|
+
// 4) 开发树 artifacts
|
|
77
85
|
return [
|
|
78
86
|
path.join(pluginDir, 'node_modules', '@huggingface', 'transformers'),
|
|
79
|
-
|
|
80
|
-
path.join(pluginDir, '..', '..', '..', '
|
|
87
|
+
path.join(pluginDir, '..', 'node_modules', '@huggingface', 'transformers'),
|
|
88
|
+
path.join(pluginDir, '..', '..', '..', '@huggingface', 'transformers'),
|
|
81
89
|
path.join(pluginDir, '..', 'artifacts', 'm7-live-pre', 'js-semantic-trial', 'node_modules', '@huggingface', 'transformers'),
|
|
82
90
|
]
|
|
83
91
|
}
|
|
84
92
|
|
|
93
|
+
/**
|
|
94
|
+
* peer 探测(2026-09-02 issue 修正):真实解析优先 —— createRequire 从 lib/ 起走 Node 标准
|
|
95
|
+
* 解析,天然覆盖 npm/pnpm(hoisted/isolated 虚拟存储)/junction 全部布局,且不执行模块本体
|
|
96
|
+
* (require.resolve 只解析不加载);静态候选仅作 exports 损坏等极端情形的兜底;
|
|
97
|
+
* extraDirs = 深度扫描(semanticDeepDetect)热接入的额外目录,最后兜底检查。
|
|
98
|
+
* 返回命中的包目录,''=未找到。
|
|
99
|
+
*/
|
|
100
|
+
export function resolvePeerTransformersDir(pluginDir, extraDirs) {
|
|
101
|
+
try {
|
|
102
|
+
const req = createRequire(path.join(pluginDir, 'noop.js'))
|
|
103
|
+
const entry = req.resolve('@huggingface/transformers')
|
|
104
|
+
// entry 是包 main 文件(可能在任意子目录,如 dist/transformers.node.cjs):
|
|
105
|
+
// 从 entry 向上走到 package.json 所在层 = 包目录
|
|
106
|
+
if (entry && existsSync(entry)) {
|
|
107
|
+
let dir = path.dirname(entry)
|
|
108
|
+
while (dir && !existsSync(path.join(dir, 'package.json'))) {
|
|
109
|
+
const up = path.dirname(dir)
|
|
110
|
+
if (up === dir) { dir = ''; break }
|
|
111
|
+
dir = up
|
|
112
|
+
}
|
|
113
|
+
if (dir) return dir
|
|
114
|
+
}
|
|
115
|
+
} catch (_) { /* 静态候选兜底 */ }
|
|
116
|
+
const hit = defaultPeerDirCandidates(pluginDir).find((c) => existsSync(c))
|
|
117
|
+
if (hit) return hit
|
|
118
|
+
for (const d of Array.isArray(extraDirs) ? extraDirs : []) {
|
|
119
|
+
if (typeof d === 'string' && d && existsSync(d)) return d
|
|
120
|
+
}
|
|
121
|
+
return ''
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 深度扫描(0.1.37「打开即自动检测」;issue #14 后续):零依赖手扫常见安装根。
|
|
126
|
+
* 每个 root 探两层:root 自身的 node_modules(直传 profile 根/包根时命中)+ 一级子目录
|
|
127
|
+
* (直传 ~/.dsh/profiles 时枚举各 profile);每个落位再探 node_modules/@huggingface/
|
|
128
|
+
* transformers、pnpm 虚拟存储 .pnpm/node_modules/... 与 .pnpm/@huggingface+transformers@版本
|
|
129
|
+
* /node_modules/...(isolated 模式包体落位)。返回存在的包目录列表(去重,保持扫描序)。
|
|
130
|
+
*/
|
|
131
|
+
export function deepScanPeerTransformers(roots) {
|
|
132
|
+
const out = []
|
|
133
|
+
const seen = new Set()
|
|
134
|
+
const push = (p) => { if (p && !seen.has(p) && existsSync(p)) { seen.add(p); out.push(p) } }
|
|
135
|
+
const probeDir = (base) => {
|
|
136
|
+
if (!base || typeof base !== 'string') return
|
|
137
|
+
push(path.join(base, 'node_modules', '@huggingface', 'transformers'))
|
|
138
|
+
push(path.join(base, 'node_modules', '.pnpm', 'node_modules', '@huggingface', 'transformers'))
|
|
139
|
+
const pnpmDir = path.join(base, 'node_modules', '.pnpm')
|
|
140
|
+
let entries = []
|
|
141
|
+
try { entries = readdirSync(pnpmDir) } catch (_) { /* base 无 .pnpm 虚拟存储 */ }
|
|
142
|
+
for (const e of entries) {
|
|
143
|
+
if (/^@huggingface\+transformers@/.test(e)) push(path.join(pnpmDir, e, 'node_modules', '@huggingface', 'transformers'))
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
for (const root of Array.isArray(roots) ? roots : []) {
|
|
147
|
+
if (!root || typeof root !== 'string') continue
|
|
148
|
+
probeDir(root)
|
|
149
|
+
let children = []
|
|
150
|
+
try { children = readdirSync(root) } catch (_) { /* root 不可枚举 */ }
|
|
151
|
+
for (const c of children.slice(0, 64)) probeDir(path.join(root, c))
|
|
152
|
+
}
|
|
153
|
+
return out
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* semanticAssetProbe 共享实现(index.js 的 status API / 档位解析 / 引导卡同源):
|
|
158
|
+
* 模型资产=发行包 lib/models 优先,其次开发树;peer=resolvePeerTransformersDir。
|
|
159
|
+
* extraDirs 透传给 peer 探测(深度扫描热接入位)。返回形状与 v0.1.36 完全一致。
|
|
160
|
+
*/
|
|
161
|
+
export function probeJsSemanticAssets(pluginDir, extraDirs) {
|
|
162
|
+
const modelCands = [
|
|
163
|
+
path.join(pluginDir, 'models', E5_MODELS_SUBDIR, 'onnx', 'model_quantized.onnx'),
|
|
164
|
+
path.join(pluginDir, '..', 'artifacts', 'm7-live-pre', 'js-semantic-trial', 'models', E5_MODELS_SUBDIR, 'onnx', 'model_quantized.onnx'),
|
|
165
|
+
]
|
|
166
|
+
const modelOnnx = modelCands.find((c) => existsSync(c)) || modelCands[0]
|
|
167
|
+
const assetPresent = existsSync(modelOnnx)
|
|
168
|
+
const peerDir = resolvePeerTransformersDir(pluginDir, extraDirs)
|
|
169
|
+
return {
|
|
170
|
+
assetPresent,
|
|
171
|
+
peerPresent: Boolean(peerDir),
|
|
172
|
+
ready: Boolean(assetPresent && peerDir),
|
|
173
|
+
assetBytes: assetPresent ? statSync(modelOnnx).size : 0,
|
|
174
|
+
assetPath: modelOnnx,
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
85
178
|
async function importPeerTransformers(peerDirs) {
|
|
86
179
|
try {
|
|
87
180
|
return await import('@huggingface/transformers') // 发行包:peer 邻接安装
|
|
@@ -213,6 +306,12 @@ export function createJsSemanticEnginePre(opts = {}) {
|
|
|
213
306
|
embedding: !!rebuilding,
|
|
214
307
|
}
|
|
215
308
|
},
|
|
309
|
+
/** 深度扫描热接入(0.1.37):把扫描发现的额外 peer 目录并入加载候选(去重,立即生效)。 */
|
|
310
|
+
addPeerDirCandidates(dirs) {
|
|
311
|
+
for (const d of Array.isArray(dirs) ? dirs : []) {
|
|
312
|
+
if (typeof d === 'string' && d && !peerDirCands.includes(d)) peerDirCands.push(d)
|
|
313
|
+
}
|
|
314
|
+
},
|
|
216
315
|
/**
|
|
217
316
|
* 对语料做稠密排名。返回 {miv, scores:Map(memoryId→cosine)};失败返回 null(调用方回退词法)。
|
|
218
317
|
*/
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@a9i5k4/dsh-auto-memory",
|
|
3
3
|
"description": "主动联想记忆插件:记忆不靠模型调用,自己被唤回——Host 观察情境,NLP+向量化双轨检索,固定边界注入不破坏前缀缓存。三层记忆自动沉淀、欢迎向导、唤起回顾、无人值守、AI 问候与反思、日历、跨工具记忆继承。Proactive associative memory for DSH: zero-call recall, three-layer auto-consolidation, welcome tour, unattended mode.",
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.37",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "lib/index.js",
|
|
7
7
|
"exports": {
|