npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@sf-agentscript/parser-tree-sitter

v2.4.0

Published

Tree-sitter parser for AgentScript language

Downloads

45

Readme

@agentscript/parser-tree-sitter

Tree-sitter grammar and parser for the AgentScript language. Provides incremental parsing via Node.js native bindings and WASM for browser environments.

Overview

This package defines the AgentScript grammar and compiles it into a fast C parser that can be used from Node.js (native N-API bindings) or the browser (WebAssembly). It is one of two parser implementations in the toolchain — the other is @agentscript/parser-javascript, a pure TypeScript parser. Both produce the same SyntaxNode tree consumed by downstream packages.

Zero internal AgentScript dependencies — this is a foundation-layer package.

How It Works

The parser is built from three pieces:

  1. grammar.js — the grammar definition, written in tree-sitter's JavaScript DSL. It describes all AgentScript syntax: blocks, fields, expressions, statements, template literals, and more. The tree-sitter CLI (tree-sitter generate) processes this file into a generated C parser (src/parser.c).

  2. src/scanner.c — a hand-written external scanner that handles tokens the generated parser cannot: INDENT, DEDENT, NEWLINE, TEMPLATE_CONTENT, and TEMPLATE_END. It maintains an indentation stack and is called by tree-sitter during parsing whenever these external tokens are valid.

  3. queries/highlights.scm — tree-sitter highlight queries that map AST node types to semantic token categories (keyword, string, comment, type, etc.). Used by the LSP and Monaco integrations for syntax highlighting.

Together, these produce:

  • Node.js native bindings (N-API) — compiled via node-gyp from the C sources. Fast, no JS overhead. Prebuilt binaries are included for Linux x64, macOS, and Windows so most users skip compilation.
  • WASM binary (tree-sitter-agentscript.wasm) — compiled via tree-sitter build --wasm. Runs in browsers and Electron via web-tree-sitter.

Tree-sitter's key advantage is incremental parsing: after an edit, only the changed region of the syntax tree is re-parsed, which makes it well-suited for editor integrations where the user is typing continuously.

Installation

pnpm add @agentscript/parser-tree-sitter

For Node.js usage, also install the tree-sitter runtime:

pnpm add tree-sitter

Usage

Node.js

import Parser from 'tree-sitter';
import AgentScript from '@agentscript/parser-tree-sitter';

const parser = new Parser();
parser.setLanguage(AgentScript);

const tree = parser.parse(`
topic billing:
    description: "Handle billing inquiries"
`);

console.log(tree.rootNode.toString());

Browser (WASM)

import initTreeSitter from 'web-tree-sitter';

await initTreeSitter.init();
const parser = new initTreeSitter();
const lang = await initTreeSitter.Language.load('path/to/tree-sitter-agentscript.wasm');
parser.setLanguage(lang);

Exports

| Export Path | Description | |-------------|-------------| | @agentscript/parser-tree-sitter | Node.js native bindings | | @agentscript/parser-tree-sitter/wasm | WASM binary | | @agentscript/parser-tree-sitter/queries/highlights.scm | Syntax highlighting queries |

Scripts

pnpm build          # Generate grammar + build Node.js bindings
pnpm build:full     # Generate + build Node.js + WASM
pnpm build:wasm     # Build WASM only
pnpm test           # Run Node.js binding tests + tree-sitter corpus tests
pnpm test:wasm      # Run WASM tests
pnpm start          # Launch tree-sitter playground (builds WASM first)
pnpm prebuild       # Create prebuilt binaries for distribution

After modifying grammar.js, always run pnpm build to regenerate the C parser and rebuild bindings.

Project Layout

grammar.js              — Grammar definition (tree-sitter DSL)
src/
  parser.c              — Generated C parser (do not edit)
  scanner.c             — Hand-written external scanner (indentation, templates)
  grammar.json          — Generated grammar metadata
queries/
  highlights.scm        — Syntax highlighting queries
bindings/
  node/                 — Node.js N-API bindings
prebuilds/              — Prebuilt binaries (Linux x64, macOS, Windows)
*.wasm                  — WebAssembly binary (after build:wasm)

License

MIT