Skip to content

feat(detect): classify Typst (.typ) as documents - #2921

Open
sashankh wants to merge 1 commit into
Graphify-Labs:v8from
sashankh:feat/typst-documents
Open

feat(detect): classify Typst (.typ) as documents#2921
sashankh wants to merge 1 commit into
Graphify-Labs:v8from
sashankh:feat/typst-documents

Conversation

@sashankh

Copy link
Copy Markdown

Fixes #2826.

The problem

.typ was in no extension set, so a repository that authors its report/spec/datasheet
chapters in Typst lost all of them:

>>> classify_file(Path("main.typ"))
None

The reporter's case is the common one — Markdown and the generated PDF were picked up while
the Typst sources that produced them were invisible.

The change

.typ joins DOC_EXTENSIONS. That is the one-line fix the issue proposes, and it also
carries watch for free: _WATCHED_EXTENSIONS is derived as
CODE_EXTENSIONS | DOC_EXTENSIONS | PAPER_EXTENSIONS | IMAGE_EXTENSIONS, so editing a .typ
chapter now triggers an incremental rebuild. There is a test pinning that, since the coupling
is easy to miss.

It also joins _SPLITTABLE_TEXT_SUFFIXES in file_slice.py. That module's stated precondition
is "plain-text document types ... where _file_to_text is a straight read_text, so a char
range matches the bytes the model is shown" — .typ satisfies both (_file_to_text only
special-cases .pdf). Without it, a new document type would be born on the wrong side of
_FILE_CHAR_CAP and every Typst chapter over the cap would be silently truncated rather than
sliced, which is exactly the complaint in #2900. Typst heads sections with =/== rather than
#, so the "\n#" boundary never fires, but the blank-line boundary carries it — the same
fallback .txt already relies on.

No AST extractor is added: Typst is not Markdown, and mapping it onto extract_markdown would
manufacture wrong structure. .typ goes through the semantic document pass like .txt, which
is the scope the issue asks for ("a richer follow-up could add Typst-aware text cleanup, but
simple document classification would already make Typst-authored repos much more usable").

Tests

Four, all failing on v8 before the change:

FAILED tests/test_detect.py::test_classify_typst
FAILED tests/test_detect.py::test_typst_is_watched
FAILED tests/test_detect.py::test_detect_surfaces_typst_chapters_as_documents
FAILED tests/test_file_slice.py::test_expand_oversized_typst_is_sliced_with_full_coverage

test_detect_surfaces_typst_chapters_as_documents runs the issue's repro through detect()
rather than stopping at classify_file, because "appears in the document set" is the actual
promise that was broken. The slicing test asserts the slices reconstruct the file byte for
byte, so nothing is dropped.

Verification

Windows 11 / Python 3.12.10, v8 @ b2cd362.

$ pytest tests/test_detect.py tests/test_file_slice.py -q
274 passed, 1 skipped

Full suite: no new failures — the failure set is identical to origin/v8's (50 pre-existing,
all optional-dependency, CI-history, or POSIX-only fixtures; see #2919).

.typ was in no extension set, so classify_file() returned None and a repo that
authors its report/spec chapters in Typst lost every one of them - Markdown and
the generated PDF were indexed while the sources that produced them were not.

Adding .typ to DOC_EXTENSIONS also carries watch, since _WATCHED_EXTENSIONS is
derived from it; there is a test pinning that coupling because it is easy to
miss.

.typ also joins _SPLITTABLE_TEXT_SUFFIXES. That module's precondition is a
plain-text document whose _file_to_text is a straight read_text, and .typ meets
both (_file_to_text only special-cases .pdf). Without it a brand-new document
type would land on the wrong side of _FILE_CHAR_CAP and every oversized Typst
chapter would be silently truncated instead of sliced (Graphify-Labs#2900). Typst heads
sections with = rather than #, so the heading boundary never fires and the
blank-line boundary carries it - the same fallback .txt already uses.

No AST extractor: Typst is not Markdown, and routing it to extract_markdown
would manufacture wrong structure. .typ goes through the semantic document pass
like .txt, which is the scope the issue asks for.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

@graphify-labs graphify-labs Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Graphify reviewed this change.

Looks safe to merge — no coupling regressions and no blocking issues, checked against the code graph (not a self-assessment).


Graphify review — findings

Adds .typ (Typst) as a recognized document type by extending DOC_EXTENSIONS in detect.py and _SPLITTABLE_TEXT_SUFFIXES in file_slice.py, so Typst files classify as documents, get watched, and slice at paragraph boundaries when oversized. Covers the new behavior with detect, watch, and file-slice tests.

No blocking issues surfaced.

Analysis details — impact, health, verification

Impact & health

Graphify review

Impact — 1656 functions depend on the 535 functions this change touches.

Health — this change adds coupling hotspots:

  • new: extract() — 474 callers, 42 callees
  • new: _rebuild_code() — 98 callers, 50 callees
  • new: detect() — 109 callers, 15 callees
  • new: save_manifest() — 39 callers, 11 callees
  • new: extract_files_direct() — 17 callers, 20 callees
  • new: extract_xaml() — 19 callers, 17 callees
  • new: extract_corpus_parallel() — 26 callers, 11 callees
  • new: dispatch_command() — 2 callers, 119 callees
  • …and 27 more — each is listed as a finding

Verification — 1656 functions in the blast radius were not formally verified this run (proofs are advisory here).

Gate & verification

graphify gate

PASS — objectively clean (no health regressions, tests not run — proofs not run this pass (advisory)). Grounded, not self-assessed.

Advisory (not blocking):

  • verification_scope: 941 function(s) in the blast radius were not formally verified this run

· 35 more finding(s) on lines outside this diff (see the check run).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Typst (.typ) documents in file detection

1 participant