dsh-mnemon-source-documents 0.6.3 → 0.6.5
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/lib/client.js +0 -1
- package/lib/contracts.d.ts +0 -20
- package/lib/contracts.js +0 -16
- package/lib/index.d.ts +1 -0
- package/lib/index.js +66 -33
- package/lib/types/client/api.d.ts +0 -1
- package/lib/types/contracts.d.ts +0 -20
- package/package.json +2 -2
package/lib/client.js
CHANGED
|
@@ -228,7 +228,6 @@ window.__ModuleLoader__.load({
|
|
|
228
228
|
function PathText(props) {
|
|
229
229
|
return canRenderPathLabel ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_deepseek_ai_dsh_client_ui_primitives.PathLabel, { path: props.path }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: props.path });
|
|
230
230
|
}
|
|
231
|
-
/** Render managed Markdown through the official DSH Markdown pipeline without raw HTML or unsafe links. */
|
|
232
231
|
function DocumentMarkdown(props) {
|
|
233
232
|
const locale = (0, dsh_mnemon_client.useLocale)();
|
|
234
233
|
const labels = (0, react.useMemo)(() => {
|
package/lib/contracts.d.ts
CHANGED
|
@@ -21,7 +21,6 @@ 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
24
|
fileRevision?: string;
|
|
26
25
|
}
|
|
27
26
|
interface DocumentSnapshot {
|
|
@@ -91,41 +90,22 @@ interface DocumentCapacityPlan {
|
|
|
91
90
|
}
|
|
92
91
|
declare const DOCUMENTS_VERSION = 1;
|
|
93
92
|
declare const DOCUMENTS_ACTIVE_LIMIT_BYTES: number;
|
|
94
|
-
/** The Documents Source's directory under a storage root; each document sits in `<status>/<filename>` below it. */
|
|
95
93
|
declare const DOCUMENTS_DIRECTORY = "documents";
|
|
96
|
-
/** The metadata of every document, the source of truth for which files belong to the Source. */
|
|
97
94
|
declare const DOCUMENTS_INDEX_FILE = "index.json";
|
|
98
|
-
/** Created exclusively while the index or a document is read or written; whoever copies them takes it too. */
|
|
99
95
|
declare const DOCUMENTS_LOCK_FILE = ".index.lock";
|
|
100
|
-
/** A lock file older than this was left by a process that stopped, and may be taken over. */
|
|
101
96
|
declare const DOCUMENTS_LOCK_STALE_MS = 30000;
|
|
102
|
-
/** The file name a document may have: one path segment, so it never leaves its status directory. */
|
|
103
97
|
declare const DOCUMENT_FILENAME_PATTERN: RegExp;
|
|
104
98
|
interface DocumentIndex {
|
|
105
99
|
version: typeof DOCUMENTS_VERSION;
|
|
106
100
|
documents: DocumentRecord[];
|
|
107
101
|
}
|
|
108
|
-
/**
|
|
109
|
-
* Read an index as a copy of it carries it, such as a Mnemon Pack or a sync branch: every record
|
|
110
|
-
* complete, each id unique and each file name safe, or the whole index is refused. A record's path
|
|
111
|
-
* is where its status puts it, whatever the copy says. Unknown fields are dropped, and so are
|
|
112
|
-
* list items that are not strings. Reading the index does not judge a record's content hash: a
|
|
113
|
-
* store that needs repair still has to be copied as one.
|
|
114
|
-
*/
|
|
115
102
|
declare function parseDocumentIndex(value: unknown): DocumentIndex;
|
|
116
|
-
/** What a stored index.json holds, counted without judging each record. */
|
|
117
103
|
interface DocumentIndexSummary {
|
|
118
|
-
/** Whether the index has a record list at all. Without one, every count is 0. */
|
|
119
104
|
valid: boolean;
|
|
120
|
-
/** Every record that is an object, whatever its status. */
|
|
121
105
|
documents: number;
|
|
122
106
|
active: number;
|
|
123
107
|
archived: number;
|
|
124
108
|
}
|
|
125
|
-
/**
|
|
126
|
-
* Count the records of a parsed index.json for a read-only inventory. It never throws: an index
|
|
127
|
-
* without a record list is not `valid`, and a malformed record is counted or skipped, never refused.
|
|
128
|
-
*/
|
|
129
109
|
declare function summarizeDocumentIndex(value: unknown): DocumentIndexSummary;
|
|
130
110
|
//#endregion
|
|
131
111
|
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,26 +1,14 @@
|
|
|
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
4
|
const DOCUMENTS_DIRECTORY = "documents";
|
|
6
|
-
/** The metadata of every document, the source of truth for which files belong to the Source. */
|
|
7
5
|
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
6
|
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
7
|
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
8
|
const DOCUMENT_FILENAME_PATTERN = /^[a-zA-Z0-9._-]+\.md$/u;
|
|
14
9
|
function isObject(value) {
|
|
15
10
|
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
16
11
|
}
|
|
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
12
|
function parseDocumentIndex(value) {
|
|
25
13
|
const index = isObject(value) ? value : void 0;
|
|
26
14
|
if (index?.version !== 1 || !Array.isArray(index.documents)) throw new Error("Documents index.json is invalid");
|
|
@@ -57,10 +45,6 @@ function parseDocumentIndex(value) {
|
|
|
57
45
|
})
|
|
58
46
|
};
|
|
59
47
|
}
|
|
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
48
|
function summarizeDocumentIndex(value) {
|
|
65
49
|
const documents = isObject(value) && Array.isArray(value.documents) ? value.documents.filter(isObject) : [];
|
|
66
50
|
return {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -5,11 +5,12 @@ import { basename, dirname, isAbsolute, join, relative, resolve, sep } from "nod
|
|
|
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, lstatSync, mkdirSync, openSync, readFileSync, realpathSync, renameSync, rmSync, statSync, unlinkSync, writeFileSync } from "node:fs";
|
|
8
|
+
import { closeSync, existsSync, fstatSync, lstatSync, mkdirSync, openSync, readFileSync, readSync, 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(),
|
|
12
12
|
bm25Recall: z.boolean(),
|
|
13
|
+
bm25IndexPush: z.boolean(),
|
|
13
14
|
limitBytes: z.number().step(1).min(1).max(1073741824)
|
|
14
15
|
});
|
|
15
16
|
function documentsSourceConfig(value, instanceKey) {
|
|
@@ -19,12 +20,12 @@ function documentsSourceConfig(value, instanceKey) {
|
|
|
19
20
|
return {
|
|
20
21
|
dataDir,
|
|
21
22
|
limitBytes: config.limitBytes ?? 10485760,
|
|
22
|
-
bm25Recall: config.bm25Recall ?? false
|
|
23
|
+
bm25Recall: config.bm25Recall ?? false,
|
|
24
|
+
bm25IndexPush: config.bm25IndexPush ?? false
|
|
23
25
|
};
|
|
24
26
|
}
|
|
25
27
|
//#endregion
|
|
26
28
|
//#region src/search-tokens.ts
|
|
27
|
-
/** Small deterministic tokenizer shared by local Document and Native recovery. */
|
|
28
29
|
function lexicalSearchTokens(value, maximum = 64) {
|
|
29
30
|
const normalized = value.normalize("NFKC").toLocaleLowerCase();
|
|
30
31
|
const tokens = [];
|
|
@@ -39,7 +40,6 @@ function lexicalSearchTokens(value, maximum = 64) {
|
|
|
39
40
|
}
|
|
40
41
|
return [...new Set(tokens)].slice(0, maximum);
|
|
41
42
|
}
|
|
42
|
-
/** Require broader coverage only after a query is focused enough to support it. */
|
|
43
43
|
function lexicalRequiredMatchCount(tokens) {
|
|
44
44
|
if (tokens.length === 0) return 0;
|
|
45
45
|
if (tokens.length < 4) return 1;
|
|
@@ -51,6 +51,7 @@ const MAX_DOCUMENT_BYTES = 2097152;
|
|
|
51
51
|
const LOCK_TIMEOUT_MS = 5e3;
|
|
52
52
|
const LOCK_RETRY_MS = 20;
|
|
53
53
|
const MAX_EXCERPT_CACHE_ENTRIES = 2048;
|
|
54
|
+
const INDEX_EXCERPT_READ_BYTES = 16384;
|
|
54
55
|
var DocumentCapacityError = class extends Error {
|
|
55
56
|
projected;
|
|
56
57
|
limit;
|
|
@@ -148,10 +149,25 @@ function excerpt(content, maximum = 220) {
|
|
|
148
149
|
const normalized = content.replace(/[#>*_`\[\]]/gu, "").replace(/\s+/gu, " ").trim();
|
|
149
150
|
return normalized.length <= maximum ? normalized : `${normalized.slice(0, maximum - 1)}…`;
|
|
150
151
|
}
|
|
151
|
-
/** Include ctime and identity so restored mtimes and atomic replacements miss. */
|
|
152
152
|
function diskIdentity(stat) {
|
|
153
153
|
return `${stat.dev}:${stat.ino}:${stat.size}:${stat.mtimeNs}:${stat.ctimeNs}:${stat.mode}`;
|
|
154
154
|
}
|
|
155
|
+
function needsIndexExcerpt(record) {
|
|
156
|
+
return record.status === "active" && record.description.trim() === "";
|
|
157
|
+
}
|
|
158
|
+
function readIndexExcerpt(path, identity) {
|
|
159
|
+
const descriptor = openSync(path, "r");
|
|
160
|
+
try {
|
|
161
|
+
if (diskIdentity(fstatSync(descriptor, { bigint: true })) !== identity) return "";
|
|
162
|
+
const buffer = Buffer.allocUnsafe(INDEX_EXCERPT_READ_BYTES);
|
|
163
|
+
const bytes = readSync(descriptor, buffer, 0, buffer.length, 0);
|
|
164
|
+
const prefix = new TextDecoder().decode(buffer.subarray(0, bytes), { stream: bytes === buffer.length }).replace(/\r\n/gu, "\n");
|
|
165
|
+
if (prefix.startsWith("---\n") && !prefix.includes("\n---\n", 4)) return "";
|
|
166
|
+
return excerpt(documentBody(prefix));
|
|
167
|
+
} finally {
|
|
168
|
+
closeSync(descriptor);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
155
171
|
function sleepSync(milliseconds) {
|
|
156
172
|
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, milliseconds);
|
|
157
173
|
}
|
|
@@ -181,7 +197,6 @@ function parseRecord(value) {
|
|
|
181
197
|
memoryBodyIds: value.memoryBodyIds.filter((entry) => typeof entry === "string")
|
|
182
198
|
};
|
|
183
199
|
}
|
|
184
|
-
/** Project-scoped control plane for managed active and cold document copies. */
|
|
185
200
|
var DocumentController = class {
|
|
186
201
|
limitBytes;
|
|
187
202
|
now;
|
|
@@ -195,6 +210,7 @@ var DocumentController = class {
|
|
|
195
210
|
managedRelativePrefix;
|
|
196
211
|
queue = Promise.resolve();
|
|
197
212
|
excerpts = /* @__PURE__ */ new Map();
|
|
213
|
+
indexExcerpts = /* @__PURE__ */ new Map();
|
|
198
214
|
indexCache;
|
|
199
215
|
indexRevisions = /* @__PURE__ */ new WeakMap();
|
|
200
216
|
constructor(workspaceRoot, limitBytes = DOCUMENTS_ACTIVE_LIMIT_BYTES, now = () => /* @__PURE__ */ new Date(), storageRoot) {
|
|
@@ -215,9 +231,8 @@ var DocumentController = class {
|
|
|
215
231
|
snapshot() {
|
|
216
232
|
return this.withLock(() => this.snapshotUnlocked(this.readIndex()));
|
|
217
233
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
return this.withLock(() => this.snapshotUnlocked(this.readIndex(), false));
|
|
234
|
+
catalog(includeIndexExcerpts = false) {
|
|
235
|
+
return this.withLock(() => this.snapshotUnlocked(this.readIndex(), includeIndexExcerpts ? "index" : false));
|
|
221
236
|
}
|
|
222
237
|
revision() {
|
|
223
238
|
return this.withLock(() => this.revisionOf(this.readIndex()));
|
|
@@ -556,28 +571,32 @@ var DocumentController = class {
|
|
|
556
571
|
return this.indexRevisions.get(index) ?? indexRevision(index);
|
|
557
572
|
}
|
|
558
573
|
snapshotUnlocked(index, includeExcerpts = true) {
|
|
559
|
-
const
|
|
574
|
+
const cache = includeExcerpts === "index" ? this.indexExcerpts : this.excerpts;
|
|
575
|
+
const excerptRecords = includeExcerpts === "index" ? index.documents.filter(needsIndexExcerpt) : index.documents;
|
|
576
|
+
const cachedPaths = includeExcerpts === false ? void 0 : excerptRecords.slice(0, MAX_EXCERPT_CACHE_ENTRIES).map((record) => this.pathFor(record));
|
|
560
577
|
const eligiblePaths = cachedPaths === void 0 ? void 0 : new Set(cachedPaths);
|
|
561
578
|
if (eligiblePaths !== void 0) {
|
|
562
|
-
for (const path of
|
|
579
|
+
for (const path of cache.keys()) if (!eligiblePaths.has(path)) cache.delete(path);
|
|
563
580
|
}
|
|
564
581
|
const documents = index.documents.map((record, position) => {
|
|
565
|
-
const path = cachedPaths?.[position] ?? this.pathFor(record);
|
|
582
|
+
const path = (includeExcerpts === true ? cachedPaths?.[position] : void 0) ?? this.pathFor(record);
|
|
583
|
+
const indexExcerpt = includeExcerpts === "index" && needsIndexExcerpt(record);
|
|
566
584
|
let stat;
|
|
567
585
|
try {
|
|
568
|
-
stat = statSync(path, { bigint: true });
|
|
586
|
+
stat = indexExcerpt ? lstatSync(path, { bigint: true }) : statSync(path, { bigint: true });
|
|
569
587
|
} catch {
|
|
570
|
-
|
|
588
|
+
cache.delete(path);
|
|
571
589
|
return {
|
|
572
590
|
...record,
|
|
573
591
|
healthy: false,
|
|
574
592
|
excerpt: ""
|
|
575
593
|
};
|
|
576
594
|
}
|
|
595
|
+
const sample = includeExcerpts === true || indexExcerpt && stat.isFile();
|
|
577
596
|
return {
|
|
578
597
|
...record,
|
|
579
598
|
healthy: true,
|
|
580
|
-
excerpt:
|
|
599
|
+
excerpt: sample ? this.bodyExcerpt(record, path, stat, eligiblePaths.has(path), indexExcerpt) : ""
|
|
581
600
|
};
|
|
582
601
|
});
|
|
583
602
|
const active = documents.filter((record) => record.status === "active");
|
|
@@ -595,16 +614,22 @@ var DocumentController = class {
|
|
|
595
614
|
documents
|
|
596
615
|
};
|
|
597
616
|
}
|
|
598
|
-
|
|
599
|
-
bodyExcerpt(record, path, stat, cacheable) {
|
|
600
|
-
if (!cacheable) return excerpt(this.readBody(record));
|
|
617
|
+
bodyExcerpt(record, path, stat, cacheable, indexExcerpt) {
|
|
601
618
|
const identity = diskIdentity(stat);
|
|
602
|
-
const
|
|
619
|
+
const cache = indexExcerpt ? this.indexExcerpts : this.excerpts;
|
|
620
|
+
const cached = cacheable ? cache.get(path) : void 0;
|
|
603
621
|
if (cached?.identity === identity) return cached.value;
|
|
604
|
-
|
|
605
|
-
|
|
622
|
+
cache.delete(path);
|
|
623
|
+
let value;
|
|
624
|
+
try {
|
|
625
|
+
value = indexExcerpt ? readIndexExcerpt(path, identity) : excerpt(this.readBody(record));
|
|
626
|
+
} catch (error) {
|
|
627
|
+
if (indexExcerpt) return "";
|
|
628
|
+
throw error;
|
|
629
|
+
}
|
|
630
|
+
if (!cacheable) return value;
|
|
606
631
|
try {
|
|
607
|
-
if (diskIdentity(statSync(path, { bigint: true })) === identity)
|
|
632
|
+
if (diskIdentity(statSync(path, { bigint: true })) === identity) cache.set(path, {
|
|
608
633
|
identity,
|
|
609
634
|
value
|
|
610
635
|
});
|
|
@@ -701,7 +726,6 @@ var DocumentController = class {
|
|
|
701
726
|
}
|
|
702
727
|
}
|
|
703
728
|
};
|
|
704
|
-
/** Resolves one cached controller per canonical DSH workspace. */
|
|
705
729
|
var DocumentManager = class {
|
|
706
730
|
limitBytes;
|
|
707
731
|
now;
|
|
@@ -726,7 +750,6 @@ var DocumentManager = class {
|
|
|
726
750
|
};
|
|
727
751
|
//#endregion
|
|
728
752
|
//#region src/evidence.ts
|
|
729
|
-
/** Preserve query-local evidence under the Source's per-document budget. */
|
|
730
753
|
function documentEvidence(content, query, maximum) {
|
|
731
754
|
if (maximum <= 0) return "";
|
|
732
755
|
if (content.length <= maximum) return content;
|
|
@@ -884,7 +907,7 @@ function createDocumentsMemorySource(config = {}) {
|
|
|
884
907
|
...configured
|
|
885
908
|
}, context.sourceInstanceKey);
|
|
886
909
|
const documents = new DocumentManager(effective.limitBytes, void 0, () => effective.dataDir);
|
|
887
|
-
const snapshot = (workspaceId
|
|
910
|
+
const snapshot = (workspaceId, indexExcerpts = false) => documents.forWorkspace(workspaceId).catalog(indexExcerpts);
|
|
888
911
|
const prepared = /* @__PURE__ */ new WeakMap();
|
|
889
912
|
const created = /* @__PURE__ */ new WeakMap();
|
|
890
913
|
return {
|
|
@@ -917,7 +940,7 @@ function createDocumentsMemorySource(config = {}) {
|
|
|
917
940
|
routeIds: ["search"],
|
|
918
941
|
actionIds: ["manage", "create"]
|
|
919
942
|
};
|
|
920
|
-
const current = snapshot(root);
|
|
943
|
+
const current = snapshot(root, effective.bm25IndexPush && request.scenario === "agent.root-turn");
|
|
921
944
|
prepared.set(request.scope, current);
|
|
922
945
|
const active = current.documents.filter((document) => document.status === "active" && document.healthy);
|
|
923
946
|
return {
|
|
@@ -941,7 +964,8 @@ function createDocumentsMemorySource(config = {}) {
|
|
|
941
964
|
project(request) {
|
|
942
965
|
const root = workspace(request.scope);
|
|
943
966
|
if (root === void 0) return { fragments: [] };
|
|
944
|
-
const
|
|
967
|
+
const indexPush = request.includeProjection && effective.bm25IndexPush;
|
|
968
|
+
const current = prepared.get(request.scope) ?? snapshot(root, indexPush);
|
|
945
969
|
prepared.delete(request.scope);
|
|
946
970
|
if (current.revision !== request.expectedRevision) throw new Error("Documents projection revision changed during composition");
|
|
947
971
|
const active = current.documents.filter((document) => document.status === "active" && document.healthy).sort((a, b) => a.id.localeCompare(b.id));
|
|
@@ -953,13 +977,22 @@ function createDocumentsMemorySource(config = {}) {
|
|
|
953
977
|
workspaceRoot: root,
|
|
954
978
|
documentIds: active.map((document) => document.id),
|
|
955
979
|
archivedDocumentIds: current.documents.filter((document) => document.status === "archived" && document.healthy).map((document) => document.id).sort(),
|
|
956
|
-
...request.includeProjection && effective.bm25Recall ? { bm25: {
|
|
957
|
-
scope: createHash("sha256").update(JSON.stringify([
|
|
980
|
+
...request.includeProjection && (effective.bm25Recall || indexPush) ? { bm25: {
|
|
981
|
+
scope: createHash("sha256").update(JSON.stringify(indexPush ? [
|
|
982
|
+
effective.dataDir,
|
|
983
|
+
root,
|
|
984
|
+
true
|
|
985
|
+
] : [effective.dataDir, root])).digest("hex"),
|
|
958
986
|
text: truncateMemoryText("Project Documents can be searched by title or topic.", request.maxCharacters),
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
987
|
+
...indexPush ? { indexPush: true } : {},
|
|
988
|
+
titles: active.map((document) => {
|
|
989
|
+
const summary = indexPush ? truncateMemoryText(document.description.trim() || document.excerpt, 240) : "";
|
|
990
|
+
return {
|
|
991
|
+
id: document.id,
|
|
992
|
+
title: document.title,
|
|
993
|
+
...summary === "" ? {} : { summary }
|
|
994
|
+
};
|
|
995
|
+
})
|
|
963
996
|
} } : {}
|
|
964
997
|
},
|
|
965
998
|
revision: current.revision,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { DocumentMutation, DocumentMutationResult, DocumentSearchResult, DocumentSnapshot, DocumentView } from '../contracts.ts';
|
|
2
|
-
/** Source-owned structural page API; the default bundle may supply agent-assisted callbacks. */
|
|
3
2
|
export interface DocumentsPageClient {
|
|
4
3
|
documents(): Promise<DocumentSnapshot>;
|
|
5
4
|
document(id: string): Promise<DocumentView>;
|
package/lib/types/contracts.d.ts
CHANGED
|
@@ -20,7 +20,6 @@ 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
23
|
fileRevision?: string;
|
|
25
24
|
}
|
|
26
25
|
export interface DocumentSnapshot {
|
|
@@ -90,39 +89,20 @@ export interface DocumentCapacityPlan {
|
|
|
90
89
|
}
|
|
91
90
|
export declare const DOCUMENTS_VERSION = 1;
|
|
92
91
|
export declare const DOCUMENTS_ACTIVE_LIMIT_BYTES: number;
|
|
93
|
-
/** The Documents Source's directory under a storage root; each document sits in `<status>/<filename>` below it. */
|
|
94
92
|
export declare const DOCUMENTS_DIRECTORY = "documents";
|
|
95
|
-
/** The metadata of every document, the source of truth for which files belong to the Source. */
|
|
96
93
|
export declare const DOCUMENTS_INDEX_FILE = "index.json";
|
|
97
|
-
/** Created exclusively while the index or a document is read or written; whoever copies them takes it too. */
|
|
98
94
|
export declare const DOCUMENTS_LOCK_FILE = ".index.lock";
|
|
99
|
-
/** A lock file older than this was left by a process that stopped, and may be taken over. */
|
|
100
95
|
export declare const DOCUMENTS_LOCK_STALE_MS = 30000;
|
|
101
|
-
/** The file name a document may have: one path segment, so it never leaves its status directory. */
|
|
102
96
|
export declare const DOCUMENT_FILENAME_PATTERN: RegExp;
|
|
103
97
|
export interface DocumentIndex {
|
|
104
98
|
version: typeof DOCUMENTS_VERSION;
|
|
105
99
|
documents: DocumentRecord[];
|
|
106
100
|
}
|
|
107
|
-
/**
|
|
108
|
-
* Read an index as a copy of it carries it, such as a Mnemon Pack or a sync branch: every record
|
|
109
|
-
* complete, each id unique and each file name safe, or the whole index is refused. A record's path
|
|
110
|
-
* is where its status puts it, whatever the copy says. Unknown fields are dropped, and so are
|
|
111
|
-
* list items that are not strings. Reading the index does not judge a record's content hash: a
|
|
112
|
-
* store that needs repair still has to be copied as one.
|
|
113
|
-
*/
|
|
114
101
|
export declare function parseDocumentIndex(value: unknown): DocumentIndex;
|
|
115
|
-
/** What a stored index.json holds, counted without judging each record. */
|
|
116
102
|
export interface DocumentIndexSummary {
|
|
117
|
-
/** Whether the index has a record list at all. Without one, every count is 0. */
|
|
118
103
|
valid: boolean;
|
|
119
|
-
/** Every record that is an object, whatever its status. */
|
|
120
104
|
documents: number;
|
|
121
105
|
active: number;
|
|
122
106
|
archived: number;
|
|
123
107
|
}
|
|
124
|
-
/**
|
|
125
|
-
* Count the records of a parsed index.json for a read-only inventory. It never throws: an index
|
|
126
|
-
* without a record list is not `valid`, and a malformed record is counted or skipped, never refused.
|
|
127
|
-
*/
|
|
128
108
|
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.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "Self-contained documents Source for Composable View Memory.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"@types/node": "^22.0.0",
|
|
61
61
|
"@types/react": "^18.3.0",
|
|
62
62
|
"@types/react-dom": "^18.3.0",
|
|
63
|
-
"dsh-mnemon": "^0.5.
|
|
63
|
+
"dsh-mnemon": "^0.5.52",
|
|
64
64
|
"jsdom": "^26.0.0",
|
|
65
65
|
"react": "^18.2.0",
|
|
66
66
|
"react-dom": "^18.2.0",
|