dsh-mnemon-source-documents 0.5.13 → 0.6.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/README.md CHANGED
@@ -19,6 +19,16 @@ Choose an existing data authority deliberately. Without `dataDir`, each stable S
19
19
 
20
20
  Manual management can create a document without a model, but it still needs a workspace in the request scope. Standalone archiving retains content locally; cross-Source LLM distillation is an optional Host workflow.
21
21
 
22
+ ## Permanent deletion / 永久删除
23
+
24
+ The detail page offers confirmed deletion for active and archived managed copies. Management uses `delete` with `{ id, fileRevision }`, `confirmed: true`, and the displayed index `expectedRevision`. It removes the managed Markdown file and index entry under the existing queue and store lock, releases active capacity, and restores the exact file bytes if committing the index fails. The file digest comes from the detail read, so edits made directly to the Markdown also reject stale confirmation. Unsafe paths, shared index paths and symlinks are rejected. This is not an archive: it runs without an Agent or a Memory Space write, and leaves project source files and existing Memory Space entries intact. There is no trash or undo; existing backup/sync retention rules are unchanged. The index stays at version 1 and needs no migration. As with existing multi-file mutations, process termination or a second disk failure during rollback is not a crash-atomic transaction.
25
+
26
+ The Source `manage` Action additionally accepts `action: "delete"`, `id`, `confirmed: true`, `expectedRevision`, and the target `fileRevision`. The target must belong to the execution's pinned active or archived ReadGrant. A Documents search returns its post-search index revision as `metadata.indexRevision` and each matched file digest as `items[].provenance.fileRevision`; a changed index or file rejects deletion rather than retrying automatically. Create-only workers cannot delete. The page client's optional `deleteDocument(id, expectedRevision, fileRevision)` callback preserves compatibility with custom pages that only implement create/update/archive.
27
+
28
+ 详情页支持确认后永久删除活跃或归档的托管副本。管理操作为 `delete`,输入 `{ id, fileRevision }`,并提供 `confirmed: true` 与页面所示索引的 `expectedRevision`。操作沿用队列与存储锁,移除托管 Markdown 和索引记录、释放活跃容量;索引提交失败时恢复原文件的完整字节,文件摘要取自详情读取,直接编辑 Markdown 也会使旧确认失效;同时拒绝不安全路径、索引共用路径与符号链接。删除无需 Agent,也不写入记忆空间;项目源文件与已有记忆空间条目保持原样。没有回收站或撤销,已有备份与同步保留规则不变。索引仍为版本 1,无需迁移。与现有多文件修改一样,进程中断或回滚期间再次发生磁盘故障不属于崩溃原子事务保证。
29
+
30
+ Source `manage` Action 新增 `action: "delete"`、`id`、`confirmed: true`、`expectedRevision` 与目标的 `fileRevision`,只允许删除该执行固定 ReadGrant 中的活跃或归档条目。档案检索在 `metadata.indexRevision` 返回检索后的索引修订,并在 `items[].provenance.fileRevision` 返回命中文件的摘要;索引或文件变化时拒绝删除,不自动重试。仅创建档案的工作 Agent 无权删除。页面客户端的 `deleteDocument(id, expectedRevision, fileRevision)` 为可选回调,原有仅支持创建、更新和归档的自定义页面可继续使用。
31
+
22
32
  ## Workspace ownership / 工作区归属
23
33
 
24
34
  Conversation tools use the session workspace (`agent.session.header.cwd`) as the Documents request scope. A shell `cd`, a Source file path, or a delegated task's initial command directory does not rebind that session workspace. Ordinary DSH subagents inherit the parent session's workspace, and delegated memory work retains the parent's pinned workspace authority.
package/lib/client.js CHANGED
@@ -80,6 +80,12 @@ window.__ModuleLoader__.load({
80
80
  "documents.selectText": "在左侧查看活跃项目知识或沿 Mnemon 引用打开归档原文。",
81
81
  "documents.coldArchive": "归档原文",
82
82
  "documents.edit": "编辑",
83
+ "documents.delete": "删除",
84
+ "documents.deleteConfirm": "永久删除这份档案?",
85
+ "documents.deleteDescription": "将永久移除档案记录和托管副本,无法撤销。不会建立记忆空间冷索引,也不会修改已有记忆空间条目或项目源文件。",
86
+ "documents.deleteNow": "永久删除",
87
+ "documents.deleting": "删除中…",
88
+ "documents.deleted": "档案已永久删除。",
83
89
  "documents.path": "托管路径",
84
90
  "documents.revision": "修订",
85
91
  "documents.hash": "内容哈希",
@@ -143,6 +149,12 @@ window.__ModuleLoader__.load({
143
149
  "documents.selectText": "Read active project knowledge or follow a Mnemon reference to an archived original.",
144
150
  "documents.coldArchive": "Archived original",
145
151
  "documents.edit": "Edit",
152
+ "documents.delete": "Delete",
153
+ "documents.deleteConfirm": "Permanently delete this document?",
154
+ "documents.deleteDescription": "This permanently removes the document record and managed copy and cannot be undone. No Memory Space index is created. Existing Memory Space entries and original project files remain unchanged.",
155
+ "documents.deleteNow": "Delete permanently",
156
+ "documents.deleting": "Deleting…",
157
+ "documents.deleted": "Document permanently deleted.",
146
158
  "documents.path": "Managed path",
147
159
  "documents.revision": "Revision",
148
160
  "documents.hash": "Content hash",
@@ -159,7 +171,7 @@ window.__ModuleLoader__.load({
159
171
  };
160
172
  //#endregion
161
173
  //#region \0source-css:/home/runner/work/dsh-mnemon/dsh-mnemon/plugins/dsh-mnemon-source-documents/presentation/page.module.css.mjs
162
- const css$2 = ".IIa07q_documentSummary{grid-template-columns:.7fr .7fr 1.6fr;gap:12px;margin-bottom:12px;display:grid}.IIa07q_documentSummary article{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);min-width:0;min-height:92px;padding:14px 16px}.IIa07q_documentSummary article>span{color:var(--mn-faint);font-size:12px;line-height:18px;display:block}.IIa07q_documentSummary article>strong{font-variant-numeric:tabular-nums;margin:4px 0 2px;font-size:20px;font-weight:500;line-height:28px;display:block}.IIa07q_documentSummary article>small{color:var(--mn-faint);font-size:12px;line-height:18px}.IIa07q_documentCapacity>div{background:var(--mn-fill);border-radius:999px;height:4px;margin:8px 0 6px;overflow:hidden}.IIa07q_documentCapacity>div i{border-radius:inherit;background:var(--dsw-alias-brand-primary);height:100%;transition:width .3s;display:block}.IIa07q_documentToolbar{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);align-items:center;gap:8px;margin-bottom:12px;padding:8px;display:flex}.IIa07q_documentToolbar form{flex:1;align-items:center;gap:8px;min-width:260px;display:flex}.IIa07q_documentSearch{flex:1}.IIa07q_documentEditor input,.IIa07q_documentEditor textarea{border:.5px solid var(--mn-field-line);border-radius:var(--dsw-radius-md);width:100%;color:var(--mn-text);background:var(--mn-input);outline:0;padding:6px 10px;font-size:13px;line-height:20px}.IIa07q_documentEditor input:focus,.IIa07q_documentEditor textarea:focus{border-color:var(--mn-accent)}.IIa07q_documentToolbar>div{border-radius:var(--dsw-radius-md);background:var(--mn-hover);align-items:center;gap:2px;padding:3px;display:flex}.IIa07q_documentToolbar>div button{border-radius:var(--dsw-radius-sm);min-height:28px;color:var(--mn-muted);cursor:pointer;background:0 0;border:0;padding:0 12px;font-size:13px;font-weight:500;line-height:20px}.IIa07q_documentToolbar>div button:hover{color:var(--mn-text)}.IIa07q_documentToolbar>div button[data-active]{color:var(--mn-text);background:var(--mn-layer-1);box-shadow:var(--dsw-elevation-soft)}.IIa07q_documentToolbar>div b{color:var(--mn-faint);font-variant-numeric:tabular-nums;margin-left:6px;font-size:12px;font-weight:400}.IIa07q_documentWorkspace{grid-template-columns:minmax(250px,310px) minmax(0,1fr);gap:12px;min-height:590px;display:grid}.IIa07q_documentList,.IIa07q_documentReader{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);min-width:0;overflow:hidden}.IIa07q_documentList{align-self:stretch}.IIa07q_documentList>header{border-bottom:.5px solid var(--mn-line);min-height:44px;color:var(--mn-faint);justify-content:space-between;align-items:center;padding:0 14px;font-size:12px;line-height:18px;display:flex}.IIa07q_documentList>header code{color:var(--mn-muted)}.IIa07q_documentList>button{--mn-provider-color:var(--mn-faint);border-radius:var(--dsw-radius-md);width:calc(100% - 12px);color:var(--mn-text);text-align:left;cursor:pointer;background:0 0;border:0;margin:6px 6px 0;padding:10px 12px;transition:background-color .15s;display:block}.IIa07q_documentList>button:hover{background:var(--mn-hover)}.IIa07q_documentList>button[data-selected]{background:var(--mn-fill)}.IIa07q_documentList>button>div{justify-content:space-between;align-items:baseline;gap:12px;display:flex}.IIa07q_documentList>button strong{text-overflow:ellipsis;white-space:nowrap;font-size:13px;font-weight:500;line-height:20px;overflow:hidden}.IIa07q_documentList>button time{color:var(--mn-faint);font-variant-numeric:tabular-nums;flex:none;font-size:11px}.IIa07q_documentList>button p{color:var(--mn-faint);-webkit-line-clamp:2;-webkit-box-orient:vertical;margin:4px 0 6px;font-size:12px;line-height:18px;display:-webkit-box;overflow:hidden}.IIa07q_documentList>button footer{color:var(--mn-faint);align-items:center;gap:8px;font-size:11px;line-height:16px;display:flex}.IIa07q_documentList>button footer code{margin-left:auto}.IIa07q_documentList>button footer em{color:var(--mn-danger);font-style:normal}.IIa07q_documentListEmpty{min-height:230px;color:var(--mn-muted);text-align:center;align-content:center;place-items:center;gap:4px;padding:24px;display:grid}.IIa07q_documentListEmpty>span{color:var(--mn-faint);margin-bottom:6px;font-size:24px;line-height:1}.IIa07q_documentListEmpty p{color:var(--mn-faint);margin:0;font-size:12px;line-height:18px}.IIa07q_documentReader{padding:clamp(16px,2vw,24px)}.IIa07q_documentReader>.IIa07q_emptyState{background:0 0;border:0;height:100%}.IIa07q_documentDetail>header{border-bottom:.5px solid var(--mn-line);justify-content:space-between;align-items:flex-start;gap:16px;padding-bottom:14px;display:flex}.IIa07q_documentDetail>header span{color:var(--mn-faint);font-size:12px;line-height:18px}.IIa07q_documentDetail>header h3{margin:2px 0;font-size:16px;font-weight:500;line-height:24px}.IIa07q_documentDetail>header p{color:var(--mn-faint);margin:0;font-size:12px;line-height:18px}.IIa07q_documentDetail>dl{border:.5px solid var(--mn-line);border-radius:var(--dsw-radius-md);grid-template-columns:2fr .45fr .8fr .55fr;margin:12px 0;display:grid;overflow:hidden}.IIa07q_documentDetail>dl>div{min-width:0;padding:8px 10px}.IIa07q_documentDetail>dl>div+div{border-left:.5px solid var(--mn-line)}.IIa07q_documentDetail dt{color:var(--mn-faint);margin-bottom:2px;font-size:11px;line-height:16px}.IIa07q_documentDetail dd{text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:12px;line-height:18px;overflow:hidden}.IIa07q_documentSources{flex-wrap:wrap;align-items:center;gap:6px;margin:12px 0;display:flex}.IIa07q_documentSources>span{color:var(--mn-faint);margin-right:4px;font-size:12px}.IIa07q_documentSources code,.IIa07q_documentArchiveReceipt code{color:var(--mn-muted);background:var(--mn-fill);border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px}.IIa07q_markdownBody{overflow-wrap:anywhere;border:.5px solid var(--mn-line);border-radius:var(--dsw-radius-md);min-height:310px;color:var(--mn-text);margin:16px 0 0;padding:clamp(16px,2.5vw,28px);font-size:14px;line-height:1.75}.IIa07q_markdownBody>:first-child{margin-top:0}.IIa07q_markdownBody>:last-child{margin-bottom:0}.IIa07q_markdownBody h1,.IIa07q_markdownBody h2,.IIa07q_markdownBody h3,.IIa07q_markdownBody h4{color:var(--mn-text);margin:1.5em 0 .6em;font-weight:500;line-height:1.35}.IIa07q_markdownBody h1{border-bottom:.5px solid var(--mn-line);padding-bottom:.35em;font-size:1.6em}.IIa07q_markdownBody h2{border-bottom:.5px solid var(--mn-line);padding-bottom:.3em;font-size:1.35em}.IIa07q_markdownBody h3{font-size:1.15em}.IIa07q_markdownBody p,.IIa07q_markdownBody ul,.IIa07q_markdownBody ol,.IIa07q_markdownBody blockquote,.IIa07q_markdownBody table,.IIa07q_markdownBody pre{margin:.85em 0}.IIa07q_markdownBody ul,.IIa07q_markdownBody ol{padding-left:1.6em}.IIa07q_markdownBody li+li{margin-top:.3em}.IIa07q_markdownBody blockquote{border-left:2px solid var(--mn-line-strong);color:var(--mn-muted);margin-inline:0;padding:.1em 1em}.IIa07q_markdownBody code{border-radius:var(--dsw-radius-xs);color:var(--mn-text);background:var(--dsw-alias-markdown-inline-code,var(--mn-fill));font:.88em/1.55 var(--mn-code);padding:.15em .4em}.IIa07q_markdownBody pre{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-markdown-code-block,var(--mn-fill));max-width:100%;padding:12px 16px;overflow:auto}.IIa07q_markdownBody pre code{background:0 0;padding:0;font-size:12px}.IIa07q_markdownBody a{color:var(--dsw-alias-link,var(--mn-accent));text-underline-offset:3px;text-decoration-thickness:1px}.IIa07q_markdownBody hr{border:0;border-top:.5px solid var(--mn-line);margin:1.8em 0}.IIa07q_markdownBody table{border-collapse:collapse;max-width:100%;display:block;overflow-x:auto}.IIa07q_markdownBody th,.IIa07q_markdownBody td{border:.5px solid var(--mn-line);text-align:left;vertical-align:top;padding:8px 10px}.IIa07q_markdownBody th{background:var(--mn-fill);font-weight:500}.IIa07q_markdownBody img{border-radius:var(--dsw-radius-sm);max-width:100%;height:auto}.IIa07q_documentArchiveReceipt{border-radius:var(--dsw-radius-md);background:color-mix(in srgb, var(--mn-success) 8%, transparent);margin:12px 0;padding:10px 12px}.IIa07q_documentArchiveReceipt p{color:var(--mn-muted);margin:2px 0 8px;font-size:12px;line-height:18px}.IIa07q_documentArchiveReceipt div{flex-wrap:wrap;gap:6px;display:flex}.IIa07q_documentDanger{border-top:.5px solid var(--mn-line);justify-content:flex-end;align-items:center;gap:8px;min-height:56px;margin-top:12px;padding-top:12px;display:flex}.IIa07q_documentDanger>div{margin-right:auto}.IIa07q_documentDanger strong{font-size:13px;font-weight:500;line-height:20px;display:block}.IIa07q_documentDanger p{color:var(--mn-faint);margin:2px 0 0;font-size:12px;line-height:18px}.IIa07q_documentDanger>span{color:var(--mn-danger);margin-right:auto;font-size:12px}.IIa07q_documentEditor{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);margin-bottom:12px;padding:16px}.IIa07q_documentReader>.IIa07q_documentEditor{background:0 0;border:0;margin:0;padding:0}.IIa07q_documentEditor>header{justify-content:space-between;align-items:flex-start;gap:16px;margin-bottom:12px;display:flex}.IIa07q_documentEditor h3{margin:0;font-size:14px;font-weight:500;line-height:22px}.IIa07q_documentEditor header p{color:var(--mn-faint);margin:2px 0 0;font-size:12px;line-height:18px}.IIa07q_documentEditor header>span,.IIa07q_documentEditor header>code{color:var(--mn-muted);background:var(--mn-fill);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}.IIa07q_documentEditor label{color:var(--mn-muted);gap:6px;margin-top:12px;font-size:12px;font-weight:500;line-height:18px;display:grid}.IIa07q_documentEditor textarea{resize:vertical;line-height:1.65}.IIa07q_documentEditorMeta{grid-template-columns:.8fr 1.2fr;gap:12px;display:grid}.IIa07q_documentEditorMeta label{margin:0}.IIa07q_documentEditor footer{justify-content:flex-end;gap:8px;margin-top:12px;display:flex}@media (width<=1000px){.IIa07q_documentWorkspace{grid-template-columns:minmax(220px,270px) minmax(0,1fr)}.IIa07q_documentDetail>dl{grid-template-columns:repeat(2,minmax(0,1fr))}.IIa07q_documentDetail>dl>div+div{border-left:0}.IIa07q_documentDetail>dl>div:nth-child(2n){border-left:.5px solid var(--mn-line)}.IIa07q_documentDetail>dl>div:nth-child(n+3){border-top:.5px solid var(--mn-line)}}@media (width<=760px){.IIa07q_documentSummary{grid-template-columns:repeat(2,minmax(0,1fr))}.IIa07q_documentCapacity{grid-column:1/-1}.IIa07q_documentToolbar{flex-direction:column;align-items:stretch}.IIa07q_documentToolbar form{min-width:0}.IIa07q_documentToolbar>div,.IIa07q_documentToolbar>button{width:100%}.IIa07q_documentToolbar>div button{flex:1}.IIa07q_documentWorkspace{grid-template-columns:1fr;min-height:0}.IIa07q_documentList{-webkit-overflow-scrolling:touch;max-height:330px;overflow:auto}.IIa07q_documentReader{min-height:430px}.IIa07q_documentEditorMeta{grid-template-columns:1fr}}@media (width<=520px){.IIa07q_documentDetail>header,.IIa07q_documentDanger{flex-direction:column;align-items:flex-start}.IIa07q_documentDetail>header>div:last-child,.IIa07q_documentDetail>header button{width:100%}.IIa07q_documentDanger>div,.IIa07q_documentDanger>span{margin-right:0}.IIa07q_documentDanger>button{width:100%}.IIa07q_documentDetail>dl{grid-template-columns:1fr}.IIa07q_documentDetail>dl>div:nth-child(2n){border-left:0}.IIa07q_documentDetail>dl>div+div{border-top:.5px solid var(--mn-line)}.IIa07q_markdownBody{padding:16px;font-size:13px}}";
174
+ const css$2 = ".IIa07q_documentSummary{grid-template-columns:.7fr .7fr 1.6fr;gap:12px;margin-bottom:12px;display:grid}.IIa07q_documentSummary article{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);min-width:0;min-height:92px;padding:14px 16px}.IIa07q_documentSummary article>span{color:var(--mn-faint);font-size:12px;line-height:18px;display:block}.IIa07q_documentSummary article>strong{font-variant-numeric:tabular-nums;margin:4px 0 2px;font-size:20px;font-weight:500;line-height:28px;display:block}.IIa07q_documentSummary article>small{color:var(--mn-faint);font-size:12px;line-height:18px}.IIa07q_documentCapacity>div{background:var(--mn-fill);border-radius:999px;height:4px;margin:8px 0 6px;overflow:hidden}.IIa07q_documentCapacity>div i{border-radius:inherit;background:var(--dsw-alias-brand-primary);height:100%;transition:width .3s;display:block}.IIa07q_documentToolbar{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);align-items:center;gap:8px;margin-bottom:12px;padding:8px;display:flex}.IIa07q_documentToolbar form{flex:1;align-items:center;gap:8px;min-width:260px;display:flex}.IIa07q_documentSearch{flex:1}.IIa07q_documentEditor input,.IIa07q_documentEditor textarea{border:.5px solid var(--mn-field-line);border-radius:var(--dsw-radius-md);width:100%;color:var(--mn-text);background:var(--mn-input);outline:0;padding:6px 10px;font-size:13px;line-height:20px}.IIa07q_documentEditor input:focus,.IIa07q_documentEditor textarea:focus{border-color:var(--mn-accent)}.IIa07q_documentToolbar>div{border-radius:var(--dsw-radius-md);background:var(--mn-hover);align-items:center;gap:2px;padding:3px;display:flex}.IIa07q_documentToolbar>div button{border-radius:var(--dsw-radius-sm);min-height:28px;color:var(--mn-muted);cursor:pointer;background:0 0;border:0;padding:0 12px;font-size:13px;font-weight:500;line-height:20px}.IIa07q_documentToolbar>div button:hover{color:var(--mn-text)}.IIa07q_documentToolbar>div button[data-active]{color:var(--mn-text);background:var(--mn-layer-1);box-shadow:var(--dsw-elevation-soft)}.IIa07q_documentToolbar>div b{color:var(--mn-faint);font-variant-numeric:tabular-nums;margin-left:6px;font-size:12px;font-weight:400}.IIa07q_documentWorkspace{grid-template-columns:minmax(250px,310px) minmax(0,1fr);gap:12px;min-height:590px;display:grid}.IIa07q_documentList,.IIa07q_documentReader{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);min-width:0;overflow:hidden}.IIa07q_documentList{align-self:stretch}.IIa07q_documentList>header{border-bottom:.5px solid var(--mn-line);min-height:44px;color:var(--mn-faint);justify-content:space-between;align-items:center;padding:0 14px;font-size:12px;line-height:18px;display:flex}.IIa07q_documentList>header code{color:var(--mn-muted)}.IIa07q_documentList>button{--mn-provider-color:var(--mn-faint);border-radius:var(--dsw-radius-md);width:calc(100% - 12px);color:var(--mn-text);text-align:left;cursor:pointer;background:0 0;border:0;margin:6px 6px 0;padding:10px 12px;transition:background-color .15s;display:block}.IIa07q_documentList>button:hover{background:var(--mn-hover)}.IIa07q_documentList>button[data-selected]{background:var(--mn-fill)}.IIa07q_documentList>button>div{justify-content:space-between;align-items:baseline;gap:12px;display:flex}.IIa07q_documentList>button strong{text-overflow:ellipsis;white-space:nowrap;font-size:13px;font-weight:500;line-height:20px;overflow:hidden}.IIa07q_documentList>button time{color:var(--mn-faint);font-variant-numeric:tabular-nums;flex:none;font-size:11px}.IIa07q_documentList>button p{color:var(--mn-faint);-webkit-line-clamp:2;-webkit-box-orient:vertical;margin:4px 0 6px;font-size:12px;line-height:18px;display:-webkit-box;overflow:hidden}.IIa07q_documentList>button footer{color:var(--mn-faint);align-items:center;gap:8px;font-size:11px;line-height:16px;display:flex}.IIa07q_documentList>button footer code{margin-left:auto}.IIa07q_documentList>button footer em{color:var(--mn-danger);font-style:normal}.IIa07q_documentListEmpty{min-height:230px;color:var(--mn-muted);text-align:center;align-content:center;place-items:center;gap:4px;padding:24px;display:grid}.IIa07q_documentListEmpty>span{color:var(--mn-faint);margin-bottom:6px;font-size:24px;line-height:1}.IIa07q_documentListEmpty p{color:var(--mn-faint);margin:0;font-size:12px;line-height:18px}.IIa07q_documentReader{padding:clamp(16px,2vw,24px)}.IIa07q_documentReader>.IIa07q_emptyState{background:0 0;border:0;height:100%}.IIa07q_documentDetail>header{border-bottom:.5px solid var(--mn-line);justify-content:space-between;align-items:flex-start;gap:16px;padding-bottom:14px;display:flex}.IIa07q_documentDetail>header span{color:var(--mn-faint);font-size:12px;line-height:18px}.IIa07q_documentDetail>header h3{margin:2px 0;font-size:16px;font-weight:500;line-height:24px}.IIa07q_documentDetail>header p{color:var(--mn-faint);margin:0;font-size:12px;line-height:18px}.IIa07q_documentActions{flex-wrap:wrap;align-items:center;gap:8px;display:flex}.IIa07q_documentDetail>dl{border:.5px solid var(--mn-line);border-radius:var(--dsw-radius-md);grid-template-columns:2fr .45fr .8fr .55fr;margin:12px 0;display:grid;overflow:hidden}.IIa07q_documentDetail>dl>div{min-width:0;padding:8px 10px}.IIa07q_documentDetail>dl>div+div{border-left:.5px solid var(--mn-line)}.IIa07q_documentDetail dt{color:var(--mn-faint);margin-bottom:2px;font-size:11px;line-height:16px}.IIa07q_documentDetail dd{text-overflow:ellipsis;white-space:nowrap;margin:0;font-size:12px;line-height:18px;overflow:hidden}.IIa07q_documentSources{flex-wrap:wrap;align-items:center;gap:6px;margin:12px 0;display:flex}.IIa07q_documentSources>span{color:var(--mn-faint);margin-right:4px;font-size:12px}.IIa07q_documentSources code,.IIa07q_documentArchiveReceipt code{color:var(--mn-muted);background:var(--mn-fill);border-radius:999px;padding:1px 8px;font-size:11px;line-height:17px}.IIa07q_markdownBody{overflow-wrap:anywhere;border:.5px solid var(--mn-line);border-radius:var(--dsw-radius-md);min-height:310px;color:var(--mn-text);margin:16px 0 0;padding:clamp(16px,2.5vw,28px);font-size:14px;line-height:1.75}.IIa07q_markdownBody>:first-child{margin-top:0}.IIa07q_markdownBody>:last-child{margin-bottom:0}.IIa07q_markdownBody h1,.IIa07q_markdownBody h2,.IIa07q_markdownBody h3,.IIa07q_markdownBody h4{color:var(--mn-text);margin:1.5em 0 .6em;font-weight:500;line-height:1.35}.IIa07q_markdownBody h1{border-bottom:.5px solid var(--mn-line);padding-bottom:.35em;font-size:1.6em}.IIa07q_markdownBody h2{border-bottom:.5px solid var(--mn-line);padding-bottom:.3em;font-size:1.35em}.IIa07q_markdownBody h3{font-size:1.15em}.IIa07q_markdownBody p,.IIa07q_markdownBody ul,.IIa07q_markdownBody ol,.IIa07q_markdownBody blockquote,.IIa07q_markdownBody table,.IIa07q_markdownBody pre{margin:.85em 0}.IIa07q_markdownBody ul,.IIa07q_markdownBody ol{padding-left:1.6em}.IIa07q_markdownBody li+li{margin-top:.3em}.IIa07q_markdownBody blockquote{border-left:2px solid var(--mn-line-strong);color:var(--mn-muted);margin-inline:0;padding:.1em 1em}.IIa07q_markdownBody code{border-radius:var(--dsw-radius-xs);color:var(--mn-text);background:var(--dsw-alias-markdown-inline-code,var(--mn-fill));font:.88em/1.55 var(--mn-code);padding:.15em .4em}.IIa07q_markdownBody pre{border-radius:var(--dsw-radius-md);background:var(--dsw-alias-markdown-code-block,var(--mn-fill));max-width:100%;padding:12px 16px;overflow:auto}.IIa07q_markdownBody pre code{background:0 0;padding:0;font-size:12px}.IIa07q_markdownBody a{color:var(--dsw-alias-link,var(--mn-accent));text-underline-offset:3px;text-decoration-thickness:1px}.IIa07q_markdownBody hr{border:0;border-top:.5px solid var(--mn-line);margin:1.8em 0}.IIa07q_markdownBody table{border-collapse:collapse;max-width:100%;display:block;overflow-x:auto}.IIa07q_markdownBody th,.IIa07q_markdownBody td{border:.5px solid var(--mn-line);text-align:left;vertical-align:top;padding:8px 10px}.IIa07q_markdownBody th{background:var(--mn-fill);font-weight:500}.IIa07q_markdownBody img{border-radius:var(--dsw-radius-sm);max-width:100%;height:auto}.IIa07q_documentArchiveReceipt{border-radius:var(--dsw-radius-md);background:color-mix(in srgb, var(--mn-success) 8%, transparent);margin:12px 0;padding:10px 12px}.IIa07q_documentArchiveReceipt p{color:var(--mn-muted);margin:2px 0 8px;font-size:12px;line-height:18px}.IIa07q_documentArchiveReceipt div{flex-wrap:wrap;gap:6px;display:flex}.IIa07q_documentDanger{border-top:.5px solid var(--mn-line);justify-content:flex-end;align-items:center;gap:8px;min-height:56px;margin-top:12px;padding-top:12px;display:flex}.IIa07q_documentDanger>div{margin-right:auto}.IIa07q_documentDanger strong{font-size:13px;font-weight:500;line-height:20px;display:block}.IIa07q_documentDanger p{color:var(--mn-faint);margin:2px 0 0;font-size:12px;line-height:18px}.IIa07q_documentDanger>span{color:var(--mn-danger);margin-right:auto;font-size:12px}.IIa07q_documentEditor{border:.5px solid var(--mn-card-line);border-radius:var(--dsw-radius-lg);margin-bottom:12px;padding:16px}.IIa07q_documentReader>.IIa07q_documentEditor{background:0 0;border:0;margin:0;padding:0}.IIa07q_documentEditor>header{justify-content:space-between;align-items:flex-start;gap:16px;margin-bottom:12px;display:flex}.IIa07q_documentEditor h3{margin:0;font-size:14px;font-weight:500;line-height:22px}.IIa07q_documentEditor header p{color:var(--mn-faint);margin:2px 0 0;font-size:12px;line-height:18px}.IIa07q_documentEditor header>span,.IIa07q_documentEditor header>code{color:var(--mn-muted);background:var(--mn-fill);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}.IIa07q_documentEditor label{color:var(--mn-muted);gap:6px;margin-top:12px;font-size:12px;font-weight:500;line-height:18px;display:grid}.IIa07q_documentEditor textarea{resize:vertical;line-height:1.65}.IIa07q_documentEditorMeta{grid-template-columns:.8fr 1.2fr;gap:12px;display:grid}.IIa07q_documentEditorMeta label{margin:0}.IIa07q_documentEditor footer{justify-content:flex-end;gap:8px;margin-top:12px;display:flex}@media (width<=1000px){.IIa07q_documentWorkspace{grid-template-columns:minmax(220px,270px) minmax(0,1fr)}.IIa07q_documentDetail>dl{grid-template-columns:repeat(2,minmax(0,1fr))}.IIa07q_documentDetail>dl>div+div{border-left:0}.IIa07q_documentDetail>dl>div:nth-child(2n){border-left:.5px solid var(--mn-line)}.IIa07q_documentDetail>dl>div:nth-child(n+3){border-top:.5px solid var(--mn-line)}}@media (width<=760px){.IIa07q_documentSummary{grid-template-columns:repeat(2,minmax(0,1fr))}.IIa07q_documentCapacity{grid-column:1/-1}.IIa07q_documentToolbar{flex-direction:column;align-items:stretch}.IIa07q_documentToolbar form{min-width:0}.IIa07q_documentToolbar>div,.IIa07q_documentToolbar>button{width:100%}.IIa07q_documentToolbar>div button{flex:1}.IIa07q_documentWorkspace{grid-template-columns:1fr;min-height:0}.IIa07q_documentList{-webkit-overflow-scrolling:touch;max-height:330px;overflow:auto}.IIa07q_documentReader{min-height:430px}.IIa07q_documentEditorMeta{grid-template-columns:1fr}}@media (width<=520px){.IIa07q_documentDetail>header,.IIa07q_documentDanger{flex-direction:column;align-items:flex-start}.IIa07q_documentDetail>header>div:last-child,.IIa07q_documentDetail>header button{width:100%}.IIa07q_documentDanger>div,.IIa07q_documentDanger>span{margin-right:0}.IIa07q_documentDanger>button{width:100%}.IIa07q_documentDetail>dl{grid-template-columns:1fr}.IIa07q_documentDetail>dl>div:nth-child(2n){border-left:0}.IIa07q_documentDetail>dl>div+div{border-top:.5px solid var(--mn-line)}.IIa07q_markdownBody{padding:16px;font-size:13px}}";
163
175
  const id$1 = "dsh-mnemon-source-documents/presentation/page.module.css";
164
176
  if (typeof document !== "undefined") {
165
177
  let tag = document.querySelector("style[data-plugin-css=" + JSON.stringify(id$1) + "]");
@@ -171,6 +183,7 @@ window.__ModuleLoader__.load({
171
183
  if (tag.textContent !== css$2) tag.textContent = css$2;
172
184
  }
173
185
  var page_module_css_default = {
186
+ "documentActions": "IIa07q_documentActions",
174
187
  "documentArchiveReceipt": "IIa07q_documentArchiveReceipt",
175
188
  "documentCapacity": "IIa07q_documentCapacity",
176
189
  "documentDanger": "IIa07q_documentDanger",
@@ -1189,6 +1202,8 @@ window.__ModuleLoader__.load({
1189
1202
  const [composing, setComposing] = (0, react.useState)(false);
1190
1203
  const [editing, setEditing] = (0, react.useState)(false);
1191
1204
  const [confirmArchive, setConfirmArchive] = (0, react.useState)(false);
1205
+ const [deleteTarget, setDeleteTarget] = (0, react.useState)(null);
1206
+ const [deleteError, setDeleteError] = (0, react.useState)(null);
1192
1207
  const [title, setTitle] = (0, react.useState)("");
1193
1208
  const [description, setDescription] = (0, react.useState)("");
1194
1209
  const [content, setContent] = (0, react.useState)("");
@@ -1200,8 +1215,9 @@ window.__ModuleLoader__.load({
1200
1215
  setError(null);
1201
1216
  setVisibleLimit(pageSize);
1202
1217
  try {
1218
+ const searched = nextQuery.trim() === "" ? void 0 : (await props.client.searchDocuments(nextQuery, nextStatus === "archived")).results;
1203
1219
  const current = await props.client.documents();
1204
- const filtered = (nextQuery.trim() === "" ? current.documents : (await props.client.searchDocuments(nextQuery, nextStatus === "archived")).results).filter((record) => record.status === nextStatus).sort((left, right) => Date.parse(right.createdAt) - Date.parse(left.createdAt));
1220
+ const filtered = (searched ?? current.documents).filter((record) => record.status === nextStatus).sort((left, right) => Date.parse(right.createdAt) - Date.parse(left.createdAt));
1205
1221
  if (!displayRequests.isCurrent(request)) return;
1206
1222
  setSnapshot(current);
1207
1223
  setItems(filtered);
@@ -1229,7 +1245,7 @@ window.__ModuleLoader__.load({
1229
1245
  ]);
1230
1246
  (0, react.useEffect)(() => {
1231
1247
  setSelected(null);
1232
- if (selectedId === null) return;
1248
+ if (selectedId === null || !snapshot?.documents.some((document) => document.id === selectedId)) return;
1233
1249
  let active = true;
1234
1250
  props.client.document(selectedId).then((value) => {
1235
1251
  if (active) setSelected(value);
@@ -1242,7 +1258,7 @@ window.__ModuleLoader__.load({
1242
1258
  }, [
1243
1259
  props.client,
1244
1260
  selectedId,
1245
- props.revision
1261
+ snapshot
1246
1262
  ]);
1247
1263
  (0, react.useLayoutEffect)(() => {
1248
1264
  if (readerRef.current !== null) readerRef.current.scrollTop = 0;
@@ -1356,9 +1372,31 @@ window.__ModuleLoader__.load({
1356
1372
  setSaving(false);
1357
1373
  }
1358
1374
  };
1375
+ const remove = async () => {
1376
+ if (!props.writeEnabled || deleteTarget?.document.fileRevision === void 0 || props.client.deleteDocument === void 0) return;
1377
+ setSaving(true);
1378
+ setDeleteError(null);
1379
+ setError(null);
1380
+ setNotice(null);
1381
+ try {
1382
+ await props.client.deleteDocument(deleteTarget.document.id, deleteTarget.revision, deleteTarget.document.fileRevision);
1383
+ setDeleteTarget(null);
1384
+ setSelected(null);
1385
+ setSelectedId(null);
1386
+ setNotice(t("documents.deleted"));
1387
+ props.onMutate();
1388
+ await display(query, status);
1389
+ } catch (reason) {
1390
+ setDeleteError((0, dsh_mnemon_client.message)(reason));
1391
+ } finally {
1392
+ setSaving(false);
1393
+ }
1394
+ };
1359
1395
  const usage = snapshot === null ? 0 : Math.min(100, snapshot.activeBytes / snapshot.limitBytes * 100);
1360
1396
  const activeCount = snapshot?.activeCount ?? 0;
1361
1397
  const archivedCount = snapshot?.archivedCount ?? 0;
1398
+ const selectedRecord = snapshot?.documents.find((document) => document.id === selected?.id);
1399
+ const selectedIsCurrent = selected?.fileRevision !== void 0 && selectedRecord?.revision === selected.revision && selectedRecord.contentHash === selected.contentHash && selectedRecord.status === selected.status;
1362
1400
  const composer = /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
1363
1401
  id: documentCreateFormId,
1364
1402
  className: css.documentEditor,
@@ -1427,6 +1465,7 @@ window.__ModuleLoader__.load({
1427
1465
  setSelectedId(documentId);
1428
1466
  setEditing(false);
1429
1467
  setConfirmArchive(false);
1468
+ setDeleteTarget(null);
1430
1469
  };
1431
1470
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1432
1471
  className: css.page,
@@ -1579,12 +1618,27 @@ window.__ModuleLoader__.load({
1579
1618
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: selected.status === "active" ? t("documents.active") : t("documents.coldArchive") }),
1580
1619
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: selected.title }),
1581
1620
  /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: selected.description || t("documents.noDescription") })
1582
- ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: props.writeEnabled && selected.status === "active" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1583
- type: "button",
1584
- className: documentEditActionClass,
1585
- onClick: beginEdit,
1586
- children: t("documents.edit")
1587
- }) })] }),
1621
+ ] }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1622
+ className: css.documentActions,
1623
+ children: [props.writeEnabled && selected.status === "active" && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1624
+ type: "button",
1625
+ className: documentEditActionClass,
1626
+ onClick: beginEdit,
1627
+ children: t("documents.edit")
1628
+ }), props.writeEnabled && props.client.deleteDocument !== void 0 && snapshot !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1629
+ type: "button",
1630
+ className: documentArchiveActionClass,
1631
+ disabled: !selectedIsCurrent,
1632
+ onClick: () => {
1633
+ setDeleteError(null);
1634
+ setDeleteTarget({
1635
+ document: selected,
1636
+ revision: snapshot.revision
1637
+ });
1638
+ },
1639
+ children: t("documents.delete")
1640
+ })]
1641
+ })] }),
1588
1642
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("dl", { children: [
1589
1643
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("documents.path") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: selected.relativePath }) })] }),
1590
1644
  /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("dt", { children: t("documents.revision") }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("dd", { children: selected.revision })] }),
@@ -1703,6 +1757,49 @@ window.__ModuleLoader__.load({
1703
1757
  ] })]
1704
1758
  })]
1705
1759
  })
1760
+ }),
1761
+ deleteTarget !== null && props.writeEnabled && /* @__PURE__ */ (0, react_jsx_runtime.jsx)(dsh_mnemon_client.SidebarModal, {
1762
+ title: t("documents.deleteConfirm"),
1763
+ description: deleteTarget.document.title,
1764
+ busy: saving,
1765
+ onClose: () => setDeleteTarget(null),
1766
+ footer: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1767
+ className: css.modalFooterActions,
1768
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1769
+ type: "button",
1770
+ "data-dialog-close": true,
1771
+ "data-autofocus": true,
1772
+ className: css.secondaryButton,
1773
+ disabled: saving,
1774
+ onClick: () => setDeleteTarget(null),
1775
+ children: t("common.cancel")
1776
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
1777
+ type: "button",
1778
+ className: css.dangerSolidButton,
1779
+ disabled: saving,
1780
+ onClick: () => void remove(),
1781
+ children: saving ? t("documents.deleting") : t("documents.deleteNow")
1782
+ })]
1783
+ }),
1784
+ children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1785
+ className: css.bodyDeleteConfirm,
1786
+ children: [
1787
+ deleteError !== null && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", {
1788
+ className: css.inlineError,
1789
+ role: "alert",
1790
+ children: deleteError
1791
+ }),
1792
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: t("documents.deleteDescription") }),
1793
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
1794
+ className: css.bodyDeleteSummary,
1795
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: deleteTarget.document.title }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", { children: [
1796
+ deleteTarget.document.relativePath,
1797
+ " · ",
1798
+ (0, dsh_mnemon_client.humanBytes)(deleteTarget.document.sizeBytes)
1799
+ ] })]
1800
+ })
1801
+ ]
1802
+ })
1706
1803
  })
1707
1804
  ]
1708
1805
  });
@@ -1719,8 +1816,18 @@ window.__ModuleLoader__.load({
1719
1816
  includeArchived,
1720
1817
  limit
1721
1818
  }),
1722
- mutateDocument: (input) => client.canAssist("mutate") ? client.assist("mutate", { ...input }, true) : client.mutate("mutate", { ...input }, true),
1723
- archiveDocument: (id) => client.canAssist("archive") ? client.assist("archive", { id }, true) : client.mutate("archive", { id }, true)
1819
+ mutateDocument: (input) => input.action === "delete" ? client.mutate("delete", {
1820
+ id: input.id,
1821
+ ...input.fileRevision === void 0 ? {} : { fileRevision: input.fileRevision }
1822
+ }, true) : client.canAssist("mutate") ? client.assist("mutate", { ...input }, true) : client.mutate("mutate", { ...input }, true),
1823
+ archiveDocument: (id) => client.canAssist("archive") ? client.assist("archive", { id }, true) : client.mutate("archive", { id }, true),
1824
+ deleteDocument: async (id, expectedRevision, fileRevision) => (await management.mutate("delete", {
1825
+ id,
1826
+ fileRevision
1827
+ }, {
1828
+ confirmed: true,
1829
+ expectedRevision
1830
+ })).value
1724
1831
  };
1725
1832
  }
1726
1833
  function DocumentsSourceView(props) {
@@ -21,6 +21,8 @@ interface DocumentRecord {
21
21
  }
22
22
  interface DocumentView extends DocumentRecord {
23
23
  content: string;
24
+ /** Digest of the exact managed file read; deletion also fences external edits. */
25
+ fileRevision?: string;
24
26
  }
25
27
  interface DocumentSnapshot {
26
28
  workspaceRoot: string;
@@ -63,10 +65,14 @@ type DocumentMutation = {
63
65
  content?: string;
64
66
  sourcePaths?: string[];
65
67
  sessionIds?: string[];
68
+ } | {
69
+ action: 'delete';
70
+ id: string;
71
+ fileRevision?: string;
66
72
  };
67
73
  interface DocumentMutationResult {
68
74
  success: true;
69
- action: 'created' | 'updated' | 'archived';
75
+ action: 'created' | 'updated' | 'archived' | 'deleted';
70
76
  document: DocumentView;
71
77
  snapshot: DocumentSnapshot;
72
78
  maintenance?: {
package/lib/index.js CHANGED
@@ -1,11 +1,11 @@
1
- import { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_DIRECTORY, DOCUMENTS_INDEX_FILE, DOCUMENTS_LOCK_FILE } from "./contracts.js";
1
+ import { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_DIRECTORY, DOCUMENTS_INDEX_FILE, DOCUMENTS_LOCK_FILE, DOCUMENT_FILENAME_PATTERN } from "./contracts.js";
2
2
  import { createMemoryMutationReceipt, defineMemoryPlugin, defineMemorySource, installMemory, memoryConfigurationDigest, memoryInputRecord, memoryInputStringArray, memoryInputText, truncateMemoryText } from "dsh-mnemon/extension-sdk";
3
3
  import { homedir } from "node:os";
4
- import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "node:path";
5
5
  import z from "@deepseek-ai/schemastery";
6
6
  import { createHash, randomUUID } from "node:crypto";
7
7
  import { COMPOSABLE_MEMORY_API_VERSION } from "dsh-mnemon/contracts";
8
- import { closeSync, existsSync, mkdirSync, openSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from "node:fs";
8
+ import { closeSync, existsSync, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
9
9
  //#region src/config.ts
10
10
  const Config = z.object({
11
11
  dataDir: z.string(),
@@ -65,7 +65,7 @@ var DocumentCapacityError = class extends Error {
65
65
  var DocumentConflictError = class extends Error {
66
66
  code = "revision-conflict";
67
67
  constructor() {
68
- super("document changed while archival was running; the active copy was preserved");
68
+ super("document index or content changed; reload before retrying");
69
69
  this.name = "DocumentConflictError";
70
70
  }
71
71
  };
@@ -93,7 +93,10 @@ function hash(value) {
93
93
  return createHash("sha256").update(value).digest("hex");
94
94
  }
95
95
  function indexRevision(index) {
96
- return hash(JSON.stringify(index));
96
+ return hash(JSON.stringify({
97
+ version: index.version,
98
+ documents: index.documents.map(parseRecord)
99
+ }));
97
100
  }
98
101
  function copyIndex(index) {
99
102
  return {
@@ -250,6 +253,14 @@ var DocumentController = class {
250
253
  memoryBodyIds: []
251
254
  };
252
255
  projected = used + Buffer.byteLength(renderDocument(record, content), "utf8");
256
+ } else if (request.action === "delete") {
257
+ const current = this.requireDocument(index, request.id);
258
+ return {
259
+ projected: used - (current.status === "active" ? current.sizeBytes : 0),
260
+ limit: this.limitBytes,
261
+ fits: true,
262
+ candidates: []
263
+ };
253
264
  } else {
254
265
  const current = this.requireDocument(index, request.id);
255
266
  if (current.status !== "active") throw new Error("archived documents are immutable; create a new active revision instead");
@@ -334,6 +345,13 @@ var DocumentController = class {
334
345
  this.queue = operation.catch(() => void 0);
335
346
  return operation;
336
347
  }
348
+ deleteDocument(id, expectedRevision, fileRevision) {
349
+ return this.mutate({
350
+ action: "delete",
351
+ id,
352
+ fileRevision
353
+ }, expectedRevision);
354
+ }
337
355
  archive(id, expectedRevision, details) {
338
356
  const operation = this.queue.then(() => this.withLock(() => {
339
357
  const index = this.readIndex();
@@ -371,7 +389,8 @@ var DocumentController = class {
371
389
  action: "archived",
372
390
  document: {
373
391
  ...updated,
374
- content
392
+ content,
393
+ fileRevision: hash(rendered)
375
394
  },
376
395
  snapshot: this.snapshotUnlocked(index)
377
396
  };
@@ -382,6 +401,37 @@ var DocumentController = class {
382
401
  mutateLocked(request, expectedRevision) {
383
402
  const index = this.readIndex();
384
403
  if (expectedRevision !== void 0 && this.revisionOf(index) !== expectedRevision) throw new DocumentConflictError();
404
+ if (request.action === "delete") {
405
+ if (expectedRevision === void 0 || expectedRevision === "") throw new Error("Documents deletion requires an index revision");
406
+ const current = this.requireDocument(index, request.id);
407
+ const path = this.pathFor(current);
408
+ const root = realpathSync(this.storageRoot);
409
+ if (!DOCUMENT_FILENAME_PATTERN.test(current.filename) || path !== join(this.directory, current.status, current.filename) || index.documents.some((record) => record !== current && this.pathFor(record) === path) || realpathSync(dirname(path)) !== join(root, "documents", current.status)) throw new Error("document index contains an unsafe managed path");
410
+ if (!lstatSync(path).isFile()) throw new Error("Documents deletion requires a regular managed file");
411
+ const original = readFileSync(path);
412
+ if (typeof request.fileRevision !== "string" || request.fileRevision === "") throw new Error("Documents deletion requires the current file revision");
413
+ const fileRevision = hash(original);
414
+ if (fileRevision !== request.fileRevision) throw new DocumentConflictError();
415
+ unlinkSync(path);
416
+ index.documents = index.documents.filter((record) => record.id !== current.id);
417
+ try {
418
+ this.persistIndex(index);
419
+ } catch (error) {
420
+ this.atomicWrite(path, original);
421
+ throw error;
422
+ }
423
+ this.excerpts.delete(path);
424
+ return {
425
+ success: true,
426
+ action: "deleted",
427
+ document: {
428
+ ...current,
429
+ content: documentBody(original.toString("utf8")),
430
+ fileRevision
431
+ },
432
+ snapshot: this.snapshotUnlocked(index)
433
+ };
434
+ }
385
435
  const now = this.now().toISOString();
386
436
  if (request.action === "create") {
387
437
  const title = normalizeLine(request.title, "document title", 160, true);
@@ -417,7 +467,8 @@ var DocumentController = class {
417
467
  action: "created",
418
468
  document: {
419
469
  ...record,
420
- content
470
+ content,
471
+ fileRevision: hash(rendered)
421
472
  },
422
473
  snapshot: this.snapshotUnlocked(index)
423
474
  };
@@ -447,7 +498,8 @@ var DocumentController = class {
447
498
  action: "updated",
448
499
  document: {
449
500
  ...updated,
450
- content
501
+ content,
502
+ fileRevision: hash(rendered)
451
503
  },
452
504
  snapshot: this.snapshotUnlocked(index)
453
505
  };
@@ -584,13 +636,15 @@ var DocumentController = class {
584
636
  if (!path.startsWith(managedRoot)) throw new Error("document index contains an unsafe managed path");
585
637
  return path;
586
638
  }
587
- readBody(record) {
588
- return documentBody(readFileSync(this.pathFor(record), "utf8"));
639
+ readBody(record, raw = readFileSync(this.pathFor(record))) {
640
+ return documentBody(raw.toString("utf8"));
589
641
  }
590
642
  view(record) {
643
+ const raw = readFileSync(this.pathFor(record));
591
644
  return {
592
645
  ...record,
593
- content: this.readBody(record)
646
+ content: this.readBody(record, raw),
647
+ fileRevision: hash(raw)
594
648
  };
595
649
  }
596
650
  persistDocument(record, content) {
@@ -721,6 +775,14 @@ function documentMutation(value, allowedIds) {
721
775
  ...input.sourcePaths === void 0 ? {} : { sourcePaths: memoryInputStringArray(input.sourcePaths, "sourcePaths") ?? [] },
722
776
  ...input.sessionIds === void 0 ? {} : { sessionIds: memoryInputStringArray(input.sessionIds, "sessionIds", 20) ?? [] }
723
777
  };
778
+ } else if (action === "delete") {
779
+ const id = memoryInputText(input.id, "id", 300);
780
+ if (allowedIds !== void 0 && !allowedIds.includes(id)) throw new Error("Documents delete target is outside this View ReadGrant");
781
+ mutation = {
782
+ action,
783
+ id,
784
+ ...input.fileRevision === void 0 ? {} : { fileRevision: memoryInputText(input.fileRevision, "fileRevision", 100) }
785
+ };
724
786
  } else throw new Error(`unsupported Documents action: ${action}`);
725
787
  return mutation;
726
788
  }
@@ -761,7 +823,7 @@ function createDocumentsMemorySource(config = {}) {
761
823
  }],
762
824
  actions: [{
763
825
  id: "manage",
764
- description: "Create a project Document, or update one pinned into this View or created in this execution.",
826
+ description: "Create a project Document, update one pinned into this View or created in this execution, or permanently delete a pinned active/archived managed copy after explicit user confirmation. Delete requires confirmed: true, expectedRevision from the latest Documents search metadata.indexRevision, and fileRevision from the target item provenance (or management document read). It does not archive or change project originals.",
765
827
  capability: "write",
766
828
  inputSchema: {
767
829
  type: "object",
@@ -770,10 +832,17 @@ function createDocumentsMemorySource(config = {}) {
770
832
  properties: {
771
833
  action: {
772
834
  type: "string",
773
- enum: ["create", "update"]
835
+ enum: [
836
+ "create",
837
+ "update",
838
+ "delete"
839
+ ]
774
840
  },
775
841
  id: { type: "string" },
776
- ...CREATE_PROPERTIES
842
+ ...CREATE_PROPERTIES,
843
+ confirmed: { type: "boolean" },
844
+ expectedRevision: { type: "string" },
845
+ fileRevision: { type: "string" }
777
846
  }
778
847
  }
779
848
  }, {
@@ -930,7 +999,8 @@ function createDocumentsMemorySource(config = {}) {
930
999
  description: document.description,
931
1000
  status: document.status,
932
1001
  relativePath: document.relativePath,
933
- sourcePaths: document.sourcePaths.slice(0, 8)
1002
+ sourcePaths: document.sourcePaths.slice(0, 8),
1003
+ ...document.fileRevision === void 0 ? {} : { fileRevision: document.fileRevision }
934
1004
  }
935
1005
  });
936
1006
  }
@@ -958,7 +1028,8 @@ function createDocumentsMemorySource(config = {}) {
958
1028
  metadata: {
959
1029
  query: result.query,
960
1030
  includeArchived: result.includeArchived,
961
- total: result.total
1031
+ total: result.total,
1032
+ indexRevision: controller.revision()
962
1033
  },
963
1034
  id: `evidence:${randomUUID()}`,
964
1035
  viewId: request.view.id,
@@ -994,8 +1065,9 @@ function createDocumentsMemorySource(config = {}) {
994
1065
  default: throw new Error("unsupported Documents management read operation: " + request.operation);
995
1066
  }
996
1067
  else {
997
- if (!request.confirmed) throw new Error("Documents management mutation requires explicit confirmation");
1068
+ if (request.confirmed !== true) throw new Error("Documents management mutation requires explicit confirmation");
998
1069
  if (request.operation === "mutate") value = await controller.mutate(documentMutation(request.input), request.expectedRevision);
1070
+ else if (request.operation === "delete") value = await controller.deleteDocument(memoryInputText(input.id, "id", 300), memoryInputText(request.expectedRevision, "expectedRevision", 100), memoryInputText(input.fileRevision, "fileRevision", 100));
999
1071
  else if (request.operation === "archive") {
1000
1072
  const document = controller.get(memoryInputText(input.id, "id", 300));
1001
1073
  const revision = input.documentRevision === void 0 ? document.revision : input.documentRevision;
@@ -1016,8 +1088,12 @@ function createDocumentsMemorySource(config = {}) {
1016
1088
  const root = workspace(request.view.scope);
1017
1089
  if (root === void 0) throw new Error("Documents Action requires a workspace-scoped View");
1018
1090
  const grant = request.grant;
1019
- const mutation = request.offer.sourceActionId === "create" ? documentCreation(request.input) : documentMutation(request.input, [...grant === void 0 ? [] : grantIds(grant), ...created.get(request.view) ?? []]);
1020
- const result = await documents.forWorkspace(root).mutate(mutation);
1091
+ const input = memoryInputRecord(request.input, "Documents Action");
1092
+ const deleting = request.offer.sourceActionId === "manage" && input.action === "delete";
1093
+ if (deleting && input.confirmed !== true) throw new Error("Documents deletion requires explicit user confirmation");
1094
+ const mutation = request.offer.sourceActionId === "create" ? documentCreation(request.input) : documentMutation(request.input, deleting ? grant === void 0 ? [] : grantIds(grant, true) : [...grant === void 0 ? [] : grantIds(grant), ...created.get(request.view) ?? []]);
1095
+ const expectedRevision = deleting ? memoryInputText(input.expectedRevision, "expectedRevision", 100) : void 0;
1096
+ const result = await documents.forWorkspace(root).mutate(mutation, expectedRevision);
1021
1097
  if (mutation.action === "create") {
1022
1098
  let ids = created.get(request.view);
1023
1099
  if (ids === void 0) {
@@ -6,4 +6,5 @@ export interface DocumentsPageClient {
6
6
  searchDocuments(query: string, includeArchived?: boolean, limit?: number): Promise<DocumentSearchResult>;
7
7
  mutateDocument(request: DocumentMutation): Promise<DocumentMutationResult>;
8
8
  archiveDocument(id: string): Promise<DocumentMutationResult>;
9
+ deleteDocument?(id: string, expectedRevision: string, fileRevision: string): Promise<DocumentMutationResult>;
9
10
  }
@@ -20,6 +20,8 @@ export interface DocumentRecord {
20
20
  }
21
21
  export interface DocumentView extends DocumentRecord {
22
22
  content: string;
23
+ /** Digest of the exact managed file read; deletion also fences external edits. */
24
+ fileRevision?: string;
23
25
  }
24
26
  export interface DocumentSnapshot {
25
27
  workspaceRoot: string;
@@ -62,10 +64,14 @@ export type DocumentMutation = {
62
64
  content?: string;
63
65
  sourcePaths?: string[];
64
66
  sessionIds?: string[];
67
+ } | {
68
+ action: 'delete';
69
+ id: string;
70
+ fileRevision?: string;
65
71
  };
66
72
  export interface DocumentMutationResult {
67
73
  success: true;
68
- action: 'created' | 'updated' | 'archived';
74
+ action: 'created' | 'updated' | 'archived' | 'deleted';
69
75
  document: DocumentView;
70
76
  snapshot: DocumentSnapshot;
71
77
  maintenance?: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-mnemon-source-documents",
3
- "version": "0.5.13",
3
+ "version": "0.6.0",
4
4
  "description": "Self-contained documents Source for Composable View Memory.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -61,7 +61,7 @@
61
61
  "@types/node": "^22.0.0",
62
62
  "@types/react": "^18.3.0",
63
63
  "@types/react-dom": "^18.3.0",
64
- "dsh-mnemon": "^0.5.40",
64
+ "dsh-mnemon": "^0.5.42",
65
65
  "jsdom": "^26.0.0",
66
66
  "react": "^18.2.0",
67
67
  "react-dom": "^18.2.0",
@@ -48,6 +48,12 @@
48
48
  "documents.selectText": "在左侧查看活跃项目知识或沿 Mnemon 引用打开归档原文。",
49
49
  "documents.coldArchive": "归档原文",
50
50
  "documents.edit": "编辑",
51
+ "documents.delete": "删除",
52
+ "documents.deleteConfirm": "永久删除这份档案?",
53
+ "documents.deleteDescription": "将永久移除档案记录和托管副本,无法撤销。不会建立记忆空间冷索引,也不会修改已有记忆空间条目或项目源文件。",
54
+ "documents.deleteNow": "永久删除",
55
+ "documents.deleting": "删除中…",
56
+ "documents.deleted": "档案已永久删除。",
51
57
  "documents.path": "托管路径",
52
58
  "documents.revision": "修订",
53
59
  "documents.hash": "内容哈希",
@@ -111,6 +117,12 @@
111
117
  "documents.selectText": "Read active project knowledge or follow a Mnemon reference to an archived original.",
112
118
  "documents.coldArchive": "Archived original",
113
119
  "documents.edit": "Edit",
120
+ "documents.delete": "Delete",
121
+ "documents.deleteConfirm": "Permanently delete this document?",
122
+ "documents.deleteDescription": "This permanently removes the document record and managed copy and cannot be undone. No Memory Space index is created. Existing Memory Space entries and original project files remain unchanged.",
123
+ "documents.deleteNow": "Delete permanently",
124
+ "documents.deleting": "Deleting…",
125
+ "documents.deleted": "Document permanently deleted.",
114
126
  "documents.path": "Managed path",
115
127
  "documents.revision": "Revision",
116
128
  "documents.hash": "Content hash",
@@ -46,6 +46,7 @@
46
46
  .documentDetail > header span { color: var(--mn-faint); font-size: 12px; line-height: 18px; }
47
47
  .documentDetail > header h3 { margin: 2px 0; font-size: 16px; font-weight: 500; line-height: 24px; }
48
48
  .documentDetail > header p { margin: 0; color: var(--mn-faint); font-size: 12px; line-height: 18px; }
49
+ .documentActions { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
49
50
  .documentDetail > dl { display: grid; grid-template-columns: 2fr .45fr .8fr .55fr; margin: 12px 0; border: .5px solid var(--mn-line); border-radius: var(--dsw-radius-md); overflow: hidden; }
50
51
  .documentDetail > dl > div { min-width: 0; padding: 8px 10px; }
51
52
  .documentDetail > dl > div + div { border-left: .5px solid var(--mn-line); }