bscript-cli 1.0.0

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 (47) hide show
  1. package/BScript.js +233 -0
  2. package/Docs/BScript/BSCRIPT-REFERENCE-CLI.md +502 -0
  3. package/Docs/Images/BScript-baner.png +0 -0
  4. package/Docs/Images/BooleanType.png +0 -0
  5. package/Docs/Images/FuncionType.png +0 -0
  6. package/Docs/Images/Logo.png +0 -0
  7. package/Docs/Images/NumberType.png +0 -0
  8. package/Docs/Images/ObjectType.png +0 -0
  9. package/Docs/Images/PromiseType.png +0 -0
  10. package/Docs/Images/RawType.png +0 -0
  11. package/Docs/Images/RefType.png +0 -0
  12. package/Docs/Images/TextType.png +0 -0
  13. package/Docs/README.md +157 -0
  14. package/Docs/REFERENCE.md +602 -0
  15. package/Docs/TECHNICAL.md +1143 -0
  16. package/Docs/TUTORIAL.md +604 -0
  17. package/SRC/BScriptHistory.js +98 -0
  18. package/SRC/CMDPermissions.js +4 -0
  19. package/SRC/utils/utils.js +63 -0
  20. package/TerminalCommandController.js +193 -0
  21. package/bin/bscript.js +94 -0
  22. package/commands/.default/BScript/$arg.js +9 -0
  23. package/commands/.default/BScript/$val.js +19 -0
  24. package/commands/.default/BScript/Input.js +10 -0
  25. package/commands/.default/BScript/bool.js +9 -0
  26. package/commands/.default/BScript/delay.js +10 -0
  27. package/commands/.default/BScript/eval.js +9 -0
  28. package/commands/.default/BScript/import.js +17 -0
  29. package/commands/.default/BScript/js_new.js +9 -0
  30. package/commands/.default/BScript/js_require.js +9 -0
  31. package/commands/.default/BScript/jstype.js +9 -0
  32. package/commands/.default/BScript/num.js +9 -0
  33. package/commands/.default/BScript/object.js +19 -0
  34. package/commands/.default/BScript/print.js +9 -0
  35. package/commands/.default/BScript/raw.js +9 -0
  36. package/commands/.default/BScript/ref.js +65 -0
  37. package/commands/.default/BScript/run-with-await.js +13 -0
  38. package/commands/.default/BScript/run.js +11 -0
  39. package/commands/.default/BScript/script.js +13 -0
  40. package/commands/.default/BScript/str.js +9 -0
  41. package/commands/.default/DebugOnly/clear.js +8 -0
  42. package/commands/.default/DebugOnly/update-commands.js +8 -0
  43. package/commands/.default/help.js +20 -0
  44. package/commands/snapshot.md +421 -0
  45. package/index.js +8 -0
  46. package/package.json +12 -0
  47. package/postinstall.js +12 -0
@@ -0,0 +1,1143 @@
1
+ # Technical Documentation
2
+
3
+ This document describes the complete internal architecture of the library, including **public and internal modules, classes, functions, constants, and helper utilities**.
4
+
5
+ Public declarations are also documented in **REFERENCE.md**, while this document contains implementation details intended primarily for contributors and maintainers.
6
+
7
+ ---
8
+
9
+ ## Guide
10
+
11
+ <details>
12
+ <summary>BScript</summary>
13
+
14
+ ## Parent
15
+ [BScript.BScript](#BScriptBScript)
16
+
17
+ ### Constants
18
+ - [perrmissionsKeys](#BScriptBScriptperrmissionsKeys)
19
+
20
+ ### Properties
21
+ - [cmdRootPermissions](#BScriptBScriptcmdRootPermissions)
22
+ - [commandHistory](#BScriptBScriptcommandHistory)
23
+ - [returnCode](#BScriptBScriptreturnCode)
24
+ - [_commands](#BScriptBScript_commands)
25
+ - [_commandHistoryLimit](#BScriptBScript_commandHistoryLimit)
26
+ - [_historyPos](#BScriptBScript_historyPos)
27
+
28
+ ### Methods
29
+ - [bscript()](#BScriptBScriptbscript)
30
+ - [Start()](#BScriptBScriptStart)
31
+ - [updateCommands()](#BScriptBScriptupdateCommands)
32
+ - [createCommand()](#BScriptBScriptcreateCommand)
33
+ - [executeCommand()](#BScriptBScriptexecuteCommand)
34
+ - [loader()](#BScriptBScriptloader)
35
+ - [pushToCommandHistory()](#BScriptBScriptpushToCommandHistory)
36
+
37
+ </details>
38
+
39
+ <details>
40
+ <summary>TerminalCommandController</summary>
41
+
42
+ ## Parent
43
+ [TerminalCommandController.TCC](#TerminalCommandControllerTCC)
44
+
45
+ ### Properties
46
+ - [stdinVal](#TerminalCommandControllerTCCstdinVal)
47
+ - [col](#TerminalCommandControllerTCCcol)
48
+ - [BScriptHistory](#TerminalCommandControllerTCCBScriptHistory)
49
+
50
+ ### Methods
51
+ - [ClearLine()](#TerminalCommandControllerTCCClearLine)
52
+ - [CursorTo()](#TerminalCommandControllerTCCCursorTo)
53
+ - [WriteCommand()](#TerminalCommandControllerTCCWriteCommand)
54
+ - [commandRender()](#TerminalCommandControllerTCCcommandRender)
55
+ - [OnData()](#TerminalCommandControllerTCCOnData)
56
+
57
+ </details>
58
+
59
+ <details>
60
+ <summary>BScriptHistory</summary>
61
+
62
+ ## Parent
63
+ [BScriptHistory.BScriptHistory](#BScriptHistoryBScriptHistory)
64
+
65
+ ### Methods
66
+ - [load()](#BScriptHistoryload)
67
+ - [save()](#BScriptHistorysave)
68
+ - [clear()](#BScriptHistoryclear)
69
+
70
+ </details>
71
+
72
+ <details>
73
+ <summary>Utilities</summary>
74
+
75
+ ## Parent
76
+ [Utilities.utils](#Utilitiesutils)
77
+
78
+ ### Functions
79
+ - [readDirRecursive()](#Utilitiesreadfilerecursive)
80
+ - [getLeftWordIndex()](#UtilitiesgetLeftWordIndex)
81
+ - [getRightWordIndex()](#UtilitiesgetRightWordIndex)
82
+ - [delay()](#Utilitiesdelay)
83
+ - [arraysIsEqual()](#UtilitiesarraysIsEqual)
84
+ - [insert()](#Utilitiesinsert)
85
+ - [removeByIndex()](#UtilitiesremoveByIndex)
86
+
87
+ </details>
88
+
89
+ ---
90
+
91
+ <a id="BScriptBScript"></a>
92
+
93
+ ## BScript.BScript
94
+
95
+ [REFERENCE.md](./REFERENCE.md#BScriptBScript)
96
+
97
+ ### Opportunities
98
+
99
+ - Support for asynchronous command execution with loader animations
100
+ - Custom sandbox contexts for safe script evaluation
101
+ - Hot-reload of commands without process restart
102
+ - Event-driven architecture for extensibility
103
+ - Fine-grained permission system for multi-role applications
104
+ - Integration with external command loaders
105
+
106
+ ### Declaration
107
+
108
+ ```javascript
109
+ class BScript extends EventEmitter
110
+ ```
111
+
112
+ Core command-line interface engine that manages command registration, execution, permissions, and terminal interaction.
113
+
114
+ ---
115
+
116
+ ## Constants
117
+
118
+ <table>
119
+
120
+ <tr>
121
+ <th>Constant</th>
122
+ <th>Declaration</th>
123
+ <th>Description</th>
124
+ </tr>
125
+
126
+ <tr>
127
+
128
+ <a id="BScriptBScriptperrmissionsKeys"></a>
129
+
130
+ <td>
131
+
132
+ <code>perrmissionsKeys</code>
133
+
134
+ </td>
135
+
136
+ <td>
137
+
138
+ ```javascript
139
+ const perrmissionsKeys = {
140
+ default: 0,
141
+ script: 999,
142
+ ...options.perrmissionsKeys
143
+ }
144
+ ```
145
+
146
+ </td>
147
+
148
+ <td>
149
+
150
+ Permission level constants merged from CMDPermissions and constructor options. Defines access control tiers for commands.
151
+
152
+ </td>
153
+
154
+ </tr>
155
+
156
+ </table>
157
+
158
+ ---
159
+
160
+ ## Properties
161
+
162
+ <table>
163
+
164
+ <tr>
165
+ <th>Property</th>
166
+ <th>Declaration</th>
167
+ <th>Description</th>
168
+ </tr>
169
+
170
+ <tr>
171
+
172
+ <a id="BScriptBScriptcmdRootPermissions"></a>
173
+
174
+ <td>
175
+
176
+ <code>cmdRootPermissions</code>
177
+
178
+ </td>
179
+
180
+ <td>
181
+
182
+ ```javascript
183
+ this.cmdRootPermissions = [
184
+ ...options.cmdRootPermissions ?? []
185
+ ]
186
+ ```
187
+
188
+ </td>
189
+
190
+ <td>
191
+
192
+ Array of current permission levels. Controls which commands are available. Modified to change access levels.
193
+
194
+ </td>
195
+
196
+ </tr>
197
+
198
+ <tr>
199
+
200
+ <a id="BScriptBScriptcommandHistory"></a>
201
+
202
+ <td>
203
+
204
+ <code>commandHistory</code>
205
+
206
+ </td>
207
+
208
+ <td>
209
+
210
+ ```javascript
211
+ this.commandHistory = []
212
+ ```
213
+
214
+ </td>
215
+
216
+ <td>
217
+
218
+ List of executed commands. Persisted through BScriptHistory. Limited to _commandHistoryLimit entries.
219
+
220
+ </td>
221
+
222
+ </tr>
223
+
224
+ <tr>
225
+
226
+ <a id="BScriptBScriptreturnCode"></a>
227
+
228
+ <td>
229
+
230
+ <code>returnCode</code>
231
+
232
+ </td>
233
+
234
+ <td>
235
+
236
+ ```javascript
237
+ this.returnCode = 1
238
+ ```
239
+
240
+ </td>
241
+
242
+ <td>
243
+
244
+ Exit status code. -1 = loading, 1 = ready, other values indicate errors or custom states.
245
+
246
+ </td>
247
+
248
+ </tr>
249
+
250
+ <tr>
251
+
252
+ <a id="BScriptBScript_commands"></a>
253
+
254
+ <td>
255
+
256
+ <code>_commands</code>
257
+
258
+ </td>
259
+
260
+ <td>
261
+
262
+ ```javascript
263
+ this._commands = {}
264
+ ```
265
+
266
+ </td>
267
+
268
+ <td>
269
+
270
+ Internal registry of loaded commands. Keyed by command name, values contain execute functions and metadata.
271
+
272
+ </td>
273
+
274
+ </tr>
275
+
276
+ <tr>
277
+
278
+ <a id="BScriptBScript_commandHistoryLimit"></a>
279
+
280
+ <td>
281
+
282
+ <code>_commandHistoryLimit</code>
283
+
284
+ </td>
285
+
286
+ <td>
287
+
288
+ ```javascript
289
+ this._commandHistoryLimit = 10
290
+ ```
291
+
292
+ </td>
293
+
294
+ <td>
295
+
296
+ Maximum number of commands to retain in history. Oldest entries are removed when limit exceeded.
297
+
298
+ </td>
299
+
300
+ </tr>
301
+
302
+ <tr>
303
+
304
+ <a id="BScriptBScript_historyPos"></a>
305
+
306
+ <td>
307
+
308
+ <code>_historyPos</code>
309
+
310
+ </td>
311
+
312
+ <td>
313
+
314
+ ```javascript
315
+ this._historyPos = -1
316
+ ```
317
+
318
+ </td>
319
+
320
+ <td>
321
+
322
+ Current position in command history during navigation. -1 = no history entry selected.
323
+
324
+ </td>
325
+
326
+ </tr>
327
+
328
+ </table>
329
+
330
+ ---
331
+
332
+ ## Methods
333
+
334
+ <table>
335
+
336
+ <tr>
337
+ <th>Method</th>
338
+ <th>Declaration</th>
339
+ <th>Description</th>
340
+ </tr>
341
+
342
+ <tr>
343
+
344
+ <a id="BScriptBScriptbscript"></a>
345
+
346
+ <td>
347
+
348
+ <code>bscript()</code>
349
+
350
+ </td>
351
+
352
+ <td>
353
+
354
+ ```javascript
355
+ bscript(scriptCode)
356
+ ```
357
+
358
+ </td>
359
+
360
+ <td>
361
+
362
+ Parses a script string and returns a function that executes it. Uses BScriptRunner for parsing. Supports script paths and inline code.
363
+
364
+ </td>
365
+
366
+ </tr>
367
+
368
+ <tr>
369
+
370
+ <a id="BScriptBScriptStart"></a>
371
+
372
+ <td>
373
+
374
+ <code>Start()</code>
375
+
376
+ </td>
377
+
378
+ <td>
379
+
380
+ ```javascript
381
+ Start()
382
+ ```
383
+
384
+ </td>
385
+
386
+ <td>
387
+
388
+ Initializes raw mode input, sets up stdin listeners, and begins the interactive command loop. Displays prompt and processes user input in real-time.
389
+
390
+ </td>
391
+
392
+ </tr>
393
+
394
+ <tr>
395
+
396
+ <a id="BScriptBScriptupdateCommands"></a>
397
+
398
+ <td>
399
+
400
+ <code>updateCommands()</code>
401
+
402
+ </td>
403
+
404
+ <td>
405
+
406
+ ```javascript
407
+ updateCommands()
408
+ ```
409
+
410
+ </td>
411
+
412
+ <td>
413
+
414
+ Scans all commandsPaths directories for .js files. Loads each file in isolated sandbox with vm.runInNewContext. Filters based on permissions and command properties.
415
+
416
+ </td>
417
+
418
+ </tr>
419
+
420
+ <tr>
421
+
422
+ <a id="BScriptBScriptcreateCommand"></a>
423
+
424
+ <td>
425
+
426
+ <code>createCommand()</code>
427
+
428
+ </td>
429
+
430
+ <td>
431
+
432
+ ```javascript
433
+ createCommand({
434
+ name,
435
+ execute,
436
+ description,
437
+ syntax,
438
+ uniqueKey
439
+ })
440
+ ```
441
+
442
+ </td>
443
+
444
+ <td>
445
+
446
+ Registers a command in \_commands. Supports command aliases (multiple names). Stores metadata for help and introspection.
447
+
448
+ </td>
449
+
450
+ </tr>
451
+
452
+ <tr>
453
+
454
+ <a id="BScriptBScriptexecuteCommand"></a>
455
+
456
+ <td>
457
+
458
+ <code>executeCommand()</code>
459
+
460
+ </td>
461
+
462
+ <td>
463
+
464
+ ```javascript
465
+ executeCommand(commandString)
466
+ ```
467
+
468
+ </td>
469
+
470
+ <td>
471
+
472
+ Parses command string into command name and arguments. Looks up command in registry and invokes execute function with arguments array.
473
+
474
+ </td>
475
+
476
+ </tr>
477
+
478
+ <tr>
479
+
480
+ <a id="BScriptBScriptloader"></a>
481
+
482
+ <td>
483
+
484
+ <code>loader()</code>
485
+
486
+ </td>
487
+
488
+ <td>
489
+
490
+ ```javascript
491
+ loader(func)
492
+ ```
493
+
494
+ </td>
495
+
496
+ <td>
497
+
498
+ Async wrapper that displays animated "Loading..." message while executing function. Calls done() callback when complete. Sets returnCode to -1 during loading, 1 when done.
499
+
500
+ </td>
501
+
502
+ </tr>
503
+
504
+ <tr>
505
+
506
+ <a id="BScriptBScriptpushToCommandHistory"></a>
507
+
508
+ <td>
509
+
510
+ <code>pushToCommandHistory()</code>
511
+
512
+ </td>
513
+
514
+ <td>
515
+
516
+ ```javascript
517
+ pushToCommandHistory(cmd)
518
+ ```
519
+
520
+ </td>
521
+
522
+ <td>
523
+
524
+ Adds command to history if not duplicate of last entry. Removes oldest entry if history exceeds \_commandHistoryLimit.
525
+
526
+ </td>
527
+
528
+ </tr>
529
+
530
+ </table>
531
+
532
+ ---
533
+
534
+ <a id="TerminalCommandControllerTCC"></a>
535
+
536
+ ## TerminalCommandController.TCC
537
+
538
+ ### Declaration
539
+
540
+ ```javascript
541
+ class TCC
542
+ ```
543
+
544
+ Low-level terminal controller managing stdin/stdout operations, cursor control, and raw input processing. Integrates with BScriptHistory for persistence.
545
+
546
+ ---
547
+
548
+ ## Properties
549
+
550
+ <table>
551
+
552
+ <tr>
553
+ <th>Property</th>
554
+ <th>Declaration</th>
555
+ <th>Description</th>
556
+ </tr>
557
+
558
+ <tr>
559
+
560
+ <a id="TerminalCommandControllerTCCstdinVal"></a>
561
+
562
+ <td>
563
+
564
+ <code>stdinVal</code>
565
+
566
+ </td>
567
+
568
+ <td>
569
+
570
+ ```javascript
571
+ this.stdinVal = args?.defaultCommandPrefix ?? 0
572
+ ```
573
+
574
+ </td>
575
+
576
+ <td>
577
+
578
+ Current value of stdin/command line buffer. Updated as user types.
579
+
580
+ </td>
581
+
582
+ </tr>
583
+
584
+ <tr>
585
+
586
+ <a id="TerminalCommandControllerTCCcol"></a>
587
+
588
+ <td>
589
+
590
+ <code>col</code>
591
+
592
+ </td>
593
+
594
+ <td>
595
+
596
+ ```javascript
597
+ this.col = args?.col ?? 0
598
+ ```
599
+
600
+ </td>
601
+
602
+ <td>
603
+
604
+ Current cursor column position relative to command prefix. Used for accurate cursor positioning during editing.
605
+
606
+ </td>
607
+
608
+ </tr>
609
+
610
+ <tr>
611
+
612
+ <a id="TerminalCommandControllerTCCBScriptHistory"></a>
613
+
614
+ <td>
615
+
616
+ <code>BScriptHistory</code>
617
+
618
+ </td>
619
+
620
+ <td>
621
+
622
+ ```javascript
623
+ this.BScriptHistory = new BScriptHistory()
624
+ ```
625
+
626
+ </td>
627
+
628
+ <td>
629
+
630
+ Instance of BScriptHistory for managing persistent command history. Synced on exit via signal handlers.
631
+
632
+ </td>
633
+
634
+ </tr>
635
+
636
+ </table>
637
+
638
+ ---
639
+
640
+ ## Methods
641
+
642
+ <table>
643
+
644
+ <tr>
645
+ <th>Method</th>
646
+ <th>Declaration</th>
647
+ <th>Description</th>
648
+ </tr>
649
+
650
+ <tr>
651
+
652
+ <a id="TerminalCommandControllerTCCClearLine"></a>
653
+
654
+ <td>
655
+
656
+ <code>ClearLine()</code>
657
+
658
+ </td>
659
+
660
+ <td>
661
+
662
+ ```javascript
663
+ ClearLine()
664
+ ```
665
+
666
+ </td>
667
+
668
+ <td>
669
+
670
+ Sends ANSI escape sequence to clear current line and move cursor to beginning. Uses "\r\x1b[K".
671
+
672
+ </td>
673
+
674
+ </tr>
675
+
676
+ <tr>
677
+
678
+ <a id="TerminalCommandControllerTCCCursorTo"></a>
679
+
680
+ <td>
681
+
682
+ <code>CursorTo()</code>
683
+
684
+ </td>
685
+
686
+ <td>
687
+
688
+ ```javascript
689
+ CursorTo(pos)
690
+ ```
691
+
692
+ </td>
693
+
694
+ <td>
695
+
696
+ Positions cursor at absolute column position using stdout.cursorTo().
697
+
698
+ </td>
699
+
700
+ </tr>
701
+
702
+ <tr>
703
+
704
+ <a id="TerminalCommandControllerTCCWriteCommand"></a>
705
+
706
+ <td>
707
+
708
+ <code>WriteCommand()</code>
709
+
710
+ </td>
711
+
712
+ <td>
713
+
714
+ ```javascript
715
+ WriteCommand(cmd)
716
+ ```
717
+
718
+ </td>
719
+
720
+ <td>
721
+
722
+ Writes command with prefix prompt. Combines defaultCommandPrefix with command text.
723
+
724
+ </td>
725
+
726
+ </tr>
727
+
728
+ <tr>
729
+
730
+ <a id="TerminalCommandControllerTCCcommandRender"></a>
731
+
732
+ <td>
733
+
734
+ <code>commandRender()</code>
735
+
736
+ </td>
737
+
738
+ <td>
739
+
740
+ ```javascript
741
+ commandRender(inputStdin)
742
+ ```
743
+
744
+ </td>
745
+
746
+ <td>
747
+
748
+ Core input handler processing single keypress. Handles arrow keys, delete, backspace, history navigation, word jumping. Returns 1 for Enter, 0 otherwise.
749
+
750
+ </td>
751
+
752
+ </tr>
753
+
754
+ <tr>
755
+
756
+ <a id="TerminalCommandControllerTCCOnData"></a>
757
+
758
+ <td>
759
+
760
+ <code>OnData()</code>
761
+
762
+ </td>
763
+
764
+ <td>
765
+
766
+ ```javascript
767
+ OnData(inputStdin)
768
+ ```
769
+
770
+ </td>
771
+
772
+ <td>
773
+
774
+ Public wrapper for commandRender(). Called by stdin 'data' event listener.
775
+
776
+ </td>
777
+
778
+ </tr>
779
+
780
+ </table>
781
+
782
+ ---
783
+
784
+ <a id="BScriptHistoryBScriptHistory"></a>
785
+
786
+ ## BScriptHistory.BScriptHistory
787
+
788
+ ### Declaration
789
+
790
+ ```javascript
791
+ class BScriptHistory
792
+ ```
793
+
794
+ Manages persistent command history stored on disk. Loads history on instantiation and provides save/load/clear interface.
795
+
796
+ ---
797
+
798
+ ## Methods
799
+
800
+ <table>
801
+
802
+ <tr>
803
+ <th>Method</th>
804
+ <th>Declaration</th>
805
+ <th>Description</th>
806
+ </tr>
807
+
808
+ <tr>
809
+
810
+ <a id="BScriptHistoryload"></a>
811
+
812
+ <td>
813
+
814
+ <code>load()</code>
815
+
816
+ </td>
817
+
818
+ <td>
819
+
820
+ ```javascript
821
+ load()
822
+ ```
823
+
824
+ </td>
825
+
826
+ <td>
827
+
828
+ Reads history file from disk and parses it. Called automatically in constructor. Returns array of command strings.
829
+
830
+ </td>
831
+
832
+ </tr>
833
+
834
+ <tr>
835
+
836
+ <a id="BScriptHistorysave"></a>
837
+
838
+ <td>
839
+
840
+ <code>save()</code>
841
+
842
+ </td>
843
+
844
+ <td>
845
+
846
+ ```javascript
847
+ save()
848
+ ```
849
+
850
+ </td>
851
+
852
+ <td>
853
+
854
+ Writes current history array to persistent storage. Called on process exit and SIGINT/SIGTERM signals.
855
+
856
+ </td>
857
+
858
+ </tr>
859
+
860
+ <tr>
861
+
862
+ <a id="BScriptHistoryclear"></a>
863
+
864
+ <td>
865
+
866
+ <code>clear()</code>
867
+
868
+ </td>
869
+
870
+ <td>
871
+
872
+ ```javascript
873
+ clear()
874
+ ```
875
+
876
+ </td>
877
+
878
+ <td>
879
+
880
+ Clears in-memory history and deletes history file. Useful for starting fresh sessions.
881
+
882
+ </td>
883
+
884
+ </tr>
885
+
886
+ </table>
887
+
888
+ ---
889
+
890
+ <a id="Utilitiesutils"></a>
891
+
892
+ ## Utilities.utils
893
+
894
+ ### Declaration
895
+
896
+ ```javascript
897
+ module.exports = {
898
+ readDirRecursive,
899
+ getLeftWordIndex,
900
+ getRightWordIndex,
901
+ delay,
902
+ arraysIsEqual,
903
+ insert,
904
+ removeByIndex
905
+ }
906
+ ```
907
+
908
+ Collection of utility functions used throughout the codebase for file scanning, text manipulation, and timing.
909
+
910
+ ---
911
+
912
+ ## Functions
913
+
914
+ <table>
915
+
916
+ <tr>
917
+ <th>Function</th>
918
+ <th>Declaration</th>
919
+ <th>Description</th>
920
+ </tr>
921
+
922
+ <tr>
923
+
924
+ <a id="Utilitiesreadfilerecursive"></a>
925
+
926
+ <td>
927
+
928
+ <code>readDirRecursive()</code>
929
+
930
+ </td>
931
+
932
+ <td>
933
+
934
+ ```javascript
935
+ readDirRecursive(dir)
936
+ ```
937
+
938
+ </td>
939
+
940
+ <td>
941
+
942
+ Recursively scans directory and returns array of all file paths (not directories). Used by updateCommands() to find .js files.
943
+
944
+ </td>
945
+
946
+ </tr>
947
+
948
+ <tr>
949
+
950
+ <a id="UtilitiesgetLeftWordIndex"></a>
951
+
952
+ <td>
953
+
954
+ <code>getLeftWordIndex()</code>
955
+
956
+ </td>
957
+
958
+ <td>
959
+
960
+ ```javascript
961
+ getLeftWordIndex(text, index)
962
+ ```
963
+
964
+ </td>
965
+
966
+ <td>
967
+
968
+ Returns character index of start of word to the left of cursor position. Handles edge cases at text boundaries.
969
+
970
+ </td>
971
+
972
+ </tr>
973
+
974
+ <tr>
975
+
976
+ <a id="UtilitiesgetRightWordIndex"></a>
977
+
978
+ <td>
979
+
980
+ <code>getRightWordIndex()</code>
981
+
982
+ </td>
983
+
984
+ <td>
985
+
986
+ ```javascript
987
+ getRightWordIndex(text, index)
988
+ ```
989
+
990
+ </td>
991
+
992
+ <td>
993
+
994
+ Returns character index of end of word to the right of cursor position.
995
+
996
+ </td>
997
+
998
+ </tr>
999
+
1000
+ <tr>
1001
+
1002
+ <a id="Utilitiesdelay"></a>
1003
+
1004
+ <td>
1005
+
1006
+ <code>delay()</code>
1007
+
1008
+ </td>
1009
+
1010
+ <td>
1011
+
1012
+ ```javascript
1013
+ delay(time)
1014
+ ```
1015
+
1016
+ </td>
1017
+
1018
+ <td>
1019
+
1020
+ Promise-based delay for async/await. Resolves after specified milliseconds. Used in loader animation.
1021
+
1022
+ </td>
1023
+
1024
+ </tr>
1025
+
1026
+ <tr>
1027
+
1028
+ <a id="UtilitiesarraysIsEqual"></a>
1029
+
1030
+ <td>
1031
+
1032
+ <code>arraysIsEqual()</code>
1033
+
1034
+ </td>
1035
+
1036
+ <td>
1037
+
1038
+ ```javascript
1039
+ arraysIsEqual(arr1, arr2)
1040
+ ```
1041
+
1042
+ </td>
1043
+
1044
+ <td>
1045
+
1046
+ Compares two arrays by JSON serialization. Returns true if contents are identical.
1047
+
1048
+ </td>
1049
+
1050
+ </tr>
1051
+
1052
+ <tr>
1053
+
1054
+ <a id="Utilitiesinsert"></a>
1055
+
1056
+ <td>
1057
+
1058
+ <code>insert()</code>
1059
+
1060
+ </td>
1061
+
1062
+ <td>
1063
+
1064
+ ```javascript
1065
+ insert(str, index, string)
1066
+ ```
1067
+
1068
+ </td>
1069
+
1070
+ <td>
1071
+
1072
+ Inserts substring at specified index. Returns modified string.
1073
+
1074
+ </td>
1075
+
1076
+ </tr>
1077
+
1078
+ <tr>
1079
+
1080
+ <a id="UtilitiesremoveByIndex"></a>
1081
+
1082
+ <td>
1083
+
1084
+ <code>removeByIndex()</code>
1085
+
1086
+ </td>
1087
+
1088
+ <td>
1089
+
1090
+ ```javascript
1091
+ removeByIndex(str, index)
1092
+ ```
1093
+
1094
+ </td>
1095
+
1096
+ <td>
1097
+
1098
+ Removes character at specified index. Used for backspace/delete key handling.
1099
+
1100
+ </td>
1101
+
1102
+ </tr>
1103
+
1104
+ </table>
1105
+
1106
+ ---
1107
+
1108
+ ## Internal Architecture Notes
1109
+
1110
+ ### Command Loading Pipeline
1111
+
1112
+ 1. `updateCommands()` called with configured permission levels
1113
+ 2. Scans all commandsPaths directories recursively for .js files
1114
+ 3. For each file, creates isolated V8 context using `vm.runInNewContext()`
1115
+ 4. File executed in sandbox with access to CMDPermissions, require, and globals
1116
+ 5. Module exports checked for command definition properties
1117
+ 6. Permission filtering applied: command must have matching perms, no excludePerms
1118
+ 7. Command(s) registered via `createCommand()`
1119
+
1120
+ ### Permission System
1121
+
1122
+ - Commands define required permissions via `.perms` array
1123
+ - Commands can exclude certain permissions via `.excludePerms` array
1124
+ - Root permissions (`cmdRootPermissions`) combined with history permissions (`cmdPermissionsHistory`)
1125
+ - Permission check: `cmdPermission.some(currentPerm => command.perms.includes(currentPerm))`
1126
+
1127
+ ### Async Loader Pattern
1128
+
1129
+ - `loader(func)` provides animation while async work completes
1130
+ - Returns Promise that resolves when done() callback invoked
1131
+ - Three parameters: `done()` to finish, `waitForPromise()` for nested async, `startAnimation()` to restart
1132
+
1133
+ ### Terminal Input Handling
1134
+
1135
+ - Raw mode enabled via stdin.setRawMode(true)
1136
+ - Each keystroke triggers `OnData()` with character code
1137
+ - Arrow keys sent as multi-byte escape sequences (e.g., "\u001b[A" for up)
1138
+ - History navigation modifies stdinVal and updates display
1139
+ - Word boundary detection via helper functions for Ctrl+Left/Right
1140
+
1141
+ ---
1142
+
1143
+ **Made with ❤️ for the Node.js ecosystem**