Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/si/harvester/test.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / si / harvester / test.om` 1150 lines ยท 21329 bytes Raw Blame History 1 om2 2 note si/harvester/test.om: Standalone OM-2 behavioral test suite for zero-telemetry harvester. 3 note Tests markdown heading/code-fence/metadata/link extraction, / reasoning & scoring, 4 note telemetry domain rejection, tracking query parameter stripping, unsafe scheme refusal, 5 note SHA-256 link deduplication, and RFC 8259 JSONL escaping. 6 7 global inbuf uchar 32768 8 global outbuf uchar 32768 9 global urlbuf uchar 512 10 global cleanurl uchar 512 11 global decbuf uchar 32 12 global stats ulong 16 13 global shastate uint 8 14 global shak uint 64 15 global shaw uint 64 16 global shablk uchar 64 17 global shadig uchar 32 18 global shahex uchar 64 19 global seenfp uchar 4096 20 21 const st_inlen ulong 0 22 const st_outlen ulong 1 23 const st_heads ulong 2 24 const st_blocks ulong 3 25 const st_links ulong 4 26 const st_telrej ulong 5 27 const st_strip ulong 6 28 const st_meta ulong 7 29 const st_reas ulong 8 30 const st_qual ulong 9 31 const st_clen ulong 10 32 const st_seencnt ulong 11 33 const st_dedup ulong 12 34 35 text khex "`0123456789abcdef`" 36 text j_head1 "{\"type\":\"heading\",\"level\":" 37 text j_text ",\"text\":\"" 38 text j_link1 "{\"type\":\"link\",\"text\":\"" 39 text j_url "\",\"url\":\"" 40 text j_meta1 "{\"type\":\"meta\",\"key\":\"" 41 text j_val "\",\"value\":\"" 42 text j_reas1 "{\"type\":\"reasoning\",\"tokens\":" 43 text j_qm ",\"quality_milli\":" 44 text j_sum1 "{\"type\":\"summary\",\"headings\":" 45 text j_sum2 ",\"code_blocks\":" 46 text j_sum3 ",\"links\":" 47 text j_sum4 ",\"telemetry_rejected\":" 48 text j_sum5 ",\"tracking_stripped\":" 49 text j_sum6 ",\"meta\":" 50 text j_sum7 ",\"reasoning\":" 51 text j_sum8 ",\"quality_milli\":" 52 text j_sum9 ",\"sha256\":\"" 53 text j_end "\"}\n" 54 55 text t_fence "```" 56 text t_think_o "" 57 text t_think_c "" 58 text t_thought_o "" 59 text t_thought_c "" 60 text t_kw_step "step" 61 text t_kw_ver "verify" 62 text t_kw_bigo "O(" 63 64 text mk_title "title:" 65 text mk_author "author:" 66 text mk_lic "license:" 67 text mk_pin "pin:" 68 text mk_src "source:" 69 text mk_date "date:" 70 text mk_ver "version:" 71 text mk_prov "provider:" 72 text mk_mod "model:" 73 74 text td_ga "google-analytics.com" 75 text td_gtm "googletagmanager.com" 76 text td_dc "doubleclick.net" 77 text td_mp "mixpanel.com" 78 text td_sg1 "segment.io" 79 text td_sg2 "segment.com" 80 text td_amp "amplitude.com" 81 text td_hj "hotjar.com" 82 text td_fb "facebook.com/tr" 83 text td_tel "telemetry." 84 text td_ana "analytics." 85 text td_pix "pixel." 86 text td_bea "beacon." 87 text td_js "javascript:" 88 text td_dat "data:" 89 90 text qp_utm "utm_" 91 text qp_fb "fbclid=" 92 text qp_gc "gclid=" 93 text qp_mc "mc_eid=" 94 95 note Test inputs 96 text doc_pos_a "title: Omega Pure Stack\nlicense: Apache-2.0\n# Main Title\n## Section Two\nSee [Omega](https://interplane.io/omega/).\n```omega\n# Not a heading\n[Ignored](https://interplane.io/ignored)\n```\n" 97 text doc_pos_b "### Section Three\n```\ncode block two\n```\nStep 1: verify O(N) extraction with deterministic zero-telemetry output.\n" 98 99 text doc_tel "[A](https://www.google-analytics.com/collect?v=1)\n[B](https://api.segment.io/v1/t)\n[C](https://mixpanel.com/track)\n[D](https://telemetry.example.com/ping)\n" 100 text doc_strip "[Keep](https://interplane.io/docs?id=42&utm_source=x&fbclid=y)\n[Pure](https://interplane.io/clean?utm_campaign=z&gclid=w)\n" 101 text doc_unsafe "[X](javascript:alert(1))\n[Y](data:text/html,hi)\n" 102 text doc_dedup "[One](https://interplane.io/Omega?utm_source=a)\n[Two](https://INTERPLANE.IO/omega?fbclid=b)\n" 103 text doc_esc "# Say \"Hi\" \\ Now\n" 104 text doc_short_thought "short\n" 105 106 text exp_clean1 "\"url\":\"https://interplane.io/docs?id=42\"" 107 text exp_clean2 "\"url\":\"https://interplane.io/clean\"" 108 text exp_esc "\"text\":\"Say \\\"Hi\\\" \\\\ Now\"" 109 110 text p_1 "PASS pos_markdown_headings_fences_meta_reasoning\n" 111 text p_2 "PASS neg_telemetry_domains_rejected\n" 112 text p_3 "PASS neg_tracking_query_params_stripped\n" 113 text p_4 "PASS neg_unsafe_url_schemes_rejected\n" 114 text p_5 "PASS dedup_sha256_case_and_tracking_invariant\n" 115 text p_6 "PASS jsonl_quote_and_backslash_escaping\n" 116 text p_7 "PASS reasoning_quality_scoring_boundaries\n" 117 text p_all "HARVESTER TEST SUITE PASS (7/7)\n" 118 text f_msg "FAIL test case " 119 text t_nl "\n" 120 121 fn write_all fd int src view uchar * off ulong n ulong to void 122 p = ulong 0 123 while lt p n bound 4096 124 k = write fd src add off p sub n p 125 if le k 0 126 exit 2 127 end 128 p = add p ulong k 129 end 130 end 131 132 fn wstr fd int s view uchar * to void 133 write_all fd s 0 len s 134 end 135 136 fn wdec fd int v ulong to void 137 i = ulong 32 138 n = v 139 while true bound 24 140 i = sub i 1 141 put decbuf i uchar add rem n 10 48 142 n = div n 10 143 if eq n 0 144 break 145 end 146 end 147 p = i 148 while lt p 32 bound 32 149 k = write fd decbuf p sub 32 p 150 if le k 0 151 exit 2 152 end 153 p = add p ulong k 154 end 155 end 156 157 fn fail_case id ulong to void 158 wstr 2 f_msg 159 wdec 2 id 160 wstr 2 t_nl 161 exit 1 162 end 163 164 fn to_lower c uchar to uchar 165 if and ge c 65 le c 90 166 ret add c 32 167 end 168 ret c 169 end 170 171 fn in_reset to void 172 put stats st_inlen 0 173 end 174 175 fn in_append s view uchar * to void 176 tot = get stats st_inlen 177 n = len s 178 i = ulong 0 179 while lt i n bound 4096 180 put inbuf add tot i get s i 181 i = add i 1 182 end 183 put stats st_inlen add tot n 184 end 185 186 fn out_push_ch c uchar to void 187 p = get stats st_outlen 188 if lt p 32768 189 put outbuf p c 190 put stats st_outlen add p 1 191 end 192 end 193 194 fn out_push_lit s view uchar * to void 195 sl = len s 196 i = ulong 0 197 while lt i sl bound 1024 198 out_push_ch get s i 199 i = add i 1 200 end 201 end 202 203 fn out_push_dec v ulong to void 204 i = ulong 32 205 n = v 206 while true bound 24 207 i = sub i 1 208 put decbuf i uchar add rem n 10 48 209 n = div n 10 210 if eq n 0 211 break 212 end 213 end 214 p = i 215 while lt p 32 bound 32 216 out_push_ch get decbuf p 217 p = add p 1 218 end 219 end 220 221 fn out_push_json_ch c uchar to void 222 if eq c 34 223 out_push_ch 92 224 out_push_ch 34 225 ret 226 end 227 if eq c 92 228 out_push_ch 92 229 out_push_ch 92 230 ret 231 end 232 if eq c 10 233 out_push_ch 92 234 out_push_ch 110 235 ret 236 end 237 if eq c 13 238 out_push_ch 92 239 out_push_ch 114 240 ret 241 end 242 if eq c 9 243 out_push_ch 92 244 out_push_ch 116 245 ret 246 end 247 if ge c 32 248 out_push_ch c 249 end 250 end 251 252 fn out_push_in_json off ulong n ulong to void 253 i = ulong 0 254 while lt i n bound 32768 255 if lt add off i 32768 256 out_push_json_ch get inbuf add off i 257 end 258 i = add i 1 259 end 260 end 261 262 fn out_push_cleanurl_json to void 263 n = get stats st_clen 264 i = ulong 0 265 while lt i n bound 512 266 out_push_json_ch get cleanurl i 267 i = add i 1 268 end 269 end 270 271 fn out_push_shahex to void 272 for i ulong 64 273 out_push_ch get shahex i 274 end 275 end 276 277 fn out_starts_at pos ulong needle view uchar * to bool 278 nl = len needle 279 tot = get stats st_outlen 280 if gt add pos nl tot 281 ret false 282 end 283 i = ulong 0 284 while lt i nl bound 256 285 if ne get outbuf add pos i get needle i 286 ret false 287 end 288 i = add i 1 289 end 290 ret true 291 end 292 293 fn out_contains needle view uchar * to bool 294 nl = len needle 295 tot = get stats st_outlen 296 if gt nl tot 297 ret false 298 end 299 lim = add sub tot nl 1 300 i = ulong 0 301 while lt i lim bound 32768 302 if out_starts_at i needle 303 ret true 304 end 305 i = add i 1 306 end 307 ret false 308 end 309 310 fn sha_kinit to void 311 put shak 0 0x428a2f98 312 put shak 1 0x71374491 313 put shak 2 0xb5c0fbcf 314 put shak 3 0xe9b5dba5 315 put shak 4 0x3956c25b 316 put shak 5 0x59f111f1 317 put shak 6 0x923f82a4 318 put shak 7 0xab1c5ed5 319 put shak 8 0xd807aa98 320 put shak 9 0x12835b01 321 put shak 10 0x243185be 322 put shak 11 0x550c7dc3 323 put shak 12 0x72be5d74 324 put shak 13 0x80deb1fe 325 put shak 14 0x9bdc06a7 326 put shak 15 0xc19bf174 327 put shak 16 0xe49b69c1 328 put shak 17 0xefbe4786 329 put shak 18 0x0fc19dc6 330 put shak 19 0x240ca1cc 331 put shak 20 0x2de92c6f 332 put shak 21 0x4a7484aa 333 put shak 22 0x5cb0a9dc 334 put shak 23 0x76f988da 335 put shak 24 0x983e5152 336 put shak 25 0xa831c66d 337 put shak 26 0xb00327c8 338 put shak 27 0xbf597fc7 339 put shak 28 0xc6e00bf3 340 put shak 29 0xd5a79147 341 put shak 30 0x06ca6351 342 put shak 31 0x14292967 343 put shak 32 0x27b70a85 344 put shak 33 0x2e1b2138 345 put shak 34 0x4d2c6dfc 346 put shak 35 0x53380d13 347 put shak 36 0x650a7354 348 put shak 37 0x766a0abb 349 put shak 38 0x81c2c92e 350 put shak 39 0x92722c85 351 put shak 40 0xa2bfe8a1 352 put shak 41 0xa81a664b 353 put shak 42 0xc24b8b70 354 put shak 43 0xc76c51a3 355 put shak 44 0xd192e819 356 put shak 45 0xd6990624 357 put shak 46 0xf40e3585 358 put shak 47 0x106aa070 359 put shak 48 0x19a4c116 360 put shak 49 0x1e376c08 361 put shak 50 0x2748774c 362 put shak 51 0x34b0bcb5 363 put shak 52 0x391c0cb3 364 put shak 53 0x4ed8aa4a 365 put shak 54 0x5b9cca4f 366 put shak 55 0x682e6ff3 367 put shak 56 0x748f82ee 368 put shak 57 0x78a5636f 369 put shak 58 0x84c87814 370 put shak 59 0x8cc70208 371 put shak 60 0x90befffa 372 put shak 61 0xa4506ceb 373 put shak 62 0xbef9a3f7 374 put shak 63 0xc67178f2 375 end 376 377 fn sha_iv to void 378 put shastate 0 0x6a09e667 379 put shastate 1 0xbb67ae85 380 put shastate 2 0x3c6ef372 381 put shastate 3 0xa54ff53a 382 put shastate 4 0x510e527f 383 put shastate 5 0x9b05688c 384 put shastate 6 0x1f83d9ab 385 put shastate 7 0x5be0cd19 386 end 387 388 fn sha_sched to void 389 for i ulong 16 390 q = mul i 4 391 x = uint get shablk q 392 x = or shl x 8 uint get shablk add q 1 393 x = or shl x 8 uint get shablk add q 2 394 put shaw i or shl x 8 uint get shablk add q 3 395 end 396 for i ulong 48 397 x = get shaw add i 1 398 y = get shaw add i 14 399 s0 = xor xor rotr x 7 rotr x 18 shr x 3 400 s1 = xor xor rotr y 17 rotr y 19 shr y 10 401 put shaw add i 16 add add get shaw i get shaw add i 9 add s0 s1 402 end 403 end 404 405 fn sha_compress to void 406 sha_sched 407 a = get shastate 0 408 b = get shastate 1 409 c = get shastate 2 410 d = get shastate 3 411 e = get shastate 4 412 f = get shastate 5 413 g = get shastate 6 414 h = get shastate 7 415 t = uint 0 416 for i ulong 64 417 h = add h get shak i 418 h = add h get shaw i 419 t = xor rotr e 6 rotr e 11 420 t = xor t rotr e 25 421 h = add h t 422 h = add h xor g and e xor f g 423 d = add d h 424 t = xor rotr a 2 rotr a 13 425 t = xor t rotr a 22 426 h = add h t 427 h = add h or and a b and c or a b 428 t = h 429 h = g 430 g = f 431 f = e 432 e = d 433 d = c 434 c = b 435 b = a 436 a = t 437 end 438 put shastate 0 add get shastate 0 a 439 put shastate 1 add get shastate 1 b 440 put shastate 2 add get shastate 2 c 441 put shastate 3 add get shastate 3 d 442 put shastate 4 add get shastate 4 e 443 put shastate 5 add get shastate 5 f 444 put shastate 6 add get shastate 6 g 445 put shastate 7 add get shastate 7 h 446 end 447 448 fn sha_finalize_hex to void 449 for i ulong 8 450 w = get shastate i 451 q = mul i 4 452 put shadig q uchar and shr w 24 255 453 put shadig add q 1 uchar and shr w 16 255 454 put shadig add q 2 uchar and shr w 8 255 455 put shadig add q 3 uchar and w 255 456 end 457 for i ulong 32 458 bv = ulong get shadig i 459 put shahex mul i 2 get khex shr bv 4 460 put shahex add mul i 2 1 get khex and bv 15 461 end 462 end 463 464 fn sha256_inbuf to void 465 dlen = get stats st_inlen 466 sha_kinit 467 sha_iv 468 off = ulong 0 469 while ge sub dlen off 64 bound 1024 470 for j ulong 64 471 put shablk j get inbuf add off j 472 end 473 sha_compress 474 off = add off 64 475 end 476 remn = sub dlen off 477 for j ulong 64 478 if lt j remn 479 put shablk j get inbuf add off j 480 else 481 put shablk j 0 482 end 483 end 484 put shablk remn 0x80 485 if gt remn 55 486 sha_compress 487 for j ulong 64 488 put shablk j 0 489 end 490 end 491 bits = mul dlen 8 492 put shablk 56 uchar and shr bits 56 255 493 put shablk 57 uchar and shr bits 48 255 494 put shablk 58 uchar and shr bits 40 255 495 put shablk 59 uchar and shr bits 32 255 496 put shablk 60 uchar and shr bits 24 255 497 put shablk 61 uchar and shr bits 16 255 498 put shablk 62 uchar and shr bits 8 255 499 put shablk 63 uchar and bits 255 500 sha_compress 501 sha_finalize_hex 502 end 503 504 fn sha256_cleanurl to void 505 dlen = get stats st_clen 506 sha_kinit 507 sha_iv 508 off = ulong 0 509 while ge sub dlen off 64 bound 16 510 for j ulong 64 511 put shablk j to_lower get cleanurl add off j 512 end 513 sha_compress 514 off = add off 64 515 end 516 remn = sub dlen off 517 for j ulong 64 518 if lt j remn 519 put shablk j to_lower get cleanurl add off j 520 else 521 put shablk j 0 522 end 523 end 524 put shablk remn 0x80 525 if gt remn 55 526 sha_compress 527 for j ulong 64 528 put shablk j 0 529 end 530 end 531 bits = mul dlen 8 532 put shablk 56 uchar and shr bits 56 255 533 put shablk 57 uchar and shr bits 48 255 534 put shablk 58 uchar and shr bits 40 255 535 put shablk 59 uchar and shr bits 32 255 536 put shablk 60 uchar and shr bits 24 255 537 put shablk 61 uchar and shr bits 16 255 538 put shablk 62 uchar and shr bits 8 255 539 put shablk 63 uchar and bits 255 540 sha_compress 541 sha_finalize_hex 542 end 543 544 fn dedup_insert_cleanurl to bool 545 sha256_cleanurl 546 cnt = get stats st_seencnt 547 k = ulong 0 548 while lt k cnt bound 64 549 base = mul k 64 550 same = true 551 for i ulong 64 552 if ne get seenfp add base i get shahex i 553 same = false 554 end 555 end 556 if same 557 put stats st_dedup add get stats st_dedup 1 558 ret false 559 end 560 k = add k 1 561 end 562 if lt cnt 64 563 base2 = mul cnt 64 564 for i ulong 64 565 put seenfp add base2 i get shahex i 566 end 567 put stats st_seencnt add cnt 1 568 end 569 ret true 570 end 571 572 fn in_starts_ci off ulong lim ulong pat view uchar * to bool 573 pl = len pat 574 if gt add off pl lim 575 ret false 576 end 577 i = ulong 0 578 while lt i pl bound 64 579 if ne to_lower get inbuf add off i to_lower get pat i 580 ret false 581 end 582 i = add i 1 583 end 584 ret true 585 end 586 587 fn in_contains_ci off ulong lim ulong pat view uchar * to bool 588 pl = len pat 589 if lt sub lim off pl 590 ret false 591 end 592 endp = add sub lim pl 1 593 p = off 594 while lt p endp bound 32768 595 if in_starts_ci p lim pat 596 ret true 597 end 598 p = add p 1 599 end 600 ret false 601 end 602 603 fn url_starts_ci pos ulong ulen ulong pat view uchar * to bool 604 pl = len pat 605 if gt add pos pl ulen 606 ret false 607 end 608 i = ulong 0 609 while lt i pl bound 64 610 if ne to_lower get urlbuf add pos i to_lower get pat i 611 ret false 612 end 613 i = add i 1 614 end 615 ret true 616 end 617 618 fn url_contains_ci ulen ulong pat view uchar * to bool 619 pl = len pat 620 if gt pl ulen 621 ret false 622 end 623 lim = add sub ulen pl 1 624 i = ulong 0 625 while lt i lim bound 512 626 if url_starts_ci i ulen pat 627 ret true 628 end 629 i = add i 1 630 end 631 ret false 632 end 633 634 fn is_telemetry_url ulen ulong to bool 635 if url_starts_ci 0 ulen td_js 636 ret true 637 end 638 if url_starts_ci 0 ulen td_dat 639 ret true 640 end 641 if url_contains_ci ulen td_ga 642 ret true 643 end 644 if url_contains_ci ulen td_gtm 645 ret true 646 end 647 if url_contains_ci ulen td_dc 648 ret true 649 end 650 if url_contains_ci ulen td_mp 651 ret true 652 end 653 if url_contains_ci ulen td_sg1 654 ret true 655 end 656 if url_contains_ci ulen td_sg2 657 ret true 658 end 659 if url_contains_ci ulen td_amp 660 ret true 661 end 662 if url_contains_ci ulen td_hj 663 ret true 664 end 665 if url_contains_ci ulen td_fb 666 ret true 667 end 668 if url_contains_ci ulen td_tel 669 ret true 670 end 671 if url_contains_ci ulen td_ana 672 ret true 673 end 674 if url_contains_ci ulen td_pix 675 ret true 676 end 677 ret url_contains_ci ulen td_bea 678 end 679 680 fn is_tracking_param pos ulong lim ulong to bool 681 if url_starts_ci pos lim qp_utm 682 ret true 683 end 684 if url_starts_ci pos lim qp_fb 685 ret true 686 end 687 if url_starts_ci pos lim qp_gc 688 ret true 689 end 690 ret url_starts_ci pos lim qp_mc 691 end 692 693 fn strip_tracking_params ulen ulong to void 694 qpos = ulen 695 i = ulong 0 696 while lt i ulen bound 512 697 if eq get urlbuf i 63 698 qpos = i 699 break 700 end 701 i = add i 1 702 end 703 cl = ulong 0 704 j = ulong 0 705 while lt j qpos bound 512 706 put cleanurl cl get urlbuf j 707 cl = add cl 1 708 j = add j 1 709 end 710 if eq qpos ulen 711 put stats st_clen cl 712 ret 713 end 714 first_q = true 715 pos = add qpos 1 716 while lt pos ulen bound 512 717 ps = pos 718 while lt pos ulen bound 512 719 if eq get urlbuf pos 38 720 break 721 end 722 pos = add pos 1 723 end 724 if is_tracking_param ps pos 725 put stats st_strip add get stats st_strip 1 726 else 727 if gt pos ps 728 if first_q 729 put cleanurl cl 63 730 cl = add cl 1 731 first_q = false 732 else 733 put cleanurl cl 38 734 cl = add cl 1 735 end 736 k = ps 737 while lt k pos bound 512 738 if lt cl 512 739 put cleanurl cl get urlbuf k 740 cl = add cl 1 741 end 742 k = add k 1 743 end 744 end 745 end 746 if lt pos ulen 747 pos = add pos 1 748 end 749 end 750 put stats st_clen cl 751 end 752 753 fn extract_links_on_line ls ulong le_pos ulong to void 754 p = ls 755 while lt p le_pos bound 32768 756 if eq get inbuf p 91 757 ts = add p 1 758 te = ts 759 while lt te le_pos bound 32768 760 if eq get inbuf te 93 761 break 762 end 763 te = add te 1 764 end 765 if and lt add te 2 le_pos eq get inbuf add te 1 40 766 us = add te 2 767 ue = us 768 while lt ue le_pos bound 32768 769 if eq get inbuf ue 41 770 break 771 end 772 ue = add ue 1 773 end 774 if and lt ue le_pos gt ue us 775 ul = sub ue us 776 if gt ul 511 777 ul = ulong 511 778 end 779 k = ulong 0 780 while lt k ul bound 512 781 put urlbuf k get inbuf add us k 782 k = add k 1 783 end 784 if is_telemetry_url ul 785 put stats st_telrej add get stats st_telrej 1 786 else 787 strip_tracking_params ul 788 if dedup_insert_cleanurl 789 put stats st_links add get stats st_links 1 790 out_push_lit j_link1 791 out_push_in_json ts sub te ts 792 out_push_lit j_url 793 out_push_cleanurl_json 794 out_push_lit j_end 795 end 796 end 797 p = ue 798 end 799 end 800 end 801 p = add p 1 802 end 803 end 804 805 fn try_meta_key ls ulong le_pos ulong key view uchar * to bool 806 kl = len key 807 if not in_starts_ci ls le_pos key 808 ret false 809 end 810 vs = add ls kl 811 while lt vs le_pos bound 32768 812 if ne get inbuf vs 32 813 break 814 end 815 vs = add vs 1 816 end 817 ve = le_pos 818 while gt ve vs bound 32768 819 if ne get inbuf sub ve 1 32 820 break 821 end 822 ve = sub ve 1 823 end 824 if eq ve vs 825 ret false 826 end 827 put stats st_meta add get stats st_meta 1 828 out_push_lit j_meta1 829 out_push_in_json ls sub kl 1 830 out_push_lit j_val 831 out_push_in_json vs sub ve vs 832 out_push_lit j_end 833 ret true 834 end 835 836 fn check_meta_line ls ulong le_pos ulong to bool 837 if try_meta_key ls le_pos mk_title 838 ret true 839 end 840 if try_meta_key ls le_pos mk_author 841 ret true 842 end 843 if try_meta_key ls le_pos mk_lic 844 ret true 845 end 846 if try_meta_key ls le_pos mk_pin 847 ret true 848 end 849 if try_meta_key ls le_pos mk_src 850 ret true 851 end 852 if try_meta_key ls le_pos mk_date 853 ret true 854 end 855 if try_meta_key ls le_pos mk_ver 856 ret true 857 end 858 if try_meta_key ls le_pos mk_prov 859 ret true 860 end 861 ret try_meta_key ls le_pos mk_mod 862 end 863 864 fn check_heading_line ls ulong le_pos ulong to bool 865 ll = sub le_pos ls 866 if lt ll 3 867 ret false 868 end 869 if ne get inbuf ls 35 870 ret false 871 end 872 lvl = ulong 0 873 while and lt lvl 3 lt add ls lvl le_pos bound 4 874 if ne get inbuf add ls lvl 35 875 break 876 end 877 lvl = add lvl 1 878 end 879 if eq lvl 0 880 ret false 881 end 882 if ge add ls lvl le_pos 883 ret false 884 end 885 if ne get inbuf add ls lvl 32 886 ret false 887 end 888 ts = add add ls lvl 1 889 while lt ts le_pos bound 32768 890 if ne get inbuf ts 32 891 break 892 end 893 ts = add ts 1 894 end 895 ve = le_pos 896 while gt ve ts bound 32768 897 if ne get inbuf sub ve 1 32 898 break 899 end 900 ve = sub ve 1 901 end 902 put stats st_heads add get stats st_heads 1 903 out_push_lit j_head1 904 out_push_dec lvl 905 out_push_lit j_text 906 out_push_in_json ts sub ve ts 907 out_push_lit j_end 908 ret true 909 end 910 911 fn extract_reasoning_blocks to void 912 tot = get stats st_inlen 913 has_code = gt get stats st_blocks 0 914 base_q = ulong 500 915 if has_code 916 base_q = add base_q 100 917 end 918 put stats st_qual base_q 919 pos = ulong 0 920 while lt pos tot bound 32768 921 rs = ulong 0 922 re = ulong 0 923 found = false 924 if in_starts_ci pos tot t_think_o 925 rs = add pos 7 926 q = rs 927 while lt q tot bound 32768 928 if in_starts_ci q tot t_think_c 929 re = q 930 found = true 931 pos = add q 8 932 break 933 end 934 q = add q 1 935 end 936 else 937 if in_starts_ci pos tot t_thought_o 938 rs = add pos 9 939 q = rs 940 while lt q tot bound 32768 941 if in_starts_ci q tot t_thought_c 942 re = q 943 found = true 944 pos = add q 10 945 break 946 end 947 q = add q 1 948 end 949 end 950 end 951 if found 952 rlen = sub re rs 953 qm = ulong 500 954 if gt rlen 0 955 qm = add qm 200 956 end 957 if gt rlen 50 958 qm = add qm 100 959 end 960 if or in_contains_ci rs re t_kw_step or in_contains_ci rs re t_kw_ver in_contains_ci rs re t_kw_bigo 961 qm = add qm 100 962 end 963 if has_code 964 qm = add qm 100 965 end 966 if gt qm 1000 967 qm = ulong 1000 968 end 969 if gt qm get stats st_qual 970 put stats st_qual qm 971 end 972 put stats st_reas add get stats st_reas 1 973 out_push_lit j_reas1 974 out_push_dec div tot 4 975 out_push_lit j_qm 976 out_push_dec qm 977 out_push_lit j_text 978 out_push_in_json rs rlen 979 out_push_lit j_end 980 else 981 pos = add pos 1 982 end 983 end 984 end 985 986 fn harvest_loaded to void 987 tot = get stats st_inlen 988 for i ulong 13 989 if ne i st_inlen 990 put stats i 0 991 end 992 end 993 in_fence = false 994 pos = ulong 0 995 while lt pos tot bound 32768 996 ls = pos 997 while lt pos tot bound 32768 998 if eq get inbuf pos 10 999 break 1000 end 1001 pos = add pos 1 1002 end 1003 if in_starts_ci ls pos t_fence 1004 if not in_fence 1005 in_fence = true 1006 put stats st_blocks add get stats st_blocks 1 1007 else 1008 in_fence = false 1009 end 1010 else 1011 if not in_fence 1012 if not check_heading_line ls pos 1013 is_m = check_meta_line ls pos 1014 if not is_m 1015 extract_links_on_line ls pos 1016 end 1017 end 1018 end 1019 end 1020 if lt pos tot 1021 pos = add pos 1 1022 end 1023 end 1024 extract_reasoning_blocks 1025 sha256_inbuf 1026 out_push_lit j_sum1 1027 out_push_dec get stats st_heads 1028 out_push_lit j_sum2 1029 out_push_dec get stats st_blocks 1030 out_push_lit j_sum3 1031 out_push_dec get stats st_links 1032 out_push_lit j_sum4 1033 out_push_dec get stats st_telrej 1034 out_push_lit j_sum5 1035 out_push_dec get stats st_strip 1036 out_push_lit j_sum6 1037 out_push_dec get stats st_meta 1038 out_push_lit j_sum7 1039 out_push_dec get stats st_reas 1040 out_push_lit j_sum8 1041 out_push_dec get stats st_qual 1042 out_push_lit j_sum9 1043 out_push_shahex 1044 out_push_lit j_end 1045 end 1046 1047 fn main to int 1048 note Test 1: positive full markdown + metadata + 2 code blocks + reasoning 1049 in_reset 1050 in_append doc_pos_a 1051 in_append doc_pos_b 1052 harvest_loaded 1053 if ne get stats st_heads 3 1054 fail_case 1 1055 end 1056 if ne get stats st_blocks 2 1057 fail_case 1 1058 end 1059 if ne get stats st_links 1 1060 fail_case 1 1061 end 1062 if ne get stats st_meta 2 1063 fail_case 1 1064 end 1065 if ne get stats st_reas 1 1066 fail_case 1 1067 end 1068 if ne get stats st_qual 1000 1069 fail_case 1 1070 end 1071 wstr 1 p_1 1072 1073 note Test 2: negative control - telemetry domains rejected 1074 in_reset 1075 in_append doc_tel 1076 harvest_loaded 1077 if ne get stats st_telrej 4 1078 fail_case 2 1079 end 1080 if ne get stats st_links 0 1081 fail_case 2 1082 end 1083 wstr 1 p_2 1084 1085 note Test 3: negative control - tracking query params stripped while preserving clean params 1086 in_reset 1087 in_append doc_strip 1088 harvest_loaded 1089 if ne get stats st_links 2 1090 fail_case 3 1091 end 1092 if ne get stats st_strip 4 1093 fail_case 3 1094 end 1095 if not out_contains exp_clean1 1096 fail_case 3 1097 end 1098 if not out_contains exp_clean2 1099 fail_case 3 1100 end 1101 wstr 1 p_3 1102 1103 note Test 4: negative control - unsafe schemes (javascript:, data:) rejected 1104 in_reset 1105 in_append doc_unsafe 1106 harvest_loaded 1107 if ne get stats st_telrej 2 1108 fail_case 4 1109 end 1110 if ne get stats st_links 0 1111 fail_case 4 1112 end 1113 wstr 1 p_4 1114 1115 note Test 5: SHA-256 link deduplication invariant to case & stripped tracking params 1116 in_reset 1117 in_append doc_dedup 1118 harvest_loaded 1119 if ne get stats st_links 1 1120 fail_case 5 1121 end 1122 if ne get stats st_dedup 1 1123 fail_case 5 1124 end 1125 wstr 1 p_5 1126 1127 note Test 6: RFC 8259 JSON escaping of quotes and backslashes 1128 in_reset 1129 in_append doc_esc 1130 harvest_loaded 1131 if not out_contains exp_esc 1132 fail_case 6 1133 end 1134 wstr 1 p_6 1135 1136 note Test 7: reasoning scoring boundary (short thought, no code, no keywords = 700) 1137 in_reset 1138 in_append doc_short_thought 1139 harvest_loaded 1140 if ne get stats st_reas 1 1141 fail_case 7 1142 end 1143 if ne get stats st_qual 700 1144 fail_case 7 1145 end 1146 wstr 1 p_7 1147 1148 wstr 1 p_all 1149 ret 0 1150 end