parse-book-source 0.7.0

Terminal reader for novel
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "BookSource",
  "description": "v2 书源。",
  "type": "object",
  "required": [
    "bookInfo",
    "content",
    "name",
    "schema",
    "toc",
    "url"
  ],
  "properties": {
    "bookInfo": {
      "$ref": "#/definitions/BookInfoOp"
    },
    "concurrentRate": {
      "description": "限速:`\"N/ms\"`(N 次/ms)或纯毫秒间隔字符串;为空则用 `http.rateLimit`。",
      "type": "string"
    },
    "content": {
      "$ref": "#/definitions/ContentRules"
    },
    "enabledCookieJar": {
      "description": "开启后:响应的 `Set-Cookie` 自动回灌进 cookie 库(按注册域归并持久化)。",
      "default": false,
      "type": "boolean"
    },
    "explore": {
      "anyOf": [
        {
          "$ref": "#/definitions/ExploreOp"
        },
        {
          "type": "null"
        }
      ]
    },
    "fontMaps": {
      "description": "命名共享 fontMap 表(`名字 -> {码点:真字}`):供多个 clean 步骤按名复用,避免同一张 大表在书源里重复内联。clean 的 `fontMap` 写字符串名(如 `{\"fontMap\":\"search\"}`)即引用本表, 在 [`BookSource::from_json`] 解析时就地展开为内联表(运行期与直接内联等价)。",
      "type": "object",
      "additionalProperties": {
        "type": "object",
        "additionalProperties": {
          "type": "string"
        }
      }
    },
    "group": {
      "type": "string"
    },
    "http": {
      "default": {
        "charset": "auto",
        "cookies": {},
        "fetcher": "auto",
        "headers": {},
        "warmup": []
      },
      "allOf": [
        {
          "$ref": "#/definitions/Http"
        }
      ]
    },
    "loginCheckJs": {
      "description": "登录态过期校验脚本:每个网络方法响应后执行(注入 `result`=响应),判失效可提示重登。",
      "type": "string"
    },
    "loginUi": {
      "description": "声明式登录表单(TUI 渲染);收集值加密存为 loginInfo,供 `login()` 脚本读取。",
      "type": "array",
      "items": {
        "$ref": "#/definitions/RowUi"
      }
    },
    "loginUrl": {
      "description": "登录:普通 URL,或登录脚本(`@js:…` / `<js>…</js>` 包裹,内含 `login()` 函数)。 非空即视为「需要登录」(见 [`BookSource::has_login`]);仅 `js-host` 构建可真正执行脚本登录。",
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "samples": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/Sample"
      }
    },
    "schema": {
      "description": "固定为 `\"trnovel-booksource/v2\"`。",
      "type": "string"
    },
    "search": {
      "anyOf": [
        {
          "$ref": "#/definitions/ListPageSpec"
        },
        {
          "type": "null"
        }
      ]
    },
    "toc": {
      "$ref": "#/definitions/TocRules"
    },
    "url": {
      "description": "站点基址,用于相对链接解析与 `{{base}}`。",
      "type": "string"
    }
  },
  "additionalProperties": false,
  "definitions": {
    "BookInfoOp": {
      "description": "书详情操作:详情字段抽取(同 [`BookRules`])+ 可选前置请求链(见 design D7-bis)。 字段与 `BookRules` 同名同序,故现有 `bookInfo:{...}` JSON 逐字节解析等价;引擎经 [`BookInfoOp::as_book_rules`] 复用既有 `eval_book_info`(不用 `flatten` 以保 `deny_unknown_fields`)。",
      "type": "object",
      "properties": {
        "author": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "bookUrl": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "cover": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "intro": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "kind": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastChapter": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "name": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "prelude": {
          "description": "详情主请求前的前置请求链;空 = 现状(直接 fetch book_url)。",
          "type": "array",
          "items": {
            "$ref": "#/definitions/PreStep"
          }
        },
        "tocUrl": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "wordCount": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "BookRules": {
      "description": "一本书的字段抽取规则(均可省略)。",
      "type": "object",
      "properties": {
        "author": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "bookUrl": {
          "description": "列表项:指向书详情页的链接(搜索/浏览结果用;bookInfo 阶段忽略)。",
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "cover": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "intro": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "kind": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "lastChapter": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "name": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "tocUrl": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "wordCount": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "ByteEnc": {
      "description": "crypto 的 key/iv/输入/输出字节编码。",
      "oneOf": [
        {
          "type": "string",
          "enum": [
            "utf8",
            "base64",
            "hex"
          ]
        },
        {
          "description": "原样字节(等同 utf8 字节,主要用于输入密文已是裸字节串的场景)。",
          "type": "string",
          "enum": [
            "raw"
          ]
        }
      ]
    },
    "Capture": {
      "description": "一条结构化命名捕获:对**所属请求的响应**用 `value` 规则求一个字符串, 写入 `scope` 指定的作用域层,后续步骤/抽取规则以 `{{name}}` 引用。",
      "type": "object",
      "required": [
        "name",
        "value"
      ],
      "properties": {
        "name": {
          "description": "变量名(后续以 `{{name}}` 引用,走现有模板插值)。",
          "type": "string"
        },
        "scope": {
          "description": "写入哪一层作用域;默认 `chapter`(本次调用临时)。",
          "default": "chapter",
          "allOf": [
            {
              "$ref": "#/definitions/VarScope"
            }
          ]
        },
        "value": {
          "description": "对响应求值的规则(复用 `Rule` AST,产物是字符串)。",
          "allOf": [
            {
              "$ref": "#/definitions/Rule"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "Charset": {
      "description": "字符集。",
      "type": "string",
      "enum": [
        "auto",
        "utf8",
        "gbk",
        "gb18030",
        "big5"
      ]
    },
    "CipherAlgo": {
      "description": "对称加密算法。",
      "type": "string",
      "enum": [
        "aes",
        "des",
        "tripleDes"
      ]
    },
    "CipherMode": {
      "description": "加密模式。",
      "type": "string",
      "enum": [
        "cbc",
        "ecb",
        "cfb",
        "gcm"
      ]
    },
    "CipherOp": {
      "description": "加解密方向。",
      "type": "string",
      "enum": [
        "decrypt",
        "encrypt"
      ]
    },
    "CipherStep": {
      "description": "加解密算子。默认值贴合「解密正文」主场景:`op=decrypt`、`inputEnc=base64`、`outputEnc=utf8`。",
      "type": "object",
      "required": [
        "algo",
        "key",
        "mode"
      ],
      "properties": {
        "algo": {
          "$ref": "#/definitions/CipherAlgo"
        },
        "inputEnc": {
          "description": "入参密文串→字节;省略时按 `op` 取默认(decrypt→base64,encrypt→utf8)。",
          "anyOf": [
            {
              "$ref": "#/definitions/ByteEnc"
            },
            {
              "type": "null"
            }
          ]
        },
        "iv": {
          "type": [
            "string",
            "null"
          ]
        },
        "ivEnc": {
          "default": "utf8",
          "allOf": [
            {
              "$ref": "#/definitions/ByteEnc"
            }
          ]
        },
        "key": {
          "type": "string"
        },
        "keyEnc": {
          "default": "utf8",
          "allOf": [
            {
              "$ref": "#/definitions/ByteEnc"
            }
          ]
        },
        "mode": {
          "$ref": "#/definitions/CipherMode"
        },
        "op": {
          "default": "decrypt",
          "allOf": [
            {
              "$ref": "#/definitions/CipherOp"
            }
          ]
        },
        "outputEnc": {
          "description": "结果字节→串;省略时按 `op` 取默认(decrypt→utf8,encrypt→base64)。",
          "anyOf": [
            {
              "$ref": "#/definitions/ByteEnc"
            },
            {
              "type": "null"
            }
          ]
        },
        "padding": {
          "default": "pkcs7",
          "allOf": [
            {
              "$ref": "#/definitions/Padding"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "CleanStep": {
      "description": "单步后处理。步内多算子按固定顺序执行: `regex/replace → trim → prepend → append → decode → encode → hash → cipher → fontMap → cn`。",
      "type": "object",
      "properties": {
        "append": {
          "type": [
            "string",
            "null"
          ]
        },
        "cipher": {
          "description": "对称加解密。",
          "anyOf": [
            {
              "$ref": "#/definitions/CipherStep"
            },
            {
              "type": "null"
            }
          ]
        },
        "cn": {
          "description": "繁简转换。",
          "anyOf": [
            {
              "$ref": "#/definitions/CnConvert"
            },
            {
              "type": "null"
            }
          ]
        },
        "decode": {
          "description": "解码(base64/base64url/hex/url)。",
          "anyOf": [
            {
              "$ref": "#/definitions/Codec"
            },
            {
              "type": "null"
            }
          ]
        },
        "encode": {
          "description": "编码(base64/base64url/hex/url)。",
          "anyOf": [
            {
              "$ref": "#/definitions/Codec"
            },
            {
              "type": "null"
            }
          ]
        },
        "fontMap": {
          "description": "字体反爬还原:私有区(PUA)字符按映射表换回真字。键为码点十六进制(如 `\"E4DE\"` 或 `\"U+E4DE\"`), 值为目标字符;表外字符原样保留。用于番茄等「自定义字体 + PUA」反爬站点——表是数据,由书源内联 提供(引擎不内置任何站点的表),可用 `trn gen-fontmap` 生成。",
          "type": [
            "object",
            "null"
          ],
          "additionalProperties": {
            "type": "string"
          }
        },
        "hash": {
          "description": "哈希/HMAC。",
          "anyOf": [
            {
              "$ref": "#/definitions/HashStep"
            },
            {
              "type": "null"
            }
          ]
        },
        "js": {
          "description": "JS 后处理(逃生舱;脚本里以当前串为 `result`)。需启用 `js` feature。",
          "type": [
            "string",
            "null"
          ]
        },
        "prepend": {
          "type": [
            "string",
            "null"
          ]
        },
        "regex": {
          "type": [
            "string",
            "null"
          ]
        },
        "replace": {
          "type": [
            "string",
            "null"
          ]
        },
        "trim": {
          "type": [
            "boolean",
            "null"
          ]
        }
      },
      "additionalProperties": false
    },
    "CnConvert": {
      "description": "繁简转换方向。",
      "oneOf": [
        {
          "description": "繁体 → 简体。",
          "type": "string",
          "enum": [
            "t2s"
          ]
        },
        {
          "description": "简体 → 繁体。",
          "type": "string",
          "enum": [
            "s2t"
          ]
        }
      ]
    },
    "Codec": {
      "description": "编解码方式(`decode`/`encode` 算子,以及 crypto 的字节↔串编码)。",
      "oneOf": [
        {
          "type": "string",
          "enum": [
            "base64",
            "base64url",
            "hex"
          ]
        },
        {
          "description": "URL 百分号编解码。",
          "type": "string",
          "enum": [
            "url"
          ]
        }
      ]
    },
    "ContentRules": {
      "description": "正文规则(可选分页)。",
      "type": "object",
      "required": [
        "value"
      ],
      "properties": {
        "maxPages": {
          "default": 100,
          "type": "integer",
          "format": "uint32",
          "minimum": 0.0
        },
        "nextPage": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "prelude": {
          "description": "正文主请求之前按序执行的前置请求链(见 design D7-bis);空 = 现状。",
          "type": "array",
          "items": {
            "$ref": "#/definitions/PreStep"
          }
        },
        "value": {
          "$ref": "#/definitions/Rule"
        }
      },
      "additionalProperties": false
    },
    "EntrySource": {
      "description": "入口源:静态固定入口 或 远端抓取入口。`explore.entries` 是其数组,按声明顺序合并 (无独立 chain 类型——「按序合并」即数组遍历)。与 [`Rule`] 一致用 untagged + 唯一键判别 (`static` / `fetch`)。",
      "anyOf": [
        {
          "description": "静态入口列表。",
          "type": "object",
          "required": [
            "static"
          ],
          "properties": {
            "static": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/StaticEntry"
              }
            }
          }
        },
        {
          "description": "远端抓取动态入口(`Box`:`FetchEntrySource` 含完整 `Request`,避免枚举变体尺寸悬殊; `Box<T>` 对 serde/schemars 透明,JSON 与 schema 形状不变)。",
          "type": "object",
          "required": [
            "fetch"
          ],
          "properties": {
            "fetch": {
              "$ref": "#/definitions/FetchEntrySource"
            }
          }
        }
      ]
    },
    "Expect": {
      "description": "样例期望不变量。",
      "type": "object",
      "properties": {
        "minChapters": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint",
          "minimum": 0.0
        },
        "minContentChars": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint",
          "minimum": 0.0
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "volumes": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint",
          "minimum": 0.0
        }
      }
    },
    "ExploreOp": {
      "description": "浏览操作:两阶段——`entries` 生成可选择的入口,`page` 用选中入口的变量取书。",
      "type": "object",
      "required": [
        "entries",
        "page"
      ],
      "properties": {
        "entries": {
          "description": "入口源数组(按声明顺序合并;static + fetch 组合)。",
          "type": "array",
          "items": {
            "$ref": "#/definitions/EntrySource"
          }
        },
        "page": {
          "description": "共享列表页规格:用选中入口变量 + page/pageSize 取书。",
          "allOf": [
            {
              "$ref": "#/definitions/ListPageSpec"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "Extract": {
      "description": "取值方式(枚举字符串 或 `{ \"attr\": \"...\" }`)。",
      "anyOf": [
        {
          "$ref": "#/definitions/ExtractOp"
        },
        {
          "type": "object",
          "required": [
            "attr"
          ],
          "properties": {
            "attr": {
              "type": "string"
            }
          }
        }
      ]
    },
    "ExtractOp": {
      "description": "文本/HTML 取值算子。",
      "type": "string",
      "enum": [
        "text",
        "ownText",
        "html",
        "innerHtml",
        "outerHtml"
      ]
    },
    "FetchEntryItem": {
      "description": "fetch 入口项的生成规则:标题 + 变量。两者对「当前数据项(ctx)+ 外层 forEach 变量(vars)」求值, 故 `title`/`vars` 规则既能 `via:json` 读数据项字段,也能 `{{name}}` 引用循环变量。",
      "type": "object",
      "required": [
        "title"
      ],
      "properties": {
        "title": {
          "$ref": "#/definitions/Rule"
        },
        "vars": {
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/Rule"
          }
        }
      },
      "additionalProperties": false
    },
    "FetchEntrySource": {
      "description": "远端抓取入口源:请求远端分类数据 → `list` 抽数组 → 每项经 `item` 生成入口。 可选 `forEach` 按多组变量重复请求并合并入口(空 = 执行一次)。",
      "type": "object",
      "required": [
        "item",
        "list",
        "request"
      ],
      "properties": {
        "forEach": {
          "description": "循环变量集:对每组变量各请求一次、合并结果;变量在请求模板与 `item` 规则中可见。空 = 一次。",
          "type": "array",
          "items": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          }
        },
        "item": {
          "$ref": "#/definitions/FetchEntryItem"
        },
        "list": {
          "description": "从响应抽取数据项数组(每项作为 `item` 规则的上下文)。",
          "allOf": [
            {
              "$ref": "#/definitions/Rule"
            }
          ]
        },
        "request": {
          "description": "入口数据请求(复用 [`Request`]:支持 render / interceptApi / charset / headers / 模板)。",
          "allOf": [
            {
              "$ref": "#/definitions/Request"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "FetchMode": {
      "description": "取页模式:是否动用浏览器解反爬挑战。 真正是否开浏览器还需 app/用户级授权(两级取交集,见 OpenSpec change `browser-fetcher` D12)。",
      "oneOf": [
        {
          "description": "默认:平时 reqwest,撞挑战才升级浏览器。",
          "type": "string",
          "enum": [
            "auto"
          ]
        },
        {
          "description": "永不开浏览器,撞挑战即降级。",
          "type": "string",
          "enum": [
            "reqwest"
          ]
        },
        {
          "description": "整站强制走浏览器(首请求即被挑战 / 整页 JS 渲染)。",
          "type": "string",
          "enum": [
            "browser"
          ]
        }
      ]
    },
    "HashAlgo": {
      "description": "哈希算法。",
      "type": "string",
      "enum": [
        "md5",
        "sha1",
        "sha256",
        "sha512"
      ]
    },
    "HashOut": {
      "description": "哈希/HMAC 输出编码。",
      "type": "string",
      "enum": [
        "hex",
        "base64"
      ]
    },
    "HashStep": {
      "description": "哈希算子(可选 HMAC)。",
      "type": "object",
      "required": [
        "algo"
      ],
      "properties": {
        "algo": {
          "$ref": "#/definitions/HashAlgo"
        },
        "hmacKey": {
          "description": "提供则计算 HMAC(以此为密钥)。",
          "type": [
            "string",
            "null"
          ]
        },
        "hmacKeyEnc": {
          "default": "utf8",
          "allOf": [
            {
              "$ref": "#/definitions/ByteEnc"
            }
          ]
        },
        "output": {
          "default": "hex",
          "allOf": [
            {
              "$ref": "#/definitions/HashOut"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "Http": {
      "description": "HTTP 配置块。",
      "type": "object",
      "properties": {
        "charset": {
          "default": "auto",
          "allOf": [
            {
              "$ref": "#/definitions/Charset"
            }
          ]
        },
        "cookies": {
          "description": "静态 cookie;也是运行时注入 clearance cookie 的落点。",
          "default": {},
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "fetcher": {
          "description": "取页模式(auto|reqwest|browser);默认 auto。",
          "default": "auto",
          "allOf": [
            {
              "$ref": "#/definitions/FetchMode"
            }
          ]
        },
        "headers": {
          "default": {},
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "rateLimit": {
          "anyOf": [
            {
              "$ref": "#/definitions/RateLimit"
            },
            {
              "type": "null"
            }
          ]
        },
        "retry": {
          "anyOf": [
            {
              "$ref": "#/definitions/Retry"
            },
            {
              "type": "null"
            }
          ]
        },
        "timeout": {
          "type": [
            "integer",
            "null"
          ],
          "format": "uint64",
          "minimum": 0.0
        },
        "warmup": {
          "description": "先 GET 这些页以预热会话 cookie。",
          "default": [],
          "type": "array",
          "items": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "LeafRule": {
      "description": "叶子规则:在当前上下文做一次抽取。",
      "type": "object",
      "properties": {
        "clean": {
          "type": "array",
          "items": {
            "$ref": "#/definitions/CleanStep"
          }
        },
        "extract": {
          "default": "text",
          "allOf": [
            {
              "$ref": "#/definitions/Extract"
            }
          ]
        },
        "index": {
          "type": [
            "integer",
            "null"
          ],
          "format": "int64"
        },
        "select": {
          "type": [
            "string",
            "null"
          ]
        },
        "via": {
          "default": "css",
          "allOf": [
            {
              "$ref": "#/definitions/Via"
            }
          ]
        }
      }
    },
    "ListPageSpec": {
      "description": "共享列表页规格:search 与 explore 取一页书共用。承载前置链、请求(render / interceptApi / readyFor / totalPages / hasMore / pageBy / vars 均在 [`Request`] 上)、列表选择与每项字段抽取。 引擎以 `run_list_page(spec, vars, page, page_size)` 统一执行。\n\n这正是历史 `SearchOp` 的形状——前序 change 已把全部取页旋钮收敛到 [`Request`],故 search/explore 共用同一规格,无需各维护一套列表求值分支。",
      "type": "object",
      "required": [
        "item",
        "list",
        "request"
      ],
      "properties": {
        "item": {
          "$ref": "#/definitions/BookRules"
        },
        "list": {
          "$ref": "#/definitions/Rule"
        },
        "prelude": {
          "description": "主请求之前按序执行的前置请求链(见 design D7-bis);空 = 单发(现状)。",
          "type": "array",
          "items": {
            "$ref": "#/definitions/PreStep"
          }
        },
        "request": {
          "$ref": "#/definitions/Request"
        }
      },
      "additionalProperties": false
    },
    "Method": {
      "description": "HTTP 方法。",
      "type": "string",
      "enum": [
        "GET",
        "POST"
      ]
    },
    "Padding": {
      "description": "填充方式(gcm 忽略)。",
      "type": "string",
      "enum": [
        "pkcs7",
        "zero",
        "none"
      ]
    },
    "PageBy": {
      "description": "点击驱动翻页策略(`search-click-pagination`):URL 不认页码的 SPA(如番茄 search)翻页只能点 分页器「下一页」,不能靠 `{{page}}` 改 URL。配在可渲染 + 拦截(`render` + `interceptApi`)的 `Request` 上,`page > 1` 时引擎在**一张活页**内点 `click` 选择器 `page-1` 次翻到目标页。 用 `{ click: ... }` 形(留 `by` 扩展位、语义自描述),当前只 `click` 一支。",
      "type": "object",
      "required": [
        "click"
      ],
      "properties": {
        "click": {
          "description": "「下一页」控件的 CSS 选择器(如番茄 `.byte-pagination .byte-pagination-item-icon:has(.byte-icon-right)`)。",
          "type": "string"
        }
      },
      "additionalProperties": false
    },
    "PreStep": {
      "description": "前置请求链中的一步:一个请求 + 其响应上的有序命名捕获(见 design D7-bis)。 本步 url/headers/body 可引用更早步骤捕获的 `{{name}}`。显式列字段(**不**用 `#[serde(flatten)]` 内嵌 [`Request`]:`Rule` 为 untagged 兜底,flatten 会令 `deny_unknown_fields` 校验失效)。",
      "type": "object",
      "required": [
        "url"
      ],
      "properties": {
        "body": {
          "anyOf": [
            {
              "$ref": "#/definitions/UrlOrRule"
            },
            {
              "type": "null"
            }
          ]
        },
        "capture": {
          "description": "本步响应上的有序命名捕获(按数组顺序求值;`capture[i]` 可引用 `capture[0..i]`)。",
          "type": "array",
          "items": {
            "$ref": "#/definitions/Capture"
          }
        },
        "headers": {
          "description": "请求头(值支持 `{{name}}` 模板,便于带 `Authorization: Bearer {{token}}`)。",
          "default": {},
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "method": {
          "default": "GET",
          "allOf": [
            {
              "$ref": "#/definitions/Method"
            }
          ]
        },
        "skipIfPresent": {
          "description": "惰性短路:列出的 key 在作用域内**全部非空**则跳过本步(token 复用,避免每章重抓)。",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "url": {
          "$ref": "#/definitions/UrlOrRule"
        }
      },
      "additionalProperties": false
    },
    "RateLimit": {
      "description": "速率限制。",
      "type": "object",
      "required": [
        "maxCount",
        "perMs"
      ],
      "properties": {
        "maxCount": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0.0
        },
        "perMs": {
          "type": "integer",
          "format": "uint64",
          "minimum": 0.0
        }
      },
      "additionalProperties": false
    },
    "Request": {
      "description": "单个请求。",
      "type": "object",
      "required": [
        "url"
      ],
      "properties": {
        "body": {
          "anyOf": [
            {
              "$ref": "#/definitions/UrlOrRule"
            },
            {
              "type": "null"
            }
          ]
        },
        "hasMore": {
          "description": "翻页边界规则(`list-has-more`):对取页结果求值「是否还有下一页」(非空且非 `false`/`0` → 有)。 源路由同 `total_pages`(按 `via`)。空 = 不提供边界(UI 不限制)。",
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "headers": {
          "default": {},
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        },
        "interceptApi": {
          "description": "CDP 拦截:渲染时拦截 URL 含此子串的响应体作为取页 body(交 `via:\"json\"` 规则)。 用于「结果只在签名 API、DOM 无关键字段」的站点(典型:番茄搜索 `search_book/v1`)。 可与 `ready_for` 共存(见上)。",
          "type": [
            "string",
            "null"
          ]
        },
        "method": {
          "default": "GET",
          "allOf": [
            {
              "$ref": "#/definitions/Method"
            }
          ]
        },
        "pageBy": {
          "description": "点击驱动翻页(`search-click-pagination`):URL 不认页码的 SPA(如番茄 search)靠点分页器 「下一页」递增页码。配 `render` + `interceptApi` 且 `page > 1` 时,引擎在一张活页内点 `pageBy.click` 选择器 `page-1` 次翻到目标页、拦该页 API 响应。空 = 现状(单拦截 / `{{page}}` URL 模板翻页),逐字节不变。",
          "anyOf": [
            {
              "$ref": "#/definitions/PageBy"
            },
            {
              "type": "null"
            }
          ]
        },
        "readyFor": {
          "description": "渲染就绪等待选择器。两种用法: - **无 `interceptApi`**:渲染后轮询该选择器出现,取渲染后 DOM 交 CSS 规则(方式 A); - **与 `interceptApi` 共存**(`render-dual-source`):拦 API 取 body 之外,等该选择器出现后 另抓渲染 DOM,供 `via:css` 的 `totalPages` 等对 DOM 求值(如分页器总页数)。",
          "type": [
            "string",
            "null"
          ]
        },
        "render": {
          "description": "渲染型取页(`render-fetcher`):为真则用受控浏览器渲染本请求 URL、跑站点自身 JS, 而非 reqwest 直取——用于 SPA 站点(结果由 JS 渲染 / 签名 API 返回)。默认 false = 现状。 仅 `browser` feature 且浏览器可用时生效;否则该 op 优雅降级。",
          "type": "boolean"
        },
        "totalPages": {
          "description": "精确总页数规则(`render-dual-source`):对取页结果求值得「共 M 页」(search 翻页进度)。 `via:json` 对 API body 求值;`via:css`/`xpath` 对渲染 DOM 求值(需 `interceptApi` + `ready_for` 共存,抓到 DOM 才有源)。空 = 不返回总数(现状)。",
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "url": {
          "$ref": "#/definitions/UrlOrRule"
        },
        "vars": {
          "description": "命名捕获:对**本请求响应**每个 `(name, Rule)` 求值,写入 `chapter` 层(等价 `scope=chapter` 的 [`Capture`]),使本 op 的 list/item 与后续步骤以 `{{name}}` 引用。见 design D7-bis。 各条**独立**对响应求值(可引用 `base`/`key`/`page` 与前置 `prelude` 捕获,但**勿互相引用**: 需有序依赖请用 `prelude` 链)。用 `BTreeMap` 保证迭代/落点顺序确定(免哈希随机化幽灵 bug)。",
          "type": "object",
          "additionalProperties": {
            "$ref": "#/definitions/Rule"
          }
        }
      },
      "additionalProperties": false
    },
    "Retry": {
      "description": "重试策略。",
      "type": "object",
      "properties": {
        "backoffMs": {
          "default": 0,
          "type": "integer",
          "format": "uint64",
          "minimum": 0.0
        },
        "max": {
          "default": 0,
          "type": "integer",
          "format": "uint32",
          "minimum": 0.0
        }
      },
      "additionalProperties": false
    },
    "RowUi": {
      "description": "声明式登录表单的一行(TUI 渲染对应控件,收集值加密存为 loginInfo)。",
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "description": "字段名(也是 loginInfo 中的 key)。",
          "type": "string"
        },
        "options": {
          "description": "`select` 类型的候选项。",
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "type": {
          "default": "text",
          "allOf": [
            {
              "$ref": "#/definitions/RowUiType"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "RowUiType": {
      "description": "声明式登录表单项类型。",
      "oneOf": [
        {
          "description": "单行文本。",
          "type": "string",
          "enum": [
            "text"
          ]
        },
        {
          "description": "密码(TUI 掩码显示)。",
          "type": "string",
          "enum": [
            "password"
          ]
        },
        {
          "description": "下拉选择(配合 `options`)。",
          "type": "string",
          "enum": [
            "select"
          ]
        },
        {
          "description": "布尔开关。",
          "type": "string",
          "enum": [
            "toggle"
          ]
        }
      ]
    },
    "Rule": {
      "description": "一条规则:叶子,或组合子。组合子按其唯一键判别(见 design D1)。\n\n反序列化时按变体顺序尝试:组合子(各有唯一必填键)在前,叶子兜底。",
      "anyOf": [
        {
          "description": "取首个非空子规则结果(回退/自愈)。",
          "type": "object",
          "required": [
            "firstOf"
          ],
          "properties": {
            "firstOf": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Rule"
              }
            }
          }
        },
        {
          "description": "拼接非空子规则结果。",
          "type": "object",
          "required": [
            "concat"
          ],
          "properties": {
            "concat": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Rule"
              }
            },
            "join": {
              "default": "",
              "type": "string"
            }
          }
        },
        {
          "description": "字面量。",
          "type": "object",
          "required": [
            "literal"
          ],
          "properties": {
            "literal": {
              "type": "string"
            }
          }
        },
        {
          "description": "模板插值(`{{key}}`/`{{page}}`/命名变量)。",
          "type": "object",
          "required": [
            "template"
          ],
          "properties": {
            "template": {
              "type": "string"
            }
          }
        },
        {
          "description": "JS 逻辑编排逃生舱(值规则):以当前上下文为 `result`、注入 `baseUrl`/变量 + `crypto` 助手求值,返回字符串。求值需启用 `js` feature(否则返回 `Unsupported(\"js\")`)。 必须置于 `Leaf` 之前——`js` 是其唯一判别键,否则会被全可选的 `Leaf` 吞掉。",
          "type": "object",
          "required": [
            "js"
          ],
          "properties": {
            "js": {
              "type": "string"
            }
          }
        },
        {
          "description": "叶子(兜底)。",
          "allOf": [
            {
              "$ref": "#/definitions/LeafRule"
            }
          ]
        }
      ]
    },
    "Sample": {
      "description": "黄金样例。",
      "type": "object",
      "required": [
        "bookUrl"
      ],
      "properties": {
        "bookUrl": {
          "type": "string"
        },
        "expect": {
          "default": {},
          "allOf": [
            {
              "$ref": "#/definitions/Expect"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    "StaticEntry": {
      "description": "一个静态入口:固定标题 + 取页变量(字面量)。供「全部·最热」这类固定入口声明。",
      "type": "object",
      "required": [
        "title"
      ],
      "properties": {
        "title": {
          "type": "string"
        },
        "vars": {
          "description": "取页变量:与 base/page/pageSize 合并后运行 `explore.page`。值为字面量。",
          "type": "object",
          "additionalProperties": {
            "type": "string"
          }
        }
      },
      "additionalProperties": false
    },
    "TocRules": {
      "description": "目录规则(章节 + 分卷 + 可选分页)。",
      "type": "object",
      "required": [
        "list",
        "name",
        "url"
      ],
      "properties": {
        "isVolume": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "list": {
          "$ref": "#/definitions/Rule"
        },
        "maxPages": {
          "default": 100,
          "type": "integer",
          "format": "uint32",
          "minimum": 0.0
        },
        "name": {
          "$ref": "#/definitions/Rule"
        },
        "nextPage": {
          "anyOf": [
            {
              "$ref": "#/definitions/Rule"
            },
            {
              "type": "null"
            }
          ]
        },
        "prelude": {
          "description": "目录主请求之前按序执行的前置请求链(见 design D7-bis);空 = 现状。",
          "type": "array",
          "items": {
            "$ref": "#/definitions/PreStep"
          }
        },
        "url": {
          "$ref": "#/definitions/Rule"
        }
      },
      "additionalProperties": false
    },
    "UrlOrRule": {
      "description": "URL 字段:可为字符串模板,或一条规则。",
      "anyOf": [
        {
          "type": "string"
        },
        {
          "$ref": "#/definitions/Rule"
        }
      ]
    },
    "VarScope": {
      "description": "多步编排:捕获变量的作用域(三级级联 章节→书籍→书源,见 design D7-bis)。 默认 `Chapter`——最短寿命、零持久、零跨书外溢;`get` 时按 章节→书籍→书源 取第一个非空。",
      "oneOf": [
        {
          "description": "仅本次 op 调用(search/explore/bookInfo/toc/content)内存活,调用结束消亡(默认)。 一次性 csrf/sign/cursor 用它。",
          "type": "string",
          "enum": [
            "chapter"
          ]
        },
        {
          "description": "随 per-book 快照持久化(由 app 注入·导出);如详情/列表 token 复用到 toc/content。 注意:**search/explore 的 `prelude` 阶段尚无 per-book 载体**(用户选书后才建 per-book 引擎), 在那里用 `book` 会写进会被丢弃的实例 → 静默无效;search 阶段的 token 请用 `source`/`chapter`。",
          "type": "string",
          "enum": [
            "book"
          ]
        },
        {
          "description": "书源级长存(引擎内跨 op 共享);如全站 API host/版本/全站 csrf。 跨会话持久仅在 app 接线落盘时保证(默认构建为进程内)。",
          "type": "string",
          "enum": [
            "source"
          ]
        }
      ]
    },
    "Via": {
      "description": "抽取后端(决定 `select` 的语义)。",
      "oneOf": [
        {
          "type": "string",
          "enum": [
            "css",
            "xpath",
            "json",
            "regex"
          ]
        },
        {
          "description": "直接使用当前上下文值(只跑 clean)。",
          "type": "string",
          "enum": [
            "raw"
          ]
        }
      ]
    }
  }
}