lingshu-skill 5.60.0 → 5.62.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 +29 -0
- package/README.md +1 -1
- package/SKILL-lite.md +1 -1
- package/SKILL-tiny.md +1 -1
- package/SKILL.md +1 -1
- package/manifest.json +461 -0
- package/package.json +8 -2
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +10 -10
- package/scripts/astrbot_plugin_lingshu/engine/CHANGELOG.md +29 -0
- package/scripts/astrbot_plugin_lingshu/engine/README.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-lite.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL-tiny.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/SKILL.md +1 -1
- package/scripts/astrbot_plugin_lingshu/engine/scripts/core.py +58 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/growth.py +3 -4
- package/scripts/astrbot_plugin_lingshu/engine/scripts/make_dsh_tgz.py +20 -3
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +11 -2
- package/scripts/astrbot_plugin_lingshu/engine/scripts/panel_build.py +13 -0
- package/scripts/core.py +58 -39
- package/scripts/growth.py +3 -4
- package/scripts/make_dsh_tgz.py +20 -3
- package/scripts/make_manifest.py +15 -10
- package/scripts/make_plugin_zip.py +7 -3
- package/scripts/memory.py +11 -2
- package/scripts/panel_build.py +13 -0
- package/scripts/_ci_env_probe.py +0 -81
- package/scripts/_panel_smoke_v299.py +0 -27
- package/scripts/_scratch/_tmp_backup_race.py +0 -70
- package/scripts/_scratch/_tmp_cleanup_move.py +0 -34
- package/scripts/_scratch/_tmp_count_kinds.py +0 -25
- package/scripts/_scratch/_tmp_diag_paths.py +0 -48
- package/scripts/_scratch/_tmp_facts.py +0 -63
- package/scripts/_scratch/_tmp_find_copies.py +0 -31
- package/scripts/_scratch/_tmp_find_pin.py +0 -29
- package/scripts/_scratch/_tmp_fix_pin.py +0 -36
- package/scripts/_scratch/_tmp_fold_fixture.py +0 -55
- package/scripts/_scratch/_tmp_fold_test.mjs +0 -81
- package/scripts/_scratch/_tmp_inject_secs.py +0 -30
- package/scripts/_scratch/_tmp_kb_balance.py +0 -159
- package/scripts/_scratch/_tmp_lines.py +0 -15
- package/scripts/_scratch/_tmp_market_probe.py +0 -13
- package/scripts/_scratch/_tmp_move_partial.py +0 -16
- package/scripts/_scratch/_tmp_patch_b3.py +0 -41
- package/scripts/_scratch/_tmp_patch_b5.py +0 -62
- package/scripts/_scratch/_tmp_patch_crash_excl.py +0 -24
- package/scripts/_scratch/_tmp_patch_handoff.py +0 -21
- package/scripts/_scratch/_tmp_patch_ps1.py +0 -25
- package/scripts/_scratch/_tmp_patch_stat.py +0 -27
- package/scripts/_scratch/_tmp_patch_todo.py +0 -25
- package/scripts/_scratch/_tmp_patch_todo2.py +0 -64
- package/scripts/_scratch/_tmp_probe_session.py +0 -51
- package/scripts/_scratch/_tmp_style_probe.py +0 -40
- package/scripts/_scratch/_tmp_write_note.py +0 -139
- package/scripts/_scratch/_/346/235/245/346/272/220/350/256/260/345/275/225.txt +0 -1
- package/scripts/_scratch/asar_compaction/dsh-compaction-basic__lib__index.js +0 -1044
- package/scripts/_scratch/asar_compaction/dsh-compaction-tool-result-pruner__lib__index.js +0 -194
- package/scripts/_scratch/asar_compaction/dsh-compaction__lib__index.js +0 -175
- package/scripts/_scratch/asar_compaction/dsh-compaction__lib__types__tool-pairing.js +0 -97
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__image-offload.js +0 -47
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__index.js +0 -40
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction-image-offload__lib__types__project-message.js +0 -37
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__brand.js +0 -9
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__checkpoint.js +0 -36
- package/scripts/_scratch/asar_compaction/dsh__node_modules__@deepseek-ai__dsh-compaction__lib__types__types.js +0 -10
- package/scripts/_scratch/commit_msg_occ.txt +0 -16
- package/scripts/_scratch/commit_msg_struct.txt +0 -16
- package/scripts/_scratch/v5.34_changelog.txt +0 -36
- package/scripts/_smoke_v299.py +0 -31
- package/scripts/_sync_trae_cn.py +0 -102
- package/scripts/_tmp_add_s10.py +0 -54
- package/scripts/_tmp_add_s11.py +0 -61
- package/scripts/_tmp_add_s12.py +0 -66
- package/scripts/_tmp_add_s13.py +0 -69
- package/scripts/_tmp_add_s14.py +0 -80
- package/scripts/_tmp_add_s9.py +0 -68
- package/scripts/_tmp_cache_load.py +0 -82
- package/scripts/_tmp_clean_market.py +0 -40
- package/scripts/_tmp_clean_pruned.py +0 -81
- package/scripts/_tmp_cleanup_docs.py +0 -39
- package/scripts/_tmp_cmp_ranker.py +0 -17
- package/scripts/_tmp_dolater_note.py +0 -35
- package/scripts/_tmp_dust_why.py +0 -27
- package/scripts/_tmp_explicit_import.py +0 -40
- package/scripts/_tmp_extract_compaction.py +0 -35
- package/scripts/_tmp_extract_compaction2.py +0 -63
- package/scripts/_tmp_extract_compaction3.py +0 -51
- package/scripts/_tmp_extract_compaction4.py +0 -54
- package/scripts/_tmp_finalize_s14.py +0 -39
- package/scripts/_tmp_find_compaction.py +0 -43
- package/scripts/_tmp_fix_b4.py +0 -22
- package/scripts/_tmp_fix_cli76.py +0 -26
- package/scripts/_tmp_fix_docs.py +0 -38
- package/scripts/_tmp_fix_docs_b.py +0 -46
- package/scripts/_tmp_fix_docs_b2.py +0 -22
- package/scripts/_tmp_fix_i3.py +0 -23
- package/scripts/_tmp_fix_s10.py +0 -83
- package/scripts/_tmp_fix_s11.py +0 -14
- package/scripts/_tmp_fix_s9_status.py +0 -19
- package/scripts/_tmp_fix_shadow_sim.py +0 -37
- package/scripts/_tmp_fix_traits_value.py +0 -41
- package/scripts/_tmp_import_idem.py +0 -106
- package/scripts/_tmp_log_ack.py +0 -45
- package/scripts/_tmp_mark_batch.py +0 -28
- package/scripts/_tmp_mark_batch2.py +0 -32
- package/scripts/_tmp_mark_dolater.py +0 -26
- package/scripts/_tmp_mark_dolater2.py +0 -31
- package/scripts/_tmp_move_self.py +0 -16
- package/scripts/_tmp_occ_cli.py +0 -22
- package/scripts/_tmp_occ_link.py +0 -108
- package/scripts/_tmp_optimize_recall.py +0 -54
- package/scripts/_tmp_panel_audit.py +0 -26
- package/scripts/_tmp_patch_batch3.py +0 -65
- package/scripts/_tmp_patch_rrf.py +0 -46
- package/scripts/_tmp_patch_s2s3.py +0 -80
- package/scripts/_tmp_patch_s4.py +0 -39
- package/scripts/_tmp_patch_s7.py +0 -43
- package/scripts/_tmp_patch_s8.py +0 -91
- package/scripts/_tmp_patch_skill.py +0 -17
- package/scripts/_tmp_release_guard.py +0 -57
- package/scripts/_tmp_rerank_breaker.py +0 -62
- package/scripts/_tmp_s16.py +0 -41
- package/scripts/_tmp_scan_asar.py +0 -41
- package/scripts/_tmp_scan_asar2.py +0 -37
- package/scripts/_tmp_speed_survey.py +0 -49
- package/scripts/_tmp_struct_docs.py +0 -49
- package/scripts/_tmp_sum_fallback.py +0 -42
- package/scripts/_tmp_sweep.py +0 -81
- package/scripts/_tmp_sync_check.py +0 -69
- package/scripts/_tmp_sync_tail.py +0 -39
- package/scripts/_tmp_todo_clean.py +0 -67
- package/scripts/_tmp_verify_copy.py +0 -17
- package/scripts/_tmp_wire_extras.py +0 -93
- package/scripts/_tmp_wire_hsum.py +0 -34
- package/scripts/_tmp_wire_occ_b5.py +0 -40
- package/scripts/_tmp_wire_ranker.py +0 -13
- package/scripts/_tmp_wire_shadow_timeline.py +0 -45
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_ci_env_probe.py +0 -81
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_panel_smoke_v299.py +0 -27
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_smoke_v299.py +0 -31
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_sync_trae_cn.py +0 -102
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s10.py +0 -54
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s11.py +0 -61
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s12.py +0 -66
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s13.py +0 -69
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s14.py +0 -80
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_add_s9.py +0 -68
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cache_load.py +0 -82
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_market.py +0 -40
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_clean_pruned.py +0 -81
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cleanup_docs.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_cmp_ranker.py +0 -17
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dolater_note.py +0 -35
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_dust_why.py +0 -27
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_explicit_import.py +0 -40
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction.py +0 -35
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction2.py +0 -63
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction3.py +0 -51
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_extract_compaction4.py +0 -54
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_finalize_s14.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_find_compaction.py +0 -43
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_b4.py +0 -22
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_cli76.py +0 -26
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs.py +0 -38
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b.py +0 -46
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_docs_b2.py +0 -22
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_i3.py +0 -23
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s10.py +0 -83
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s11.py +0 -14
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_s9_status.py +0 -19
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_shadow_sim.py +0 -37
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_fix_traits_value.py +0 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_import_idem.py +0 -106
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_log_ack.py +0 -45
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch.py +0 -28
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_batch2.py +0 -32
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater.py +0 -26
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_mark_dolater2.py +0 -31
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_move_self.py +0 -16
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_cli.py +0 -22
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_occ_link.py +0 -108
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_optimize_recall.py +0 -54
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_panel_audit.py +0 -26
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_batch3.py +0 -65
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_rrf.py +0 -46
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s2s3.py +0 -80
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s4.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s7.py +0 -43
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_s8.py +0 -91
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_patch_skill.py +0 -17
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_release_guard.py +0 -57
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_rerank_breaker.py +0 -62
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_s16.py +0 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar.py +0 -41
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_scan_asar2.py +0 -37
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_speed_survey.py +0 -49
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_struct_docs.py +0 -49
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sum_fallback.py +0 -42
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sweep.py +0 -81
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_check.py +0 -69
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_sync_tail.py +0 -39
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_todo_clean.py +0 -67
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_verify_copy.py +0 -17
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_extras.py +0 -93
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_hsum.py +0 -34
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_occ_b5.py +0 -40
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_ranker.py +0 -13
- package/scripts/astrbot_plugin_lingshu/engine/scripts/_tmp_wire_shadow_timeline.py +0 -45
package/scripts/_ci_env_probe.py
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""CI 诊断探针:只在 sync_engine 失败时被调用,把环境事实打出来。
|
|
3
|
-
|
|
4
|
-
为什么单独成文件:内联在 workflow 的 heredoc 会破坏 YAML 缩进(实测解析失败),
|
|
5
|
-
而这一段逻辑值得留档——它回答的是"为什么在 Windows runner 上失败、Linux 上不".
|
|
6
|
-
"""
|
|
7
|
-
import locale
|
|
8
|
-
import pathlib
|
|
9
|
-
import sys
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def main() -> int:
|
|
13
|
-
root = pathlib.Path(".").resolve()
|
|
14
|
-
print(f" cwd={root}")
|
|
15
|
-
print(f" python={sys.version.split()[0]}")
|
|
16
|
-
print(f" fsencoding={sys.getfilesystemencoding()}")
|
|
17
|
-
print(f" preferred={locale.getpreferredencoding(False)}")
|
|
18
|
-
|
|
19
|
-
print(" --- 关键路径 ---")
|
|
20
|
-
for rel in ("scripts",
|
|
21
|
-
"scripts/astrbot_plugin_lingshu",
|
|
22
|
-
"scripts/astrbot_plugin_lingshu/engine",
|
|
23
|
-
"docs/panel-api.md", "docs/commands.md",
|
|
24
|
-
"docs/mechanics.md", "docs/models.md", "docs/recovery.md",
|
|
25
|
-
"assets/panel.html"):
|
|
26
|
-
p = root / rel
|
|
27
|
-
kind = "-" if not p.exists() else ("dir" if p.is_dir() else f"{p.stat().st_size}B")
|
|
28
|
-
print(f" {rel}: {kind}")
|
|
29
|
-
|
|
30
|
-
# 换行抽样:CI 若在 Windows 上 checkout 成 CRLF,这里能直接看出来
|
|
31
|
-
print(" --- 换行抽样(前 5 个 .md/.py)---")
|
|
32
|
-
shown = 0
|
|
33
|
-
for p in sorted(root.rglob("*")):
|
|
34
|
-
if shown >= 5:
|
|
35
|
-
break
|
|
36
|
-
if p.is_file() and p.suffix.lower() in (".md", ".py") and "node_modules" not in str(p):
|
|
37
|
-
b = p.read_bytes()[:400]
|
|
38
|
-
crlf = b.count(b"\r\n")
|
|
39
|
-
lf = b.count(b"\n") - crlf
|
|
40
|
-
print(f" {p.relative_to(root)}: CRLF={crlf} LF={lf}")
|
|
41
|
-
shown += 1
|
|
42
|
-
|
|
43
|
-
# engine 里是否残留已从根目录删掉的文档
|
|
44
|
-
eng = root / "scripts" / "astrbot_plugin_lingshu" / "engine"
|
|
45
|
-
if eng.is_dir():
|
|
46
|
-
stale = [p.name for p in eng.rglob("*.md")
|
|
47
|
-
if not (root / p.relative_to(eng)).exists()]
|
|
48
|
-
print(f" --- engine 里根目录已无对应项的 .md: {stale[:8] or '无'}")
|
|
49
|
-
return 0
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def _ensure_utf8_stdout() -> None:
|
|
53
|
-
"""把 stdout/stderr 切到 UTF-8,避免 Windows 控制台(cp1252/cp936)编不了中文就崩。
|
|
54
|
-
|
|
55
|
-
CI 的 windows-latest stdout 是 cp1252:脚本一 print 中文就 UnicodeEncodeError
|
|
56
|
-
直接退出(实测 sync_engine.py / make_checksums.py 都因此挂过,Ubuntu 同期正常)。
|
|
57
|
-
这不是业务 bug,是"中文输出 + 非 UTF-8 控制台"的必然结果。
|
|
58
|
-
"""
|
|
59
|
-
for name in ("stdout", "stderr"):
|
|
60
|
-
stream = getattr(sys, name, None)
|
|
61
|
-
fn = getattr(stream, "reconfigure", None)
|
|
62
|
-
if callable(fn):
|
|
63
|
-
try:
|
|
64
|
-
fn(encoding="utf-8", errors="replace")
|
|
65
|
-
continue
|
|
66
|
-
except (OSError, ValueError, AttributeError):
|
|
67
|
-
pass
|
|
68
|
-
try:
|
|
69
|
-
import io
|
|
70
|
-
buf = getattr(stream, "buffer", None)
|
|
71
|
-
if buf is not None:
|
|
72
|
-
setattr(sys, name,
|
|
73
|
-
io.TextIOWrapper(buf, encoding="utf-8", errors="replace",
|
|
74
|
-
line_buffering=True))
|
|
75
|
-
except Exception: # noqa: BLE001
|
|
76
|
-
pass
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if __name__ == "__main__":
|
|
80
|
-
_ensure_utf8_stdout()
|
|
81
|
-
sys.exit(main())
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""验证脚本:后台起 panel_server(临时 HOME),查 /api/extensions/ollama/status,然后关掉。"""
|
|
3
|
-
import os, subprocess, sys, tempfile, time, urllib.request
|
|
4
|
-
|
|
5
|
-
tmp = os.path.join(tempfile.gettempdir(), "lingshu-panel-smoke")
|
|
6
|
-
os.makedirs(tmp, exist_ok=True)
|
|
7
|
-
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
8
|
-
flags = getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
|
9
|
-
proc = subprocess.Popen([sys.executable, os.path.join(root, "scripts", "panel_server.py"),
|
|
10
|
-
"--port", "8791", "--no-browser", "--home", tmp],
|
|
11
|
-
cwd=root, creationflags=flags,
|
|
12
|
-
stdout=subprocess.DEVNULL, stderr=subprocess.PIPE)
|
|
13
|
-
time.sleep(6)
|
|
14
|
-
try:
|
|
15
|
-
with urllib.request.urlopen("http://127.0.0.1:8791/api/extensions/ollama/status", timeout=10) as r:
|
|
16
|
-
print("STATUS:", r.read().decode("utf-8"))
|
|
17
|
-
except Exception as exc:
|
|
18
|
-
print("ERR:", exc)
|
|
19
|
-
finally:
|
|
20
|
-
proc.terminate()
|
|
21
|
-
try:
|
|
22
|
-
_, err = proc.communicate(timeout=10)
|
|
23
|
-
if err:
|
|
24
|
-
print("STDERR:", err.decode("utf-8", "replace")[-800:])
|
|
25
|
-
except Exception:
|
|
26
|
-
proc.kill()
|
|
27
|
-
print("PANEL SMOKE DONE")
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性并发压力测试(可删):在**临时**工作区里搭同结构,边修剪边连跑备份。
|
|
3
|
-
|
|
4
|
-
根因场景:safety_net 每次 save_all 后把旧快照**移入** .safety/.pruned/,
|
|
5
|
-
备份 rglob 已列出那些文件 → 写包时文件消失 → 整包失败。
|
|
6
|
-
用临时目录模拟同结构,不碰真实数据。
|
|
7
|
-
"""
|
|
8
|
-
import concurrent.futures
|
|
9
|
-
import os
|
|
10
|
-
import shutil
|
|
11
|
-
import sys
|
|
12
|
-
import tempfile
|
|
13
|
-
import time
|
|
14
|
-
from pathlib import Path
|
|
15
|
-
|
|
16
|
-
sys.path.insert(0, r"E:\丁厚同\文档\程序\灵枢-skill\scripts")
|
|
17
|
-
|
|
18
|
-
home = Path(tempfile.mkdtemp(prefix="ls-bk-race-"))
|
|
19
|
-
(home / "cortex.jsonl").write_text('{"id":"m1"}\n', encoding="utf-8")
|
|
20
|
-
(home / "persona.json").write_text('{"name":"砚"}', encoding="utf-8")
|
|
21
|
-
safety = home / ".safety"
|
|
22
|
-
for i in range(26):
|
|
23
|
-
d = safety / f"2026110{i}-000000_save_all"
|
|
24
|
-
d.mkdir(parents=True, exist_ok=True)
|
|
25
|
-
(d / "cortex.jsonl").write_text(f"snap{i}\n", encoding="utf-8")
|
|
26
|
-
|
|
27
|
-
os.environ["BRAIN_MEMORY_HOME"] = str(home)
|
|
28
|
-
out = home / "_race_out"
|
|
29
|
-
|
|
30
|
-
import brain # noqa: E402
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
def prune_loop():
|
|
34
|
-
"""模拟 safety_net 修剪:反复把最旧快照移入 .pruned(只移不删)。"""
|
|
35
|
-
end = time.time() + 20
|
|
36
|
-
moved = 0
|
|
37
|
-
while time.time() < end:
|
|
38
|
-
cands = sorted([p for p in safety.glob("2026*_save_all*") if p.is_dir()],
|
|
39
|
-
key=lambda p: p.stat().st_mtime)
|
|
40
|
-
if cands:
|
|
41
|
-
dst = safety / ".pruned"
|
|
42
|
-
dst.mkdir(parents=True, exist_ok=True)
|
|
43
|
-
try:
|
|
44
|
-
shutil.move(str(cands[0]), str(dst / f"{cands[0].name}.raced"))
|
|
45
|
-
moved += 1
|
|
46
|
-
except OSError:
|
|
47
|
-
pass
|
|
48
|
-
time.sleep(0.02)
|
|
49
|
-
return moved
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
def run_backup():
|
|
53
|
-
t0 = time.time()
|
|
54
|
-
rc = brain.cmd_backup(str(out), keep=0, assume_yes=True)
|
|
55
|
-
return rc, round(time.time() - t0, 2)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
with concurrent.futures.ThreadPoolExecutor(max_workers=3) as ex:
|
|
59
|
-
fut_prune = ex.submit(prune_loop)
|
|
60
|
-
outs = [f.result() for f in [ex.submit(run_backup) for _ in range(6)]]
|
|
61
|
-
moved = fut_prune.result()
|
|
62
|
-
|
|
63
|
-
zips = sorted(out.glob("*.zip"))
|
|
64
|
-
print(f"并发移动快照次数 = {moved}")
|
|
65
|
-
print(f"备份结果(rc, 秒): {outs}")
|
|
66
|
-
print(f"产出 zip = {len(zips)}")
|
|
67
|
-
ok = all(rc == 0 for rc, _ in outs) and len(zips) == len(outs)
|
|
68
|
-
print("RESULT:", "PASS" if ok else "FAIL")
|
|
69
|
-
shutil.rmtree(home, ignore_errors=True)
|
|
70
|
-
sys.exit(0 if ok else 1)
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:把仓库里的 _tmp_* 一次性脚本挪进 scripts/_scratch/(§7 #38,可删)。
|
|
3
|
-
|
|
4
|
-
按用户规矩:**只移不删**,并记录来源与时间。
|
|
5
|
-
"""
|
|
6
|
-
import shutil
|
|
7
|
-
import time
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
ROOT = Path(r"E:\丁厚同\文档\程序\灵枢-skill")
|
|
11
|
-
SCRATCH = ROOT / "scripts" / "_scratch"
|
|
12
|
-
SCRATCH.mkdir(parents=True, exist_ok=True)
|
|
13
|
-
|
|
14
|
-
targets = sorted(ROOT.glob("_tmp_*.py")) + sorted(ROOT.glob("_tmp_*.mjs")) \
|
|
15
|
-
+ sorted((ROOT / "scripts").glob("_tmp_*.py")) + sorted((ROOT / "scripts").glob("_tmp_*.mjs"))
|
|
16
|
-
moved = 0
|
|
17
|
-
_self = Path(__file__).resolve()
|
|
18
|
-
for p in targets:
|
|
19
|
-
if not p.is_file():
|
|
20
|
-
continue
|
|
21
|
-
if p.resolve() == _self: # 自己正在被解释器占用,别动
|
|
22
|
-
continue
|
|
23
|
-
dst = SCRATCH / p.name
|
|
24
|
-
if dst.exists():
|
|
25
|
-
dst = SCRATCH / f"{p.stem}.{int(time.time())}{p.suffix}"
|
|
26
|
-
shutil.move(str(p), str(dst))
|
|
27
|
-
moved += 1
|
|
28
|
-
print("moved:", p.name, "->", dst.relative_to(ROOT))
|
|
29
|
-
|
|
30
|
-
note = SCRATCH / "_来源记录.txt"
|
|
31
|
-
with note.open("a", encoding="utf-8") as f:
|
|
32
|
-
f.write(f"[{time.strftime('%Y-%m-%d %H:%M:%S')}] 从仓库根/scripts 迁入 {moved} 个 _tmp_* 一次性脚本"
|
|
33
|
-
"(§7 #38:清理探针堆积;只移不删,确认无用后可整目录删除)\n")
|
|
34
|
-
print(f"共移动 {moved} 个到 {SCRATCH}")
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:列出 lingshu.log 里 inject/warn 的不同消息(可删)。"""
|
|
3
|
-
import collections
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import re
|
|
7
|
-
|
|
8
|
-
p = os.path.expanduser(r"~\.brain-memory\lingshu.log")
|
|
9
|
-
c = collections.Counter()
|
|
10
|
-
for ln in open(p, encoding="utf-8", errors="replace"):
|
|
11
|
-
ln = ln.strip()
|
|
12
|
-
if not ln:
|
|
13
|
-
continue
|
|
14
|
-
try:
|
|
15
|
-
o = json.loads(ln)
|
|
16
|
-
except Exception:
|
|
17
|
-
continue
|
|
18
|
-
if o.get("kind") != "inject" or str(o.get("level")).lower() != "warn":
|
|
19
|
-
continue
|
|
20
|
-
msg = str(o.get("msg") or "")
|
|
21
|
-
# 把数字抹平,便于聚合
|
|
22
|
-
key = re.sub(r"-?\d+", "N", msg)[:110]
|
|
23
|
-
c[key] += 1
|
|
24
|
-
for k, v in c.most_common():
|
|
25
|
-
print(f"{v:>3}x {k}")
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""临时诊断 3:验证 APP 会话目录名编码 + 直接构造路径可达性(可删)。"""
|
|
3
|
-
import os
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
SESS_ROOT = r"C:\Users\Administrator\.app\sessions"
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
def encode(part: str) -> str:
|
|
10
|
-
out = []
|
|
11
|
-
for ch in part:
|
|
12
|
-
if ch.isascii() and (ch.isalnum() or ch in "._-"):
|
|
13
|
-
out.append(ch)
|
|
14
|
-
elif ch.isascii():
|
|
15
|
-
out.append("-")
|
|
16
|
-
else:
|
|
17
|
-
out.append("~%04X" % ord(ch))
|
|
18
|
-
return "".join(out)
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
def session_dir_name(path: str) -> str:
|
|
22
|
-
p = Path(path)
|
|
23
|
-
parts = [p.drive.rstrip(":")] + list(p.parts[1:])
|
|
24
|
-
return "--" + "-".join(encode(x) for x in parts if x) + "--"
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
for cwd in (r"E:\丁厚同\文档\程序", r"E:\丁厚同\文档\程序\灵枢-skill"):
|
|
28
|
-
name = session_dir_name(cwd)
|
|
29
|
-
full = os.path.join(SESS_ROOT, name)
|
|
30
|
-
print("cwd:", cwd)
|
|
31
|
-
print(" encoded:", name)
|
|
32
|
-
print(" isdir:", os.path.isdir(full))
|
|
33
|
-
if os.path.isdir(full):
|
|
34
|
-
try:
|
|
35
|
-
subs = sorted(os.listdir(full))
|
|
36
|
-
print(" sessions:", len(subs), subs[:3])
|
|
37
|
-
for sid in subs[:2]:
|
|
38
|
-
f = os.path.join(full, sid, "session.v4.jsonl.zstd")
|
|
39
|
-
print(" file exists:", os.path.isfile(f), f[-70:])
|
|
40
|
-
except Exception as e:
|
|
41
|
-
print(" listdir 失败:", type(e).__name__, e)
|
|
42
|
-
print()
|
|
43
|
-
|
|
44
|
-
# 已知正确名对照
|
|
45
|
-
known = "--E-~4E01~539A~540C-~6587~6863-~7A0B~5E8F--"
|
|
46
|
-
print("known :", known)
|
|
47
|
-
print("computed:", session_dir_name(r"E:\丁厚同\文档\程序"))
|
|
48
|
-
print("match:", known == session_dir_name(r"E:\丁厚同\文档\程序"))
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:为"待办补充缺点"取证(可删)。"""
|
|
3
|
-
import glob
|
|
4
|
-
import json
|
|
5
|
-
import os
|
|
6
|
-
import zipfile
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
|
|
9
|
-
HOME = Path(os.path.expanduser("~"))
|
|
10
|
-
BM = HOME / ".brain-memory"
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
def du(p: Path) -> tuple:
|
|
14
|
-
if not p.exists():
|
|
15
|
-
return (0, 0)
|
|
16
|
-
n = s = 0
|
|
17
|
-
for root, _dirs, files in os.walk(p):
|
|
18
|
-
for f in files:
|
|
19
|
-
try:
|
|
20
|
-
s += (Path(root) / f).stat().st_size
|
|
21
|
-
n += 1
|
|
22
|
-
except OSError:
|
|
23
|
-
pass
|
|
24
|
-
return (n, s)
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
def mb(b: int) -> str:
|
|
28
|
-
return f"{b / 1024 / 1024:.1f}MB"
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
print("== 磁盘占用 ==")
|
|
32
|
-
for name in (".safety", ".safety/.pruned", "backups", "sources"):
|
|
33
|
-
n, s = du(BM / name)
|
|
34
|
-
print(f" {name:<20} {n:>5} 文件 {mb(s):>8}")
|
|
35
|
-
|
|
36
|
-
print("\n== HOME 里的诊断残留 ==")
|
|
37
|
-
crashes = sorted(BM.glob("crash-*.log"))
|
|
38
|
-
print(f" crash-*.log: {len(crashes)} 个,合计 {mb(sum(p.stat().st_size for p in crashes))}")
|
|
39
|
-
for p in crashes[:3]:
|
|
40
|
-
print(" ", p.name, f"{p.stat().st_size // 1024}KB")
|
|
41
|
-
|
|
42
|
-
print("\n== 备份包是否含 crash 日志 / .safety ==")
|
|
43
|
-
zs = sorted(glob.glob(str(BM / "backups" / "*.zip")), key=os.path.getmtime)
|
|
44
|
-
cand = sorted(glob.glob(r"D:\brain-memory-backups\*.zip"), key=os.path.getmtime)
|
|
45
|
-
z = (cand or zs)[-1] if (cand or zs) else None
|
|
46
|
-
if z:
|
|
47
|
-
names = zipfile.ZipFile(z).namelist()
|
|
48
|
-
print(f" 包: {os.path.basename(z)}({len(names)} 条目)")
|
|
49
|
-
print(" 含 crash-*.log:", sum(1 for n in names if n.startswith("crash-")))
|
|
50
|
-
print(" 含 .safety:", sum(1 for n in names if ".safety" in n))
|
|
51
|
-
|
|
52
|
-
print("\n== 仓库里的临时脚本(未入库) ==")
|
|
53
|
-
tmp = sorted(glob.glob(r"E:\丁厚同\文档\程序\灵枢-skill\scripts\_tmp_*.py"))
|
|
54
|
-
tmp += sorted(glob.glob(r"E:\丁厚同\文档\程序\灵枢-skill\_tmp_*.mjs"))
|
|
55
|
-
print(f" 共 {len(tmp)} 个")
|
|
56
|
-
for p in tmp[:12]:
|
|
57
|
-
print(" ", os.path.basename(p))
|
|
58
|
-
|
|
59
|
-
print("\n== 未跟踪测试文件数 ==")
|
|
60
|
-
import subprocess
|
|
61
|
-
r = subprocess.run(["git", "status", "--porcelain", "tests/"],
|
|
62
|
-
cwd=r"E:\丁厚同\文档\程序\灵枢-skill", capture_output=True, text=True)
|
|
63
|
-
print(" ", len([l for l in r.stdout.splitlines() if l.strip()]), "条改动/未跟踪")
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:用 Python 视角列出所有已安装的 lingshu brain.py/cli.py 副本及其修复状态。"""
|
|
3
|
-
import os
|
|
4
|
-
from pathlib import Path
|
|
5
|
-
|
|
6
|
-
HOME = Path(os.path.expanduser("~"))
|
|
7
|
-
MARK = "_EXCLUDE_DIR_PARTS"
|
|
8
|
-
|
|
9
|
-
cands = [
|
|
10
|
-
HOME / ".app" / "skills" / "lingshu" / "scripts" / "cli.py",
|
|
11
|
-
HOME / ".trae-cn" / "skills" / "lingshu" / "scripts" / "cli.py",
|
|
12
|
-
HOME / ".app" / "profiles" / "desktop" / "node_modules" / "lingshu-skill" / "scripts" / "cli.py",
|
|
13
|
-
]
|
|
14
|
-
print("== 候选路径 ==")
|
|
15
|
-
for p in cands:
|
|
16
|
-
ok = p.is_file()
|
|
17
|
-
fix = (MARK in p.read_text(encoding="utf-8", errors="replace")) if ok else None
|
|
18
|
-
print(f" exists={ok!s:<5} fix={fix!s:<5} {p}")
|
|
19
|
-
|
|
20
|
-
print("\n== 全盘搜 node_modules/lingshu-skill/scripts/cli.py(限深) ==")
|
|
21
|
-
base = HOME
|
|
22
|
-
depth_limit = 7
|
|
23
|
-
for root, dirs, files in os.walk(base):
|
|
24
|
-
depth = len(Path(root).relative_to(base).parts)
|
|
25
|
-
if depth >= depth_limit:
|
|
26
|
-
dirs[:] = []
|
|
27
|
-
continue
|
|
28
|
-
if Path(root).name == "scripts" and "cli.py" in files and "lingshu" in str(Path(root).parent):
|
|
29
|
-
p = Path(root) / "cli.py"
|
|
30
|
-
fix = MARK in p.read_text(encoding="utf-8", errors="replace")
|
|
31
|
-
print(f" fix={fix!s:<5} mtime={p.stat().st_mtime_ns} {p}")
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:按 doctor 的办法定位 APP profile,并打印目录名码位 + 依赖声明(可删)。"""
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
|
|
7
|
-
home = Path(os.path.expanduser("~"))
|
|
8
|
-
found = None
|
|
9
|
-
for name in os.listdir(home):
|
|
10
|
-
cand = home / name / "profiles" / "desktop"
|
|
11
|
-
try:
|
|
12
|
-
if (cand / "package.json").is_file():
|
|
13
|
-
found = cand
|
|
14
|
-
print("命中目录名:", name, "| chars=", ",".join(str(ord(c)) for c in name))
|
|
15
|
-
break
|
|
16
|
-
except OSError:
|
|
17
|
-
continue
|
|
18
|
-
if not found:
|
|
19
|
-
print("没找到")
|
|
20
|
-
raise SystemExit(1)
|
|
21
|
-
|
|
22
|
-
d = json.loads((found / "package.json").read_text(encoding="utf-8-sig"))
|
|
23
|
-
spec = str(((d.get("dependencies") or {}).get("lingshu-skill")) or "")
|
|
24
|
-
inst = found / "node_modules" / "lingshu-skill" / "package.json"
|
|
25
|
-
ver = ""
|
|
26
|
-
if inst.is_file():
|
|
27
|
-
ver = json.loads(inst.read_text(encoding="utf-8-sig")).get("version", "")
|
|
28
|
-
print("profile:", found)
|
|
29
|
-
print("声明 spec =", repr(spec), "| node_modules 实际版本 =", ver)
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:把 profile 里 lingshu-skill 的依赖声明从 ^5.33.0 改成 ^5.34.0(可删)。
|
|
3
|
-
|
|
4
|
-
只改声明,不跑 pnpm install——npm 上还没发布 5.34,install 会 404。
|
|
5
|
-
真正升级应在 `release.py publish` 之后再做。
|
|
6
|
-
"""
|
|
7
|
-
import os
|
|
8
|
-
from pathlib import Path
|
|
9
|
-
|
|
10
|
-
home = Path(os.path.expanduser("~"))
|
|
11
|
-
prof = None
|
|
12
|
-
for name in os.listdir(home):
|
|
13
|
-
cand = home / name / "profiles" / "desktop"
|
|
14
|
-
try:
|
|
15
|
-
if (cand / "package.json").is_file():
|
|
16
|
-
prof = cand
|
|
17
|
-
break
|
|
18
|
-
except OSError:
|
|
19
|
-
continue
|
|
20
|
-
if prof is None:
|
|
21
|
-
print("没找到 profile")
|
|
22
|
-
raise SystemExit(1)
|
|
23
|
-
|
|
24
|
-
p = prof / "package.json"
|
|
25
|
-
raw = p.read_text(encoding="utf-8-sig")
|
|
26
|
-
old = '"lingshu-skill": "^5.33.0"'
|
|
27
|
-
new = '"lingshu-skill": "^5.34.0"'
|
|
28
|
-
if old not in raw:
|
|
29
|
-
print("没匹配到旧声明;当前包含 lingshu-skill 的行:")
|
|
30
|
-
for ln in raw.splitlines():
|
|
31
|
-
if "lingshu-skill" in ln:
|
|
32
|
-
print(" ", ln.strip())
|
|
33
|
-
raise SystemExit(2)
|
|
34
|
-
p.write_text(raw.replace(old, new, 1), encoding="utf-8")
|
|
35
|
-
print("已更新:", p)
|
|
36
|
-
print("新声明:", new)
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性:导出**保真**的决策消息(保留 tool-call 段)+ 真实折叠(可删)。
|
|
3
|
-
|
|
4
|
-
注意:把 text 段截到 200 字只为缩小夹具;**结构(段类型/配对)必须原样保留**,
|
|
5
|
-
否则「悬挂工具结果」这类检查会全是假阳性。
|
|
6
|
-
"""
|
|
7
|
-
import json
|
|
8
|
-
import sys
|
|
9
|
-
from pathlib import Path
|
|
10
|
-
|
|
11
|
-
sys.path.insert(0, r"E:\丁厚同\文档\程序\灵枢-skill\scripts")
|
|
12
|
-
import app_context
|
|
13
|
-
|
|
14
|
-
p = app_context.find_session()
|
|
15
|
-
ev = app_context.read_events(p)
|
|
16
|
-
|
|
17
|
-
# 直接按事件原样取消息体(_msg_of 已处理两种形态),按 id 去重
|
|
18
|
-
seen = set()
|
|
19
|
-
host_msgs = []
|
|
20
|
-
for e in ev:
|
|
21
|
-
m = app_context._msg_of(e)
|
|
22
|
-
if not isinstance(m, dict):
|
|
23
|
-
continue
|
|
24
|
-
mid = m.get("id")
|
|
25
|
-
if mid and mid in seen:
|
|
26
|
-
continue
|
|
27
|
-
if mid:
|
|
28
|
-
seen.add(mid)
|
|
29
|
-
if m.get("role") == "system":
|
|
30
|
-
continue
|
|
31
|
-
parts = []
|
|
32
|
-
for x in (m.get("content") or []):
|
|
33
|
-
if not isinstance(x, dict):
|
|
34
|
-
continue
|
|
35
|
-
if x.get("type") == "text":
|
|
36
|
-
parts.append({"type": "text", "text": str(x.get("text") or "")[:200]})
|
|
37
|
-
elif x.get("type") == "tool-call":
|
|
38
|
-
parts.append(x) # 原样保留,含 id
|
|
39
|
-
elif x.get("type") == "reasoning":
|
|
40
|
-
parts.append({"type": "reasoning", "text": "…"})
|
|
41
|
-
item = {"id": mid, "role": m.get("role"), "content": parts}
|
|
42
|
-
if m.get("toolCallId"):
|
|
43
|
-
item["toolCallId"] = m.get("toolCallId")
|
|
44
|
-
host_msgs.append(item)
|
|
45
|
-
|
|
46
|
-
doc = app_context.load_folds()
|
|
47
|
-
active = [f for f in doc["folds"] if not f.get("restored")]
|
|
48
|
-
out = Path(sys.argv[1])
|
|
49
|
-
out.write_text(json.dumps({"folds": active, "messages": host_msgs}, ensure_ascii=False),
|
|
50
|
-
encoding="utf-8")
|
|
51
|
-
print("fold_id:", active[-1]["id"], "fold_msgs:", len(active[-1]["message_ids"]))
|
|
52
|
-
print("host_messages:", len(host_msgs),
|
|
53
|
-
"| with tool-call:", sum(1 for m in host_msgs if any(p.get("type") == "tool-call" for p in m["content"])),
|
|
54
|
-
"| tool results:", sum(1 for m in host_msgs if m.get("toolCallId")))
|
|
55
|
-
print("fixture ->", out)
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
// 一次性:验证 context-fold.js 的 applyFolds(可删)
|
|
2
|
-
import { readFileSync, mkdirSync, writeFileSync, rmSync } from 'node:fs'
|
|
3
|
-
import { join } from 'node:path'
|
|
4
|
-
import { tmpdir } from 'node:os'
|
|
5
|
-
import { applyFolds } from './cordis-plugin/lingshu-startup/context-fold.js'
|
|
6
|
-
|
|
7
|
-
const fx = JSON.parse(readFileSync(process.argv[2], 'utf8'))
|
|
8
|
-
|
|
9
|
-
const home = join(tmpdir(), 'ls-fold-test-' + Date.now())
|
|
10
|
-
mkdirSync(home, { recursive: true })
|
|
11
|
-
// 必须设环境变量:模块的 memoryHome() 每次调用都读 BRAIN_MEMORY_HOME,
|
|
12
|
-
// 不设就会去读真实的 ~/.brain-memory/context-folds.json,测试全部失真。
|
|
13
|
-
process.env.BRAIN_MEMORY_HOME = home
|
|
14
|
-
|
|
15
|
-
function writeLedger(doc) {
|
|
16
|
-
writeFileSync(join(home, 'context-folds.json'), JSON.stringify(doc, null, 2), 'utf8')
|
|
17
|
-
}
|
|
18
|
-
function mkDecision(messages) {
|
|
19
|
-
return { kind: 'enter', messages: messages.map((m) => JSON.parse(JSON.stringify(m))) }
|
|
20
|
-
}
|
|
21
|
-
function countOrphans(messages) {
|
|
22
|
-
const produced = new Set()
|
|
23
|
-
for (const m of messages) {
|
|
24
|
-
for (const p of (m.content || [])) {
|
|
25
|
-
if (p && p.type === 'tool-call' && p.id) produced.add(String(p.id))
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return messages.filter((m) => m.toolCallId && !produced.has(String(m.toolCallId))).length
|
|
29
|
-
}
|
|
30
|
-
function foldCount(messages) {
|
|
31
|
-
return messages.filter((m) => String(m.id || '').startsWith('fold-')).length
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
let fail = 0
|
|
35
|
-
|
|
36
|
-
// ---- 场景 A:真实账本,整轮折叠 ----
|
|
37
|
-
writeLedger({ version: 1, folds: fx.folds })
|
|
38
|
-
const dA = mkDecision(fx.messages)
|
|
39
|
-
const rA = applyFolds(dA, 1600)
|
|
40
|
-
const orphanA = countOrphans(dA.messages)
|
|
41
|
-
console.log('A 真实账本:', JSON.stringify({
|
|
42
|
-
ok: rA.ok, changed: rA.changed, folded: rA.folded,
|
|
43
|
-
before: fx.messages.length, after: dA.messages.length,
|
|
44
|
-
inserted: foldCount(dA.messages), orphan: orphanA,
|
|
45
|
-
}))
|
|
46
|
-
if (orphanA !== 0) { console.error('FAIL A: 悬挂工具结果'); fail++ }
|
|
47
|
-
if (!rA.changed) { console.error('FAIL A: 没折叠'); fail++ }
|
|
48
|
-
if (foldCount(dA.messages) !== fx.folds.length) { console.error('FAIL A: 插入条数不符'); fail++ }
|
|
49
|
-
|
|
50
|
-
// ---- 场景 B:对抗——把一个工具结果从折叠里抠掉(模拟不完整折叠)----
|
|
51
|
-
const f0 = fx.folds[0]
|
|
52
|
-
const toolMsg = fx.messages.find((m) => m.role === 'tool' && f0.message_ids.includes(m.id))
|
|
53
|
-
let rB = null, orphanB = null, changedB = null
|
|
54
|
-
if (toolMsg) {
|
|
55
|
-
const tampered = { ...f0, message_ids: f0.message_ids.filter((x) => x !== toolMsg.id) }
|
|
56
|
-
writeLedger({ version: 1, folds: [tampered] })
|
|
57
|
-
const dB = mkDecision(fx.messages)
|
|
58
|
-
rB = applyFolds(dB, 1600)
|
|
59
|
-
orphanB = countOrphans(dB.messages)
|
|
60
|
-
changedB = rB.changed
|
|
61
|
-
console.log('B 抠掉工具结果后:', JSON.stringify({
|
|
62
|
-
ok: rB.ok, changed: rB.changed, folded: rB.folded, reason: rB.reason,
|
|
63
|
-
after: dB.messages.length, orphan: orphanB,
|
|
64
|
-
}))
|
|
65
|
-
if (orphanB !== 0) { console.error('FAIL B: 悬挂工具结果(防护没拦住)'); fail++ }
|
|
66
|
-
if (changedB === true) { console.error('FAIL B: 不完整折叠被应用了'); fail++ }
|
|
67
|
-
} else {
|
|
68
|
-
console.log('B 跳过:该折叠里没有 tool 消息')
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// ---- 场景 C:无账本 → 原样返回 ----
|
|
72
|
-
writeLedger({ version: 1, folds: [] })
|
|
73
|
-
const dC = mkDecision(fx.messages)
|
|
74
|
-
const rC = applyFolds(dC, 1600)
|
|
75
|
-
console.log('C 空账本:', JSON.stringify({ ok: rC.ok, changed: rC.changed,
|
|
76
|
-
before: fx.messages.length, after: dC.messages.length }))
|
|
77
|
-
if (rC.changed) { console.error('FAIL C: 空账本也改了'); fail++ }
|
|
78
|
-
|
|
79
|
-
rmSync(home, { recursive: true, force: true })
|
|
80
|
-
console.log(fail === 0 ? 'PASS' : `FAILED(${fail})`)
|
|
81
|
-
process.exit(fail === 0 ? 0 : 1)
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""一次性诊断:注入包里每段到底装了什么(可删)。"""
|
|
3
|
-
import sys
|
|
4
|
-
from collections import Counter
|
|
5
|
-
|
|
6
|
-
sys.path.insert(0, r"E:\丁厚同\文档\程序\灵枢-skill\scripts")
|
|
7
|
-
import brain # noqa: E402
|
|
8
|
-
|
|
9
|
-
rep = {}
|
|
10
|
-
res = brain.build_injection("", 1400, rep)
|
|
11
|
-
print("总字符:", len(res))
|
|
12
|
-
secs = rep.get("sections") or []
|
|
13
|
-
for s in secs:
|
|
14
|
-
print(f" {s['name']:<14} chars={s['chars']:<6} tokens={s['tokens']}")
|
|
15
|
-
|
|
16
|
-
print("\n== 各段内容样本(前 3 行) ==")
|
|
17
|
-
# 用带段名的原因:build_injection 内部 out 已恒为 _SectionList,但外部拿不到,
|
|
18
|
-
# 所以这里退一步:直接看注入文本里每个二级标题归属哪一段。
|
|
19
|
-
lines = res.splitlines()
|
|
20
|
-
cur = None
|
|
21
|
-
buckets = {}
|
|
22
|
-
for ln in lines:
|
|
23
|
-
if ln.startswith("## ") or ln.startswith("\n## "):
|
|
24
|
-
cur = ln.strip("# ").strip()
|
|
25
|
-
buckets.setdefault(cur or "<头部>", []).append(ln)
|
|
26
|
-
for k, v in sorted(buckets.items(), key=lambda x: -sum(len(i) for i in x[1]))[:8]:
|
|
27
|
-
size = sum(len(i) for i in v)
|
|
28
|
-
print(f"\n--- {k} ({size} 字符, {len(v)} 行) ---")
|
|
29
|
-
for ln in v[:3]:
|
|
30
|
-
print(" ", ln[:100])
|