dsh-memu-memory 1.3.11 → 1.3.12
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 +11 -0
- package/README.md +1 -1
- package/README.zh.md +1 -1
- package/docs/memory-semantics.md +2 -0
- package/docs/troubleshooting.md +9 -0
- package/lib/client.js +96 -33
- package/lib/memory.js +81 -0
- package/lib/rpc.js +35 -2
- package/package.json +1 -1
- package/tests/client-render.test.mjs +110 -0
- package/tests/global-lifecycle.test.mjs +130 -0
- package/tests/webui-auth.test.mjs +72 -0
- package/tests/webui.test.mjs +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# 更新日志 / Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.12] - 2026-11-20
|
|
4
|
+
|
|
5
|
+
> 全局记忆生命周期与私有同权:记忆墙全局块多选批量归档/恢复/删除、抽屉与全局记忆页的归档/恢复/两段确认永久删除补齐;内容仍由 curator 书写。
|
|
6
|
+
|
|
7
|
+
- **管理面 RPC(不新增方法)**:既有 `archiveMemory` / `updateMemory` / `deleteMemory` 支持显式 `scope:'global'`。全局 `updateMemory` 只接受 `{status:'active'}` 恢复补丁,其余字段一律拒绝(内容写入仍归 curator,硬规则 2 不变);`scope:'global'` 与 `libraryId` 同现是作用域冲突,鉴权层直接拒。鉴权与全局复核队列同口径:embedded 要活绑定,standalone 走 `libraryId=null` 的 `review.manage` capability。
|
|
8
|
+
- **归档即生效**:`globalSetStatus` 只改 status——召回/锚点/注入统一过 `isMemoryEligible`,archived 立即自动排除,不动向量行(与 privateArchive 同口径)。`pending_review` 必须先走复核队列;`superseded` 可归档但不能直接恢复。
|
|
9
|
+
- **永久删除**:只开放 archived/suppressed/expired,需显式确认 + 删除前整库备份;先删引擎/向量行再单事务删行,级联清他条 `links[].to` 与 `duplicateOf/relatedTo/conflictingWith/supersededBy/absorbedBy` 指针。合并稿(带 `absorbedFrom`)与活跃合并的来源拒删——`absorbSnapshot` 是撤销合并的唯一依据。全局删除没有 preview/restore 撤销缓冲(明确报错,不静默)。
|
|
10
|
+
- **UI 统一**:记忆墙全局块启用多选(批量归档/恢复/两段删除,逐条失败一次性报错口径与私有一致);抽屉全局条目内容只读但生命周期按钮齐全(待复核条目不显示归档,走复核裁决);全局记忆页每条带状态 Tag 与归档/恢复/两段删除。侧栏会话视图保持只读。
|
|
11
|
+
- 守卫:`tests/global-lifecycle.test.mjs`(状态机/召回排除/级联/合并守卫/管理视图/私有回归)、`tests/webui-auth.test.mjs` 全局生命周期凭据矩阵、`tests/client-render.test.mjs` 全局块多选与抽屉两段删除;`tests/webui.test.mjs` 抽屉删除静态守卫更新为双作用域形状。
|
|
12
|
+
- 文档同步:README(中英)抽屉口径、`docs/memory-semantics.md` §8.3 生命周期管理面、`docs/troubleshooting.md` §3.42。
|
|
13
|
+
|
|
3
14
|
## [1.3.11] - 2026-11-20
|
|
4
15
|
|
|
5
16
|
> 隐藏记忆不再经词法统计挤掉可见召回;必写候选核验改为保守证据比对,同日不同事/极性相反/数值改变不再被误判「已覆盖」。
|
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ The sidebar has exactly **one** entry: **MemU WebUI**. The memory wall and all s
|
|
|
93
93
|
|
|
94
94
|
**Private / global groups with multi-select.** The "Memories" page splits into **Private** and **Global** blocks (private first, default). The private block supports **multi-select**: bulk archive, restore and permanent delete (two-step confirm) — one failed row never eats the rest. Every row on the Global memory page has a "View" action that jumps straight to that entry on the wall.
|
|
95
95
|
|
|
96
|
-
**In-place work.** Clicking a memory card opens a right-side drawer with the full text and the fields that decide how it behaves — title, content, tags, disclosure, confidence, open loop — plus save, archive, restore and "open in the browser" for heavier work. Archived memories can be deleted in the same drawer; the first click only arms it and the second confirms. Global memories
|
|
96
|
+
**In-place work.** Clicking a memory card opens a right-side drawer with the full text and the fields that decide how it behaves — title, content, tags, disclosure, confidence, open loop — plus save, archive, restore and "open in the browser" for heavier work. Archived memories can be deleted in the same drawer; the first click only arms it and the second confirms. Global memories keep their curator-written content read-only in the drawer, but archive, restore and two-step permanent delete work there just like private ones, and link to their own page. Filters and scroll position stay where they were. Cards that carry images use the first usable attachment as a cover, and the drawer opens the full gallery; `secret` and `never_say` entries never receive a pixel URL, so they show a label instead.
|
|
97
97
|
|
|
98
98
|
**One page for the graph.** **Relations** is its own full-screen page in the WebUI (`#/settings/graph`): the canvas on the left, the inspector on the right, and a **Manage** tab for the list view with the same filters. Source (all / automatic only / manual only), rule, library and search all narrow one shared dataset instead of switching modes, and Settings → Relations is a single button that opens that page. The scope selector still carries a **Global memory** entry: nodes are global entries and edges are `related/refines/supports`; the global view is read-only, and edges are removed from the global memory list.
|
|
99
99
|
|
package/README.zh.md
CHANGED
|
@@ -92,7 +92,7 @@
|
|
|
92
92
|
|
|
93
93
|
**私有 / 全局分组与多选。** 「MemU 记忆」页按 **私有 / 全局** 分块(默认私有),私有块支持**多选**:批量归档、恢复、彻底删除(两段确认),一条失败不影响其余成果。「全局记忆」页每条记忆带「查看此记忆」,点击直达 MemU 记忆页对应条目。
|
|
94
94
|
|
|
95
|
-
**原地操作。**
|
|
95
|
+
**原地操作。** 点记忆卡片会从右侧滑出详情抽屉:完整正文,以及决定它行为的字段——标题、正文、标签、说出口径、置信度、未了之事——外加保存、归档、恢复,以及需要重编辑时的「在记忆浏览中打开」。已归档的记忆可以直接在抽屉里删除:第一次点击只是准备,第二次才真正删除。全局记忆的正文仍由整理器书写、在抽屉里只读,但归档、恢复与两段确认的永久删除与私有记忆同权,并给出跳转。筛选条件与滚动位置保持不动。带图片的卡片会把第一张可用附件作为封面,抽屉里展开完整图片组;`secret` 与 `never_say` 条目不会拿到像素 URL,只显示标签占位。
|
|
96
96
|
|
|
97
97
|
**图谱单独一页。** 「关系图谱」是 WebUI 里一个全屏页面(`#/settings/graph`):左边画布、右边检视面板,列表视图在同页的**管理**页签下,用的是同一套筛选。来源(全部 / 仅自动 / 仅手动)、规则、记忆库与搜索都在收窄同一份数据,不是要记得切换的模式;设置里的「关系图谱」只有一个按钮,点了直达这一页。范围选择器仍然带一项**全局记忆**:节点是全局条目、边是 `related/refines/supports`,全局视图只读,移除边仍在全局记忆列表里完成。
|
|
98
98
|
|
package/docs/memory-semantics.md
CHANGED
|
@@ -26,6 +26,8 @@
|
|
|
26
26
|
|
|
27
27
|
只有 curator 写,主 agent 只读。domain:`universal / coding / rp / project:<name> / tooling / personal`,**RP 与 coding 冲突分域存,不合并**。RP 剧情事实、关系进度、临时情绪**不写全局**;每条必须有 `evidence` + `confidence`。
|
|
28
28
|
|
|
29
|
+
**生命周期管理面(1.3.12)**:内容仍由 curator 书写,但用户管理面与私有同权——记忆墙全局块支持多选批量归档/恢复/删除,抽屉与全局记忆页提供归档、恢复、两段确认永久删除。RPC 走既有 `archiveMemory` / `updateMemory` / `deleteMemory` 加显式 `scope:'global'`(不新增方法):全局 `updateMemory` 只接受 `{status:'active'}` 恢复补丁,其余字段一律拒绝;鉴权与全局复核队列同口径(embedded 要活绑定,standalone 走 `libraryId=null` 的 `review.manage`),`scope:'global'` 与 `libraryId` 同现是作用域冲突。归档只改 status——召回/锚点/注入统一过 `isMemoryEligible`,archived 立即自动排除,不动向量行;`pending_review` 必须先走复核队列,`superseded` 不能直接恢复。永久删除只开放 archived/suppressed/expired,需显式确认 + 删除前整库备份,单事务级联清他条 `links[].to` 与 `duplicateOf/relatedTo/conflictingWith/supersededBy/absorbedBy` 指针;合并稿(带 `absorbedFrom`)与活跃合并的来源拒删——`absorbSnapshot` 是撤销合并的唯一依据。全局删除没有 preview/restore 撤销缓冲。守卫:`tests/global-lifecycle.test.mjs`、`tests/webui-auth.test.mjs`(全局生命周期凭据矩阵)、`tests/client-render.test.mjs`(全局块多选与抽屉两段删除)。
|
|
30
|
+
|
|
29
31
|
**审核模式(`curatorReviewMode`)**:`auto`(默认)= 有落地证据的提炼结果自动通过;`review-all` = 提炼产物一律进待复核。`conflict`(说法矛盾)与无证据的条目在任何模式下都进人审;rewrite 类操作(merge/supersede/absorb)在 auto 下风险 ≥0.70 也暂扣。每条都带 `reviewRisk/reviewRiskReasons` 供审计与复核排序。
|
|
30
32
|
|
|
31
33
|
**证据落地(grounding)**:evidence 的 quote 必须是本次策划所含会话转录的规范化子串(≥6 字,省略号分段校验,先脱敏)——模型编造的"原话"进不了库;未落地恒 pending 或不落库。
|
package/docs/troubleshooting.md
CHANGED
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
worker 前置依赖 / 完整包超限 / usage 未知 → §3.39
|
|
38
38
|
整理输出截断 / 改预算后同快照仍冻结 → §3.40
|
|
39
39
|
隐藏记忆增加后可见结果消失 / 必写候选误结算 → §3.41
|
|
40
|
+
全局记忆归档/删除不生效或越权 / 合并稿被误删 → §3.42
|
|
40
41
|
聊很久一条记忆都没写 → §3.18
|
|
41
42
|
人格预设会话里完全没有记忆 → §3.19
|
|
42
43
|
鉴权 / 401/403 行为说不清 → §3.20
|
|
@@ -730,3 +731,11 @@ grep tests 里的硬编码清单。守卫:全量 `npm test` 1676/1674 pass / 0
|
|
|
730
731
|
**落点:** `lib/memory.js` 的私库纯词法与混合召回词法支路在建 BM25 语料前应用会话、自动资格、披露与说话人过滤。只在最终排序时过滤会让隐藏条目污染词频,甚至触发高频词裁剪。显式精确 id 读取维持原资格规则;全局路由不扩大可见范围。`lib/private.js` 的 `candidateCovered` 不能仅凭日期相同或两个相邻字片段就结算候选。
|
|
731
732
|
|
|
732
733
|
**守卫:** `tests/recall-corpus-eligibility.test.mjs` 用隔离临时库覆盖纯词法、成功的混合路径与向量故障回退,加入 secret、错角色、never_say、only_if_asked 条目后,可见命中保持不变,并保留精确 id 读取。`tests/consolidation-fork.test.mjs` 覆盖同日不同事件、极性相反、动作改变、数值改变及日期单独命中等反例,并保留真实改写正例。`scripts/recall-bench.mjs` 的 `recallAt3` 是任一预期条目命中率;新增 `allExpectedAt3` 要求前三名包含所有预期 id,避免冲突题仅命中一方就被误读为完整覆盖。
|
|
734
|
+
|
|
735
|
+
### 3.42 全局记忆生命周期管理面
|
|
736
|
+
|
|
737
|
+
**症状:** 全局块没有多选/归档/删除按钮(1.3.12 前的旧版);或归档后全局记忆仍被召回;或带 `sessionId` 的全局写被拒/越权;或合并稿、活跃合并的来源被永久删除后撤销合并悬空。
|
|
738
|
+
|
|
739
|
+
**落点:** 全局生命周期走既有 `archiveMemory` / `updateMemory` / `deleteMemory` 加显式 `scope:'global'`(`lib/rpc.js`),鉴权与全局复核队列同口径(`authorizeGlobalReviewRoute`:embedded 要活绑定,standalone 走 `libraryId=null` 的 `review.manage`);`scope:'global'` 与 `libraryId` 同现在鉴权层就拒。`lib/memory.js` 的 `globalSetStatus` 只改 status(召回/锚点/注入统一过 `isMemoryEligible`,archived 立即排除,不动向量行);全局 `updateMemory` 只接受 `{status:'active'}`。`globalDelete` 只开放 archived/suppressed/expired + 显式确认 + 删除前 `backupDatabases`,单事务级联清他条 `links[].to` 与 `duplicateOf/relatedTo/conflictingWith/supersededBy/absorbedBy`;带 `absorbedFrom` 的合并稿与活跃合并的来源拒删。前端:记忆墙全局块多选与私有同权(`lib/client.js` MemoryWallPanel),抽屉全局条目内容只读但生命周期按钮齐全,全局记忆页每条带归档/恢复/两段删除。
|
|
740
|
+
|
|
741
|
+
**守卫:** `tests/global-lifecycle.test.mjs`(归档即排除召回/恢复即回来、状态机边界、内容补丁拒绝、删除级联与合并守卫、管理视图仍见 archived、私有路径回归);`tests/webui-auth.test.mjs` 的「global lifecycle」凭据矩阵(活绑定/悬空会话/作用域冲突/review.manage 四态);`tests/client-render.test.mjs` 的全局块多选批量归档与抽屉两段删除(注意 harness 的 hook 游标全局递增:同一棵树只能 walk 一遍)。
|
package/lib/client.js
CHANGED
|
@@ -318,7 +318,7 @@ window.__ModuleLoader__.load({
|
|
|
318
318
|
viewRelations: '节点图',
|
|
319
319
|
close: '关闭',
|
|
320
320
|
openInBrowser: '在记忆浏览中打开',
|
|
321
|
-
globalReadOnly: '
|
|
321
|
+
globalReadOnly: '全局记忆的内容由整理器书写,这里只读;归档、恢复与删除用下方按钮,与私有记忆同权。',
|
|
322
322
|
confidenceLabel: '置信度',
|
|
323
323
|
tagsLabel: '标签',
|
|
324
324
|
memoryMissing: '这条记忆已经不在了。',
|
|
@@ -1267,7 +1267,7 @@ window.__ModuleLoader__.load({
|
|
|
1267
1267
|
viewRelations: 'Node graph',
|
|
1268
1268
|
close: 'Close',
|
|
1269
1269
|
openInBrowser: 'Open in the browser',
|
|
1270
|
-
globalReadOnly: 'Global
|
|
1270
|
+
globalReadOnly: 'Global memory content is curator-written and read-only here; archive, restore and delete below carry the same rights as private memories.',
|
|
1271
1271
|
confidenceLabel: 'Confidence',
|
|
1272
1272
|
tagsLabel: 'Tags',
|
|
1273
1273
|
memoryMissing: 'This memory no longer exists.',
|
|
@@ -4436,7 +4436,8 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4436
4436
|
const [query, setQuery] = React.useState('')
|
|
4437
4437
|
const [error, setError] = React.useState('')
|
|
4438
4438
|
const [version, setVersion] = React.useState(0)
|
|
4439
|
-
// 组分类:私有 /
|
|
4439
|
+
// 组分类:私有 / 全局两块,默认私有、私有靠前。全局条目内容只读(curator 写),
|
|
4440
|
+
// 但生命周期(归档/恢复/删除)与私有同权,多选两块都生效。
|
|
4440
4441
|
const [scope, setScope] = React.useState('private')
|
|
4441
4442
|
const [multi, setMulti] = React.useState(false)
|
|
4442
4443
|
const [selectedIds, setSelectedIds] = React.useState(() => new Set())
|
|
@@ -4567,6 +4568,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4567
4568
|
setDetail({ ...current, file, draft: draftOf(file), busy: false, error: '' })
|
|
4568
4569
|
reload()
|
|
4569
4570
|
}
|
|
4571
|
+
// 全局条目没有 getMemory 路由:刷新重拉 listGlobal(管理面不过滤状态,
|
|
4572
|
+
// 归档后仍读得到),内容保持只读。
|
|
4573
|
+
const refreshGlobalDetail = async (current) => {
|
|
4574
|
+
const res = await call('listGlobal', {})
|
|
4575
|
+
const file = (res.files || []).find(entry => entry.id === current.item.id) || null
|
|
4576
|
+
setDetail({ ...current, file, draft: null, busy: false, error: file ? '' : t('memoryMissing'), readonly: true })
|
|
4577
|
+
reload()
|
|
4578
|
+
}
|
|
4570
4579
|
const saveDetail = async () => {
|
|
4571
4580
|
const current = detail
|
|
4572
4581
|
if (!current?.file || current.readonly || !current.draft) return
|
|
@@ -4593,11 +4602,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4593
4602
|
}
|
|
4594
4603
|
const setDetailStatus = async (status) => {
|
|
4595
4604
|
const current = detail
|
|
4596
|
-
if (!current?.file
|
|
4605
|
+
if (!current?.file) return
|
|
4597
4606
|
setDetail({ ...current, busy: true, error: '' })
|
|
4598
4607
|
try {
|
|
4599
|
-
|
|
4600
|
-
|
|
4608
|
+
if (current.item.libraryId) {
|
|
4609
|
+
await call('updateMemory', { libraryId: current.item.libraryId, id: current.item.id, patch: { status } })
|
|
4610
|
+
await refreshDetail(current)
|
|
4611
|
+
} else {
|
|
4612
|
+
if (status === 'archived') await call('archiveMemory', { scope: 'global', id: current.item.id })
|
|
4613
|
+
else await call('updateMemory', { scope: 'global', id: current.item.id, patch: { status: 'active' } })
|
|
4614
|
+
await refreshGlobalDetail(current)
|
|
4615
|
+
}
|
|
4601
4616
|
// 归档/恢复/保存是三个不同结果,同一条通知通道但各说各话。
|
|
4602
4617
|
notice(status === 'archived' ? t('memoryArchived') : status === 'active' ? t('memoryRestored') : t('memorySaved'))
|
|
4603
4618
|
} catch (failure) {
|
|
@@ -4606,13 +4621,16 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4606
4621
|
}
|
|
4607
4622
|
const deleteDetail = async () => {
|
|
4608
4623
|
const current = detail
|
|
4609
|
-
if (!current?.file || current.
|
|
4624
|
+
if (!current?.file || current.file.status !== 'archived') return
|
|
4610
4625
|
setDetail({ ...current, busy: true, error: '' })
|
|
4611
4626
|
try {
|
|
4612
|
-
await call('deleteMemory', {
|
|
4627
|
+
await call('deleteMemory', {
|
|
4628
|
+
...(current.item.libraryId ? { libraryId: current.item.libraryId } : { scope: 'global' }),
|
|
4629
|
+
id: current.item.id, confirmed: true,
|
|
4630
|
+
})
|
|
4613
4631
|
setDetail(null)
|
|
4614
4632
|
setDeleteArmed(false)
|
|
4615
|
-
notifyMemoryWrite('memory', current.item.libraryId)
|
|
4633
|
+
notifyMemoryWrite('memory', current.item.libraryId || null)
|
|
4616
4634
|
notice(t('memoryDeleted'))
|
|
4617
4635
|
reload()
|
|
4618
4636
|
} catch (failure) {
|
|
@@ -4639,9 +4657,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4639
4657
|
}
|
|
4640
4658
|
}
|
|
4641
4659
|
|
|
4642
|
-
// ——
|
|
4643
|
-
// 逐条走既有 RPC(updateMemory patch.status / deleteMemory
|
|
4644
|
-
//
|
|
4660
|
+
// —— 多选批量操作(私有与全局同权;全局走显式 scope:'global' 管理面路由)——
|
|
4661
|
+
// 逐条走既有 RPC(updateMemory patch.status / archiveMemory / deleteMemory),
|
|
4662
|
+
// 循环里失败的条目记下来一次性报错:部分成功不能说成全部成功,也不该让一条失败吞掉其余的成果。
|
|
4645
4663
|
const exitMulti = () => { setMulti(false); setSelectedIds(new Set()); setDeleteArmedMulti(false) }
|
|
4646
4664
|
const bulkApply = async (action) => {
|
|
4647
4665
|
const targets = selectedRows(visible).filter(item => action === 'archive'
|
|
@@ -4653,15 +4671,18 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4653
4671
|
const failures = []
|
|
4654
4672
|
for (const item of targets) {
|
|
4655
4673
|
try {
|
|
4656
|
-
|
|
4657
|
-
|
|
4674
|
+
const global = !item.libraryId
|
|
4675
|
+
const target = global ? { scope: 'global' } : { libraryId: item.libraryId }
|
|
4676
|
+
if (action === 'delete') await call('deleteMemory', { ...target, id: item.id, confirmed: true })
|
|
4677
|
+
else if (global && action === 'archive') await call('archiveMemory', { ...target, id: item.id })
|
|
4678
|
+
else await call('updateMemory', { ...target, id: item.id, patch: { status: action === 'archive' ? 'archived' : 'active' } })
|
|
4658
4679
|
done += 1
|
|
4659
4680
|
} catch (failure) { failures.push(`${item.title || item.id}: ${String(failure?.message || failure)}`) }
|
|
4660
4681
|
}
|
|
4661
4682
|
setWallBusy(false)
|
|
4662
4683
|
setDeleteArmedMulti(false)
|
|
4663
4684
|
setSelectedIds(new Set())
|
|
4664
|
-
if (done > 0) { notifyMemoryWrite('memory', libraryId || null); reload() }
|
|
4685
|
+
if (done > 0) { notifyMemoryWrite('memory', scope === 'global' ? null : (libraryId || null)); reload() }
|
|
4665
4686
|
// 部分成功不说成全部成功:有失败只走 error(带 done/total 前缀),全成功才报 notice。
|
|
4666
4687
|
if (failures.length > 0) setError(`${done}/${targets.length} · ` + failures.slice(0, 3).join(';'))
|
|
4667
4688
|
else if (done > 0) notice(t('bulkDone').replace('{n}', String(done)))
|
|
@@ -4721,8 +4742,9 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4721
4742
|
affectText ? h('div', { className: 'dshm-drawer-note' }, affectText) : null)
|
|
4722
4743
|
: detail && detail.file && detail.readonly
|
|
4723
4744
|
? (() => {
|
|
4724
|
-
//
|
|
4725
|
-
//
|
|
4745
|
+
// 全局条目内容只读(spec §6.7 UI):详情抽屉里只读展示 links / absorbedFrom,
|
|
4746
|
+
// 不提供编辑、不提供手动全局关联;生命周期按钮(归档/恢复/删除)与私有同权。
|
|
4747
|
+
// links 移除按钮在全局页(F1 接入)。
|
|
4726
4748
|
const absorbed = Array.isArray(detail.file.absorbedFrom) ? detail.file.absorbedFrom : []
|
|
4727
4749
|
const links = Array.isArray(detail.file.links) ? detail.file.links : []
|
|
4728
4750
|
return h(React.Fragment, null,
|
|
@@ -4793,14 +4815,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4793
4815
|
!detail.readonly
|
|
4794
4816
|
? h(Button, { primary: true, disabled: detail.busy, onClick: () => { void saveDetail() } }, t('save'))
|
|
4795
4817
|
: null,
|
|
4796
|
-
!detail.readonly && detail.file
|
|
4818
|
+
detail.file && !(detail.readonly && detail.file.status === 'pending_review')
|
|
4797
4819
|
? h(Button, {
|
|
4798
4820
|
style: S.ghost,
|
|
4799
4821
|
disabled: detail.busy,
|
|
4800
4822
|
onClick: () => { void setDetailStatus(detail.file.status === 'archived' ? 'active' : 'archived') },
|
|
4801
4823
|
}, detail.file.status === 'archived' ? t('restore') : t('archive'))
|
|
4802
4824
|
: null,
|
|
4803
|
-
|
|
4825
|
+
detail.file?.status === 'archived'
|
|
4804
4826
|
? deleteArmed
|
|
4805
4827
|
? h(React.Fragment, null,
|
|
4806
4828
|
h(Button, {
|
|
@@ -4879,15 +4901,13 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4879
4901
|
h('option', { value: '', disabled: multiBlocked }, t('allLibraries')),
|
|
4880
4902
|
libraries.map((lib) => h('option', { key: lib.id, value: lib.id }, libraryOptionLabel(lib, libraries))))
|
|
4881
4903
|
: null
|
|
4882
|
-
const hasOptionControls =
|
|
4883
|
-
const multiToggle =
|
|
4884
|
-
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
|
|
4889
|
-
: null
|
|
4890
|
-
const multiActions = multi && scope === 'private' ? (() => {
|
|
4904
|
+
const hasOptionControls = true
|
|
4905
|
+
const multiToggle = h(Button, {
|
|
4906
|
+
'aria-pressed': multi,
|
|
4907
|
+
style: multi ? { ...S.ghost, color: V.accent, borderColor: V.accent } : S.ghost,
|
|
4908
|
+
onClick: () => { if (multi) exitMulti(); else setMulti(true) },
|
|
4909
|
+
}, multi ? t('wallMultiExit') : t('multiSelect'))
|
|
4910
|
+
const multiActions = multi ? (() => {
|
|
4891
4911
|
const chosen = selectedRows(visible)
|
|
4892
4912
|
const archiveN = chosen.filter(item => ['active', 'inactive'].includes(poolOf(item))).length
|
|
4893
4913
|
const restoreN = chosen.filter(item => item.status === 'archived').length
|
|
@@ -4925,10 +4945,10 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4925
4945
|
'aria-label': multi ? t('multiSelect') : undefined,
|
|
4926
4946
|
style: { marginTop: 8, marginBottom: 0 },
|
|
4927
4947
|
},
|
|
4928
|
-
//
|
|
4948
|
+
// 多选对私有与全局同权:全局走 scope:'global' 管理面路由。
|
|
4929
4949
|
multiToggle,
|
|
4930
4950
|
multiActions,
|
|
4931
|
-
multiBlocked ? h('span', { style: S.muted, role: 'status' }, t('wallAllBlocked')) : null,
|
|
4951
|
+
multiBlocked && scope === 'private' ? h('span', { style: S.muted, role: 'status' }, t('wallAllBlocked')) : null,
|
|
4932
4952
|
data?.total > items.length ? h('span', { style: S.muted }, t('wallLimit') + ` (${items.length}/${data.total})`) : null) : null,
|
|
4933
4953
|
wallTabGroup(poolItems, pool, setPool, { label: t('wallFilterStatus'), marginTop: 12 }),
|
|
4934
4954
|
wallTabGroup(layerItems, layer, setLayer, { label: t('wallFilterLayer'), marginTop: 10 }),
|
|
@@ -4938,14 +4958,14 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
4938
4958
|
style: multi && selectedIds.has(keyOf(item)) ? { outline: '2px solid ' + V.accent, outlineOffset: -2 } : undefined,
|
|
4939
4959
|
onClick: () => {
|
|
4940
4960
|
// 多选模式下点卡片 = 勾选/取消勾选;正常模式打开抽屉。
|
|
4941
|
-
if (multi
|
|
4961
|
+
if (multi) {
|
|
4942
4962
|
setSelectedIds(prev => { const next = new Set(prev); if (next.has(keyOf(item))) next.delete(keyOf(item)); else next.add(keyOf(item)); return next })
|
|
4943
4963
|
return
|
|
4944
4964
|
}
|
|
4945
4965
|
void openDetail(item)
|
|
4946
4966
|
},
|
|
4947
4967
|
},
|
|
4948
|
-
multi
|
|
4968
|
+
multi ? h(Tag, { tone: selectedIds.has(keyOf(item)) ? 'info' : null }, selectedIds.has(keyOf(item)) ? '✓' : '□') : null,
|
|
4949
4969
|
h(WallCover, { item }),
|
|
4950
4970
|
h('div', { className: 'dshm-wall-meta' }, h('span', null, item.libraryId ? item.libraryName : t('globalMemory')), h('span', null, enumText(t, LAYER_LABELS, item.layer))),
|
|
4951
4971
|
h('strong', null, item.title || item.id),
|
|
@@ -6353,6 +6373,34 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
6353
6373
|
await loadReviews()
|
|
6354
6374
|
} catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
|
|
6355
6375
|
}
|
|
6376
|
+
// 全局生命周期(归档/恢复/永久删除):与 undo-absorb 同一管理面凭据口径
|
|
6377
|
+
// (embedded 带活会话 sessionId,standalone 走 capability)。归档/恢复可逆,
|
|
6378
|
+
// 单击即行;永久删除两段确认,服务端删除前整库备份。
|
|
6379
|
+
const refreshGlobalList = async () => {
|
|
6380
|
+
const res = await call('listGlobal', {})
|
|
6381
|
+
setGlobalFiles(res.files || [])
|
|
6382
|
+
setGlobalLoaded(true)
|
|
6383
|
+
}
|
|
6384
|
+
const setGlobalStatus = async (id, status) => {
|
|
6385
|
+
setBusy(true)
|
|
6386
|
+
try {
|
|
6387
|
+
if (status === 'archived') await call('archiveMemory', { scope: 'global', id, sessionId: sessionId || undefined })
|
|
6388
|
+
else await call('updateMemory', { scope: 'global', id, patch: { status: 'active' }, sessionId: sessionId || undefined })
|
|
6389
|
+
setNotice(status === 'archived' ? t('memoryArchived') : t('memoryRestored'))
|
|
6390
|
+
notifyMemoryWrite('memory', null)
|
|
6391
|
+
await refreshGlobalList()
|
|
6392
|
+
} catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
|
|
6393
|
+
}
|
|
6394
|
+
const deleteGlobalEntry = async (id) => {
|
|
6395
|
+
if (!confirmAction('global-delete:' + id)) return
|
|
6396
|
+
setBusy(true)
|
|
6397
|
+
try {
|
|
6398
|
+
await call('deleteMemory', { scope: 'global', id, confirmed: true, sessionId: sessionId || undefined })
|
|
6399
|
+
setNotice(t('memoryDeleted'))
|
|
6400
|
+
notifyMemoryWrite('memory', null)
|
|
6401
|
+
await refreshGlobalList()
|
|
6402
|
+
} catch (e) { setError(String(e?.message || e)) } finally { setBusy(false) }
|
|
6403
|
+
}
|
|
6356
6404
|
// 导出契约(spec §6.2):显式对象参数——libraryId 缺省取当前浏览库,但调用点可以
|
|
6357
6405
|
// 传入别的 id(契约保证 payload、回退文件名、成功提示都用**传入**的 id)。
|
|
6358
6406
|
const exportLibraryNow = async ({ libraryId = browseLibId, includeAttachments = false } = {}) => {
|
|
@@ -7314,15 +7362,17 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
7314
7362
|
// 集合记忆(spec §6.7 UI):absorbedFrom → 「集合记忆 · N 条来源」Tag +
|
|
7315
7363
|
// 「撤销合并」两段确认按钮(resolveReview action:'undo-absorb')。links
|
|
7316
7364
|
// 只读展示 + 「移除」(resolveReview action:'unlink'),不提供手动全局关联。
|
|
7365
|
+
// 生命周期与私有同权:归档/恢复单击,永久删除两段确认(仅已归档条目)。
|
|
7317
7366
|
const absorbed = Array.isArray(f.absorbedFrom) ? f.absorbedFrom : []
|
|
7318
7367
|
const links = Array.isArray(f.links) ? f.links : []
|
|
7319
7368
|
const titleOf = (id) => (globalFiles.find((item) => item.id === id)?.title) || id
|
|
7320
7369
|
return h('div', { key: f.id, style: S.item },
|
|
7321
7370
|
h('div', { style: { display: 'flex', justifyContent: 'space-between', gap: 8 } },
|
|
7322
7371
|
h('strong', null, f.title || f.id),
|
|
7323
|
-
h('div', { style: { display: 'flex', gap: 6, flexShrink: 0 } },
|
|
7372
|
+
h('div', { style: { display: 'flex', gap: 6, flexShrink: 0, flexWrap: 'wrap', justifyContent: 'flex-end' } },
|
|
7324
7373
|
h(Tag, null, domainText(t, f.domain)),
|
|
7325
7374
|
h(Tag, null, `conf ${f.confidence ?? '?'}`),
|
|
7375
|
+
f.status && f.status !== 'active' ? h(Tag, { tone: 'warn' }, enumText(t, STATUS_LABELS, f.status)) : null,
|
|
7326
7376
|
links.length ? h(Tag, { tone: 'info' }, t('linkCountTag').replace('{n}', String(links.length))) : null,
|
|
7327
7377
|
absorbed.length ? h(Tag, { tone: 'info' }, t('absorbSourcesTag').replace('{n}', String(absorbed.length))) : null,
|
|
7328
7378
|
// 撤销合并:两段确认(点一次变为「确认此操作?」,再点才发请求)。
|
|
@@ -7334,6 +7384,19 @@ const SOURCE_LABELS = { user_said: 'sourceUserSaid', inferred: 'sourceInferred',
|
|
|
7334
7384
|
onClick: () => { void undoAbsorb(f.id) },
|
|
7335
7385
|
}, actionLabel('undo-absorb:' + f.id, t('absorbUndo')))
|
|
7336
7386
|
: null,
|
|
7387
|
+
f.status === 'archived'
|
|
7388
|
+
? h(Button, { style: S.ghost, disabled: busy, onClick: () => { void setGlobalStatus(f.id, 'active') } }, t('restore'))
|
|
7389
|
+
: f.status !== 'pending_review'
|
|
7390
|
+
? h(Button, { style: S.ghost, disabled: busy, onClick: () => { void setGlobalStatus(f.id, 'archived') } }, t('archive'))
|
|
7391
|
+
: null,
|
|
7392
|
+
f.status === 'archived'
|
|
7393
|
+
? h(Button, {
|
|
7394
|
+
style: { ...S.ghost, color: V.danger },
|
|
7395
|
+
disabled: busy,
|
|
7396
|
+
title: t('browseArchivedHint'),
|
|
7397
|
+
onClick: () => { void deleteGlobalEntry(f.id) },
|
|
7398
|
+
}, actionLabel('global-delete:' + f.id, t('deleteForever')))
|
|
7399
|
+
: null,
|
|
7337
7400
|
// 查看此记忆:切到 MemU 记忆页的全局块并直接打开对应条目的抽屉。
|
|
7338
7401
|
h(Button, {
|
|
7339
7402
|
style: S.ghost,
|
package/lib/memory.js
CHANGED
|
@@ -4591,6 +4591,87 @@ export function noteGlobalInjected({ ids = [], at = stamp() }) {
|
|
|
4591
4591
|
return touched
|
|
4592
4592
|
}
|
|
4593
4593
|
|
|
4594
|
+
// 全局生命周期是用户管理面动作(与 resolveReview 的全局元数据动作同鉴权口径),
|
|
4595
|
+
// 不是 curator 的内容写入:只改 status。召回/锚点/注入都过 isMemoryEligible,
|
|
4596
|
+
// archived 立即自动排除,向量行无需改动(与 privateArchive 同口径)。
|
|
4597
|
+
export async function globalSetStatus({ id, status }) {
|
|
4598
|
+
const target = String(id || '').trim()
|
|
4599
|
+
if (!target) throw new Error('memory id is required')
|
|
4600
|
+
if (!['active', 'archived'].includes(status)) throw new Error('global lifecycle only supports active and archived')
|
|
4601
|
+
let result = null
|
|
4602
|
+
let changed = false
|
|
4603
|
+
await retryStoreWrite(() => updateGlobalIndex((index) => {
|
|
4604
|
+
const entry = index.entries[target]
|
|
4605
|
+
if (!entry) throw new Error(`unknown global memory: ${target}`)
|
|
4606
|
+
if (status === 'archived') {
|
|
4607
|
+
if (entry.status === 'pending_review') throw new Error('a pending global memory must be resolved in the review queue first')
|
|
4608
|
+
if (entry.status === 'archived') { result = { id: target, entry }; return }
|
|
4609
|
+
} else if (entry.status !== 'archived') {
|
|
4610
|
+
throw new Error('only archived global memories can be restored')
|
|
4611
|
+
}
|
|
4612
|
+
entry.status = status
|
|
4613
|
+
entry.updatedAt = stamp()
|
|
4614
|
+
changed = true
|
|
4615
|
+
result = { id: target, entry }
|
|
4616
|
+
}))
|
|
4617
|
+
if (changed) {
|
|
4618
|
+
record({
|
|
4619
|
+
kind: 'write', scope: 'global', libraryId: null,
|
|
4620
|
+
message: status === 'archived' ? '全局记忆归档(管理面)' : '全局记忆恢复(管理面)',
|
|
4621
|
+
detail: { id: target, status }, refs: [target],
|
|
4622
|
+
})
|
|
4623
|
+
}
|
|
4624
|
+
return result
|
|
4625
|
+
}
|
|
4626
|
+
|
|
4627
|
+
/**
|
|
4628
|
+
* 全局永久删除,与 privateDeleteImpl 同序:先删引擎/向量行(引擎拒绝则索引不动),
|
|
4629
|
+
* 再在单事务里删行并级联清掉他条指向它的 links 与指针字段。合并稿与活跃合并的
|
|
4630
|
+
* 来源拒删——absorbSnapshot 是撤销合并的唯一依据,删掉成员会让撤销悬空。
|
|
4631
|
+
* 安全网是 RPC 层的两段确认 + backupDatabases,与私有单条删除一致。
|
|
4632
|
+
*/
|
|
4633
|
+
export async function globalDelete({ id }) {
|
|
4634
|
+
const target = String(id || '').trim()
|
|
4635
|
+
if (!target) throw new Error('memory id is required')
|
|
4636
|
+
const index = loadGlobalIndex()
|
|
4637
|
+
const entry = index.entries[target]
|
|
4638
|
+
if (!entry) throw new Error(`unknown global memory: ${target}`)
|
|
4639
|
+
if (!['archived', 'suppressed', 'expired'].includes(entry.status)) {
|
|
4640
|
+
throw new Error('only archived memories can be deleted permanently; archive it first')
|
|
4641
|
+
}
|
|
4642
|
+
if (Array.isArray(entry.absorbedFrom) && entry.absorbedFrom.length) {
|
|
4643
|
+
throw new Error('this merged memory still carries its absorb snapshot; undo the merge first')
|
|
4644
|
+
}
|
|
4645
|
+
const merged = Object.entries(index.entries).find(([otherId, other]) => otherId !== target
|
|
4646
|
+
&& other?.status === 'active' && Array.isArray(other.absorbedFrom) && other.absorbedFrom.includes(target))
|
|
4647
|
+
if (merged) throw new Error(`this memory is a source of merged memory ${merged[0]}; undo the merge first`)
|
|
4648
|
+
const backend = engineRoute()
|
|
4649
|
+
let engine = null
|
|
4650
|
+
if (backend !== 'lexical') {
|
|
4651
|
+
engine = await forget({ route: backend, db: globalDbPath(), name: target })
|
|
4652
|
+
}
|
|
4653
|
+
await retryStoreWrite(() => updateGlobalIndex((fresh) => {
|
|
4654
|
+
if (JSON.stringify(fresh.entries[target]) !== JSON.stringify(entry)) throw new Error('memory changed during deletion; reload and retry')
|
|
4655
|
+
delete fresh.entries[target]
|
|
4656
|
+
for (const other of Object.values(fresh.entries)) {
|
|
4657
|
+
if (Array.isArray(other.links) && other.links.some(link => link?.to === target)) {
|
|
4658
|
+
other.links = other.links.filter(link => link?.to !== target)
|
|
4659
|
+
}
|
|
4660
|
+
if (other.duplicateOf === target) delete other.duplicateOf
|
|
4661
|
+
if (other.relatedTo === target) delete other.relatedTo
|
|
4662
|
+
if (other.conflictingWith === target) delete other.conflictingWith
|
|
4663
|
+
if (other.supersededBy === target) delete other.supersededBy
|
|
4664
|
+
if (other.absorbedBy === target) delete other.absorbedBy
|
|
4665
|
+
}
|
|
4666
|
+
}))
|
|
4667
|
+
record({
|
|
4668
|
+
kind: 'write', scope: 'global', libraryId: null,
|
|
4669
|
+
message: '全局记忆永久删除(管理面)',
|
|
4670
|
+
detail: { id: target, backend }, refs: [target],
|
|
4671
|
+
})
|
|
4672
|
+
return { id: target, libraryId: null, deleted: true, backend, engine }
|
|
4673
|
+
}
|
|
4674
|
+
|
|
4594
4675
|
// Local calendar day (not UTC): "today" for a reminder is the user's today, the same
|
|
4595
4676
|
// unit `salientDaysAhead` measures in.
|
|
4596
4677
|
function localDateKey(date) {
|
package/lib/rpc.js
CHANGED
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
storageHealth, effectiveScope, summarizeIndex, getPromptDomains, addPromptDomain, removePromptDomain, memoryRevision, memoryStamp, noteMemoryBeat,
|
|
9
9
|
} from './state.js'
|
|
10
10
|
import { commit, closeMemuResident, prewarmMemuResident } from './memu.js'
|
|
11
|
-
import { privateList, privateUpdate, privateRemember, privateRecall, privateArchive, privateDelete, previewDelete, restoreDeleted, globalList, globalRecall, domainOf, decayStrength, appliesToDomain, importMemories, recordImportBatch, revertImportBatch, resolveMemoryReview, visibleToSession, isMemoryEligible } from './memory.js'
|
|
11
|
+
import { privateList, privateUpdate, privateRemember, privateRecall, privateArchive, privateDelete, previewDelete, restoreDeleted, globalList, globalRecall, globalSetStatus, globalDelete, domainOf, decayStrength, appliesToDomain, importMemories, recordImportBatch, revertImportBatch, resolveMemoryReview, visibleToSession, isMemoryEligible } from './memory.js'
|
|
12
12
|
import { normalizeMemoryContext } from './context.js'
|
|
13
13
|
import { requestPrivateConsolidation } from './private.js'
|
|
14
14
|
import { listHostModelOptions, discoverForkModels, redactConsolidationSettings, disposeConsolidationRoute } from './fork-model.js'
|
|
@@ -73,7 +73,10 @@ function requireSessionId(payload) {
|
|
|
73
73
|
// entry's dispatch consumes `payload.libraryId` — or, for updateMemory and
|
|
74
74
|
// archiveMemory, falls back to the same persisted session binding that
|
|
75
75
|
// `routeLibraryId` resolves — so the target authorized here is exactly the
|
|
76
|
-
// target dispatch works on.
|
|
76
|
+
// target dispatch works on. updateMemory/archiveMemory/deleteMemory are
|
|
77
|
+
// additionally dual-scope: an explicit `scope:'global'` addresses the global
|
|
78
|
+
// store and is authorized by authorizeGlobalReviewRoute, never as a library.
|
|
79
|
+
// Endpoints that are session- or host-scoped
|
|
77
80
|
// (getState, getSidebarState, initSession, setLibrary, setFolderPolicy, engine
|
|
78
81
|
// and settings management, …) are not library-addressed: their credential is
|
|
79
82
|
// the host's own requestRejection plus, for session-scoped reads, the session
|
|
@@ -172,6 +175,13 @@ async function authorizeGlobalLexiconRoute(connection, req, endpoint, payload) {
|
|
|
172
175
|
}
|
|
173
176
|
|
|
174
177
|
async function authorizeLibraryRoute(connection, req, endpoint, payload, libraryId = routeLibraryId(endpoint, payload)) {
|
|
178
|
+
// Global lifecycle (archive/restore/delete via scope:'global') is management-plane
|
|
179
|
+
// like the global review queue, never a private-library target: it follows the
|
|
180
|
+
// same credential model, and naming a library alongside it is a scope conflict.
|
|
181
|
+
if (payload?.scope === 'global' && ['archiveMemory', 'updateMemory', 'deleteMemory'].includes(endpoint)) {
|
|
182
|
+
if (String(payload?.libraryId || '').trim()) return false
|
|
183
|
+
return authorizeGlobalReviewRoute(connection, req, endpoint, payload)
|
|
184
|
+
}
|
|
175
185
|
// Review endpoints are dual-scope: without an explicit libraryId they address
|
|
176
186
|
// the global curator queue, which follows its own management model.
|
|
177
187
|
if ((endpoint === 'listReviews' || endpoint === 'resolveReview') && !String(payload?.libraryId || '').trim()) {
|
|
@@ -1389,6 +1399,16 @@ async function dispatch(ctx, endpoint, payload = {}) {
|
|
|
1389
1399
|
const id = String(payload?.id || '')
|
|
1390
1400
|
if (!id) throw new Error('id is required')
|
|
1391
1401
|
const patch = payload?.patch || {}
|
|
1402
|
+
// 全局条目内容仍由 curator 写(硬规则 2):管理面这里只开放「从归档恢复」,
|
|
1403
|
+
// 其余字段一律拒绝,不做静默丢弃。
|
|
1404
|
+
if (payload?.scope === 'global') {
|
|
1405
|
+
if (String(payload?.libraryId || '').trim()) throw new Error('global scope takes no libraryId')
|
|
1406
|
+
const keys = Object.keys(patch)
|
|
1407
|
+
if (keys.length !== 1 || keys[0] !== 'status' || patch.status !== 'active') {
|
|
1408
|
+
throw new Error('global memories only support restoring to active here; content stays curator-written')
|
|
1409
|
+
}
|
|
1410
|
+
return globalSetStatus({ id, status: 'active' })
|
|
1411
|
+
}
|
|
1392
1412
|
// `layer` is here so the browser can promote a short_term draft to long_term,
|
|
1393
1413
|
// which is the one upgrade path memory.js supports in place.
|
|
1394
1414
|
// `source` is writable: correcting provenance is the point of showing it.
|
|
@@ -1975,6 +1995,10 @@ async function dispatch(ctx, endpoint, payload = {}) {
|
|
|
1975
1995
|
case 'archiveMemory': {
|
|
1976
1996
|
const id = String(payload?.id || '')
|
|
1977
1997
|
if (!id) throw new Error('memory id is required')
|
|
1998
|
+
if (payload?.scope === 'global') {
|
|
1999
|
+
if (String(payload?.libraryId || '').trim()) throw new Error('global scope takes no libraryId')
|
|
2000
|
+
return globalSetStatus({ id, status: 'archived' })
|
|
2001
|
+
}
|
|
1978
2002
|
if (payload?.libraryId) return privateArchive({ libraryId: String(payload.libraryId), id })
|
|
1979
2003
|
return privateArchive({ exec: execFor(requireSessionId(payload)), id })
|
|
1980
2004
|
}
|
|
@@ -1984,6 +2008,15 @@ async function dispatch(ctx, endpoint, payload = {}) {
|
|
|
1984
2008
|
// hallucinated id away from erasing a memory it never read.
|
|
1985
2009
|
const id = String(payload?.id || '')
|
|
1986
2010
|
if (!id) throw new Error('memory id is required')
|
|
2011
|
+
// 全局删除走显式 scope:'global'(管理面鉴权):没有私有库目标,也没有
|
|
2012
|
+
// preview/restore 撤销缓冲——安全网是两段确认 + 删除前整库备份。
|
|
2013
|
+
if (payload?.scope === 'global') {
|
|
2014
|
+
if (String(payload?.libraryId || '').trim()) throw new Error('global scope takes no libraryId')
|
|
2015
|
+
if (payload?.preview === true || payload?.restore === true) throw new Error('global delete has no preview/restore buffer; it is guarded by two-step confirmation and a fresh backup')
|
|
2016
|
+
if (payload?.confirmed !== true) throw new Error('permanently deleting a memory requires explicit confirmation')
|
|
2017
|
+
const safety = await backupDatabases()
|
|
2018
|
+
return { ...await globalDelete({ id }), safety }
|
|
2019
|
+
}
|
|
1987
2020
|
const libraryId = String(payload?.libraryId || '')
|
|
1988
2021
|
if (!libraryId) throw new Error('libraryId is required')
|
|
1989
2022
|
if (!getLibrary(libraryId)) throw new Error('library not found')
|
package/package.json
CHANGED
|
@@ -1391,3 +1391,113 @@ test('the log page renders rows with copy, download and locate actions', async (
|
|
|
1391
1391
|
assert.match(text, /logKindCheck/, 'the activity log labels wake-up checks')
|
|
1392
1392
|
assert.match(text, /large-transcript-thin/, 'the check row keeps its reason and score visible')
|
|
1393
1393
|
})
|
|
1394
|
+
|
|
1395
|
+
test('the memory wall global block bulk-archives and the drawer deletes global entries two-step', async () => {
|
|
1396
|
+
const rpcCalls = []
|
|
1397
|
+
const ctx = fakeCtx({ rpcCalls })
|
|
1398
|
+
const originalGetState = RPC_ANSWERS.getState
|
|
1399
|
+
const originalSettingsState = RPC_ANSWERS.getSettingsState
|
|
1400
|
+
const loaded = {
|
|
1401
|
+
...EMPTY_STATE,
|
|
1402
|
+
libraries: [{ id: 'lib-1', name: 'demo', scopeKey: '/proj/demo', privateCount: 0 }],
|
|
1403
|
+
}
|
|
1404
|
+
RPC_ANSWERS.getState = loaded
|
|
1405
|
+
RPC_ANSWERS.getSettingsState = loaded
|
|
1406
|
+
RPC_ANSWERS.browseWall = {
|
|
1407
|
+
total: 2,
|
|
1408
|
+
items: [
|
|
1409
|
+
{ id: 'mem-g-active', libraryId: null, libraryName: 'global', title: 'global active', preview: 'active body', layer: 'long_term', status: 'active', source: 'inferred', decay: 0.5, tags: [] },
|
|
1410
|
+
{ id: 'mem-g-archived', libraryId: null, libraryName: 'global', title: 'global archived', preview: 'archived body', layer: 'long_term', status: 'archived', source: 'inferred', decay: 0.5, tags: [] },
|
|
1411
|
+
],
|
|
1412
|
+
}
|
|
1413
|
+
RPC_ANSWERS.listGlobal = {
|
|
1414
|
+
files: [
|
|
1415
|
+
{ id: 'mem-g-active', title: 'global active', content: 'active body', status: 'active', domain: 'general' },
|
|
1416
|
+
{ id: 'mem-g-archived', title: 'global archived', content: 'archived body', status: 'archived', domain: 'general' },
|
|
1417
|
+
],
|
|
1418
|
+
}
|
|
1419
|
+
RPC_ANSWERS.archiveMemory = { id: 'mem-g-active', entry: { status: 'archived' } }
|
|
1420
|
+
RPC_ANSWERS.deleteMemory = { id: 'mem-g-archived', libraryId: null, deleted: true }
|
|
1421
|
+
const tick = () => new Promise((resolve) => setTimeout(resolve, 0))
|
|
1422
|
+
// harness 的 hook 游标是全局的:同一棵树只能展开一次,二次 walk 会把子组件
|
|
1423
|
+
// 的 useState 重新初始化。所以每次 renderPage 后只 walk 一遍,收齐所有节点。
|
|
1424
|
+
const collect = (tree) => {
|
|
1425
|
+
const labels = new Map()
|
|
1426
|
+
const cards = []
|
|
1427
|
+
const tabs = []
|
|
1428
|
+
walkNodes(tree, (node) => {
|
|
1429
|
+
if (typeof node.type === 'function' && typeof node.props?.children === 'string' && !labels.has(node.props.children)) {
|
|
1430
|
+
labels.set(node.props.children, node)
|
|
1431
|
+
}
|
|
1432
|
+
if (node.type === 'button' && String(node.props?.className || '').includes('dshm-wall-item')) cards.push(node)
|
|
1433
|
+
if (node.type === 'button' && node.props?.role === 'tab') tabs.push(node)
|
|
1434
|
+
})
|
|
1435
|
+
return { labels, cards, tabs }
|
|
1436
|
+
}
|
|
1437
|
+
try {
|
|
1438
|
+
globalThis.__dshMemuExports.apply(ctx)
|
|
1439
|
+
const settings = registrations.filter((r) => r.slot === 'settings.section').pop()
|
|
1440
|
+
const props = { ctx, t: (key) => key }
|
|
1441
|
+
const first = await renderPage(settings.component, props, undefined, { remount: true })
|
|
1442
|
+
collectPageHook()
|
|
1443
|
+
for (const effect of first.effects) effect.fn()
|
|
1444
|
+
await tick(); await tick()
|
|
1445
|
+
let view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1446
|
+
for (const effect of effects) effect.fn()
|
|
1447
|
+
await tick(); await tick()
|
|
1448
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1449
|
+
|
|
1450
|
+
// 切到全局块:多选开关必须存在(旧版全局块没有)。
|
|
1451
|
+
const scopeTab = view.tabs.find((node) => String(node.props?.children || '').startsWith('wallScopeGlobal'))
|
|
1452
|
+
assert.ok(scopeTab, 'the global scope tab did not render')
|
|
1453
|
+
scopeTab.props.onClick()
|
|
1454
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1455
|
+
assert.ok(view.labels.has('multiSelect'), 'the global block offers multi-select')
|
|
1456
|
+
view.labels.get('multiSelect').props.onClick()
|
|
1457
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1458
|
+
assert.equal(view.cards.length, 1, 'the active pool shows the active global card')
|
|
1459
|
+
view.cards[0].props.onClick()
|
|
1460
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1461
|
+
assert.ok(view.labels.has('archive (1)'), 'selecting one global card arms the bulk archive button')
|
|
1462
|
+
view.labels.get('archive (1)').props.onClick()
|
|
1463
|
+
await tick(); await tick()
|
|
1464
|
+
const archived = rpcCalls.filter((call) => call.endpoint === 'archiveMemory')
|
|
1465
|
+
assert.equal(archived.length, 1)
|
|
1466
|
+
assert.equal(archived[0].payload.scope, 'global')
|
|
1467
|
+
assert.equal(archived[0].payload.id, 'mem-g-active')
|
|
1468
|
+
assert.equal(archived[0].payload.libraryId, undefined, 'global bulk writes never name a private library')
|
|
1469
|
+
|
|
1470
|
+
// 已归档池开抽屉:恢复与两段删除都在,删除第一段只武装、第二段才发请求。
|
|
1471
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1472
|
+
view.labels.get('wallMultiExit').props.onClick()
|
|
1473
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1474
|
+
const archivedTab = view.tabs.find((node) => String(node.props?.children || '').startsWith('browseArchivedTab'))
|
|
1475
|
+
archivedTab.props.onClick()
|
|
1476
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1477
|
+
assert.equal(view.cards.length, 1)
|
|
1478
|
+
view.cards[0].props.onClick()
|
|
1479
|
+
await tick(); await tick()
|
|
1480
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1481
|
+
assert.ok(view.labels.has('restore'), 'the archived global drawer offers restore')
|
|
1482
|
+
assert.ok(view.labels.has('deleteForever'), 'the archived global drawer offers permanent delete')
|
|
1483
|
+
assert.ok(!view.labels.has('save'), 'global content stays curator-written')
|
|
1484
|
+
view.labels.get('deleteForever').props.onClick()
|
|
1485
|
+
view = collect((await renderPage(settings.component, props, 9)).tree)
|
|
1486
|
+
assert.equal(rpcCalls.filter((call) => call.endpoint === 'deleteMemory').length, 0, 'the first click only arms')
|
|
1487
|
+
assert.ok(view.labels.has('confirmDelete'))
|
|
1488
|
+
view.labels.get('confirmDelete').props.onClick()
|
|
1489
|
+
await tick(); await tick()
|
|
1490
|
+
const deleted = rpcCalls.filter((call) => call.endpoint === 'deleteMemory')
|
|
1491
|
+
assert.equal(deleted.length, 1)
|
|
1492
|
+
assert.equal(deleted[0].payload.scope, 'global')
|
|
1493
|
+
assert.equal(deleted[0].payload.id, 'mem-g-archived')
|
|
1494
|
+
assert.equal(deleted[0].payload.confirmed, true)
|
|
1495
|
+
} finally {
|
|
1496
|
+
RPC_ANSWERS.getState = originalGetState
|
|
1497
|
+
RPC_ANSWERS.getSettingsState = originalSettingsState
|
|
1498
|
+
delete RPC_ANSWERS.browseWall
|
|
1499
|
+
delete RPC_ANSWERS.listGlobal
|
|
1500
|
+
delete RPC_ANSWERS.archiveMemory
|
|
1501
|
+
delete RPC_ANSWERS.deleteMemory
|
|
1502
|
+
}
|
|
1503
|
+
})
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import test from 'node:test'
|
|
2
|
+
import assert from 'node:assert/strict'
|
|
3
|
+
import fs from 'node:fs'
|
|
4
|
+
import os from 'node:os'
|
|
5
|
+
import path from 'node:path'
|
|
6
|
+
|
|
7
|
+
// 全局生命周期管理面(1.3.12):归档/恢复/两步永久删除与私有同权,内容仍由
|
|
8
|
+
// curator 书写。守卫口径:
|
|
9
|
+
// 1. 归档立即被召回排除(isMemoryEligible 统一闸门),恢复即回来;
|
|
10
|
+
// 2. 状态机边界:pending_review 走复核队列、superseded 不能直接恢复;
|
|
11
|
+
// 3. 全局 updateMemory 只接受 {status:'active'},内容补丁一律拒绝;
|
|
12
|
+
// 4. 删除只开放已归档/抑制/过期条目,需显式确认,级联清他条 links 与指针;
|
|
13
|
+
// 5. 合并稿与活跃合并的来源拒删(absorbSnapshot 是撤销合并的唯一依据);
|
|
14
|
+
// 6. 管理视图(browseWall/listGlobal standalone)仍看得到 archived 条目。
|
|
15
|
+
const home = fs.mkdtempSync(path.join(os.tmpdir(), 'dsh-memu-global-lifecycle-'))
|
|
16
|
+
process.env.DSH_MEMU_HOME = home
|
|
17
|
+
process.env.DSH_MEMU_MEMORY_HOME = home
|
|
18
|
+
const state = await import('../lib/state.js')
|
|
19
|
+
const memory = await import('../lib/memory.js')
|
|
20
|
+
const rpc = await import('../lib/rpc.js')
|
|
21
|
+
test.after(() => { state.flushState(); fs.rmSync(home, { recursive: true, force: true }) })
|
|
22
|
+
|
|
23
|
+
state.updateSettings({ memoryBackend: 'agent', vectorSource: 'local', crossLibraryRecall: false })
|
|
24
|
+
const sessionId = 'global-lifecycle-session'
|
|
25
|
+
state.ensureSession(sessionId, { cwd: path.join(home, 'proj') })
|
|
26
|
+
// 域自动探测会随 cwd 落成 coding:这里钉成 general,与种子条目的 domain 对齐。
|
|
27
|
+
state.setSessionBinding(sessionId, { domain: 'general', domainOverride: 'general', domainSource: 'manual' })
|
|
28
|
+
const exec = { agent: { session: { header: { id: sessionId } } } }
|
|
29
|
+
|
|
30
|
+
const entry = (title, extra = {}) => ({
|
|
31
|
+
title, content: title, status: 'active', layer: 'long_term', domain: 'general',
|
|
32
|
+
visibility: 'shared', disclosure: 'can_tell', source: 'inferred',
|
|
33
|
+
createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(), ...extra,
|
|
34
|
+
})
|
|
35
|
+
const seed = (entries) => {
|
|
36
|
+
state.updateGlobalIndex((index) => { index.entries = entries })
|
|
37
|
+
state.flushState()
|
|
38
|
+
}
|
|
39
|
+
const globalEntry = (id) => state.loadGlobalIndex().entries[id]
|
|
40
|
+
|
|
41
|
+
test('global archive drops the entry from recall; restore brings it back', async () => {
|
|
42
|
+
seed({ 'mem-g-visible': entry('zxquartzglobal 部署窗口'), 'mem-g-other': entry('unrelated filler') })
|
|
43
|
+
const before = await memory.globalRecall({ exec, query: 'zxquartzglobal', purpose: 'automatic', topK: 5, relevanceThreshold: 0 })
|
|
44
|
+
assert.deepEqual(before.files.map(f => f.name), ['mem-g-visible'])
|
|
45
|
+
assert.equal(memory.isMemoryEligible(globalEntry('mem-g-visible'), { automatic: true }), true)
|
|
46
|
+
|
|
47
|
+
const archived = await rpc.dispatch({}, 'archiveMemory', { scope: 'global', id: 'mem-g-visible' })
|
|
48
|
+
assert.equal(archived.entry.status, 'archived')
|
|
49
|
+
assert.equal(memory.isMemoryEligible(globalEntry('mem-g-visible'), { automatic: true }), false)
|
|
50
|
+
const after = await memory.globalRecall({ exec, query: 'zxquartzglobal', purpose: 'automatic', topK: 5, relevanceThreshold: 0 })
|
|
51
|
+
assert.deepEqual(after.files.map(f => f.name), [], 'archived global memory must not recall')
|
|
52
|
+
|
|
53
|
+
// 幂等归档不报错;恢复走 updateMemory 的唯一全局补丁形状。
|
|
54
|
+
await rpc.dispatch({}, 'archiveMemory', { scope: 'global', id: 'mem-g-visible' })
|
|
55
|
+
const restored = await rpc.dispatch({}, 'updateMemory', { scope: 'global', id: 'mem-g-visible', patch: { status: 'active' } })
|
|
56
|
+
assert.equal(restored.entry.status, 'active')
|
|
57
|
+
const back = await memory.globalRecall({ exec, query: 'zxquartzglobal', purpose: 'automatic', topK: 5, relevanceThreshold: 0 })
|
|
58
|
+
assert.deepEqual(back.files.map(f => f.name), ['mem-g-visible'])
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('global lifecycle state machine refuses review, superseded and content edits', async () => {
|
|
62
|
+
seed({
|
|
63
|
+
'mem-g-pending': entry('待复核条目', { status: 'pending_review' }),
|
|
64
|
+
'mem-g-superseded': entry('被取代条目', { status: 'superseded', supersededBy: 'mem-g-active' }),
|
|
65
|
+
'mem-g-active': entry('现行条目'),
|
|
66
|
+
})
|
|
67
|
+
await assert.rejects(() => rpc.dispatch({}, 'archiveMemory', { scope: 'global', id: 'mem-g-pending' }), /review queue/)
|
|
68
|
+
await assert.rejects(() => rpc.dispatch({}, 'updateMemory', { scope: 'global', id: 'mem-g-superseded', patch: { status: 'active' } }), /only archived/)
|
|
69
|
+
await assert.rejects(() => rpc.dispatch({}, 'updateMemory', { scope: 'global', id: 'mem-g-active', patch: { status: 'active' } }), /only archived/)
|
|
70
|
+
await assert.rejects(() => rpc.dispatch({}, 'updateMemory', { scope: 'global', id: 'mem-g-active', patch: { content: '改写' } }), /curator-written/)
|
|
71
|
+
await assert.rejects(() => rpc.dispatch({}, 'updateMemory', { scope: 'global', id: 'mem-g-active', patch: { status: 'archived' } }), /curator-written/)
|
|
72
|
+
await assert.rejects(() => rpc.dispatch({}, 'archiveMemory', { scope: 'global', id: 'mem-g-active', libraryId: 'lib-x' }), /libraryId/)
|
|
73
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-active', libraryId: 'lib-x', confirmed: true }), /libraryId/)
|
|
74
|
+
await assert.rejects(() => rpc.dispatch({}, 'archiveMemory', { scope: 'global', id: 'mem-g-missing' }), /unknown global memory/)
|
|
75
|
+
// superseded 可以归档(本就不可召回),但仍不能直接恢复。
|
|
76
|
+
await rpc.dispatch({}, 'archiveMemory', { scope: 'global', id: 'mem-g-superseded' })
|
|
77
|
+
assert.equal(globalEntry('mem-g-superseded').status, 'archived')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
test('global permanent delete is gated, confirmed, and cascades inbound pointers', async () => {
|
|
81
|
+
seed({
|
|
82
|
+
'mem-g-target': entry('删除目标', { status: 'archived' }),
|
|
83
|
+
'mem-g-live': entry('活跃条目'),
|
|
84
|
+
'mem-g-referrer': entry('引用者', {
|
|
85
|
+
links: [{ id: 'lnk-1', to: 'mem-g-target', kind: 'related' }, { id: 'lnk-2', to: 'mem-g-live', kind: 'related' }],
|
|
86
|
+
duplicateOf: 'mem-g-target', relatedTo: 'mem-g-target', conflictingWith: 'mem-g-target',
|
|
87
|
+
supersededBy: 'mem-g-target', absorbedBy: 'mem-g-target',
|
|
88
|
+
}),
|
|
89
|
+
})
|
|
90
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-live', confirmed: true }), /archive it first/)
|
|
91
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-target' }), /explicit confirmation/)
|
|
92
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-target', preview: true }), /no preview\/restore buffer/)
|
|
93
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-target', restore: true }), /no preview\/restore buffer/)
|
|
94
|
+
|
|
95
|
+
const deleted = await rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-target', confirmed: true })
|
|
96
|
+
assert.equal(deleted.deleted, true)
|
|
97
|
+
assert.equal(deleted.libraryId, null)
|
|
98
|
+
assert.equal(globalEntry('mem-g-target'), undefined)
|
|
99
|
+
const referrer = globalEntry('mem-g-referrer')
|
|
100
|
+
assert.deepEqual(referrer.links.map(l => l.to), ['mem-g-live'], 'inbound links to the deleted row are swept')
|
|
101
|
+
for (const field of ['duplicateOf', 'relatedTo', 'conflictingWith', 'supersededBy', 'absorbedBy']) {
|
|
102
|
+
assert.equal(referrer[field], undefined, `${field} must not dangle`)
|
|
103
|
+
}
|
|
104
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-target', confirmed: true }), /unknown global memory/)
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
test('global delete refuses merged entries and sources of a live merge', async () => {
|
|
108
|
+
seed({
|
|
109
|
+
'mem-g-merged': entry('合并稿', { status: 'archived', absorbedFrom: ['mem-g-source'], absorbSnapshot: {} }),
|
|
110
|
+
'mem-g-source': entry('来源', { status: 'archived', absorbedBy: 'mem-g-merged-live' }),
|
|
111
|
+
'mem-g-merged-live': entry('活跃合并稿', { absorbedFrom: ['mem-g-source'] }),
|
|
112
|
+
})
|
|
113
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-merged', confirmed: true }), /undo the merge first/)
|
|
114
|
+
await assert.rejects(() => rpc.dispatch({}, 'deleteMemory', { scope: 'global', id: 'mem-g-source', confirmed: true }), /source of merged memory mem-g-merged-live/)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
test('management views still show archived global rows; private archive path is unchanged', async () => {
|
|
118
|
+
seed({ 'mem-g-archived': entry('已归档全局', { status: 'archived' }) })
|
|
119
|
+
const wall = await rpc.dispatch({}, 'browseWall', { libraryId: null, limit: 300 })
|
|
120
|
+
assert.ok(wall.items.some(item => item.libraryId === null && item.id === 'mem-g-archived' && item.status === 'archived'))
|
|
121
|
+
const listed = await rpc.dispatch({}, 'listGlobal', {})
|
|
122
|
+
assert.ok(listed.files.some(file => file.id === 'mem-g-archived' && file.status === 'archived'))
|
|
123
|
+
|
|
124
|
+
// 私有路径回归:显式 libraryId 的 archiveMemory 不受 scope 分支影响。
|
|
125
|
+
const lib = state.createLibrary({ name: 'global-lifecycle-private', cwd: path.join(home, 'private') })
|
|
126
|
+
state.updatePrivateIndex(lib.id, (index) => { index.entries['mem-p-row'] = entry('私有条目') })
|
|
127
|
+
const archived = await rpc.dispatch({}, 'archiveMemory', { libraryId: lib.id, id: 'mem-p-row' })
|
|
128
|
+
assert.equal(archived.entry.status, 'archived')
|
|
129
|
+
assert.equal(state.loadPrivateIndex(lib.id).entries['mem-p-row'].status, 'archived')
|
|
130
|
+
})
|
|
@@ -783,6 +783,78 @@ test('global review queue: embedded sessions may read, writes need a live bindin
|
|
|
783
783
|
}
|
|
784
784
|
})
|
|
785
785
|
|
|
786
|
+
// 全局生命周期(1.3.12):scope:'global' 的 archiveMemory/updateMemory/deleteMemory
|
|
787
|
+
// 与全局复核队列同一管理面凭据模型——embedded 要活绑定、standalone 走 libraryId=null
|
|
788
|
+
// 的 review.manage;scope 与 libraryId 同时出现是作用域冲突,先于 dispatch 拒绝。
|
|
789
|
+
test('global lifecycle: scope global follows the global management credential model', async () => {
|
|
790
|
+
const seedGlobalActive = () => {
|
|
791
|
+
state.updateGlobalIndex((index) => {
|
|
792
|
+
index.entries['mem-global-lifecycle'] = {
|
|
793
|
+
title: 'global lifecycle', content: 'global lifecycle body', status: 'active', layer: 'long_term',
|
|
794
|
+
domain: 'general', visibility: 'shared', disclosure: 'can_tell', source: 'inferred',
|
|
795
|
+
createdAt: new Date().toISOString(), updatedAt: new Date().toISOString(),
|
|
796
|
+
}
|
|
797
|
+
})
|
|
798
|
+
state.flushState()
|
|
799
|
+
}
|
|
800
|
+
const post = (prefix, endpoint, payload) => send(prefix.route, prefix.base + '/' + endpoint, { method: 'POST', body: envelope(endpoint, payload) })
|
|
801
|
+
for (const prefix of prefixes) {
|
|
802
|
+
seedGlobalActive()
|
|
803
|
+
auth.callbackMode = 'present'
|
|
804
|
+
auth.libraryDecision = true
|
|
805
|
+
auth.libraryCalls = 0
|
|
806
|
+
const embedded = await post(prefix, 'archiveMemory', { scope: 'global', sessionId, id: 'mem-global-lifecycle' })
|
|
807
|
+
assert.equal(embedded.res.status, 200, `${prefix.name}: a live binding may archive global memory without the host callback`)
|
|
808
|
+
assert.equal(JSON.parse(embedded.res.text).result.ok, true)
|
|
809
|
+
assert.equal(state.loadGlobalIndex().entries['mem-global-lifecycle'].status, 'archived')
|
|
810
|
+
assert.equal(auth.libraryCalls, 0)
|
|
811
|
+
|
|
812
|
+
seedGlobalActive()
|
|
813
|
+
const ghost = await post(prefix, 'archiveMemory', { scope: 'global', sessionId: 'ghost-session', id: 'mem-global-lifecycle' })
|
|
814
|
+
assert.equal(ghost.res.status, 403, `${prefix.name}: a dangling session is never a credential`)
|
|
815
|
+
assert.equal(state.loadGlobalIndex().entries['mem-global-lifecycle'].status, 'active', 'a denied write must not touch the store')
|
|
816
|
+
|
|
817
|
+
const conflict = await post(prefix, 'archiveMemory', { scope: 'global', libraryId: 'lib-whatever', id: 'mem-global-lifecycle' })
|
|
818
|
+
assert.equal(conflict.res.status, 403, `${prefix.name}: scope global alongside a libraryId is a scope conflict`)
|
|
819
|
+
|
|
820
|
+
const rows = [
|
|
821
|
+
['archiveMemory', { scope: 'global', id: 'mem-global-lifecycle' }],
|
|
822
|
+
['updateMemory', { scope: 'global', id: 'mem-global-lifecycle', patch: { status: 'active' } }],
|
|
823
|
+
['deleteMemory', { scope: 'global', id: 'mem-global-lifecycle', confirmed: true }],
|
|
824
|
+
]
|
|
825
|
+
for (const [endpoint, payload] of rows) {
|
|
826
|
+
seedGlobalActive()
|
|
827
|
+
if (endpoint !== 'archiveMemory') {
|
|
828
|
+
state.updateGlobalIndex((index) => { index.entries['mem-global-lifecycle'].status = 'archived' })
|
|
829
|
+
}
|
|
830
|
+
auth.callbackMode = 'present'
|
|
831
|
+
auth.libraryDecision = true
|
|
832
|
+
auth.libraryCalls = 0
|
|
833
|
+
auth.libraryRequests.length = 0
|
|
834
|
+
const granted = await post(prefix, endpoint, payload)
|
|
835
|
+
assert.equal(granted.res.status, 200, `${prefix.name} ${endpoint}: review.manage true must grant`)
|
|
836
|
+
assert.equal(JSON.parse(granted.res.text).result.ok, true)
|
|
837
|
+
assert.equal(auth.libraryCalls, 1)
|
|
838
|
+
assert.equal(auth.libraryRequests.at(-1).libraryId, null, 'global lifecycle authorizes with libraryId null')
|
|
839
|
+
assert.equal(auth.libraryRequests.at(-1).operation, 'review.manage')
|
|
840
|
+
|
|
841
|
+
seedGlobalActive()
|
|
842
|
+
auth.libraryDecision = false
|
|
843
|
+
auth.libraryCalls = 0
|
|
844
|
+
assert.equal((await post(prefix, endpoint, payload)).res.status, 403, `${prefix.name} ${endpoint}: review.manage false must deny`)
|
|
845
|
+
assert.equal(auth.libraryCalls, 1)
|
|
846
|
+
|
|
847
|
+
auth.callbackMode = 'throw'
|
|
848
|
+
auth.libraryDecision = true
|
|
849
|
+
assert.equal((await post(prefix, endpoint, payload)).res.status, 403, `${prefix.name} ${endpoint}: a thrown callback must deny`)
|
|
850
|
+
|
|
851
|
+
auth.callbackMode = 'absent'
|
|
852
|
+
assert.equal((await post(prefix, endpoint, payload)).res.status, 200, `${prefix.name} ${endpoint}: absent callback falls back to the HTTP boundary`)
|
|
853
|
+
auth.callbackMode = 'present'
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
})
|
|
857
|
+
|
|
786
858
|
|
|
787
859
|
// ---- 2026-11-01 现场(Unexpected token "forbidden" / Invalid RPC response: 403)----
|
|
788
860
|
// 无 libraryId 的 browseWall("全部记忆库"视图)曾被硬拒 403:capability 缺席的宿主
|
package/tests/webui.test.mjs
CHANGED
|
@@ -135,7 +135,8 @@ test('the wall drawer reads exactly one memory', async () => {
|
|
|
135
135
|
assert.match(source, /function WallCover/, 'cards use the first usable attachment as a cover')
|
|
136
136
|
assert.match(source, /className: 'dshm-wall-cover'/)
|
|
137
137
|
assert.match(source, /detail\.file\?\.status === 'archived'/, 'delete is offered only for archived memories')
|
|
138
|
-
assert.match(source, /call\('deleteMemory', \{ libraryId: current\.item\.libraryId
|
|
138
|
+
assert.match(source, /call\('deleteMemory', \{\s*\.\.\.\(current\.item\.libraryId \? \{ libraryId: current\.item\.libraryId \} : \{ scope: 'global' \}\)/, 'the drawer delete names its target: private libraryId or explicit global scope')
|
|
139
|
+
assert.match(source, /id: current\.item\.id, confirmed: true/, 'the drawer delete always carries explicit confirmation')
|
|
139
140
|
assert.match(source, /t\('confirmDelete'\)/, 'deleting takes a second click')
|
|
140
141
|
assert.match(source, /current\.file\.status !== 'archived'/, 'the delete handler refuses live memories')
|
|
141
142
|
})
|