code wiki / _hdl_build / nx_context_packer.nx

nx_context_packer.nx

buildroot/runtime/_hdl_build/nx_context_packer.nx

2918 B50 linesdepth 3pulls 3 transitivereach 0 importersview sourcekind tool
docsdependenciesstructsconstsfunctions

about

nx_context_packer.nx -- THE sovereign "push a document into an LLM natively" CLI: read a text file (a book's extracted chapters, a research doc, anything), pack it into an LLM context that fits a TOKEN BUDGET (with a 10% safety margin), and write an LLM-ready context file. Greedy in-order line packing + an honest truncation marker when the document exceeds the budget. No 3rd-party tokenizer/SDK -- pure Nishi. Composes nx_token_counter. usage: nx_context_packer <infile> <budget_tokens> <outfile> license_tier: ORIGINAL

dependencies 1 imports · 0 importers

nx_token_counter.nx nx_context_packer.nx

imports: nx_token_counter.nx

imported by: nobody (leaf or entry point)

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main cp_w cp_slen cp_atoi sys_read_file sys_openat_rd sys_lseek sys_mmap sys_read sys_close pack_text tok_estimate tc_isspace tc_cat tc_catn sys_mmap ↻ sys_openat_wr cp_slen ↻ cp_wn cp_w ↻

structs

none

consts

7const K_MAGIC_65536: i64 = 65536

functions

9func cp_slen(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} return n }
called by 2: cp_wmain
10func cp_w(s: *u8) -> i64 { sys_write(1, s, cp_slen(s)); return 0 }
called by 2: cp_wnmain calls 1: cp_slen
11func cp_atoi(s: *u8) -> i64 { var v: i64=0; var i: i64=0; while s[i]!=(0 as u8){ let c: i64=s[i] as i64; if c>=48 { if c<=57 { v=v*10+(c-48) } } i=i+1 } return v }
called by 1: main
12func cp_wn(v: i64) -> i64
called by 1: main calls 1: cp_w
21func main(argc: i64, argv: *i64) -> i64