dsh-mnemon-source-documents 0.5.9 → 0.5.11
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 +4 -0
- package/lib/client.js +13 -8
- package/lib/contracts.d.ts +37 -1
- package/lib/contracts.js +70 -1
- package/lib/index.d.ts +2 -2
- package/lib/index.js +7 -8
- package/lib/types/contracts.d.ts +36 -0
- package/package.json +6 -6
- package/presentation/locales.json +10 -6
package/README.md
CHANGED
|
@@ -25,6 +25,10 @@ The `create` Action accepts `title`, `content`, and optional `description`, `sou
|
|
|
25
25
|
|
|
26
26
|
`create` Action 接收 `title`、`content`,以及可选的 `description`、`sourcePaths`、`sessionIds`。它始终新建独立档案,拒绝 `action`、`id` 等 mutation 选择字段;容量不足时失败,不更新或归档已有档案。原有 `manage` Action 继续支持创建和更新。Mnemon 后台审查只获得仅创建档案工具,已有内容覆盖候选时跳过。本变更无需迁移档案格式。
|
|
27
27
|
|
|
28
|
+
## Storage files
|
|
29
|
+
|
|
30
|
+
The `./contracts` entry names this Source's directory, index and lock under a storage root (`documents/`, `index.json`, `.index.lock`; each document lies in `active/` or `archived/` by its status) and exports `parseDocumentIndex`, which reads an index as a backup or sync carries it, and `summarizeDocumentIndex`, which counts one for an inventory. They are pure and browser-safe. The `dsh-mnemon` Starter's backup, sync and storage inventory use them instead of keeping copies.
|
|
31
|
+
|
|
28
32
|
## Source-owned UI and tests
|
|
29
33
|
|
|
30
34
|
The optional `./client` entry is an ordinary DSH Client plugin. This package owns its pages and `presentation/` resources and uses `dsh-mnemon/client` for the shared frame and scoped management client. It never receives a Host Context, credentials or another Source's controller.
|
package/lib/client.js
CHANGED
|
@@ -65,6 +65,7 @@ window.__ModuleLoader__.load({
|
|
|
65
65
|
"documents.updated": "已保存新的档案修订。",
|
|
66
66
|
"documents.updatedAfterArchive": "已先迁移 {count} 份旧档案,再保存修订。",
|
|
67
67
|
"documents.archived": "已建立 Mnemon 冷索引并归档;关联记忆空间:{spaces}",
|
|
68
|
+
"documents.archivedLocally": "已归档到本地:原文移入归档目录,没有建立 Mnemon 冷索引。",
|
|
68
69
|
"documents.list": "项目档案列表",
|
|
69
70
|
"documents.activeList": "活跃目录",
|
|
70
71
|
"documents.archiveList": "归档目录",
|
|
@@ -84,11 +85,12 @@ window.__ModuleLoader__.load({
|
|
|
84
85
|
"documents.hash": "内容哈希",
|
|
85
86
|
"documents.size": "文件大小",
|
|
86
87
|
"documents.archiveReceipt": "Mnemon 冷索引回执",
|
|
88
|
+
"documents.archiveNote": "归档说明",
|
|
87
89
|
"documents.archiveTitle": "迁入归档",
|
|
88
|
-
"documents.archiveDescription": "独立任务 Agent 先拟定摘要和目标空间;Host
|
|
90
|
+
"documents.archiveDescription": "独立任务 Agent 先拟定摘要和目标空间;Host 校验后写入冷索引,再移动原文。没有已启用且支持精确写入与删除的记忆空间时,原文直接移入本地归档,不建立索引。",
|
|
89
91
|
"documents.archive": "归档",
|
|
90
|
-
"documents.archiveConfirm": "
|
|
91
|
-
"documents.archiving": "
|
|
92
|
+
"documents.archiveConfirm": "确认归档这份档案?",
|
|
93
|
+
"documents.archiving": "归档中…",
|
|
92
94
|
"documents.archiveNow": "确认归档",
|
|
93
95
|
"documents.footnote": "`.mnemon/documents/index.json` 是控制面事实源;active 总量固定不超过 10 MB,archived 不计入上限,项目源文件不会被修改。"
|
|
94
96
|
};
|
|
@@ -126,6 +128,7 @@ window.__ModuleLoader__.load({
|
|
|
126
128
|
"documents.updated": "New document revision saved.",
|
|
127
129
|
"documents.updatedAfterArchive": "Archived {count} older document(s), then saved the revision.",
|
|
128
130
|
"documents.archived": "Mnemon cold index created and document archived; Memory Spaces: {spaces}",
|
|
131
|
+
"documents.archivedLocally": "Archived locally: the original moved to the archive, without a Mnemon cold index.",
|
|
129
132
|
"documents.list": "Project document list",
|
|
130
133
|
"documents.activeList": "Active directory",
|
|
131
134
|
"documents.archiveList": "Archive directory",
|
|
@@ -145,11 +148,12 @@ window.__ModuleLoader__.load({
|
|
|
145
148
|
"documents.hash": "Content hash",
|
|
146
149
|
"documents.size": "File size",
|
|
147
150
|
"documents.archiveReceipt": "Mnemon cold-index receipt",
|
|
151
|
+
"documents.archiveNote": "Archive note",
|
|
148
152
|
"documents.archiveTitle": "Move to archive",
|
|
149
|
-
"documents.archiveDescription": "An independent task Agent proposes a summary and destination. The Host validates and writes the cold index before moving the original.
|
|
153
|
+
"documents.archiveDescription": "An independent task Agent proposes a summary and destination. The Host validates and writes the cold index before moving the original. Without an active Memory Space that has exact writes and safe deletion, the original moves to the local archive without an index.",
|
|
150
154
|
"documents.archive": "Archive",
|
|
151
|
-
"documents.archiveConfirm": "
|
|
152
|
-
"documents.archiving": "
|
|
155
|
+
"documents.archiveConfirm": "Archive this document?",
|
|
156
|
+
"documents.archiving": "Archiving…",
|
|
153
157
|
"documents.archiveNow": "Confirm archive",
|
|
154
158
|
"documents.footnote": "`.mnemon/documents/index.json` is the control-plane source of truth. active stays at or below 10 MB, archived is excluded, and project source files are never modified."
|
|
155
159
|
};
|
|
@@ -1338,7 +1342,8 @@ window.__ModuleLoader__.load({
|
|
|
1338
1342
|
setNotice(null);
|
|
1339
1343
|
try {
|
|
1340
1344
|
const result = await props.client.archiveDocument(selected.id);
|
|
1341
|
-
|
|
1345
|
+
const spaces = result.maintenance?.memoryBodyIds ?? [];
|
|
1346
|
+
setNotice(spaces.length === 0 ? t("documents.archivedLocally") : t("documents.archived", { spaces: spaces.join(", ") }));
|
|
1342
1347
|
setConfirmArchive(false);
|
|
1343
1348
|
setStatus("archived");
|
|
1344
1349
|
setQuery("");
|
|
@@ -1593,7 +1598,7 @@ window.__ModuleLoader__.load({
|
|
|
1593
1598
|
selected.status === "archived" && /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
|
|
1594
1599
|
className: css.documentArchiveReceipt,
|
|
1595
1600
|
children: [
|
|
1596
|
-
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: t("documents.archiveReceipt") }),
|
|
1601
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { children: t(selected.memoryBodyIds.length === 0 ? "documents.archiveNote" : "documents.archiveReceipt") }),
|
|
1597
1602
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", { children: selected.archiveSummary }),
|
|
1598
1603
|
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { children: selected.memoryBodyIds.map((id) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: id }, id)) })
|
|
1599
1604
|
]
|
package/lib/contracts.d.ts
CHANGED
|
@@ -85,5 +85,41 @@ interface DocumentCapacityPlan {
|
|
|
85
85
|
}
|
|
86
86
|
declare const DOCUMENTS_VERSION = 1;
|
|
87
87
|
declare const DOCUMENTS_ACTIVE_LIMIT_BYTES: number;
|
|
88
|
+
/** The Documents Source's directory under a storage root; each document sits in `<status>/<filename>` below it. */
|
|
89
|
+
declare const DOCUMENTS_DIRECTORY = "documents";
|
|
90
|
+
/** The metadata of every document, the source of truth for which files belong to the Source. */
|
|
91
|
+
declare const DOCUMENTS_INDEX_FILE = "index.json";
|
|
92
|
+
/** Created exclusively while the index or a document is read or written; whoever copies them takes it too. */
|
|
93
|
+
declare const DOCUMENTS_LOCK_FILE = ".index.lock";
|
|
94
|
+
/** A lock file older than this was left by a process that stopped, and may be taken over. */
|
|
95
|
+
declare const DOCUMENTS_LOCK_STALE_MS = 30000;
|
|
96
|
+
/** The file name a document may have: one path segment, so it never leaves its status directory. */
|
|
97
|
+
declare const DOCUMENT_FILENAME_PATTERN: RegExp;
|
|
98
|
+
interface DocumentIndex {
|
|
99
|
+
version: typeof DOCUMENTS_VERSION;
|
|
100
|
+
documents: DocumentRecord[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Read an index as a copy of it carries it, such as a Mnemon Pack or a sync branch: every record
|
|
104
|
+
* complete, each id unique and each file name safe, or the whole index is refused. A record's path
|
|
105
|
+
* is where its status puts it, whatever the copy says. Unknown fields are dropped, and so are
|
|
106
|
+
* list items that are not strings. Reading the index does not judge a record's content hash: a
|
|
107
|
+
* store that needs repair still has to be copied as one.
|
|
108
|
+
*/
|
|
109
|
+
declare function parseDocumentIndex(value: unknown): DocumentIndex;
|
|
110
|
+
/** What a stored index.json holds, counted without judging each record. */
|
|
111
|
+
interface DocumentIndexSummary {
|
|
112
|
+
/** Whether the index has a record list at all. Without one, every count is 0. */
|
|
113
|
+
valid: boolean;
|
|
114
|
+
/** Every record that is an object, whatever its status. */
|
|
115
|
+
documents: number;
|
|
116
|
+
active: number;
|
|
117
|
+
archived: number;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Count the records of a parsed index.json for a read-only inventory. It never throws: an index
|
|
121
|
+
* without a record list is not `valid`, and a malformed record is counted or skipped, never refused.
|
|
122
|
+
*/
|
|
123
|
+
declare function summarizeDocumentIndex(value: unknown): DocumentIndexSummary;
|
|
88
124
|
//#endregion
|
|
89
|
-
export { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_VERSION, DocumentCapacityPlan, DocumentMutation, DocumentMutationResult, DocumentRecord, DocumentSearchResult, DocumentSnapshot, DocumentStatus, DocumentView };
|
|
125
|
+
export { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_DIRECTORY, DOCUMENTS_INDEX_FILE, DOCUMENTS_LOCK_FILE, DOCUMENTS_LOCK_STALE_MS, DOCUMENTS_VERSION, DOCUMENT_FILENAME_PATTERN, DocumentCapacityPlan, DocumentIndex, DocumentIndexSummary, DocumentMutation, DocumentMutationResult, DocumentRecord, DocumentSearchResult, DocumentSnapshot, DocumentStatus, DocumentView, parseDocumentIndex, summarizeDocumentIndex };
|
package/lib/contracts.js
CHANGED
|
@@ -1,5 +1,74 @@
|
|
|
1
1
|
//#region src/contracts.ts
|
|
2
2
|
const DOCUMENTS_VERSION = 1;
|
|
3
3
|
const DOCUMENTS_ACTIVE_LIMIT_BYTES = 10485760;
|
|
4
|
+
/** The Documents Source's directory under a storage root; each document sits in `<status>/<filename>` below it. */
|
|
5
|
+
const DOCUMENTS_DIRECTORY = "documents";
|
|
6
|
+
/** The metadata of every document, the source of truth for which files belong to the Source. */
|
|
7
|
+
const DOCUMENTS_INDEX_FILE = "index.json";
|
|
8
|
+
/** Created exclusively while the index or a document is read or written; whoever copies them takes it too. */
|
|
9
|
+
const DOCUMENTS_LOCK_FILE = ".index.lock";
|
|
10
|
+
/** A lock file older than this was left by a process that stopped, and may be taken over. */
|
|
11
|
+
const DOCUMENTS_LOCK_STALE_MS = 3e4;
|
|
12
|
+
/** The file name a document may have: one path segment, so it never leaves its status directory. */
|
|
13
|
+
const DOCUMENT_FILENAME_PATTERN = /^[a-zA-Z0-9._-]+\.md$/u;
|
|
14
|
+
function isObject(value) {
|
|
15
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Read an index as a copy of it carries it, such as a Mnemon Pack or a sync branch: every record
|
|
19
|
+
* complete, each id unique and each file name safe, or the whole index is refused. A record's path
|
|
20
|
+
* is where its status puts it, whatever the copy says. Unknown fields are dropped, and so are
|
|
21
|
+
* list items that are not strings. Reading the index does not judge a record's content hash: a
|
|
22
|
+
* store that needs repair still has to be copied as one.
|
|
23
|
+
*/
|
|
24
|
+
function parseDocumentIndex(value) {
|
|
25
|
+
const index = isObject(value) ? value : void 0;
|
|
26
|
+
if (index?.version !== 1 || !Array.isArray(index.documents)) throw new Error("Documents index.json is invalid");
|
|
27
|
+
const ids = /* @__PURE__ */ new Set();
|
|
28
|
+
return {
|
|
29
|
+
version: 1,
|
|
30
|
+
documents: index.documents.map((raw) => {
|
|
31
|
+
const item = isObject(raw) ? raw : void 0;
|
|
32
|
+
if (typeof item?.id !== "string" || item.id.trim() === "" || ids.has(item.id)) throw new Error("Documents index contains an invalid or duplicate id");
|
|
33
|
+
if (typeof item.title !== "string" || typeof item.description !== "string" || item.status !== "active" && item.status !== "archived") throw new Error("Documents index contains an invalid record");
|
|
34
|
+
if (typeof item.filename !== "string" || !DOCUMENT_FILENAME_PATTERN.test(item.filename)) throw new Error("Documents index contains an unsafe filename");
|
|
35
|
+
if (typeof item.createdAt !== "string" || typeof item.updatedAt !== "string" || typeof item.lastAccessedAt !== "string" || !Number.isSafeInteger(item.revision) || typeof item.contentHash !== "string" || !Number.isSafeInteger(item.sizeBytes)) throw new Error("Documents index contains invalid metadata");
|
|
36
|
+
if (!Array.isArray(item.sourcePaths) || !Array.isArray(item.sessionIds) || !Array.isArray(item.memoryBodyIds)) throw new Error("Documents index contains invalid lists");
|
|
37
|
+
ids.add(item.id);
|
|
38
|
+
return {
|
|
39
|
+
id: item.id,
|
|
40
|
+
title: item.title,
|
|
41
|
+
description: item.description,
|
|
42
|
+
status: item.status,
|
|
43
|
+
filename: item.filename,
|
|
44
|
+
relativePath: `${DOCUMENTS_DIRECTORY}/${item.status}/${item.filename}`,
|
|
45
|
+
sourcePaths: item.sourcePaths.filter((entry) => typeof entry === "string"),
|
|
46
|
+
sessionIds: item.sessionIds.filter((entry) => typeof entry === "string"),
|
|
47
|
+
createdAt: item.createdAt,
|
|
48
|
+
updatedAt: item.updatedAt,
|
|
49
|
+
lastAccessedAt: item.lastAccessedAt,
|
|
50
|
+
revision: Number(item.revision),
|
|
51
|
+
contentHash: item.contentHash,
|
|
52
|
+
sizeBytes: Number(item.sizeBytes),
|
|
53
|
+
...typeof item.archivedAt === "string" ? { archivedAt: item.archivedAt } : {},
|
|
54
|
+
...typeof item.archiveSummary === "string" ? { archiveSummary: item.archiveSummary } : {},
|
|
55
|
+
memoryBodyIds: item.memoryBodyIds.filter((entry) => typeof entry === "string")
|
|
56
|
+
};
|
|
57
|
+
})
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Count the records of a parsed index.json for a read-only inventory. It never throws: an index
|
|
62
|
+
* without a record list is not `valid`, and a malformed record is counted or skipped, never refused.
|
|
63
|
+
*/
|
|
64
|
+
function summarizeDocumentIndex(value) {
|
|
65
|
+
const documents = isObject(value) && Array.isArray(value.documents) ? value.documents.filter(isObject) : [];
|
|
66
|
+
return {
|
|
67
|
+
valid: isObject(value) && Array.isArray(value.documents),
|
|
68
|
+
documents: documents.length,
|
|
69
|
+
active: documents.filter((document) => document.status === "active").length,
|
|
70
|
+
archived: documents.filter((document) => document.status === "archived").length
|
|
71
|
+
};
|
|
72
|
+
}
|
|
4
73
|
//#endregion
|
|
5
|
-
export { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_VERSION };
|
|
74
|
+
export { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_DIRECTORY, DOCUMENTS_INDEX_FILE, DOCUMENTS_LOCK_FILE, DOCUMENTS_LOCK_STALE_MS, DOCUMENTS_VERSION, DOCUMENT_FILENAME_PATTERN, parseDocumentIndex, summarizeDocumentIndex };
|
package/lib/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_VERSION, DocumentCapacityPlan, DocumentMutation, DocumentMutationResult, DocumentRecord, DocumentSearchResult, DocumentSnapshot, DocumentStatus, DocumentView } from "./contracts.js";
|
|
1
|
+
import { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_DIRECTORY, DOCUMENTS_INDEX_FILE, DOCUMENTS_LOCK_FILE, DOCUMENTS_LOCK_STALE_MS, DOCUMENTS_VERSION, DOCUMENT_FILENAME_PATTERN, DocumentCapacityPlan, DocumentIndex, DocumentIndexSummary, DocumentMutation, DocumentMutationResult, DocumentRecord, DocumentSearchResult, DocumentSnapshot, DocumentStatus, DocumentView, parseDocumentIndex, summarizeDocumentIndex } from "./contracts.js";
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
import { MemorySourceDefinition } from "dsh-mnemon/contracts";
|
|
4
4
|
import { Context } from "@deepseek-ai/cordis";
|
|
@@ -19,4 +19,4 @@ declare const inject: string[];
|
|
|
19
19
|
declare const memoryPlugin: import("dsh-mnemon/extension-sdk").MemoryPluginDescriptor;
|
|
20
20
|
declare function apply(ctx: Context, config?: Config): void;
|
|
21
21
|
//#endregion
|
|
22
|
-
export { Config, type DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_MEMORY_SOURCE, type DOCUMENTS_VERSION, type DocumentCapacityPlan, type DocumentMutation, type DocumentMutationResult, type DocumentRecord, type DocumentSearchResult, type DocumentSnapshot, type DocumentStatus, type DocumentView, apply, createDocumentsMemorySource, inject, memoryPlugin, name };
|
|
22
|
+
export { Config, type DOCUMENTS_ACTIVE_LIMIT_BYTES, type DOCUMENTS_DIRECTORY, type DOCUMENTS_INDEX_FILE, type DOCUMENTS_LOCK_FILE, type DOCUMENTS_LOCK_STALE_MS, DOCUMENTS_MEMORY_SOURCE, type DOCUMENTS_VERSION, type DOCUMENT_FILENAME_PATTERN, type DocumentCapacityPlan, type DocumentIndex, type DocumentIndexSummary, type DocumentMutation, type DocumentMutationResult, type DocumentRecord, type DocumentSearchResult, type DocumentSnapshot, type DocumentStatus, type DocumentView, apply, createDocumentsMemorySource, inject, memoryPlugin, name, type parseDocumentIndex, type summarizeDocumentIndex };
|
package/lib/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DOCUMENTS_ACTIVE_LIMIT_BYTES } from "./contracts.js";
|
|
1
|
+
import { DOCUMENTS_ACTIVE_LIMIT_BYTES, DOCUMENTS_DIRECTORY, DOCUMENTS_INDEX_FILE, DOCUMENTS_LOCK_FILE } 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
4
|
import { basename, isAbsolute, join, relative, resolve, sep } from "node:path";
|
|
@@ -47,7 +47,6 @@ function lexicalRequiredMatchCount(tokens) {
|
|
|
47
47
|
//#region src/controller.ts
|
|
48
48
|
const MAX_DOCUMENT_BYTES = 2097152;
|
|
49
49
|
const LOCK_TIMEOUT_MS = 5e3;
|
|
50
|
-
const LOCK_STALE_MS = 3e4;
|
|
51
50
|
const LOCK_RETRY_MS = 20;
|
|
52
51
|
const MAX_EXCERPT_CACHE_ENTRIES = 2048;
|
|
53
52
|
var DocumentCapacityError = class extends Error {
|
|
@@ -200,12 +199,12 @@ var DocumentController = class {
|
|
|
200
199
|
if (!existsSync(this.workspaceRoot) || !statSync(this.workspaceRoot).isDirectory()) throw new Error(`document workspace is unavailable: ${this.workspaceRoot}`);
|
|
201
200
|
if (!Number.isSafeInteger(limitBytes) || limitBytes < 1) throw new Error("active document limit must be a positive integer");
|
|
202
201
|
this.storageRoot = storageRoot === void 0 ? join(this.workspaceRoot, ".mnemon") : resolve(storageRoot);
|
|
203
|
-
this.managedRelativePrefix = storageRoot === void 0 ? [".mnemon",
|
|
204
|
-
this.directory = join(this.storageRoot,
|
|
202
|
+
this.managedRelativePrefix = storageRoot === void 0 ? [".mnemon", DOCUMENTS_DIRECTORY].join("/") : DOCUMENTS_DIRECTORY;
|
|
203
|
+
this.directory = join(this.storageRoot, DOCUMENTS_DIRECTORY);
|
|
205
204
|
this.activeDirectory = join(this.directory, "active");
|
|
206
205
|
this.archivedDirectory = join(this.directory, "archived");
|
|
207
|
-
this.indexPath = join(this.directory,
|
|
208
|
-
this.lockPath = join(this.directory,
|
|
206
|
+
this.indexPath = join(this.directory, DOCUMENTS_INDEX_FILE);
|
|
207
|
+
this.lockPath = join(this.directory, DOCUMENTS_LOCK_FILE);
|
|
209
208
|
this.initialize();
|
|
210
209
|
}
|
|
211
210
|
snapshot() {
|
|
@@ -578,7 +577,7 @@ var DocumentController = class {
|
|
|
578
577
|
].join("/");
|
|
579
578
|
}
|
|
580
579
|
pathFor(record) {
|
|
581
|
-
const legacyPrefix = [".mnemon",
|
|
580
|
+
const legacyPrefix = [".mnemon", DOCUMENTS_DIRECTORY].join("/");
|
|
582
581
|
const relativePath = record.relativePath === legacyPrefix || record.relativePath.startsWith(`${legacyPrefix}/`) ? record.relativePath.slice(8) : record.relativePath;
|
|
583
582
|
const path = resolve(this.storageRoot, relativePath);
|
|
584
583
|
const managedRoot = `${resolve(this.directory)}${sep}`;
|
|
@@ -618,7 +617,7 @@ var DocumentController = class {
|
|
|
618
617
|
} catch (error) {
|
|
619
618
|
if (error.code !== "EEXIST") throw error;
|
|
620
619
|
try {
|
|
621
|
-
if (Date.now() - statSync(this.lockPath).mtimeMs >
|
|
620
|
+
if (Date.now() - statSync(this.lockPath).mtimeMs > 3e4) rmSync(this.lockPath, { force: true });
|
|
622
621
|
} catch {}
|
|
623
622
|
if (Date.now() >= deadline) throw new Error(`timed out waiting for document lock: ${this.lockPath}`);
|
|
624
623
|
sleepSync(LOCK_RETRY_MS);
|
package/lib/types/contracts.d.ts
CHANGED
|
@@ -84,3 +84,39 @@ export interface DocumentCapacityPlan {
|
|
|
84
84
|
}
|
|
85
85
|
export declare const DOCUMENTS_VERSION = 1;
|
|
86
86
|
export declare const DOCUMENTS_ACTIVE_LIMIT_BYTES: number;
|
|
87
|
+
/** The Documents Source's directory under a storage root; each document sits in `<status>/<filename>` below it. */
|
|
88
|
+
export declare const DOCUMENTS_DIRECTORY = "documents";
|
|
89
|
+
/** The metadata of every document, the source of truth for which files belong to the Source. */
|
|
90
|
+
export declare const DOCUMENTS_INDEX_FILE = "index.json";
|
|
91
|
+
/** Created exclusively while the index or a document is read or written; whoever copies them takes it too. */
|
|
92
|
+
export declare const DOCUMENTS_LOCK_FILE = ".index.lock";
|
|
93
|
+
/** A lock file older than this was left by a process that stopped, and may be taken over. */
|
|
94
|
+
export declare const DOCUMENTS_LOCK_STALE_MS = 30000;
|
|
95
|
+
/** The file name a document may have: one path segment, so it never leaves its status directory. */
|
|
96
|
+
export declare const DOCUMENT_FILENAME_PATTERN: RegExp;
|
|
97
|
+
export interface DocumentIndex {
|
|
98
|
+
version: typeof DOCUMENTS_VERSION;
|
|
99
|
+
documents: DocumentRecord[];
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Read an index as a copy of it carries it, such as a Mnemon Pack or a sync branch: every record
|
|
103
|
+
* complete, each id unique and each file name safe, or the whole index is refused. A record's path
|
|
104
|
+
* is where its status puts it, whatever the copy says. Unknown fields are dropped, and so are
|
|
105
|
+
* list items that are not strings. Reading the index does not judge a record's content hash: a
|
|
106
|
+
* store that needs repair still has to be copied as one.
|
|
107
|
+
*/
|
|
108
|
+
export declare function parseDocumentIndex(value: unknown): DocumentIndex;
|
|
109
|
+
/** What a stored index.json holds, counted without judging each record. */
|
|
110
|
+
export interface DocumentIndexSummary {
|
|
111
|
+
/** Whether the index has a record list at all. Without one, every count is 0. */
|
|
112
|
+
valid: boolean;
|
|
113
|
+
/** Every record that is an object, whatever its status. */
|
|
114
|
+
documents: number;
|
|
115
|
+
active: number;
|
|
116
|
+
archived: number;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Count the records of a parsed index.json for a read-only inventory. It never throws: an index
|
|
120
|
+
* without a record list is not `valid`, and a malformed record is counted or skipped, never refused.
|
|
121
|
+
*/
|
|
122
|
+
export declare function summarizeDocumentIndex(value: unknown): DocumentIndexSummary;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-mnemon-source-documents",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.11",
|
|
4
4
|
"description": "Self-contained documents Source for Composable View Memory.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
"react": "^18.2.0"
|
|
57
57
|
},
|
|
58
58
|
"devDependencies": {
|
|
59
|
-
"@deepseek-ai/dsh-client-ui-primitives": "0.1
|
|
59
|
+
"@deepseek-ai/dsh-client-ui-primitives": "0.2.1-rc.2",
|
|
60
60
|
"@testing-library/react": "^16.3.0",
|
|
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.
|
|
64
|
+
"dsh-mnemon": "^0.5.32",
|
|
65
65
|
"jsdom": "^26.0.0",
|
|
66
66
|
"react": "^18.2.0",
|
|
67
67
|
"react-dom": "^18.2.0",
|
|
@@ -85,9 +85,9 @@
|
|
|
85
85
|
"micromark-util-sanitize-uri": "^2.0.1",
|
|
86
86
|
"micromark-util-symbol": "^2.0.1",
|
|
87
87
|
"shiki": "^4.3.1",
|
|
88
|
-
"@deepseek-ai/dsh-client-store": "0.1
|
|
89
|
-
"@deepseek-ai/dsh-util-code-language": "0.1
|
|
90
|
-
"@deepseek-ai/dsh-util-workspace-path": "0.1
|
|
88
|
+
"@deepseek-ai/dsh-client-store": "0.2.1-rc.2",
|
|
89
|
+
"@deepseek-ai/dsh-util-code-language": "0.2.1-rc.2",
|
|
90
|
+
"@deepseek-ai/dsh-util-workspace-path": "0.2.1-rc.2",
|
|
91
91
|
"diff": "^9.0.0",
|
|
92
92
|
"immer": "^10.1.1",
|
|
93
93
|
"simple-icons": "16.31.0",
|
|
@@ -33,6 +33,7 @@
|
|
|
33
33
|
"documents.updated": "已保存新的档案修订。",
|
|
34
34
|
"documents.updatedAfterArchive": "已先迁移 {count} 份旧档案,再保存修订。",
|
|
35
35
|
"documents.archived": "已建立 Mnemon 冷索引并归档;关联记忆空间:{spaces}",
|
|
36
|
+
"documents.archivedLocally": "已归档到本地:原文移入归档目录,没有建立 Mnemon 冷索引。",
|
|
36
37
|
"documents.list": "项目档案列表",
|
|
37
38
|
"documents.activeList": "活跃目录",
|
|
38
39
|
"documents.archiveList": "归档目录",
|
|
@@ -52,11 +53,12 @@
|
|
|
52
53
|
"documents.hash": "内容哈希",
|
|
53
54
|
"documents.size": "文件大小",
|
|
54
55
|
"documents.archiveReceipt": "Mnemon 冷索引回执",
|
|
56
|
+
"documents.archiveNote": "归档说明",
|
|
55
57
|
"documents.archiveTitle": "迁入归档",
|
|
56
|
-
"documents.archiveDescription": "独立任务 Agent 先拟定摘要和目标空间;Host
|
|
58
|
+
"documents.archiveDescription": "独立任务 Agent 先拟定摘要和目标空间;Host 校验后写入冷索引,再移动原文。没有已启用且支持精确写入与删除的记忆空间时,原文直接移入本地归档,不建立索引。",
|
|
57
59
|
"documents.archive": "归档",
|
|
58
|
-
"documents.archiveConfirm": "
|
|
59
|
-
"documents.archiving": "
|
|
60
|
+
"documents.archiveConfirm": "确认归档这份档案?",
|
|
61
|
+
"documents.archiving": "归档中…",
|
|
60
62
|
"documents.archiveNow": "确认归档",
|
|
61
63
|
"documents.footnote": "`.mnemon/documents/index.json` 是控制面事实源;active 总量固定不超过 10 MB,archived 不计入上限,项目源文件不会被修改。"
|
|
62
64
|
},
|
|
@@ -94,6 +96,7 @@
|
|
|
94
96
|
"documents.updated": "New document revision saved.",
|
|
95
97
|
"documents.updatedAfterArchive": "Archived {count} older document(s), then saved the revision.",
|
|
96
98
|
"documents.archived": "Mnemon cold index created and document archived; Memory Spaces: {spaces}",
|
|
99
|
+
"documents.archivedLocally": "Archived locally: the original moved to the archive, without a Mnemon cold index.",
|
|
97
100
|
"documents.list": "Project document list",
|
|
98
101
|
"documents.activeList": "Active directory",
|
|
99
102
|
"documents.archiveList": "Archive directory",
|
|
@@ -113,11 +116,12 @@
|
|
|
113
116
|
"documents.hash": "Content hash",
|
|
114
117
|
"documents.size": "File size",
|
|
115
118
|
"documents.archiveReceipt": "Mnemon cold-index receipt",
|
|
119
|
+
"documents.archiveNote": "Archive note",
|
|
116
120
|
"documents.archiveTitle": "Move to archive",
|
|
117
|
-
"documents.archiveDescription": "An independent task Agent proposes a summary and destination. The Host validates and writes the cold index before moving the original.
|
|
121
|
+
"documents.archiveDescription": "An independent task Agent proposes a summary and destination. The Host validates and writes the cold index before moving the original. Without an active Memory Space that has exact writes and safe deletion, the original moves to the local archive without an index.",
|
|
118
122
|
"documents.archive": "Archive",
|
|
119
|
-
"documents.archiveConfirm": "
|
|
120
|
-
"documents.archiving": "
|
|
123
|
+
"documents.archiveConfirm": "Archive this document?",
|
|
124
|
+
"documents.archiving": "Archiving…",
|
|
121
125
|
"documents.archiveNow": "Confirm archive",
|
|
122
126
|
"documents.footnote": "`.mnemon/documents/index.json` is the control-plane source of truth. active stays at or below 10 MB, archived is excluded, and project source files are never modified."
|
|
123
127
|
}
|