Skip to content

feat(grammar): publish BAML TextMate grammar via self-updating mirror pipeline - #3986

Merged
hellovai merged 2 commits into
canaryfrom
vbv/b-870
Jul 12, 2026
Merged

feat(grammar): publish BAML TextMate grammar via self-updating mirror pipeline#3986
hellovai merged 2 commits into
canaryfrom
vbv/b-870

Conversation

@hellovai

@hellovai hellovai commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Implements B-870 (with the release mechanism moved out of the monorepo, per design discussion).

Architecture

typescript2/pkg-grammar stays the single source of truth. Every external consumer is fed through the BoundaryML/textMate-baml mirror, entirely by automation:

src/baml.ts
  └─ build → baml.tmLanguage.json + dist/ (inlined-grammar ESM)
       ├─ app-vscode-ext / app-promptfiddle   (existing sync, unchanged)
       └─ sync-grammar-mirror workflow → BoundaryML/textMate-baml
            ├─ npm @boundaryml/baml-grammar   (mirror's own publish.yml, OIDC)
            ├─ GitHub Linguist                (auto submodule bump each release)
            └─ Shiki grammar registry         (weekly refetch; follow-up PR)

What's in this PR

  • dist artifact: build.ts emits dist/index.js + .d.ts with the grammar inlined as a JS object literal, typed as a Shiki LanguageRegistration. npm consumers never touch JSON import attributes (Metro/React Native can't parse them).
  • language-configuration.json moves into pkg-grammar as source of truth; sync.mjs mirrors it into app-vscode-ext (pre-commit + CI guarded).
  • assemble-mirror.mjs builds the complete mirror layout from mirror/ templates: publishable package.json, README, LICENSE, grammars/baml.tmLanguage.json (Linguist's stable path), and the mirror's own npm publish workflow.
  • sync-grammar-mirror workflow (canary, path-filtered): build → verify committed artifacts → tests → assemble → push to mirror only when content actually changed (version-stamp-aware diff) → wait until the npm version appears, so a broken mirror publish is red CI here, not silence in a repo nobody watches.
  • linguist-compile-gate CI job: runs GitHub Linguist's own grammar-compiler (their Oniguruma→PCRE conversion, the exact code path GitHub runs at release time) against the freshly built grammar. Grammars valid in Shiki/VSCode can still fail there; now that fails the PR instead of .baml highlighting on github.com breaking at Linguist's next quarterly release.
  • New tests: external-consumer invariants (scopeName: source.baml, .baml fileType, grammar self-containedness), dist-vs-raw drift, strict-JSON language configuration, and a whole-repo corpus pass (1293 .baml files) catching crashes and catastrophic-backtracking regexes.
  • grammar-tests job now rebuilds and diffs, so committed artifacts can't drift from src/.

Deployment state

  • Write deploy key created on the mirror; private half stored as TEXTMATE_BAML_DEPLOY_KEY secret on this repo. ✅
  • Remaining manual bootstrap (once, after merge): first npm publish --access public of @boundaryml/baml-grammar from a mirror checkout (OIDC can't create a new package), then configure the trusted publisher (repo BoundaryML/textMate-baml, workflow publish.yml) in the npm package settings.
  • Follow-up (separate, external): PR to shikijs/textmate-grammars-themes pointing at the mirror's raw grammar URL.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Added an npm-distributable BAML grammar package with compiled runtime exports and language-configuration support.
    • Added tooling and workflows to assemble, publish, and sync grammar mirror updates.
  • Bug Fixes
    • Updated language configuration auto-closing for {# ... #} pairs.
  • CI / Tests
    • Strengthened grammar generation checks, enabled full grammar test runs, added a Linguist compile validation gate, and expanded Vitest coverage for artifacts and repo corpus tokenization.
  • Documentation / Chores
    • Updated grammar READMEs and broadened pre-commit grammar file coverage.

… pipeline

The grammar in typescript2/pkg-grammar now feeds every external consumer
through the BoundaryML/textMate-baml mirror, with no manual steps:

- build.ts also emits dist/index.js + dist/index.d.ts with the grammar
  inlined as a JS object literal (Shiki LanguageRegistration), so npm
  consumers never import JSON (Metro can't parse import attributes)
- language-configuration.json moves into pkg-grammar as the source of
  truth; sync.mjs mirrors it into app-vscode-ext like the grammar
- scripts/assemble-mirror.mjs assembles the complete mirror repo layout
  (npm package @boundaryml/baml-grammar + Linguist vendor dir + the
  mirror's own npm publish workflow) from the templates in mirror/
- sync-grammar-mirror workflow pushes the assembled mirror to
  BoundaryML/textMate-baml on grammar changes on canary, stamps a
  patch-bumped version only when content actually changed, and fails
  loudly if the npm release doesn't appear
- new linguist-compile-gate CI job runs GitHub Linguist's own
  grammar-compiler (Oniguruma->PCRE conversion) against the freshly
  built grammar, so a change that would break .baml highlighting on
  github.com fails the PR instead of Linguist's next quarterly release
- new tests: external-consumer invariants (scopeName/fileTypes/
  self-containedness), dist-vs-raw drift, strict-JSON language config,
  and a whole-repo corpus tokenization pass (1293 files) that catches
  crashes and catastrophic-backtracking regexes
- grammar-tests CI job now rebuilds and fails if committed artifacts
  drift from src/

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@linear

linear Bot commented Jul 12, 2026

Copy link
Copy Markdown

B-870

@vercel

vercel Bot commented Jul 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
beps Ready Ready Preview, Comment Jul 12, 2026 8:05am
promptfiddle Ready Ready Preview, Comment Jul 12, 2026 8:05am
promptfiddle2 Ready Ready Preview, Comment Jul 12, 2026 8:05am

Request Review

@github-actions

Copy link
Copy Markdown

⏭️ Performance benchmarks were skipped

Perf benchmarks (CodSpeed) are opt-in on pull requests — they no longer run on every push. They always run automatically after merge to canary/main.

To run them on this PR, do any of the following, then push a commit (or re-run CI):

  • Add RUN_CODSPEED=1 to the PR description, or
  • Include run-perf or /perf in the PR title or any commit message.

@coderabbitai

coderabbitai Bot commented Jul 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 86cafbbb-18be-4424-af85-53ee5b5030e8

📥 Commits

Reviewing files that changed from the base of the PR and between f14f17e and a523e75.

📒 Files selected for processing (2)
  • typescript2/app-vscode-ext/language-configuration.json
  • typescript2/pkg-grammar/language-configuration.json
🚧 Files skipped from review as they are similar to previous changes (2)
  • typescript2/pkg-grammar/language-configuration.json
  • typescript2/app-vscode-ext/language-configuration.json

📝 Walkthrough

Walkthrough

Grammar packaging now emits typed ESM artifacts and language configuration files, synchronizes mirrors, publishes an external npm package, and adds corpus, artifact, Linguist, and generated-file consistency checks to CI.

Changes

Grammar artifact pipeline

Layer / File(s) Summary
Canonical grammar and generated artifacts
typescript2/pkg-grammar/..., typescript2/app-vscode-ext/language-configuration.json, .pre-commit-config.yaml
Canonical configuration, package exports, generated ESM artifacts, mirror synchronization, pre-commit coverage, documentation, and artifact tests were expanded.
Mirror assembly and npm publishing
typescript2/pkg-grammar/mirror/*, typescript2/pkg-grammar/scripts/assemble-mirror.mjs, .github/workflows/sync-grammar-mirror.yml
The external mirror is assembled, versioned, pushed, and verified on npm, with package metadata, documentation, and publishing workflow added.
CI grammar and Linguist validation
.github/workflows/ci.yaml
CI rebuilds and checks committed grammar artifacts, runs grammar validation, validates Linguist compilation, detects configuration changes, and reports the new required job.

Estimated code review effort: 4 (Complex) | ~45 minutes

Possibly related PRs

Poem

I’m a bunny with grammar to share,
Building bright artifacts everywhere.
Mirrors hop, packages fly,
Linguist checks the syntax sky.
CI thumps its paws: all clear!

Sequence Diagram(s)

sequenceDiagram
  participant GrammarSource
  participant BuildAndTest
  participant MirrorWorkflow
  participant MirrorRepository
  participant NpmRegistry
  GrammarSource->>BuildAndTest: build and validate grammar artifacts
  BuildAndTest->>MirrorWorkflow: provide committed generated artifacts
  MirrorWorkflow->>MirrorRepository: assemble, version, commit, and push mirror
  MirrorRepository->>NpmRegistry: publish package
  MirrorWorkflow->>NpmRegistry: poll for published version
Loading
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Accurately summarizes the main change: publishing the BAML TextMate grammar through an automated self-updating mirror pipeline.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch vbv/b-870

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 12, 2026

Copy link
Copy Markdown

Binary size checks passed

7 passed

Artifact Platform File Gzip Gated on Baseline Delta Status
baml-cli Linux 🔒 21.9 MB 9.4 MB file 21.5 MB +356.3 KB (+1.7%) OK
packed-program Linux 🔒 15.8 MB 6.7 MB file 15.6 MB +138.7 KB (+0.9%) OK
baml-cli macOS 🔒 16.8 MB 8.1 MB file 16.6 MB +283.0 KB (+1.7%) OK
packed-program macOS 🔒 12.2 MB 5.9 MB file 12.1 MB +83.9 KB (+0.7%) OK
baml-cli Windows 🔒 18.4 MB 8.3 MB file 18.1 MB +271.9 KB (+1.5%) OK
packed-program Windows 🔒 13.1 MB 6.0 MB file 13.0 MB +65.0 KB (+0.5%) OK
bridge_wasm WASM 14.6 MB 🔒 4.1 MB gzip 4.1 MB +72.4 KB (+1.8%) OK

🔒 = the size this artifact is GATED on (ceiling + delta). Binaries gate on file size (installed binary); WASM gates on gzip (download size). The other size is shown for information only.


Generated by cargo size-gate · workflow run

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
typescript2/pkg-grammar/mirror/publish.yml (1)

33-36: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Consider pinning node-version instead of using latest.

node-version: latest resolves to the newest Node.js release on the runner, which can change without notice and potentially break the workflow. Consider pinning to a specific major (e.g., 22) or using lts/* for more reproducible behavior while still meeting the npm ≥ 11.5.1 requirement.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@typescript2/pkg-grammar/mirror/publish.yml` around lines 33 - 36, Update the
node-version setting in the setup-node step to use a stable pinned Node.js major
or lts/* value instead of latest, while retaining compatibility with the npm ≥
11.5.1 requirement.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@typescript2/pkg-grammar/language-configuration.json`:
- Line 14: Update the bracket-pair configuration in language-configuration.json
so the `{#` opener uses `#}` as its closing token instead of `}`; leave the
other bracket pairs unchanged.

---

Nitpick comments:
In `@typescript2/pkg-grammar/mirror/publish.yml`:
- Around line 33-36: Update the node-version setting in the setup-node step to
use a stable pinned Node.js major or lts/* value instead of latest, while
retaining compatibility with the npm ≥ 11.5.1 requirement.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: c04e1918-2240-4121-89c5-5feeb54591e0

📥 Commits

Reviewing files that changed from the base of the PR and between 663ad17 and f14f17e.

⛔ Files ignored due to path filters (1)
  • typescript2/pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (15)
  • .github/workflows/ci.yaml
  • .github/workflows/sync-grammar-mirror.yml
  • .pre-commit-config.yaml
  • typescript2/app-vscode-ext/language-configuration.json
  • typescript2/pkg-grammar/README.md
  • typescript2/pkg-grammar/language-configuration.json
  • typescript2/pkg-grammar/mirror/README.md
  • typescript2/pkg-grammar/mirror/package.json
  • typescript2/pkg-grammar/mirror/publish.yml
  • typescript2/pkg-grammar/package.json
  • typescript2/pkg-grammar/scripts/assemble-mirror.mjs
  • typescript2/pkg-grammar/scripts/build.ts
  • typescript2/pkg-grammar/scripts/sync.mjs
  • typescript2/pkg-grammar/tests/package-artifacts.test.ts
  • typescript2/pkg-grammar/tests/repo-corpus.test.ts
💤 Files with no reviewable changes (1)
  • typescript2/app-vscode-ext/language-configuration.json

Comment thread typescript2/pkg-grammar/language-configuration.json Outdated
{# ... #} is the template comment form, so typing {# should insert #},
not a bare brace.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hellovai
hellovai added this pull request to the merge queue Jul 12, 2026
Merged via the queue into canary with commit 77aa7f2 Jul 12, 2026
54 checks passed
@hellovai
hellovai deleted the vbv/b-870 branch July 12, 2026 17:37
meefs pushed a commit to meefs/baml that referenced this pull request Jul 13, 2026
…ghlight.js, tree-sitter (BoundaryML#3996)

Extends the grammar mirror pipeline (BoundaryML#3986) so every syntax-highlighting
registry on the internet is fed from this monorepo, with mirrors as
write-only build artifacts. Follows the plan in
`typescript2/pkg-grammar/DISTRIBUTION.md` (included).

## What's here

**`pkg-grammar` (extended)**
- `baml.sublime-syntax` generated from the TextMate grammar by
`scripts/emit-sublime.ts` (wired into `build`, drift-guard test).
Validated against real syntect: `bat` renders every fixture with zero
errors.
- `syntaxes/baml.xml` — hand-authored KDE KSyntaxHighlighting definition
(Kate, Pandoc via skylighting). Validates against the official KDE
`language.xsd`. Dynamic rules support arbitrary raw-string `#` depth.
- `tests/fixtures/showcase__golden_sample.baml` — canonical showcase
sample, mirrored as `samples/baml.sample` for registry submissions
(Shiki etc.).
- Mirror hardening: `SUPPORT.md` registry matrix, frozen-path contract +
read-only footer in the mirror README, `DISTRIBUTION.md` rollout
playbook.

**`pkg-grammar-hljs` (new)** → mirrors to
[BoundaryML/baml-highlightjs](https://github.com/BoundaryML/baml-highlightjs),
npm `@boundaryml/baml-highlightjs`
- highlight.js 11 language definition with Jinja `{{ }}`/`{% %}`
highlighting inside prompt bodies, raw/backtick/byte strings, full
keyword taxonomy from the real lexer.
- Tested against every `pkg-grammar` fixture (82 tests); browser/CDN
dist build generated at mirror-assembly time.

**`pkg-grammar-treesitter` (new)** → mirrors to
[BoundaryML/baml-treesitter](https://github.com/BoundaryML/baml-treesitter)
(nvim-treesitter / Zed / Helix)
- Modern tree-sitter grammar for the full current language (interfaces,
generics, lambdas, match patterns, `let`/`const` destructuring, backtick
`${}` bodies). No external scanner.
- **80/80 fixtures parse with zero ERROR/MISSING**; 63 corpus tests;
highlight queries + jinja injection into prompt bodies.
- The old `BoundaryML/tree-sitter-baml` (15 months stale) is untouched;
the Zed pin migrates later.

**Automation**
- `sync-grammar-mirror.yml` fans out to all three mirrors; npm-published
mirrors get `v*` tags (bat/Package Control/Linguist pinning).
- `grammar-tests` CI runs all three packages as a conformance gate:
every port validates against the shared fixture corpus, so a language
change a port doesn't handle fails the PR.

## Bootstrap status (already done via gh)
- [x] `BoundaryML/baml-highlightjs` + `BoundaryML/baml-treesitter`
created and seeded with assembled content (hljs tagged `v0.1.0`)
- [x] Write deploy keys added; `BAML_HIGHLIGHTJS_DEPLOY_KEY` /
`BAML_TREESITTER_DEPLOY_KEY` secrets set on this repo
- [x] First manual `npm publish` of `@boundaryml/baml-highlightjs`
(v0.1.0 on npm) + trusted publisher configured

🤖 Generated with [Claude Code](https://claude.com/claude-code)

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Added Highlight.js and Tree-sitter BAML grammar support with expanded
automated read-only mirror syncing and npm publishing.
* Expanded the generated syntax-highlighting artifacts across the
grammar family (including KDE and Sublime outputs).
* Added support for constructor field shorthand (fields without `:`) in
syntax highlighting.
* **Bug Fixes**
* Improved CI change detection to ensure grammar-impacting updates
trigger full conformance runs.
* **Tests**
* Added/extended Highlight.js and Tree-sitter test suites with new
fixtures and snapshot/golden validation.
* **Documentation**
* Added documentation for the new grammar packages and
distribution/mirroring outputs.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
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.

1 participant