nx_asset_visibility.nx source
↩ module page · 112 lines · 5817 B
1// nx_asset_visibility.nx -- flag every asset PUBLIC vs PRIVATE *BY ITS SOURCE*, on the NATIVE store.
2//
3// Operator (2026-06-20): "flag what's public and what's private by source" + "stop using tsv, get
4// everything to nishi ecosystem only." The visibility of an asset is DERIVED from where it came from
5// (location path/URL, provenance class, or type), via an ORDERED policy that now lives in the NATIVE
6// content-addressed seg_store (nx_native_config), NOT a flat .tsv. Rules try in order, FIRST match
7// wins; an UNMATCHED source is OPERATOR-ONLY (fail-closed / deny-by-default, Rule 12). The policy is
8// AUTHORED BY THIS ORGAN (vis_seed writes the rows) and READ from the store -- data-driven, sovereign.
9//
10// PURE COMPOSITION (Rule 15): record decode -> nx_asset_record; policy store -> nx_native_config
11// (seg_store+canon); access-level bridge -> nx_asset_access. No TSV, no SQL. No hardware writes (#26).
12// license_tier: ORIGINAL
13import "nx_syscalls.nx"
14import "nx_uxf_decode.nx"
15import "nx_asset_record.nx"
16import "nx_asset_access.nx"
17import "nx_native_config.nx"
18
19// the native policy seg_store prefix (one content-addressed store; distinct from the catalog).
20func vis_policy_prefix() -> *u8 { return "knowledge/store/asset-vispolicy-\x00" as *u8 }
21// the config tag for the visibility rule list.
22func vis_tag() -> *u8 { return "vis\x00" as *u8 }
23
24func vis_streq(a: *u8, b: *u8) -> i64 {
25 var i: i64 = 0
26 while 1 == 1 { if a[i] != b[i] { return 0 } if a[i] == (0 as u8) { return 1 } i = i + 1 }
27 return 1
28}
29func vis_startswith(s: *u8, prefix: *u8) -> i64 {
30 if (s as i64) == 0 { return 0 }
31 var i: i64 = 0
32 while prefix[i] != (0 as u8) { if s[i] != prefix[i] { return 0 } i = i + 1 }
33 return 1
34}
35func vis_dup(s: *u8) -> *u8 {
36 let out: *u8 = sys_mmap(64)
37 var i: i64 = 0
38 while s[i] != (0 as u8) { out[i] = s[i]; i = i + 1 }
39 out[i] = 0 as u8
40 return out
41}
42
43// ---- SEED the policy into the native store (the authored-by-organ source of the rules) ----
44func vis_seed_rule(w: *i64, idx: i64, kind: *u8, value: *u8, viz: *u8) -> i64 {
45 let keys: *i64 = sys_mmap(8 * 4) as *i64
46 let vals: *i64 = sys_mmap(8 * 4) as *i64
47 keys[0] = ("kind\x00") as i64; vals[0] = (kind as i64)
48 keys[1] = ("val\x00") as i64; vals[1] = (value as i64)
49 keys[2] = ("viz\x00") as i64; vals[2] = (viz as i64)
50 return ncfg_add_row(w, vis_tag(), idx, keys, vals, 3)
51}
52// write the full ordered policy to `prefix`. Order = specificity (gallery before its parent dir).
53func vis_seed(prefix: *u8) -> i64 {
54 let w: *i64 = ncfg_begin()
55 vis_seed_rule(w, 0, "location_prefix\x00" as *u8, "knowledge/staging/media/gallery/\x00" as *u8, "operator-only\x00" as *u8)
56 vis_seed_rule(w, 1, "location_prefix\x00" as *u8, "knowledge/staging/media/\x00" as *u8, "private\x00" as *u8)
57 vis_seed_rule(w, 2, "location_prefix\x00" as *u8, "web_assets/\x00" as *u8, "public\x00" as *u8)
58 vis_seed_rule(w, 3, "location_prefix\x00" as *u8, "/volume1/homes/elderwesto/nishihost/sites/nishifamily/\x00" as *u8, "public\x00" as *u8)
59 vis_seed_rule(w, 4, "prov_class\x00" as *u8, "downloaded\x00" as *u8, "private\x00" as *u8)
60 vis_seed_rule(w, 5, "type\x00" as *u8, "doc\x00" as *u8, "public\x00" as *u8)
61 ncfg_set_count(w, vis_tag(), 6)
62 return ncfg_commit(prefix, w)
63}
64
65// ---- THE FLAG: visibility of a record BY SOURCE, reading the policy from the native store `prefix` ----
66func vis_of_p(rec: *u8, n: i64, prefix: *u8) -> *u8 {
67 let dk: *i64 = sys_mmap(8 * 32) as *i64
68 let dv: *i64 = sys_mmap(8 * 32) as *i64
69 let nf: i64 = canon_decode(rec, n, dk, dv, 32)
70 let loc: *u8 = ar_get(dk, dv, nf, "location\x00" as *u8)
71 let pc: *u8 = ar_get(dk, dv, nf, "prov_class\x00" as *u8)
72 let ty: *u8 = ar_get(dk, dv, nf, "type\x00" as *u8)
73
74 let h: *i64 = ncfg_open(prefix)
75 if (h as i64) == 0 { return "operator-only\x00" as *u8 } // no policy store -> fail-closed
76 let cnt: i64 = ncfg_count(h, vis_tag())
77 let rk: *i64 = sys_mmap(8 * 8) as *i64
78 let rv: *i64 = sys_mmap(8 * 8) as *i64
79 var i: i64 = 0
80 while i < cnt {
81 let rf: i64 = ncfg_row(h, vis_tag(), i, rk, rv, 8)
82 if rf > 0 {
83 let kind: *u8 = ncfg_field(rk, rv, rf, "kind\x00" as *u8)
84 let val: *u8 = ncfg_field(rk, rv, rf, "val\x00" as *u8)
85 let viz: *u8 = ncfg_field(rk, rv, rf, "viz\x00" as *u8)
86 var hit: i64 = 0
87 if vis_streq(kind, "location_prefix\x00" as *u8) == 1 { if vis_startswith(loc, val) == 1 { hit = 1 } }
88 if vis_streq(kind, "prov_class\x00" as *u8) == 1 { if (pc as i64) != 0 { if vis_streq(pc, val) == 1 { hit = 1 } } }
89 if vis_streq(kind, "type\x00" as *u8) == 1 { if (ty as i64) != 0 { if vis_streq(ty, val) == 1 { hit = 1 } } }
90 if hit == 1 { return vis_dup(viz) }
91 }
92 i = i + 1
93 }
94 return "operator-only\x00" as *u8
95}
96func vis_of(rec: *u8, n: i64) -> *u8 { return vis_of_p(rec, n, vis_policy_prefix()) }
97
98// is this asset releasable to the public internet? (policy from `prefix` / production)
99func vis_is_public_p(rec: *u8, n: i64, prefix: *u8) -> i64 {
100 if vis_streq(vis_of_p(rec, n, prefix), "public\x00" as *u8) == 1 { return 1 }
101 return 0
102}
103func vis_is_public(rec: *u8, n: i64) -> i64 { return vis_is_public_p(rec, n, vis_policy_prefix()) }
104
105// bridge to R6 access clearance: public->ANON, private->PRO, operator-only(or unknown)->OWNER.
106func vis_required_level_p(rec: *u8, n: i64, prefix: *u8) -> i64 {
107 let v: *u8 = vis_of_p(rec, n, prefix)
108 if vis_streq(v, "public\x00" as *u8) == 1 { return AA_ANON() }
109 if vis_streq(v, "private\x00" as *u8) == 1 { return AA_PRO() }
110 return AA_OWNER()
111}
112func vis_required_level(rec: *u8, n: i64) -> i64 { return vis_required_level_p(rec, n, vis_policy_prefix()) }