@hraness/wordcell 0.21.3 → 0.22.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/README.md +170 -64
- package/dist/authoring.js +5 -3
- package/dist/{authority-4sp9d552.js → authority-06eqhqam.js} +57 -12
- package/dist/benchmark.js +4 -4
- package/dist/capture.js +6 -5
- package/dist/cli.js +39 -33
- package/dist/clip/acquire.js +3 -2
- package/dist/clip/cli.js +6 -5
- package/dist/clip/doctor.js +4 -3
- package/dist/clip/jobs.js +3 -3
- package/dist/clip/refresh.js +1 -1
- package/dist/evaluation-builder.js +20 -19
- package/dist/evaluation-kb.js +16 -15
- package/dist/graph-authority.js +5 -5
- package/dist/graph-percolation.js +7 -7
- package/dist/graph.js +1 -1
- package/dist/{index-pbr6rv47.js → index-1k595z6v.js} +6 -6
- package/dist/{index-0k2x4nn9.js → index-233z9wmn.js} +17 -5
- package/dist/index-3agn8scn.js +306 -0
- package/dist/index-4knsp9qj.js +34 -0
- package/dist/index-66pshdtx.js +341 -0
- package/dist/{index-59ssmqqm.js → index-76dbn6pe.js} +1 -1
- package/dist/{index-0rfcqab6.js → index-810nfzdj.js} +617 -66
- package/dist/index-9rf81m0p.js +368 -0
- package/dist/{index-51bap0mq.js → index-bqtqeak3.js} +10 -10
- package/dist/{index-9zcpdbjg.js → index-de2w8crk.js} +13 -13
- package/dist/{index-bgfzwt4h.js → index-djrcc1yf.js} +6 -6
- package/dist/{index-6sw24nvv.js → index-ecqpgr5y.js} +53 -2
- package/dist/{index-van48n3g.js → index-fc4dr114.js} +4 -2
- package/dist/{index-jzcws0zn.js → index-g5vsqmdy.js} +27 -57
- package/dist/index-hmw17zaa.js +1985 -0
- package/dist/index-j70m75wd.js +217 -0
- package/dist/{index-nd6nynv2.js → index-jk1sgx36.js} +1 -1
- package/dist/{index-3ehtt59c.js → index-n386evxj.js} +1 -1
- package/dist/{index-vdw5yjfa.js → index-q7tbg07z.js} +110 -20
- package/dist/{index-ekpwvbra.js → index-qbssx940.js} +1 -2
- package/dist/{index-115b07ap.js → index-rr9kzq4n.js} +5 -5
- package/dist/{index-11621h23.js → index-tf4wzjew.js} +1 -1
- package/dist/{index-why54q5p.js → index-vnybgywh.js} +4 -4
- package/dist/{index-bcfn9xah.js → index-xv80vzfp.js} +7 -7
- package/dist/index.js +289 -95
- package/dist/percolate.js +2 -2
- package/dist/portfolio.js +16 -15
- package/dist/publish-model.js +36 -0
- package/dist/publish-reader/reader.css +1042 -0
- package/dist/publish-reader/reader.js +1534 -0
- package/dist/publish-reader/theme.js +92 -0
- package/dist/publish-search.js +52 -0
- package/dist/publish.js +36 -0
- package/dist/rerank-typesafe.js +13 -0
- package/dist/rerank.js +14 -0
- package/dist/sdk.js +16 -13
- package/dist/search.js +3 -3
- package/dist/semantic.js +5 -5
- package/dist/{support-vm4mkw0k.js → support-1rh2d7mt.js} +38 -32
- package/dist/workflows/decision-context.js +15 -14
- package/dist/workflows/index.js +15 -14
- package/package.json +65 -6
- package/skills/wordcell/AGENTS.md +1 -0
- package/skills/wordcell/SKILL.md +2 -1
- package/skills/wordcell/agents/openai.yaml +1 -1
- package/skills/wordcell/references/publish.md +127 -0
- package/skills/wordcell/references/query.md +22 -0
- package/skills/wordcell/references/refresh.md +14 -0
- package/src/authoring-model.ts +29 -0
- package/src/authoring-program.ts +38 -3
- package/src/authoring.ts +17 -3
- package/src/cli-program.ts +441 -12
- package/src/graph.ts +1 -1
- package/src/index.ts +4 -0
- package/src/oh/authority.ts +14 -5
- package/src/oh/canonical-rust.ts +127 -0
- package/src/oh/projection-rust.ts +63 -0
- package/src/oh-adoption.ts +7 -1
- package/src/publish-graph.ts +0 -0
- package/src/publish-index.ts +195 -0
- package/src/publish-markdown.ts +617 -0
- package/src/publish-model.ts +599 -0
- package/src/publish-nav.ts +204 -0
- package/src/publish-pages.ts +382 -0
- package/src/publish-reader/reader.css +1042 -0
- package/src/publish-reader/reader.ts +1017 -0
- package/src/publish-reader/theme.ts +97 -0
- package/src/publish-search.ts +418 -0
- package/src/publish-select.ts +419 -0
- package/src/publish-theme.ts +106 -0
- package/src/publish.ts +904 -0
- package/src/rerank-credentials.ts +56 -0
- package/src/rerank-typesafe.ts +472 -0
- package/src/rerank.ts +389 -0
- package/src/sdk.ts +157 -6
- package/src/serve.ts +180 -0
- package/src/vault.ts +23 -9
package/dist/clip/doctor.js
CHANGED
|
@@ -9,16 +9,17 @@ import {
|
|
|
9
9
|
renderAdapterCapabilities,
|
|
10
10
|
renderDoctorReport,
|
|
11
11
|
runDiagnosticCommand
|
|
12
|
-
} from "../index-
|
|
13
|
-
import"../index-
|
|
12
|
+
} from "../index-fc4dr114.js";
|
|
13
|
+
import"../index-g5vsqmdy.js";
|
|
14
14
|
import"../index-hgve9rh2.js";
|
|
15
|
+
import"../index-2gv8y733.js";
|
|
15
16
|
import"../index-w2zc0vwa.js";
|
|
16
17
|
import"../index-e5fbsywq.js";
|
|
17
18
|
import"../index-dfag79p7.js";
|
|
18
19
|
import"../index-gh719d91.js";
|
|
19
20
|
import"../index-mxxxytys.js";
|
|
20
|
-
import"../index-2gv8y733.js";
|
|
21
21
|
import"../index-1xxnjn0d.js";
|
|
22
|
+
import"../index-4knsp9qj.js";
|
|
22
23
|
import"../index-z1w83f81.js";
|
|
23
24
|
export {
|
|
24
25
|
runDiagnosticCommand,
|
package/dist/clip/jobs.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
import {
|
|
3
|
-
acquireFileLease
|
|
4
|
-
} from "../index-3rm7cz6h.js";
|
|
5
2
|
import {
|
|
6
3
|
redactSensitiveText
|
|
7
4
|
} from "../index-mxxxytys.js";
|
|
@@ -9,6 +6,9 @@ import {
|
|
|
9
6
|
sanitizeTerminalLine,
|
|
10
7
|
sanitizeTerminalText
|
|
11
8
|
} from "../index-1xxnjn0d.js";
|
|
9
|
+
import {
|
|
10
|
+
acquireFileLease
|
|
11
|
+
} from "../index-3rm7cz6h.js";
|
|
12
12
|
import"../index-z1w83f81.js";
|
|
13
13
|
|
|
14
14
|
// src/clip/jobs.ts
|
package/dist/clip/refresh.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
diffCaptureBundle
|
|
4
4
|
} from "../index-j4zgmzjr.js";
|
|
5
5
|
import"../index-npg9z1a4.js";
|
|
6
|
-
import"../index-1gwbassd.js";
|
|
7
6
|
import"../index-mxxxytys.js";
|
|
7
|
+
import"../index-1gwbassd.js";
|
|
8
8
|
import"../index-1xxnjn0d.js";
|
|
9
9
|
import"../index-z1w83f81.js";
|
|
10
10
|
export {
|
|
@@ -4,38 +4,39 @@ import {
|
|
|
4
4
|
knowledgeBaseEvaluationRetrieverIds,
|
|
5
5
|
openKnowledgeBaseEvaluation,
|
|
6
6
|
verifyFrozenEvaluationSnapshot
|
|
7
|
-
} from "./index-
|
|
8
|
-
import"./index-
|
|
9
|
-
import"./index-4j3tt0c3.js";
|
|
7
|
+
} from "./index-1k595z6v.js";
|
|
8
|
+
import"./index-q7tbg07z.js";
|
|
10
9
|
import"./index-adx6khj5.js";
|
|
11
10
|
import {
|
|
12
11
|
indexSemanticVault,
|
|
13
12
|
recommendedEmbeddingModel,
|
|
14
13
|
recommendedEmbeddingModelSha256
|
|
15
|
-
} from "./index-
|
|
16
|
-
import"./index-
|
|
17
|
-
import"./index-
|
|
18
|
-
import"./index-11621h23.js";
|
|
19
|
-
import {
|
|
20
|
-
scanVault
|
|
21
|
-
} from "./index-0k2x4nn9.js";
|
|
22
|
-
import"./index-nd6nynv2.js";
|
|
23
|
-
import {
|
|
24
|
-
runGitCommand
|
|
25
|
-
} from "./index-1gwbassd.js";
|
|
14
|
+
} from "./index-rr9kzq4n.js";
|
|
15
|
+
import"./index-4j3tt0c3.js";
|
|
16
|
+
import"./index-j70m75wd.js";
|
|
26
17
|
import {
|
|
27
18
|
MAX_EVALUATION_DIAGNOSTICS,
|
|
28
19
|
MAX_EVALUATION_EVIDENCE_BYTES,
|
|
29
20
|
MAX_EVALUATION_RESULTS_PER_QUERY
|
|
30
21
|
} from "./index-b88v3vtm.js";
|
|
31
|
-
import"./index-
|
|
32
|
-
import"./index-
|
|
22
|
+
import"./index-djrcc1yf.js";
|
|
23
|
+
import"./index-jk1sgx36.js";
|
|
24
|
+
import"./index-xv80vzfp.js";
|
|
25
|
+
import"./index-tf4wzjew.js";
|
|
26
|
+
import {
|
|
27
|
+
runGitCommand
|
|
28
|
+
} from "./index-1gwbassd.js";
|
|
29
|
+
import"./index-vnybgywh.js";
|
|
30
|
+
import"./index-1xxnjn0d.js";
|
|
31
|
+
import {
|
|
32
|
+
scanVault
|
|
33
|
+
} from "./index-233z9wmn.js";
|
|
34
|
+
import"./index-d13v9ckt.js";
|
|
33
35
|
import"./index-48pz4jpc.js";
|
|
34
36
|
import"./index-06c9ctr6.js";
|
|
35
|
-
import"./index-d13v9ckt.js";
|
|
36
37
|
import"./index-5vwpzb5a.js";
|
|
37
|
-
import"./index-
|
|
38
|
-
import"./index-
|
|
38
|
+
import"./index-3rm7cz6h.js";
|
|
39
|
+
import"./index-qbssx940.js";
|
|
39
40
|
import"./index-z1w83f81.js";
|
|
40
41
|
|
|
41
42
|
// src/evaluation-builder.ts
|
package/dist/evaluation-kb.js
CHANGED
|
@@ -4,26 +4,27 @@ import {
|
|
|
4
4
|
knowledgeBaseEvaluationRetrieverIds,
|
|
5
5
|
openKnowledgeBaseEvaluation,
|
|
6
6
|
verifyFrozenEvaluationSnapshot
|
|
7
|
-
} from "./index-
|
|
8
|
-
import"./index-
|
|
9
|
-
import"./index-4j3tt0c3.js";
|
|
7
|
+
} from "./index-1k595z6v.js";
|
|
8
|
+
import"./index-q7tbg07z.js";
|
|
10
9
|
import"./index-adx6khj5.js";
|
|
11
|
-
import"./index-
|
|
12
|
-
import"./index-
|
|
13
|
-
import"./index-
|
|
14
|
-
import"./index-11621h23.js";
|
|
15
|
-
import"./index-0k2x4nn9.js";
|
|
16
|
-
import"./index-nd6nynv2.js";
|
|
17
|
-
import"./index-1gwbassd.js";
|
|
10
|
+
import"./index-rr9kzq4n.js";
|
|
11
|
+
import"./index-4j3tt0c3.js";
|
|
12
|
+
import"./index-j70m75wd.js";
|
|
18
13
|
import"./index-b88v3vtm.js";
|
|
19
|
-
import"./index-
|
|
20
|
-
import"./index-
|
|
14
|
+
import"./index-djrcc1yf.js";
|
|
15
|
+
import"./index-jk1sgx36.js";
|
|
16
|
+
import"./index-xv80vzfp.js";
|
|
17
|
+
import"./index-tf4wzjew.js";
|
|
18
|
+
import"./index-1gwbassd.js";
|
|
19
|
+
import"./index-vnybgywh.js";
|
|
20
|
+
import"./index-1xxnjn0d.js";
|
|
21
|
+
import"./index-233z9wmn.js";
|
|
22
|
+
import"./index-d13v9ckt.js";
|
|
21
23
|
import"./index-48pz4jpc.js";
|
|
22
24
|
import"./index-06c9ctr6.js";
|
|
23
|
-
import"./index-d13v9ckt.js";
|
|
24
25
|
import"./index-5vwpzb5a.js";
|
|
25
|
-
import"./index-
|
|
26
|
-
import"./index-
|
|
26
|
+
import"./index-3rm7cz6h.js";
|
|
27
|
+
import"./index-qbssx940.js";
|
|
27
28
|
import"./index-z1w83f81.js";
|
|
28
29
|
export {
|
|
29
30
|
verifyFrozenEvaluationSnapshot,
|
package/dist/graph-authority.js
CHANGED
|
@@ -5,17 +5,17 @@ import {
|
|
|
5
5
|
queryGraph,
|
|
6
6
|
rebuildGraph,
|
|
7
7
|
verifyGraph
|
|
8
|
-
} from "./index-
|
|
8
|
+
} from "./index-xv80vzfp.js";
|
|
9
9
|
import {
|
|
10
10
|
GRAPH_LIMITS,
|
|
11
11
|
GraphAuthorityError,
|
|
12
12
|
validateGraphQueryRequest
|
|
13
|
-
} from "./index-
|
|
14
|
-
import"./index-
|
|
15
|
-
import"./index-3rm7cz6h.js";
|
|
13
|
+
} from "./index-tf4wzjew.js";
|
|
14
|
+
import"./index-233z9wmn.js";
|
|
16
15
|
import"./index-06c9ctr6.js";
|
|
17
16
|
import"./index-5vwpzb5a.js";
|
|
18
|
-
import"./index-
|
|
17
|
+
import"./index-3rm7cz6h.js";
|
|
18
|
+
import"./index-qbssx940.js";
|
|
19
19
|
import"./index-z1w83f81.js";
|
|
20
20
|
export {
|
|
21
21
|
verifyGraph,
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
// @bun
|
|
2
2
|
import {
|
|
3
3
|
percolateWithGraph
|
|
4
|
-
} from "./index-
|
|
5
|
-
import"./index-
|
|
6
|
-
import"./index-
|
|
7
|
-
import"./index-
|
|
8
|
-
import"./index-
|
|
9
|
-
import"./index-3rm7cz6h.js";
|
|
4
|
+
} from "./index-djrcc1yf.js";
|
|
5
|
+
import"./index-jk1sgx36.js";
|
|
6
|
+
import"./index-xv80vzfp.js";
|
|
7
|
+
import"./index-tf4wzjew.js";
|
|
8
|
+
import"./index-233z9wmn.js";
|
|
10
9
|
import"./index-06c9ctr6.js";
|
|
11
10
|
import"./index-5vwpzb5a.js";
|
|
12
|
-
import"./index-
|
|
11
|
+
import"./index-3rm7cz6h.js";
|
|
12
|
+
import"./index-qbssx940.js";
|
|
13
13
|
import"./index-z1w83f81.js";
|
|
14
14
|
export {
|
|
15
15
|
percolateWithGraph
|
package/dist/graph.js
CHANGED
|
@@ -2,17 +2,17 @@
|
|
|
2
2
|
import {
|
|
3
3
|
MAX_SEARCH_RESULTS,
|
|
4
4
|
openKnowledgeBase
|
|
5
|
-
} from "./index-
|
|
5
|
+
} from "./index-q7tbg07z.js";
|
|
6
6
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
MAX_EVALUATION_EVIDENCE_BYTES,
|
|
8
|
+
redactEvaluationMachinePaths
|
|
9
|
+
} from "./index-b88v3vtm.js";
|
|
9
10
|
import {
|
|
10
11
|
runGitCommand
|
|
11
12
|
} from "./index-1gwbassd.js";
|
|
12
13
|
import {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
} from "./index-b88v3vtm.js";
|
|
14
|
+
scanVault
|
|
15
|
+
} from "./index-233z9wmn.js";
|
|
16
16
|
import {
|
|
17
17
|
MAX_REPOSITORY_MEMORY_DETAIL_LIMIT,
|
|
18
18
|
MAX_REPOSITORY_MEMORY_GROUP_LIMIT,
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
parseNote,
|
|
9
9
|
renderCatalog,
|
|
10
10
|
replaceCatalog
|
|
11
|
-
} from "./index-
|
|
11
|
+
} from "./index-qbssx940.js";
|
|
12
12
|
|
|
13
13
|
// src/vault.ts
|
|
14
14
|
import { randomUUID } from "crypto";
|
|
@@ -334,12 +334,24 @@ async function snapshot(rootInput, options, writeIndex) {
|
|
|
334
334
|
...options.maxNoteBytes === undefined ? {} : { maxNoteBytes: options.maxNoteBytes },
|
|
335
335
|
...options.maxTotalBytes === undefined ? {} : { maxTotalBytes: options.maxTotalBytes }
|
|
336
336
|
});
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
337
|
+
const configuredCatalogMode = parsedCatalogMode(options.catalogMode, "ScanVaultOptions.catalogMode");
|
|
338
|
+
let indexRevision;
|
|
339
|
+
try {
|
|
340
|
+
indexRevision = await readIndexRevision(root, indexPath, options.maxNoteBytes ?? MAX_NOTE_UTF8_BYTES);
|
|
341
|
+
} catch (error) {
|
|
342
|
+
const absent = error instanceof Error && "code" in error && error.code === "ENOENT";
|
|
343
|
+
if (!absent || options.index !== undefined || configuredCatalogMode === "managed" || notes.some((note) => note.path === vaultIndexPath))
|
|
344
|
+
throw error;
|
|
345
|
+
if (writeIndex) {
|
|
346
|
+
throw new Error("Refresh requires an index.md front door. Add one with kb_catalog: authored to preserve its contents, or catalog markers for a managed catalog. Search and graph commands can read this folder without one.", { cause: error });
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
const currentIndex = indexRevision?.content ?? "";
|
|
350
|
+
const catalogMode = configuredCatalogMode ?? (indexRevision === undefined ? "authored" : declaredCatalogMode(parseNote(vaultIndexPath, currentIndex)) ?? "managed");
|
|
341
351
|
let index = "authored";
|
|
342
352
|
if (catalogMode === "managed") {
|
|
353
|
+
if (indexRevision === undefined)
|
|
354
|
+
throw new Error("A managed catalog requires an existing index file.");
|
|
343
355
|
const expectedIndex = replaceCatalog(currentIndex, renderCatalog(notes, catalogNoteId));
|
|
344
356
|
const stale = currentIndex !== expectedIndex;
|
|
345
357
|
index = stale ? "stale" : "current";
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/publish-search.ts
|
|
3
|
+
var PUBLISH_FIELD_TITLE = 1;
|
|
4
|
+
var PUBLISH_FIELD_ALIAS = 2;
|
|
5
|
+
var PUBLISH_FIELD_PATH = 4;
|
|
6
|
+
var PUBLISH_FIELD_TAG = 8;
|
|
7
|
+
var PUBLISH_FIELD_METADATA = 16;
|
|
8
|
+
var PUBLISH_FIELD_CONTENT = 32;
|
|
9
|
+
var PUBLISH_SEARCH_WEIGHTS_V1 = Object.freeze({
|
|
10
|
+
identity: Object.freeze({ title: 1000, alias: 950, path: 900 }),
|
|
11
|
+
phrase: Object.freeze({
|
|
12
|
+
title: 400,
|
|
13
|
+
alias: 350,
|
|
14
|
+
path: 300,
|
|
15
|
+
tag: 250,
|
|
16
|
+
content: 150,
|
|
17
|
+
metadata: 100
|
|
18
|
+
}),
|
|
19
|
+
term: Object.freeze({
|
|
20
|
+
title: 40,
|
|
21
|
+
alias: 35,
|
|
22
|
+
path: 30,
|
|
23
|
+
tag: 30,
|
|
24
|
+
metadata: 10,
|
|
25
|
+
content: 5
|
|
26
|
+
}),
|
|
27
|
+
coverage: 100
|
|
28
|
+
});
|
|
29
|
+
var MAX_PUBLISH_QUERY_BYTES = 16 * 1024;
|
|
30
|
+
var MAX_PUBLISH_QUERY_TERMS = 64;
|
|
31
|
+
var MAX_PUBLISH_PREFIX_EXPANSIONS = 32;
|
|
32
|
+
var TERM_PATTERN = /[\p{L}\p{N}][\p{L}\p{N}._/-]*/gu;
|
|
33
|
+
var textEncoder = new TextEncoder;
|
|
34
|
+
function publishUtf8Bytes(value) {
|
|
35
|
+
return textEncoder.encode(value).byteLength;
|
|
36
|
+
}
|
|
37
|
+
function publishNormalize(value) {
|
|
38
|
+
return value.normalize("NFC").toLocaleLowerCase("en-US");
|
|
39
|
+
}
|
|
40
|
+
var MAX_PUBLISH_QUERY_FILTERS = 8;
|
|
41
|
+
var FILTER_PATTERN = /^(tag|type|path):(\S+)$/u;
|
|
42
|
+
function trimSlashes(value) {
|
|
43
|
+
let start = 0;
|
|
44
|
+
let end = value.length;
|
|
45
|
+
while (start < end && value.charCodeAt(start) === 47)
|
|
46
|
+
start += 1;
|
|
47
|
+
while (end > start && value.charCodeAt(end - 1) === 47)
|
|
48
|
+
end -= 1;
|
|
49
|
+
return value.slice(start, end);
|
|
50
|
+
}
|
|
51
|
+
function publishQueryParts(raw) {
|
|
52
|
+
const tags = [];
|
|
53
|
+
const types = [];
|
|
54
|
+
const paths = [];
|
|
55
|
+
const rest = [];
|
|
56
|
+
for (const token of raw.split(/\s+/u)) {
|
|
57
|
+
if (token === "")
|
|
58
|
+
continue;
|
|
59
|
+
const match = FILTER_PATTERN.exec(token);
|
|
60
|
+
const value = match === null ? "" : publishNormalize(trimSlashes(match[2] ?? ""));
|
|
61
|
+
if (match === null || value === "") {
|
|
62
|
+
rest.push(token);
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
const bucket = match[1] === "tag" ? tags : match[1] === "type" ? types : paths;
|
|
66
|
+
if (bucket.length < MAX_PUBLISH_QUERY_FILTERS)
|
|
67
|
+
bucket.push(value);
|
|
68
|
+
else
|
|
69
|
+
rest.push(token);
|
|
70
|
+
}
|
|
71
|
+
return { filters: { tags, types, paths }, text: rest.join(" ") };
|
|
72
|
+
}
|
|
73
|
+
function publishDocMatchesFilters(doc, filters, type) {
|
|
74
|
+
if (filters.tags.length > 0) {
|
|
75
|
+
const tags = doc.f.g === "" ? [] : doc.f.g.split(`
|
|
76
|
+
`);
|
|
77
|
+
for (const tag of filters.tags) {
|
|
78
|
+
if (!tags.includes(publishNormalize(tag)))
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
if (filters.types.length > 0) {
|
|
83
|
+
const docType = publishNormalize(type === undefined || type === "" ? "note" : type);
|
|
84
|
+
for (const wanted of filters.types) {
|
|
85
|
+
if (docType !== publishNormalize(wanted))
|
|
86
|
+
return false;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (filters.paths.length > 0) {
|
|
90
|
+
const slug = publishNormalize(doc.s);
|
|
91
|
+
const fields = doc.f.p === "" ? [] : doc.f.p.split(`
|
|
92
|
+
`);
|
|
93
|
+
for (const value of filters.paths) {
|
|
94
|
+
const prefix = publishNormalize(trimSlashes(value));
|
|
95
|
+
const boundary = `${prefix}/`;
|
|
96
|
+
const inSlug = slug === prefix || slug.startsWith(boundary);
|
|
97
|
+
const inFields = fields.some((line) => line === prefix || line.startsWith(boundary));
|
|
98
|
+
if (!inSlug && !inFields)
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return true;
|
|
103
|
+
}
|
|
104
|
+
var MAX_PUBLISH_MARK_RANGES = 32;
|
|
105
|
+
function publishMarkRanges(text, terms, maximum = MAX_PUBLISH_MARK_RANGES) {
|
|
106
|
+
const display = text.normalize("NFC");
|
|
107
|
+
let normalized = "";
|
|
108
|
+
const map = [];
|
|
109
|
+
for (let offset = 0;offset < display.length; ) {
|
|
110
|
+
const point = display.codePointAt(offset) ?? 0;
|
|
111
|
+
const character = String.fromCodePoint(point);
|
|
112
|
+
const lowered = character.toLocaleLowerCase("en-US");
|
|
113
|
+
for (let index = 0;index < lowered.length; index += 1)
|
|
114
|
+
map.push(offset);
|
|
115
|
+
normalized += lowered;
|
|
116
|
+
offset += character.length;
|
|
117
|
+
}
|
|
118
|
+
const ranges = [];
|
|
119
|
+
for (const term of terms) {
|
|
120
|
+
const needle = publishNormalize(term);
|
|
121
|
+
if (needle === "")
|
|
122
|
+
continue;
|
|
123
|
+
let from = 0;
|
|
124
|
+
while (ranges.length < maximum) {
|
|
125
|
+
const hit = normalized.indexOf(needle, from);
|
|
126
|
+
if (hit === -1)
|
|
127
|
+
break;
|
|
128
|
+
const start = map[hit] ?? 0;
|
|
129
|
+
const tail = hit + needle.length;
|
|
130
|
+
const end = tail >= map.length ? display.length : map[tail] ?? display.length;
|
|
131
|
+
if (end > start)
|
|
132
|
+
ranges.push({ start, end });
|
|
133
|
+
from = tail === 0 ? 1 : tail;
|
|
134
|
+
}
|
|
135
|
+
if (ranges.length >= maximum)
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
ranges.sort((left, right) => left.start - right.start || left.end - right.end);
|
|
139
|
+
const merged = [];
|
|
140
|
+
for (const range of ranges) {
|
|
141
|
+
const last = merged[merged.length - 1];
|
|
142
|
+
if (last !== undefined && range.start <= last.end) {
|
|
143
|
+
merged[merged.length - 1] = { start: last.start, end: Math.max(last.end, range.end) };
|
|
144
|
+
} else {
|
|
145
|
+
merged.push(range);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
return merged;
|
|
149
|
+
}
|
|
150
|
+
function publishQuery(value) {
|
|
151
|
+
if (typeof value !== "string") {
|
|
152
|
+
throw new TypeError("Search query must be a string.");
|
|
153
|
+
}
|
|
154
|
+
if (publishUtf8Bytes(value) > MAX_PUBLISH_QUERY_BYTES) {
|
|
155
|
+
throw new RangeError(`Search query exceeds the ${MAX_PUBLISH_QUERY_BYTES}-byte limit.`);
|
|
156
|
+
}
|
|
157
|
+
const raw = value.trim();
|
|
158
|
+
const normalized = publishNormalize(raw);
|
|
159
|
+
const terms = [];
|
|
160
|
+
const seen = new Set;
|
|
161
|
+
for (const match of normalized.matchAll(TERM_PATTERN)) {
|
|
162
|
+
if (seen.has(match[0]))
|
|
163
|
+
continue;
|
|
164
|
+
seen.add(match[0]);
|
|
165
|
+
terms.push(match[0]);
|
|
166
|
+
if (terms.length > MAX_PUBLISH_QUERY_TERMS) {
|
|
167
|
+
throw new RangeError(`Search query may contain at most ${MAX_PUBLISH_QUERY_TERMS} unique normalized terms.`);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return { raw, normalized, terms };
|
|
171
|
+
}
|
|
172
|
+
function publishShardName(term) {
|
|
173
|
+
let hash = 2166136261;
|
|
174
|
+
for (let index = 0;index < term.length; index += 1) {
|
|
175
|
+
hash ^= term.charCodeAt(index);
|
|
176
|
+
hash = Math.imul(hash, 16777619) >>> 0;
|
|
177
|
+
}
|
|
178
|
+
return (hash >>> 24).toString(16).padStart(2, "0");
|
|
179
|
+
}
|
|
180
|
+
function publishPrefixTerms(dictionary, prefix, maximum = MAX_PUBLISH_PREFIX_EXPANSIONS) {
|
|
181
|
+
if (prefix === "")
|
|
182
|
+
return [];
|
|
183
|
+
let low = 0;
|
|
184
|
+
let high = dictionary.length;
|
|
185
|
+
while (low < high) {
|
|
186
|
+
const middle = low + high >> 1;
|
|
187
|
+
if ((dictionary[middle] ?? "") < prefix)
|
|
188
|
+
low = middle + 1;
|
|
189
|
+
else
|
|
190
|
+
high = middle;
|
|
191
|
+
}
|
|
192
|
+
const found = [];
|
|
193
|
+
for (let index = low;index < dictionary.length && found.length < maximum; index += 1) {
|
|
194
|
+
const term = dictionary[index] ?? "";
|
|
195
|
+
if (!term.startsWith(prefix))
|
|
196
|
+
break;
|
|
197
|
+
found.push(term);
|
|
198
|
+
}
|
|
199
|
+
return found;
|
|
200
|
+
}
|
|
201
|
+
function fieldMasks(term, fields) {
|
|
202
|
+
let mask = 0;
|
|
203
|
+
if (fields.t.includes(term))
|
|
204
|
+
mask |= PUBLISH_FIELD_TITLE;
|
|
205
|
+
if (fields.a.includes(term))
|
|
206
|
+
mask |= PUBLISH_FIELD_ALIAS;
|
|
207
|
+
if (fields.p.includes(term))
|
|
208
|
+
mask |= PUBLISH_FIELD_PATH;
|
|
209
|
+
if (fields.g.includes(term))
|
|
210
|
+
mask |= PUBLISH_FIELD_TAG;
|
|
211
|
+
if (fields.m.includes(term))
|
|
212
|
+
mask |= PUBLISH_FIELD_METADATA;
|
|
213
|
+
return mask;
|
|
214
|
+
}
|
|
215
|
+
function scorePublishDocument(input, query) {
|
|
216
|
+
const fields = input.doc.f;
|
|
217
|
+
const phrase = query.normalized;
|
|
218
|
+
const weights = PUBLISH_SEARCH_WEIGHTS_V1;
|
|
219
|
+
let score = 0;
|
|
220
|
+
let identity = false;
|
|
221
|
+
let phraseMatched = false;
|
|
222
|
+
if (phrase !== "") {
|
|
223
|
+
if (fields.t === phrase) {
|
|
224
|
+
identity = true;
|
|
225
|
+
score += weights.identity.title;
|
|
226
|
+
}
|
|
227
|
+
if (fields.a.split(`
|
|
228
|
+
`).includes(phrase)) {
|
|
229
|
+
identity = true;
|
|
230
|
+
score += weights.identity.alias;
|
|
231
|
+
}
|
|
232
|
+
if (fields.p.split(`
|
|
233
|
+
`).includes(phrase)) {
|
|
234
|
+
identity = true;
|
|
235
|
+
score += weights.identity.path;
|
|
236
|
+
}
|
|
237
|
+
const phraseFields = [
|
|
238
|
+
[PUBLISH_FIELD_TITLE, fields.t, weights.phrase.title],
|
|
239
|
+
[PUBLISH_FIELD_ALIAS, fields.a, weights.phrase.alias],
|
|
240
|
+
[PUBLISH_FIELD_PATH, fields.p, weights.phrase.path],
|
|
241
|
+
[PUBLISH_FIELD_TAG, fields.g, weights.phrase.tag],
|
|
242
|
+
[PUBLISH_FIELD_METADATA, fields.m, weights.phrase.metadata]
|
|
243
|
+
];
|
|
244
|
+
for (const [, value, weight] of phraseFields) {
|
|
245
|
+
if (value.includes(phrase)) {
|
|
246
|
+
phraseMatched = true;
|
|
247
|
+
score += weight;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
if (input.contentText !== undefined && input.contentText.includes(phrase)) {
|
|
251
|
+
phraseMatched = true;
|
|
252
|
+
score += weights.phrase.content;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
let matchedTerms = 0;
|
|
256
|
+
for (const term of query.terms) {
|
|
257
|
+
const mask = fieldMasks(term, fields) | (input.contentTerms.has(term) ? PUBLISH_FIELD_CONTENT : 0);
|
|
258
|
+
if (mask === 0)
|
|
259
|
+
continue;
|
|
260
|
+
matchedTerms += 1;
|
|
261
|
+
if (mask & PUBLISH_FIELD_TITLE)
|
|
262
|
+
score += weights.term.title;
|
|
263
|
+
if (mask & PUBLISH_FIELD_ALIAS)
|
|
264
|
+
score += weights.term.alias;
|
|
265
|
+
if (mask & PUBLISH_FIELD_PATH)
|
|
266
|
+
score += weights.term.path;
|
|
267
|
+
if (mask & PUBLISH_FIELD_TAG)
|
|
268
|
+
score += weights.term.tag;
|
|
269
|
+
if (mask & PUBLISH_FIELD_METADATA)
|
|
270
|
+
score += weights.term.metadata;
|
|
271
|
+
if (mask & PUBLISH_FIELD_CONTENT)
|
|
272
|
+
score += weights.term.content;
|
|
273
|
+
}
|
|
274
|
+
const requiredTerms = query.terms.length <= 1 ? query.terms.length : Math.min(3, Math.ceil(query.terms.length / 2));
|
|
275
|
+
if (!identity && !phraseMatched && matchedTerms < requiredTerms)
|
|
276
|
+
return null;
|
|
277
|
+
if (query.terms.length > 0) {
|
|
278
|
+
score += Math.round(matchedTerms / query.terms.length * weights.coverage);
|
|
279
|
+
}
|
|
280
|
+
if (score === 0)
|
|
281
|
+
return null;
|
|
282
|
+
return { score, identity, phraseMatched, matchedTerms };
|
|
283
|
+
}
|
|
284
|
+
function comparePublishScores(left, right) {
|
|
285
|
+
return Number(right.identity) - Number(left.identity) || right.score - left.score || left.i - right.i;
|
|
286
|
+
}
|
|
287
|
+
function publishSnippet(text, query, fallback, windowBytes = 160) {
|
|
288
|
+
const normalized = publishNormalize(text);
|
|
289
|
+
let offset = query.normalized === "" ? -1 : normalized.indexOf(query.normalized);
|
|
290
|
+
if (offset < 0) {
|
|
291
|
+
for (const term of query.terms) {
|
|
292
|
+
offset = normalized.indexOf(term);
|
|
293
|
+
if (offset >= 0)
|
|
294
|
+
break;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
if (offset < 0)
|
|
298
|
+
return fallback;
|
|
299
|
+
const half = Math.floor(windowBytes / 2);
|
|
300
|
+
const start = Math.max(0, offset - half);
|
|
301
|
+
const end = Math.min(text.length, offset + half);
|
|
302
|
+
const snippet = text.slice(start, end).replace(/\s+/gu, " ").trim();
|
|
303
|
+
return `${start > 0 ? "\u2026" : ""}${snippet}${end < text.length ? "\u2026" : ""}`;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
export { PUBLISH_FIELD_TITLE, PUBLISH_FIELD_ALIAS, PUBLISH_FIELD_PATH, PUBLISH_FIELD_TAG, PUBLISH_FIELD_METADATA, PUBLISH_FIELD_CONTENT, PUBLISH_SEARCH_WEIGHTS_V1, MAX_PUBLISH_QUERY_BYTES, MAX_PUBLISH_QUERY_TERMS, MAX_PUBLISH_PREFIX_EXPANSIONS, publishUtf8Bytes, publishNormalize, MAX_PUBLISH_QUERY_FILTERS, publishQueryParts, publishDocMatchesFilters, MAX_PUBLISH_MARK_RANGES, publishMarkRanges, publishQuery, publishShardName, publishPrefixTerms, scorePublishDocument, comparePublishScores, publishSnippet };
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
// src/clip/package-root.ts
|
|
3
|
+
import { existsSync, readFileSync } from "fs";
|
|
4
|
+
import { createRequire } from "module";
|
|
5
|
+
import { dirname, join, resolve } from "path";
|
|
6
|
+
function isPackageManifest(value) {
|
|
7
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
+
}
|
|
9
|
+
function findKbPackageRoot(startDirectory = import.meta.dir, dependencies = {}) {
|
|
10
|
+
const exists = dependencies.exists ?? existsSync;
|
|
11
|
+
const readText = dependencies.readText ?? ((path) => readFileSync(path, "utf8"));
|
|
12
|
+
let directory = resolve(startDirectory);
|
|
13
|
+
for (let depth = 0;depth < 8; depth += 1) {
|
|
14
|
+
const manifestPath = join(directory, "package.json");
|
|
15
|
+
if (exists(manifestPath)) {
|
|
16
|
+
try {
|
|
17
|
+
const parsed = JSON.parse(readText(manifestPath));
|
|
18
|
+
if (isPackageManifest(parsed) && typeof parsed.name === "string" && parsed.name === "@hraness/wordcell" && typeof parsed.version === "string")
|
|
19
|
+
return directory;
|
|
20
|
+
} catch {}
|
|
21
|
+
}
|
|
22
|
+
const parent = dirname(directory);
|
|
23
|
+
if (parent === directory)
|
|
24
|
+
break;
|
|
25
|
+
directory = parent;
|
|
26
|
+
}
|
|
27
|
+
throw new Error("Could not locate the wordcell package root.");
|
|
28
|
+
}
|
|
29
|
+
function resolvePackageDirectory(packageName, parentUrl = import.meta.url) {
|
|
30
|
+
const manifest = createRequire(parentUrl).resolve(`${packageName}/package.json`);
|
|
31
|
+
return dirname(manifest);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export { findKbPackageRoot, resolvePackageDirectory };
|