@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.
Files changed (93) hide show
  1. package/README.md +170 -64
  2. package/dist/authoring.js +5 -3
  3. package/dist/{authority-4sp9d552.js → authority-06eqhqam.js} +57 -12
  4. package/dist/benchmark.js +4 -4
  5. package/dist/capture.js +6 -5
  6. package/dist/cli.js +39 -33
  7. package/dist/clip/acquire.js +3 -2
  8. package/dist/clip/cli.js +6 -5
  9. package/dist/clip/doctor.js +4 -3
  10. package/dist/clip/jobs.js +3 -3
  11. package/dist/clip/refresh.js +1 -1
  12. package/dist/evaluation-builder.js +20 -19
  13. package/dist/evaluation-kb.js +16 -15
  14. package/dist/graph-authority.js +5 -5
  15. package/dist/graph-percolation.js +7 -7
  16. package/dist/graph.js +1 -1
  17. package/dist/{index-pbr6rv47.js → index-1k595z6v.js} +6 -6
  18. package/dist/{index-0k2x4nn9.js → index-233z9wmn.js} +17 -5
  19. package/dist/index-3agn8scn.js +306 -0
  20. package/dist/index-4knsp9qj.js +34 -0
  21. package/dist/index-66pshdtx.js +341 -0
  22. package/dist/{index-59ssmqqm.js → index-76dbn6pe.js} +1 -1
  23. package/dist/{index-0rfcqab6.js → index-810nfzdj.js} +617 -66
  24. package/dist/index-9rf81m0p.js +368 -0
  25. package/dist/{index-51bap0mq.js → index-bqtqeak3.js} +10 -10
  26. package/dist/{index-9zcpdbjg.js → index-de2w8crk.js} +13 -13
  27. package/dist/{index-bgfzwt4h.js → index-djrcc1yf.js} +6 -6
  28. package/dist/{index-6sw24nvv.js → index-ecqpgr5y.js} +53 -2
  29. package/dist/{index-van48n3g.js → index-fc4dr114.js} +4 -2
  30. package/dist/{index-jzcws0zn.js → index-g5vsqmdy.js} +27 -57
  31. package/dist/index-hmw17zaa.js +1985 -0
  32. package/dist/index-j70m75wd.js +217 -0
  33. package/dist/{index-nd6nynv2.js → index-jk1sgx36.js} +1 -1
  34. package/dist/{index-3ehtt59c.js → index-n386evxj.js} +1 -1
  35. package/dist/{index-vdw5yjfa.js → index-q7tbg07z.js} +110 -20
  36. package/dist/{index-ekpwvbra.js → index-qbssx940.js} +1 -2
  37. package/dist/{index-115b07ap.js → index-rr9kzq4n.js} +5 -5
  38. package/dist/{index-11621h23.js → index-tf4wzjew.js} +1 -1
  39. package/dist/{index-why54q5p.js → index-vnybgywh.js} +4 -4
  40. package/dist/{index-bcfn9xah.js → index-xv80vzfp.js} +7 -7
  41. package/dist/index.js +289 -95
  42. package/dist/percolate.js +2 -2
  43. package/dist/portfolio.js +16 -15
  44. package/dist/publish-model.js +36 -0
  45. package/dist/publish-reader/reader.css +1042 -0
  46. package/dist/publish-reader/reader.js +1534 -0
  47. package/dist/publish-reader/theme.js +92 -0
  48. package/dist/publish-search.js +52 -0
  49. package/dist/publish.js +36 -0
  50. package/dist/rerank-typesafe.js +13 -0
  51. package/dist/rerank.js +14 -0
  52. package/dist/sdk.js +16 -13
  53. package/dist/search.js +3 -3
  54. package/dist/semantic.js +5 -5
  55. package/dist/{support-vm4mkw0k.js → support-1rh2d7mt.js} +38 -32
  56. package/dist/workflows/decision-context.js +15 -14
  57. package/dist/workflows/index.js +15 -14
  58. package/package.json +65 -6
  59. package/skills/wordcell/AGENTS.md +1 -0
  60. package/skills/wordcell/SKILL.md +2 -1
  61. package/skills/wordcell/agents/openai.yaml +1 -1
  62. package/skills/wordcell/references/publish.md +127 -0
  63. package/skills/wordcell/references/query.md +22 -0
  64. package/skills/wordcell/references/refresh.md +14 -0
  65. package/src/authoring-model.ts +29 -0
  66. package/src/authoring-program.ts +38 -3
  67. package/src/authoring.ts +17 -3
  68. package/src/cli-program.ts +441 -12
  69. package/src/graph.ts +1 -1
  70. package/src/index.ts +4 -0
  71. package/src/oh/authority.ts +14 -5
  72. package/src/oh/canonical-rust.ts +127 -0
  73. package/src/oh/projection-rust.ts +63 -0
  74. package/src/oh-adoption.ts +7 -1
  75. package/src/publish-graph.ts +0 -0
  76. package/src/publish-index.ts +195 -0
  77. package/src/publish-markdown.ts +617 -0
  78. package/src/publish-model.ts +599 -0
  79. package/src/publish-nav.ts +204 -0
  80. package/src/publish-pages.ts +382 -0
  81. package/src/publish-reader/reader.css +1042 -0
  82. package/src/publish-reader/reader.ts +1017 -0
  83. package/src/publish-reader/theme.ts +97 -0
  84. package/src/publish-search.ts +418 -0
  85. package/src/publish-select.ts +419 -0
  86. package/src/publish-theme.ts +106 -0
  87. package/src/publish.ts +904 -0
  88. package/src/rerank-credentials.ts +56 -0
  89. package/src/rerank-typesafe.ts +472 -0
  90. package/src/rerank.ts +389 -0
  91. package/src/sdk.ts +157 -6
  92. package/src/serve.ts +180 -0
  93. package/src/vault.ts +23 -9
@@ -0,0 +1,217 @@
1
+ // @bun
2
+ // src/rerank.ts
3
+ var MAX_RERANK_CANDIDATES = 25;
4
+ var MAX_RERANK_SNIPPET_BYTES = 512;
5
+ var MAX_RERANK_STATE_BYTES = 24 * 1024;
6
+ var MALFORMED_RERANK_RESULT_MESSAGE = "Rerank engine returned a malformed result.";
7
+ var MAX_RERANK_DIAGNOSTIC_BYTES = 512;
8
+ var MAX_RERANK_MODEL_BYTES = 128;
9
+ var MAX_RERANK_TOKEN_COUNT = 1e9;
10
+ function dataRecord(value) {
11
+ if (typeof value !== "object" || value === null || Array.isArray(value))
12
+ return null;
13
+ const prototype = Object.getPrototypeOf(value);
14
+ if (prototype !== Object.prototype && prototype !== null)
15
+ return null;
16
+ const keys = Reflect.ownKeys(value);
17
+ if (keys.length > MAX_RERANK_CANDIDATES)
18
+ return null;
19
+ const output = Object.create(null);
20
+ for (const key of keys) {
21
+ if (typeof key !== "string")
22
+ return null;
23
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
24
+ if (descriptor === undefined || !("value" in descriptor) || !descriptor.enumerable)
25
+ return null;
26
+ output[key] = descriptor.value;
27
+ }
28
+ return output;
29
+ }
30
+ function hasOnlyKeys(value, allowed) {
31
+ return Object.keys(value).every((key) => allowed.includes(key));
32
+ }
33
+ function boundedDiagnostic(value) {
34
+ return typeof value === "string" && value !== "" && Buffer.byteLength(value, "utf8") <= MAX_RERANK_DIAGNOSTIC_BYTES && !/[\u0000-\u001f\u007f]/u.test(value);
35
+ }
36
+ function tokenCount(value) {
37
+ return Number.isSafeInteger(value) && value >= 0 && value <= MAX_RERANK_TOKEN_COUNT;
38
+ }
39
+ function inspectRerankDetails(result) {
40
+ const model = result["model"];
41
+ if (model !== undefined && (typeof model !== "string" || !/^[\x20-\x7e]+$/u.test(model) || Buffer.byteLength(model, "utf8") > MAX_RERANK_MODEL_BYTES)) {
42
+ return null;
43
+ }
44
+ const rawUsage = result["usage"];
45
+ let usage;
46
+ if (rawUsage !== undefined) {
47
+ const usageRecord = dataRecord(rawUsage);
48
+ if (usageRecord === null || !hasOnlyKeys(usageRecord, ["inputTokens", "outputTokens"]) || usageRecord["inputTokens"] !== undefined && !tokenCount(usageRecord["inputTokens"]) || usageRecord["outputTokens"] !== undefined && !tokenCount(usageRecord["outputTokens"])) {
49
+ return null;
50
+ }
51
+ usage = {
52
+ ...usageRecord["inputTokens"] === undefined ? {} : { inputTokens: usageRecord["inputTokens"] },
53
+ ...usageRecord["outputTokens"] === undefined ? {} : { outputTokens: usageRecord["outputTokens"] }
54
+ };
55
+ }
56
+ const rawAccounting = result["accounting"];
57
+ let accounting;
58
+ if (rawAccounting !== undefined) {
59
+ const record = dataRecord(rawAccounting);
60
+ if (record === null || !hasOnlyKeys(record, ["candidates", "attempted", "completed", "elapsedMs", "usageComplete"]))
61
+ return null;
62
+ const { candidates, attempted, completed, elapsedMs, usageComplete } = record;
63
+ if (!Number.isSafeInteger(candidates) || candidates < 0 || candidates > MAX_RERANK_CANDIDATES || !Number.isSafeInteger(attempted) || attempted < 0 || attempted > candidates || !Number.isSafeInteger(completed) || completed < 0 || completed > attempted || typeof elapsedMs !== "number" || !Number.isFinite(elapsedMs) || elapsedMs < 0 || elapsedMs > 86400000 || typeof usageComplete !== "boolean" || usageComplete && (completed !== attempted || attempted > 0 && (usage?.inputTokens === undefined || usage.outputTokens === undefined)))
64
+ return null;
65
+ accounting = Object.freeze({
66
+ candidates,
67
+ attempted,
68
+ completed,
69
+ elapsedMs,
70
+ usageComplete
71
+ });
72
+ }
73
+ return {
74
+ ...model === undefined ? {} : { model },
75
+ ...usage === undefined ? {} : { usage: Object.freeze(usage) },
76
+ ...accounting === undefined ? {} : { accounting }
77
+ };
78
+ }
79
+ function inspectRerankResult(value) {
80
+ let details = {};
81
+ const malformed = () => ({
82
+ status: "failed",
83
+ message: MALFORMED_RERANK_RESULT_MESSAGE,
84
+ ...details
85
+ });
86
+ try {
87
+ const result = dataRecord(value);
88
+ if (result === null || typeof result["status"] !== "string") {
89
+ return malformed();
90
+ }
91
+ const inspectedDetails = inspectRerankDetails(result);
92
+ if (inspectedDetails === null)
93
+ return malformed();
94
+ details = inspectedDetails;
95
+ if (result["status"] === "failed" || result["status"] === "unavailable") {
96
+ if (!hasOnlyKeys(result, ["status", "message", "model", "usage", "accounting"]) || !boundedDiagnostic(result["message"])) {
97
+ return malformed();
98
+ }
99
+ return { status: result["status"], message: result["message"], ...details };
100
+ }
101
+ if (result["status"] !== "ready" || !hasOnlyKeys(result, ["status", "ordering", "probabilities", "confidence", "model", "usage", "accounting"])) {
102
+ return malformed();
103
+ }
104
+ if (!Array.isArray(result["ordering"]) || result["ordering"].length > MAX_RERANK_CANDIDATES) {
105
+ return malformed();
106
+ }
107
+ const ordering = [];
108
+ const rawOrdering = result["ordering"];
109
+ for (let index = 0;index < rawOrdering.length; index += 1) {
110
+ const descriptor = Object.getOwnPropertyDescriptor(rawOrdering, String(index));
111
+ const id = descriptor !== undefined && "value" in descriptor ? descriptor.value : undefined;
112
+ if (typeof id !== "string" || id === "" || Buffer.byteLength(id, "utf8") > MAX_RERANK_STATE_BYTES) {
113
+ return malformed();
114
+ }
115
+ ordering.push(id);
116
+ }
117
+ const rawProbabilities = dataRecord(result["probabilities"]);
118
+ if (rawProbabilities === null) {
119
+ return malformed();
120
+ }
121
+ const probabilities = Object.create(null);
122
+ for (const [id, probability] of Object.entries(rawProbabilities)) {
123
+ if (typeof probability !== "number" || !Number.isFinite(probability) || probability < 0 || probability > 1) {
124
+ return malformed();
125
+ }
126
+ probabilities[id] = probability;
127
+ }
128
+ const confidence = result["confidence"];
129
+ if (confidence !== undefined && (typeof confidence !== "number" || !Number.isFinite(confidence) || confidence < 0 || confidence > 1)) {
130
+ return malformed();
131
+ }
132
+ return {
133
+ status: "ready",
134
+ ordering: Object.freeze(ordering),
135
+ probabilities,
136
+ ...confidence === undefined ? {} : { confidence },
137
+ ...details
138
+ };
139
+ } catch {
140
+ return malformed();
141
+ }
142
+ }
143
+ function failedRerank(hits, message, details) {
144
+ const result = {
145
+ status: "failed",
146
+ message,
147
+ ...details.model === undefined ? {} : { model: details.model },
148
+ ...details.usage === undefined ? {} : { usage: details.usage },
149
+ ...details.accounting === undefined ? {} : { accounting: details.accounting }
150
+ };
151
+ return { status: "failed", hits, placements: new Map, result, message };
152
+ }
153
+ function applyRerank(hits, result, expectedWindowIds) {
154
+ const inspected = inspectRerankResult(result);
155
+ if (inspected.status !== "ready") {
156
+ return {
157
+ status: inspected.status,
158
+ hits,
159
+ placements: new Map,
160
+ result: inspected,
161
+ message: inspected.message
162
+ };
163
+ }
164
+ const ordering = inspected.ordering;
165
+ if (expectedWindowIds !== undefined && (ordering.length !== expectedWindowIds.length || expectedWindowIds.some((id) => !ordering.includes(id)))) {
166
+ return failedRerank(hits, MALFORMED_RERANK_RESULT_MESSAGE, inspected);
167
+ }
168
+ const windowIds = new Set;
169
+ for (const id of ordering) {
170
+ if (windowIds.has(id)) {
171
+ return failedRerank(hits, "Rerank ordering contained a duplicate candidate id.", inspected);
172
+ }
173
+ windowIds.add(id);
174
+ }
175
+ const window = hits.slice(0, ordering.length);
176
+ const windowById = new Map(window.map((hit) => [hit.id, hit]));
177
+ for (const id of ordering) {
178
+ if (!windowById.has(id)) {
179
+ return failedRerank(hits, "Rerank ordering contained an unknown candidate id.", inspected);
180
+ }
181
+ }
182
+ for (const hit of window) {
183
+ if (!windowIds.has(hit.id)) {
184
+ return failedRerank(hits, "Rerank ordering omitted a window candidate id.", inspected);
185
+ }
186
+ }
187
+ const probabilityKeys = Object.keys(inspected.probabilities);
188
+ for (const id of probabilityKeys) {
189
+ if (!windowIds.has(id)) {
190
+ return failedRerank(hits, "Rerank probabilities contained an unknown candidate id.", inspected);
191
+ }
192
+ }
193
+ for (const id of ordering) {
194
+ if (inspected.probabilities[id] === undefined) {
195
+ return failedRerank(hits, "Rerank probability for a candidate id was missing or invalid.", inspected);
196
+ }
197
+ }
198
+ const probabilityOf = (id) => inspected.probabilities[id];
199
+ const sorted = window.toSorted((left, right) => Number(right.identity === true) - Number(left.identity === true) || probabilityOf(right.id) - probabilityOf(left.id) || left.rank - right.rank || left.id.localeCompare(right.id));
200
+ const placements = new Map;
201
+ const reordered = sorted.map((hit, index) => {
202
+ placements.set(hit.id, {
203
+ baselineRank: hit.rank,
204
+ rerankRank: index + 1,
205
+ probability: probabilityOf(hit.id)
206
+ });
207
+ return hit.rank === index + 1 ? hit : { ...hit, rank: index + 1 };
208
+ });
209
+ return {
210
+ status: "ready",
211
+ hits: Object.freeze([...reordered, ...hits.slice(ordering.length)]),
212
+ placements,
213
+ result: inspected
214
+ };
215
+ }
216
+
217
+ export { MAX_RERANK_CANDIDATES, MAX_RERANK_SNIPPET_BYTES, MAX_RERANK_STATE_BYTES, applyRerank };
@@ -5,7 +5,7 @@ import {
5
5
  isCanonicalNoteId,
6
6
  isCanonicalRelationPredicate,
7
7
  lookupNote
8
- } from "./index-ekpwvbra.js";
8
+ } from "./index-qbssx940.js";
9
9
 
10
10
  // src/percolate.ts
11
11
  import { createHash } from "crypto";
@@ -1,7 +1,7 @@
1
1
  // @bun
2
2
  import {
3
3
  fuseRankedCandidates
4
- } from "./index-why54q5p.js";
4
+ } from "./index-vnybgywh.js";
5
5
 
6
6
  // src/benchmark.ts
7
7
  var MAX_BENCHMARK_CASES = 500;
@@ -1,8 +1,4 @@
1
1
  // @bun
2
- import {
3
- UntrustedContentBudgetError,
4
- createUntrustedToolResult
5
- } from "./index-4j3tt0c3.js";
6
2
  import {
7
3
  expandSearchRequest,
8
4
  parseSearchRules,
@@ -11,20 +7,26 @@ import {
11
7
  import {
12
8
  openSemanticSearchSession,
13
9
  recommendedEmbeddingModel
14
- } from "./index-115b07ap.js";
10
+ } from "./index-rr9kzq4n.js";
11
+ import {
12
+ UntrustedContentBudgetError,
13
+ createUntrustedToolResult
14
+ } from "./index-4j3tt0c3.js";
15
+ import {
16
+ MAX_RERANK_CANDIDATES,
17
+ MAX_RERANK_SNIPPET_BYTES,
18
+ applyRerank
19
+ } from "./index-j70m75wd.js";
15
20
  import {
16
21
  percolateWithGraph
17
- } from "./index-bgfzwt4h.js";
22
+ } from "./index-djrcc1yf.js";
18
23
  import {
19
24
  openGraphAuthority
20
- } from "./index-bcfn9xah.js";
25
+ } from "./index-xv80vzfp.js";
21
26
  import {
22
27
  validateGraphPercolationOptions,
23
28
  validateGraphQueryRequest
24
- } from "./index-11621h23.js";
25
- import {
26
- scanVault
27
- } from "./index-0k2x4nn9.js";
29
+ } from "./index-tf4wzjew.js";
28
30
  import {
29
31
  GitHistoryError,
30
32
  gitHistoryForNotes,
@@ -39,17 +41,20 @@ import {
39
41
  fuseRankedCandidates,
40
42
  searchExactVault,
41
43
  validateSearchQuery
42
- } from "./index-why54q5p.js";
44
+ } from "./index-vnybgywh.js";
43
45
  import {
44
- queryVault
45
- } from "./index-48pz4jpc.js";
46
+ scanVault
47
+ } from "./index-233z9wmn.js";
46
48
  import {
47
49
  NavigationBudgetError,
48
50
  navigateLinks
49
51
  } from "./index-d13v9ckt.js";
52
+ import {
53
+ queryVault
54
+ } from "./index-48pz4jpc.js";
50
55
  import {
51
56
  lookupNote
52
- } from "./index-ekpwvbra.js";
57
+ } from "./index-qbssx940.js";
53
58
 
54
59
  // src/sdk.ts
55
60
  import { resolve } from "path";
@@ -83,6 +88,9 @@ function noteOrThrow(notes, query) {
83
88
  function errorMessage(error) {
84
89
  return error instanceof Error ? error.message : String(error);
85
90
  }
91
+ function searchEvidenceRank(item) {
92
+ return item.kind === "rerank" ? item.rerankRank : item.rank;
93
+ }
86
94
  function utf8Prefix(value, maximumBytes) {
87
95
  let bytes = 0;
88
96
  let end = 0;
@@ -203,6 +211,29 @@ function checkedHistoryRequest(value) {
203
211
  function validateKnowledgeBaseSearchHistory(value) {
204
212
  checkedHistoryRequest(value);
205
213
  }
214
+ function checkedRerankRequest(value, rerankers) {
215
+ if (value === undefined)
216
+ return { enabled: false };
217
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
218
+ throw new TypeError("Search rerank options must be an options object.");
219
+ }
220
+ const options = value;
221
+ if (options.engine !== "typesafe") {
222
+ throw new Error('Search rerank engine must be "typesafe".');
223
+ }
224
+ const reranker = rerankers?.find((entry) => entry.id === options.engine);
225
+ if (reranker === undefined) {
226
+ throw new Error(`Search rerank engine ${JSON.stringify(options.engine)} is not available in this session.`);
227
+ }
228
+ const limit = options.limit ?? MAX_RERANK_CANDIDATES;
229
+ if (!Number.isSafeInteger(limit) || limit < 2 || limit > MAX_RERANK_CANDIDATES) {
230
+ throw new RangeError(`Search rerank limit must be an integer from 2 through ${MAX_RERANK_CANDIDATES}.`);
231
+ }
232
+ if (options.signal !== undefined && !(options.signal instanceof AbortSignal)) {
233
+ throw new TypeError("Search rerank signal must be an AbortSignal.");
234
+ }
235
+ return { enabled: true, limit, reranker, ...options.signal === undefined ? {} : { signal: options.signal } };
236
+ }
206
237
  async function openKnowledgeBase(options, dependencies = {}) {
207
238
  const searchRules = options.searchRules === undefined ? null : parseSearchRules(options.searchRules);
208
239
  if (options.embeddingModelFile !== undefined && options.embeddingModelLease !== undefined) {
@@ -322,6 +353,7 @@ async function openKnowledgeBase(options, dependencies = {}) {
322
353
  }
323
354
  const historyRequest = checkedHistoryRequest(effectiveOptions.history);
324
355
  const graphOptions = checkedGraphOptions(effectiveOptions.graph);
356
+ const rerankRequest = checkedRerankRequest(effectiveOptions.rerank, dependencies.rerankers);
325
357
  const explicitSeeds = graphOptions === null ? [] : resolvedGraphSeeds(snapshot.notes, graphOptions.related);
326
358
  const historyNoteLimit = historyRequest.enabled ? historyRequest.noteLimit : null;
327
359
  const allowedIds = new Set(queryVault(snapshot.notes, snapshot.analysis, {
@@ -415,7 +447,8 @@ async function openKnowledgeBase(options, dependencies = {}) {
415
447
  const fused = fuseRankedCandidates(lanes);
416
448
  const ordered = fused.toSorted((left, right) => Number(exactById.get(right.id)?.hit.identity ?? false) - Number(exactById.get(left.id)?.hit.identity ?? false) || left.rank - right.rank || left.id.localeCompare(right.id));
417
449
  const shouldApplyPriority = ordering === "priority-then-relevance" && searchRules !== null && searchRules.priorityRules.length > 0;
418
- const relevanceResults = (shouldApplyPriority ? ordered : ordered.slice(0, limit)).map((candidate, index) => {
450
+ const resultWindow = rerankRequest.enabled ? Math.max(limit, rerankRequest.limit) : limit;
451
+ const relevanceResults = (shouldApplyPriority ? ordered : ordered.slice(0, resultWindow)).map((candidate, index) => {
419
452
  const note = notesById.get(candidate.id);
420
453
  if (note === undefined) {
421
454
  throw new Error(`Fused retrieval returned unknown note ${JSON.stringify(candidate.id)}.`);
@@ -458,10 +491,67 @@ async function openKnowledgeBase(options, dependencies = {}) {
458
491
  contributions: candidate.contributions
459
492
  };
460
493
  });
494
+ let rankedResults = relevanceResults;
495
+ if (rerankRequest.enabled) {
496
+ const candidates = relevanceResults.slice(0, rerankRequest.limit).map((hit, index) => ({
497
+ id: hit.id,
498
+ baselineRank: index + 1,
499
+ score: hit.score,
500
+ title: hit.title,
501
+ path: hit.path,
502
+ snippet: utf8Prefix(hit.snippet, MAX_RERANK_SNIPPET_BYTES).value
503
+ }));
504
+ const outcome = await Promise.resolve().then(() => rerankRequest.reranker.rerank({
505
+ query: effectiveQuery,
506
+ candidates,
507
+ ...rerankRequest.signal === undefined ? {} : { signal: rerankRequest.signal }
508
+ })).then((result) => ({ ok: true, result }), (error) => ({ ok: false, error }));
509
+ const applied = applyRerank(relevanceResults, outcome.ok ? outcome.result : {
510
+ status: "failed",
511
+ message: "Rerank engine failed before returning a result."
512
+ }, candidates.map(({ id }) => id));
513
+ rankedResults = applied.hits.map((hit) => {
514
+ const placement = applied.placements.get(hit.id);
515
+ if (placement === undefined)
516
+ return hit;
517
+ return {
518
+ ...hit,
519
+ evidence: [
520
+ ...hit.evidence,
521
+ {
522
+ kind: "rerank",
523
+ engine: rerankRequest.reranker.id,
524
+ baselineRank: placement.baselineRank,
525
+ rerankRank: placement.rerankRank,
526
+ ...placement.probability === undefined ? {} : { probability: placement.probability }
527
+ }
528
+ ]
529
+ };
530
+ });
531
+ const resultDetails = {
532
+ ...applied.result.model === undefined ? {} : { model: applied.result.model },
533
+ ...applied.result.usage === undefined ? {} : { usage: applied.result.usage },
534
+ ...applied.result.accounting === undefined ? {} : { accounting: applied.result.accounting }
535
+ };
536
+ const details = [];
537
+ if (resultDetails.model !== undefined)
538
+ details.push(resultDetails.model);
539
+ if (resultDetails.usage !== undefined) {
540
+ details.push(`${(resultDetails.usage.inputTokens ?? 0).toLocaleString("en-US")} input tokens, ` + `${(resultDetails.usage.outputTokens ?? 0).toLocaleString("en-US")} output tokens`);
541
+ }
542
+ const rerankMessage = applied.status === "ready" ? details.length === 0 ? undefined : details.join("; ") : applied.message ?? "Rerank engine did not return a result.";
543
+ diagnostics.push({
544
+ lane: "rerank",
545
+ ...Object.keys(resultDetails).length === 0 ? {} : { rerank: resultDetails },
546
+ status: applied.status === "failed" ? "degraded" : applied.status,
547
+ results: applied.status === "ready" ? applied.placements.size : 0,
548
+ ...rerankMessage === undefined ? {} : { message: rerankMessage }
549
+ });
550
+ }
461
551
  let priorityTrace = null;
462
- let results = relevanceResults.slice(0, limit);
552
+ let results = rankedResults.slice(0, limit);
463
553
  if (shouldApplyPriority && searchRules !== null) {
464
- const prioritized = prioritizeSearchHits(relevanceResults, searchRules, {
554
+ const prioritized = prioritizeSearchHits(rankedResults, searchRules, {
465
555
  ...options.vaultId === undefined ? {} : { vaultId: options.vaultId }
466
556
  });
467
557
  const selectedHits = prioritized.hits.slice(0, limit);
@@ -696,7 +786,7 @@ Evidence: `))
696
786
  return writer.result();
697
787
  if (!append("#"))
698
788
  return writer.result();
699
- if (!append(String(item.rank)))
789
+ if (!append(String(searchEvidenceRank(item))))
700
790
  return writer.result();
701
791
  }
702
792
  if (!append(`
@@ -1015,4 +1105,4 @@ function packUntrustedSearchContext(result, options = {}) {
1015
1105
  });
1016
1106
  }
1017
1107
 
1018
- export { MAX_SEARCH_RESULTS, MAX_SEARCH_CANDIDATES, DEFAULT_SEARCH_RESULTS, MIN_UNTRUSTED_CONTEXT_BYTES, MAX_SEARCH_RELATED_SEEDS, MAX_SEARCH_NOTE_REFERENCE_BYTES, validateKnowledgeBaseSearchHistory, openKnowledgeBase, packSearchContext, packUntrustedSearchContext };
1108
+ export { MAX_SEARCH_RESULTS, MAX_SEARCH_CANDIDATES, DEFAULT_SEARCH_RESULTS, MIN_UNTRUSTED_CONTEXT_BYTES, MAX_SEARCH_RELATED_SEEDS, MAX_SEARCH_NOTE_REFERENCE_BYTES, searchEvidenceRank, validateKnowledgeBaseSearchHistory, openKnowledgeBase, packSearchContext, packUntrustedSearchContext };
@@ -374,8 +374,7 @@ function aliasesFromMetadata(metadata) {
374
374
  return value.filter((candidate) => typeof candidate === "string" && candidate.trim() !== "");
375
375
  }
376
376
  function frontmatterOf(content, path) {
377
- const lines = content.split(`
378
- `);
377
+ const lines = content.split(/\r?\n/u);
379
378
  if (lines[0]?.trim() !== "---") {
380
379
  return {
381
380
  values: new Map,
@@ -1,15 +1,15 @@
1
1
  // @bun
2
+ import {
3
+ fuseRankedCandidates,
4
+ validateSearchQuery
5
+ } from "./index-vnybgywh.js";
2
6
  import {
3
7
  MAX_NOTE_UTF8_BYTES,
4
8
  MAX_SCANNED_NOTES,
5
9
  MAX_VAULT_UTF8_BYTES,
6
10
  VaultScanBudgetError,
7
11
  scanVault
8
- } from "./index-0k2x4nn9.js";
9
- import {
10
- fuseRankedCandidates,
11
- validateSearchQuery
12
- } from "./index-why54q5p.js";
12
+ } from "./index-233z9wmn.js";
13
13
 
14
14
  // src/semantic.ts
15
15
  import { createHash as createHash2 } from "crypto";
@@ -5,7 +5,7 @@ import {
5
5
  import {
6
6
  isCanonicalNoteId,
7
7
  isCanonicalRelationPredicate
8
- } from "./index-ekpwvbra.js";
8
+ } from "./index-qbssx940.js";
9
9
 
10
10
  // src/graph-authority-model.ts
11
11
  var GRAPH_LIMITS = Object.freeze({
@@ -1,13 +1,13 @@
1
1
  // @bun
2
- import {
3
- queryVault
4
- } from "./index-48pz4jpc.js";
5
2
  import {
6
3
  navigateLinks
7
4
  } from "./index-d13v9ckt.js";
5
+ import {
6
+ queryVault
7
+ } from "./index-48pz4jpc.js";
8
8
  import {
9
9
  lookupNote
10
- } from "./index-ekpwvbra.js";
10
+ } from "./index-qbssx940.js";
11
11
 
12
12
  // src/search.ts
13
13
  var MAX_EXACT_RESULTS = 500;
@@ -3,23 +3,23 @@ import {
3
3
  GRAPH_LIMITS,
4
4
  GraphAuthorityError,
5
5
  validateGraphQueryRequest
6
- } from "./index-11621h23.js";
6
+ } from "./index-tf4wzjew.js";
7
7
  import {
8
8
  scanVault
9
- } from "./index-0k2x4nn9.js";
10
- import {
11
- acquireFileLease
12
- } from "./index-3rm7cz6h.js";
9
+ } from "./index-233z9wmn.js";
13
10
  import {
14
11
  analyzeAuthoredRepositoryScopes
15
12
  } from "./index-06c9ctr6.js";
13
+ import {
14
+ acquireFileLease
15
+ } from "./index-3rm7cz6h.js";
16
16
  import {
17
17
  VaultAnalysisBudgetError,
18
18
  analyzeVault,
19
19
  documentIdState,
20
20
  isCanonicalNoteId,
21
21
  parseNote
22
- } from "./index-ekpwvbra.js";
22
+ } from "./index-qbssx940.js";
23
23
  import {
24
24
  __require
25
25
  } from "./index-z1w83f81.js";
@@ -231,7 +231,7 @@ import { lstat, open } from "fs/promises";
231
231
  var graphCacheFileSystem = { lstat, open };
232
232
 
233
233
  // src/graph-authority.ts
234
- var openOhGraphAdapter = async (...args) => await (await import("./authority-4sp9d552.js")).openOhGraphAdapter(...args);
234
+ var openOhGraphAdapter = async (...args) => await (await import("./authority-06eqhqam.js")).openOhGraphAdapter(...args);
235
235
  var MAX_CACHE_BYTES = 67108864;
236
236
  var ignoredCache = `# Disposable Wordcell graph state. Rebuild from Markdown.
237
237
  *