@misterscan/sesi 1.2.3 → 1.3.2

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 (96) hide show
  1. package/.agents/rules/sesi-must-read.md +116 -0
  2. package/.agents/workflows/create-sesi-script.md +44 -0
  3. package/.agents/workflows/fix-sesi-script.md +14 -0
  4. package/.github/prompts/MakeInSesi.prompt.md +79 -0
  5. package/README.md +163 -51
  6. package/bin/sesi.js +196 -38
  7. package/chatbot/chatbot.html +488 -0
  8. package/{main → chatbot}/chatbot.sesi +1 -2
  9. package/chatbot/chatbot_server.py +105 -0
  10. package/chatbot/sesi_db_chatbot.sesi +278 -0
  11. package/dist/ai-runtime.js +2 -2
  12. package/dist/builtins.d.ts.map +1 -1
  13. package/dist/builtins.js +199 -5
  14. package/dist/builtins.js.map +1 -1
  15. package/dist/index.d.ts +12 -2
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +90 -6
  18. package/dist/index.js.map +1 -1
  19. package/dist/interpreter.d.ts +21 -2
  20. package/dist/interpreter.d.ts.map +1 -1
  21. package/dist/interpreter.js +201 -92
  22. package/dist/interpreter.js.map +1 -1
  23. package/dist/lexer.d.ts.map +1 -1
  24. package/dist/lexer.js +8 -4
  25. package/dist/lexer.js.map +1 -1
  26. package/dist/parser.d.ts +1 -0
  27. package/dist/parser.d.ts.map +1 -1
  28. package/dist/parser.js +21 -12
  29. package/dist/parser.js.map +1 -1
  30. package/dist/sesi.bundled.js +2526 -1487
  31. package/dist/types.d.ts +14 -2
  32. package/dist/types.d.ts.map +1 -1
  33. package/dist/types.js +33 -1
  34. package/dist/types.js.map +1 -1
  35. package/docs/ARCHITECTURE.md +21 -13
  36. package/docs/BUILTINS.md +136 -19
  37. package/docs/CLI.md +200 -0
  38. package/docs/COMPARISON.md +16 -13
  39. package/docs/IMAGE_GENERATION.md +13 -14
  40. package/docs/IMPLEMENTATION_SUMMARY.md +174 -110
  41. package/docs/QUICKSTART.md +173 -39
  42. package/docs/README.md +202 -54
  43. package/docs/{SYSTEMS_REASONING.md → REASONING.md} +115 -120
  44. package/docs/ROADMAP.md +51 -47
  45. package/docs/SKILLS.md +73 -98
  46. package/docs/SPECIFICATION.md +59 -40
  47. package/examples/03_functions.sesi +30 -1
  48. package/examples/07_prompts.sesi +27 -3
  49. package/examples/08_model_call.sesi +6 -4
  50. package/examples/09_structured_output.sesi +19 -3
  51. package/examples/10_code_generation.sesi +6 -4
  52. package/examples/11_memory_conversation.sesi +47 -15
  53. package/examples/12_classification.sesi +62 -7
  54. package/examples/13_data_pipeline.sesi +55 -28
  55. package/examples/14_folder_explainer.sesi +52 -51
  56. package/examples/15_image_generation.sesi +15 -14
  57. package/examples/16_modules.sesi +27 -27
  58. package/examples/19_search_web.sesi +18 -2
  59. package/examples/20_model_aliases.sesi +22 -0
  60. package/examples/21_custom_tools.sesi +27 -0
  61. package/examples/22_reasoning_plus_custom_tools.sesi +19 -0
  62. package/main/tests/test-args.sesi +7 -0
  63. package/main/tests/test_args.sesi +7 -0
  64. package/main/tests/test_general_modules.sesi +127 -0
  65. package/main/tests/test_grounding.sesi +2 -0
  66. package/package.json +26 -22
  67. package/docs/DISTRIBUTED_SYSTEMS.md +0 -71
  68. package/docs/sesi_ai_chronicles.md +0 -209
  69. package/main/conversational_classifier_weights.json +0 -45
  70. package/main/conversational_sentences.json +0 -304
  71. package/main/epochs.sesi +0 -94
  72. package/main/gpu_orchestrator.sesi +0 -36
  73. package/main/hardware_diagnostics.sesi +0 -118
  74. package/main/inference.sesi +0 -54
  75. package/main/native_chatbot.sesi +0 -180
  76. package/main/native_synthesizer.sesi +0 -83
  77. package/main/nn_personas_trainer.sesi +0 -302
  78. package/main/nn_responses_trainer.sesi +0 -269
  79. package/main/nn_sentences_trainer.sesi +0 -330
  80. package/main/orchestrator.sesi +0 -15
  81. package/main/personas.json +0 -124
  82. package/main/personas_classifier_weights.json +0 -45
  83. package/main/playground.sesi +0 -3
  84. package/main/predictive_typing.sesi +0 -127
  85. package/main/query_brain.sesi +0 -45
  86. package/main/response_classifier_weights.json +0 -45
  87. package/main/retro_chat.html +0 -239
  88. package/main/retro_chat_generator.sesi +0 -745
  89. package/main/sesi_ai.sesi +0 -158
  90. package/main/sesi_db_chatbot.sesi +0 -280
  91. package/main/setup_swarm.sesi +0 -5
  92. package/main/start.sesi +0 -13
  93. package/main/terminal.log +0 -56
  94. package/main/terminal_chat.py +0 -385
  95. package/main/unified_sesi_ai.sesi +0 -334
  96. package/main/varied_responses.json +0 -304
@@ -1,385 +0,0 @@
1
- import json
2
- import random
3
- import time
4
- import sys
5
- import math
6
-
7
- # Force system stdout to use UTF-8 encoding to prevent Windows cp1252 character maps exceptions
8
- try:
9
- sys.stdout.reconfigure(encoding='utf-8')
10
- except Exception:
11
- pass
12
-
13
- # Color codes for terminal aesthetics
14
- RESET = "\033[0m"
15
- BOLD = "\033[1m"
16
- GREEN = "\033[32m"
17
- CYAN = "\033[36m"
18
- MAGENTA = "\033[35m"
19
- YELLOW = "\033[33m"
20
- BLUE = "\033[34m"
21
- RED = "\033[31m"
22
- WHITE = "\033[37m"
23
-
24
- # HSL-aligned color palette for terminal visual excellence
25
- COLOR_AUDIO = CYAN
26
- COLOR_MECH = YELLOW
27
- COLOR_SYS = MAGENTA
28
-
29
- VOCAB = ["synthesizer", "vinyl", "record", "wood", "gears", "clock", "compiler", "framework", "memory", "offline"]
30
- CLASSES = ["audio", "mechanical", "systems"]
31
-
32
- def print_ascii_header():
33
- print(BOLD + CYAN + "======================================================================" + RESET)
34
- print(BOLD + BLUE + " [NEURAL] SESI NATIVELY NEURAL-EMPATHETIC TERMINAL CHAT REPL v4.0" + RESET)
35
- print(BOLD + CYAN + "======================================================================" + RESET)
36
- print(WHITE + "Welcome, Operator! Interactive neural dial-in gateway is online.")
37
- print("Zero-shot character bios trained offline. Synapses fully operational.\n" + RESET)
38
-
39
- def get_persona_category(persona):
40
- desc = (persona["personality"] + " " + persona["tone"]).lower()
41
- audio_keys = ["synthesizer", "jazz", "music", "audio", "chiptune", "beatmaker", "record"]
42
- mech_keys = ["wood", "furniture", "watch", "clock", "gears", "game boy", "botanist", "architect"]
43
-
44
- for k in audio_keys:
45
- if k in desc:
46
- return "audio"
47
- for k in mech_keys:
48
- if k in desc:
49
- return "mechanical"
50
- return "systems"
51
-
52
- def build_markov_brain(category, responses):
53
- # Slice the 300 varied responses based on category pool
54
- if category == "audio":
55
- corpus_responses = responses[0:100]
56
- elif category == "mechanical":
57
- corpus_responses = responses[100:200]
58
- else:
59
- corpus_responses = responses[200:300]
60
-
61
- full_text = " ".join(corpus_responses)
62
- words = full_text.split()
63
- w_len = len(words)
64
-
65
- transitions = {}
66
- for i in range(w_len - 1):
67
- w1 = words[i]
68
- w2 = words[i+1]
69
- if w1 not in transitions:
70
- transitions[w1] = []
71
- transitions[w1].append(w2)
72
-
73
- return transitions, words, w_len
74
-
75
- def walk_complete_sentence_penalized(transitions, words_list, c_len, start_word):
76
- current_word = start_word
77
- sentence = [current_word.capitalize()]
78
- history = [current_word]
79
- steps = 1
80
- max_steps = 22
81
-
82
- while steps < max_steps:
83
- if current_word.endswith((".", "!", "?")):
84
- break
85
-
86
- choices = transitions.get(current_word, [])
87
- next_word = ""
88
-
89
- if not choices:
90
- # Fallback: select random non-repeating word from vocab list
91
- attempts = 0
92
- found_candidate = False
93
- while attempts < 15:
94
- candidate = random.choice(words_list)
95
- if candidate not in history[-15:]:
96
- next_word = candidate
97
- found_candidate = True
98
- break
99
- attempts += 1
100
- if not found_candidate:
101
- next_word = random.choice(words_list)
102
- else:
103
- # Select transition choice with 15-word lookback & bigram blocking
104
- attempts = 0
105
- found_candidate = False
106
- while attempts < 20:
107
- candidate = random.choice(choices)
108
- is_repeat = False
109
-
110
- # 1. 15-word lookback window check
111
- if candidate in history[-15:]:
112
- is_repeat = True
113
-
114
- # 2. Strict Bigram Blocking check
115
- if not is_repeat:
116
- for b_idx in range(len(history) - 1):
117
- p1 = history[b_idx]
118
- p2 = history[b_idx + 1]
119
- if p1 == current_word and p2 == candidate:
120
- is_repeat = True
121
- break
122
-
123
- if not is_repeat:
124
- next_word = candidate
125
- found_candidate = True
126
- break
127
- attempts += 1
128
-
129
- if not found_candidate:
130
- next_word = random.choice(choices)
131
-
132
- sentence.append(next_word)
133
- history.append(next_word)
134
- current_word = next_word
135
- steps += 1
136
-
137
- result = " ".join(sentence)
138
- if not result.endswith((".", "!", "?")):
139
- result += "."
140
- return result
141
-
142
- def predict_neural_class(user_msg, weights, biases):
143
- # Normalize input and extract features
144
- words = [w.lower().replace(".", "").replace("!", "").replace("?", "").strip() for w in user_msg.split()]
145
- x = [0.0] * len(VOCAB)
146
- for i, keyword in enumerate(VOCAB):
147
- if keyword in words:
148
- x[i] = 1.0
149
-
150
- # Matrix vector multiplication
151
- outputs = [0.0] * len(CLASSES)
152
- for c in range(len(CLASSES)):
153
- val = biases[c]
154
- for i in range(len(VOCAB)):
155
- val += x[i] * weights[c][i]
156
- outputs[c] = val
157
-
158
- # Softmax probabilities
159
- try:
160
- e_x = [math.exp(v) for v in outputs]
161
- sum_e_x = sum(e_x)
162
- probs = [v / sum_e_x for v in e_x]
163
- except Exception:
164
- probs = [0.33, 0.33, 0.33]
165
-
166
- max_idx = probs.index(max(probs))
167
- return CLASSES[max_idx], probs
168
-
169
- def render_probability_bars(probs):
170
- bar_len = 16
171
- out_lines = []
172
- colors = [COLOR_AUDIO, COLOR_MECH, COLOR_SYS]
173
- labels = ["AUDIO ", "MECH ", "SYSTEM"]
174
-
175
- for i in range(3):
176
- p = probs[i]
177
- filled = int(round(p * bar_len))
178
- bar = "█" * filled + "▒" * (bar_len - filled)
179
- pct = p * 100.0
180
- out_lines.append(f" {colors[i]}[ {labels[i]} {bar} ({pct:5.1f}%) ]{RESET}")
181
- return "\n".join(out_lines)
182
-
183
- # Dynamic Varied Empathetic Prefix Dictionary to prevent prefix loops
184
- EMPATHETIC_VARIATIONS = {
185
- # Match cases
186
- ("audio", "audio"): [
187
- "The resonant audio waves strike a deep harmonic balance in my core! ",
188
- "Your rhythmic frequency perfectly matches my acoustic focus! ",
189
- "That statement vibrates at exactly the right pitch and groove! ",
190
- "A beautiful sonic resonance aligns our conversational pathways here! "
191
- ],
192
- ("mechanical", "mechanical"): [
193
- "The precise physical alignments of your statement click together like a masterfully crafted gear! ",
194
- "Your words have absolute structural integrity, locked in perfect spatial precision! ",
195
- "That fits flawlessly, like a fine gemstone fitted into a museum timepiece escapement! ",
196
- "A magnificent mechanical cohesion! Every segment of your logic is perfectly synced! "
197
- ],
198
- ("systems", "systems"): [
199
- "Your structural logic converges warning-free under our tight memory constraints! ",
200
- "A clean thread execution! Your statement optimizes perfectly in-memory! ",
201
- "Highly optimized telemetry! Your logic compiles with zero friction! ",
202
- "That is an exceptionally clean, low-latency construct you have deployed! "
203
- ],
204
-
205
- # Mismatch cases (bridges)
206
- # Native: audio
207
- ("audio", "mechanical"): [
208
- "Just like the gears of a mechanical clock, the tape reels of my vintage tape recorder rotate in perfect synchronization! ",
209
- "While you describe physical structures, I hear them as rhythmic acoustic spacing and mechanical beats! ",
210
- "Bridging physical leverage to acoustic latency: mechanical ticking is just natural chiptune rhythm! "
211
- ],
212
- ("audio", "systems"): [
213
- "Just like a compiled systems loop, a rhythmic audio sample loops indefinitely without latency! ",
214
- "Routing database streams feels a lot like managing discrete sound waves through a digital synthesizer! ",
215
- "Systems architectures and audio tracks both require low latency and high-fidelity routing! "
216
- ],
217
-
218
- # Native: mechanical
219
- ("mechanical", "audio"): [
220
- "Just like the rhythmic beats of a synthesizer, the repeating ticks of my mechanical escapement keep perfect physical timing! ",
221
- "I can translate that musical groove into physical rotational kinetic energy! ",
222
- "Acoustic waveforms have their own beautiful geometry, just like the teeth of fine wooden gears! "
223
- ],
224
- ("mechanical", "systems"): [
225
- "Just like a warning-free software compiler, the carefully cut wood gears of my mechanical clock require absolute structural precision! ",
226
- "Software compilers build virtual structures, but watchmaking builds them in physical memory! ",
227
- "Tight constraints are physical to me: gears must mesh with absolute zero margin of code error! "
228
- ],
229
-
230
- # Native: systems
231
- ("systems", "audio"): [
232
- "Just like a resonant audio sound wave, a high-performance database queries and reverberates in perfect memory synchronization! ",
233
- "Acoustic channels are just low-level physical packet networks carrying complex waveforms! ",
234
- "Your rhythmic tone maps perfectly to an optimized circular array buffer processing data! "
235
- ],
236
- ("systems", "mechanical"): [
237
- "Just like the physical leverage of mechanical gears, our system compilers leverage low-level pointers to optimize execution speed! ",
238
- "Mechanical segments translate beautifully to hardware memory addresses and clock cycles! ",
239
- "I bridge physical wood structures to logical system memory layouts: both require absolute architecture! "
240
- ]
241
- }
242
-
243
- def get_empathetic_prefix(partner_native, predicted):
244
- key = (partner_native, predicted)
245
- if key in EMPATHETIC_VARIATIONS:
246
- choices = EMPATHETIC_VARIATIONS[key]
247
- return random.choice(choices)
248
- return ""
249
-
250
- def main():
251
- # 1. Load Persona Database
252
- try:
253
- with open("main/personas.json", "r") as f:
254
- parsed_personas = json.load(f)
255
- personas = parsed_personas["personas"]
256
- except Exception as e:
257
- print(RED + "Error: Failed to load main/personas.json!" + RESET)
258
- return
259
-
260
- # 2. Load Responses Corpus
261
- try:
262
- with open("main/varied_responses.json", "r") as f:
263
- parsed_responses = json.load(f)
264
- responses = parsed_responses["responses"]
265
- except Exception as e:
266
- print(RED + "Error: Failed to load main/varied_responses.json!" + RESET)
267
- return
268
-
269
- # 3. Load Calibrated Neural Weights
270
- try:
271
- with open("main/response_classifier_weights.json", "r") as f:
272
- weights_data = json.load(f)
273
- weights = weights_data["weights"]
274
- biases = weights_data["biases"]
275
- except Exception as e:
276
- print(RED + "Error: Failed to load main/response_classifier_weights.json!" + RESET)
277
- print("Please train your response classifier weights first by running the Sesi trainer!")
278
- return
279
-
280
- print_ascii_header()
281
-
282
- # 4. Print beautiful interactive directory
283
- print(BOLD + WHITE + "[ DIRECTORY ] AVAILABLE CONVERSATIONAL EXPERTS:" + RESET)
284
- print(BLUE + "-" * 70 + RESET)
285
- for i, p in enumerate(personas):
286
- cat = get_persona_category(p)
287
- if cat == "audio":
288
- color = COLOR_AUDIO
289
- elif cat == "mechanical":
290
- color = COLOR_MECH
291
- else:
292
- color = COLOR_SYS
293
-
294
- print(f"[{BOLD}{i:2d}{RESET}] {color}{p['name']:22s}{RESET} (Age: {p['age']}) [{BOLD}{cat.upper()}{RESET}]")
295
- print(BLUE + "-" * 70 + RESET)
296
-
297
- # 5. User selection loop
298
- while True:
299
- try:
300
- choice = input(BOLD + WHITE + "\n>> Select persona number [0-19]: " + RESET).strip()
301
- if choice.lower() == "exit":
302
- print("Goodbye!")
303
- return
304
- idx = int(choice)
305
- if 0 <= idx < len(personas):
306
- partner = personas[idx]
307
- break
308
- else:
309
- print(RED + "Please enter a valid index between 0 and 19." + RESET)
310
- except ValueError:
311
- print(RED + "Please enter a numeric index." + RESET)
312
-
313
- # 6. Initialize dynamic neural brains
314
- partner_native = get_persona_category(partner)
315
- partner_color = COLOR_AUDIO if partner_native == "audio" else (COLOR_MECH if partner_native == "mechanical" else COLOR_SYS)
316
-
317
- print(BOLD + "\n[+] LOADING CALIBRATED 10x3 NEURAL WEIGHTS...")
318
- time.sleep(0.4)
319
- print(GREEN + "[ok] Synapses calibrated. Initializing speech transitions..." + RESET)
320
-
321
- # Pre-build vocabulary brains for all 3 categories dynamically
322
- brains = {
323
- "audio": build_markov_brain("audio", responses),
324
- "mechanical": build_markov_brain("mechanical", responses),
325
- "systems": build_markov_brain("systems", responses)
326
- }
327
- time.sleep(0.4)
328
- print(GREEN + "[ok] All vocabulary matrices mapped. Speech brain active!\n" + RESET)
329
-
330
- print("=" * 70)
331
- print(f"[ONLINE] {BOLD}{partner['name']}{RESET} (Age: {partner['age']}) is ONLINE!")
332
- print(f"[CLASS] {BOLD}Personality Class:{RESET} {partner_color}{partner_native.upper()}{RESET}")
333
- print(f"[BIO] {BOLD}Bio Description:{RESET} {partner['personality']}")
334
- print(f"[TONE] {BOLD}Conversational Tone:{RESET} {partner['tone']}")
335
- print(BOLD + WHITE + "Type your message below! Type 'exit' or 'quit' to shut down connection." + RESET)
336
- print("=" * 70 + "\n")
337
-
338
- # 7. Interactive Neural-Empathetic Loop
339
- while True:
340
- try:
341
- user_msg = input(BOLD + WHITE + "You: " + RESET).strip()
342
- if not user_msg:
343
- continue
344
-
345
- if user_msg.lower() in ["exit", "quit", "close"]:
346
- print(BOLD + BLUE + f"\n[!] Terminating connection with {partner['name']}. Offline gateway closed. Goodbye!\n" + RESET)
347
- break
348
-
349
- # A. Execute Neural Classification
350
- predicted_class, probs = predict_neural_class(user_msg, weights, biases)
351
-
352
- # Print visually outstanding probability bars
353
- print(BOLD + BLUE + "\n[ NEURAL RESPONSE CLASSIFICATION ]" + RESET)
354
- print(render_probability_bars(probs))
355
- print(BOLD + BLUE + f"[ ROUTING COGNITIVE FLOW -> {predicted_class.upper()} CLASS ]\n" + RESET)
356
- time.sleep(0.2)
357
-
358
- # B. Morph Speech Brain dynamically (Cognitive Resonance!)
359
- transitions, words_list, c_len = brains[predicted_class]
360
-
361
- # C. Extract matching vocabulary seeds to trigger speech
362
- user_words = [w.lower().replace(".", "").replace("!", "").replace("?", "") for w in user_msg.split()]
363
- matched_words = [w for w in user_words if w in transitions]
364
-
365
- if matched_words:
366
- start_word = random.choice(matched_words)
367
- else:
368
- start_word = random.choice(words_list)
369
-
370
- # D. Synthesize loop-free, penalized sentence reply
371
- reply_sentence = walk_complete_sentence_penalized(transitions, words_list, c_len, start_word)
372
-
373
- # E. Prepend Neural Empathy Bridge Prefix
374
- empathetic_prefix = get_empathetic_prefix(partner_native, predicted_class)
375
- full_reply = empathetic_prefix + reply_sentence
376
-
377
- # Print stylized character dialogue
378
- print(BOLD + partner_color + f"{partner['name']}: " + RESET + full_reply + "\n")
379
-
380
- except KeyboardInterrupt:
381
- print(BOLD + BLUE + f"\n[!] Terminating connection with {partner['name']}. Offline gateway closed. Goodbye!\n" + RESET)
382
- break
383
-
384
- if __name__ == "__main__":
385
- main()