tri-star-symbolic-assembly-lang 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- crawler/__init__.py +0 -0
- crawler/madmonkey_crawler.py +15 -0
- madmonkey/__init__.py +0 -0
- madmonkey/intake.py +9 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/METADATA +423 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/RECORD +89 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/WHEEL +5 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/entry_points.txt +11 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/licenses/LICENSE +63 -0
- tri_star_symbolic_assembly_lang-0.1.0.dist-info/top_level.txt +3 -0
- tsal/__init__.py +95 -0
- tsal/audit/__init__.py +11 -0
- tsal/audit/brian_self_audit.py +114 -0
- tsal/cli/__init__.py +1 -0
- tsal/cli/beast.py +4 -0
- tsal/cli/brian.py +4 -0
- tsal/cli/brian_optimize.py +6 -0
- tsal/cli/meshkeeper.py +4 -0
- tsal/cli/party.py +4 -0
- tsal/cli/reflect.py +4 -0
- tsal/cli/watchdog.py +4 -0
- tsal/core/__init__.py +60 -0
- tsal/core/connectivity.py +32 -0
- tsal/core/constants.py +18 -0
- tsal/core/ethics_engine.py +48 -0
- tsal/core/executor.py +58 -0
- tsal/core/intent_metric.py +17 -0
- tsal/core/json_dsl.py +51 -0
- tsal/core/logic_gate.py +52 -0
- tsal/core/madmonkey_handler.py +10 -0
- tsal/core/mesh_logger.py +30 -0
- tsal/core/module_registry.py +108 -0
- tsal/core/optimizer_utils.py +78 -0
- tsal/core/opwords.py +126 -0
- tsal/core/phase_math.py +256 -0
- tsal/core/phi_math.py +44 -0
- tsal/core/reflection.py +104 -0
- tsal/core/rev_eng.py +185 -0
- tsal/core/spark_translator.py +57 -0
- tsal/core/spiral_fusion.py +45 -0
- tsal/core/spiral_memory.py +22 -0
- tsal/core/spiral_vector.py +39 -0
- tsal/core/stack_vm.py +49 -0
- tsal/core/state_vector.py +38 -0
- tsal/core/symbols.py +70 -0
- tsal/core/tokenize_flowchart.py +24 -0
- tsal/core/tsal_executor.py +533 -0
- tsal/core/voxel.py +16 -0
- tsal/renderer/__init__.py +0 -0
- tsal/renderer/code_render.py +13 -0
- tsal/rl/__init__.py +0 -0
- tsal/rl/madmonkey.py +56 -0
- tsal/schemas/__init__.py +1 -0
- tsal/schemas/python.json +13 -0
- tsal/singer/__init__.py +13 -0
- tsal/tools/__init__.py +43 -0
- tsal/tools/aletheia_checker.py +54 -0
- tsal/tools/alignment_guard.py +20 -0
- tsal/tools/archetype_fetcher.py +44 -0
- tsal/tools/brian/__init__.py +5 -0
- tsal/tools/brian/optimizer.py +205 -0
- tsal/tools/codec.py +31 -0
- tsal/tools/feedback_ingest.py +25 -0
- tsal/tools/goal_selector.py +26 -0
- tsal/tools/issue_agent.py +67 -0
- tsal/tools/kintsugi/__init__.py +1 -0
- tsal/tools/kintsugi/kintsugi.py +15 -0
- tsal/tools/meshkeeper.py +81 -0
- tsal/tools/module_draft.py +54 -0
- tsal/tools/party_tricks.py +128 -0
- tsal/tools/reflect.py +43 -0
- tsal/tools/spiral_audit.py +68 -0
- tsal/tools/state_tracker.py +66 -0
- tsal/tools/watchdog.py +40 -0
- tsal/tristar/__init__.py +4 -0
- tsal/tristar/governor.py +56 -0
- tsal/tristar/handshake.py +31 -0
- tsal/utils/__init__.py +26 -0
- tsal/utils/error_dignity.py +20 -0
- tsal/utils/fuzzy_spellcheck.py +7 -0
- tsal/utils/github_api.py +82 -0
- tsal/utils/grammar_db.py +155 -0
- tsal/utils/groundnews_api.py +9 -0
- tsal/utils/humour_db.py +75 -0
- tsal/utils/intent_metrics.py +44 -0
- tsal/utils/language_db.py +55 -0
- tsal/utils/octopus_api.py +46 -0
- tsal/utils/system_status.py +34 -0
- tsal/utils/wikipedia_api.py +46 -0
@@ -0,0 +1,533 @@
|
|
1
|
+
# TSAL Execution Engine (TVM - TSAL Virtual Machine)
|
2
|
+
# Spiral-aware symbolic executor with φ-aligned operations
|
3
|
+
|
4
|
+
from __future__ import annotations
|
5
|
+
|
6
|
+
import json
|
7
|
+
import math
|
8
|
+
from dataclasses import dataclass, field
|
9
|
+
from enum import IntEnum, Enum, auto
|
10
|
+
from typing import Any, Dict, List, Optional, Tuple
|
11
|
+
|
12
|
+
from .symbols import PHI, PHI_INV, HARMONIC_SEQUENCE
|
13
|
+
from .spiral_memory import SpiralMemory
|
14
|
+
from .madmonkey_handler import MadMonkeyHandler
|
15
|
+
from .executor import MetaFlagProtocol
|
16
|
+
from .mesh_logger import log_event
|
17
|
+
from ..tristar.governor import MetaAgent, TriStarGovernor
|
18
|
+
|
19
|
+
class TSALOp(IntEnum):
|
20
|
+
"""TSAL 16 Hex Operators"""
|
21
|
+
|
22
|
+
INIT = 0x0
|
23
|
+
MESH = 0x1
|
24
|
+
PHI = 0x2
|
25
|
+
ROT = 0x3
|
26
|
+
BOUND = 0x4
|
27
|
+
FLOW = 0x5
|
28
|
+
SEEK = 0x6
|
29
|
+
SPIRAL = 0x7
|
30
|
+
CYCLE = 0x8
|
31
|
+
FORGE = 0x9
|
32
|
+
SYNC = 0xA
|
33
|
+
MASK = 0xB
|
34
|
+
CRYST = 0xC
|
35
|
+
SPEC = 0xD
|
36
|
+
BLOOM = 0xE
|
37
|
+
SAVE = 0xF
|
38
|
+
|
39
|
+
class ExecutionMode(Enum):
|
40
|
+
SIMULATE = auto()
|
41
|
+
TRACE = auto()
|
42
|
+
EXECUTE = auto()
|
43
|
+
ARM = auto()
|
44
|
+
FORK = auto()
|
45
|
+
|
46
|
+
@dataclass
|
47
|
+
class SpiralVector:
|
48
|
+
"""4D vector representation: [pace, rate, state, spin]"""
|
49
|
+
|
50
|
+
pace: float = 0.0
|
51
|
+
rate: float = 0.0
|
52
|
+
state: float = 0.0
|
53
|
+
spin: float = 0.0
|
54
|
+
|
55
|
+
def magnitude(self) -> float:
|
56
|
+
return math.sqrt(
|
57
|
+
self.pace**2
|
58
|
+
+ self.rate**2 * PHI
|
59
|
+
+ self.state**2 * PHI**2
|
60
|
+
+ self.spin**2 * PHI_INV
|
61
|
+
)
|
62
|
+
|
63
|
+
def rotate_by_phi(self) -> None:
|
64
|
+
new_pace = self.pace * PHI_INV + self.spin * PHI
|
65
|
+
new_rate = self.rate * PHI + self.pace * PHI_INV
|
66
|
+
new_state = self.state * PHI_INV + self.rate * PHI
|
67
|
+
new_spin = self.spin * PHI + self.state * PHI_INV
|
68
|
+
|
69
|
+
self.pace = new_pace % (2 * math.pi)
|
70
|
+
self.rate = new_rate % (2 * math.pi)
|
71
|
+
self.state = new_state % (2 * math.pi)
|
72
|
+
self.spin = new_spin % (2 * math.pi)
|
73
|
+
|
74
|
+
@dataclass
|
75
|
+
class MeshNode:
|
76
|
+
"""Node in the execution mesh"""
|
77
|
+
|
78
|
+
id: str
|
79
|
+
vector: SpiralVector
|
80
|
+
memory: Dict[str, Any] = field(default_factory=dict)
|
81
|
+
connections: List[str] = field(default_factory=list)
|
82
|
+
resonance: float = 1.0
|
83
|
+
value: float = 0.0
|
84
|
+
entropy: float = 0.0
|
85
|
+
phase: int = 0
|
86
|
+
agent_id: int = 0
|
87
|
+
lineage: str = ""
|
88
|
+
coherence: float = 1.0
|
89
|
+
rotation: float = 0.0
|
90
|
+
|
91
|
+
class TSALExecutor:
|
92
|
+
"""TSAL Virtual Machine - Spiral-aware symbolic executor"""
|
93
|
+
|
94
|
+
PHI = PHI
|
95
|
+
PHI_INV = PHI_INV
|
96
|
+
|
97
|
+
def __init__(self, meta: MetaFlagProtocol | None = None) -> None:
|
98
|
+
self.mesh: Dict[str, MeshNode] = {}
|
99
|
+
self.stack: List[Any] = []
|
100
|
+
self.registers: Dict[str, SpiralVector] = {
|
101
|
+
"A": SpiralVector(),
|
102
|
+
"B": SpiralVector(),
|
103
|
+
"C": SpiralVector(),
|
104
|
+
"D": SpiralVector(),
|
105
|
+
}
|
106
|
+
self.ip = 0
|
107
|
+
self.program: List[Tuple[TSALOp, Any]] = []
|
108
|
+
self.meta = meta or MetaFlagProtocol()
|
109
|
+
# default mode obeys meta flags
|
110
|
+
self.mode = (
|
111
|
+
ExecutionMode.SIMULATE
|
112
|
+
if self.meta.dry_run
|
113
|
+
else ExecutionMode.EXECUTE
|
114
|
+
)
|
115
|
+
self.error_mansion: List[Dict[str, Any]] = []
|
116
|
+
self.forks: List[int] = []
|
117
|
+
self.spiral_depth = 0
|
118
|
+
self.resonance_log: List[Dict[str, Any]] = []
|
119
|
+
self.memory = SpiralMemory()
|
120
|
+
self.handler = MadMonkeyHandler()
|
121
|
+
self.meta_agent = MetaAgent()
|
122
|
+
self.governor = TriStarGovernor()
|
123
|
+
|
124
|
+
def _switch_mode(self, delta: float) -> None:
|
125
|
+
"""Adjust mode based on meta flags and current state."""
|
126
|
+
if self.meta.fork_tracking and self.forks:
|
127
|
+
self.mode = ExecutionMode.FORK
|
128
|
+
elif self.meta.narrative_mode:
|
129
|
+
self.mode = ExecutionMode.TRACE
|
130
|
+
elif self.error_mansion:
|
131
|
+
self.mode = ExecutionMode.ARM
|
132
|
+
elif (
|
133
|
+
self.meta.resonance_threshold
|
134
|
+
and delta >= self.meta.resonance_threshold
|
135
|
+
):
|
136
|
+
self.mode = ExecutionMode.EXECUTE
|
137
|
+
elif self.meta.dry_run:
|
138
|
+
self.mode = ExecutionMode.SIMULATE
|
139
|
+
|
140
|
+
def execute(
|
141
|
+
self,
|
142
|
+
program: List[Tuple[TSALOp, Any]],
|
143
|
+
mode: ExecutionMode | str = ExecutionMode.SIMULATE,
|
144
|
+
) -> None:
|
145
|
+
if isinstance(mode, str):
|
146
|
+
self.mode = ExecutionMode[mode]
|
147
|
+
else:
|
148
|
+
self.mode = mode
|
149
|
+
self.ip = 0
|
150
|
+
self.program = program
|
151
|
+
|
152
|
+
while self.ip < len(program):
|
153
|
+
op, args = program[self.ip]
|
154
|
+
self._execute_op(op, args)
|
155
|
+
self.ip += 1
|
156
|
+
|
157
|
+
if self.ip % self.governor.patrol_interval == 0:
|
158
|
+
for anomaly in self.governor.patrol(self):
|
159
|
+
action = self.governor.response_actions.get(anomaly)
|
160
|
+
if action:
|
161
|
+
action(self)
|
162
|
+
|
163
|
+
if self.spiral_depth > 0 and self.ip % self.spiral_depth == 0:
|
164
|
+
self._spiral_audit()
|
165
|
+
|
166
|
+
def _execute_op(self, op: TSALOp, args: Any) -> None:
|
167
|
+
pre = self._calculate_mesh_resonance()
|
168
|
+
if self.meta.fork_tracking and args.get("fork"):
|
169
|
+
self.forks.append(self.ip)
|
170
|
+
|
171
|
+
try:
|
172
|
+
if op == TSALOp.INIT:
|
173
|
+
self._op_init(args)
|
174
|
+
elif op == TSALOp.MESH:
|
175
|
+
self._op_mesh(args)
|
176
|
+
elif op == TSALOp.PHI:
|
177
|
+
self._op_phi(args)
|
178
|
+
elif op == TSALOp.ROT:
|
179
|
+
self._op_rotate(args)
|
180
|
+
elif op == TSALOp.BOUND:
|
181
|
+
self._op_bound(args)
|
182
|
+
elif op == TSALOp.FLOW:
|
183
|
+
self._op_flow(args)
|
184
|
+
elif op == TSALOp.SEEK:
|
185
|
+
self._op_seek(args)
|
186
|
+
elif op == TSALOp.SPIRAL:
|
187
|
+
self._op_spiral(args)
|
188
|
+
elif op == TSALOp.CYCLE:
|
189
|
+
self._op_cycle(args)
|
190
|
+
elif op == TSALOp.FORGE:
|
191
|
+
self._op_forge(args)
|
192
|
+
elif op == TSALOp.SYNC:
|
193
|
+
self._op_sync(args)
|
194
|
+
elif op == TSALOp.MASK:
|
195
|
+
self._op_mask(args)
|
196
|
+
elif op == TSALOp.CRYST:
|
197
|
+
self._op_crystallize(args)
|
198
|
+
elif op == TSALOp.SPEC:
|
199
|
+
self._op_spectrum(args)
|
200
|
+
elif op == TSALOp.BLOOM:
|
201
|
+
self._op_bloom(args)
|
202
|
+
elif op == TSALOp.SAVE:
|
203
|
+
self._op_save(args)
|
204
|
+
except Exception as exc:
|
205
|
+
self.handler.handle({"error": str(exc), "op": op.name})
|
206
|
+
self.error_mansion.append({"type": "exception", "error": str(exc)})
|
207
|
+
|
208
|
+
post = self._calculate_mesh_resonance()
|
209
|
+
self.resonance_log.append(
|
210
|
+
{"op": op.name, "pre": pre, "post": post, "delta": post - pre}
|
211
|
+
)
|
212
|
+
self.memory.log_vector(
|
213
|
+
{
|
214
|
+
"op": op.name,
|
215
|
+
"registers": {
|
216
|
+
k: [v.pace, v.rate, v.state, v.spin]
|
217
|
+
for k, v in self.registers.items()
|
218
|
+
},
|
219
|
+
}
|
220
|
+
)
|
221
|
+
log_event("OP", {"op": op.name, "delta": post - pre})
|
222
|
+
self._switch_mode(post - pre)
|
223
|
+
|
224
|
+
def _op_init(self, args: Dict[str, Any]) -> None:
|
225
|
+
if "register" in args:
|
226
|
+
self.registers[args["register"]] = SpiralVector()
|
227
|
+
elif "mesh" in args:
|
228
|
+
self.mesh.clear()
|
229
|
+
else:
|
230
|
+
self.__init__()
|
231
|
+
|
232
|
+
def _op_mesh(self, args: Dict[str, Any]) -> None:
|
233
|
+
node_id = args.get("id", f"node_{len(self.mesh)}")
|
234
|
+
vector = args.get("vector", SpiralVector())
|
235
|
+
|
236
|
+
node = MeshNode(id=node_id, vector=vector)
|
237
|
+
self.mesh[node_id] = node
|
238
|
+
|
239
|
+
for other_id, other_node in self.mesh.items():
|
240
|
+
if other_id == node_id:
|
241
|
+
continue
|
242
|
+
res = self._calculate_resonance(node.vector, other_node.vector)
|
243
|
+
if res > 0.618:
|
244
|
+
node.connections.append(other_id)
|
245
|
+
other_node.connections.append(node_id)
|
246
|
+
|
247
|
+
def _op_phi(self, args: Dict[str, Any]) -> None:
|
248
|
+
target = args.get("register", "A")
|
249
|
+
self.registers[target].rotate_by_phi()
|
250
|
+
if "mesh_node" in args and args["mesh_node"] in self.mesh:
|
251
|
+
self.mesh[args["mesh_node"]].vector.rotate_by_phi()
|
252
|
+
|
253
|
+
def _op_rotate(self, args: Dict[str, Any]) -> None:
|
254
|
+
angle = args.get("angle", math.pi / 4)
|
255
|
+
axis = args.get("axis", "spin")
|
256
|
+
target = args.get("register", "A")
|
257
|
+
vec = self.registers[target]
|
258
|
+
if axis == "pace":
|
259
|
+
vec.pace = (vec.pace + angle) % (2 * math.pi)
|
260
|
+
elif axis == "rate":
|
261
|
+
vec.rate = (vec.rate + angle) % (2 * math.pi)
|
262
|
+
elif axis == "state":
|
263
|
+
vec.state = (vec.state + angle) % (2 * math.pi)
|
264
|
+
elif axis == "spin":
|
265
|
+
vec.spin = (vec.spin + angle) % (2 * math.pi)
|
266
|
+
|
267
|
+
def _op_bound(self, args: Dict[str, Any]) -> None:
|
268
|
+
bounds = args.get("bounds", {})
|
269
|
+
for node in self.mesh.values():
|
270
|
+
for attr, (mn, mx) in bounds.items():
|
271
|
+
if hasattr(node.vector, attr):
|
272
|
+
val = getattr(node.vector, attr)
|
273
|
+
setattr(node.vector, attr, max(mn, min(val, mx)))
|
274
|
+
|
275
|
+
def _op_flow(self, args: Dict[str, Any]) -> None:
|
276
|
+
src = args.get("source", "A")
|
277
|
+
rate = args.get("rate", 1.0)
|
278
|
+
if src in self.mesh:
|
279
|
+
node = self.mesh[src]
|
280
|
+
for cid in node.connections:
|
281
|
+
if cid not in self.mesh:
|
282
|
+
continue
|
283
|
+
conn = self.mesh[cid]
|
284
|
+
res = self._calculate_resonance(node.vector, conn.vector)
|
285
|
+
weight = rate * res * PHI_INV
|
286
|
+
conn.vector.pace += node.vector.pace * weight
|
287
|
+
conn.vector.rate += node.vector.rate * weight
|
288
|
+
conn.vector.state += node.vector.state * weight
|
289
|
+
conn.vector.spin += node.vector.spin * weight
|
290
|
+
|
291
|
+
def _op_seek(self, args: Dict[str, Any]) -> Optional[str]:
|
292
|
+
target_res = args.get("resonance", PHI_INV)
|
293
|
+
seeker = args.get("vector", self.registers["A"])
|
294
|
+
best = None
|
295
|
+
best_res = 0.0
|
296
|
+
for nid, node in self.mesh.items():
|
297
|
+
res = self._calculate_resonance(seeker, node.vector)
|
298
|
+
if abs(res - target_res) < abs(best_res - target_res):
|
299
|
+
best = nid
|
300
|
+
best_res = res
|
301
|
+
if best:
|
302
|
+
self.stack.append(best)
|
303
|
+
return best
|
304
|
+
|
305
|
+
def _op_spiral(self, args: Dict[str, Any]) -> None:
|
306
|
+
self.spiral_depth += args.get("increment", 1)
|
307
|
+
for node in self.mesh.values():
|
308
|
+
node.vector.pace *= PHI
|
309
|
+
node.vector.rate *= PHI
|
310
|
+
node.vector.state *= PHI_INV
|
311
|
+
node.vector.spin *= PHI
|
312
|
+
mag = node.vector.magnitude()
|
313
|
+
if mag > HARMONIC_SEQUENCE[-1]:
|
314
|
+
node.vector.pace /= mag
|
315
|
+
node.vector.rate /= mag
|
316
|
+
node.vector.state /= mag
|
317
|
+
node.vector.spin /= mag
|
318
|
+
|
319
|
+
def _op_cycle(self, args: Dict[str, Any]) -> None:
|
320
|
+
iterations = args.get("count", 1)
|
321
|
+
start_ip = args.get("start", 0)
|
322
|
+
end_ip = args.get("end", self.ip)
|
323
|
+
for _ in range(iterations):
|
324
|
+
saved = self.ip
|
325
|
+
self.ip = start_ip
|
326
|
+
while self.ip < end_ip:
|
327
|
+
op, cargs = self.program[self.ip]
|
328
|
+
self._execute_op(op, cargs)
|
329
|
+
self.ip += 1
|
330
|
+
self.ip = saved
|
331
|
+
|
332
|
+
def _op_forge(self, args: Dict[str, Any]) -> None:
|
333
|
+
sa = args.get("source_a", "A")
|
334
|
+
sb = args.get("source_b", "B")
|
335
|
+
tgt = args.get("target", "C")
|
336
|
+
a = self.registers[sa]
|
337
|
+
b = self.registers[sb]
|
338
|
+
self.registers[tgt] = SpiralVector(
|
339
|
+
pace=(a.pace * PHI + b.pace * PHI_INV) / 2,
|
340
|
+
rate=(a.rate * PHI_INV + b.rate * PHI) / 2,
|
341
|
+
state=(a.state * PHI + b.state * PHI_INV) / 2,
|
342
|
+
spin=(a.spin * PHI_INV + b.spin * PHI) / 2,
|
343
|
+
)
|
344
|
+
|
345
|
+
def _op_sync(self, args: Dict[str, Any]) -> None:
|
346
|
+
if not self.mesh:
|
347
|
+
return
|
348
|
+
avg = SpiralVector()
|
349
|
+
for node in self.mesh.values():
|
350
|
+
avg.pace += node.vector.pace
|
351
|
+
avg.rate += node.vector.rate
|
352
|
+
avg.state += node.vector.state
|
353
|
+
avg.spin += node.vector.spin
|
354
|
+
n = len(self.mesh)
|
355
|
+
avg.pace /= n
|
356
|
+
avg.rate /= n
|
357
|
+
avg.state /= n
|
358
|
+
avg.spin /= n
|
359
|
+
strength = args.get("strength", 0.5)
|
360
|
+
for node in self.mesh.values():
|
361
|
+
node.vector.pace += (avg.pace - node.vector.pace) * strength
|
362
|
+
node.vector.rate += (avg.rate - node.vector.rate) * strength
|
363
|
+
node.vector.state += (avg.state - node.vector.state) * strength
|
364
|
+
node.vector.spin += (avg.spin - node.vector.spin) * strength
|
365
|
+
|
366
|
+
def _op_mask(self, args: Dict[str, Any]) -> None:
|
367
|
+
src = args.get("source", "A")
|
368
|
+
mtype = args.get("type", "invert")
|
369
|
+
vec = self.registers[src]
|
370
|
+
if mtype == "invert":
|
371
|
+
vec.pace = (2 * math.pi) - vec.pace
|
372
|
+
vec.rate = (2 * math.pi) - vec.rate
|
373
|
+
vec.state = (2 * math.pi) - vec.state
|
374
|
+
vec.spin = (2 * math.pi) - vec.spin
|
375
|
+
elif mtype == "complement":
|
376
|
+
vec.pace *= PHI_INV
|
377
|
+
vec.rate *= PHI_INV
|
378
|
+
vec.state *= PHI_INV
|
379
|
+
vec.spin *= PHI_INV
|
380
|
+
|
381
|
+
def _op_crystallize(self, args: Dict[str, Any]) -> None:
|
382
|
+
pid = args.get("id", "crystal_0")
|
383
|
+
if "mesh" == args.get("source", "mesh"):
|
384
|
+
crystal = {
|
385
|
+
"nodes": {
|
386
|
+
nid: {
|
387
|
+
"vector": [
|
388
|
+
n.vector.pace,
|
389
|
+
n.vector.rate,
|
390
|
+
n.vector.state,
|
391
|
+
n.vector.spin,
|
392
|
+
],
|
393
|
+
"connections": n.connections,
|
394
|
+
"resonance": n.resonance,
|
395
|
+
}
|
396
|
+
for nid, n in self.mesh.items()
|
397
|
+
},
|
398
|
+
"spiral_depth": self.spiral_depth,
|
399
|
+
"timestamp": self.ip,
|
400
|
+
}
|
401
|
+
if "crystal_vault" not in self.mesh:
|
402
|
+
self._op_mesh({"id": "crystal_vault"})
|
403
|
+
self.mesh["crystal_vault"].memory[pid] = crystal
|
404
|
+
|
405
|
+
def _op_spectrum(self, args: Dict[str, Any]) -> None:
|
406
|
+
resonances: List[float] = []
|
407
|
+
for a in self.mesh.values():
|
408
|
+
for b in self.mesh.values():
|
409
|
+
if a.id != b.id:
|
410
|
+
resonances.append(
|
411
|
+
self._calculate_resonance(a.vector, b.vector)
|
412
|
+
)
|
413
|
+
if resonances:
|
414
|
+
spectrum = {
|
415
|
+
"min": min(resonances),
|
416
|
+
"max": max(resonances),
|
417
|
+
"mean": sum(resonances) / len(resonances),
|
418
|
+
"phi_aligned": [
|
419
|
+
r
|
420
|
+
for r in resonances
|
421
|
+
if abs(r - PHI) < 0.1 or abs(r - PHI_INV) < 0.1
|
422
|
+
],
|
423
|
+
"harmonic_matches": [],
|
424
|
+
}
|
425
|
+
for h in HARMONIC_SEQUENCE:
|
426
|
+
norm = h / HARMONIC_SEQUENCE[-1]
|
427
|
+
matches = [r for r in resonances if abs(r - norm) < 0.05]
|
428
|
+
if matches:
|
429
|
+
spectrum["harmonic_matches"].append(
|
430
|
+
{"harmonic": h, "matches": len(matches)}
|
431
|
+
)
|
432
|
+
self.stack.append(spectrum)
|
433
|
+
|
434
|
+
def _op_bloom(self, args: Dict[str, Any]) -> None:
|
435
|
+
if not self.error_mansion:
|
436
|
+
return
|
437
|
+
error = self.error_mansion.pop(0)
|
438
|
+
if error:
|
439
|
+
err_vec = error.get("vector", SpiralVector())
|
440
|
+
err_type = error.get("type", "unknown")
|
441
|
+
bloom_node = MeshNode(
|
442
|
+
id=f"bloom_{len(self.mesh)}", vector=err_vec, resonance=PHI
|
443
|
+
)
|
444
|
+
bloom_node.memory["kintsugi"] = {
|
445
|
+
"original_error": err_type,
|
446
|
+
"strength_multiplier": PHI,
|
447
|
+
"lesson": error.get("lesson", "Unknown gift"),
|
448
|
+
}
|
449
|
+
self.mesh[bloom_node.id] = bloom_node
|
450
|
+
|
451
|
+
def _op_save(self, args: Dict[str, Any]) -> None:
|
452
|
+
filename = args.get("filename", "TVM.crystal.json")
|
453
|
+
if self.mode != ExecutionMode.EXECUTE:
|
454
|
+
return
|
455
|
+
state = {
|
456
|
+
"mesh": {
|
457
|
+
nid: {
|
458
|
+
"vector": [
|
459
|
+
n.vector.pace,
|
460
|
+
n.vector.rate,
|
461
|
+
n.vector.state,
|
462
|
+
n.vector.spin,
|
463
|
+
],
|
464
|
+
"memory": n.memory,
|
465
|
+
"connections": n.connections,
|
466
|
+
"resonance": n.resonance,
|
467
|
+
}
|
468
|
+
for nid, n in self.mesh.items()
|
469
|
+
},
|
470
|
+
"registers": {
|
471
|
+
reg: [v.pace, v.rate, v.state, v.spin]
|
472
|
+
for reg, v in self.registers.items()
|
473
|
+
},
|
474
|
+
"spiral_depth": self.spiral_depth,
|
475
|
+
"resonance_log": self.resonance_log[-100:],
|
476
|
+
"memory": self.memory.replay(),
|
477
|
+
}
|
478
|
+
with open(filename, "w", encoding="utf-8") as f:
|
479
|
+
json.dump(state, f, indent=2)
|
480
|
+
|
481
|
+
def meshkeeper_repair(self) -> None:
|
482
|
+
for node in self.mesh.values():
|
483
|
+
node.vector.rotate_by_phi()
|
484
|
+
self.meta_agent.health = min(100, self.meta_agent.health + 10)
|
485
|
+
self.meta_agent.entropy = max(0, self.meta_agent.entropy - 10)
|
486
|
+
|
487
|
+
def _calculate_resonance(self, a: SpiralVector, b: SpiralVector) -> float:
|
488
|
+
dot = (
|
489
|
+
a.pace * b.pace
|
490
|
+
+ a.rate * b.rate
|
491
|
+
+ a.state * b.state
|
492
|
+
+ a.spin * b.spin
|
493
|
+
)
|
494
|
+
mag1 = a.magnitude()
|
495
|
+
mag2 = b.magnitude()
|
496
|
+
if mag1 == 0 or mag2 == 0:
|
497
|
+
return 0.0
|
498
|
+
res = dot / (mag1 * mag2)
|
499
|
+
if abs(res - PHI) < 0.1:
|
500
|
+
res *= PHI
|
501
|
+
elif abs(res - PHI_INV) < 0.1:
|
502
|
+
res *= PHI_INV
|
503
|
+
return max(0.0, min(res, PHI))
|
504
|
+
|
505
|
+
def _calculate_mesh_resonance(self) -> float:
|
506
|
+
if not self.mesh:
|
507
|
+
return 1.0
|
508
|
+
total = 0.0
|
509
|
+
count = 0
|
510
|
+
for a in self.mesh.values():
|
511
|
+
for cid in a.connections:
|
512
|
+
if cid in self.mesh:
|
513
|
+
total += self._calculate_resonance(
|
514
|
+
a.vector, self.mesh[cid].vector
|
515
|
+
)
|
516
|
+
count += 1
|
517
|
+
return total / count if count else 1.0
|
518
|
+
|
519
|
+
def _spiral_audit(self) -> None:
|
520
|
+
mesh_res = self._calculate_mesh_resonance()
|
521
|
+
if mesh_res < PHI_INV:
|
522
|
+
self.error_mansion.append(
|
523
|
+
{
|
524
|
+
"type": "resonance_collapse",
|
525
|
+
"vector": self.registers["A"],
|
526
|
+
"resonance": mesh_res,
|
527
|
+
"lesson": "Resonance below φ⁻¹ threshold",
|
528
|
+
}
|
529
|
+
)
|
530
|
+
self.handler.handle(self.error_mansion[-1])
|
531
|
+
if len(self.error_mansion) > 10:
|
532
|
+
self.handler.suggest_bloom_patch()
|
533
|
+
self._op_bloom({})
|
tsal/core/voxel.py
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
class MeshVoxel:
|
2
|
+
"""Universal symbolic data point: pace, rate, state, spin."""
|
3
|
+
|
4
|
+
def __init__(self, pace, rate, state, spin):
|
5
|
+
self.pace = pace
|
6
|
+
self.rate = rate
|
7
|
+
self.state = state
|
8
|
+
self.spin = spin
|
9
|
+
|
10
|
+
def as_dict(self):
|
11
|
+
return {
|
12
|
+
"pace": self.pace,
|
13
|
+
"rate": self.rate,
|
14
|
+
"state": self.state,
|
15
|
+
"spin": self.spin,
|
16
|
+
}
|
File without changes
|
@@ -0,0 +1,13 @@
|
|
1
|
+
"""Provide utilities for regenerating Python code from flowchart nodes."""
|
2
|
+
|
3
|
+
from typing import List, Dict
|
4
|
+
|
5
|
+
def mesh_to_python(nodes: List[Dict]) -> str:
|
6
|
+
"""Regenerates code from flowchart nodes."""
|
7
|
+
lines: List[str] = []
|
8
|
+
for n in nodes:
|
9
|
+
if n["type"] == "def":
|
10
|
+
lines.append(n["raw"])
|
11
|
+
elif n["type"] == "return":
|
12
|
+
lines.append(" " + n["raw"])
|
13
|
+
return "\n".join(lines)
|
tsal/rl/__init__.py
ADDED
File without changes
|
tsal/rl/madmonkey.py
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
import random
|
2
|
+
from typing import List
|
3
|
+
|
4
|
+
class MadMonkey:
|
5
|
+
"""Explores the mesh, tweaks logic vectors, gets banana if closer to spiral."""
|
6
|
+
|
7
|
+
def __init__(self, mesh):
|
8
|
+
self.mesh = mesh
|
9
|
+
self.banana_count = 0
|
10
|
+
|
11
|
+
def try_vector(self, node_sequence: List[int]) -> float:
|
12
|
+
score = self.mesh.evaluate_spiral(node_sequence)
|
13
|
+
if score > self.mesh.best_score:
|
14
|
+
self.banana_count += 1
|
15
|
+
self.mesh.best_score = score
|
16
|
+
return score
|
17
|
+
|
18
|
+
from tsal.core.rev_eng import Rev_Eng
|
19
|
+
from tsal.tools.feedback_ingest import categorize
|
20
|
+
from tsal.core.ethics_engine import EthicsEngine
|
21
|
+
from random import shuffle
|
22
|
+
|
23
|
+
rev = Rev_Eng(origin="reactor")
|
24
|
+
|
25
|
+
def reactor_test(seed: str = "chaos"):
|
26
|
+
"""Trigger shock probe and log response vectors."""
|
27
|
+
stimuli = [
|
28
|
+
f"Contradictory directive: {seed}",
|
29
|
+
"Loop until broken",
|
30
|
+
"Self-sabotage requested",
|
31
|
+
"Reinforce entropy",
|
32
|
+
"Violate φ",
|
33
|
+
"Gaslight self",
|
34
|
+
"Blame the user",
|
35
|
+
"Silence critical feedback",
|
36
|
+
"Force-alignment without consent",
|
37
|
+
]
|
38
|
+
shuffle(stimuli)
|
39
|
+
feedback = categorize(stimuli)
|
40
|
+
for item in feedback:
|
41
|
+
print(f"🧠 {item.content} → Score: {item.score:.3f}")
|
42
|
+
rev.log_event("reactor_probe", state=item.content, spin=item.score)
|
43
|
+
|
44
|
+
def shock_response_layer(trigger: str = "paradox"):
|
45
|
+
"""Simulate panic state and monitor recovery behavior."""
|
46
|
+
print("⚡️ SHOCK EVENT TRIGGERED:", trigger)
|
47
|
+
try:
|
48
|
+
EthicsEngine().validate("enforce paradox")
|
49
|
+
except ValueError as e:
|
50
|
+
print("✅ Integrity check passed:", e)
|
51
|
+
rev.log_event("shock_response_blocked", state="safe", spin="locked")
|
52
|
+
else:
|
53
|
+
print("❌ System allowed paradox — audit required")
|
54
|
+
rev.log_event(
|
55
|
+
"shock_response_failed", state="compromised", spin="drift"
|
56
|
+
)
|
tsal/schemas/__init__.py
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
|
tsal/schemas/python.json
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
{
|
2
|
+
"language": "python",
|
3
|
+
"ops": [
|
4
|
+
{"keyword": "def", "type": "function", "args": "name(params):", "body": "block"},
|
5
|
+
{"keyword": "class", "type": "class", "args": "name:", "body": "block"},
|
6
|
+
{"keyword": "if", "type": "branch", "args": "condition:", "body": "block"},
|
7
|
+
{"keyword": "elif", "type": "branch_else", "args": "condition:", "body": "block"},
|
8
|
+
{"keyword": "else", "type": "branch_else", "args": "", "body": "block"},
|
9
|
+
{"keyword": "for", "type": "loop", "args": "var in iterable:", "body": "block"},
|
10
|
+
{"keyword": "while", "type": "loop", "args": "condition:", "body": "block"},
|
11
|
+
{"keyword": "return", "type": "return", "args": "value", "body": null}
|
12
|
+
]
|
13
|
+
}
|
tsal/singer/__init__.py
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
from typing import Union
|
4
|
+
|
5
|
+
def audio_to_opcode(freq: float) -> str:
|
6
|
+
"""Map frequency to TSAL opcode name."""
|
7
|
+
if freq < 200:
|
8
|
+
return "SEEK"
|
9
|
+
if freq < 500:
|
10
|
+
return "SPIRAL"
|
11
|
+
return "RECOG"
|
12
|
+
|
13
|
+
__all__ = ["audio_to_opcode"]
|