@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.
- package/README.md +1 -1
- package/assets/skill/SKILL.md +27 -0
- package/assets/skill/cli-reference.md +24 -15
- package/assets/spa-production.json.gz +0 -0
- package/browser-extension/artifacts/{gno-browser-clipper-v2.15.0.zip → gno-browser-clipper-v2.17.0.zip} +0 -0
- package/browser-extension/artifacts/gno-browser-clipper-v2.17.0.zip.sha256 +1 -0
- package/browser-extension/dist/manifest.json +1 -1
- package/package.json +1 -1
- package/spec/cli.md +43 -3
- package/spec/db/schema.sql +53 -1
- package/spec/mcp.md +9 -3
- package/spec/output-schemas/doctor.schema.json +27 -0
- package/spec/output-schemas/retrieval-trace-payloads.schema.json +14 -0
- package/spec/output-schemas/search-results.schema.json +14 -0
- package/spec/output-schemas/status.schema.json +22 -0
- package/src/cli/commands/agents/commands.ts +1 -1
- package/src/cli/commands/ask.ts +1 -1
- package/src/cli/commands/context-build.ts +1 -1
- package/src/cli/commands/doctor.ts +101 -29
- package/src/cli/commands/embed.ts +2 -2
- package/src/cli/commands/links.ts +30 -6
- package/src/cli/commands/mcp/install.ts +2 -2
- package/src/cli/commands/mcp/status.ts +1 -1
- package/src/cli/commands/mcp/uninstall.ts +1 -1
- package/src/cli/commands/query.ts +1 -1
- package/src/cli/commands/shared.ts +4 -4
- package/src/cli/commands/skill/install.ts +1 -1
- package/src/cli/commands/skill/paths-cmd.ts +1 -1
- package/src/cli/commands/skill/uninstall.ts +1 -1
- package/src/cli/commands/status.ts +75 -58
- package/src/cli/commands/vec.ts +180 -8
- package/src/cli/config-cache.ts +86 -0
- package/src/cli/globals.ts +64 -0
- package/src/cli/program.ts +63 -36
- package/src/cli/run.ts +121 -67
- package/src/cli/runtime-health.ts +132 -122
- package/src/cli/session-binding.ts +11 -2
- package/src/config/saver.ts +8 -0
- package/src/config/types.ts +6 -0
- package/src/converters/adapters/browser-export/formats.ts +25 -15
- package/src/converters/adapters/email/adapter.ts +37 -53
- package/src/converters/adapters/email/html.ts +37 -20
- package/src/converters/adapters/email/mime.ts +71 -39
- package/src/converters/adapters/ical/adapter.ts +20 -12
- package/src/converters/adapters/jsonl/adapter.ts +8 -6
- package/src/converters/adapters/shared/html-text.ts +55 -37
- package/src/converters/adapters/shared/ooxml-protection.ts +5 -13
- package/src/converters/adapters/shared/utf8-lines.ts +69 -31
- package/src/converters/adapters/transcript/adapter.ts +12 -7
- package/src/converters/adapters/xlsx/adapter.ts +10 -7
- package/src/converters/adapters/xlsx/sheet-markdown.ts +93 -50
- package/src/converters/canonicalize.ts +17 -3
- package/src/converters/native/markdown.ts +24 -17
- package/src/converters/native/plaintext.ts +5 -6
- package/src/converters/registry.ts +130 -8
- package/src/core/activation-status.ts +4 -8
- package/src/core/change-diff.ts +38 -11
- package/src/core/context-compiler.ts +17 -18
- package/src/core/context-evidence.ts +116 -25
- package/src/core/context-verifier.ts +70 -31
- package/src/core/file-lock.ts +10 -2
- package/src/core/graph-analysis.ts +3 -3
- package/src/core/link-inventory-markdown.ts +2 -2
- package/src/core/links.ts +20 -87
- package/src/core/memory-fence.ts +16 -9
- package/src/core/memory-recall.ts +168 -34
- package/src/core/path-rules.ts +143 -0
- package/src/core/retrieval-trace-session.ts +3 -0
- package/src/core/retrieval-trace.ts +9 -0
- package/src/core/section-parse.ts +16 -6
- package/src/core/typed-metadata.ts +68 -0
- package/src/core/vector-partition-status.ts +13 -0
- package/src/core/wiki-link-syntax.ts +88 -0
- package/src/embed/backlog.ts +142 -60
- package/src/embed/retry.ts +39 -33
- package/src/embed/variant-backlog.ts +582 -116
- package/src/embed/variant-retry.ts +157 -48
- package/src/index.ts +3 -3
- package/src/ingestion/budget-error-codes.ts +13 -0
- package/src/ingestion/chunker.ts +60 -49
- package/src/ingestion/compiled-context.ts +4 -5
- package/src/ingestion/convert-file.ts +1 -1
- package/src/ingestion/document-metadata.ts +16 -9
- package/src/ingestion/excluded-ranges.ts +97 -0
- package/src/ingestion/file-processor.ts +122 -37
- package/src/ingestion/frontmatter.ts +35 -7
- package/src/ingestion/graph-reconciliation.ts +187 -51
- package/src/ingestion/language.ts +66 -61
- package/src/ingestion/position.ts +5 -5
- package/src/ingestion/prepare-file.ts +50 -29
- package/src/ingestion/record-adapter-canonical.ts +37 -26
- package/src/ingestion/record-adapter.ts +46 -26
- package/src/ingestion/record-container.ts +121 -53
- package/src/ingestion/record-path.ts +5 -2
- package/src/ingestion/source-availability/darwin-io.ts +10 -7
- package/src/ingestion/source-availability/darwin-path.ts +21 -3
- package/src/ingestion/source-availability/readers.ts +51 -0
- package/src/ingestion/strip.ts +39 -105
- package/src/ingestion/sync.ts +692 -386
- package/src/ingestion/typed-metadata.ts +10 -4
- package/src/ingestion/walker.ts +485 -158
- package/src/llm/cache.ts +128 -84
- package/src/llm/http-inference.ts +112 -35
- package/src/llm/http-policy.ts +101 -0
- package/src/llm/httpEmbedding.ts +8 -1
- package/src/llm/httpGeneration.ts +5 -1
- package/src/llm/httpRerank.ts +5 -1
- package/src/llm/inference-scope.ts +15 -2
- package/src/llm/lazy-ports.ts +33 -3
- package/src/llm/lockfile.ts +34 -7
- package/src/llm/model-cleanup.ts +24 -0
- package/src/llm/native-worker/client.ts +23 -12
- package/src/llm/native-worker/dispatcher.ts +19 -9
- package/src/llm/native-worker/embedding-identity.ts +42 -16
- package/src/llm/native-worker/entry.ts +2 -1
- package/src/llm/native-worker/owner.ts +1 -0
- package/src/llm/native-worker/ports.ts +86 -23
- package/src/llm/native-worker/protocol.ts +386 -55
- package/src/llm/nodeLlamaCpp/adapter.ts +46 -29
- package/src/llm/nodeLlamaCpp/embedding.ts +93 -40
- package/src/llm/nodeLlamaCpp/generation.ts +194 -30
- package/src/llm/nodeLlamaCpp/lifecycle.ts +2 -0
- package/src/llm/nodeLlamaCpp/rerank-capacity.ts +101 -23
- package/src/llm/nodeLlamaCpp/rerank.ts +253 -44
- package/src/llm/types.ts +14 -0
- package/src/mcp/context.ts +342 -23
- package/src/mcp/http-transport.ts +21 -3
- package/src/mcp/tool-profile-types.ts +62 -0
- package/src/mcp/tool-profile.ts +32 -56
- package/src/mcp/tools/context.ts +5 -1
- package/src/mcp/tools/index.ts +269 -191
- package/src/mcp/tools/links.ts +14 -6
- package/src/mcp/tools/query.ts +60 -37
- package/src/mcp/tools/vsearch.ts +25 -14
- package/src/pipeline/answer.ts +133 -40
- package/src/pipeline/claim-verification.ts +293 -189
- package/src/pipeline/claim-verifier.ts +6 -7
- package/src/pipeline/egress-lineage.ts +37 -26
- package/src/pipeline/exclude.ts +34 -11
- package/src/pipeline/expansion.ts +233 -19
- package/src/pipeline/explain.ts +17 -2
- package/src/pipeline/filters.ts +169 -33
- package/src/pipeline/graph-retrieval.ts +117 -61
- package/src/pipeline/hybrid.ts +626 -330
- package/src/pipeline/hydration.ts +86 -24
- package/src/pipeline/intent.ts +15 -7
- package/src/pipeline/owner-fusion.ts +61 -19
- package/src/pipeline/query-language.ts +15 -2
- package/src/pipeline/rerank.ts +15 -22
- package/src/pipeline/search.ts +193 -72
- package/src/pipeline/snippet.ts +15 -2
- package/src/pipeline/temporal.ts +51 -10
- package/src/pipeline/types.ts +7 -0
- package/src/pipeline/vsearch.ts +269 -154
- package/src/publish/attachment-raster.ts +2 -16
- package/src/publish/encrypted-export.ts +15 -5
- package/src/serve/browse-tree.ts +50 -42
- package/src/serve/connectors.ts +2 -1
- package/src/serve/context.ts +13 -4
- package/src/serve/doc-events.ts +3 -0
- package/src/serve/public/app.tsx +49 -21
- package/src/serve/public/components/BrowseTreeSidebar.tsx +163 -23
- package/src/serve/public/components/CaptureModal.tsx +14 -10
- package/src/serve/public/components/ai-elements/code-block.tsx +87 -50
- package/src/serve/public/components/editor/MarkdownPreview.tsx +99 -67
- package/src/serve/public/globals.built.css +1 -1
- package/src/serve/public/globals.css +19 -0
- package/src/serve/public/hooks/useCaptureModal.tsx +23 -10
- package/src/serve/public/lib/metadata-filter.ts +234 -9
- package/src/serve/public/pages/Browse.tsx +61 -27
- package/src/serve/public/pages/DocView.tsx +44 -25
- package/src/serve/public/pages/GraphView.tsx +8 -3
- package/src/serve/resident-runtime.ts +199 -48
- package/src/serve/routes/api.ts +98 -67
- package/src/serve/routes/links.ts +25 -5
- package/src/serve/server.ts +1370 -1180
- package/src/serve/spa-bundle-source.ts +52 -27
- package/src/serve/status.ts +101 -52
- package/src/serve/watch-reconciliation-fallback.ts +11 -7
- package/src/serve/watch-reconciliation-shared.ts +42 -4
- package/src/serve/watch-reconciliation.ts +21 -8
- package/src/serve/watch-service-events.ts +7 -1
- package/src/serve/watch-service-hosts.ts +3 -1
- package/src/serve/watch-service.ts +46 -21
- package/src/serve/watch-snapshot-scan.ts +6 -15
- package/src/sessions/archive.ts +20 -8
- package/src/sessions/sanitize.ts +38 -18
- package/src/sessions/service.ts +180 -102
- package/src/store/migrations/037-performance-indexes.ts +56 -0
- package/src/store/migrations/038-vector-mirror-null-cosine.ts +47 -0
- package/src/store/migrations/039-vector-mirror-v2.ts +94 -0
- package/src/store/migrations/index.ts +6 -0
- package/src/store/sqlite/adapter.ts +1260 -651
- package/src/store/sqlite/chunking-policy.ts +15 -1
- package/src/store/sqlite/eligibility.ts +110 -70
- package/src/store/sqlite/graph-neighbors.ts +71 -46
- package/src/store/sqlite/graph-reference-state.ts +27 -3
- package/src/store/sqlite/graph-similarity.ts +59 -12
- package/src/store/sqlite/metadata-predicate.ts +123 -28
- package/src/store/sqlite/retrieval-trace-management-store.ts +126 -33
- package/src/store/sqlite/retrieval-trace-retention.ts +88 -76
- package/src/store/sqlite/retrieval-trace-rows.ts +7 -3
- package/src/store/types.ts +32 -0
- package/src/store/vector/coarse-router.ts +312 -0
- package/src/store/vector/eligibility.ts +39 -0
- package/src/store/vector/lazy.ts +17 -0
- package/src/store/vector/partition-index.ts +333 -59
- package/src/store/vector/proof-cache.ts +209 -0
- package/src/store/vector/runtime-compat.ts +6 -0
- package/src/store/vector/sqlite-vec.ts +270 -162
- package/src/store/vector/stats.ts +37 -73
- package/src/store/vector/status.ts +169 -53
- package/src/store/vector/stored-vectors.ts +131 -45
- package/src/store/vector/types.ts +19 -0
- package/src/store/vector/v2-mirror.ts +669 -0
- package/src/store/vector/variant-search.ts +1187 -111
- package/src/store/vector/variants.ts +964 -160
- package/browser-extension/artifacts/gno-browser-clipper-v2.15.0.zip.sha256 +0 -1
|
@@ -60,51 +60,66 @@ interface MimeState {
|
|
|
60
60
|
limits: ParseEmailLimits;
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
const CHARSET_LABELS: Record<string, string> = {
|
|
64
|
+
ascii: "windows-1252",
|
|
65
|
+
"iso-8859-1": "windows-1252",
|
|
66
|
+
latin1: "windows-1252",
|
|
67
|
+
"us-ascii": "windows-1252",
|
|
68
|
+
utf8: "utf-8",
|
|
69
69
|
};
|
|
70
|
+
const UTF8_DECODER = new TextDecoder("utf-8", { fatal: false });
|
|
71
|
+
const DECODER_CACHE = new Map<string, TextDecoder>([["utf-8", UTF8_DECODER]]);
|
|
72
|
+
|
|
73
|
+
const binaryToBytes = (value: string): Uint8Array =>
|
|
74
|
+
Buffer.from(value, "latin1");
|
|
70
75
|
|
|
71
76
|
const decodeBytes = (bytes: Uint8Array, charset = "utf-8"): string => {
|
|
72
77
|
const normalized = charset.trim().toLowerCase().replaceAll("_", "-");
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
} catch {
|
|
85
|
-
return new TextDecoder("utf-8", { fatal: false }).decode(bytes);
|
|
78
|
+
const label = CHARSET_LABELS[normalized] ?? normalized;
|
|
79
|
+
let decoder = DECODER_CACHE.get(label);
|
|
80
|
+
if (!decoder) {
|
|
81
|
+
try {
|
|
82
|
+
decoder = new TextDecoder(label, { fatal: false });
|
|
83
|
+
} catch {
|
|
84
|
+
return UTF8_DECODER.decode(bytes);
|
|
85
|
+
}
|
|
86
|
+
if (DECODER_CACHE.size < 64) {
|
|
87
|
+
DECODER_CACHE.set(label, decoder);
|
|
88
|
+
}
|
|
86
89
|
}
|
|
90
|
+
return decoder.decode(bytes);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const hexNibble = (code: number): number => {
|
|
94
|
+
if (code >= 48 && code <= 57) return code - 48;
|
|
95
|
+
if (code >= 65 && code <= 70) return code - 55;
|
|
96
|
+
if (code >= 97 && code <= 102) return code - 87;
|
|
97
|
+
return -1;
|
|
87
98
|
};
|
|
88
99
|
|
|
89
100
|
const decodeQuotedPrintable = (value: string): Uint8Array => {
|
|
90
|
-
const unfolded = value.replace(/=\r?\n/g, "");
|
|
91
|
-
const
|
|
101
|
+
const unfolded = value.includes("=") ? value.replace(/=\r?\n/g, "") : value;
|
|
102
|
+
const out = new Uint8Array(unfolded.length);
|
|
103
|
+
let outLen = 0;
|
|
92
104
|
for (let index = 0; index < unfolded.length; index += 1) {
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
105
|
+
const code = unfolded.charCodeAt(index);
|
|
106
|
+
if (code === 61 && index + 2 < unfolded.length) {
|
|
107
|
+
const hi = hexNibble(unfolded.charCodeAt(index + 1));
|
|
108
|
+
const lo = hexNibble(unfolded.charCodeAt(index + 2));
|
|
109
|
+
if (hi >= 0 && lo >= 0) {
|
|
110
|
+
out[outLen] = (hi << 4) | lo;
|
|
111
|
+
outLen += 1;
|
|
112
|
+
index += 2;
|
|
113
|
+
continue;
|
|
114
|
+
}
|
|
101
115
|
}
|
|
116
|
+
out[outLen] = code & 0xff;
|
|
117
|
+
outLen += 1;
|
|
102
118
|
}
|
|
103
|
-
return
|
|
119
|
+
return out.subarray(0, outLen);
|
|
104
120
|
};
|
|
105
121
|
|
|
106
|
-
const
|
|
107
|
-
const compact = value.replace(/\s/g, "");
|
|
122
|
+
const decodeCompactBase64 = (compact: string): Uint8Array => {
|
|
108
123
|
if (
|
|
109
124
|
compact.length === 0 ||
|
|
110
125
|
compact.length % 4 === 1 ||
|
|
@@ -119,6 +134,9 @@ const decodeBase64 = (value: string): Uint8Array => {
|
|
|
119
134
|
}
|
|
120
135
|
};
|
|
121
136
|
|
|
137
|
+
const decodeBase64 = (value: string): Uint8Array =>
|
|
138
|
+
decodeCompactBase64(value.replace(/\s/g, ""));
|
|
139
|
+
|
|
122
140
|
const decodeTransfer = (
|
|
123
141
|
value: string,
|
|
124
142
|
encoding: string | undefined,
|
|
@@ -127,13 +145,14 @@ const decodeTransfer = (
|
|
|
127
145
|
const normalized = encoding?.trim().toLowerCase();
|
|
128
146
|
let bytes: Uint8Array;
|
|
129
147
|
if (normalized === "base64") {
|
|
130
|
-
|
|
148
|
+
const compact = value.replace(/\s/g, "");
|
|
149
|
+
if (compact.length > maxBytes * 2) {
|
|
131
150
|
throw new MailParseError(
|
|
132
151
|
"MIME body exceeds its decoded byte limit.",
|
|
133
152
|
"limit"
|
|
134
153
|
);
|
|
135
154
|
}
|
|
136
|
-
bytes =
|
|
155
|
+
bytes = decodeCompactBase64(compact);
|
|
137
156
|
} else if (normalized === "quoted-printable") {
|
|
138
157
|
if (value.length > maxBytes * 3) {
|
|
139
158
|
throw new MailParseError(
|
|
@@ -251,7 +270,12 @@ const safeFilename = (value: string | undefined, index: number): string => {
|
|
|
251
270
|
return (normalized || `attachment-${index}`).slice(0, 240);
|
|
252
271
|
};
|
|
253
272
|
|
|
254
|
-
const walkMimePart = (
|
|
273
|
+
const walkMimePart = (
|
|
274
|
+
raw: string,
|
|
275
|
+
state: MimeState,
|
|
276
|
+
depth: number,
|
|
277
|
+
preParsed?: { headers: Map<string, string>; body: string }
|
|
278
|
+
): void => {
|
|
255
279
|
if (depth > MAX_MIME_DEPTH) {
|
|
256
280
|
throw new MailParseError("MIME nesting exceeds its depth limit.", "limit");
|
|
257
281
|
}
|
|
@@ -259,8 +283,16 @@ const walkMimePart = (raw: string, state: MimeState, depth: number): void => {
|
|
|
259
283
|
if (state.partCount > MAX_MIME_PARTS) {
|
|
260
284
|
throw new MailParseError("MIME message exceeds its part limit.", "limit");
|
|
261
285
|
}
|
|
262
|
-
|
|
263
|
-
|
|
286
|
+
let headers: Map<string, string>;
|
|
287
|
+
let body: string;
|
|
288
|
+
if (preParsed) {
|
|
289
|
+
headers = preParsed.headers;
|
|
290
|
+
body = preParsed.body;
|
|
291
|
+
} else {
|
|
292
|
+
const [rawHeaders, splitBody] = splitHeaderBody(raw);
|
|
293
|
+
headers = parseHeaders(rawHeaders);
|
|
294
|
+
body = splitBody;
|
|
295
|
+
}
|
|
264
296
|
const contentType = parseParameterizedHeader(
|
|
265
297
|
headers.get("content-type"),
|
|
266
298
|
decodeHeaderWords
|
|
@@ -384,7 +416,7 @@ export const parseEmail = (
|
|
|
384
416
|
raw: string,
|
|
385
417
|
limits: ParseEmailLimits
|
|
386
418
|
): ParsedEmail => {
|
|
387
|
-
const [rawHeaders] = splitHeaderBody(raw);
|
|
419
|
+
const [rawHeaders, bodyRaw] = splitHeaderBody(raw);
|
|
388
420
|
const headers = parseHeaders(rawHeaders);
|
|
389
421
|
const state: MimeState = {
|
|
390
422
|
plainBodies: [],
|
|
@@ -393,7 +425,7 @@ export const parseEmail = (
|
|
|
393
425
|
partCount: 0,
|
|
394
426
|
limits,
|
|
395
427
|
};
|
|
396
|
-
walkMimePart(raw, state, 0);
|
|
428
|
+
walkMimePart(raw, state, 0, { headers, body: bodyRaw });
|
|
397
429
|
const bodyParts = state.plainBodies.some(Boolean)
|
|
398
430
|
? state.plainBodies
|
|
399
431
|
: state.htmlBodies;
|
|
@@ -42,33 +42,41 @@ async function* physicalLines(
|
|
|
42
42
|
const decoder = new TextDecoder("utf-8", { fatal: true });
|
|
43
43
|
let pending = "";
|
|
44
44
|
let line = 0;
|
|
45
|
+
const maxRecordChars = input.limits.maxRecordChars;
|
|
45
46
|
for await (const chunk of input.open()) {
|
|
46
|
-
|
|
47
|
+
const decoded = decoder.decode(chunk, { stream: true });
|
|
48
|
+
pending = pending.length > 0 ? pending + decoded : decoded;
|
|
49
|
+
let cursor = 0;
|
|
47
50
|
while (true) {
|
|
48
|
-
const newline = pending.indexOf("\n");
|
|
51
|
+
const newline = pending.indexOf("\n", cursor);
|
|
49
52
|
if (newline < 0) break;
|
|
50
53
|
line += 1;
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
if (raw.length > input.limits.maxRecordChars) {
|
|
54
|
+
const rawLength = newline - cursor;
|
|
55
|
+
if (rawLength > maxRecordChars) {
|
|
54
56
|
throw new Error("iCalendar physical line exceeded its limit.");
|
|
55
57
|
}
|
|
56
|
-
const
|
|
58
|
+
const lineEnd =
|
|
59
|
+
rawLength > 0 && pending.charCodeAt(newline - 1) === 13
|
|
60
|
+
? newline - 1
|
|
61
|
+
: newline;
|
|
62
|
+
const lineStart =
|
|
63
|
+
line === 1 && lineEnd > cursor && pending.charCodeAt(cursor) === 0xfeff
|
|
64
|
+
? cursor + 1
|
|
65
|
+
: cursor;
|
|
66
|
+
cursor = newline + 1;
|
|
57
67
|
yield {
|
|
58
|
-
text:
|
|
59
|
-
line === 1 && withoutCarriageReturn.startsWith("\uFEFF")
|
|
60
|
-
? withoutCarriageReturn.slice(1)
|
|
61
|
-
: withoutCarriageReturn,
|
|
68
|
+
text: pending.slice(lineStart, lineEnd),
|
|
62
69
|
line,
|
|
63
70
|
};
|
|
64
71
|
}
|
|
65
|
-
|
|
72
|
+
pending = cursor > 0 ? pending.slice(cursor) : pending;
|
|
73
|
+
if (pending.length > maxRecordChars) {
|
|
66
74
|
throw new Error("iCalendar physical line exceeded its limit.");
|
|
67
75
|
}
|
|
68
76
|
}
|
|
69
77
|
pending += decoder.decode();
|
|
70
78
|
if (pending.length > 0) {
|
|
71
|
-
if (pending.length >
|
|
79
|
+
if (pending.length > maxRecordChars) {
|
|
72
80
|
throw new Error("iCalendar physical line exceeded its limit.");
|
|
73
81
|
}
|
|
74
82
|
line += 1;
|
|
@@ -102,12 +102,12 @@ const buildMetadata = (
|
|
|
102
102
|
const recordFromLine = (
|
|
103
103
|
source: Record<string, unknown>,
|
|
104
104
|
lineNumber: number,
|
|
105
|
-
|
|
105
|
+
container: string,
|
|
106
106
|
mapping: JsonlFieldMapping,
|
|
107
|
+
authorMapping: JsonlFieldMapping,
|
|
107
108
|
allowConventionalId: boolean
|
|
108
109
|
): RecordAdapterEvent => {
|
|
109
110
|
const canonicalSource = canonicalJson(source);
|
|
110
|
-
const container = sourceNamespace(input);
|
|
111
111
|
const configuredId = resolveJsonlField(
|
|
112
112
|
source,
|
|
113
113
|
mapping.id ?? (allowConventionalId ? DEFAULT_ID_SELECTORS : undefined)
|
|
@@ -128,9 +128,6 @@ const recordFromLine = (
|
|
|
128
128
|
resolveJsonlField(source, mapping.title ?? DEFAULT_TITLE_SELECTORS)
|
|
129
129
|
);
|
|
130
130
|
if (!titleValue.ok) return failure("MALFORMED_RECORD", lineNumber);
|
|
131
|
-
const authorMapping = mapping.author
|
|
132
|
-
? mapping
|
|
133
|
-
: { ...mapping, author: DEFAULT_AUTHOR_SELECTORS };
|
|
134
131
|
const metadata = buildMetadata(source, authorMapping);
|
|
135
132
|
if (!metadata.ok) return failure("MALFORMED_RECORD", lineNumber);
|
|
136
133
|
|
|
@@ -154,6 +151,9 @@ export const createJsonlAdapter = (
|
|
|
154
151
|
fieldMapping?: JsonlFieldMapping
|
|
155
152
|
): RecordAdapter => {
|
|
156
153
|
const mapping = parseJsonlFieldMapping(fieldMapping);
|
|
154
|
+
const authorMapping = mapping.author
|
|
155
|
+
? mapping
|
|
156
|
+
: { ...mapping, author: DEFAULT_AUTHOR_SELECTORS };
|
|
157
157
|
const allowConventionalId = fieldMapping === undefined;
|
|
158
158
|
return {
|
|
159
159
|
id: ADAPTER_ID,
|
|
@@ -170,6 +170,7 @@ export const createJsonlAdapter = (
|
|
|
170
170
|
records: async function* (
|
|
171
171
|
input: RecordAdapterInput
|
|
172
172
|
): AsyncGenerator<RecordAdapterEvent> {
|
|
173
|
+
const container = sourceNamespace(input);
|
|
173
174
|
let hadFailure = false;
|
|
174
175
|
try {
|
|
175
176
|
const lines = readBoundedUtf8Lines(
|
|
@@ -209,8 +210,9 @@ export const createJsonlAdapter = (
|
|
|
209
210
|
const event = recordFromLine(
|
|
210
211
|
parsed as Record<string, unknown>,
|
|
211
212
|
line.lineNumber,
|
|
212
|
-
|
|
213
|
+
container,
|
|
213
214
|
mapping,
|
|
215
|
+
authorMapping,
|
|
214
216
|
allowConventionalId
|
|
215
217
|
);
|
|
216
218
|
hadFailure ||= event.type === "failure";
|
|
@@ -44,27 +44,33 @@ const hasOnlyDigits = (value: string, hexadecimal: boolean): boolean => {
|
|
|
44
44
|
|
|
45
45
|
/** Decode recognized entities from the original input exactly once. */
|
|
46
46
|
export const decodeHtmlEntitiesOnce = (value: string): string => {
|
|
47
|
-
let
|
|
47
|
+
let amp = value.indexOf("&");
|
|
48
|
+
if (amp === -1) return value;
|
|
49
|
+
const parts: string[] = [];
|
|
48
50
|
let cursor = 0;
|
|
49
|
-
while (
|
|
50
|
-
if (
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
while (amp !== -1) {
|
|
52
|
+
if (amp > cursor) {
|
|
53
|
+
parts.push(value.slice(cursor, amp));
|
|
54
|
+
}
|
|
55
|
+
const entityEnd = Math.min(value.length, amp + MAX_ENTITY_CHARS + 2);
|
|
56
|
+
let absoluteSemicolon = -1;
|
|
57
|
+
for (let i = amp + 1; i < entityEnd; i += 1) {
|
|
58
|
+
if (value.charCodeAt(i) === 59) {
|
|
59
|
+
absoluteSemicolon = i;
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
54
62
|
}
|
|
55
|
-
const entityEnd = Math.min(value.length, cursor + MAX_ENTITY_CHARS + 2);
|
|
56
|
-
const semicolon = value.slice(cursor + 1, entityEnd).indexOf(";");
|
|
57
|
-
const absoluteSemicolon = semicolon < 0 ? -1 : cursor + semicolon + 1;
|
|
58
63
|
if (
|
|
59
64
|
absoluteSemicolon < 0 ||
|
|
60
|
-
absoluteSemicolon -
|
|
61
|
-
absoluteSemicolon -
|
|
65
|
+
absoluteSemicolon - amp - 1 <= 0 ||
|
|
66
|
+
absoluteSemicolon - amp - 1 > MAX_ENTITY_CHARS
|
|
62
67
|
) {
|
|
63
|
-
|
|
64
|
-
cursor
|
|
68
|
+
parts.push("&");
|
|
69
|
+
cursor = amp + 1;
|
|
70
|
+
amp = value.indexOf("&", cursor);
|
|
65
71
|
continue;
|
|
66
72
|
}
|
|
67
|
-
const entity = value.slice(
|
|
73
|
+
const entity = value.slice(amp + 1, absoluteSemicolon);
|
|
68
74
|
const named = NAMED_ENTITIES.get(entity.toLowerCase());
|
|
69
75
|
let decoded = named;
|
|
70
76
|
if (!decoded && entity.startsWith("#")) {
|
|
@@ -84,14 +90,16 @@ export const decodeHtmlEntitiesOnce = (value: string): string => {
|
|
|
84
90
|
decoded = String.fromCodePoint(codePoint);
|
|
85
91
|
}
|
|
86
92
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
output += decoded;
|
|
91
|
-
}
|
|
93
|
+
parts.push(
|
|
94
|
+
decoded === undefined ? value.slice(amp, absoluteSemicolon + 1) : decoded
|
|
95
|
+
);
|
|
92
96
|
cursor = absoluteSemicolon + 1;
|
|
97
|
+
amp = value.indexOf("&", cursor);
|
|
98
|
+
}
|
|
99
|
+
if (cursor < value.length) {
|
|
100
|
+
parts.push(value.slice(cursor));
|
|
93
101
|
}
|
|
94
|
-
return
|
|
102
|
+
return parts.join("");
|
|
95
103
|
};
|
|
96
104
|
|
|
97
105
|
interface HtmlTag {
|
|
@@ -124,25 +132,30 @@ const readTag = (source: string, start: number): HtmlTag | undefined => {
|
|
|
124
132
|
* Script/style contents and comments are discarded; entities decode once.
|
|
125
133
|
*/
|
|
126
134
|
export const htmlFragmentToText = (source: string): string => {
|
|
127
|
-
let
|
|
135
|
+
let lt = source.indexOf("<");
|
|
136
|
+
if (lt === -1) return decodeHtmlEntitiesOnce(source);
|
|
137
|
+
const parts: string[] = [];
|
|
128
138
|
let cursor = 0;
|
|
129
139
|
let blockedName: "script" | "style" | undefined;
|
|
130
140
|
let blockedDepth = 0;
|
|
131
|
-
while (
|
|
132
|
-
if (
|
|
133
|
-
|
|
134
|
-
cursor += 1;
|
|
135
|
-
continue;
|
|
141
|
+
while (lt !== -1) {
|
|
142
|
+
if (!blockedName && lt > cursor) {
|
|
143
|
+
parts.push(source.slice(cursor, lt));
|
|
136
144
|
}
|
|
137
|
-
if (source.startsWith("<!--",
|
|
138
|
-
const commentEnd = source.indexOf("-->",
|
|
139
|
-
if (commentEnd < 0)
|
|
145
|
+
if (source.startsWith("<!--", lt)) {
|
|
146
|
+
const commentEnd = source.indexOf("-->", lt + 4);
|
|
147
|
+
if (commentEnd < 0) {
|
|
148
|
+
cursor = source.length;
|
|
149
|
+
break;
|
|
150
|
+
}
|
|
140
151
|
cursor = commentEnd + 3;
|
|
152
|
+
lt = source.indexOf("<", cursor);
|
|
141
153
|
continue;
|
|
142
154
|
}
|
|
143
|
-
const tag = readTag(source,
|
|
155
|
+
const tag = readTag(source, lt);
|
|
144
156
|
if (!tag) {
|
|
145
|
-
if (!blockedName)
|
|
157
|
+
if (!blockedName) parts.push(source.slice(lt));
|
|
158
|
+
cursor = source.length;
|
|
146
159
|
break;
|
|
147
160
|
}
|
|
148
161
|
cursor = tag.end + 1;
|
|
@@ -152,14 +165,19 @@ export const htmlFragmentToText = (source: string): string => {
|
|
|
152
165
|
else blockedDepth += 1;
|
|
153
166
|
if (blockedDepth === 0) blockedName = undefined;
|
|
154
167
|
}
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
168
|
+
} else if (
|
|
169
|
+
!tag.closing &&
|
|
170
|
+
(tag.name === "script" || tag.name === "style")
|
|
171
|
+
) {
|
|
158
172
|
blockedName = tag.name;
|
|
159
173
|
blockedDepth = 1;
|
|
160
|
-
|
|
174
|
+
} else if (!tag.closing && tag.name === "br") {
|
|
175
|
+
parts.push("\n");
|
|
161
176
|
}
|
|
162
|
-
|
|
177
|
+
lt = source.indexOf("<", cursor);
|
|
178
|
+
}
|
|
179
|
+
if (!blockedName && cursor < source.length) {
|
|
180
|
+
parts.push(source.slice(cursor));
|
|
163
181
|
}
|
|
164
|
-
return decodeHtmlEntitiesOnce(
|
|
182
|
+
return decodeHtmlEntitiesOnce(parts.join(""));
|
|
165
183
|
};
|
|
@@ -33,19 +33,11 @@ export function includesBytes(bytes: Uint8Array, needle: Uint8Array): boolean {
|
|
|
33
33
|
if (needle.length === 0 || bytes.length < needle.length) {
|
|
34
34
|
return false;
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
)
|
|
41
|
-
for (let offset = 0; offset < needle.length; offset += 1) {
|
|
42
|
-
if (bytes[index + offset] !== needle[offset]) {
|
|
43
|
-
continue outer;
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
return true;
|
|
47
|
-
}
|
|
48
|
-
return false;
|
|
36
|
+
return (
|
|
37
|
+
Buffer.from(bytes.buffer, bytes.byteOffset, bytes.byteLength).indexOf(
|
|
38
|
+
needle
|
|
39
|
+
) !== -1
|
|
40
|
+
);
|
|
49
41
|
}
|
|
50
42
|
|
|
51
43
|
/** An encrypted (password-protected) OOXML workbook: a CFB container. */
|
|
@@ -16,6 +16,9 @@ const BYTE_LF = 0x0a;
|
|
|
16
16
|
const BYTE_CR = 0x0d;
|
|
17
17
|
const UTF8_BOM = new Uint8Array([0xef, 0xbb, 0xbf]);
|
|
18
18
|
|
|
19
|
+
const createUtf8Decoder = (): TextDecoder =>
|
|
20
|
+
new TextDecoder("utf-8", { fatal: true });
|
|
21
|
+
|
|
19
22
|
const concatenate = (
|
|
20
23
|
parts: readonly Uint8Array[],
|
|
21
24
|
byteLength: number
|
|
@@ -38,30 +41,37 @@ const stripLineEnvelope = (
|
|
|
38
41
|
let end = bytes.byteLength;
|
|
39
42
|
if (
|
|
40
43
|
lineNumber === 1 &&
|
|
41
|
-
end >=
|
|
42
|
-
|
|
44
|
+
end >= 3 &&
|
|
45
|
+
bytes[0] === UTF8_BOM[0] &&
|
|
46
|
+
bytes[1] === UTF8_BOM[1] &&
|
|
47
|
+
bytes[2] === UTF8_BOM[2]
|
|
43
48
|
) {
|
|
44
|
-
start =
|
|
49
|
+
start = 3;
|
|
45
50
|
}
|
|
46
51
|
if (end > start && bytes[end - 1] === BYTE_CR) end -= 1;
|
|
47
|
-
return
|
|
52
|
+
return start === 0 && end === bytes.byteLength
|
|
53
|
+
? bytes
|
|
54
|
+
: bytes.subarray(start, end);
|
|
48
55
|
};
|
|
49
56
|
|
|
50
|
-
const
|
|
51
|
-
|
|
52
|
-
byteLength: number,
|
|
57
|
+
const decodeSingleBytes = (
|
|
58
|
+
rawBytes: Uint8Array,
|
|
53
59
|
lineNumber: number,
|
|
54
|
-
terminated: boolean
|
|
60
|
+
terminated: boolean,
|
|
61
|
+
decoderState: { decoder: TextDecoder }
|
|
55
62
|
): Utf8LineResult => {
|
|
56
|
-
const bytes = stripLineEnvelope(
|
|
63
|
+
const bytes = stripLineEnvelope(rawBytes, lineNumber);
|
|
57
64
|
try {
|
|
58
65
|
return {
|
|
59
66
|
ok: true,
|
|
60
67
|
lineNumber,
|
|
61
|
-
text:
|
|
68
|
+
text: decoderState.decoder.decode(bytes),
|
|
62
69
|
terminated,
|
|
63
70
|
};
|
|
64
71
|
} catch {
|
|
72
|
+
// Recreate the fatal decoder after an error so no runtime-specific error
|
|
73
|
+
// state can bleed into subsequent valid lines.
|
|
74
|
+
decoderState.decoder = createUtf8Decoder();
|
|
65
75
|
return {
|
|
66
76
|
ok: false,
|
|
67
77
|
lineNumber,
|
|
@@ -71,6 +81,20 @@ const decodeLine = (
|
|
|
71
81
|
}
|
|
72
82
|
};
|
|
73
83
|
|
|
84
|
+
const decodeLine = (
|
|
85
|
+
parts: readonly Uint8Array[],
|
|
86
|
+
byteLength: number,
|
|
87
|
+
lineNumber: number,
|
|
88
|
+
terminated: boolean,
|
|
89
|
+
decoderState: { decoder: TextDecoder }
|
|
90
|
+
): Utf8LineResult =>
|
|
91
|
+
decodeSingleBytes(
|
|
92
|
+
concatenate(parts, byteLength),
|
|
93
|
+
lineNumber,
|
|
94
|
+
terminated,
|
|
95
|
+
decoderState
|
|
96
|
+
);
|
|
97
|
+
|
|
74
98
|
/**
|
|
75
99
|
* Split an async byte source without retaining an unbounded physical line.
|
|
76
100
|
* Invalid UTF-8 and oversized lines are isolated so later siblings can proceed.
|
|
@@ -80,6 +104,7 @@ export async function* readBoundedUtf8Lines(
|
|
|
80
104
|
maxLineBytes: number
|
|
81
105
|
): AsyncGenerator<Utf8LineResult> {
|
|
82
106
|
const safeMaxLineBytes = Math.max(1, Math.floor(maxLineBytes));
|
|
107
|
+
const decoderState = { decoder: createUtf8Decoder() };
|
|
83
108
|
let parts: Uint8Array[] = [];
|
|
84
109
|
let lineBytes = 0;
|
|
85
110
|
let lineNumber = 1;
|
|
@@ -94,37 +119,50 @@ export async function* readBoundedUtf8Lines(
|
|
|
94
119
|
|
|
95
120
|
for await (const chunk of source) {
|
|
96
121
|
let segmentStart = 0;
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
122
|
+
while (segmentStart < chunk.byteLength) {
|
|
123
|
+
const nl = chunk.indexOf(BYTE_LF, segmentStart);
|
|
124
|
+
if (nl === -1) break;
|
|
125
|
+
const segmentLen = nl - segmentStart;
|
|
126
|
+
if (!oversized && lineBytes + segmentLen <= safeMaxLineBytes) {
|
|
127
|
+
if (parts.length === 0) {
|
|
128
|
+
yield decodeSingleBytes(
|
|
129
|
+
chunk.subarray(segmentStart, nl),
|
|
130
|
+
lineNumber,
|
|
131
|
+
true,
|
|
132
|
+
decoderState
|
|
133
|
+
);
|
|
134
|
+
} else {
|
|
135
|
+
if (segmentLen > 0) parts.push(chunk.subarray(segmentStart, nl));
|
|
136
|
+
yield decodeLine(
|
|
137
|
+
parts,
|
|
138
|
+
lineBytes + segmentLen,
|
|
139
|
+
lineNumber,
|
|
140
|
+
true,
|
|
141
|
+
decoderState
|
|
142
|
+
);
|
|
143
|
+
}
|
|
103
144
|
} else {
|
|
104
|
-
oversized = true;
|
|
105
|
-
}
|
|
106
|
-
if (oversized) {
|
|
107
145
|
yield {
|
|
108
146
|
ok: false,
|
|
109
147
|
lineNumber,
|
|
110
148
|
reason: "line_too_large",
|
|
111
149
|
terminated: true,
|
|
112
150
|
};
|
|
113
|
-
} else {
|
|
114
|
-
yield decodeLine(parts, lineBytes, lineNumber, true);
|
|
115
151
|
}
|
|
116
152
|
reset();
|
|
117
|
-
segmentStart =
|
|
153
|
+
segmentStart = nl + 1;
|
|
118
154
|
}
|
|
119
155
|
|
|
120
|
-
const
|
|
121
|
-
if (
|
|
122
|
-
if (
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
156
|
+
const remainderLen = chunk.byteLength - segmentStart;
|
|
157
|
+
if (remainderLen > 0) {
|
|
158
|
+
if (!oversized && lineBytes + remainderLen <= safeMaxLineBytes) {
|
|
159
|
+
parts.push(chunk.subarray(segmentStart).slice());
|
|
160
|
+
lineBytes += remainderLen;
|
|
161
|
+
} else {
|
|
162
|
+
oversized = true;
|
|
163
|
+
parts = [];
|
|
164
|
+
lineBytes = 0;
|
|
165
|
+
}
|
|
128
166
|
}
|
|
129
167
|
}
|
|
130
168
|
|
|
@@ -136,6 +174,6 @@ export async function* readBoundedUtf8Lines(
|
|
|
136
174
|
terminated: false,
|
|
137
175
|
};
|
|
138
176
|
} else if (lineBytes > 0) {
|
|
139
|
-
yield decodeLine(parts, lineBytes, lineNumber, false);
|
|
177
|
+
yield decodeLine(parts, lineBytes, lineNumber, false, decoderState);
|
|
140
178
|
}
|
|
141
179
|
}
|
|
@@ -101,10 +101,11 @@ const localIdentity = (
|
|
|
101
101
|
|
|
102
102
|
const segmentRecord = (
|
|
103
103
|
segment: TranscriptSegment,
|
|
104
|
-
|
|
104
|
+
namespace: string,
|
|
105
|
+
defaultSessionTitle: string,
|
|
105
106
|
occurrences: Map<string, number>
|
|
106
107
|
): RecordAdapterRecord => {
|
|
107
|
-
const sessionTitle = segment.sessionTitle ??
|
|
108
|
+
const sessionTitle = segment.sessionTitle ?? defaultSessionTitle;
|
|
108
109
|
const label = segment.speaker
|
|
109
110
|
? `${sessionTitle} — ${segment.speaker}`
|
|
110
111
|
: sessionTitle;
|
|
@@ -143,10 +144,7 @@ const segmentRecord = (
|
|
|
143
144
|
});
|
|
144
145
|
}
|
|
145
146
|
return {
|
|
146
|
-
stableId: `transcript:${
|
|
147
|
-
segment,
|
|
148
|
-
occurrences
|
|
149
|
-
)}`,
|
|
147
|
+
stableId: `transcript:${namespace}:${localIdentity(segment, occurrences)}`,
|
|
150
148
|
sourceLocator: segment.sourceLocator,
|
|
151
149
|
sourceHash: hashRecordValue(
|
|
152
150
|
"gno-transcript-segment-source-v1",
|
|
@@ -259,6 +257,8 @@ export const createTranscriptAdapter = (
|
|
|
259
257
|
yield { type: "snapshot", state: "partial" };
|
|
260
258
|
return;
|
|
261
259
|
}
|
|
260
|
+
const namespace = sourceNamespace(input);
|
|
261
|
+
const defaultSessionTitle = fileTitle(input.relativePath);
|
|
262
262
|
const occurrences = new Map<string, number>();
|
|
263
263
|
let hadFailure = false;
|
|
264
264
|
try {
|
|
@@ -270,7 +270,12 @@ export const createTranscriptAdapter = (
|
|
|
270
270
|
}
|
|
271
271
|
yield {
|
|
272
272
|
type: "record",
|
|
273
|
-
record: segmentRecord(
|
|
273
|
+
record: segmentRecord(
|
|
274
|
+
event.segment,
|
|
275
|
+
namespace,
|
|
276
|
+
defaultSessionTitle,
|
|
277
|
+
occurrences
|
|
278
|
+
),
|
|
274
279
|
};
|
|
275
280
|
}
|
|
276
281
|
} catch {
|