nx_clause_gate.nx source
↩ module page · 94 lines · 8013 B
1// nx_clause_gate.nx -- INDEPENDENT GATE: contract-text retrieval, redline drift, playbook risk.
2// This gate runs on REAL CLAUSE TEXT, not on supplied flags. The teeth:
3// u2605DELETION and INSERTION are measured SEPARATELY. The headline case below is a draft that RETAINS
4// 100% of the standard clause -- it would score "identical" on any single similarity number -- while
5// having an uncapped-liability carve-out bolted onto the end. Retention 1000, novelty 555, risk MEDIUM.
6// That is precisely the edit that passes human review.
7// u2605RETRIEVAL IS BY CONTENT, NOT BY HEADING: a paragraph that reads like an indemnity matches the
8// indemnity standard even though it is offered as a liability clause.
9// u2605AN UNMATCHED CLAUSE IS BLOCK, never "closest guess".
10// u2605WORD BOUNDARIES ARE LOAD-BEARING: "liability" must not satisfy a search for "ability".
11// license_tier: ORIGINAL No hw writes (Rule 26). expect_exit: 0
12
13import "nx_clause_lib.nx"
14import "nx_gate_verdict.nx"
15
16func main(argc: i64, argv: *i64) -> i64 {
17 let ctr: *i64 = gv_ctr()
18 let lbl: *u8 = sys_mmap(32)
19
20 // ---- the playbook corpus (2 standard clauses) ----
21 let std_lol: *u8 = "In no event shall either party be liable for indirect incidental consequential or punitive damages arising out of this agreement" as *u8
22 let std_indem: *u8 = "Each party shall indemnify defend and hold harmless the other party from third party claims arising from its negligence or willful misconduct" as *u8
23
24 let lib: *i64 = sys_mmap(8 * 2) as *i64
25 lib[0] = std_lol as i64
26 lib[1] = std_indem as i64
27
28 // ---- the drafts under review ----
29 let draft_same: *u8 = "In no event shall either party be liable for indirect incidental consequential or punitive damages arising out of this agreement" as *u8
30 let draft_gutted: *u8 = "In no event shall either party be liable for indirect damages" as *u8
31 let draft_carveout: *u8 = "In no event shall either party be liable for indirect incidental consequential or punitive damages arising out of this agreement notwithstanding the foregoing customer bears unlimited uncapped exposure including lost profits revenue goodwill reputational harm regulatory fines penalties sanctions and all attorney fees whatsoever incurred" as *u8
32 let draft_mislabeled: *u8 = "Each party shall indemnify defend and hold harmless the other from third party claims" as *u8
33 let draft_alien: *u8 = "The quick brown fox jumps over lazy dogs repeatedly" as *u8
34
35 gv_head("NISHI-CLAUSE-GATE (contract TEXT: retrieval by content, deletion vs insertion, playbook risk)" as *u8)
36
37 // ---- W: word primitives ----
38 gv_check("W1 the standard liability clause has 20 words" as *u8, cl_word_count(std_lol) == 20, ctr)
39 gv_check("W2 whole word found" as *u8, cl_has_word(std_lol, "punitive" as *u8) == 1, ctr)
40 gv_check("W3 case-insensitive match" as *u8, cl_has_word(std_lol, "event" as *u8) == 1, ctr)
41 gv_check("W4 u2605'ability' must NOT match inside 'liability'" as *u8, cl_has_word(std_lol, "ability" as *u8) == 0, ctr)
42 gv_check("W5 'liable' IS present as its own word" as *u8, cl_has_word(std_lol, "liable" as *u8) == 1, ctr)
43 gv_check("W6 absent word" as *u8, cl_has_word(std_lol, "indemnify" as *u8) == 0, ctr)
44 gv_check("W7 empty text has no words" as *u8, cl_word_count("" as *u8) == 0, ctr)
45
46 // ---- R: retention -- what the draft DELETED ----
47 gv_check("R1 an identical draft retains everything" as *u8, cl_retained_permille(std_lol, draft_same) == 1000, ctr)
48 gv_check("R1a and deviates not at all" as *u8, cl_deviation_permille(std_lol, draft_same) == 0, ctr)
49 gv_check("R2 u2605the gutted draft retains only 550 permille" as *u8, cl_retained_permille(std_lol, draft_gutted) == 550, ctr)
50 gv_check("R2a so its deviation is 450" as *u8, cl_deviation_permille(std_lol, draft_gutted) == 450, ctr)
51 gv_check("R3 an unrelated text retains nothing" as *u8, cl_retained_permille(std_lol, draft_alien) == 0, ctr)
52
53 // ---- N: novelty -- what the draft INSERTED ----
54 gv_check("N1 an identical draft adds nothing" as *u8, cl_novel_permille(std_lol, draft_same) == 0, ctr)
55 gv_check("N2 u2605u2605the carve-out draft RETAINS 100% of the standard..." as *u8, cl_retained_permille(std_lol, draft_carveout) == 1000, ctr)
56 gv_check("N2a u2605u2605...so deviation alone says it is CLEAN" as *u8, cl_deviation_permille(std_lol, draft_carveout) == 0, ctr)
57 gv_check("N2b u2605u2605but novelty exposes the bolted-on carve-out" as *u8, cl_novel_permille(std_lol, draft_carveout) == 555, ctr)
58 gv_check("N2c u2605u2605and novelty clears the alert threshold that deviation never would" as *u8, cl_novel_permille(std_lol, draft_carveout) > CL_NOVEL_ALERT == 1, ctr)
59 gv_check("N3 the gutted draft inserted nothing new" as *u8, cl_novel_permille(std_lol, draft_gutted) == 0, ctr)
60
61 // ---- M: retrieval BY CONTENT ----
62 gv_check("M1 a faithful liability draft retrieves the liability standard" as *u8, cl_best_match(draft_same, lib, 2) == 0, ctr)
63 gv_check("M2 u2605a paragraph that READS like an indemnity retrieves the INDEMNITY standard" as *u8, cl_best_match(draft_mislabeled, lib, 2) == 1, ctr)
64 gv_check("M3 u2605an alien paragraph matches NOTHING" as *u8, cl_best_match(draft_alien, lib, 2) == CL_NO_MATCH, ctr)
65 gv_check("M3a an unmatched clause is BLOCK, never a closest guess" as *u8, cl_unmatched_risk_pure(cl_best_match(draft_alien, lib, 2)) == CL_RISK_BLOCK, ctr)
66 gv_check("M4 an empty playbook matches nothing" as *u8, cl_best_match(draft_same, lib, 0) == CL_NO_MATCH, ctr)
67 gv_check("M5 the best score for a faithful draft is total" as *u8, cl_best_score(draft_same, lib, 2) == 1000, ctr)
68 gv_check("M6 an unmatched draft scores zero" as *u8, cl_best_score(draft_alien, lib, 2) == 0, ctr)
69
70 // ---- K: risk scoring against the playbook ----
71 gv_check("K1 no drift on an ordinary clause -> NONE" as *u8, cl_risk_pure(0, 0, 300) == CL_RISK_NONE, ctr)
72 gv_check("K2 slight drift -> LOW" as *u8, cl_risk_pure(150, 0, 300) == CL_RISK_LOW, ctr)
73 gv_check("K3 the gutted draft (450) on an ordinary clause -> MEDIUM" as *u8, cl_risk_pure(450, 0, 300) == CL_RISK_MEDIUM, ctr)
74 gv_check("K4 heavy deletion -> HIGH" as *u8, cl_risk_pure(600, 0, 300) == CL_RISK_HIGH, ctr)
75 gv_check("K5 u2605u2605insertion alone escalates even at ZERO deviation" as *u8, cl_risk_pure(0, 555, 300) == CL_RISK_MEDIUM, ctr)
76 gv_check("K6 u2605on a CRITICAL clause the gutted draft escalates to HIGH" as *u8, cl_risk_pure(450, 0, 900) == CL_RISK_HIGH, ctr)
77 gv_check("K7 a critical clause never sits below MEDIUM once it drifts" as *u8, cl_risk_pure(150, 0, 900) == CL_RISK_MEDIUM, ctr)
78 gv_check("K8 a clean critical clause is still NONE" as *u8, cl_risk_pure(0, 0, 900) == CL_RISK_NONE, ctr)
79 gv_check("K9 heavy deletion on a critical clause -> BLOCK" as *u8, cl_risk_pure(600, 0, 900) == CL_RISK_BLOCK, ctr)
80
81 // ---- A: the negotiator-facing verdict ----
82 gv_check("A1 NONE auto-approves" as *u8, cl_auto_approve_pure(CL_RISK_NONE) == 1, ctr)
83 gv_check("A2 LOW auto-approves" as *u8, cl_auto_approve_pure(CL_RISK_LOW) == 1, ctr)
84 gv_check("A3 MEDIUM does NOT" as *u8, cl_auto_approve_pure(CL_RISK_MEDIUM) == 0, ctr)
85 gv_check("A4 BLOCK does NOT" as *u8, cl_auto_approve_pure(CL_RISK_BLOCK) == 0, ctr)
86 gv_check("A5 u2605u2605the carve-out draft does NOT auto-approve despite 0 deviation" as *u8, cl_auto_approve_pure(cl_risk_pure(cl_deviation_permille(std_lol, draft_carveout), cl_novel_permille(std_lol, draft_carveout), 900)) == 0, ctr)
87
88 cl_risk_label(cl_risk_pure(600, 0, 900), lbl)
89 gv_check("L1 block label" as *u8, mt_streq(lbl, "BLOCK-ESCALATE" as *u8) == 1, ctr)
90 cl_risk_label(CL_RISK_NONE, lbl)
91 gv_check("L2 clean label" as *u8, mt_streq(lbl, "NONE" as *u8) == 1, ctr)
92
93 return gv_verdict("CLAUSE-REDLINE" as *u8, ctr, "retrieval by content not heading; insertion caught at ZERO deviation; unmatched clause blocks" as *u8)
94}