BREAKING CHANGES: - Relationship syntax now requires blocks for all participants - Removed self/other perspective blocks from relationships - Replaced 'guard' keyword with 'if' for behavior tree decorators Language Features: - Add tree-sitter grammar with improved if/condition disambiguation - Add comprehensive tutorial and reference documentation - Add SBIR v0.2.0 binary format specification - Add resource linking system for behaviors and schedules - Add year-long schedule patterns (day, season, recurrence) - Add behavior tree enhancements (named nodes, decorators) Documentation: - Complete tutorial series (9 chapters) with baker family examples - Complete reference documentation for all language features - SBIR v0.2.0 specification with binary format details - Added locations and institutions documentation Examples: - Convert all examples to baker family scenario - Add comprehensive working examples Tooling: - Zed extension with LSP integration - Tree-sitter grammar for syntax highlighting - Build scripts and development tools Version Updates: - Main package: 0.1.0 → 0.2.0 - Tree-sitter grammar: 0.1.0 → 0.2.0 - Zed extension: 0.1.0 → 0.2.0 - Storybook editor: 0.1.0 → 0.2.0
6.9 KiB
Behavior Tree Keyword Implementation Status
Task: #7 - Implement behavior tree keyword transformation system Status: In Progress (60% complete) Date: February 12, 2026
✅ Completed Work
1. Tree-sitter Grammar (tree-sitter-storybook/grammar.js)
- ✅ Updated
selector_nodeto usechoosekeyword with optional label - ✅ Updated
sequence_nodeto usethenkeyword with optional label - ✅ Added
condition_nodeforif(expr)andwhen(expr) - ✅ Added
decorator_nodewith full parameter support - ✅ Added
decorator_keywordenumeration - ✅ Added
decorator_paramsfor all parameter types - ✅ Updated
subtree_nodeto useincludekeyword - ✅ Extended
durationpattern to support days (d)
2. AST Structures (src/syntax/ast.rs + storybook/src/syntax/ast.rs)
- ✅ Restructured
BehaviorNode::Selectorwith label support - ✅ Restructured
BehaviorNode::Sequencewith label support - ✅ Added
BehaviorNode::Decoratorwith typed decorators - ✅ Created
DecoratorTypeenum with 10 variants - ✅ Created
Durationstruct withDurationUnitenum - ✅ Implemented
Duration::to_milliseconds()conversion
3. LALRPOP Parser (src/syntax/parser.lalrpop)
- ✅ Updated
BehaviorNodechoice to include new node types - ✅ Implemented
SelectorNodewithchoosekeyword and optional label - ✅ Implemented
SequenceNodewiththenkeyword and optional label - ✅ Implemented
ConditionNodeforif/whenexpressions - ✅ Implemented all 10 decorator parsers:
DecoratorRepeat(infinite)DecoratorRepeatN(n)DecoratorRepeatRange(min..max)DecoratorInvertDecoratorRetry(n)DecoratorTimeout(duration)DecoratorCooldown(duration)DecoratorGuard(expr)DecoratorSucceedAlwaysDecoratorFailAlways
- ✅ Updated
SubTreeNodeto useincludekeyword
4. Lexer Tokens (src/syntax/lexer.rs + storybook/src/syntax/lexer.rs)
- ✅ Added
Choosetoken - ✅ Added
Thentoken - ✅ Added
Iftoken - ✅ Added
Whentoken - ✅ Added
Repeattoken - ✅ Added
Inverttoken - ✅ Added
Retrytoken - ✅ Added
Timeouttoken - ✅ Added
Cooldowntoken - ✅ Added
Guardtoken - ✅ Added
SucceedAlwaystoken - ✅ Added
FailAlwaystoken
5. Example Files
- ✅ Created
examples/new-syntax-demo.sbwith comprehensive demonstrations
🚧 In Progress / Pending
6. Fix Compilation Errors
The AST changes will break existing code that pattern-matches on BehaviorNode:
- Update all
match BehaviorNode::Selector(nodes)toBehaviorNode::Selector { label, children } - Update all
match BehaviorNode::Sequence(nodes)toBehaviorNode::Sequence { label, children } - Update all
match BehaviorNode::Decorator(name, child)toBehaviorNode::Decorator { decorator_type, child } - Check files:
src/resolve/validate.rssrc/resolve/types.rssrc/types.rs- LSP code in
storybook/src/lsp/ - Test files
7. Compiler / SBIR Generation
- Update SBIR node type encoding for decorators
- Implement serialization for
DecoratorTypevariants - Implement
Durationserialization - Update compiler to handle new AST structures
- Test SBIR output for correctness
8. Testing
- Rebuild Tree-sitter grammar (
npm run buildor similar) - Test parsing
examples/new-syntax-demo.sb - Add unit tests for each decorator type
- Add integration tests for nested decorators
- Test round-trip: parse → compile → decompile
9. Example Migration
- Migrate
examples/alice-in-wonderland/world/characters/white_rabbit.sb - Migrate
examples/alice-in-wonderland/world/characters/mad_tea_party.sb(addrepeatdecorator) - Migrate
examples/alice-in-wonderland/world/characters/cheshire_cat.sb(add decorators) - Migrate
examples/alice-in-wonderland/world/characters/royal_court.sb(addrepeatdecorators) - Migrate
examples/alice-in-wonderland/world/characters/caterpillar.sb - Migrate
tests/examples/behavior_and_lifearc.sb - Update test corpus in
tree-sitter-storybook/test/corpus/behaviors.txt
10. Documentation
- Update
design.mdSection 6 with new syntax - Create migration guide
- Add tutorial examples highlighting named nodes
- Update CHANGELOG with breaking changes
- Prepare handoff notes for language documentation agent
📊 Progress Metrics
Overall Completion: 60%
By Phase:
- Phase 1 (Grammar & Parser): 100% ✅
- Phase 2 (AST & Compiler): 70% (AST done, compiler pending)
- Phase 3 (Examples & Tests): 10% (example created, migration pending)
- Phase 4 (Documentation): 0%
By Component:
- Grammar: 100% ✅
- AST: 100% ✅
- Lexer: 100% ✅
- Parser: 100% ✅
- Compilation fixes: 0%
- Compiler/SBIR: 0%
- Testing: 10%
- Migration: 0%
- Documentation: 0%
🎯 Next Immediate Actions
- Find and fix compilation errors from AST changes
- Update compiler to handle new
DecoratorTypeenum - Test parsing the new syntax example
- Migrate one example (White Rabbit) to validate end-to-end
- Add unit tests for decorator parsing
📝 Design Decisions Implemented
Following Sienna's feedback from design review:
✅ Use choose only (not selector)
✅ Use then only (not sequence)
✅ Remove @ prefix for actions
✅ Use include for subtrees
✅ Named nodes are prominent (optional label on choose/then)
✅ Decorators approved (all 10 types implemented)
✅ No backward compatibility (clean break from symbolic syntax)
🔄 Files Modified
Grammar:
tree-sitter-storybook/grammar.js
AST:
src/syntax/ast.rsstorybook/src/syntax/ast.rs
Parser:
src/syntax/parser.lalrpop
Lexer:
src/syntax/lexer.rsstorybook/src/syntax/lexer.rs
Examples:
examples/new-syntax-demo.sb(new)
🐛 Known Issues / Blockers
Compilation Errors Expected:
The AST structure changes will cause compilation errors in any code that pattern-matches on BehaviorNode. These need to be fixed before the code will compile.
Files Likely Affected:
src/resolve/validate.rs- behavior tree validationsrc/resolve/types.rs- type resolutionsrc/types.rs- type definitionsstorybook/src/lsp/semantic_tokens.rs- LSP highlightingstorybook/src/lsp/navigation_tests.rs- LSP tests- Test files with behavior tree examples
Resolution Strategy:
- Attempt to compile
- Fix each compilation error by updating pattern matches
- Test that fixes maintain correct behavior
- Coordinate with LSP agent if LSP changes are extensive
📚 Resources
Design Document: /Users/sienna/Development/storybook/design/behavior-tree-keywords-design.md
Example File: /Users/sienna/Development/storybook/examples/new-syntax-demo.sb
TEAM PLAN: /Users/sienna/Development/storybook/TEAM_PLAN.md (Task #7)
Last Updated: 2026-02-12 Next Update: After fixing compilation errors