@misterscan/sesi 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +191 -0
  3. package/bin/sesi.js +56 -0
  4. package/dist/ai-runtime.d.ts +15 -0
  5. package/dist/ai-runtime.d.ts.map +1 -0
  6. package/dist/ai-runtime.js +214 -0
  7. package/dist/ai-runtime.js.map +1 -0
  8. package/dist/builtins.d.ts +7 -0
  9. package/dist/builtins.d.ts.map +1 -0
  10. package/dist/builtins.js +473 -0
  11. package/dist/builtins.js.map +1 -0
  12. package/dist/index.d.ts +3 -0
  13. package/dist/index.d.ts.map +1 -0
  14. package/dist/index.js +72 -0
  15. package/dist/index.js.map +1 -0
  16. package/dist/interpreter.d.ts +36 -0
  17. package/dist/interpreter.d.ts.map +1 -0
  18. package/dist/interpreter.js +495 -0
  19. package/dist/interpreter.js.map +1 -0
  20. package/dist/lexer.d.ts +26 -0
  21. package/dist/lexer.d.ts.map +1 -0
  22. package/dist/lexer.js +340 -0
  23. package/dist/lexer.js.map +1 -0
  24. package/dist/parser.d.ts +55 -0
  25. package/dist/parser.d.ts.map +1 -0
  26. package/dist/parser.js +1022 -0
  27. package/dist/parser.js.map +1 -0
  28. package/dist/types.d.ts +304 -0
  29. package/dist/types.d.ts.map +1 -0
  30. package/dist/types.js +63 -0
  31. package/dist/types.js.map +1 -0
  32. package/docs/ARCHITECTURE.md +430 -0
  33. package/docs/BUILTINS.md +577 -0
  34. package/docs/COMPARISON.md +334 -0
  35. package/docs/DISTRIBUTED_SYSTEMS.md +71 -0
  36. package/docs/IMAGE_GENERATION.md +76 -0
  37. package/docs/IMPLEMENTATION_SUMMARY.md +533 -0
  38. package/docs/QUICKSTART.md +351 -0
  39. package/docs/README.md +191 -0
  40. package/docs/ROADMAP.md +408 -0
  41. package/docs/SPECIFICATION.md +462 -0
  42. package/docs/SYSTEMS_REASONING.md +522 -0
  43. package/examples/01_hello.sesi +2 -0
  44. package/examples/02_variables.sesi +11 -0
  45. package/examples/03_functions.sesi +6 -0
  46. package/examples/04_conditionals.sesi +6 -0
  47. package/examples/05_loops.sesi +12 -0
  48. package/examples/06_arrays_objects.sesi +18 -0
  49. package/examples/07_prompts.sesi +10 -0
  50. package/examples/08_model_call.sesi +5 -0
  51. package/examples/09_structured_output.sesi +7 -0
  52. package/examples/10_code_generation.sesi +5 -0
  53. package/examples/11_memory_conversation.sesi +16 -0
  54. package/examples/12_classification.sesi +8 -0
  55. package/examples/13_data_pipeline.sesi +35 -0
  56. package/examples/14_folder_explainer.sesi +58 -0
  57. package/examples/15_image_generation.sesi +17 -0
  58. package/main/atm_deposit.sesi +37 -0
  59. package/main/atm_withdraw.sesi +37 -0
  60. package/main/data.txt +1 -0
  61. package/main/math_aggregator.sesi +15 -0
  62. package/main/math_generator.sesi +7 -0
  63. package/main/math_processor.sesi +23 -0
  64. package/main/orchestrator.sesi +15 -0
  65. package/main/playground.sesi +1 -0
  66. package/main/setup_swarm.sesi +5 -0
  67. package/main/start.sesi +13 -0
  68. package/main/tax_calculator.sesi +15 -0
  69. package/main/tests/compare.sesi +23 -0
  70. package/main/tests/compare.ts +104 -0
  71. package/main/tests/debug.sesi +1 -0
  72. package/main/tests/demo.sesi +24 -0
  73. package/main/tests/primitive_validation.sesi +18 -0
  74. package/main/tests/test_connection.sesi +4 -0
  75. package/main/tests/test_failure_debug.sesi +2 -0
  76. package/main/tests/test_image.sesi +3 -0
  77. package/main/tests/test_parser_config.sesi +2 -0
  78. package/main/tests/test_syntax.sesi +3 -0
  79. package/main/tests/test_tool_call.sesi +14 -0
  80. package/main/tests/try.sesi +7 -0
  81. package/main/vault.sesi +15 -0
  82. package/package.json +50 -0
@@ -0,0 +1,462 @@
1
+ # Sesi Systems Language Specification (v1.1)
2
+
3
+ ## 1. Philosophy & Design Principles
4
+
5
+ Sesi is built on these core principles:
6
+
7
+ 1. **High-Performance Systems Orchestration**: Designed for building resilient, stateful applications with first-class primitives for process management and filesystem orchestration.
8
+ 2. **Reasoning as a First-Class Citizen**: Model calls, schema definitions, and tool orchestration are treated as language primitives rather than external SDK dependencies.
9
+ 3. **Transparency Over Magic**: Explicit model calls with clear costs and latency, not hidden inference.
10
+ 4. **Distributed State Management**: Optimized for coordination and state integrity using filesystem locking and concurrent `spawn()` patterns.
11
+ 5. **Practical Over Perfect**: Focus on reducing boilerplate code for complex reasoning logic, emphasizing what developers actually need over complete generality.
12
+
13
+ ## 2. Target Users
14
+
15
+ **Primary**: Developers building resilient, stateful applications that require systems-level orchestration alongside integrated reasoning.
16
+
17
+ **Secondary**:
18
+
19
+ - Engineers transitioning from traditional languages (TypeScript, Python, Go)
20
+ - Developers building agentic swarms and distributed systems
21
+ - Teams requiring complex logic with a fraction of the boilerplate
22
+
23
+ **Use Cases**:
24
+
25
+ - Stateful multi-agent swarm orchestration
26
+ - High-performance data pipelines with structured extraction
27
+ - Concurrent process management and distributed locking
28
+ - Multi-stage reasoning workflows with stateful memory
29
+
30
+ ## 3. V1.1 Feature Set (Current)
31
+
32
+ ### Core Language Features
33
+
34
+ - ✅ Variables and bindings (`let`)
35
+ - ✅ Functions (named, anonymous)
36
+ - ✅ Conditionals (`if/else`)
37
+ - ✅ Loops (`while`, `for`)
38
+ - ✅ Error Handling (`try/catch` blocks)
39
+ - ✅ Data types (number, string, bool, array, object)
40
+ - ✅ Systems Orchestration (`spawn`, `exec`, `time`, `random`)
41
+ - ✅ Comments (`//`, `/* */`)
42
+ - ✅ Operators (arithmetic, logical, comparison)
43
+ - ✅ Standard library (print, len, range, etc.)
44
+
45
+ ### Reasoning-Native Features
46
+
47
+ - ✅ `prompt` blocks (composable message templates)
48
+ - ✅ `model()` calls (native model with configuration)
49
+ - ✅ `image()` calls (native image generation with configuration)
50
+ - ✅ `structured_output()` (schema-guided structured output with JSON recovery and empty-object fallback on failure)
51
+ - ✅ `tool_call()` (Fully functional function calling via models)
52
+ - ✅ Simple memory (conversation context)
53
+
54
+ ### Type System
55
+
56
+ - ✅ Primitive types: `number`, `string`, `bool`, `null`
57
+ - ✅ Collection types: `array<T>`, `object<T>`
58
+ - ✅ Type inference
59
+ - ✅ Union types: `T | U`
60
+ - ✅ Optional types: `T?`
61
+
62
+ ### Module System
63
+
64
+ - ✅ `import` / `export`
65
+ - ✅ Namespace support
66
+ - ✅ Built-in modules
67
+
68
+ ## 4. Target Language (Syntax)
69
+
70
+ ### 4.1 Lexical Elements
71
+
72
+ #### Keywords
73
+
74
+ ```
75
+ let if else while for fn print import export
76
+ prompt model image memory structured_output tool_call break continue try catch true false null
77
+ ```
78
+
79
+ #### Identifiers & Literals
80
+
81
+ ```
82
+ identifier: [a-zA-Z_][a-zA-Z0-9_]*
83
+ number: [0-9]+ | [0-9]*\.[0-9]+
84
+ string: "..." | '...'
85
+ comment: // ... | /* ... */
86
+ ```
87
+
88
+ ### 4.2 Program Structure
89
+
90
+ ```
91
+ program := statement*
92
+ statement := declaration | expression_statement | block_statement
93
+ ```
94
+
95
+ ### 4.3 Declarations
96
+
97
+ #### Variable Declaration
98
+
99
+ ```
100
+ let_stmt := 'let' identifier ('=' expression)? (';' | newline)
101
+ ```
102
+
103
+ Example:
104
+
105
+ ```sesi
106
+ let x = 10
107
+ let y = 20
108
+ let z // z is null initially
109
+ ```
110
+
111
+ #### Function Declaration
112
+
113
+ ```
114
+ fn_stmt := 'fn' identifier '(' parameters ')' '->' type? block
115
+ parameters := (identifier ':' type ('=' expr)?)? (',' identifier ':' type ('=' expr)?)*
116
+ ```
117
+
118
+ Example:
119
+
120
+ ```sesi
121
+ fn add(a: number, b: number) {print a + b}
122
+ fn greet(name: string = "World") {print "Hello," name}
123
+ ```
124
+
125
+ #### Import/Export
126
+
127
+ ```
128
+ import_stmt := 'import' (identifier | '{' identifiers '}') 'from' string
129
+ export_stmt := 'export' (fn_stmt | let_stmt)
130
+ ```
131
+
132
+ Example:
133
+
134
+ ```sesi
135
+ import {add, subtract} from "math"
136
+ export fn multiply(a, b) {print a * b}
137
+ ```
138
+
139
+ ### 4.4 Control Flow
140
+
141
+ #### If Statement
142
+
143
+ ```
144
+ if_stmt := 'if' expression block ('else' block)?
145
+ ```
146
+
147
+ #### Loops
148
+
149
+ ```
150
+ while_stmt := 'while' expression block
151
+ for_stmt := 'for' identifier 'in' expression block | 'for' identifier '=' expr 'to' expr block
152
+ ```
153
+
154
+ #### Error Handling
155
+
156
+ ```
157
+ try_stmt := 'try' block 'catch' '(' identifier ')' block
158
+ ```
159
+
160
+ #### Loop Control
161
+
162
+ ```
163
+ break_stmt := 'break'
164
+ continue_stmt := 'continue'
165
+ ```
166
+
167
+ Example:
168
+
169
+ ```sesi
170
+ for i = 0 to 10 {print i}
171
+ try
172
+ {let result = model("Hello")
173
+ } catch (e) {
174
+ print e}
175
+ ```
176
+
177
+ ### 4.5 Expressions
178
+
179
+ #### Literals
180
+
181
+ ```
182
+ literal := number | string | bool | null | array | object
183
+ array := '[' (expression (',' expression)*)? ']'
184
+ object := '{' (string ':' expression (',' string ':' expression)*)? '}'
185
+ ```
186
+
187
+ #### Operators (Left to Right, Lowest to Highest Precedence)
188
+
189
+ ```
190
+ expr := assignment
191
+ assignment := logical_or ('=' assignment)?
192
+ logical_or := logical_and ('||' logical_and)*
193
+ logical_and := equality ('&&' equality)*
194
+ equality := comparison (('==' | '!=') comparison)*
195
+ comparison := addition (('<' | '>' | '<=' | '>=' | '<>') addition)*
196
+ addition := multiplication (('+' | '-') multiplication)*
197
+ multiplication := unary (('*' | '/' | '%') unary)*
198
+ unary := ('!' | '-') unary | postfix
199
+ postfix := primary ('['expression']' | '.'identifier | '('args?')' | primary)*
200
+ primary := identifier | literal | '('expression')' | prompt | model | image | memory | call
201
+ ```
202
+
203
+ #### Function Call
204
+
205
+ ```
206
+ call := identifier '(' (expression (',' expression)*)? ')'
207
+ ```
208
+
209
+ #### Prompt Block
210
+
211
+ ```
212
+ prompt := 'prompt' identifier '{'content'}'
213
+ content := (string | expression | newline)
214
+ ```
215
+
216
+ Example:
217
+
218
+ ```sesi
219
+ prompt codeReview {"Review this code for bugs:" code "Provide specific issues found."}
220
+ ```
221
+
222
+ #### Model & Image Calls
223
+
224
+ ```
225
+ model_call := 'model' '('STRING')' '{'config (optional)'}' '{'prompt'}'
226
+ | 'model' '('STRING')' '{'prompt'}'
227
+ image_call := 'image' '('STRING')' '{'config (optional)'}' '{'prompt'}'
228
+ | 'image' '('STRING')' '{'prompt'}'
229
+ config := ((STRING | identifier) ':' expression (',' (STRING | identifier) ':' expression)*)?
230
+ ```
231
+
232
+ Example:
233
+
234
+ ```sesi
235
+ let result = model("gemini-3.1-flash-lite") {codeReview}
236
+ let output = model("gemini-3.1-flash-lite") {"temperature": 0.4, "max_tokens": 2000} {prompt}
237
+ ```
238
+
239
+ #### Structured Output
240
+
241
+ ```
242
+ structured_output := 'structured_output' '('schema')' '('expression')'
243
+ schema := '{' (identifier ':' type (',' identifier ':' type)*)? '}'
244
+ ```
245
+
246
+ Example:
247
+
248
+ ```sesi
249
+ let analysis = structured_output({sentiment: string, score: number, keywords: array<string>})(model("gemini-3.1-flash-lite") { analyzeText })
250
+ ```
251
+
252
+ #### Tool Call
253
+
254
+ ```
255
+ tool_call := 'tool_call' '('function_name')' '('model_call')'
256
+ ```
257
+
258
+ #### Memory (State Management)
259
+
260
+ ```
261
+ memory := 'memory' identifier ('{'expressions'}')?
262
+ ```
263
+
264
+ Example:
265
+
266
+ ```sesi
267
+ memory conversation {"Previous messages here"}
268
+ let response = model("gemini-3-flash-preview") {prompt {conversation "New question:" userInput}}
269
+ conversation = conversation "Assistant:" response
270
+ ```
271
+
272
+ ### 4.6 Type Annotations
273
+
274
+ ```
275
+ type := primitive_type | collection_type | union_type | optional_type
276
+ primitive_type := 'number' | 'string' | 'bool' | 'null'
277
+ collection_type := 'array' '<' type '>' | 'object' '<' type '>'
278
+ union_type := type ('|' type)
279
+ optional_type := type '?'
280
+ ```
281
+
282
+ ## 5. Expression Evaluation Rules
283
+
284
+ 1. **Short-circuit evaluation**: `&&` and `||` short-circuit
285
+ 2. **Type coercion**: Automatic for numeric operations; explicit for string/number
286
+ 3. **Null propagation**: Operations on `null` return `null` (no exceptions in v1.1)
287
+ 4. **Model responses**: Always returned as strings initially; structured_output provides type safety
288
+
289
+ ## 6. Scope and Binding
290
+
291
+ - **Global scope**: Module level
292
+ - **Function scope**: Within function definitions
293
+ - **Block scope**: Within blocks (if/while/for)
294
+ - **Lexical scoping**: Inner scopes shadow outer scopes
295
+ - **Closure support**: Functions capture enclosing scope
296
+
297
+ ## 7. Runtime Semantics
298
+
299
+ ### Execution Order
300
+
301
+ 1. Tokenize (lexer)
302
+ 2. Parse (parser) → AST
303
+ 3. Evaluate (interpreter)
304
+ 4. Model calls are **blocking** (no async in v1)
305
+
306
+ ### Memory Model
307
+
308
+ - **Stack**: Local variables, function parameters
309
+ - **Heap**: Arrays, objects, strings
310
+ - **Reasoning Context**: Implicit conversation history per `memory` binding
311
+
312
+ ### Error Handling (V1 Simple)
313
+
314
+ - Runtime and model errors can be caught with `try/catch`
315
+ - Model errors throw when Gemini returns no text or a non-`STOP` finish reason
316
+ - `read_file()`, `write_file()`, and `list_dir()` throw on filesystem failure
317
+ - `structured_output()` currently logs parsing failures and returns `{}` if recovery fails
318
+
319
+ ## 8. Built-in Functions (V1)
320
+
321
+ ```
322
+ print(any) // Output to stdout
323
+ len(array | string | object) // Length
324
+ range(number) -> array // [0, 1, ..., n-1]
325
+ type(any) -> string // Type name
326
+ str(any) -> string // Convert to string
327
+ num(any) -> number // Convert to number
328
+ bool(any) -> bool // Convert to bool
329
+ keys(object) -> array // Object keys
330
+ values(object) -> array // Object values
331
+ push(array, any) // Add element
332
+ pop(array) -> any // Remove last
333
+ join(array, string) -> string // Join with separator
334
+ split(string, string) -> array // Split by separator
335
+ read_file(string) -> string // Read file contents
336
+ write_file(string, string) -> bool // Write file contents
337
+ write_image(string, string) -> bool // Write base64 image data to file
338
+ list_dir(string) -> array<string> // List directory contents
339
+ make_dir(string) -> bool // Create directory (recursive)
340
+ spawn(string) -> number // Concurrent process creation
341
+ exec(string) -> string // Synchronous shell execution
342
+ time() -> number // Current Unix timestamp
343
+ random() -> number // Random float (0.0 to 1.0)
344
+ ```
345
+
346
+ ## 9. Module System
347
+
348
+ Parser support for `import` / `export` syntax exists in v1.1, but runtime module execution is not implemented yet.
349
+
350
+ ### Defining Modules
351
+
352
+ ```sesi
353
+ // math.sesi
354
+ export fn add(a, b) {print a + b}
355
+ export fn multiply(a, b) {print a * b}
356
+ export let PI = 3.14159
357
+ ```
358
+
359
+ ### Importing Modules
360
+
361
+ ```sesi
362
+ import {add, multiply, PI} from "math"
363
+ let result = add(10, 20)
364
+ ```
365
+
366
+ ### Built-in Modules
367
+
368
+ ```sesi
369
+ import time from "std/time" // Time/date functions
370
+ import math from "std/math" // Math operations
371
+ import json from "std/json" // JSON parsing
372
+ ```
373
+
374
+ ## 10. Reasoning Features Details
375
+
376
+ ### Prompt Blocks
377
+
378
+ Prompts are composable message templates:
379
+
380
+ ```sesi
381
+ prompt translate {"Translate the following to Spanish:" sourceText}
382
+ prompt summarize {"Summarize this in 3 sentences:" text}
383
+ prompt combined {summarize "Now translate:" translate}
384
+ ```
385
+
386
+ ### Model & Image Calls
387
+
388
+ ```sesi
389
+ let response = model("gemini-3-flash-preview") {"temperature": 0} {"Say hello"}
390
+ print response // Returns string
391
+
392
+ let logo = image("gemini-3.1-flash-image-preview") {ratio: "1:1", size: "512"} {"A vector logo"}
393
+ write_image("logo.png", logo)
394
+ print "Image written to logo.png"
395
+ ```
396
+
397
+ ### Structured Output
398
+
399
+ ```sesi
400
+ let result = structured_output({title: string, category: string, confidence: number})(model("gemini-3.1-flash-lite") {"Extract metadata from this text:" text})
401
+ print result.title // Access fields
402
+ print result.confidence // Type-safe access
403
+ ```
404
+
405
+ ### Tool Calling
406
+
407
+ ```sesi
408
+ fn calculateTax(amount: number, rate: number) {print amount * rate}
409
+ let taxAmount = tool_call(calculateTax)(model("gemini-3.1-flash-lite") {"Calculate 8% tax on $100"})
410
+ taxAmount
411
+ ```
412
+
413
+ ### Memory
414
+
415
+ ```sesi
416
+ memory chat {"System: You are a helpful assistant."}
417
+ fn askQuestion(question: string)
418
+ {let response = model("gemini-3-flash-preview") {chat "User:" question}
419
+ chat = chat "Assistant:" response}
420
+ ```
421
+
422
+ ## 11. Examples
423
+
424
+ ### Example 1: Simple Computation
425
+
426
+ ```sesi
427
+ let x = 10
428
+ let y = 20
429
+ print x + y // Output: 30
430
+ ```
431
+
432
+ ### Example 2: Function with Reasoning
433
+
434
+ ```sesi
435
+ fn analyzeText(text: string) -> string {return model("gemini-3.1-pro-preview") {"temperature": 0} {"Analyze this text and return key insights:" text}}
436
+ print analyzeText("Reasoning is transforming industries")
437
+ ```
438
+
439
+ ### Example 3: Structured Output
440
+
441
+ ```sesi
442
+ let sentiment = structured_output({label: string, score: number})(model("gemini-3-flash-preview") {"Analyze sentiment of:" userInput})
443
+ print sentiment.label
444
+ print sentiment.score
445
+ ```
446
+
447
+ ## 12. Undefined Behavior & Limitations (V1.1)
448
+
449
+ - **No async/await**: All operations within a script are blocking (including model calls). Concurrency must be achieved via `spawn()`.
450
+ - **No custom types**: Only built-in types are supported natively.
451
+ - **No pattern matching**: Basic if/else only.
452
+ - **No generics**: Array and object collections are untyped at runtime.
453
+ - **Limited introspection**: Basic type() only.
454
+ - **No macros**: No compile-time code generation.
455
+ - **Single-threaded runtime**: Execution per script is single-threaded. System-level concurrency is handled via multi-process `spawn()`.
456
+ - **No garbage collection tuning**: Rely on Node.js GC.
457
+
458
+ ## 13. Compatibility Notes
459
+
460
+ - Sesi programs run on Node.js 18+
461
+ - Requires `@google/genai` SDK v2.0.1+
462
+ - Requires valid Gemini API key (GEMINI_API_KEY env var)