Skip to content

Conversation

@steveluc
Copy link
Contributor

Summary

  • Adds schema-to-grammar generator that creates .agr grammars from TypeAgent action schemas
  • Enables extending existing grammars with new examples and improvements
  • Uses Claude to identify common actions, generate examples, and create complete grammars
  • Includes validation and auto-fixing of generated grammars

Key Features

Grammar Generation

  • Identifies most common actions in a schema using Claude
  • Generates natural language examples for those actions
  • Creates complete .agr grammar with shared sub-rules
  • Validates syntax and automatically fixes errors (up to 3 retries)
  • Handles union types (e.g., CalendarTime | CalendarTimeRange)

Grammar Extension (New)

  • Load existing .agr file with --input/-i flag
  • Provide improvement instructions with --improve flag
  • Outputs to .extended.agr by default to avoid overwriting original
  • Maintains consistency with existing patterns while adding improvements

CLI Commands

# Generate new grammar from schema
generate-grammar packages/agents/player/dist/playerSchema.pas.json

# Extend existing grammar
generate-grammar -i player.agr packages/agents/player/dist/playerSchema.pas.json

# Extend with specific improvements
generate-grammar -i player.agr --improve "Add more polite variations" packages/agents/player/dist/playerSchema.pas.json

Technical Implementation

  • New files: schemaToGrammarGenerator.ts, generate-grammar-cli.ts
  • Modified: schemaReader.ts (union type support), index.ts (exports)
  • Uses @anthropic-ai/claude-agent-sdk for Claude interactions
  • Uses action-grammar package for validation

Testing

  • Successfully generated calendar grammar with shared sub-rules
  • Successfully extended calendar grammar with natural improvements
  • All regexes reviewed for security (non-greedy, proper anchors)

🤖 Generated with Claude Code

steveluc and others added 8 commits January 22, 2026 14:34
Created a VS Code extension that provides comprehensive syntax highlighting
for Action Grammar files used in TypeAgent.

Features:
- Rule definition highlighting (@ <RuleName> = ...)
- Rule reference highlighting (<RuleName>)
- Capture syntax highlighting ($(name:Type) and $(name))
- Action object highlighting with embedded JavaScript syntax (-> { })
- Operator highlighting (|, ?, *, +)
- Comment support (//)
- String literal highlighting
- Bracket matching and auto-closing pairs
- Language configuration for editor features

File structure:
- package.json: Extension manifest with language contributions
- language-configuration.json: Editor behavior configuration
- syntaxes/agr.tmLanguage.json: TextMate grammar definition
- README.md: Installation and usage documentation
- OVERVIEW.md: Technical implementation details
- sample.agr: Sample file demonstrating all syntax features
- LICENSE: MIT license

The extension uses TextMate grammar for syntax highlighting and follows
VS Code extension best practices.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Added required package.json fields: license, author, homepage, repository, private
- Sorted package.json fields according to project conventions
- Added Trademarks section to README per Microsoft guidelines

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Reordered package.json fields to match project conventions
- Added third-party trademarks clause to README

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Used sort-package-json to ensure fields are in the correct order per project standards.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This adds a generator that creates .agr grammar files from TypeAgent action schemas.

The generator:
1. Takes a complete action schema as input
2. Identifies the most common actions and generates example requests
3. Uses Claude to generate an efficient grammar with shared sub-rules
4. Validates the grammar and automatically fixes syntax errors
5. Outputs a complete .agr file ready for use in TypeAgent

Key features:
- Automatically extracts shared patterns across actions (e.g., <Polite>, <DateExpr>)
- Handles union types (e.g., CalendarTime | CalendarTimeRange)
- Validates generated grammar using the action-grammar compiler
- Provides error feedback loop to fix syntax issues
- Exports CLI tool: generate-grammar

Files added:
- packages/agentSdkWrapper/src/schemaToGrammarGenerator.ts: Main generator class
- packages/agentSdkWrapper/src/generate-grammar-cli.ts: CLI interface

Files modified:
- packages/agentSdkWrapper/src/schemaReader.ts: Added union type handling
- packages/agentSdkWrapper/src/index.ts: Export new generator classes
- packages/agentSdkWrapper/package.json: Add action-grammar dependency and CLI command

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enables extending existing .agr grammars with new examples and improvements
rather than always generating from scratch.

New CLI options:
- --input/-i: Load existing .agr file to extend
- --improve: Provide improvement instructions to Claude

Key features:
- Extension mode uses specialized prompt to maintain consistency
- Outputs to .extended.agr by default to avoid overwriting original
- Successfully tested with calendar grammar

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@steveluc steveluc temporarily deployed to development-fork January 23, 2026 01:28 — with GitHub Actions Inactive
@steveluc steveluc temporarily deployed to development-fork January 23, 2026 01:28 — with GitHub Actions Inactive
@steveluc steveluc added this pull request to the merge queue Jan 23, 2026
Merged via the queue into main with commit 430d1b5 Jan 23, 2026
21 checks passed
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.

2 participants