@gmickel/gno 2.15.0 → 2.17.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.
Files changed (218) hide show
  1. package/README.md +1 -1
  2. package/assets/skill/SKILL.md +27 -0
  3. package/assets/skill/cli-reference.md +24 -15
  4. package/assets/spa-production.json.gz +0 -0
  5. package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
  6. package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
  7. package/browser-extension/dist/manifest.json +1 -1
  8. package/package.json +1 -1
  9. package/spec/cli.md +43 -3
  10. package/spec/db/schema.sql +53 -1
  11. package/spec/mcp.md +9 -3
  12. package/spec/output-schemas/doctor.schema.json +27 -0
  13. package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
  14. package/spec/output-schemas/search-results.schema.json +14 -0
  15. package/spec/output-schemas/status.schema.json +22 -0
  16. package/src/cli/commands/agents/commands.ts +1 -1
  17. package/src/cli/commands/ask.ts +1 -1
  18. package/src/cli/commands/context-build.ts +1 -1
  19. package/src/cli/commands/doctor.ts +101 -29
  20. package/src/cli/commands/embed.ts +2 -2
  21. package/src/cli/commands/links.ts +30 -6
  22. package/src/cli/commands/mcp/install.ts +2 -2
  23. package/src/cli/commands/mcp/status.ts +1 -1
  24. package/src/cli/commands/mcp/uninstall.ts +1 -1
  25. package/src/cli/commands/query.ts +1 -1
  26. package/src/cli/commands/shared.ts +4 -4
  27. package/src/cli/commands/skill/install.ts +1 -1
  28. package/src/cli/commands/skill/paths-cmd.ts +1 -1
  29. package/src/cli/commands/skill/uninstall.ts +1 -1
  30. package/src/cli/commands/status.ts +75 -58
  31. package/src/cli/commands/vec.ts +180 -8
  32. package/src/cli/config-cache.ts +86 -0
  33. package/src/cli/globals.ts +64 -0
  34. package/src/cli/program.ts +63 -36
  35. package/src/cli/run.ts +121 -67
  36. package/src/cli/runtime-health.ts +132 -122
  37. package/src/cli/session-binding.ts +11 -2
  38. package/src/config/saver.ts +8 -0
  39. package/src/config/types.ts +6 -0
  40. package/src/converters/adapters/browser-export/formats.ts +25 -15
  41. package/src/converters/adapters/email/adapter.ts +37 -53
  42. package/src/converters/adapters/email/html.ts +37 -20
  43. package/src/converters/adapters/email/mime.ts +71 -39
  44. package/src/converters/adapters/ical/adapter.ts +20 -12
  45. package/src/converters/adapters/jsonl/adapter.ts +8 -6
  46. package/src/converters/adapters/shared/html-text.ts +55 -37
  47. package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
  48. package/src/converters/adapters/shared/utf8-lines.ts +69 -31
  49. package/src/converters/adapters/transcript/adapter.ts +12 -7
  50. package/src/converters/adapters/xlsx/adapter.ts +10 -7
  51. package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
  52. package/src/converters/canonicalize.ts +17 -3
  53. package/src/converters/native/markdown.ts +24 -17
  54. package/src/converters/native/plaintext.ts +5 -6
  55. package/src/converters/registry.ts +130 -8
  56. package/src/core/activation-status.ts +4 -8
  57. package/src/core/change-diff.ts +38 -11
  58. package/src/core/context-compiler.ts +17 -18
  59. package/src/core/context-evidence.ts +116 -25
  60. package/src/core/context-verifier.ts +70 -31
  61. package/src/core/file-lock.ts +10 -2
  62. package/src/core/graph-analysis.ts +3 -3
  63. package/src/core/link-inventory-markdown.ts +2 -2
  64. package/src/core/links.ts +20 -87
  65. package/src/core/memory-fence.ts +16 -9
  66. package/src/core/memory-recall.ts +168 -34
  67. package/src/core/path-rules.ts +143 -0
  68. package/src/core/retrieval-trace-session.ts +3 -0
  69. package/src/core/retrieval-trace.ts +9 -0
  70. package/src/core/section-parse.ts +16 -6
  71. package/src/core/typed-metadata.ts +68 -0
  72. package/src/core/vector-partition-status.ts +13 -0
  73. package/src/core/wiki-link-syntax.ts +88 -0
  74. package/src/embed/backlog.ts +142 -60
  75. package/src/embed/retry.ts +39 -33
  76. package/src/embed/variant-backlog.ts +582 -116
  77. package/src/embed/variant-retry.ts +157 -48
  78. package/src/index.ts +3 -3
  79. package/src/ingestion/budget-error-codes.ts +13 -0
  80. package/src/ingestion/chunker.ts +60 -49
  81. package/src/ingestion/compiled-context.ts +4 -5
  82. package/src/ingestion/convert-file.ts +1 -1
  83. package/src/ingestion/document-metadata.ts +16 -9
  84. package/src/ingestion/excluded-ranges.ts +97 -0
  85. package/src/ingestion/file-processor.ts +122 -37
  86. package/src/ingestion/frontmatter.ts +35 -7
  87. package/src/ingestion/graph-reconciliation.ts +187 -51
  88. package/src/ingestion/language.ts +66 -61
  89. package/src/ingestion/position.ts +5 -5
  90. package/src/ingestion/prepare-file.ts +50 -29
  91. package/src/ingestion/record-adapter-canonical.ts +37 -26
  92. package/src/ingestion/record-adapter.ts +46 -26
  93. package/src/ingestion/record-container.ts +121 -53
  94. package/src/ingestion/record-path.ts +5 -2
  95. package/src/ingestion/source-availability/darwin-io.ts +10 -7
  96. package/src/ingestion/source-availability/darwin-path.ts +21 -3
  97. package/src/ingestion/source-availability/readers.ts +51 -0
  98. package/src/ingestion/strip.ts +39 -105
  99. package/src/ingestion/sync.ts +692 -386
  100. package/src/ingestion/typed-metadata.ts +10 -4
  101. package/src/ingestion/walker.ts +485 -158
  102. package/src/llm/cache.ts +128 -84
  103. package/src/llm/http-inference.ts +112 -35
  104. package/src/llm/http-policy.ts +101 -0
  105. package/src/llm/httpEmbedding.ts +8 -1
  106. package/src/llm/httpGeneration.ts +5 -1
  107. package/src/llm/httpRerank.ts +5 -1
  108. package/src/llm/inference-scope.ts +15 -2
  109. package/src/llm/lazy-ports.ts +33 -3
  110. package/src/llm/lockfile.ts +34 -7
  111. package/src/llm/model-cleanup.ts +24 -0
  112. package/src/llm/native-worker/client.ts +23 -12
  113. package/src/llm/native-worker/dispatcher.ts +19 -9
  114. package/src/llm/native-worker/embedding-identity.ts +42 -16
  115. package/src/llm/native-worker/entry.ts +2 -1
  116. package/src/llm/native-worker/owner.ts +1 -0
  117. package/src/llm/native-worker/ports.ts +86 -23
  118. package/src/llm/native-worker/protocol.ts +386 -55
  119. package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
  120. package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
  121. package/src/llm/nodeLlamaCpp/generation.ts +194 -30
  122. package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
  123. package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
  124. package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
  125. package/src/llm/types.ts +14 -0
  126. package/src/mcp/context.ts +342 -23
  127. package/src/mcp/http-transport.ts +21 -3
  128. package/src/mcp/tool-profile-types.ts +62 -0
  129. package/src/mcp/tool-profile.ts +32 -56
  130. package/src/mcp/tools/context.ts +5 -1
  131. package/src/mcp/tools/index.ts +269 -191
  132. package/src/mcp/tools/links.ts +14 -6
  133. package/src/mcp/tools/query.ts +60 -37
  134. package/src/mcp/tools/vsearch.ts +25 -14
  135. package/src/pipeline/answer.ts +133 -40
  136. package/src/pipeline/claim-verification.ts +293 -189
  137. package/src/pipeline/claim-verifier.ts +6 -7
  138. package/src/pipeline/egress-lineage.ts +37 -26
  139. package/src/pipeline/exclude.ts +34 -11
  140. package/src/pipeline/expansion.ts +233 -19
  141. package/src/pipeline/explain.ts +17 -2
  142. package/src/pipeline/filters.ts +169 -33
  143. package/src/pipeline/graph-retrieval.ts +117 -61
  144. package/src/pipeline/hybrid.ts +626 -330
  145. package/src/pipeline/hydration.ts +86 -24
  146. package/src/pipeline/intent.ts +15 -7
  147. package/src/pipeline/owner-fusion.ts +61 -19
  148. package/src/pipeline/query-language.ts +15 -2
  149. package/src/pipeline/rerank.ts +15 -22
  150. package/src/pipeline/search.ts +193 -72
  151. package/src/pipeline/snippet.ts +15 -2
  152. package/src/pipeline/temporal.ts +51 -10
  153. package/src/pipeline/types.ts +7 -0
  154. package/src/pipeline/vsearch.ts +269 -154
  155. package/src/publish/attachment-raster.ts +2 -16
  156. package/src/publish/encrypted-export.ts +15 -5
  157. package/src/serve/browse-tree.ts +50 -42
  158. package/src/serve/connectors.ts +2 -1
  159. package/src/serve/context.ts +13 -4
  160. package/src/serve/doc-events.ts +3 -0
  161. package/src/serve/public/app.tsx +49 -21
  162. package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
  163. package/src/serve/public/components/CaptureModal.tsx +14 -10
  164. package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
  165. package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
  166. package/src/serve/public/globals.built.css +1 -1
  167. package/src/serve/public/globals.css +19 -0
  168. package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
  169. package/src/serve/public/lib/metadata-filter.ts +234 -9
  170. package/src/serve/public/pages/Browse.tsx +61 -27
  171. package/src/serve/public/pages/DocView.tsx +44 -25
  172. package/src/serve/public/pages/GraphView.tsx +8 -3
  173. package/src/serve/resident-runtime.ts +199 -48
  174. package/src/serve/routes/api.ts +98 -67
  175. package/src/serve/routes/links.ts +25 -5
  176. package/src/serve/server.ts +1370 -1180
  177. package/src/serve/spa-bundle-source.ts +52 -27
  178. package/src/serve/status.ts +101 -52
  179. package/src/serve/watch-reconciliation-fallback.ts +11 -7
  180. package/src/serve/watch-reconciliation-shared.ts +42 -4
  181. package/src/serve/watch-reconciliation.ts +21 -8
  182. package/src/serve/watch-service-events.ts +7 -1
  183. package/src/serve/watch-service-hosts.ts +3 -1
  184. package/src/serve/watch-service.ts +46 -21
  185. package/src/serve/watch-snapshot-scan.ts +6 -15
  186. package/src/sessions/archive.ts +20 -8
  187. package/src/sessions/sanitize.ts +38 -18
  188. package/src/sessions/service.ts +180 -102
  189. package/src/store/migrations/037-performance-indexes.ts +56 -0
  190. package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
  191. package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
  192. package/src/store/migrations/index.ts +6 -0
  193. package/src/store/sqlite/adapter.ts +1260 -651
  194. package/src/store/sqlite/chunking-policy.ts +15 -1
  195. package/src/store/sqlite/eligibility.ts +110 -70
  196. package/src/store/sqlite/graph-neighbors.ts +71 -46
  197. package/src/store/sqlite/graph-reference-state.ts +27 -3
  198. package/src/store/sqlite/graph-similarity.ts +59 -12
  199. package/src/store/sqlite/metadata-predicate.ts +123 -28
  200. package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
  201. package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
  202. package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
  203. package/src/store/types.ts +32 -0
  204. package/src/store/vector/coarse-router.ts +312 -0
  205. package/src/store/vector/eligibility.ts +39 -0
  206. package/src/store/vector/lazy.ts +17 -0
  207. package/src/store/vector/partition-index.ts +333 -59
  208. package/src/store/vector/proof-cache.ts +209 -0
  209. package/src/store/vector/runtime-compat.ts +6 -0
  210. package/src/store/vector/sqlite-vec.ts +270 -162
  211. package/src/store/vector/stats.ts +37 -73
  212. package/src/store/vector/status.ts +169 -53
  213. package/src/store/vector/stored-vectors.ts +131 -45
  214. package/src/store/vector/types.ts +19 -0
  215. package/src/store/vector/v2-mirror.ts +669 -0
  216. package/src/store/vector/variant-search.ts +1187 -111
  217. package/src/store/vector/variants.ts +964 -160
  218. package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
@@ -35,15 +35,18 @@ const SHORT_OUTPUT_MIN_BYTES = 1000;
35
35
  * normalized as markitdown-ts normalizes every result (line endings, outer
36
36
  * whitespace, at most one blank line).
37
37
  */
38
- export function workbookToMarkdown(workbook: XLSX.WorkBook): string {
39
- let markdown = "";
38
+ export async function workbookToMarkdown(
39
+ workbook: XLSX.WorkBook
40
+ ): Promise<string> {
41
+ const sections: string[] = [];
40
42
  for (const name of workbook.SheetNames) {
41
43
  const sheet = workbook.Sheets[name];
42
44
  if (sheet?.["!ref"]) {
43
- markdown += `## ${name}\n${sheetToMarkdown(sheet)}\n\n`;
45
+ sections.push(`## ${name}\n${await sheetToMarkdown(sheet)}\n\n`);
44
46
  }
45
47
  }
46
- return markdown
48
+ return sections
49
+ .join("")
47
50
  .replace(/\r\n|\r|\n/g, "\n")
48
51
  .trim()
49
52
  .replace(/\n{3,}/g, "\n\n");
@@ -58,11 +61,11 @@ export const xlsxAdapter: Converter = {
58
61
  },
59
62
 
60
63
  convert(input: ConvertInput): Promise<ConvertResult> {
61
- return Promise.resolve(convertWorkbook(input));
64
+ return convertWorkbook(input);
62
65
  },
63
66
  };
64
67
 
65
- function convertWorkbook(input: ConvertInput): ConvertResult {
68
+ async function convertWorkbook(input: ConvertInput): Promise<ConvertResult> {
66
69
  if (input.bytes.length > input.limits.maxBytes) {
67
70
  return { ok: false, error: tooLargeError(input, CONVERTER_ID) };
68
71
  }
@@ -104,7 +107,7 @@ function convertWorkbook(input: ConvertInput): ConvertResult {
104
107
  };
105
108
  }
106
109
 
107
- const markdown = workbookToMarkdown(workbook);
110
+ const markdown = await workbookToMarkdown(workbook);
108
111
  if (!markdown) {
109
112
  return {
110
113
  ok: false,
@@ -22,10 +22,6 @@
22
22
 
23
23
  import type { CellObject, WorkSheet } from "xlsx";
24
24
 
25
- // @ts-expect-error -- @joplin/turndown-plugin-gfm ships no types
26
- import turndownPluginGfm from "@joplin/turndown-plugin-gfm";
27
- // @ts-expect-error -- turndown ships no types
28
- import TurndownService from "turndown";
29
25
  import * as XLSX from "xlsx";
30
26
 
31
27
  /** The part of turndown's API this module uses. */
@@ -43,7 +39,7 @@ interface Turndown {
43
39
  }
44
40
  ): Turndown;
45
41
  }
46
- const TurndownConstructor = TurndownService as new (options: {
42
+ type TurndownConstructorType = new (options: {
47
43
  headingStyle: "atx";
48
44
  }) => Turndown;
49
45
 
@@ -101,40 +97,60 @@ const LINE_BREAK = " \n";
101
97
  * and trailing space dropped (cells and line breaks are block boundaries),
102
98
  * escaped on its own; every line break renders, empty lines included.
103
99
  */
100
+ const plainLineContent = (raw: string): string => {
101
+ // The HTML parser turns the escaped NUL (&#x0000;) into U+FFFD.
102
+ const line = raw
103
+ .replaceAll("\u0000", "\uFFFD")
104
+ .replace(/[ \r\n\t]+/g, " ")
105
+ .replace(/^ | $/g, "");
106
+ return line ? escapeMarkdown(line) : "";
107
+ };
108
+
104
109
  const plainCellContent = (text: string): string => {
110
+ if (!text.includes("\n")) {
111
+ return plainLineContent(text);
112
+ }
105
113
  const lines: string[] = [];
106
114
  for (const raw of text.split("\n")) {
107
- // The HTML parser turns the escaped NUL (&#x0000;) into U+FFFD.
108
- const line = raw
109
- .replaceAll("\u0000", "\uFFFD")
110
- .replace(/[ \r\n\t]+/g, " ")
111
- .replace(/^ | $/g, "");
112
- lines.push(line ? escapeMarkdown(line) : "");
115
+ lines.push(plainLineContent(raw));
113
116
  }
114
117
  return lines.join(LINE_BREAK);
115
118
  };
116
119
 
117
120
  let markupTurndown: Turndown | null = null;
121
+ let markupTurndownPromise: Promise<Turndown> | null = null;
118
122
  const markupCache = new Map<string, string>();
119
123
 
120
124
  /**
121
125
  * Cell HTML with markup (rich-text runs, a hyperlink), converted by turndown
122
- * with markitdown's rules. A paragraph gives the same block context as a
123
- * table cell.
126
+ * with markitdown's rules. Dynamically imports turndown + GFM plugin only when
127
+ * rich-text or hyperlink markup is actually encountered.
124
128
  */
125
- const markupCellContent = (html: string): string => {
129
+ const markupCellContent = async (html: string): Promise<string> => {
126
130
  const cached = markupCache.get(html);
127
131
  if (cached !== undefined) return cached;
128
- markupTurndown ??= createMarkitdownTurndown();
132
+ if (!markupTurndown) {
133
+ markupTurndownPromise ??= createMarkitdownTurndown();
134
+ markupTurndown = await markupTurndownPromise;
135
+ }
129
136
  const content = markupTurndown.turndown(`<p>${html}</p>`);
130
137
  markupCache.set(html, content);
131
138
  return content;
132
139
  };
133
140
 
134
141
  /** markitdown-ts `CustomTurnDown` configuration (vendored dist). */
135
- function createMarkitdownTurndown(): Turndown {
142
+ async function createMarkitdownTurndown(): Promise<Turndown> {
143
+ const [turndownMod, gfmMod] = await Promise.all([
144
+ // @ts-expect-error -- turndown ships no types
145
+ import("turndown"),
146
+ // @ts-expect-error -- @joplin/turndown-plugin-gfm ships no types
147
+ import("@joplin/turndown-plugin-gfm"),
148
+ ]);
149
+ const TurndownConstructor = (turndownMod.default ??
150
+ turndownMod) as TurndownConstructorType;
151
+ const turndownPluginGfm = (gfmMod.default ?? gfmMod) as { gfm: unknown };
136
152
  const service = new TurndownConstructor({ headingStyle: "atx" });
137
- service.use((turndownPluginGfm as { gfm: unknown }).gfm);
153
+ service.use(turndownPluginGfm.gfm);
138
154
  service.addRule("anchor tags", {
139
155
  filter: ["a"],
140
156
  replacement(content, node) {
@@ -190,33 +206,39 @@ const nonFiniteText = (value: number): string =>
190
206
  * the escaped text is rendered from the text; any other HTML goes through
191
207
  * turndown.
192
208
  */
193
- const cellContent = (cell: CellObject | undefined): string => {
209
+ const cellContent = (
210
+ cell: CellObject | undefined
211
+ ): string | Promise<string> => {
194
212
  if (!cell || cell.v == null) return "";
195
- let text: string;
196
- let html: string;
197
213
  if (cell.t === "n" && !Number.isFinite(cell.v as number)) {
198
214
  // SheetJS swaps in an error cell, which has no `h` and no hyperlink.
199
- text = nonFiniteText(cell.v as number);
215
+ const text = nonFiniteText(cell.v as number);
200
216
  return text ? plainCellContent(text) : "";
201
217
  }
218
+ const target = cell.l?.Target;
219
+ const hasExternalLink = Boolean(target && target.charAt(0) !== "#");
202
220
  if (cell.h) {
203
- html = cell.h;
204
- text = typeof cell.v === "string" ? cell.v : "";
205
- } else {
206
- text =
207
- cell.w ||
208
- (XLSX.utils.format_cell(cell), cell.w as string | undefined) ||
209
- "";
210
- html = escapeHtml(text);
221
+ const html = cell.h;
222
+ if (hasExternalLink) {
223
+ return markupCellContent(`<a href="${escapeHtml(target!)}">${html}</a>`);
224
+ }
225
+ const text = typeof cell.v === "string" ? cell.v : "";
226
+ return escapeHtml(text) === html
227
+ ? plainCellContent(text)
228
+ : markupCellContent(html);
211
229
  }
212
- if (!html) return "";
213
- const target = cell.l?.Target;
214
- if (target && target.charAt(0) !== "#") {
215
- return markupCellContent(`<a href="${escapeHtml(target)}">${html}</a>`);
230
+ const text =
231
+ cell.w ||
232
+ (XLSX.utils.format_cell(cell), cell.w as string | undefined) ||
233
+ "";
234
+ if (!text) return "";
235
+ if (hasExternalLink) {
236
+ return markupCellContent(
237
+ `<a href="${escapeHtml(target!)}">${escapeHtml(text)}</a>`
238
+ );
216
239
  }
217
- return escapeHtml(text) === html
218
- ? plainCellContent(text)
219
- : markupCellContent(html);
240
+ // Plain cell with no cell.h and no external link: skip escapeHtml completely.
241
+ return plainCellContent(text);
220
242
  };
221
243
 
222
244
  interface MergeSpan {
@@ -224,23 +246,37 @@ interface MergeSpan {
224
246
  colspan: number;
225
247
  }
226
248
 
249
+ interface MergeLookupIndex {
250
+ minRow: number;
251
+ maxRow: number;
252
+ byRow: Map<number, Map<number, MergeSpan | "covered">>;
253
+ }
254
+
227
255
  /**
228
256
  * Merge lookup as `make_html_row` resolves it: the first merge (in sheet
229
257
  * order) containing a cell decides; its top-left cell carries the span and
230
- * the other covered cells are skipped.
258
+ * the other covered cells are skipped. Keyed numerically by row -> col with
259
+ * a row-range bailout to avoid per-cell `${row}:${col}` string allocations.
231
260
  */
232
- const mergeLookup = (
233
- merges: XLSX.Range[]
234
- ): ((row: number, col: number) => MergeSpan | "covered" | undefined) => {
235
- if (merges.length === 0) return () => undefined;
236
- const byCell = new Map<string, MergeSpan | "covered">();
261
+ const buildMergeLookup = (merges: XLSX.Range[]): MergeLookupIndex | null => {
262
+ if (merges.length === 0) return null;
263
+ const byRow = new Map<number, Map<number, MergeSpan | "covered">>();
264
+ let minRow = Number.POSITIVE_INFINITY;
265
+ let maxRow = Number.NEGATIVE_INFINITY;
237
266
  for (let index = merges.length - 1; index >= 0; index -= 1) {
238
267
  const merge = merges[index];
239
268
  if (!merge) continue;
269
+ if (merge.s.r < minRow) minRow = merge.s.r;
270
+ if (merge.e.r > maxRow) maxRow = merge.e.r;
240
271
  for (let row = merge.s.r; row <= merge.e.r; row += 1) {
272
+ let rowMap = byRow.get(row);
273
+ if (!rowMap) {
274
+ rowMap = new Map();
275
+ byRow.set(row, rowMap);
276
+ }
241
277
  for (let col = merge.s.c; col <= merge.e.c; col += 1) {
242
- byCell.set(
243
- `${row}:${col}`,
278
+ rowMap.set(
279
+ col,
244
280
  row === merge.s.r && col === merge.s.c
245
281
  ? {
246
282
  rowspan: merge.e.r - merge.s.r + 1,
@@ -251,15 +287,15 @@ const mergeLookup = (
251
287
  }
252
288
  }
253
289
  }
254
- return (row, col) => byCell.get(`${row}:${col}`);
290
+ return byRow.size > 0 ? { minRow, maxRow, byRow } : null;
255
291
  };
256
292
 
257
293
  const readCell = (
258
294
  sheet: WorkSheet,
295
+ dense: CellObject[][] | undefined,
259
296
  row: number,
260
297
  col: number
261
298
  ): CellObject | undefined => {
262
- const dense = (sheet as { "!data"?: CellObject[][] })["!data"];
263
299
  if (dense) return dense[row]?.[col];
264
300
  return sheet[XLSX.utils.encode_cell({ r: row, c: col })] as
265
301
  | CellObject
@@ -270,23 +306,30 @@ const readCell = (
270
306
  * Markdown for one worksheet with a `!ref`, trimmed as markitdown trims it.
271
307
  * Output matches `turndown(sheet_to_html(sheet))` for the same sheet.
272
308
  */
273
- export function sheetToMarkdown(sheet: WorkSheet): string {
309
+ export async function sheetToMarkdown(sheet: WorkSheet): Promise<string> {
274
310
  // Memoized markup is per sheet: the file processor reuses one worker across
275
311
  // files, so a process-wide cache would retain every earlier workbook.
276
312
  markupCache.clear();
277
313
  const range = XLSX.utils.decode_range(sheet["!ref"] ?? "A1");
278
- const mergeAt = mergeLookup(sheet["!merges"] ?? []);
314
+ const merges = buildMergeLookup(sheet["!merges"] ?? []);
315
+ const dense = (sheet as { "!data"?: CellObject[][] })["!data"];
279
316
  const rows: string[] = [];
280
317
  let columnCount = 0;
281
318
  let onlyCell: string | null = null;
282
319
  let firstRowCells = 0;
283
320
  for (let row = range.s.r; row <= range.e.r; row += 1) {
321
+ const rowMerges =
322
+ merges && row >= merges.minRow && row <= merges.maxRow
323
+ ? merges.byRow.get(row)
324
+ : undefined;
284
325
  const cells: string[] = [];
285
326
  let cellCount = 0;
286
327
  for (let col = range.s.c; col <= range.e.c; col += 1) {
287
- const merge = mergeAt(row, col);
328
+ const merge = rowMerges?.get(col);
288
329
  if (merge === "covered") continue;
289
- const content = cellContent(readCell(sheet, row, col));
330
+ const rawContent = cellContent(readCell(sheet, dense, row, col));
331
+ const content =
332
+ typeof rawContent === "string" ? rawContent : await rawContent;
290
333
  cells.push(formatCell(content, cellCount === 0, merge?.colspan ?? 1));
291
334
  cellCount += 1;
292
335
  onlyCell = content;
@@ -15,6 +15,16 @@ const CONTROL_CHAR_PATTERN = new RegExp(
15
15
  "g"
16
16
  );
17
17
 
18
+ /** Returns true if value contains any non-ASCII code unit; pure ASCII is already NFC. */
19
+ function hasNonAscii(value: string): boolean {
20
+ for (let i = 0; i < value.length; i += 1) {
21
+ if (value.charCodeAt(i) > 0x7f) {
22
+ return true;
23
+ }
24
+ }
25
+ return false;
26
+ }
27
+
18
28
  /**
19
29
  * Canonicalize markdown to ensure deterministic output.
20
30
  *
@@ -37,10 +47,14 @@ export function canonicalize(markdown: string): string {
37
47
  let result = markdown.startsWith("\uFEFF") ? markdown.slice(1) : markdown;
38
48
 
39
49
  // 1. Normalize line endings: \r\n → \n, lone \r → \n
40
- result = result.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
50
+ if (result.includes("\r")) {
51
+ result = result.replace(/\r\n/g, "\n").replace(/\r/g, "\n");
52
+ }
41
53
 
42
- // 2. Apply NFC Unicode normalization
43
- result = result.normalize("NFC");
54
+ // 2. Apply NFC Unicode normalization (skip only for strictly pure ASCII)
55
+ if (hasNonAscii(result)) {
56
+ result = result.normalize("NFC");
57
+ }
44
58
 
45
59
  // 3. Strip control characters except \n (U+000A) and \t (U+0009)
46
60
  // Range: U+0000-U+0008, U+000B-U+000C, U+000E-U+001F, U+007F
@@ -15,6 +15,7 @@ const CONVERTER_VERSION = NATIVE_VERSIONS.markdown;
15
15
 
16
16
  /** UTF-8 BOM character */
17
17
  const BOM = "\uFEFF";
18
+ const UTF8_DECODER = new TextDecoder("utf-8", { fatal: false });
18
19
 
19
20
  /** Regex to match # heading at line start */
20
21
  const HEADING_PATTERN = /^\s*#\s+(.+)/;
@@ -50,33 +51,39 @@ function isClosingFence(
50
51
  * Returns undefined if no heading found.
51
52
  */
52
53
  function extractFirstHeading(markdown: string): string | undefined {
53
- const lines = markdown.split("\n");
54
54
  let fenceChar = "";
55
55
  let fenceLen = 0;
56
+ let lineStart = 0;
57
+ const len = markdown.length;
58
+
59
+ while (lineStart <= len) {
60
+ const nl = markdown.indexOf("\n", lineStart);
61
+ const line =
62
+ nl === -1 ? markdown.slice(lineStart) : markdown.slice(lineStart, nl);
56
63
 
57
- for (const line of lines) {
58
64
  // If inside a fence, check for closing
59
65
  if (fenceLen > 0) {
60
66
  if (isClosingFence(line, fenceChar, fenceLen)) {
61
67
  fenceChar = "";
62
68
  fenceLen = 0;
63
69
  }
64
- continue;
65
- }
66
-
67
- // Check for fence opening
68
- const fenceMatch = line.match(CODE_FENCE_START);
69
- if (fenceMatch?.[1]) {
70
- fenceChar = fenceMatch[1].charAt(0);
71
- fenceLen = fenceMatch[1].length;
72
- continue;
70
+ } else {
71
+ // Check for fence opening
72
+ const fenceMatch = line.match(CODE_FENCE_START);
73
+ if (fenceMatch?.[1]) {
74
+ fenceChar = fenceMatch[1].charAt(0);
75
+ fenceLen = fenceMatch[1].length;
76
+ } else {
77
+ // Check for heading (not inside fence)
78
+ const headingMatch = line.match(HEADING_PATTERN);
79
+ if (headingMatch?.[1]) {
80
+ return headingMatch[1].trim();
81
+ }
82
+ }
73
83
  }
74
84
 
75
- // Check for heading (not inside fence)
76
- const headingMatch = line.match(HEADING_PATTERN);
77
- if (headingMatch?.[1]) {
78
- return headingMatch[1].trim();
79
- }
85
+ if (nl === -1) break;
86
+ lineStart = nl + 1;
80
87
  }
81
88
 
82
89
  return;
@@ -92,7 +99,7 @@ export const markdownConverter: Converter = {
92
99
 
93
100
  convert(input: ConvertInput): Promise<ConvertResult> {
94
101
  // Decode bytes to string (assumes UTF-8)
95
- let text = new TextDecoder("utf-8", { fatal: false }).decode(input.bytes);
102
+ let text = UTF8_DECODER.decode(input.bytes);
96
103
 
97
104
  // Strip BOM if present (ensures consistent hashes)
98
105
  if (text.startsWith(BOM)) {
@@ -13,6 +13,10 @@ const CONVERTER_VERSION = NATIVE_VERSIONS.plaintext;
13
13
 
14
14
  /** UTF-8 BOM character */
15
15
  const BOM = "\uFEFF";
16
+ const UTF8_DECODER = new TextDecoder("utf-8", {
17
+ fatal: false, // Don't throw on invalid bytes
18
+ ignoreBOM: false, // We'll strip manually for determinism
19
+ });
16
20
 
17
21
  export const plaintextConverter: Converter = {
18
22
  id: CONVERTER_ID,
@@ -24,12 +28,7 @@ export const plaintextConverter: Converter = {
24
28
 
25
29
  convert(input: ConvertInput): Promise<ConvertResult> {
26
30
  // Decode as UTF-8 with replacement for invalid bytes (deterministic)
27
- const decoder = new TextDecoder("utf-8", {
28
- fatal: false, // Don't throw on invalid bytes
29
- ignoreBOM: false, // We'll strip manually for determinism
30
- });
31
-
32
- let text = decoder.decode(input.bytes);
31
+ let text = UTF8_DECODER.decode(input.bytes);
33
32
 
34
33
  // Strip BOM if present (ensures consistent hashes)
35
34
  if (text.startsWith(BOM)) {
@@ -133,6 +133,61 @@ function unavailableAdapter(spec: LazyAdapterSpec, reason: string): Converter {
133
133
  };
134
134
  }
135
135
 
136
+ /** Identity and routing of a record adapter whose module loads on first use. */
137
+ export interface LazyRecordAdapterSpec {
138
+ id: string;
139
+ version: string;
140
+ configurationFingerprint?: string;
141
+ canHandle: RecordAdapter["canHandle"];
142
+ }
143
+
144
+ /**
145
+ * A streaming record adapter that defers loading its parser module until first
146
+ * invocation. Routing, identity, and configuration fingerprint match the eager
147
+ * adapter identically while keeping startup free of unused adapter modules.
148
+ */
149
+ export function lazyRecordAdapter(
150
+ spec: LazyRecordAdapterSpec,
151
+ load: () => Promise<RecordAdapter>
152
+ ): RecordAdapter {
153
+ let loaded: Promise<RecordAdapter> | undefined;
154
+ return {
155
+ id: spec.id,
156
+ version: spec.version,
157
+ ...(spec.configurationFingerprint !== undefined
158
+ ? { configurationFingerprint: spec.configurationFingerprint }
159
+ : {}),
160
+ canHandle: spec.canHandle,
161
+ async *records(input) {
162
+ loaded ??= load();
163
+ let adapter: RecordAdapter;
164
+ try {
165
+ adapter = await loaded;
166
+ } catch (cause) {
167
+ loaded = undefined;
168
+ yield {
169
+ type: "failure",
170
+ failure: {
171
+ code: "ADAPTER_FAILURE",
172
+ message: `${spec.id} is unavailable: ${cause instanceof Error ? cause.message : String(cause)}`,
173
+ retryable: true,
174
+ },
175
+ };
176
+ yield { type: "snapshot", state: "partial" };
177
+ return;
178
+ }
179
+ yield* adapter.records(input);
180
+ },
181
+ };
182
+ }
183
+
184
+ const XLSX_MIME =
185
+ "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
186
+ const DEFAULT_JSONL_CONFIG_FINGERPRINT =
187
+ "35e7c3045f7eef59f74a6b6bfe450e5e50f37ef5e023edd0bc1c4327035cc5a2";
188
+ const DEFAULT_TRANSCRIPT_CONFIG_FINGERPRINT =
189
+ "f1de45113a28155cdbe998e44af239561c91e4357cfd9a7b05f7765f5ba20cf4";
190
+
136
191
  /**
137
192
  * Create the default registry with all MVP converters.
138
193
  * Priority order per PRD §8.6:
@@ -145,10 +200,18 @@ function unavailableAdapter(spec: LazyAdapterSpec, reason: string): Converter {
145
200
  export async function createDefaultRegistry(): Promise<ConverterRegistry> {
146
201
  const registry = new ConverterRegistry();
147
202
 
148
- // Import converters dynamically to avoid circular deps
203
+ // Only lightweight native converters load eagerly; heavy office parsers and
204
+ // streaming record adapters defer module evaluation until first matched.
149
205
  const { markdownConverter } = await import("./native/markdown");
150
206
  const { plaintextConverter } = await import("./native/plaintext");
151
- const { xlsxAdapter } = await import("./adapters/xlsx/adapter");
207
+ const xlsxAdapter = lazyAdapter(
208
+ {
209
+ id: "adapter/xlsx",
210
+ version: ADAPTER_VERSIONS.xlsx,
211
+ canHandle: (mime, ext) => ext === ".xlsx" || mime === XLSX_MIME,
212
+ },
213
+ async () => (await import("./adapters/xlsx/adapter")).xlsxAdapter
214
+ );
152
215
  const markitdownAdapter = lazyAdapter(
153
216
  {
154
217
  id: MARKITDOWN_CONVERTER_ID,
@@ -167,12 +230,71 @@ export async function createDefaultRegistry(): Promise<ConverterRegistry> {
167
230
  async () =>
168
231
  (await import("./adapters/officeparser/adapter")).officeparserAdapter
169
232
  );
170
- const { jsonlAdapter } = await import("./adapters/jsonl/adapter");
171
- const { transcriptAdapter } = await import("./adapters/transcript/adapter");
172
- const { emailRecordAdapter } = await import("./adapters/email/adapter");
173
- const { icalAdapter } = await import("./adapters/ical/adapter");
174
- const { browserExportAdapter } =
175
- await import("./adapters/browser-export/adapter");
233
+ const jsonlAdapter = lazyRecordAdapter(
234
+ {
235
+ id: "adapter/jsonl",
236
+ version: "1.0.0",
237
+ configurationFingerprint: DEFAULT_JSONL_CONFIG_FINGERPRINT,
238
+ canHandle: (mime, ext) =>
239
+ mime === "application/x-ndjson" ||
240
+ mime === "application/jsonl" ||
241
+ ext === ".jsonl" ||
242
+ ext === ".ndjson",
243
+ },
244
+ async () => (await import("./adapters/jsonl/adapter")).jsonlAdapter
245
+ );
246
+ const transcriptAdapter = lazyRecordAdapter(
247
+ {
248
+ id: "adapter/transcript",
249
+ version: "1.0.0",
250
+ configurationFingerprint: DEFAULT_TRANSCRIPT_CONFIG_FINGERPRINT,
251
+ canHandle: (mime, ext) =>
252
+ mime === "text/vtt" ||
253
+ ext === ".vtt" ||
254
+ mime === "application/x-subrip" ||
255
+ mime === "text/srt" ||
256
+ ext === ".srt",
257
+ },
258
+ async () =>
259
+ (await import("./adapters/transcript/adapter")).transcriptAdapter
260
+ );
261
+ const emailRecordAdapter = lazyRecordAdapter(
262
+ {
263
+ id: "native/email-export",
264
+ version: "1.0.0",
265
+ canHandle: (mime, ext) => {
266
+ const normalizedMime = mime.toLowerCase();
267
+ const normalizedExt = ext.toLowerCase();
268
+ return (
269
+ normalizedExt === ".eml" ||
270
+ normalizedExt === ".mbox" ||
271
+ normalizedMime === "message/rfc822" ||
272
+ normalizedMime === "application/mbox"
273
+ );
274
+ },
275
+ },
276
+ async () => (await import("./adapters/email/adapter")).emailRecordAdapter
277
+ );
278
+ const icalAdapter = lazyRecordAdapter(
279
+ {
280
+ id: "adapter/ical-export",
281
+ version: "1.0.0",
282
+ canHandle: (mime, ext) => mime === "text/calendar" || ext === ".ics",
283
+ },
284
+ async () => (await import("./adapters/ical/adapter")).icalAdapter
285
+ );
286
+ const browserExportAdapter = lazyRecordAdapter(
287
+ {
288
+ id: "adapter/browser-export",
289
+ version: "1.0.0",
290
+ canHandle: (mime, ext) =>
291
+ mime === "application/x-gno-browser-export+json" ||
292
+ mime === "text/x-gno-browser-bookmarks+html" ||
293
+ ext === ".browser-export",
294
+ },
295
+ async () =>
296
+ (await import("./adapters/browser-export/adapter")).browserExportAdapter
297
+ );
176
298
 
177
299
  // Register in priority order
178
300
  registry.register(markdownConverter);
@@ -9,19 +9,15 @@ import type {
9
9
  StoreResult,
10
10
  } from "../store/types";
11
11
  import type { EphemeralActivationProbePlan } from "./activation-probe-plan";
12
- import type {
13
- ConnectorVerificationCode,
14
- ConnectorVerificationTarget,
15
- } from "./connector-verifier";
12
+ import type { ConnectorVerificationCode } from "./connector-policy";
13
+ import type { ConnectorVerificationTarget } from "./connector-verification-target";
16
14
 
17
15
  import { summarizeConnectorProofs } from "./activation-connector-health";
18
16
  import { isEmptyActivationCollection } from "./activation-empty";
19
17
  import { createEphemeralActivationProbePlan } from "./activation-probe-plan";
20
18
  import { verifyLexicalActivation } from "./activation-verifier";
21
- import {
22
- getConnectorActivationReceiptLookup,
23
- getConnectorVerificationRemediation,
24
- } from "./connector-verifier";
19
+ import { getConnectorVerificationRemediation } from "./connector-policy";
20
+ import { getConnectorActivationReceiptLookup } from "./connector-verification-target";
25
21
 
26
22
  const DEFAULT_CONCURRENCY = 4;
27
23
  /** Bounds the listed pairs only; completeness is decided from every pair. */