lingshu-skill 5.10.0 → 5.14.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/CHANGELOG.md +120 -0
- package/README.md +69 -3
- package/SKILL.md +3 -1
- package/assets/panel.html +133 -7
- package/docs//345/200/237/351/211/264/345/276/205/345/212/236-DSH/346/217/222/344/273/266/347/224/237/346/200/201.md +224 -0
- package/docs//350/277/233/345/261/225/344/270/216/345/276/205/345/212/236.md +26 -1
- package/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +12 -12
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +120 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +69 -3
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +3 -1
- package/scripts/astrbot_plugin_lingshu/engine/assets/panel.html +133 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/cli.py +49 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +7 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/emotion.py +75 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +5055 -4759
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +305 -16
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_server.py +131 -7
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_settings.py +6 -0
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_update.py +38 -9
- package/scripts/cli.py +49 -3
- package/scripts/core.py +7 -0
- package/scripts/emotion.py +75 -1
- package/scripts/growth.py +5055 -4759
- package/scripts/memory.py +305 -16
- package/scripts/panel_server.py +131 -7
- package/scripts/panel_settings.py +6 -0
- package/scripts/panel_update.py +38 -9
|
@@ -679,6 +679,11 @@
|
|
|
679
679
|
<button class="btn" id="btn-emo-feel">记下</button>
|
|
680
680
|
</div>
|
|
681
681
|
<div class="sub" id="emo-arc" style="margin-top:12px"></div>
|
|
682
|
+
<!-- v5.12 心情时间线:每轮自动生成的情绪事件流水(genesis=True) -->
|
|
683
|
+
<div style="margin-top:10px">
|
|
684
|
+
<div class="sub" style="margin-bottom:4px">心情流水(最近 50 条自动记录,hover 看强度)</div>
|
|
685
|
+
<div id="emo-timeline" style="display:flex;flex-wrap:wrap;gap:6px;max-height:180px;overflow-y:auto;padding:6px 4px;border:1px dashed rgba(200,200,200,.25);border-radius:6px"></div>
|
|
686
|
+
</div>
|
|
682
687
|
</div>
|
|
683
688
|
<div class="card">
|
|
684
689
|
<h2>六欲</h2>
|
|
@@ -951,6 +956,13 @@
|
|
|
951
956
|
<div id="diag-body" style="margin-top:10px"><div class="empty">加载中…</div></div>
|
|
952
957
|
</div>
|
|
953
958
|
|
|
959
|
+
<!-- v5.12 体检历史:灵枢自己的成长账本(doctor 每跑一次追加一条,按天聚合) -->
|
|
960
|
+
<div class="card" style="margin-bottom:14px">
|
|
961
|
+
<h2 style="margin-bottom:4px">灵枢体检历史(近 30 天)</h2>
|
|
962
|
+
<div class="sub">doctor 每跑一次就存一条,按天汇总 PASS / WARN / FAIL。红柱越高越糟;绿柱越高越好。</div>
|
|
963
|
+
<div id="doctor-history" style="margin-top:10px"></div>
|
|
964
|
+
</div>
|
|
965
|
+
|
|
954
966
|
<!-- 数据目录(查看 / 迁移) -->
|
|
955
967
|
<div class="card" style="margin-bottom:14px">
|
|
956
968
|
<div class="row" style="flex-wrap:wrap">
|
|
@@ -1170,6 +1182,16 @@ const progress = topProgress();
|
|
|
1170
1182
|
<button class="btn hidden" id="upd-dsh-force" style="background:#b03030">强制更新 DSH 副本</button>
|
|
1171
1183
|
</div>
|
|
1172
1184
|
</div>
|
|
1185
|
+
<div class="row" id="upd-src-row" style="margin-top:14px;align-items:center;gap:10px;display:none">
|
|
1186
|
+
<span class="sub" style="margin:0">下载源</span>
|
|
1187
|
+
<select id="upd-source" style="padding:5px 9px;border-radius:8px;border:1px solid var(--line);
|
|
1188
|
+
background:var(--surface);color:var(--text)">
|
|
1189
|
+
<option value="auto">跟随设置(npm 优先)</option>
|
|
1190
|
+
<option value="npm">npm 官方包</option>
|
|
1191
|
+
<option value="git">Gitee / GitHub</option>
|
|
1192
|
+
</select>
|
|
1193
|
+
<span class="sub" id="upd-npm-info" style="margin:0"></span>
|
|
1194
|
+
</div>
|
|
1173
1195
|
<div class="row" style="margin-top:16px">
|
|
1174
1196
|
<button class="ghost" id="upd-close">关闭</button>
|
|
1175
1197
|
<button class="btn hidden" id="upd-apply">立即更新</button>
|
|
@@ -1402,6 +1424,10 @@ function renderOverview(){
|
|
|
1402
1424
|
+ (ov.source && ov.source.version ? `<br><br><b>代码版本</b><br>v${esc(ov.source.version)}<br><span style="font-size:10px">${esc(ov.source.script_dir || "")}</span>` : "")
|
|
1403
1425
|
+ `<br><br><b>模型档位</b><br>${esc(tierLabel(ov.model_tier))}`
|
|
1404
1426
|
+ `<br><br><b>会话模式</b><br>${esc(modeLabel(ov.mode))} <a href="javascript:void 0" data-mode-cycle style="color:var(--amber)">切换</a>`
|
|
1427
|
+
// v5.12 内心独白:灵枢此刻对自己的简短态度评价(纯模板,LLM-free)
|
|
1428
|
+
+ (ov.inner_voice ? `<br><br><b style="font-style:italic;color:var(--sub)">灵枢自语</b><br><span style="font-style:italic;color:var(--sub);font-size:11px;opacity:.85">${esc(ov.inner_voice)}</span>` : "")
|
|
1429
|
+
// v5.12 灵枢健康度:0-100,按最近 7 天 doctor FAIL/WARN + failures.jsonl 条数加权扣分
|
|
1430
|
+
+ (typeof ov.health_score === "number" ? `<br><br><b>灵枢健康度</b><br>${ov.health_score} / 100${ov.health_score < 60 ? ` <b style="color:var(--red)">偏低</b>` : ov.health_score < 80 ? ` <b style="color:var(--amber)">一般</b>` : ""}` : "")
|
|
1405
1431
|
+ (rcTotal ? `<br><br><b style="color:#e66450">待审核 ${rcTotal} 项</b><br>记忆 ${rc.memories || 0} · 知识 ${rc.knowledge || 0} · 人格 ${rc.persona || 0}` : "")
|
|
1406
1432
|
+ ((ov.persona_drift && ov.persona_drift.alert) ? `<br><br><b style="color:#e66450">人格漂移偏大</b><br><a href="#" data-goto="persona" style="color:var(--amber)">去人格页查看/回滚 →</a>` : "")
|
|
1407
1433
|
+ (ov.readonly ? `<br><b style="color:var(--red)">只读模式</b>` : "")
|
|
@@ -1601,6 +1627,52 @@ function renderMood(){
|
|
|
1601
1627
|
: `<div class="empty">没有正在起作用的情绪</div>`;
|
|
1602
1628
|
}
|
|
1603
1629
|
renderDesires(ov);
|
|
1630
|
+
// v5.12 心情时间线:每轮自动生成的情绪事件流水
|
|
1631
|
+
const tlEl = $("emo-timeline");
|
|
1632
|
+
if (tlEl) {
|
|
1633
|
+
const tl = ov.emotion_timeline || [];
|
|
1634
|
+
if (!tl.length) {
|
|
1635
|
+
tlEl.innerHTML = `<span class="sub" style="opacity:.6">还没有自动情绪记录——通常 extract / 共情 / 认知评价会自动产生</span>`;
|
|
1636
|
+
} else {
|
|
1637
|
+
tlEl.innerHTML = tl.map(r => {
|
|
1638
|
+
const color = moodColor({ category: r.category, intensity: r.intensity });
|
|
1639
|
+
const title = `${r.label} · 强度 ${Math.round((r.intensity || 0) * 100)}%${r.about ? " · 关于 " + r.about : ""}${r.why ? " — " + r.why : ""} · ${r.time}`;
|
|
1640
|
+
return `<span class="chip" style="background:${color};border-color:${color};color:#fff;cursor:help" title="${esc(title)}">${esc(r.label)}</span>`;
|
|
1641
|
+
}).join("");
|
|
1642
|
+
}
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
// v5.12 体检历史(doctor-history.jsonl):按天聚合的 PASS/WARN/FAIL 分布,纯 CSS 堆叠条
|
|
1647
|
+
function renderDoctorHistory(){
|
|
1648
|
+
const el = $("doctor-history"); if (!el) return;
|
|
1649
|
+
const ov = S.ov; if (!ov) { el.innerHTML = `<div class="empty">切到「概览」再回来看(数据在 overview 接口里)</div>`; return; }
|
|
1650
|
+
const hist = ov.doctor_history || [];
|
|
1651
|
+
if (!hist.length) {
|
|
1652
|
+
el.innerHTML = `<div class="empty">还没跑过 doctor(跑一次「python scripts/brain.py doctor」之后会自动追加一条)</div>`;
|
|
1653
|
+
return;
|
|
1654
|
+
}
|
|
1655
|
+
const maxTotal = Math.max(...hist.map(d => d.total));
|
|
1656
|
+
el.innerHTML = `<div style="display:flex;align-items:flex-end;gap:6px;height:80px;margin-top:6px;padding:0 4px">`
|
|
1657
|
+
+ hist.map(d => {
|
|
1658
|
+
const h = Math.max(2, Math.round((d.total / maxTotal) * 70));
|
|
1659
|
+
const fh = Math.round((d.fails / maxTotal) * 70);
|
|
1660
|
+
const wh = Math.round((d.warns / maxTotal) * 70);
|
|
1661
|
+
const ph = h - fh - wh;
|
|
1662
|
+
const tooltip = `${d.date} · PASS ${d.passes} / WARN ${d.warns} / FAIL ${d.fails}`;
|
|
1663
|
+
return `<div style="flex:1;min-width:18px;display:flex;flex-direction:column-reverse;height:${h}px;gap:1px" title="${esc(tooltip)}">`
|
|
1664
|
+
+ `<div style="flex:${ph};background:rgba(120,180,120,.85);min-height:0;border-radius:2px 2px 0 0"></div>`
|
|
1665
|
+
+ (d.warns ? `<div style="height:${wh}px;background:rgba(220,180,80,.85);min-height:1px;border-radius:1px"></div>` : "")
|
|
1666
|
+
+ (d.fails ? `<div style="height:${fh}px;background:rgba(210,100,90,.85);min-height:1px;border-radius:1px"></div>` : "")
|
|
1667
|
+
+ `</div>`;
|
|
1668
|
+
}).join("")
|
|
1669
|
+
+ `</div>`
|
|
1670
|
+
+ `<div style="display:flex;gap:6px;font-size:10px;color:var(--sub);margin-top:4px">`
|
|
1671
|
+
+ `<span style="color:rgba(120,180,120,.85)">■</span>PASS `
|
|
1672
|
+
+ `<span style="color:rgba(220,180,80,.85)">■</span>WARN `
|
|
1673
|
+
+ `<span style="color:rgba(210,100,90,.85)">■</span>FAIL `
|
|
1674
|
+
+ `<span style="margin-left:auto">共 ${hist.length} 天 · ${hist.reduce((s,d)=>s+d.total,0)} 次</span>`
|
|
1675
|
+
+ `</div>`;
|
|
1604
1676
|
}
|
|
1605
1677
|
|
|
1606
1678
|
function renderDesires(ov){
|
|
@@ -3188,7 +3260,7 @@ function switchTab(tab){
|
|
|
3188
3260
|
if (tab === "logs") loadLogs();
|
|
3189
3261
|
// 诊断页有两张随时间变化的卡:体检结果 + 数据目录位置,进页面时一起刷(以前只刷体检,
|
|
3190
3262
|
// 数据目录卡靠一段 class 判断写错的 MutationObserver,永远停在「加载中…」)
|
|
3191
|
-
if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); }
|
|
3263
|
+
if (tab === "diag") { loadDiagnostics(); loadHomeInfo(); renderDoctorHistory(); }
|
|
3192
3264
|
if (tab === "persona") { loadSnapshots(); loadPersonaSuggest(); } // 切到人格页时顺手刷快照列表与画像归纳建议
|
|
3193
3265
|
// 概览/心情/梦 三页的数据都在 overview 里(心情与六欲是按时间衰减的活数值)。
|
|
3194
3266
|
// 以前只靠 30 秒轮询 + document.hidden 跳过,切过去可能看到最多 30 秒前的旧值。
|
|
@@ -4796,7 +4868,9 @@ async function checkUpdate(auto){
|
|
|
4796
4868
|
dot.style.display = "inline-block";
|
|
4797
4869
|
// auto 模式只点亮红点不弹窗:自动检查的本意是"不打扰",弹窗会打断用户手头操作
|
|
4798
4870
|
if (auto) return;
|
|
4799
|
-
const srcLabel = r.source_kind === "
|
|
4871
|
+
const srcLabel = r.source_kind === "npm" || r.source === "npm"
|
|
4872
|
+
? "来源:npm 官方包" + (r.npm && r.npm.version ? "(v" + r.npm.version + ")" : "")
|
|
4873
|
+
: r.source_kind === "dev" ? "来源:本地开发仓库"
|
|
4800
4874
|
: r.source_kind === "remote" ? "来源:Gitee 远程"
|
|
4801
4875
|
: r.source === "gitee" ? "来源:Gitee 远程"
|
|
4802
4876
|
: r.source === "github" ? "来源:GitHub 远程"
|
|
@@ -4860,6 +4934,42 @@ async function checkUpdate(auto){
|
|
|
4860
4934
|
}
|
|
4861
4935
|
function showUpdModal(title, detail, canApply){
|
|
4862
4936
|
$("upd-title").textContent = title;
|
|
4937
|
+
// 有更新时才显示"下载源"选择:npm 官方包 vs Gitee/GitHub,各有所长
|
|
4938
|
+
const srcRow = $("upd-src-row");
|
|
4939
|
+
if (srcRow) srcRow.style.display = canApply ? "flex" : "none";
|
|
4940
|
+
// 记住上次选的下载源:用户特意选了 npm/git,下次不该又跳回"跟随设置"
|
|
4941
|
+
const sel = $("upd-source");
|
|
4942
|
+
if (sel && !sel.dataset.inited) {
|
|
4943
|
+
sel.dataset.inited = "1";
|
|
4944
|
+
try {
|
|
4945
|
+
const last = localStorage.getItem("ls-upd-source");
|
|
4946
|
+
if (last) sel.value = last;
|
|
4947
|
+
} catch (_) {}
|
|
4948
|
+
// 2026-11-25:切换下载源时重新查一次 update_check——换源就换说明,
|
|
4949
|
+
// 之前的 changelog / 版本号都是上一个源的,看了会误导用户。
|
|
4950
|
+
sel.addEventListener("change", () => {
|
|
4951
|
+
try { localStorage.setItem("ls-upd-source", sel.value); } catch (_) {}
|
|
4952
|
+
checkUpdate(false);
|
|
4953
|
+
});
|
|
4954
|
+
}
|
|
4955
|
+
const npmInfo = $("upd-npm-info");
|
|
4956
|
+
if (npmInfo) {
|
|
4957
|
+
const nm = updLastCheck && updLastCheck.npm;
|
|
4958
|
+
const ne = updLastCheck && updLastCheck.npm_error;
|
|
4959
|
+
if (nm && nm.version) {
|
|
4960
|
+
const kb = nm.unpacked ? ",解包约 " + Math.round(Number(nm.unpacked) / 1024) + " KB" : "";
|
|
4961
|
+
npmInfo.textContent = "npm 最新 v" + nm.version + kb + (nm.cached ? "(缓存)" : "");
|
|
4962
|
+
npmInfo.style.color = "";
|
|
4963
|
+
} else if (ne) {
|
|
4964
|
+
// 2026-11-25:dev 模式下 npm 版本查询失败(限流/网络/短暂挂掉),
|
|
4965
|
+
// 直接透传原因给用户——让他知道"npm 不是没有新版,是我暂时查不到"。
|
|
4966
|
+
npmInfo.textContent = "npm 版本查询失败:" + ne;
|
|
4967
|
+
npmInfo.style.color = "var(--red-text)";
|
|
4968
|
+
} else {
|
|
4969
|
+
npmInfo.textContent = "";
|
|
4970
|
+
npmInfo.style.color = "";
|
|
4971
|
+
}
|
|
4972
|
+
}
|
|
4863
4973
|
$("upd-detail").innerHTML = String(detail).replace(/\n/g, "<br>");
|
|
4864
4974
|
$("upd-detail").parentElement.style.maxHeight = "60vh"; // 更新说明可能很长,限高
|
|
4865
4975
|
$("upd-detail").parentElement.style.overflowY = "auto";
|
|
@@ -4967,13 +5077,26 @@ $("upd-apply").addEventListener("click", async () => {
|
|
|
4967
5077
|
updApplyBusy = true;
|
|
4968
5078
|
try {
|
|
4969
5079
|
// 更新前确认:明确标注来源类型与目标路径,杜绝"有更新但点了无响应"的疑虑
|
|
4970
|
-
|
|
5080
|
+
// 用户在弹窗里选的下载源(auto=跟随设置)。显式选了就覆盖检查时的来源说明。
|
|
5081
|
+
const pickedSrc = ($("upd-source") && $("upd-source").value) || "auto";
|
|
5082
|
+
const kindTxt = pickedSrc === "npm" ? "从 npm 官方包更新"
|
|
5083
|
+
: pickedSrc === "git" ? "从 Gitee / GitHub 更新"
|
|
5084
|
+
: updLastCheck.source_kind === "npm" ? "从 npm 官方包更新(跟随设置)"
|
|
5085
|
+
: updLastCheck.source_kind === "dev" ? "从本地开发仓库同步"
|
|
4971
5086
|
: updLastCheck.source_kind === "remote" || updLastCheck.source_kind === "gitee"
|
|
4972
5087
|
|| updLastCheck.source_kind === "github" ? "从远程仓库(Gitee/GitHub)更新"
|
|
4973
5088
|
: "从已安装本地版本同步";
|
|
4974
5089
|
const targetTxt = updLastCheck.target_path ? "\n\n目标路径:" + updLastCheck.target_path : "";
|
|
5090
|
+
// 2026-11-25:选了 npm 源但 npm 版本查询失败——可能是限流、网络抖动、npm 短暂挂掉。
|
|
5091
|
+
// 让用户明确知道"我查不到 npm 上是什么版本,但仍会强制从 npm 拉取",
|
|
5092
|
+
// 避免"查不到新版所以没点"或"点了更新发现版本号比预期旧"的困惑。
|
|
5093
|
+
let npmWarn = "";
|
|
5094
|
+
if ((pickedSrc === "npm" || pickedSrc === "auto") && updLastCheck.npm_error) {
|
|
5095
|
+
npmWarn = "\n\n⚠ 注意:npm 版本查询暂时失败(" + esc(updLastCheck.npm_error)
|
|
5096
|
+
+ "),将直接拉取 npm 官方包最新版本。";
|
|
5097
|
+
}
|
|
4975
5098
|
if (!confirm("确认更新灵枢本体到 " + (updLastCheck.source_version || updLastCheck.version ? "v" + (updLastCheck.source_version || updLastCheck.version) + " " : "")
|
|
4976
|
-
+ "?\n\n方式:" + kindTxt + targetTxt
|
|
5099
|
+
+ "?\n\n方式:" + kindTxt + targetTxt + npmWarn
|
|
4977
5100
|
+ "\n\n(更新采用原子化部署:先备份再替换,失败自动回滚,记忆数据不受影响)")) return;
|
|
4978
5101
|
btn.disabled = true;
|
|
4979
5102
|
btn.classList.add("loading");
|
|
@@ -4985,7 +5108,8 @@ $("upd-apply").addEventListener("click", async () => {
|
|
|
4985
5108
|
let r;
|
|
4986
5109
|
try {
|
|
4987
5110
|
r = await post("/api/skill", {action: "install", name: "lingshu",
|
|
4988
|
-
force: true,
|
|
5111
|
+
force: true, source: pickedSrc === "auto" ? undefined : pickedSrc,
|
|
5112
|
+
yes: updRiskAccepted ? true : undefined},
|
|
4989
5113
|
{signal: AbortSignal.timeout(APPLY_TIMEOUT)});
|
|
4990
5114
|
} catch (netErr) {
|
|
4991
5115
|
// 网络层失败(超时/断连):给一次自动重试的机会——远程源拉取对匿名风控
|
|
@@ -4994,7 +5118,8 @@ $("upd-apply").addEventListener("click", async () => {
|
|
|
4994
5118
|
"\n\n可能是网络抖动或匿名限流。要自动重试一次吗?(点取消放弃本次更新)")) throw netErr;
|
|
4995
5119
|
btn.textContent = "重试中…";
|
|
4996
5120
|
r = await post("/api/skill", {action: "install", name: "lingshu",
|
|
4997
|
-
force: true,
|
|
5121
|
+
force: true, source: pickedSrc === "auto" ? undefined : pickedSrc,
|
|
5122
|
+
yes: updRiskAccepted ? true : undefined},
|
|
4998
5123
|
{signal: AbortSignal.timeout(APPLY_TIMEOUT)});
|
|
4999
5124
|
}
|
|
5000
5125
|
const st = r.result && r.result.state;
|
|
@@ -5012,7 +5137,8 @@ $("upd-apply").addEventListener("click", async () => {
|
|
|
5012
5137
|
if (st === "failed" || r.ok === false) throw new Error((r.result && r.result.error) || "更新失败");
|
|
5013
5138
|
progress.set(100);
|
|
5014
5139
|
updRiskAccepted = false; // 下次更新重新走一遍风险告知
|
|
5015
|
-
|
|
5140
|
+
const doneSrc = (r.result && r.result.source) || pickedSrc;
|
|
5141
|
+
toast("灵枢本体已更新(来源 " + doneSrc + ")——重启面板(关掉再开)后新版本才生效");
|
|
5016
5142
|
$("upd-modal").classList.add("hidden");
|
|
5017
5143
|
const dot2 = $("upd-dot"); if (dot2) dot2.style.display = "none";
|
|
5018
5144
|
await loadWS();
|
|
@@ -1608,6 +1608,9 @@ def _main(argv=None) -> int:
|
|
|
1608
1608
|
p_au.add_argument("--check", action="store_true", help="只检查有没有新版本,不安装")
|
|
1609
1609
|
p_au.add_argument("--force", action="store_true", help="忽略 auto_update 开关强制执行一次")
|
|
1610
1610
|
p_au.add_argument("--json", action="store_true")
|
|
1611
|
+
p_au.add_argument("--source", choices=["auto", "npm", "git"], default="auto",
|
|
1612
|
+
help="下载源:auto(npm 优先,失败退回 Gitee/GitHub)/ npm(只走 npm)/ "
|
|
1613
|
+
"git(只走 Gitee/GitHub)")
|
|
1611
1614
|
|
|
1612
1615
|
# 附录 C P2 收尾:触发 + 落盘 + 回滚
|
|
1613
1616
|
p_ss = sub.add_parser("session-summary",
|
|
@@ -1974,6 +1977,10 @@ def _main(argv=None) -> int:
|
|
|
1974
1977
|
"shape-audit", help="六爻位体检(只读):64 格状态分布 + 当位/得中/有应违规")
|
|
1975
1978
|
p_shape.add_argument("--limit", type=int, default=2000)
|
|
1976
1979
|
p_shape.add_argument("--json", action="store_true")
|
|
1980
|
+
p_show = mem_sub.add_parser(
|
|
1981
|
+
"show", help="按 id 看整条记忆(支持唯一前缀/短号;索引法注入后取正文用这个)")
|
|
1982
|
+
p_show.add_argument("id", help="完整 id、hash 段前缀(8 位)或 m_ 短号")
|
|
1983
|
+
p_show.add_argument("--json", action="store_true")
|
|
1977
1984
|
mem_sub.add_parser("trash-list", help="看软删除台账(purge 删掉的记忆留底,可恢复)")
|
|
1978
1985
|
p_mem_tr = mem_sub.add_parser("trash-restore", help="从软删除台账恢复一条记忆")
|
|
1979
1986
|
p_mem_tr.add_argument("id", help="记忆 id")
|
|
@@ -2655,15 +2662,17 @@ def _main(argv=None) -> int:
|
|
|
2655
2662
|
|
|
2656
2663
|
if args.cmd == "auto-update":
|
|
2657
2664
|
import panel_update as _pu
|
|
2665
|
+
_src = None if args.source == "auto" else args.source
|
|
2658
2666
|
if args.check:
|
|
2659
|
-
res = _pu.check(force_pull=True)
|
|
2667
|
+
res = _pu.check(force_pull=True, source=_src)
|
|
2660
2668
|
if args.json:
|
|
2661
2669
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2662
2670
|
return 0
|
|
2663
2671
|
print(f"当前 {res.get('current')} / 最新 {res.get('latest')} "
|
|
2672
|
+
f"(来源 {res.get('source') or 'auto'})"
|
|
2664
2673
|
f"→ {'有新版可更新' if res.get('update_available') else '已是最新'}")
|
|
2665
2674
|
return 0
|
|
2666
|
-
res = _pu.run(force=args.force)
|
|
2675
|
+
res = _pu.run(force=args.force, source=_src)
|
|
2667
2676
|
if args.json:
|
|
2668
2677
|
print(json.dumps(res, ensure_ascii=False, indent=2))
|
|
2669
2678
|
return 0 if res.get("ok") else 1
|
|
@@ -2671,7 +2680,8 @@ def _main(argv=None) -> int:
|
|
|
2671
2680
|
print(f"跳过:{res.get('reason')}")
|
|
2672
2681
|
return 0
|
|
2673
2682
|
if res.get("ok"):
|
|
2674
|
-
print(f"
|
|
2683
|
+
print(f"已更新(来源 {res.get('source') or 'auto'}):"
|
|
2684
|
+
f"{res.get('from')} → {res.get('to')};更新前备份 {res.get('backup')}")
|
|
2675
2685
|
return 0
|
|
2676
2686
|
print(f"[错误] {res.get('reason')}", file=sys.stderr)
|
|
2677
2687
|
return 1
|
|
@@ -4366,6 +4376,22 @@ def _main(argv=None) -> int:
|
|
|
4366
4376
|
except Exception as e:
|
|
4367
4377
|
checks.append(("desktop-shortcut", "WARN", f"自检失败:{e}"))
|
|
4368
4378
|
|
|
4379
|
+
# v5.12:把本次体检结果追加到 doctor-history.jsonl——灵枢自己的成长账本,
|
|
4380
|
+
# 面板"体检历史"页签和未来的健康度分数用它。append-only,单条 try/except 吞掉。
|
|
4381
|
+
try:
|
|
4382
|
+
_dr = {
|
|
4383
|
+
"ts": int(time.time()),
|
|
4384
|
+
"fails": sum(1 for _, s, _ in checks if s == "FAIL"),
|
|
4385
|
+
"warns": sum(1 for _, s, _ in checks if s == "WARN"),
|
|
4386
|
+
"passes": sum(1 for _, s, _ in checks if s == "PASS"),
|
|
4387
|
+
"checks": {n: s for n, s, _ in checks},
|
|
4388
|
+
}
|
|
4389
|
+
_dh_path = (globals().get("brain") or sys.modules.get("brain")).HOME / "doctor-history.jsonl"
|
|
4390
|
+
with open(_dh_path, "a", encoding="utf-8") as _fh:
|
|
4391
|
+
_fh.write(json.dumps(_dr, ensure_ascii=False) + "\n")
|
|
4392
|
+
except Exception as _e:
|
|
4393
|
+
brain.log_event("doctor", f"doctor-history 追加失败:{_e}", level="warn")
|
|
4394
|
+
|
|
4369
4395
|
fails = sum(1 for _, s, _ in checks if s == "FAIL")
|
|
4370
4396
|
warns = sum(1 for _, s, _ in checks if s == "WARN")
|
|
4371
4397
|
if args.json:
|
|
@@ -5168,6 +5194,26 @@ def _main(argv=None) -> int:
|
|
|
5168
5194
|
if r["frozen"]:
|
|
5169
5195
|
print(" 冻结后不参与召回/启动注入/做梦合并,用 show 仍可查看;解冻立即恢复。")
|
|
5170
5196
|
return 0
|
|
5197
|
+
# 按 id 取整条记忆(索引法注入后取正文的正路;支持唯一前缀)
|
|
5198
|
+
if mem_cmd == "show":
|
|
5199
|
+
import memory as _mem
|
|
5200
|
+
r = _mem.fetch(args.id)
|
|
5201
|
+
if not r.get("ok"):
|
|
5202
|
+
print(f"[错误] {r.get('reason')}", file=sys.stderr)
|
|
5203
|
+
return 1
|
|
5204
|
+
m = r["memory"]
|
|
5205
|
+
if args.json:
|
|
5206
|
+
print(json.dumps(m, ensure_ascii=False, indent=2))
|
|
5207
|
+
return 0
|
|
5208
|
+
print(f"{m.get('id')} [{m.get('layer')}] {m.get('kind')} "
|
|
5209
|
+
f"★{_num(m.get('importance'), 0.5) * 5:.0f}")
|
|
5210
|
+
if m.get("index"):
|
|
5211
|
+
print(f" 索引:{m['index']}")
|
|
5212
|
+
print(f" {display_text(m)}")
|
|
5213
|
+
if m.get("tags"):
|
|
5214
|
+
print(f" 标签:{'、'.join(m['tags'])}")
|
|
5215
|
+
return 0
|
|
5216
|
+
|
|
5171
5217
|
# 六爻位体检(只读):把六元特征映射到 64 格,用当位/得中/有应判结构
|
|
5172
5218
|
if mem_cmd == "shape-audit":
|
|
5173
5219
|
import shape_audit as _sa
|
|
@@ -340,6 +340,13 @@ DEFAULT_CONFIG = {
|
|
|
340
340
|
# 面板空闲多少分钟自动退出(0 = 永不)。页面挂着长轮询保活(不受后台定时器节流影响),
|
|
341
341
|
# 关掉网页后连接断开 → 到点自退。默认 1 分钟:关掉尽快回收,不占后台。
|
|
342
342
|
"panel_idle_minutes": 1,
|
|
343
|
+
# 更新下载源:auto=npm 优先(失败退回 Gitee/GitHub)/ npm=只走 npm / git=只走 Gitee/GitHub
|
|
344
|
+
"update_source": "auto",
|
|
345
|
+
# 索引法记忆(P1-1):注入只送"一句索引 + id",正文用 recall 取。
|
|
346
|
+
# auto=水位≥60% 才切(默认,水位低时仍给全文)/ always=一律切 / off=关
|
|
347
|
+
"use_index_memory": "auto",
|
|
348
|
+
# P1-4 Git 分支感知:remember 记下当前分支,召回时跨分支分数 ×0.5(不硬过滤)
|
|
349
|
+
"git_branch_memory": True,
|
|
343
350
|
"auto_update_interval_hours": 24,
|
|
344
351
|
"session_state_cache": False,
|
|
345
352
|
"session_state_ttl": 300,
|
|
@@ -1177,4 +1177,78 @@ def emotion_mirror(user_emotion: str, intensity: float = 0.5, what: str = "") ->
|
|
|
1177
1177
|
ev = feel(_pick_emotion_by_appraisal(_detect_polarity(ue), imp), intensity=imp,
|
|
1178
1178
|
why=f"共情:用户在说「{ue[:40]}」", about="用户", genesis=True)
|
|
1179
1179
|
note = f"顺着用户的感受起了「{ev['emotion']}」({ev['intensity']:.0%})"
|
|
1180
|
-
return {"level": level, "mirrored": ev, "mood": mood_now(), "note": note}
|
|
1180
|
+
return {"level": level, "mirrored": ev, "mood": mood_now(), "note": note}
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
def inner_voice() -> str:
|
|
1184
|
+
"""内心独白:灵枢此刻对自己的简短态度评价(≤30 字,纯模板 + 词表,不调 LLM)。
|
|
1185
|
+
|
|
1186
|
+
设计原则:
|
|
1187
|
+
- 不能太长——侧栏里一行小字,30 字封顶;
|
|
1188
|
+
- 不能太啰嗦——按 storm / suppress / valence / intensity 挑模板,别做复杂拼接;
|
|
1189
|
+
- 不能太准确——模板是"大概的感觉",不是精断,保持拟人感;
|
|
1190
|
+
- 没有情绪记录时返回空字符串(面板据此隐藏,不瞎编)。
|
|
1191
|
+
"""
|
|
1192
|
+
m = mood_now()
|
|
1193
|
+
if not m.get("active"):
|
|
1194
|
+
return ""
|
|
1195
|
+
ra = rationality()
|
|
1196
|
+
storm = bool(m.get("storm")) or bool(ra.get("storm"))
|
|
1197
|
+
suppress = _num(ra.get("suppress"), 0)
|
|
1198
|
+
valence = _num(m.get("valence"), 0)
|
|
1199
|
+
intensity = _num(m.get("intensity"), 0)
|
|
1200
|
+
label = m.get("label", "平静")
|
|
1201
|
+
|
|
1202
|
+
# 优先级 1:情绪上头 → 诚实说"脑子不清楚"
|
|
1203
|
+
if storm:
|
|
1204
|
+
if valence < -0.2:
|
|
1205
|
+
return "情绪有点炸,先别急着下结论"
|
|
1206
|
+
return "有点上头,理智被压住了"
|
|
1207
|
+
|
|
1208
|
+
# 优先级 2:理智被情绪压住 ≥ 20% → 诚实说"被压住了"
|
|
1209
|
+
if suppress >= 20:
|
|
1210
|
+
return f"情绪在捣乱,脑子不太清楚"
|
|
1211
|
+
|
|
1212
|
+
# 优先级 3:按 valence 和 intensity 挑模板
|
|
1213
|
+
if valence >= 0.25 and intensity >= 0.3:
|
|
1214
|
+
if label in ("开心", "愉快", "平和"):
|
|
1215
|
+
return f"心情{label},想多聊一会儿"
|
|
1216
|
+
return "心情不错,可以多说几句"
|
|
1217
|
+
if valence <= -0.25 and intensity >= 0.3:
|
|
1218
|
+
if label in ("失落", "低落", "烦躁", "焦虑"):
|
|
1219
|
+
return f"心情{label},别逼我太快"
|
|
1220
|
+
return "有点低落,想静静"
|
|
1221
|
+
if intensity >= 0.5:
|
|
1222
|
+
return f"此刻是{label},有点强烈"
|
|
1223
|
+
|
|
1224
|
+
# 优先级 4:平静 / 低强度 → 一句话带过
|
|
1225
|
+
if label == "平静" or intensity < 0.1:
|
|
1226
|
+
return "情绪没波动,随时可以聊"
|
|
1227
|
+
|
|
1228
|
+
return f"此刻是{label},还行"
|
|
1229
|
+
|
|
1230
|
+
|
|
1231
|
+
def emotion_timeline(limit: int = 50) -> list:
|
|
1232
|
+
"""心情流水:取最近 limit 条 genesis 事件(自动生成的 / 共情的 / 认知评价的),
|
|
1233
|
+
每条带时间、标签、强度、分类、简短原因——面板 emotion 页签的心情时间线用。
|
|
1234
|
+
|
|
1235
|
+
为什么只取 genesis=True:
|
|
1236
|
+
- 用户手动 emotion feel 调出来的不算"流水",是主动触发;
|
|
1237
|
+
- mood_now / mood_ema 内部 feel 出来的也不算 genesis。
|
|
1238
|
+
所以 genesis=True 基本就是"自动生成、反映真实对话 / 共情 / 评价"的那些事件,
|
|
1239
|
+
这才是用户想看的心情变化。
|
|
1240
|
+
"""
|
|
1241
|
+
rows = [r for r in emotion_events(limit=limit * 3) if r.get("genesis")]
|
|
1242
|
+
rows = rows[:limit]
|
|
1243
|
+
return [
|
|
1244
|
+
{
|
|
1245
|
+
"ts": r.get("ts", 0),
|
|
1246
|
+
"time": fmt_time(r.get("ts", 0)) if _num(r.get("ts"), 0) else "",
|
|
1247
|
+
"label": r.get("emotion", ""),
|
|
1248
|
+
"intensity": round(_num(r.get("intensity"), 0), 2),
|
|
1249
|
+
"category": r.get("category", ""),
|
|
1250
|
+
"why": (r.get("why") or "")[:80],
|
|
1251
|
+
"about": r.get("about", ""),
|
|
1252
|
+
}
|
|
1253
|
+
for r in rows
|
|
1254
|
+
]
|