Compare commits
673
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d4ccb77003 | ||
|
|
328cc5c61b | ||
|
|
520931ca34 | ||
|
|
f17e23aeec | ||
|
|
f4e292e7b0 | ||
|
|
e7324edc0f | ||
|
|
c190ffb184 | ||
|
|
380d4f95a3 | ||
|
|
48189243f7 | ||
|
|
4fade3e981 | ||
|
|
0c7430ede0 | ||
|
|
8fa728b302 | ||
|
|
7475c79cb2 | ||
|
|
484cb10d66 | ||
|
|
8f842a7f08 | ||
|
|
5798999691 | ||
|
|
7aac052149 | ||
|
|
f08ec00dec | ||
|
|
198b3acc86 | ||
|
|
c5415d5bc5 | ||
|
|
8c1ec4c91e | ||
|
|
451000e9ad | ||
|
|
b4395416fd | ||
|
|
cbbd819370 | ||
|
|
ad52612355 | ||
|
|
024d803494 | ||
|
|
4c5c102593 | ||
|
|
1c55baabd5 | ||
|
|
ffe06d7afa | ||
|
|
180a111799 | ||
|
|
a3948dbe0d | ||
|
|
24959a0ba8 | ||
|
|
afbb9f191c | ||
|
|
8db699191e | ||
|
|
e5580d9640 | ||
|
|
9ce2ae1037 | ||
|
|
166b01c86b | ||
|
|
87cfe05095 | ||
|
|
b37387e6da | ||
|
|
895752a1fd | ||
|
|
38c07d9a0e | ||
|
|
a7a5554c0f | ||
|
|
343504c7a8 | ||
|
|
3d9fa0da96 | ||
|
|
bb8960c5eb | ||
|
|
9331af78e2 | ||
|
|
73bf574a55 | ||
|
|
4fae71342d | ||
|
|
63d60e3ba1 | ||
|
|
44d2928c06 | ||
|
|
fa832268b3 | ||
|
|
9576188a2e | ||
|
|
528a1f0dbc | ||
|
|
a11b347659 | ||
|
|
8e437e2cd3 | ||
|
|
23229a6ac9 | ||
|
|
58b65215a1 | ||
|
|
92c3f80055 | ||
|
|
8a66f803cb | ||
|
|
3ce59a4da8 | ||
|
|
90688741c5 | ||
|
|
70b88b3767 | ||
|
|
f859e6eeea | ||
|
|
6705e2e6b7 | ||
|
|
6e8a62928b | ||
|
|
398a0b7222 | ||
|
|
e8f1a3e126 | ||
|
|
8ea56cbe30 | ||
|
|
8085d06124 | ||
|
|
6f929dc2da | ||
|
|
dd22180269 | ||
|
|
cc48bf6d05 | ||
|
|
19f986953a | ||
|
|
770dee5199 | ||
|
|
f6612813e3 | ||
|
|
643ea06340 | ||
|
|
0cd64a7450 | ||
|
|
981faac022 | ||
|
|
f818834ec1 | ||
|
|
8d47507d15 | ||
|
|
1e1f05c087 | ||
|
|
06e61efc51 | ||
|
|
2dfa0b2a5b | ||
|
|
629ad8ed39 | ||
|
|
ee677478be | ||
|
|
edbf241d99 | ||
|
|
add6a7d32c | ||
|
|
c64ec99115 | ||
|
|
60a3b84a84 | ||
|
|
02a4f2d20d | ||
|
|
88490e3092 | ||
|
|
9031c106a1 | ||
|
|
633436e40f | ||
|
|
cf73fcf1ef | ||
|
|
e48fd5b0f4 | ||
|
|
b2f97e72c3 | ||
|
|
c7c0f66d1f | ||
|
|
d5ab9daebb | ||
|
|
5795236d1f | ||
|
|
e8d6dc92fc | ||
|
|
afe31cb2a8 | ||
|
|
905a67df32 | ||
|
|
f63b7ef48d | ||
|
|
393558ca97 | ||
|
|
0d9bd99fc0 | ||
|
|
a0c779e022 | ||
|
|
a82b6fdde1 | ||
|
|
3613ed7c4e | ||
|
|
9564dff777 | ||
|
|
f56deffefe | ||
|
|
bdedf3ecd8 | ||
|
|
b0ee958fcf | ||
|
|
e64f6b23b4 | ||
|
|
eed4f05ea4 | ||
|
|
d88ed274ed | ||
|
|
7fdd97f675 | ||
|
|
c299efe589 | ||
|
|
b3867c46db | ||
|
|
1a39a53d93 | ||
|
|
6d6f580d24 | ||
|
|
af05f19301 | ||
|
|
3201369470 | ||
|
|
05197378b3 | ||
|
|
f3b3152f07 | ||
|
|
22364f2f1b | ||
|
|
b69a90501d | ||
|
|
7ff881f506 | ||
|
|
9acbe10986 | ||
|
|
81989a26d7 | ||
|
|
cf0ba6dccd | ||
|
|
0de703f86a | ||
|
|
4907f92d84 | ||
|
|
eac6921524 | ||
|
|
c0dc18433b | ||
|
|
7d9af11398 | ||
|
|
d9aef957f7 | ||
|
|
aa0c4d0f55 | ||
|
|
c50c515c4a | ||
|
|
16c44588d5 | ||
|
|
5080136d65 | ||
|
|
cc5277d2b5 | ||
|
|
bb06dad134 | ||
|
|
24dcb97354 | ||
|
|
76aa02846a | ||
|
|
0e389f34ec | ||
|
|
492790e985 | ||
|
|
ca434a8bab | ||
|
|
6195ad1d5d | ||
|
|
a87c2154ff | ||
|
|
8f1010f967 | ||
|
|
e3d9021bb6 | ||
|
|
142ab523d6 | ||
|
|
82c8d78fd3 | ||
|
|
58791fc7d9 | ||
|
|
1730f26fc7 | ||
|
|
4018e9928a | ||
|
|
628e3b6e5d | ||
|
|
5c6c612edd | ||
|
|
41587f319e | ||
|
|
298fbd51ea | ||
|
|
265dfdbcc4 | ||
|
|
42a43f5ffd | ||
|
|
037a963547 | ||
|
|
a32638e935 | ||
|
|
43eebe5671 | ||
|
|
e833dc05e2 | ||
|
|
11bb7ef277 | ||
|
|
6bd90bb2d0 | ||
|
|
4683f2e067 | ||
|
|
5912164039 | ||
|
|
303c06f773 | ||
|
|
a1086fd6c3 | ||
|
|
6ffe5ceb19 | ||
|
|
6b568aff3d | ||
|
|
16f26d7d60 | ||
|
|
b8265a92aa | ||
|
|
9af929971c | ||
|
|
2c4fa4bb05 | ||
|
|
3cabe53da2 | ||
|
|
58e13ee6d3 | ||
|
|
1b11fe063a | ||
|
|
b792f44556 | ||
|
|
9ea5bebfc3 | ||
|
|
c7c329341b | ||
|
|
8cf5288481 | ||
|
|
69c4e74872 | ||
|
|
af0bda2e40 | ||
|
|
090b026547 | ||
|
|
03396afd02 | ||
|
|
663a8ba2c0 | ||
|
|
dc853fb580 | ||
|
|
0b80ff8e50 | ||
|
|
b8a4ddd38f | ||
|
|
352bc0d2c5 | ||
|
|
8a6d09d582 | ||
|
|
dcd3d329d4 | ||
|
|
0e1bfb3359 | ||
|
|
e9ae7ff1ae | ||
|
|
ecbdd18303 | ||
|
|
bedd53e212 | ||
|
|
7674ebb869 | ||
|
|
434be9fd52 | ||
|
|
ae97891266 | ||
|
|
aea86746e7 | ||
|
|
c773503938 | ||
|
|
939e23ee88 | ||
|
|
687c168014 | ||
|
|
eac9b45263 | ||
|
|
74b298e80d | ||
|
|
fc7097bae4 | ||
|
|
b624084745 | ||
|
|
0bbe735c3c | ||
|
|
92de46aca4 | ||
|
|
8bbe017a5e | ||
|
|
1a13989230 | ||
|
|
5ad1a07f5c | ||
|
|
bcfc763ba4 | ||
|
|
bf76e069ee | ||
|
|
9015de26e5 | ||
|
|
8c24d96626 | ||
|
|
4a2f5bf226 | ||
|
|
86e921e959 | ||
|
|
b196a44685 | ||
|
|
c8ed5bffb7 | ||
|
|
fb135ae2f8 | ||
|
|
69fcdd6227 | ||
|
|
deac53d0f5 | ||
|
|
932403237a | ||
|
|
a14a6e221d | ||
|
|
8b0ea9ed7a | ||
|
|
6ae0d39e5a | ||
|
|
307c8efa81 | ||
|
|
34b0911218 | ||
|
|
4488a3cb70 | ||
|
|
9dbcc728b6 | ||
|
|
0405a60d68 | ||
|
|
409b8df2cb | ||
|
|
6bba0be6d2 | ||
|
|
1c90312c02 | ||
|
|
fd0cfcb566 | ||
|
|
6dd0ce47b1 | ||
|
|
1a94cc8490 | ||
|
|
11417c42e0 | ||
|
|
13012cac0e | ||
|
|
5a0f4ed747 | ||
|
|
05b8edc186 | ||
|
|
8926f7bed6 | ||
|
|
18b0c655f7 | ||
|
|
924885969f | ||
|
|
619271b8eb | ||
|
|
719b7a8d82 | ||
|
|
dfe99a10b4 | ||
|
|
fac68e85ea | ||
|
|
639b0ebcd1 | ||
|
|
2c4dac005c | ||
|
|
0ac661eef2 | ||
|
|
1dd74578b5 | ||
|
|
14114993c4 | ||
|
|
e80c944c40 | ||
|
|
30cd5a0833 | ||
|
|
e2068c2051 | ||
|
|
9cda80ee7d | ||
|
|
eae4815fc7 | ||
|
|
3260494e5c | ||
|
|
3330a0fc66 | ||
|
|
42a1a46383 | ||
|
|
b6629e5450 | ||
|
|
ecd7d5e433 | ||
|
|
aeb5a2a43d | ||
|
|
f2d651e063 | ||
|
|
b020b9d218 | ||
|
|
33a14d272c | ||
|
|
6ed70fd8b8 | ||
|
|
115d1f6c0b | ||
|
|
7dc5e56850 | ||
|
|
514caa55ae | ||
|
|
74908ebf04 | ||
|
|
0f852593bc | ||
|
|
34e2fb4f74 | ||
|
|
0e407b2bd3 | ||
|
|
e5e532d83f | ||
|
|
064522a338 | ||
|
|
c85f1a2829 | ||
|
|
a7266185b2 | ||
|
|
4d7c0bea1b | ||
|
|
53758ebd1c | ||
|
|
dff0b700ae | ||
|
|
4da07c1b26 | ||
|
|
78922102e4 | ||
|
|
064bae2c65 | ||
|
|
92b91ffc81 | ||
|
|
ab6648ae0e | ||
|
|
5acf026e0c | ||
|
|
8dcd69412f | ||
|
|
2a13e52981 | ||
|
|
9b269f6447 | ||
|
|
15362cb048 | ||
|
|
05d48f68a4 | ||
|
|
e4387259ba | ||
|
|
518f8e386b | ||
|
|
9da12c9093 | ||
|
|
e0d34669e0 | ||
|
|
0ba4d3d2d7 | ||
|
|
ad3ebf243a | ||
|
|
142d30ce08 | ||
|
|
4757b82edd | ||
|
|
bff2f53e52 | ||
|
|
fb28eee62f | ||
|
|
01468ad976 | ||
|
|
f3791d11b4 | ||
|
|
7fef690167 | ||
|
|
024cdee82a | ||
|
|
f666eaaf40 | ||
|
|
e6f05c7748 | ||
|
|
81f9ea0072 | ||
|
|
dbf3f3a14b | ||
|
|
654e89d98c | ||
|
|
be20629496 | ||
|
|
3223295841 | ||
|
|
beb5bdbe8c | ||
|
|
b8cb022018 | ||
|
|
b9e331cb31 | ||
|
|
476c2b607b | ||
|
|
d99b275336 | ||
|
|
1415aee08f | ||
|
|
0f2c12b636 | ||
|
|
9873df7099 | ||
|
|
3001ed7ba5 | ||
|
|
050d71927f | ||
|
|
7859170aec | ||
|
|
e32ff8f6b3 | ||
|
|
c21a28c3bc | ||
|
|
1e61dca9d8 | ||
|
|
ba675a4767 | ||
|
|
bfd468d5e3 | ||
|
|
8353ba38fe | ||
|
|
b43a08b2e2 | ||
|
|
1908bf1a53 | ||
|
|
c44ea38ae2 | ||
|
|
d489f7c088 | ||
|
|
a993cfd76a | ||
|
|
d5f826a8c8 | ||
|
|
0f72173d08 | ||
|
|
a707758d47 | ||
|
|
63bcb882a6 | ||
|
|
1bb16dd6db | ||
|
|
58ec2172d6 | ||
|
|
66926e9e0a | ||
|
|
dcf4c05663 | ||
|
|
f47a1e143a | ||
|
|
9cf98a98b5 | ||
|
|
f99d552d87 | ||
|
|
7d49c358c1 | ||
|
|
a32c0cd78f | ||
|
|
0a8f76d9b4 | ||
|
|
4e2419b598 | ||
|
|
f6374d1593 | ||
|
|
9ede4bc63d | ||
|
|
3ae8f2c843 | ||
|
|
e9c1a8a730 | ||
|
|
5554b1642c | ||
|
|
fe15603a91 | ||
|
|
1418742655 | ||
|
|
ed31a2b31d | ||
|
|
56ab52356f | ||
|
|
2e425c3010 | ||
|
|
46a0263d7f | ||
|
|
ff252fd469 | ||
|
|
67bac1bf02 | ||
|
|
33f8b94bb0 | ||
|
|
0ed57b6d54 | ||
|
|
c29d48f38c | ||
|
|
f1e82ce4e5 | ||
|
|
2d412e3bba | ||
|
|
46d78c6e15 | ||
|
|
81a14f9b38 | ||
|
|
88dc6d5a54 | ||
|
|
4a2d89406b | ||
|
|
d8d435fead | ||
|
|
1f8e61f3bf | ||
|
|
a9ee858f53 | ||
|
|
8489d90926 | ||
|
|
5272acaea0 | ||
|
|
cba51238b6 | ||
|
|
5fffb800f9 | ||
|
|
1a729eb9ec | ||
|
|
00c763300e | ||
|
|
224b3d4a66 | ||
|
|
81d26a265a | ||
|
|
5b599125d1 | ||
|
|
18d89d6cf2 | ||
|
|
199b5c532f | ||
|
|
db5f0e830b | ||
|
|
7a449c40b1 | ||
|
|
97fda7aa10 | ||
|
|
a49592a3ba | ||
|
|
ed9ac03c0c | ||
|
|
cb46ad7abe | ||
|
|
586975090b | ||
|
|
544805266b | ||
|
|
f3051fb536 | ||
|
|
86b183e2d7 | ||
|
|
8e23a5395a | ||
|
|
cab609ee91 | ||
|
|
b752cd49b7 | ||
|
|
2c91b5cc7b | ||
|
|
453321c8c2 | ||
|
|
981d754133 | ||
|
|
410f36f719 | ||
|
|
bd06aedb90 | ||
|
|
42ddeb14e7 | ||
|
|
6bd127a313 | ||
|
|
4b7643d833 | ||
|
|
3f96592c99 | ||
|
|
98018fc63b | ||
|
|
aeac4d6d20 | ||
|
|
9e9a80df31 | ||
|
|
5f07b1c3b1 | ||
|
|
bfea2204eb | ||
|
|
fb30cd3db3 | ||
|
|
584cb9ac9d | ||
|
|
428ee141e1 | ||
|
|
ec9718466d | ||
|
|
c5bb08022a | ||
|
|
b710745e88 | ||
|
|
5cf84fe9b7 | ||
|
|
27991a7822 | ||
|
|
d1e2f0ced0 | ||
|
|
e848306187 | ||
|
|
2ee9d7e66d | ||
|
|
e31585842d | ||
|
|
f068b4ab75 | ||
|
|
26e29409a9 | ||
|
|
4923129d10 | ||
|
|
8ab55e2193 | ||
|
|
9bc7ef3b5a | ||
|
|
9431ad835c | ||
|
|
2984d7d4f8 | ||
|
|
6324036e41 | ||
|
|
3287799959 | ||
|
|
f95e5d3339 | ||
|
|
52b4bae423 | ||
|
|
037592087c | ||
|
|
3eb8e732ea | ||
|
|
761b92afce | ||
|
|
b5f43ee993 | ||
|
|
76da97f090 | ||
|
|
7554e45f60 | ||
|
|
6994acb91d | ||
|
|
bccfec86ba | ||
|
|
114fd53cd1 | ||
|
|
c8f41164c5 | ||
|
|
6f303ff957 | ||
|
|
95a49697f7 | ||
|
|
8846f5f070 | ||
|
|
4f09e515ee | ||
|
|
551f4ff322 | ||
|
|
d5a9301c7f | ||
|
|
34915e3b16 | ||
|
|
c55aad775e | ||
|
|
ac3f0633cd | ||
|
|
d55567a634 | ||
|
|
abcb141737 | ||
|
|
8d97adc1dc | ||
|
|
5c37d54070 | ||
|
|
fecaacd5be | ||
|
|
53bc3538da | ||
|
|
0e0655b316 | ||
|
|
5058f5ddcf | ||
|
|
4a1c9c48a2 | ||
|
|
5e74ff39f2 | ||
|
|
b5c07385e9 | ||
|
|
bfb10d172b | ||
|
|
00a77181ef | ||
|
|
e13468dc43 | ||
|
|
d3b137c919 | ||
|
|
e292c8a7c7 | ||
|
|
ce195998c1 | ||
|
|
e20cf8b386 | ||
|
|
c4a726397d | ||
|
|
7fab85b389 | ||
|
|
12d2c7be69 | ||
|
|
26955f4f36 | ||
|
|
56df0736fa | ||
|
|
695939ac74 | ||
|
|
4c06851e0e | ||
|
|
23e4bc406e | ||
|
|
fe18c4d1d6 | ||
|
|
e6fdeb0b31 | ||
|
|
5ec4b3c17d | ||
|
|
6e94d0a179 | ||
|
|
4357045904 | ||
|
|
1ef71d7492 | ||
|
|
1fc985db7e | ||
|
|
364428ca1e | ||
|
|
09b549a862 | ||
|
|
2d238a8c36 | ||
|
|
7a0309284a | ||
|
|
fd3f1724e6 | ||
|
|
ca40c698a2 | ||
|
|
fb6254e501 | ||
|
|
cf9d96477b | ||
|
|
493d0ad91a | ||
|
|
a0e88919a6 | ||
|
|
237962c3be | ||
|
|
1637acce6e | ||
|
|
68c4f8c822 | ||
|
|
784d5ec346 | ||
|
|
955834e453 | ||
|
|
435f36b6e9 | ||
|
|
08c48f3acb | ||
|
|
ff1870cedc | ||
|
|
5e51ee1bb2 | ||
|
|
55f1a37b3d | ||
|
|
58dff0a1e9 | ||
|
|
fc543f1ca5 | ||
|
|
2e068e66d4 | ||
|
|
a4c346d4a2 | ||
|
|
fe14d1f7e3 | ||
|
|
f4b39dfe80 | ||
|
|
7d86ed1d9c | ||
|
|
506de65dae | ||
|
|
08384c7540 | ||
|
|
94ae6713aa | ||
|
|
838a2b425a | ||
|
|
1a5ee57a6f | ||
|
|
d539e6b96b | ||
|
|
3ade036d34 | ||
|
|
f3c49e86ae | ||
|
|
b2401b8458 | ||
|
|
51bb8767e3 | ||
|
|
c0fbe9b182 | ||
|
|
01287d9e7e | ||
|
|
70fb2fbfb2 | ||
|
|
b6f116108c | ||
|
|
03aca7cdac | ||
|
|
96da88e168 | ||
|
|
b6cceab218 | ||
|
|
95b16be714 | ||
|
|
d31ad79bc0 | ||
|
|
5745805a5d | ||
|
|
590f7a58fa | ||
|
|
027b19c5db | ||
|
|
7670673a39 | ||
|
|
824b9bf607 | ||
|
|
155183eb30 | ||
|
|
b10a84466b | ||
|
|
0aa0f47a9d | ||
|
|
5f91be7c21 | ||
|
|
e3e2cfa9d1 | ||
|
|
d1b4e62d4d | ||
|
|
ff1b846b73 | ||
|
|
ad47d4a0d2 | ||
|
|
c080b79c5b | ||
|
|
f19f614e0d | ||
|
|
8fbf617e05 | ||
|
|
a9d30cdf4a | ||
|
|
4c27c8afeb | ||
|
|
9d591674aa | ||
|
|
e40d21760a | ||
|
|
2445c290c9 | ||
|
|
04890e0c73 | ||
|
|
ab52db2037 | ||
|
|
aac896b044 | ||
|
|
fb037022ba | ||
|
|
a75b7a1c87 | ||
|
|
f2fd4fb34e | ||
|
|
2079577314 | ||
|
|
416914a346 | ||
|
|
1e5e6f4891 | ||
|
|
4c37e79dae | ||
|
|
9a8545b725 | ||
|
|
ee3116513b | ||
|
|
729357b7c0 | ||
|
|
07ab7d52c6 | ||
|
|
d7be903297 | ||
|
|
d0b184939f | ||
|
|
c36383bf28 | ||
|
|
eba0d703c5 | ||
|
|
dfb27d41dc | ||
|
|
cf4dbdeade | ||
|
|
f3fe7f268e | ||
|
|
88fe076216 | ||
|
|
4956460773 | ||
|
|
eafa203205 | ||
|
|
7317a653c7 | ||
|
|
0fddc3bf05 | ||
|
|
724a22e48d | ||
|
|
6db3da1cc0 | ||
|
|
86bfb0648c | ||
|
|
c6360adccb | ||
|
|
2d51f29199 | ||
|
|
323449c2c3 | ||
|
|
6808d56c9d | ||
|
|
e3b0314382 | ||
|
|
a900fd550f | ||
|
|
034f52b7e7 | ||
|
|
e7c9c21a49 | ||
|
|
be6223f1fb | ||
|
|
da9fc75b1e | ||
|
|
7645dd4c1f | ||
|
|
7dfa161422 | ||
|
|
b84e82eb56 | ||
|
|
d7924ea8c7 | ||
|
|
bd5555afaa | ||
|
|
f275d1e030 | ||
|
|
1bf414c745 | ||
|
|
ecc92f473a | ||
|
|
56b9bfa5a3 | ||
|
|
209dc4fc5d | ||
|
|
db27f5c8d3 | ||
|
|
106e1d5136 | ||
|
|
d269ccb7e7 | ||
|
|
505d478724 | ||
|
|
b842644686 | ||
|
|
60d570756f | ||
|
|
eea6fe1a0e | ||
|
|
25b7be6739 | ||
|
|
91d51f3f0a | ||
|
|
ff6425e6c5 | ||
|
|
e853b00fe2 | ||
|
|
4a7a33e29a | ||
|
|
25b6b86c26 | ||
|
|
e4be0b0492 | ||
|
|
db6158e9e2 | ||
|
|
a0c56fa352 | ||
|
|
c181b74a88 | ||
|
|
02b3dfab48 | ||
|
|
b09538d242 | ||
|
|
0dcd9e3d03 | ||
|
|
897db76aa7 | ||
|
|
ee019fb1c2 | ||
|
|
9599303c4c | ||
|
|
8041a2274c | ||
|
|
ab8ea8438f | ||
|
|
f240bdf156 | ||
|
|
ff84c43c10 | ||
|
|
dbb2765553 | ||
|
|
7e3b193d49 | ||
|
|
2a9fceb51c | ||
|
|
d1ddb74235 | ||
|
|
b6bb42e460 | ||
|
|
5456d9ff83 | ||
|
|
a23fdedfa2 | ||
|
|
3463628165 | ||
|
|
d1b33c78c6 | ||
|
|
fbece725e1 | ||
|
|
1f23e2ed93 | ||
|
|
99132ac8fc | ||
|
|
118448538c | ||
|
|
2e65c055b8 | ||
|
|
3da7b276d3 | ||
|
|
63e5be80ab | ||
|
|
92d88fe761 | ||
|
|
c4ffb9473f | ||
|
|
3a7e11c995 | ||
|
|
b0c777c480 | ||
|
|
b00b018056 | ||
|
|
b974f10c6e | ||
|
|
72777a8c74 | ||
|
|
e08cd839be | ||
|
|
5309848292 | ||
|
|
1271aafcdd | ||
|
|
54a507d906 | ||
|
|
ea17ae1074 | ||
|
|
fe9046cecf | ||
|
|
b5e9d15391 | ||
|
|
dcd0cdb8f7 | ||
|
|
a53ebb65ee | ||
|
|
a5d30c00b3 | ||
|
|
fd36b92224 | ||
|
|
30cd39fd8f | ||
|
|
31a4b69bbd |
No files matched your search
Executable
+2
@@ -0,0 +1,2 @@
|
||||
* text=auto
|
||||
*.sh text eol=lf
|
||||
@@ -0,0 +1,34 @@
|
||||
---
|
||||
name: 功能、缺陷或迁移
|
||||
about: 记录唯一负责仓库、可复现候选与验收
|
||||
---
|
||||
|
||||
## 问题与所有权
|
||||
|
||||
- 责任组件(全局 ID / 仓库):
|
||||
- 类型:bug | missing capability | contract change | migration
|
||||
- 影响消费者(ID / 关联工单):
|
||||
- 权威合同链接:
|
||||
|
||||
## 可复现的候选组合
|
||||
|
||||
- 根 / 领域 / 组件 SHA:
|
||||
- CLI、Worker、Stdlib、依赖制品 SHA-256 与平台:
|
||||
- 环境与工具链:
|
||||
- 最小 fixture / 命令 / 实际结果:
|
||||
- 预期结果:
|
||||
|
||||
## 修复范围
|
||||
|
||||
- 必须:
|
||||
- 禁止:兼容旧协议、复制实现、无关重构、扩大权限等
|
||||
- 上游阻塞:<工单链接或无>
|
||||
|
||||
## 验收
|
||||
|
||||
- 正例:
|
||||
- 负例 / 授权与安全边界:
|
||||
- 回归 / 性能条件:
|
||||
- 组件 CI:
|
||||
- 领域 / 消费者组合测试:
|
||||
- 修复提交与制品证据:
|
||||
@@ -0,0 +1,25 @@
|
||||
## 工单与责任仓库
|
||||
|
||||
- 责任工单:
|
||||
- 唯一责任仓库与组件 ID:
|
||||
- 本次变更是否涉及 domain、gitlink、`planned → active` 或公共合同:<是/否,说明>
|
||||
|
||||
## 组合与证据
|
||||
|
||||
- 组件提交(C2)/ 领域组合(B2)/ 根组合(A2):
|
||||
- C1/C2/C3 CI 链接:
|
||||
- 可复现命令、平台、依赖制品摘要:
|
||||
- 本次未运行 / UNVERIFIED 的项:
|
||||
|
||||
## 分层与边界检查
|
||||
|
||||
- [ ] 变更落在唯一责任仓库,聚合仓未引入生产实现
|
||||
- [ ] 未创建占位 gitlink 或伪造 active `entry`;planned 不计入验收
|
||||
- [ ] 公共合同变更与实际消费者配对候选,未引入旧协议 fallback
|
||||
- [ ] 主仓库只更新精确 gitlink、治理文件与集成脚本,未借机重构无关组件
|
||||
- [ ] 未在根或聚合脚本中加入 workaround、复制协议或绕开权限
|
||||
|
||||
## 发行与回滚
|
||||
|
||||
- 公共协议 / 制品影响:
|
||||
- 旧基线或回滚方式(恢复上一组已接受 gitlink):
|
||||
@@ -1,50 +0,0 @@
|
||||
# Build public/ with marqdo and publish to the gh-pages branch.
|
||||
name: User docs site
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [main, master]
|
||||
paths:
|
||||
- "public/**"
|
||||
- "src/**"
|
||||
- "Cargo.toml"
|
||||
- "Cargo.lock"
|
||||
- ".github/workflows/pages.yml"
|
||||
- "scripts/build-public.*"
|
||||
workflow_dispatch:
|
||||
|
||||
permissions:
|
||||
contents: write
|
||||
|
||||
jobs:
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust
|
||||
uses: dtolnay/rust-toolchain@stable
|
||||
|
||||
- name: Build & export site
|
||||
run: |
|
||||
cargo build --release
|
||||
find public -name '*.mq.md' ! -name 'utils.mq.md' -print0 \
|
||||
| xargs -0 -n1 ./target/release/marqdo run
|
||||
./target/release/marqdo view output public -o public
|
||||
|
||||
- name: Verify site shape
|
||||
run: |
|
||||
if grep -R "tests/errors" public --include='*.html' ; then
|
||||
echo "user site must not include tests/errors fixtures" >&2
|
||||
exit 1
|
||||
fi
|
||||
test -f public/index.html
|
||||
test -f public/00-welcome.mq.md
|
||||
|
||||
- name: Deploy to gh-pages
|
||||
uses: peaceiris/actions-gh-pages@v4
|
||||
with:
|
||||
github_token: ${{ secrets.GITHUB_TOKEN }}
|
||||
publish_dir: ./public
|
||||
publish_branch: gh-pages
|
||||
force_orphan: true
|
||||
Regular → Executable
+8
-17
@@ -1,18 +1,9 @@
|
||||
/target/
|
||||
**/*.rs.bk
|
||||
.idea/
|
||||
.vscode/
|
||||
*.pdb
|
||||
.DS_Store
|
||||
.marqdo/
|
||||
|
||||
# Generated HTML beside tracked public/*.mq.md (sources stay in git)
|
||||
/public/index.html
|
||||
/public/pages/
|
||||
|
||||
# Python spike venv (local)
|
||||
spike/.venv/
|
||||
spike/__pycache__/
|
||||
spike/.pytest_cache/
|
||||
.env
|
||||
.env.*
|
||||
/.migration-work/
|
||||
/.integration-work/
|
||||
/__pycache__/
|
||||
**/__pycache__/
|
||||
*.pyc
|
||||
|
||||
# Local build/cache/scratch (DSH workspace tooling)
|
||||
/.build/
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
[submodule "cli"]
|
||||
path = cli
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-cli.git
|
||||
[submodule "tests/conformance"]
|
||||
path = tests/conformance
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-extension-conformance.git
|
||||
[submodule "tools/view"]
|
||||
path = tools/view
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-view.git
|
||||
[submodule "tools/knowledge"]
|
||||
path = tools/knowledge
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-knowledge.git
|
||||
[submodule "tools/prove"]
|
||||
path = tools/prove
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-prove.git
|
||||
[submodule "tools/lint"]
|
||||
path = tools/lint
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-lint.git
|
||||
[submodule "extensions/ai"]
|
||||
path = extensions/ai
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-ai.git
|
||||
[submodule "extensions/archive"]
|
||||
path = extensions/archive
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-archive.git
|
||||
[submodule "extensions/browser"]
|
||||
path = extensions/browser
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-browser.git
|
||||
[submodule "extensions/cache"]
|
||||
path = extensions/cache
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-cache.git
|
||||
[submodule "extensions/crypto"]
|
||||
path = extensions/crypto
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-crypto.git
|
||||
[submodule "extensions/database"]
|
||||
path = extensions/database
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-database.git
|
||||
[submodule "extensions/datetime"]
|
||||
path = extensions/datetime
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-datetime.git
|
||||
[submodule "extensions/document"]
|
||||
path = extensions/document
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-document.git
|
||||
[submodule "extensions/engineering"]
|
||||
path = extensions/engineering
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-engineering.git
|
||||
[submodule "extensions/http"]
|
||||
path = extensions/http
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-http.git
|
||||
[submodule "extensions/linalg"]
|
||||
path = extensions/linalg
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-linalg.git
|
||||
[submodule "extensions/math"]
|
||||
path = extensions/math
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-math.git
|
||||
[submodule "extensions/mcp"]
|
||||
path = extensions/mcp
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-mcp.git
|
||||
[submodule "extensions/quantum"]
|
||||
path = extensions/quantum
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-quantum.git
|
||||
[submodule "extensions/regex"]
|
||||
path = extensions/regex
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-regex.git
|
||||
[submodule "extensions/security"]
|
||||
path = extensions/security
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-security.git
|
||||
[submodule "extensions/storage"]
|
||||
path = extensions/storage
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-storage.git
|
||||
[submodule "extensions/web"]
|
||||
path = extensions/web
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-web.git
|
||||
[submodule "extensions/websocket"]
|
||||
path = extensions/websocket
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-ext-websocket.git
|
||||
[submodule "stdlib/collections"]
|
||||
path = stdlib/collections
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-collections.git
|
||||
[submodule "stdlib/core"]
|
||||
path = stdlib/core
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-core.git
|
||||
[submodule "stdlib/data"]
|
||||
path = stdlib/data
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-data.git
|
||||
[submodule "stdlib/encoding"]
|
||||
path = stdlib/encoding
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-encoding.git
|
||||
[submodule "stdlib/fs"]
|
||||
path = stdlib/fs
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-fs.git
|
||||
[submodule "stdlib/io"]
|
||||
path = stdlib/io
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-io.git
|
||||
[submodule "stdlib/net"]
|
||||
path = stdlib/net
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-net.git
|
||||
[submodule "stdlib/system"]
|
||||
path = stdlib/system
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-system.git
|
||||
[submodule "stdlib/text"]
|
||||
path = stdlib/text
|
||||
url = https://git.cflmy.cn/cflmy/marqdo-std-text.git
|
||||
@@ -0,0 +1,40 @@
|
||||
when:
|
||||
event: [push, pull_request, manual]
|
||||
|
||||
steps:
|
||||
layout:
|
||||
image: rust:1.100-bookworm
|
||||
commands:
|
||||
- apt-get update && apt-get install -y --no-install-recommends ca-certificates git python3
|
||||
- python3 scripts/check-layout.py
|
||||
- python3 -m unittest discover -s tests/integration
|
||||
- git submodule update --init
|
||||
- |
|
||||
set -eu
|
||||
domains="$(python3 scripts/check-layout.py --domain-paths)"
|
||||
for domain in $domains; do
|
||||
git -C "$domain" submodule update --init
|
||||
done
|
||||
- python3 scripts/check-layout.py --checkouts
|
||||
|
||||
candidate:
|
||||
# Match the Linux/glibc environment already used by View for the RC.4 artifact.
|
||||
image: mcr.microsoft.com/playwright:v1.49.0-noble
|
||||
depends_on: [layout]
|
||||
commands:
|
||||
- |
|
||||
set -eu
|
||||
for attempt in 1 2 3; do
|
||||
if apt-get -o Acquire::By-Hash=force -o Acquire::Retries=3 update --error-on=any; then
|
||||
break
|
||||
fi
|
||||
if [ "$attempt" -eq 3 ]; then
|
||||
exit 1
|
||||
fi
|
||||
sleep 15
|
||||
done
|
||||
apt-get -o Acquire::Retries=3 install -y --no-install-recommends ca-certificates curl git python3 python3-jsonschema build-essential
|
||||
curl -fsSL --retry 3 https://sh.rustup.rs -o /tmp/marqdo-rustup.sh
|
||||
sh /tmp/marqdo-rustup.sh -y --profile minimal --default-toolchain 1.100.0 --no-modify-path
|
||||
export PATH="$HOME/.cargo/bin:$PATH"
|
||||
bash scripts/integration.sh
|
||||
@@ -0,0 +1,10 @@
|
||||
# Marqdo 维护指引
|
||||
|
||||
1. 从 [各仓库任务](docs/REPOSITORY-TASKS.md)、[组件目录](components.toml) 与 [架构边界](docs/ARCHITECTURE.md) 确定**唯一**责任仓库:功能缺陷在功能仓库,领域合同/组合在领域聚合仓库,gitlink、跨领域集成、发行组合与治理在主仓库。主仓库和聚合仓库不实现子组件业务。
|
||||
2. 治理树最多两级:根 → 领域聚合(`kind = "domain"`)→ 功能组件。每个组件只有一个父级,全局 ID 与权威远端唯一,领域聚合仓库只做治理、合同、示例和组合验收。已发布的 `planned` 仓库可以挂载真实 gitlink。激活时登记实际 `entry`,只有通过验收的 active 组件计入完成率。
|
||||
3. 找到或建立责任仓库的工单,按 `.gitea/ISSUE_TEMPLATE/change.md` 记录目标、当前提交、最小复现、公共契约、影响消费者和验收命令。跨仓库阻塞在上游开关联工单,并在消费者记录回归条件。不要按错误最终显示的仓库定责,找第一个违反公开合同的所有者。
|
||||
4. 在责任仓库独立修改、构建和测试。需要调整公共语义时,在 CLI 提交 ADR;调整 Web 作者面语义时,只在 `marqdo-ext-web` 的 [WEB-DESIGN 合同](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md) 走 ADR,并与实际消费者(Design/Preview)同候选验证;不得并列维护第二份现行规范或旧协议 fallback。
|
||||
5. 逐层晋升:功能提交 C2 通过组件 CI → 领域 PR 更新 gitlink 至 C2 并通过领域 CI(B2)→ 主仓库 PR 更新领域 gitlink 至 B2 并通过根递归校验与受影响组合验收(A2)。先推送子仓库提交,再在主仓库提交精确 gitlink;区分组件 CI、公共契约 CI 和生态 CI 证据。以 [开发流程](docs/DEVELOPMENT.md) 为准。
|
||||
6. 新接入组件先核对公开 API、直接依赖、独立入口和实际测试。空仓在 [迁移台账](docs/MIGRATION.md) 中保持 `planned`;Web 领域的 Design/Preview 子组件记录在 `marqdo-ext-web` 自己的 `components.toml`,根目录不登记其后代路径。
|
||||
7. 记录 FAIL 和 UNVERIFIED 的具体环境、命令和日志。只有实际通过且匹配候选 SHA 的证据才可用于集成与发行;模拟、mock 或原型测试不能冒充生产验收。
|
||||
8. Web 边界硬约束:不新增 CLI 核心语法或 Web 专属关键字;不复制 Markdown/语言解析器;默认不允许 HTML 注入、业务 JS 或真实网络/数据库/认证;预览是有限确定性解释,生产实现由成熟框架在目标应用仓库承担。
|
||||
Generated
-447
@@ -1,447 +0,0 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 3
|
||||
|
||||
[[package]]
|
||||
name = "aho-corasick"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstream"
|
||||
version = "0.6.21"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "43d5b281e737544384e969a5ccad3f1cdd24b48086a0fc1b2a5262a26b8f4f4a"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"anstyle-parse",
|
||||
"anstyle-query",
|
||||
"anstyle-wincon",
|
||||
"colorchoice",
|
||||
"is_terminal_polyfill",
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle"
|
||||
version = "1.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-parse"
|
||||
version = "0.2.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7644824f0aa2c7b9384579234ef10eb7efb6a0deb83f9630a49594dd9c15c2"
|
||||
dependencies = [
|
||||
"utf8parse",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-query"
|
||||
version = "1.1.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||
dependencies = [
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anstyle-wincon"
|
||||
version = "3.0.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"once_cell_polyfill",
|
||||
"windows-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "anyhow"
|
||||
version = "1.0.104"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"
|
||||
|
||||
[[package]]
|
||||
name = "ascii"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16"
|
||||
|
||||
[[package]]
|
||||
name = "assert_cmd"
|
||||
version = "2.0.14"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ed72493ac66d5804837f480ab3766c72bdfab91a65e565fc54fa9e42db0073a8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"bstr",
|
||||
"doc-comment",
|
||||
"predicates",
|
||||
"predicates-core",
|
||||
"predicates-tree",
|
||||
"wait-timeout",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "autocfg"
|
||||
version = "1.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53"
|
||||
|
||||
[[package]]
|
||||
name = "bstr"
|
||||
version = "1.13.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1f7dc094d718f2e1c1559ad110e27eeaae14a5465d3d56dd6dbd793079fbd530"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"serde_core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "chunked_transfer"
|
||||
version = "1.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901"
|
||||
|
||||
[[package]]
|
||||
name = "clap"
|
||||
version = "4.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c"
|
||||
dependencies = [
|
||||
"clap_builder",
|
||||
"clap_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_builder"
|
||||
version = "4.4.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7"
|
||||
dependencies = [
|
||||
"anstream",
|
||||
"anstyle",
|
||||
"clap_lex",
|
||||
"strsim",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_derive"
|
||||
version = "4.4.7"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
|
||||
dependencies = [
|
||||
"heck",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_lex"
|
||||
version = "0.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
|
||||
|
||||
[[package]]
|
||||
name = "colorchoice"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||
|
||||
[[package]]
|
||||
name = "difflib"
|
||||
version = "0.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8"
|
||||
|
||||
[[package]]
|
||||
name = "doc-comment"
|
||||
version = "0.3.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "780955b8b195a21ab8e4ac6b60dd1dbdcec1dc6c51c0617964b08c81785e12c9"
|
||||
|
||||
[[package]]
|
||||
name = "float-cmp"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
|
||||
dependencies = [
|
||||
"num-traits",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heck"
|
||||
version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
|
||||
|
||||
[[package]]
|
||||
name = "httpdate"
|
||||
version = "1.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "df3b46402a9d5adb4c86a0cf463f42e19994e3ee891101b1841f30a545cb49a9"
|
||||
|
||||
[[package]]
|
||||
name = "is_terminal_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.189"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3eaf3ede3fee6db1a4c2ee091bf8a8b4dccdc6d17f656fb07896ee72867612f2"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.33"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0ceec5bc11778974d1bcb055b18002eba7f4b3518b6a0081b3af5f21666da9ad"
|
||||
|
||||
[[package]]
|
||||
name = "marqdo"
|
||||
version = "0.0.3"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"assert_cmd",
|
||||
"clap",
|
||||
"predicates",
|
||||
"thiserror",
|
||||
"tiny_http",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.8.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98"
|
||||
|
||||
[[package]]
|
||||
name = "normalize-line-endings"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "61807f77802ff30975e01f4f071c8ba10c022052f98b3294119f3e615d13e5be"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
||||
dependencies = [
|
||||
"autocfg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||
|
||||
[[package]]
|
||||
name = "predicates"
|
||||
version = "3.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "68b87bfd4605926cdfefc1c3b5f8fe560e3feca9d5552cf68c466d3d8236c7e8"
|
||||
dependencies = [
|
||||
"anstyle",
|
||||
"difflib",
|
||||
"float-cmp",
|
||||
"normalize-line-endings",
|
||||
"predicates-core",
|
||||
"regex",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "predicates-core"
|
||||
version = "1.0.10"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cad38746f3166b4031b1a0d39ad9f954dd291e7854fcc0eed52ee41a0b50d144"
|
||||
|
||||
[[package]]
|
||||
name = "predicates-tree"
|
||||
version = "1.0.13"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d0de1b847b39c8131db0467e9df1ff60e6d0562ab8e9a16e568ad0fdb372e2f2"
|
||||
dependencies = [
|
||||
"predicates-core",
|
||||
"termtree",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex"
|
||||
version = "1.13.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f020237b6c8eed93db2e2cb53c00c60a8e1bc73da7d073199a1180401450218d"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-automata",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-automata"
|
||||
version = "0.4.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8fcfdb36bda0c880c5931cdc7a2bcdc8ba4556847b9d912bca70bc94708711ad"
|
||||
dependencies = [
|
||||
"aho-corasick",
|
||||
"memchr",
|
||||
"regex-syntax",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "regex-syntax"
|
||||
version = "0.8.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
|
||||
|
||||
[[package]]
|
||||
name = "serde_core"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48"
|
||||
dependencies = [
|
||||
"serde_derive",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_derive"
|
||||
version = "1.0.229"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 3.0.3",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.10.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.119"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "53e9bae58849f64dfa4f5d5ae372c8341f7305f82a3868709269343628b659a3"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "termtree"
|
||||
version = "0.5.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f50febec83f5ee1df3015341d8bd429f2d1cc62bcba7ea2076759d315084683"
|
||||
|
||||
[[package]]
|
||||
name = "thiserror"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
|
||||
dependencies = [
|
||||
"thiserror-impl",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "thiserror-impl"
|
||||
version = "1.0.69"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn 2.0.119",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny_http"
|
||||
version = "0.12.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82"
|
||||
dependencies = [
|
||||
"ascii",
|
||||
"chunked_transfer",
|
||||
"httpdate",
|
||||
"log",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.24"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
||||
|
||||
[[package]]
|
||||
name = "utf8parse"
|
||||
version = "0.2.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||
|
||||
[[package]]
|
||||
name = "wait-timeout"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09ac3b126d3914f9849036f826e054cbabdc8519970b8998ddaf3b5bd3c65f11"
|
||||
dependencies = [
|
||||
"libc",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-link"
|
||||
version = "0.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.61.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
[package]
|
||||
name = "marqdo"
|
||||
version = "0.0.3"
|
||||
edition = "2021"
|
||||
license = "Apache-2.0"
|
||||
description = "Marqdo — Markdown markers as an interpreted programming language"
|
||||
readme = "README.md"
|
||||
repository = "https://github.com/cflmy/marqdo"
|
||||
|
||||
[[bin]]
|
||||
name = "marqdo"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
anyhow = "1"
|
||||
clap = { version = "=4.4.18", features = ["derive"] }
|
||||
thiserror = "1"
|
||||
tiny_http = "0.12"
|
||||
|
||||
[dev-dependencies]
|
||||
assert_cmd = "=2.0.14"
|
||||
predicates = "=3.1.0"
|
||||
@@ -1,76 +1,133 @@
|
||||
# Marqdo
|
||||
# Marqdo
|
||||
|
||||
**代码即文档。文档即代码。**
|
||||
**Marqdo 是一门以 Markdown 为源文档的编程语言。** 用 `.mq.md` 可以把业务规则、公式、解释和可执行步骤写在同一份文档中。读者用 Markdown 阅读器查看正文,开发者用 Marqdo 检查、运行和验证其中的程序。这个仓库维护生态组件的集成、验收和发行入口。
|
||||
|
||||
Marqdo:Markdown **标记即语法**。源文件 `.mq.md` 既是文稿也是程序。
|
||||
生态治理采用有限分层:主仓库固定领域聚合仓库,领域聚合仓库固定本领域功能仓库,最多两级 Gitlink。主仓库和聚合仓库只做治理、组合与验收,不实现子组件业务;Web 领域把设计文档直接作为原型与工程交付的源材料,详见 [架构边界](docs/ARCHITECTURE.md)。
|
||||
|
||||
语法宪法:[doc/design/markdown-mapping.md](doc/design/markdown-mapping.md) · 调用实参:[call-arguments.md](doc/design/call-arguments.md) · 测试布局:[examples-and-tests.md](doc/design/examples-and-tests.md) · 用户站:[user-site.md](doc/design/user-site.md) · 浏览:[view.md](doc/design/view.md) · 金样例:[tests/](tests/) · 用户文档:[public/](public/)
|
||||
## 为什么开发 Marqdo
|
||||
|
||||
---
|
||||
规则通常写在说明文档里,实现放在脚本里,结果再写进报告。三份内容分开维护后,读者很难确认某个结果用了哪条规则,也很难重新验证。Marqdo 让解释和计算随同一份源文档修改、评审和运行。它适合写带示例的算法说明、可重跑的分析流程,以及需要交代验证过程的知识文档。
|
||||
|
||||
## 语法速览(v0.1)
|
||||
## 主要特性
|
||||
|
||||
| 标记 | 含义 |
|
||||
|------|------|
|
||||
| 无标记行 | 注释 |
|
||||
| `*…*` | 程序语句 |
|
||||
| `**…**` | **返回值**(架构) |
|
||||
| `> print …` 等 | 输出等副作用 = **普通函数**,非架构标记 |
|
||||
| `#` / `##` | 函数与作用域 |
|
||||
| `+` / `1.` | 分支(臂头单独 `*` = else) |
|
||||
| `-` | 循环(头下纯名则为形参) |
|
||||
| 表格 | 集合 |
|
||||
| `---` / `***` | 可选:框住分支/循环(不强制) |
|
||||
- **Markdown 原生**。文档保留 CommonMark/GFM 的结构,并支持公式。在 `.mq.md` 中,以 `@exec` 标明可执行区,以 `@knowledge` 标明说明与知识区。正文可以直接阅读。
|
||||
- **先检查,再运行**。`marqdo check` 静态检查语法与调用,`--refs` 检查文档引用。Analysis 提供结构化分析结果,供编辑器和独立工具使用。
|
||||
- **可观察的运行**。Rust 解释器显式运行文档代码,Observation 记录执行事件与结果。文件、网络、进程等外部操作受运行模式与能力授权约束。
|
||||
- **可组合的生态**。基础发行包含标准库。程序可以通过锁文件固定包与领域扩展的来源和摘要。阅读、知识索引、证明和静态诊断由独立工具提供。
|
||||
|
||||
```markdown
|
||||
# main
|
||||
## 快速开始
|
||||
|
||||
> print text=Hello World!
|
||||
从 [CLI 发行页](https://git.cflmy.cn/cflmy/marqdo-cli/releases) 下载适合平台的发行包。把解包目录加入 `PATH`,保持 CLI、Worker 和旁置 `stdlib/` 的目录结构。将下面的内容保存为 `hello.mq.md`。
|
||||
|
||||
## 加一
|
||||
- n
|
||||
````markdown
|
||||
# 问候示例
|
||||
|
||||
**`n` + 1**
|
||||
这一节说明程序的用途。下方函数由 CLI 执行。
|
||||
|
||||
## @exec main
|
||||
|
||||
`params()`
|
||||
|
||||
`打印("你好,Marqdo")`
|
||||
````
|
||||
|
||||
```sh
|
||||
marqdo check hello.mq.md
|
||||
marqdo run hello.mq.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 理念
|
||||
|
||||
1. 叙述默认安全(无标记 = 注释)。
|
||||
2. 返回是架构;打印只是函数。
|
||||
3. 依赖清单由工具生成(OKF 风格),不是手填配置。
|
||||
4. **正经解释器(Rust)**:词法/行分类 → 递归下降语法 → 语义 → 树遍历 → 日后字节码;**不用 Flex/Bison**。见 [路线图](doc/roadmap/interpreter.md) 与 [依赖说明](doc/design/dependencies.md)。
|
||||
|
||||
---
|
||||
|
||||
## 现状
|
||||
|
||||
- 映射 v0.1:[markdown-mapping.md](doc/design/markdown-mapping.md)
|
||||
- 解释器路线图:[interpreter.md](doc/roadmap/interpreter.md)
|
||||
- **Phase I(树遍历)已通**:`tests/structure/` 与 `tests/keywords/` 金样例均可 `marqdo run`
|
||||
- **view**:`marqdo view public` 浏览用户文档;金样例用 `marqdo view tests`
|
||||
- **用户静态站**:可执行文稿在 `public/`(无 errors);`view output` 生成 HTML(ignore),CI 发布到 `gh-pages` — 见 [user-site.md](doc/design/user-site.md)
|
||||
- 依赖(Rust,无 Flex/Bison):[dependencies.md](doc/design/dependencies.md)
|
||||
- 选型:[ADR 0001 — Rust](doc/adr/0001-implementation-language.md)
|
||||
|
||||
```bash
|
||||
cargo run -- run tests/structure/hello.mq.md
|
||||
cargo run -- run tests/structure/hello.mq.md --backend bytecode
|
||||
cargo run -- view public --no-open
|
||||
cargo run -- view output public -o public
|
||||
powershell -File ./scripts/build-public.ps1
|
||||
cargo run -- catalog tests -o .marqdo
|
||||
```text
|
||||
你好,Marqdo
|
||||
```
|
||||
|
||||
文档:用户站见 [public/](public/) 与 [user-site.md](doc/design/user-site.md);设计文稿见 [doc/](doc/);`view` 皮肤见 [view.md](doc/design/view.md);OKF 清单见 [catalog-cli.md](doc/design/catalog-cli.md)。
|
||||
[CLI 使用指南](https://git.cflmy.cn/cflmy/marqdo-cli) · [语言规范](https://git.cflmy.cn/cflmy/marqdo-cli/src/branch/master/spec/mapping.md)
|
||||
|
||||
---
|
||||
## 仓库与职责
|
||||
|
||||
## 命名
|
||||
### 已接入的核心和工具
|
||||
|
||||
**Marqdo** = Marq(Markdown)+ do(执行)
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo](https://git.cflmy.cn/cflmy/marqdo) | 生态主仓库,维护仓库索引、固定提交组合、跨仓库验收与发行 |
|
||||
| [marqdo-cli](https://git.cflmy.cn/cflmy/marqdo-cli) | 语言规范、Rust 解释器、CLI、运行权限和公开协议 |
|
||||
| [marqdo-extension-conformance](https://git.cflmy.cn/cflmy/marqdo-extension-conformance) | 用冻结的真实 CLI 独立验收包、插件、Provider、Foreign 和 Tool |
|
||||
| [marqdo-knowledge](https://git.cflmy.cn/cflmy/marqdo-knowledge) | 使用公开 Analysis 编译、索引和检索知识文档 |
|
||||
| [marqdo-prove](https://git.cflmy.cn/cflmy/marqdo-prove) | 处理证明依赖、Lean 证书与独立重放 |
|
||||
| [marqdo-view](https://git.cflmy.cn/cflmy/marqdo-view) | 阅读和预览文档、显示执行观察、静态导出 |
|
||||
| [marqdo-lint](https://git.cflmy.cn/cflmy/marqdo-lint) | 静态规则、诊断定位与显式修复 |
|
||||
|
||||
## 许可
|
||||
### 独立产品
|
||||
|
||||
[Apache License 2.0](LICENSE)
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-site](https://git.cflmy.cn/cflmy/marqdo-site) | 官网、入门文档、静态站点构建与托管 |
|
||||
| [marqdo-vscode](https://git.cflmy.cn/cflmy/marqdo-vscode) | VS Code 文件关联、编辑体验、CLI 集成与 VSIX 发布 |
|
||||
|
||||
### 标准库
|
||||
|
||||
标准库组件负责低层通用能力,验收后共同组成基础发行的标准库 Bundle。`stdlib/` 的子模块固定各独立仓库的开发提交,状态为 `planned`。 [标准库目录](stdlib/README.md)
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-std-core](https://git.cflmy.cn/cflmy/marqdo-std-core) | Result 与基础数值 |
|
||||
| [marqdo-std-collections](https://git.cflmy.cn/cflmy/marqdo-std-collections) | List、Map 和 Table 值操作 |
|
||||
| [marqdo-std-text](https://git.cflmy.cn/cflmy/marqdo-std-text) | Unicode 文本、字节值与 UTF-8 |
|
||||
| [marqdo-std-encoding](https://git.cflmy.cn/cflmy/marqdo-std-encoding) | Base64、Base32 和 Hex |
|
||||
| [marqdo-std-data](https://git.cflmy.cn/cflmy/marqdo-std-data) | JSON、CSV、TOML 与 GFM 数据转换 |
|
||||
| [marqdo-std-io](https://git.cflmy.cn/cflmy/marqdo-std-io) | Console、Stream、格式化和官方 print 别名 |
|
||||
| [marqdo-std-fs](https://git.cflmy.cn/cflmy/marqdo-std-fs) | 文件、目录与路径 |
|
||||
| [marqdo-std-system](https://git.cflmy.cn/cflmy/marqdo-std-system) | 时钟、UTC、环境、进程与随机 |
|
||||
| [marqdo-std-net](https://git.cflmy.cn/cflmy/marqdo-std-net) | TCP、UDP、TLS 和网络字节流 |
|
||||
|
||||
### 领域扩展
|
||||
|
||||
领域扩展负责按需安装的算法、协议和业务能力。`extensions/` 的子模块链接各独立仓库,功能从 `planned` 状态开始开发。 [领域扩展目录](extensions/README.md)
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-ext-math](https://git.cflmy.cn/cflmy/marqdo-ext-math) | 数值算法、统计、符号数学及绘图 |
|
||||
| [marqdo-ext-linalg](https://git.cflmy.cn/cflmy/marqdo-ext-linalg) | 复数、矩阵、分解及数值线性代数 |
|
||||
| [marqdo-ext-quantum](https://git.cflmy.cn/cflmy/marqdo-ext-quantum) | 量子电路、态向量、采样与模拟 |
|
||||
| [marqdo-ext-http](https://git.cflmy.cn/cflmy/marqdo-ext-http) | HTTP、URL、SSE 与报文生命周期 |
|
||||
| [marqdo-ext-websocket](https://git.cflmy.cn/cflmy/marqdo-ext-websocket) | WebSocket 握手、帧与连接语义 |
|
||||
| [marqdo-ext-ai](https://git.cflmy.cn/cflmy/marqdo-ext-ai) | 模型协议、流式输出与工具调用数据 |
|
||||
| [marqdo-ext-mcp](https://git.cflmy.cn/cflmy/marqdo-ext-mcp) | MCP 协议、传输、发现和调用 |
|
||||
| [marqdo-ext-crypto](https://git.cflmy.cn/cflmy/marqdo-ext-crypto) | 成熟密码学实现的封装 |
|
||||
| [marqdo-ext-database](https://git.cflmy.cn/cflmy/marqdo-ext-database) | SQL 参数绑定、事务和驱动连接 |
|
||||
| [marqdo-ext-storage](https://git.cflmy.cn/cflmy/marqdo-ext-storage) | 本地和对象存储接口 |
|
||||
| [marqdo-ext-cache](https://git.cflmy.cn/cflmy/marqdo-ext-cache) | TTL、缓存和失效 |
|
||||
| [marqdo-ext-security](https://git.cflmy.cn/cflmy/marqdo-ext-security) | 应用身份、会话及权限模型 |
|
||||
| [marqdo-ext-browser](https://git.cflmy.cn/cflmy/marqdo-ext-browser) | 浏览器宿主、WASM 适配、DOM 和事件 |
|
||||
| [marqdo-ext-document](https://git.cflmy.cn/cflmy/marqdo-ext-document) | Markdown 结构与显式文档编辑 |
|
||||
| [marqdo-ext-archive](https://git.cflmy.cn/cflmy/marqdo-ext-archive) | 压缩、安全归档和解包 |
|
||||
| [marqdo-ext-engineering](https://git.cflmy.cn/cflmy/marqdo-ext-engineering) | 工程操作、文件补丁与产物 |
|
||||
| [marqdo-ext-regex](https://git.cflmy.cn/cflmy/marqdo-ext-regex) | 正则匹配、捕获、扫描和替换 |
|
||||
| [marqdo-ext-datetime](https://git.cflmy.cn/cflmy/marqdo-ext-datetime) | IANA 时区、DST 和高级日历 |
|
||||
|
||||
### Web 领域聚合
|
||||
|
||||
Web 领域以设计文档为源材料,面向可交互的原型预览与工程交付。HTTP、数据库、认证和浏览器运行时各自独立维护。`extensions/web` 链接 `planned` 的 Web 领域仓,Design 和 Preview 由该领域仓固定。 [WEB-DESIGN](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md)
|
||||
|
||||
| 仓库 | 职责 |
|
||||
| --- | --- |
|
||||
| [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) | Web 领域聚合:唯一设计合同、示例、组合验收与交付协调,不含生产实现 |
|
||||
| [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) | 设计文档解释、校验、组件/依赖图、诊断与 handoff(独立 Rust library) |
|
||||
| [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview) | 通用离线预览渲染、有限状态交互与 `web` Tool 发行 |
|
||||
|
||||
## 参与开发
|
||||
|
||||
在负责的独立仓库提交实现和测试。主仓库用 Git 子模块按“根 → 领域 → 功能”最多两级固定提交,组件的发行状态由 catalog 独立记录。需要获取当前组合时,运行:
|
||||
|
||||
```sh
|
||||
git clone https://git.cflmy.cn/cflmy/marqdo.git
|
||||
cd marqdo
|
||||
git submodule update --init --recursive
|
||||
python3 scripts/check-layout.py --checkouts
|
||||
python3 -m unittest discover -s tests/integration
|
||||
```
|
||||
|
||||
`check-layout.py` 校验每层 catalog、gitlink、权威远端、全局 ID 和依赖图。`--checkouts` 同时核对递归检出的实际提交。`planned` 子模块提供固定开发快照,只有 `active` 组件进入发行验收。
|
||||
|
||||
[各仓库任务](docs/REPOSITORY-TASKS.md) · [组件目录](components.toml) · [架构边界](docs/ARCHITECTURE.md) · [开发流程](docs/DEVELOPMENT.md) · [迁移台账](docs/MIGRATION.md) · [架构决策记录](docs/adr/README.md) · [AGENTS](AGENTS.md)
|
||||
|
||||
旧版实现与文档可在历史标签查阅。 [v2.9.1 历史树](https://git.cflmy.cn/cflmy/marqdo/src/tag/v2.9.1)
|
||||
Submodule
+1
Submodule cli added at deadf6edee.
+393
@@ -0,0 +1,393 @@
|
||||
# 生态组件职责与构建关系。精确提交由 Git tree 的 gitlink 锁定。
|
||||
# 治理树最多两级:根 → 领域聚合(kind = "domain")→ 功能组件。每个聚合仓库只登记直属子组件,
|
||||
# 递归展平后全局 ID 与权威远端唯一;禁止在根同时登记某个计划中聚合及其后代路径。
|
||||
# kind = "domain" 是治理角色:requires = [],release 为 none(普通领域)或 base(Stdlib Bundle 聚合),
|
||||
# 聚合仓自身不含生产实现;其子组件在领域仓库自己的 components.toml 登记。
|
||||
# planned 的 requires 是设计输入,激活前须核对实际 imports 和发布依赖。
|
||||
# 已发布的仓库提交可以作为 planned gitlink 固定,发行验收以 active 状态为准。
|
||||
|
||||
[[component]]
|
||||
id = "cli"
|
||||
path = "cli"
|
||||
kind = "core"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "语言语义、运行时、受控宿主和公共协议"
|
||||
requires = []
|
||||
checks_with = ["conformance"]
|
||||
release = "base"
|
||||
entry = "tools/release/smoke.py"
|
||||
|
||||
[[component]]
|
||||
id = "conformance"
|
||||
path = "tests/conformance"
|
||||
kind = "test"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "可执行的独立公共协议测试"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "none"
|
||||
entry = "scripts/build_all.sh"
|
||||
|
||||
[[component]]
|
||||
id = "view"
|
||||
path = "tools/view"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "阅读、运行观察与静态导出"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/acceptance.sh"
|
||||
|
||||
[[component]]
|
||||
id = "knowledge"
|
||||
path = "tools/knowledge"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "静态知识编译与检索"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/ci.sh"
|
||||
|
||||
[[component]]
|
||||
id = "prove"
|
||||
path = "tools/prove"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "证明依赖、证书及 Lean 后端"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/package-tool.sh"
|
||||
|
||||
[[component]]
|
||||
id = "lint"
|
||||
path = "tools/lint"
|
||||
kind = "tool"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "静态规则、诊断及显式修复"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
entry = "scripts/package-tool.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-core"
|
||||
path = "stdlib/core"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Result 与基础数值"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
|
||||
[[component]]
|
||||
id = "std-collections"
|
||||
path = "stdlib/collections"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "List、Map 和 Table 值操作"
|
||||
requires = ["cli"]
|
||||
checks_with = ["std-data"]
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-text"
|
||||
path = "stdlib/text"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "Unicode 文本、字节值与 UTF-8"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-encoding"
|
||||
path = "stdlib/encoding"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Base64、Base32 和 Hex"
|
||||
requires = ["cli", "std-core", "std-text"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
|
||||
[[component]]
|
||||
id = "std-data"
|
||||
path = "stdlib/data"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "JSON、CSV、TOML 与 GFM 数据转换"
|
||||
requires = ["cli"]
|
||||
checks_with = ["std-collections"]
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-io"
|
||||
path = "stdlib/io"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "Console、Stream、格式化和官方 print 别名"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-fs"
|
||||
path = "stdlib/fs"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "文件、目录与路径"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-system"
|
||||
path = "stdlib/system"
|
||||
kind = "stdlib"
|
||||
state = "active"
|
||||
owner = "cflmy"
|
||||
scope = "时钟、UTC、环境、进程与随机"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
entry = "scripts/test.sh"
|
||||
|
||||
[[component]]
|
||||
id = "std-net"
|
||||
path = "stdlib/net"
|
||||
kind = "stdlib"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "TCP、UDP、TLS 和网络字节流"
|
||||
requires = ["cli", "std-io", "std-system"]
|
||||
checks_with = []
|
||||
release = "base"
|
||||
|
||||
[[component]]
|
||||
id = "math"
|
||||
path = "extensions/math"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "数值算法、统计、符号数学及绘图"
|
||||
requires = ["cli", "std-core", "std-collections", "std-text"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "linalg"
|
||||
path = "extensions/linalg"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "复数、矩阵、分解及数值线性代数"
|
||||
requires = ["cli", "math"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "quantum"
|
||||
path = "extensions/quantum"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "量子电路、态向量、采样与模拟"
|
||||
requires = ["cli", "linalg"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "http"
|
||||
path = "extensions/http"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "HTTP、URL、SSE 与报文生命周期"
|
||||
requires = ["cli", "std-net", "std-text", "std-encoding"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "websocket"
|
||||
path = "extensions/websocket"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "WebSocket 握手、帧与连接语义"
|
||||
requires = ["cli", "http"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "ai"
|
||||
path = "extensions/ai"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "模型协议、流式输出与工具调用数据"
|
||||
requires = ["cli", "http", "std-data"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "mcp"
|
||||
path = "extensions/mcp"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "MCP 协议、传输、发现和调用"
|
||||
requires = ["cli", "http", "std-system"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "crypto"
|
||||
path = "extensions/crypto"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "成熟密码学实现的封装"
|
||||
requires = ["cli", "std-encoding"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "database"
|
||||
path = "extensions/database"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "SQL 参数绑定、事务和驱动连接"
|
||||
requires = ["cli", "std-data"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "storage"
|
||||
path = "extensions/storage"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "本地和对象存储接口"
|
||||
requires = ["cli", "std-fs"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "cache"
|
||||
path = "extensions/cache"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "TTL、缓存和失效"
|
||||
requires = ["cli", "std-system"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "security"
|
||||
path = "extensions/security"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "应用身份、会话及权限模型"
|
||||
requires = ["cli", "crypto", "http"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "web"
|
||||
path = "extensions/web"
|
||||
kind = "domain"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Web 原型设计领域治理:唯一设计合同、组合验收与交付协调"
|
||||
requires = []
|
||||
checks_with = []
|
||||
release = "none"
|
||||
|
||||
[[component]]
|
||||
id = "browser"
|
||||
path = "extensions/browser"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "浏览器宿主、WASM 适配、DOM 和事件"
|
||||
requires = ["cli"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "document"
|
||||
path = "extensions/document"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "Markdown 结构与显式文档编辑"
|
||||
requires = ["cli", "std-fs", "std-text"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "archive"
|
||||
path = "extensions/archive"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "压缩、安全归档和解包"
|
||||
requires = ["cli", "std-text", "std-fs"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "engineering"
|
||||
path = "extensions/engineering"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "工程操作、文件补丁与产物"
|
||||
requires = ["cli", "document", "archive"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "regex"
|
||||
path = "extensions/regex"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "正则匹配、捕获、扫描和替换"
|
||||
requires = ["cli", "std-text"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
|
||||
[[component]]
|
||||
id = "datetime"
|
||||
path = "extensions/datetime"
|
||||
kind = "extension"
|
||||
state = "planned"
|
||||
owner = "cflmy"
|
||||
scope = "IANA 时区、DST 和高级日历"
|
||||
requires = ["cli", "std-system"]
|
||||
checks_with = []
|
||||
release = "optional"
|
||||
@@ -1,43 +0,0 @@
|
||||
# Marqdo 开发文档
|
||||
|
||||
本目录存放各阶段设计、选型与路线图。
|
||||
|
||||
## 目录约定
|
||||
|
||||
| 路径 | 用途 |
|
||||
|------|------|
|
||||
| [`research/`](research/) | 外部标准与调研 |
|
||||
| [`design/`](design/) | 语言设计(语法映射等) |
|
||||
| [`adr/`](adr/) | 架构决策记录 |
|
||||
| [`roadmap/`](roadmap/) | 实现路线与里程碑 |
|
||||
|
||||
## 当前文档
|
||||
|
||||
| 文档 | 摘要 |
|
||||
|------|------|
|
||||
| [design/markdown-mapping.md](design/markdown-mapping.md) | **v0.1 语法宪法** |
|
||||
| [design/code-vs-comment.md](design/code-vs-comment.md) | 叙述 / 可执行 / 外联 |
|
||||
| [design/return-hr-and-code-surface.md](design/return-hr-and-code-surface.md) | 语句/返回/输出决议 |
|
||||
| [design/generated-yaml-manifest.md](design/generated-yaml-manifest.md) | 生成式 OKF 清单 |
|
||||
| [design/tech-stack.md](design/tech-stack.md) | 实现栈对比 |
|
||||
| [adr/0001-implementation-language.md](adr/0001-implementation-language.md) | **Accepted:Rust 参考解释器;不用 Flex/Bison** |
|
||||
| [design/dependencies.md](design/dependencies.md) | 依赖详单(无 Flex/Bison) |
|
||||
| [design/keywords.md](design/keywords.md) | **英文最小关键字 / 内置 `print` `input`** |
|
||||
| [design/call-arguments.md](design/call-arguments.md) | **调用:具名 + 位置实参** |
|
||||
| [design/examples-and-tests.md](design/examples-and-tests.md) | **tests/ 金样例目录布局** |
|
||||
| [design/view.md](design/view.md) | **`marqdo view` / `view output` 黑白极简 + 静态文档** |
|
||||
| [design/user-site.md](design/user-site.md) | **用户站:`public/` → `gh-pages`** |
|
||||
| [design/catalog-cli.md](design/catalog-cli.md) | **`marqdo catalog` / `sync` OKF 清单命令** |
|
||||
| [design/bytecode.md](design/bytecode.md) | **M5 字节码 / 双后端** |
|
||||
| [design/pipeline-debug.md](design/pipeline-debug.md) | **流水线 `--dump-*` 可视调试** |
|
||||
| [dev-setup.md](dev-setup.md) | 开发环境配置(Rust M0) |
|
||||
| [roadmap/interpreter.md](roadmap/interpreter.md) | 正经解释器路线图 |
|
||||
| [research/okf-and-marqdo.md](research/okf-and-marqdo.md) | OKF 调研 |
|
||||
|
||||
金样例与集成测试:[`tests/`](../tests/)。面向访客的可执行文档:[`public/`](../public/)。Spike 存档:[`spike/`](../spike/)。
|
||||
|
||||
## 写作原则
|
||||
|
||||
1. 先宪法与路线图,再实现。
|
||||
2. 金样例不过 = 未完成。
|
||||
3. 示例统一 `.mq.md`。
|
||||
@@ -1,53 +0,0 @@
|
||||
# ADR 0001:参考实现语言与前端工具
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **Accepted**(修订:实现语言 = Rust) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 决策者 | chaungming + 协作 |
|
||||
| 相关 | [dependencies.md](../design/dependencies.md) · [interpreter 路线图](../roadmap/interpreter.md) · [spike/REPORT.md](../../spike/REPORT.md) |
|
||||
|
||||
---
|
||||
|
||||
## 背景
|
||||
|
||||
语法宪法 v0.1 已定;Python Spike 已验证 GFM/行扫描风险。产品目标是正经**解释器**(`marqdo run index.mq.md`),实现语言需兼顾安全与可维护性。
|
||||
|
||||
---
|
||||
|
||||
## 决策
|
||||
|
||||
1. **参考解释器实现语言:Rust(stable)**
|
||||
- 内存安全、单静态二进制、适合长期演进到字节码 VM。
|
||||
- Python Spike **保留为算法原型/对照**,不是运行时依赖。
|
||||
|
||||
2. **词法 / 语法:不使用 Flex、Bison**
|
||||
- **主因是 Marqdo 的 Markdown 语法形态**,不是「因为选了 Rust」。换成 C++ 同样不建议用 Flex/Bison 做整语言前端。
|
||||
- 解释器需要词法·语法**阶段**;采用自研行分类 + GFM 库 + **手写递归下降** → AST。
|
||||
- 详见 [dependencies.md](../design/dependencies.md)。
|
||||
|
||||
3. **架构分期不变**
|
||||
- Phase I:树遍历解释器
|
||||
- Phase II:字节码 + VM
|
||||
- 见 [interpreter.md](../roadmap/interpreter.md)
|
||||
|
||||
4. **Markdown 库**
|
||||
- `pulldown-cmark` 或 `comrak` 二选一(建包前短 Spike 钉死)。
|
||||
|
||||
---
|
||||
|
||||
## 后果
|
||||
|
||||
- 正式代码以 Cargo 工程生长;不把 Flex/Bison/LLVM 列入 v1 依赖。
|
||||
- 金样例仍为 `tests/`;行为与宪法一致。
|
||||
- 此前「Python 作参考实现」的倾向由本修订取代;Spike 结论(行扫描等)仍然有效并迁入 Rust。
|
||||
|
||||
---
|
||||
|
||||
## 否决
|
||||
|
||||
| 方案 | 原因 |
|
||||
|------|------|
|
||||
| Flex + Bison 作主前端 | 与 Markup-as-Syntax / Rust 栈错配;解释器非必需 |
|
||||
| v1 上 LLVM | 产品是解释执行文档,不是机器后端 |
|
||||
| 仅 Python 正则玩具 | 达不到安全与长期目标 |
|
||||
@@ -1,89 +0,0 @@
|
||||
# Marqdo 字节码(M5 原型)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 进行中(原型) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 相关 | [roadmap/interpreter.md](../roadmap/interpreter.md) · Phase I 树遍历 |
|
||||
|
||||
---
|
||||
|
||||
## 1. 目标
|
||||
|
||||
在保留树遍历后端(`--backend tree`,默认)的同时,提供栈式字节码 VM(`--backend bytecode`),使**核心金样例** stdout 与树遍历 bit 一致。
|
||||
|
||||
```
|
||||
.mq.md → load/parse → Module AST
|
||||
├─ tree-walk
|
||||
└─ compile → Chunk → VM
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 2. 指令集(草案 / 原型已实现子集)
|
||||
|
||||
| Op | 栈效应 | 说明 |
|
||||
|----|--------|------|
|
||||
| `Constant i` | → v | 常量池 |
|
||||
| `True` / `False` / `None` | → b | |
|
||||
| `Pop` | v → | |
|
||||
| `GetLocal i` / `SetLocal i` | | 当前帧槽 |
|
||||
| `GetGlobal i` / `SetGlobal i` | | 名字在常量池(文本) |
|
||||
| `Add` `Sub` `Mul` `Div` `Negate` `Not` | | |
|
||||
| `Equal` `NotEqual` `Greater` `GreaterEqual` `Less` `LessEqual` | | |
|
||||
| `Jump a` / `JumpIfFalse a` / `JumpBack a` | | 相对/绝对跳转(原型用绝对 u16) |
|
||||
| `Print` | v → | 弹出并写 stdout |
|
||||
| `BuildList n` | v… → list | |
|
||||
| `GetIndex` | list, i → v | foreach 用 |
|
||||
| `Call f argc` | args… → ret | 用户函数(按形参序压栈) |
|
||||
| `Return` | | 返回 / 结束帧 |
|
||||
| `Interp n` | parts… → text | n 个交错 Lit/Var 标记后的拼接(简化:编译期展开为常量+拼接) |
|
||||
|
||||
原型实现以 `src/bytecode/` 为准;未列出的 Op 不存在于当前构建。
|
||||
|
||||
---
|
||||
|
||||
## 3. 编译约定
|
||||
|
||||
- 每个 Marqdo `Function` → 一个 `FnChunk`(含 `name`、`params`、`code`、`constants`)。
|
||||
- 模块级 `Program`:函数表 + 入口名(`main` 或唯一无参 level-1)。
|
||||
- 局部变量:函数体内首次赋值/形参分配槽位。
|
||||
- 嵌套 `##`:编入同一 `Program`,按名 `Call`;查找规则对齐树遍历(子树优先,再顶层)。
|
||||
- `and` / `or`:短接跳转。
|
||||
- 分支 / while:`JumpIfFalse` + `Jump` / `JumpBack`。
|
||||
- foreach:`BuildList` 或已有 list 全局/局部 → 索引循环。
|
||||
|
||||
---
|
||||
|
||||
## 4. 覆盖表(M5 原型)
|
||||
|
||||
| 金样例 | tree | bytecode |
|
||||
|--------|------|----------|
|
||||
| `structure/hello` | ✅ | ✅ |
|
||||
| `structure/branch` | ✅ | ✅ |
|
||||
| `structure/loop` | ✅ | ✅ |
|
||||
| `structure/collection` | ✅ | ✅ |
|
||||
| `keywords/print` | ✅ | ✅ |
|
||||
| `keywords/bool-logic` | ✅ | ✅ |
|
||||
| `structure/nested-call` | ✅ | ✅ |
|
||||
| `structure/positional-call` | ✅ | ✅ |
|
||||
| `structure/import/*` | ✅ | ✅(load 合并 AST 后编译) |
|
||||
| `tests/errors/*` | ✅(非零退出) | 同 tree 语义(编译期/运行期诊断) |
|
||||
|
||||
核心金样例双后端已对齐;后续可扩展 Op、优化与更好的调试信息。
|
||||
|
||||
---
|
||||
|
||||
## 5. CLI
|
||||
|
||||
```bash
|
||||
marqdo run FILE --backend tree # 默认
|
||||
marqdo run FILE --backend bytecode
|
||||
marqdo run FILE --dump-bytecode # 反汇编后仍可按 backend 执行
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 6. 非目标(本原型)
|
||||
|
||||
优化、寄存器分配、GC、与树遍历指令级调试对齐、独立 sema IR。
|
||||
@@ -1,50 +0,0 @@
|
||||
# 调用实参:具名与位置
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定(v0.1 增补) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 相关 | [markdown-mapping.md](markdown-mapping.md) · [keywords.md](keywords.md) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 目标
|
||||
|
||||
`>` 调用同时支持:
|
||||
|
||||
| 形式 | 示例 | 说明 |
|
||||
|------|------|------|
|
||||
| **具名**(保留) | `> 问候 谁=Marqdo` | `名=值`;值可含空格(至下一 `名=`) |
|
||||
| **位置**(新增) | `> 问候 Marqdo` | 按形参声明顺序绑定 |
|
||||
|
||||
二者可混用:位置实参按「尚未被具名绑定的形参」从左到右填充。具名不可绑定同一形参两次;位置实参不得出现在「已出现具名实参」之后(对齐常见「位置在前、关键字在后」习惯)。
|
||||
|
||||
---
|
||||
|
||||
## 2. 文法(调用尾部)
|
||||
|
||||
```
|
||||
call_tail ::= callee arg*
|
||||
arg ::= named | positional
|
||||
named ::= ident '=' value
|
||||
positional ::= value_token
|
||||
```
|
||||
|
||||
- `value`(具名右侧):可含空格与 `` `var` `` 插值,直到下一个 `ident=` 边界。
|
||||
- `value_token`(位置):空白分隔的一个词法单元——数字、`` `名` ``、标识/文本词;**不含空格**。多词字符串请用具名,例如 `> print text=Hello World!`。
|
||||
- 内置 `print` 形参名为 `text`:`> print Hi` 与 `> print text=Hi` 等价。
|
||||
|
||||
---
|
||||
|
||||
## 3. 绑定算法
|
||||
|
||||
1. 收集具名 → 映射;冲突则报错。
|
||||
2. 按函数形参表顺序:若具名已提供则用之,否则取下一个位置实参。
|
||||
3. 位置实参有余、或必填形参仍缺 → 报错(内置 `input` 的 `prompt` 可缺省)。
|
||||
4. 用户函数:额外具名键仍写入调用环境(便于扩展);位置实参不可超过形参数目。
|
||||
|
||||
---
|
||||
|
||||
## 4. 金样例
|
||||
|
||||
见 `tests/structure/positional-call.mq.md` 与更新后的 `tests/structure/import/`。
|
||||
@@ -1,128 +0,0 @@
|
||||
# OKF 兼容清单:`marqdo catalog`
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定(v0 命令落地) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 取代 | [generated-yaml-manifest.md](generated-yaml-manifest.md) 中「待决:sync/doc 命令」的命令名部分 |
|
||||
| 相关 | [generated-yaml-manifest.md](generated-yaml-manifest.md) · [view.md](view.md) · [okf-and-marqdo.md](../research/okf-and-marqdo.md) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 决策(重申)
|
||||
|
||||
YAML / OKF 风格清单是**从 `.mq.md` 派生的生成物**,不是手写配置。详见 [generated-yaml-manifest.md](generated-yaml-manifest.md)。
|
||||
|
||||
本文件规定 **CLI 与 v0 落盘格式**。
|
||||
|
||||
---
|
||||
|
||||
## 2. CLI
|
||||
|
||||
```bash
|
||||
marqdo catalog [PATH] -o OUT_DIR
|
||||
# 别名(与早期草案一致)
|
||||
marqdo sync [PATH] -o OUT_DIR
|
||||
```
|
||||
|
||||
| 参数 | 默认 | 说明 |
|
||||
|------|------|------|
|
||||
| `PATH` | `.` | 工程根或含 `.mq.md` 的目录(递归扫描) |
|
||||
| `-o` / `--out` | `.marqdo` | 生成目录(写入前创建;**覆盖**同名生成文件) |
|
||||
|
||||
退出码:成功 0;无可扫描文件或 IO/解析失败非 0(单文件解析失败时写入 `diagnostics` 并继续其余文件,最终若有失败则非 0)。
|
||||
|
||||
---
|
||||
|
||||
## 3. 生成物(v0)
|
||||
|
||||
```
|
||||
OUT_DIR/
|
||||
catalog.yaml # 机器向总清单(OKF 风格字段)
|
||||
index.md # 人/Agent 可读总览(含 YAML frontmatter)
|
||||
modules/
|
||||
<stem>.md # 每个 .mq.md 一个概念页(frontmatter + 摘要)
|
||||
```
|
||||
|
||||
路径中的目录层级拍扁为文件名时用 `__` 连接,例如:
|
||||
|
||||
`structure/import/main.mq.md` → `modules/structure__import__main.md`
|
||||
|
||||
### 3.1 `catalog.yaml`(示意)
|
||||
|
||||
```yaml
|
||||
# GENERATED by marqdo — do not edit by hand
|
||||
type: Marqdo Catalog
|
||||
title: marqdo-project
|
||||
generated:
|
||||
by: marqdo/0.0.1
|
||||
# at: 可选 ISO8601;CI 比对时可忽略
|
||||
modules:
|
||||
- id: structure/hello
|
||||
resource: structure/hello.mq.md
|
||||
title: Hello World # 来自源 frontmatter title,缺省用文件名
|
||||
imports: []
|
||||
exports:
|
||||
- name: Hello World
|
||||
kind: fn
|
||||
- id: structure/import/main
|
||||
resource: structure/import/main.mq.md
|
||||
imports:
|
||||
- utils.mq.md
|
||||
exports:
|
||||
- name: main
|
||||
kind: fn
|
||||
```
|
||||
|
||||
字段约定(v0 最小集):
|
||||
|
||||
| 字段 | 含义 |
|
||||
|------|------|
|
||||
| `type` | 固定 `Marqdo Catalog`(OKF:未知 type 可降级) |
|
||||
| `modules[].resource` | 相对 `PATH` 的源路径 |
|
||||
| `modules[].imports` | 源 frontmatter 中的 `> *.mq.md` |
|
||||
| `modules[].exports` | 顶层 `#` 函数名(`kind: fn`);嵌套 `##` 列入 `children`(可选,v0 可扁平只列顶层) |
|
||||
| `generated.by` | `marqdo/<crate version>` |
|
||||
|
||||
不在 v0:版本锁定哈希、跨仓 URL、完整符号类型。
|
||||
|
||||
### 3.2 模块概念页 frontmatter
|
||||
|
||||
```yaml
|
||||
---
|
||||
type: Marqdo Module
|
||||
title: …
|
||||
resource: structure/hello.mq.md
|
||||
depends: [] # imports 列表
|
||||
exports: [Hello World]
|
||||
generated:
|
||||
by: marqdo/0.0.1
|
||||
---
|
||||
```
|
||||
|
||||
正文含「请勿手改」提示、依赖列表、导出列表;可链到同包其它模块页。
|
||||
|
||||
---
|
||||
|
||||
## 4. 与 `view output` 的分工
|
||||
|
||||
| 命令 | 产物 | 受众 |
|
||||
|------|------|------|
|
||||
| `marqdo view output` | 静态 HTML(结构 + 运行结果) | 人类读程序文档站 |
|
||||
| `marqdo catalog` | OKF 风格 YAML + Markdown 索引 | 工具 / Agent / 依赖总览 |
|
||||
|
||||
二者都从同一源树生成,互不替代。发布用户文档时可同时:
|
||||
|
||||
```bash
|
||||
marqdo view output public -o public
|
||||
marqdo catalog tests -o .marqdo
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 验收
|
||||
|
||||
1. `marqdo catalog tests -o /tmp/mq-cat` 写出 `catalog.yaml` 与 `modules/`。
|
||||
2. `catalog.yaml` 含 `structure/hello` 与 import 模块的 `imports: [utils.mq.md]`。
|
||||
3. 文件头或 `generated` 标明 GENERATED;文档声明勿手改。
|
||||
4. `marqdo sync` 与 `catalog` 行为一致。
|
||||
@@ -1,37 +0,0 @@
|
||||
# 可执行面与叙述面
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 与 mapping v0.1 / keywords 对齐(成段注释) |
|
||||
| 日期 | 2026-08-04 |
|
||||
|
||||
---
|
||||
|
||||
## 三层
|
||||
|
||||
| 层 | 形态 | 角色 |
|
||||
|----|------|------|
|
||||
| **叙述面** | 成段注释(空行分段) | 注释;段内任意标记无语义 |
|
||||
| **Marqdo 可执行面** | 结构标记 + `*语句*` + `**返回**` | 本语言程序 |
|
||||
| **外联面** | ` ```lang ` | 其它语言(FFI) |
|
||||
|
||||
输出属于可执行面里的**函数调用**(`> print …`),见 [keywords.md](keywords.md)。
|
||||
|
||||
### 成段注释
|
||||
|
||||
- 以**空行**划分段落。
|
||||
- 段首行:首字符非标记 → 注释。
|
||||
- 段内续行:一律注释(即使以 `` ` `` / `-` 等开头)。
|
||||
- 叙述段与可执行代码之间**必须空一行**,否则 `> print` 等会被吞进注释段。
|
||||
|
||||
---
|
||||
|
||||
## 语句 vs 返回 vs 输出
|
||||
|
||||
| 标记/形式 | 角色 | 是否架构级 |
|
||||
|-----------|------|------------|
|
||||
| `*…*` | 程序语句 | 是 |
|
||||
| `**…**` | 返回值 | 是 |
|
||||
| `****` / 空粗体 | 空返回 + 结束函数体 | 是 |
|
||||
| `> print …` | 打印副作用 | 否(内置函数) |
|
||||
| 函数体 `---` / `***` | 结束函数体 | 是(边界) |
|
||||
@@ -1,174 +0,0 @@
|
||||
# Marqdo 实现依赖说明(Rust 参考解释器)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定 |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 相关 | [ADR 0001](../adr/0001-implementation-language.md) · [interpreter 路线图](../roadmap/interpreter.md) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 要不要 Flex / Bison?
|
||||
|
||||
### 结论:**不需要。** 主因不是「用了 Rust」,而是 **Marqdo 的语法形态 + 解释器并不绑定生成器。**
|
||||
|
||||
把两件事分开:
|
||||
|
||||
| 问题 | 答案 |
|
||||
|------|------|
|
||||
| 因为 Rust 才不用 Flex/Bison? | **否。** Flex/Bison 生成的是 C(也可接 C++)。若实现改成 **C++**,**仍然不建议**用它们做 Marqdo 主前端。 |
|
||||
| 因为是解释器才不用? | **部分相关,但不是全部。** 解释器**需要**词法/语法阶段,但**不规定**必须用 Flex/Bison;手写递归下降是主流。即便将来做「编译到字节码/原生」,Marqdo 也因 Markdown 外壳而不适合整语言 Bison 化。 |
|
||||
| 真正主因 | **Markup-as-Syntax**:源是 GFM 文档结构(标题/列表/强调/表格/行分类),不是 Cminusf 那种纯字符流文法。 |
|
||||
|
||||
| 工具 | 典型用途 | Marqdo 为何不用(与宿主语言无关) |
|
||||
|------|----------|----------------------------------|
|
||||
| **Flex** | 正则 → C 词法分析器 | 「词法」是 **行分类 + Markdown 标记**,不是经典 `id\|num\|op` 字符流 |
|
||||
| **Bison** | Yacc 文法 → C LR 分析器 | 整体语法绑在 **GFM 块结构**上,硬写成单一 Bison 文法别扭且难与预览器对齐 |
|
||||
|
||||
[USTC 编译课 Lab1](https://ustc-compiler-2025.github.io/homepage/) 用 Flex/Bison,是因为对象语言是 **C 式源码的编译器**;换 C++ 写那个编译器也合理。
|
||||
Marqdo 换 **Rust 或 C++** 都不改变「主前端不该是 Flex/Bison」这一判断。
|
||||
|
||||
**解释型语言同样需要词法与语法分析**,要的是阶段,不是这两个具体程序。
|
||||
|
||||
---
|
||||
|
||||
## 2. Marqdo 前端应怎样做(替代 Flex/Bison)
|
||||
|
||||
拆成三层,比「一个大 lexer/parser」更贴合宪法:
|
||||
|
||||
```
|
||||
.mq.md 文本
|
||||
│
|
||||
├─① 行分类(自研) 无标记 → 注释;有标记 → 代码行
|
||||
├─② GFM 块/行内(库) 标题、表、强调、列表结构
|
||||
├─③ 行扫描补强(自研) 保留 '-' / '+';frontmatter `> file.mq.md`
|
||||
└─④ Marqdo 语法(自研) 递归下降:Module/Fun/Stmt/Expr → AST
|
||||
└─ 表达式子语言 可手写,或仅对 Expr 用 pest/nom
|
||||
```
|
||||
|
||||
| 阶段 | 做法 | 对应编译学 |
|
||||
|------|------|------------|
|
||||
| ①③ | Rust 手写扫描 | 词法 / 扫描器 |
|
||||
| ② | `pulldown-cmark` 或 `comrak` | 复用 GFM,避免自研表格/强调 |
|
||||
| ④ | **手写递归下降**(推荐主路径) | 语法分析 |
|
||||
| Expr(可选) | `pest`(PEG)或 `nom`(组合子) | 仅迷你表达式,不是整门语言 |
|
||||
|
||||
**不推荐**整门语言上 LALRPOP / rusty_lr / Bison 等价物作为 v1 主前端:Markdown 外壳 + 行语义会让文法极度别扭。若将来有「纯文本 Marqdo 方言」,再另议生成器。
|
||||
|
||||
---
|
||||
|
||||
## 3. 详细依赖清单(Rust)
|
||||
|
||||
### 3.1 工具链(开发机)
|
||||
|
||||
| 依赖 | 用途 | 安装 |
|
||||
|------|------|------|
|
||||
| **Rust**(stable,建议 ≥ 1.75) | 编译实现 | [rustup](https://rustup.rs/):`rustup default stable` |
|
||||
| **Cargo** | 包与构建 | 随 rustup |
|
||||
| **rustfmt / clippy** | 格式与静态检查 | `rustup component add rustfmt clippy` |
|
||||
| **Git** | 版本管理 | 已有 |
|
||||
|
||||
**不要安装:** Flex、Bison、LLVM(v1 解释器不需要)。
|
||||
(日后若做原生后端再开 ADR;与当前解释器无关。)
|
||||
|
||||
### 3.2 Cargo crate(建议写入根 `Cargo.toml` / workspace)
|
||||
|
||||
#### 必选(Phase I 树遍历解释器)
|
||||
|
||||
| Crate | 角色 | 说明 |
|
||||
|-------|------|------|
|
||||
| **pulldown-cmark** *或* **comrak** | GFM 事件/AST | 标题、列表、表格、emphasis/strong;Spike 已证明「库 + 行扫描」可行。二选一做 Spike 对比后钉死 |
|
||||
| **thiserror** / **anyhow** | 错误类型 | 诊断与 CLI 报错 |
|
||||
| **clap** | CLI | `marqdo run [path]` |
|
||||
| **serde** + **serde_yaml** | 元信息 | 仅解析 frontmatter 中的 YAML **键值**;`> x.mq.md` 仍按**行**抽取(见 Spike) |
|
||||
|
||||
#### 强烈建议
|
||||
|
||||
| Crate | 角色 |
|
||||
|-------|------|
|
||||
| **camino** 或标准 `PathBuf` | 路径 |
|
||||
| **indexmap** | 保序 map(模块导出等) |
|
||||
|
||||
#### 测试
|
||||
|
||||
| Crate | 角色 |
|
||||
|-------|------|
|
||||
| **rust 自带** `#[test]` | 单元测试 |
|
||||
| **insta** 或手写金文件 | tests 期望 stdout 快照(可选) |
|
||||
| **assert_cmd** / **predicates** | CLI 集成测试(可选) |
|
||||
|
||||
#### Phase II(字节码 VM,后加)
|
||||
|
||||
无强制新依赖;VM 以自研为主。可选:
|
||||
|
||||
| Crate | 角色 |
|
||||
|-------|------|
|
||||
| **num_enum** 等 | opcode 枚举(可选) |
|
||||
|
||||
#### 明确不引入(v1)
|
||||
|
||||
| 东西 | 原因 |
|
||||
|------|------|
|
||||
| flex / bison / lemon | 见 §1 |
|
||||
| lalrpop / rusty_lr 作**整语言**前端 | 与 MD 外壳冲突;递归下降更合适 |
|
||||
| llvm-sys / inkwell | 非解释器 v1 |
|
||||
| 完整 Python 运行时嵌入 | 参考实现已定为 Rust,避免双运行时 |
|
||||
|
||||
### 3.3 表达式子语言(可选增强)
|
||||
|
||||
若手写 Expr 递归下降过痛,**仅**对 `` `a` + 1 == `b` `` 这类表达式引入其一:
|
||||
|
||||
| 选项 | 类型 | 何时用 |
|
||||
|------|------|--------|
|
||||
| **手写递归下降** | 无新依赖 | 默认;与全书一致、错误信息最好控 |
|
||||
| **pest** | PEG 生成器 | 文法清晰、想要 `.pest` 文件时 |
|
||||
| **nom** | 解析组合子 | 要零拷贝/细控时 |
|
||||
|
||||
整文件 `.mq.md` **不要**整份丢给 pest/nom。
|
||||
|
||||
---
|
||||
|
||||
## 4. 仓库布局(与依赖对应)
|
||||
|
||||
```
|
||||
Cargo.toml # workspace 或单包
|
||||
crates/marqdo/ # 或根包 marqdo
|
||||
src/
|
||||
main.rs / lib.rs
|
||||
lex/ # 行分类、Token(自研,无 flex)
|
||||
parse/ # 递归下降(自研,无 bison)
|
||||
ast/
|
||||
sema/
|
||||
interp/ # Phase I
|
||||
bytecode/ # Phase II
|
||||
runtime/
|
||||
tests/ # gold.rs + structure|keywords|errors
|
||||
public/ # 用户可执行文档
|
||||
spike/ # Python 风险探测存档(可保留,非运行时依赖)
|
||||
```
|
||||
|
||||
开发命令示例:
|
||||
|
||||
```bash
|
||||
cargo build
|
||||
cargo test
|
||||
cargo run -- run tests/structure/nested-call.mq.md
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 5. 与 Python Spike 的关系
|
||||
|
||||
| | Python `spike/` | Rust 参考实现 |
|
||||
|--|-----------------|---------------|
|
||||
| 角色 | 已验证 S1–S5 风险 | **正式**词法/语法/语义/解释器 |
|
||||
| 是否运行时依赖 | 否 | 是 |
|
||||
| 算法可迁移 | 行扫描、`split_front_matter`、导入正则 | 用 Rust 重写同算法 |
|
||||
|
||||
---
|
||||
|
||||
## 6. 一句话对照
|
||||
|
||||
- **需要:** 词法(行分类+标记)、语法(递归下降→AST)、语义、解释器/日后 VM。
|
||||
- **不需要:** Flex、Bison、LLVM(v1)。
|
||||
- **外部库只需:** Rust 工具链 + GFM crate(pulldown-cmark/comrak)+ CLI/错误/测试若干;表达式可选 pest/nom。
|
||||
@@ -1,68 +0,0 @@
|
||||
# 示例与测试布局
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定 |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 原则 | **夹具即金样例**:`tests/{structure,keywords,errors}/**/*.mq.md` 由 `cargo test` / CI 跑通;`marqdo view tests` 也可浏览 |
|
||||
|
||||
---
|
||||
|
||||
## 1. 目录
|
||||
|
||||
只保留 **`tests/`**,用子目录区分类别(不再另设 `examples/`):
|
||||
|
||||
```
|
||||
tests/
|
||||
README.md
|
||||
gold.rs # 集成测试入口
|
||||
structure/ # 代码基础结构(Markup 架构)
|
||||
hello.mq.md
|
||||
nested-call.mq.md
|
||||
positional-call.mq.md
|
||||
branch.mq.md
|
||||
loop.mq.md
|
||||
collection.mq.md
|
||||
import/
|
||||
main.mq.md
|
||||
utils.mq.md
|
||||
keywords/ # 关键字与内置名
|
||||
print.mq.md
|
||||
bool-logic.mq.md
|
||||
errors/ # 期望失败(诊断文案稳定后再加金样例)
|
||||
…
|
||||
```
|
||||
|
||||
面向访客的可执行介绍在 [`public/`](../../public/)(无 `errors/`),见 [user-site.md](user-site.md)。
|
||||
开发设计文稿在 [`doc/`](../)(单数)。
|
||||
|
||||
---
|
||||
|
||||
## 2. 分类职责
|
||||
|
||||
| 类别 | 测什么 | 不测什么 |
|
||||
|------|--------|----------|
|
||||
| **structure** | `#`/`##`、形参、`>` 调用、`*`/`**`、`+`/`-`、表、导入、位置/具名实参 | 关键字边角 |
|
||||
| **keywords** | `True`/`False`/`None`、`and`/`or`/`not`、`print`/`input` 约定 | 复杂控制流(可极简) |
|
||||
| **errors** | 未定义名、实参错误、语法错误的诊断 | 成功路径 |
|
||||
|
||||
未单独建夹、但应覆盖的其它测试(`src/**` 单测或日后 `tests/runtime/`):
|
||||
|
||||
- **流水线调试**:`--dump-lines` / `--dump-ast` / `--trace-eval`
|
||||
- **CLI**:默认 `index.mq.md`、退出码
|
||||
- **view**:目录扫描、单文件页、执行区(见 [view.md](view.md))
|
||||
- **模块图**:循环导入拒绝
|
||||
|
||||
---
|
||||
|
||||
## 3. 金样例约定
|
||||
|
||||
每个可执行 `.mq.md` 在 `tests/gold.rs` 登记期望 stdout。
|
||||
`errors/` 内文件登记期望 stderr 子串与非零退出码。
|
||||
|
||||
---
|
||||
|
||||
## 4. 与 `view` / `public` 的关系
|
||||
|
||||
- `marqdo view tests`:开发者浏览金样例(含 errors)。
|
||||
- `marqdo view public`:用户文档站源;**不要**把 `tests/errors` 编进 `public/`。
|
||||
@@ -1,163 +0,0 @@
|
||||
# 设计草案:机器生成的 YAML 清单(OKF 风格)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 草案(已采纳方向;修正「配置文件」误解) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 相关 | [OKF 调研](../research/okf-and-marqdo.md) |
|
||||
| 取代 | 此前「YAML = 人手写的编译器配置 / frontmatter 契约」的表述 |
|
||||
|
||||
---
|
||||
|
||||
## 决策
|
||||
|
||||
Marqdo 项目中的 **YAML(及由其组成的 OKF 风格知识包)是工具自动生成的产物,不是给人填的配置文件。**
|
||||
|
||||
它的角色接近其它语言里由工具维护的**依赖与包元数据**,例如:
|
||||
|
||||
| 生态 | 类比(职责相近,不是语法相同) |
|
||||
|------|--------------------------------|
|
||||
| Rust | `Cargo.toml` / 解析后的依赖图(由源与清单共同推导,工具可改写) |
|
||||
| Python | `requirements.txt`(常由解析/冻结生成) |
|
||||
| Go | `go.mod` + `go.sum`(`go mod tidy` 维护) |
|
||||
|
||||
我们选择 **OKF 的形态**(Markdown + YAML frontmatter 的概念目录)来承载这份生成结果,从而一举两得:
|
||||
|
||||
1. **给编译器 / 包管理**:依赖图、模块身份、导出符号、版本锁定等可查询元数据
|
||||
2. **给本项目文档**:同一份生成物可直接渲染为「项目知识目录」——模块说明、依赖关系、API 索引等**自动生成本项目文档内容**
|
||||
|
||||
**唯一手写真相**仍是 `.mq.md` 源文件正文。YAML 清单是派生工件;过时则重新生成,禁止当成第二套权威配置去手改(除非工具链明确支持的「生成后微调」流程,且须可复现)。
|
||||
|
||||
**与源 frontmatter 的分工**(见 [markdown-mapping.md](markdown-mapping.md)):源文件 `---` 块可含 `title` 等元信息,以及人手声明的跨文件导入行 `> other.mq.md`。那是**源上的导入声明**,不是工程依赖锁。工具仍应据此(及正文 `>` 调用)**生成** OKF 风格依赖/模块目录;不要把生成目录手改成权威。
|
||||
|
||||
---
|
||||
|
||||
## 纠正:它不是什么
|
||||
|
||||
| ❌ 不是 | ✅ 是 |
|
||||
|--------|------|
|
||||
| 人手维护的 `run` / `target` / 路径配置 | 从源码 **推导** 出的依赖与模块元数据 |
|
||||
| 编译器「怎么跑」的 ini/配置替代品 | 解析、链接、文档站共用的 **生成清单** |
|
||||
| 与正文平行的第二套程序描述 | 正文的 **投影**(projection):结构化、可查询、可渲染 |
|
||||
|
||||
执行方式(解释 / 检查 / 编译到某后端)由 **CLI、子命令或工程约定** 决定,不塞进这份 YAML 让人配置。
|
||||
|
||||
---
|
||||
|
||||
## 数据流
|
||||
|
||||
```
|
||||
手写 .mq.md 源
|
||||
(叙事 + 类型 + 函数 + 正文中的引用/导入)
|
||||
│
|
||||
▼
|
||||
marqdo 工具链
|
||||
· 解析正文 AST
|
||||
· 收集 import / 链接 / 导出
|
||||
· 解析依赖、锁定版本
|
||||
│
|
||||
├──────────────────────────────┐
|
||||
▼ ▼
|
||||
生成 OKF 风格清单 编译 / 类型检查 / 运行
|
||||
(YAML + 概念 Markdown) (消费清单加速解析)
|
||||
│
|
||||
▼
|
||||
自动生成本项目文档
|
||||
(模块索引、依赖图、API 目录……)
|
||||
```
|
||||
|
||||
- **源 → 清单**:单向派生;清单不得反向成为「唯一写依赖的地方」。
|
||||
- **清单 → 文档**:OKF 包本身即可浏览;也可再生成站点/目录页。
|
||||
- **清单 → 编译**:编译器可读生成结果以跳过重复发现,但语义仍以源为准;清单缺失时应能从源重建。
|
||||
|
||||
---
|
||||
|
||||
## 生成物长什么样(示意)
|
||||
|
||||
工程在构建或 `marqdo sync` 类命令后,可得到类似 OKF bundle 的目录(路径未定):
|
||||
|
||||
```
|
||||
.marqdo/ # 或 docs/catalog/ 等 — 待 ADR
|
||||
index.md # 生成:项目总览
|
||||
modules/
|
||||
cart.md # 生成:每个模块一个概念文档
|
||||
prelude-list.md
|
||||
deps/
|
||||
lock.yaml # 生成:依赖锁定(机器向)
|
||||
```
|
||||
|
||||
单个生成的概念文件可呈 OKF 形:
|
||||
|
||||
```yaml
|
||||
---
|
||||
type: Marqdo Module # 生成
|
||||
title: cart
|
||||
description: 购物车:行项目与总额
|
||||
resource: src/cart.mq.md # 指向源文件
|
||||
depends:
|
||||
- prelude/list
|
||||
- math/sum
|
||||
exports: [Line, total]
|
||||
generated:
|
||||
by: "marqdo/0.1"
|
||||
at: 2026-08-04T01:00:00Z
|
||||
---
|
||||
|
||||
# cart
|
||||
|
||||
> 本页由 Marqdo 工具链根据 [`src/cart.mq.md`](../../src/cart.mq.md) **自动生成**,请勿手改。
|
||||
|
||||
## 依赖
|
||||
|
||||
- [prelude/list](../modules/prelude-list.md)
|
||||
- [math/sum](../modules/math-sum.md)
|
||||
|
||||
## 导出
|
||||
|
||||
| 符号 | 种类 |
|
||||
|------|------|
|
||||
| `Line` | type |
|
||||
| `total` | fn |
|
||||
```
|
||||
|
||||
人要改行为或说明 → 改 `src/cart.mq.md`;再生成,文档与依赖清单一起更新。
|
||||
|
||||
---
|
||||
|
||||
## 与「代码即文档」的关系
|
||||
|
||||
Marqdo 有两层「文档」,不要混为一谈:
|
||||
|
||||
| 层 | 谁写 | 是什么 |
|
||||
|----|------|--------|
|
||||
| **源文档** | 人(及协助编写的 Agent) | `.mq.md`:程序本身,打开即读、即可跑 |
|
||||
| **项目目录文档** | 机器 | OKF 风格 YAML/Markdown:从全项目源 **汇总** 的依赖、模块图、索引 |
|
||||
|
||||
前者消灭「实现与说明漂移」;后者消灭「仓库级总览靠手维护 README 目录」——总览从源自动长出,格式还对 Agent / 搜索友好(OKF)。
|
||||
|
||||
---
|
||||
|
||||
## 原则
|
||||
|
||||
1. **源为唯一权威** — 依赖与导出以 `.mq.md` 正文中的语言构造为准;YAML 是提取结果。
|
||||
2. **生成、可复现** — 同一源树 + 同一工具版本 → 同一清单(允许时间戳等字段除外或规范化)。
|
||||
3. **勿手改生成物** — 生成文件应带头注释或 `generated` 字段;CI 可校验「未提交脏生成」或「提交的生成与源一致」。
|
||||
4. **OKF 形、Marqdo 义** — 文件形态对齐 OKF(`type`、链接、目录),词汇服务模块/依赖/导出,而不是照搬 BigQuery 概念类型。
|
||||
5. **清单可删可再生** — 没有清单时,编译器仍须能直接从源工作(可能更慢);清单是缓存与文档面,不是语言语义的一部分。
|
||||
|
||||
---
|
||||
|
||||
## 待决问题(后续 ADR)
|
||||
|
||||
- [x] 生成物默认路径:`.marqdo/`(`-o` 可改)— 见 [catalog-cli.md](catalog-cli.md)
|
||||
- [x] `marqdo catalog` / `sync`;静态用户文档:`marqdo view output` — 见 [view.md](view.md)
|
||||
- [ ] 是否提交生成物进 git(项目自定;CI 可校验干净生成)
|
||||
- [ ] 与「可手写包身份 name/version」的边界
|
||||
- [ ] 是否沿用 OKF v0.2 的 `sources` 等溯源字段
|
||||
|
||||
---
|
||||
|
||||
## 结论
|
||||
|
||||
**YAML(OKF 风格清单)= 机器从 `.mq.md` 自动生成的依赖与项目元数据,并可据此自动生成本项目文档;不是人手填写的配置文件。**
|
||||
人写源,工具写清单与目录文档;编译器与文档站共同消费生成物,语义始终回到源。
|
||||
@@ -1,84 +0,0 @@
|
||||
# Marqdo 关键字与内置名(v0 最小集)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定(前期够用) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 原则 | **英文**;参考 [Python](https://realpython.com/python-keywords/) 但远更少;控制流仍靠 Markdown 标记,不引入 `if`/`while`/`def` |
|
||||
| 相关 | [markdown-mapping.md](markdown-mapping.md) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 设计原则
|
||||
|
||||
1. **标记承担架构**:函数=`#`,分支=`+`,循环=`-`,返回=`**…**`,语句=`*…*`。因此 **不**把 `def`/`if`/`else`/`while`/`for`/`return` 做成关键字。
|
||||
2. **英文标识**:内置与字面量用英文,便于工具高亮与国际协作。
|
||||
3. **学 Python 的边界**:Python 3 里 [`print` / `input` 是内置函数,不是关键字](https://realpython.com/python-keywords/);布尔与空值是字面量关键字。Marqdo 同样区分 **关键字** vs **内置函数名**。
|
||||
4. **宁少勿多**:前期只列执行金样例所需;要加再进 ADR。
|
||||
|
||||
---
|
||||
|
||||
## 2. 关键字(词法保留,不可作变量名)
|
||||
|
||||
| 关键字 | 含义 | 备注 |
|
||||
|--------|------|------|
|
||||
| `True` | 布尔真 | 对齐 Python 大小写 |
|
||||
| `False` | 布尔假 | |
|
||||
| `None` | 空值 | |
|
||||
| `and` | 逻辑与 | 表达式内 |
|
||||
| `or` | 逻辑或 | |
|
||||
| `not` | 逻辑非 | |
|
||||
|
||||
**本期不引入:** `if` `else` `elif` `while` `for` `def` `class` `return` `import` `pass` `break` `continue` `in` `is` `lambda` …
|
||||
(`else` 分支臂仍用臂头单独的 `*` 标记,不是单词 `else`。)
|
||||
|
||||
---
|
||||
|
||||
## 3. 内置函数(可调用名,建议勿遮蔽)
|
||||
|
||||
| 名称 | 作用 | 调用示例 |
|
||||
|------|------|----------|
|
||||
| `print` | 写到 stdout(副作用) | `> print text=Hello` 或 `> print Hello`(位置实参,见 [call-arguments.md](call-arguments.md)) |
|
||||
| `input` | 从 stdin 读一行(返回文本) | `*`name` = > input prompt=Name: *` |
|
||||
|
||||
参数约定(v0):
|
||||
|
||||
- `print`:具名实参 `text`(必填);日后可扩展 `end` 等。
|
||||
- `input`:可选 `prompt`;返回用户输入字符串(不含换行)。
|
||||
|
||||
旧文档中的中文 `print` **废弃**,统一为 `print`。
|
||||
|
||||
---
|
||||
|
||||
## 4. 与 Markup 调用的关系
|
||||
|
||||
```markdown
|
||||
# main
|
||||
|
||||
> print text=Hello World!
|
||||
|
||||
*`n` = 1*
|
||||
|
||||
+ `n` > 0
|
||||
> print text=positive
|
||||
+ *
|
||||
> print text=other
|
||||
```
|
||||
|
||||
- `>` 是**调用标记**(架构)。
|
||||
- `print` 是**被调名字**(内置库)。
|
||||
- 用户自定义 `# print` 会遮蔽内置(实现应警告)。
|
||||
|
||||
---
|
||||
|
||||
## 5. 标识符规则(摘要)
|
||||
|
||||
- 变量:行内 `` `name` ``;`name` 不可为上表关键字。
|
||||
- 函数名:`#` 标题文本;建议 ASCII/英文,中文标题仍允许但内置名保持英文。
|
||||
- 比较:`==` `>` `<` `>=` `<=`;逻辑:`and` `or` `not`。
|
||||
|
||||
---
|
||||
|
||||
## 6. 后续可增(未批准)
|
||||
|
||||
`len`、`str`、`int`、`float`、`range`;以及 `break`/`continue`(若循环需要)。增加前开短 ADR。
|
||||
@@ -1,220 +0,0 @@
|
||||
# Marqdo 语法映射 v0.1(Markup-as-Syntax)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定论(修订:语句 / 返回 / 输出职责分离) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 取代 | v0 中「`**`=输出、`*`=返回」 |
|
||||
| 相关 | [code-vs-comment.md](code-vs-comment.md) · [return-hr-and-code-surface.md](return-hr-and-code-surface.md) |
|
||||
|
||||
Markdown **标记即语法**。输出**不是**语言架构原语,而是内置函数 **`print`**(英文;见 [keywords.md](keywords.md))。
|
||||
|
||||
---
|
||||
|
||||
## 1. 哲学
|
||||
|
||||
1. `.mq.md`:打开即文档,运行即程序。
|
||||
2. **叙述注释**以空行分段:段首无标记 → 注释;段内续行一律注释(见 §2)。
|
||||
3. **可执行**靠标记:结构标记(`#` `>` `+` `-` 表…)与 **斜体语句** / **粗体返回**。
|
||||
4. 作用域 = `#` 层数;入口 = `index.mq.md`。函数体可用 `---` / `***` 或空返回收束(见 §11)。
|
||||
|
||||
---
|
||||
|
||||
## 2. 行首判别与成段注释
|
||||
|
||||
跳过前导空白后,对**段首行**(空行之后的第一行,或文件起始):
|
||||
|
||||
| 首字符 | 分类 |
|
||||
|--------|------|
|
||||
| 普通文字 / 空 | **注释** |
|
||||
| 标记字符 | **代码** |
|
||||
|
||||
标记含:`#` `*` `>` `+` `-` `` ` `` `|`、有序数字、围栏 `` ` ``、以及函数体内的结束分割线 `---` / `***`(见 §11)。
|
||||
|
||||
**成段注释(空行分段)**:段首一旦判定为注释,则直至下一空行之前的所有非空行一律为注释——即使续行以 `` ` `` / `-` / `*` 等开头也不升级为代码。叙述与可执行代码之间**必须空一行**。例外:单独一行的 `---` / `***` / `****`(函数结束或 frontmatter 闭合)始终为代码,并打断注释段。
|
||||
|
||||
---
|
||||
|
||||
## 3. 映射总表(v0.1)
|
||||
|
||||
| 标记 | 语义 |
|
||||
|------|------|
|
||||
| `#` … `######` | 函数;层数 = 作用域 |
|
||||
| 函数头下 `-` 纯名 | 形参 |
|
||||
| 体内 `-` | 循环 |
|
||||
| 体内 `+` 或 `1.` | 分支 |
|
||||
| 分支臂头整行恰为 `*` | else |
|
||||
| `> 函数 形参=实参` 或 `> 函数 实参` | 调用(具名 / 位置,见 [call-arguments.md](call-arguments.md)) |
|
||||
| frontmatter `> path.mq.md` | 跨文件导入 |
|
||||
| `*…*` | **程序语句**(绑定、表达式句、可写的调用句等) |
|
||||
| `**…**` | **返回值**(架构级;函数结果) |
|
||||
| `****` / `**` + 空白 + `**` | **空返回**(`None`),并结束本函数体 |
|
||||
| 无标记行 / 成段续行 | 注释(空行分段,见 §2) |
|
||||
| GFM 表格 | 集合 |
|
||||
| ` ```lang ` | 外联异种代码 |
|
||||
| 函数体内 `---` / `***` | **结束本函数体**(无返回值函数的收束;见 §11) |
|
||||
|
||||
### 输出不是架构
|
||||
|
||||
| 错误(旧) | 正确(v0.1) |
|
||||
|------------|--------------|
|
||||
| `**Hello**` 表示打印 | `> print text=Hello` |
|
||||
| 中文名 `输出`(已废弃) | 统一英文内置 `print` |
|
||||
| 输出与返回抢粗体 | 粗体只表示 **返回** |
|
||||
|
||||
`print` / `input` 为内置函数,完整表见 [keywords.md](keywords.md)。
|
||||
|
||||
---
|
||||
|
||||
## 4. 语句、返回、调用
|
||||
|
||||
### 程序语句(斜体)
|
||||
|
||||
```markdown
|
||||
*`x` = 1*
|
||||
|
||||
*`y` = `x` + 2*
|
||||
```
|
||||
|
||||
行首已是结构标记的构造(`#` `>` `+` `-` `|`)**不必**再包一层斜体;斜体用于「一般语句」槽位。
|
||||
|
||||
### 返回值(粗体)
|
||||
|
||||
```markdown
|
||||
# 加一
|
||||
- n
|
||||
|
||||
**`n` + 1**
|
||||
```
|
||||
|
||||
### 输出(内置函数 `print`)
|
||||
|
||||
```markdown
|
||||
# main
|
||||
|
||||
> print text=Hello World!
|
||||
```
|
||||
|
||||
### else 与斜体消歧
|
||||
|
||||
- 分支臂**第一行整行只有一个** `*` → else。
|
||||
- `*中间有内容*` → 程序语句。
|
||||
- `**…**` → 返回(与 else 无关)。
|
||||
|
||||
---
|
||||
|
||||
## 5. Frontmatter 与跨文件
|
||||
|
||||
同 v0:文件头 `---` 对为元信息;其中 `> file.mq.md` 为导入。
|
||||
**函数体内的** `---` / `***` 不解释为 frontmatter(见 §11)。
|
||||
|
||||
---
|
||||
|
||||
## 6. 函数、作用域、提升
|
||||
|
||||
规则同 v0。推荐:
|
||||
|
||||
```markdown
|
||||
# main
|
||||
|
||||
> print text=Hello World!
|
||||
|
||||
## 加问候
|
||||
- 谁
|
||||
|
||||
**你好,`谁`**
|
||||
```
|
||||
|
||||
(需要打印时对返回值再 `> print`,或直接 `> print`。)
|
||||
|
||||
形参 `- 名` → 体内 `` `名` ``。
|
||||
|
||||
---
|
||||
|
||||
## 7. 绑定与比较
|
||||
|
||||
| 写法 | 含义 |
|
||||
|------|------|
|
||||
| `*`x` = 1*` 或行首 `` `x` = 1 `` | 绑定(两种均允许;实现应统一) |
|
||||
| `` `x` == 1 `` | 相等比较 |
|
||||
|
||||
v0.1 **推荐**绑定写在斜体语句内,以保持「语句=斜体」一致;行首 `` ` `` 仍合法以便表格右值绑定。
|
||||
|
||||
---
|
||||
|
||||
## 8. 分支与循环
|
||||
|
||||
分支(`+` / 有序),循环(`-`),语义同 v0。臂体内打印改为调用 `print`:
|
||||
|
||||
```markdown
|
||||
*`x` = 0*
|
||||
|
||||
+ `x` > 0
|
||||
> print text=正数
|
||||
+ `x` < 0
|
||||
> print text=负数
|
||||
+ *
|
||||
> print text=零
|
||||
```
|
||||
|
||||
```markdown
|
||||
- [果](篮子)
|
||||
> print text=今天吃`果`
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 9. 集合(表格)
|
||||
|
||||
同 v0。`` `篮子` = `` 后接 GFM 表。
|
||||
|
||||
---
|
||||
|
||||
## 10. 求值入口
|
||||
|
||||
1. 加载 `index.mq.md` + 导入。
|
||||
2. Pass1 收集定义。
|
||||
3. Pass2 执行 `# main`。
|
||||
4. `*` 语句、`**` 返回、`>` 调用、`+`/`-` 控制流、表绑定按语义执行;`> print` 写 stdout。
|
||||
|
||||
---
|
||||
|
||||
## 11. 函数体结束(`---` / `***` / 空返回)
|
||||
|
||||
无返回值(或已写完副作用)的函数,在体末用分割线收束,避免后续同级语句被吞进嵌套函数:
|
||||
|
||||
```markdown
|
||||
# main
|
||||
|
||||
> 问候 谁=World
|
||||
|
||||
## 问候
|
||||
- 谁
|
||||
|
||||
> print text=Hello `谁`!
|
||||
|
||||
---
|
||||
```
|
||||
|
||||
| 约定 | 说明 |
|
||||
|------|------|
|
||||
| `---` 或 `***` | 函数体**顶层**单独一行(长度 ≥ 3 且全为 `-` 或全为 `*`)→ **结束本函数**;后续语句属于外层 |
|
||||
| `****` / 空粗体 | 空返回(值为 `None`),并同样结束本函数体 |
|
||||
| 有值 `**expr**` | 普通返回;**不**自动截断后续兄弟句(仍可用分割线或下一同级/更浅标题收束) |
|
||||
| Frontmatter | 仅**文件开头**成对 `---` = 元信息;与函数体内结束符消歧 |
|
||||
| 分支/循环臂内 | 分割线仍可忽略(噪声),不截断外层函数 |
|
||||
|
||||
曾设想的「可选框住分支/循环」废止,分割线专用于函数收束。
|
||||
|
||||
---
|
||||
|
||||
## 12. v0.1 非目标
|
||||
|
||||
- break/continue、完整错误模型、静态类型、完整 FFI
|
||||
- 用 `*` 作无序列表符
|
||||
|
||||
---
|
||||
|
||||
## 13. 示例索引
|
||||
|
||||
见 [`tests/`](../../tests/)。
|
||||
@@ -1,73 +0,0 @@
|
||||
# 解释器流水线可视调试
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定(开发期强制友好) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 参考 | [Crafting Interpreters — Scanning](https://www.craftinginterpreters.com/scanning.html)(先打 token)· [AstPrinter](https://craftinginterpreters.com/representing-code.html) · CLI `--dump-ast` 类实践 |
|
||||
|
||||
---
|
||||
|
||||
## 1. 目标
|
||||
|
||||
开发 `marqdo` 时,对任意 `.mq.md` 应能**分阶段看见**中间结果,避免黑盒;正式 `run` 默认安静,仅输出程序 `print` 的内容。
|
||||
|
||||
---
|
||||
|
||||
## 2. CLI 开关
|
||||
|
||||
```bash
|
||||
marqdo run FILE [dumps...]
|
||||
marqdo dump FILE --stage lines|tokens|ast|sema|all
|
||||
```
|
||||
|
||||
| 标志 | 阶段 | 输出内容 |
|
||||
|------|------|----------|
|
||||
| `--dump-lines` | 行分类 | 每行:`LINE kind=Comment\|Code\|Blank` + 原文预览 |
|
||||
| `--dump-tokens` | 词法 | Token 流:`type lexeme line:col` |
|
||||
| `--dump-ast` | 语法 | S 表达式或缩进树(模块/函数/语句) |
|
||||
| `--dump-sema` | 语义 | 作用域、导入图、提升后的符号表 |
|
||||
| `--trace-eval` | 求值 | 进入/离开函数、绑定、分支臂选择、`print` 调用 |
|
||||
| `--dump-bytecode` | 字节码 | 反汇编 `Program`(见 [bytecode.md](bytecode.md)) |
|
||||
| `--backend tree\|bytecode` | 执行后端 | 默认 `tree`;`bytecode` 走栈式 VM |
|
||||
| `--dump-all` | 以上全部 | 按管道顺序打印,段之间用横幅分隔 |
|
||||
|
||||
格式约定:
|
||||
|
||||
- 人类可读优先;段首统一:`=== marqdo: <stage> ===`
|
||||
- 可选 `--dump-format=text|json`(json 后置,text 先做)
|
||||
- 有 dump 时:若求值未实现,仍打印已实现阶段再以非 0 退出(便于 M1 只测 lines)
|
||||
|
||||
---
|
||||
|
||||
## 3. 横幅示例
|
||||
|
||||
```
|
||||
=== marqdo: lines (tests/structure/hello.mq.md) ===
|
||||
1 Blank
|
||||
2 Comment | # Hello World
|
||||
3 Blank
|
||||
4 Comment | 本程序调用...
|
||||
5 Blank
|
||||
6 Code | > print text=Hello World!
|
||||
=== marqdo: end lines ===
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 实现要点
|
||||
|
||||
- dump 逻辑放在 `src/debug/`(或各阶段 `fmt`),**不**与安静求值路径搅在一起。
|
||||
- 每个阶段纯函数:`input → (artifacts, diagnostics)`,CLI 负责打印。
|
||||
- 单测可断言 dump 字符串包含关键行(稳定子集),避免绑死全文格式。
|
||||
|
||||
---
|
||||
|
||||
## 5. 与里程碑
|
||||
|
||||
| 里程碑 | 必须可用的 dump |
|
||||
|--------|-----------------|
|
||||
| M1 | `--dump-lines`(及可选 tokens 雏形) |
|
||||
| M2 | `--dump-ast` |
|
||||
| M3–M4 | `--dump-sema`、`--trace-eval` |
|
||||
| 全程 | `--dump-all` 随阶段增长自动变完整 |
|
||||
@@ -1,19 +0,0 @@
|
||||
# 记录:返回 / 语句 / 输出 / 分割线(决议)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已决议(并入 mapping v0.1 + keywords;2026-08-04 修订函数收束) |
|
||||
| 日期 | 2026-08-04 |
|
||||
|
||||
---
|
||||
|
||||
## 决议
|
||||
|
||||
1. **`*…*` = 程序语句**。
|
||||
2. **`**…**` = 返回值**(架构级);空粗体 `****` / `** **` = 空返回(`None`)并结束函数体。
|
||||
3. **输出**用内置函数 **`print`**(英文),不是粗体,不是中文名。
|
||||
4. **`---` / `***`(函数体顶层)**:结束本函数体(无返回值函数收束);**不是**分支/循环装饰框。
|
||||
5. **成段注释**:空行分段;段内续行不因首字符升级为代码。
|
||||
6. **否决**:无标记行 = 默认代码。
|
||||
|
||||
详见 [keywords.md](keywords.md)、[markdown-mapping.md](markdown-mapping.md)、[code-vs-comment.md](code-vs-comment.md)。
|
||||
@@ -1,152 +0,0 @@
|
||||
# 参考实现:技术选型分析(尚未拍板)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | **分析中 — 未定案** |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 说明 | 对比候选与约束;**不在本文直接开写实现仓库脚手架** |
|
||||
|
||||
上一版曾草率写「就用 TypeScript」——信息不足,已作废为定论。本文只做选型框架与对比,**最终实现语言须单开 ADR 确认后再动工。**
|
||||
|
||||
---
|
||||
|
||||
## 1. 我们在选什么
|
||||
|
||||
参考实现至少包含:
|
||||
|
||||
1. **读入** `.mq.md`(含 frontmatter 混合行)
|
||||
2. **对齐 GFM** 的结构:标题、列表(`-`/`+`/`1.`)、强调、表格、围栏、链接
|
||||
3. **Lower**:行首判别、标题树作用域、列表符语义、注释剥离
|
||||
4. **两遍**:收集定义 + 导入 → 求值
|
||||
5. **CLI** + **金样例测试**(`tests/`)
|
||||
|
||||
可选后期:字节码/编译、LSP、格式化。首版目标是**验证语法宪法**,不是上生产编译器。
|
||||
|
||||
---
|
||||
|
||||
## 2. 选型准则(按权重)
|
||||
|
||||
| 权重 | 准则 | 说明 |
|
||||
|------|------|------|
|
||||
| 高 | GFM 忠实度 | 表格、列表符、强调边界与 GitHub 预览一致,减少「能渲染不能跑 / 能跑不能渲染」 |
|
||||
| 高 | 与宪法同构 | 易于表达「先 mdast/事件流,再 Marqdo AST」 |
|
||||
| 高 | 测试与迭代速度 | 改语法宪法时能快速改测试 |
|
||||
| 中 | 静态类型 / 可维护 AST | 长期改解释器不疼 |
|
||||
| 中 | CLI 与打包 | 单二进制或 `npx`/等价体验 |
|
||||
| 低 | 极致性能 | v0 样例很小 |
|
||||
| 低 | 浏览器内运行 | 可后置 |
|
||||
|
||||
非准则:跟风、先写再选、与「生成 OKF」强绑某一云厂商。
|
||||
|
||||
---
|
||||
|
||||
## 3. 架构共性(与语言无关)
|
||||
|
||||
无论选哪门实现语言,流水线应一致:
|
||||
|
||||
```
|
||||
.mq.md 文本
|
||||
→ 前端:GFM 友好解析(或事件扫描)
|
||||
→ Middle:Marqdo lower(行类、标题树、- / +、表、围栏)
|
||||
→ Marqdo AST
|
||||
→ 语义:导入图、提升、作用域
|
||||
→ 后端:解释器(v0)/日后编译
|
||||
→ 测试:tests 金样例 → 期望 stdout
|
||||
```
|
||||
|
||||
**前端可复用成熟 GFM 库,也可自研**;Middle/后端必须自研(这是语言本体)。
|
||||
|
||||
---
|
||||
|
||||
## 4. 候选对比
|
||||
|
||||
### A. TypeScript / Node + remark(mdast)
|
||||
|
||||
| 利 | 弊 |
|
||||
|----|----|
|
||||
| remark-gfm 与预览器语义接近;mdast 节点齐全 | 运行时依赖 Node;发行 CLI 需打包 |
|
||||
| 迭代快、Vitest 方便 | 性能与「系统级编译器」形象偏软 |
|
||||
| 与 Markdown 工具链同生态 | 需纪律:避免把业务写进插件泥潭 |
|
||||
|
||||
**适合:** 验证宪法、快速金样例。
|
||||
**不自动等于最终生产编译器。**
|
||||
|
||||
### B. Rust + pulldown-cmark / comrak
|
||||
|
||||
| 利 | 弊 |
|
||||
|----|----|
|
||||
| 单静态二进制、性能好、适合日后正式编译器 | GFM 表格/细节与 GitHub 仍可能有差异,要对齐测试 |
|
||||
| 类型与代数数据类型适合 AST | 前期迭代比 TS 慢 |
|
||||
| 无 GC、可嵌入 | MD 生态碎片,选库要论证 |
|
||||
|
||||
**适合:** 中长期「真编译器」或与 TS 原型双轨。
|
||||
**风险:** 首版就上 Rust 可能拖慢语法验证。
|
||||
|
||||
### C. Python + markdown-it-py / mistune
|
||||
|
||||
| 利 | 弊 |
|
||||
|----|----|
|
||||
| 原型极快 | 类型与工程化偏弱;双实现时易弃 |
|
||||
| 文本处理友好 | 打包 CLI 体验一般 |
|
||||
|
||||
**适合:** 一次性语法实验。
|
||||
**不推荐**作为唯一长期实现,除非团队强约束。
|
||||
|
||||
### D. Go + goldmark
|
||||
|
||||
| 利 | 弊 |
|
||||
|----|----|
|
||||
| 单二进制、部署简单 | 泛型/AST 表达力一般;MD 库选 goldmark 需 GFM 扩展评估 |
|
||||
| 并发与工具链成熟 | 与 MD 研究生态联系弱于 JS |
|
||||
|
||||
**适合:** 工具型 CLI 优先的团队。
|
||||
|
||||
### E. 自研扫描器(任意语言)+ 仅用 GFM 做对照测试
|
||||
|
||||
| 利 | 弊 |
|
||||
|----|----|
|
||||
| 完全控制行首判别与 `+`/`-` 语义 | 重复实现表格/强调,易与渲染不一致 |
|
||||
| 可强制「行分类优先于块解析」 | 工作量大 |
|
||||
|
||||
**适合:** 证明「行首判别」与 CommonMark 块结构冲突时的研究分支。
|
||||
可与 A/B 组合:自研 lower,块结构仍喂给现成解析器。
|
||||
|
||||
---
|
||||
|
||||
## 5. 关键技术风险(与选语言正交)
|
||||
|
||||
1. **行首判别 vs 块解析器** — CommonMark 先成块再看内容;Marqdo 先看行类。可能需「行预分类再喂解析器」或「解析后按源位置重分类」。选型时要让候选语言/库能拿到**源行映射**。
|
||||
2. **frontmatter 非纯 YAML** — `>` 导入行是扩展;不能整块丢给严格 YAML 解析器。
|
||||
3. **`+` 与 `-` 列表** — 多数解析器都认,但 lower 必须保留**项目符字符**,不能只得「unordered list」。选库时验证 AST 是否保留 bullet type。
|
||||
4. **`*` else vs `*返回*` vs 强调** — 依赖 inline 解析与「整行恰好一个 `*`」的行级规则并存。
|
||||
|
||||
以上 4 点应作为**选型验收用例**,写进 ADR:用最小样例在候选栈上 Spike,再定案。
|
||||
|
||||
---
|
||||
|
||||
## 6. 建议的决策流程(尚未执行)
|
||||
|
||||
1. **Spike(各 ≤0.5–1 日)**
|
||||
- 候选 A:TS + remark-gfm — 能否区分 `-`/`+` bullet、解析单列表格、读 strong/emphasis。
|
||||
- 候选 B:Rust + comrak/pulldown — 同上。
|
||||
- (可选)C 或 D 若团队有偏好再做。
|
||||
2. **对照验收用例**(固定):`tests/structure/hello.mq.md`、`branch.mq.md`(`+`)、`collection.mq.md`(表)、含 `> x.mq.md` 的 frontmatter 行。
|
||||
3. **出 ADR**:选定「验证期实现」与(可选)「生产目标实现」是否同一语言。
|
||||
4. **再**建仓库脚手架与测试——禁止在 ADR 前默认生成 `package.json` / `Cargo.toml` 当既成事实。
|
||||
|
||||
---
|
||||
|
||||
## 7. 当前态度(非正式投票)
|
||||
|
||||
| 阶段 | 倾向(待 Spike 验证) |
|
||||
|------|------------------------|
|
||||
| 语法验证期 | 更可能是 **TypeScript + remark**(快、GFM 近) |
|
||||
| 长期生产编译器 | **开放** Rust / Go,不与验证期绑定 |
|
||||
|
||||
**本文不授权开始实现。** 确认 Spike 计划或直接指定语言后,再写 `adr/0001-implementation-language.md`。
|
||||
|
||||
---
|
||||
|
||||
## 8. 与「无标记 = 注释」的关系
|
||||
|
||||
实现必须先做**行分类**(见 [code-vs-comment.md](code-vs-comment.md)),再谈用何种语言写分类器。选型不能假设「整文件都是可执行代码」。
|
||||
@@ -1,57 +0,0 @@
|
||||
# 用户静态文档站(public / gh-pages)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定 |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 相关 | [view.md](view.md) · 源目录 [`public/`](../../public/) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 分工
|
||||
|
||||
| 路径 | 是否入库 | 职责 |
|
||||
|------|----------|------|
|
||||
| `doc/` | 是 | 开发者设计 / ADR / 路线图(单数 `doc`,勿再造 `docs/`) |
|
||||
| `public/**/*.mq.md` | 是 | 用户可读、可执行、可下载的介绍(结构 / 关键字 / 特性迭代) |
|
||||
| `public/index.html`、`public/pages/` | **否**(ignore) | `marqdo view output` 生成的 HTML |
|
||||
| `tests/{structure,keywords,errors}/` | 是 | 金样例与失败夹具(含 errors) |
|
||||
| 远程分支 `gh-pages` | 发布产物 | 发布整个 `public/`(源文件 + 生成 HTML) |
|
||||
|
||||
**禁止**把 `tests/errors/` 编进用户站。
|
||||
|
||||
---
|
||||
|
||||
## 2. 生成
|
||||
|
||||
```bash
|
||||
cargo run --release -- view output public -o public
|
||||
# 或
|
||||
./scripts/build-public.sh
|
||||
powershell -File ./scripts/build-public.ps1
|
||||
```
|
||||
|
||||
产物写在源旁:
|
||||
|
||||
```
|
||||
public/
|
||||
*.mq.md / structure/ / … # 入库源
|
||||
index.html # 生成(ignore)
|
||||
pages/… # 生成(ignore)
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 3. 发布分支
|
||||
|
||||
将构建后的 `public/` 推到 **`gh-pages`**。CI:`.github/workflows/pages.yml`。
|
||||
|
||||
仓库 Settings → Pages → Source = Deploy from branch → `gh-pages` / root。
|
||||
|
||||
---
|
||||
|
||||
## 4. 验收
|
||||
|
||||
1. `public/` 下每个 `.mq.md`(除纯工具模块外)`marqdo run` 退出码 0。
|
||||
2. `view output public -o public` 后首页为欢迎页,侧栏无 errors。
|
||||
3. 主分支跟踪 `public/**/*.mq.md`;不提交 `public/index.html` / `public/pages/`。
|
||||
@@ -1,113 +0,0 @@
|
||||
# `marqdo view` — 源结构浏览器与静态文档导出
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已定(v0.0.2 方向) |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 相关 | [examples-and-tests.md](examples-and-tests.md) · [generated-yaml-manifest.md](generated-yaml-manifest.md) · 视觉参考 [id.cflmy.cn](https://id.cflmy.cn) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 动机
|
||||
|
||||
`.mq.md` 既是文档也是程序。需要:
|
||||
|
||||
1. **本地浏览**:按 AST 展示结构 + 执行结果;
|
||||
2. **静态导出**:同一套渲染写成 HTML,作为**用户文档站点**(勿手写第二套站点);
|
||||
3. **启动快**:样式极简,无外链字体/厚主题,避免 view 冷启动慢。
|
||||
|
||||
---
|
||||
|
||||
## 2. 视觉(Apple HIG / Docs 极简)
|
||||
|
||||
对齐 [Apple HIG](https://developer.apple.com/design/human-interface-guidelines) 的 **clarity / deference / white space**,并参考常见 docs 布局(sticky 侧栏 + 居中主栏,见 Nextra / Docusaurus 类站点):**系统灰底、白内容面、浅分隔线、系统字体**。作者站 [id.cflmy.cn](https://id.cflmy.cn) 仍作克制感参考,但不强行纯黑描边。
|
||||
|
||||
| 规则 | 要求 |
|
||||
|------|------|
|
||||
| 色板 | 页底 `#f5f5f7`;内容面 `#ffffff`;正文 `#1d1d1f`;次要字 `#6e6e73`;分隔 `#d2d2d7`;选中侧栏项反白 |
|
||||
| 布局 | 壳层 `max-width ≈ 1400px` 居中;侧栏 ≈280px sticky;主内容 `max-width ≈ 58rem`(宽屏可读、不过窄);**≤800px 侧栏收起**,顶栏汉堡(checkbox,无 JS) |
|
||||
| 默认页 | 打开目录时 **直接展示排序后的第一个 `.mq.md`**(实时 `/` 与静态 `index.html` 同),不要求用户先从欢迎页点选 |
|
||||
| 字体 | 仅系统栈:`-apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif`;等宽 `ui-monospace, SFMono-Regular, Menlo, Consolas, monospace` |
|
||||
| 外链 | **禁止** Google Fonts / CDN 样式;CSS 全部内联于 HTML |
|
||||
| 装饰 | 无多层阴影、无渐变、无发光;圆角 ≈12px;结构区为分组列表(底部分隔),非堆叠厚卡片 |
|
||||
| 诊断路径 | 展示时去掉 Windows `\\?\` 前缀,并优先用相对 view 根的路径 |
|
||||
|
||||
验收:首屏无外网字体请求;宽屏主栏明显宽于早期 `40rem` 方案。
|
||||
|
||||
---
|
||||
|
||||
## 3. CLI
|
||||
|
||||
### 3.1 实时浏览
|
||||
|
||||
```bash
|
||||
marqdo view [PATH] [--port PORT] [--host HOST] [--no-open]
|
||||
```
|
||||
|
||||
| 参数 | 默认 | 说明 |
|
||||
|------|------|------|
|
||||
| `PATH` | `.` | `.mq.md` 或目录 |
|
||||
| `--port` | `7429` | |
|
||||
| `--host` | `127.0.0.1` | |
|
||||
| `--no-open` | 关 | 不打开浏览器 |
|
||||
|
||||
### 3.2 静态导出(文档生成)
|
||||
|
||||
```bash
|
||||
marqdo view output [PATH] -o OUT_DIR [--no-exec]
|
||||
```
|
||||
|
||||
| 参数 | 默认 | 说明 |
|
||||
|------|------|------|
|
||||
| `PATH` | `.` | 与 `view` 相同扫描范围 |
|
||||
| `-o` / `--out` | (必填) | 输出目录(不存在则创建) |
|
||||
| `--no-exec` | 关 | 不跑程序,执行区显示「skipped」 |
|
||||
|
||||
**产物布局:**
|
||||
|
||||
```
|
||||
OUT_DIR/
|
||||
index.html # 默认 = 排序后第一个 .mq.md 的完整页(侧栏高亮该项)
|
||||
pages/
|
||||
<相对路径>.html # 每个 .mq.md 一页;路径中的 `/` 保留为子目录
|
||||
# 例:structure/hello.mq.md → pages/structure/hello.mq.md.html
|
||||
```
|
||||
|
||||
- 页内链接一律**相对路径**,可用任意静态服务器或 `file://`(同目录结构下)打开。
|
||||
- 用户文档推荐流程:`marqdo view output public -o public`,将生成物发布到 `gh-pages`(见 [user-site.md](user-site.md))。
|
||||
- 金样例浏览仍可用:`marqdo view output tests -o /tmp/mq-tests`(含 errors,勿当对外用户站)。
|
||||
- 渲染逻辑与实时 `view` **共用**同一套 HTML 构件(结构 / 执行 / 源码),禁止两套皮肤分叉。
|
||||
|
||||
示例:
|
||||
|
||||
```bash
|
||||
marqdo view output public -o public
|
||||
marqdo view output tests/structure/hello.mq.md -o /tmp/hello-doc
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 信息架构(不变)
|
||||
|
||||
侧栏索引 + 主区三节:结构(AST+注释插回)· 执行 · 源码。表达式为表面语法,非 Debug。
|
||||
|
||||
---
|
||||
|
||||
## 5. HTTP(实时模式)
|
||||
|
||||
| 方法 | 路径 | 含义 |
|
||||
|------|------|------|
|
||||
| `GET` | `/` | 默认打开第一个 `.mq.md`(无文件时为空提示) |
|
||||
| `GET` | `/file?path=…` | 单文件页 |
|
||||
| `GET` | `/api/tree` | JSON 树(可选) |
|
||||
|
||||
根目录锁死;拒绝 `..` 逃逸。
|
||||
|
||||
---
|
||||
|
||||
## 6. 验收
|
||||
|
||||
1. 实时 `view`:HIG 风极简、无外链字体、结构与执行正确;打开目录即见首个文件。
|
||||
2. `view output public -o public`(或临时目录)生成可点的 `index.html`(首文件)与各 `pages/…`。
|
||||
3. 静态页中执行区与 `marqdo run` 一致(未加 `--no-exec` 时);失败诊断路径无 `\\?\`。
|
||||
4. 冷启动无明显外网依赖。
|
||||
@@ -1,87 +0,0 @@
|
||||
# 开发环境配置(Rust 参考解释器)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | M0 |
|
||||
| 相关 | [dependencies.md](design/dependencies.md) · [interpreter.md](roadmap/interpreter.md) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 必备软件
|
||||
|
||||
| 软件 | 要求 | 检查 |
|
||||
|------|------|------|
|
||||
| Rust + Cargo | stable,建议 ≥ 1.81(本机验证过 1.81) | `rustc --version` / `cargo --version` |
|
||||
| Git | 任意近期版本 | `git --version` |
|
||||
|
||||
安装 Rust(若尚未安装):
|
||||
|
||||
- 官方:[https://rustup.rs/](https://rustup.rs/)
|
||||
- Windows:下载 `rustup-init.exe`,按提示安装后**重新打开终端**
|
||||
|
||||
本仓库可选 `rust-toolchain.toml`(钉 1.81.0)。若本机无 `rustup`、但已有匹配的 `rustc`/`cargo`,也可直接开发。
|
||||
|
||||
**不需要:** Flex、Bison、LLVM、Node/npm(实现栈为 Rust)。
|
||||
|
||||
---
|
||||
|
||||
## 2. 获取代码与构建
|
||||
|
||||
```bash
|
||||
git clone https://github.com/cflmy/marqdo.git
|
||||
cd marqdo
|
||||
|
||||
cargo build
|
||||
cargo test
|
||||
cargo run -- run tests/structure/hello.mq.md
|
||||
```
|
||||
|
||||
当前 M0:`run` 会读入文件并明确报错「evaluation not implemented」(脚手架,非静默假成功)。
|
||||
|
||||
> 若 `cargo build` 报 `edition2024` / 过新 crate:仓库已对 `clap` 等做兼容钉扎(见 `Cargo.toml`);请使用附带的 `Cargo.lock`,勿盲目 `cargo update` 到最新 major。
|
||||
|
||||
---
|
||||
|
||||
## 3. 推荐组件
|
||||
|
||||
```bash
|
||||
rustup component add rustfmt clippy # 若使用 rustup
|
||||
cargo fmt
|
||||
cargo clippy --all-targets
|
||||
```
|
||||
|
||||
代理下拉 crate(可选,与 git 推送类似):
|
||||
|
||||
```bash
|
||||
# Windows PowerShell 示例
|
||||
$env:HTTPS_PROXY="http://127.0.0.1:7897"
|
||||
$env:HTTP_PROXY="http://127.0.0.1:7897"
|
||||
cargo build
|
||||
```
|
||||
|
||||
或配置 `%USERPROFILE%\.cargo\config.toml`:
|
||||
|
||||
```toml
|
||||
[http]
|
||||
proxy = "http://127.0.0.1:7897"
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 4. 目录约定
|
||||
|
||||
| 路径 | 含义 |
|
||||
|------|------|
|
||||
| `src/lex` | 行分类 / 词法(自研) |
|
||||
| `src/parse` | 递归下降语法 |
|
||||
| `src/diagnostics` | 诊断 |
|
||||
| `tests/` | 金样例 + 集成测试(`structure` / `keywords` / `errors`) |
|
||||
| `public/` | 用户可执行文档(无 errors) |
|
||||
| `spike/` | 旧 Python 风险探测,非运行时依赖 |
|
||||
| `doc/` | 设计与路线图 |
|
||||
|
||||
---
|
||||
|
||||
## 5. 下一里程碑
|
||||
|
||||
见 [interpreter.md](roadmap/interpreter.md):M1 词法·行分类与最小 AST。
|
||||
@@ -1,215 +0,0 @@
|
||||
# 调研:Google Open Knowledge Format(OKF)与 Marqdo
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 调研笔记 |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 对象 | [OKF v0.2](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md) |
|
||||
| 公告 | [v0.1 介绍](https://cloud.google.com/blog/products/data-analytics/how-the-open-knowledge-format-can-improve-data-sharing) · [v0.2 trust signals](https://cloud.google.com/blog/products/data-analytics/okf-v0-2-adds-trust-signals) |
|
||||
|
||||
---
|
||||
|
||||
## 1. OKF 是什么
|
||||
|
||||
**Open Knowledge Format(开放知识格式)** 是 Google Cloud 于 2026 年 6 月发布的厂商中立开放规范(Apache 2.0)。它把「LLM Wiki」模式形式化为可移植格式:用**目录树中的 Markdown 文件 + YAML frontmatter** 表示组织知识(表结构、指标、API、操作手册等),供人类与 AI Agent 共同阅读、交换与维护。
|
||||
|
||||
一句话定位:
|
||||
|
||||
> 知识应活在**格式**里,而不是专有服务或散落的非结构化文本里。
|
||||
|
||||
### 核心形态
|
||||
|
||||
```
|
||||
bundle/
|
||||
index.md # 可选:目录索引(渐进披露)
|
||||
log.md # 可选:变更历史
|
||||
concepts/.../*.md # 每个概念一个 Markdown 文件
|
||||
```
|
||||
|
||||
每个概念文件:
|
||||
|
||||
```yaml
|
||||
---
|
||||
type: Metric # 唯一必填
|
||||
title: Monthly Active Users
|
||||
description: ...
|
||||
tags: [product, growth]
|
||||
sources: [...] # v0.2:出处
|
||||
generated: {...} # v0.2:谁生成的
|
||||
verified: {...} # v0.2:谁验证的
|
||||
status: stable # v0.2:生命周期
|
||||
stale_after: 2026-12-01 # v0.2:过期日
|
||||
---
|
||||
|
||||
# 正文(自由 Markdown)
|
||||
|
||||
指标定义为……
|
||||
```
|
||||
|
||||
- **Concept ID** = 相对路径去掉 `.md`
|
||||
- **链接** = 普通 Markdown 链接,形成可遍历关系图
|
||||
- **无中心 schema registry**;未知 `type` 必须被优雅降级处理
|
||||
|
||||
### 设计三原则(官方表述)
|
||||
|
||||
1. **Minimally opinionated** — 只强制互通所需的最小公约;其余留给生产者。
|
||||
2. **Producer / consumer independence** — 写知识的人(或 Agent)与读知识的 Agent/工具解耦;格式即契约。
|
||||
3. **Format, not platform** — 不绑定云、数据库、模型或 Agent 框架;`cat` 能读,`git clone` 能分发。
|
||||
|
||||
### v0.2 新增:五类信任信号
|
||||
|
||||
当知识主要由 Agent **持续生成**时,纯 Markdown 不够。v0.2 把下列问题变成 frontmatter 一等字段:
|
||||
|
||||
| 问题 | 机制 |
|
||||
|------|------|
|
||||
| 从何而来? | `sources`(出处 + 可信度信号,不作统一打分) |
|
||||
| 该信多少? | `generated` / `verified` → 推导 trust tier(未验证 / 机器确认 / 人工审核) |
|
||||
| 是否仍真? | `stale_after`(绝对日期,非相对 TTL) |
|
||||
| 是否现行? | `status`: `draft` → `stable` → `deprecated` |
|
||||
| 数字是否按约定算出? | 概念类型 `Attested Computation`:executor 跑计算出 receipt,**非 LLM** 的 attester 核验 |
|
||||
|
||||
---
|
||||
|
||||
## 2. OKF 与 Marqdo:相邻,但不等同
|
||||
|
||||
| 维度 | OKF | Marqdo |
|
||||
|------|-----|--------|
|
||||
| 本质 | **知识交换格式** | **编程语言** |
|
||||
| 文件角色 | 描述资产与概念的文档 | 可执行程序 = 可渲染文档 |
|
||||
| 机器侧 | 解析 metadata、遍历链接、过滤信任 | 解析、类型检查、求值/编译 |
|
||||
| Markdown 地位 | 载体与呈现层 | **语法表层的一部分**(源即 Markdown) |
|
||||
| 成功标准 | 跨组织互通、Agent 可策展 | 严肃编程能力 + 阅读体验同时成立 |
|
||||
|
||||
OKF 回答:「人和 Agent 如何**共享与信任知识**?」
|
||||
Marqdo 回答:「程序如何**本身就是知识**,且仍能运行?」
|
||||
|
||||
因此借鉴应落在**表示哲学与工程约束**,而不是照搬「知识目录」产品形态。
|
||||
|
||||
---
|
||||
|
||||
## 3. 值得借鉴的设计点
|
||||
|
||||
### 3.1 后缀与生态搭便车 — 已采纳
|
||||
|
||||
OKF 坚持「就是 Markdown」:GitHub 渲染、编辑器预览、静态站、搜索索引零摩擦。
|
||||
|
||||
**Marqdo 对应决策:源文件后缀为 `.mq.md`。**
|
||||
|
||||
- `.md` 确保通用 Markdown 渲染器开箱可用
|
||||
- `.mq` 前缀声明这是 Marqdo 源,而非普通文档
|
||||
- 与 OKF「格式优先于平台」一致:可读性不依赖自研 viewer
|
||||
|
||||
### 3.2 最小强制面(Minimally opinionated)
|
||||
|
||||
OKF 只强制 `type`;其余可选,未知字段保留不拒绝。
|
||||
|
||||
**对 Marqdo 的启发:**
|
||||
|
||||
- 语言的「文档面」与「程序面」之间,划清**硬语法**与**散文**
|
||||
- 第一版语法宜小:标题层级、声明、表达式……先钉死互通/可执行最小集
|
||||
- 扩展用约定或可选 frontmatter,避免一上来造完整注解宇宙
|
||||
|
||||
### 3.3 生成式 YAML / OKF 清单 — 已采纳方向(已修正)
|
||||
|
||||
OKF 用 YAML frontmatter 承载「可查询元数据」。Marqdo **借鉴其形态**,但职责不同:
|
||||
|
||||
**YAML(OKF 风格知识包)由工具从 `.mq.md` 自动生成,不是人手写的配置文件。**
|
||||
|
||||
详见 [`design/generated-yaml-manifest.md`](../design/generated-yaml-manifest.md)。
|
||||
|
||||
| | |
|
||||
|--|--|
|
||||
| 类比 | 其它语言中由工具维护的依赖描述(如 `Cargo.toml` / `requirements.txt` 所承担的那类角色) |
|
||||
| 形态 | OKF:概念目录 + YAML frontmatter + Markdown 正文 |
|
||||
| 用途 | ① 编译器/包管理消费依赖图与导出 ② **自动生成本项目文档**(模块索引、依赖关系等) |
|
||||
| 权威 | 始终是手写 `.mq.md`;清单可删、可重建 |
|
||||
|
||||
```
|
||||
.mq.md 源(人写)
|
||||
→ marqdo 工具链
|
||||
→ 生成 OKF 风格清单(YAML + 概念页)
|
||||
→ 供编译解析,并渲染为项目目录文档
|
||||
```
|
||||
|
||||
执行方式等运行参数不放进该 YAML 当配置;由 CLI / 子命令决定。
|
||||
程序本体(类型、函数)只活在源正文里。
|
||||
|
||||
### 3.4 路径即身份,链接即关系
|
||||
|
||||
Concept ID = 路径;关系 = Markdown 链接;目录 = 渐进披露(`index.md`)。
|
||||
|
||||
**对模块系统的启发:**
|
||||
|
||||
- 文件路径可成为模块身份的一部分(类比 OKF concept ID)
|
||||
- `import` / 交叉引用尽量与 Markdown 链接同构,使「读文档跳转」与「解析依赖」共用一种边
|
||||
- 大型程序按「书的章节」组织目录,而不是扁平包名墙
|
||||
|
||||
### 3.5 生产者 / 消费者分离
|
||||
|
||||
同一 bundle:人手写、Agent 生成、管道导出,均可被另一 Agent 或 UI 消费。
|
||||
|
||||
**对 Marqdo 工具链:**
|
||||
|
||||
- 解析器、渲染器、求值器、LSP 都是**消费者**;源格式是唯一契约
|
||||
- 允许 Agent 协助编写 `.mq.md`,但语言必须对「纯手写」同样友好
|
||||
- 不把语义锁进某一 IDE 或云服务
|
||||
|
||||
### 3.6 信任与 attestation(中长期)
|
||||
|
||||
OKF v0.2 的 Attested Computation:批准的算法 + 确定性核验,防止 Agent「随口报数」。
|
||||
|
||||
**远期可借鉴(非 v0 范围):**
|
||||
|
||||
- 文档中嵌入的「可运行示例」是否经过核验执行?
|
||||
- 渲染出的结果是否带来源与 receipt?
|
||||
- Agent 生成的 Marqdo 模块如何标注 `generated` / `verified`?
|
||||
|
||||
这强化「文档中的数字/行为与真实执行一致」——与 Marqdo「同一份真相」高度同向。
|
||||
|
||||
### 3.7 规范本身的克制
|
||||
|
||||
OKF 规范强调:一页纸能讲清 v0.1 的互通面;v0.2 只**加词汇、不加强制规则**。
|
||||
|
||||
**对 Marqdo 文档文化:**
|
||||
|
||||
- ADR 记录否决项
|
||||
- 语法草案保持短小、可验证的 conformance 描述
|
||||
- 版本演进优先加法兼容,避免随意破坏「已是有效程序」的源文件
|
||||
|
||||
---
|
||||
|
||||
## 4. 不应照搬之处
|
||||
|
||||
1. **OKF 不是语言** — 其 body 是自由散文;Marqdo body 必须有严格可执行语义。不能停在「Markdown 知识库」。
|
||||
2. **无中心 type 注册** 适合知识目录;编程语言的类型系统需要更强的一致性与检查规则。
|
||||
3. **`Attested Computation` 的 executor/attester** 面向数据平台查询核验;Marqdo 若引入类似机制,应长在「测试 / 示例求值 / 再现构建」上,而不是 BigQuery 收据模型。
|
||||
4. **保留文件名**(`index.md` / `log.md`)可参考,但是否占用需在模块设计里单独 ADR,避免与源文件约定冲突。
|
||||
|
||||
---
|
||||
|
||||
## 5. 建议纳入 Marqdo 设计议程的议题
|
||||
|
||||
来自本次调研、建议在 `design/` 或 `adr/` 中跟进:
|
||||
|
||||
1. **`.mq.md` 的双重解析模型** — Markdown CST 与 Marqdo AST 如何共享同一文本、何处分叉。
|
||||
2. **生成式 OKF 清单的落盘与命令** — 路径、是否提交 git、`sync`/`doc` 行为(方向已采纳,见 [design/generated-yaml-manifest.md](../design/generated-yaml-manifest.md))。
|
||||
3. **正文中的依赖声明语法** — import / 链接如何写出,供工具提取进生成清单。
|
||||
4. **Agent 友好但不 Agent 绑定** — 源格式对 LLM 可写,语义对确定性工具可检。
|
||||
5. **可渲染结果的 attestation(后期)** — 文档内求值结果的可验证性。
|
||||
|
||||
---
|
||||
|
||||
## 6. 参考链接
|
||||
|
||||
- 规范:[okf/SPEC.md](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md)(v0.2)
|
||||
- 仓库:[GoogleCloudPlatform/knowledge-catalog](https://github.com/GoogleCloudPlatform/knowledge-catalog/tree/main/okf)
|
||||
- 博客:[Introducing OKF](https://cloud.google.com/blog/products/data-analytics/how-the-open-knowledge-format-can-improve-data-sharing)
|
||||
- 博客:[OKF v0.2 trust signals](https://cloud.google.com/blog/products/data-analytics/okf-v0-2-adds-trust-signals)
|
||||
|
||||
---
|
||||
|
||||
## 7. 结论
|
||||
|
||||
OKF 证明了一条与 Marqdo 同向的产业判断:**人类可读的 Markdown 可以成为机器与 Agent 的一等交换面**,前提是约定足够小、足够稳,并把信任做成可查询字段而非口头保证。
|
||||
|
||||
Marqdo 比 OKF 多走一步:Markdown 不仅是知识的容器,更是**程序的表面语法**。我们借鉴 OKF 的形态,用作**从源自动生成的依赖清单与项目目录文档**(而非人手配置);同时借鉴「格式而非平台」、路径/链接身份、以及(远期)provenance。语言设计必须单独完成——**可渲染不等于可执行,可执行才是 Marqdo 的终点。**
|
||||
@@ -1,178 +0,0 @@
|
||||
# Marqdo 参考实现:正经解释器路线图
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 状态 | 已采纳方向 |
|
||||
| 日期 | 2026-08-04 |
|
||||
| 目标 | `marqdo run path/to/index.mq.md` 得到真实执行结果;非演示玩具 |
|
||||
| 相关 | [markdown-mapping.md](../design/markdown-mapping.md) · [ADR 0001](../adr/0001-implementation-language.md) · [USTC 编译课 2025](https://ustc-compiler-2025.github.io/homepage/) |
|
||||
|
||||
---
|
||||
|
||||
## 1. 为何是解释器,而不是 USTC 式「编译到机器码」
|
||||
|
||||
[USTC《编译原理与技术》2025](https://ustc-compiler-2025.github.io/homepage/) 的实验链是经典**编译器**路径:
|
||||
|
||||
```
|
||||
源码 → 词法(Flex) → 语法(Bison) → AST
|
||||
→ 语义 / Light IR → 优化 → 后端(龙芯汇编等)
|
||||
```
|
||||
|
||||
这条路适合 Cminusf 一类「最终变成机器指令」的语言。Marqdo 的产品形态是:
|
||||
|
||||
- 源即 Markdown 文档,**打开即读、运行即算**;
|
||||
- 首要交付是 **从 `index.mq.md` 得到求值结果**(stdout、返回值、模块图),不是龙芯/ x86 二进制;
|
||||
- 语法表面是 Markup-as-Syntax,前端与传统正则+Bison 不同,但**中后端的编译学知识仍然全部用得上**。
|
||||
|
||||
因此:
|
||||
|
||||
| USTC / 龙书阶段 | Marqdo 解释器中的对应 |
|
||||
|-----------------|------------------------|
|
||||
| 词法分析 | **行分类 + 标记词法**(无标记=注释;`#`/`*`/`**`/`>`/`+`/`-`/表…) |
|
||||
| 语法分析 | **结构解析 → Marqdo AST**(可递归下降;不必上 Bison,除非日后自研纯文本方言) |
|
||||
| 语义分析 | 作用域、提升、导入、形参绑定、类型(可后置) |
|
||||
| 中间代码 | **可选**:先树遍历;第二期再降到**字节码** |
|
||||
| 优化 / 目标代码 | **非 v1 目标**;日后若要可另开「编译后端」ADR |
|
||||
|
||||
**结论:做正经解释器 = 把编译前端做扎实 + 把运行时做完整;不是跳过词法语法,也不是一上来 LLVM。**
|
||||
|
||||
权威地图见 [Crafting Interpreters — A Map of the Territory](https://craftinginterpreters.com/a-map-of-the-territory.html):用户眼里的「解释器」内部往往仍含编译到字节码(如 CPython);树遍历是第一期,字节码 VM 是第二期。
|
||||
|
||||
---
|
||||
|
||||
## 2. 推荐总体架构
|
||||
|
||||
```
|
||||
index.mq.md (+ 导入的 .mq.md)
|
||||
│
|
||||
▼
|
||||
┌───────────────────┐
|
||||
│ 0. 源加载 / 模块图 │ frontmatter `> a.mq.md` → 依赖图
|
||||
└─────────┬─────────┘
|
||||
▼
|
||||
┌───────────────────┐
|
||||
│ 1. 词法·行分类 │ 注释行丢弃语义;代码行 → Token 流
|
||||
│ (+ MD 块辅助) │ pulldown-cmark/comrak;+/- 靠行扫描
|
||||
└─────────┬─────────┘
|
||||
▼
|
||||
┌───────────────────┐
|
||||
│ 2. 语法分析 │ Token/块 → Marqdo AST
|
||||
│ (递归下降) │ Module / Fun / Stmt / Expr / Branch / Loop …
|
||||
│ │ **不用 Flex/Bison**(见 dependencies.md)
|
||||
└─────────┬─────────┘
|
||||
▼
|
||||
┌───────────────────┐
|
||||
│ 3. 语义·绑定 │ Pass1: 收集函数(提升)+ 导入合并
|
||||
│ │ 作用域链、形参、未定义名诊断
|
||||
└─────────┬─────────┘
|
||||
▼
|
||||
┌───────────────────┐
|
||||
│ 4a. 树遍历解释器 │ ← Phase I(必须先完成,跑通全部 tests 金样例)
|
||||
│ 或 │
|
||||
│ 4b. 字节码编译+VM │ ← Phase II(性能与「更像真语言实现」)
|
||||
└─────────┬─────────┘
|
||||
▼
|
||||
stdout / 返回值 / 退出码
|
||||
```
|
||||
|
||||
Phase I 对齐 Crafting Interpreters 的 **jlox(树遍历)**;Phase II 对齐 **clox(字节码 VM)**(见 [Chunks of Bytecode](https://craftinginterpreters.com/chunks-of-bytecode.html))。这是 Python/Ruby/Lua 主实现走过的正经路径,不是玩具捷径。
|
||||
|
||||
---
|
||||
|
||||
## 3. 各阶段「做满」的标准(反玩具清单)
|
||||
|
||||
### Phase 0 — 工程骨架(正式包,不是 `spike/`)
|
||||
|
||||
- 包名:`marqdo`(`src/marqdo/` 或 `marqdo/`)
|
||||
- CLI:`marqdo run <file.mq.md>`,默认找目录下 `index.mq.md`
|
||||
- 诊断:带文件名、行号、列号
|
||||
- 测试:每个 `tests/{structure,keywords}/*.mq.md` 有期望 stdout(金样例);CI 可跑
|
||||
|
||||
### Phase I — 可运行的语言核心(树遍历)
|
||||
|
||||
必须全部为真实现,禁止「正则特判 hello」:
|
||||
|
||||
1. **词法 / 行分类**:注释与代码严格分离。
|
||||
2. **语法 → AST**:函数、形参、`*` 语句、`**` 返回、`>` 调用、`+` 分支、`-` 循环、表格集合、绑定与 `==`。
|
||||
3. **语义**:提升、嵌套作用域、`##` 私有、frontmatter 导入公有顶层。
|
||||
4. **运行时**:环境、调用栈、值(文/数/表/记录)、内置 `print`。
|
||||
5. **验收**:`tests/structure/*` 与 `tests/keywords/*` 全部 `marqdo run` 通过。
|
||||
|
||||
### Phase II — 字节码 VM(正经化)
|
||||
|
||||
- AST → 线性字节码(栈式 VM 即可,与 clox / [GoAWK 经验](https://benhoyt.com/writings/goawk-compiler-vm/) 同类)
|
||||
- 控制流用跳转指令实现分支/循环
|
||||
- 同一套金样例必须 bit-同结果(回归)
|
||||
- 性能与可调试性(反汇编、栈跟踪)优于 Phase I
|
||||
|
||||
### Phase III — 语言完备(按需)
|
||||
|
||||
- 更完整表达式文法、错误模型、外联围栏 FFI
|
||||
- 生成 OKF 依赖目录
|
||||
- (可选)另一后端:编译到 Python/WASM——**另开 ADR**,不替代自研语义
|
||||
|
||||
---
|
||||
|
||||
## 4. 与 USTC Lab 的知识复用(学什么、不搬什么)
|
||||
|
||||
| 课程内容(摘要) | Marqdo 用法 |
|
||||
|------------------|-------------|
|
||||
| Lab1 词法/语法/AST | **直接对标** Phase I 前端;工具可自研递归下降,不必 Flex/Bison |
|
||||
| Lab2 IR / 访问者 | Phase II 字节码 ≈ 轻量 IR;访问者可用于 AST→字节码 |
|
||||
| Lab3 后端汇编 | **v1 不做**;解释器 VM 代替机器后端 |
|
||||
| Lab4 优化 | Phase II 之后可选;解释器也可做常量折叠等 |
|
||||
|
||||
教材仍可读:龙书、陈意云《编译原理》、课主页参考书;解释器专项读 **Crafting Interpreters**(免费:[craftinginterpreters.com](https://craftinginterpreters.com/))。
|
||||
|
||||
---
|
||||
|
||||
## 5. 实现语言(本路线图默认)
|
||||
|
||||
**参考解释器:Rust**([ADR 0001](../adr/0001-implementation-language.md))。
|
||||
|
||||
- 词法/语法:**自研 + GFM crate**,不用 Flex/Bison([dependencies.md](../design/dependencies.md))。
|
||||
- Python `spike/` 仅作风险探测与算法草稿。
|
||||
- Phase I 树遍历、Phase II 字节码 VM 均在 Rust 中实现。
|
||||
|
||||
---
|
||||
|
||||
## 6. 目录规划(正式代码,非 spike)
|
||||
|
||||
```
|
||||
Cargo.toml
|
||||
src/lex/ parse/ ast/ sema/ interp/ bytecode/ runtime/
|
||||
tests/ # gold.rs + structure|keywords|errors 夹具
|
||||
public/ # 用户可执行文档
|
||||
doc/ # 设计文稿
|
||||
spike/ # Python 存档,非运行时依赖
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
## 7. 近期里程碑(可执行顺序)
|
||||
|
||||
| 周序 | 交付 | 完成定义 |
|
||||
|------|------|----------|
|
||||
| M0 | 正式包 + CLI 空壳 + 金样例框架 | `marqdo run` 可调用;测试发现「未实现」 | ✅ |
|
||||
| M1 | 词法·行分类 + 最小 AST | 单测覆盖注释/代码行 | ✅ |
|
||||
| M2 | 解析:函数、输出调用、返回 | `hello` + `index` 金样例绿 | ✅ |
|
||||
| M3 | 分支、循环、表格、绑定 | `branch`/`loop`/`collection` 绿 | ✅ |
|
||||
| M4 | 导入与提升 | `with-import` 绿;**宣称 Phase I 达标** | ✅ |
|
||||
| M5 | 字节码设计文档 + 原型 opcode | 核心金样例双后端一致;覆盖表见 [bytecode.md](../design/bytecode.md) | ✅ 原型 |
|
||||
|
||||
**Phase I 完成前,不宣称「语言已实现」。**
|
||||
**仅 hello 特判通过,不算完成。**
|
||||
|
||||
---
|
||||
|
||||
## 8. 成功判据(产品级)
|
||||
|
||||
在仓库根或任意含 `index.mq.md` 的目录:
|
||||
|
||||
```bash
|
||||
marqdo run tests/structure/nested-call.mq.md
|
||||
# 或
|
||||
marqdo run tests/structure/import/main.mq.md
|
||||
```
|
||||
|
||||
输出与金样例一致;错误带位置;新增语法必须加金样例与单测。这才是「一门解释型语言」的最低合格线。
|
||||
@@ -0,0 +1,105 @@
|
||||
# 架构与所有权
|
||||
|
||||
自建 Git `git.cflmy.cn/cflmy` 是代码、工单和合并的权威,`ci.cflmy.cn` 是 CI 权威,GitHub 仅作镜像或分发渠道。主仓库维护生态组件关系、精确组合、跨组件验收、发行与责任治理;领域聚合仓库维护本领域的合同与组合验收;功能仓库拥有唯一实现、测试和缺陷修复。
|
||||
|
||||
## 三种关系,不得混用
|
||||
|
||||
| 关系 | 表达载体 | 用途 | 约束 |
|
||||
| --- | --- | --- | --- |
|
||||
| 治理树 | `.gitmodules` + Git tree gitlink + 每层 `components.toml` | 源码归属、父级与提交身份 | 每个组件只有一个父级;全局 ID 与权威远端唯一;Gitlink 是提交身份唯一权威,`.gitmodules` 是权威远端唯一记录 |
|
||||
| 构建/制品依赖 DAG | `requires` 与真实 package/Cargo/Tool/Bundle 依赖 | 编译、打包、发行装配顺序 | 可以跨治理树;必须有向无环;聚合节点不是可被程序 import 的包 |
|
||||
| 协同验收关系 | `checks_with` | 跨组件测试与消费者回归 | 不是安装依赖;允许互相测试;调度固定点必须去重且不得互相等待形成死锁 |
|
||||
|
||||
组件关系不能由目录物理位置推导,也不能把兄弟仓库的源码路径当作公开依赖。`requires` 只表达真实直接构建或制品依赖,禁止把计划假想写成实际依赖。
|
||||
|
||||
## 治理树与分层
|
||||
|
||||
治理树最多两级 Gitlink:**根仓库 → 领域聚合仓库 → 功能仓库**(主仓库→领域→功能,深度 2)。新增三级 gitlink 需要生态 ADR 和真实跨仓维护收益,默认拒绝。目录层级不等于运行时依赖层级。
|
||||
|
||||
- **领域(`kind = "domain"`)**:工程治理角色,不是语言层也不是运行协议。领域仓库只登记直属子组件,可拥有 `components.toml`、`.gitmodules`、领域公共规范、跨组件集成测试、综合示例、发布装配脚本、ADR 与维护指南;禁止在其中建立 renderer、解析器、数据库驱动等生产实现,也禁止把子仓库源码复制进普通目录。领域 `requires = []`,`release` 为 `none`(普通领域)或 `base`(Stdlib Bundle 聚合)。
|
||||
- **功能组件**:`kind` 仍为 `core/stdlib/extension/tool/test`,在责任仓库独立实现、测试和发版;`release` 与 `kind` 的对应关系不变(base/optional/none)。
|
||||
- **唯一归属**:一个功能只有一个权威实现,一个组件只有一个治理归属,一个公共边界只有一套现行合同。已有仓库直接复用,不能因为命名不符创建重复实现。
|
||||
- **`planned` 纪律**:已有仓库可以通过 gitlink 固定已发布的开发提交。尚无提交的仓库登记在 [迁移台账](MIGRATION.md)。组件通过联合验收后才晋升为 `active` 并登记实际 `entry`。将直属组件迁入领域时,在同一根候选转移清单和 gitlink,保证一个组件只有一个父级。
|
||||
- **聚合准入**:功能拆分须至少有一种独立价值(独立维护责任、显著不同依赖/安全/平台边界、独立版本与制品、可重复独立验收)。若两个仓库几乎每个 PR 都必须一起改动且接口未稳定,应先收敛合同或合并,不能无限拆分。
|
||||
- **工具目录**(`tools/`)暂不聚合,现有四个 Tool 保持原路径。
|
||||
|
||||
**当前状态**(以 [components.toml](../components.toml) 与 [迁移台账](MIGRATION.md) 为准):根仓库有六个核心/工具 active 组件(`cli`、`conformance`、`view`、`knowledge`、`prove`、`lint`)和六个已交付源码的 active 标准库组件(`std-collections/data/fs/io/system/text`)。`std-core/encoding/net` 与十八个独立扩展仍是根层 planned 子模块。`extensions/web` 是 planned 领域子模块,Design 和 Preview 由 Web 领域仓挂载。`marqdo-stdlib` 聚合和 `web-components` 仍在计划中。
|
||||
|
||||
## 语言与产品层(不因仓库变多而改变)
|
||||
|
||||
| 层 | 权威所有者 | 允许 | 禁止 |
|
||||
| --- | --- | --- | --- |
|
||||
| L0 语言核心 | CLI | Markdown 映射、AST、IR、Value、Memory、求值 | Web/AI/数据库专属关键字 |
|
||||
| L1 平台能力 | CLI Capability Host | 权限、预算、通用资源/扩展机制 | 网页布局和业务协议 |
|
||||
| L2 标准库 | Stdlib 各功能仓库 | 基础发行默认安装的通用低层算法及薄封装 | 依赖领域扩展或大型专业运行环境 |
|
||||
| L3 扩展 | 各领域功能仓库 | 可选专业算法、协议和资源后端 | 修改或复制语言内核 |
|
||||
| L4 应用 | 用户项目 | 使用已发布能力实现具体任务 | 作为默认基础发行依赖 |
|
||||
| Tool(旁路) | 独立工具 | 通过公开 CLI 协议处理源码、分析及制品 | 伪装成 Runtime 插件,反向侵入核心 |
|
||||
|
||||
## 权威记录与递归校验
|
||||
|
||||
每个拥有子模块的聚合仓库只登记直接子组件;普通功能仓库不需要另建治理清单。配置与身份的唯一来源:
|
||||
|
||||
| 记录 | 权威内容 |
|
||||
| --- | --- |
|
||||
| `components.toml`(每层) | 组件 ID、父级路径、kind、state、owner、scope、`requires`、`checks_with`、release、active 入口 |
|
||||
| `.gitmodules`(每层) | 直属子组件权威远端 |
|
||||
| Git tree gitlink | 精确提交身份 |
|
||||
| Cargo.lock / `marqdo.lock` / 现行 Bundle manifest | 相应依赖与制品身份 |
|
||||
|
||||
主仓库 `scripts/check-layout.py` 校验 catalog、gitlink、远端与文件白名单。`--checkouts` 递归读取每个已挂载领域的固定提交,逐层验证 gitlink、远端、工作树和活跃入口,并检查全局 ID、依赖边界和无环性。CI 用 `--domain-paths` 在检出子组件前校验领域远端。 [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 各领域排他边界
|
||||
|
||||
| 领域 / 功能 | 应拥有 | 不应拥有 |
|
||||
| --- | --- | --- |
|
||||
| Stdlib/Core、Collections、Text、Encoding、Data、IO、FS、System、Net | 默认安装的通用低层能力及薄封装 | 专业计算、外部服务、HTTP 协议 |
|
||||
| Ext-Net(HTTP/WebSocket) | URL、HTTP 客户端/服务端协议、SSE、Cookie、Multipart、WebSocket 帧与生命周期 | Web 页面模型、应用实时协作状态 |
|
||||
| Web 领域 | 设计模型、快速预览、交付清单与组件复用 | 生产级前端框架、HTTP/DB/认证协议、AI 调度 |
|
||||
| Browser | 将来可选的真实浏览器执行宿主与平台桥 | 本期 Web 原型必需依赖、第二套解释器 |
|
||||
| AI / MCP | 模型访问、流式结果、工具调用数据;MCP 发现/调用/传输 | 全量 Agent 调度、HTTP 实现、Agent 框架 |
|
||||
| Database / Storage / Cache / Auth | 参数化查询与事务、存储接口、TTL 缓存、OIDC/会话/RBAC | Web 后台页面、文件系统原语、替代 Capability Host |
|
||||
| Crypto / Datetime / Regex / Archive | 成熟密码学封装、IANA 时区、完整正则、安全归档 | 自制不安全加密、重复宿主基础原语 |
|
||||
| Document / Engineering | 文档显式编辑、工程操作与产物 | 静态分析或编辑器全栈平台 |
|
||||
| Quantum / Linalg / Math | 量子态/电路/模拟、矩阵/张量/分解、数值与符号数学 | 复制矩阵内核、通用前端框架 |
|
||||
|
||||
上表是规划边界,不是开发完成承诺。旧标准库中 `net/http.mq.md`、`regex.mq.md`、`compress.mq.md` 的迁移必须有真实替代实现与验收才能退出原归属,不得先删造成回归,也不得长期维护两个官方实现。
|
||||
|
||||
## Web 领域
|
||||
|
||||
Web 领域的产品定义是**文档原生、可交互的前端设计原型及工程交付**,不是新的通用前端框架。GFM 表描述组件关系,普通 Markdown 描述内容与意图,链接表达精确的组件引用与设计依赖,有限场景表达交互原型;生产级前端由成熟框架完成。HTTP、数据库、认证、浏览器运行时仍是独立通用能力,不是原型工具的强制依赖。
|
||||
|
||||
- **唯一作者合同**:[marqdo-ext-web 的 WEB-DESIGN](https://git.cflmy.cn/cflmy/marqdo-ext-web/src/branch/main/docs/WEB-DESIGN.md)。主仓库、组件仓库和作者文档都引用它,不并列维护第二份现行合同;合同变更在该领域走 ADR 并与 Design/Preview 同候选验证。
|
||||
- **领域聚合** `marqdo-ext-web`(planned):治理、合同、示例、组合验收;无运行时入口,不实现 renderer/parser。
|
||||
- **Web Design** `marqdo-web-design`(planned):独立 Rust library,唯一解释作者合同、消费真实 CLI Analysis、产出设计模型/诊断/handoff;不启动服务、不渲染 DOM、不复制 CLI parser。
|
||||
- **Web Preview** `marqdo-web-preview`(planned):独立 executable + `tool.json`,注册唯一 `web` 命令;消费 Design 公开 API,生成离线安全预览与有限状态交互;不自行解释表格、不写任务专用 JS、不启动生产服务器。
|
||||
- **组件模板** `web-components`:候选,只有至少两个独立真实复用模板及稳定合同后才准入,不阻塞首版。
|
||||
- **边界**:首版不迁移 WASM、不重新实现语言、不要求旧 plugin 回调,不新增 CLI Web 关键字或 `@component` 语义;复杂视觉、真实登录/支付/数据库/网络和任意状态管理交给生产实现。Web 领域已通过 gitlink 固定开发提交,状态为 `planned`。 [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 新增能力与公共边界
|
||||
|
||||
先复用职责匹配的组件。需要独立维护、依赖、安全或发行边界时,为新仓库发起评审;加入标准库须证明基础发行默认需要、至少三个领域真实复用、依赖闭包受控,并说明错误、授权和预算语义。
|
||||
|
||||
需要新增 builtin、HostOp、值类型、语法或公共协议字段时,在 CLI 提交 ADR,写明现有机制为何不足、最小复现、三个领域用例、替换及正负例。Web 专属需求不得进入 CLI 核心;设计领域能自己解释的内容留在 Web 合同。公开接口破坏性更新按同一候选组合切换产生者和消费者,保留单套现行协议;历史行为通过固定版本的历史发行复现。
|
||||
|
||||
## 架构门禁
|
||||
|
||||
| 门禁 | 检查与拒绝条件 | 权威 |
|
||||
| --- | --- | --- |
|
||||
| 归属唯一 | Git tree/catalog 递归一致,一个全局 ID 与远端只出现一次,不允许同功能两个官方实现 | 根 |
|
||||
| 聚合纯度 | 根与领域聚合不含生产实现;新增文件须落在治理/集成/示例职责 | 根/领域 |
|
||||
| 深度 | 超过两级 Gitlink 拒绝,除非批准 ADR 先更新单一规则 | 根 |
|
||||
| 真实依赖 | active 不依赖 planned;requires DAG 无环;无父 checkout 或跨仓私有源码依赖 | 根/组件 |
|
||||
| 标准库准入 | 基础发行默认必需、低层、至少三类真实消费者、依赖与授权有界;新功能默认 extension | Stdlib/根 |
|
||||
| 内核准入 | 新 builtin/HostOp/语法/协议字段须 ADR、最小复现、三个不相关领域用例;Web 专属需求不进入 CLI | CLI |
|
||||
| Web 作者面 | 不新增核心语法、重复表头方言、隐式解析普通文档、HTML 注入默认通道 | Ext-Web/Design |
|
||||
| 通用渲染 | 新普通组件由设计文档复用实现;不得新增任务/页面/业务专用 renderer 分支 | Preview |
|
||||
| 原型诚实性 | 模拟明确标注;无真实后端、无假执行、无伪造生产测试 | Web |
|
||||
| 独立产品 | 组件能独立构建;只有实际产品需要才创建新仓库 | 各级 |
|
||||
| 现行合同唯一 | 不引入旧协议 fallback、版本数组、旧语法探测;配对候选一次切换 | 各级 |
|
||||
| 默认安装规模 | 基础制品不引入可选 Tool/领域环境;体积、构建时间及依赖增长记录基线 | 根/Stdlib |
|
||||
| 范围控制 | 每个 PR 关联责任工单、复现与验收;无关重构拆独立任务 | 各级 |
|
||||
|
||||
每次架构变更须回答:谁是唯一责任方?是否必须新增公开边界?如何证明现有机制不足?能否在单仓修复?新功能能否独立测试?删除或替代了什么?回答不明确则不进入开发。
|
||||
|
||||
跨组件测试以真实 CLI/Worker、独立消费者和现行权限配置验证。Native 后端与外部工具按 CLI 安全边界执行,权限、隔离和预算声明以可验证的实际行为为准。
|
||||
@@ -0,0 +1,101 @@
|
||||
# 开发、验收与发行
|
||||
|
||||
生态采用**逐层候选晋升**:功能仓库修实现,领域聚合仓库固定组合并做领域验收,主仓库固定整个递归树并做生态验收。任何一层失败都停在该层,不让未验证组合进入受保护的分支;回退根 gitlink 即可复现上一个已接受组合,不重写子仓库历史。
|
||||
|
||||
## 责任仓库与工单
|
||||
|
||||
1. 先确定唯一责任仓库:功能行为在功能仓库;领域合同、示例与组合在领域聚合仓库;gitlink、跨领域集成、发行组合与治理在主仓库。拿不准时按“第一个违反公开合同的所有者”定责,而不是按错误最后显示的仓库。
|
||||
2. 在责任仓库找到或建立工单,按 `.gitea/ISSUE_TEMPLATE/change.md` 记录:责任组件与类型、影响消费者、根/领域/组件 SHA、CLI 与依赖制品摘要及平台、最小 fixture 与命令、实际与预期结果、权威合同链接、修复范围、验收命令。
|
||||
3. 跨仓库阻塞在上游仓库开工单,并在消费者工单记录回归条件;不同问题拆分,重复发现追加证据。任何维护者或 AI 都可以读其它仓库定位,但修改必须进入对应责任仓库的独立提交。
|
||||
|
||||
## 分层候选流程
|
||||
|
||||
以 Web 领域为例,一般组件同理:
|
||||
|
||||
```text
|
||||
功能提交 C2(功能仓库,通过组件 CI)
|
||||
-> 领域 PR 将 gitlink 更新到 C2,通过领域 CI,形成 B2
|
||||
-> 主仓库 PR 将领域 gitlink 更新到 B2,通过根递归校验与受影响组合验收,形成 A2
|
||||
```
|
||||
|
||||
- 子模块的 detached HEAD 只用于复现与集成;开发应在子仓库独立创建分支后推送,禁止 `git submodule update --remote` 在发布/验收中追踪浮动分支。
|
||||
- 同一份公共合同切换需要多个组件同步变化时,在一个候选组合中提交整组 gitlink,配对候选联调通过后再晋升;不允许主分支出现半套协议。
|
||||
- 领域激活(planned → active)的门禁:两个功能仓具备真实 `entry` 与候选提交,领域 `components.toml` 与 gitlink 一致,领域 CI 和根递归校验通过,Design/Preview 等有依赖关系的组件获得同候选证据。已发布的开发提交可先作为 `planned` 子模块固定。
|
||||
|
||||
## 递归校验与组合检查
|
||||
|
||||
```sh
|
||||
git submodule update --init --recursive
|
||||
python3 scripts/check-layout.py # 根层:catalog/gitlink/远端/白名单
|
||||
python3 scripts/check-layout.py --checkouts # 递归:各 active 领域固定提交、全局图与依赖
|
||||
python3 -m unittest discover -s tests/integration
|
||||
bash scripts/integration.sh # 生态候选:真实 CLI 制品 + 组件验收
|
||||
```
|
||||
|
||||
- 校验器读取 Git tree 中固定提交的 catalog,不以工作区改动替代候选;`--checkouts` 需要子模块已初始化,缺失、错误 HEAD、脏工作区、错误入口都明确 FAIL/UNVERIFIED,不静默跳过。CI 先验证并检出直属子模块,再用 `--domain-paths` 校验领域的子模块远端,最后逐个领域检出直属子库。
|
||||
- 没有 active 领域时,新校验规则同样接受合法的直属功能组件,这不是历史协议兼容。
|
||||
- 未知的 active 入口、未声明的 gitlink、目录与 catalog 不一致都必须让候选失败。`planned` 不进入验收计数。
|
||||
- 当前 CI 为 `layout` 与 `candidate` 两段;统一 CLI 制品准备、声明驱动调度与递归影响分析仍在推进(见 `.woodpecker/eco.yml` 与主仓库工单),不得以本文件描述当作已实现。
|
||||
|
||||
## 三层验收
|
||||
|
||||
| 层 | 责任与证据 |
|
||||
| --- | --- |
|
||||
| C1 组件 CI | 责任组件独立检出、独立构建与测试、授权负例、固定依赖、打包 smoke;由组件仓库维护 |
|
||||
| C2 公共契约 | 真实 CLI 和 Worker、独立 Conformance 与消费者,覆盖当前协议、失败和正确身份 |
|
||||
| C3 生态集成 | 递归结构校验、公开冷克隆、精确 gitlink、官方基础发行、CLI Tool 与契约消费回归 |
|
||||
|
||||
三层不是重复跑三次测试:同一候选、同一制品、同一环境的有效证据可以复用;身份不匹配必须重跑。每个 active 组件提供独立验收入口(建议 `scripts/ci.sh` 或 `scripts/integration.sh`),从显式传入的 `MARQDO_BIN`、Bundle/依赖制品位置和隔离输出目录读取输入,不自行拉取浮动 CLI 或其它组件 main。
|
||||
|
||||
## 统一 CLI 与制品输入
|
||||
|
||||
- 生态候选使用**固定、可验证**的 CLI/Worker/Stdlib 候选制品;输入必须绑定 CLI gitlink SHA、目标平台、归档/二进制/Bundle digest、工具链与锁。
|
||||
- 标准库 Bundle 的唯一生产者是根仓库的 `scripts/build-stdlib.py`:它从根提交的精确组件 gitlink 读取各 active `kind = "stdlib"` 组件的 `modules/`,校验发布路径(只发布 `.mq.md`、拒绝 symlink/子模块/大小写与 NFC 冲突、`tests/` 不入库),生成现行 `stdlib.json`(tree digest + aliases digest),配置在 `scripts/stdlib-bundle.json`。版本变化必须显式(`--baseline-manifest` 拒绝同版本不同摘要)。组件仓继续拥有源码与测试,根不复制模块。
|
||||
- 组合验收入口是根仓库的 `scripts/acceptance-stdlib.py`:只接受显式 `--cli` 与 `--bundle`(或按根 gitlink 构建),运行各 active 组件的 `entry`、跨仓组合 fixture(别名、Table 切分、默认 Bundle smoke)和必须失败的负例;提供 `--pack-tool` 时用 CLI 自己的打包器做两次确定性打包并核对摘要。CLI 自身打包请使用 Phase A 之后的 `--stdlib-dir` 输入,不再默认读取 CLI 源码树。
|
||||
- 统一制品输入已落地(ECO-02 核心):`scripts/integration.sh` 不再从 View 的冻结脚本取 CLI 制品,而是由同一根候选派生全部输入——根唯一生产者 `scripts/build-stdlib.py` 按固定 gitlink 生成 Bundle;`cli/` 固定提交构建 CLI 与 Worker;`cli/tools/release/package.py --stdlib-dir <Bundle>` 生成发行归档;随后 Conformance、View、Knowledge、Prove、Lint 与根 `acceptance-stdlib.py` 全部使用同一安装后二进制与相邻 Bundle。任何消费者都不能决定 CLI 版本,也不再有浮动或隐式制品。
|
||||
- 组件验收只读取传入制品,不自行下载未知版本;开发目录覆盖入口(如 `MARQDO_STDLIB_DIR`)不得当作发行行为。缺失、摘要不符或平台不符必须拒绝。
|
||||
|
||||
## 影响范围与调度
|
||||
|
||||
根 `scripts/impact.py` 比较已接受根提交与候选递归展开的 `(global_id, parent, remote, SHA, state)`:领域指针变化展开到子组件身份,不能只标记父节点;变更叶子加入集合后,取 `requires` 新旧图并集的反向传递依赖闭包,再加所在祖先领域及 `checks_with` 固定点(协同验收不是构建先决)。领域无法展开(缺对象/检出)时结果标 UNVERIFIED 并**全量**扩大范围,不静默跳过;`--fail-on-unverified` 可把该情形变成硬失败。`integration.sh` 将报告写入候选证据(changed/affected/checks_with/fallback),正式发行仍执行所有 active 组件与完整测试。
|
||||
|
||||
## 工单路由与状态
|
||||
|
||||
| 现象 | 责任归属 |
|
||||
| --- | --- |
|
||||
| 组件表头正确但 Design 未识别 | web-design(若 Analysis 的真实 AST 正确) |
|
||||
| Link 中 `not_loaded` 错误处理 | web-design;若 CLI candidate 违反公开 resolver 合同则 CLI |
|
||||
| 手机布局溢出、场景实例串扰 | web-preview |
|
||||
| 特定设计模板不符合合同 | web-components(激活后)或作者项目,不修改核心 renderer 迎合坏模板 |
|
||||
| Web 设计约定出现冲突 | marqdo-ext-web 协调,Design/Preview 各自提交 |
|
||||
| 真实生产框架渲染/业务错误 | 目标应用仓库,不归 Web 原型 |
|
||||
| SSE 或网络传输错误 | Ext-Net 的 HTTP/WS 或 CLI Resource 真正责任方 |
|
||||
| 固定 SHA 组合构建失败 | 若各组件公开制品正确,由所属聚合/根修复装配,否则责任组件 |
|
||||
|
||||
状态流:`open → triaged → in-progress / blocked → component-verified → integrated`。可用现有 Git 平台标签与关联链接,不设计新工单数据库;阻塞项不能以 mock PASS 关闭。组件 PR 合并后可关闭组件修复工单,但消费者/领域或生态集成任务保留到真实候选组合通过。
|
||||
|
||||
## 自动化权限
|
||||
|
||||
先实现人工触发与 PR/CI 门禁,不开发自动 Agent 管理平台。候选通知的授权校验由根 `scripts/candidate-notify.py` 承担:只接受规范化通知(仓库、类型、head/base SHA、CI 状态与 URL),校验仓库在根图远端允许列表内、提交在本地对象库可达、组件候选的 base 必须是 accepted 根图当前固定的 SHA、CI 为允许主机上的 success 且必须是 https;按 `(repository, head SHA)` 去重,拒绝重放,accepted 基线变化时标记 `revalidate` 并要求重跑门禁;影响范围复用 `scripts/impact.py`,无法确定时全量。校验器只输出计划(`auto_promote=false`、`auto_merge=false`、仅创建候选分支需人工评审),不合并、不推送、不扩权。Webhook 只作通知(记录仓库、完整 SHA、CI URL);上级通过 API 验证存在性、审批与权限后再创建候选 PR,不得自动合入或提升权限。外部不可信 PR、未批准 gitlink 或脚本不得在拥有跨仓库写权限/发版密钥的 runner 中运行;区分只读 checkout/test token、受限 issue/PR token、受保护发布权限。日志不得输出凭证、完整 Analysis 或生产 API key。
|
||||
|
||||
## 发行与回滚
|
||||
|
||||
- 组件可独立 SemVer 发布;领域可发布经过验证的组合制品;根生态 release 固定整个 gitlink 树。独立版本不代表维护多套现行协议。
|
||||
- 每份证据记录根及递归组件 SHA、制品摘要、真实命令、退出码、环境/工具链、日志、测试范围与未验证项。复用现有 manifest/evidence 模式,不复制成新的权威锁。
|
||||
- Git tree 是源码身份权威;Cargo.lock/`marqdo.lock`/现行 Bundle manifest 是对应依赖权威。记录不可变归档校验和、可信来源及获取方法;摘要校验不是发布者身份认证。
|
||||
- 基础发行包含同源 CLI、必需 Worker 与单一标准库 Bundle;不使用浮动 branch/标签名作为发布依据。发布失败保留日志,使用新候选;已有标签和资产保持不可变。回滚用新集成提交恢复上一组通过的 gitlink。
|
||||
|
||||
## Web 领域开发约束
|
||||
|
||||
- 唯一作者合同是 `marqdo-ext-web` 的 `docs/WEB-DESIGN.md`;Design 是唯一解释实现,Preview 不另加解析规则。合同变更在该领域走 ADR,并让 Design/Preview 以配对候选一次切换。
|
||||
- Design 只消费公开 CLI `check --emit` 的 Analysis 3,不复制 Markdown/语言解析器、不依赖 CLI 私有 Rust crate;Preview 只消费 Design 的公开 crate/固定 revision,`,...` 不通过 `../design` 长期路径依赖,最终发布以 `Cargo.lock` 固定真实依赖身份。
|
||||
- 首版不迁移 WASM、不新增 CLI 语义、不要求旧 plugin 回调;模拟状态、原型标识与“未实现真实功能”必须对作者可见。
|
||||
- 真实验收使用真实浏览器 `file://` 制品、真实 CLI 正负例与真实冷安装;原型测试 PASS 不能当作生产测试 PASS。
|
||||
|
||||
## 本地环境
|
||||
|
||||
需要 Linux x86_64/glibc ≥ 2.39、Python 3.11+、Git、Rust、C 编译器和 curl;`integration.sh` 另需 jsonschema 与冻结 CLI 归档。详细命令与组件验收入口见各仓库 `README.md` 与 [各仓库任务](REPOSITORY-TASKS.md)。
|
||||
|
||||
## 迁移台账
|
||||
|
||||
标准库与扩展的现状、历史归属和切换顺序以 [迁移台账](MIGRATION.md) 为准。当前 CLI 内置标准库仍是基础发行的现行权威;`marqdo-stdlib` 聚合与九个功能仓库的迁移完成前,不得声称 Stdlib 拆分完成,也不得先删旧实现造成产品回归。
|
||||
@@ -0,0 +1,207 @@
|
||||
# 迁移台账
|
||||
|
||||
## 权威盘点
|
||||
|
||||
历史主分支最后提交为 `1c55baabd570e18b9da8f9057cef2f848e176690`,v2.9.1 的发布提交为 `ffe06d7afab7acaed87be5ff16edddc37da536a2`。自建 Git 已核验旧标签和主分支。旧实现、文档、示例、测试与工作流以历史提交为迁移资料。[历史主分支末尾](https://git.cflmy.cn/cflmy/marqdo/src/commit/1c55baabd570e18b9da8f9057cef2f848e176690)
|
||||
|
||||
| 已有仓库 | 审计时默认分支 | 发行或证据 |
|
||||
| --- | --- | --- |
|
||||
| [marqdo-cli](https://git.cflmy.cn/cflmy/marqdo-cli) | `master` | v3.0.0-rc.4 |
|
||||
| [marqdo-extension-conformance](https://git.cflmy.cn/cflmy/marqdo-extension-conformance) | `main` | 有独立固定 fixture |
|
||||
| [marqdo-knowledge](https://git.cflmy.cn/cflmy/marqdo-knowledge) | `master` | v0.1.0-beta.3 |
|
||||
| [marqdo-lint](https://git.cflmy.cn/cflmy/marqdo-lint) | `main` | v0.2.0 |
|
||||
| [marqdo-prove](https://git.cflmy.cn/cflmy/marqdo-prove) | `master` | v0.1.0-beta.1 |
|
||||
| [marqdo-view](https://git.cflmy.cn/cflmy/marqdo-view) | `master` | v0.3.0 |
|
||||
| [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) | `main` | Web 领域聚合,planned;唯一设计合同在 `docs/WEB-DESIGN.md` |
|
||||
| [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) | `main` | Web Design 组件,planned;初始开发文档 |
|
||||
| [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview) | `main` | Web Preview 组件,planned;初始开发文档 |
|
||||
|
||||
CLI gitlink 采用 RC.4 正式发布源码,以匹配冻结归档和现有 View/Lint 契约。
|
||||
其文档后续提交曾用于 Knowledge 的独立 CI;生态候选以自身测试判定实际组合。
|
||||
Conformance 使用 CLI 已固定的真实 fixture 提交。
|
||||
|
||||
## 标准库和扩展目录
|
||||
|
||||
主仓库的 [标准库目录](../stdlib/README.md) 和 [扩展目录](../extensions/README.md) 通过 Git 子模块固定独立仓库的开发提交。Web Design 和 Preview 从 Web 领域聚合仓递归获取。是否参加发行验收以 [组件目录](../components.toml) 与该组件所在层的 catalog 为准。
|
||||
|
||||
**标准库(planned,聚合仓库 marqdo-stdlib 尚未创建)** · [core](https://git.cflmy.cn/cflmy/marqdo-std-core) · [collections](https://git.cflmy.cn/cflmy/marqdo-std-collections) · [text](https://git.cflmy.cn/cflmy/marqdo-std-text) · [encoding](https://git.cflmy.cn/cflmy/marqdo-std-encoding) · [data](https://git.cflmy.cn/cflmy/marqdo-std-data) · [io](https://git.cflmy.cn/cflmy/marqdo-std-io) · [fs](https://git.cflmy.cn/cflmy/marqdo-std-fs) · [system](https://git.cflmy.cn/cflmy/marqdo-std-system) · [net](https://git.cflmy.cn/cflmy/marqdo-std-net)
|
||||
|
||||
**扩展(planned,独立组件)** · [math](https://git.cflmy.cn/cflmy/marqdo-ext-math) · [linalg](https://git.cflmy.cn/cflmy/marqdo-ext-linalg) · [quantum](https://git.cflmy.cn/cflmy/marqdo-ext-quantum) · [http](https://git.cflmy.cn/cflmy/marqdo-ext-http) · [websocket](https://git.cflmy.cn/cflmy/marqdo-ext-websocket) · [ai](https://git.cflmy.cn/cflmy/marqdo-ext-ai) · [mcp](https://git.cflmy.cn/cflmy/marqdo-ext-mcp) · [crypto](https://git.cflmy.cn/cflmy/marqdo-ext-crypto) · [database](https://git.cflmy.cn/cflmy/marqdo-ext-database) · [storage](https://git.cflmy.cn/cflmy/marqdo-ext-storage) · [cache](https://git.cflmy.cn/cflmy/marqdo-ext-cache) · [security](https://git.cflmy.cn/cflmy/marqdo-ext-security) · [browser](https://git.cflmy.cn/cflmy/marqdo-ext-browser) · [document](https://git.cflmy.cn/cflmy/marqdo-ext-document) · [archive](https://git.cflmy.cn/cflmy/marqdo-ext-archive) · [engineering](https://git.cflmy.cn/cflmy/marqdo-ext-engineering) · [regex](https://git.cflmy.cn/cflmy/marqdo-ext-regex) · [datetime](https://git.cflmy.cn/cflmy/marqdo-ext-datetime)
|
||||
|
||||
**Web 领域(planned domain)** · 聚合 [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web)(唯一合同 `docs/WEB-DESIGN.md`)· 子组件 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design) · [marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview)
|
||||
|
||||
## 分层治理与领域聚合(2026-11-26 起)
|
||||
|
||||
根 catalog 支持唯一的新增类型 `kind = "domain"`(聚合治理角色),治理树最多两级:**根 → 领域聚合 → 功能组件**。规则要点:
|
||||
|
||||
- 每个拥有子模块的聚合仓库只登记直接子组件;全局 ID 与权威远端唯一;功能仓库仍只有一个父级。Gitlink 是提交身份唯一权威,`.gitmodules` 是权威远端唯一记录。
|
||||
- 聚合仓库可拥有 `components.toml`、`.gitmodules`、领域公共规范、跨组件集成测试、综合示例、发布装配脚本、ADR 与维护指南;**禁止**生产实现与源码复制。
|
||||
- 已有 `planned` 仓的 gitlink 固定真实开发提交。尚无提交的组件只登记计划,激活以后再填写真实 `entry` 并计入完成率。领域及其后代分别登记在各自父仓库。
|
||||
- 领域激活门禁:子组件具备真实入口与候选提交、领域 catalog 与 gitlink 一致、领域 CI 通过、根 `check-layout.py --checkouts` 递归校验通过、存在依赖关系的组件以同候选证据验证。
|
||||
- 主仓库 `scripts/check-layout.py` 已引入 domain 角色与递归校验;统一 CLI 制品准备、声明驱动调度、递归影响分析仍在推进,CI 证据以真实候选为准。
|
||||
|
||||
当前状态:**没有任何 active 领域**。Web 领域为 planned(`extensions/web`,聚合仓 marqdo-ext-web,子组件 design/preview 在其 catalog 登记);标准库聚合 marqdo-stdlib 尚未创建,九个 `std-*` 保持根 catalog 的 planned 直属记录;HTTP/WebSocket 等仍为独立 planned 扩展,等至少两个真实组件形成共同边界后再评估聚合。首批 Web 实施工单为 WEB-00(合同与真实 Analysis 风险探测)、WEB-01(Design)、WEB-02(Preview)、WEB-03(handoff/组件图)、WEB-04(组合案例与框架交付)、WEB-05(根接入与冷安装),WEB-06(components)为候选;工单在对应责任仓库创建。Web 合同语义冲突由 marqdo-ext-web 协调,不回流 CLI 核心。
|
||||
|
||||
## 阶段与阻塞
|
||||
|
||||
| 原分支 | 独立仓库与迁移状态 |
|
||||
| --- | --- |
|
||||
| `gh-pages` | 官网架构、v2.9.1 源内容和部署快照均已迁入 marqdo-site。原分支保留现有公共入口,部署切换以独立托管和路由验收为准。[托管切换工单](https://git.cflmy.cn/cflmy/marqdo-site/issues/1) |
|
||||
| `vscode-extension` | 扩展目录历史归档到 marqdo-vscode 的 `legacy-v2.8.0`。现行 CLI 适配和新版 VSIX 由扩展仓独立开发和验收。[首版实现工单](https://git.cflmy.cn/cflmy/marqdo-vscode/issues/1) |
|
||||
|
||||
| 阶段 | 当前范围 | 后续验收 |
|
||||
| --- | --- | --- |
|
||||
| M0 盘点 | 自建 Git、历史标签、已有六组件和新仓位 | 通过真实远端候选持续维护台账 |
|
||||
| M1 集成骨架 | 六个 active gitlink,另固定 28 个直属和 2 个 Web 子级的 planned 开发提交 | 查看候选 Woodpecker 运行及各组件独立 CI |
|
||||
| M2 标准库切换 | planned,CLI RC.4 提供官方完整 Bundle | [CLI 外部 Bundle](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11) 和 [九组件切换](https://git.cflmy.cn/cflmy/marqdo/issues/2),包括 HTTP、Regex、Archive 迁出与同步删除旧路径 |
|
||||
| M3 跨仓闭环 | 工单、人工候选、同 SHA 门禁 | [跨仓库 CI](https://git.cflmy.cn/cflmy/marqdo/issues/3) 跟踪真实缺陷闭环、候选通知鉴权、去重和影响分析 |
|
||||
| M4 领域接入 | Web 领域 planned:三仓文档与工单就绪;根 catalog 登记 planned domain | W-M0 真实 CLI 风险探测、WEB-01/02 实现、领域 gitlink、根递归校验与冷安装验收;Stdlib 聚合按 STD-01..04 独立推进 |
|
||||
| 后续领域 | 空仓和预期职责 | 逐组件开展最小真实功能、独立 CI、制品与接入 |
|
||||
|
||||
### 标准库切换顺序
|
||||
|
||||
1. CLI 打包器与产品测试接受单一显式外部 Bundle 输入。内核独立编译;制品仍附带一个校验过的标准库。
|
||||
2. 标准库在各组件维护唯一生产源码和自测。组装拒绝冲突、符号链接或测试污染,调用 CLI 权威打包器。std-io 维护 print/打印 的别名元数据。
|
||||
3. HTTP、Regex、Archive 的真实替代和授权回归先行。候选同时移除 CLI 中旧领域宿主服务和旧导入。
|
||||
4. 验证同输入两次组装结果、摘要及路径负例、C1/C2/C3、独立冷安装和真实工具集成后,再切换基础发行。当前状态为 UNVERIFIED。
|
||||
|
||||
## 标准库源码归位迁移(marqdo#9,2026-11-26 M0 冻结)
|
||||
|
||||
本节是标准库迁出的**唯一现行台账**,取代此前按未来目录规划起草的路径表(如 `system/clock.mq.md`、`io/index.mq.md`);旧路径方案会改变公开 `std:` 路径,与“迁移不改语言/库语义”冲突,已作废。详细实施与验收见父仓工单 [marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9),各接收仓子工单在对应仓库 issue #1。
|
||||
|
||||
### 基线与身份(M0)
|
||||
|
||||
| 对象 | 权威身份 |
|
||||
| --- | --- |
|
||||
| 根仓库 | `cflmy/marqdo@484cb10d66db9b92f0527499642ae6abddb3ef29` |
|
||||
| CLI 标准库源 | `cflmy/marqdo-cli@452e9a32bd9e40dba427d4180691c58bab74449e`(RC.4 发行组合;`stdlib/` 自 `4bbefc9` 起未变) |
|
||||
| 迁移前 Bundle | `marqdo-stdlib@0.1.0`,tree digest `sha256:5407d3665ba2fe105820d0f1af5efaafa10c277a69eb819c3225719813c8c713`(含 `tests/`) |
|
||||
| 公开函数台账 | 20 个模块、151 个 H2 函数,由基线 Bundle 上 `marqdo inspect --signature` 生成并记入各接收仓工单 |
|
||||
| CLI 显式 Bundle 输入 | [marqdo-cli#11](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11) Phase A(PR #12)已提供 `--stdlib-dir`/pin 校验;Phase B(删除仓内源树)以本台账根组合验收为前置 |
|
||||
|
||||
### 模块归属与冻结发布路径
|
||||
|
||||
接收仓库负责源码、测试和后续缺陷;根只做组合、锁定和验收。`modules/` 镜像 Bundle 根相对路径,只收模块不收 `tests/`;官方 manifest 由根唯一生产者生成。
|
||||
|
||||
| 原 CLI 路径(相对 `stdlib/`) | 接收仓 / 工单 | 冻结发布路径(Bundle 根相对) | 公开函数 |
|
||||
| --- | --- | --- | --- |
|
||||
| `clock.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `clock.mq.md` | 1 |
|
||||
| `datetime.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `datetime.mq.md` | 14 |
|
||||
| `env.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `env.mq.md` | 2 |
|
||||
| `process.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `process.mq.md` | 1 |
|
||||
| `random.mq.md` | [std-system#1](https://git.cflmy.cn/cflmy/marqdo-std-system/issues/1) | `random.mq.md` | 2 |
|
||||
| `format.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `format.mq.md` | 8 |
|
||||
| `io.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `io.mq.md` | 5 |
|
||||
| `io/console.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `io/console.mq.md` | 4 |
|
||||
| `io/stream.mq.md` | [std-io#1](https://git.cflmy.cn/cflmy/marqdo-std-io/issues/1) | `io/stream.mq.md` | 3 |
|
||||
| `data/json.mq.md` | [std-data#1](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/1) | `data/json.mq.md` | 22 |
|
||||
| `data/csv.mq.md` | [std-data#1](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/1) | `data/csv.mq.md` | 7 |
|
||||
| `data/table.mq.md` | [std-collections#1](https://git.cflmy.cn/cflmy/marqdo-std-collections/issues/1) / [std-data#1](https://git.cflmy.cn/cflmy/marqdo-std-data/issues/1) | `collections/table.mq.md`(8 个值操作)/ `data/table.mq.md`(4 个序列化) | 12 |
|
||||
| `fs/file.mq.md` | [std-fs#1](https://git.cflmy.cn/cflmy/marqdo-std-fs/issues/1) | `fs/file.mq.md` | 14 |
|
||||
| `path.mq.md` | [std-fs#1](https://git.cflmy.cn/cflmy/marqdo-std-fs/issues/1) | `path.mq.md` | 8 |
|
||||
| `text.mq.md` | [std-text#1](https://git.cflmy.cn/cflmy/marqdo-std-text/issues/1) | `text.mq.md`(`utf8编码` 薄封装) | 1 |
|
||||
| `text/utf8.mq.md` | [std-text#1](https://git.cflmy.cn/cflmy/marqdo-std-text/issues/1) | `text/utf8.mq.md`(唯一编解码实现) | 10 |
|
||||
| `net/http.mq.md` | [ext-http#1](https://git.cflmy.cn/cflmy/marqdo-ext-http/issues/1) | 显式 Package 入口 `index.mq.md`,**不进入默认 Bundle**,不再是 `std:` | 11 |
|
||||
| `regex.mq.md` | [ext-regex#1](https://git.cflmy.cn/cflmy/marqdo-ext-regex/issues/1) | 显式 Package 入口 `index.mq.md`,**不进入默认 Bundle**,不再是 `std:` | 22 |
|
||||
| `compress.mq.md` | [ext-archive#1](https://git.cflmy.cn/cflmy/marqdo-ext-archive/issues/1) | 显式 Package 入口 `index.mq.md`,**不进入默认 Bundle**,不再是 `std:` | 2 |
|
||||
| `demo.mq.md` | 不设接收仓;根 Bundle 组合 fixture | 不作为公开安装模块 | 2 |
|
||||
|
||||
`std-core`、`std-encoding`、`std-net` 没有与之对应的旧模块:本轮不发空工单、不激活、不要求补齐未来规划;若已实现模块被本期 Bundle 实际依赖,再按真实依赖补充工单。
|
||||
|
||||
### 原测试断言归属
|
||||
|
||||
每项必须在新归属留下真实执行证据;跨模块断言归根 Bundle 组合测试。
|
||||
|
||||
| 原 `stdlib/tests/` 文件 | 接收仓 | 断言载体 |
|
||||
| --- | --- | --- |
|
||||
| `clock.mq.md`、`datetime.mq.md`、`env.mq.md`、`process.mq.md`、`random.mq.md` | std-system | 组件 case,覆盖原 Rust 断言 |
|
||||
| `console.mq.md`、`format.mq.md`、`io.mq.md`、`stream.mq.md` | std-io | 组件 case + resource 端点事件检查 |
|
||||
| `csv.mq.md`、`json.mq.md` | std-data | 组件 case,覆盖原 Rust 断言 |
|
||||
| `table.mq.md` | std-collections(值操作)+ std-data(GFM)+ 根组合 | 切分后的组件 case 与根组合用例 |
|
||||
| `fs.mq.md`、`path.mq.md` | std-fs | 组件 case,覆盖原 Rust 断言 |
|
||||
| `text.mq.md`、`utf8.mq.md` | std-text | 组件 case,覆盖原 Rust 断言 |
|
||||
| `http.mq.md` | ext-http | 领域回归(基线仅运行级覆盖,需补真实断言) |
|
||||
| `regex.mq.md` | ext-regex | 领域回归,覆盖原 Rust 断言 |
|
||||
| `compress.mq.md` | ext-archive | 领域回归,覆盖原 Rust 断言 |
|
||||
| `demo.mq.md` | 根 Bundle 组合测试 | 组合运行证据 |
|
||||
|
||||
### 决策与取舍
|
||||
|
||||
1. **冻结路径**:以 Bundle 根相对路径为公开身份,迁移不改 `std:` 导入路径;被旧台账规划改名(如 `system/clock.mq.md`、`io/index.mq.md`)的条目按本表冻结。
|
||||
2. **测试不随发行**:`tests/` 迁入组件仓并留在仓库外,默认 Bundle 只含模块;因此 Bundle 内容必然变化,版本与 digest 由 MIG-BUNDLE 唯一生产者显式更新,摘要算法不变。
|
||||
3. **Table 切分**:值操作以 `std:collections/table` 为唯一权威,GFM 序列化以 `std:data/table` 为唯一权威;不保留旧 `std:data/table` 的值操作兼容转发,已知消费者在同一候选内更新。
|
||||
4. **Text 去重**:UTF-8 编解码唯一实现在 `text/utf8.mq.md`,`text.mq.md#utf8编码` 为保留公开名称的薄封装。
|
||||
5. **IO 别名**:`io.mq.md` 保持官方 `print`/`打印` 的别名目标 `写值`,签名与 effects 不变;别名元数据仍由 Bundle 生产者生成。
|
||||
6. **三个领域模块**:HTTP/Regex/Archive 迁入既有扩展仓,按现行 Package 布局以 `index.mq.md` 为唯一公开入口(消费者经 `@alias` 显式依赖),退出默认 Bundle,不保留隐藏的 `std:` fallback;HTTP 的 bundle 内相对 import 改为公开 `std:text/utf8`。CLI 现有 `regex.*`/`compress.*` 宿主请求是历史例外,本轮不删除也不新增同类请求,彻底消除另开工单。
|
||||
7. **`demo.mq.md`**:不作为公开库模块,转为根 Bundle 组合 fixture,避免为了放置文件创建无独立责任的新仓库。
|
||||
8. **staging 不是发行**:迁移期为了隔离测试,允许用基线 Bundle 覆盖组件模块并重算 digest 的 staging 组合;它不是官方发布源,最终只有根唯一生产路径。
|
||||
9. **CLI 侧最小修改**:Phase A 显式制品输入已落地;Phase B 删除仓内官方源树只在组件替代与根组合验收通过后执行,不同时进行核心重构。
|
||||
10. **未创建的新仓**:不为缺失模块创建同名替代仓;`marqdo-stdlib` 聚合仓仍未建立,聚合治理按原独立计划推进,不阻塞本次源码归位。
|
||||
|
||||
### 迁移状态
|
||||
|
||||
| 项 | 状态 | 证据 |
|
||||
| --- | --- | --- |
|
||||
| M0 盘点与派单 | 完成 | 本节、9 个接收仓 issue #1、[marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9) 评论 |
|
||||
| 组件接收(源码+断言) | 候选已推送(6 个 std 仓,同候选配对) | [std-text PR #2](https://git.cflmy.cn/cflmy/marqdo-std-text/pulls/2)、[std-system PR #2](https://git.cflmy.cn/cflmy/marqdo-std-system/pulls/2)、[std-io PR #2](https://git.cflmy.cn/cflmy/marqdo-std-io/pulls/2)、[std-fs PR #2](https://git.cflmy.cn/cflmy/marqdo-std-fs/pulls/2)、[std-data PR #2](https://git.cflmy.cn/cflmy/marqdo-std-data/pulls/2)、[std-collections PR #2](https://git.cflmy.cn/cflmy/marqdo-std-collections/pulls/2) |
|
||||
| 领域模块(http/regex/archive) | 候选已合并为显式 Package | [ext-http PR #2](https://git.cflmy.cn/cflmy/marqdo-ext-http/pulls/2)、[ext-regex PR #2](https://git.cflmy.cn/cflmy/marqdo-ext-regex/pulls/2)、[ext-archive PR #2](https://git.cflmy.cn/cflmy/marqdo-ext-archive/pulls/2) |
|
||||
| Bundle 唯一生产者 | 已实现,M2 候选真实构建两次逐字节一致 | `scripts/build-stdlib.py`、`scripts/stdlib-bundle.json`、`tests/integration/test_build_stdlib.py` |
|
||||
| 组合验收入口 | M2 候选 PASS(组件 entry + 跨仓组合 + 负例 + 相邻离线安装 + CLI 确定性打包) | `scripts/acceptance-stdlib.py`、[M2 候选证据](evidence/2026-11-26-stdlib-m2-candidate.md)、[根 PR #11](https://git.cflmy.cn/cflmy/marqdo/pulls/11) |
|
||||
| CLI 旧源树删除 | 候选完成:CLI 仓已无 `stdlib/` 源树、无编译期 fallback,pin 指向生态 Bundle | [marqdo-cli#11](https://git.cflmy.cn/cflmy/marqdo-cli/issues/11)、[CLI PR #17](https://git.cflmy.cn/cflmy/marqdo-cli/pulls/17)、[Phase B 证据](https://git.cflmy.cn/cflmy/marqdo-cli/src/branch/migration/cli-stdlib-phase-b/docs/evidence/2026-11-27-issue-11-phase-b.md) |
|
||||
| 统一 CLI/Worker/Bundle 制品输入(ECO-02 核心) | 已落地:integration.sh 由同一根候选派生全部输入,不再使用 View 冻结制品 | 根 `scripts/integration.sh`、[marqdo#7](https://git.cflmy.cn/cflmy/marqdo/issues/7) |
|
||||
| 根组合与切换 | **已晋升**:`main` = `f4e292e`,固定 CLI Phase B `deadf6e` 与六个 std/三个 ext 组件;根生态 CI(pipeline 38)PASS | [M3 证据](evidence/2026-11-27-stdlib-m3-candidate.md)、[根 PR #12](https://git.cflmy.cn/cflmy/marqdo/pulls/12) |
|
||||
| M4 发行级验收 | 离线冷安装 PASS(`ubuntu:24.04 --network none`,归档 `sha256:377d2787...`);多平台不在本线支持矩阵 | [M3 证据的晋升章节](evidence/2026-11-27-stdlib-m3-candidate.md#晋升与-m4-验收) |
|
||||
|
||||
## v2 功能历史索引
|
||||
|
||||
按表中的归属逐项拆分工单,记录来源路径、目标接口、正负例、状态和真实测试提交。
|
||||
|
||||
| 旧版 lib 模块 | 目标 | 迁移决策 / 主要缺口 |
|
||||
|---|---|---|
|
||||
| archive | archive | ZIP/TAR 等安全归档;现有 gzip 迁移,测试路径穿越 |
|
||||
| browser | browser | 31 个 H2 所涉 DOM、存储、事件、fetch、WS、下载;不复制旧 WASM runtime |
|
||||
| bytes | std-text / std-encoding | 字节值、slice、UTF-8 归 Text,base64 归 Encoding,单一 byte 表示 |
|
||||
| cli | std-system | 应用参数 parse,非 CLI 自身 flag parser |
|
||||
| csv | std-data | 已有 parse/format;补非法输入与多行测试 |
|
||||
| datetime | std-system / datetime | UTC 基础已有;时区、DST 和高级日历明确拆分 |
|
||||
| document | document | sections、tables、links、code blocks、replace;通过受支持静态事实与显式文件编辑 |
|
||||
| encoding | std-encoding | Base64/Base32/Hex 编解码缺失 |
|
||||
| foreign | CLI 现有 Foreign / 独立可选会话扩展(待 ADR) | one-shot run/call 已有;不恢复 set_cmd/register 等隐式动态机制;session/replay 需真实设计 |
|
||||
| fs | std-fs / document / engineering | 40 个 H2 涵盖文件操作;新版14个 H2;二进制、递归、原子、临时、读写组合;文本 patch/工程 sync 归相应扩展 |
|
||||
| hash | crypto | SHA/HMAC 等,密码学不进入内核 |
|
||||
| html | web(合同见 WEB-DESIGN) | HTML escape/unescape 属渲染安全细节,按 WEB-DESIGN 与 Preview 安全合同处理;不恢复旧页面/模板插件模型 |
|
||||
| json | std-data | parse/stringify 已有;get/keys/set 等可复用 collections;严格 Result |
|
||||
| log | std-system | 结构化、level、输出门面,不引入服务框架 |
|
||||
| math | std-core / math | abs/min/max/clamp 基础归 Core;数值、超越、公式、CAS、绘图归 Math;随机归 System |
|
||||
| net | std-net / http / ai / document | TCP/TLS 基础归 Net;HTTP/SSE/cookie/multipart/download 归 HTTP;OpenAI 特定 SSE 归 AI;Markdown 解析归 Document 或公开静态事实 |
|
||||
| path | std-fs | join/normalize 等已有;relative/with_extension 等补齐 |
|
||||
| plugin | CLI 现行扩展选择机制 | 不迁移 load/unload 自动加载;使用显式 descriptors、lock、grant |
|
||||
| re | regex | 查找/替换/分割/捕获和现有纯子集、成熟后端,取消宿主 convenience 重复 |
|
||||
| result | std-core | ok/error/value_or,统一现行可恢复错误约定 |
|
||||
| secrets | std-system / crypto | token 生成归 System,密钥/密码学安全操作归 Crypto;不泄漏 secret |
|
||||
| stats | math | mean/median/stdev;定义样本与总体、空集合、精度 |
|
||||
| subtask | CLI Structured Tasks(待开发) / std-system | spawn/join/cancel 等先验证通用语义;库只薄封装,不移植旧 scheduler |
|
||||
| sys | std-system / CLI 公共事实 | env/args/process/clock;旧 stream_publish 和 meta 由现行 Observation/Analysis 或真正应用输出处理;不恢复隐式环境写入 |
|
||||
| table | std-collections / std-data | 60 个 H2 入口(List/Map/Table 混合);值操作归 Collections,GFM/数据格式归 Data |
|
||||
| text | std-text | trim/split/join、contains/replace、大小写、repeat/pad 等缺口 |
|
||||
| time | std-system | now/UTC parse 已部分有;sleep 仅在受控原语可用后实现 |
|
||||
| toml | std-data | parse/stringify/try_parse,实际支持标准及错误边界 |
|
||||
| url | http | URL parse/query/percent 与同协议归属,std-net 不重复 |
|
||||
| uuid | std-system | v4 使用 OS entropy;检查版本/variant |
|
||||
| writeback | document / engineering | 显式有界编辑、来源摘要及冲突检查;不恢复隐式自修改/自动 oracle writeback |
|
||||
| lint/narrative | lint Tool | 静态诊断与显式修复,不进 CLI runtime |
|
||||
|
||||
### 领域与插件
|
||||
|
||||
| 旧目录 | 目标及处理 |
|
||||
|---|---|
|
||||
| `ext/ai` + `plugins/llm` / `plugins/agent` | AI 模型协议、MCP 独立迁移;agent 97 个 H2 涉及 workflow/memory/工具/恢复等,按真实通用能力拆分,不整体复制。qdagent 应用管理其自己的最小工作流、记忆、意图和 SKILL,不作为通用标准库。知识检索、证明分别由对应 Tool;sandbox 用 CLI 的实际保证,不伪造 OS 隔离。 |
|
||||
| `ext/linalg` + `plugins/linalg` | Linalg;迁移数值算法、复数及矩阵符号知识;重新适配 ABI,减少重复。 |
|
||||
| `ext/quantum` + `plugins/quantum` | Quantum;gate/state/circuit/simulate/density/viz,移除与 Linalg 重复的实现或建立经测试的后端共享边界。 |
|
||||
| `ext/net` | HTTP、WebSocket、URL,低层 TCP/TLS 归 Std Net。 |
|
||||
| `ext/data` | Database/Cache/Storage;form/admin/api/view 的 Web 部分归 Web,数据验证及查询归唯一相应库。旧 Web Go plugin 的 DB、storage、cache 子模块分别迁移。 |
|
||||
| `ext/security` | Security + Crypto;旧 Go plugin auth/OIDC/RBAC/tenant/password 按归属拆分,不混入 Host capability。 |
|
||||
| `ext/web` + `plugins/web` | 拆为 Web 设计原型领域(唯一合同见 marqdo-ext-web `docs/WEB-DESIGN.md`:设计文档解释、递归组件、有限场景、离线预览与 handoff)与 HTTP/WebSocket/Browser/Database/Security 各自独立组件;删除 monolithic Go plugin 调度与旧页面模型,不恢复旧 Web Artifact 兼容层。 |
|
||||
| `ext/engineering` + `plugins/engineering` | Engineering;Git 操作、文件、archive 分配给已有权威库,避免重复平台操作。 |
|
||||
| `crates/marqdo-wasm`、旧 browser examples | Browser 组件参考;语言核心可移植性需要 CLI 工单,而非复制旧执行器。 |
|
||||
| 旧 `src/knowledge`/proof/view/lint/对应历史 CI 与 examples | 独立 Tool,只迁移所需知识、算法和 fixture;当前公共 Analysis/Observation 优先;新旧协议不并存。 |
|
||||
@@ -0,0 +1,76 @@
|
||||
# Marqdo 各仓库任务
|
||||
|
||||
按仓库领取任务。标为 **大改** 的条目可涉及模块拆分、实现重写或发布切换。责任仓库应先限定本轮交付范围,涉及公共接口时与实际消费者一起验收。
|
||||
|
||||
生态治理采用“根 → 领域聚合 → 功能组件”最多两级 Gitlink:功能仓库实现与修复、领域聚合仓库维护合同与组合验收、主仓库固定 gitlink、治理与发行。`planned` 组件可以挂载真实开发提交,实际入口随验收登记。当前没有 active 领域;Web 领域为 planned(聚合仓 `marqdo-ext-web`,子组件 `marqdo-web-design`/`marqdo-web-preview` 在其 catalog 登记)。先推进 CLI 外部 Bundle、九个标准库,以及 HTTP、Regex、Archive 的迁出;这些改动在同一候选组合中验证后切换基础发行。官网和 VS Code 可独立推进。[迁移台账](MIGRATION.md) · [开发流程](DEVELOPMENT.md)
|
||||
|
||||
## 集成和语言
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo` | 固定已验收的组件组合与领域 gitlink,完成跨仓库工单闭环、CI 和生态发行验证。推进递归治理校验(domain 角色与全局依赖 DAG)、声明驱动集成计划、统一 CLI 制品输入与递归影响分析;保留现有 conformance/View/Knowledge/Prove/Lint 真实门禁。 |
|
||||
| `marqdo-cli` | **大改**。拆分内核构建和基础发行装配,接受显式外部标准库 Bundle。完成领域能力迁出后,移除旧标准库入口和被替代的专用宿主实现。 |
|
||||
| `marqdo-extension-conformance` | 更新真实 CLI 的公共契约测试,覆盖 Bundle 切换、五类扩展机制及其权限边界。 |
|
||||
|
||||
## 领域聚合(planned)
|
||||
|
||||
领域聚合仓库只做治理、唯一合同、示例、跨组件验收与交付协调,不含生产实现。激活前保持 planned,子组件在其自身 `components.toml` 登记,根 catalog 不重复登记。
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-ext-web` | Web 领域聚合:维护唯一作者合同 `docs/WEB-DESIGN.md`、§8 组合示例与领域 CI;验证真实 Analysis 风险(WEB-00),协调设计合同变更与 Design/Preview 配对候选;在子组件通过 WEB-01..04 后以领域 gitlink 接入根(WEB-05)。 |
|
||||
| `marqdo-web-design` | WEB-01:消费真实 CLI Analysis 3,解释精确组件引用、递归布局、有限场景与依赖,输出稳定诊断、组件图和源身份;WEB-03:handoff、单组件切片与漂移标识。独立 Rust library,禁止复制 parser/启动服务。 |
|
||||
| `marqdo-web-preview` | WEB-02:通用离线预览渲染器与有限状态交互、响应式、安全负例、Tool 打包;作为唯一 `web` 命令入口消费 Design 公开 API,禁止任务专用 JS、第二套解析或生产服务器。 |
|
||||
|
||||
## 工具和产品
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-knowledge` | 基于公开 Analysis 完善可复现的知识编译、索引和检索,验证独立发行。 |
|
||||
| `marqdo-prove` | 完善证明依赖、Lean 证书生成和独立重放,清楚展示各项证明的核验状态。 |
|
||||
| `marqdo-view` | 维护文档阅读、显式运行、Observation 和静态导出,验证与现行 CLI 及官网构建的组合。 |
|
||||
| `marqdo-lint` | 扩展静态规则和诊断定位,为可修复规则提供显式修复。 |
|
||||
| `marqdo-site` | **大改**。用现行 CLI 和 View 重建官网与入门内容,验证新站和旧链接后切换托管。 |
|
||||
| `marqdo-vscode` | **大改**。按现行 CLI 重做诊断和运行适配,先完成高亮、静态诊断、显式运行和可安装的 VSIX。 |
|
||||
|
||||
## 标准库
|
||||
|
||||
每个仓库交付可独立测试的模块,共同组成默认 Bundle。标准库源码归位已完成并晋升:六个交付源码的 `std-*` 在根 catalog 为 active,`std-core/encoding/net` 保持 planned 且不入 Bundle;CLI 已无内置标准库源树,唯一 Bundle 由根 `scripts/build-stdlib.py` 从固定 gitlink 生成,组合验收为 `scripts/acceptance-stdlib.py`。迁移基线、模块/函数与断言台账、冻结发布路径见 [迁移台账](MIGRATION.md) 的“标准库源码归位迁移”一节。`marqdo-stdlib` 聚合仓库仍未建立;发行级冷安装已通过,后续缺陷回各责任仓。
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-std-core` | 实现共用 Result 和基础数值操作。 |
|
||||
| `marqdo-std-collections` | 实现 List、Map 和 Table 的通用集合操作,从数据格式处理中拆出表格算法。 |
|
||||
| `marqdo-std-text` | 统一 Unicode 文本、字节值切片和 UTF-8 编解码。 |
|
||||
| `marqdo-std-encoding` | 提供 Base64、Base32 和 Hex,并定义非法输入的行为。 |
|
||||
| `marqdo-std-data` | 迁入 JSON、CSV 和表格格式转换,补齐 TOML 与 GFM。 |
|
||||
| `marqdo-std-io` | 迁入 Console、Stream 和格式化,负责官方 `print` 与 `打印` 别名。 |
|
||||
| `marqdo-std-fs` | 迁入文件、路径和目录操作,核验读写边界。 |
|
||||
| `marqdo-std-system` | 迁入时钟、UTC、环境、进程和随机能力。 |
|
||||
| `marqdo-std-net` | 提供有界 TCP、UDP、TLS 和字节流,供上层协议复用。 |
|
||||
|
||||
## 扩展
|
||||
|
||||
每个仓库先完成一个可安装、可验证的用例。历史实现可用于迁移取证,公开接口按现行契约验收。
|
||||
|
||||
| 仓库 | 要完成的任务 |
|
||||
| --- | --- |
|
||||
| `marqdo-ext-math` | 建立数值算法、统计、符号数学和绘图能力,先交付可验证的数值用例。 |
|
||||
| `marqdo-ext-linalg` | 迁移复数、矩阵和分解,向量子组件提供可复用的线性代数接口。 |
|
||||
| `marqdo-ext-quantum` | 迁移量子电路、态向量、采样与模拟,验证代表性电路结果。 |
|
||||
| `marqdo-ext-http` | **大改**。把现有 HTTP 迁为基于 std-net 的独立包,覆盖 URL、消息编解码、请求生命周期和 SSE。 |
|
||||
| `marqdo-ext-websocket` | 交付基于 HTTP 与网络流的 WebSocket 握手、帧和连接生命周期。 |
|
||||
| `marqdo-ext-ai` | **大改**。从旧 AI 实现拆出模型协议、流式输出和工具调用数据。 |
|
||||
| `marqdo-ext-mcp` | 交付 MCP 传输、能力发现和受控工具调用。 |
|
||||
| `marqdo-ext-crypto` | 封装成熟密码学实现,先交付一种带标准测试向量的能力。 |
|
||||
| `marqdo-ext-database` | 交付一个支持参数绑定和事务的数据库驱动。 |
|
||||
| `marqdo-ext-storage` | 定义本地与对象存储接口,先验证一套读写和错误处理流程。 |
|
||||
| `marqdo-ext-cache` | 交付带 TTL 和失效行为的缓存。 |
|
||||
| `marqdo-ext-security` | 交付应用身份、会话与授权,复用加密扩展。 |
|
||||
| `marqdo-ext-web` | 已改为 Web 领域聚合仓库,任务见「领域聚合」小节;不再作为 HTTP 页面/路由渲染实现。 |
|
||||
| `marqdo-ext-browser` | **大改**。按现行运行时边界适配浏览器宿主、WASM、DOM 和事件。 |
|
||||
| `marqdo-ext-document` | 交付 Markdown 结构查询与显式编辑接口。 |
|
||||
| `marqdo-ext-archive` | 实现归档与安全解包,为 CLI 移除旧压缩入口提供可验证的替代。 |
|
||||
| `marqdo-ext-engineering` | 拆分工程操作、文件补丁和产物处理,先交付一个独立工程用例。 |
|
||||
| `marqdo-ext-regex` | 提供匹配、捕获、扫描与替换,为 CLI 移除旧正则入口提供可验证的替代。 |
|
||||
| `marqdo-ext-datetime` | 交付 IANA 时区、夏令时和高级日历能力,与标准库 UTC 接口对接。 |
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,7 @@
|
||||
# 架构决策记录
|
||||
|
||||
按时间顺序保存影响生态边界、公共合同或发行方式的决策。现行规则以 `docs/ARCHITECTURE.md`、`docs/DEVELOPMENT.md`、`components.toml` 与各责任仓库的合同文档为准;ADR 是决策历史,不是第二套现行规范。
|
||||
|
||||
| ADR | 状态 | 主题 |
|
||||
| --- | --- | --- |
|
||||
| [0001](0001-hierarchical-ecosystem-and-web-domain.md) | 已采纳(实施记录) | 分层生态治理(根→领域→功能)与 Web 原型设计领域合同 |
|
||||
@@ -0,0 +1,72 @@
|
||||
# 标准库源码归位 M2 候选证据(2026-11-26)
|
||||
|
||||
父仓工单:[cflmy/marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9)。本文件记录 **M2 候选组合**的真实执行结果,是候选证据,不是已发布声明。根主分支仍保持迁移前组合(`484cb10`);本候选只有在 CLI Phase A 与六个接收仓 PR 合并、且完整生态门禁通过后才可晋升。
|
||||
|
||||
## 候选身份
|
||||
|
||||
| 对象 | 身份 |
|
||||
| --- | --- |
|
||||
| 根候选分支 | `migration/stdlib-m2-candidate`(本文档提交前树 `8fa728b302fa29caf8268a758eb4b0e90431d780`) |
|
||||
| 根主分支基线 | `484cb10d66db9b92f0527499642ae6abddb3ef29`(未改动) |
|
||||
| CLI gitlink(未变) | `cflmy/marqdo-cli@452e9a32bd9e40dba427d4180691c58bab74449e`(RC.4 组合) |
|
||||
| CLI Phase A 候选(仅用于打包/验证,PR #12) | `cflmy/marqdo-cli@f8b82d414328d92b31865fed05e68223f7bee917` |
|
||||
| std-text | `cflmy/marqdo-std-text@c2a7d327e5d1914db8952562614707c112a07da1`(PR #2) |
|
||||
| std-system | `cflmy/marqdo-std-system@053ddb0e59dc016b9c7833f115d14fa04e721d48`(PR #2) |
|
||||
| std-io | `cflmy/marqdo-std-io@e18b0b1b40fcc6adcb42b5ab9fe1c9c04e9b8263`(PR #2) |
|
||||
| std-fs | `cflmy/marqdo-std-fs@63bceae58736f13770c7eead02535726d08c19d0`(PR #2) |
|
||||
| std-data | `cflmy/marqdo-std-data@848af7a357ceda2cfc20721b93406cf4be705889`(PR #2) |
|
||||
| std-collections | `cflmy/marqdo-std-collections@490765226866ac74b7365471c202e7638187bff8`(PR #2) |
|
||||
| ext-http(显式 Package) | `cflmy/marqdo-ext-http@368b33d241`(PR #2,合并后精确 SHA 以根 gitlink 为准) |
|
||||
| ext-regex(显式 Package) | `cflmy/marqdo-ext-regex@6e7e633798`(PR #2) |
|
||||
| ext-archive(显式 Package) | `cflmy/marqdo-ext-archive@aba6b60934`(PR #2) |
|
||||
|
||||
`std-core`、`std-encoding`、`std-net` 保持 `planned`,不加入 Bundle。HTTP/Regex/Archive 已迁为显式 Package(`index.mq.md` + `marqdo.yaml`,消费者经 `@alias` 导入),不进入默认 Bundle;其源码候选已合并到各自仓库 main,根候选固定对应提交并执行显式 Package 消费门禁(`kind = "explicit-package"`)。
|
||||
|
||||
## 唯一 Bundle 制品
|
||||
|
||||
`scripts/build-stdlib.py` 从上述根 gitlink 组合,两次干净构建逐字节一致:
|
||||
|
||||
| 字段 | 值 |
|
||||
| --- | --- |
|
||||
| name / version | `marqdo-stdlib` / `0.2.0`(内容变化显式升版本;摘要算法不变) |
|
||||
| tree digest | `sha256:db905508dde89763b9d43b47fc5d52c6a1d5445a91f3c86a550ced43e8aac9d7` |
|
||||
| aliases digest | `sha256:5f513c0fdbb3c1e9829be3c9fa23a2d1e89cb8510073fb5eb1e8e2f5265a83bb`(与迁移前一致) |
|
||||
| 模块数 | 17(仅模块;`tests/`、`demo.mq.md`、`net/http`、`regex`、`compress` 均不在默认 Bundle) |
|
||||
| 打包归档 | `marqdo-stdlib-0.2.0.tar.gz`,`sha256:212cca32f10ecfa0cdedfa976f7726db5e01cdb0e664a41ae26d4b34a8fd7048`(CLI Phase A `tools/pack-stdlib.py` 两次输出逐字节一致) |
|
||||
|
||||
## 门禁结果
|
||||
|
||||
| 门禁 | 命令 | 结果 |
|
||||
| --- | --- | --- |
|
||||
| 根布局 | `python3 scripts/check-layout.py` | PASS |
|
||||
| 递归布局 | `python3 scripts/check-layout.py --checkouts` | PASS(33 个固定子树;6 个 active stdlib entry 存在且工作区干净) |
|
||||
| 根集成测试 | `python3 -m unittest discover -s tests/integration` | Ran 56 tests,OK(含 9 个 Bundle 生产者契约测试) |
|
||||
| 组件独立验收 | `MARQDO_BIN=<RC.4 由 452e9a3 构建> MARQDO_STDLIB_DIR=<新 Bundle> scripts/test.sh`(各仓) | 6/6 PASS,共 17 个 case(collections 1、text 2、data 3、io 4、fs 2、system 5) |
|
||||
| 跨仓组合 | `scripts/acceptance-stdlib.py --cli <CLI> --bundle <新 Bundle>` | PASS:官方 `print`/`打印` 别名、Table 值操作+GFM 跨模块、默认 Bundle smoke |
|
||||
| Table 等价性 | 组合 fixture 终值与迁移前原 `stdlib/tests/table.mq.md` 终值 | 逐字节一致 |
|
||||
| 显式 Package 消费 | `scripts/acceptance-stdlib.py` 内 http/regex/archive 各自 `scripts/test.sh`(临时消费者工程 + `marqdo lock` + `@alias` 导入) | PASS(原领域测试终值与迁移前基线一致) |
|
||||
| 失败负例 | 缺显式 Bundle、篡改模块摘要 | 均按预期失败(exit 1),不静默回退 |
|
||||
| 相邻安装离线运行 | 把新 Bundle 放到 CLI 二进制旁 `stdlib/`,不设 `MARQDO_STDLIB_DIR` | PASS(默认离线安装路径可用) |
|
||||
| CLI 打包 | Phase A `pack-stdlib.py --stdlib-dir <新 Bundle>` ×2 + 篡改输入 | 确定性 PASS;篡改拒绝 |
|
||||
|
||||
CLI 身份(sha256):由 `452e9a3` 构建的 RC.4 二进制 `sha256:0377b855...`;Phase A 合并 master(`f8b82d4`)二进制 `sha256:6ede3b9e...`。两者对同一 Bundle 的组件与组合门禁结果一致。
|
||||
|
||||
## 未验证 / 待办
|
||||
|
||||
- 完整 `scripts/integration.sh` 的既有消费者门禁(Conformance/View/Knowledge/Prove/Lint)本轮**未执行**:该流程仍取冻结 RC.4 制品,本次未替换为统一制品输入(ECO-02,marqdo#7);不能把本次 PASS 当作生态发行验收。
|
||||
- CLI Phase B(删除仓内官方标准库源树、pin 切换)未做,等待 CLI PR #12 合并与本候选组件 PR 合并。
|
||||
- HTTP/Regex/Archive 已成为显式 Package 且组件内测试通过;本候选的根组合门禁只验证了独立 Package 行为,尚未验证真实应用项目的 `git` 依赖锁定/同步与发布分发,也尚未从默认 Bundle 删除后验证既有 `std:` 用户的迁移提示(按合同不保留 fallback)。
|
||||
- 未做完整产品归档冷安装(新 Bundle + 新 CLI 发行归档)与多平台证据;Windows/macOS 未验证。
|
||||
- 根主分支未改动,回退方式为放弃本候选分支,迁移前组合 `484cb10` 仍可检出。
|
||||
|
||||
## 复现
|
||||
|
||||
```sh
|
||||
git checkout migration/stdlib-m2-candidate
|
||||
git submodule update --init --recursive
|
||||
python3 scripts/check-layout.py --checkouts
|
||||
python3 -m unittest discover -s tests/integration
|
||||
python3 scripts/build-stdlib.py --out build/stdlib
|
||||
python3 scripts/acceptance-stdlib.py --cli <verified-marqdo> --work build/accept
|
||||
# 可选:--pack-tool <cli>/tools/pack-stdlib.py(Phase A 之后)
|
||||
```
|
||||
@@ -0,0 +1,54 @@
|
||||
# 标准库源码归位 M3 候选证据(2026-11-27)
|
||||
|
||||
父仓工单:[cflmy/marqdo#9](https://git.cflmy.cn/cflmy/marqdo/issues/9)。
|
||||
本文件记录 **M3 候选组合**(源码所有权切换 + 统一制品输入)的候选证据,不是已完成发行声明。主分支仍保持迁移前组合 `484cb10`,根 PR #12 只有在 CI 通过且 CLI Phase B 合并后才晋升。
|
||||
|
||||
## 候选身份
|
||||
|
||||
| 对象 | 身份 |
|
||||
| --- | --- |
|
||||
| 根候选 | `migration/stdlib-m2-candidate`(CLI Phase B 合并提交 `deadf6e`) |
|
||||
| CLI Phase B 合并 | `cflmy/marqdo-cli@deadf6edeea6dd0f5abf51c47e80204fd851baf0`(PR #17 fast-forward 合并;Phase B 代码提交 `72f57be`,另含 CI 脚本修复;`stdlib/` 已删除,pin 指向生态 Bundle) |
|
||||
| 生态 Bundle | `marqdo-stdlib@0.2.0`,source `cflmy/marqdo@48189243f7`,tree digest `sha256:db905508...`,aliases digest `sha256:5f513c0f...`(17 模块 + manifest) |
|
||||
| 组件固定 | 六个 std 与三个 ext 的已合并候选 SHA(M2 证据同一组) |
|
||||
| 发行归档(本地候选) | `marqdo-3.0.0-rc.4-x86_64-unknown-linux-gnu.tar.gz`,`sha256:9a926010ffe8e7353ee18b65fc568ced8bbf4b09b7592713f1213e2f3e3d40f9`(CLI `72f57be` + 新 Bundle) |
|
||||
|
||||
## 统一制品输入(ECO-02 核心)
|
||||
|
||||
根 `scripts/integration.sh` 不再读取 View 的冻结 RC.4 脚本;一次候选内派生全部输入:
|
||||
|
||||
1. `scripts/build-stdlib.py --out <work>/stdlib` 由固定组件 gitlink 生成唯一 Bundle;
|
||||
2. 从根固定的 `cli/` 提交构建 CLI 与 Provider Worker;
|
||||
3. `cli/tools/release/package.py --source-sha <cli SHA> --version <workspace version> --stdlib-dir <Bundle>` 生成发行归档与 `RELEASE_INFO.json`;
|
||||
4. `cli/tools/release/smoke.py` 验证归档、`SOURCE_SHA`、stdlib 摘要与语言-only 运行;
|
||||
5. `scripts/acceptance-stdlib.py --cli <installed> --bundle <Bundle>` 跑组件 entry、显式 Package、组合 fixture 与失败负例;
|
||||
6. Conformance、View、Knowledge、Prove、Lint 使用同一安装后二进制与相邻 Bundle。
|
||||
|
||||
## 本地候选验证
|
||||
|
||||
| 门禁 | 命令 | 结果 |
|
||||
| --- | --- | --- |
|
||||
| 根布局 | `python3 scripts/check-layout.py --checkouts` | PASS(含 6 个 active stdlib entry 与 9 个固定组件) |
|
||||
| Bundle | `python3 scripts/build-stdlib.py --out <dir>` | 两次构建一致,digest `sha256:db9055...` |
|
||||
| CLI Phase B | `cargo fmt` / `clippy -D warnings` / `cargo test --workspace`(显式 Bundle) | fmt/clippy PASS;72 个测试二进制 PASS |
|
||||
| CLI 工具测试 | `MARQDO_TEST_STDLIB_BUNDLE=<bundle> python3 -m unittest discover -s tools/ci` | 75 tests OK |
|
||||
| 独立构建 | `python3 tools/ci/independent_build.py` | PASS(无 stdlib 源树、无兄弟 Bundle,语言-only 运行成功,依赖 std 的程序 fail-closed) |
|
||||
| 发行归档 | `package.py --stdlib-dir <Bundle>` + `smoke.py --archive` | PASS(stdlib 0.2.0 摘要校验、缺失 Bundle fail-closed、language-only 运行) |
|
||||
| 验收脚本 | `scripts/acceptance-stdlib.py` 本地 M2 版 | PASS(6 组件 + 3 显式 Package + 4 组合 + 2 负例) |
|
||||
|
||||
## 未验证 / 待办
|
||||
|
||||
- 完整根 CI(`scripts/integration.sh` 含 View/Knowledge/Prove/Lint 消费者)在候选分支执行,结果记录在 PR #12/评论,不以本地部分运行替代。
|
||||
- 根晋升(合并 CLI PR #17 与根 PR #12、climo gitlink 与制品同一候选)属 MIG-RELEASE。
|
||||
- 完整产品归档冷安装(docker `--network none`)、多平台、ext-http loopback 领域测试仍待补;如需标记为发行门禁必须另行执行,不得以本文件冒充 PASS。
|
||||
|
||||
|
||||
## 晋升与 M4 验收(2026-11-27)
|
||||
|
||||
- CLI Phase B [PR #17](https://git.cflmy.cn/cflmy/marqdo-cli/pulls/17) fast-forward 合并,`master` = `deadf6e`(contract/test/independent-build/minimum-rust/build 全绿)。
|
||||
- 根 [PR #12](https://git.cflmy.cn/cflmy/marqdo/pulls/12) fast-forward 合并,`main` = `f4e292e7b09057c77e2a9293b40051be2666c4f8`;根树固定 CLI Phase B 与六个 std、三个 ext 提交,六个 stdlib 组件 active。
|
||||
- 根生态 CI 必须门禁 `ci/woodpecker/pr/eco` PASS([pipeline 38](https://ci.cflmy.cn/repos/6/pipeline/38/1)):一次候选派生 Bundle(`sha256:db9055...`)→ 从 cli gitlink 构建 CLI/Worker → `package.py --stdlib-dir`(归档 `sha256:0827ba4b...`)→ smoke → 根 acceptance(组件 entry、显式 Package、组合、负例)→ Conformance/View/Knowledge/Prove/Lint 全部同一安装后二进制与相邻 Bundle。
|
||||
- 发行级离线冷安装:在本机对同一晋升组合(根 `f4e292e`、CLI `deadf6e`、Bundle `db9055`)重新打包(归档 `sha256:377d2787...`)并执行 `cli/tools/release/cold-install.sh`(`ubuntu:24.04`、`--network none`、非 root 用户):PASS——安装后打印、`check`、示例运行、隐藏 Bundle 时 fail-closed、仅语言程序可运行均符合门禁。
|
||||
- 两个归档 SHA 不同是因为示例插件二进制由本机构建产生,不是同一构建环境的确定性证据;确定性打包证据以 CI 同一环境两次构建为准。发行归档身份以 CI/发布记录为准,本文件只记录晋升组合与冷安装通过。
|
||||
|
||||
仍保留为后续(不阻塞本轮关闭):Windows/macOS 不在本线发行支持矩阵;`marqdo-ext-http` 的 HTTP-over-TCP loopback 领域测试;ECO-02 的递归影响分析自动化。
|
||||
@@ -0,0 +1,32 @@
|
||||
# 领域扩展与领域聚合
|
||||
|
||||
本目录覆盖按需安装的领域能力。功能组件默认 `planned`,通过 Git 子模块固定独立仓库的开发提交,完成验收后晋升;聚合仓库不实现子组件业务,根 catalog 只登记 `kind = "domain"` 的聚合本身,不重复登记其后代路径。
|
||||
|
||||
## 领域聚合(planned)
|
||||
|
||||
| 路径 | 仓库 | 说明 |
|
||||
| --- | --- | --- |
|
||||
| `web/` | [marqdo-ext-web](https://git.cflmy.cn/cflmy/marqdo-ext-web) | Web 原型设计领域聚合:唯一设计合同、示例、组合验收与交付协调;子组件 [marqdo-web-design](https://git.cflmy.cn/cflmy/marqdo-web-design)、[marqdo-web-preview](https://git.cflmy.cn/cflmy/marqdo-web-preview) 在领域 `components.toml` 登记 |
|
||||
|
||||
## 独立组件(planned)
|
||||
|
||||
- [marqdo-ext-math](https://git.cflmy.cn/cflmy/marqdo-ext-math) · 数值算法、统计、符号数学及绘图
|
||||
- [marqdo-ext-linalg](https://git.cflmy.cn/cflmy/marqdo-ext-linalg) · 复数、矩阵、分解及数值线性代数
|
||||
- [marqdo-ext-quantum](https://git.cflmy.cn/cflmy/marqdo-ext-quantum) · 量子电路、态向量、采样与模拟
|
||||
- [marqdo-ext-http](https://git.cflmy.cn/cflmy/marqdo-ext-http) · HTTP、URL、SSE 与报文生命周期
|
||||
- [marqdo-ext-websocket](https://git.cflmy.cn/cflmy/marqdo-ext-websocket) · WebSocket 握手、帧与连接语义
|
||||
- [marqdo-ext-ai](https://git.cflmy.cn/cflmy/marqdo-ext-ai) · 模型协议、流式输出与工具调用数据
|
||||
- [marqdo-ext-mcp](https://git.cflmy.cn/cflmy/marqdo-ext-mcp) · MCP 协议、传输、发现和调用
|
||||
- [marqdo-ext-crypto](https://git.cflmy.cn/cflmy/marqdo-ext-crypto) · 成熟密码学实现的封装
|
||||
- [marqdo-ext-database](https://git.cflmy.cn/cflmy/marqdo-ext-database) · SQL 参数绑定、事务和驱动连接
|
||||
- [marqdo-ext-storage](https://git.cflmy.cn/cflmy/marqdo-ext-storage) · 本地和对象存储接口
|
||||
- [marqdo-ext-cache](https://git.cflmy.cn/cflmy/marqdo-ext-cache) · TTL、缓存和失效
|
||||
- [marqdo-ext-security](https://git.cflmy.cn/cflmy/marqdo-ext-security) · 应用身份、会话及权限模型
|
||||
- [marqdo-ext-browser](https://git.cflmy.cn/cflmy/marqdo-ext-browser) · 浏览器宿主、WASM 适配、DOM 和事件
|
||||
- [marqdo-ext-document](https://git.cflmy.cn/cflmy/marqdo-ext-document) · Markdown 结构与显式文档编辑
|
||||
- [marqdo-ext-archive](https://git.cflmy.cn/cflmy/marqdo-ext-archive) · 压缩、安全归档和解包
|
||||
- [marqdo-ext-engineering](https://git.cflmy.cn/cflmy/marqdo-ext-engineering) · 工程操作、文件补丁与产物
|
||||
- [marqdo-ext-regex](https://git.cflmy.cn/cflmy/marqdo-ext-regex) · 正则匹配、捕获、扫描和替换
|
||||
- [marqdo-ext-datetime](https://git.cflmy.cn/cflmy/marqdo-ext-datetime) · IANA 时区、DST 和高级日历
|
||||
|
||||
[组件目录](../components.toml) · [各仓库任务](../docs/REPOSITORY-TASKS.md) · [架构边界](../docs/ARCHITECTURE.md)
|
||||
Submodule
+1
Submodule extensions/ai added at 4d2c3e4f1a.
Submodule
+1
Submodule extensions/archive added at aba6b60934.
Submodule
+1
Submodule extensions/browser added at 35c1a75fd0.
Submodule
+1
Submodule extensions/cache added at 0357907e1d.
Submodule
+1
Submodule extensions/crypto added at 21529b8b25.
Submodule
+1
Submodule extensions/database added at e86a397c8e.
Submodule
+1
Submodule extensions/datetime added at 5e2e2a1b34.
Submodule
+1
Submodule extensions/document added at eb88be346a.
Submodule
+1
Submodule extensions/engineering added at b9f3ddba05.
Submodule
+1
Submodule extensions/http added at 368b33d241.
Submodule
+1
Submodule extensions/linalg added at 773ba9ef2e.
Submodule
+1
Submodule extensions/math added at f7ef25014a.
Submodule
+1
Submodule extensions/mcp added at df477bceec.
Submodule
+1
Submodule extensions/quantum added at 33f4780e9e.
Submodule
+1
Submodule extensions/regex added at 6e7e633798.
Submodule
+1
Submodule extensions/security added at 6939018249.
Submodule
+1
Submodule extensions/storage added at 6a798f099e.
Submodule
+1
Submodule extensions/web added at f70095d60a.
Submodule
+1
Submodule extensions/websocket added at e79f2e78fa.
@@ -1,31 +0,0 @@
|
||||
---
|
||||
title: 欢迎使用 Marqdo
|
||||
description: 用户文档首页 — 代码即文档
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
阅读到这里的朋友你好!我是marqdo的开发者,很高兴你看到这个网站,marqdo是一个代码即文档的编程语言,作者想要做这个项目来源于一个小小的想法,AI输出的首选语言是markdown,为什么不能基于markdown创建一个新式的编程语言,不再区分文档和代码,代码写出来就是一份文档,文档也是代码(这个项目的野心实际更大些,项目立项之处就调研了谷歌OKF规范,计划自动生成YAML使得代码和文档能够自动的变成知识库,与此同时还有更多可能,例如规范化生成的PPT)。
|
||||
|
||||
所以marqdo产生了,为了确保我们的新语言能够百分百被markdown渲染,这门语言甚至采用了`.mq.md`的双层嵌套后缀,所以不需要有压力使用这门语言,就算出现了巨大的问题,就当让ai写文档好了,如果成功了,试想这样一种场景,你不再需要让ai生成代码的文档,ai写的代码能够便捷的被你读懂,至少能省点token,毕竟烧了太多,钱包容易饿瘦。
|
||||
|
||||
这门语言还是起步阶段,目前计划是制作一个解释型的语言,现在的marqdo支持一些特定的语法结构和关键字,并且允许自由的输出调试信息,以及直接通过前端预览各个代码块,生成静态文件,是的,没错,这个网站就是marqdo制作的,至少我相信marqdo会成为一个博客工具。
|
||||
|
||||
除了部分内置的关键字,marqdo并不限制必须使用英文编程,当然这并不意味着我要开发一个中文编程系统,事实上,这是由于文档即代码、代码即文档的结构决定的,如果只支持英文,那还有什么作用?还要掌握一门语言,这并不是让人愉悦的阅读体验,所以marqdo会长期支持多语言编程的可能。
|
||||
|
||||
欢迎各位加入开源库,共同建设和完成这个项目[marqdo的github仓库链接](https://github.com/cflmy/marqdo)
|
||||
|
||||
最后,引用所有程序员的开始欢迎各位:
|
||||
|
||||
> 问候 marqdo
|
||||
|
||||
如果你是一个敏锐的程序员应该会察觉到一个小问题,这个问题的解决方案是像下面这样的,我其实并不知道这样解决是否正确,但是我暂且放在这里,欢迎你,敏锐的程序元朋友。
|
||||
|
||||
> 问候 谁=marqdo user
|
||||
|
||||
## 问候
|
||||
- 谁
|
||||
|
||||
> print text=欢迎,`谁`!
|
||||
|
||||
---
|
||||
@@ -1,26 +0,0 @@
|
||||
# 用户文档(可执行 · 可下载)
|
||||
|
||||
本目录即面向访客的 Marqdo 介绍:每个 `.mq.md` 既是文稿也能 `marqdo run`,并随仓库 / 静态站一起下载。
|
||||
|
||||
| 路径 | 内容 |
|
||||
|------|------|
|
||||
| [`00-welcome.mq.md`](00-welcome.mq.md) | 首页 |
|
||||
| [`structure/`](structure/) | 基本结构 |
|
||||
| [`keywords/`](keywords/) | 关键字与内置 `print` |
|
||||
| [`features/`](features/) | 特性迭代说明 |
|
||||
|
||||
**不放** `errors/`:失败样例只在 `tests/errors/`,避免用户站出现红色执行失败。
|
||||
|
||||
开发文档(语言设计等)在 [`doc/`](../doc/),与本目录分离。
|
||||
|
||||
## 浏览与生成 HTML
|
||||
|
||||
```bash
|
||||
cargo run -- view public
|
||||
cargo run -- view output public -o public
|
||||
# 或
|
||||
./scripts/build-public.sh
|
||||
powershell -File ./scripts/build-public.ps1
|
||||
```
|
||||
|
||||
生成的 `index.html` 与 `pages/` 默认被 ignore;CI 构建后推到 `gh-pages`。详见 [user-site.md](../doc/design/user-site.md)。
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: Phase I — 树遍历解释器
|
||||
description: 词法 · 语法 · 语义 · 树遍历已贯通
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
里程碑:Phase I(树遍历)。
|
||||
|
||||
流水线:加载 → 行分类 → 递归下降语法 → 语义检查 → 树遍历执行。实现不用 Flex/Bison。
|
||||
|
||||
本页本身即可运行,证明「文档即程序」在解释器里已落地:
|
||||
|
||||
> print text=Phase I:tree-walk interpreter is live.
|
||||
@@ -1,18 +0,0 @@
|
||||
---
|
||||
title: 字节码后端
|
||||
description: --backend bytecode 与树遍历共用语义
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
里程碑:字节码原型。
|
||||
|
||||
同一套 .mq.md 可用树遍历或字节码 VM 执行。命令示例:
|
||||
|
||||
marqdo run FILE --backend tree
|
||||
|
||||
marqdo run FILE --backend bytecode
|
||||
|
||||
下面这段在两种后端下输出一致:
|
||||
|
||||
> print text=Bytecode backend:same program, alternate engine.
|
||||
@@ -1,16 +0,0 @@
|
||||
---
|
||||
title: view 与用户文档站
|
||||
description: 本地浏览与静态导出由解释器生成
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
里程碑:marqdo view 与 view output。
|
||||
|
||||
本地浏览:marqdo view public
|
||||
|
||||
静态导出:marqdo view output public -o public
|
||||
|
||||
用户可执行文档就在 public/;生成的 HTML(index.html / pages/)供静态托管,CI 发布到 gh-pages。
|
||||
|
||||
> print text=Docs site:generated by the Marqdo interpreter, not hand-written HTML.
|
||||
@@ -1,23 +0,0 @@
|
||||
---
|
||||
title: 布尔与逻辑
|
||||
description: True / False / None 与 and / or / not
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
关键字:`True`、`False`、`None`,以及 `and` / `or` / `not`。
|
||||
|
||||
*`a` = True*
|
||||
*`b` = False*
|
||||
|
||||
+ `a` and not `b`
|
||||
> print text=ok
|
||||
+ *
|
||||
> print text=fail
|
||||
|
||||
*`probe` = 1*
|
||||
|
||||
+ None
|
||||
> print text=none-truthy
|
||||
+ *
|
||||
> print text=none-falsy
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: 内置 print
|
||||
description: 具名与位置两种写法
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
内置 print 接受具名或位置实参:
|
||||
|
||||
> print text=named form
|
||||
|
||||
> print positional
|
||||
|
||||
这里的设计思路是具名实参允许空格的传入,位置实参则不允许。
|
||||
@@ -1,12 +0,0 @@
|
||||
---
|
||||
title: Hello World
|
||||
description: 最简单的可执行文档
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
普通段落是注释。print 是内置函数,不是语法架构。
|
||||
|
||||
注释里的粗体与斜体标记若出现在行首会被当成代码,所以叙述行请用普通文字开头。
|
||||
|
||||
> print text=Hello World!
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
title: 函数与具名调用
|
||||
description: `#` 定义函数,`>` 调用;`-` 下列纯名为形参
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
用 `#` / `##` 定义函数。形参写在函数头下方的 `-` 纯名行。
|
||||
|
||||
调用用 `>`:具名实参写作 `形参=值`。
|
||||
|
||||
> 问候 谁=World
|
||||
|
||||
## 问候
|
||||
- 谁
|
||||
|
||||
> print text=Hello `谁`!
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
title: 位置实参
|
||||
description: 按形参顺序传参;也可继续用具名
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
位置实参:按形参声明顺序绑定,不必写 `谁=`。
|
||||
|
||||
> 问候 Marqdo
|
||||
|
||||
具名形式仍然可用:
|
||||
|
||||
> 问候 谁=World
|
||||
|
||||
## 问候
|
||||
- 谁
|
||||
|
||||
> print text=Hello `谁`!
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
title: 分支
|
||||
description: `+` 臂;整行 `*` 为 else
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
斜体行是程序语句。分支用 `+`;臂头单独一行 `*` 表示 else。
|
||||
|
||||
*`x` = 0*
|
||||
|
||||
+ `x` > 0
|
||||
> print text=正数
|
||||
+ `x` < 0
|
||||
> print text=负数
|
||||
+ *
|
||||
> print text=零
|
||||
@@ -1,28 +0,0 @@
|
||||
---
|
||||
title: 循环
|
||||
description: 条件循环与表格遍历
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
函数体内的 `-` 是循环(不是形参)。
|
||||
|
||||
倒数:
|
||||
|
||||
*`n` = 3*
|
||||
|
||||
- `n` > 0
|
||||
> print text=`n`
|
||||
*`n` = `n` - 1*
|
||||
|
||||
遍历篮子(表格是集合):
|
||||
|
||||
`篮子` =
|
||||
|
||||
| 果 |
|
||||
|----|
|
||||
| 苹果 |
|
||||
| 梨 |
|
||||
|
||||
- [果](篮子)
|
||||
> print text=今天吃`果`
|
||||
@@ -1,19 +0,0 @@
|
||||
---
|
||||
title: 集合(表格)
|
||||
description: GFM 表格即集合
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
Markdown 表格在 Marqdo 里就是集合,可用循环逐行取出。
|
||||
|
||||
`篮子` =
|
||||
|
||||
| 果 |
|
||||
|----|
|
||||
| 苹果 |
|
||||
| 梨 |
|
||||
| 桃 |
|
||||
|
||||
- [果](篮子)
|
||||
> print text=`果`
|
||||
@@ -1,17 +0,0 @@
|
||||
---
|
||||
title: 跨文件导入
|
||||
description: frontmatter 中 `> 文件.mq.md` 导入模块
|
||||
> utils.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
文件头 YAML 里写 `> utils.mq.md` 即可导入同目录模块。
|
||||
|
||||
导入后:用返回值绑定,再输出;并直接调用问候。
|
||||
|
||||
*`y` = > 加一 n=41*
|
||||
|
||||
> print text=`y`
|
||||
|
||||
> 问候 谁=Marqdo
|
||||
@@ -1,14 +0,0 @@
|
||||
---
|
||||
title: 工具模块
|
||||
description: 被 main 导入;粗体是返回值
|
||||
---
|
||||
|
||||
# 加一
|
||||
- n
|
||||
|
||||
**`n` + 1**
|
||||
|
||||
# 问候
|
||||
- 谁
|
||||
|
||||
> print text=你好,`谁`!
|
||||
Executable
+413
@@ -0,0 +1,413 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Accept the stdlib migration candidate with explicit, verified inputs.
|
||||
|
||||
This is the root-layer composition gate: it builds (or accepts) the one Bundle
|
||||
produced by ``scripts/build-stdlib.py`` from the pinned component gitlinks, runs
|
||||
each active stdlib component's own entry point against that Bundle, runs the
|
||||
cross-repository composition fixtures, exercises the negative inputs that must
|
||||
fail closed, and optionally packages the Bundle with the CLI's own packer twice
|
||||
to prove determinism.
|
||||
|
||||
Every input is explicit: a real ``marqdo`` executable (``--cli``) and either a
|
||||
Bundle (``--bundle``) or a checkout that can build one at its pinned gitlinks.
|
||||
Nothing is downloaded and no sibling component is discovered implicitly.
|
||||
|
||||
Usage:
|
||||
|
||||
python3 scripts/acceptance-stdlib.py --cli build/marqdo --work build/accept
|
||||
python3 scripts/acceptance-stdlib.py --cli build/marqdo --work build/accept \
|
||||
--pack-tool /path/to/cli/tools/pack-stdlib.py --evidence build/accept/evidence.json
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import base64
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
CASES = ROOT / "tests" / "integration" / "composition" / "cases"
|
||||
CASES_SCHEMA = "marqdo.stdlib-test-case"
|
||||
FORBIDDEN = {
|
||||
"net/http.mq.md",
|
||||
"regex.mq.md",
|
||||
"compress.mq.md",
|
||||
"demo.mq.md",
|
||||
"tests",
|
||||
}
|
||||
|
||||
|
||||
class AcceptanceError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def run(command, cwd=None, env=None, input_bytes=b""):
|
||||
result = subprocess.run(
|
||||
command, cwd=cwd, env=env, input=input_bytes, capture_output=True
|
||||
)
|
||||
return result
|
||||
|
||||
|
||||
def sha256(path: Path) -> str:
|
||||
return "sha256:" + hashlib.sha256(path.read_bytes()).hexdigest()
|
||||
|
||||
|
||||
def channel_text(events: list[dict], channel: str) -> str:
|
||||
chunks = []
|
||||
for event in events:
|
||||
if event.get("kind") != channel:
|
||||
continue
|
||||
payload = event["payload"]
|
||||
data = base64.b64decode(payload["data_base64"])
|
||||
if len(data) != payload["byte_count"]:
|
||||
raise AcceptanceError(f"{channel} byte_count mismatch")
|
||||
chunks.append(data)
|
||||
return b"".join(chunks).decode("utf-8")
|
||||
|
||||
|
||||
def tree_digest(bundle: Path) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for path in sorted(bundle.rglob("*.mq.md"), key=lambda p: p.relative_to(bundle).as_posix()):
|
||||
digest.update(path.relative_to(bundle).as_posix().encode())
|
||||
digest.update(b"\0")
|
||||
digest.update(path.read_bytes())
|
||||
digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def aliases_digest(aliases: list[dict]) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for alias in sorted(aliases, key=lambda a: (a["target_module"], a["target_function"])):
|
||||
digest.update(alias["target_module"].encode()); digest.update(b"\0")
|
||||
digest.update(alias["target_function"].encode()); digest.update(b"\0")
|
||||
for name in sorted(alias["public_names"]):
|
||||
digest.update(name.encode()); digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def verify_bundle(bundle: Path) -> dict:
|
||||
manifest_path = bundle / "stdlib.json"
|
||||
if not manifest_path.is_file():
|
||||
raise AcceptanceError(f"missing Bundle manifest: {manifest_path}")
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
for field in ("name", "version", "digest", "aliases_digest"):
|
||||
if not isinstance(manifest.get(field), str) or not manifest[field]:
|
||||
raise AcceptanceError(f"manifest has no {field}")
|
||||
computed = tree_digest(bundle)
|
||||
if computed != manifest["digest"]:
|
||||
raise AcceptanceError(
|
||||
f"manifest digest mismatch: {manifest['digest']} != {computed}"
|
||||
)
|
||||
aliases = manifest.get("public_aliases", [])
|
||||
expected_alias = aliases_digest(aliases)
|
||||
if expected_alias != manifest["aliases_digest"]:
|
||||
raise AcceptanceError("aliases digest mismatch")
|
||||
files = sorted(
|
||||
path.relative_to(bundle).as_posix()
|
||||
for path in bundle.rglob("*.mq.md")
|
||||
)
|
||||
for relative in files:
|
||||
parts = relative.split("/")
|
||||
if "tests" in parts or relative in FORBIDDEN:
|
||||
raise AcceptanceError(f"forbidden module in Bundle: {relative}")
|
||||
for alias in aliases:
|
||||
if alias["target_module"] not in files:
|
||||
raise AcceptanceError(
|
||||
f"public alias targets missing module {alias['target_module']}"
|
||||
)
|
||||
if "io.mq.md" not in files:
|
||||
raise AcceptanceError("Bundle lost the io.mq.md alias target")
|
||||
return {
|
||||
"manifest": manifest,
|
||||
"files": files,
|
||||
"tree_digest": computed,
|
||||
}
|
||||
|
||||
|
||||
def run_case(cli: str, bundle: Path, case: dict) -> dict:
|
||||
source = ROOT / "tests" / "integration" / "composition" / case["file"]
|
||||
command = [cli, "run", str(source), *case.get("args", []), "--output", "json"]
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_STDLIB_DIR"] = str(bundle)
|
||||
for key, value in case.get("env", {}).items():
|
||||
env[key] = value.replace("$MARQDO_BIN", cli)
|
||||
result = run(command, cwd=ROOT, env=env, input_bytes=case.get("stdin", "").encode())
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} failed: "
|
||||
f"{result.stderr.decode(errors='replace')}"
|
||||
)
|
||||
report = json.loads(result.stdout)
|
||||
if report.get("run", {}).get("status") != "ok":
|
||||
raise AcceptanceError(f"composition case {case['name']} run status not ok")
|
||||
terminal = report["events"][-1]["payload"]
|
||||
if terminal.get("value") != case["expected_terminal"]:
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} terminal value changed"
|
||||
)
|
||||
stdout = channel_text(report["events"], "stdout.chunk")
|
||||
if stdout != case.get("expected_stdout", ""):
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} stdout changed: {stdout!r}"
|
||||
)
|
||||
lines = stdout.splitlines()
|
||||
for left, right in case.get("stdout_line_pairs", []):
|
||||
if left >= len(lines) or right >= len(lines):
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']} has no line pair {left}/{right}"
|
||||
)
|
||||
if lines[left] != lines[right]:
|
||||
raise AcceptanceError(
|
||||
f"composition case {case['name']}: line {left} differs from line {right}: "
|
||||
f"{lines[left]!r} != {lines[right]!r}"
|
||||
)
|
||||
return {"name": case["name"], "status": "PASS"}
|
||||
|
||||
|
||||
def load_components() -> list[dict]:
|
||||
catalog = tomllib.loads((ROOT / "components.toml").read_text())
|
||||
return [
|
||||
component
|
||||
for component in catalog["component"]
|
||||
if component.get("kind") == "stdlib" and component.get("state") == "active"
|
||||
]
|
||||
|
||||
|
||||
def load_explicit_packages() -> list[dict]:
|
||||
"""Planned extensions that already publish an explicit Package entry.
|
||||
|
||||
A component is gated as an explicit package only when its pinned checkout
|
||||
carries the current package layout (``marqdo.yaml`` + ``index.mq.md`` +
|
||||
``scripts/test.sh``); it is never silently loaded into the default Bundle.
|
||||
"""
|
||||
catalog = tomllib.loads((ROOT / "components.toml").read_text())
|
||||
packages = []
|
||||
for component in catalog["component"]:
|
||||
if component.get("kind") != "extension":
|
||||
continue
|
||||
checkout = ROOT / component["path"]
|
||||
if (checkout / "marqdo.yaml").is_file() and (
|
||||
checkout / "index.mq.md"
|
||||
).is_file() and (checkout / "scripts" / "test.sh").is_file():
|
||||
packages.append(component)
|
||||
return packages
|
||||
|
||||
|
||||
def component_gates(cli: str, bundle: Path) -> list[dict]:
|
||||
results = []
|
||||
for component in load_components():
|
||||
entry = ROOT / component["path"] / component["entry"]
|
||||
if not entry.is_file():
|
||||
raise AcceptanceError(
|
||||
f"active component {component['id']} has no entry {component['entry']}"
|
||||
)
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_BIN"] = cli
|
||||
env["MARQDO_STDLIB_DIR"] = str(bundle)
|
||||
result = run([str(entry)], cwd=entry.parent.parent, env=env)
|
||||
output = (result.stdout + result.stderr).decode(errors="replace").strip()
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
f"component {component['id']} failed entry {component['entry']}:\n{output}"
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
"id": component["id"],
|
||||
"entry": component["entry"],
|
||||
"status": "PASS",
|
||||
"output": output,
|
||||
}
|
||||
)
|
||||
for component in load_explicit_packages():
|
||||
entry = ROOT / component["path"] / "scripts" / "test.sh"
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_BIN"] = cli
|
||||
env["MARQDO_STDLIB_DIR"] = str(bundle)
|
||||
result = run([str(entry)], cwd=ROOT / component["path"], env=env)
|
||||
output = (result.stdout + result.stderr).decode(errors="replace").strip()
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
f"explicit package {component['id']} failed: {output}"
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
"id": component["id"],
|
||||
"entry": "scripts/test.sh",
|
||||
"kind": "explicit-package",
|
||||
"status": "PASS",
|
||||
"output": output,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def negative_gates(cli: str, bundle: Path, work: Path) -> list[dict]:
|
||||
results = []
|
||||
|
||||
def expect_failure(name, command, env_for_gate):
|
||||
result = run(command, env=env_for_gate)
|
||||
if result.returncode == 0:
|
||||
raise AcceptanceError(f"negative gate {name} unexpectedly passed")
|
||||
results.append(
|
||||
{
|
||||
"name": name,
|
||||
"status": "PASS",
|
||||
"exit": result.returncode,
|
||||
"stderr": result.stderr.decode(errors="replace").strip()[:400],
|
||||
}
|
||||
)
|
||||
|
||||
missing = work / "missing-bundle"
|
||||
env = os.environ.copy()
|
||||
env["MARQDO_STDLIB_DIR"] = str(missing)
|
||||
expect_failure(
|
||||
"missing-explicit-bundle",
|
||||
[cli, "run", str(ROOT / "tests/integration/composition/default-bundle.mq.md")],
|
||||
env,
|
||||
)
|
||||
|
||||
tampered = work / "tampered-bundle"
|
||||
if tampered.exists():
|
||||
shutil.rmtree(tampered)
|
||||
shutil.copytree(bundle, tampered)
|
||||
target = next(iter(sorted(tampered.rglob("*.mq.md"))))
|
||||
target.write_bytes(target.read_bytes() + b"\n")
|
||||
env["MARQDO_STDLIB_DIR"] = str(tampered)
|
||||
expect_failure(
|
||||
"tampered-module-digest",
|
||||
[cli, "run", str(ROOT / "tests/integration/composition/default-bundle.mq.md")],
|
||||
env,
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def packaging_gates(pack_tool: str, bundle: Path, work: Path) -> list[dict]:
|
||||
results = []
|
||||
archives = []
|
||||
for attempt in (1, 2):
|
||||
out_dir = work / f"pack-{attempt}"
|
||||
if out_dir.exists():
|
||||
shutil.rmtree(out_dir)
|
||||
result = run(
|
||||
[
|
||||
sys.executable,
|
||||
pack_tool,
|
||||
"--stdlib-dir",
|
||||
str(bundle),
|
||||
"--out-dir",
|
||||
str(out_dir),
|
||||
]
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
"CLI packer rejected the Bundle: "
|
||||
+ result.stderr.decode(errors="replace")
|
||||
)
|
||||
archives.append(sorted(out_dir.glob("*.tar.gz"))[0])
|
||||
if archives[0].read_bytes() != archives[1].read_bytes():
|
||||
raise AcceptanceError("two packaging runs are not byte-identical")
|
||||
descriptor = json.loads(
|
||||
sorted(archives[0].parent.glob("*.json"))[0].read_text()
|
||||
)
|
||||
results.append(
|
||||
{
|
||||
"status": "PASS",
|
||||
"archive": archives[0].name,
|
||||
"archive_sha256": sha256(archives[0]),
|
||||
"tree_digest": descriptor.get("tree_digest"),
|
||||
"aliases_digest": descriptor.get("aliases_digest"),
|
||||
"deterministic": True,
|
||||
}
|
||||
)
|
||||
return results
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--cli", required=True)
|
||||
parser.add_argument("--work", required=True)
|
||||
parser.add_argument("--bundle")
|
||||
parser.add_argument("--pack-tool")
|
||||
parser.add_argument("--evidence")
|
||||
parser.add_argument("--root-commit")
|
||||
args = parser.parse_args(argv)
|
||||
cli = str(Path(args.cli).resolve())
|
||||
if not Path(cli).is_file():
|
||||
raise SystemExit(f"acceptance-stdlib: error: no CLI executable at {cli}")
|
||||
work = Path(args.work).resolve()
|
||||
work.mkdir(parents=True, exist_ok=True)
|
||||
try:
|
||||
if args.bundle:
|
||||
bundle = Path(args.bundle).resolve()
|
||||
else:
|
||||
bundle = work / "bundle"
|
||||
if bundle.exists():
|
||||
shutil.rmtree(bundle)
|
||||
command = [
|
||||
sys.executable,
|
||||
str(ROOT / "scripts" / "build-stdlib.py"),
|
||||
"--out",
|
||||
str(bundle),
|
||||
]
|
||||
if args.root_commit:
|
||||
command += ["--root-commit", args.root_commit]
|
||||
result = run(command, cwd=ROOT)
|
||||
if result.returncode != 0:
|
||||
raise AcceptanceError(
|
||||
"Bundle producer failed: "
|
||||
+ result.stderr.decode(errors="replace")
|
||||
)
|
||||
bundle_record = verify_bundle(bundle)
|
||||
version = run([cli, "--version"]).stdout.decode().strip()
|
||||
cases = []
|
||||
for path in sorted(CASES.glob("*.json")):
|
||||
case = json.loads(path.read_text())
|
||||
if case.get("schema") != CASES_SCHEMA:
|
||||
raise AcceptanceError(f"unsupported case schema: {path}")
|
||||
cases.append(run_case(cli, bundle, case))
|
||||
components = component_gates(cli, bundle)
|
||||
negatives = negative_gates(cli, bundle, work)
|
||||
packaging = (
|
||||
packaging_gates(args.pack_tool, bundle, work)
|
||||
if args.pack_tool
|
||||
else []
|
||||
)
|
||||
evidence = {
|
||||
"schema": "marqdo.stdlib-acceptance",
|
||||
"schema_version": 1,
|
||||
"cli": {"path": cli, "version": version, "sha256": sha256(Path(cli))},
|
||||
"root_commit": run(
|
||||
["git", "-C", str(ROOT), "rev-parse", "HEAD"]
|
||||
).stdout.decode().strip(),
|
||||
"bundle": {
|
||||
"name": bundle_record["manifest"]["name"],
|
||||
"version": bundle_record["manifest"]["version"],
|
||||
"tree_digest": bundle_record["tree_digest"],
|
||||
"aliases_digest": bundle_record["manifest"]["aliases_digest"],
|
||||
"files": bundle_record["files"],
|
||||
},
|
||||
"components": components,
|
||||
"composition": cases,
|
||||
"negatives": negatives,
|
||||
"packaging": packaging,
|
||||
"status": "PASS",
|
||||
}
|
||||
except AcceptanceError as error:
|
||||
print(f"acceptance-stdlib: FAIL: {error}", file=sys.stderr)
|
||||
return 1
|
||||
text = json.dumps(evidence, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.evidence:
|
||||
Path(args.evidence).write_text(text)
|
||||
print(text)
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@@ -1,6 +0,0 @@
|
||||
# Generate HTML next to public/*.mq.md via the Marqdo interpreter.
|
||||
$ErrorActionPreference = "Stop"
|
||||
Set-Location (Split-Path $PSScriptRoot -Parent)
|
||||
cargo build --release -q
|
||||
& .\target\release\marqdo.exe view output public -o public
|
||||
Write-Host "OK → public/index.html + public/pages/ (sources: public/**/*.mq.md)"
|
||||
@@ -1,7 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
# Generate HTML next to public/*.mq.md via the Marqdo interpreter.
|
||||
set -euo pipefail
|
||||
cd "$(dirname "$0")/.."
|
||||
cargo build --release -q
|
||||
./target/release/marqdo view output public -o public
|
||||
echo "OK → public/index.html + public/pages/ (sources: public/**/*.mq.md)"
|
||||
Executable
+397
@@ -0,0 +1,397 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Build the one official `marqdo-stdlib` Bundle from pinned component gitlinks.
|
||||
|
||||
The producer owns composition only: it collects the published `modules/` files
|
||||
of every **active** `kind = "stdlib"` component at the exact commit pinned by
|
||||
the root Gitlink, validates the published path set, generates the current
|
||||
`stdlib.json` (tree digest + public aliases digest) and writes a deterministic
|
||||
Bundle directory. Component repositories keep the module sources and tests; the
|
||||
root repository does not copy or edit them. The CLI packages the resulting
|
||||
Bundle with its existing `tools/pack-stdlib.py`.
|
||||
|
||||
Identity rules:
|
||||
|
||||
* release mode (default) reads `components.toml`, the Bundle config and the
|
||||
gitlinks from the ``--root-commit`` tree, never from the working tree;
|
||||
* `--worktree` is a development-only mode that reads each component's
|
||||
``HEAD`` and requires a clean component checkout;
|
||||
* only ``modules/**/*.mq.md`` is published. Other files under ``modules/``
|
||||
(for example ``modules/README.md``) stay repository documentation and are
|
||||
not packed. Symlinks, submodules and non-regular entries are refused;
|
||||
* published paths must be NFC, case-insensitively unique and free of
|
||||
``tests/``, ``.git`` or traversal segments;
|
||||
* a version bump is explicit: with ``--baseline-manifest`` content digest
|
||||
changes are refused unless ``version`` also changes.
|
||||
|
||||
Usage:
|
||||
|
||||
python3 scripts/build-stdlib.py --out build/stdlib
|
||||
python3 scripts/build-stdlib.py --out build/stdlib --worktree
|
||||
python3 scripts/build-stdlib.py --out build/stdlib \
|
||||
--baseline-manifest previous/stdlib.json
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import tomllib
|
||||
import unicodedata
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
DEFAULT_CONFIG = Path("scripts") / "stdlib-bundle.json"
|
||||
MANIFEST = "stdlib.json"
|
||||
MODULES = "modules"
|
||||
PUBLISHED_SUFFIX = ".mq.md"
|
||||
|
||||
|
||||
class BundleError(Exception):
|
||||
"""An input cannot become the official Bundle."""
|
||||
|
||||
|
||||
def _git(repo: Path, *args: str) -> bytes:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(repo), *args], capture_output=True
|
||||
)
|
||||
if result.returncode != 0:
|
||||
raise BundleError(
|
||||
f"git failed in {repo}: {' '.join(args)}: "
|
||||
f"{result.stderr.decode(errors='replace').strip()}"
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def _nfc(value: str) -> str:
|
||||
return unicodedata.normalize("NFC", value)
|
||||
|
||||
|
||||
def load_json(path: Path) -> dict:
|
||||
try:
|
||||
data = json.loads(path.read_text(encoding="utf-8"))
|
||||
except (OSError, UnicodeDecodeError, json.JSONDecodeError) as error:
|
||||
raise BundleError(f"cannot read {path}: {error}") from error
|
||||
if not isinstance(data, dict):
|
||||
raise BundleError(f"{path} must contain a JSON object")
|
||||
return data
|
||||
|
||||
|
||||
def read_blob(repo: Path, revision: str, path: str) -> bytes | None:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(repo), "show", f"{revision}:{path}"],
|
||||
capture_output=True,
|
||||
)
|
||||
return result.stdout if result.returncode == 0 else None
|
||||
|
||||
|
||||
def read_catalog(root: Path, revision: str | None) -> list[dict]:
|
||||
if revision is None:
|
||||
raw = (root / "components.toml").read_bytes()
|
||||
else:
|
||||
raw = read_blob(root, revision, "components.toml")
|
||||
if raw is None:
|
||||
raise BundleError(f"root commit {revision} has no components.toml")
|
||||
try:
|
||||
catalog = tomllib.loads(raw.decode("utf-8"))
|
||||
except (UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
|
||||
raise BundleError(f"invalid components.toml: {error}") from error
|
||||
components = catalog.get("component")
|
||||
if not isinstance(components, list):
|
||||
raise BundleError("components.toml has no [[component]] entries")
|
||||
return components
|
||||
|
||||
|
||||
def read_config(root: Path, revision: str | None, path: Path) -> dict:
|
||||
if not path.is_absolute():
|
||||
path = root / path
|
||||
if revision is not None:
|
||||
relative = path.resolve().relative_to(root.resolve()).as_posix()
|
||||
raw = read_blob(root, revision, relative)
|
||||
if raw is None:
|
||||
raise BundleError(f"root commit {revision} has no {relative}")
|
||||
try:
|
||||
config = json.loads(raw.decode("utf-8"))
|
||||
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
||||
raise BundleError(f"invalid Bundle config {relative}: {error}") from error
|
||||
else:
|
||||
config = load_json(path)
|
||||
for field in ("name", "version"):
|
||||
value = config.get(field)
|
||||
if not isinstance(value, str) or not value:
|
||||
raise BundleError(f"Bundle config has no non-empty `{field}`")
|
||||
aliases = config.get("public_aliases", [])
|
||||
if not isinstance(aliases, list):
|
||||
raise BundleError("Bundle config `public_aliases` must be a list")
|
||||
return config
|
||||
|
||||
|
||||
def pinned_gitlink(root: Path, revision: str, path: str) -> str:
|
||||
result = _git(root, "ls-tree", revision, "--", path).decode().strip()
|
||||
if not result:
|
||||
raise BundleError(
|
||||
f"root commit {revision} has no gitlink at {path}; only published "
|
||||
"components may join the Bundle"
|
||||
)
|
||||
fields = result.split()
|
||||
if len(fields) != 4:
|
||||
raise BundleError(f"invalid gitlink record for {path}")
|
||||
mode, kind, sha, _ = fields
|
||||
if mode != "160000" or kind != "commit":
|
||||
raise BundleError(f"{path} is not a gitlink in root commit {revision}")
|
||||
return sha
|
||||
|
||||
|
||||
def worktree_sha(component_dir: Path) -> str:
|
||||
if not (component_dir / ".git").exists():
|
||||
raise BundleError(f"missing component checkout: {component_dir}")
|
||||
status = _git(component_dir, "status", "--porcelain").decode().strip()
|
||||
if status:
|
||||
raise BundleError(f"dirty component checkout: {component_dir}")
|
||||
return _git(component_dir, "rev-parse", "HEAD").decode().strip()
|
||||
|
||||
|
||||
def validate_published_path(relative: str, component_id: str) -> None:
|
||||
if not relative or relative.startswith("/"):
|
||||
raise BundleError(f"{component_id}: invalid published path {relative!r}")
|
||||
parts = relative.split("/")
|
||||
if any(part in ("", ".", "..") for part in parts):
|
||||
raise BundleError(f"{component_id}: unsafe published path {relative!r}")
|
||||
if any(part.startswith(".") for part in parts):
|
||||
raise BundleError(f"{component_id}: hidden path segment in {relative!r}")
|
||||
if "tests" in parts:
|
||||
raise BundleError(f"{component_id}: tests must not enter the Bundle: {relative!r}")
|
||||
if not relative.endswith(PUBLISHED_SUFFIX):
|
||||
raise BundleError(
|
||||
f"{component_id}: only {PUBLISHED_SUFFIX} files are published, got {relative!r}"
|
||||
)
|
||||
if _nfc(relative) != relative:
|
||||
raise BundleError(
|
||||
f"{component_id}: published path is not NFC normalised: {relative!r}"
|
||||
)
|
||||
|
||||
|
||||
def component_modules(component_dir: Path, revision: str, component_id: str) -> list[tuple[str, str]]:
|
||||
output = _git(
|
||||
component_dir, "ls-tree", "-r", "-z", revision, "--", MODULES
|
||||
)
|
||||
records = [record for record in output.split(b"\0") if record]
|
||||
published: list[tuple[str, str]] = []
|
||||
for record in records:
|
||||
header, _, raw_path = record.partition(b"\t")
|
||||
fields = header.decode().split()
|
||||
if len(fields) != 3:
|
||||
raise BundleError(f"{component_id}: invalid tree record {record!r}")
|
||||
mode, kind, sha = fields
|
||||
path = raw_path.decode()
|
||||
if kind != "blob" or mode not in ("100644", "100755"):
|
||||
raise BundleError(
|
||||
f"{component_id}: only regular modules files are publishable, "
|
||||
f"found {mode} {kind} at {path}"
|
||||
)
|
||||
relative = path[len(MODULES) + 1 :]
|
||||
if not relative.endswith(PUBLISHED_SUFFIX):
|
||||
continue
|
||||
validate_published_path(relative, component_id)
|
||||
published.append((relative, sha))
|
||||
if not published:
|
||||
raise BundleError(
|
||||
f"{component_id}: active component publishes no {PUBLISHED_SUFFIX} modules"
|
||||
)
|
||||
return published
|
||||
|
||||
|
||||
def collect(root: Path, components: list[dict], *, root_commit: str | None) -> tuple[dict[str, bytes], list[dict]]:
|
||||
active = [
|
||||
component
|
||||
for component in components
|
||||
if component.get("kind") == "stdlib" and component.get("state") == "active"
|
||||
]
|
||||
if not active:
|
||||
raise BundleError("no active stdlib component; nothing to publish")
|
||||
for component in active:
|
||||
if component.get("release") != "base":
|
||||
raise BundleError(
|
||||
f'{component["id"]}: active stdlib component must have release = "base"'
|
||||
)
|
||||
files: dict[str, bytes] = {}
|
||||
identities: list[dict] = []
|
||||
owners: dict[str, str] = {}
|
||||
folded: dict[str, str] = {}
|
||||
for component in active:
|
||||
component_id = component["id"]
|
||||
path = component["path"]
|
||||
component_dir = (root / path).resolve()
|
||||
revision = (
|
||||
pinned_gitlink(root, root_commit, path)
|
||||
if root_commit is not None
|
||||
else worktree_sha(component_dir)
|
||||
)
|
||||
modules = component_modules(component_dir, revision, component_id)
|
||||
for relative, sha in modules:
|
||||
key = _nfc(relative).casefold()
|
||||
if relative in owners:
|
||||
raise BundleError(
|
||||
f"duplicate published path {relative!r}: "
|
||||
f"{owners[relative]} and {component_id}"
|
||||
)
|
||||
if key in folded:
|
||||
raise BundleError(
|
||||
f"case/NFC collision on {relative!r}: "
|
||||
f"{folded[key]} and {component_id}"
|
||||
)
|
||||
owners[relative] = component_id
|
||||
folded[key] = component_id
|
||||
files[relative] = _git(component_dir, "cat-file", "blob", sha)
|
||||
identities.append(
|
||||
{"id": component_id, "path": path, "revision": revision, "files": len(modules)}
|
||||
)
|
||||
return files, identities
|
||||
|
||||
|
||||
def tree_digest(files: dict[str, bytes]) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for relative in sorted(files):
|
||||
digest.update(relative.encode())
|
||||
digest.update(b"\0")
|
||||
digest.update(files[relative])
|
||||
digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def aliases_digest(aliases: list[dict]) -> str:
|
||||
digest = hashlib.sha256()
|
||||
for alias in sorted(
|
||||
aliases, key=lambda item: (item["target_module"], item["target_function"])
|
||||
):
|
||||
digest.update(alias["target_module"].encode())
|
||||
digest.update(b"\0")
|
||||
digest.update(alias["target_function"].encode())
|
||||
digest.update(b"\0")
|
||||
for name in sorted(alias["public_names"]):
|
||||
digest.update(name.encode())
|
||||
digest.update(b"\0")
|
||||
return "sha256:" + digest.hexdigest()
|
||||
|
||||
|
||||
def validate_aliases(aliases: list[dict], files: dict[str, bytes]) -> None:
|
||||
seen: set[str] = set()
|
||||
for alias in aliases:
|
||||
if not isinstance(alias, dict):
|
||||
raise BundleError("public alias entry must be an object")
|
||||
module = alias.get("target_module")
|
||||
function = alias.get("target_function")
|
||||
names = alias.get("public_names")
|
||||
if module not in files:
|
||||
raise BundleError(f"public alias targets missing module: {module!r}")
|
||||
if not isinstance(function, str) or not function:
|
||||
raise BundleError(f"public alias for {module} has no target_function")
|
||||
if not isinstance(names, list) or not names or not all(
|
||||
isinstance(name, str) and name for name in names
|
||||
):
|
||||
raise BundleError(f"public alias for {module}.{function} has invalid names")
|
||||
for name in names:
|
||||
if name in seen:
|
||||
raise BundleError(f"public alias name declared twice: {name!r}")
|
||||
seen.add(name)
|
||||
if alias.get("expected_signature") != "params(值)":
|
||||
raise BundleError(
|
||||
f"public alias {module}.{function} must keep expected_signature params(值)"
|
||||
)
|
||||
if alias.get("effects") != ["host"]:
|
||||
raise BundleError(
|
||||
f"public alias {module}.{function} must keep effects [host]"
|
||||
)
|
||||
|
||||
|
||||
def build_manifest(config: dict, files: dict[str, bytes]) -> dict:
|
||||
aliases = config.get("public_aliases", [])
|
||||
validate_aliases(aliases, files)
|
||||
return {
|
||||
"name": config["name"],
|
||||
"version": config["version"],
|
||||
"digest": tree_digest(files),
|
||||
"public_aliases": aliases,
|
||||
"aliases_digest": aliases_digest(aliases),
|
||||
}
|
||||
|
||||
|
||||
def check_baseline(manifest: dict, baseline_path: Path) -> None:
|
||||
baseline = load_json(baseline_path)
|
||||
if baseline.get("version") == manifest["version"] and baseline.get(
|
||||
"digest"
|
||||
) != manifest["digest"]:
|
||||
raise BundleError(
|
||||
f"Bundle content changed but version is still {manifest['version']}; "
|
||||
"bump the version explicitly"
|
||||
)
|
||||
|
||||
|
||||
def write_bundle(out: Path, manifest: dict, files: dict[str, bytes], force: bool) -> None:
|
||||
if out.exists():
|
||||
if not force:
|
||||
raise BundleError(f"output directory already exists: {out}")
|
||||
shutil.rmtree(out)
|
||||
out.parent.mkdir(parents=True, exist_ok=True)
|
||||
staging = Path(tempfile.mkdtemp(prefix=".stdlib-build-", dir=str(out.parent)))
|
||||
try:
|
||||
for relative, data in files.items():
|
||||
target = staging / relative
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
target.write_bytes(data)
|
||||
(staging / MANIFEST).write_text(
|
||||
json.dumps(manifest, ensure_ascii=False, indent=2) + "\n",
|
||||
encoding="utf-8",
|
||||
)
|
||||
os.replace(staging, out)
|
||||
except BaseException:
|
||||
shutil.rmtree(staging, ignore_errors=True)
|
||||
raise
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--out", required=True, help="Bundle output directory")
|
||||
parser.add_argument("--root-commit", default=None)
|
||||
parser.add_argument("--worktree", action="store_true")
|
||||
parser.add_argument("--config", default=None)
|
||||
parser.add_argument("--baseline-manifest", default=None)
|
||||
parser.add_argument("--force", action="store_true")
|
||||
parser.add_argument("--root", default=str(ROOT), help=argparse.SUPPRESS)
|
||||
args = parser.parse_args(argv)
|
||||
if args.worktree and args.root_commit:
|
||||
parser.error("--worktree and --root-commit are mutually exclusive")
|
||||
root = Path(args.root).resolve()
|
||||
revision = None
|
||||
if not args.worktree:
|
||||
revision = args.root_commit or _git(root, "rev-parse", "HEAD").decode().strip()
|
||||
try:
|
||||
components = read_catalog(root, revision)
|
||||
config = read_config(root, revision, Path(args.config) if args.config else DEFAULT_CONFIG)
|
||||
files, identities = collect(root, components, root_commit=revision)
|
||||
manifest = build_manifest(config, files)
|
||||
if args.baseline_manifest:
|
||||
check_baseline(manifest, Path(args.baseline_manifest))
|
||||
except BundleError as error:
|
||||
raise SystemExit(f"build-stdlib: error: {error}") from error
|
||||
write_bundle(Path(args.out), manifest, files, args.force)
|
||||
summary = {
|
||||
"name": manifest["name"],
|
||||
"version": manifest["version"],
|
||||
"tree_digest": manifest["digest"],
|
||||
"aliases_digest": manifest["aliases_digest"],
|
||||
"root_commit": revision,
|
||||
"components": identities,
|
||||
"files": sorted(files),
|
||||
}
|
||||
print(json.dumps(summary, ensure_ascii=False, indent=2))
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
Executable
+317
@@ -0,0 +1,317 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify one candidate notification before any automation acts on it.
|
||||
|
||||
The ecosystem uses manual PR gates; this verifier is the authorization step for
|
||||
a (future) bot that may only create candidate branches/PRs. It accepts a
|
||||
normalized notification (from a reviewed webhook adapter), never a raw remote
|
||||
payload, and returns a machine plan. It refuses forged, replayed, stale,
|
||||
unknown or failed candidates instead of trusting the sender.
|
||||
|
||||
Checks, in order:
|
||||
|
||||
1. notification schema and 40-hex commits;
|
||||
2. the repository is an allowlisted component remote (or the root repository);
|
||||
3. the CI result is `success` on an allowlisted CI host with an https URL;
|
||||
4. the commit is reachable in the owning local repository;
|
||||
5. a component candidate starts from the exact SHA currently pinned by the
|
||||
accepted root graph (a stale/retargeted base is rejected);
|
||||
6. the (repository, head SHA) pair is not a replay; a new accepted baseline
|
||||
allows a re-validation and marks the result `revalidate`;
|
||||
7. impact is computed with the shared union-graph analyzer; undetermined scope
|
||||
widens to full re-validation instead of skipping.
|
||||
|
||||
The verifier never merges, pushes, grants permissions or fetches floating
|
||||
branches. Its only proposed action is recording the candidate / creating a
|
||||
candidate branch that a human still reviews.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import datetime as dt
|
||||
import importlib.util
|
||||
import json
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
import urllib.parse
|
||||
from pathlib import Path
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
ROOT = PROJECT_ROOT
|
||||
SCHEMA = "marqdo.candidate-notification"
|
||||
PLAN_SCHEMA = "marqdo.candidate-plan"
|
||||
SCHEMA_VERSION = 1
|
||||
DEFAULT_CI_HOST = "ci.cflmy.cn"
|
||||
|
||||
|
||||
def load_impact():
|
||||
"""Load the shared analyzer and point it at the verifier's root checkout."""
|
||||
spec = importlib.util.spec_from_file_location(
|
||||
"marqdo_impact", PROJECT_ROOT / "scripts" / "impact.py"
|
||||
)
|
||||
module = importlib.util.module_from_spec(spec)
|
||||
spec.loader.exec_module(module)
|
||||
module.ROOT = ROOT
|
||||
return module
|
||||
|
||||
|
||||
def git(repo: Path, *args: str) -> str:
|
||||
result = subprocess.run(["git", "-C", str(repo), *args], capture_output=True)
|
||||
if result.returncode != 0:
|
||||
raise NotificationError(
|
||||
f"git {' '.join(args)} failed in {repo}: "
|
||||
f"{result.stderr.decode(errors='replace').strip()}"
|
||||
)
|
||||
return result.stdout.decode(errors="replace")
|
||||
|
||||
|
||||
class NotificationError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def is_sha(value) -> bool:
|
||||
return isinstance(value, str) and len(value) == 40 and all(
|
||||
ch in "0123456789abcdef" for ch in value
|
||||
)
|
||||
|
||||
|
||||
def repository_allowlist(accepted_revision: str) -> dict[str, dict]:
|
||||
"""Map `owner/name` -> component identity from the accepted root graph."""
|
||||
impact = load_impact()
|
||||
graph, unverified = impact.load_graph(ROOT, accepted_revision, "root")
|
||||
if unverified:
|
||||
raise NotificationError(
|
||||
"accepted graph cannot be expanded: " + "; ".join(unverified)
|
||||
)
|
||||
allowlist: dict[str, dict] = {}
|
||||
for component in graph.values():
|
||||
remote = component.get("remote")
|
||||
if not remote:
|
||||
continue
|
||||
parsed = urllib.parse.urlparse(remote)
|
||||
name = parsed.path.strip("/")
|
||||
if name.endswith(".git"):
|
||||
name = name[:-4]
|
||||
if name:
|
||||
allowlist[name] = component
|
||||
return allowlist
|
||||
|
||||
|
||||
def check_schema(notification: dict) -> None:
|
||||
if notification.get("schema") != SCHEMA:
|
||||
raise NotificationError(f"unsupported notification schema: {notification.get('schema')!r}")
|
||||
if notification.get("schema_version") != SCHEMA_VERSION:
|
||||
raise NotificationError("unsupported notification schema_version")
|
||||
if notification.get("kind") not in ("component", "root"):
|
||||
raise NotificationError("kind must be 'component' or 'root'")
|
||||
for field in ("repository", "head_sha", "base_sha"):
|
||||
if not isinstance(notification.get(field), str) or not notification[field]:
|
||||
raise NotificationError(f"notification has no {field}")
|
||||
if not is_sha(notification["head_sha"]) or not is_sha(notification["base_sha"]):
|
||||
raise NotificationError("head_sha/base_sha must be full lowercase commit SHAs")
|
||||
if notification["head_sha"] == notification["base_sha"]:
|
||||
raise NotificationError("head_sha equals base_sha; nothing to verify")
|
||||
|
||||
|
||||
def check_ci(notification: dict, ci_hosts: list[str]) -> dict:
|
||||
ci = notification.get("ci")
|
||||
if not isinstance(ci, dict):
|
||||
raise NotificationError("notification has no ci object")
|
||||
if ci.get("status") != "success":
|
||||
raise NotificationError(f"CI status is not success: {ci.get('status')!r}")
|
||||
url = ci.get("url")
|
||||
if not isinstance(url, str):
|
||||
raise NotificationError("notification ci.url must be a string")
|
||||
parsed = urllib.parse.urlparse(url)
|
||||
if parsed.scheme != "https" or parsed.hostname not in ci_hosts:
|
||||
raise NotificationError(
|
||||
f"CI URL must be https on one of {ci_hosts}: {url!r}"
|
||||
)
|
||||
return ci
|
||||
|
||||
|
||||
def load_state(path: Path) -> dict:
|
||||
if not path.is_file():
|
||||
return {"schema": "marqdo.candidate-state", "schema_version": 1, "seen": {}}
|
||||
state = json.loads(path.read_text())
|
||||
if not isinstance(state.get("seen"), dict):
|
||||
raise NotificationError(f"invalid candidate state file: {path}")
|
||||
return state
|
||||
|
||||
|
||||
def verify(
|
||||
notification: dict,
|
||||
accepted_ref: str,
|
||||
state_path: Path,
|
||||
ci_hosts: list[str],
|
||||
root_repository: str,
|
||||
write_state: bool,
|
||||
) -> dict:
|
||||
check_schema(notification)
|
||||
ci = check_ci(notification, ci_hosts)
|
||||
impact = load_impact()
|
||||
impact.ROOT = ROOT
|
||||
accepted_revision = impact.resolve(ROOT, accepted_ref)
|
||||
reasons: list[str] = []
|
||||
revalidate = False
|
||||
kind = notification["kind"]
|
||||
repository = notification["repository"]
|
||||
allowlist = repository_allowlist(accepted_revision)
|
||||
if kind == "root":
|
||||
if repository != root_repository:
|
||||
raise NotificationError(
|
||||
f"unknown root repository {repository!r}; allowlist is {root_repository!r}"
|
||||
)
|
||||
if not subprocess.run(
|
||||
["git", "-C", str(ROOT), "cat-file", "-e", notification["head_sha"] + "^{commit}"],
|
||||
capture_output=True,
|
||||
).returncode == 0:
|
||||
raise NotificationError("candidate commit is not reachable in the root repository")
|
||||
report = impact.analyze(accepted_revision, notification["head_sha"])
|
||||
base_sha = accepted_revision
|
||||
key = f"root@{notification['head_sha']}"
|
||||
else:
|
||||
component = allowlist.get(repository)
|
||||
if component is None:
|
||||
raise NotificationError(
|
||||
f"unknown repository {repository!r}; allowlist: {sorted(allowlist)}"
|
||||
)
|
||||
component_id = notification.get("component") or component["id"]
|
||||
if component_id != component["id"]:
|
||||
raise NotificationError(
|
||||
f"notification component {component_id!r} does not own repository {repository!r}"
|
||||
)
|
||||
checkout = ROOT / component["path"]
|
||||
if not (checkout / ".git").exists():
|
||||
raise NotificationError(f"missing component checkout: {checkout}")
|
||||
if not subprocess.run(
|
||||
["git", "-C", str(checkout), "cat-file", "-e", notification["head_sha"] + "^{commit}"],
|
||||
capture_output=True,
|
||||
).returncode == 0:
|
||||
raise NotificationError("candidate commit is not reachable in the component repository")
|
||||
if component.get("sha") != notification["base_sha"]:
|
||||
raise NotificationError(
|
||||
"base_sha is stale: the accepted root graph pins "
|
||||
f"{component.get('sha')} for {component_id}"
|
||||
)
|
||||
report = impact.consumers_of(component_id, accepted_revision)
|
||||
base_sha = component["sha"]
|
||||
key = f"{repository}@{notification['head_sha']}"
|
||||
state = load_state(state_path)
|
||||
previous = state["seen"].get(key)
|
||||
if previous is not None:
|
||||
if previous.get("accepted") == accepted_revision:
|
||||
raise NotificationError(
|
||||
"duplicate/replay: this candidate was already verified against the same accepted baseline"
|
||||
)
|
||||
revalidate = True
|
||||
reasons.append(
|
||||
"new accepted baseline since first notification; re-run the full candidate gates"
|
||||
)
|
||||
if report.get("unverified"):
|
||||
reasons.append("impact scope undetermined; full re-validation required")
|
||||
state["seen"][key] = {
|
||||
"accepted": accepted_revision,
|
||||
"base_sha": base_sha,
|
||||
"kind": kind,
|
||||
"repository": repository,
|
||||
"first_verified": previous.get("first_verified")
|
||||
if previous
|
||||
else dt.datetime.now(dt.timezone.utc).isoformat(),
|
||||
"last_verified": dt.datetime.now(dt.timezone.utc).isoformat(),
|
||||
}
|
||||
if write_state:
|
||||
state_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
state_path.write_text(json.dumps(state, indent=2) + "\n")
|
||||
return {
|
||||
"schema": PLAN_SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"verified": True,
|
||||
"revalidate": revalidate,
|
||||
"reasons": reasons,
|
||||
"kind": kind,
|
||||
"repository": repository,
|
||||
"head_sha": notification["head_sha"],
|
||||
"base_sha": notification["base_sha"],
|
||||
"accepted": {"ref": accepted_ref, "revision": accepted_revision},
|
||||
"ci": ci,
|
||||
"impact": {
|
||||
"affected": report.get("affected", []),
|
||||
"changed": report.get("changed", []),
|
||||
"checks_with": report.get("checks_with", []),
|
||||
"fallback": report.get("fallback"),
|
||||
"unverified": report.get("unverified", []),
|
||||
},
|
||||
"actions": {
|
||||
"auto_promote": False,
|
||||
"auto_merge": False,
|
||||
"create_candidate_branch": True,
|
||||
"requires_human_review": True,
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--notification", required=True, help="normalized notification JSON")
|
||||
parser.add_argument("--accepted", required=True, help="accepted root revision")
|
||||
parser.add_argument("--state", required=True, help="candidate dedupe state file")
|
||||
parser.add_argument(
|
||||
"--ci-host", action="append", default=None, help="allowlisted CI host (repeatable)"
|
||||
)
|
||||
parser.add_argument("--root-repository", default="cflmy/marqdo")
|
||||
parser.add_argument("--out", default=None)
|
||||
parser.add_argument("--json", action="store_true")
|
||||
parser.add_argument("--dry-run", action="store_true", help="do not write the dedupe state")
|
||||
args = parser.parse_args(argv)
|
||||
ci_hosts = args.ci_host or [DEFAULT_CI_HOST]
|
||||
try:
|
||||
notification = json.loads(Path(args.notification).read_text())
|
||||
if not isinstance(notification, dict):
|
||||
raise NotificationError("notification must be a JSON object")
|
||||
plan = verify(
|
||||
notification,
|
||||
args.accepted,
|
||||
Path(args.state),
|
||||
ci_hosts,
|
||||
args.root_repository,
|
||||
write_state=not args.dry_run,
|
||||
)
|
||||
except (NotificationError, json.JSONDecodeError, OSError) as error:
|
||||
rejected = {
|
||||
"schema": PLAN_SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"verified": False,
|
||||
"reasons": [str(error)],
|
||||
"actions": {
|
||||
"auto_promote": False,
|
||||
"auto_merge": False,
|
||||
"create_candidate_branch": False,
|
||||
"requires_human_review": True,
|
||||
},
|
||||
}
|
||||
text = json.dumps(rejected, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.out:
|
||||
Path(args.out).write_text(text)
|
||||
if args.json:
|
||||
print(text, end="")
|
||||
print(f"candidate-notify: rejected: {error}", file=sys.stderr)
|
||||
return 1
|
||||
text = json.dumps(plan, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.out:
|
||||
Path(args.out).write_text(text)
|
||||
if args.json:
|
||||
print(text, end="")
|
||||
else:
|
||||
print(
|
||||
f"verified {plan['kind']} candidate {plan['repository']}@{plan['head_sha'][:12]} "
|
||||
f"affected={len(plan['impact']['affected'])} revalidate={plan['revalidate']}"
|
||||
)
|
||||
for reason in plan["reasons"]:
|
||||
print(f" note: {reason}")
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
@@ -0,0 +1,455 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Validate a Marqdo ecosystem Git tree.
|
||||
|
||||
The checker follows the hierarchical governance rules of the Marqdo ecosystem
|
||||
specification (sections 2-4, 13):
|
||||
|
||||
* the root catalog describes direct components and domain aggregates;
|
||||
* a registered ``kind = "domain"`` gitlink is expanded at its exact pinned
|
||||
commit for ``--checkouts`` or to validate URLs before updating its children;
|
||||
* each aggregate layer has its own ``components.toml`` / ``.gitmodules`` and
|
||||
registers only its direct children;
|
||||
* governance depth is limited to two gitlink levels (root -> domain -> leaf);
|
||||
* global ids and remotes are unique, dependency edges resolve globally and
|
||||
``requires`` stays acyclic while ``checks_with`` may contain cycles.
|
||||
|
||||
Commit identity comes from the Git tree (gitlinks), the authority for remotes
|
||||
is ``.gitmodules`` and the catalog never repeats SHAs. The checker never
|
||||
fetches from a network remote, never runs ``git submodule update`` and only
|
||||
reads objects already present in the local repositories.
|
||||
"""
|
||||
|
||||
import argparse
|
||||
import graphlib
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
import unicodedata
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
NAME = r"[a-z][a-z0-9]*(?:-[a-z0-9]+)*"
|
||||
FIELDS = {"id", "path", "kind", "state", "owner", "scope", "requires", "checks_with", "release"}
|
||||
ROOT_FILES = {".gitattributes", ".gitignore", ".gitmodules", "AGENTS.md", "LICENSE", "README.md", "components.toml"}
|
||||
ROOT_DIRS = {".gitea", ".woodpecker", "docs", "examples", "scripts"}
|
||||
CATEGORY_READMES = {"stdlib/README.md", "extensions/README.md"}
|
||||
RELEASE_ROLES = {"core": "base", "stdlib": "base", "extension": "optional", "tool": "optional", "test": "none"}
|
||||
DOMAIN_RELEASE = {"none", "base"}
|
||||
DOMAIN_FILES = {".gitattributes", ".gitignore", ".gitmodules", "AGENTS.md", "LICENSE", "README.md", "components.toml"}
|
||||
DOMAIN_DIRS = {".gitea", ".woodpecker", "docs", "examples", "scripts", "tests"}
|
||||
DOMAIN_CHILD_KINDS = {"stdlib", "extension", "tool"}
|
||||
AUTHORITY = "https://git.cflmy.cn/cflmy"
|
||||
ENTRY = r"(?:[a-zA-Z0-9_-]+/)*[a-zA-Z0-9_-][a-zA-Z0-9_.-]*"
|
||||
|
||||
|
||||
def git(*args, cwd=ROOT):
|
||||
return subprocess.check_output(["git", "-C", str(cwd), *args]).decode()
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
if not condition:
|
||||
raise ValueError(message)
|
||||
|
||||
|
||||
def nfc(value):
|
||||
return unicodedata.normalize("NFC", value)
|
||||
|
||||
|
||||
class Layer:
|
||||
"""One governance level: the root tree or one expanded domain aggregate."""
|
||||
|
||||
def __init__(self, repo, revision, label, depth, order, components, gitlinks, linked, urls):
|
||||
self.repo = Path(repo)
|
||||
self.revision = revision
|
||||
self.label = label
|
||||
self.depth = depth
|
||||
self.order = order
|
||||
self.components = components
|
||||
self.gitlinks = gitlinks
|
||||
self.linked = linked
|
||||
self.urls = urls
|
||||
|
||||
|
||||
def read_blob(repo, revision, path, label):
|
||||
try:
|
||||
return git("show", f"{revision}:{path}", cwd=repo)
|
||||
except subprocess.CalledProcessError:
|
||||
return None
|
||||
|
||||
|
||||
def check_relative_path(path, id, label):
|
||||
require(isinstance(path, str) and path, f"{label}: invalid path for {id}: {path!r}")
|
||||
require("\\" not in path and not path.startswith("/") and not path.endswith("/"),
|
||||
f"{label}: invalid path for {id}: {path!r}")
|
||||
segments = path.split("/")
|
||||
require(all(segment and segment not in {".", ".."} for segment in segments),
|
||||
f"{label}: invalid path for {id}: {path!r}")
|
||||
require(all(re.fullmatch(NAME, segment) for segment in segments),
|
||||
f"{label}: invalid path for {id}: {path!r}")
|
||||
require(nfc(path) == path, f"{label}: non-NFC path for {id}: {path!r}")
|
||||
return path
|
||||
|
||||
|
||||
def expected_root_path(component):
|
||||
kind = component["kind"]
|
||||
id = component["id"]
|
||||
if kind == "core":
|
||||
return "cli" if id == "cli" else None
|
||||
if kind == "test":
|
||||
return "tests/conformance" if id == "conformance" else None
|
||||
if kind == "stdlib":
|
||||
return f"stdlib/{id.removeprefix('std-')}" if id.startswith("std-") else None
|
||||
if kind == "extension":
|
||||
return f"extensions/{id}"
|
||||
if kind == "tool":
|
||||
return f"tools/{id}"
|
||||
if kind == "domain":
|
||||
return "stdlib" if id == "stdlib" else f"extensions/{id}"
|
||||
return None
|
||||
|
||||
|
||||
def expected_remote(component, depth):
|
||||
"""Derive the single approved self-hosted HTTPS remote for a component.
|
||||
|
||||
Root direct components keep their historical ``marqdo-<id>`` /
|
||||
``marqdo-ext-<id>`` / ``marqdo-extension-conformance`` repository names.
|
||||
Components registered by a domain aggregate are independently named
|
||||
``marqdo-<id>`` (for example ``marqdo-web-design``).
|
||||
"""
|
||||
id = component["id"]
|
||||
kind = component["kind"]
|
||||
if depth == 0:
|
||||
if kind == "test":
|
||||
name = "extension-conformance"
|
||||
elif kind == "extension":
|
||||
name = f"ext-{id}"
|
||||
elif kind == "domain":
|
||||
name = "stdlib" if id == "stdlib" else f"ext-{id}"
|
||||
else:
|
||||
name = id
|
||||
else:
|
||||
name = id
|
||||
return f"{AUTHORITY}/marqdo-{name}.git"
|
||||
|
||||
|
||||
def check_component(raw, depth, label, by_id, paths, path_keys):
|
||||
require(isinstance(raw, dict), f"{label}: invalid component entry: {raw!r}")
|
||||
id = raw.get("id")
|
||||
state = raw.get("state")
|
||||
require(state in {"active", "planned"}, f"{label}: invalid state: {id!r}")
|
||||
fields = FIELDS | ({"entry"} if state == "active" else set())
|
||||
require(set(raw) == fields, f"{label}: invalid fields for {id!r}: {sorted(set(raw) ^ fields)}")
|
||||
require(isinstance(id, str) and re.fullmatch(NAME, id), f"{label}: invalid id: {id!r}")
|
||||
|
||||
for key in ("requires", "checks_with"):
|
||||
items = raw[key]
|
||||
require(isinstance(items, list) and all(isinstance(item, str) for item in items),
|
||||
f"{label}: invalid {key}: {id}")
|
||||
require(id not in items and len(set(items)) == len(items), f"{label}: invalid {key}: {id}")
|
||||
|
||||
kind = raw["kind"]
|
||||
require(kind in RELEASE_ROLES or kind == "domain", f"{label}: unknown kind: {id}: {kind!r}")
|
||||
if kind == "domain":
|
||||
require(depth == 0, f"{label}: domain kind is only allowed at the root layer: {id}")
|
||||
require(raw["release"] in DOMAIN_RELEASE, f"{label}: invalid release role: {id}")
|
||||
require(raw["requires"] == [], f"{label}: domain requires must be empty: {id}")
|
||||
else:
|
||||
require(depth == 0 or kind in DOMAIN_CHILD_KINDS,
|
||||
f"{label}: component kind is not allowed inside a domain: {id} ({kind})")
|
||||
require(raw["release"] == RELEASE_ROLES[kind], f"{label}: invalid release role: {id}")
|
||||
|
||||
path = check_relative_path(raw["path"], id, label)
|
||||
if depth == 0:
|
||||
expected = expected_root_path(raw)
|
||||
require(expected is not None and path == expected,
|
||||
f"{label}: invalid path: {id}: {path} (expected {expected})")
|
||||
require(path not in paths, f"{label}: invalid or duplicate path: {path}")
|
||||
key = nfc(path).casefold()
|
||||
require(key not in path_keys, f"{label}: path case/NFC conflict: {id}: {path}")
|
||||
for other in paths:
|
||||
require(not path.startswith(other + "/") and not other.startswith(path + "/"),
|
||||
f"{label}: overlapping component path: {path} / {other}")
|
||||
|
||||
for key in ("owner", "scope"):
|
||||
require(isinstance(raw[key], str) and raw[key].strip(), f"{label}: missing {key}: {id}")
|
||||
if state == "active":
|
||||
require(isinstance(raw["entry"], str) and re.fullmatch(ENTRY, raw["entry"]),
|
||||
f"{label}: unsafe entry: {id}")
|
||||
|
||||
paths.add(path)
|
||||
path_keys.add(key)
|
||||
by_id[id] = raw
|
||||
return raw
|
||||
|
||||
|
||||
def parse_catalog(repo, revision, label):
|
||||
text = read_blob(repo, revision, "components.toml", label)
|
||||
require(text is not None, f"{label}: missing components.toml at {revision}")
|
||||
try:
|
||||
data = tomllib.loads(text)
|
||||
except tomllib.TOMLDecodeError as error:
|
||||
raise ValueError(f"{label}: invalid components.toml: {error}") from None
|
||||
require(set(data) == {"component"} and isinstance(data["component"], list), f"{label}: invalid catalog")
|
||||
return data["component"]
|
||||
|
||||
|
||||
def tree_entries(repo, revision, label):
|
||||
try:
|
||||
output = git("ls-tree", "-rz", "--full-tree", revision, cwd=repo)
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(f"{label}: missing Git tree at {revision}") from None
|
||||
entries = {}
|
||||
for record in output.split("\0"):
|
||||
if record:
|
||||
metadata, path = record.split("\t", 1)
|
||||
mode, _, sha = metadata.split()
|
||||
entries[path] = (mode, sha)
|
||||
return entries
|
||||
|
||||
|
||||
def check_root_tree(entries, linked, unlinked, label):
|
||||
allowed_readmes = CATEGORY_READMES | {
|
||||
f'{item["path"]}/README.md'
|
||||
for item in unlinked
|
||||
if item["kind"] in {"stdlib", "extension", "domain"}
|
||||
}
|
||||
for path, (mode, _) in entries.items():
|
||||
root = path.split("/", 1)[0]
|
||||
require(
|
||||
path in linked or (mode == "100644" and path in allowed_readmes)
|
||||
or (mode in {"100644", "100755"} and (
|
||||
path in ROOT_FILES or root in ROOT_DIRS and "/" in path or path.startswith("tests/integration/")
|
||||
)),
|
||||
f"{label}: unexpected tracked path or mode: {path} ({mode})",
|
||||
)
|
||||
|
||||
|
||||
def check_domain_tree(entries, linked, unlinked, label):
|
||||
"""Aggregate layers only carry governance, docs, examples and tests.
|
||||
|
||||
Production implementations stay in the child repositories: an aggregate
|
||||
may not add a renderer, parser or driver under its own tree.
|
||||
"""
|
||||
allowed_readmes = {f'{item["path"]}/README.md' for item in unlinked}
|
||||
for path, (mode, _) in entries.items():
|
||||
if path in linked:
|
||||
continue
|
||||
if mode == "100644" and path in allowed_readmes:
|
||||
continue
|
||||
top = path.split("/", 1)[0]
|
||||
top_level_doc = mode == "100644" and "/" not in path and path.endswith(".md")
|
||||
require(
|
||||
mode in {"100644", "100755"} and (
|
||||
path in DOMAIN_FILES or top_level_doc or (top in DOMAIN_DIRS and "/" in path)
|
||||
),
|
||||
f"{label}: unexpected aggregate tracked path or mode: {path} ({mode})",
|
||||
)
|
||||
|
||||
|
||||
def read_submodules(repo, revision, label):
|
||||
if read_blob(repo, revision, ".gitmodules", label) is None:
|
||||
return {}
|
||||
try:
|
||||
output = git("config", "--null", "--blob", f"{revision}:.gitmodules", "--list", cwd=repo)
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(f"{label}: invalid .gitmodules") from None
|
||||
config = {}
|
||||
for record in output.split("\0"):
|
||||
if record:
|
||||
key, value = record.split("\n", 1)
|
||||
require(key not in config, f"{label}: duplicate submodule setting: {key}")
|
||||
config[key] = value
|
||||
return config
|
||||
|
||||
|
||||
def check_submodules(config, linked, depth, label, urls):
|
||||
"""Match ``.gitmodules`` sections by ``path``, not by section name.
|
||||
|
||||
Git configuration keys are keyed by the submodule section name, which is
|
||||
not required to equal the checked-out path. Path and URL remain the
|
||||
authority for identity; any other setting (for example an ``update``
|
||||
command or a relative override) is rejected as unexpected.
|
||||
"""
|
||||
sections = {}
|
||||
extras = []
|
||||
for key, value in config.items():
|
||||
match = re.fullmatch(r"submodule\.(.+)\.(path|url)", key)
|
||||
if not match:
|
||||
extras.append(key)
|
||||
continue
|
||||
name, field = match.groups()
|
||||
sections.setdefault(name, {})[field] = value
|
||||
by_path = {}
|
||||
for name, fields in sections.items():
|
||||
require(set(fields) == {"path", "url"},
|
||||
f"{label}: unexpected submodule settings: "
|
||||
f"{sorted(f'submodule.{name}.{field}' for field in set(fields) ^ {'path', 'url'})}")
|
||||
path = fields["path"]
|
||||
require(path not in by_path, f"{label}: duplicate submodule path: {path}")
|
||||
by_path[path] = fields["url"]
|
||||
require(not extras, f"{label}: unexpected submodule settings: {sorted(extras)}")
|
||||
for path, component in linked.items():
|
||||
require(path in by_path, f"{label}: missing or invalid submodule path: {path}")
|
||||
url = by_path.pop(path)
|
||||
expected = expected_remote(component, depth)
|
||||
require(url == expected, f"{label}: invalid submodule URL: {path}: {url!r}")
|
||||
require(url not in urls, f"{label}: duplicate submodule remote: {path}: {url}")
|
||||
urls[url] = path
|
||||
require(not by_path, f"{label}: unexpected submodule settings: {sorted(by_path)}")
|
||||
|
||||
|
||||
def read_layer(repo, revision, label, depth):
|
||||
repo = Path(repo)
|
||||
order = []
|
||||
components = {}
|
||||
paths = set()
|
||||
path_keys = set()
|
||||
for raw in parse_catalog(repo, revision, label):
|
||||
order.append(check_component(raw, depth, label, components, paths, path_keys))
|
||||
entries = tree_entries(repo, revision, label)
|
||||
gitlinks = {path: sha for path, (mode, sha) in entries.items() if mode == "160000"}
|
||||
active_paths = {item["path"] for item in order if item["state"] == "active"}
|
||||
mismatch = (active_paths - gitlinks.keys()) | (gitlinks.keys() - paths)
|
||||
require(not mismatch, f"{label}: gitlink/catalog mismatch: {sorted(mismatch)}")
|
||||
linked = {item["path"]: item for item in order if item["path"] in gitlinks}
|
||||
unlinked = [item for item in order if item["path"] not in gitlinks]
|
||||
if depth == 0:
|
||||
check_root_tree(entries, linked, unlinked, label)
|
||||
else:
|
||||
check_domain_tree(entries, linked, unlinked, label)
|
||||
urls = {}
|
||||
check_submodules(read_submodules(repo, revision, label), linked, depth, label, urls)
|
||||
return Layer(repo, revision, label, depth, order, components, gitlinks, linked, urls)
|
||||
|
||||
|
||||
def verify_checkout(layer, component):
|
||||
path = component["path"]
|
||||
checkout = layer.repo / path
|
||||
sha = layer.gitlinks[path]
|
||||
require(checkout.resolve() == checkout and (checkout / ".git").exists(),
|
||||
f"{layer.label}: missing submodule checkout: {path}")
|
||||
try:
|
||||
git("cat-file", "-e", f"{sha}^{{commit}}", cwd=checkout)
|
||||
except subprocess.CalledProcessError:
|
||||
raise ValueError(f"{layer.label}: missing committed object: {path}@{sha}") from None
|
||||
require(git("rev-parse", "HEAD", cwd=checkout).strip() == sha,
|
||||
f"{layer.label}: wrong checked-out commit: {path}")
|
||||
status = ["status", "--porcelain"]
|
||||
if component["kind"] == "domain":
|
||||
# Child dirt is the responsibility of the child checkout and is
|
||||
# reported by its own leaf check, not by the aggregate repository.
|
||||
status.append("--ignore-submodules=all")
|
||||
require(not git(*status, cwd=checkout),
|
||||
f"{layer.label}: dirty submodule: {path}")
|
||||
if component["state"] == "active":
|
||||
entry = checkout / component["entry"]
|
||||
require(entry.is_file() and entry.resolve() == entry,
|
||||
f"{layer.label}: missing or symbolic entry: {path}/{component['entry']}")
|
||||
return checkout
|
||||
|
||||
|
||||
def verify_leaf(layer, component):
|
||||
checkout = verify_checkout(layer, component)
|
||||
sha = layer.gitlinks[component["path"]]
|
||||
label = f'{layer.label} leaf {component["id"]} ({component["path"]})'
|
||||
nested = tree_entries(checkout, sha, label)
|
||||
gitlinks = sorted(path for path, (mode, _) in nested.items() if mode == "160000")
|
||||
require(not gitlinks, f"{label}: leaf must not register gitlinks: {gitlinks}")
|
||||
|
||||
|
||||
def validate_graph(layers):
|
||||
components = {}
|
||||
for layer in layers:
|
||||
for component in layer.order:
|
||||
id = component["id"]
|
||||
require(id not in components, f"{layer.label}: duplicate global id: {id}")
|
||||
components[id] = (component, layer)
|
||||
remotes = {}
|
||||
for layer in layers:
|
||||
for url, path in layer.urls.items():
|
||||
require(url not in remotes, f"{layer.label}: duplicate global remote: {path}: {url}")
|
||||
remotes[url] = path
|
||||
for layer in layers:
|
||||
for component in layer.order:
|
||||
id = component["id"]
|
||||
for field in ("requires", "checks_with"):
|
||||
for dependency in component[field]:
|
||||
require(dependency in components, f"{layer.label}: unknown dependency: {id} -> {dependency}")
|
||||
target, _ = components[dependency]
|
||||
require(component["state"] != "active" or target["state"] == "active",
|
||||
f"{layer.label}: active depends on planned: {id} -> {dependency}")
|
||||
if field != "requires":
|
||||
continue
|
||||
target_kind = target["kind"]
|
||||
source_kind = component["kind"]
|
||||
require(target_kind != "domain",
|
||||
f"{layer.label}: requires must not target a domain: {id} -> {dependency}")
|
||||
if source_kind in {"core", "domain"}:
|
||||
require(False, f"{layer.label}: dependency violation: {id} must not require {dependency}")
|
||||
if source_kind == "stdlib":
|
||||
require(target_kind in {"core", "stdlib"},
|
||||
f"{layer.label}: stdlib dependency violation: {id} -> {dependency}")
|
||||
elif source_kind == "tool":
|
||||
require(target_kind in {"core", "extension"},
|
||||
f"{layer.label}: tool dependency violation: {id} -> {dependency}")
|
||||
elif source_kind == "extension":
|
||||
require(target_kind in {"core", "stdlib", "extension"},
|
||||
f"{layer.label}: extension dependency violation: {id} -> {dependency}")
|
||||
try:
|
||||
graph = {id: list(item["requires"]) for id, (item, _) in components.items()}
|
||||
tuple(graphlib.TopologicalSorter(graph).static_order())
|
||||
except graphlib.CycleError as error:
|
||||
raise ValueError(f"root: requires DAG cycle: {error}") from None
|
||||
|
||||
|
||||
def validate(revision, checkouts, expand_domains=False):
|
||||
layers = [read_layer(ROOT, revision, "root", 0)]
|
||||
if checkouts or expand_domains:
|
||||
root = layers[0]
|
||||
for path, component in root.linked.items():
|
||||
if component["kind"] != "domain":
|
||||
if checkouts:
|
||||
verify_leaf(root, component)
|
||||
continue
|
||||
domain_repo = verify_checkout(root, component)
|
||||
domain = read_layer(domain_repo, root.gitlinks[path],
|
||||
f"domain {component['id']} ({path})", 1)
|
||||
layers.append(domain)
|
||||
if checkouts:
|
||||
for child in domain.linked.values():
|
||||
verify_leaf(domain, child)
|
||||
validate_graph(layers)
|
||||
return layers
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Validate a Marqdo ecosystem Git tree")
|
||||
parser.add_argument("revision", nargs="?", default="HEAD")
|
||||
parser.add_argument("--checkouts", action="store_true")
|
||||
paths = parser.add_mutually_exclusive_group()
|
||||
paths.add_argument("--active-paths", action="store_true", help="print only direct active component paths")
|
||||
paths.add_argument("--domain-paths", action="store_true", help="validate domain URLs and print domain paths")
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
revision = git("rev-parse", "--verify", args.revision + "^{commit}").strip()
|
||||
layers = validate(revision, args.checkouts, expand_domains=args.domain_paths)
|
||||
if args.active_paths:
|
||||
for path, component in sorted(layers[0].linked.items()):
|
||||
if component["state"] == "active":
|
||||
print(path)
|
||||
elif args.domain_paths:
|
||||
for path, component in sorted(layers[0].linked.items()):
|
||||
if component["kind"] == "domain":
|
||||
print(path)
|
||||
else:
|
||||
for layer in layers:
|
||||
for path, component in sorted(layer.linked.items()):
|
||||
relative = (layer.repo / path).relative_to(ROOT).as_posix()
|
||||
print(f'{component["id"]} {relative} {layer.gitlinks[path]} {component["state"]}')
|
||||
except (AttributeError, KeyError, OSError, subprocess.CalledProcessError, TypeError, ValueError) as error:
|
||||
sys.exit(f"layout: {error}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Executable
+423
@@ -0,0 +1,423 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Recursive impact analysis between an accepted root commit and a candidate.
|
||||
|
||||
Compares the recursively expanded governance tree of two root revisions. A
|
||||
component identity is `(global_id, parent, remote, SHA, state)`; a domain
|
||||
gitlink change is expanded to its child identities so leaf changes are visible
|
||||
even when the parent pointer did not change as a string.
|
||||
|
||||
The affected set is computed in the order the development contract requires:
|
||||
|
||||
1. changed or removed leaves;
|
||||
2. reverse transitive closure over `requires` edges from the union of both
|
||||
graphs (removed edges cannot hide a consumer);
|
||||
3. parent domains of affected components;
|
||||
4. `checks_with` fixed point (co-validation is not a build prerequisite).
|
||||
|
||||
When a domain cannot be expanded (missing object/checkout) the result is marked
|
||||
UNVERIFIED and the whole domain is treated as affected rather than silently
|
||||
skipping it.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
import tomllib
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
SCHEMA = "marqdo.impact"
|
||||
SCHEMA_VERSION = 1
|
||||
|
||||
|
||||
class ImpactError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def git(repo: Path, *args: str) -> bytes:
|
||||
result = subprocess.run(["git", "-C", str(repo), *args], capture_output=True)
|
||||
if result.returncode != 0:
|
||||
raise ImpactError(
|
||||
f"git {' '.join(args)} failed in {repo}: "
|
||||
f"{result.stderr.decode(errors='replace').strip()}"
|
||||
)
|
||||
return result.stdout
|
||||
|
||||
|
||||
def show(repo: Path, revision: str, path: str) -> bytes | None:
|
||||
result = subprocess.run(
|
||||
["git", "-C", str(repo), "show", f"{revision}:{path}"], capture_output=True
|
||||
)
|
||||
return result.stdout if result.returncode == 0 else None
|
||||
|
||||
|
||||
def resolve(repo: Path, revision: str) -> str:
|
||||
try:
|
||||
return (
|
||||
git(repo, "rev-parse", "--verify", revision + "^{commit}")
|
||||
.decode()
|
||||
.strip()
|
||||
)
|
||||
except ImpactError as error:
|
||||
raise ImpactError(f"cannot resolve revision {revision!r}: {error}") from error
|
||||
|
||||
|
||||
def tree_entries(repo: Path, revision: str) -> dict[str, tuple[str, str]]:
|
||||
output = git(repo, "ls-tree", "-r", "-z", revision)
|
||||
entries: dict[str, tuple[str, str]] = {}
|
||||
for record in output.split(b"\0"):
|
||||
if not record:
|
||||
continue
|
||||
header, _, raw_path = record.partition(b"\t")
|
||||
fields = header.decode().split()
|
||||
if len(fields) != 3:
|
||||
raise ImpactError(f"invalid tree record in {repo}@{revision}")
|
||||
mode, _kind, sha = fields
|
||||
entries[raw_path.decode()] = (mode, sha)
|
||||
return entries
|
||||
|
||||
|
||||
def submodule_urls(repo: Path, revision: str) -> dict[str, str]:
|
||||
"""Map `.gitmodules` path to URL at a revision (authority for remotes)."""
|
||||
raw = show(repo, revision, ".gitmodules")
|
||||
if raw is None:
|
||||
return {}
|
||||
config = git(
|
||||
repo, "config", "--null", "--blob", f"{revision}:.gitmodules", "--list"
|
||||
)
|
||||
urls: dict[str, str] = {}
|
||||
pending: dict[str, dict[str, str]] = {}
|
||||
for record in config.split(b"\0"):
|
||||
if not record:
|
||||
continue
|
||||
key, _, value = record.decode(errors="replace").partition("\n")
|
||||
match = re.fullmatch(r"submodule\.(.+)\.(path|url)", key)
|
||||
if match:
|
||||
name, field = match.groups()
|
||||
pending.setdefault(name, {})[field] = value
|
||||
for fields in pending.values():
|
||||
if "path" in fields and "url" in fields:
|
||||
urls[fields["path"]] = fields["url"]
|
||||
return urls
|
||||
|
||||
|
||||
def read_catalog(repo: Path, revision: str, label: str) -> list[dict]:
|
||||
raw = show(repo, revision, "components.toml")
|
||||
if raw is None:
|
||||
raise ImpactError(f"{label}: revision {revision} has no components.toml")
|
||||
try:
|
||||
catalog = tomllib.loads(raw.decode())
|
||||
except (UnicodeDecodeError, tomllib.TOMLDecodeError) as error:
|
||||
raise ImpactError(f"{label}: invalid components.toml: {error}") from error
|
||||
components = catalog.get("component")
|
||||
if not isinstance(components, list):
|
||||
raise ImpactError(f"{label}: components.toml has no [[component]] entries")
|
||||
return components
|
||||
|
||||
|
||||
def load_graph(
|
||||
repo: Path, revision: str, label: str, depth: int = 0
|
||||
) -> tuple[dict[str, dict], list[str]]:
|
||||
"""Expand one governance layer (root then domains) into global identities."""
|
||||
components = read_catalog(repo, revision, label)
|
||||
entries = tree_entries(repo, revision)
|
||||
urls = submodule_urls(repo, revision)
|
||||
gitlinks = {path: sha for path, (mode, sha) in entries.items() if mode == "160000"}
|
||||
graph: dict[str, dict] = {}
|
||||
unverified: list[str] = []
|
||||
for component in components:
|
||||
component_id = component.get("id")
|
||||
path = component.get("path")
|
||||
if not isinstance(component_id, str) or not isinstance(path, str):
|
||||
raise ImpactError(f"{label}: component without id/path")
|
||||
sha = gitlinks.get(path)
|
||||
identity = {
|
||||
"id": component_id,
|
||||
"parent": None,
|
||||
"path": path,
|
||||
"remote": urls.get(path),
|
||||
"sha": sha,
|
||||
"state": component.get("state"),
|
||||
"kind": component.get("kind"),
|
||||
"requires": sorted(component.get("requires", [])),
|
||||
"checks_with": sorted(component.get("checks_with", [])),
|
||||
"layer": label,
|
||||
}
|
||||
graph[component_id] = identity
|
||||
if component.get("kind") != "domain" or depth > 0:
|
||||
continue
|
||||
domain_repo = repo / path
|
||||
if sha is None or not (domain_repo / ".git").exists():
|
||||
unverified.append(
|
||||
f"{label}: domain {component_id} ({path}) cannot be expanded: "
|
||||
"missing gitlink or checkout"
|
||||
)
|
||||
continue
|
||||
try:
|
||||
children, child_unverified = load_graph(
|
||||
domain_repo, sha, f"domain {component_id}", depth + 1
|
||||
)
|
||||
except ImpactError as error:
|
||||
unverified.append(
|
||||
f"{label}: domain {component_id} ({path})@{sha} cannot be expanded: {error}"
|
||||
)
|
||||
continue
|
||||
unverified.extend(child_unverified)
|
||||
for child_id, child in children.items():
|
||||
if child_id in graph:
|
||||
raise ImpactError(f"{label}: duplicate global id {child_id}")
|
||||
child["parent"] = component_id
|
||||
graph[child_id] = child
|
||||
return graph, unverified
|
||||
|
||||
|
||||
def identity_fields(component: dict) -> tuple:
|
||||
return (
|
||||
component.get("parent"),
|
||||
component.get("remote"),
|
||||
component.get("sha"),
|
||||
component.get("state"),
|
||||
tuple(component.get("requires", [])),
|
||||
tuple(component.get("checks_with", [])),
|
||||
)
|
||||
|
||||
|
||||
def changed_components(
|
||||
accepted: dict[str, dict], candidate: dict[str, dict]
|
||||
) -> list[dict]:
|
||||
changed = []
|
||||
for component_id in sorted(set(accepted) | set(candidate)):
|
||||
before = accepted.get(component_id)
|
||||
after = candidate.get(component_id)
|
||||
if before is None:
|
||||
changed.append({"id": component_id, "reason": "added"})
|
||||
continue
|
||||
if after is None:
|
||||
changed.append({"id": component_id, "reason": "removed"})
|
||||
continue
|
||||
if before.get("sha") != after.get("sha"):
|
||||
changed.append({"id": component_id, "reason": "sha"})
|
||||
elif before.get("state") != after.get("state"):
|
||||
changed.append({"id": component_id, "reason": "state"})
|
||||
elif before.get("remote") != after.get("remote"):
|
||||
changed.append({"id": component_id, "reason": "remote"})
|
||||
elif before.get("parent") != after.get("parent"):
|
||||
changed.append({"id": component_id, "reason": "parent"})
|
||||
elif before.get("requires") != after.get("requires") or before.get(
|
||||
"checks_with"
|
||||
) != after.get("checks_with"):
|
||||
changed.append({"id": component_id, "reason": "dependencies"})
|
||||
return changed
|
||||
|
||||
|
||||
def affected_set(
|
||||
accepted: dict[str, dict], candidate: dict[str, dict], changed: list[dict]
|
||||
) -> tuple[list[str], list[str], list[str]]:
|
||||
graph = {**accepted, **candidate}
|
||||
dependents: dict[str, set[str]] = {component_id: set() for component_id in graph}
|
||||
for component in graph.values():
|
||||
for dependency in component.get("requires", []):
|
||||
dependents.setdefault(dependency, set()).add(component["id"])
|
||||
affected = {item["id"] for item in changed}
|
||||
queue = list(affected)
|
||||
while queue:
|
||||
current = queue.pop()
|
||||
for consumer in dependents.get(current, set()):
|
||||
if consumer not in affected:
|
||||
affected.add(consumer)
|
||||
queue.append(consumer)
|
||||
domains = set()
|
||||
for component_id in list(affected):
|
||||
parent = graph[component_id].get("parent")
|
||||
while parent:
|
||||
if parent not in affected:
|
||||
domains.add(parent)
|
||||
parent = graph[parent].get("parent") if parent in graph else None
|
||||
co_validation: set[str] = set()
|
||||
while True:
|
||||
additions = set()
|
||||
for component_id in affected:
|
||||
for partner in graph[component_id].get("checks_with", []):
|
||||
if partner not in affected:
|
||||
additions.add(partner)
|
||||
if not additions:
|
||||
break
|
||||
affected |= additions
|
||||
co_validation |= additions
|
||||
return sorted(affected), sorted(domains), sorted(co_validation)
|
||||
|
||||
|
||||
def consumers_of(component_id: str, revision: str) -> dict:
|
||||
"""Consumers of one component at a revision (component-PR impact scope).
|
||||
|
||||
Uses the accepted graph only: a component candidate cannot change the root
|
||||
graph it is evaluated against. Unknown component or unexpandable domain
|
||||
widens the scope to the whole graph (never silently skip).
|
||||
"""
|
||||
revision_sha = resolve(ROOT, revision)
|
||||
graph, unverified = load_graph(ROOT, revision_sha, "root")
|
||||
if component_id not in graph:
|
||||
graph, unverified = load_graph(ROOT, revision_sha, "root")
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"accepted": {"ref": revision, "revision": revision_sha},
|
||||
"component": component_id,
|
||||
"affected": sorted(graph),
|
||||
"checks_with": [],
|
||||
"domain_ancestors": [],
|
||||
"fallback": "full",
|
||||
"unverified": unverified
|
||||
+ [f"unknown component {component_id!r} at {revision_sha}; scope widened"],
|
||||
}
|
||||
dependents: dict[str, set[str]] = {key: set() for key in graph}
|
||||
for component in graph.values():
|
||||
for dependency in component.get("requires", []):
|
||||
dependents.setdefault(dependency, set()).add(component["id"])
|
||||
affected = {component_id}
|
||||
queue = [component_id]
|
||||
while queue:
|
||||
current = queue.pop()
|
||||
for consumer in dependents.get(current, set()):
|
||||
if consumer not in affected:
|
||||
affected.add(consumer)
|
||||
queue.append(consumer)
|
||||
domains = set()
|
||||
for item in list(affected):
|
||||
parent = graph[item].get("parent")
|
||||
while parent:
|
||||
if parent not in affected:
|
||||
domains.add(parent)
|
||||
parent = graph[parent].get("parent") if parent in graph else None
|
||||
co_validation: set[str] = set()
|
||||
while True:
|
||||
additions = {
|
||||
partner
|
||||
for item in affected
|
||||
for partner in graph[item].get("checks_with", [])
|
||||
if partner not in affected
|
||||
}
|
||||
if not additions:
|
||||
break
|
||||
affected |= additions
|
||||
co_validation |= additions
|
||||
fallback = None
|
||||
if unverified:
|
||||
affected = set(graph)
|
||||
domains = set()
|
||||
co_validation = set()
|
||||
fallback = "full"
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"accepted": {"ref": revision, "revision": revision_sha},
|
||||
"component": component_id,
|
||||
"affected": sorted(affected),
|
||||
"checks_with": sorted(co_validation),
|
||||
"domain_ancestors": sorted(domains),
|
||||
"fallback": fallback,
|
||||
"unverified": unverified,
|
||||
}
|
||||
|
||||
|
||||
def analyze(accepted_ref: str, candidate_ref: str) -> dict:
|
||||
accepted_revision = resolve(ROOT, accepted_ref)
|
||||
candidate_revision = resolve(ROOT, candidate_ref)
|
||||
accepted, accepted_unverified = load_graph(ROOT, accepted_revision, "root")
|
||||
candidate, candidate_unverified = load_graph(ROOT, candidate_revision, "root")
|
||||
changed = changed_components(accepted, candidate)
|
||||
affected, domains, co_validation = affected_set(accepted, candidate, changed)
|
||||
unverified = accepted_unverified + candidate_unverified
|
||||
fallback = None
|
||||
if unverified:
|
||||
# Undetermined scope must widen, never silently skip.
|
||||
affected = sorted(set(accepted) | set(candidate))
|
||||
domains = []
|
||||
co_validation = []
|
||||
fallback = "full"
|
||||
return {
|
||||
"schema": SCHEMA,
|
||||
"schema_version": SCHEMA_VERSION,
|
||||
"accepted": {"ref": accepted_ref, "revision": accepted_revision},
|
||||
"candidate": {"ref": candidate_ref, "revision": candidate_revision},
|
||||
"counts": {
|
||||
"accepted_components": len(accepted),
|
||||
"candidate_components": len(candidate),
|
||||
"changed": len(changed),
|
||||
"affected": len(affected),
|
||||
},
|
||||
"changed": changed,
|
||||
"affected": affected,
|
||||
"domain_ancestors": domains,
|
||||
"checks_with": co_validation,
|
||||
"fallback": fallback,
|
||||
"unverified": unverified,
|
||||
}
|
||||
|
||||
|
||||
def main(argv: list[str]) -> int:
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--accepted", required=True, help="accepted root revision")
|
||||
parser.add_argument("--candidate", default="HEAD", help="candidate root revision")
|
||||
parser.add_argument("--out", default=None)
|
||||
parser.add_argument("--json", action="store_true")
|
||||
parser.add_argument(
|
||||
"--component",
|
||||
default=None,
|
||||
help="report consumers of one component at --accepted instead of a root diff",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--fail-on-unverified",
|
||||
action="store_true",
|
||||
help="exit 2 when a domain cannot be expanded",
|
||||
)
|
||||
args = parser.parse_args(argv)
|
||||
try:
|
||||
if args.component:
|
||||
report = consumers_of(args.component, args.accepted)
|
||||
else:
|
||||
report = analyze(args.accepted, args.candidate)
|
||||
except ImpactError as error:
|
||||
print(f"impact: error: {error}", file=sys.stderr)
|
||||
return 1
|
||||
text = json.dumps(report, ensure_ascii=False, indent=2) + "\n"
|
||||
if args.out:
|
||||
Path(args.out).write_text(text)
|
||||
if args.json:
|
||||
print(text, end="")
|
||||
else:
|
||||
if "candidate" in report:
|
||||
print(
|
||||
f"accepted {report['accepted']['revision'][:12]} "
|
||||
f"candidate {report['candidate']['revision'][:12]}"
|
||||
)
|
||||
print(
|
||||
f"changed={report['counts']['changed']} "
|
||||
f"affected={report['counts']['affected']}"
|
||||
)
|
||||
for item in report["changed"]:
|
||||
print(f" changed {item['id']}: {item['reason']}")
|
||||
else:
|
||||
print(
|
||||
f"component {report['component']} at "
|
||||
f"{report['accepted']['revision'][:12]}"
|
||||
)
|
||||
print(f"consumers={len(report['affected'])}")
|
||||
print("affected: " + ", ".join(report["affected"]))
|
||||
if report["checks_with"]:
|
||||
print("co-validation: " + ", ".join(report["checks_with"]))
|
||||
if report["fallback"]:
|
||||
print("fallback: full (impact scope undetermined)")
|
||||
for note in report["unverified"]:
|
||||
print(f"UNVERIFIED: {note}", file=sys.stderr)
|
||||
if args.fail_on_unverified and report["unverified"]:
|
||||
return 2
|
||||
return 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main(sys.argv[1:]))
|
||||
Executable
+188
@@ -0,0 +1,188 @@
|
||||
#!/usr/bin/env bash
|
||||
# Ecosystem integration for one exact candidate combination.
|
||||
#
|
||||
# Inputs are the pinned root gitlinks: the root-owned Bundle producer assembles
|
||||
# the one stdlib Bundle, the CLI/Worker are built from the pinned `cli` commit,
|
||||
# the release archive is packaged with that explicit Bundle, and every consumer
|
||||
# runs against that same installed binary + adjacent Bundle. There is no
|
||||
# implicit artifact from View, no floating branch and no network-selected CLI.
|
||||
set -euo pipefail
|
||||
|
||||
cd "$(dirname "$0")/.."
|
||||
root="$PWD"
|
||||
active="$(python3 scripts/check-layout.py --checkouts --active-paths)"
|
||||
expected=$'cli\nstdlib/collections\nstdlib/data\nstdlib/fs\nstdlib/io\nstdlib/system\nstdlib/text\ntests/conformance\ntools/knowledge\ntools/lint\ntools/prove\ntools/view'
|
||||
if [[ "$active" != "$expected" ]]; then
|
||||
echo "UNVERIFIED: update the integration plan for the changed active component set" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mkdir -p .integration-work
|
||||
work="$(mktemp -d "$root/.integration-work/run.XXXXXX")"
|
||||
echo "integration evidence: $work"
|
||||
exec > >(tee "$work/run.log") 2>&1
|
||||
set -x
|
||||
|
||||
git rev-parse HEAD
|
||||
git submodule status --recursive
|
||||
uname -m
|
||||
ldd --version
|
||||
cargo --version
|
||||
python3 --version
|
||||
python3 -c 'import jsonschema'
|
||||
python3 scripts/check-layout.py --checkouts > "$work/layout.txt"
|
||||
cat "$work/layout.txt"
|
||||
|
||||
# Recursive impact analysis against the accepted root commit: the change set
|
||||
# comes from the recursively expanded (global_id, parent, remote, SHA, state)
|
||||
# identities, then reverse `requires` closure, parent domains and `checks_with`
|
||||
# fixed point. An undetermined scope widens to the full candidate.
|
||||
accepted_ref="${MARQDO_ACCEPTED_REF:-}"
|
||||
if [[ -z "$accepted_ref" && -n "${CI_COMMIT_TARGET_BRANCH:-}" ]] \
|
||||
&& git rev-parse --verify "origin/$CI_COMMIT_TARGET_BRANCH" >/dev/null 2>&1; then
|
||||
accepted_ref="origin/$CI_COMMIT_TARGET_BRANCH"
|
||||
elif [[ -z "$accepted_ref" ]] && git rev-parse --verify origin/main >/dev/null 2>&1; then
|
||||
accepted_ref="origin/main"
|
||||
fi
|
||||
if [[ -n "$accepted_ref" ]]; then
|
||||
python3 scripts/impact.py --accepted "$accepted_ref" --candidate HEAD \
|
||||
--out "$work/impact.json"
|
||||
fi
|
||||
|
||||
# 1. One Bundle, produced by the root-owned producer from the pinned gitlinks.
|
||||
python3 scripts/build-stdlib.py --out "$work/stdlib" | tee "$work/bundle.json"
|
||||
bundle_digest="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["tree_digest"])' < "$work/bundle.json")"
|
||||
bundle_aliases="$(python3 -c 'import json,sys; print(json.load(sys.stdin)["aliases_digest"])' < "$work/bundle.json")"
|
||||
test -f "$work/stdlib/stdlib.json"
|
||||
|
||||
# 2. CLI and Worker from the exact pinned CLI gitlink.
|
||||
source_sha="$(git -C cli rev-parse HEAD)"
|
||||
# The CLI release packager resolves its binaries from the pinned CLI checkout's
|
||||
# own target directory; keep this build there so the package step consumes the
|
||||
# same artifacts without a second build. Do not export CARGO_TARGET_DIR: the
|
||||
# consumer repositories build into their own target directories.
|
||||
CARGO_TARGET_DIR="$root/cli/target" \
|
||||
cargo build --manifest-path cli/Cargo.toml --locked --release \
|
||||
-p marqdo-cli -p marqdo-provider-worker
|
||||
version="$(python3 -c '
|
||||
import pathlib, tomllib
|
||||
data = tomllib.loads(pathlib.Path("cli/Cargo.toml").read_text())
|
||||
print(data["workspace"]["package"]["version"])
|
||||
')"
|
||||
|
||||
# 3. The release archive takes the Bundle as one explicit input.
|
||||
python3 cli/tools/release/package.py \
|
||||
--source-sha "$source_sha" --version "$version" \
|
||||
--stdlib-dir "$work/stdlib" --out-dir "$work/dist" | tee "$work/package.json"
|
||||
archive="$(find "$work/dist" -maxdepth 1 -name 'marqdo-*.tar.gz' -print -quit)"
|
||||
python3 cli/tools/release/smoke.py --archive "$archive"
|
||||
mkdir -p "$work/install"
|
||||
tar -xzf "$archive" -C "$work/install"
|
||||
installed="$(find "$work/install" -mindepth 1 -maxdepth 1 -type d -print -quit)"
|
||||
MARQDO_BIN="$installed/marqdo"
|
||||
export MARQDO_BIN
|
||||
test "$(cat "$installed/SOURCE_SHA")" = "$source_sha"
|
||||
test "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$installed/stdlib/stdlib.json")" = "$(python3 -c 'import json,sys; print(json.load(open(sys.argv[1]))["version"])' "$work/stdlib/stdlib.json")"
|
||||
sha256sum "$archive" "$MARQDO_BIN" "$installed/marqdo-provider-worker"
|
||||
|
||||
# 4. Root stdlib acceptance: component entries, explicit Packages, composition
|
||||
# fixtures and fail-closed negatives with the same installed CLI/Bundle.
|
||||
python3 scripts/acceptance-stdlib.py \
|
||||
--cli "$MARQDO_BIN" --bundle "$work/stdlib" \
|
||||
--work "$work/stdlib-acceptance" --evidence "$work/stdlib-acceptance.json"
|
||||
|
||||
# 5. Frozen independent public-contract fixtures against the same CLI.
|
||||
python3 cli/tools/ci/verify_extension_contracts.py \
|
||||
--source-repo cli --tested-sha "$source_sha" --cli "$MARQDO_BIN" \
|
||||
--release-info "$installed/RELEASE_INFO.json" \
|
||||
--fixtures tests/conformance --out "$work/conformance.json"
|
||||
|
||||
# 6. Existing consumers, same installed binary and adjacent Bundle.
|
||||
(
|
||||
cd tools/view
|
||||
export MARQDO_TOOL_HOME="$work/view-registry"
|
||||
scripts/package.sh
|
||||
"$MARQDO_BIN" tool install dist/marqdo-view/tool.json
|
||||
"$MARQDO_BIN" view verify examples/mixed-modes/index.mq.md
|
||||
"$MARQDO_BIN" view export examples/tables-math --out "$work/view-export"
|
||||
setsid "$MARQDO_BIN" view examples/control-flow --port 0 --no-open >"$work/view-server.log" 2>&1 &
|
||||
view_pid=$!
|
||||
stop_view() {
|
||||
kill -- "-$view_pid" 2>/dev/null || true
|
||||
wait "$view_pid" 2>/dev/null || true
|
||||
}
|
||||
trap stop_view EXIT
|
||||
view_url=""
|
||||
for attempt in {1..100}; do
|
||||
view_url="$(grep -m1 -o 'http://127\.0\.0\.1:[0-9]\+/' "$work/view-server.log" || true)"
|
||||
if [[ -n "$view_url" ]] || ! kill -0 "$view_pid" 2>/dev/null; then
|
||||
break
|
||||
fi
|
||||
sleep 0.1
|
||||
done
|
||||
if [[ -z "$view_url" ]]; then
|
||||
cat "$work/view-server.log" >&2
|
||||
exit 1
|
||||
fi
|
||||
python3 scripts/acceptance-run.py "$view_url"
|
||||
stop_view
|
||||
trap - EXIT
|
||||
python3 scripts/check-observation.py stream-snapshot
|
||||
"$MARQDO_BIN" tool remove view
|
||||
if "$MARQDO_BIN" view --version; then
|
||||
echo "view still dispatches after removal" >&2
|
||||
exit 1
|
||||
fi
|
||||
)
|
||||
(
|
||||
cd tools/knowledge
|
||||
MARQDO_TEST_BIN="$MARQDO_BIN" cargo test --locked --test core_cli --test compile
|
||||
)
|
||||
(
|
||||
cd tools/prove
|
||||
cargo test --locked --test analysis_document --test document_contract
|
||||
)
|
||||
(
|
||||
cd tools/lint
|
||||
export MARQDO_TOOL_HOME="$work/lint-registry"
|
||||
scripts/package-tool.sh "$work/lint"
|
||||
"$MARQDO_BIN" tool install "$work/lint/tool.json"
|
||||
"$MARQDO_BIN" lint examples/nested/inventory.mq.md --format json
|
||||
"$MARQDO_BIN" tool remove lint
|
||||
)
|
||||
|
||||
# 7. Evidence identity for the accepted candidate.
|
||||
root_commit="$(git rev-parse HEAD)"
|
||||
python3 - "$work" "$root_commit" "$source_sha" "$bundle_digest" "$bundle_aliases" "$archive" <<'PY'
|
||||
import hashlib, json, pathlib, sys
|
||||
work = pathlib.Path(sys.argv[1])
|
||||
archive = pathlib.Path(sys.argv[6])
|
||||
impact_path = work / "impact.json"
|
||||
impact = json.loads(impact_path.read_text()) if impact_path.is_file() else None
|
||||
evidence = {
|
||||
"schema": "marqdo.ecosystem-integration",
|
||||
"schema_version": 1,
|
||||
"root_commit": sys.argv[2],
|
||||
"cli_source_sha": sys.argv[3],
|
||||
"stdlib_tree_digest": sys.argv[4],
|
||||
"stdlib_aliases_digest": sys.argv[5],
|
||||
"archive": archive.name,
|
||||
"archive_sha256": "sha256:" + hashlib.sha256(archive.read_bytes()).hexdigest(),
|
||||
"impact": (
|
||||
{
|
||||
"changed": impact["changed"],
|
||||
"affected": impact["affected"],
|
||||
"checks_with": impact["checks_with"],
|
||||
"fallback": impact["fallback"],
|
||||
"unverified": impact["unverified"],
|
||||
}
|
||||
if impact
|
||||
else None
|
||||
),
|
||||
"status": "PASS",
|
||||
}
|
||||
(work / "integration-evidence.json").write_text(json.dumps(evidence, indent=2) + "\n")
|
||||
print(json.dumps(evidence, indent=2))
|
||||
PY
|
||||
|
||||
echo "PASS: ecosystem candidate (single CLI/Worker/Bundle artifact, consumers green)"
|
||||
@@ -1,149 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""Create a GitHub release from Cargo.toml version and upload Windows binaries."""
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
import re
|
||||
import subprocess
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
from pathlib import Path
|
||||
|
||||
REPO = "cflmy/marqdo"
|
||||
|
||||
|
||||
def crate_version() -> str:
|
||||
text = Path("Cargo.toml").read_text(encoding="utf-8")
|
||||
m = re.search(r'(?m)^version\s*=\s*"([^"]+)"', text)
|
||||
if not m:
|
||||
raise SystemExit("version not found in Cargo.toml")
|
||||
return m.group(1)
|
||||
|
||||
|
||||
def git_token() -> str:
|
||||
proc = subprocess.run(
|
||||
["git", "credential", "fill"],
|
||||
input="protocol=https\nhost=github.com\n\n",
|
||||
text=True,
|
||||
capture_output=True,
|
||||
check=True,
|
||||
)
|
||||
for line in proc.stdout.splitlines():
|
||||
if line.startswith("password="):
|
||||
return line[len("password=") :]
|
||||
raise SystemExit("no github password from git credential fill")
|
||||
|
||||
|
||||
def api(method: str, url: str, token: str, data: bytes | None = None, content_type: str | None = None):
|
||||
req = urllib.request.Request(url, data=data, method=method)
|
||||
req.add_header("Accept", "application/vnd.github+json")
|
||||
req.add_header("Authorization", f"Bearer {token}")
|
||||
req.add_header("X-GitHub-Api-Version", "2022-11-28")
|
||||
req.add_header("User-Agent", "marqdo-release-script")
|
||||
if content_type:
|
||||
req.add_header("Content-Type", content_type)
|
||||
try:
|
||||
with urllib.request.urlopen(req) as resp:
|
||||
body = resp.read()
|
||||
return resp.status, json.loads(body.decode()) if body else {}
|
||||
except urllib.error.HTTPError as e:
|
||||
err = e.read().decode("utf-8", errors="replace")
|
||||
raise SystemExit(f"HTTP {e.code} {url}: {err}") from e
|
||||
|
||||
|
||||
def main() -> None:
|
||||
ver = crate_version()
|
||||
tag = f"v{ver}"
|
||||
stem = f"marqdo-{ver}-x86_64-pc-windows-msvc"
|
||||
assets = [
|
||||
Path(f"target/dist/{stem}.exe"),
|
||||
Path(f"target/dist/{stem}.zip"),
|
||||
]
|
||||
for p in assets:
|
||||
if not p.exists():
|
||||
raise SystemExit(f"missing asset: {p}")
|
||||
|
||||
notes = f"""## Marqdo {tag}
|
||||
|
||||
### Highlights
|
||||
- Function body end via `---` / `***` or empty `****` return
|
||||
- Blank-line paragraph comments (lex + view rendering)
|
||||
- Brand logo / favicon from s3.cflmy.cn
|
||||
- Welcome docs and call-arg spaced named values
|
||||
|
||||
### Assets
|
||||
- `{stem}.exe` — Windows x64 binary
|
||||
- `{stem}.zip` — same binary zipped
|
||||
|
||||
```text
|
||||
marqdo --version
|
||||
marqdo run public/00-welcome.mq.md
|
||||
marqdo view public
|
||||
```
|
||||
"""
|
||||
|
||||
token = git_token()
|
||||
|
||||
existing = None
|
||||
try:
|
||||
_, existing = api(
|
||||
"GET",
|
||||
f"https://api.github.com/repos/{REPO}/releases/tags/{tag}",
|
||||
token,
|
||||
)
|
||||
except SystemExit as e:
|
||||
if "404" not in str(e):
|
||||
raise
|
||||
|
||||
if existing:
|
||||
release_id = existing["id"]
|
||||
upload_url = existing["upload_url"].split("{", 1)[0]
|
||||
print(f"reuse release id={release_id}")
|
||||
else:
|
||||
payload = json.dumps(
|
||||
{
|
||||
"tag_name": tag,
|
||||
"name": tag,
|
||||
"body": notes,
|
||||
"draft": False,
|
||||
"prerelease": False,
|
||||
}
|
||||
).encode("utf-8")
|
||||
_, created = api(
|
||||
"POST",
|
||||
f"https://api.github.com/repos/{REPO}/releases",
|
||||
token,
|
||||
data=payload,
|
||||
content_type="application/json",
|
||||
)
|
||||
release_id = created["id"]
|
||||
upload_url = created["upload_url"].split("{", 1)[0]
|
||||
print(f"created release id={release_id}")
|
||||
|
||||
_, rel = api(
|
||||
"GET",
|
||||
f"https://api.github.com/repos/{REPO}/releases/{release_id}",
|
||||
token,
|
||||
)
|
||||
want = {p.name for p in assets}
|
||||
for asset in rel.get("assets", []):
|
||||
if asset["name"] in want:
|
||||
api(
|
||||
"DELETE",
|
||||
f"https://api.github.com/repos/{REPO}/releases/assets/{asset['id']}",
|
||||
token,
|
||||
)
|
||||
print(f"deleted old asset {asset['name']}")
|
||||
|
||||
for path in assets:
|
||||
data = path.read_bytes()
|
||||
url = f"{upload_url}?name={path.name}"
|
||||
ctype = "application/zip" if path.suffix == ".zip" else "application/octet-stream"
|
||||
_, uploaded = api("POST", url, token, data=data, content_type=ctype)
|
||||
print(f"uploaded {path.name} -> {uploaded.get('browser_download_url')}")
|
||||
|
||||
print(f"OK https://github.com/{REPO}/releases/tag/{tag}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "marqdo-stdlib",
|
||||
"version": "0.2.0",
|
||||
"public_aliases": [
|
||||
{
|
||||
"public_names": ["print", "打印"],
|
||||
"target_module": "io.mq.md",
|
||||
"target_function": "写值",
|
||||
"expected_signature": "params(值)",
|
||||
"effects": ["host"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
.venv/
|
||||
__pycache__/
|
||||
*.pyc
|
||||
.pytest_cache/
|
||||
@@ -1,14 +0,0 @@
|
||||
# Marqdo Spike(Python)
|
||||
|
||||
快速验收 ADR 0001 中的 S1–S5,**不是**完整解释器。
|
||||
|
||||
```bash
|
||||
cd spike
|
||||
python -m venv .venv
|
||||
# Windows:
|
||||
.\.venv\Scripts\activate
|
||||
pip install -r requirements.txt
|
||||
pytest -q
|
||||
```
|
||||
|
||||
若需代理:`pip install -r requirements.txt --proxy http://127.0.0.1:7897`
|
||||
@@ -1,35 +0,0 @@
|
||||
# Spike 报告:Python + markdown-it-py(S1–S5)
|
||||
|
||||
| | |
|
||||
|---|---|
|
||||
| 日期 | 2026-08-04 |
|
||||
| 状态 | **通过** |
|
||||
| 命令 | `cd spike && pytest -q` → `6 passed` |
|
||||
|
||||
---
|
||||
|
||||
## 结果
|
||||
|
||||
| ID | 项 | 结果 | 备注 |
|
||||
|----|----|------|------|
|
||||
| S1 | `*` vs `**` | 通过 | `em_*` / `strong_*` 在 inline children 中 |
|
||||
| S2 | `-` vs `+` | 通过 | **行扫描** `scan_bullets` 保留项目符;库只保证有 `bullet_list` |
|
||||
| S3 | 单列表格 | 通过 | `table` 规则开启后可解析 |
|
||||
| S4 | FM `---` vs 正文 `---` | 通过 | 自研 `split_front_matter` |
|
||||
| S5 | FM 内 `> *.mq.md` | 通过 | 行正则抽取,不整块丢给严格 YAML |
|
||||
|
||||
---
|
||||
|
||||
## 对实现的含义
|
||||
|
||||
1. **行扫描是必需层**:`-`/`+` 消歧、frontmatter 导入、注释行分类,不宜只靠 MD 库 AST。
|
||||
2. **markdown-it-py** 足够做块/inline 结构(标题、表、强调、列表);避免 `gfm-like` 默认 `linkify`(缺可选依赖会炸)。
|
||||
3. Spike **不**等于选定长期实现语言;仅证明 Python 路径可验证宪法。参考实现可继续 Python,或再评 TS/Rust。
|
||||
|
||||
---
|
||||
|
||||
## 建议下一步
|
||||
|
||||
1. 将 ADR 0001 中 Spike 标为通过。
|
||||
2. 拍板:参考实现是否 **继续 Python**(推荐,与 Spike 同栈)或换栈。
|
||||
3. 再搭建正式包(`src/marqdo`)与 `marqdo run`,按 examples 金样例推进。
|
||||
@@ -1,78 +0,0 @@
|
||||
"""
|
||||
Spike helpers: GFM parse via markdown-it-py + line-level bullet probe.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import re
|
||||
from dataclasses import dataclass
|
||||
|
||||
from markdown_it import MarkdownIt
|
||||
from mdit_py_plugins.front_matter import front_matter_plugin
|
||||
|
||||
|
||||
def make_md() -> MarkdownIt:
|
||||
# Avoid gfm-like's linkify (needs optional linkify-it-py).
|
||||
md = MarkdownIt("commonmark", {"html": False, "linkify": False})
|
||||
md.enable(["table"])
|
||||
md.use(front_matter_plugin)
|
||||
return md
|
||||
|
||||
|
||||
@dataclass
|
||||
class BulletLine:
|
||||
line_no: int
|
||||
marker: str # "-" | "+" | "*" | "1."
|
||||
text: str
|
||||
|
||||
|
||||
_BULLET = re.compile(
|
||||
r"^(?P<indent>\s*)(?P<marker>[-+*]|\d+\.)\s+(?P<text>.*)$"
|
||||
)
|
||||
|
||||
|
||||
def scan_bullets(source: str) -> list[BulletLine]:
|
||||
"""Line-level scan: preserves '-' vs '+' regardless of MD library."""
|
||||
out: list[BulletLine] = []
|
||||
for i, line in enumerate(source.splitlines(), start=1):
|
||||
m = _BULLET.match(line)
|
||||
if not m:
|
||||
continue
|
||||
out.append(
|
||||
BulletLine(line_no=i, marker=m.group("marker"), text=m.group("text"))
|
||||
)
|
||||
return out
|
||||
|
||||
|
||||
def parse_tokens(source: str):
|
||||
return make_md().parse(source)
|
||||
|
||||
|
||||
def split_front_matter(source: str) -> tuple[str | None, str]:
|
||||
"""
|
||||
Split leading --- ... --- front matter from body.
|
||||
Body-internal --- is left untouched.
|
||||
"""
|
||||
if not source.startswith("---"):
|
||||
return None, source
|
||||
lines = source.splitlines(keepends=True)
|
||||
if not lines or lines[0].strip() != "---":
|
||||
return None, source
|
||||
for i in range(1, len(lines)):
|
||||
if lines[i].strip() == "---":
|
||||
fm = "".join(lines[1:i])
|
||||
body = "".join(lines[i + 1 :])
|
||||
return fm, body
|
||||
return None, source
|
||||
|
||||
|
||||
_IMPORT = re.compile(r"^>\s*(?P<path>\S+\.mq\.md)\s*$")
|
||||
|
||||
|
||||
def front_matter_imports(fm: str) -> list[str]:
|
||||
paths: list[str] = []
|
||||
for line in fm.splitlines():
|
||||
m = _IMPORT.match(line.strip())
|
||||
if m:
|
||||
paths.append(m.group("path"))
|
||||
return paths
|
||||
@@ -1,3 +0,0 @@
|
||||
markdown-it-py>=3.0,<4
|
||||
mdit-py-plugins>=0.4,<1
|
||||
pytest>=8.0,<9
|
||||
@@ -1,104 +0,0 @@
|
||||
"""ADR 0001 Spike acceptance: S1–S5."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from marqdo_spike import (
|
||||
front_matter_imports,
|
||||
parse_tokens,
|
||||
scan_bullets,
|
||||
split_front_matter,
|
||||
)
|
||||
|
||||
|
||||
def test_s1_emphasis_vs_strong():
|
||||
"""S1: *a* vs **a** yield distinct inline marks."""
|
||||
src = "hello *em* and **strong** end\n"
|
||||
tokens = parse_tokens(src)
|
||||
inlines = [t for t in tokens if t.type == "inline"]
|
||||
assert inlines, "expected inline token"
|
||||
children = inlines[0].children or []
|
||||
types = [c.type for c in children]
|
||||
assert "em_open" in types and "em_close" in types
|
||||
assert "strong_open" in types and "strong_close" in types
|
||||
assert any(c.type == "text" and c.content == "em" for c in children)
|
||||
assert any(c.type == "text" and c.content == "strong" for c in children)
|
||||
|
||||
|
||||
def test_s2_bullet_minus_vs_plus_line_scan():
|
||||
"""S2: line scan distinguishes '-' (loop) vs '+' (branch)."""
|
||||
src = """
|
||||
# main
|
||||
|
||||
- loop item
|
||||
+ branch item
|
||||
"""
|
||||
bullets = scan_bullets(src)
|
||||
markers = [b.marker for b in bullets]
|
||||
assert "-" in markers
|
||||
assert "+" in markers
|
||||
assert bullets[0].marker == "-"
|
||||
assert bullets[1].marker == "+"
|
||||
|
||||
|
||||
def test_s2_library_list_tokens_exist():
|
||||
"""S2b: library at least parses both as lists (bullet char may need line scan)."""
|
||||
src = "- a\n\n+ b\n"
|
||||
tokens = parse_tokens(src)
|
||||
assert any(t.type == "bullet_list_open" for t in tokens)
|
||||
|
||||
|
||||
def test_s3_single_column_table():
|
||||
"""S3: GFM single-column table."""
|
||||
src = """
|
||||
| 果 |
|
||||
|----|
|
||||
| 苹果 |
|
||||
| 梨 |
|
||||
"""
|
||||
tokens = parse_tokens(src)
|
||||
assert any(t.type == "table_open" for t in tokens)
|
||||
texts = [t.content for t in tokens if t.type == "inline"]
|
||||
flat = " ".join(texts)
|
||||
assert "果" in flat
|
||||
assert "苹果" in flat
|
||||
assert "梨" in flat
|
||||
|
||||
|
||||
def test_s4_front_matter_vs_body_hr():
|
||||
"""S4: file-level --- front matter vs body --- frame."""
|
||||
src = """---
|
||||
title: demo
|
||||
---
|
||||
|
||||
# main
|
||||
|
||||
---
|
||||
+ `x` > 0
|
||||
> 输出 内容=正
|
||||
---
|
||||
"""
|
||||
fm, body = split_front_matter(src)
|
||||
assert fm is not None
|
||||
assert "title: demo" in fm
|
||||
assert body.lstrip().startswith("# main")
|
||||
assert "---" in body
|
||||
assert "+ `x` > 0" in body
|
||||
# Body still has its own ---; must not be eaten by FM splitter
|
||||
assert body.count("---") >= 2
|
||||
|
||||
|
||||
def test_s5_front_matter_mq_imports():
|
||||
"""S5: `> file.mq.md` lines inside front matter."""
|
||||
src = """---
|
||||
title: main
|
||||
> utils.mq.md
|
||||
> lib/math.mq.md
|
||||
---
|
||||
|
||||
# main
|
||||
"""
|
||||
fm, body = split_front_matter(src)
|
||||
assert fm is not None
|
||||
imports = front_matter_imports(fm)
|
||||
assert imports == ["utils.mq.md", "lib/math.mq.md"]
|
||||
assert "# main" in body
|
||||
-208
@@ -1,208 +0,0 @@
|
||||
//! Marqdo AST (Phase I).
|
||||
|
||||
use crate::diagnostics::Span;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Module {
|
||||
pub imports: Vec<String>,
|
||||
pub functions: Vec<Function>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Function {
|
||||
pub name: String,
|
||||
pub level: u8,
|
||||
pub span: Span,
|
||||
pub params: Vec<String>,
|
||||
pub body: Vec<Stmt>,
|
||||
pub children: Vec<Function>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Stmt {
|
||||
Assign {
|
||||
name: String,
|
||||
value: Expr,
|
||||
span: Span,
|
||||
},
|
||||
Return {
|
||||
value: Expr,
|
||||
span: Span,
|
||||
},
|
||||
/// Statement-form call (`> …`); return value discarded.
|
||||
Call {
|
||||
call: CallExpr,
|
||||
span: Span,
|
||||
},
|
||||
Branch {
|
||||
arms: Vec<BranchArm>,
|
||||
span: Span,
|
||||
},
|
||||
While {
|
||||
condition: Expr,
|
||||
body: Vec<Stmt>,
|
||||
span: Span,
|
||||
},
|
||||
ForEach {
|
||||
item: String,
|
||||
collection: String,
|
||||
body: Vec<Stmt>,
|
||||
span: Span,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct BranchArm {
|
||||
pub condition: Option<Expr>, // None = else
|
||||
pub body: Vec<Stmt>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct CallExpr {
|
||||
pub callee: String,
|
||||
pub args: Vec<Arg>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Arg {
|
||||
Positional(Expr),
|
||||
Named { name: String, value: Expr },
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Expr {
|
||||
Literal(Literal),
|
||||
Var(String),
|
||||
/// Text with embedded `` `var` `` segments.
|
||||
Interp(Vec<InterpPart>),
|
||||
Unary {
|
||||
op: UnaryOp,
|
||||
expr: Box<Expr>,
|
||||
},
|
||||
Binary {
|
||||
op: BinaryOp,
|
||||
left: Box<Expr>,
|
||||
right: Box<Expr>,
|
||||
},
|
||||
Call(CallExpr),
|
||||
List(Vec<Expr>),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum InterpPart {
|
||||
Lit(String),
|
||||
Var(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub enum Literal {
|
||||
None,
|
||||
Bool(bool),
|
||||
Int(i64),
|
||||
Text(String),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum UnaryOp {
|
||||
Not,
|
||||
Neg,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum BinaryOp {
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Eq,
|
||||
Ne,
|
||||
Lt,
|
||||
Le,
|
||||
Gt,
|
||||
Ge,
|
||||
And,
|
||||
Or,
|
||||
}
|
||||
|
||||
/// Pretty-print AST for `--dump-ast`.
|
||||
pub fn format_ast_dump(path: &str, module: &Module) -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str(&format!("=== marqdo: ast ({path}) ===\n"));
|
||||
if !module.imports.is_empty() {
|
||||
out.push_str(&format!("(imports {:?})\n", module.imports));
|
||||
}
|
||||
for fun in &module.functions {
|
||||
dump_fun(&mut out, fun, 0);
|
||||
}
|
||||
out.push_str("=== marqdo: end ast ===\n");
|
||||
out
|
||||
}
|
||||
|
||||
fn dump_fun(out: &mut String, fun: &Function, depth: usize) {
|
||||
let pad = " ".repeat(depth);
|
||||
out.push_str(&format!(
|
||||
"{pad}(fun level={} {:?} params={:?} @{}\n",
|
||||
fun.level, fun.name, fun.params, fun.span
|
||||
));
|
||||
for stmt in &fun.body {
|
||||
dump_stmt(out, stmt, depth + 1);
|
||||
}
|
||||
for child in &fun.children {
|
||||
dump_fun(out, child, depth + 1);
|
||||
}
|
||||
out.push_str(&format!("{pad})\n"));
|
||||
}
|
||||
|
||||
fn dump_stmt(out: &mut String, stmt: &Stmt, depth: usize) {
|
||||
let pad = " ".repeat(depth);
|
||||
match stmt {
|
||||
Stmt::Assign { name, value, span } => {
|
||||
out.push_str(&format!("{pad}(assign {name:?} {value:?} @{span})\n"));
|
||||
}
|
||||
Stmt::Return { value, span } => {
|
||||
out.push_str(&format!("{pad}(return {value:?} @{span})\n"));
|
||||
}
|
||||
Stmt::Call { call, span } => {
|
||||
out.push_str(&format!(
|
||||
"{pad}(call {:?} {:?} @{span})\n",
|
||||
call.callee, call.args
|
||||
));
|
||||
}
|
||||
Stmt::Branch { arms, span } => {
|
||||
out.push_str(&format!("{pad}(branch @{span}\n"));
|
||||
for arm in arms {
|
||||
out.push_str(&format!("{pad} (arm cond={:?}\n", arm.condition));
|
||||
for s in &arm.body {
|
||||
dump_stmt(out, s, depth + 2);
|
||||
}
|
||||
out.push_str(&format!("{pad} )\n"));
|
||||
}
|
||||
out.push_str(&format!("{pad})\n"));
|
||||
}
|
||||
Stmt::While {
|
||||
condition,
|
||||
body,
|
||||
span,
|
||||
} => {
|
||||
out.push_str(&format!("{pad}(while {condition:?} @{span}\n"));
|
||||
for s in body {
|
||||
dump_stmt(out, s, depth + 1);
|
||||
}
|
||||
out.push_str(&format!("{pad})\n"));
|
||||
}
|
||||
Stmt::ForEach {
|
||||
item,
|
||||
collection,
|
||||
body,
|
||||
span,
|
||||
} => {
|
||||
out.push_str(&format!(
|
||||
"{pad}(foreach {item:?} in {collection:?} @{span}\n"
|
||||
));
|
||||
for s in body {
|
||||
dump_stmt(out, s, depth + 1);
|
||||
}
|
||||
out.push_str(&format!("{pad})\n"));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,453 +0,0 @@
|
||||
//! AST → bytecode Program.
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::ast::{
|
||||
Arg, BinaryOp, CallExpr, Expr, Function, InterpPart, Literal, Module, Stmt, UnaryOp,
|
||||
};
|
||||
use crate::bytecode::{FnChunk, Op, Program};
|
||||
use crate::value::Value;
|
||||
|
||||
struct FlatFun {
|
||||
name: String,
|
||||
parent: Option<usize>,
|
||||
params: Vec<String>,
|
||||
body: Vec<Stmt>,
|
||||
children: Vec<usize>,
|
||||
}
|
||||
|
||||
pub fn compile_module(module: &Module) -> Result<Program> {
|
||||
let mut flat = Vec::new();
|
||||
for fun in &module.functions {
|
||||
collect_fun(fun, None, &mut flat);
|
||||
}
|
||||
if flat.is_empty() {
|
||||
bail!("bytecode: no functions to compile");
|
||||
}
|
||||
|
||||
let entry = flat
|
||||
.iter()
|
||||
.position(|f| f.name == "main" && f.parent.is_none())
|
||||
.or_else(|| {
|
||||
flat.iter()
|
||||
.position(|f| f.parent.is_none() && f.params.is_empty())
|
||||
})
|
||||
.ok_or_else(|| anyhow::anyhow!("bytecode: no entry function"))?;
|
||||
|
||||
let mut functions = Vec::new();
|
||||
for i in 0..flat.len() {
|
||||
functions.push(compile_function(i, &flat)?);
|
||||
}
|
||||
|
||||
Ok(Program { functions, entry })
|
||||
}
|
||||
|
||||
fn collect_fun(fun: &Function, parent: Option<usize>, flat: &mut Vec<FlatFun>) -> usize {
|
||||
let id = flat.len();
|
||||
flat.push(FlatFun {
|
||||
name: fun.name.clone(),
|
||||
parent,
|
||||
params: fun.params.clone(),
|
||||
body: fun.body.clone(),
|
||||
children: Vec::new(),
|
||||
});
|
||||
let mut child_ids = Vec::new();
|
||||
for child in &fun.children {
|
||||
child_ids.push(collect_fun(child, Some(id), flat));
|
||||
}
|
||||
flat[id].children = child_ids;
|
||||
id
|
||||
}
|
||||
|
||||
struct FnCompiler<'a> {
|
||||
flat: &'a [FlatFun],
|
||||
fn_id: usize,
|
||||
chunk: FnChunk,
|
||||
locals: HashMap<String, u8>,
|
||||
}
|
||||
|
||||
fn compile_function(fn_id: usize, flat: &[FlatFun]) -> Result<FnChunk> {
|
||||
let fun = &flat[fn_id];
|
||||
let mut locals = HashMap::new();
|
||||
for (i, p) in fun.params.iter().enumerate() {
|
||||
locals.insert(p.clone(), i as u8);
|
||||
}
|
||||
let mut c = FnCompiler {
|
||||
flat,
|
||||
fn_id,
|
||||
chunk: FnChunk {
|
||||
name: fun.name.clone(),
|
||||
params: fun.params.clone(),
|
||||
code: Vec::new(),
|
||||
constants: Vec::new(),
|
||||
locals: fun.params.clone(),
|
||||
},
|
||||
locals,
|
||||
};
|
||||
for stmt in &fun.body {
|
||||
c.compile_stmt(stmt)?;
|
||||
}
|
||||
c.emit(Op::None_);
|
||||
c.emit(Op::Return);
|
||||
let mut names = vec![String::new(); c.locals.len()];
|
||||
for (name, slot) in &c.locals {
|
||||
names[*slot as usize] = name.clone();
|
||||
}
|
||||
c.chunk.locals = names;
|
||||
Ok(c.chunk)
|
||||
}
|
||||
|
||||
impl<'a> FnCompiler<'a> {
|
||||
fn emit(&mut self, op: Op) {
|
||||
self.chunk.code.push(op);
|
||||
}
|
||||
|
||||
fn here(&self) -> u16 {
|
||||
self.chunk.code.len() as u16
|
||||
}
|
||||
|
||||
fn patch(&mut self, at: u16, op: Op) {
|
||||
self.chunk.code[at as usize] = op;
|
||||
}
|
||||
|
||||
fn add_const(&mut self, v: Value) -> u16 {
|
||||
if let Some(i) = self.chunk.constants.iter().position(|c| c == &v) {
|
||||
return i as u16;
|
||||
}
|
||||
let i = self.chunk.constants.len() as u16;
|
||||
self.chunk.constants.push(v);
|
||||
i
|
||||
}
|
||||
|
||||
fn local_slot(&mut self, name: &str) -> u8 {
|
||||
if let Some(&s) = self.locals.get(name) {
|
||||
return s;
|
||||
}
|
||||
let s = self.locals.len() as u8;
|
||||
self.locals.insert(name.to_string(), s);
|
||||
s
|
||||
}
|
||||
|
||||
fn resolve_call(&self, name: &str) -> Result<usize> {
|
||||
let fun = &self.flat[self.fn_id];
|
||||
for &cid in &fun.children {
|
||||
if self.flat[cid].name == name {
|
||||
return Ok(cid);
|
||||
}
|
||||
}
|
||||
let mut parent = fun.parent;
|
||||
while let Some(pid) = parent {
|
||||
for &cid in &self.flat[pid].children {
|
||||
if self.flat[cid].name == name {
|
||||
return Ok(cid);
|
||||
}
|
||||
}
|
||||
parent = self.flat[pid].parent;
|
||||
}
|
||||
for (i, f) in self.flat.iter().enumerate() {
|
||||
if f.parent.is_none() && f.name == name {
|
||||
return Ok(i);
|
||||
}
|
||||
}
|
||||
bail!("bytecode: unknown function `{name}`")
|
||||
}
|
||||
|
||||
fn compile_stmt(&mut self, stmt: &Stmt) -> Result<()> {
|
||||
match stmt {
|
||||
Stmt::Assign { name, value, .. } => {
|
||||
self.compile_expr(value)?;
|
||||
let slot = self.local_slot(name);
|
||||
self.emit(Op::SetLocal(slot));
|
||||
self.emit(Op::Pop);
|
||||
}
|
||||
Stmt::Return { value, .. } => {
|
||||
self.compile_expr(value)?;
|
||||
self.emit(Op::Return);
|
||||
}
|
||||
Stmt::Call { call, .. } => self.compile_call(call, true)?,
|
||||
Stmt::Branch { arms, .. } => {
|
||||
let mut end_jumps = Vec::new();
|
||||
for (i, arm) in arms.iter().enumerate() {
|
||||
let is_last = i + 1 == arms.len();
|
||||
let mut else_jump = None;
|
||||
if let Some(cond) = &arm.condition {
|
||||
self.compile_expr(cond)?;
|
||||
let jf = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
else_jump = Some(jf);
|
||||
}
|
||||
for st in &arm.body {
|
||||
self.compile_stmt(st)?;
|
||||
}
|
||||
if !is_last {
|
||||
let j = self.here();
|
||||
self.emit(Op::Jump(0));
|
||||
end_jumps.push(j);
|
||||
}
|
||||
if let Some(jf) = else_jump {
|
||||
self.patch(jf, Op::JumpIfFalse(self.here()));
|
||||
}
|
||||
}
|
||||
let end = self.here();
|
||||
for j in end_jumps {
|
||||
self.patch(j, Op::Jump(end));
|
||||
}
|
||||
}
|
||||
Stmt::While {
|
||||
condition, body, ..
|
||||
} => {
|
||||
let loop_start = self.here();
|
||||
self.compile_expr(condition)?;
|
||||
let exit_j = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
for st in body {
|
||||
self.compile_stmt(st)?;
|
||||
}
|
||||
self.emit(Op::Jump(loop_start));
|
||||
self.patch(exit_j, Op::JumpIfFalse(self.here()));
|
||||
}
|
||||
Stmt::ForEach {
|
||||
item,
|
||||
collection,
|
||||
body,
|
||||
..
|
||||
} => {
|
||||
self.compile_expr(&Expr::Var(collection.clone()))?;
|
||||
let coll_slot = self.local_slot(&format!("__coll_{collection}"));
|
||||
self.emit(Op::SetLocal(coll_slot));
|
||||
self.emit(Op::Pop);
|
||||
let i_slot = self.local_slot(&format!("__i_{collection}"));
|
||||
let zero = self.add_const(Value::Int(0));
|
||||
self.emit(Op::Constant(zero));
|
||||
self.emit(Op::SetLocal(i_slot));
|
||||
self.emit(Op::Pop);
|
||||
let item_slot = self.local_slot(item);
|
||||
|
||||
let loop_start = self.here();
|
||||
self.emit(Op::GetLocal(i_slot));
|
||||
self.emit(Op::GetLocal(coll_slot));
|
||||
self.emit(Op::Len);
|
||||
self.emit(Op::Less);
|
||||
let exit_j = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
|
||||
self.emit(Op::GetLocal(coll_slot));
|
||||
self.emit(Op::GetLocal(i_slot));
|
||||
self.emit(Op::GetIndex);
|
||||
self.emit(Op::SetLocal(item_slot));
|
||||
self.emit(Op::Pop);
|
||||
|
||||
for st in body {
|
||||
self.compile_stmt(st)?;
|
||||
}
|
||||
|
||||
self.emit(Op::GetLocal(i_slot));
|
||||
let one = self.add_const(Value::Int(1));
|
||||
self.emit(Op::Constant(one));
|
||||
self.emit(Op::Add);
|
||||
self.emit(Op::SetLocal(i_slot));
|
||||
self.emit(Op::Pop);
|
||||
self.emit(Op::Jump(loop_start));
|
||||
self.patch(exit_j, Op::JumpIfFalse(self.here()));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile_call(&mut self, call: &CallExpr, as_stmt: bool) -> Result<()> {
|
||||
match call.callee.as_str() {
|
||||
"print" => {
|
||||
let text_expr = call
|
||||
.args
|
||||
.iter()
|
||||
.find_map(|a| match a {
|
||||
Arg::Named { name, value } if name == "text" => Some(value),
|
||||
_ => None,
|
||||
})
|
||||
.or_else(|| {
|
||||
call.args.iter().find_map(|a| match a {
|
||||
Arg::Positional(e) => Some(e),
|
||||
_ => None,
|
||||
})
|
||||
})
|
||||
.ok_or_else(|| anyhow::anyhow!("bytecode: print needs text"))?;
|
||||
self.compile_expr(text_expr)?;
|
||||
self.emit(Op::Print);
|
||||
if !as_stmt {
|
||||
self.emit(Op::None_);
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
"input" => bail!("bytecode: input not supported"),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let fid = self.resolve_call(&call.callee)?;
|
||||
let params = self.flat[fid].params.clone();
|
||||
let mut named: HashMap<String, &Expr> = HashMap::new();
|
||||
let mut positionals = Vec::new();
|
||||
for a in &call.args {
|
||||
match a {
|
||||
Arg::Positional(e) => positionals.push(e),
|
||||
Arg::Named { name, value } => {
|
||||
named.insert(name.clone(), value);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut pos_i = 0;
|
||||
for p in ¶ms {
|
||||
if let Some(e) = named.get(p) {
|
||||
self.compile_expr(e)?;
|
||||
} else if pos_i < positionals.len() {
|
||||
self.compile_expr(positionals[pos_i])?;
|
||||
pos_i += 1;
|
||||
} else {
|
||||
bail!("bytecode: missing argument for parameter `{p}`");
|
||||
}
|
||||
}
|
||||
if pos_i < positionals.len() {
|
||||
bail!("bytecode: too many positional arguments");
|
||||
}
|
||||
self.emit(Op::Call(fid as u16, params.len() as u8));
|
||||
if as_stmt {
|
||||
self.emit(Op::Pop);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn compile_expr(&mut self, expr: &Expr) -> Result<()> {
|
||||
match expr {
|
||||
Expr::Literal(lit) => match lit {
|
||||
Literal::None => self.emit(Op::None_),
|
||||
Literal::Bool(true) => self.emit(Op::True),
|
||||
Literal::Bool(false) => self.emit(Op::False),
|
||||
Literal::Int(n) => {
|
||||
let i = self.add_const(Value::Int(*n));
|
||||
self.emit(Op::Constant(i));
|
||||
}
|
||||
Literal::Text(t) => {
|
||||
let i = self.add_const(Value::Text(t.clone()));
|
||||
self.emit(Op::Constant(i));
|
||||
}
|
||||
},
|
||||
Expr::Var(name) => {
|
||||
let slot = self
|
||||
.locals
|
||||
.get(name)
|
||||
.copied()
|
||||
.ok_or_else(|| anyhow::anyhow!("bytecode: undefined variable `{name}`"))?;
|
||||
self.emit(Op::GetLocal(slot));
|
||||
}
|
||||
Expr::Interp(parts) => {
|
||||
if parts.is_empty() {
|
||||
let i = self.add_const(Value::Text(String::new()));
|
||||
self.emit(Op::Constant(i));
|
||||
return Ok(());
|
||||
}
|
||||
for (idx, part) in parts.iter().enumerate() {
|
||||
match part {
|
||||
InterpPart::Lit(t) => {
|
||||
let i = self.add_const(Value::Text(t.clone()));
|
||||
self.emit(Op::Constant(i));
|
||||
}
|
||||
InterpPart::Var(n) => {
|
||||
let slot = self.locals.get(n).copied().ok_or_else(|| {
|
||||
anyhow::anyhow!("bytecode: undefined variable `{n}`")
|
||||
})?;
|
||||
self.emit(Op::GetLocal(slot));
|
||||
}
|
||||
}
|
||||
if idx > 0 {
|
||||
self.emit(Op::Add);
|
||||
}
|
||||
}
|
||||
}
|
||||
Expr::Unary { op, expr } => {
|
||||
self.compile_expr(expr)?;
|
||||
match op {
|
||||
UnaryOp::Not => self.emit(Op::Not),
|
||||
UnaryOp::Neg => self.emit(Op::Negate),
|
||||
}
|
||||
}
|
||||
Expr::Binary {
|
||||
op: BinaryOp::And,
|
||||
left,
|
||||
right,
|
||||
} => {
|
||||
// JumpIfFalse always pops the tested value.
|
||||
self.compile_expr(left)?;
|
||||
let j_false = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
self.compile_expr(right)?;
|
||||
let j_false2 = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
self.emit(Op::True);
|
||||
let j_end = self.here();
|
||||
self.emit(Op::Jump(0));
|
||||
let f2 = self.here();
|
||||
self.patch(j_false2, Op::JumpIfFalse(f2));
|
||||
self.emit(Op::False);
|
||||
let j_end2 = self.here();
|
||||
self.emit(Op::Jump(0));
|
||||
let f1 = self.here();
|
||||
self.patch(j_false, Op::JumpIfFalse(f1));
|
||||
self.emit(Op::False);
|
||||
let end = self.here();
|
||||
self.patch(j_end, Op::Jump(end));
|
||||
self.patch(j_end2, Op::Jump(end));
|
||||
}
|
||||
Expr::Binary {
|
||||
op: BinaryOp::Or,
|
||||
left,
|
||||
right,
|
||||
} => {
|
||||
self.compile_expr(left)?;
|
||||
let j_else = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
self.emit(Op::True);
|
||||
let j_end = self.here();
|
||||
self.emit(Op::Jump(0));
|
||||
let else_ip = self.here();
|
||||
self.patch(j_else, Op::JumpIfFalse(else_ip));
|
||||
self.compile_expr(right)?;
|
||||
let j_f = self.here();
|
||||
self.emit(Op::JumpIfFalse(0));
|
||||
self.emit(Op::True);
|
||||
let j_end2 = self.here();
|
||||
self.emit(Op::Jump(0));
|
||||
let f = self.here();
|
||||
self.patch(j_f, Op::JumpIfFalse(f));
|
||||
self.emit(Op::False);
|
||||
let end = self.here();
|
||||
self.patch(j_end, Op::Jump(end));
|
||||
self.patch(j_end2, Op::Jump(end));
|
||||
}
|
||||
Expr::Binary { op, left, right } => {
|
||||
self.compile_expr(left)?;
|
||||
self.compile_expr(right)?;
|
||||
self.emit(match op {
|
||||
BinaryOp::Add => Op::Add,
|
||||
BinaryOp::Sub => Op::Sub,
|
||||
BinaryOp::Mul => Op::Mul,
|
||||
BinaryOp::Div => Op::Div,
|
||||
BinaryOp::Eq => Op::Equal,
|
||||
BinaryOp::Ne => Op::NotEqual,
|
||||
BinaryOp::Lt => Op::Less,
|
||||
BinaryOp::Le => Op::Lessequal,
|
||||
BinaryOp::Gt => Op::Greater,
|
||||
BinaryOp::Ge => Op::GreaterEqual,
|
||||
BinaryOp::And | BinaryOp::Or => unreachable!(),
|
||||
});
|
||||
}
|
||||
Expr::Call(call) => self.compile_call(call, false)?,
|
||||
Expr::List(items) => {
|
||||
for it in items {
|
||||
self.compile_expr(it)?;
|
||||
}
|
||||
self.emit(Op::BuildList(items.len() as u16));
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
//! Bytecode chunk + opcodes (M5 prototype).
|
||||
|
||||
mod compile;
|
||||
mod vm;
|
||||
|
||||
pub use compile::compile_module;
|
||||
pub use vm::Vm;
|
||||
|
||||
use crate::value::Value;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum Op {
|
||||
Constant(u16),
|
||||
True,
|
||||
False,
|
||||
None_,
|
||||
Pop,
|
||||
GetLocal(u8),
|
||||
SetLocal(u8),
|
||||
Add,
|
||||
Sub,
|
||||
Mul,
|
||||
Div,
|
||||
Negate,
|
||||
Not,
|
||||
Equal,
|
||||
NotEqual,
|
||||
Greater,
|
||||
GreaterEqual,
|
||||
Less,
|
||||
Lessequal,
|
||||
/// Absolute jump to instruction index.
|
||||
Jump(u16),
|
||||
JumpIfFalse(u16),
|
||||
Print,
|
||||
BuildList(u16),
|
||||
Len,
|
||||
GetIndex,
|
||||
/// Call function by index; argc values are on the stack (param order).
|
||||
Call(u16, u8),
|
||||
Return,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct FnChunk {
|
||||
pub name: String,
|
||||
pub params: Vec<String>,
|
||||
pub code: Vec<Op>,
|
||||
pub constants: Vec<Value>,
|
||||
/// Local slot names (params first).
|
||||
pub locals: Vec<String>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Program {
|
||||
pub functions: Vec<FnChunk>,
|
||||
pub entry: usize,
|
||||
}
|
||||
|
||||
impl Program {
|
||||
pub fn disassemble(&self) -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str("=== marqdo: bytecode ===\n");
|
||||
for (fi, fun) in self.functions.iter().enumerate() {
|
||||
let entry = if fi == self.entry { " <entry>" } else { "" };
|
||||
out.push_str(&format!(
|
||||
"fn[{fi}] {} params={:?} locals={:?}{entry}\n",
|
||||
fun.name, fun.params, fun.locals
|
||||
));
|
||||
for (i, c) in fun.constants.iter().enumerate() {
|
||||
out.push_str(&format!(" const[{i}] = {c:?}\n"));
|
||||
}
|
||||
for (ip, op) in fun.code.iter().enumerate() {
|
||||
out.push_str(&format!(" {ip:04} {op:?}\n"));
|
||||
}
|
||||
}
|
||||
out.push_str("=== marqdo: end bytecode ===\n");
|
||||
out
|
||||
}
|
||||
}
|
||||
@@ -1,236 +0,0 @@
|
||||
//! Stack VM for Marqdo bytecode.
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
|
||||
use crate::bytecode::{Op, Program};
|
||||
use crate::value::Value;
|
||||
|
||||
pub struct Vm {
|
||||
capture: bool,
|
||||
pub captured_stdout: String,
|
||||
}
|
||||
|
||||
struct Frame {
|
||||
fn_idx: usize,
|
||||
ip: usize,
|
||||
slots: Vec<Value>,
|
||||
}
|
||||
|
||||
impl Vm {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
capture: false,
|
||||
captured_stdout: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn with_capture() -> Self {
|
||||
Self {
|
||||
capture: true,
|
||||
captured_stdout: String::new(),
|
||||
}
|
||||
}
|
||||
|
||||
fn emit_line(&mut self, text: &str) {
|
||||
if self.capture {
|
||||
self.captured_stdout.push_str(text);
|
||||
self.captured_stdout.push('\n');
|
||||
} else {
|
||||
println!("{text}");
|
||||
}
|
||||
}
|
||||
|
||||
pub fn run(&mut self, program: &Program) -> Result<Value> {
|
||||
let mut stack: Vec<Value> = Vec::new();
|
||||
let entry = program.entry;
|
||||
let arity = program.functions[entry].params.len();
|
||||
if arity != 0 {
|
||||
bail!("bytecode: entry function needs arguments");
|
||||
}
|
||||
let mut frames = vec![Frame {
|
||||
fn_idx: entry,
|
||||
ip: 0,
|
||||
slots: vec![Value::None; program.functions[entry].locals.len().max(1)],
|
||||
}];
|
||||
|
||||
loop {
|
||||
let frame = frames.last_mut().unwrap();
|
||||
let fun = &program.functions[frame.fn_idx];
|
||||
if frame.ip >= fun.code.len() {
|
||||
bail!("bytecode: ip out of range in {}", fun.name);
|
||||
}
|
||||
let op = fun.code[frame.ip];
|
||||
frame.ip += 1;
|
||||
|
||||
match op {
|
||||
Op::Constant(i) => stack.push(fun.constants[i as usize].clone()),
|
||||
Op::True => stack.push(Value::Bool(true)),
|
||||
Op::False => stack.push(Value::Bool(false)),
|
||||
Op::None_ => stack.push(Value::None),
|
||||
Op::Pop => {
|
||||
stack.pop();
|
||||
}
|
||||
Op::GetLocal(i) => {
|
||||
let v = frames.last().unwrap().slots[i as usize].clone();
|
||||
stack.push(v);
|
||||
}
|
||||
Op::SetLocal(i) => {
|
||||
let v = stack.last().cloned().unwrap_or(Value::None);
|
||||
let slot = i as usize;
|
||||
let fr = frames.last_mut().unwrap();
|
||||
if fr.slots.len() <= slot {
|
||||
fr.slots.resize(slot + 1, Value::None);
|
||||
}
|
||||
fr.slots[slot] = v;
|
||||
}
|
||||
Op::Add => {
|
||||
let b = pop(&mut stack)?;
|
||||
let a = pop(&mut stack)?;
|
||||
stack.push(add(a, b)?);
|
||||
}
|
||||
Op::Sub => bin_int(&mut stack, |a, b| a - b)?,
|
||||
Op::Mul => bin_int(&mut stack, |a, b| a * b)?,
|
||||
Op::Div => {
|
||||
let b = pop(&mut stack)?;
|
||||
let a = pop(&mut stack)?;
|
||||
match (a, b) {
|
||||
(Value::Int(_), Value::Int(0)) => bail!("division by zero"),
|
||||
(Value::Int(x), Value::Int(y)) => stack.push(Value::Int(x / y)),
|
||||
_ => bail!("`/` needs ints"),
|
||||
}
|
||||
}
|
||||
Op::Negate => match pop(&mut stack)? {
|
||||
Value::Int(n) => stack.push(Value::Int(-n)),
|
||||
_ => bail!("unary `-` needs int"),
|
||||
},
|
||||
Op::Not => {
|
||||
let v = pop(&mut stack)?;
|
||||
stack.push(Value::Bool(!v.truthy()));
|
||||
}
|
||||
Op::Equal => {
|
||||
let b = pop(&mut stack)?;
|
||||
let a = pop(&mut stack)?;
|
||||
stack.push(Value::Bool(a == b));
|
||||
}
|
||||
Op::NotEqual => {
|
||||
let b = pop(&mut stack)?;
|
||||
let a = pop(&mut stack)?;
|
||||
stack.push(Value::Bool(a != b));
|
||||
}
|
||||
Op::Greater => cmp(&mut stack, |o| o.is_gt())?,
|
||||
Op::GreaterEqual => cmp(&mut stack, |o| o.is_ge())?,
|
||||
Op::Less => cmp(&mut stack, |o| o.is_lt())?,
|
||||
Op::Lessequal => cmp(&mut stack, |o| o.is_le())?,
|
||||
Op::Jump(t) => {
|
||||
frames.last_mut().unwrap().ip = t as usize;
|
||||
}
|
||||
Op::JumpIfFalse(t) => {
|
||||
let v = pop(&mut stack)?;
|
||||
if !v.truthy() {
|
||||
frames.last_mut().unwrap().ip = t as usize;
|
||||
}
|
||||
}
|
||||
Op::Print => {
|
||||
let v = pop(&mut stack)?;
|
||||
self.emit_line(&v.as_display());
|
||||
}
|
||||
Op::BuildList(n) => {
|
||||
let n = n as usize;
|
||||
let mut items = Vec::with_capacity(n);
|
||||
for _ in 0..n {
|
||||
items.push(pop(&mut stack)?);
|
||||
}
|
||||
items.reverse();
|
||||
stack.push(Value::List(items));
|
||||
}
|
||||
Op::Len => match pop(&mut stack)? {
|
||||
Value::List(xs) => stack.push(Value::Int(xs.len() as i64)),
|
||||
_ => bail!("len needs list"),
|
||||
},
|
||||
Op::GetIndex => {
|
||||
let idx = pop(&mut stack)?;
|
||||
let list = pop(&mut stack)?;
|
||||
match (list, idx) {
|
||||
(Value::List(xs), Value::Int(i)) if i >= 0 && (i as usize) < xs.len() => {
|
||||
stack.push(xs[i as usize].clone());
|
||||
}
|
||||
(Value::List(_), Value::Int(_)) => stack.push(Value::None),
|
||||
_ => bail!("GetIndex needs list and int"),
|
||||
}
|
||||
}
|
||||
Op::Call(fid, argc) => {
|
||||
let fid = fid as usize;
|
||||
let argc = argc as usize;
|
||||
let callee = &program.functions[fid];
|
||||
if callee.params.len() != argc {
|
||||
bail!("bytecode: call argc mismatch");
|
||||
}
|
||||
let mut slots = vec![Value::None; callee.locals.len().max(argc).max(1)];
|
||||
for i in (0..argc).rev() {
|
||||
slots[i] = pop(&mut stack)?;
|
||||
}
|
||||
// args were pushed in param order; we popped reverse so slots[0] is last param — fix:
|
||||
// stack had p0, p1, p2 (top). pop → p2, p1, p0. So assign slots[argc-1-i] or pop into reverse.
|
||||
// Actually we did: for i in (0..argc).rev() { slots[i] = pop() }
|
||||
// first pop → slots[argc-1] = top = last param. Good if push order was p0..plast.
|
||||
frames.push(Frame {
|
||||
fn_idx: fid,
|
||||
ip: 0,
|
||||
slots,
|
||||
});
|
||||
}
|
||||
Op::Return => {
|
||||
let ret = pop(&mut stack).unwrap_or(Value::None);
|
||||
frames.pop();
|
||||
if frames.is_empty() {
|
||||
return Ok(ret);
|
||||
}
|
||||
stack.push(ret);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn pop(stack: &mut Vec<Value>) -> Result<Value> {
|
||||
stack
|
||||
.pop()
|
||||
.ok_or_else(|| anyhow::anyhow!("bytecode: stack underflow"))
|
||||
}
|
||||
|
||||
fn add(a: Value, b: Value) -> Result<Value> {
|
||||
match (a, b) {
|
||||
(Value::Int(x), Value::Int(y)) => Ok(Value::Int(x + y)),
|
||||
(Value::Text(x), Value::Text(y)) => Ok(Value::Text(format!("{x}{y}"))),
|
||||
(Value::Text(x), y) => Ok(Value::Text(format!("{x}{}", y.as_display()))),
|
||||
(x, Value::Text(y)) => Ok(Value::Text(format!("{}{y}", x.as_display()))),
|
||||
// Int + display for interp GetLocal Int + Lit text
|
||||
(Value::Int(x), y) => Ok(Value::Text(format!("{}{}", x, y.as_display()))),
|
||||
(x, Value::Int(y)) => Ok(Value::Text(format!("{}{y}", x.as_display()))),
|
||||
_ => bail!("`+` needs ints or text"),
|
||||
}
|
||||
}
|
||||
|
||||
fn bin_int(stack: &mut Vec<Value>, f: impl Fn(i64, i64) -> i64) -> Result<()> {
|
||||
let b = pop(stack)?;
|
||||
let a = pop(stack)?;
|
||||
match (a, b) {
|
||||
(Value::Int(x), Value::Int(y)) => {
|
||||
stack.push(Value::Int(f(x, y)));
|
||||
Ok(())
|
||||
}
|
||||
_ => bail!("binary op needs ints"),
|
||||
}
|
||||
}
|
||||
|
||||
fn cmp(stack: &mut Vec<Value>, pred: impl Fn(std::cmp::Ordering) -> bool) -> Result<()> {
|
||||
let b = pop(stack)?;
|
||||
let a = pop(stack)?;
|
||||
let ord = match (&a, &b) {
|
||||
(Value::Int(x), Value::Int(y)) => x.cmp(y),
|
||||
(Value::Text(x), Value::Text(y)) => x.cmp(y),
|
||||
_ => bail!("comparison needs two ints or two texts"),
|
||||
};
|
||||
stack.push(Value::Bool(pred(ord)));
|
||||
Ok(())
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
//! Captured program run (for tests and `view`).
|
||||
|
||||
use crate::value::Value;
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct RunCapture {
|
||||
pub stdout: String,
|
||||
pub value: Value,
|
||||
}
|
||||
-312
@@ -1,312 +0,0 @@
|
||||
//! OKF-compatible catalog generation: `marqdo catalog` / `sync`.
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
|
||||
use crate::lex::{classify_source, LineKind};
|
||||
use crate::parse::parse_source;
|
||||
|
||||
pub struct CatalogOptions {
|
||||
pub path: PathBuf,
|
||||
pub out_dir: PathBuf,
|
||||
}
|
||||
|
||||
struct ModuleInfo {
|
||||
id: String,
|
||||
resource: String,
|
||||
title: String,
|
||||
imports: Vec<String>,
|
||||
exports: Vec<String>,
|
||||
}
|
||||
|
||||
pub fn write_catalog(opts: CatalogOptions) -> Result<()> {
|
||||
let root = if opts.path.is_file() {
|
||||
opts.path
|
||||
.parent()
|
||||
.map(|p| p.to_path_buf())
|
||||
.unwrap_or_else(|| PathBuf::from("."))
|
||||
} else {
|
||||
opts.path.clone()
|
||||
};
|
||||
let root = root.canonicalize().unwrap_or(root);
|
||||
|
||||
let mut files = Vec::new();
|
||||
if opts.path.is_file() {
|
||||
files.push(opts.path.canonicalize().unwrap_or(opts.path.clone()));
|
||||
} else {
|
||||
collect_mq_md(&root, &root, &mut files)?;
|
||||
files.sort();
|
||||
}
|
||||
|
||||
fs::create_dir_all(opts.out_dir.join("modules"))
|
||||
.with_context(|| format!("create {}", opts.out_dir.display()))?;
|
||||
|
||||
let version = env!("CARGO_PKG_VERSION");
|
||||
let mut modules = Vec::new();
|
||||
let mut had_err = false;
|
||||
|
||||
for abs in &files {
|
||||
let rel = abs
|
||||
.strip_prefix(&root)
|
||||
.unwrap_or(abs)
|
||||
.to_string_lossy()
|
||||
.replace('\\', "/");
|
||||
match inspect_file(abs, &rel) {
|
||||
Ok(info) => modules.push(info),
|
||||
Err(e) => {
|
||||
eprintln!("catalog: skip {rel}: {e:#}");
|
||||
had_err = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let catalog_yaml = render_catalog_yaml(&modules, version);
|
||||
fs::write(opts.out_dir.join("catalog.yaml"), catalog_yaml)?;
|
||||
|
||||
let index_md = render_index_md(&modules, version);
|
||||
fs::write(opts.out_dir.join("index.md"), index_md)?;
|
||||
|
||||
for m in &modules {
|
||||
let stem = m.resource.replace('/', "__").replace('\\', "__");
|
||||
let stem = stem.trim_end_matches(".mq.md");
|
||||
let path = opts.out_dir.join("modules").join(format!("{stem}.md"));
|
||||
fs::write(&path, render_module_md(m, version))?;
|
||||
}
|
||||
|
||||
eprintln!(
|
||||
"marqdo catalog: {} module(s) → {}",
|
||||
modules.len(),
|
||||
opts.out_dir.display()
|
||||
);
|
||||
if had_err {
|
||||
anyhow::bail!("catalog completed with errors");
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn collect_mq_md(root: &Path, dir: &Path, out: &mut Vec<PathBuf>) -> Result<()> {
|
||||
for entry in fs::read_dir(dir)? {
|
||||
let entry = entry?;
|
||||
let p = entry.path();
|
||||
if p.is_dir() {
|
||||
collect_mq_md(root, &p, out)?;
|
||||
} else if p
|
||||
.file_name()
|
||||
.and_then(|s| s.to_str())
|
||||
.map(|s| s.ends_with(".mq.md"))
|
||||
.unwrap_or(false)
|
||||
{
|
||||
out.push(p);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn inspect_file(abs: &Path, rel: &str) -> Result<ModuleInfo> {
|
||||
let source = fs::read_to_string(abs)?;
|
||||
let imports = extract_frontmatter_imports(&source);
|
||||
let title = extract_frontmatter_title(&source)
|
||||
.unwrap_or_else(|| rel.trim_end_matches(".mq.md").to_string());
|
||||
|
||||
let mut exports = Vec::new();
|
||||
// Prefer parse for accurate top-level fn names
|
||||
match parse_source(&source) {
|
||||
Ok(module) => {
|
||||
for f in &module.functions {
|
||||
exports.push(f.name.clone());
|
||||
}
|
||||
}
|
||||
Err(_) => {
|
||||
for line in classify_source(&source) {
|
||||
if line.kind != LineKind::Code {
|
||||
continue;
|
||||
}
|
||||
let t = line.text.trim();
|
||||
if let Some(rest) = t.strip_prefix("# ") {
|
||||
if !rest.starts_with('#') {
|
||||
exports.push(rest.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
let id = rel.trim_end_matches(".mq.md").to_string();
|
||||
Ok(ModuleInfo {
|
||||
id,
|
||||
resource: rel.to_string(),
|
||||
title,
|
||||
imports,
|
||||
exports,
|
||||
})
|
||||
}
|
||||
|
||||
fn extract_frontmatter_imports(source: &str) -> Vec<String> {
|
||||
let source = source.strip_prefix('\u{feff}').unwrap_or(source);
|
||||
let mut imports = Vec::new();
|
||||
let lines: Vec<&str> = source.lines().collect();
|
||||
if lines.first().map(|l| l.trim()) != Some("---") {
|
||||
return imports;
|
||||
}
|
||||
for line in lines.iter().skip(1) {
|
||||
let t = line.trim();
|
||||
if t == "---" {
|
||||
break;
|
||||
}
|
||||
if let Some(rest) = t.strip_prefix('>') {
|
||||
let path = rest.trim();
|
||||
if path.ends_with(".mq.md") {
|
||||
imports.push(path.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
imports
|
||||
}
|
||||
|
||||
fn extract_frontmatter_title(source: &str) -> Option<String> {
|
||||
let source = source.strip_prefix('\u{feff}').unwrap_or(source);
|
||||
let lines: Vec<&str> = source.lines().collect();
|
||||
if lines.first().map(|l| l.trim()) != Some("---") {
|
||||
return None;
|
||||
}
|
||||
for line in lines.iter().skip(1) {
|
||||
let t = line.trim();
|
||||
if t == "---" {
|
||||
break;
|
||||
}
|
||||
if let Some(v) = t.strip_prefix("title:") {
|
||||
return Some(v.trim().trim_matches('"').to_string());
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn yaml_escape(s: &str) -> String {
|
||||
if s.is_empty()
|
||||
|| s.contains(':')
|
||||
|| s.contains('#')
|
||||
|| s.contains('"')
|
||||
|| s.contains('\'')
|
||||
|| s.contains('\n')
|
||||
|| s.starts_with(' ')
|
||||
{
|
||||
format!("\"{}\"", s.replace('\\', "\\\\").replace('"', "\\\""))
|
||||
} else {
|
||||
s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
fn render_catalog_yaml(modules: &[ModuleInfo], version: &str) -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str("# GENERATED by marqdo — do not edit by hand\n");
|
||||
out.push_str("type: Marqdo Catalog\n");
|
||||
out.push_str("title: marqdo-project\n");
|
||||
out.push_str("generated:\n");
|
||||
out.push_str(&format!(" by: marqdo/{version}\n"));
|
||||
out.push_str("modules:\n");
|
||||
for m in modules {
|
||||
out.push_str(&format!(" - id: {}\n", yaml_escape(&m.id)));
|
||||
out.push_str(&format!(" resource: {}\n", yaml_escape(&m.resource)));
|
||||
out.push_str(&format!(" title: {}\n", yaml_escape(&m.title)));
|
||||
if m.imports.is_empty() {
|
||||
out.push_str(" imports: []\n");
|
||||
} else {
|
||||
out.push_str(" imports:\n");
|
||||
for i in &m.imports {
|
||||
out.push_str(&format!(" - {}\n", yaml_escape(i)));
|
||||
}
|
||||
}
|
||||
if m.exports.is_empty() {
|
||||
out.push_str(" exports: []\n");
|
||||
} else {
|
||||
out.push_str(" exports:\n");
|
||||
for e in &m.exports {
|
||||
out.push_str(&format!(" - name: {}\n", yaml_escape(e)));
|
||||
out.push_str(" kind: fn\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn render_index_md(modules: &[ModuleInfo], version: &str) -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str("---\n");
|
||||
out.push_str("type: Marqdo Catalog\n");
|
||||
out.push_str("title: marqdo catalog\n");
|
||||
out.push_str("generated:\n");
|
||||
out.push_str(&format!(" by: marqdo/{version}\n"));
|
||||
out.push_str("---\n\n");
|
||||
out.push_str("# Catalog\n\n");
|
||||
out.push_str("> Generated by Marqdo. Do not edit by hand.\n\n");
|
||||
out.push_str("| Module | Resource | Imports |\n");
|
||||
out.push_str("|--------|----------|--------|\n");
|
||||
for m in modules {
|
||||
let stem = m.resource.replace('/', "__");
|
||||
let stem = stem.trim_end_matches(".mq.md");
|
||||
out.push_str(&format!(
|
||||
"| [{}](modules/{stem}.md) | `{}` | {} |\n",
|
||||
m.title,
|
||||
m.resource,
|
||||
if m.imports.is_empty() {
|
||||
"—".into()
|
||||
} else {
|
||||
m.imports.join(", ")
|
||||
}
|
||||
));
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn render_module_md(m: &ModuleInfo, version: &str) -> String {
|
||||
let mut out = String::new();
|
||||
out.push_str("---\n");
|
||||
out.push_str("type: Marqdo Module\n");
|
||||
out.push_str(&format!("title: {}\n", m.title));
|
||||
out.push_str(&format!("resource: {}\n", m.resource));
|
||||
if m.imports.is_empty() {
|
||||
out.push_str("depends: []\n");
|
||||
} else {
|
||||
out.push_str("depends:\n");
|
||||
for i in &m.imports {
|
||||
out.push_str(&format!(" - {i}\n"));
|
||||
}
|
||||
}
|
||||
if m.exports.is_empty() {
|
||||
out.push_str("exports: []\n");
|
||||
} else {
|
||||
out.push_str("exports:\n");
|
||||
for e in &m.exports {
|
||||
out.push_str(&format!(" - {e}\n"));
|
||||
}
|
||||
}
|
||||
out.push_str("generated:\n");
|
||||
out.push_str(&format!(" by: marqdo/{version}\n"));
|
||||
out.push_str("---\n\n");
|
||||
out.push_str(&format!("# {}\n\n", m.title));
|
||||
out.push_str(&format!(
|
||||
"> Auto-generated from [`{}`](../../{}). Do not edit by hand.\n\n",
|
||||
m.resource, m.resource
|
||||
));
|
||||
out.push_str("## Dependencies\n\n");
|
||||
if m.imports.is_empty() {
|
||||
out.push_str("_None_\n\n");
|
||||
} else {
|
||||
for i in &m.imports {
|
||||
out.push_str(&format!("- `{i}`\n"));
|
||||
}
|
||||
out.push('\n');
|
||||
}
|
||||
out.push_str("## Exports\n\n");
|
||||
if m.exports.is_empty() {
|
||||
out.push_str("_None_\n");
|
||||
} else {
|
||||
out.push_str("| Symbol | Kind |\n|--------|------|\n");
|
||||
for e in &m.exports {
|
||||
out.push_str(&format!("| `{e}` | fn |\n"));
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -1,3 +0,0 @@
|
||||
//! Pipeline dump helpers (see doc/design/pipeline-debug.md).
|
||||
|
||||
pub use crate::lex::format_lines_dump;
|
||||
@@ -1,109 +0,0 @@
|
||||
//! Diagnostics with file/line/column.
|
||||
|
||||
use std::fmt;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use thiserror::Error;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub struct Span {
|
||||
pub line: u32,
|
||||
pub col: u32,
|
||||
}
|
||||
|
||||
impl Span {
|
||||
pub fn new(line: u32, col: u32) -> Self {
|
||||
Self { line, col }
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Span {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "{}:{}", self.line, self.col)
|
||||
}
|
||||
}
|
||||
|
||||
/// Format a path for user-facing diagnostics.
|
||||
///
|
||||
/// Strips the Windows extended-length prefix (`\\?\` / `\\?\UNC\`) that
|
||||
/// `canonicalize` often adds, so messages stay readable.
|
||||
pub fn display_path(path: &Path) -> String {
|
||||
let raw = path.display().to_string();
|
||||
if let Some(rest) = raw.strip_prefix(r"\\?\UNC\") {
|
||||
format!(r"\\{rest}")
|
||||
} else if let Some(rest) = raw.strip_prefix(r"\\?\") {
|
||||
rest.to_string()
|
||||
} else if let Some(rest) = raw.strip_prefix("//?/") {
|
||||
// Some tools emit forward-slash forms
|
||||
rest.to_string()
|
||||
} else {
|
||||
raw
|
||||
}
|
||||
}
|
||||
|
||||
/// Unified diagnostic: `path:line:col: message` (path omitted if unknown).
|
||||
#[derive(Debug, Error, Clone)]
|
||||
#[error("{}", self.format_message())]
|
||||
pub struct Diagnostic {
|
||||
pub path: Option<PathBuf>,
|
||||
pub span: Span,
|
||||
pub message: String,
|
||||
}
|
||||
|
||||
impl Diagnostic {
|
||||
pub fn new(path: Option<&Path>, span: Span, message: impl Into<String>) -> Self {
|
||||
Self {
|
||||
path: path.map(|p| p.to_path_buf()),
|
||||
span,
|
||||
message: message.into(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn at(path: &Path, span: Span, message: impl Into<String>) -> Self {
|
||||
Self::new(Some(path), span, message)
|
||||
}
|
||||
|
||||
pub fn format_message(&self) -> String {
|
||||
match &self.path {
|
||||
Some(p) => format!("{}:{}: {}", display_path(p), self.span, self.message),
|
||||
None => format!("{}: {}", self.span, self.message),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Convenience for `anyhow` sites that already have a span.
|
||||
pub fn bail_at(path: Option<&Path>, span: Span, message: impl Into<String>) -> anyhow::Error {
|
||||
anyhow::Error::new(Diagnostic::new(path, span, message))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn strips_windows_extended_prefix() {
|
||||
let p = PathBuf::from(r"\\?\E:\marqdo\examples\errors\bad-arity.mq.md");
|
||||
assert_eq!(
|
||||
display_path(&p),
|
||||
r"E:\marqdo\examples\errors\bad-arity.mq.md"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn strips_unc_extended_prefix() {
|
||||
let p = PathBuf::from(r"\\?\UNC\server\share\file.mq.md");
|
||||
assert_eq!(display_path(&p), r"\\server\share\file.mq.md");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn diagnostic_message_uses_clean_path() {
|
||||
let d = Diagnostic::at(
|
||||
Path::new(r"\\?\E:\marqdo\x.mq.md"),
|
||||
Span::new(7, 1),
|
||||
"missing argument for parameter `x`",
|
||||
);
|
||||
let msg = d.format_message();
|
||||
assert!(!msg.contains(r"\\?\"));
|
||||
assert!(msg.contains(r"E:\marqdo\x.mq.md:7:1:"));
|
||||
}
|
||||
}
|
||||
Loaded 100 of 160 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user