Installation Guide

Installation Guide

Follow the Spectral installation guide to bootstrap CLI tooling and knowledge artifacts.

šŸš€ SPECTRAL INSTALLATION & SETUP GUIDE

Quick Start - 3 Steps to Spectral

Step 1: Language Tools (Already Ready!)

The Spectral language tools are already integrated into the Ouro project:

# Navigate to project
cd /Users/arturczemiel/projects/aexol/ouro

# The language is ready to use:
# - Lexer: src/spectral/lexer.ts
# - Parser: src/spectral/parser.ts
# - Validator: src/spectral/validator.ts
# - CodeGen: src/spectral/codegen.ts

Step 2: Set Up VS Code Extension

# Navigate to extension
cd /Users/arturczemiel/projects/aexol/ouro/vscode-extension

# Install dependencies
npm install

# Compile TypeScript
npm run compile

Step 3: Test in VS Code

# In VS Code, open the extension folder
# Press F5 to launch extension host
# Create a test.spectral file and start coding!

āœ… Installation Verification

Check Language Tools

# Verify all modules exist
ls -la /Users/arturczemiel/projects/aexol/ouro/src/spectral/

# You should see:
# āœ… lexer.ts
# āœ… tokenizer.ts
# āœ… parser.ts
# āœ… validator.ts
# āœ… codegen.ts
# āœ… utils.ts
# āœ… index.ts
# āœ… README.md
# āœ… examples/

Check VS Code Extension

# Verify extension files
ls -la /Users/arturczemiel/projects/aexol/ouro/vscode-extension/

# You should see:
# āœ… package.json
# āœ… tsconfig.json
# āœ… language-configuration.json
# āœ… README.md
# āœ… DEVELOPMENT.md
# āœ… src/
# āœ… syntaxes/

Verify npm Installation

cd /Users/arturczemiel/projects/aexol/ouro/vscode-extension

# Check package.json
npm list

# You should see:
# [email protected]

šŸŽÆ Using the Language

Via CLI

cd /Users/arturczemiel/projects/aexol/ouro

# Parse a file
deno run -A src/main.ts parse --input examples/sample.spectral

# Validate
deno run -A src/main.ts validate --input examples/sample.spectral

# Generate code
deno run -A src/main.ts generate --input examples/sample.spectral --language typescript

# Analyze
deno run -A src/main.ts analyze --input examples/sample.spectral

Via Deno TypeScript

import { Parser, Validator } from "./src/spectral/index.ts";

// Create a parser
const parser = new Parser(spectralCode);
const ast = parser.parse();

// Validate
const validator = new Validator(ast);
const result = validator.validate();

// Check results
console.log(result.isValid);
console.log(result.errors);

In VS Code

  1. Install Extension:

    • Open vscode-extension folder in VS Code
    • Run: npm install && npm run compile
    • Press F5 to launch test instance
  2. Create .spectral File:

    visitor UserCapabilities
      can read
        can list
        can view
    
  3. Features Work Automatically:

    • āœ… Syntax highlighting
    • āœ… Error checking
    • āœ… Code completion (Ctrl+Space)
    • āœ… Hover info

šŸ“¦ What's Included

Language Implementation (2,390+ lines)

src/spectral/
ā”œā”€ā”€ lexer.ts              # 550+ lines - Tokenization
ā”œā”€ā”€ tokenizer.ts          # 230+ lines - Token stream
ā”œā”€ā”€ parser.ts             # 750+ lines - AST building
ā”œā”€ā”€ validator.ts          # 200+ lines - Semantic analysis
ā”œā”€ā”€ codegen.ts            # 350+ lines - Code generation
ā”œā”€ā”€ utils.ts              # 310+ lines - Analysis tools
└── index.ts              # Exports

Capabilities:

  • āœ… 50+ token types
  • āœ… 14+ AST node types
  • āœ… Full error recovery
  • āœ… 5 language code generation
  • āœ… Comprehensive analysis

VS Code Extension (1,837 lines)

vscode-extension/
ā”œā”€ā”€ src/
│   ā”œā”€ā”€ extension.ts           # 100+ lines - Main extension
│   └── language-provider.ts   # 400+ lines - Language features
ā”œā”€ā”€ syntaxes/
│   └── spectral.tmLanguage.json  # 150+ lines - Highlighting
ā”œā”€ā”€ package.json               # 90+ lines - Manifest
ā”œā”€ā”€ tsconfig.json             # 20+ lines - TypeScript config
ā”œā”€ā”€ language-configuration.json # 25+ lines - Editor config
ā”œā”€ā”€ README.md                 # 1,000+ lines - User guide
└── DEVELOPMENT.md            # 300+ lines - Dev guide

Features:

  • āœ… Syntax highlighting
  • āœ… Real-time error checking
  • āœ… Code completion
  • āœ… Hover information
  • āœ… Symbol outline
  • āœ… Commands and keybindings

Documentation (2,500+ lines)

docs/content/
ā”œā”€ā”€ spectral.mdx                    # 700+ lines - Tutorial
ā”œā”€ā”€ spectral-spec.mdx               # 400+ lines - Specification
ā”œā”€ā”€ spectral-quick-reference.mdx    # 300+ lines - Reference
└── spectral-index.mdx              # Navigation

SPECTRAL_*.md files
ā”œā”€ā”€ SPECTRAL_EXECUTIVE_SUMMARY.md
ā”œā”€ā”€ SPECTRAL_COMPLETE_SOLUTION.md
ā”œā”€ā”€ SPECTRAL_VSCODE_EXTENSION.md
ā”œā”€ā”€ SPECTRAL_README.md
ā”œā”€ā”€ SPECTRAL_IMPLEMENTATION.md
ā”œā”€ā”€ SPECTRAL_COMPLETE.md
└── SPECTRAL_DELIVERABLES.md

šŸŽ“ Learning Resources

Start Here

  1. Read: docs/content/spectral.mdx

    • 700+ lines of tutorial and examples
    • Covers all language features
    • Best practices included
  2. Try: src/spectral/examples/

    • todo.spectral - Simple example
    • ecommerce.spectral - Complex example (200+ lines)
  3. Reference: docs/content/spectral-quick-reference.mdx

    • Quick syntax guide
    • Common patterns
    • Command reference

For Developers

  1. API: src/spectral/README.md

    • Complete API documentation
    • Function signatures
    • Usage examples
  2. Implementation: src/spectral/parser.ts

    • Grammar specification
    • AST types
    • Parsing logic
  3. Extension: vscode-extension/DEVELOPMENT.md

    • Extension architecture
    • Adding features
    • Building and publishing

āš™ļø Configuration

VS Code Settings

Create .vscode/settings.json in your workspace:

{
  "spectral.enable": true,
  "spectral.validateOnType": true,
  "spectral.showDiagnostics": true,
  "spectral.maxDiagnostics": 100
}

Language Configuration

Edit vscode-extension/language-configuration.json:

  • Comments
  • Bracket pairs
  • Auto-closing pairs
  • Word patterns

TextMate Grammar

Edit vscode-extension/syntaxes/spectral.tmLanguage.json:

  • Add new keywords
  • Adjust token scopes
  • Customize highlighting

šŸ”§ Development Setup

For Language Development

cd /Users/arturczemiel/projects/aexol/ouro

# Check Deno installation
deno --version

# Run tests
deno test src/spectral/

# Generate documentation
deno run -A src/commands/docs.ts

For Extension Development

cd /Users/arturczemiel/projects/aexol/ouro/vscode-extension

# Install dependencies
npm install

# Watch TypeScript changes
npm run watch

# In VS Code, press F5 to debug
# Make changes and reload with Ctrl+R in extension host

For Documentation

# Read existing docs
cat docs/content/spectral.mdx

# Generate new docs
deno run -A src/commands/docs.ts --input src/spectral/examples/custom.spectral

🚨 Troubleshooting

Extension Not Loading

Problem: .spectral files not recognized

Solution:

# Verify language registration
grep -n "spectral" vscode-extension/package.json

# Check file extension is .spectral
ls -la *.spectral

# Restart VS Code

No Syntax Highlighting

Problem: Code not colored

Solution:

# Verify grammar is loaded
cat vscode-extension/syntaxes/spectral.tmLanguage.json

# Rebuild extension
cd vscode-extension
npm run compile

Validation Not Working

Problem: No error messages

Solution:

// In settings.json, enable:
{
  "spectral.validateOnType": true,
  "spectral.showDiagnostics": true
}

Build Errors

Problem: TypeScript compilation fails

Solution:

# Clear and reinstall
rm -rf node_modules package-lock.json
npm install

# Update TypeScript
npm install -D typescript@latest

# Try compiling again
npm run compile

šŸ“Š System Requirements

For Language Tools

  • Deno: 1.38+
  • Node: 18+ (for TypeScript)
  • OS: macOS, Linux, Windows

For VS Code Extension

  • VS Code: 1.85+
  • Node: 18+
  • npm: 9+
  • TypeScript: 5.3+

Disk Space

  • Language tools: ~2 MB
  • Extension (with dependencies): ~200 MB
  • Total with docs: ~5 MB

šŸŽÆ Common Tasks

Create a New Spectral File

# Create file
touch myproject.spectral

# Edit with syntax highlighting in VS Code
code myproject.spectral

# Validate
deno run -A src/main.ts validate --input myproject.spectral

Parse and Analyze

# Parse file to see AST
deno run -A src/main.ts parse --input myproject.spectral

# Analyze structure
deno run -A src/main.ts analyze --input myproject.spectral

# Generate code
deno run -A src/main.ts generate --input myproject.spectral --language typescript

Generate Documentation

# From Spectral file
deno run -A src/main.ts docs --input myproject.spectral

# View generated docs
cat myproject.md

Integrate into Your Project

// In your Deno project
import { Parser, Validator } from "./src/spectral/index.ts";

const code = Deno.readTextFileSync("system.spectral");
const parser = new Parser(code);
const ast = parser.parse();
const validator = new Validator(ast);
const result = validator.validate();

šŸš€ Next Steps

1. Try the Examples

# Look at todo example
cat src/spectral/examples/todo.spectral

# Look at e-commerce example  
cat src/spectral/examples/ecommerce.spectral

2. Create Your First Spectral File

# Create and edit
code myagents.spectral

# In VS Code, type:
# visitor, role, workflow, agent, type
# Get full syntax highlighting and validation!

3. Integrate with Your Project

// Import the parser
import { Parser } from "./src/spectral/index.ts";

// Parse your Spectral files
const ast = new Parser(code).parse();

// Build on top of it!

4. Customize Extension

# Edit syntax
vim vscode-extension/syntaxes/spectral.tmLanguage.json

# Add completion items
vim vscode-extension/src/language-provider.ts

# Rebuild
npm run compile

āœ… Verification

Run this to verify everything is installed:

#!/bin/bash
echo "šŸ” Spectral Installation Check"
echo "================================"

# Check language tools
echo "āœ… Language tools:"
ls -1 src/spectral/*.ts | wc -l | xargs echo "   Files:"

# Check extension
echo "āœ… Extension:"
ls -1 vscode-extension/src/*.ts | wc -l | xargs echo "   Files:"

# Check documentation
echo "āœ… Documentation:"
find . -name "SPECTRAL_*.md" | wc -l | xargs echo "   Files:"

# Check examples
echo "āœ… Examples:"
find src/spectral/examples -name "*.spectral" | wc -l | xargs echo "   Files:"

echo ""
echo "🟢 Installation verified!"

šŸ“ž Getting Help

Documentation Resources

  • Language Guide: docs/content/spectral.mdx
  • Quick Reference: docs/content/spectral-quick-reference.mdx
  • Specification: docs/content/spectral-spec.mdx
  • Extension Guide: vscode-extension/README.md
  • Developer Guide: vscode-extension/DEVELOPMENT.md

Code Examples

  • Simple: src/spectral/examples/todo.spectral
  • Complex: src/spectral/examples/ecommerce.spectral

API Reference

  • Parser API: src/spectral/README.md
  • CLI Usage: src/commands/spectral.ts

When Something's Wrong

  1. Check relevant documentation
  2. Review examples
  3. Look at inline code comments
  4. Check troubleshooting section

šŸŽŠ You're All Set!

āœ… Language tools installed
āœ… VS Code extension ready
āœ… Documentation complete
āœ… Examples available
āœ… Ready to start!

Start Now!

# 1. Navigate to project
cd /Users/arturczemiel/projects/aexol/ouro

# 2. Create first Spectral file
echo 'visitor Test
  can read
    can list' > hello.spectral

# 3. Parse it
deno run -A src/main.ts parse --input hello.spectral

# 4. In VS Code
code vscode-extension/
npm install && npm run compile
# Press F5 to test!

šŸŽ‰ Welcome to Spectral!

For more information, see the documentation in the docs/ folder or README files.

Happy coding! šŸš€