Merged
Conversation
Add support for importing non-terminals, types, and functions from external grammar files and action schemas. This enables modular grammar composition and code reuse across grammar files. Features: - Granular imports: @import { Name1, Name2 } from "file" - Wildcard imports: @import * from "file" - Compiler validation: imported names don't trigger undefined reference errors - Local definitions take precedence over imported names Changes: - Add ImportStatement type and parsing logic to grammarRuleParser - Update compiler to track and validate imported names - Add comprehensive test coverage for import functionality - Fix parseId() to not include trailing whitespace in identifiers Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit implements proper separation between two kinds of imports in
the action grammar system:
1. Type imports - Type names from .ts files that can be referenced in
variable type specifications: $(x:TypeName)
2. Grammar imports - Non-terminal rule names from .agr files that can be
referenced as rule definitions: <RuleName>
Core Changes:
- Split CompileContext.importedNames into importedRuleNames and
importedTypeNames to track the two import kinds separately
- Import processing now distinguishes based on file extension:
* .ts files → importedTypeNames (for type references)
* .agr/.grammar files → importedRuleNames (for rule references)
- Added compile-time validation for type references:
* Detects when grammar imports are misused as types
* When type imports exist, validates that all type references are either
built-in (string, number, wildcard, word) or properly imported
* Maintains backward compatibility: types are validated at runtime if
no type imports are present
- Rule reference validation now uses importedRuleNames exclusively
Parser Improvements:
- Refactored parse() method to handle @ prefix consistently
- Moved @ token consumption from parseRuleDefinition to main parse loop
- Fixed whitespace skip count for import statement parsing
Testing:
- Added comprehensive test suite with 9 test cases covering:
* Type imports from .ts files
* Wildcard type imports
* Multiple type imports
* Built-in types not requiring imports
* Undefined type errors
* Namespace separation between grammar and type imports
* Mixed grammar and type imports
- All 304 existing tests pass, ensuring backward compatibility
Examples Updated:
- calendarModule.agr: Changed entity declaration to type import
- playerSchema.agr: Added type import for MusicDevice
This change enforces proper separation of concerns at compile time,
preventing common mistakes like trying to use grammar rules as types
or vice versa, while detecting undefined type references early.
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Enforces strict compile-time validation where ALL type names (except built-in types) must be explicitly imported from .ts files using @import statements. Changes: - Updated comment in grammarCompiler.ts to clarify that all non-built-in types must be explicitly imported - Fixed test files to add @import statements for types they reference: * grammarMatcher.spec.ts: Added import for TrackName * dynamicGrammarLoader.spec.ts: Added imports for Ordinal and CalendarDate * agentGrammarRegistry.spec.ts: Updated tests to use @import instead of entity declarations * grammarRuleParser.spec.ts: Updated error message expectations to match new parser format ('@ import' instead of '@import') This removes the previous behavior where types could be validated at runtime through the entity registry. Now all types must be declared upfront in the grammar file via @import statements. Built-in types that do NOT require imports: - string - number - wildcard - word All 304 actionGrammar tests pass. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Standardize on the .agr extension throughout the codebase: - Update compiler logic to check for .agr (grammar imports) vs .ts (type imports) - Update all test files to use .agr instead of .grammar - Fix test expectation regex to match .agr filename Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
steveluc
added a commit
that referenced
this pull request
Feb 16, 2026
Merges Curtis's grammar import system (#1920), undefined variable validation (#1921), and duplicate variable detection (#1922) with our normalization and entity changes. Conflict resolution in grammarCompiler.ts: kept both main's validateVariableReferences + duplicate var detection AND our hasValue logic for single-literal and passthrough rules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
7 tasks
github-merge-queue bot
pushed a commit
that referenced
this pull request
Feb 17, 2026
…1926) ## Summary - **New `chat-ui` package**: Shared rendering code (setContent, ChatPanel, CSS) used by both Electron shell and Chrome extension side panel, with `PlatformAdapter` abstraction for link handling - **Chrome extension chat panel**: Side panel view connecting to the dispatcher via service worker WebSocket (`ws://localhost:8999`), with full send/receive of agent messages, connection banner, and auto-reconnect - **Per-request browser routing**: Shell commands route to the embedded Electron browser; extension commands route to Chrome tabs — both work simultaneously via `clientType` tracking in `sharedDispatcher` - **Follow link improvements**: Filters non-navigable hrefs (`#`, `javascript:`, same-page fragments), uses `window.location.href` for proper browser history (goBack works), discovers links via ancestor/sibling traversal for complex page layouts - **Chat panel UX**: Collapsible action details (click timestamp to expand), automatic status message cleanup, input box sizing fix, connection status banner - **Desktop agent sub-schemas**: Refactored 50+ Windows settings actions into categorized sub-schema `.agr` files (display, input, personalization, power, privacy, system, taskbar) with build scripts and manifest configuration - **Grammar improvements**: Single-literal and passthrough rule normalization, CalendarTime/CalendarTimeRange entities, recursive grammar caching — merged with PRs #1920 (imports), #1921 (undefined variable validation), #1922 (duplicate variable detection) - **Email RAG search**: Integration with knowledge processor for online email search ## Test plan - [x] actionGrammar unit tests: 17 suites, 331 passed (including 28 new import tests) - [x] cache grammarIntegration tests: 19 passed - [x] TypeScript compilation clean across actionGrammar, actionGrammarCompiler, cache - [x] End-to-end: player commands (pause, play track 5) via grammar matching - [x] End-to-end: extension chat panel connects and sends/receives messages - [x] End-to-end: follow link + goBack in extension - [x] End-to-end: shell embedded browser still works independently 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add Import System to Action Grammar
Summary
This PR introduces a comprehensive import/module system for action grammars, enabling better code organization and reusability. Grammar definitions can now be split across multiple files and composed through explicit imports, similar to module systems in modern programming languages.
Key Features
Grammar Imports
.agrfiles using@importsyntax@import { RuleA, RuleB } from "./rules.agr"@import * from "./rules.agr"Type Imports
.tsfiles for compile-time validation@import { CustomType } from "./types.ts"File Extension Change
.agrextension instead of.grammarin tests.Circular Dependency Support
File Loading Abstraction
FileLoaderinterface for customizable file resolution and loadingfsandpathmodulesTechnical Changes
New Files
Modified Core Files
@importstatements, distinguish grammar vs type importsTest Coverage
The PR includes test coverage for:
.tsfilesExample Usage
Migration Notes
.agr