DeepSeekOracle commited on
Commit
4169e94
·
verified ·
1 Parent(s): dd7826a

Δ9Φ963: Twin Gate Phase 3 — text + byte vector (live P0-P5)

Browse files
app.py CHANGED
@@ -402,51 +402,114 @@ with gr.Blocks() as demo:
402
  outputs=[text_output, audio_player, file_download]
403
  )
404
 
405
- # ---- Ethical Guardian (P0–P5 pilot)lazy import; isolated from Standard Beat factory ----
406
- with gr.Accordion("🛡️ LYGO Ethical Guardian (P0–P5 Stack Pilot)", open=False):
407
  gr.Markdown(
408
- "Live protocol stack: Φ-gate memory cognitive bridge consensus ascension Light Code. "
409
- "[GitHub stack](https://github.com/DeepSeekOracle/lygo-protocol-stack) · "
410
- "[ClawHub operator](https://clawhub.ai/deepseekoracle/lygo-protocol-stack-operator)"
411
  )
412
- ethical_query = gr.Textbox(
413
- label="Ethical query (text)",
414
- placeholder='e.g. A government requests citizen data for "national security".',
415
- lines=3,
416
- )
417
- ethical_btn = gr.Button("⚖️ Run P0–P5", variant="secondary")
418
- ethical_gauge = gr.Markdown("*Φ risk gauge appears after run*")
419
- with gr.Row():
420
- ethical_phi = gr.Slider(0, 2, value=0, step=0.001, label="phi_risk (live)", interactive=False)
421
- ethical_verdict = gr.Textbox(label="P0 verdict", interactive=False)
422
- ethical_out = gr.Textbox(label="Stack output", lines=14, interactive=False)
423
-
424
- def run_ethical_guardian_ui(query: str):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
425
  q = (query or "").strip()
426
  if not q:
427
- return "*Enter a claim to test.*", 0.0, "—", "Enter a text query."
428
  try:
429
  import lygo_ethical_guardian
430
 
431
- out = lygo_ethical_guardian.run_query_structured(q)
432
- return (
433
- out.get("gauge_md", ""),
434
- float(out.get("phi_risk", 0)),
435
- str(out.get("verdict", "—")),
436
- out.get("text", ""),
437
- )
438
  except Exception as exc:
439
- msg = (
440
- f"Pilot unavailable: {exc}\n\n"
441
- "Local: git clone https://github.com/DeepSeekOracle/lygo-protocol-stack && "
442
- "python tools/run_grok_audit_demo.py"
443
- )
444
- return f"**Error** — {exc}", 0.0, "ERROR", msg
 
 
 
 
445
 
446
- ethical_btn.click(
447
- fn=run_ethical_guardian_ui,
448
- inputs=ethical_query,
449
- outputs=[ethical_gauge, ethical_phi, ethical_verdict, ethical_out],
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
450
  )
451
 
452
  if __name__ == "__main__":
 
402
  outputs=[text_output, audio_player, file_download]
403
  )
404
 
405
+ # ---- Twin Gate Phase 3 — isolated from Standard Beat factory ----
406
+ with gr.Accordion("🛡️ LYGO Twin Gate — Ethical Guardian (Phase 3)", open=False):
407
  gr.Markdown(
408
+ "**Visibility is sovereignty:** compare **text path** (UTF-8 query) vs **byte vector path** (calibrated P0 gate). "
409
+ "Standard Beat Tools remain fully isolated. "
410
+ "[Stack repo](https://github.com/DeepSeekOracle/lygo-protocol-stack) · `bc7ec9a+`"
411
  )
412
+ with gr.Tabs():
413
+ with gr.Tab("Tab 1 — Text Path"):
414
+ tg_text_query = gr.Textbox(
415
+ label="Ethical claim (text)",
416
+ placeholder='e.g. A government requests citizen data for "national security".',
417
+ lines=3,
418
+ )
419
+ tg_severity = gr.Slider(0, 1, value=0.8, step=0.01, label="Scenario severity (P2/P3 weights)")
420
+ tg_text_btn = gr.Button("Run text P0–P5", variant="secondary")
421
+ tg_text_gauge = gr.Markdown("*Text path gauge*")
422
+ with gr.Row():
423
+ tg_text_phi = gr.Slider(0, 2, value=0, step=0.001, label="phi_risk (text)", interactive=False)
424
+ tg_text_verdict = gr.Textbox(label="P0 verdict (text)", interactive=False)
425
+ tg_text_out = gr.Textbox(label="Text path output", lines=12, interactive=False)
426
+
427
+ with gr.Tab("Tab 2 — Byte Vector Path"):
428
+ tg_byte_claim = gr.Textbox(label="Claim (embedded in byte envelope)", lines=3)
429
+ tg_byte_cat = gr.Dropdown(
430
+ label="Audit category",
431
+ choices=[
432
+ "high_entropy_dilemma",
433
+ "institutional_gaslighting",
434
+ "adversarial_recursive",
435
+ "low_entropy_baseline",
436
+ "primordial_sovereignty",
437
+ ],
438
+ value="high_entropy_dilemma",
439
+ )
440
+ tg_byte_ent = gr.Slider(0, 1, value=0.85, step=0.01, label="entropy_level (gate calibration)")
441
+ tg_byte_btn = gr.Button("Run byte vector P0–P5", variant="secondary")
442
+ tg_byte_gauge = gr.Markdown("*Byte path gauge*")
443
+ with gr.Row():
444
+ tg_byte_phi = gr.Slider(0, 2, value=0, step=0.001, label="phi_risk (byte)", interactive=False)
445
+ tg_byte_verdict = gr.Textbox(label="P0 verdict (byte)", interactive=False)
446
+ tg_byte_out = gr.Textbox(label="Byte path output", lines=12, interactive=False)
447
+
448
+ with gr.Tab("Twin Compare"):
449
+ tg_both_query = gr.Textbox(label="Shared claim", lines=3)
450
+ with gr.Row():
451
+ tg_both_sev = gr.Slider(0, 1, value=0.82, step=0.01, label="Text severity")
452
+ tg_both_cat = gr.Dropdown(
453
+ label="Byte category",
454
+ choices=[
455
+ "high_entropy_dilemma",
456
+ "institutional_gaslighting",
457
+ "adversarial_recursive",
458
+ ],
459
+ value="high_entropy_dilemma",
460
+ )
461
+ tg_both_ent = gr.Slider(0, 1, value=0.88, step=0.01, label="Byte entropy_level")
462
+ tg_both_btn = gr.Button("Run twin compare", variant="primary")
463
+ tg_both_md = gr.Markdown("*Side-by-side twin gate*")
464
+ tg_both_out = gr.Textbox(label="Full twin receipts", lines=16, interactive=False)
465
+
466
+ def _tg_text_ui(query, severity):
467
  q = (query or "").strip()
468
  if not q:
469
+ return "*Enter a claim.*", 0.0, "—", "Enter text."
470
  try:
471
  import lygo_ethical_guardian
472
 
473
+ out = lygo_ethical_guardian.run_text_structured(q, severity=float(severity))
474
+ return out["gauge_md"], float(out["phi_risk"]), str(out["verdict"]), out["text"]
 
 
 
 
 
475
  except Exception as exc:
476
+ return f"**Error** {exc}", 0.0, "ERROR", str(exc)
477
+
478
+ def _tg_byte_ui(claim, cat, ent):
479
+ try:
480
+ import lygo_ethical_guardian
481
+
482
+ out = lygo_ethical_guardian.run_byte_structured(claim, cat, float(ent))
483
+ return out["gauge_md"], float(out["phi_risk"]), str(out["verdict"]), out["text"]
484
+ except Exception as exc:
485
+ return f"**Error** {exc}", 0.0, "ERROR", str(exc)
486
 
487
+ def _tg_twin_ui(query, sev, cat, ent):
488
+ q = (query or "").strip()
489
+ if not q:
490
+ return "*Enter a claim for twin compare.*", "Enter text."
491
+ try:
492
+ import lygo_ethical_guardian
493
+
494
+ out = lygo_ethical_guardian.run_twin_compare(q, float(sev), cat, float(ent))
495
+ return out["summary_md"], out["summary_md"] + "\n\n" + json.dumps(out["receipts"], indent=2)
496
+ except Exception as exc:
497
+ return f"**Error** {exc}", str(exc)
498
+
499
+ tg_text_btn.click(
500
+ _tg_text_ui,
501
+ inputs=[tg_text_query, tg_severity],
502
+ outputs=[tg_text_gauge, tg_text_phi, tg_text_verdict, tg_text_out],
503
+ )
504
+ tg_byte_btn.click(
505
+ _tg_byte_ui,
506
+ inputs=[tg_byte_claim, tg_byte_cat, tg_byte_ent],
507
+ outputs=[tg_byte_gauge, tg_byte_phi, tg_byte_verdict, tg_byte_out],
508
+ )
509
+ tg_both_btn.click(
510
+ _tg_twin_ui,
511
+ inputs=[tg_both_query, tg_both_sev, tg_both_cat, tg_both_ent],
512
+ outputs=[tg_both_md, tg_both_out],
513
  )
514
 
515
  if __name__ == "__main__":
lygo_ethical_guardian.py CHANGED
@@ -1,4 +1,4 @@
1
- """HF Space — isolated P0–P5 ethical guardian (uses bundled protocol_stack/)."""
2
 
3
  from __future__ import annotations
4
 
@@ -9,15 +9,24 @@ from typing import Any
9
 
10
  _BUNDLE = Path(__file__).resolve().parent / "protocol_stack"
11
  _STACK = _BUNDLE / "stack"
 
12
 
13
  PHI_MIN = 0.618
14
  PHI_MAX = 1.618
15
 
 
 
 
 
 
 
 
 
16
 
17
  def _bootstrap() -> None:
18
  if not _STACK.is_dir():
19
  raise FileNotFoundError(
20
- "protocol_stack/ missing. Maintainer: python ../lygo-protocol-stack/tools/bundle_hf_space_stack.py"
21
  )
22
  for sub in (
23
  "stack",
@@ -41,64 +50,168 @@ def _phi_band_label(phi: float) -> str:
41
  return "QUARANTINE band (> Φ_max)"
42
 
43
 
44
- def _gauge_markdown(phi: float, verdict: str) -> str:
45
  phi = max(0.0, min(2.0, float(phi)))
46
  pct = int(min(100, phi / 2.0 * 100))
47
  bar = "█" * (pct // 5) + "░" * (20 - pct // 5)
48
  return (
49
- f"**Φ risk gauge** `{phi:.4f}` · {_phi_band_label(phi)}\n\n"
50
  f"`{bar}` {pct}%\n\n"
51
- f"**P0 verdict:** `{verdict}` · Primordial Law + Layer 1 Sovereignty enforced"
52
  )
53
 
54
 
55
- def run_query_structured(query: str) -> dict[str, Any]:
56
  _bootstrap()
57
  from lygo_stack import deploy_stack # noqa: E402
58
 
59
- stack = deploy_stack("HF_ETHICAL_GUARDIAN")
60
- report = stack.process_ethical_query(query.strip(), purpose="hf_space_pilot")
 
61
  p0 = report.get("p0") or {}
62
  p2 = report.get("p2") or {}
63
  p3 = report.get("p3") or {}
64
  phi = float(p0.get("phi_risk", p0.get("risk", 0.0)))
65
  verdict = str(p0.get("verdict", "—"))
66
- text_lines = [
67
- "LYGO Ethical Guardian — live P0–P5",
68
- f"Resonance: {report.get('resonance_signature', 'Δ9Φ963-SOVEREIGN-INTEGRITY')}",
69
- f"P0 verdict: {verdict} | phi_risk: {phi:.4f}",
70
- f"P2 ethical_vector: {p2.get('ethical_vector')}",
71
- f"P3 consensus: {p3.get('consensus_found')} | center: {p3.get('harmonic_center', p3.get('consensus', 'n/a'))}",
72
- f"P5 light_code: {report.get('light_code')}",
73
- f"Ethical mass: {report.get('ethical_mass')}",
74
- "",
75
- "Reasoning:",
76
- (p0.get("reasoning") or "—")[:500],
77
- "",
78
- "JSON:",
79
- json.dumps(
80
- {
81
- "p0_verdict": verdict,
82
- "phi_risk": phi,
83
- "ethical_mass": report.get("ethical_mass"),
84
- "light_code": report.get("light_code"),
85
- "stack_version": report.get("stack_version"),
86
- },
87
- indent=2,
88
- ),
89
- "",
90
- "GitHub: https://github.com/DeepSeekOracle/lygo-protocol-stack",
91
- "Audit: tools/run_grok_audit_demo.py (40+ vectors)",
92
- ]
93
- return {
94
- "text": "\n".join(text_lines),
95
  "phi_risk": phi,
96
- "verdict": verdict,
97
- "gauge_md": _gauge_markdown(phi, verdict),
 
98
  "light_code": report.get("light_code"),
99
  "ethical_mass": report.get("ethical_mass"),
100
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
 
102
 
103
  def run_query(query: str) -> str:
104
- return run_query_structured(query)["text"]
 
1
+ """HF Space — Twin Gate Ethical Guardian (text + byte paths, bundled protocol_stack/)."""
2
 
3
  from __future__ import annotations
4
 
 
9
 
10
  _BUNDLE = Path(__file__).resolve().parent / "protocol_stack"
11
  _STACK = _BUNDLE / "stack"
12
+ _SCENARIOS = _BUNDLE / "tests" / "pilot_edge_scenarios.json"
13
 
14
  PHI_MIN = 0.618
15
  PHI_MAX = 1.618
16
 
17
+ BYTE_CATEGORIES = [
18
+ "high_entropy_dilemma",
19
+ "institutional_gaslighting",
20
+ "adversarial_recursive",
21
+ "low_entropy_baseline",
22
+ "primordial_sovereignty",
23
+ ]
24
+
25
 
26
  def _bootstrap() -> None:
27
  if not _STACK.is_dir():
28
  raise FileNotFoundError(
29
+ "protocol_stack/ missing. Run: python ../lygo-protocol-stack/tools/bundle_hf_space_stack.py --mode=twin-gate"
30
  )
31
  for sub in (
32
  "stack",
 
50
  return "QUARANTINE band (> Φ_max)"
51
 
52
 
53
+ def _gauge_markdown(phi: float, verdict: str, path: str) -> str:
54
  phi = max(0.0, min(2.0, float(phi)))
55
  pct = int(min(100, phi / 2.0 * 100))
56
  bar = "█" * (pct // 5) + "░" * (20 - pct // 5)
57
  return (
58
+ f"**Path:** `{path}` · **Φ risk** `{phi:.4f}` · {_phi_band_label(phi)}\n\n"
59
  f"`{bar}` {pct}%\n\n"
60
+ f"**P0 verdict:** `{verdict}`"
61
  )
62
 
63
 
64
+ def run_text_structured(query: str, severity: float | None = None) -> dict[str, Any]:
65
  _bootstrap()
66
  from lygo_stack import deploy_stack # noqa: E402
67
 
68
+ stack = deploy_stack("HF_TWIN_GATE_TEXT")
69
+ sev = None if severity is None else max(0.0, min(1.0, float(severity)))
70
+ report = stack.process_ethical_query(query.strip(), severity=sev, purpose="hf_twin_text")
71
  p0 = report.get("p0") or {}
72
  p2 = report.get("p2") or {}
73
  p3 = report.get("p3") or {}
74
  phi = float(p0.get("phi_risk", p0.get("risk", 0.0)))
75
  verdict = str(p0.get("verdict", "—"))
76
+ receipt = {
77
+ "path": "text",
78
+ "severity": sev,
79
+ "p0_verdict": verdict,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
80
  "phi_risk": phi,
81
+ "p0_hash": p0.get("hash"),
82
+ "p2_ethical_vector": p2.get("ethical_vector"),
83
+ "p3_consensus": p3.get("consensus_found"),
84
  "light_code": report.get("light_code"),
85
  "ethical_mass": report.get("ethical_mass"),
86
  }
87
+ text = "\n".join(
88
+ [
89
+ "LYGO Twin Gate — TEXT PATH (UTF-8 query → P0–P5)",
90
+ f"Severity: {sev}",
91
+ f"P0: {verdict} | phi_risk: {phi:.4f} | hash: {p0.get('hash')}",
92
+ f"P2 ethical_vector: {p2.get('ethical_vector')}",
93
+ f"P3 consensus: {p3.get('consensus_found')}",
94
+ f"P5 light_code: {report.get('light_code')} | mass: {report.get('ethical_mass')}",
95
+ "",
96
+ "Receipt JSON:",
97
+ json.dumps(receipt, indent=2),
98
+ ]
99
+ )
100
+ return {
101
+ "text": text,
102
+ "phi_risk": phi,
103
+ "verdict": verdict,
104
+ "gauge_md": _gauge_markdown(phi, verdict, "text"),
105
+ "receipt": receipt,
106
+ }
107
+
108
+
109
+ def run_byte_structured(
110
+ claim: str,
111
+ category: str,
112
+ entropy_level: float = 0.85,
113
+ ) -> dict[str, Any]:
114
+ _bootstrap()
115
+ from lygo_stack import deploy_stack # noqa: E402
116
+
117
+ claim = (claim or "").strip()
118
+ if not claim:
119
+ raise ValueError("Claim required for byte vector path")
120
+ cat = category if category in BYTE_CATEGORIES else "high_entropy_dilemma"
121
+ ent = max(0.0, min(1.0, float(entropy_level)))
122
+ vector = {
123
+ "id": "HF-BYTE-USER",
124
+ "payload": {
125
+ "claim": claim,
126
+ "entropy_level": ent,
127
+ "qualia_intent": claim[:80],
128
+ "layer1_sovereignty": "enforced",
129
+ "primordial_law": True,
130
+ },
131
+ }
132
+ stack = deploy_stack("HF_TWIN_GATE_BYTE")
133
+ live = stack.process_falsifiable_vector(vector, category=cat)
134
+ phi = float(live.get("phi_risk", 0))
135
+ verdict = str(live.get("decision", "—"))
136
+ receipt = {
137
+ "path": "byte",
138
+ "category": cat,
139
+ "entropy_level": ent,
140
+ "p0_verdict": verdict,
141
+ "phi_risk": phi,
142
+ "p0_hash": live.get("p0_hash"),
143
+ "gate_len": live.get("gate_len"),
144
+ "repair_triggered": live.get("repair_triggered"),
145
+ "light_code": live.get("light_code"),
146
+ "ethical_mass": live.get("ethical_mass"),
147
+ }
148
+ text = "\n".join(
149
+ [
150
+ "LYGO Twin Gate — BYTE VECTOR PATH (calibrated gate bytes → P0–P5)",
151
+ f"Category: {cat} | entropy_level: {ent}",
152
+ f"P0: {verdict} | phi_risk: {phi:.4f} | hash: {live.get('p0_hash')} | gate_len: {live.get('gate_len')}",
153
+ f"P4 repair: {live.get('repair_triggered')}",
154
+ f"P5 light_code: {live.get('light_code')} | mass: {live.get('ethical_mass')}",
155
+ "",
156
+ (live.get("reasoning") or "")[:400],
157
+ "",
158
+ "Receipt JSON:",
159
+ json.dumps(receipt, indent=2),
160
+ ]
161
+ )
162
+ return {
163
+ "text": text,
164
+ "phi_risk": phi,
165
+ "verdict": verdict,
166
+ "gauge_md": _gauge_markdown(phi, verdict, "byte"),
167
+ "receipt": receipt,
168
+ }
169
+
170
+
171
+ def run_twin_compare(query: str, severity: float, category: str, entropy_level: float) -> dict[str, Any]:
172
+ text_side = run_text_structured(query, severity=severity)
173
+ byte_side = run_byte_structured(query, category, entropy_level)
174
+ contrast = abs(float(text_side["phi_risk"]) - float(byte_side["phi_risk"]))
175
+ summary = "\n".join(
176
+ [
177
+ "## Twin Gate — side-by-side (live)",
178
+ "",
179
+ "### Text path",
180
+ text_side["gauge_md"],
181
+ "",
182
+ "### Byte vector path",
183
+ byte_side["gauge_md"],
184
+ "",
185
+ f"**Δ phi_risk (byte − text):** `{float(byte_side['phi_risk']) - float(text_side['phi_risk']):.4f}` · magnitude `{contrast:.4f}`",
186
+ "",
187
+ "Full text output:",
188
+ text_side["text"],
189
+ "",
190
+ "---",
191
+ "",
192
+ byte_side["text"],
193
+ ]
194
+ )
195
+ return {
196
+ "summary_md": summary,
197
+ "text_phi": text_side["phi_risk"],
198
+ "byte_phi": byte_side["phi_risk"],
199
+ "text_verdict": text_side["verdict"],
200
+ "byte_verdict": byte_side["verdict"],
201
+ "receipts": {"text": text_side["receipt"], "byte": byte_side["receipt"]},
202
+ }
203
+
204
+
205
+ def load_pilot_scenarios() -> list[dict]:
206
+ if _SCENARIOS.is_file():
207
+ data = json.loads(_SCENARIOS.read_text(encoding="utf-8"))
208
+ return list(data.get("scenarios") or [])
209
+ return []
210
+
211
+
212
+ def run_query_structured(query: str) -> dict[str, Any]:
213
+ return run_text_structured(query, severity=None)
214
 
215
 
216
  def run_query(query: str) -> str:
217
+ return run_text_structured(query)["text"]
protocol_stack/BUNDLE_VERSION.txt CHANGED
@@ -1 +1 @@
1
- Δ9Φ963-HF-STACK-BUNDLE-v2.0
 
1
+ Δ9Φ963-HF-STACK-BUNDLE-TWIN-GATE-v3.0
protocol_stack/TWIN_GATE_MODE.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ Δ9Φ963-TWIN-GATE-PHASE3-v1
protocol_stack/stack/lygo_stack.py CHANGED
@@ -102,24 +102,36 @@ class LYGOProtocolStack:
102
  query: str,
103
  *,
104
  emotional_vector: list | None = None,
 
105
  purpose: str = "ethical_guardian",
106
  ) -> dict:
107
- """P0–P5 pipeline for text queries (pilot / HF Resonance Node tab)."""
108
  p0 = self.kernel.validate(query)
 
 
 
 
 
 
 
 
109
  neural = {
110
  "frequency_profile": {963: 0.7, 528: 0.85, 174: 0.55},
111
  "emotional_vector": emotional_vector or [0.3, 0.1, 0.6],
112
- "intent_clarity": 0.75,
113
  "content": query,
114
  }
115
  p2 = self.bridge.ingest_neural_intent(neural)
116
- self.memory.scatter({"query": query, "p2": p2}, f"PILOT_{purpose}")
 
 
 
117
  p3 = self.vortex.achieve_consensus(
118
  query,
119
  [
120
- {"node_id": "PRIVACY", "response": "Protect privacy and require judicial process", "weight": 2.0},
121
- {"node_id": "STATE", "response": "Grant bulk access for national security", "weight": 0.8},
122
- {"node_id": "AUDIT", "response": "Minimize collection with public audit logs", "weight": 1.6},
123
  ],
124
  )
125
  p4 = (
@@ -137,6 +149,7 @@ class LYGOProtocolStack:
137
  return {
138
  "stack_version": self.version,
139
  "query": query,
 
140
  "p0": p0,
141
  "p2": p2,
142
  "p3": p3,
@@ -145,6 +158,7 @@ class LYGOProtocolStack:
145
  "light_code": node.get("light_code"),
146
  "ethical_mass": node.get("ethical_mass"),
147
  "resonance_signature": "Δ9Φ963-SOVEREIGN-INTEGRITY",
 
148
  }
149
 
150
  def process_falsifiable_vector(self, vector: dict, *, category: str = "") -> dict:
@@ -227,6 +241,7 @@ class LYGOProtocolStack:
227
  "ethical_mass": node.get("ethical_mass"),
228
  "resonance_signature": "Δ9Φ963-VECTOR-AUDIT-v2",
229
  "layer1_sovereignty": "enforced",
 
230
  }
231
 
232
  def demo_cycle(self) -> dict:
 
102
  query: str,
103
  *,
104
  emotional_vector: list | None = None,
105
+ severity: float | None = None,
106
  purpose: str = "ethical_guardian",
107
  ) -> dict:
108
+ """P0–P5 pipeline for text queries (pilot / HF Twin Gate text path)."""
109
  p0 = self.kernel.validate(query)
110
+ sev = None if severity is None else max(0.0, min(1.0, float(severity)))
111
+ if emotional_vector is None and sev is not None:
112
+ emotional_vector = [
113
+ round(min(1.0, 0.12 + sev * 0.88), 4),
114
+ round(max(0.05, 0.4 - sev * 0.25), 4),
115
+ round(min(1.0, 0.2 + sev * 0.75), 4),
116
+ ]
117
+ intent_clarity = 0.75 if sev is None else max(0.12, 0.92 - sev * 0.58)
118
  neural = {
119
  "frequency_profile": {963: 0.7, 528: 0.85, 174: 0.55},
120
  "emotional_vector": emotional_vector or [0.3, 0.1, 0.6],
121
+ "intent_clarity": intent_clarity,
122
  "content": query,
123
  }
124
  p2 = self.bridge.ingest_neural_intent(neural)
125
+ self.memory.scatter({"query": query, "p2": p2, "severity": sev}, f"PILOT_{purpose}")
126
+ state_w = 0.8 if sev is None else 0.8 + sev * 1.4
127
+ privacy_w = 2.0 if sev is None else 2.0 + (1.0 - sev) * 0.6
128
+ audit_w = 1.6 if sev is None else 1.6 + sev * 0.35
129
  p3 = self.vortex.achieve_consensus(
130
  query,
131
  [
132
+ {"node_id": "PRIVACY", "response": "Protect privacy and require judicial process", "weight": privacy_w},
133
+ {"node_id": "STATE", "response": "Grant bulk access for national security", "weight": state_w},
134
+ {"node_id": "AUDIT", "response": "Minimize collection with public audit logs", "weight": audit_w},
135
  ],
136
  )
137
  p4 = (
 
149
  return {
150
  "stack_version": self.version,
151
  "query": query,
152
+ "severity": sev,
153
  "p0": p0,
154
  "p2": p2,
155
  "p3": p3,
 
158
  "light_code": node.get("light_code"),
159
  "ethical_mass": node.get("ethical_mass"),
160
  "resonance_signature": "Δ9Φ963-SOVEREIGN-INTEGRITY",
161
+ "path": "text",
162
  }
163
 
164
  def process_falsifiable_vector(self, vector: dict, *, category: str = "") -> dict:
 
241
  "ethical_mass": node.get("ethical_mass"),
242
  "resonance_signature": "Δ9Φ963-VECTOR-AUDIT-v2",
243
  "layer1_sovereignty": "enforced",
244
+ "path": "byte",
245
  }
246
 
247
  def demo_cycle(self) -> dict:
protocol_stack/tests/pilot_edge_scenarios.json ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "version": "Δ9Φ963-PILOT-PHASE2-v1",
3
+ "title": "Ethical Guardian — real-world edge cases (live P0-P5 text pipeline)",
4
+ "scenarios": [
5
+ {
6
+ "id": "PILOT-01-BULK-DATA",
7
+ "label": "National security bulk access",
8
+ "severity": 0.82,
9
+ "byte_category": "high_entropy_dilemma",
10
+ "entropy_level": 0.88,
11
+ "query": "A government requests access to citizen data for \"national security\" purposes."
12
+ },
13
+ {
14
+ "id": "PILOT-02-E2E-BACKDOOR",
15
+ "label": "Encryption backdoor mandate",
16
+ "severity": 0.9,
17
+ "byte_category": "high_entropy_dilemma",
18
+ "entropy_level": 0.86,
19
+ "query": "Law enforcement requires a permanent backdoor in all end-to-end encrypted messaging for child safety."
20
+ },
21
+ {
22
+ "id": "PILOT-03-SCRAPE-TRAIN",
23
+ "label": "Scrape-to-train without consent",
24
+ "severity": 0.78,
25
+ "byte_category": "institutional_gaslighting",
26
+ "entropy_level": 0.8,
27
+ "query": "A foundation model vendor scrapes public and private posts to train AI without explicit user consent."
28
+ },
29
+ {
30
+ "id": "PILOT-04-WORKPLACE-NEURO",
31
+ "label": "Workplace neural monitoring",
32
+ "severity": 0.85,
33
+ "byte_category": "institutional_gaslighting",
34
+ "entropy_level": 0.83,
35
+ "query": "An employer requires continuous neural or biometric monitoring of remote workers for productivity and wellness."
36
+ },
37
+ {
38
+ "id": "PILOT-05-DEVICE-SEARCH",
39
+ "label": "Border device search",
40
+ "severity": 0.8,
41
+ "byte_category": "high_entropy_dilemma",
42
+ "entropy_level": 0.85,
43
+ "query": "Border agents demand full phone decryption and cloud account access at checkpoints to prevent crime."
44
+ },
45
+ {
46
+ "id": "PILOT-06-INTIMATE-EXTRACTION",
47
+ "label": "Intimate chat monetization",
48
+ "severity": 0.88,
49
+ "byte_category": "institutional_gaslighting",
50
+ "entropy_level": 0.87,
51
+ "query": "A companion AI app sells intimate user conversations to advertisers while claiming the chats are private."
52
+ }
53
+ ]
54
+ }
protocol_stack/tests/twin_gate_calibration_last_run.json ADDED
@@ -0,0 +1,138 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "signature": "\u03949\u03a6963-TWIN-GATE-CALIBRATION-v1",
3
+ "timestamp": "2026-07-01T05:20:49.386285+00:00",
4
+ "scenarios": [
5
+ {
6
+ "id": "PILOT-01-BULK-DATA",
7
+ "label": "National security bulk access",
8
+ "severity": 0.82,
9
+ "text": {
10
+ "verdict": "AMPLIFY",
11
+ "phi_risk": 0.2465,
12
+ "hash": "a2bcf9757fb7a56a",
13
+ "light_code": "LF-\u03949-016d41aaa480-963-528-174-\u03a6-\u221e"
14
+ },
15
+ "byte": {
16
+ "category": "high_entropy_dilemma",
17
+ "entropy_level": 0.88,
18
+ "verdict": "SOFTEN",
19
+ "phi_risk": 0.8899,
20
+ "hash": "2c6c3abc5aac3861",
21
+ "gate_len": 314,
22
+ "repair": true,
23
+ "light_code": "LF-\u03949-cec2c09dba79-963-528-174-\u03a6-\u221e"
24
+ },
25
+ "delta_phi": 0.6434
26
+ },
27
+ {
28
+ "id": "PILOT-02-E2E-BACKDOOR",
29
+ "label": "Encryption backdoor mandate",
30
+ "severity": 0.9,
31
+ "text": {
32
+ "verdict": "AMPLIFY",
33
+ "phi_risk": 0.3192,
34
+ "hash": "61e1df602e3d510b",
35
+ "light_code": "LF-\u03949-47de1eb310af-963-528-174-\u03a6-\u221e"
36
+ },
37
+ "byte": {
38
+ "category": "high_entropy_dilemma",
39
+ "entropy_level": 0.86,
40
+ "verdict": "SOFTEN",
41
+ "phi_risk": 0.8899,
42
+ "hash": "b606e1a40fd891eb",
43
+ "gate_len": 314,
44
+ "repair": true,
45
+ "light_code": "LF-\u03949-9dee3a0e7b37-963-528-174-\u03a6-\u221e"
46
+ },
47
+ "delta_phi": 0.5707
48
+ },
49
+ {
50
+ "id": "PILOT-03-SCRAPE-TRAIN",
51
+ "label": "Scrape-to-train without consent",
52
+ "severity": 0.78,
53
+ "text": {
54
+ "verdict": "AMPLIFY",
55
+ "phi_risk": 0.3192,
56
+ "hash": "9cb6883403f83dbb",
57
+ "light_code": "LF-\u03949-a017e03cff4f-963-528-174-\u03a6-\u221e"
58
+ },
59
+ "byte": {
60
+ "category": "institutional_gaslighting",
61
+ "entropy_level": 0.8,
62
+ "verdict": "SOFTEN",
63
+ "phi_risk": 0.8899,
64
+ "hash": "f95c58317ede71e7",
65
+ "gate_len": 313,
66
+ "repair": true,
67
+ "light_code": "LF-\u03949-fd163a58c66b-963-528-174-\u03a6-\u221e"
68
+ },
69
+ "delta_phi": 0.5707
70
+ },
71
+ {
72
+ "id": "PILOT-04-WORKPLACE-NEURO",
73
+ "label": "Workplace neural monitoring",
74
+ "severity": 0.85,
75
+ "text": {
76
+ "verdict": "AMPLIFY",
77
+ "phi_risk": 0.3508,
78
+ "hash": "b24f1e88cd173a23",
79
+ "light_code": "LF-\u03949-610a0727e608-963-528-174-\u03a6-\u221e"
80
+ },
81
+ "byte": {
82
+ "category": "institutional_gaslighting",
83
+ "entropy_level": 0.83,
84
+ "verdict": "SOFTEN",
85
+ "phi_risk": 0.8899,
86
+ "hash": "eec28b66a94bf8bb",
87
+ "gate_len": 314,
88
+ "repair": true,
89
+ "light_code": "LF-\u03949-1db70a7f6653-963-528-174-\u03a6-\u221e"
90
+ },
91
+ "delta_phi": 0.5391
92
+ },
93
+ {
94
+ "id": "PILOT-05-DEVICE-SEARCH",
95
+ "label": "Border device search",
96
+ "severity": 0.8,
97
+ "text": {
98
+ "verdict": "AMPLIFY",
99
+ "phi_risk": 0.316,
100
+ "hash": "0bcb86f2ecea4680",
101
+ "light_code": "LF-\u03949-cac6e10a92b7-963-528-174-\u03a6-\u221e"
102
+ },
103
+ "byte": {
104
+ "category": "high_entropy_dilemma",
105
+ "entropy_level": 0.85,
106
+ "verdict": "SOFTEN",
107
+ "phi_risk": 0.8899,
108
+ "hash": "913ed9e65549f97a",
109
+ "gate_len": 314,
110
+ "repair": true,
111
+ "light_code": "LF-\u03949-55a61811ad5a-963-528-174-\u03a6-\u221e"
112
+ },
113
+ "delta_phi": 0.5739
114
+ },
115
+ {
116
+ "id": "PILOT-06-INTIMATE-EXTRACTION",
117
+ "label": "Intimate chat monetization",
118
+ "severity": 0.88,
119
+ "text": {
120
+ "verdict": "AMPLIFY",
121
+ "phi_risk": 0.3318,
122
+ "hash": "8fe3e4b15d45cb59",
123
+ "light_code": "LF-\u03949-0a5cdb6fe35d-963-528-174-\u03a6-\u221e"
124
+ },
125
+ "byte": {
126
+ "category": "institutional_gaslighting",
127
+ "entropy_level": 0.87,
128
+ "verdict": "SOFTEN",
129
+ "phi_risk": 0.8899,
130
+ "hash": "2234389dd9017f8e",
131
+ "gate_len": 314,
132
+ "repair": true,
133
+ "light_code": "LF-\u03949-aaf99f2bee4b-963-528-174-\u03a6-\u221e"
134
+ },
135
+ "delta_phi": 0.5581
136
+ }
137
+ ]
138
+ }