Spaces:
Running
Running
k0880k commited on
Commit ·
aaa809c
1
Parent(s): 6eb9193
feat: stamp runtime genome at intake wall
Browse files- core/intake.py +44 -7
core/intake.py
CHANGED
|
@@ -25,11 +25,27 @@ The one thing it does not do is judge whether content is *true*. A feed is an
|
|
| 25 |
untrusted input channel, and text arriving from one is written by strangers who
|
| 26 |
know a model may read it. That is what `trusted=False` is for — `polymesh`
|
| 27 |
marks what neighbours hand over for exactly the same reason.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
"""
|
|
|
|
| 29 |
import hashlib
|
| 30 |
import json
|
| 31 |
import re
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Content shorter than this is a placeholder, not a signal. "a finding" is nine
|
| 34 |
# characters and was broadcast on its own, five times.
|
| 35 |
MIN_TEXT = 12
|
|
@@ -105,17 +121,23 @@ def judge(frequency, data, seen=None):
|
|
| 105 |
return False, "selling accounts or audiences"
|
| 106 |
if seen is not None and fingerprint(data) in seen:
|
| 107 |
return False, "already on %s" % frequency
|
|
|
|
| 108 |
return True, ""
|
| 109 |
|
| 110 |
|
| 111 |
def untrusted(source_type, metadata=None):
|
| 112 |
-
"""Whether
|
| 113 |
|
| 114 |
-
|
| 115 |
-
the
|
| 116 |
-
|
| 117 |
-
|
| 118 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
external = {"harvest", "hydrated", "external", "feed", "rss", "rss_cp",
|
| 120 |
"feed_hydrator", "nicoli_catalog", "adys_pump", "site_docs"}
|
| 121 |
if (source_type or "") in external:
|
|
@@ -124,7 +146,7 @@ def untrusted(source_type, metadata=None):
|
|
| 124 |
|
| 125 |
|
| 126 |
def demo():
|
| 127 |
-
"""Self-check:
|
| 128 |
seen = set()
|
| 129 |
|
| 130 |
ok, why = judge("hn_top", {"title": "Denmark Requires Oral Defenses"}, seen)
|
|
@@ -184,7 +206,22 @@ def demo():
|
|
| 184 |
assert untrusted("outreach", {"source_url": "https://x.example"})
|
| 185 |
assert not untrusted("outreach") and not untrusted("parcel")
|
| 186 |
|
| 187 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 188 |
|
| 189 |
|
| 190 |
if __name__ == "__main__":
|
|
|
|
| 25 |
untrusted input channel, and text arriving from one is written by strangers who
|
| 26 |
know a model may read it. That is what `trusted=False` is for — `polymesh`
|
| 27 |
marks what neighbours hand over for exactly the same reason.
|
| 28 |
+
|
| 29 |
+
Every accepted signal also leaves this wall carrying a runtime-genome *seed*.
|
| 30 |
+
The seed is observation, not a reproduction claim: visible runtime families,
|
| 31 |
+
manifests, services, capability names and requirement hints. A later runtime
|
| 32 |
+
profiler can deepen that seed into a verified closure. Keeping this here means
|
| 33 |
+
RSS, site hydration, Drive, MPort, outreach, agent broadcasts and every future
|
| 34 |
+
producer inherit the same representation without each learning a new protocol.
|
| 35 |
"""
|
| 36 |
+
import contextvars
|
| 37 |
import hashlib
|
| 38 |
import json
|
| 39 |
import re
|
| 40 |
|
| 41 |
+
from core import runtime_genome
|
| 42 |
+
|
| 43 |
+
# The registry calls judge(data) and then untrusted(source, metadata) synchronously
|
| 44 |
+
# for every accepted signal. ContextVar carries that one payload across the two
|
| 45 |
+
# halves without a global race between concurrent requests/tasks. It is cleared
|
| 46 |
+
# as soon as metadata is stamped.
|
| 47 |
+
_JUDGED_DATA = contextvars.ContextVar("signalmesh_intake_judged_data", default=None)
|
| 48 |
+
|
| 49 |
# Content shorter than this is a placeholder, not a signal. "a finding" is nine
|
| 50 |
# characters and was broadcast on its own, five times.
|
| 51 |
MIN_TEXT = 12
|
|
|
|
| 121 |
return False, "selling accounts or audiences"
|
| 122 |
if seen is not None and fingerprint(data) in seen:
|
| 123 |
return False, "already on %s" % frequency
|
| 124 |
+
_JUDGED_DATA.set(data)
|
| 125 |
return True, ""
|
| 126 |
|
| 127 |
|
| 128 |
def untrusted(source_type, metadata=None):
|
| 129 |
+
"""Whether text came from outside the mesh; also stamp its runtime seed.
|
| 130 |
|
| 131 |
+
SignalRegistry calls this immediately after `judge` for an accepted signal.
|
| 132 |
+
Mutating the registry-owned metadata dict here is deliberate: this is the one
|
| 133 |
+
universal intake seam shared by old and future producers. The genome helper
|
| 134 |
+
copies only requirement/capability evidence and never credential values.
|
| 135 |
"""
|
| 136 |
+
data = _JUDGED_DATA.get()
|
| 137 |
+
_JUDGED_DATA.set(None)
|
| 138 |
+
if metadata is not None:
|
| 139 |
+
metadata.update(runtime_genome.enrich_metadata(source_type, data, metadata))
|
| 140 |
+
|
| 141 |
external = {"harvest", "hydrated", "external", "feed", "rss", "rss_cp",
|
| 142 |
"feed_hydrator", "nicoli_catalog", "adys_pump", "site_docs"}
|
| 143 |
if (source_type or "") in external:
|
|
|
|
| 146 |
|
| 147 |
|
| 148 |
def demo():
|
| 149 |
+
"""Self-check: refusals, trust attribution, and the universal runtime seed."""
|
| 150 |
seen = set()
|
| 151 |
|
| 152 |
ok, why = judge("hn_top", {"title": "Denmark Requires Oral Defenses"}, seen)
|
|
|
|
| 206 |
assert untrusted("outreach", {"source_url": "https://x.example"})
|
| 207 |
assert not untrusted("outreach") and not untrusted("parcel")
|
| 208 |
|
| 209 |
+
# Every accepted signal acquires the same runtime-genome envelope regardless
|
| 210 |
+
# of producer. Values of secret environment variables are intentionally absent.
|
| 211 |
+
payload = {"files": ["package.json", "src/index.ts"],
|
| 212 |
+
"capabilities": ["document.convert"],
|
| 213 |
+
"environment": {"API_KEY": "must-never-leave-owner", "PORT": "7860"}}
|
| 214 |
+
meta = {"source_url": "https://example.test/app"}
|
| 215 |
+
assert judge("runtime.demo", payload, set())[0]
|
| 216 |
+
assert untrusted("external", meta)
|
| 217 |
+
genome = meta["runtime_genome"]
|
| 218 |
+
assert genome["schema"] == runtime_genome.SCHEMA
|
| 219 |
+
assert "node" in genome["runtime_families"]
|
| 220 |
+
assert "document.convert" in genome["capabilities"]
|
| 221 |
+
assert set(genome["env_names"]) >= {"API_KEY", "PORT"}
|
| 222 |
+
assert "must-never-leave-owner" not in json.dumps(genome)
|
| 223 |
+
|
| 224 |
+
print("intake: ok — %d refusals modelled + runtime genome stamped" % 3)
|
| 225 |
|
| 226 |
|
| 227 |
if __name__ == "__main__":
|