lingshu-skill 5.58.0 → 5.60.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/package.json +1 -1
- package/scripts/astrbot_plugin_lingshu/CHECKSUMS.json +8 -8
- 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/cli.py +81 -28
- package/scripts/astrbot_plugin_lingshu/engine/scripts/dream.py +1235 -1214
- package/scripts/astrbot_plugin_lingshu/engine/scripts/memory.py +58 -12
- package/scripts/cli.py +81 -28
- package/scripts/dream.py +1235 -1214
- package/scripts/memory.py +58 -12
package/scripts/memory.py
CHANGED
|
@@ -1102,8 +1102,40 @@ def save_all(records: list) -> None:
|
|
|
1102
1102
|
except OSError:
|
|
1103
1103
|
pass
|
|
1104
1104
|
raise
|
|
1105
|
-
|
|
1106
|
-
|
|
1105
|
+
# LS-009(v5.59):为 save_all 增加多文件替换失败原子回滚!
|
|
1106
|
+
replaced_backups = [] # [(target_path, backup_path)]
|
|
1107
|
+
try:
|
|
1108
|
+
for tmp, p in staged:
|
|
1109
|
+
bak_old = None
|
|
1110
|
+
if p.exists():
|
|
1111
|
+
bak_old = p.with_name(p.name + f".rollback-{os.getpid()}-{int(now_ts() * 1000) % 1000000}")
|
|
1112
|
+
try:
|
|
1113
|
+
shutil.copy2(p, bak_old)
|
|
1114
|
+
except Exception:
|
|
1115
|
+
bak_old = None
|
|
1116
|
+
_replace_retry(tmp, p)
|
|
1117
|
+
if bak_old:
|
|
1118
|
+
replaced_backups.append((p, bak_old))
|
|
1119
|
+
except BaseException as replace_err:
|
|
1120
|
+
for target_p, bak_p in reversed(replaced_backups):
|
|
1121
|
+
try:
|
|
1122
|
+
_replace_retry(bak_p, target_p)
|
|
1123
|
+
except Exception:
|
|
1124
|
+
pass
|
|
1125
|
+
for tmp, _ in staged:
|
|
1126
|
+
try:
|
|
1127
|
+
if tmp.exists():
|
|
1128
|
+
os.unlink(tmp)
|
|
1129
|
+
except OSError:
|
|
1130
|
+
pass
|
|
1131
|
+
raise replace_err
|
|
1132
|
+
finally:
|
|
1133
|
+
for _, bak_p in replaced_backups:
|
|
1134
|
+
try:
|
|
1135
|
+
if bak_p.exists():
|
|
1136
|
+
os.unlink(bak_p)
|
|
1137
|
+
except OSError:
|
|
1138
|
+
pass
|
|
1107
1139
|
|
|
1108
1140
|
# 写后校验:JSON 可解析 + 末行完整 + 层级自洽。不通过就回滚并抛错
|
|
1109
1141
|
# (回滚成功时数据是"旧的一致状态",比留着一份写坏的新数据安全)。
|
|
@@ -3075,8 +3107,8 @@ def _ledger_path():
|
|
|
3075
3107
|
return HOME / _LEDGER_FILE
|
|
3076
3108
|
|
|
3077
3109
|
|
|
3078
|
-
def
|
|
3079
|
-
"""
|
|
3110
|
+
def _ledger_add_strict(record: dict, reason: str = "purge") -> bool:
|
|
3111
|
+
"""LS-016: 把一条记录追加进软删除台账,返回是否成功。"""
|
|
3080
3112
|
try:
|
|
3081
3113
|
row = dict(record)
|
|
3082
3114
|
row["deleted_at"] = now_ts()
|
|
@@ -3085,10 +3117,15 @@ def _ledger_add(record: dict, reason: str = "purge") -> None:
|
|
|
3085
3117
|
with _locked(_ledger_path()):
|
|
3086
3118
|
with _ledger_path().open("a", encoding="utf-8") as f:
|
|
3087
3119
|
f.write(json.dumps(row, ensure_ascii=False) + "\n")
|
|
3088
|
-
|
|
3089
|
-
|
|
3120
|
+
return True
|
|
3121
|
+
except Exception as exc:
|
|
3122
|
+
log_event("purge", f"软删除台账严格写入失败:{exc}", level="error")
|
|
3123
|
+
return False
|
|
3090
3124
|
|
|
3091
3125
|
|
|
3126
|
+
def _ledger_add(record: dict, reason: str = "purge") -> None:
|
|
3127
|
+
"""把一条记录追加进软删除台账(调用方负责持锁)。失败不阻断删除主流程。"""
|
|
3128
|
+
_ledger_add_strict(record, reason)
|
|
3092
3129
|
def trash_list(limit: int = 50) -> list:
|
|
3093
3130
|
"""看软删除台账里有什么(最近优先)。"""
|
|
3094
3131
|
rows = []
|
|
@@ -3210,7 +3247,9 @@ def purge(memory_id: str, confirm_token: str) -> dict:
|
|
|
3210
3247
|
# 而 _ledger_add 会吞掉所有异常只记 warn —— 于是"删成功 + 台账写失败"
|
|
3211
3248
|
# (磁盘满/权限/文件被占)时,这条归档记忆被物理销毁且哪里都没有副本,
|
|
3212
3249
|
# 用户无法恢复,直接违反"只移不删、删除必须先留底"。
|
|
3213
|
-
|
|
3250
|
+
# LS-016(v5.59):台账写入失败时必须禁止物理删除!
|
|
3251
|
+
if not _ledger_add_strict(target, reason="purge-archive"):
|
|
3252
|
+
raise RuntimeError(f"软删除台账写入失败,为防数据丢失已中止物理删除:{memory_id}")
|
|
3214
3253
|
write_jsonl(HOME / "archive.jsonl", archive)
|
|
3215
3254
|
_cut_assoc_links(memory_id)
|
|
3216
3255
|
audit_log("user", "purge", memory_id, "物理删除(archive 副本)")
|
|
@@ -3224,7 +3263,9 @@ def purge(memory_id: str, confirm_token: str) -> dict:
|
|
|
3224
3263
|
raise ValueError(
|
|
3225
3264
|
f"淡忘记忆需冷静满 {_PURGE_COOLDOWN_DAYS} 天后才能物理删除"
|
|
3226
3265
|
f"(当前淡忘于 {fmt_date(forgotten_at)})")
|
|
3227
|
-
|
|
3266
|
+
# LS-016(v5.59):台账写入失败时必须禁止物理删除!
|
|
3267
|
+
if not _ledger_add_strict(target, reason="purge-dust"):
|
|
3268
|
+
raise RuntimeError(f"软删除台账写入失败,为防数据丢失已中止物理删除:{memory_id}")
|
|
3228
3269
|
records = [m for m in records if m.get("id") != memory_id]
|
|
3229
3270
|
save_all(records)
|
|
3230
3271
|
# archive 里可能也有同名副本(归档过的),一并清掉
|
|
@@ -3716,15 +3757,20 @@ def _sweep_locked(rows: list) -> int:
|
|
|
3716
3757
|
arch.append(r)
|
|
3717
3758
|
continue
|
|
3718
3759
|
keep.append(r)
|
|
3760
|
+
# LS-017(v5.59):归档失败时保留工作记忆原记录!
|
|
3761
|
+
actually_archived = []
|
|
3762
|
+
failed_arch = []
|
|
3719
3763
|
if arch:
|
|
3720
|
-
rows[:] = keep
|
|
3721
3764
|
path = _work_archive_path()
|
|
3722
3765
|
for r in arch:
|
|
3723
3766
|
try:
|
|
3724
3767
|
_append_jsonl(path, r)
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3768
|
+
actually_archived.append(r)
|
|
3769
|
+
except OSError as exc:
|
|
3770
|
+
log_event("working", f"工作记忆归档单条失败,保留在原工作区:{exc}", level="warn")
|
|
3771
|
+
failed_arch.append(r)
|
|
3772
|
+
rows[:] = keep + failed_arch
|
|
3773
|
+
return len(actually_archived)
|
|
3728
3774
|
|
|
3729
3775
|
|
|
3730
3776
|
def work_sweep() -> int:
|