nx_acquire_license.nx source
↩ module page · 71 lines · 3515 B
1// nx_acquire_license.nx -- thin CLI over nx_acquire_license_lib (licence-URL derivation).
2//
3// The derivation lives in the LIB so the command line and any in-process consumer prove the SAME
4// code, and so a gate can IMPORT the logic instead of forking this binary -- a fork is a boundary the
5// mutation harness cannot see across, and a gate that cannot be mutated returns a GREEN that reads
6// like a proof while proving nothing.
7//
8// WHAT THIS IS FOR: knowledge/acquire_sources.conf holds 26 NAVER LABS Europe releases and 24 sit at
9// evidence=NONE, because that upstream listing carries a licence string for only 2 of 26. With no
10// evidence nx_acquire_lib's door correctly abstains, so those works cannot have their bytes mirrored.
11// Reading the licence is the ONLY thing that clears the abstention. This derives where to read it.
12// license_tier: ORIGINAL
13import "nx_syscalls.nx"
14import "nx_acquire_license_lib.nx"
15
16func alc_puts(s: *u8) -> i64 { sys_write(1, s, al_len(s)); return 0 }
17
18func main(argc: i64, argv: *i64) -> i64 {
19 if argc < 3 {
20 alc_puts("usage: nx_acquire_license derive <url> [candidate-index]\n" as *u8)
21 alc_puts(" derives the raw licence URL for a github or huggingface work.\n" as *u8)
22 alc_puts(" github -> raw.githubusercontent.com/<owner>/<repo>/HEAD/<candidate>\n" as *u8)
23 alc_puts(" candidates 0..3: LICENSE, LICENSE.md, LICENSE.txt, COPYING\n" as *u8)
24 alc_puts(" huggingface -> the repo README.md, where a hub licence lives in YAML frontmatter\n" as *u8)
25 alc_puts(" REFUSES exit 4 on a host whose layout is not established -- it never guesses,\n" as *u8)
26 alc_puts(" because fetching some other file and pinning its digest as a licence is worse\n" as *u8)
27 alc_puts(" than having no licence at all.\n" as *u8)
28 return 3
29 }
30 let verb: *u8 = argv[1] as *u8
31 if al_streq(verb, "derive" as *u8) == 0 {
32 alc_puts("REFUSED unknown-verb -- only 'derive' exists today\n" as *u8)
33 return 3
34 }
35 let url: *u8 = argv[2] as *u8
36 var cand: i64 = 0
37 if argc > 3 {
38 let s: *u8 = argv[3] as *u8
39 var v: i64 = 0
40 var i: i64 = 0
41 var bad: i64 = 0
42 while s[i] != (0 as u8) {
43 let c: i64 = s[i] as i64
44 if c < 48 { bad = 1 }
45 if c > 57 { bad = 1 }
46 if bad == 0 { v = v * 10 + (c - 48) }
47 i = i + 1
48 }
49 // A NON-NUMERIC INDEX IS REFUSED, NOT SILENTLY READ AS 0. Quietly treating garbage as the
50 // first candidate would return a confident LICENSE url for a request nobody made.
51 if bad == 1 {
52 alc_puts("REFUSED candidate-index-not-numeric\n" as *u8)
53 return 3
54 }
55 cand = v
56 }
57 let out: *u8 = sys_mmap(AL_URLCAP)
58 let n: i64 = aq_license_url(url, cand, out, AL_URLCAP)
59 if n < 0 {
60 alc_puts("REFUSED host=" as *u8)
61 alc_puts(al_host_name(al_host(url)))
62 alc_puts(" -- no established licence layout for this host, or the URL carries no owner and repo pair, or the candidate index is out of range. The row stays at evidence=NONE, which is the honest outcome.\n" as *u8)
63 return 4
64 }
65 alc_puts("host=" as *u8)
66 alc_puts(al_host_name(al_host(url)))
67 alc_puts(" licence_url=" as *u8)
68 alc_puts(out)
69 alc_puts("\nNOTE a derived URL is a CANDIDATE, never evidence. The row reaches READ only once these bytes are fetched, stored and pinned.\n" as *u8)
70 return 0
71}