@avantf/dsh-mem 0.6.4 → 0.8.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 +19 -10
- package/lib/client.js +1665 -3466
- package/lib/dsh-build.json +6 -5
- package/lib/engine/graph-recall/in-memory.d.ts +93 -0
- package/lib/engine/graph-recall/index.d.ts +22 -0
- package/lib/engine/graph-recall/traverse.d.ts +119 -0
- package/lib/engine/graph-recall/types.d.ts +188 -0
- package/lib/engine/mem/config/config_files.d.ts +1 -1
- package/lib/engine/mem/config/loader.d.ts +2 -3
- package/lib/engine/mem/config/paths.d.ts +2 -13
- package/lib/engine/mem/db/dao/contradictions.d.ts +4 -22
- package/lib/engine/mem/db/dao/entities.d.ts +80 -7
- package/lib/engine/mem/db/dao/fact_sources.d.ts +3 -13
- package/lib/engine/mem/db/dao/facts.d.ts +311 -56
- package/lib/engine/mem/db/dao/triples.d.ts +1 -26
- package/lib/engine/mem/db/graph.d.ts +249 -0
- package/lib/engine/mem/db/journal_notes.d.ts +35 -0
- package/lib/engine/mem/db/migrations.d.ts +9 -0
- package/lib/engine/mem/db/port.d.ts +22 -3
- package/lib/engine/mem/db/schema.d.ts +119 -0
- package/lib/engine/mem/db/tokenizer.d.ts +9 -0
- package/lib/engine/mem/dbdrivers/fake/driver.d.ts +75 -0
- package/lib/engine/mem/dbdrivers/fake/index.d.ts +7 -0
- package/lib/engine/mem/dbdrivers/fake/surface.d.ts +34 -0
- package/lib/engine/mem/dbdrivers/fake/transport.d.ts +61 -0
- package/lib/engine/mem/dbdrivers/sqlite/connection.d.ts +14 -0
- package/lib/engine/mem/dbdrivers/sqlite/contradictions.d.ts +35 -0
- package/lib/engine/mem/dbdrivers/sqlite/dao/index.d.ts +16 -0
- package/lib/engine/mem/dbdrivers/sqlite/driver.d.ts +54 -0
- package/lib/engine/mem/dbdrivers/sqlite/facts.d.ts +117 -0
- package/lib/engine/mem/dbdrivers/sqlite/index.d.ts +6 -0
- package/lib/engine/mem/dbdrivers/sqlite/migrations.d.ts +15 -0
- package/lib/engine/mem/dbdrivers/sqlite/relations.d.ts +62 -0
- package/lib/engine/mem/dbdrivers/sqlite/search.d.ts +56 -0
- package/lib/engine/mem/dbdrivers/sqlite/sources.d.ts +37 -0
- package/lib/engine/mem/defaults.d.ts +3 -4
- package/lib/engine/mem/dispatch.d.ts +7 -32
- package/lib/engine/mem/entities/extract.d.ts +44 -47
- package/lib/engine/mem/eval/derived_runner.d.ts +6 -1
- package/lib/engine/mem/eval/relation_gold.d.ts +251 -0
- package/lib/engine/mem/eval/write_metrics.d.ts +1 -1
- package/lib/engine/mem/facts_io.d.ts +328 -0
- package/lib/engine/mem/index.d.ts +10 -2
- package/lib/engine/mem/interfaces/capabilities.d.ts +30 -0
- package/lib/engine/mem/interfaces/common.d.ts +11 -0
- package/lib/engine/mem/interfaces/errors.d.ts +65 -0
- package/lib/engine/mem/interfaces/index.d.ts +18 -0
- package/lib/engine/mem/interfaces/migrations.d.ts +21 -0
- package/lib/engine/mem/interfaces/repositories.d.ts +471 -0
- package/lib/engine/mem/interfaces/search_index.d.ts +113 -0
- package/lib/engine/mem/interfaces/storage_backend.d.ts +84 -0
- package/lib/engine/mem/interfaces/storage_driver.d.ts +43 -0
- package/lib/engine/mem/interfaces/version.d.ts +34 -0
- package/lib/engine/mem/lifecycle/contradiction.d.ts +2 -2
- package/lib/engine/mem/maintenance_paths.d.ts +41 -0
- package/lib/engine/mem/modelBootstrap.d.ts +1 -1
- package/lib/engine/mem/relations/confidence.d.ts +39 -0
- package/lib/engine/mem/relations/extract.d.ts +128 -0
- package/lib/engine/mem/relations/index.d.ts +32 -0
- package/lib/engine/mem/relations/name-quality.d.ts +78 -0
- package/lib/engine/mem/relations/normalize.d.ts +275 -0
- package/lib/engine/mem/relations/patterns.d.ts +67 -0
- package/lib/engine/mem/relations/statement.d.ts +88 -0
- package/lib/engine/mem/relations/types.d.ts +79 -0
- package/lib/engine/mem/runtime.d.ts +117 -90
- package/lib/engine/mem/storage/create.d.ts +42 -0
- package/lib/engine/mem/storage/errors.d.ts +65 -0
- package/lib/engine/mem/storage/index.d.ts +15 -0
- package/lib/engine/mem/storage/ports.d.ts +472 -0
- package/lib/engine/mem/storage/registry.d.ts +37 -0
- package/lib/engine/mem/storage/sqlite.d.ts +28 -0
- package/lib/engine/mem/store/common.d.ts +1 -1
- package/lib/engine/mem/store/entity_leg.d.ts +59 -2
- package/lib/engine/mem/store/entity_sweep.d.ts +4 -3
- package/lib/engine/mem/store/explicit_relations.d.ts +52 -0
- package/lib/engine/mem/store/facts_restore.d.ts +124 -0
- package/lib/engine/mem/store/floors.d.ts +4 -1
- package/lib/engine/mem/store/graph_reader.d.ts +146 -0
- package/lib/engine/mem/store/hybrid.d.ts +50 -13
- package/lib/engine/mem/store/kinds.d.ts +47 -0
- package/lib/engine/mem/store/legs.d.ts +24 -29
- package/lib/engine/mem/store/lexical.d.ts +36 -45
- package/lib/engine/mem/store/memory.d.ts +486 -82
- package/lib/engine/mem/store/recall_policy.d.ts +49 -0
- package/lib/engine/mem/store/relation_backfill.d.ts +210 -0
- package/lib/engine/mem/store/relation_planner.d.ts +191 -0
- package/lib/engine/mem/store/secret_guard.d.ts +0 -1
- package/lib/engine/mem/store/self_query.d.ts +4 -2
- package/lib/engine/mem/store/time_filter.d.ts +121 -0
- package/lib/engine/mem/store/titles.d.ts +52 -0
- package/lib/engine/mem/store/vector_repair.d.ts +44 -54
- package/lib/engine/mem-contract/config.d.ts +44 -38
- package/lib/engine/mem-contract/text.d.ts +1 -1
- package/lib/engine/mem-contract/tools.d.ts +184 -117
- package/lib/engine/mem-contract/types.d.ts +364 -288
- package/lib/index.js +13898 -11500
- package/lib/interface-version.json +1 -1
- package/lib/types/client/index.d.ts +2 -2
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/paging.d.ts +3 -12
- package/lib/types/client/paging.d.ts.map +1 -1
- package/lib/types/client/summarize.d.ts.map +1 -1
- package/lib/types/command.d.ts +61 -0
- package/lib/types/command.d.ts.map +1 -0
- package/lib/types/envinit-bootstrap.d.ts +1 -1
- package/lib/types/envinit.d.ts +2 -6
- package/lib/types/envinit.d.ts.map +1 -1
- package/lib/types/hints.d.ts +28 -24
- package/lib/types/hints.d.ts.map +1 -1
- package/lib/types/index.d.ts +21 -40
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/inject.d.ts +3 -2
- package/lib/types/inject.d.ts.map +1 -1
- package/lib/types/interface_gate.d.ts +9 -9
- package/lib/types/prompt.d.ts +17 -41
- package/lib/types/prompt.d.ts.map +1 -1
- package/lib/types/provision.d.ts +3 -0
- package/lib/types/provision.d.ts.map +1 -1
- package/lib/types/remote.d.ts +23 -9
- package/lib/types/remote.d.ts.map +1 -1
- package/lib/types/render.d.ts +3 -3
- package/lib/types/tool_schema.d.ts +4 -0
- package/lib/types/tool_schema.d.ts.map +1 -1
- package/lib/types/vectorMigration.d.ts +5 -7
- package/lib/types/vectorMigration.d.ts.map +1 -1
- package/package.json +16 -15
- package/lib/engine/mem/config/domains.d.ts +0 -20
- package/lib/engine/mem/db/dao/chunks.d.ts +0 -231
- package/lib/engine/mem/db/dao/documents.d.ts +0 -51
- package/lib/engine/mem/db/hash.d.ts +0 -2
- package/lib/engine/mem/db/knowledge.d.ts +0 -17
- package/lib/engine/mem/eval/index.d.ts +0 -4
- package/lib/engine/mem/git.d.ts +0 -73
- package/lib/engine/mem/router.d.ts +0 -51
- package/lib/engine/mem/store/doc_files.d.ts +0 -125
- package/lib/engine/mem/store/document_text.d.ts +0 -47
- package/lib/engine/mem/store/ingest_guard.d.ts +0 -25
- package/lib/engine/mem/store/knowledge.d.ts +0 -598
- package/lib/engine/mem/store/source_picker.d.ts +0 -43
- package/lib/engine/mem-retrieval/adapters/local_reranker.d.ts +0 -52
- package/lib/engine/mem-retrieval/adapters/none_reranker.d.ts +0 -10
- package/lib/engine/mem-retrieval/rerank.d.ts +0 -13
- package/lib/types/client/domains.d.ts +0 -53
- package/lib/types/client/domains.d.ts.map +0 -1
- package/lib/types/client/ingest.d.ts +0 -24
- package/lib/types/client/ingest.d.ts.map +0 -1
- package/lib/types/open.d.ts +0 -77
- package/lib/types/open.d.ts.map +0 -1
- package/lib/types/reconcile.d.ts +0 -64
- package/lib/types/reconcile.d.ts.map +0 -1
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
/** The frontmatter a managed file carries; `content_hash` is the body AS INGESTED. */
|
|
2
|
-
interface DocFileMeta {
|
|
3
|
-
doc_id: number;
|
|
4
|
-
domain: string;
|
|
5
|
-
source: string;
|
|
6
|
-
title: string;
|
|
7
|
-
source_uri: string | null;
|
|
8
|
-
ingested_at: string;
|
|
9
|
-
content_hash: string;
|
|
10
|
-
/**
|
|
11
|
-
* The `@avantf/mem-convert` converter that produced the body, when the source was converted
|
|
12
|
-
* (absent for text and PDF, and for every file written before this field existed — readers must
|
|
13
|
-
* treat it as optional, which is why it is not `null`).
|
|
14
|
-
*/
|
|
15
|
-
converter?: string;
|
|
16
|
-
}
|
|
17
|
-
/** One managed file as the file system sees it now. */
|
|
18
|
-
interface DocFileState {
|
|
19
|
-
path: string;
|
|
20
|
-
stale: boolean;
|
|
21
|
-
missing: boolean;
|
|
22
|
-
}
|
|
23
|
-
/** A parsed managed file: frontmatter (possibly partial — a hand-written file may omit it) + body. */
|
|
24
|
-
interface ParsedDocFile {
|
|
25
|
-
meta: Partial<DocFileMeta>;
|
|
26
|
-
body: string;
|
|
27
|
-
}
|
|
28
|
-
/** One path segment, made safe and human-readable; `fallback` covers names that sanitize away. */
|
|
29
|
-
export declare function sanitizeSegment(raw: string, fallback: string): string;
|
|
30
|
-
/**
|
|
31
|
-
* A stable title for a body that arrived as TEXT (a paste), where there is no file name to borrow.
|
|
32
|
-
*
|
|
33
|
-
* Pasted text has no `source_uri` to name it after, and `source` defaults to the same value for
|
|
34
|
-
* every paste — so without this, every untitled paste into one domain collapsed onto one identity
|
|
35
|
-
* and the second ingest silently replaced the first. The rule: the first Markdown ATX heading,
|
|
36
|
-
* else the first non-empty line with its block markers stripped.
|
|
37
|
-
*
|
|
38
|
-
* Fenced code is stepped over in BOTH halves: `#include` is not a heading, and a fence opener is
|
|
39
|
-
* not a title. `MAX_SEGMENT` is the same cap the file name uses, so a long line cannot produce a
|
|
40
|
-
* title the managed path has to truncate differently. Empty input falls back to `untitled`, and the
|
|
41
|
-
* result depends only on the text (same body → same title), which is what keeps a re-paste
|
|
42
|
-
* landing on the SAME identity instead of quietly creating a sibling every time.
|
|
43
|
-
*/
|
|
44
|
-
export declare function deriveDocTitle(text: string): string;
|
|
45
|
-
/** sha256 of a document body — the staleness key. */
|
|
46
|
-
export declare function bodyHash(body: string): string;
|
|
47
|
-
/**
|
|
48
|
-
* Render one managed file: frontmatter (JSON-encoded values, so any title/URI survives) + body.
|
|
49
|
-
*
|
|
50
|
-
* The body is written VERBATIM — no trailing newline is added. `content_hash` records the ingested
|
|
51
|
-
* text, and `state` compares it against the file's body, so anything this function normalizes
|
|
52
|
-
* would make every document read as edited the moment it was written.
|
|
53
|
-
*
|
|
54
|
-
* An `undefined` value is OMITTED rather than rendered: JSON.stringify(undefined) is the bare token
|
|
55
|
-
* `undefined`, which the tolerant parser would then hand back as the string "undefined". Optional
|
|
56
|
-
* keys (today: `converter`) therefore simply do not appear for the documents that lack them.
|
|
57
|
-
*/
|
|
58
|
-
export declare function renderDocFile(meta: DocFileMeta, body: string): string;
|
|
59
|
-
/**
|
|
60
|
-
* Split one managed file into frontmatter and body.
|
|
61
|
-
*
|
|
62
|
-
* Deliberately tolerant: a file without frontmatter (or with a hand-mangled one) is ALL body —
|
|
63
|
-
* the user's content is never thrown away because a header key is missing, and the caller decides
|
|
64
|
-
* what an unknown `doc_id` means.
|
|
65
|
-
*/
|
|
66
|
-
export declare function parseDocFile(text: string): ParsedDocFile;
|
|
67
|
-
/**
|
|
68
|
-
* The managed document directory.
|
|
69
|
-
*
|
|
70
|
-
* Paths are `<root>/<domain>/<source>/<title>.md`, sanitized per segment. Collisions resolve by
|
|
71
|
-
* asking the EXISTING file who it belongs to: a file whose frontmatter names another `doc_id` is
|
|
72
|
-
* left alone and this document takes the `<title>~<doc_id>.md` variant. Without that check two
|
|
73
|
-
* documents that sanitize to the same name would take turns clobbering each other.
|
|
74
|
-
*/
|
|
75
|
-
export declare class DocFiles {
|
|
76
|
-
private readonly root;
|
|
77
|
-
constructor(root: string);
|
|
78
|
-
/** The directory holding one document's file (created on write, not here). */
|
|
79
|
-
dirFor(domain: string, source: string): string;
|
|
80
|
-
/**
|
|
81
|
-
* The file NAME for a title, minus the directory: a title that is already a Markdown file name
|
|
82
|
-
* (`kb ingest --uri notes.md` names the document after the file) must not become `notes.md.md`.
|
|
83
|
-
*/
|
|
84
|
-
fileName(title: string, suffix?: string): string;
|
|
85
|
-
/** The base path for a title (before collision handling). */
|
|
86
|
-
basePath(domain: string, source: string, title: string): string;
|
|
87
|
-
/**
|
|
88
|
-
* The file this document owns: the base path, or its `~<doc_id>` variant when the base path is
|
|
89
|
-
* taken by a DIFFERENT document. Purely derived — no state is written to answer this.
|
|
90
|
-
*/
|
|
91
|
-
pathFor(docId: number, domain: string, source: string, title: string): string;
|
|
92
|
-
/** Write the managed file for one document (atomic: temp file + rename). Returns its path. */
|
|
93
|
-
write(meta: DocFileMeta, body: string): string;
|
|
94
|
-
/** Parse one managed file, or `null` when it does not exist. */
|
|
95
|
-
read(path: string): ParsedDocFile | null;
|
|
96
|
-
/**
|
|
97
|
-
* A cheap per-file stamp — `mtimeMs:size`, no reads — or `null` when the file is absent.
|
|
98
|
-
*
|
|
99
|
-
* This is a TRIGGER, never a judgement: same-second edits, coarse filesystem timestamps and
|
|
100
|
-
* `cp -p` can all leave it unchanged, so a matching stamp means "probably unchanged" and only
|
|
101
|
-
* `state()` (which hashes the body) decides. The point is that the common case costs one `stat`
|
|
102
|
-
* per file instead of reading and hashing every file in the corpus.
|
|
103
|
-
*/
|
|
104
|
-
stamp(path: string): string | null;
|
|
105
|
-
/** Every `.md` path under the root. A directory walk WITHOUT reads — no frontmatter, no hashing. */
|
|
106
|
-
listPaths(): string[];
|
|
107
|
-
/** Is this document's file there, and does it still match what was ingested? */
|
|
108
|
-
state(docId: number, domain: string, source: string, title: string): DocFileState;
|
|
109
|
-
/** Delete this document's file. `false` when there was nothing to delete. */
|
|
110
|
-
remove(docId: number, domain: string, source: string, title: string): boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Every `.md` under the root, with the `doc_id` its frontmatter names (when it names one).
|
|
113
|
-
* Used to report orphans — files left behind by a document that no longer exists.
|
|
114
|
-
*
|
|
115
|
-
* ASYNC and batched: the walk itself is an async recursive `readdir` (a `readdirSync` gathers
|
|
116
|
-
* every entry in one ~41 ms call at 10k files), and the per-file parse is a `read` — at 10k
|
|
117
|
-
* documents that is a second full read of the corpus on top of `sync`'s staleness pass, and it
|
|
118
|
-
* used to be one uninterrupted synchronous block (performance review §7.5 / P6).
|
|
119
|
-
*/
|
|
120
|
-
scan(): Promise<{
|
|
121
|
-
path: string;
|
|
122
|
-
doc_id?: number;
|
|
123
|
-
}[]>;
|
|
124
|
-
}
|
|
125
|
-
export {};
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
/** What the first bytes say a document is. */
|
|
2
|
-
type DocumentFormat = 'pdf' | 'binary' | 'text';
|
|
3
|
-
/** How text bytes were decoded. Reported so a guess is visible instead of silent. */
|
|
4
|
-
type DocumentEncoding = 'utf-8' | 'utf-8-bom' | 'utf-16le' | 'utf-16be' | 'gb18030';
|
|
5
|
-
/** One document's indexable text, and where it came from. */
|
|
6
|
-
export interface DocumentText {
|
|
7
|
-
text: string;
|
|
8
|
-
/**
|
|
9
|
-
* `pdf` = extracted text layer; `converter` = a document format turned into Markdown (see
|
|
10
|
-
* {@link DocumentText.converter}); `text` = decoded bytes (see {@link DocumentText.encoding}).
|
|
11
|
-
*/
|
|
12
|
-
via: 'text' | 'pdf' | 'converter';
|
|
13
|
-
encoding?: DocumentEncoding;
|
|
14
|
-
/** Which `@avantf/mem-convert` converter produced the body (only when `via === 'converter'`). */
|
|
15
|
-
converter?: string;
|
|
16
|
-
/** What that conversion could not carry over (dropped media, a truncated sheet, …). */
|
|
17
|
-
warnings?: string[];
|
|
18
|
-
}
|
|
19
|
-
/** Classify one document by its leading bytes. */
|
|
20
|
-
export declare function sniffFormat(bytes: Uint8Array): {
|
|
21
|
-
format: DocumentFormat;
|
|
22
|
-
kind?: string;
|
|
23
|
-
};
|
|
24
|
-
/**
|
|
25
|
-
* Restore the ideographs pdfjs sometimes reports as compatibility codepoints.
|
|
26
|
-
*
|
|
27
|
-
* Some CJK PDFs extract `⽹站` (KANGXI RADICAL NET + 站) instead of `网站` — visually identical,
|
|
28
|
-
* different codepoints, so a search for the real word misses. Only those three compatibility ranges
|
|
29
|
-
* are normalized: NFKC over the whole text would also rewrite full-width punctuation (,。!?),
|
|
30
|
-
* which is real content and must survive verbatim.
|
|
31
|
-
*/
|
|
32
|
-
export declare function normalizeCjkCompatibility(text: string): string;
|
|
33
|
-
/**
|
|
34
|
-
* The text of one document, whatever its bytes are.
|
|
35
|
-
*
|
|
36
|
-
* CONVERSION RUNS FIRST, before the magic-number sniff and therefore before the binary rejection.
|
|
37
|
-
* docx/xlsx/html/csv are converted to Markdown here, and the order is not cosmetic: docx and xlsx
|
|
38
|
-
* are ZIPs, so a sniff-first pipeline would file them under "known binary" and refuse them. A
|
|
39
|
-
* document no converter claims falls through to the text/PDF/binary paths unchanged.
|
|
40
|
-
*
|
|
41
|
-
* @param bytes - the whole document (already bounded by the byte cap).
|
|
42
|
-
* @param label - the path or URL, used verbatim in error messages and as the sniff's extension hint.
|
|
43
|
-
* @throws when the document is a binary we cannot read, is not decodable, or is a PDF without a
|
|
44
|
-
* text layer.
|
|
45
|
-
*/
|
|
46
|
-
export declare function documentText(bytes: Uint8Array, label: string): Promise<DocumentText>;
|
|
47
|
-
export {};
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
/** The boundary knobs, as resolved from `knowledge.ingest`. */
|
|
2
|
-
export interface IngestLimits {
|
|
3
|
-
/** Roots a local `source_uri` may be read from; empty ⇒ the process workspace. */
|
|
4
|
-
local_roots: readonly string[];
|
|
5
|
-
allow_outside_workspace: boolean;
|
|
6
|
-
allow_private_network: boolean;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Whether a URL hostname addresses loopback / private / link-local / other
|
|
10
|
-
* non-public space. Names are matched by suffix too (`*.local` mDNS, `*.internal`,
|
|
11
|
-
* `*.home.arpa`), since those resolve inside the LAN by construction.
|
|
12
|
-
*/
|
|
13
|
-
export declare function isPrivateHostname(hostname: string): boolean;
|
|
14
|
-
/** Validate one `http(s)` source URL, refusing non-public targets unless opted in. */
|
|
15
|
-
export declare function assertFetchableUrl(uri: string, limits: Pick<IngestLimits, 'allow_private_network'>): URL;
|
|
16
|
-
/** The roots a local `source_uri` may be read from (realpath'd), defaulting to the workspace. */
|
|
17
|
-
export declare function allowedLocalRoots(limits: Pick<IngestLimits, 'local_roots'>): string[];
|
|
18
|
-
/**
|
|
19
|
-
* Resolve a local `source_uri` to the real absolute path it names, refusing one
|
|
20
|
-
* that lands outside the allowed roots.
|
|
21
|
-
*
|
|
22
|
-
* @returns the `realpath` — which is what the caller should BOTH read and store, so
|
|
23
|
-
* the recorded `source_uri` is exactly the file that was read.
|
|
24
|
-
*/
|
|
25
|
-
export declare function resolveLocalSource(raw: string, limits: IngestLimits): string;
|