zshrs 0.10.4

The first compiled Unix shell — bytecode VM, worker pool, AOP intercept, SQLite caching
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta name="color-scheme" content="dark light">
  <meta name="description" content="zshrs — the most powerful shell ever created. No-fork architecture, AOP intercept, worker thread pool, bytecode caching, fusevm compiled execution.">
  <title>zshrs — Documentation</title>
  <link rel="preconnect" href="https://fonts.googleapis.com">
  <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
  <link href="https://fonts.googleapis.com/css2?family=Orbitron:wght@400;600;700;900&amp;family=Share+Tech+Mono&amp;display=swap" rel="stylesheet">
  <link rel="stylesheet" href="hud-static.css">
  <link rel="stylesheet" href="tutorial.css">
  <style>
    .tutorial-main { max-width: 68rem; }
    .arch-table { width: 100%; border-collapse: collapse; margin: 0.6rem 0 1rem; font-size: 12px; }
    .arch-table th {
      background: var(--bg-secondary); color: var(--cyan);
      font-family: 'Orbitron', sans-serif; font-size: 10px; font-weight: 700;
      letter-spacing: 1px; text-transform: uppercase; text-align: left;
      padding: 6px 10px; border: 1px solid var(--border);
    }
    .arch-table td { padding: 6px 10px; border: 1px solid var(--border); color: var(--text-dim); vertical-align: top; }
    .arch-table td code { color: var(--accent-light); background: var(--bg); padding: 1px 4px; font-size: 11px; }
    .arch-table tr:hover td { background: var(--bg-hover); }
    .motto { font-family: 'Orbitron', sans-serif; font-size: 16px; color: var(--accent); letter-spacing: 3px; margin: 0.5rem 0 1.5rem; }
    .section-num { color: var(--cyan); font-family: 'Share Tech Mono', monospace; margin-right: 0.5rem; }
    .code-block {
      margin: 0.5rem 0; padding: 0.7rem 1rem; border-left: 2px solid var(--cyan);
      background: var(--bg); font-family: 'Share Tech Mono', ui-monospace, monospace;
      font-size: 12px; color: var(--text); white-space: pre-wrap; word-break: break-word;
      line-height: 1.6;
    }
    .code-block .comment { color: var(--text-muted); }
    .code-block .keyword { color: var(--cyan); }
    .code-block .string { color: var(--green); }
    .code-block .var { color: var(--accent-light); }
    .diagram {
      margin: 0.8rem 0; padding: 1rem; border: 1px solid var(--border);
      background: var(--bg-secondary); font-family: 'Share Tech Mono', monospace;
      font-size: 12px; color: var(--cyan); white-space: pre; overflow-x: auto; line-height: 1.5;
    }
    .cat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(16rem, 1fr)); gap: 0.6rem; margin: 0.7rem 0; }
    .cat-card {
      border: 1px solid var(--border); border-left: 2px solid var(--cyan);
      padding: 0.6rem 0.8rem; background: color-mix(in srgb, var(--bg-card) 92%, transparent); border-radius: 2px;
    }
    .cat-card h4 {
      font-family: 'Orbitron', sans-serif; font-size: 11px; font-weight: 700;
      letter-spacing: 1.5px; text-transform: uppercase; color: var(--cyan); margin: 0 0 0.35rem;
    }
    .cat-card p { margin: 0; font-size: 11.5px; color: var(--text-dim); line-height: 1.5; }
    .cat-card code { font-size: 11px; color: var(--accent-light); }
    .highlight { color: var(--accent); font-weight: 700; }
    .stat { font-family: 'Orbitron', sans-serif; font-size: 28px; font-weight: 900; color: var(--cyan); }
    .stat-label { font-size: 11px; color: var(--text-muted); letter-spacing: 1px; text-transform: uppercase; }
    .stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(10rem, 1fr)); gap: 1rem; margin: 1rem 0; text-align: center; }
    .docs-build-line {
      margin: 0.35rem 0 0;
      font-family: 'Share Tech Mono', ui-monospace, monospace;
      font-size: 11px;
      color: var(--text-dim);
      letter-spacing: 0.03em;
      max-width: 42rem;
      opacity: 0.75;
    }
    .hub-scheme-strip {
      border-bottom: 1px dashed var(--border);
      background: color-mix(in srgb, var(--bg-secondary) 85%, transparent);
      padding: 0.55rem 1.5rem 0.65rem;
      position: relative;
    }
    .hub-scheme-strip-inner {
      max-width: 68rem;
      margin: 0 auto;
      display: flex;
      align-items: center;
      gap: 0.85rem;
    }
    .hub-scheme-strip .hud-scheme-label {
      flex: 0 0 auto;
      font-family: 'Orbitron', sans-serif;
      font-size: 9px;
      font-weight: 700;
      letter-spacing: 2px;
      text-transform: uppercase;
      color: var(--accent);
      text-align: left;
    }
    .hub-scheme-strip .scheme-grid {
      flex: 1 1 auto;
      display: grid;
      grid-template-columns: repeat(5, minmax(0, 1fr));
      gap: 6px;
    }
    @media (max-width: 720px) {
      .hub-scheme-strip-inner { flex-direction: column; align-items: stretch; }
      .hub-scheme-strip .scheme-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    }
  </style>
</head>
<body>
  <div class="app tutorial-app" id="docsApp">
    <div class="crt-scanline" id="crtH" aria-hidden="true"></div>
    <div class="crt-scanline-v" id="crtV" aria-hidden="true"></div>

    <header class="tutorial-header">
      <div class="tutorial-header-inner">
        <div>
          <h1 class="tutorial-brand">// ZSHRS — COMPILED SHELL</h1>
          <nav class="tutorial-crumbs" aria-label="Breadcrumb">
            <span class="current">Docs</span>
            <span class="sep">/</span>
            <a href="https://github.com/MenkeTechnologies/zshrs" target="_blank" rel="noopener noreferrer">GitHub</a>
            <span class="sep">/</span>
            <a href="https://crates.io/crates/zshrs" target="_blank" rel="noopener noreferrer">crates.io</a>
            <span class="sep">/</span>
            <a href="https://docs.rs/zshrs" target="_blank" rel="noopener noreferrer">docs.rs</a>
          </nav>
          <p class="docs-build-line">zshrs v0.9.4 · Anti-fork architecture · 23 coreutils builtins · VM-executed parallel · Bytecode caching · JIT · <a href="reference.html" style="color: var(--cyan);">Full reference</a> · <a href="daemon-report.html" style="color: var(--cyan);">Daemon impl map</a></p>
        </div>
        <div class="tutorial-toolbar">
          <button type="button" class="btn btn-secondary" id="btnTheme" title="Toggle light/dark">Theme</button>
          <button type="button" class="btn btn-secondary active" id="btnCrt" title="CRT scanline overlay">CRT</button>
          <button type="button" class="btn btn-secondary active" id="btnNeon" title="Neon border pulse">Neon</button>
          <a class="btn btn-secondary" href="reference.html">Reference</a>
          <a class="btn btn-secondary" href="daemon-report.html" title="DAEMON.md → daemon/*.rs implementation map with file:line citations">Daemon Map</a>
          <a class="btn btn-secondary" href="https://github.com/MenkeTechnologies/zshrs" target="_blank" rel="noopener noreferrer">GitHub</a>
          <a class="btn btn-secondary" href="https://github.com/MenkeTechnologies/zshrs/issues" target="_blank" rel="noopener noreferrer">Issues</a>
        </div>
      </div>
    </header>

    <div class="hub-scheme-strip">
      <div class="hub-scheme-strip-inner">
        <span class="hud-scheme-label">// Color scheme</span>
        <div class="scheme-grid" id="hudSchemeGrid"></div>
      </div>
    </div>

    <main class="tutorial-main">
      <h2 class="tutorial-title"><span class="step-hash">&gt;_</span>ZSHRS REFERENCE</h2>
      <p class="tutorial-subtitle">The most powerful shell ever created. No-fork architecture, AOP intercept, worker thread pool, bytecode caching, fusevm compiled execution.</p>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <p class="motto">SHELL SCRIPTS AT MACHINE CODE SPEED.</p>
        <p class="motto" style="font-size: 12px; color: var(--cyan); margin-top: -1rem;">NO FORK. NO INTERPRETER. JUST BYTECODES.</p>

        <div class="stat-grid">
          <div><div class="stat">0</div><div class="stat-label">forks in hot path</div></div>
          <div><div class="stat">100%</div><div class="stat-label">bytecode compiled</div></div>
          <div><div class="stat">18</div><div class="stat-label">worker threads</div></div>
          <div><div class="stat">180+</div><div class="stat-label">builtins</div></div>
          <div><div class="stat">23</div><div class="stat-label">coreutils builtins</div></div>
          <div><div class="stat">100x</div><div class="stat-label">warm start speedup</div></div>
          <div><div class="stat">2000x</div><div class="stat-label">fork avoidance speedup</div></div>
          <div><div class="stat">1st</div><div class="stat-label">compiled Unix shell</div></div>
        </div>

        <p style="font-size: 14px; line-height: 1.8; color: var(--text);">
        For the first time in the history of computing &mdash; since the dawn of Unix at Bell Labs
        in 1970 &mdash; a shell compiles to executable bytecodes and runs them on a virtual machine
        with fused superinstructions. <span class="highlight">Every interactive command line, every shell script,
        every function invocation, every <code>source</code>&rsquo;d file</span> compiles to fusevm bytecodes
        and executes at near-machine-code speed. No tree-walking interpreter. No fork. No parsing at
        runtime if bytecodes are cached.</p>

        <p style="font-size: 14px; line-height: 1.8; color: var(--text);">
        Compiled bytecodes are cached as <code>rkyv</code> zero-copy archives mmap'd directly into
        memory. Function invocations deserialize cached bytecodes
        in microseconds &mdash; skipping the lexer, parser, and compiler entirely. <code>source</code>&rsquo;d
        scripts and interpreted scripts follow the same path: compile once, cache, execute from bytecode
        forever. This has <span class="highlight">never been achieved in a Unix shell</span>.</p>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x00]</span> THE COMPILATION PIPELINE</h2>

        <p>Every path through zshrs ends at the same place: fusevm bytecode execution.</p>

        <div class="diagram">
  ┌─────────────────────────────────────────────────────────────────┐
  │                    THREE EXECUTION PATHS                        │
  │                                                                 │
  │  ┌─────────────┐   Interactive command line                     │
  │  │  REPL Input  │──► Parser ──► ShellCompiler ──► fusevm::Op   │
  │  └─────────────┘                                    │           │
  │                                                     ▼           │
  │  ┌─────────────┐   Shell script / source file      VM::run()   │
  │  │ Script File  │──► Parser ──► ShellCompiler ──►   │           │
  │  └─────────────┘         │                          │           │
  │                          └──► rkyv image  ──────────┘           │
  │                               (cached on first compile)         │
  │                                                                 │
  │  ┌─────────────┐   Autoload function (compinit)                 │
  │  │ rkyv image  │──► mmap zero-copy archive ──► fusevm::Chunk ──►│
  │  │  shard      │   (no lexer, no parser,      VM::run()        │
  │  └─────────────┘    no compiler — microseconds)                 │
  └─────────────────────────────────────────────────────────────────┘
        </div>

        <table class="arch-table">
          <tr><th>Path</th><th>Lex</th><th>Parse</th><th>Compile</th><th>Execute</th><th>Cache</th></tr>
          <tr><td>Interactive command</td><td>Yes</td><td>Yes</td><td>Yes</td><td>fusevm</td><td>No (ephemeral)</td></tr>
          <tr><td>Script file (first run)</td><td>Yes</td><td>Yes</td><td>Yes</td><td>fusevm</td><td>Yes &rarr; rkyv</td></tr>
          <tr><td>Script file (cached)</td><td><span class="highlight">No</span></td><td><span class="highlight">No</span></td><td><span class="highlight">No</span></td><td>fusevm</td><td>Hit &rarr; deserialize</td></tr>
          <tr><td>Autoload function (cached)</td><td><span class="highlight">No</span></td><td><span class="highlight">No</span></td><td><span class="highlight">No</span></td><td>fusevm</td><td>Hit &rarr; deserialize</td></tr>
          <tr><td>Plugin source (cached)</td><td><span class="highlight">No</span></td><td><span class="highlight">No</span></td><td><span class="highlight">No</span></td><td>fusevm</td><td>Delta replay &rarr; &micro;s</td></tr>
        </table>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x01]</span> ARCHITECTURE</h2>

        <div class="diagram">
                         zshrs Architecture

  ┌─────────────────────────────────────────────────────┐
  │                    REPL / ZLE                        │
  │   reedline + syntax highlighting + autosuggestions   │
  └──────────────────────┬──────────────────────────────┘
                         │
  ┌──────────────────────▼──────────────────────────────┐
  │              ShellExecutor (19K lines)               │
  │   parser ─► compiler ─► fusevm bytecode dispatch     │
  │   180+ builtins │ AOP intercept │ trap/signal        │
  └──────┬─────────┬─────────┬─────────┬────────────────┘
         │         │         │         │
  ┌──────▼───┐ ┌───▼────┐ ┌─▼──────┐ ┌▼──────────────┐
  │ Worker   │ │ rkyv   │ │ fusevm │ │ compsys       │
  │ Pool     │ │ images │ │ VM     │ │ completion    │
  │ [2-18]   │ │ +      │ │        │ │ engine        │
  │ threads  │ │catalog │ │ Op enum│ │               │
  │          │ │ .db    │ │ fused  │ │ MenuState     │
  │ glob     │ │(query) │ │ super- │ │ MenuKeymap    │
  │ rehash   │ │bytecode│ │ instr  │ │ FTS5 mirror   │
  │ compinit │ │mmap'd  │ │ JIT ►  │ │               │
  │ history  │ │ shards │ │Cranelft│ │               │
  └──────────┘ └────────┘ └────────┘ └───────────────┘
        </div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x01]</span> ANTI-FORK ARCHITECTURE</h2>

        <p>Every fork is a full process copy. On macOS, <code>fork()</code> costs 2-5ms
        including exec + ld.so + libc init. zsh forks for <em>every</em>
        <code>$(...)</code>, <code>&lt;(...)</code>, <code>cat</code>, <code>grep</code>, subshell, and completion.
        zshrs forks for <em>none</em> of them.</p>

        <table class="arch-table">
          <tr><th>Operation</th><th>zsh</th><th>zshrs</th><th>Speedup</th></tr>
          <tr><td><code>cat file</code></td><td>fork + exec /bin/cat</td><td><span class="highlight">Builtin</span> &mdash; zero fork</td><td>2000-5000x</td></tr>
          <tr><td><code>head</code>/<code>tail</code>/<code>wc</code></td><td>fork + exec</td><td><span class="highlight">Builtin</span> &mdash; zero fork</td><td>2000-5000x</td></tr>
          <tr><td><code>sort</code>/<code>find</code>/<code>uniq</code></td><td>fork + exec</td><td><span class="highlight">Builtin</span> &mdash; zero fork</td><td>2000-5000x</td></tr>
          <tr><td><code>date</code>/<code>hostname</code>/<code>uname</code></td><td>fork + exec</td><td><span class="highlight">Direct syscall</span></td><td>3000-8000x</td></tr>
          <tr><td><code>sleep</code>/<code>mktemp</code>/<code>touch</code></td><td>fork + exec</td><td><span class="highlight">Builtin</span> &mdash; zero fork</td><td>2000-5000x</td></tr>
          <tr><td><code>xattr</code> operations</td><td>fork + exec xattr</td><td><span class="highlight">Direct syscall</span></td><td>2000-5000x</td></tr>
          <tr><td><code>pmap</code>/<code>pgrep</code>/<code>peach</code></td><td>fork N times to sh -c</td><td><span class="highlight">VM execution</span> &mdash; zero fork</td><td>Nx</td></tr>
          <tr><td><code>$(cmd)</code></td><td>fork + pipe + exec</td><td>In-process stdout capture via <code>dup2</code></td><td>&mdash;</td></tr>
          <tr><td><code>&lt;(cmd)</code> / <code>&gt;(cmd)</code></td><td>fork + FIFO</td><td>Worker pool thread + FIFO</td><td>&mdash;</td></tr>
          <tr><td>Glob <code>**/*.rs</code></td><td>Single-threaded <code>opendir</code></td><td>Parallel <code>walkdir</code> per-subdir on pool</td><td>&mdash;</td></tr>
          <tr><td><code>rehash</code></td><td>Serial <code>readdir</code> per PATH dir</td><td>Parallel scan across pool</td><td>&mdash;</td></tr>
          <tr><td>Autoload function</td><td>Read file + parse every time</td><td>Zero-copy mmap of rkyv-archived bytecode (&micro;s)</td><td>100x</td></tr>
        </table>

        <h3>Coreutils Builtins (23 commands, zero fork)</h3>
        <div class="code-block">cat  head  tail  wc  sort  find  uniq  cut  tr  seq  rev  tee
basename  dirname  touch  realpath  sleep  whoami  id  hostname
uname  date  mktemp</div>
        <p>Every invocation of these commands is <span class="highlight">2000-5000x faster</span> than forking to the external binary.</p>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x02]</span> WORKER THREAD POOL</h2>

        <p>Persistent pool of warm threads. Bounded crossbeam channel with backpressure.
        Panic recovery keeps workers alive. Task cancellation on Ctrl-C. Instant shutdown on exit.</p>

        <div class="code-block"><span class="comment"># ~/.config/zshrs/config.toml</span>
[worker_pool]
<span class="var">size</span> = <span class="string">8</span>            <span class="comment"># 0 = auto (num_cpus clamped [2, 18])</span>

[completion]
<span class="var">bytecode_cache</span> = <span class="keyword">true</span>  <span class="comment"># compile autoload functions to fusevm bytecodes</span>

[history]
<span class="var">async_writes</span> = <span class="keyword">true</span> <span class="comment"># write history on worker pool</span>

[glob]
<span class="var">parallel_threshold</span> = <span class="string">32</span>   <span class="comment"># min files before parallel metadata prefetch</span>
<span class="var">recursive_parallel</span> = <span class="keyword">true</span> <span class="comment"># fan out **/ across worker pool</span></div>

        <p>Tasks shipped to the pool:</p>
        <div class="cat-grid">
          <div class="cat-card"><h4>compinit</h4><p>Background fpath scan + bytecode compilation of 16K+ functions</p></div>
          <div class="cat-card"><h4>Process Sub</h4><p><code>&lt;(cmd)</code> and <code>&gt;(cmd)</code> on pool threads instead of fork</p></div>
          <div class="cat-card"><h4>Parallel Glob</h4><p><code>**/</code> recursive walk split per-subdir across pool</p></div>
          <div class="cat-card"><h4>Metadata Prefetch</h4><p>Glob qualifiers: one parallel <code>stat</code> batch, zero syscalls after</p></div>
          <div class="cat-card"><h4>PATH Rehash</h4><p>Parallel <code>readdir</code> across every PATH directory</p></div>
          <div class="cat-card"><h4>History Writes</h4><p>Daemon-side writes via IPC &mdash; prompt never waits, zero client SQLite handle</p></div>
        </div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x03]</span> AOP INTERCEPT</h2>

        <p>The first shell ever with aspect-oriented programming. Hook <span class="highlight">before</span>,
        <span class="highlight">after</span>, or <span class="highlight">around</span> any command or function
        &mdash; at machine code speed, no fork. One primitive that replaces <code>defer</code>,
        <code>profile</code>, <code>memo</code>, <code>retry</code>, and <code>timeout</code>.</p>

        <div class="code-block"><span class="comment"># Before &mdash; log every git command</span>
<span class="keyword">intercept</span> before git { echo "[$(date)] git <span class="var">$INTERCEPT_ARGS</span>" >> ~/git.log }

<span class="comment"># After &mdash; show timing for completion functions</span>
<span class="keyword">intercept</span> after '_*' { echo "<span class="var">$INTERCEPT_NAME</span> took <span class="var">${INTERCEPT_MS}</span>ms" }

<span class="comment"># Around &mdash; memoize expensive function</span>
<span class="keyword">intercept</span> around expensive_func {
    local cache=/tmp/cache_<span class="var">${INTERCEPT_ARGS// /_}</span>
    if [[ -f <span class="var">$cache</span> ]]; then cat <span class="var">$cache</span>
    else <span class="keyword">intercept_proceed</span> | tee <span class="var">$cache</span>; fi
}

<span class="comment"># Around &mdash; retry with backoff</span>
<span class="keyword">intercept</span> around flaky_api {
    repeat 3; do <span class="keyword">intercept_proceed</span>; [[ $? == 0 ]] && break; sleep 1; done
}

<span class="comment"># Fat binary &mdash; stryke code at machine code speed</span>
<span class="keyword">intercept</span> after 'make *' { <span class="string">@pmaps { notify "done: $_" } @(slack email)</span> }</div>

        <p>Variables available in advice:</p>
        <table class="arch-table">
          <tr><th>Variable</th><th>Available</th><th>Description</th></tr>
          <tr><td><code>$INTERCEPT_NAME</code></td><td>all</td><td>Command name</td></tr>
          <tr><td><code>$INTERCEPT_ARGS</code></td><td>all</td><td>Arguments as space-separated string</td></tr>
          <tr><td><code>$INTERCEPT_CMD</code></td><td>all</td><td>Full command string</td></tr>
          <tr><td><code>$INTERCEPT_MS</code></td><td>after</td><td>Execution time in milliseconds (nanosecond source)</td></tr>
          <tr><td><code>$INTERCEPT_US</code></td><td>after</td><td>Execution time in microseconds</td></tr>
          <tr><td><code>$?</code></td><td>after</td><td>Exit status</td></tr>
        </table>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x04]</span> RKYV ZERO-COPY CACHE LAYER</h2>

        <p>Cached bytecode lives in <code>rkyv</code> archives mmap'd by clients &mdash; zero-copy
        deserialization, no allocator pressure on hot paths. The daemon owns all writes; clients
        only mmap. The single queryable mirror is <code>catalog.db</code> (SQLite) for
        <code>dbview</code> introspection &mdash; never touched on the hot path.</p>

        <div class="cat-grid">
          <div class="cat-card">
            <h4>images/{hash}-{slug}.rkyv</h4>
            <p>Per-source-root rkyv shards. Compiled bytecode for autoloads, plugins, sourced
            scripts. Daemon writes; clients mmap zero-copy. Validates with rkyv's bytecheck on first
            access; format-versioned for migration safety.</p>
          </div>
          <div class="cat-card">
            <h4>index.rkyv</h4>
            <p>Top-level shard index: source-root path &rarr; shard hash + mtime. Daemon rewrites
            on changes; clients mmap to resolve which shard to load.</p>
          </div>
          <div class="cat-card">
            <h4>catalog.db (SQLite mirror)</h4>
            <p>Daemon-hydrated FTS5-indexed mirror of all rkyv contents. Used ONLY by
            <code>dbview</code> and <code>zcache</code> introspection &mdash; never read on the
            hot path. Clients have ZERO SQLite handles. <code>history.db</code> sits next to it.</p>
          </div>
        </div>

        <p>Browse caches without SQL:</p>
        <div class="code-block"><span class="keyword">dbview</span>                      <span class="comment"># list all tables + row counts (hits catalog.db)</span>
<span class="keyword">dbview</span> autoloads             <span class="comment"># dump autoloads: name, body size, ast size</span>
<span class="keyword">dbview</span> autoloads _git        <span class="comment"># single row: source, body, ast status, preview</span>
<span class="keyword">dbview</span> comps git             <span class="comment"># search comps for "git"</span>
<span class="keyword">dbview</span> executables rustc     <span class="comment"># search PATH cache</span>
<span class="keyword">dbview</span> history docker        <span class="comment"># search history</span>
<span class="keyword">zcache</span> rebuild               <span class="comment"># force daemon to recompile every shard</span>
<span class="keyword">zcache</span> verify                <span class="comment"># bytecheck every rkyv archive</span></div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x05]</span> BYTECODE CACHING</h2>

        <p>Every autoload function in fpath gets compiled to fusevm bytecodes during <code>compinit</code>.
        Compiled chunks are serialized via <code>rkyv</code> into per-source-root shards and written
        by the daemon. Subsequent loads mmap the archive zero-copy, validate via <code>bytecheck</code>,
        and dispatch directly &mdash; no lex, no parse, no compile, no allocator hit.</p>

        <div class="diagram">
First call to _git (daemon path):

  fpath/_git (source text)
       │
       ▼
  ShellParser::parse_script()     ~1ms
       │
       ▼
  ShellCompiler::compile()         ~0.5ms
       │
       ▼
  fusevm::Chunk (bytecodes)
       │
       ├──► VM::run()              native dispatch
       │
       └──► rkyv::to_bytes()       ~0.1ms (zero-copy archive)
            │
            ▼
       images/{hash}-fpath.rkyv    (daemon writes)

Every subsequent call (client path, ZERO daemon RTT):

  images/{hash}-fpath.rkyv         mmap (kernel page cache)
       │
       ▼
  rkyv::access::&lt;ArchivedChunk&gt;   ~0 µs (zero-copy access)
       │
       ▼
  fusevm::Chunk                    (no lexer, no parser, no compiler, no alloc)
       │
       ▼
  VM::run()                        native bytecode dispatch
        </div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x06]</span> FUSEVM BYTECODE TARGET</h2>

        <p><span class="highlight">100% lowered.</span> Every shell construct compiles to <code>fusevm</code>
        bytecodes &mdash; a language-agnostic VM with fused superinstructions and Cranelift JIT.
        The same VM that powers stryke (which beats LuaJIT on benchmarks). No tree-walking
        interpreter remains. Hot bytecodes compile to native x86-64 machine code.</p>

        <div class="diagram">
  stryke source ───► stryke compiler ──┐
                                        ├──► fusevm::Op ──► VM::run() ──► JIT ──► native
  zshrs source  ───► shell compiler  ──┘                     │
                                                              ├── Linear JIT: straight-line code
                                                              ├── Block JIT: loops, conditionals
                                                              └── Cranelift codegen → x86-64
        </div>

        <p>Shell constructs already lowered to fusevm bytecodes:</p>

        <div class="cat-grid">
          <div class="cat-card"><h4>Arithmetic</h4><p><code>$(( ))</code> &mdash; full precedence, ternary, assignment, hex/octal, bitwise</p></div>
          <div class="cat-card"><h4>Loops</h4><p><code>for</code>, <code>for(())</code>, <code>while</code>, <code>until</code>, <code>repeat</code></p></div>
          <div class="cat-card"><h4>Conditionals</h4><p><code>if/elif/else</code>, <code>case</code>, <code>[[ ]]</code> with all file tests and comparisons</p></div>
          <div class="cat-card"><h4>Commands</h4><p><code>Exec</code>, <code>ExecBg</code>, pipelines, redirects, here-docs, here-strings</p></div>
          <div class="cat-card"><h4>Functions</h4><p>Definition, <code>Call</code>/<code>Return</code>, <code>PushFrame</code>/<code>PopFrame</code></p></div>
          <div class="cat-card"><h4>Fused Ops</h4><p><code>AccumSumLoop</code>, <code>SlotIncLtIntJumpBack</code>, <code>PreIncSlotVoid</code> &mdash; single-dispatch loop execution</p></div>
        </div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x07]</span> EXCLUSIVE BUILTINS</h2>

        <h3>Parallel Primitives (VM-executed, zero fork)</h3>
        <table class="arch-table">
          <tr><th>Builtin</th><th>Description</th></tr>
          <tr><td><code>async</code> / <code>await</code></td><td>Ship work to pool, collect result</td></tr>
          <tr><td><code>pmap</code></td><td>Parallel map with ordered output &mdash; compiles to bytecode, runs on VM, zero forks</td></tr>
          <tr><td><code>pgrep</code></td><td>Parallel filter &mdash; compiles to bytecode, runs on VM, zero forks</td></tr>
          <tr><td><code>peach</code></td><td>Parallel for-each, unordered &mdash; compiles to bytecode, runs on VM, zero forks</td></tr>
          <tr><td><code>barrier</code></td><td>Run all commands in parallel, wait for all</td></tr>
        </table>

        <h3>AOP / Debugging</h3>
        <table class="arch-table">
          <tr><th>Builtin</th><th>Description</th></tr>
          <tr><td><code>intercept</code></td><td>AOP before/after/around advice on any command. Glob pattern matching. Nanosecond timing.</td></tr>
          <tr><td><code>intercept_proceed</code></td><td>Call original command from around advice.</td></tr>
          <tr><td><code>doctor</code></td><td>Full diagnostic: worker pool metrics, cache stats, bytecode coverage, startup health.</td></tr>
          <tr><td><code>dbview</code></td><td>Browse the daemon's catalog.db mirror without SQL. Tables: autoloads, comps, executables, history, plugins. Hot path uses rkyv mmap directly.</td></tr>
          <tr><td><code>profile</code></td><td>In-process command profiling. Nanosecond accuracy. No fork overhead in measurement.</td></tr>
        </table>

        <h3>Coreutils (Anti-Fork)</h3>
        <table class="arch-table">
          <tr><th>Builtin</th><th>Description</th><th>Speedup vs fork</th></tr>
          <tr><td><code>cat</code></td><td>Concatenate files &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>head</code> / <code>tail</code></td><td>First/last N lines &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>wc</code></td><td>Line/word/char count &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>sort</code> / <code>uniq</code></td><td>Sort and dedupe &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>find</code></td><td>Walk directories &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>cut</code> / <code>tr</code> / <code>rev</code></td><td>Text manipulation &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>seq</code> / <code>tee</code></td><td>Number sequences, copy stdin &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>date</code></td><td>Current date/time &mdash; direct strftime</td><td>3000-8000x</td></tr>
          <tr><td><code>sleep</code></td><td>Delay &mdash; std::thread::sleep</td><td>2000-5000x</td></tr>
          <tr><td><code>mktemp</code></td><td>Create temp file/dir &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>hostname</code> / <code>uname</code></td><td>System info &mdash; direct syscall</td><td>3000-8000x</td></tr>
          <tr><td><code>id</code> / <code>whoami</code></td><td>User info &mdash; direct syscall</td><td>3000-8000x</td></tr>
          <tr><td><code>touch</code> / <code>realpath</code></td><td>File ops &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>basename</code> / <code>dirname</code></td><td>Path manipulation &mdash; no fork</td><td>2000-5000x</td></tr>
          <tr><td><code>zgetattr</code> / <code>zsetattr</code></td><td>xattr ops &mdash; direct syscall</td><td>2000-5000x</td></tr>
        </table>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x07b]</span> SHELL LANGUAGE FEATURES</h2>

        <p>Every shell construct compiles to fusevm bytecode &mdash; no tree-walker
        dispatch lives in zshrs. The categories below are summaries; the
        <a href="reference.html">full reference</a> documents each entry with a runnable
        code example.</p>

        <div class="cat-grid">
          <div class="cat-card">
            <h4>Control Flow</h4>
            <p><code>if</code>, <code>while</code>, <code>until</code>, <code>for</code>, <code>for ((;;))</code>,
            <code>case</code>, <code>select</code>, <code>coproc</code>, <code>break</code>, <code>continue</code>,
            <code>return</code>, <code>;</code>/<code>&amp;&amp;</code>/<code>||</code>/<code>&amp;</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Indexed Arrays</h4>
            <p><code>arr=(a b c)</code>, <code>arr+=(d)</code>, <code>${arr[1]}</code> (1-based),
            <code>${arr[-1]}</code>, <code>${arr[@]}</code> (argv splice), <code>${#arr[@]}</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Associative Arrays</h4>
            <p><code>typeset -A m</code>, <code>m[key]=val</code>, <code>${m[key]}</code>,
            <code>${(k)m}</code> (keys), <code>${(v)m}</code> (values).</p>
          </div>
          <div class="cat-card">
            <h4>Parameter Expansion</h4>
            <p><code>${var:-x}</code>, <code>${var:=x}</code>, <code>${var:?msg}</code>,
            <code>${var:+x}</code>, <code>${#var}</code>, <code>${var:o:l}</code>, <code>${var#pat}</code>,
            <code>${var/pat/repl}</code>, <code>${var:u}</code>/<code>:l</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Zsh Flags</h4>
            <p><code>(L)</code>/<code>(U)</code> case, <code>(j: :)</code> join,
            <code>(s. .)</code> split, <code>(f)</code> newline-split, <code>(o)</code>/<code>(O)</code> sort,
            <code>(P)</code> indirect, <code>(@)</code> force-array, <code>(k)</code>/<code>(v)</code>,
            <code>(#)</code>. Stack: <code>(jL)</code>, <code>(s:,:U)</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Redirects &amp; Pipelines</h4>
            <p><code>&gt;</code> <code>&gt;&gt;</code> <code>&lt;</code> <code>&lt;&lt;EOF</code> <code>&lt;&lt;&lt;</code>
            <code>2&gt;&amp;1</code> <code>&amp;&gt;</code> <code>&amp;&gt;&gt;</code> <code>|</code>
            <code>|&amp;</code> <code>!</code> <code>&lt;(cmd)</code> <code>&gt;(cmd)</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Background &amp; Async</h4>
            <p><code>cmd &amp;</code> (fork + setsid), <code>$!</code>, <code>wait</code>,
            <code>jobs</code>/<code>fg</code>/<code>bg</code>; <code>async</code>/<code>await</code>
            (worker pool, no fork).</p>
          </div>
          <div class="cat-card">
            <h4>Coprocesses</h4>
            <p><code>coproc { body }</code> creates two pipes, forks, registers
            <code>$COPROC=[read_fd, write_fd]</code>. Read from <code>/dev/fd/${COPROC[1]}</code>,
            write to <code>/dev/fd/${COPROC[2]}</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Eval &amp; Indirect Dispatch</h4>
            <p><code>eval 'echo $x'</code> defers expansion correctly (single-quoted specials honored).
            <code>cmd=ls; $cmd</code> routes through host intercepts.</p>
          </div>
          <div class="cat-card">
            <h4>Arithmetic</h4>
            <p><code>$((expr))</code>, <code>(( cond ))</code>, <code>let</code>; full integer expression
            grammar compiled inline (no runtime parser).</p>
          </div>
          <div class="cat-card">
            <h4>Glob &amp; Brace</h4>
            <p><code>*.rs</code>, <code>**/*.rs</code> (parallel walk), <code>{a,b,c}</code>,
            <code>{1..10}</code>, glob qualifiers <code>*(.x)</code> <code>*(N)</code>.</p>
          </div>
          <div class="cat-card">
            <h4>Tilde &amp; Cmd-Sub</h4>
            <p><code>~</code>, <code>~user</code>, <code>~+</code>/<code>~-</code>; <code>$(cmd)</code>
            (in-process pipe-capture), backticks.</p>
          </div>
        </div>

        <p style="margin-top: 1rem; font-size: 12px; color: var(--text-muted);">
        For the complete catalog &mdash; every supported builtin, keyword, parameter-expansion form,
        ZshFlag, AOP primitive, parallel primitive, and anti-fork coreutils replacement with a code
        example for each &mdash; see the <a href="reference.html" style="color: var(--cyan); font-weight: 700;">FULL REFERENCE</a>.</p>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x08]</span> INSTALL</h2>

        <div class="code-block"><span class="comment"># Lean build &mdash; pure shell, all features, no stryke</span>
cargo install --path zsh

<span class="comment"># Fat build &mdash; shell + stryke runtime (@ prefix, AOP stryke advice)</span>
cargo install strykelang

<span class="comment"># From source</span>
git clone https://github.com/MenkeTechnologies/strykelang
cd strykelang
cargo build --release -p zsh    <span class="comment"># target/release/zshrs</span></div>

        <div class="code-block"><span class="comment"># Set as default shell</span>
sudo sh -c 'echo /Users/$(whoami)/.cargo/bin/zshrs >> /etc/shells'
chsh -s /Users/$(whoami)/.cargo/bin/zshrs

<span class="comment"># Tab completion for zshrs itself</span>
cp completions/_zshrs /usr/local/share/zsh/site-functions/</div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0x09]</span> DIAGNOSTICS</h2>

        <div class="code-block"><span class="comment"># Full health check</span>
zshrs --doctor

<span class="comment"># In-session diagnostics</span>
doctor

<span class="comment"># Browse cache</span>
dbview
dbview autoloads _git

<span class="comment"># Profile a command</span>
profile 'compinit'
profile -s 'for i in {1..1000}; do echo $i > /dev/null; done'

<span class="comment"># Show intercepts</span>
intercept list</div>
      </section>

      <!-- ════════════════════════════════════════════════════════════ -->
      <section class="tutorial-section">
        <h2><span class="section-num">[0xFF]</span> THE PHILOSOPHY</h2>

        <p>Shells haven't fundamentally improved since the 1990s. bash is a GNU rewrite of
        the Bourne shell from 1979. zsh added features but kept the fork-based C architecture.
        fish focused on UX and abandoned POSIX. nushell reinvented the data model but lost compatibility.</p>

        <p>zshrs takes a different approach: keep everything that makes zsh powerful &mdash;
        glob qualifiers, parameter expansion flags, the completion system, ZLE, zstyle, modules &mdash;
        and replace the runtime with modern systems engineering. Rust instead of C. Thread pool
        instead of fork. <code>rkyv</code> mmap'd zero-copy archives instead of flat files. Bytecode VM
        instead of tree-walker. AOP instead of monkey-patching.</p>

        <p>The result is the first shell that gets <em>faster</em> as you add more plugins,
        because the plugin cache means each plugin is only parsed once. The first shell where
        <code>**/*.rs</code> scales with your CPU count. The first shell where you can
        intercept any command with nanosecond-accurate timing and zero overhead.</p>

        <p>The result is the first shell where every command &mdash; interactive or scripted &mdash;
        compiles to bytecodes and executes on a VM with fused superinstructions. The first
        shell where autoload functions load from pre-compiled bytecodes in microseconds. The first
        shell where <code>source ~/.zshrc</code> can skip the lexer, parser, and compiler entirely
        because the bytecodes are mmap'd zero-copy from <code>rkyv</code> archives the daemon
        already validated.</p>

        <p>Since the Bourne shell at Bell Labs in 1970, through csh, ksh, bash, zsh, and fish &mdash;
        every Unix shell has been an interpreter. zshrs is the first to be a compiler. Shell scripts
        at machine code speed. Achieved in alpha.</p>

        <p class="motto">THE FIRST COMPILED UNIX SHELL. THE MOST POWERFUL SHELL EVER CREATED.</p>
      </section>

    </main>

    <footer style="border-top: 1px solid var(--border); padding: 1rem 1.5rem; text-align: center; color: var(--text-muted); font-size: 11px;">
      &copy; 2026 MenkeTechnologies &middot; MIT License &middot;
      <a href="https://github.com/MenkeTechnologies/strykelang" style="color: var(--cyan);">GitHub</a>
    </footer>
  </div>

  <script src="hud-theme.js"></script>
</body>
</html>