oxdock-parser 0.17.0-alpha

Parser and AST definitions for the OxDock DSL.
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
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
<!-- GENERATED by docs-gen from oxdock-parser metadata. Do not edit by hand. -->
## Command Reference

See the [changelog](https://github.com/jzombie/rust-oxdock/blob/main/CHANGELOG.md) for what changed in each release.

| Command | Syntax |
| --- | --- |
| [`WORKDIR`]#workdir | `WORKDIR <path>` |
| [`WORKSPACE`]#workspace | `WORKSPACE (SNAPSHOT\|LOCAL, case-insensitive)` |
| [`ENV`]#env | `ENV KEY=value` |
| [`INHERIT_ENV`]#inherit_env | `INHERIT_ENV [<key>, ...]` |
| [`ECHO`]#echo | `ECHO <message>` |
| [`RUN`]#run | `RUN <command...> \| RUN ["exe", "arg", ...]` |
| [`COPY`]#copy | `COPY [--from-current-workspace] <from> <to>` |
| [`COPY_GIT`]#copy_git | `COPY_GIT [--include-dirty] <rev> <src> <dst>` |
| [`SYMLINK`]#symlink | `SYMLINK <from> <to>` |
| [`MKDIR`]#mkdir | `MKDIR <path>` |
| [`LS`]#ls | `LS [<path>]` |
| [`CWD`]#cwd | `CWD` |
| [`READ`]#read | `READ [<path>]` |
| [`READ_LINE`]#read_line | `READ_LINE $var` |
| [`WRITE`]#write | `WRITE <path> [<contents>]` |
| [`APPEND`]#append | `APPEND <path> [<contents>]` |
| [`EXPAND`]#expand | `EXPAND [<path>] [<KEY=val> ...]` |
| [`ASSERT_EQ`]#assert_eq | `ASSERT_EQ <actual> <expected> \| ASSERT_EQ --hash <sha256> <actual>` |
| [`ASSERT_CONTAINS`]#assert_contains | `ASSERT_CONTAINS <haystack> <needle>` |
| [`HASH_SHA256`]#hash_sha256 | `HASH_SHA256 <path>` |
| [`EXIT`]#exit | `EXIT <code>` |
| [`SLEEP`]#sleep | `SLEEP <duration>` |
| [`LIST_APPEND`]#list_append | `LIST_APPEND $list <item>` |
| [`WITH_IO`]#with_io | `WITH_IO [<stream>[=$var], ...] <command> \| WITH_IO [bindings] { <commands> }` |
| [`FOR`]#for | `FOR $item: TYPE IN <expr> { <commands> } \| FOR $key: STRING, $value: TYPE IN <expr> { <commands> }` |
| [`IF`]#if | `IF <expr> { <commands> } [ELSE IF <expr> { <commands> } ...] [ELSE { <commands> }]` |
| [`LET`]#let | `LET $var: TYPE = <expr> \| LET $p: PIPE \| LET $var: TYPE = ASYNC { <commands> } \| LET $var: TYPE = <command> \| LET $var: TYPE = AWAIT $task \| LET $var: TYPE = { <commands> }` |
| [`MUTATION`]#mutation | `$var = <expr>` |
| [`ASYNC`]#async | `ASYNC <command...> \| ASYNC { <commands> } \| LET $var: HANDLE = ASYNC { <commands> }` |
| [`AWAIT`]#await | `AWAIT $var \| LET $out: STRING = AWAIT $var` |
| [`CANCEL`]#cancel | `CANCEL $var` |
| [`TIMEOUT`]#timeout | `TIMEOUT <duration> <command...> \| TIMEOUT <duration> { <commands> } \| TIMEOUT <duration> AWAIT $var` |
| [`FUNC`]#func | `FUNC NAME([$param: TYPE, ...]) { <commands> }` |
| [`RETURN`]#return | `RETURN [<expr>]` |
| [`WHILE`]#while | `WHILE <bool-expr> { <commands> }` |
| [`BREAK`]#break | `BREAK` |
| [`CONTINUE`]#continue | `CONTINUE` |
| [`IMPORT`]#import | `IMPORT [<module>, ...] \| IMPORT <module>` |

### WITH_IO

Reroute standard streams.

**Syntax:** `WITH_IO [<stream>[=$var], ...] <command> | WITH_IO [bindings] { <commands> }`

Reroutes the standard streams of the next command or, in block form,
of every enclosed command.

Bindings map streams (`stdin`, `stdout`, `stderr`) to a PIPE-typed
variable (`stdout=$p`, `stdin=$p`), resolved from the variable
when the step runs. Both stdout and stderr pipes capture output
the same way. Declare the handle first with `LET $p: PIPE`.

Pipes hold bytes in memory and spill to a temp file above 8 MiB, so a
producer can finish before the consumer starts.

If WITH_IO wraps an ASYNC block whose body is a single RUN, guarded or
not, the pipe is a zero copy OS kernel pipe instead: pair it with a
consumer that runs while the producer is alive, since output past the
64 KiB kernel buffer stalls until drained. That promotion never crosses
a function boundary: pipes created, bound, or passed by variable inside FUNC
bodies are always script pipes, even when the surrounding task would
otherwise promote.

A second producer or consumer on a live handle is an explicit
error. A handle bound as output can later feed another
command's `stdin`, connecting commands without touching the
terminal. Binding `stdout` and `stderr` to the same live
handle fails deterministically. Merge streams in shell
via `2>&1` instead.

Nested blocks stack defaults; inline bindings override inherited ones for
their command only; closing a block restores previous wiring.


**Examples:**

**Example: with_io block**

```oxdock
LET $log: PIPE
WITH_IO [stdout=$log] {
  ECHO first
  ECHO second
}
WITH_IO [stdin=$log] WRITE captured.txt
```

**Example: variable pipe binding**

```oxdock
# Declare the pipe first: `LET $p: PIPE` mints a fresh
# backend without touching a stream. A plain string here
# would be a TypeMismatch.
LET $p: PIPE
WITH_IO [stdout=$p] ECHO hello
WITH_IO [stdin=$p] READ_LINE $line
ASSERT_EQ $line "hello"
```


### FOR

Iterate over a list or map.

**Syntax:** `FOR $item: TYPE IN <expr> { <commands> } | FOR $key: STRING, $value: TYPE IN <expr> { <commands> }`

The loop variable receives each element (lists) or value (maps); with
two variables, the first receives the key.

Loop variables are declared with explicit types and scoped per iteration;
they do not leak outward. The body may be a braced block
or a single-line `{ ... }` command.

`GLOB("...")` patterns must be quoted (`*` is not a bare word, so
`GLOB(*)` is a parse error); GLOB returns a root-relative sorted list,
empty when nothing matches, and rejects `..` escapes.


**Examples:**

**Example: for loop**

```oxdock
LET $items: LIST = ["a", "b"]
FOR $item: STRING IN $items {
  ECHO $item
}

LET $map: MAP = {"x": 1}
FOR $k: STRING, $v: INT IN $map {
  ECHO "$k=$v"
}
```

**Example: expand every match**

```oxdock
# single-line body; $x is a template path, WHO an override
WRITE a.txt "hi \{{ env:WHO }}!"
IMPORT [STD]
FOR $x: STRING IN GLOB("*.txt") { EXPAND $x WHO=World }
ASSERT_CONTAINS stdout "hi World!"
```


### IF

Conditional execution.

**Syntax:** `IF <expr> { <commands> } [ELSE IF <expr> { <commands> } ...] [ELSE { <commands> }]`

The condition is evaluated as a boolean expression.

Prefix `!` negates (`IF !false`); `&&` binds tighter than
`||`, and both short-circuit, so `IF true || $missing`
never evaluates the right side. Only Bool values are
accepted as conditions.


**Examples:**

**Example: if else**

```oxdock
IMPORT [STD]
IF true {
  WRITE yes.txt taken
} ELSE {
  WRITE yes.txt skipped
}

IF false {
  WRITE skipped.txt no
} ELSE IF true {
  WRITE fallback.txt taken
}

# !false evaluates to true, so this branch runs.
IF !false {
  WRITE negated.txt taken
}
LET $yes_body: STRING = READ yes.txt
LET $fallback_body: STRING = READ fallback.txt
LET $negated_body: STRING = READ negated.txt
ASSERT_EQ $yes_body "taken"
ASSERT_EQ $fallback_body "taken"
ASSERT_EQ $negated_body "taken"
LET $t: STRING = PATH_TYPE("skipped.txt")
ASSERT_EQ $t "absent"
```

**Example: logical condition composition**

```oxdock
IMPORT [STD]
LET $role: STRING = "admin"
LET $level: INT = 3
# || is true when either side holds; && needs both.
IF $role == "owner" || $level >= 5 {
    WRITE unexpected.txt no
} ELSE {
    WRITE fallback.txt or-false
}
IF $role == "admin" || $level >= 5 {
    WRITE chosen.txt or-true
}
IF $role == "admin" && $level >= 5 {
    WRITE unexpected-too.txt no
} ELSE {
    WRITE and.txt and-false
}
LET $fb: STRING = READ fallback.txt
LET $ch: STRING = READ chosen.txt
LET $an: STRING = READ and.txt
ASSERT_EQ $fb "or-false"
ASSERT_EQ $ch "or-true"
ASSERT_EQ $an "and-false"
LET $t1: STRING = PATH_TYPE("unexpected.txt")
LET $t2: STRING = PATH_TYPE("unexpected-too.txt")
ASSERT_EQ $t1 "absent"
ASSERT_EQ $t2 "absent"
```


### LET

Bind script-local variables.

**Syntax:** `LET $var: TYPE = <expr> | LET $p: PIPE | LET $var: TYPE = ASYNC { <commands> } | LET $var: TYPE = <command> | LET $var: TYPE = AWAIT $task | LET $var: TYPE = { <commands> }`

Declares a script-local variable with an explicit type (STRING, INT,
FLOAT, BOOL, PIPE, LIST, MAP, HANDLE, DURATION, PATH). Duplicate LET
in the same scope frame is a redeclaration error; mutate with
`$var = <expr>`.

Variables are usable in templates (`{{ $var }}`), guards, and
expressions. With `ASYNC`, spawns a background task and stores its
handle (see ASYNC). The `$` sigil on the name is mandatory.

No hoisting: a variable exists only after its LET runs, in
execution order. Reading `$var` before its LET (or after the
block that declared it exits) fails with
`undefined variable $var`. Scopes are a stack of frames and
resolution walks innermost outward, so nothing pre-declares
names. Function bodies read outer variables through the same
walk, but their own LETs never leak out (see FUNC).

The right-hand side is always an expression — literals, lists, maps,
arithmetic (`+ - * /` with `*`/`/` binding tighter, unary `-`,
parentheses), comparisons (`< <= > >=` binding tighter than
`== !=`), logical `&&` (tighter) and `||` with short-circuit,
`!` negation, `env:KEY` reads, `INSPECT($var)` snapshots,
`GLOB("*.md")`, `INT(x)` / `FLOAT(x)` conversions — never a
`{{ ... }}` template; interpolation happens in string values,
not here.
The one exception is pipes: `LET $p: PIPE` with no `=`
and no initializer mints a fresh anonymous backend,
lazily materialized at first binding, so two declarations
never share a channel.

Numbers are numeric literals: `42` binds `INT`, `3.14` binds
`FLOAT`. `Int x Int` stays `INT` (checked, integer division,
so `7 / 2` is `3`); any `Float` operand promotes to `FLOAT`.
Division by zero, overflow, and non-finite results are errors.
Both numeric sides compare numerically (`1 == 1.0` is true);
otherwise `==`/`!=` compare rendered strings and ordering on
non-numerics is a Type Error. Constant subtrees fold at parse
time and dynamic arithmetic compiles to flat RPN with
identical semantics.

Float equality is exact with no epsilon. Floats store decimals
in binary, so a value is exact only when its reduced fraction
has a power-of-2 denominator: 0.5 (1/2), 0.25 (1/4), 0.75
(3/4) are exact, while 0.1 (1/10), 0.2 (1/5), 0.3 (3/10)
repeat forever in binary (like 1/3 in decimal) and truncate,
so `0.1 + 0.2 == 0.3` is false (the sum is
`0.30000000000000004`). Rule of thumb: endings .5, .25, .75,
.125, .625, .875 are exact; .1, .2, .3 and similar are
approximations. Bound approximations instead of comparing
them: `IF $sum > 0.299999 && $sum < 0.300001`.

Comparisons do not chain: `a < b < c` is a parse error, not
`(a < b) < c`. Chaining would compare a `BOOL` against a
number (a runtime Type Error in C-style parsing) or evaluate
the middle term twice (Python-style chaining), so the grammar
accepts exactly one comparison operator per level. Write the
conjunction explicitly: `$a < $b && $b < $c`. The same holds
for equality (`$a == $b == $c` is rejected).

Captured command output is a string, so convert before math:
`LET $total: INT = $total + INT($size_str)` (`INT` trims ASCII
whitespace; `FLOAT` accepts int strings and rejects
non-finite).

Bare words need no quotes: `LET $d: STRING = 30s` binds the same string
as quoted.

When the right-hand side is a synchronous command
(`LET $out: STRING = ECHO hi`), the command runs to completion and its
exact stdout bytes are captured into the variable as a string (no newline
stripping; commands with no stdout capture as `""`; non-UTF8 stdout is
an error). Combining capture with an explicit
`WITH_IO [stdout=$var]` is a parse error.

Coming from Bash, the capture line looks familiar but behaves
strictly:

| | Bash `output=$(...)` | OxDock `LET $out: STRING = ...` |
| --- | --- | --- |
| Trailing newlines | Stripped (all of them) | Preserved byte-exact |
| Variable type | Always an untyped string | Declared: STRING, INT, FLOAT, ... |
| Math on output | Implicit: `$((var + 1))` | Explicit: `INT($out) + 1` |
| Failing command | Continues with empty output unless `set -e` | Step fails immediately, binds nothing |

`LET $out: TYPE = AWAIT $var` binds the background task's
explicit `RETURN` value instead (tasks stream their stdout
live, so there is no output left to capture); a task that
succeeded without `RETURN` yields `INT` 0, like a process
exit status.

An inline block (`LET $var: TYPE = { <commands> }`) runs its
steps in a fresh scope and binds the nearest `RETURN` value,
like a zero-arg function body: fallthrough without `RETURN`
binds `""`, and `BREAK`/`CONTINUE` escaping the block are
errors. The block reads outer variables but its own LETs
never leak out. A `{k: v}` shape still parses as a map
literal; anything else in braces is a block.

The split is deliberate: synchronous commands capture
stdout because they run inline to completion on the same
thread; background tasks never capture stdout because
concurrent output has no well-defined value. Task results
travel only through `RETURN` (or `INT` 0 for void tasks).

`LET $e: STRING = env:FOO` reads the script environment into a plain
string.


**Examples:**

**Example: let**

```oxdock
LET $name: STRING = "world"
ECHO "hello, {{ $name }}"

LET $items: LIST = ["a", "b"]
LET $count: INT = 42
```

**Example: no hoisting**

```oxdock expect_error:"undefined variable"
# reading before the LET runs is an error, not an empty value
ECHO $too_early
LET $too_early: STRING = "too late"
```

**Expected error:** `undefined variable`

**Example: glob binding**

```oxdock
# the RHS is an expression: GLOB(...) runs and binds a list
WRITE a.txt "x"
IMPORT [STD]
LET $files: LIST = GLOB("*.txt")
FOR $f: STRING IN $files { ECHO $f }
ASSERT_CONTAINS stdout "a.txt"
```

**Example: scoped variable reverts**

```oxdock
# LET inside a braced block reverts when the block exits
LET $a: STRING = "outer"
[bool:true] {
    LET $a: STRING = "inner"
    WRITE inner.txt "{{ $a }}"
}
WRITE outer.txt "{{ $a }}"
LET $in_body: STRING = READ inner.txt
LET $out_body: STRING = READ outer.txt
ASSERT_EQ $in_body "inner"
ASSERT_EQ $out_body "outer"
```

**Example: capture command output**

```oxdock
LET $out: STRING = ECHO hi
ASSERT_EQ $out "hi\n"
```

**Example: inline block**

```oxdock
LET $who: STRING = "ada"
LET $res: STRING = {
    LET $loud: STRING = "{{ $who }}!"
    RETURN $loud
}
ASSERT_EQ $res "ada!"
# Any declared type works: the block value checks like any RHS.
LET $n: INT = {
    RETURN 40 + 2
}
ASSERT_EQ $n 42
```

**Example: arithmetic over captured output**

```oxdock
LET $size_str: STRING = ECHO 41
IMPORT [STD]
LET $total: INT = INT($size_str) + 1
LET $ratio: FLOAT = 1 + 2.5
# Int x Int stays INT: integer division truncates.
LET $half: INT = 7 / 2
ASSERT_EQ $total 42
ASSERT_EQ $ratio 3.5
ASSERT_EQ $half 3
```

**Example: float equality is exact**

```oxdock
# Binary fractions compare cleanly; decimal fractions may not:
# 0.1 + 0.2 is 0.30000000000000004, so == is false.
IMPORT [STD]
LET $exact: BOOL = 0.5 + 0.25 == 0.75
LET $decimal: BOOL = 0.1 + 0.2 == 0.3
IF $exact {
    WRITE exact.txt yes
}
IF $decimal {
    WRITE unexpected.txt no
}
LET $ok: STRING = READ exact.txt
ASSERT_EQ $ok "yes"
LET $t: STRING = PATH_TYPE("unexpected.txt")
ASSERT_EQ $t "absent"
```

**Example: bound inexact decimals**

```oxdock
# Never test inexact decimals for equality; bound them.
LET $sum: FLOAT = 0.1 + 0.2
IF $sum > 0.299999 && $sum < 0.300001 {
    WRITE bounded.txt yes
}
LET $ok: STRING = READ bounded.txt
ASSERT_EQ $ok "yes"
```

**Example: inspect a variable**

```oxdock
# INSPECT($var) snapshots a variable into a MAP: declared
# type plus live details (pipe backend stats here), so
# scripts can branch on engine state.
LET $p: PIPE
WITH_IO [stdout=$p] ECHO hello
LET $info: MAP = INSPECT($p)
IF $info.is_os_pipe {
    WRITE unexpected.txt "should be a script pipe"
}
ASSERT_EQ $info.type "PIPE"
```


### MUTATION

Mutate a declared variable.

**Syntax:** `$var = <expr>`

Reassigns an existing variable, converting the new value to
the type declared at LET time. The explicit annotation is
what authorizes string-to-number conversion here (`$n = "42"`
binds 42 for an INT); a non-numeric string is an error.
Expressions never convert: `"100" + 1` is a Type Error, use
`INT()` / `FLOAT()` to cross that boundary explicitly.

The leading `$` distinguishes mutation from `KEY=value` command
assignments. Assigning an undeclared variable or a mismatched type is
an error.

Mutation writes through to the scope where the variable was
declared, so it survives block exit: `LET $x` outside a block
followed by `$x = ...` inside still reads back the new value
afterwards, for every type. This is the counterpart to LET
shadowing, where `LET $x` *inside* the block declares a
separate inner variable that reverts on exit.


**Examples:**

**Example: mutate**

```oxdock
LET $count: INT = 1
$count = 2
ASSERT_EQ $count 2
```

**Example: convert before math**

```oxdock
# Captured output is a string: `"100" + 1` is a Type Error.
# Convert explicitly, then mutate with arithmetic.
LET $raw: STRING = ECHO 100
IMPORT [STD]
LET $n: INT = INT($raw)
$n = $n + 1
# The declared type also converts plain strings on assignment.
$n = "42"
# Same crossing for decimals via FLOAT().
LET $frac_str: STRING = ECHO 2.5
LET $f: FLOAT = FLOAT($frac_str) + 0.25
ASSERT_EQ $n 42
ASSERT_EQ $f 2.75
```


### ASYNC

Run steps in a background thread.

**Syntax:** `ASYNC <command...> | ASYNC { <commands> } | LET $var: HANDLE = ASYNC { <commands> }`

Runs a command or block of commands in a background thread with
subshell isolation.

Mutations (ENV, WORKDIR) stay within the block. With `LET`, stores a
task handle for `AWAIT`. Task output streams live to the parent
stdout; a task publishes a value with an explicit `RETURN`,
which `LET $out: TYPE = AWAIT $task` binds.


**Examples:**

**Example: async**

```oxdock
ASYNC ECHO "first"

ASYNC {
    ECHO "first"
    ECHO "second"
}
```

**Example: async task handle**

```oxdock
LET $task: HANDLE = ASYNC {
    ECHO "built"
}
AWAIT $task
```


### AWAIT

Join a background task.

**Syntax:** `AWAIT $var | LET $out: STRING = AWAIT $var`

Blocks until the named task completes. Propagates errors if the task failed.

Task output streams live during the run; joining binds nothing by
itself. `LET $out: TYPE = AWAIT $var` binds the task's explicit
`RETURN` value instead, or `INT` 0 when the task succeeded
without one (add `RETURN <expr>` to the task body to yield
a value).


**Examples:**

**Example: await**

```oxdock
LET $task: HANDLE = ASYNC ECHO "done"
AWAIT $task
```

**Example: await capture**

```oxdock
LET $task: HANDLE = ASYNC {
    ECHO "logged"
    RETURN "returned"
}
LET $out: STRING = AWAIT $task
ASSERT_EQ $out "returned"
```


### CANCEL

Synchronously cancel a background task.

**Syntax:** `CANCEL $var`

Kills the named background task spawned via LET $var: HANDLE = ASYNC ....

Blocking: returns only after the task thread has been joined and its OS
process reaped, so no residual filesystem or stream mutation follows. A
later AWAIT $var reports cancellation. Only named tasks can be cancelled.


**Examples:**

**Example: cancel**

```oxdock
LET $task: HANDLE = ASYNC SLEEP 30s
CANCEL $task
```


### TIMEOUT

Enforce an execution deadline.

**Syntax:** `TIMEOUT <duration> <command...> | TIMEOUT <duration> { <commands> } | TIMEOUT <duration> AWAIT $var`

Aborts the wrapped step or block with a deadline error if it exceeds the
duration (e.g. 500ms, 10s, 2m; a bare number means seconds).

A blocking foreground process is killed.


**Examples:**

**Example: timeout**

```oxdock
TIMEOUT 30s WRITE heartbeat.txt alive
```

**Example: timeout block**

```oxdock
TIMEOUT 30s {
    WRITE a.txt one
    WRITE b.txt two
}
```

**Example: timeout variable duration**

```oxdock
# durations resolve at runtime, so variables work too
LET $budget: DURATION = "30s"
TIMEOUT $budget WRITE heartbeat.txt alive
LET $beat: STRING = READ heartbeat.txt
ASSERT_EQ $beat "alive"
```


### FUNC

Define a user function.

**Syntax:** `FUNC NAME([$param: TYPE, ...]) { <commands> }`

Defines a user function with UPPERCASE name and explicitly typed
parameters.

Params bind by position, converting each argument to its
declared parameter type before the body runs.
Bodies run in a fresh variable scope; LETs inside do not leak. A nested
FUNC definition is scoped to its block and reverts on exit. Names share
one namespace with native and host-registered functions, which a FUNC
may never shadow.

Functions resolve like variables: a name is visible from its
definition line, so recursion works but mutual recursion does
not (the second name does not exist while the first body
lowers). Calls name their module (`STD::GLOB(...)`) unless
imported; see IMPORT.

Invoke any function with one syntax: `NAME(...)` as a statement
(discarding the value) or `LET $var: TYPE = NAME(...)` to capture
the RETURN value (fallthrough without RETURN captures as "").


**Examples:**

**Example: func def call**

```oxdock
FUNC GREET($name: STRING) {
  RETURN $name
}
LET $res: STRING = GREET("ada")
ASSERT_EQ $res "ada"
# Statement form: parens stay, the value drops.
GREET("bex")
```

**Example: call with pipes**

```oxdock
# A pipe handle travels into a function as a typed argument
# and is usable as a binding target in both directions.
# `LET $p: PIPE` mints the handle; `$p` passes it on.
FUNC DRAIN($q: PIPE) {
  WITH_IO [stdin=$q] READ_LINE $line
  RETURN $line
}
LET $p: PIPE
WITH_IO [stdout=$p] ECHO "payload"
LET $got: STRING = DRAIN($p)
ASSERT_EQ $got "payload"
```


### RETURN

Return a value from a function, task, or inline block.

**Syntax:** `RETURN [<expr>]`

Ends the nearest enclosing boundary with a value: a function
call, an `ASYNC` task (bound by `LET $o = AWAIT $t`), or an
inline `LET` block. Bare `RETURN` with no expression yields
`""`.

Falling off the end without RETURN yields "". RETURN with no
enclosing boundary (including at top level) is an error; use
EXIT or ECHO there.


**Examples:**

**Example: return**

```oxdock
FUNC PICK($flag: BOOL) {
  IF $flag {
    RETURN "yes"
  }
  RETURN "no"
}
LET $res: STRING = PICK(true)
ASSERT_EQ $res "yes"
```


### WHILE

Loop while a condition holds.

**Syntax:** `WHILE <bool-expr> { <commands> }`

Re-evaluates a Bool condition each iteration (same is_truthy rule as IF;
non-Bool is a type error).

Each iteration runs in a fresh scope; mutate outer state with $var = ...
so the next check observes it. BREAK exits the loop; CONTINUE skips to
the next check.


**Examples:**

**Example: while loop**

```oxdock
LET $done: BOOL = false
WHILE !$done {
  WRITE tick.txt "once"
  $done = true
}
LET $tick: STRING = READ tick.txt
ASSERT_EQ $tick "once"
```


### BREAK

Exit the innermost loop.

**Syntax:** `BREAK`

Exits the innermost enclosing FOR or WHILE loop.

BREAK outside a loop, or across a FUNC or ASYNC boundary, is an error.


**Examples:**

**Example: break**

```oxdock
FOR $x: STRING IN ["a", "b"] {
  BREAK
}
```


### CONTINUE

Skip to the next loop iteration.

**Syntax:** `CONTINUE`

Skips the rest of the innermost enclosing FOR or WHILE body and starts
the next iteration.

CONTINUE outside a loop, or across a FUNC or ASYNC boundary, is an error.


**Examples:**

**Example: continue**

```oxdock
FOR $x: STRING IN ["a", "b"] {
  CONTINUE
}
```


### IMPORT

Bring module functions into bare-call scope.

**Syntax:** `IMPORT [<module>, ...] | IMPORT <module>`

Every function call names its module (`STD::GLOB(...)`,
`MOCK::READ_CSV(...)`) unless the module is imported:
`IMPORT [STD]` lets the rest of the scope call `GLOB(...)`
bare. Calls resolve at parse time against `SCRIPT`
definitions first, then imported modules; unknown modules,
unknown functions, and unimported bare calls are parse
errors, never runtime surprises.

IMPORT is a lowering directive, not a step: it applies from
its line to the enclosing block exit, then reverts, exactly
like `LET` scoping but with no runtime footprint. Guards do
not apply to it. Two imported modules exporting one name is
an ambiguity error: qualify the call instead.

`EXPORT` is reserved for future script-module support and
cannot be used yet.


**Examples:**

**Example: import**

```oxdock
WRITE a.txt "hi \{{ env:WHO }}!"
IMPORT [STD]
FOR $x: STRING IN GLOB("*.txt") { EXPAND $x WHO=World }
ASSERT_CONTAINS stdout "hi World!"
```


### WORKDIR

Change the working directory.

**Syntax:** `WORKDIR <path>`

Sets the current working directory.

Relative paths resolve against the current directory; `/` resets to
the workspace root. Paths cannot escape the workspace.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | yes | Directory to change to |

**Examples:**

**Example: change working directory**

```oxdock
WORKDIR project/src
WRITE generated.txt generated-under-workdir
LET $body: STRING = READ generated.txt
ASSERT_EQ $body "generated-under-workdir"
```


### WORKSPACE

Switch workspace roots.

**Syntax:** `WORKSPACE (SNAPSHOT|LOCAL, case-insensitive)`

SNAPSHOT or LOCAL root.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `target` | `SNAPSHOT\|LOCAL` | yes | Target root |

**Examples:**

**Example: switch roots**

```oxdock
WORKSPACE LOCAL
```


### ENV

Set an environment variable.

**Syntax:** `ENV KEY=value`

Inserts or updates an env var.

The value uses the unified string-value rules shared by every command:
`"..."` or `'...'` quotes keep exact bytes (spaces, tabs), a lone `$var`
evaluates that variable, `{{ ... }}` placeholders interpolate, unquoted
words join with single spaces, and the first `=` splits key from value
(`KEY=a=b` stores `a=b`).

A `$var` inside larger text stays literal — write `{{ $var }}` to
interpolate there.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `assignment` | [`STRING`]#value-type-string | yes | KEY=value pair; the value resolves as STRING |

**Examples:**

**Example: set env**

```oxdock
ENV APP_MODE=production
```

**Example: quoted value with spaces**

```oxdock
# quotes keep the space: SET_FORTH stores `outer scope`
ENV SET_FORTH="outer scope"
WRITE out.txt "{{ env:SET_FORTH }}"
LET $body: STRING = READ out.txt
ASSERT_EQ $body "outer scope"
```

**Example: variable value**

```oxdock
# a lone $var evaluates, like ECHO $var
LET $who: STRING = "Alice"
ENV GREETING=$who
WRITE out.txt "{{ env:GREETING }}"
LET $body: STRING = READ out.txt
ASSERT_EQ $body "Alice"
```

**Example: all value forms agree**

```oxdock
# a bare variable, a quoted literal, and a template all
# store plain strings through the same value rules
LET $x: STRING = "Ada"
ENV A=$x
ENV B="hello world"
ENV C="{{ $x }} concatenated"
WRITE check.txt "{{ env:A }}|{{ env:B }}|{{ env:C }}"
LET $body: STRING = READ check.txt
ASSERT_EQ $body "Ada|hello world|Ada concatenated"
```

**Example: scoped env reverts**

```oxdock
# ENV inside a braced block reverts when the block exits
ENV MODE=production
[bool:true] {
    ENV MODE=staging
    WRITE inner.txt "{{ env:MODE }}"
}
WRITE outer.txt "{{ env:MODE }}"
LET $inner_body: STRING = READ inner.txt
LET $outer_body: STRING = READ outer.txt
ASSERT_EQ $inner_body "staging"
ASSERT_EQ $outer_body "production"
```


### INHERIT_ENV

Inherit env vars from host.

**Syntax:** `INHERIT_ENV [<key>, ...]`

Declares which host environment variables to inherit into the script.

Must appear before any other commands and at most once. Without this
directive, the script starts with an empty environment.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `keys` | [`STRING...`]#value-type-string | no | Host variables to inherit |

**Examples:**

**Example: inherit env**

```oxdock
INHERIT_ENV [PATH, HOME]
```


### ECHO

Print to stdout.

**Syntax:** `ECHO <message>`

Outputs message to stdout.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `message` | [`STRING...`]#value-type-string | yes | Text |

**Output:** Stdout

**Examples:**

**Example: echo**

```oxdock
ECHO build-complete
```

**Example: variables**

```oxdock
# a lone $x evaluates; {{ }} interpolates inside text
LET $x: STRING = "World"
ECHO {{ $x }}
ECHO $x
ASSERT_CONTAINS stdout "World"
```


### RUN

Execute shell command or direct executable.

**Syntax:** `RUN <command...> | RUN ["exe", "arg", ...]`

Shell form (`RUN <command...>`) runs the joined command string in the
system shell (`$SHELL -c` / `COMSPEC /C`).

Exec form (`RUN ["exe", "arg", ...]`) spawns the executable directly
with no shell, so there is no shell expansion, globbing, redirection,
or pipes; use it for portable commands.

Guards and wrappers (`ASYNC`, `TIMEOUT`, `WITH_IO`, `LET`) apply to
both forms.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `command` | [`STRING...`]#value-type-string | yes | Command |

**Examples:**

**Example: run**

```oxdock
RUN echo hello
```

**Example: run exec form**

```oxdock
RUN ["cargo", "--version"]
```


### COPY

Copy file into workspace.

**Syntax:** `COPY [--from-current-workspace] <from> <to>`

Copies from host.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | [`PATH`]#value-type-path | yes | Source |
| `to` | [`PATH`]#value-type-path | yes | Dest |

**Flags:**

| Flag | Type | Description |
| --- | --- | --- |
| `--from-current-workspace` | `BOOL` | Copy from workspace instead of build context |

**Examples:**

**Example: copy**

```oxdock roots:unified
WRITE src.txt content
COPY src.txt dst.txt
LET $body: STRING = READ dst.txt
ASSERT_EQ $body "content"
```

**Example: copy from workspace**

```oxdock roots:unified
WRITE ws-src.txt ws-content
COPY --from-current-workspace ws-src.txt ws-copy.txt
LET $body: STRING = READ ws-copy.txt
ASSERT_EQ $body "ws-content"
```


### COPY_GIT

Copy from git revision.

**Syntax:** `COPY_GIT [--include-dirty] <rev> <src> <dst>`

Checkout and copy.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `rev` | [`STRING`]#value-type-string | yes | Rev |
| `src` | [`PATH`]#value-type-path | yes | Src |
| `dst` | [`PATH`]#value-type-path | yes | Dst |

**Flags:**

| Flag | Type | Description |
| --- | --- | --- |
| `--include-dirty` | `BOOL` | Include dirty |

**Examples:**

**Example: git copy**

```oxdock expect_error:"COPY source missing"
COPY_GIT HEAD src.txt dst.txt
```

**Expected error:** `COPY source missing`


### SYMLINK

Create symlink.

**Syntax:** `SYMLINK <from> <to>`

Creates symlink.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `from` | [`PATH`]#value-type-path | yes | Target |
| `to` | [`PATH`]#value-type-path | yes | Link |

**Examples:**

**Example: symlink**

```oxdock roots:unified
WRITE original.txt content
SYMLINK original.txt link.txt
LET $body: STRING = READ link.txt
ASSERT_EQ $body "content"
```


### MKDIR

Create directory.

**Syntax:** `MKDIR <path>`

Creates dir with parents.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | yes | Dir path |

**Examples:**

**Example: mkdir**

```oxdock
MKDIR deeply/nested/tree
```


### LS

List directory.

**Syntax:** `LS [<path>]`

Lists entries.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | no | Dir |

**Output:** Stdout

**Examples:**

**Example: ls**

```oxdock
MKDIR inventory
WRITE inventory/a.txt a
LS inventory
```


### CWD

Print working directory.

**Syntax:** `CWD`

Outputs cwd.

**Output:** Stdout

**Examples:**

**Example: cwd**

```oxdock
CWD
```


### READ

Read file to stdout.

**Syntax:** `READ [<path>]`

Outputs file contents.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | no | File |

**Output:** Stdout

**Examples:**

**Example: read**

```oxdock
WRITE note.txt "hello"
READ note.txt
```


### READ_LINE

Read one line from stdin into a variable.

**Syntax:** `READ_LINE $var`

Reads bytes until newline without waiting for EOF, leaving the pipe open.

Trailing newline is stripped (shell-read parity). On premature EOF
assigns accumulated bytes and returns.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `var` | [`STRING`]#value-type-string | yes | Target variable (`$name`); the line binds as STRING |

**Examples:**

**Example: read line**

```oxdock
LET $lines: PIPE
WITH_IO [stdout=$lines] ECHO "first"
WITH_IO [stdin=$lines] READ_LINE $reply
```


### WRITE

Write to file.

**Syntax:** `WRITE <path> [<contents>]`

Writes contents.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | yes | File |
| `contents` | [`STRING...`]#value-type-string | no | Content |

**Examples:**

**Example: write**

```oxdock
WRITE output.txt hello-world
```


### APPEND

Append to file.

**Syntax:** `APPEND <path> [<contents>]`

Appends contents.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | yes | File |
| `contents` | [`STRING...`]#value-type-string | no | Content |

**Examples:**

**Example: append**

```oxdock
WRITE log.txt line1
APPEND log.txt line2
LET $all: STRING = READ log.txt
ASSERT_EQ $all "line1line2"
```


### EXPAND

Expand a template file (or stdin) to stdout.

**Syntax:** `EXPAND [<path>] [<KEY=val> ...]`

A template is any text file — or piped stdin when no path is given —
containing `{{ ... }}` placeholders. EXPAND replaces each placeholder
and prints the result to stdout.

Placeholders: `{{ NAME }}` reads a `KEY=val` override passed on this
command; `{{ env:NAME }}` reads an override, falling back to the
environment; `{{ $var }}` reads a script variable (dotted paths allowed).
A missing key is an error, never a silent empty.

Substitution runs in a single pass. EXPAND is not recursive and does not
expand nested placeholders: a value that itself contains `{{ ... }}` is
inserted verbatim and never expanded again.

A bare `$var` argument is a template path; `KEY=val` arguments are
overrides whose values follow the unified string-value rules (same as
`ENV`: quotes keep exact bytes, a lone `$var` evaluates,
`{{ ... }}` interpolates).

NOTE: `WRITE` interpolates `{{ ... }}` while writing, so escape it
(`\{{ ... }}`) when writing a template file for a later `EXPAND`.

With no path, the template arrives on stdin through a pipe. When piping
from a shell, single-quote the template (`echo '{{ $x }}'`): double
quotes let the shell swallow `$x`, so oxdock receives an empty `{{ }}`
placeholder and errors.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | no | Template file to expand; omit to expand stdin |
| `overrides` | [`STRING...`]#value-type-string | no | Template overrides shadowing that key (unified string values) |

**Output:** Stdout

**Examples:**

**Example: expand**

```oxdock
ENV NAME="Alice"
WRITE template.md "Hello {{ env:NAME }}!"
EXPAND template.md
ASSERT_CONTAINS stdout "Hello Alice!"
```

**Example: override with spaces**

```oxdock
# WRITE would interpolate {{ }} right away, so escape it:
# the file must literally contain {{ env:NAME }} for EXPAND
WRITE template.md "Hello \{{ env:NAME }}!"
EXPAND template.md NAME="Alice Smith"
ASSERT_CONTAINS stdout "Hello Alice Smith!"
```

**Example: variable override**

```oxdock
# same escaping: keep the placeholder literal until EXPAND;
# a lone $who evaluates, like ECHO $who
LET $who: STRING = "Bob"
WRITE template.md "Hi \{{ env:WHO }}!"
EXPAND template.md WHO=$who
ASSERT_CONTAINS stdout "Hi Bob!"
```

**Example: override forms agree**

```oxdock
# a bare variable and a template-with-tail expand identically
LET $x: STRING = "Ada"
WRITE template.md "Hi \{{ env:NAME }} and \{{ env:NAME2 }}!"
EXPAND template.md NAME=$x NAME2="{{ $x }} concatenated"
ASSERT_CONTAINS stdout "Hi Ada and Ada concatenated!"
```

**Example: expand stdin**

```oxdock
# no path: the template arrives on stdin through a pipe
LET $tpl: PIPE
WITH_IO [stdout=$tpl] ECHO "Hello \{{ env:NAME }}!"
WITH_IO [stdin=$tpl] EXPAND NAME=Alice
ASSERT_CONTAINS stdout "Hello Alice!"
```

**Example: override does not leak**

```oxdock
# KEY=val overrides shadow env for that EXPAND only —
# they never update the environment itself
ENV NAME="Alice"
WRITE template.md "Hi \{{ env:NAME }}!"
EXPAND template.md NAME="Bob"
ASSERT_CONTAINS stdout "Hi Bob!"
EXPAND template.md
ASSERT_CONTAINS stdout "Hi Alice!"
```


### ASSERT_EQ

Assert strict equality.

**Syntax:** `ASSERT_EQ <actual> <expected> | ASSERT_EQ --hash <sha256> <actual>`

Compares two evaluated values with typed equality (no coercion:
`INT(42)` never equals `STRING("42")`), aborting the pipeline
with a step-numbered error showing expected vs actual otherwise.

Both sides are values: `$var`, literals, templates, and calls
evaluate in memory and never touch disk. Read files explicitly
first (`LET $text: STRING = READ "out.txt"`, then
`ASSERT_EQ $text ...`).
Bare `stdout` / `stderr` observe stream buffers; a `$var`
holding a `PIPE` observes its backend bytes. `--hash` compares
the SHA-256 of a string, pipe, or captured-stdout actual
instead of the raw bytes (`stderr` is unsupported).


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `actual` | `<any>` | yes | Value, stdout, stderr, or a $var holding a PIPE |
| `expected` | `<any>...` | no | Expected (required unless --hash) |

**Flags:**

| Flag | Type | Description |
| --- | --- | --- |
| `--hash` | `STRING` | SHA-256 |

**Examples:**

**Example: assert eq**

```oxdock
LET $status: INT = 200
ASSERT_EQ $status 200
```

**Example: assert eq file**

```oxdock
WRITE payload.bin stable-content
LET $body: STRING = READ payload.bin
ASSERT_EQ $body "stable-content"
```

**Example: assert eq hash**

```oxdock
# --hash compares the SHA-256 digest instead of raw bytes
WRITE payload.bin stable-content
LET $body: STRING = READ payload.bin
ASSERT_EQ --hash 08135c1b6349b0e4f894c36221952f0de00e6b4d82f80895abf359755e77103c $body
```


### ASSERT_CONTAINS

Assert containment.

**Syntax:** `ASSERT_CONTAINS <haystack> <needle>`

Checks containment and aborts the pipeline with a step-numbered
error otherwise: substring for strings, element match for lists,
key presence for maps, substring over stream and pipe buffers.

Like `ASSERT_EQ`, both sides are values read without implicit
I/O; read files explicitly first
(`LET $text: STRING = READ "cfg.txt"`).
Bare `stdout` / `stderr` observe stream buffers; a `$var`
holding a `PIPE` observes its backend bytes.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `haystack` | `<any>` | yes | Value, stdout, stderr, or a $var holding a PIPE |
| `needle` | `<any>...` | yes | Substring, element, or key |

**Examples:**

**Example: assert contains**

```oxdock
ECHO build-complete
ASSERT_CONTAINS stdout "build-complete"
```


### HASH_SHA256

Print SHA-256.

**Syntax:** `HASH_SHA256 <path>`

Computes digest.

**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `path` | [`PATH`]#value-type-path | yes | File |

**Output:** Stdout

**Examples:**

**Example: hash**

```oxdock
WRITE payload.txt hello
HASH_SHA256 payload.txt
```


### EXIT

Exit pipeline.

**Syntax:** `EXIT <code>`

Stops the pipeline immediately with an `EXIT requested with code <code>`
error; steps after it never run, at any nesting depth.

Enclosing blocks still unwind their LET/ENV/WORKDIR/WORKSPACE state,
anonymous background tasks are killed synchronously, and files written
before the EXIT persist.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `code` | [`INT`]#value-type-int | yes | Code |

**Examples:**

**Example: exit**

```oxdock expect_error:"EXIT requested with code 0"
EXIT 0
```

**Expected error:** `EXIT requested with code 0`


### SLEEP

Pause execution for a duration.

**Syntax:** `SLEEP <duration>`

Parks the step for the duration (e.g. 500ms, 10s, 2m).

Cooperative: checks for cancellation so an enclosing TIMEOUT or task
teardown interrupts the sleep. Cross-platform alternative to shell sleep
for testing time boundaries.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `duration` | [`DURATION`]#value-type-duration | yes | How long to sleep |

**Examples:**

**Example: sleep**

```oxdock
SLEEP 100ms
```

**Example: sleep variable duration**

```oxdock
# durations resolve at runtime, so variables work too —
# quoted or bare, both bind the same string
LET $pause: STRING = "100ms"
SLEEP $pause
LET $bare: STRING = 100ms
SLEEP $bare
```


### LIST_APPEND

Append an item to a LIST variable in place.

**Syntax:** `LIST_APPEND $list <item>`

Appends the item to the LIST variable in place.

When the binding holds the only reference the push runs in
amortized constant time. Aliased buffers detach first, so
other holders keep their contents.


**Arguments:**

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `list` | [`LIST`]#value-type-list | yes | Target LIST variable (`$name`) |
| `item` | `<any>` | yes | Item to append (any value) |

**Examples:**

**Example: list append**

```oxdock
LET $items: LIST = []
LIST_APPEND $items "first"
LIST_APPEND $items "second"
LET $want: LIST = ["first", "second"]
ASSERT_EQ $items $want
```


## Value types

### Value type: INT

64-bit signed integer, e.g. an exit code.

### Value type: FLOAT

64-bit float, e.g. a ratio.

### Value type: STRING

Arbitrary text. Quotes keep exact bytes, lone `$var` evaluates, `{{ ... }}` interpolates.

### Value type: BOOL

Boolean `true` or `false`.

### Value type: LIST

Ordered list of values. Shared heap: cloning bumps a refcount.

### Value type: MAP

String-keyed map of values. Shared heap: cloning bumps a refcount.

### Value type: PATH

Workspace path, resolved against cwd and guarded against escape.

### Value type: DURATION

Positive time span: `500ms`, `10s`, `2m`, `1h`; bare number means seconds.

### Value type: PIPE

Anonymous pipe handle. The backend materializes lazily on first
binding (never eagerly at declaration), so the choice always has full
usage context. Cloning shares the backend (explicit-sharing fan-out);
equality is handle identity, never byte comparison.

### Value type: HANDLE

Background ASYNC task handle for AWAIT/CANCEL.

### Value type: SEMAPHORE

Counting semaphore for admission control. Cloning shares the backend
(explicit-sharing fan-out); equality is handle identity, never the
count.

### Value type: PERMIT

Opaque admission permit minted by `SEMAPHORE_TRY_ACQUIRE`. Cloning
shares the release obligation (first drops release nothing, the last
releases once); equality is handle identity.

<!-- GENERATED by docs-gen from STD function metadata. Do not edit by hand. -->
## Functions

Callable as `MODULE::NAME(...)` in expressions (or bare `NAME(...)` with the module imported via `IMPORT`). Introspectable from scripts with `FUNCTIONS()` and `DESCRIBE(name)`.

### STD::DESCRIBE

**Signature:** `STD::DESCRIBE($name: STRING) -> MAP`

**Contexts:** AST only

Describe one function by qualified name.

Returns a MAP with name, module, kind, params, returns, and summary.
Bare names fail closed: `DESCRIBE` requires the qualified form (except
`INSPECT`, which is syntax rather than a registry entry). Errors on
unknown function.

### STD::FLOAT

**Signature:** `STD::FLOAT($val) -> FLOAT`

**Contexts:** AST, RPN

Convert a value to FLOAT.

Parses f64 (accepts int strings), bails on non-finite or non-numeric.

### STD::FUNCTIONS

**Signature:** `STD::FUNCTIONS() -> LIST`

**Contexts:** AST only

List all visible function names.

Sorted LIST of qualified `MODULE::NAME` entries: DSL-defined plus native
plus host-registered names.

### STD::GLOB

**Signature:** `STD::GLOB($pattern: STRING) -> LIST`

**Contexts:** AST, RPN

List workspace paths matching a glob pattern.

Sorted, root-relative LIST; empty on no match or `..` escape.

### STD::INT

**Signature:** `STD::INT($val) -> INT`

**Contexts:** AST, RPN

Convert a value to INT.

Trims ASCII whitespace and parses i64. Passes Int through; Float only
when integral and finite.

### STD::IS_TERMINAL

**Signature:** `STD::IS_TERMINAL($stream: STRING) -> BOOL`

**Contexts:** AST only

Report whether a standard stream is a terminal.

`IS_TERMINAL("stdin")`, `IS_TERMINAL("stdout")`, or `IS_TERMINAL("stderr")`
answers for the step's stream as currently bound, so scripts can adapt
prompts, colors, and progress output. Anything diverted from the
terminal reports false without touching host handles: `WITH_IO` pipe
bindings (script backends and OS pairs), `LET`-capture sinks, staged
runner sinks, and any materialized stdin stream (only a directly
inherited fd falls back to the process check). A transparent root tee
still answers the session question via the process check. The name
matches exactly (no case folding): anything else bails. AST-only:
reads the step context like the other introspection functions.

### STD::LOAD_JSON

**Signature:** `STD::LOAD_JSON($path: STRING) -> MAP`

**Contexts:** AST, RPN

Load and parse a JSON file.

Reads a workspace file and parses JSON into a DSL value.

### STD::LOAD_TOML

**Signature:** `STD::LOAD_TOML($path: STRING) -> MAP`

**Contexts:** AST, RPN

Load and parse a TOML file.

Reads a workspace file and parses TOML into a DSL value.

### STD::PATH_TYPE

**Signature:** `STD::PATH_TYPE($path: STRING) -> STRING`

**Contexts:** AST only

Describe a filesystem entry.

Reports file, dir, symlink (no-follow), or absent. AST-only by design;
there is no RPN arm for filesystem IO.

### STD::SEMAPHORE_AVAILABLE

**Signature:** `STD::SEMAPHORE_AVAILABLE($sem) -> INT`

**Contexts:** AST, RPN

Read free permits under the lock, with no mutation.

Observability only (audit lines, healthchecks: `active = max - free`).
Exact at read time and stale the instant the caller acts on it, so it
must never drive admission: that is `SEMAPHORE_TRY_ACQUIRE`'s job.

```text
LET $free: INT = SEMAPHORE_AVAILABLE($sem)
```

### STD::SEMAPHORE_NEW

**Signature:** `STD::SEMAPHORE_NEW($max: INT) -> SEMAPHORE`

**Contexts:** AST only

Create a counting semaphore admitting at most `max` concurrent holders.

Non-positive maxima bail. The word names a shared backend: every clone
observes the same count, and admission runs through
`SEMAPHORE_TRY_ACQUIRE`, never through the `SEMAPHORE_AVAILABLE`
readout.

```text
LET $sem: SEMAPHORE = SEMAPHORE_NEW(10)
```

### STD::SEMAPHORE_TRY_ACQUIRE

**Signature:** `STD::SEMAPHORE_TRY_ACQUIRE($sem) -> MAP`

**Contexts:** AST only

Attempt one non-blocking acquire, always answering a MAP.

`held` is `1` with the permit under the `permit` key, or `0` with no
`permit` key: branch on `$m.held` (the DSL has no null, so the absent
key is the miss shape, and missing-key access already bails strictly).
Never waits, so no wait can wedge.

```text
LET $acq: MAP = SEMAPHORE_TRY_ACQUIRE($sem)
IF $acq.held == 0 {
  ECHO "at cap, rejecting"
} ELSE {
  LET $permit: PERMIT = $acq.permit
  ASYNC { session work }
}
```

### STD::TYPES

**Signature:** `STD::TYPES() -> LIST`

**Contexts:** AST only

List all known type names.

Sorted LIST of startup plus host-registered type descriptors. Reads the
run's name directory, so it runs on the AST path like the other
introspection functions.

### STD::TYPE_DESCRIBE

**Signature:** `STD::TYPE_DESCRIBE($name: STRING) -> MAP`

**Contexts:** AST only

Describe one type by name.

Returns a MAP with name, summary, and docs. Errors on unknown type.
Reads the run's name directory, so it runs on the AST path.