code wiki / (root) / nx_gather_compost.nx

nx_gather_compost.nx source

↩ module page · 171 lines · 5824 B

1// nx_gather_compost.nx -- prior-arc knowledge recycling. 2// 3// Per [[feedback-hunter-gatherer-meta-primitives-outward-inward-axes]]: 4// "nx_gather_compost (recycled-prior-arc knowledge informing current)." 5// When a prior arc (Argon2id implementation, browser CSS phase 2, 6// vision-triangulation, etc.) has shipped + closed, the lessons it 7// produced become COMPOST -- mineral-rich knowledge that informs 8// future arcs without being re-derived from scratch. 9// 10// Distinct from nx_aerobic (cleanup discipline): aerobic is "release 11// stale data with stewardship"; compost is "re-apply old wisdom to 12// new fields." 13// 14// Composes: 15// nx_gatherer -- compost is a field kind that can be sown 16// nx_gather_journal -- COMPOSTED event records re-application 17// nx_hunt_evidence -- prior hunt evidence forms the compost 18// (e.g., a fix from Argon2id arc informs 19// a current TLS arc) 20 21import "nx_syscalls.nx" 22import "nx_tier.nx" 23 24const NX_GC_OK: nx_int = 0 25const NX_GC_ERR_FULL: nx_int = 1 26const NX_GC_ERR_NOT_FOUND: nx_int = 2 27const NX_GC_ERR_BAD_SOURCE: nx_int = 3 28 29// ===== Sealed enum: NxCompostSource ================================ 30 31const NX_CS_HUNT_EVIDENCE: nx_int = 0 // prior hunt's kill receipt 32const NX_CS_GATHER_YIELD: nx_int = 1 // prior gather's measured yield 33const NX_CS_CARDINAL_TEXT: nx_int = 2 // doctrine learned earlier 34const NX_CS_BUG_TAPE_LESSON: nx_int = 3 // bug-tape entry archived 35const NX_CS_PR_RESEARCH: nx_int = 4 // prior research arc artifact 36const NX_CS_N_SOURCES: nx_int = 5 37 38// ===== Struct: NxCompostEntry ====================================== 39// 40// One unit of recycled knowledge. source identifies the prior arc. 41// content_hash points to the actual lesson body (caller-owned). 42// applied_count tracks how many times this compost has been 43// re-applied — high count = high mineral value. 44 45struct NxCompostEntry { 46 entry_id: nx_int, 47 source: nx_int, 48 source_arc_id: nx_int, // which arc produced this 49 content_hash: nx_size, 50 deposited_us: nx_size, 51 applied_count: nx_int, 52 last_applied_us: nx_size, 53} 54 55struct NxCompostPile { 56 entries: *NxCompostEntry, 57 capacity: nx_size, 58 count: nx_size, 59} 60 61const NX_GC_ENTRY_BYTES: nx_size = 56 62 63func nx_cs_source_is_valid(s: nx_int) -> nx_int { 64 if s < 0 { return 0 } 65 if s >= NX_CS_N_SOURCES { return 0 } 66 return 1 67} 68 69func nx_compost_pile_new(capacity: nx_size) -> *NxCompostPile { 70 let p: *NxCompostPile = (sys_mmap(24)) as *NxCompostPile 71 let bytes: nx_size = capacity * NX_GC_ENTRY_BYTES 72 p.entries = (sys_mmap(bytes)) as *NxCompostEntry 73 p.capacity = capacity 74 p.count = 0 75 return p 76} 77 78func _gc_at(p: *NxCompostPile, idx: nx_size) -> *NxCompostEntry { 79 return (p.entries as i64 + (idx as i64) * NX_GC_ENTRY_BYTES) as *NxCompostEntry 80} 81 82func _gc_find(p: *NxCompostPile, entry_id: nx_int) -> nx_int { 83 var i: nx_size = 0 84 while i < p.count { 85 let e: *NxCompostEntry = _gc_at(p, i) 86 if e.entry_id == entry_id { return i as i64 } 87 i = i + 1 88 } 89 return -1 90} 91 92// ===== nx_compost_deposit ========================================= 93// 94// Register a lesson into the compost pile. Each lesson is a unit 95// of mineral-rich knowledge waiting to be re-applied to current 96// work. 97 98func nx_compost_deposit(p: *NxCompostPile, 99 entry_id: nx_int, 100 source: nx_int, 101 source_arc_id: nx_int, 102 content_hash: nx_size, 103 now_us: nx_size) -> nx_int { 104 if nx_cs_source_is_valid(source) == 0 { return NX_GC_ERR_BAD_SOURCE } 105 if p.count >= p.capacity { return NX_GC_ERR_FULL } 106 let e: *NxCompostEntry = _gc_at(p, p.count) 107 e.entry_id = entry_id 108 e.source = source 109 e.source_arc_id = source_arc_id 110 e.content_hash = content_hash 111 e.deposited_us = now_us 112 e.applied_count = 0 113 e.last_applied_us = 0 114 p.count = p.count + 1 115 return NX_GC_OK 116} 117 118// ===== nx_compost_apply ============================================ 119// 120// Re-apply this compost entry to a current arc. Increments 121// applied_count + updates last_applied_us. Used by gathered/hunter 122// to mark "this Argon2id lesson was applied to current TLS work." 123 124func nx_compost_apply(p: *NxCompostPile, 125 entry_id: nx_int, 126 now_us: nx_size) -> nx_int { 127 let idx: nx_int = _gc_find(p, entry_id) 128 if idx < 0 { return NX_GC_ERR_NOT_FOUND } 129 let e: *NxCompostEntry = _gc_at(p, idx as nx_size) 130 e.applied_count = e.applied_count + 1 131 e.last_applied_us = now_us 132 return NX_GC_OK 133} 134 135func nx_compost_count(p: *NxCompostPile) -> nx_size { 136 return p.count 137} 138 139func nx_compost_count_by_source(p: *NxCompostPile, source: nx_int) -> nx_int { 140 var hits: nx_int = 0 141 var i: nx_size = 0 142 while i < p.count { 143 let e: *NxCompostEntry = _gc_at(p, i) 144 if e.source == source { hits = hits + 1 } 145 i = i + 1 146 } 147 return hits 148} 149 150// ===== nx_compost_total_applications =============================== 151// 152// Sum applied_count across all entries. High value = this compost 153// pile is actively recycling. Low value = stagnant intel. 154 155func nx_compost_total_applications(p: *NxCompostPile) -> nx_int { 156 var sum: nx_int = 0 157 var i: nx_size = 0 158 while i < p.count { 159 let e: *NxCompostEntry = _gc_at(p, i) 160 sum = sum + e.applied_count 161 i = i + 1 162 } 163 return sum 164} 165 166func nx_compost_applied_count(p: *NxCompostPile, entry_id: nx_int) -> nx_int { 167 let idx: nx_int = _gc_find(p, entry_id) 168 if idx < 0 { return 0 } 169 let e: *NxCompostEntry = _gc_at(p, idx as nx_size) 170 return e.applied_count 171}