Sesi Language - Complete Implementation Summary
๐ Overview
Sesi is a highly legible, buildable programming language. It provides clean primitives for executing robust internal logic and external APIs, acting as the ideal layer to parse text, orchestrate shell commands, and interact with the file system. Unlike traditional languages, Sesi integrates command execution naturally, enabling developers to build context-aware scripts with minimal boilerplate.
๐ฏ Design Philosophy
- Practical Over Perfect: Focus on what developers actually need, not theoretical completeness.
- Transparency Over Magic: Sesi runs exactly what you write with clear costs and execution maps.
- Simplicity First: A custom tree-walking interpreter for clarity and maintainability.
- Type Safety with Flexibility: Static types for normal code, runtime checking for integration outputs.
๐ง Technology Stack
| Component | Technology | Rationale |
|---|---|---|
| Language | TypeScript | Type safety, IDE support, easy debugging |
| Runtime | Node.js 18+ | Wide availability, async support |
| Reasoning | Gemini 3.1 | Latest models, 1M token context, fast |
| SDK | @google/genai | Official, well-maintained, async-first |
| Parser | Recursive descent | Simple, readable, extensible |
| Execution | Tree-walking interpreter | Easy to understand and modify |
| Testing | Typescript | Standard Node.js test framework |
Why a tree-walking interpreter?
- Simplicity: Easy to understand, modify, extend
- Debugging: Can print AST and execution steps
- Iteration: No compilation overhead, fast development
- Good enough: Performance is adequate for v1+
Why recursive descent parser?
- Clarity: Each grammar rule is a function
- Flexibility: Easy to add new constructs
- Error recovery: Can synchronize after errors
- No dependencies: No external parser generators
Why Gemini specifically?
- Instruction following: Excellent at understanding prompts
- Function calling: Built-in tool use support
- Context window: 1M tokens for long documents
- Cost: Competitive pricing
- Availability: Easy to use via official SDK
๐ Language Features (V1)
Core Language โ
Variables & Bindings
let x = 10
let PI = 3.14159
let y // null initially
Functions
fn add(a: number, b: number) -> number {return a + b}
fn greet(name: string = "World") {print "Hello, " + name}
Control Flow
if condition { ... } else { ... }
while condition { ... }
for x = 0 to 10 { ... }
for item in array { ... }
try { ... } catch (e) { ... }
Operators
- Arithmetic:
+,-,,/,% - Comparison:
==,!=,<,>,<=,>= - Logical:
&&,||,! - Assignment:
=
Data Types
- Primitives:
number,string,bool,null - Collections:
array,object - Functions: First-class values
- Union types:
T | U - Optional:
T?
Scoping
- Lexical scoping with environment chain
- Block scope for loops/conditionals
- Closure support
Prompt Blocks
prompt greeting {"Hello, " name "!"}
Structured Output
let rawJson = "{\"projectName\": \"Sesi\", \"version\": \"1.5.5\", \"status\": \"active\"}"
let parsedRegistry = structured_output({projectName: string, version: string, status: string})(rawJson)
Integrated Reasoning Features โ
Reasoning Calls
let response = model("gemini-3-flash-preview") {temperature: 0.7, max_tokens: 1000} {"Your prompt here"}
Web Search Grounding
let response = model("gemini-3.1-flash-lite") {search, max_tokens: 1000} {"What is the weather in Tokyo?"}
Image Generation
let logo = image("gemini-3.1-flash-image") {ratio: "1:1", size: "512"} {"Your prompt here"}
write_image("logo.png", logo)
Temporal Context Injection โ
Every reasoning call automatically includes the current UTC date and time in its context, providing the script with a native sense of "now."
Implicit Statement Termination โ
Expressions ending in } (such as prompt blocks) no longer strictly require an escape character or semicolon to terminate, allowing for cleaner one-line or multi-line syntax.
Async Polling for MAX_TOKENS โ
The runtime natively polls the model if it hits a MAX_TOKENS finish status during large generation tasks.
Tool Calling
let result = tool_call(functionName)(model(gemini-3.1-flash-lite) {"Your prompt here"})
Memory
memory conversation {"Initial context"}
conversation = conversation + "User: How are you?"
print("Current Conversation Memory:")
print(conversation)
// Demonstrate using the memory in a model call
print("Calling model with memory context...")
let response = model("gemini-3-flash-preview") {conversation}
print("Reasoning Response:", response)
๐ Built-in Global Variables
args(array): Contains the command-line arguments passed to the script, excluding Sesi runtime options and the script path.
๐ ๏ธ Built-in Functions
I/O
print(...args)read_file(path)write_file(path, content)write_image(path, content)list_dir(path)make_dir(path)spawn(path)exec(command)time()random()debug()
Type & Conversion Functions
type(value)str(value)to_json(value)from_json(string)num(value)bool(value)convert(type) { config } { file }
Collection Functions
len(collection)push(array, value)pop(array)join(array, sep)split(string, sep)keys(object)values(object)range(n)
Network
web_get(url, headers)web_send(url, body, headers)listen(port, handler)api(port, handler)live(filePath, exportName)
Concurrency
multi_req(fns)
Tools
define_tool(name, fn, description)list_tools()tool_call(name)(...)
Reasoning
workflow(steps, input)set_alias(alias, model)
Error Handling
error_type(type, message, data)raise_error(type_or_error, message, data)
Math
exp(x)
Standard Library Modules
Sesi supports importing standard utility library modules natively at runtime:
std/math: ConstantsPI,E, and functionssin,cos,tan,sqrt,floor,ceil,abs,pow,log,expstd/time:now(),sleep(ms), andformat(timestamp, options)for timezone/locale formattingstd/json:stringify(val)andparse(str)std/audio:play,beep,synth,save,sequence,mixfor sound synthesis. Upgraded to a professional DSP backend with Stereo Panning, ADSR Envelopes, Low-Pass Filtering, Soft-Clipping, physical modeling drums (kick,snare,hat,clap), andsf2(High-speed FluidSynth batch-rendering for SoundFonts).std/theory:chord(root, type),scale(root, type),transpose(notes, steps),duration(minutes, seconds), andbar(bars, bpm, beatsPerBar?)for algorithmic composition, timing conversions, and harmonic logic.std/draw: Upgraded SVG generation library supporting complex shapes (ellipse,polygon,path), definition management (gradient,style), inline XML (raw), formatting/indentation, and class/attribute mappings via optional trailingoptionsdictionaries.std/db:db_open(filename, password?)returning a Document Database instance (with automatic AES-256-CBC disk encryption if a passphrase is provided) supporting collections and CRUD operations:
- db.collection(name) -> Collection object
- collection.insert(document)
- collection.find(query?)
- collection.update(query, update_obj)
- collection.delete(query)
๐ Implementation Statistics
| Metric | Value |
|---|---|
| Total lines of code | ~4,000 |
| Source files | 9 |
| Documentation pages | 23 |
| Example programs | 31 |
| Built-in functions | 50+ |
| Supported operators | 20+ |
| AST node types | 30+ |
| Token types | 50+ |
๐ Getting Started
Installation
cd Sesi
npm install
npm run build
npm install -g .
Run Example
sesi examples/main/01_hello.sesi
Run with Reasoning
sesi examples/optional/08_model_call.sesi
Run Tests
npm test
๐ก Key Implementation Details
Lexer Design
- Character-by-character scanning
- Keyword recognition
- String/number literal parsing
- Comment stripping
- Position tracking for error messages
Parser Design
- Recursive descent parsing
- Expression precedence (11 levels)
- Error recovery via synchronization
- Full AST construction
- Support for all language constructs
Interpreter Design
- Tree-walking evaluation
- Environment chain for scoping
- Async support for reasoning calls
- Control flow exceptions (return, break, continue)
- Built-in function dispatch
Reasoning Runtime Design
- Async Gemini API calls (via @google/genai)
- Response parsing and validation
- Memory buffer management
- Structured output JSON extraction with automatic schema simplification
- Automatic injection of current UTC date/time context
- Graceful error handling
๐ Documentation Coverage
โ SPECIFICATION.md (600+ lines)
- Complete language grammar
- All language constructs
- Type system details
- Built-in functions
- Runtime semantics
- Module system design
โ ARCHITECTURE.md (400+ lines)
- Component stack diagram
- Execution flow explanation
- Scope management
- Type system details
- Reasoning integration flow
- Error handling strategy
- Performance characteristics
โ BUILTINS.md (450+ lines)
- Complete function reference
- Usage examples
- Return value documentation
- Performance notes
- Standard library plans
โ REASONING.md (500+ lines)
- Systems reasoning overview
- Prompt blocks explained
- Model call configuration
- Structured output guide
- Memory system details
- Practical patterns
- Error handling
- Performance tips
โ ROADMAP.md (400+ lines)
- V1.0 features (Complete)
- V1.5 improvements (Complete)
- V2.0 async & advanced reasoning (Q3-Q4 2026)
- V3.0 systems framework
- V4.0+ vision
- Community involvement
- Backwards compatibility
๐ Example Programs
| File | Demonstrates |
|---|---|
| main/01_hello.sesi | Basic print |
| main/02_variables.sesi | Variables and operations |
| main/03_functions.sesi | Functions, parameters, defaults |
| main/04_conditionals.sesi | If/else logic |
| main/05_loops.sesi | While, for, for-in |
| main/06_arrays_objects.sesi | Collections and indexing |
| main/07_prompts.sesi | Prompt blocks |
| optional/08_model_call.sesi | Basic reasoning calls |
| main/09_structured_output.sesi | Structured output |
| optional/10_code_generation.sesi | Code generation |
| main/11_memory_storage.sesi | Multi-turn with memory |
| main/12_classification.sesi | Classification |
| main/13_data_pipeline.sesi | Data pipeline |
| optional/14_folder_explainer.sesi | Directory parsing & reasoning |
| optional/15_image_generation.sesi | Image generation |
| main/16_modules.sesi | Imports/exports & std namespaces |
| main/17_http_client.sesi | HTTP GET and POST operations |
| main/18_parallel_requests.sesi | Parallel request concurrency |
| main/19_search_web.sesi | Web search integration |
| optional/20_model_aliases.sesi | Custom model naming aliases |
| main/21_custom_tools.sesi | Custom runtime tool definitions |
| optional/22_reasoning_plus_custom_tools.sesi | Compose reasoning & tools |
| main/23_file_conversion.sesi | Document and media conversion via convert() |
| main/24_http_server.sesi | Native async HTTP server (listen, live) |
| main/24_http_handler.sesi | Dynamic routing HTTP handler |
| main/25_webpage_server.sesi | High-performance dynamic HTML site rendering |
| main/26_database.sesi | Embedded Document Database (std/db) crud operations |
| main/27_robust_web_db.sesi | Secured combined API server backed by persistent DB |
| optional/28_streaming.sesi | Streaming API responses |
| main/29_tool_piping.sesi | Tool-chaining and data pipelining |
| main/30_error_recovery.sesi | Robust error handling and retry policies |
| main/31_synthesizer.sesi | Music and SVG native capabilities |
๐ฎ Future Directions
V2: Async & Advanced Logic
- Async/await
- Streaming responses
- Advanced memory with embeddings
- finally blocks, custom error types, retry policies, timeout handling
V3: Systems Framework
- System state machines
- Multi-process collaboration
- Knowledge base integration
- RAG (Retrieval-Augmented Generation)
V4+: Scale & Optimization
- Bytecode compilation
- JIT compilation
- Distributed execution
- Cross-model orchestration
๐งช Testing Strategy
Component Testing
- Lexer: Token stream correctness
- Parser: AST structure correctness
- Interpreter: Evaluation correctness
Example Coverage
- 31 complete example programs
- Covers all major language features
- Demonstrates reasoning integration
- Real-world use cases
๐ Learning Path
- Start: QUICKSTART.md - Get running in 5 minutes
- Builtins: BUILTINS.md - Built-in functions
- CLI: CLI.md - Complete CLI flags & parametric execution guide
- Basics: examples/main/01-06 - Core language features
- Prompts: examples/main/07 - Prompt blocks
- Reasoning: examples/optional/08, examples/main/09, examples/optional/10, examples/main/11-12 - Reasoning feature exploration
- Advanced: REASONING.md - Patterns and best practices
- Systems: examples/main/13, examples/optional/14 - Systems reasoning and data pipelines
- Modules: examples/main/16 - Modules & std library namespaces
- Image Generation: IMAGE_GENERATION.md examples/optional/15 - Generating images natively
- Concurrency: examples/main/17-18 - Concurrency & coordination
- Web Search: examples/main/19 - Web search integration
- Model Aliases: examples/optional/20 - Custom model naming aliases
- Custom Tools: examples/main/21, examples/optional/22 - Custom runtime tool definitions and compose reasoning with custom tools
- Specification: SPECIFICATION.md - Complete grammar
- Architecture: ARCHITECTURE.md - How it works
- Roadmap: ROADMAP.md - Future vision
๐ค Contributing Path
- Report bugs with minimal examples
- Suggest language features via RFCs
- Add built-in functions
- Improve documentation
- Submit example programs
- Help with test coverage
๐ What's Included
- โ Complete interpreter (3000+ lines of TypeScript)
- โ Full language specification (600+ lines)
- โ Architecture documentation (400+ lines)
- โ API reference (450+ lines)
- โ Systems reasoning guide (500+ lines)
- โ Development roadmap (400+ lines)
- โ 30+ example programs
- โ CLI executable
- โ Test suite
- โ Quick start guide
๐ Next Steps
- Build and install:
npm install && npm run build && npm install -g . - Try examples:
sesi examples/main/01_hello.sesi - Set up Reasoning: Set GEMINI_API_KEY in
.env - Explore Reasoning:
sesi examples/optional/08_model_call.sesi - Read docs: Start with SPECIFICATION.md
- Write programs: Create your own .sesi files
- Check roadmap: See where language is headed
๐ Philosophy
"Sesi demonstrates that coding shouldn't need to be hard to understand, eliminating the boilerplate of traditional development and lowering the entry-level for those interested in code or programming."
The language is designed to evolve. V1+ provides a solid foundation. V2+ adds power. The architecture supports this gracefully without breaking existing programs.
Status: โ Complete V1.5 implementation
Ready for: File manipulation and process orchestration
Not ready for: Massive-scale production (until v2.0 bytecode)
Next milestone: V2.0 (Async & advanced reasoning)
Sesi is not just an experiment in language design. Use it to learn, explore, and evolve what the future of coding will become.
For more information, see the documentation in docs/ and examples in examples/.