@monoes/monomindcli 2.14.0 → 2.15.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/.claude/helpers/control-start.cjs +10 -13
- package/.claude/skills/monodesign/scripts/context.mjs +5 -5
- 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 +69 -49
- 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 +26 -27
- 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 +406 -433
- 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/bin/cli.js +21 -1
- package/bin/mcp-server.js +21 -1
- package/dist/src/capabilities/cap-documents.d.ts.map +1 -1
- package/dist/src/capabilities/cap-documents.js +23 -0
- package/dist/src/capabilities/cap-documents.js.map +1 -1
- package/dist/src/commands/doc-filters.d.ts +19 -0
- package/dist/src/commands/doc-filters.d.ts.map +1 -0
- package/dist/src/commands/doc-filters.js +64 -0
- package/dist/src/commands/doc-filters.js.map +1 -0
- package/dist/src/commands/doc-library.d.ts +22 -0
- package/dist/src/commands/doc-library.d.ts.map +1 -0
- package/dist/src/commands/doc-library.js +454 -0
- package/dist/src/commands/doc-library.js.map +1 -0
- package/dist/src/commands/doc-list.d.ts +9 -0
- package/dist/src/commands/doc-list.d.ts.map +1 -0
- package/dist/src/commands/doc-list.js +99 -0
- package/dist/src/commands/doc-list.js.map +1 -0
- package/dist/src/commands/doc.d.ts.map +1 -1
- package/dist/src/commands/doc.js +51 -37
- package/dist/src/commands/doc.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 +85 -0
- package/dist/src/knowledge/capture-envelope.d.ts.map +1 -0
- package/dist/src/knowledge/capture-envelope.js +167 -0
- package/dist/src/knowledge/capture-envelope.js.map +1 -0
- package/dist/src/knowledge/capture-text.d.ts +23 -0
- package/dist/src/knowledge/capture-text.d.ts.map +1 -0
- package/dist/src/knowledge/capture-text.js +49 -0
- package/dist/src/knowledge/capture-text.js.map +1 -0
- package/dist/src/knowledge/citation.d.ts +121 -0
- package/dist/src/knowledge/citation.d.ts.map +1 -0
- package/dist/src/knowledge/citation.js +252 -0
- package/dist/src/knowledge/citation.js.map +1 -0
- 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 -148
- package/dist/src/knowledge/document-pipeline.d.ts.map +1 -1
- package/dist/src/knowledge/document-pipeline.js +25 -920
- 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/html-extract.d.ts +43 -0
- package/dist/src/knowledge/html-extract.d.ts.map +1 -0
- package/dist/src/knowledge/html-extract.js +286 -0
- package/dist/src/knowledge/html-extract.js.map +1 -0
- package/dist/src/knowledge/html-tags.d.ts +30 -0
- package/dist/src/knowledge/html-tags.d.ts.map +1 -0
- package/dist/src/knowledge/html-tags.js +229 -0
- package/dist/src/knowledge/html-tags.js.map +1 -0
- package/dist/src/knowledge/library.d.ts +106 -0
- package/dist/src/knowledge/library.d.ts.map +1 -0
- package/dist/src/knowledge/library.js +195 -0
- package/dist/src/knowledge/library.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/mhtml.d.ts +60 -0
- package/dist/src/knowledge/mhtml.d.ts.map +1 -0
- package/dist/src/knowledge/mhtml.js +154 -0
- package/dist/src/knowledge/mhtml.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/knowledge/related.d.ts +58 -0
- package/dist/src/knowledge/related.d.ts.map +1 -0
- package/dist/src/knowledge/related.js +222 -0
- package/dist/src/knowledge/related.js.map +1 -0
- package/dist/src/knowledge/section-diff.d.ts +48 -0
- package/dist/src/knowledge/section-diff.d.ts.map +1 -0
- package/dist/src/knowledge/section-diff.js +151 -0
- package/dist/src/knowledge/section-diff.js.map +1 -0
- package/dist/src/knowledge/watch.d.ts +92 -0
- package/dist/src/knowledge/watch.d.ts.map +1 -0
- package/dist/src/knowledge/watch.js +221 -0
- package/dist/src/knowledge/watch.js.map +1 -0
- package/dist/src/mcp-server.d.ts.map +1 -1
- package/dist/src/mcp-server.js +44 -87
- package/dist/src/mcp-server.js.map +1 -1
- package/dist/src/mcp-tools/browser-instrument-tools.d.ts +35 -0
- package/dist/src/mcp-tools/browser-instrument-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/browser-instrument-tools.js +359 -0
- package/dist/src/mcp-tools/browser-instrument-tools.js.map +1 -0
- package/dist/src/mcp-tools/browser-metrics.d.ts +42 -0
- package/dist/src/mcp-tools/browser-metrics.d.ts.map +1 -0
- package/dist/src/mcp-tools/browser-metrics.js +91 -0
- package/dist/src/mcp-tools/browser-metrics.js.map +1 -0
- package/dist/src/mcp-tools/browser-profile-tools.d.ts +16 -0
- package/dist/src/mcp-tools/browser-profile-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/browser-profile-tools.js +324 -0
- package/dist/src/mcp-tools/browser-profile-tools.js.map +1 -0
- package/dist/src/mcp-tools/browser-session.d.ts +68 -0
- package/dist/src/mcp-tools/browser-session.d.ts.map +1 -0
- package/dist/src/mcp-tools/browser-session.js +224 -0
- package/dist/src/mcp-tools/browser-session.js.map +1 -0
- package/dist/src/mcp-tools/browser-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/browser-tools.js +10 -176
- package/dist/src/mcp-tools/browser-tools.js.map +1 -1
- package/dist/src/mcp-tools/capture-resource-read.d.ts +115 -0
- package/dist/src/mcp-tools/capture-resource-read.d.ts.map +1 -0
- package/dist/src/mcp-tools/capture-resource-read.js +296 -0
- package/dist/src/mcp-tools/capture-resource-read.js.map +1 -0
- package/dist/src/mcp-tools/capture-resource-tools.d.ts +22 -0
- package/dist/src/mcp-tools/capture-resource-tools.d.ts.map +1 -0
- package/dist/src/mcp-tools/capture-resource-tools.js +182 -0
- package/dist/src/mcp-tools/capture-resource-tools.js.map +1 -0
- package/dist/src/mcp-tools/capture-resources.d.ts +142 -0
- package/dist/src/mcp-tools/capture-resources.d.ts.map +1 -0
- package/dist/src/mcp-tools/capture-resources.js +289 -0
- package/dist/src/mcp-tools/capture-resources.js.map +1 -0
- package/dist/src/mcp-tools/index.d.ts +3 -0
- package/dist/src/mcp-tools/index.d.ts.map +1 -1
- package/dist/src/mcp-tools/index.js +6 -0
- package/dist/src/mcp-tools/index.js.map +1 -1
- package/dist/src/mcp-tools/knowledge-tools.d.ts.map +1 -1
- package/dist/src/mcp-tools/knowledge-tools.js +9 -1
- package/dist/src/mcp-tools/knowledge-tools.js.map +1 -1
- package/dist/src/mcp-tools/resource-router.d.ts +86 -0
- package/dist/src/mcp-tools/resource-router.d.ts.map +1 -0
- package/dist/src/mcp-tools/resource-router.js +181 -0
- package/dist/src/mcp-tools/resource-router.js.map +1 -0
- package/dist/src/memory/memory-bridge.js +1 -1
- package/dist/src/memory/memory-bridge.js.map +1 -1
- 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-ledger.d.ts +7 -0
- package/dist/src/orgrt/session-ledger.d.ts.map +1 -1
- package/dist/src/orgrt/session-ledger.js +15 -0
- package/dist/src/orgrt/session-ledger.js.map +1 -1
- package/dist/src/orgrt/session.d.ts.map +1 -1
- package/dist/src/orgrt/session.js +42 -10
- 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 +90 -2
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -9
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MHTML / MHT container parsing (RCL-01).
|
|
3
|
+
*
|
|
4
|
+
* An MHTML archive is an RFC 2557 `multipart/related` MIME message: the page
|
|
5
|
+
* plus every subresource it referenced, each part carrying its own transfer
|
|
6
|
+
* encoding and charset. Chrome's `Page.captureSnapshot` writes them
|
|
7
|
+
* quoted-printable; Internet Explorer and most "save as web archive" tools
|
|
8
|
+
* write base64.
|
|
9
|
+
*
|
|
10
|
+
* Only the ROOT frame is prose. Picking the first `text/html` part instead is
|
|
11
|
+
* how an ad iframe ends up indexed as the article, so the root is resolved
|
|
12
|
+
* from the container's `Snapshot-Content-Location` / `Content-Location` when
|
|
13
|
+
* one is present.
|
|
14
|
+
*
|
|
15
|
+
* Read the file as `latin1` (or pass a Buffer): byte fidelity matters before
|
|
16
|
+
* transfer decoding, and the real charset is only known per part.
|
|
17
|
+
*
|
|
18
|
+
* @module v1/cli/knowledge/mhtml
|
|
19
|
+
*/
|
|
20
|
+
/** Decode a quoted-printable body to bytes: soft line breaks vanish, `=XX`
|
|
21
|
+
* becomes one byte, everything else is its own latin1 byte. */
|
|
22
|
+
export function decodeQuotedPrintable(input) {
|
|
23
|
+
const out = [];
|
|
24
|
+
for (let i = 0; i < input.length; i++) {
|
|
25
|
+
const ch = input[i];
|
|
26
|
+
if (ch !== '=') {
|
|
27
|
+
out.push(input.charCodeAt(i) & 0xff);
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
if (input[i + 1] === '\r' && input[i + 2] === '\n') {
|
|
31
|
+
i += 2; // soft line break
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (input[i + 1] === '\n') {
|
|
35
|
+
i += 1; // soft line break, LF-only file
|
|
36
|
+
continue;
|
|
37
|
+
}
|
|
38
|
+
const hex = input.slice(i + 1, i + 3);
|
|
39
|
+
if (/^[0-9a-fA-F]{2}$/.test(hex)) {
|
|
40
|
+
out.push(Number.parseInt(hex, 16));
|
|
41
|
+
i += 2;
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
out.push(0x3d); // a lone `=` — keep it
|
|
45
|
+
}
|
|
46
|
+
return Buffer.from(out);
|
|
47
|
+
}
|
|
48
|
+
function decodeBody(raw, encoding) {
|
|
49
|
+
switch (encoding) {
|
|
50
|
+
case 'quoted-printable':
|
|
51
|
+
return decodeQuotedPrintable(raw);
|
|
52
|
+
case 'base64':
|
|
53
|
+
return Buffer.from(raw.replace(/\s+/g, ''), 'base64');
|
|
54
|
+
default:
|
|
55
|
+
return Buffer.from(raw, 'latin1');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
/** Decode bytes under a MIME charset, falling back to UTF-8 (then latin1)
|
|
59
|
+
* rather than failing an ingest over an exotic label. */
|
|
60
|
+
export function decodeCharset(bytes, charset) {
|
|
61
|
+
const label = (charset ?? 'utf-8').trim().toLowerCase();
|
|
62
|
+
for (const candidate of [label, 'utf-8']) {
|
|
63
|
+
try {
|
|
64
|
+
return new TextDecoder(candidate, { fatal: false }).decode(bytes);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
/* unknown label — try the next */
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return bytes.toString('latin1');
|
|
71
|
+
}
|
|
72
|
+
/** Split a MIME chunk into unfolded headers and the body after the first
|
|
73
|
+
* blank line. Continuation lines (leading space/tab) join their header. */
|
|
74
|
+
function splitHeaders(chunk) {
|
|
75
|
+
const sep = /\r?\n\r?\n/.exec(chunk);
|
|
76
|
+
const headerText = sep ? chunk.slice(0, sep.index) : chunk;
|
|
77
|
+
const body = sep ? chunk.slice(sep.index + sep[0].length) : '';
|
|
78
|
+
const headers = {};
|
|
79
|
+
let current = '';
|
|
80
|
+
for (const rawLine of headerText.split(/\r?\n/)) {
|
|
81
|
+
if (/^[ \t]/.test(rawLine) && current) {
|
|
82
|
+
headers[current] += ` ${rawLine.trim()}`;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
const colon = rawLine.indexOf(':');
|
|
86
|
+
if (colon === -1)
|
|
87
|
+
continue;
|
|
88
|
+
current = rawLine.slice(0, colon).trim().toLowerCase();
|
|
89
|
+
headers[current] = rawLine.slice(colon + 1).trim();
|
|
90
|
+
}
|
|
91
|
+
return { headers, body };
|
|
92
|
+
}
|
|
93
|
+
function param(headerValue, name) {
|
|
94
|
+
if (!headerValue)
|
|
95
|
+
return null;
|
|
96
|
+
const m = new RegExp(`${name}\\s*=\\s*("[^"]*"|'[^']*'|[^;\\s]+)`, 'i').exec(headerValue);
|
|
97
|
+
return m ? m[1].replace(/^["']|["']$/g, '') : null;
|
|
98
|
+
}
|
|
99
|
+
function toPart(chunk) {
|
|
100
|
+
const { headers, body } = splitHeaders(chunk);
|
|
101
|
+
const contentType = (headers['content-type'] ?? 'text/html').split(';')[0].trim().toLowerCase();
|
|
102
|
+
const encoding = (headers['content-transfer-encoding'] ?? 'binary').trim().toLowerCase();
|
|
103
|
+
return {
|
|
104
|
+
contentType,
|
|
105
|
+
charset: param(headers['content-type'], 'charset')?.toLowerCase() ?? null,
|
|
106
|
+
location: headers['content-location'] ?? null,
|
|
107
|
+
encoding,
|
|
108
|
+
body: decodeBody(body, encoding),
|
|
109
|
+
headers,
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Parse an MHTML container. Anything that is not a well-formed multipart
|
|
114
|
+
* message is treated as a single part, so a plain `.html` file renamed to
|
|
115
|
+
* `.mhtml` still ingests.
|
|
116
|
+
*/
|
|
117
|
+
export function parseMhtml(raw) {
|
|
118
|
+
const text = typeof raw === 'string' ? raw : raw.toString('latin1');
|
|
119
|
+
const { headers, body } = splitHeaders(text);
|
|
120
|
+
const snapshotLocation = headers['snapshot-content-location'] ?? headers['content-location'] ?? null;
|
|
121
|
+
const subject = headers.subject ?? null;
|
|
122
|
+
const boundary = param(headers['content-type'], 'boundary');
|
|
123
|
+
let parts;
|
|
124
|
+
if (!boundary) {
|
|
125
|
+
// No boundary: either a single-part message or a bare HTML file. Feeding
|
|
126
|
+
// the whole document through `toPart` covers both — an HTML file has no
|
|
127
|
+
// header block, so everything lands in the body.
|
|
128
|
+
parts = [toPart(/^[a-z-]+:/i.test(text) ? text : `Content-Type: text/html\r\n\r\n${text}`)];
|
|
129
|
+
}
|
|
130
|
+
else {
|
|
131
|
+
const delimiter = `--${boundary}`;
|
|
132
|
+
parts = body
|
|
133
|
+
.split(delimiter)
|
|
134
|
+
.slice(1) // text before the first delimiter is the MIME preamble
|
|
135
|
+
.filter((chunk) => !chunk.startsWith('--')) // the closing `--boundary--`
|
|
136
|
+
.map((chunk) => chunk.replace(/^\r?\n/, ''))
|
|
137
|
+
.map(toPart);
|
|
138
|
+
}
|
|
139
|
+
const html = parts.filter((p) => p.contentType === 'text/html' || p.contentType === 'application/xhtml+xml');
|
|
140
|
+
const root = (snapshotLocation ? html.find((p) => p.location === snapshotLocation) : undefined) ??
|
|
141
|
+
html[0] ??
|
|
142
|
+
null;
|
|
143
|
+
return { root, parts, snapshotLocation, subject };
|
|
144
|
+
}
|
|
145
|
+
/** Parse a container and return its root frame decoded to a string. */
|
|
146
|
+
export function mhtmlToHtml(raw) {
|
|
147
|
+
const parsed = parseMhtml(raw);
|
|
148
|
+
return {
|
|
149
|
+
html: parsed.root ? decodeCharset(parsed.root.body, parsed.root.charset) : '',
|
|
150
|
+
location: parsed.root?.location ?? parsed.snapshotLocation,
|
|
151
|
+
subject: parsed.subject,
|
|
152
|
+
};
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=mhtml.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mhtml.js","sourceRoot":"","sources":["../../../src/knowledge/mhtml.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AA0BH;gEACgE;AAChE,MAAM,UAAU,qBAAqB,CAAC,KAAa;IACjD,MAAM,GAAG,GAAa,EAAE,CAAC;IACzB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,EAAE,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QACpB,IAAI,EAAE,KAAK,GAAG,EAAE,CAAC;YACf,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;YACrC,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YACnD,CAAC,IAAI,CAAC,CAAC,CAAC,kBAAkB;YAC1B,SAAS;QACX,CAAC;QACD,IAAI,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC;YAC1B,CAAC,IAAI,CAAC,CAAC,CAAC,gCAAgC;YACxC,SAAS;QACX,CAAC;QACD,MAAM,GAAG,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QACtC,IAAI,kBAAkB,CAAC,IAAI,CAAC,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,IAAI,CAAC;IAEP,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,EAAE,OAAO,EAAE,CAAC;AACpD,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,WAAW,CAAC,GAAoB;IAK9C,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC;IAC/B,OAAO;QACL,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;QAC7E,QAAQ,EAAE,MAAM,CAAC,IAAI,EAAE,QAAQ,IAAI,MAAM,CAAC,gBAAgB;QAC1D,OAAO,EAAE,MAAM,CAAC,OAAO;KACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OKF bundles — export the indexed documents to a portable Markdown bundle
|
|
3
|
+
* (frontmatter + `index.md`), and ingest one back.
|
|
4
|
+
*
|
|
5
|
+
* A bundle is plain files, so a round trip goes back through the ordinary
|
|
6
|
+
* ingest path rather than restoring index records directly: whatever comes
|
|
7
|
+
* back is re-extracted, re-chunked and re-versioned like any other document.
|
|
8
|
+
*
|
|
9
|
+
* Split out of document-pipeline.ts.
|
|
10
|
+
*
|
|
11
|
+
* @module v1/cli/knowledge/okf-bundle
|
|
12
|
+
*/
|
|
13
|
+
import type { BatchIngestResult } from './document-types.js';
|
|
14
|
+
export declare function exportToOKF(outputDir: string, rootDir?: string, scope?: string): Promise<{
|
|
15
|
+
exported: number;
|
|
16
|
+
outputDir: string;
|
|
17
|
+
}>;
|
|
18
|
+
export declare function importFromOKF(bundleDir: string, scope?: string, rootDir?: string): Promise<BatchIngestResult>;
|
|
19
|
+
//# sourceMappingURL=okf-bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"okf-bundle.d.ts","sourceRoot":"","sources":["../../../src/knowledge/okf-bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAYH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE7D,wBAAsB,WAAW,CAC/B,SAAS,EAAE,MAAM,EACjB,OAAO,SAAmB,EAC1B,KAAK,SAAW,GACf,OAAO,CAAC;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC,CA8DlD;AAID,wBAAsB,aAAa,CACjC,SAAS,EAAE,MAAM,EACjB,KAAK,SAAW,EAChB,OAAO,SAAmB,GACzB,OAAO,CAAC,iBAAiB,CAAC,CA4B5B"}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OKF bundles — export the indexed documents to a portable Markdown bundle
|
|
3
|
+
* (frontmatter + `index.md`), and ingest one back.
|
|
4
|
+
*
|
|
5
|
+
* A bundle is plain files, so a round trip goes back through the ordinary
|
|
6
|
+
* ingest path rather than restoring index records directly: whatever comes
|
|
7
|
+
* back is re-extracted, re-chunked and re-versioned like any other document.
|
|
8
|
+
*
|
|
9
|
+
* Split out of document-pipeline.ts.
|
|
10
|
+
*
|
|
11
|
+
* @module v1/cli/knowledge/okf-bundle
|
|
12
|
+
*/
|
|
13
|
+
import * as fs from 'node:fs';
|
|
14
|
+
import * as path from 'node:path';
|
|
15
|
+
import { extractText } from '../capabilities/cap-documents.js';
|
|
16
|
+
// Static import is safe and deliberate: memory-bridge imports only node builtins
|
|
17
|
+
// at module scope (everything heavy is lazy), and the project-root rule must not
|
|
18
|
+
// be duplicated — two copies of "which directory is this project" is exactly the
|
|
19
|
+
// bug this default exists to fix.
|
|
20
|
+
import { getProjectRoot } from '../memory/memory-bridge.js';
|
|
21
|
+
import { listDocuments } from './document-index.js';
|
|
22
|
+
import { ingestDocument, toFileEntry } from './document-ingest.js';
|
|
23
|
+
export async function exportToOKF(outputDir, rootDir = getProjectRoot(), scope = 'shared') {
|
|
24
|
+
const docs = listDocuments(rootDir, scope);
|
|
25
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
26
|
+
let exported = 0;
|
|
27
|
+
const indexEntries = [];
|
|
28
|
+
for (const doc of docs) {
|
|
29
|
+
// Read original content
|
|
30
|
+
let content = '';
|
|
31
|
+
try {
|
|
32
|
+
if (fs.existsSync(doc.filePath)) {
|
|
33
|
+
const entry = toFileEntry(doc.filePath);
|
|
34
|
+
content = await extractText(entry);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (!content)
|
|
41
|
+
continue;
|
|
42
|
+
const title = path.basename(doc.filePath, path.extname(doc.filePath));
|
|
43
|
+
const ext = path.extname(doc.filePath).toLowerCase();
|
|
44
|
+
const relativePath = path.relative(rootDir, doc.filePath);
|
|
45
|
+
const slug = title.replace(/[^a-zA-Z0-9._-]+/g, '-').toLowerCase();
|
|
46
|
+
const outFile = path.join(outputDir, `${slug}.md`);
|
|
47
|
+
const yamlEscape = (s) => /[:"'[\]{}#&*!|>%@`]/.test(s) ? `"${s.replace(/\\/g, '\\\\').replace(/"/g, '\\"')}"` : s;
|
|
48
|
+
const frontmatter = [
|
|
49
|
+
'---',
|
|
50
|
+
`type: Document`,
|
|
51
|
+
`title: ${yamlEscape(title)}`,
|
|
52
|
+
`description: ${yamlEscape(`Extracted from ${path.basename(doc.filePath)}`)}`,
|
|
53
|
+
`resource: ${yamlEscape(relativePath)}`,
|
|
54
|
+
`tags: ["document", ${yamlEscape(ext.slice(1))}]`,
|
|
55
|
+
`timestamp: ${yamlEscape(doc.indexedAt)}`,
|
|
56
|
+
`contentHash: ${yamlEscape(doc.contentHash)}`,
|
|
57
|
+
`chunkCount: ${doc.chunkCount}`,
|
|
58
|
+
'---',
|
|
59
|
+
'',
|
|
60
|
+
].join('\n');
|
|
61
|
+
fs.writeFileSync(outFile, frontmatter + content, 'utf-8');
|
|
62
|
+
indexEntries.push(`* [${title}](${slug}.md) - ${path.basename(doc.filePath)} (${doc.chunkCount} chunks)`);
|
|
63
|
+
exported++;
|
|
64
|
+
}
|
|
65
|
+
// Write index.md
|
|
66
|
+
const indexContent = [
|
|
67
|
+
`# Knowledge Bundle`,
|
|
68
|
+
'',
|
|
69
|
+
`Exported from monomind on ${new Date().toISOString().slice(0, 10)}`,
|
|
70
|
+
'',
|
|
71
|
+
...indexEntries,
|
|
72
|
+
'',
|
|
73
|
+
].join('\n');
|
|
74
|
+
fs.writeFileSync(path.join(outputDir, 'index.md'), indexContent, 'utf-8');
|
|
75
|
+
return { exported, outputDir };
|
|
76
|
+
}
|
|
77
|
+
// ── OKF Import ─────────────────────────────────────────────────────
|
|
78
|
+
export async function importFromOKF(bundleDir, scope = 'shared', rootDir = getProjectRoot()) {
|
|
79
|
+
const resolved = path.resolve(bundleDir);
|
|
80
|
+
const files = fs
|
|
81
|
+
.readdirSync(resolved)
|
|
82
|
+
.filter((f) => f.endsWith('.md') && f !== 'index.md' && f !== 'log.md')
|
|
83
|
+
.map((f) => path.join(resolved, f));
|
|
84
|
+
const result = {
|
|
85
|
+
filesProcessed: 0,
|
|
86
|
+
filesSkipped: 0,
|
|
87
|
+
totalChunks: 0,
|
|
88
|
+
errors: [],
|
|
89
|
+
results: [],
|
|
90
|
+
};
|
|
91
|
+
for (const file of files) {
|
|
92
|
+
const r = await ingestDocument(file, scope, rootDir);
|
|
93
|
+
result.results.push(r);
|
|
94
|
+
if (r.skipped) {
|
|
95
|
+
result.filesSkipped++;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
result.filesProcessed++;
|
|
99
|
+
result.totalChunks += r.chunksIndexed;
|
|
100
|
+
}
|
|
101
|
+
if (r.error && !r.skipped)
|
|
102
|
+
result.errors.push(`${r.filePath}: ${r.error}`);
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
//# sourceMappingURL=okf-bundle.js.map
|
|
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C,CAAC,CAAC,CAAC;IAEtC,MAAM,MAAM,GAAsB;QAChC,cAAc,EAAE,CAAC;QACjB,YAAY,EAAE,CAAC;QACf,WAAW,EAAE,CAAC;QACd,MAAM,EAAE,EAAE;QACV,OAAO,EAAE,EAAE;KACZ,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACzB,MAAM,CAAC,GAAG,MAAM,cAAc,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,CAAC;QACrD,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACvB,IAAI,CAAC,CAAC,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;QACD,IAAI,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,OAAO;YAAE,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,KAAK,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC;IAC7E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Per-profile capture stores (the browser track's profile feature).
|
|
3
|
+
*
|
|
4
|
+
* mono-agent has profiles — work, personal, a client — and a page captured
|
|
5
|
+
* from the browser can name the one it belongs to (`meta.profile` on the
|
|
6
|
+
* capture envelope). The promise that makes that worth having is negative:
|
|
7
|
+
* a page saved into `work` must NOT come back from a search of `personal`.
|
|
8
|
+
*
|
|
9
|
+
* WHICH MECHANISM, AND WHY. A store here is three things — a vector db
|
|
10
|
+
* directory (`dbPath`), a namespace, and the root the `doc-metadata.jsonl`
|
|
11
|
+
* lives under — and `scope` already decides all three (see
|
|
12
|
+
* document-pipeline: `namespace()`, `effectiveRoot()`, `storeDbPath()`).
|
|
13
|
+
* `global` is the existing proof: one scope value routes to a directory
|
|
14
|
+
* outside any project. A profile is the same shape, so it is expressed the
|
|
15
|
+
* same way — a scope of `profile:<id>` — rather than as a second, parallel
|
|
16
|
+
* "which brain" parameter threaded through ingest, search, cite and
|
|
17
|
+
* related. Nothing here is a new concept; it is one more value of an
|
|
18
|
+
* existing one.
|
|
19
|
+
*
|
|
20
|
+
* WHERE THE DIRECTORY GOES. Inside the global brain
|
|
21
|
+
* (`~/.monomind/global-brain/profiles/<id>`), not beside it. That is not
|
|
22
|
+
* cosmetic: `memory-bridge.getDbPath` refuses any dbPath outside the
|
|
23
|
+
* project, the per-project data dir, or the global brain, and — this is the
|
|
24
|
+
* dangerous part — a refused path does not throw, it silently falls back to
|
|
25
|
+
* the DEFAULT store. A profile brain anywhere else would quietly put every
|
|
26
|
+
* profile's captures in one database, which is the exact failure this
|
|
27
|
+
* feature exists to prevent. Being inside the global brain also inherits
|
|
28
|
+
* its protection from `cleanup --data`, which prunes `~/.monomind/projects`
|
|
29
|
+
* and deliberately never touches its sibling.
|
|
30
|
+
*
|
|
31
|
+
* UNTRUSTED INPUT. The profile id arrives from a browser extension and
|
|
32
|
+
* becomes a directory name. `isValidProfileId` is the guard, kept
|
|
33
|
+
* deliberately identical to Go's `profiledir.ValidProfileID` — the two
|
|
34
|
+
* sides of this contract must reject exactly the same strings.
|
|
35
|
+
*
|
|
36
|
+
* @module v1/cli/knowledge/profile-store
|
|
37
|
+
*/
|
|
38
|
+
/** Scopes of the form `profile:<id>` address one profile's own store. */
|
|
39
|
+
export declare const PROFILE_SCOPE_PREFIX = "profile:";
|
|
40
|
+
/**
|
|
41
|
+
* isValidProfileId mirrors `profiledir.ValidProfileID` (Go): non-empty, no
|
|
42
|
+
* path separator, no parent-directory component. Every other function here
|
|
43
|
+
* returns undefined for an id this rejects, so a hostile id can never
|
|
44
|
+
* become a path — not even a path that is then refused.
|
|
45
|
+
*/
|
|
46
|
+
export declare function isValidProfileId(id: unknown): id is string;
|
|
47
|
+
/** The scope value addressing one profile's store, or undefined. */
|
|
48
|
+
export declare function profileScope(id: unknown): string | undefined;
|
|
49
|
+
/** The profile id inside a `profile:<id>` scope, or undefined for any other. */
|
|
50
|
+
export declare function parseProfileScope(scope: unknown): string | undefined;
|
|
51
|
+
/** True for a scope that names a profile. */
|
|
52
|
+
export declare const isProfileScope: (scope: unknown) => boolean;
|
|
53
|
+
/**
|
|
54
|
+
* profileBrainDir is a profile's store directory — the value used BOTH as
|
|
55
|
+
* the dbPath and as the metadata root, exactly as the global brain uses one
|
|
56
|
+
* directory for both.
|
|
57
|
+
*
|
|
58
|
+
* It creates the directory, which a resolver would not normally do. The
|
|
59
|
+
* reason is specific: `memory-bridge.getDbPath` compares
|
|
60
|
+
* `fs.realpathSync(dbPath)` against `fs.realpathSync(globalBrainDir)`, and
|
|
61
|
+
* a path that does not exist yet cannot be realpath'd. On a machine where
|
|
62
|
+
* the home directory is reached through a symlink, the two sides would then
|
|
63
|
+
* resolve differently, the guard would reject the path, and — because that
|
|
64
|
+
* guard falls back instead of throwing — the profile's captures would land
|
|
65
|
+
* in the default store together with every other profile's. Creating the
|
|
66
|
+
* directory first makes both sides resolvable and the comparison honest.
|
|
67
|
+
*/
|
|
68
|
+
export declare function profileBrainDir(id: unknown): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* profileStoreDir is profileBrainDir for a `profile:<id>` SCOPE, and
|
|
71
|
+
* undefined for every other scope — the single function
|
|
72
|
+
* `document-store`'s `effectiveRoot`/`storeDbPath` consult, so that the
|
|
73
|
+
* routing rule lives in one place and the pipeline keeps a two-line hook.
|
|
74
|
+
*
|
|
75
|
+
* DO NOT MOVE THIS DIRECTORY OUT OF THE GLOBAL BRAIN. The nesting looks
|
|
76
|
+
* arbitrary and is not: `memory-bridge.getDbPath` accepts a dbPath only
|
|
77
|
+
* inside the project, the per-project data dir, or the global brain, and a
|
|
78
|
+
* path it does not accept is NOT rejected — it SILENTLY RETURNS THE DEFAULT
|
|
79
|
+
* STORE. So a profile brain sited anywhere else (beside the global brain,
|
|
80
|
+
* under `~/.monoagent`, under the profile's own root) does not fail: every
|
|
81
|
+
* profile's captures quietly land in one database, `work` turns up in a
|
|
82
|
+
* `personal` search, and nothing anywhere reports a problem. The feature
|
|
83
|
+
* fails by succeeding. `src/__tests__/profile-store-dbpath.test.ts` holds
|
|
84
|
+
* both halves of that — this path surviving, and an outside path silently
|
|
85
|
+
* becoming the default.
|
|
86
|
+
*/
|
|
87
|
+
export declare function profileStoreDir(scope: unknown): string | undefined;
|
|
88
|
+
/**
|
|
89
|
+
* profileInboxDir is where that profile's captures land, as the Go side
|
|
90
|
+
* writes them: `~/.monoagent/profiles/<id>/.monomind/inbox`.
|
|
91
|
+
*
|
|
92
|
+
* Keyed by profile id alone. mono-agent lets a profile's root be moved
|
|
93
|
+
* (`profiles.root_dir`), and the capture inbox deliberately does NOT follow
|
|
94
|
+
* it on either side — see `ProfileInbox` in `internal/capture/profile.go`
|
|
95
|
+
* for why. This path and that one are the same rule written twice, which is
|
|
96
|
+
* the cost of the two repos agreeing about a directory at all.
|
|
97
|
+
*/
|
|
98
|
+
export declare function profileInboxDir(id: unknown): string | undefined;
|
|
99
|
+
/**
|
|
100
|
+
* profileInboxes lists the profile inboxes that exist on this machine, for
|
|
101
|
+
* a sweep that wants to ingest every profile's captures rather than only
|
|
102
|
+
* the shared inbox. Missing directories are simply absent; nothing here
|
|
103
|
+
* throws.
|
|
104
|
+
*/
|
|
105
|
+
export declare function profileInboxes(): Array<{
|
|
106
|
+
id: string;
|
|
107
|
+
inbox: string;
|
|
108
|
+
scope: string;
|
|
109
|
+
}>;
|
|
110
|
+
/**
|
|
111
|
+
* captureScope is the routing rule, applied once per ingest: a capture
|
|
112
|
+
* whose envelope names a profile belongs to that profile's store, whatever
|
|
113
|
+
* scope the caller reached for.
|
|
114
|
+
*
|
|
115
|
+
* The envelope wins on purpose. The profile was chosen by a person at save
|
|
116
|
+
* time, in the browser, and every automatic caller (`doc ingest` on a path
|
|
117
|
+
* outside any project, the dashboard's watcher, an inbox sweep) picks its
|
|
118
|
+
* scope from where the FILE is rather than from what it holds. A caller
|
|
119
|
+
* that genuinely means a particular store says so by passing a
|
|
120
|
+
* `profile:<id>` scope, which is returned untouched.
|
|
121
|
+
*/
|
|
122
|
+
export declare function captureScope(scope: string, filePath: string): string;
|
|
123
|
+
/**
|
|
124
|
+
* envelopeProfile reads the `profile` out of the capture envelope holding
|
|
125
|
+
* `filePath`, if there is one. Defensive on the same terms as the rest of
|
|
126
|
+
* capture-envelope: `meta.json` is written by a browser extension on a
|
|
127
|
+
* machine we do not control, so every failure — absent, oversized,
|
|
128
|
+
* truncated, wrong-typed, or an id that could escape a directory — is
|
|
129
|
+
* "this capture names no profile", never a thrown error.
|
|
130
|
+
*/
|
|
131
|
+
export declare function envelopeProfile(filePath: string): string | undefined;
|
|
132
|
+
/** A human-readable name for a scope, for a listing or a search result. */
|
|
133
|
+
export declare function describeScope(scope: string): string;
|
|
134
|
+
//# sourceMappingURL=profile-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profile-store.d.ts","sourceRoot":"","sources":["../../../src/knowledge/profile-store.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AAMH,yEAAyE;AACzE,eAAO,MAAM,oBAAoB,aAAa,CAAC;AAiB/C;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,EAAE,EAAE,OAAO,GAAG,EAAE,IAAI,MAAM,CAO1D;AAED,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,EAAE,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAE5D;AAED,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,SAAS,CAIpE;AAED,6CAA6C;AAC7C,eAAO,MAAM,cAAc,UAAW,OAAO,KAAG,OAA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