@monoes/monomindcli 2.14.1 → 2.15.1
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/.claude/helpers/control-start.cjs +10 -13
- package/.claude/skills/monodesign/scripts/context.mjs +4 -4
- package/.claude/skills/monodesign/scripts/critique-storage.mjs +1 -1
- package/.claude/skills/monodesign/scripts/detect-csp.mjs +1 -6
- package/.claude/skills/monodesign/scripts/detector/browser/injected/index.mjs +16 -18
- package/.claude/skills/monodesign/scripts/detector/cli/main.mjs +3 -3
- package/.claude/skills/monodesign/scripts/detector/detect-antipatterns-browser.js +67 -47
- package/.claude/skills/monodesign/scripts/detector/engines/regex/detect-text.mjs +6 -6
- package/.claude/skills/monodesign/scripts/detector/engines/static-html/css-cascade.mjs +6 -5
- package/.claude/skills/monodesign/scripts/detector/engines/static-html/detect-html.mjs +6 -6
- package/.claude/skills/monodesign/scripts/detector/fix/index.mjs +3 -3
- package/.claude/skills/monodesign/scripts/detector/node/file-system.mjs +1 -1
- package/.claude/skills/monodesign/scripts/detector/registry/antipatterns.mjs +1 -1
- package/.claude/skills/monodesign/scripts/detector/rules/checks.mjs +24 -25
- package/.claude/skills/monodesign/scripts/detector/shared/color.mjs +2 -2
- package/.claude/skills/monodesign/scripts/detector/shared/constants.mjs +1 -1
- package/.claude/skills/monodesign/scripts/detector/shared/inline-ignores.mjs +2 -2
- package/.claude/skills/monodesign/scripts/hook-admin.mjs +6 -6
- package/.claude/skills/monodesign/scripts/hook-before-edit.mjs +4 -4
- package/.claude/skills/monodesign/scripts/hook-lib.mjs +20 -11
- package/.claude/skills/monodesign/scripts/hook.mjs +1 -1
- package/.claude/skills/monodesign/scripts/lib/design-parser.mjs +9 -42
- package/.claude/skills/monodesign/scripts/lib/is-generated.mjs +1 -1
- package/.claude/skills/monodesign/scripts/lib/monodesign-config.mjs +5 -5
- package/.claude/skills/monodesign/scripts/lib/monodesign-paths.mjs +1 -1
- package/.claude/skills/monodesign/scripts/live/event-validation.mjs +13 -13
- package/.claude/skills/monodesign/scripts/live/manual-apply.mjs +4 -4
- package/.claude/skills/monodesign/scripts/live/manual-edits-buffer.mjs +1 -1
- package/.claude/skills/monodesign/scripts/live/session-store.mjs +5 -5
- package/.claude/skills/monodesign/scripts/live/svelte-component.mjs +13 -13
- package/.claude/skills/monodesign/scripts/live/sveltekit-adapter.mjs +4 -4
- package/.claude/skills/monodesign/scripts/live/ui-core.mjs +1 -1
- package/.claude/skills/monodesign/scripts/live-accept.mjs +24 -24
- package/.claude/skills/monodesign/scripts/live-browser-dom.js +8 -7
- package/.claude/skills/monodesign/scripts/live-browser-session.js +8 -7
- package/.claude/skills/monodesign/scripts/live-browser.js +405 -432
- package/.claude/skills/monodesign/scripts/live-commit-manual-edits.mjs +6 -6
- package/.claude/skills/monodesign/scripts/live-copy-edit-agent.mjs +2 -2
- package/.claude/skills/monodesign/scripts/live-discard-manual-edits.mjs +1 -1
- package/.claude/skills/monodesign/scripts/live-inject.mjs +7 -7
- package/.claude/skills/monodesign/scripts/live-insert.mjs +11 -11
- package/.claude/skills/monodesign/scripts/live-manual-edit-evidence.mjs +4 -4
- package/.claude/skills/monodesign/scripts/live-poll.mjs +5 -5
- package/.claude/skills/monodesign/scripts/live-server.mjs +10 -10
- package/.claude/skills/monodesign/scripts/live-wrap.mjs +31 -41
- package/.claude/skills/monodesign/scripts/live.mjs +5 -5
- package/.claude/skills/monodesign/scripts/palette.mjs +3 -1
- package/.claude/skills/monodesign/scripts/pin.mjs +1 -1
- package/dist/src/commands/doc-filters.d.ts.map +1 -1
- package/dist/src/commands/doc-filters.js +6 -0
- package/dist/src/commands/doc-filters.js.map +1 -1
- package/dist/src/commands/doc-library.d.ts +2 -1
- package/dist/src/commands/doc-library.d.ts.map +1 -1
- package/dist/src/commands/doc-library.js +66 -2
- package/dist/src/commands/doc-library.js.map +1 -1
- package/dist/src/commands/doc.d.ts.map +1 -1
- package/dist/src/commands/doc.js +2 -0
- package/dist/src/commands/doc.js.map +1 -1
- package/dist/src/commands/org.d.ts.map +1 -1
- package/dist/src/commands/org.js +42 -4
- package/dist/src/commands/org.js.map +1 -1
- package/dist/src/commands/ui.d.ts.map +1 -1
- package/dist/src/commands/ui.js +60 -0
- package/dist/src/commands/ui.js.map +1 -1
- package/dist/src/knowledge/capture-envelope.d.ts +5 -0
- package/dist/src/knowledge/capture-envelope.d.ts.map +1 -1
- package/dist/src/knowledge/capture-envelope.js +2 -0
- package/dist/src/knowledge/capture-envelope.js.map +1 -1
- package/dist/src/knowledge/document-chunking.d.ts +42 -0
- package/dist/src/knowledge/document-chunking.d.ts.map +1 -0
- package/dist/src/knowledge/document-chunking.js +288 -0
- package/dist/src/knowledge/document-chunking.js.map +1 -0
- package/dist/src/knowledge/document-index.d.ts +124 -0
- package/dist/src/knowledge/document-index.d.ts.map +1 -0
- package/dist/src/knowledge/document-index.js +314 -0
- package/dist/src/knowledge/document-index.js.map +1 -0
- package/dist/src/knowledge/document-ingest.d.ts +23 -0
- package/dist/src/knowledge/document-ingest.d.ts.map +1 -0
- package/dist/src/knowledge/document-ingest.js +368 -0
- package/dist/src/knowledge/document-ingest.js.map +1 -0
- package/dist/src/knowledge/document-pipeline.d.ts +26 -208
- package/dist/src/knowledge/document-pipeline.d.ts.map +1 -1
- package/dist/src/knowledge/document-pipeline.js +25 -1104
- package/dist/src/knowledge/document-pipeline.js.map +1 -1
- package/dist/src/knowledge/document-search.d.ts +27 -0
- package/dist/src/knowledge/document-search.d.ts.map +1 -0
- package/dist/src/knowledge/document-search.js +138 -0
- package/dist/src/knowledge/document-search.js.map +1 -0
- package/dist/src/knowledge/document-store.d.ts +28 -0
- package/dist/src/knowledge/document-store.d.ts.map +1 -0
- package/dist/src/knowledge/document-store.js +61 -0
- package/dist/src/knowledge/document-store.js.map +1 -0
- package/dist/src/knowledge/document-types.d.ts +103 -0
- package/dist/src/knowledge/document-types.d.ts.map +1 -0
- package/dist/src/knowledge/document-types.js +12 -0
- package/dist/src/knowledge/document-types.js.map +1 -0
- package/dist/src/knowledge/highlights.d.ts +168 -0
- package/dist/src/knowledge/highlights.d.ts.map +1 -0
- package/dist/src/knowledge/highlights.js +311 -0
- package/dist/src/knowledge/highlights.js.map +1 -0
- package/dist/src/knowledge/lookup.d.ts +80 -0
- package/dist/src/knowledge/lookup.d.ts.map +1 -0
- package/dist/src/knowledge/lookup.js +156 -0
- package/dist/src/knowledge/lookup.js.map +1 -0
- package/dist/src/knowledge/okf-bundle.d.ts +19 -0
- package/dist/src/knowledge/okf-bundle.d.ts.map +1 -0
- package/dist/src/knowledge/okf-bundle.js +106 -0
- package/dist/src/knowledge/okf-bundle.js.map +1 -0
- package/dist/src/knowledge/profile-store.d.ts +134 -0
- package/dist/src/knowledge/profile-store.d.ts.map +1 -0
- package/dist/src/knowledge/profile-store.js +237 -0
- package/dist/src/knowledge/profile-store.js.map +1 -0
- package/dist/src/orgrt/agent-runner.d.ts +4 -0
- package/dist/src/orgrt/agent-runner.d.ts.map +1 -1
- package/dist/src/orgrt/agent-runner.js +22 -0
- package/dist/src/orgrt/agent-runner.js.map +1 -1
- package/dist/src/orgrt/antigravity-runner.d.ts.map +1 -1
- package/dist/src/orgrt/antigravity-runner.js +2 -1
- package/dist/src/orgrt/antigravity-runner.js.map +1 -1
- package/dist/src/orgrt/authority-mask.d.ts +32 -0
- package/dist/src/orgrt/authority-mask.d.ts.map +1 -0
- package/dist/src/orgrt/authority-mask.js +135 -0
- package/dist/src/orgrt/authority-mask.js.map +1 -0
- package/dist/src/orgrt/codex-runner.d.ts.map +1 -1
- package/dist/src/orgrt/codex-runner.js +2 -1
- package/dist/src/orgrt/codex-runner.js.map +1 -1
- package/dist/src/orgrt/copilot-runner.d.ts.map +1 -1
- package/dist/src/orgrt/copilot-runner.js +2 -1
- package/dist/src/orgrt/copilot-runner.js.map +1 -1
- package/dist/src/orgrt/crush-runner.d.ts.map +1 -1
- package/dist/src/orgrt/crush-runner.js +6 -1
- package/dist/src/orgrt/crush-runner.js.map +1 -1
- package/dist/src/orgrt/daemon.d.ts +4 -0
- package/dist/src/orgrt/daemon.d.ts.map +1 -1
- package/dist/src/orgrt/daemon.js +13 -2
- package/dist/src/orgrt/daemon.js.map +1 -1
- package/dist/src/orgrt/decisions.d.ts +9 -0
- package/dist/src/orgrt/decisions.d.ts.map +1 -1
- package/dist/src/orgrt/decisions.js +32 -5
- package/dist/src/orgrt/decisions.js.map +1 -1
- package/dist/src/orgrt/file-roots.d.ts +2 -1
- package/dist/src/orgrt/file-roots.d.ts.map +1 -1
- package/dist/src/orgrt/file-roots.js +7 -3
- package/dist/src/orgrt/file-roots.js.map +1 -1
- package/dist/src/orgrt/grok-runner.d.ts.map +1 -1
- package/dist/src/orgrt/grok-runner.js +2 -1
- package/dist/src/orgrt/grok-runner.js.map +1 -1
- package/dist/src/orgrt/hermes-runner.d.ts.map +1 -1
- package/dist/src/orgrt/hermes-runner.js +2 -1
- package/dist/src/orgrt/hermes-runner.js.map +1 -1
- package/dist/src/orgrt/inbox.d.ts.map +1 -1
- package/dist/src/orgrt/inbox.js +70 -4
- package/dist/src/orgrt/inbox.js.map +1 -1
- package/dist/src/orgrt/kimicode-runner.d.ts.map +1 -1
- package/dist/src/orgrt/kimicode-runner.js +2 -1
- package/dist/src/orgrt/kimicode-runner.js.map +1 -1
- package/dist/src/orgrt/opencode-runner.d.ts.map +1 -1
- package/dist/src/orgrt/opencode-runner.js +3 -2
- package/dist/src/orgrt/opencode-runner.js.map +1 -1
- package/dist/src/orgrt/pi-rpc-runner.d.ts.map +1 -1
- package/dist/src/orgrt/pi-rpc-runner.js +3 -2
- package/dist/src/orgrt/pi-rpc-runner.js.map +1 -1
- package/dist/src/orgrt/pi-runner.d.ts.map +1 -1
- package/dist/src/orgrt/pi-runner.js +2 -1
- package/dist/src/orgrt/pi-runner.js.map +1 -1
- package/dist/src/orgrt/policy.d.ts.map +1 -1
- package/dist/src/orgrt/policy.js +3 -0
- package/dist/src/orgrt/policy.js.map +1 -1
- package/dist/src/orgrt/qwen-rpc-runner.d.ts.map +1 -1
- package/dist/src/orgrt/qwen-rpc-runner.js +3 -2
- package/dist/src/orgrt/qwen-rpc-runner.js.map +1 -1
- package/dist/src/orgrt/qwen-runner.d.ts.map +1 -1
- package/dist/src/orgrt/qwen-runner.js +2 -1
- package/dist/src/orgrt/qwen-runner.js.map +1 -1
- package/dist/src/orgrt/role-sandbox.d.ts +21 -0
- package/dist/src/orgrt/role-sandbox.d.ts.map +1 -1
- package/dist/src/orgrt/role-sandbox.js +31 -6
- package/dist/src/orgrt/role-sandbox.js.map +1 -1
- package/dist/src/orgrt/session.d.ts.map +1 -1
- package/dist/src/orgrt/session.js +21 -2
- package/dist/src/orgrt/session.js.map +1 -1
- package/dist/src/orgrt/task-dag.d.ts +3 -0
- package/dist/src/orgrt/task-dag.d.ts.map +1 -1
- package/dist/src/orgrt/task-dag.js +1 -0
- package/dist/src/orgrt/task-dag.js.map +1 -1
- package/dist/src/orgrt/types.d.ts +5 -0
- package/dist/src/orgrt/types.d.ts.map +1 -1
- package/dist/src/orgrt/types.js +23 -1
- package/dist/src/orgrt/types.js.map +1 -1
- package/dist/src/ui/dashboard.html +28 -848
- package/dist/src/ui/human-auth.mjs +103 -0
- package/dist/src/ui/org-hil.mjs +86 -37
- package/dist/src/ui/org-runtime.mjs +21 -13
- package/dist/src/ui/routes-org.mjs +49 -445
- package/dist/src/ui/server.mjs +103 -4
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +6 -6
|
@@ -0,0 +1,368 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Document ingest — the write side of the pipeline: a file on disk (or a
|
|
3
|
+
* capture envelope) becomes an indexed, versioned, searchable document.
|
|
4
|
+
*
|
|
5
|
+
* One pass per document: guard the input, resolve the capture envelope's
|
|
6
|
+
* identity, extract and hash the text, chunk and enrich it, store every chunk,
|
|
7
|
+
* and only then commit the version record. An incomplete store commits
|
|
8
|
+
* nothing, which is what makes a re-ingest repair it.
|
|
9
|
+
*
|
|
10
|
+
* Split out of document-pipeline.ts.
|
|
11
|
+
*
|
|
12
|
+
* @module v1/cli/knowledge/document-ingest
|
|
13
|
+
*/
|
|
14
|
+
import * as fs from 'node:fs';
|
|
15
|
+
import * as path from 'node:path';
|
|
16
|
+
import { DOC_EXTENSIONS, extractText } from '../capabilities/cap-documents.js';
|
|
17
|
+
// Static import is safe and deliberate: memory-bridge imports only node builtins
|
|
18
|
+
// at module scope (everything heavy is lazy), and the project-root rule must not
|
|
19
|
+
// be duplicated — two copies of "which directory is this project" is exactly the
|
|
20
|
+
// bug this default exists to fix.
|
|
21
|
+
import { getProjectRoot } from '../memory/memory-bridge.js';
|
|
22
|
+
import { captureIdentityUrl, ENVELOPE_DOCUMENTS, ENVELOPE_READABLE_FILE, envelopePrimaryDocument, readCaptureProvenance, } from './capture-envelope.js';
|
|
23
|
+
import { spanTag } from './citation.js';
|
|
24
|
+
import { chunkDocument, enrichChunks } from './document-chunking.js';
|
|
25
|
+
import { appendMetadata, isResourceFork, readMetadata, removeMetadataEntry, } from './document-index.js';
|
|
26
|
+
import { contentHash, effectiveRoot, getBridge, namespace, storeDbPath } from './document-store.js';
|
|
27
|
+
import { captureScope } from './profile-store.js';
|
|
28
|
+
const IGNORE_DIRS = new Set([
|
|
29
|
+
'node_modules',
|
|
30
|
+
'.git',
|
|
31
|
+
'dist',
|
|
32
|
+
'.monomind',
|
|
33
|
+
'.claude',
|
|
34
|
+
'.next',
|
|
35
|
+
'__pycache__',
|
|
36
|
+
'.venv',
|
|
37
|
+
'vendor',
|
|
38
|
+
]);
|
|
39
|
+
const MAX_FILE_SIZE = 50 * 1024 * 1024; // 50MB
|
|
40
|
+
/** @internal — shared with okf-bundle, which extracts text the same way. */
|
|
41
|
+
export function toFileEntry(filePath) {
|
|
42
|
+
const stat = fs.statSync(filePath);
|
|
43
|
+
return {
|
|
44
|
+
path: filePath,
|
|
45
|
+
absolutePath: path.resolve(filePath),
|
|
46
|
+
extension: path.extname(filePath).toLowerCase(),
|
|
47
|
+
size: stat.size,
|
|
48
|
+
modified: stat.mtime,
|
|
49
|
+
created: stat.birthtime,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export async function ingestDocument(filePath, scope = 'shared', rootDir = getProjectRoot(), _metadataCache) {
|
|
53
|
+
const resolved = path.resolve(filePath);
|
|
54
|
+
const ext = path.extname(resolved).toLowerCase();
|
|
55
|
+
// AppleDouble resource forks (`._name.md`) are binary macOS sidecars, not
|
|
56
|
+
// documents. The directory walk has skipped dotfiles since 3e429194
|
|
57
|
+
// (2026-07-19), but that walk is only ONE of six callers that reach this
|
|
58
|
+
// function — the CLI `doc ingest`, the MCP `knowledge_ingest` tool, the
|
|
59
|
+
// dashboard's live fs.watch and its polling sweep, the eval harness, and
|
|
60
|
+
// `ingestDirectory` all land here, and four of them had no guard at all.
|
|
61
|
+
//
|
|
62
|
+
// Guarding at the boundary covers every caller at once, including callers
|
|
63
|
+
// added later. Guarding at each call site covers only the ones we thought to
|
|
64
|
+
// enumerate — which is how two `._` files reached the live index despite a
|
|
65
|
+
// working guard in the walk.
|
|
66
|
+
//
|
|
67
|
+
// Measured on this repo 2026-07-28: 96 `._` entries in the live index, 91 of
|
|
68
|
+
// them shadowing a real document of the same name and competing with it for
|
|
69
|
+
// top-k slots. That is a direct Recall@5/MRR@10 loss, not wasted storage.
|
|
70
|
+
if (isResourceFork(resolved)) {
|
|
71
|
+
return {
|
|
72
|
+
filePath: resolved,
|
|
73
|
+
chunksIndexed: 0,
|
|
74
|
+
scope,
|
|
75
|
+
skipped: true,
|
|
76
|
+
error: 'AppleDouble resource fork',
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
if (!DOC_EXTENSIONS.has(ext)) {
|
|
80
|
+
return {
|
|
81
|
+
filePath: resolved,
|
|
82
|
+
chunksIndexed: 0,
|
|
83
|
+
scope,
|
|
84
|
+
skipped: true,
|
|
85
|
+
error: `unsupported extension: ${ext}`,
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
if (!fs.existsSync(resolved)) {
|
|
89
|
+
return { filePath: resolved, chunksIndexed: 0, scope, skipped: true, error: 'file not found' };
|
|
90
|
+
}
|
|
91
|
+
const stat = fs.statSync(resolved);
|
|
92
|
+
if (stat.size > MAX_FILE_SIZE) {
|
|
93
|
+
return {
|
|
94
|
+
filePath: resolved,
|
|
95
|
+
chunksIndexed: 0,
|
|
96
|
+
scope,
|
|
97
|
+
skipped: true,
|
|
98
|
+
error: 'file too large (>50MB)',
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
// RCL-01/RCL-06: one capture envelope is ONE document, whichever of its
|
|
102
|
+
// members the caller points at. `page.html`/`page.mhtml` need no guard —
|
|
103
|
+
// extraction already redirects them to `readable.md`, so they hash
|
|
104
|
+
// identically and fall out as "unchanged" below. `page.pdf` does not: its
|
|
105
|
+
// text differs from the readable pass, so ingesting it alongside would
|
|
106
|
+
// version-flip the same page back and forth on every sweep.
|
|
107
|
+
const envelopePrimary = envelopePrimaryDocument(path.dirname(resolved));
|
|
108
|
+
if (envelopePrimary && envelopePrimary !== resolved) {
|
|
109
|
+
const isMember = ENVELOPE_DOCUMENTS.includes(path.basename(resolved));
|
|
110
|
+
const redirectsToPrimary = path.basename(envelopePrimary) === ENVELOPE_READABLE_FILE &&
|
|
111
|
+
(ext === '.html' || ext === '.htm' || ext === '.xhtml' || ext === '.mhtml' || ext === '.mht');
|
|
112
|
+
if (isMember && !redirectsToPrimary) {
|
|
113
|
+
return {
|
|
114
|
+
filePath: resolved,
|
|
115
|
+
chunksIndexed: 0,
|
|
116
|
+
scope,
|
|
117
|
+
skipped: true,
|
|
118
|
+
error: `capture envelope: ${path.basename(envelopePrimary)} is this capture's document`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
// A capture that names a profile belongs to that profile's store, whoever
|
|
123
|
+
// is ingesting it and whatever scope they reached for — see
|
|
124
|
+
// knowledge/profile-store.ts. A no-op for everything else.
|
|
125
|
+
scope = captureScope(scope, resolved);
|
|
126
|
+
rootDir = effectiveRoot(scope, rootDir);
|
|
127
|
+
const meta = _metadataCache ?? readMetadata(rootDir);
|
|
128
|
+
// RCL-07: provenance is read before extraction so it is recorded even when a
|
|
129
|
+
// later step degrades. Absent, truncated or wrong-typed `meta.json` yields
|
|
130
|
+
// null and never throws — see capture-envelope.
|
|
131
|
+
const provenance = readCaptureProvenance(resolved);
|
|
132
|
+
const canonicalUrl = captureIdentityUrl(provenance);
|
|
133
|
+
// RCL-06: identity is the PAGE, not the path. A re-capture lands in a new
|
|
134
|
+
// timestamped directory, so matching on filePath alone would file every
|
|
135
|
+
// capture of one article as a separate document.
|
|
136
|
+
const existing = meta.find((m) => m.filePath === resolved && m.scope === scope) ??
|
|
137
|
+
(canonicalUrl
|
|
138
|
+
? meta.find((m) => m.scope === scope && m.canonicalUrl === canonicalUrl)
|
|
139
|
+
: undefined);
|
|
140
|
+
let fullContent;
|
|
141
|
+
try {
|
|
142
|
+
const entry = toFileEntry(resolved);
|
|
143
|
+
fullContent = await extractText(entry);
|
|
144
|
+
}
|
|
145
|
+
catch (err) {
|
|
146
|
+
return { filePath: resolved, chunksIndexed: 0, scope, skipped: false, error: String(err) };
|
|
147
|
+
}
|
|
148
|
+
if (!fullContent || fullContent.trim().length === 0) {
|
|
149
|
+
return {
|
|
150
|
+
filePath: resolved,
|
|
151
|
+
chunksIndexed: 0,
|
|
152
|
+
scope,
|
|
153
|
+
skipped: true,
|
|
154
|
+
error: 'no text extracted',
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
const hash = contentHash(fullContent);
|
|
158
|
+
// RCL-06: same page, same extracted text — a no-op, not a duplicate row and
|
|
159
|
+
// not an error. `unchanged` is what a caller reports to the user.
|
|
160
|
+
if (existing && existing.contentHash === hash) {
|
|
161
|
+
return {
|
|
162
|
+
filePath: resolved,
|
|
163
|
+
chunksIndexed: existing.chunkCount,
|
|
164
|
+
scope,
|
|
165
|
+
skipped: true,
|
|
166
|
+
unchanged: true,
|
|
167
|
+
...(existing.version ? { version: existing.version } : {}),
|
|
168
|
+
...(provenance ? { provenance } : {}),
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
const version = (existing?.version ?? (existing ? 1 : 0)) + 1;
|
|
172
|
+
const supersedes = existing?.contentHash || undefined;
|
|
173
|
+
// NOTE: the previous version's metadata record is deliberately NOT tombstoned
|
|
174
|
+
// here. `readMetadata` is last-wins per (filePath, scope), so appending the
|
|
175
|
+
// new record below already supersedes the old one — the tombstone was a no-op
|
|
176
|
+
// on the success path and destructive on the failure path: it retired a
|
|
177
|
+
// perfectly good previous index before knowing whether the replacement would
|
|
178
|
+
// land, so a failed re-ingest left the document with NO live version at all.
|
|
179
|
+
const docId = `${scope}:${resolved}`;
|
|
180
|
+
const rawChunks = await chunkDocument(docId, fullContent);
|
|
181
|
+
// monolean: [re-enabled] item 2 shipped 768d gte-modernbert-base — capacity handles enrichment
|
|
182
|
+
const chunks = enrichChunks(rawChunks, fullContent, resolved);
|
|
183
|
+
const bridge = await getBridge();
|
|
184
|
+
let indexed = 0;
|
|
185
|
+
let highlights;
|
|
186
|
+
for (const chunk of chunks) {
|
|
187
|
+
const key = `doc:${hash}:${chunk.chunkIndex}`;
|
|
188
|
+
if (bridge) {
|
|
189
|
+
try {
|
|
190
|
+
const storeResult = await bridge.bridgeStoreEntry({
|
|
191
|
+
key,
|
|
192
|
+
value: chunk.text,
|
|
193
|
+
namespace: namespace(scope),
|
|
194
|
+
generateEmbeddingFlag: true,
|
|
195
|
+
tags: [
|
|
196
|
+
'document',
|
|
197
|
+
ext,
|
|
198
|
+
`src:${resolved}`,
|
|
199
|
+
// RCL-10: the chunk's span against the extracted text, so a search
|
|
200
|
+
// hit can cite a passage without re-reading the document.
|
|
201
|
+
spanTag(chunk.startChar, chunk.endChar),
|
|
202
|
+
...(canonicalUrl ? [`url:${canonicalUrl}`] : []),
|
|
203
|
+
],
|
|
204
|
+
upsert: true,
|
|
205
|
+
dbPath: storeDbPath(scope),
|
|
206
|
+
});
|
|
207
|
+
if (storeResult?.success)
|
|
208
|
+
indexed++;
|
|
209
|
+
}
|
|
210
|
+
catch (e) {
|
|
211
|
+
if (process.env.DEBUG || process.env.MONOMIND_DEBUG)
|
|
212
|
+
console.error(`[ingestDocument] failed to store chunk ${chunk.chunkIndex} of ${resolved}:`, e);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
// Commit the document version ONLY when EVERY chunk stored. Recording the
|
|
217
|
+
// content hash after a partial store was the worse half of this bug: the
|
|
218
|
+
// hash check above then skipped the file on every future ingest, so the
|
|
219
|
+
// chunks that failed were never retried — a permanently, silently
|
|
220
|
+
// half-indexed document feeding knowledge retrieval with no signal at all.
|
|
221
|
+
// (Total failure was already handled; partial success was not.)
|
|
222
|
+
//
|
|
223
|
+
// Not committing is what makes a retry work: chunk keys are
|
|
224
|
+
// `doc:<contentHash>:<index>` and stores are upserts, so re-ingesting the
|
|
225
|
+
// same bytes rewrites the same keys and fills the gaps. Until it succeeds the
|
|
226
|
+
// partially-written chunks sit under a hash that is not live, and superseded
|
|
227
|
+
// filtering keeps them out of search (see `liveContentHashes`).
|
|
228
|
+
const complete = indexed === chunks.length;
|
|
229
|
+
if (complete) {
|
|
230
|
+
appendMetadata(rootDir, {
|
|
231
|
+
filePath: resolved,
|
|
232
|
+
contentHash: hash,
|
|
233
|
+
chunkCount: indexed,
|
|
234
|
+
indexedAt: new Date().toISOString(),
|
|
235
|
+
scope,
|
|
236
|
+
size: stat.size,
|
|
237
|
+
version,
|
|
238
|
+
...(supersedes ? { supersedes } : {}),
|
|
239
|
+
...(canonicalUrl ? { canonicalUrl } : {}),
|
|
240
|
+
...(provenance ? { provenance } : {}),
|
|
241
|
+
});
|
|
242
|
+
// A re-capture of the same page arrives at a NEW path, so the previous
|
|
243
|
+
// version's record is a different (filePath, scope) key and survives
|
|
244
|
+
// last-wins — leaving its contentHash live and its chunks answering
|
|
245
|
+
// searches forever. Tombstone it so it leaves the live-hash set, which is
|
|
246
|
+
// exactly how a same-path re-ingest already retires its predecessor.
|
|
247
|
+
//
|
|
248
|
+
// AFTER the append, never before: retiring the old version before the
|
|
249
|
+
// replacement is known to have landed is the failure mode the partial-store
|
|
250
|
+
// fix above exists to prevent.
|
|
251
|
+
if (existing && existing.filePath !== resolved) {
|
|
252
|
+
removeMetadataEntry(rootDir, existing.filePath, scope);
|
|
253
|
+
}
|
|
254
|
+
// RCL-04: the reader's own highlights, stored as notes linked to this
|
|
255
|
+
// document — see knowledge/highlights.ts. AFTER the version is committed,
|
|
256
|
+
// because a note pointing at an uncommitted version would be a citation
|
|
257
|
+
// into something search cannot return.
|
|
258
|
+
//
|
|
259
|
+
// Wrapped, and never fatal: a malformed highlight, a failed note store,
|
|
260
|
+
// anything at all here must not cost someone their capture. The page is
|
|
261
|
+
// already committed above; the annotations are a bonus that reports its
|
|
262
|
+
// own shortfall through `IngestResult.highlights`.
|
|
263
|
+
try {
|
|
264
|
+
const { ingestHighlights, readHighlightsFor } = await import('./highlights.js');
|
|
265
|
+
const found = readHighlightsFor(resolved);
|
|
266
|
+
if (found.length) {
|
|
267
|
+
const result = await ingestHighlights({
|
|
268
|
+
filePath: resolved,
|
|
269
|
+
scope,
|
|
270
|
+
contentHash: hash,
|
|
271
|
+
text: fullContent,
|
|
272
|
+
...(canonicalUrl ? { canonicalUrl } : {}),
|
|
273
|
+
...(provenance ? { provenance } : {}),
|
|
274
|
+
}, { highlights: found, ...(storeDbPath(scope) ? { dbPath: storeDbPath(scope) } : {}) });
|
|
275
|
+
highlights = {
|
|
276
|
+
found: result.found,
|
|
277
|
+
stored: result.stored,
|
|
278
|
+
anchored: result.anchored,
|
|
279
|
+
...(result.error ? { error: result.error } : {}),
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
catch (e) {
|
|
284
|
+
if (process.env.DEBUG || process.env.MONOMIND_DEBUG)
|
|
285
|
+
console.error(`[ingestDocument] highlights for ${resolved}:`, e);
|
|
286
|
+
highlights = { found: 0, stored: 0, anchored: 0, error: String(e) };
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
return {
|
|
290
|
+
filePath: resolved,
|
|
291
|
+
chunksIndexed: indexed,
|
|
292
|
+
scope,
|
|
293
|
+
skipped: false,
|
|
294
|
+
...(complete ? { version, ...(supersedes ? { supersedes } : {}) } : {}),
|
|
295
|
+
...(provenance ? { provenance } : {}),
|
|
296
|
+
...(highlights ? { highlights } : {}),
|
|
297
|
+
...(complete
|
|
298
|
+
? {}
|
|
299
|
+
: indexed > 0
|
|
300
|
+
? {
|
|
301
|
+
partial: true,
|
|
302
|
+
error: `partial store: ${indexed}/${chunks.length} chunks — version not committed, re-ingest to repair`,
|
|
303
|
+
}
|
|
304
|
+
: {
|
|
305
|
+
error: bridge
|
|
306
|
+
? 'all chunk stores failed'
|
|
307
|
+
: 'memory bridge unavailable — nothing indexed',
|
|
308
|
+
}),
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
export async function ingestDirectory(dirPath, scope = 'shared', opts) {
|
|
312
|
+
const scanDir = path.resolve(dirPath);
|
|
313
|
+
const rootDir = path.resolve(opts?.rootDir ?? getProjectRoot());
|
|
314
|
+
const files = [];
|
|
315
|
+
function walk(dir, depth = 0) {
|
|
316
|
+
if (depth > 10)
|
|
317
|
+
return;
|
|
318
|
+
let entries;
|
|
319
|
+
try {
|
|
320
|
+
entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
321
|
+
}
|
|
322
|
+
catch {
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
for (const entry of entries) {
|
|
326
|
+
// Skip dotfiles/dot-dirs (incl. exFAT `._*` junk) — except `.monodesign`,
|
|
327
|
+
// whose critique snapshots are markdown worth surfacing in the Second Brain.
|
|
328
|
+
if (entry.name.startsWith('.') && entry.name !== '.monodesign')
|
|
329
|
+
continue;
|
|
330
|
+
const full = path.join(dir, entry.name);
|
|
331
|
+
if (entry.isDirectory()) {
|
|
332
|
+
if (!IGNORE_DIRS.has(entry.name))
|
|
333
|
+
walk(full, depth + 1);
|
|
334
|
+
}
|
|
335
|
+
else if (entry.isFile()) {
|
|
336
|
+
const ext = path.extname(entry.name).toLowerCase();
|
|
337
|
+
if (DOC_EXTENSIONS.has(ext))
|
|
338
|
+
files.push(full);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
walk(scanDir);
|
|
343
|
+
const metadataCache = readMetadata(rootDir);
|
|
344
|
+
const result = {
|
|
345
|
+
filesProcessed: 0,
|
|
346
|
+
filesSkipped: 0,
|
|
347
|
+
totalChunks: 0,
|
|
348
|
+
errors: [],
|
|
349
|
+
results: [],
|
|
350
|
+
};
|
|
351
|
+
for (let i = 0; i < files.length; i++) {
|
|
352
|
+
opts?.onProgress?.(files[i], i, files.length);
|
|
353
|
+
const r = await ingestDocument(files[i], scope, rootDir, metadataCache);
|
|
354
|
+
result.results.push(r);
|
|
355
|
+
if (r.skipped) {
|
|
356
|
+
result.filesSkipped++;
|
|
357
|
+
}
|
|
358
|
+
else {
|
|
359
|
+
result.filesProcessed++;
|
|
360
|
+
result.totalChunks += r.chunksIndexed;
|
|
361
|
+
}
|
|
362
|
+
if (r.error && !r.skipped) {
|
|
363
|
+
result.errors.push(`${r.filePath}: ${r.error}`);
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
return result;
|
|
367
|
+
}
|
|
368
|
+
//# sourceMappingURL=document-ingest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-ingest.js","sourceRoot":"","sources":["../../../src/knowledge/document-ingest.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AAE/E,iFAAiF;AACj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,OAAO,EAAE,CAAC;YACd,MAAM,CAAC,YAAY,EAAE,CAAC;QACxB,CAAC;aAAM,CAAC;YACN,MAAM,CAAC,cAAc,EAAE,CAAC;YACxB,MAAM,CAAC,WAAW,IAAI,CAAC,CAAC,aAAa,CAAC;QACxC,CAAC;QAED,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC;YAC1B,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;QAClD,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -1,213 +1,31 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Document Pipeline —
|
|
3
|
-
*
|
|
2
|
+
* Document Pipeline — the Second Brain's end-to-end ingest/search/export path,
|
|
3
|
+
* and the single import point for it.
|
|
4
|
+
*
|
|
5
|
+
* The implementation lives in focused modules; this file is the public surface
|
|
6
|
+
* every caller (CLI commands, MCP tools, the dashboard, the eval harness)
|
|
7
|
+
* imports from, so the map is here:
|
|
8
|
+
*
|
|
9
|
+
* - `document-types.ts` the shapes: IngestResult, KnowledgeExcerpt,
|
|
10
|
+
* DocumentMeta, ReconcileReport.
|
|
11
|
+
* - `document-store.ts` which store a scope writes to, and the lazy memory
|
|
12
|
+
* bridge that reaches it.
|
|
13
|
+
* - `document-chunking.ts` text → heading-anchored, context-enriched chunks
|
|
14
|
+
* (and the spans that make one citable).
|
|
15
|
+
* - `document-index.ts` the append-only metadata log: versions,
|
|
16
|
+
* tombstones, lookups, superseded filtering,
|
|
17
|
+
* filesystem reconciliation.
|
|
18
|
+
* - `document-ingest.ts` file → extracted → chunked → stored → committed.
|
|
19
|
+
* - `document-search.ts` query → live chunks, decorated for citation.
|
|
20
|
+
* - `okf-bundle.ts` export to / import from a portable OKF bundle.
|
|
4
21
|
*
|
|
5
22
|
* @module v1/cli/knowledge/document-pipeline
|
|
6
23
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
error?: string;
|
|
15
|
-
/** True when SOME but not all chunks stored. The new version was NOT
|
|
16
|
-
* committed: the document keeps whatever version it had before (possibly
|
|
17
|
-
* none), and re-ingesting repairs it. Absent means the ingest was complete —
|
|
18
|
-
* a caller must not read `chunksIndexed > 0` alone as success. */
|
|
19
|
-
partial?: boolean;
|
|
20
|
-
/** RCL-06: the document was already indexed at this exact extracted-text
|
|
21
|
-
* hash, so nothing was written. Reported as "unchanged" rather than as a
|
|
22
|
-
* skip with an error, because nothing went wrong. */
|
|
23
|
-
unchanged?: boolean;
|
|
24
|
-
/** RCL-06: 1 for a first ingest, incremented for each stored revision. */
|
|
25
|
-
version?: number;
|
|
26
|
-
/** RCL-06: contentHash of the version this one replaced, when there was one. */
|
|
27
|
-
supersedes?: string;
|
|
28
|
-
/** RCL-07: provenance read from the capture envelope's `meta.json`. */
|
|
29
|
-
provenance?: CaptureProvenance;
|
|
30
|
-
}
|
|
31
|
-
export interface BatchIngestResult {
|
|
32
|
-
filesProcessed: number;
|
|
33
|
-
filesSkipped: number;
|
|
34
|
-
totalChunks: number;
|
|
35
|
-
errors: string[];
|
|
36
|
-
results: IngestResult[];
|
|
37
|
-
}
|
|
38
|
-
export interface KnowledgeExcerpt {
|
|
39
|
-
/** Memory entry id — pass back to memory_feedback/bridgeApplyFeedback to rate usefulness. */
|
|
40
|
-
id: string;
|
|
41
|
-
filePath: string;
|
|
42
|
-
text: string;
|
|
43
|
-
similarity: number;
|
|
44
|
-
chunkIndex: number;
|
|
45
|
-
scope: string;
|
|
46
|
-
/** True when this chunk belongs to a document version that has since been
|
|
47
|
-
* re-ingested (its contentHash is no longer the file's current one). Only
|
|
48
|
-
* ever set when the caller opted into `includeSuperseded`. */
|
|
49
|
-
superseded?: boolean;
|
|
50
|
-
/** RCL-07: capture provenance, when the document came from a capture
|
|
51
|
-
* envelope — this is what lets a result cite the page it came from
|
|
52
|
-
* instead of a path under `~/.monomind/inbox`. */
|
|
53
|
-
provenance?: CaptureProvenance;
|
|
54
|
-
/** RCL-10: the chunk's character span against the extracted text. Absent
|
|
55
|
-
* for chunks stored before span tags existed — re-ingest to get them. */
|
|
56
|
-
startChar?: number;
|
|
57
|
-
endChar?: number;
|
|
58
|
-
/** RCL-10: `<hash12>#<start>-<end>`, resolvable with `monomind doc cite`. */
|
|
59
|
-
anchor?: string;
|
|
60
|
-
}
|
|
61
|
-
export interface DocumentMeta {
|
|
62
|
-
filePath: string;
|
|
63
|
-
contentHash: string;
|
|
64
|
-
chunkCount: number;
|
|
65
|
-
indexedAt: string;
|
|
66
|
-
scope: string;
|
|
67
|
-
size: number;
|
|
68
|
-
/** RCL-06: identity URL for a captured page (`canonicalUrl`, else `url`,
|
|
69
|
-
* fragment stripped). Absent for ordinary files on disk. */
|
|
70
|
-
canonicalUrl?: string;
|
|
71
|
-
/** RCL-06: 1 for a first ingest, +1 per stored revision. */
|
|
72
|
-
version?: number;
|
|
73
|
-
/** RCL-06: contentHash of the version this record replaced. Walk it back
|
|
74
|
-
* through `listDocumentVersions` to reach the older ones. */
|
|
75
|
-
supersedes?: string;
|
|
76
|
-
/** RCL-07: the capture envelope's `meta.json`, normalized. */
|
|
77
|
-
provenance?: CaptureProvenance;
|
|
78
|
-
}
|
|
79
|
-
export declare function ingestDocument(filePath: string, scope?: string, rootDir?: string, _metadataCache?: DocumentMeta[]): Promise<IngestResult>;
|
|
80
|
-
export declare function ingestDirectory(dirPath: string, scope?: string, opts?: {
|
|
81
|
-
rootDir?: string;
|
|
82
|
-
onProgress?: (file: string, done: number, total: number) => void;
|
|
83
|
-
}): Promise<BatchIngestResult>;
|
|
84
|
-
/** Content hashes of the documents currently indexed under `rootDir`. */
|
|
85
|
-
export declare function liveContentHashes(rootDir: string): Set<string>;
|
|
86
|
-
/** True when a metadata log exists under `rootDir`.
|
|
87
|
-
*
|
|
88
|
-
* An empty live-hash set has two very different causes: the log is missing (we
|
|
89
|
-
* cannot judge what is current) or the log exists and every document has been
|
|
90
|
-
* removed (nothing is current). Collapsing them made `doc remove` of the LAST
|
|
91
|
-
* document a no-op — the tombstoned chunks came straight back in search.
|
|
92
|
-
*
|
|
93
|
-
* Reads the path directly instead of via `metadataPath`, which mkdir's. */
|
|
94
|
-
export declare function hasKnowledgeMetadata(rootDir: string): boolean;
|
|
95
|
-
/**
|
|
96
|
-
* True when `key` is a document chunk whose version is no longer current.
|
|
97
|
-
* Non-`doc:` keys are never superseded. When no metadata is available nothing
|
|
98
|
-
* is filtered, because "no metadata" must not read as "everything is stale".
|
|
99
|
-
*
|
|
100
|
-
* `metadataPresent` defaults to the old `live.size > 0` heuristic so existing
|
|
101
|
-
* two-argument callers keep their exact behaviour; pass `hasKnowledgeMetadata`
|
|
102
|
-
* to also filter correctly once the last document has been removed.
|
|
103
|
-
*/
|
|
104
|
-
export declare function isSupersededKey(key: string, live: Set<string>, metadataPresent?: boolean): boolean;
|
|
105
|
-
export declare function supersededOverfetchLimit(limit: number, live: Set<string>): number;
|
|
106
|
-
export declare function searchKnowledge(query: string, opts?: {
|
|
107
|
-
scope?: string;
|
|
108
|
-
limit?: number;
|
|
109
|
-
minScore?: number;
|
|
110
|
-
rootDir?: string;
|
|
111
|
-
/** which store(s): project-only, global-only, or both (default). */
|
|
112
|
-
store?: 'project' | 'global' | 'all';
|
|
113
|
-
/** Return chunks from superseded document versions too, flagged
|
|
114
|
-
* `superseded: true`. Default false — see the note above `liveContentHashes`. */
|
|
115
|
-
includeSuperseded?: boolean;
|
|
116
|
-
/** Skip cross-encoder reranking. Default false. */
|
|
117
|
-
skipRerank?: boolean;
|
|
118
|
-
}): Promise<KnowledgeExcerpt[]>;
|
|
119
|
-
export declare function listDocuments(rootDir?: string, scope?: string): DocumentMeta[];
|
|
120
|
-
/**
|
|
121
|
-
* Every recorded version of one document, oldest first (RCL-06).
|
|
122
|
-
*
|
|
123
|
-
* `target` is either an indexed file path or a capture's `canonicalUrl`. Read
|
|
124
|
-
* from the append-only log rather than the last-wins view, which is how a
|
|
125
|
-
* superseded version stays addressable after its record has been replaced or
|
|
126
|
-
* tombstoned.
|
|
127
|
-
*
|
|
128
|
-
* Best-effort by design: `readMetadata` compacts the log once it passes 1MB
|
|
129
|
-
* and keeps only live records, so history older than a compaction is gone.
|
|
130
|
-
* The `supersedes` pointer on each record is the durable part.
|
|
131
|
-
*/
|
|
132
|
-
export declare function listDocumentVersions(rootDir?: string, target?: string, scope?: string): DocumentMeta[];
|
|
133
|
-
/** The store root for a scope: the global brain for `global`, else the project. */
|
|
134
|
-
export declare function getKnowledgeRoot(scope?: string, rootDir?: string): string;
|
|
135
|
-
/** Chunk spans for a text, using the SAME chunker the ingest used — this is
|
|
136
|
-
* what makes a chunk index resolvable back to a character range without
|
|
137
|
-
* storing the text twice. */
|
|
138
|
-
export declare function chunkSpans(text: string): Promise<ChunkSpan[]>;
|
|
139
|
-
/**
|
|
140
|
-
* The indexed record for whatever a caller wrote down: a file path, a
|
|
141
|
-
* capture's `canonicalUrl` (fragment ignored), or the `<scope>:<path>` docId.
|
|
142
|
-
*
|
|
143
|
-
* Live records win. A superseded version is only reached through the
|
|
144
|
-
* append-only log, and only when nothing live matches — otherwise citing a
|
|
145
|
-
* re-captured page would resolve against the version it replaced.
|
|
146
|
-
*/
|
|
147
|
-
export declare function findDocumentRecord(rootDir?: string, target?: string, scope?: string): DocumentMeta | undefined;
|
|
148
|
-
export declare function removeDocument(filePath: string, scope?: string, rootDir?: string): Promise<void>;
|
|
149
|
-
/**
|
|
150
|
-
* True for macOS AppleDouble sidecars (`._name`).
|
|
151
|
-
*
|
|
152
|
-
* Matches on the BASENAME PREFIX only. A legitimate document may contain `._`
|
|
153
|
-
* elsewhere in its name (`v1._2-release.md`), or live under a dot-directory
|
|
154
|
-
* that is deliberately indexed (`.monodesign/` critique snapshots), and
|
|
155
|
-
* neither may be rejected.
|
|
156
|
-
*/
|
|
157
|
-
export declare function isResourceFork(filePath: string): boolean;
|
|
158
|
-
export interface ReconcileReport {
|
|
159
|
-
/** Indexed documents whose source file is no longer on disk. */
|
|
160
|
-
missing: DocumentMeta[];
|
|
161
|
-
/** Total index entries examined. */
|
|
162
|
-
scanned: number;
|
|
163
|
-
/** False for a dry run — the default. */
|
|
164
|
-
applied: boolean;
|
|
165
|
-
/** Entries actually tombstoned. Always 0 when `applied` is false. */
|
|
166
|
-
removed: number;
|
|
167
|
-
/** Where removed records were archived, when anything was removed. */
|
|
168
|
-
archivePath?: string;
|
|
169
|
-
}
|
|
170
|
-
/**
|
|
171
|
-
* Reconcile the document index against the filesystem: find index entries whose
|
|
172
|
-
* source file no longer exists and, only when explicitly asked, tombstone them.
|
|
173
|
-
*
|
|
174
|
-
* WHY — `removeDocument` only ever tombstoned metadata, and nothing has ever
|
|
175
|
-
* compared the index against the disk, so a deleted file stayed searchable
|
|
176
|
-
* forever. Measured 2026-07-28: 109 of 257 live entries (42.4%) had no file
|
|
177
|
-
* behind them, including `docs/concepts/memory.md`. The Second Brain was
|
|
178
|
-
* answering questions from documents the user had deleted.
|
|
179
|
-
*
|
|
180
|
-
* WHY IT IS THIS CAUTIOUS — "drop the index entry when the file is missing" is
|
|
181
|
-
* a rule with a known catastrophic reading. A missing file is also an unmounted
|
|
182
|
-
* volume, a checked-out branch, a partial clone, or a permissions failure. Two
|
|
183
|
-
* guards were tried against real data and REJECTED; they are recorded here so
|
|
184
|
-
* they are not re-proposed:
|
|
185
|
-
*
|
|
186
|
-
* - "abort if >50% of entries are missing" — the real, legitimate missing
|
|
187
|
-
* fraction was 42.4%, so the threshold never fires in the one case we have.
|
|
188
|
-
* Any threshold that would have blocked this reconcile is fitted to nothing.
|
|
189
|
-
* - "only reconcile when the parent directory still exists" — 26 of the 109
|
|
190
|
-
* missing files had no parent directory, because `docs/concepts`,
|
|
191
|
-
* `docs/adrs` and `docs/commands` were legitimately deleted wholesale. A
|
|
192
|
-
* deleted directory and an unmounted volume are indistinguishable there.
|
|
193
|
-
*
|
|
194
|
-
* What does discriminate is the ROOT. An intact, readable root carrying a
|
|
195
|
-
* metadata log means the tree is genuinely present, so a missing file is
|
|
196
|
-
* genuinely gone. A missing root means nothing beneath it is knowable and
|
|
197
|
-
* nothing may be removed — hence throw rather than reconcile.
|
|
198
|
-
*
|
|
199
|
-
* Removal tombstones metadata; it does not delete store rows. Chunks stay on
|
|
200
|
-
* disk and fall out of search through the existing superseded filter, which
|
|
201
|
-
* keeps this consistent with the mark-don't-destroy rule and leaves the whole
|
|
202
|
-
* operation reversible from the archive.
|
|
203
|
-
*/
|
|
204
|
-
export declare function reconcileIndex(rootDir?: string, opts?: {
|
|
205
|
-
scope?: string;
|
|
206
|
-
apply?: boolean;
|
|
207
|
-
}): Promise<ReconcileReport>;
|
|
208
|
-
export declare function exportToOKF(outputDir: string, rootDir?: string, scope?: string): Promise<{
|
|
209
|
-
exported: number;
|
|
210
|
-
outputDir: string;
|
|
211
|
-
}>;
|
|
212
|
-
export declare function importFromOKF(bundleDir: string, scope?: string, rootDir?: string): Promise<BatchIngestResult>;
|
|
24
|
+
export { chunkSpans } from './document-chunking.js';
|
|
25
|
+
export { findDocumentRecord, hasKnowledgeMetadata, isResourceFork, isSupersededKey, listDocuments, listDocumentVersions, liveContentHashes, reconcileIndex, removeDocument, supersededOverfetchLimit, } from './document-index.js';
|
|
26
|
+
export { ingestDirectory, ingestDocument } from './document-ingest.js';
|
|
27
|
+
export { searchKnowledge } from './document-search.js';
|
|
28
|
+
export { getKnowledgeRoot } from './document-store.js';
|
|
29
|
+
export type { BatchIngestResult, DocumentMeta, IngestResult, KnowledgeExcerpt, ReconcileReport, } from './document-types.js';
|
|
30
|
+
export { exportToOKF, importFromOKF } from './okf-bundle.js';
|
|
213
31
|
//# sourceMappingURL=document-pipeline.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"document-pipeline.d.ts","sourceRoot":"","sources":["../../../src/knowledge/document-pipeline.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"document-pipeline.d.ts","sourceRoot":"","sources":["../../../src/knowledge/document-pipeline.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,kBAAkB,EAClB,oBAAoB,EACpB,cAAc,EACd,eAAe,EACf,aAAa,EACb,oBAAoB,EACpB,iBAAiB,EACjB,cAAc,EACd,cAAc,EACd,wBAAwB,GACzB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,eAAe,GAChB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|