Commit 78e14b2
fix(parsers): structure-preserving knowledge base parsers with before/after benchmark (#7709)
* chore(parsers): add parser quality evaluation framework
Ground-truth corpus generator, real-world fetcher, bun harness over the
production parseBuffer path, reference extractors and scorer, plus the
plan and findings from the 2026-09-09 audit.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): index spreadsheet cells as display text
`XlsxParser` converted sheets without `raw: false`, so the indexed text held
stored values rather than what a user sees: dates as Excel serials (46085),
20% as 0.2, $1,250.00 as 1250, booleans as `true`, and ODS dates as
`String(Date)` in the worker's local time zone. The Google Drive connector
exports every Google Sheet through this parser while the Sheets and Excel
connectors already request formatted text, so the same sheet indexed
differently by path. The Files viewer had the same defect.
Read with `cellDates` + `cellNF` and convert with `raw: false`, rewriting
only the two cases the file's own text gets wrong inside the bounded window:
dates become zone-free ISO text from the UTC fields SheetJS parsed, and
General numbers print their full stored value instead of Excel's 11-char
rendering (4111111111111111 -> 4.11111E+15). The shared pass handles dense
and sparse sheets so the viewer reuses it without pulling `xlsx` into the
client bundle.
The parser-eval fixture used `0.#%`, which Excel renders as `20.%`; it now
uses `0%` / `0.0%` so the spec strings match Excel. The `sheet-wide` row
builder is also typed so the script type-checks.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): walk office document structure instead of flattening cells
DOCX now routes mammoth's HTML rendering through the shared HTML
structured-text walker so tables keep their rows, lists keep their
markers, and footnotes survive; the unread metadata.html field is gone.
PPTX and ODT/ODP get dedicated XML walkers that render tables row by
row, skip slide-number/date/header/footer placeholders, read presenter
notes from the notes body placeholder only, and drop ODF annotations
and tracked deletions. Legacy OLE .ppt is rejected as unsupported_type
instead of scraping printable bytes from the container.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): decode text by encoding, sniff bytes before routing, read legacy .doc
Text parsers decoded every buffer as UTF-8 and then stripped U+FFFD, so a
Latin-1 or Windows-1252 file silently lost every accented character, a UTF-8
BOM leaked into content and broke JSON.parse, and UTF-16 only worked for
ASCII. `decodeTextBuffer` (BOM > strict UTF-8 with a guarded truncated-tail
retry > Windows-1252) now backs txt/md/csv/json/jsonl/yaml, the .doc plain-text
fallback and the connectors' text decode, and records `encoding`/`warning`
in metadata.
`parseBuffer` routed on the caller-supplied extension alone. `sniff.ts` now
identifies the bytes (PDF, OLE2, ZIP central-directory part names, ODF
mimetype, UTF-16 layout, HTML head) and reconciles them with the extension's
family: a sniffed kind with its own parser overrides the route and records
`detectedType`; binary/unknown bytes under a mismatched family are a typed
`invalid_format` instead of mojibake or placeholder prose.
Legacy OLE .doc goes through word-extractor (body, headers, footers,
footnotes, endnotes; Word 6/95 magic maps to `unsupported_type`); the byte
scrape that returned ZIP part names as degraded prose is deleted. Legacy .ppt
is dropped from the registry, upload and connector allowlists and Chat's
parseable set so it is refused up front. Chat's file reader and the internal
file tool now treat `degraded` output as a parse failure.
pdf.js `InvalidPDFException`/`FormatError`/`PasswordException` are mapped to
typed parser errors at the single `openPdfDocument` choke point, and the zip
guard's `ArchiveIntegrityError` surfaces from `parseBuffer` as a typed
`invalid_format`, so neither classifies as transient and retries forever.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): decode HTML by detected encoding and add before/after benchmark
Wires decodeTextBuffer into the HTML parser, refreshes the degraded
docblock now that legacy formats raise typed errors, and adds the large
corpus harness plus the regression-gated comparer.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): rebuild PDF line and paragraph structure from item geometry
The PDF parser collapsed every page to a single line and concatenated
items without separators, so the chunker fell back to sentence splits,
words fused across Form XObject boundaries and backwards x-moves, and
running headers/footers landed mid-sentence in most chunks.
- Build positioned lines from pdf.js item transforms; derive separators
from baseline shifts, backwards x-moves, and word-sized gaps, falling
back to hasEOL when an item carries no geometry
- Join lines per page with paragraph breaks from the median pitch and
height changes, rejoin same-row and wrapped table cells, and
dehyphenate line-end breaks unless the compound appears intact in the
document
- Suppress repeated header/footer furniture and page numbers across
pages, keeping the first occurrence of each
- Prefix short oversized lines with a heading marker
- Replace the whitespace collapse with a structure-preserving normaliser
and join pages with a paragraph break
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): tighten benchmark-found edge cases
Ambiguous archives and binary layouts stay on the SheetJS and legacy
Word routes instead of being refused; line-end hyphens are removed only
when the document shows the joined word; page numbers printed inside a
wide margin are dropped from a page's edge lines; time-of-day cells no
longer carry the 1899 epoch; table cells with several paragraphs keep a
space between them.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* docs(parsers): record the before/after parser benchmark
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* style(parsers): apply biome formatting
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): accept YAML document streams and JSON with comments
Kubernetes manifests, Helm output and CI fixtures hold several YAML
documents separated by ---; js-yaml's single-document load rejected them
outright. A stream now becomes one item per document. JSON files with
comments or trailing commas (tsconfig, editor settings) parse leniently
after strict parsing fails, with a warning in metadata.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): render elapsed, time-only and General cells as Excel does
Elapsed formats (`[h]:mm`, `[mm]:ss`) are durations; `cellDates` still
parses them into a Date, so the ISO rewrite fabricated `1900-01-01T06:00:00`
where Excel shows `30:00`. Their SSF-rendered `w` is now kept. A time-only
cell was decided by its epoch year, which breaks in a 1904 workbook where
`h:mm:ss` landed on `1904-01-01T12:29:59`; the decision now comes from the
format (no `y`/`d`, and every `m` run beside hours or seconds), verified for
xlsx, xls, xlsb and ods in both epochs. General numbers round fractions to
Excel's 15 significant digits (`=0.1+0.2` reads `0.3`) while integers stay
exact.
The Files viewer read its workbook without `cellDates`/`cellNF`, which left
the normalizer overwriting every rendered `w`; the read now lives in
`readXlsxWorkbook` with the display options, and its test builds the fixture
through that read path. A tab or line break inside a cell no longer splits
the row.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): round float date serials to the nearest second
A serial such as 45366.572916666664 parses to 13:44:59.999, and slicing the
ISO string truncated it to 13:44:59 — one second early for three of twelve
probed cells. The instant is rounded to the nearest second before either the
date-time or time-only text is formatted, and a value that rounds up to
midnight renders as a whole date.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* chore(parser-eval): harden the comparer and pin the benchmark corpus
Sample reference lines across the whole document instead of its head,
add count-aware word-depletion checks so a repeated table header that
vanishes is visible, score noise symmetrically, and commit the corpus
build scripts with a SHA-256 manifest so the 961-file benchmark can be
rebuilt. Adds a README with requirements.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): close audit findings on byte sniffing, decoding and legacy formats
Routing and the KB pipeline:
- A non-PDF named .pdf (HTML error page, plain text) is rejected as a
permanent `invalid_file` in `readEmbeddedPdfText` instead of being indexed
as the "text layer" or sent to OCR to fail terminally; the document
processor logs `detectedType`/`warning` at info with the filename (no
document id is in scope in that module).
- The HTML override now applies only to `.txt` and `.md` (a `.md` opening
with `<!DOCTYPE html>` is deliberately treated as HTML); an HTML document
under csv/json/jsonl/yaml is `invalid_format`.
- RTF (`{\rtf` at offset 0) is a sniffed kind and is `unsupported_type`
under any extension, so control words are never indexed as prose.
- `%PDF-` is searched through the first KiB only under a declared `.pdf`;
elsewhere it must be at offset 0 (after BOM/whitespace), so a `.txt` that
mentions the magic string stays text.
- NUL bytes in a declared text file keep the text route: the decoder handles
UTF-16/Windows-1252 and the sanitizer strips stray NULs. Recognised
containers under a text extension are still refused.
- `resolveParserExtension` throws `FileParserError('unsupported_type')`, so
stored `.ppt` documents dead-letter as permanent instead of burning the
retry budget as transient.
- Workspace-file "get content" (`internal/file/operations.ts`) treats
`degraded` output as a parse failure like the other two tool paths.
Decoding:
- Windows-1252 uses the runtime `TextDecoder` when a module-init self-test
proves the label is real (Bun 1.3.14), else a one-pass table decode into
UTF-16 code units. 100 MB of C1 bytes: 379 ms / +200 MB native,
286 ms / +401 MB table (was ~4 s / +5.4 GB).
- Connectors sftp, s3, databricks, google-drive and bitbucket decode through
`decodeTextBuffer` (bitbucket previously skipped non-UTF-8 files; it now
indexes them decoded). Connectors hash source revisions (blob sha, etag,
rev), not decoded text, so there is no mass re-sync: documents indexed
earlier with mojibake stay as they are until the source changes.
Legacy .doc: text boxes are a sixth extracted section; word-extractor's raw
`RangeError` text is replaced by the stable "This .doc file could not be
read".
Behaviour notes: UTF-32 input is not recognised and decodes as Windows-1252;
BOM-less UTF-16 whose code units are mostly non-ASCII (CJK) does not match
the NUL-layout heuristic and also falls to Windows-1252 — the warning now
says the file may use another encoding. Stale `.ppt` mentions removed from
the files-audit OpenAPI description (regenerated), the Box representation
list, `OFFICE_REPAIR_EXTENSIONS` and two TSDoc blocks; the package.json
re-sort from the previous commit is reverted.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): dedupe nested tables, sniff encrypted OOXML, cap XML parts
Nested tables in HTML and DOCX were emitted once glued into the outer
cell and again as rows of their own; the HTML walker now visits only a
table's direct rows and renders a nested table inline as its cells
joined with ' / '. The ODF walker does the same inside cells. An
encrypted .docx/.pptx/.xlsx is an OLE container carrying
EncryptedPackage and EncryptionInfo streams, so the sniff now reports it
as encrypted-ooxml and every route maps it to encrypted_file instead of
unsupported_type or a mojibake plaintext fallback. The presentation and
ODF walkers bound each XML part at 16 MB before parsing, honor
mc:AlternateContent, skip slidenum/datetime fields anywhere, clamp notes
targets under ppt/notesSlides, emit picture alt text, and reject an
archive with no content.xml as invalid_format.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* chore(parsers): re-record tool-registry module baseline for the new parser modules
The knowledge page reaches document-processor and therefore the file
parsers; seven new parser modules plus word-extractor's dependency tree
add server-graph modules beyond the allowed drift.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): keep table headers, bound PDF assembly, disable heading markers
Furniture suppression treated any band text repeating across pages as a
running header, which deleted multi-page table headers (IRS tax tables,
NIST recommendation tables, EIC tables, DFAST captions). A band group is
now exempt when it runs into the body at line pitch, when its key also
occurs in body positions, or when dropping it would orphan a hyphenated
word; folio candidates get the same flow test so edge table cells
survive, and roman numerals must parse and fit the page count.
joinLines accumulated the page in one string and ran anchored regexes
over it per line, which was quadratic (40k lines: 72 s, now 7 ms); the
hyphen and compound scans are bounded to the line tail, assembly yields
to the event loop and honours the abort signal, and the line count and
word set are capped. Geometry separators no longer count against the
character budget, and preview output that overflows after decoration
sets the truncated flag.
Heading markers are off by default: on documents dominated by table or
footnote text the estimated body height turned prose into headings that
the chunker then split per line. The estimator now weighs prose-like
lines only and skips runs of same-height lines for when it is enabled.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): keep date fields, drop file-name image alt text, fast-path plain cells
Only the slide-number field is layout text; date and time fields outside
a dt placeholder are content, and skipping them emptied a deck made of
them. Image alternative text that is a bare file name or an auto caption
is noise, so the HTML, PresentationML, and OpenDocument walkers share
one filter. A table cell with no element children is read directly
instead of running the block-spacing and nested-table queries.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* docs(parsers): regenerate the benchmark from the final run
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): walk slides in display order and read SmartArt and chart text
The PPTX walker sorted physical slide part names, but a deck reordered in
PowerPoint keeps its old part names and changes only p:sldIdLst, so it
was indexed out of order. Slides now follow the presentation's id list
resolved through its rels, skipping ids whose part is missing and falling
back to part numbering only when nothing resolves. Graphic frames that
hold SmartArt or a chart were dropped entirely; the diagram data part's
dgm:pt text bodies and a modest chart summary (title, axis titles,
series, categories) are now emitted, with connector text included. Every
relationship target is clamped under ppt/ and read through the per-part
size cap.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
* fix(parsers): bound ODF whitespace expansion and accept absolute OPC targets
An ODF text:s element passed its text:c count straight to String.repeat,
so one tiny element could request a multi-gigabyte allocation. Each run
is now capped at 100 spaces, every emitted piece is charged against a
16 MiB document budget that throws complexity_limit before later parts
are inflated, and both walkers assert the assembled text against the
same ceiling. The line-end trim that followed was quadratic on a long
whitespace run — a document inside the budget could still hang it — so
it is now a linear per-line trimEnd.
OPC relationship targets may be package-absolute (/ppt/slides/slide1.xml);
the PPTX resolver joined them onto the base directory and skipped those
parts. A leading slash now resolves from the package root under the same
ppt/ clamp.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>1 parent b8ceb2e commit 78e14b2
109 files changed
Lines changed: 16102 additions & 758 deletions
File tree
- apps
- docs
- sim
- app/workspace/[workspaceId]/files/components/file-viewer
- connectors
- azure-devops
- bitbucket
- box
- databricks
- dropbox
- github
- gitlab
- google-drive
- s3
- sftp
- lib
- api/contracts/v2/openapi
- copilot/vfs
- file-parsers
- internal/file
- knowledge/documents
- uploads/utils
- workspace-files/application
- scripts/parser-eval
- bench
- types
- scripts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
745 | 745 | | |
746 | 746 | | |
747 | 747 | | |
748 | | - | |
| 748 | + | |
749 | 749 | | |
750 | 750 | | |
751 | 751 | | |
| |||
Lines changed: 36 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| 30 | + | |
29 | 31 | | |
30 | 32 | | |
31 | 33 | | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
71 | 74 | | |
72 | 75 | | |
73 | 76 | | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
74 | 110 | | |
Lines changed: 30 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
2 | 6 | | |
3 | 7 | | |
4 | 8 | | |
5 | 9 | | |
6 | 10 | | |
7 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
8 | 23 | | |
9 | 24 | | |
10 | 25 | | |
| |||
18 | 33 | | |
19 | 34 | | |
20 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
21 | 47 | | |
22 | 48 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
| 49 | + | |
| 50 | + | |
27 | 51 | | |
28 | 52 | | |
29 | 53 | | |
| |||
Lines changed: 2 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
58 | | - | |
| 59 | + | |
59 | 60 | | |
60 | 61 | | |
61 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
1182 | 1183 | | |
1183 | 1184 | | |
1184 | 1185 | | |
1185 | | - | |
| 1186 | + | |
1186 | 1187 | | |
1187 | 1188 | | |
1188 | 1189 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
774 | 774 | | |
775 | 775 | | |
776 | 776 | | |
777 | | - | |
| 777 | + | |
778 | 778 | | |
779 | 779 | | |
780 | 780 | | |
| |||
784 | 784 | | |
785 | 785 | | |
786 | 786 | | |
787 | | - | |
788 | | - | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
789 | 790 | | |
790 | 791 | | |
791 | 792 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
1240 | 1240 | | |
1241 | 1241 | | |
1242 | 1242 | | |
1243 | | - | |
1244 | | - | |
1245 | | - | |
1246 | | - | |
1247 | | - | |
1248 | | - | |
1249 | | - | |
| 1243 | + | |
1250 | 1244 | | |
1251 | 1245 | | |
1252 | 1246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
132 | 133 | | |
133 | 134 | | |
134 | 135 | | |
135 | | - | |
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
| |||
319 | 319 | | |
320 | 320 | | |
321 | 321 | | |
322 | | - | |
| 322 | + | |
323 | 323 | | |
324 | 324 | | |
325 | 325 | | |
| |||
347 | 347 | | |
348 | 348 | | |
349 | 349 | | |
350 | | - | |
| 350 | + | |
351 | 351 | | |
352 | 352 | | |
353 | 353 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
586 | 587 | | |
587 | 588 | | |
588 | 589 | | |
589 | | - | |
| 590 | + | |
590 | 591 | | |
591 | 592 | | |
592 | 593 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
| |||
147 | 148 | | |
148 | 149 | | |
149 | 150 | | |
150 | | - | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
0 commit comments