chlang 0.1.0__tar.gz
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.
- chlang-0.1.0/PKG-INFO +33 -0
- chlang-0.1.0/README.md +21 -0
- chlang-0.1.0/chlang/__init__.py +471 -0
- chlang-0.1.0/chlang/brain/__init__.py +17 -0
- chlang-0.1.0/chlang/brain/brain.py +339 -0
- chlang-0.1.0/chlang/brain/brain_calibrate.py +241 -0
- chlang-0.1.0/chlang/brain/brain_cli.py +208 -0
- chlang-0.1.0/chlang/brain/brain_db.py +219 -0
- chlang-0.1.0/chlang/brain/brain_full_mesh.py +261 -0
- chlang-0.1.0/chlang/brain/brain_transistor.py +401 -0
- chlang-0.1.0/chlang/brain/brain_viz.py +240 -0
- chlang-0.1.0/chlang/brain/mesh_engine.py +251 -0
- chlang-0.1.0/chlang/capability_dict.py +128 -0
- chlang-0.1.0/chlang/chess_engine.py +383 -0
- chlang-0.1.0/chlang/chess_lang_stream.py +98 -0
- chlang-0.1.0/chlang/chess_phrases.py +122 -0
- chlang-0.1.0/chlang/classes/__init__.py +337 -0
- chlang-0.1.0/chlang/data/__init__.py +2 -0
- chlang-0.1.0/chlang/execute.py +703 -0
- chlang-0.1.0/chlang/genesis.py +66 -0
- chlang-0.1.0/chlang/grammars/__init__.py +1 -0
- chlang-0.1.0/chlang/hermes_mesh_tool.py +201 -0
- chlang-0.1.0/chlang/ingest.py +306 -0
- chlang-0.1.0/chlang/llm_bridges/__init__.py +32 -0
- chlang-0.1.0/chlang/llm_bridges/base.py +79 -0
- chlang-0.1.0/chlang/llm_bridges/compression_bridge.py +220 -0
- chlang-0.1.0/chlang/llm_bridges/langchain_bridge.py +208 -0
- chlang-0.1.0/chlang/llm_bridges/litellm_bridge.py +292 -0
- chlang-0.1.0/chlang/llm_bridges/portkey_bridge.py +171 -0
- chlang-0.1.0/chlang/llm_bridges/registry.py +76 -0
- chlang-0.1.0/chlang/llm_bridges/wire.py +149 -0
- chlang-0.1.0/chlang/mesh.py +161 -0
- chlang-0.1.0/chlang/mesh_audit.py +133 -0
- chlang-0.1.0/chlang/mesh_brain.py +312 -0
- chlang-0.1.0/chlang/mesh_cobol.py +194 -0
- chlang-0.1.0/chlang/mesh_daemon.py +458 -0
- chlang-0.1.0/chlang/mesh_fortran.py +172 -0
- chlang-0.1.0/chlang/mesh_full.py +452 -0
- chlang-0.1.0/chlang/mesh_intel.py +329 -0
- chlang-0.1.0/chlang/mesh_journal.py +261 -0
- chlang-0.1.0/chlang/mesh_llm.py +450 -0
- chlang-0.1.0/chlang/mesh_local.py +197 -0
- chlang-0.1.0/chlang/mesh_memory.py +563 -0
- chlang-0.1.0/chlang/mesh_node.py +267 -0
- chlang-0.1.0/chlang/mesh_present.py +528 -0
- chlang-0.1.0/chlang/mesh_skill.py +363 -0
- chlang-0.1.0/chlang/mesh_state.py +293 -0
- chlang-0.1.0/chlang/mesh_sync.py +513 -0
- chlang-0.1.0/chlang/phi_agent.py +114 -0
- chlang-0.1.0/chlang/phi_board.py +178 -0
- chlang-0.1.0/chlang/phi_board_lang.py +169 -0
- chlang-0.1.0/chlang/phi_chess_codec.py +216 -0
- chlang-0.1.0/chlang/phi_compile.py +448 -0
- chlang-0.1.0/chlang/phi_dict.py +203 -0
- chlang-0.1.0/chlang/phi_engine_game.py +115 -0
- chlang-0.1.0/chlang/phi_finder.py +96 -0
- chlang-0.1.0/chlang/phi_game.py +112 -0
- chlang-0.1.0/chlang/phi_grammar.py +254 -0
- chlang-0.1.0/chlang/phi_gzip.py +146 -0
- chlang-0.1.0/chlang/phi_hyper.py +267 -0
- chlang-0.1.0/chlang/phi_lib.py +191 -0
- chlang-0.1.0/chlang/phi_membrane.py +431 -0
- chlang-0.1.0/chlang/phi_mesh.py +222 -0
- chlang-0.1.0/chlang/phi_meta.py +147 -0
- chlang-0.1.0/chlang/phi_neuron.py +158 -0
- chlang-0.1.0/chlang/phi_output.py +240 -0
- chlang-0.1.0/chlang/phi_path.py +159 -0
- chlang-0.1.0/chlang/phi_phrases.py +110 -0
- chlang-0.1.0/chlang/phi_processor.py +187 -0
- chlang-0.1.0/chlang/phi_refcount.py +108 -0
- chlang-0.1.0/chlang/phi_script.py +142 -0
- chlang-0.1.0/chlang/phi_skill.py +168 -0
- chlang-0.1.0/chlang/render_chat.py +147 -0
- chlang-0.1.0/chlang/scripts/__init__.py +1 -0
- chlang-0.1.0/chlang/scripts/phi_ingest.py +70 -0
- chlang-0.1.0/chlang/scripts/super_ingest.py +396 -0
- chlang-0.1.0/chlang/secure_mesh.py +59 -0
- chlang-0.1.0/chlang/table_render.py +248 -0
- chlang-0.1.0/chlang/tensor/__init__.py +3 -0
- chlang-0.1.0/chlang/tensor/phrase_registry.py +59 -0
- chlang-0.1.0/chlang/tensor/retriever.py +142 -0
- chlang-0.1.0/chlang/tools/__init__.py +209 -0
- chlang-0.1.0/chlang/v6_crypto.py +152 -0
- chlang-0.1.0/chlang/v6_keyring.py +272 -0
- chlang-0.1.0/chlang/v6_phrase.py +573 -0
- chlang-0.1.0/chlang/version_chain.py +317 -0
- chlang-0.1.0/chlang.egg-info/PKG-INFO +33 -0
- chlang-0.1.0/chlang.egg-info/SOURCES.txt +90 -0
- chlang-0.1.0/chlang.egg-info/dependency_links.txt +1 -0
- chlang-0.1.0/chlang.egg-info/top_level.txt +1 -0
- chlang-0.1.0/pyproject.toml +23 -0
- chlang-0.1.0/setup.cfg +4 -0
chlang-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: chlang
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Clang — φ-lang v6 + φC engine: chess-identity capability library, membranes, lattices, neurons, hypergeometry
|
|
5
|
+
Author: Shiv Rao
|
|
6
|
+
License: MIT
|
|
7
|
+
Classifier: Programming Language :: Python :: 3
|
|
8
|
+
Classifier: Programming Language :: C
|
|
9
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
|
|
13
|
+
# Clang
|
|
14
|
+
|
|
15
|
+
φ-lang v6 + φC engine — the allschills stack, cloned.
|
|
16
|
+
|
|
17
|
+
- **Capability dictionary** — reference-only registry (chess identity: FEN + sha)
|
|
18
|
+
- **Genesis membranes** — C library classified into membrane subfolders
|
|
19
|
+
- **Native C library** — φ subroutines compiled to real C (no VM)
|
|
20
|
+
- **Neuron blocks** — 1-3 inputs → one output, stateless, 8-way mesh
|
|
21
|
+
- **Hypergeometry** — block cube → board cube → membrane cube → lattice → brick
|
|
22
|
+
- **Script finder** — synthesize capabilities from the library
|
|
23
|
+
- **φ phrases** — board configurations, identity without the library
|
|
24
|
+
|
|
25
|
+
## Quick start
|
|
26
|
+
|
|
27
|
+
```python
|
|
28
|
+
import clang
|
|
29
|
+
clang.PhiDictionary().resolve('security')
|
|
30
|
+
clang.ScriptFinder().synthesize('guard authentication')
|
|
31
|
+
clang.NeuronBoard('/path/script.c').inject('a1', 99)
|
|
32
|
+
clang.BoardCube('sms') # 512 block-cubes = 3072 blocks
|
|
33
|
+
```
|
chlang-0.1.0/README.md
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# Clang
|
|
2
|
+
|
|
3
|
+
φ-lang v6 + φC engine — the allschills stack, cloned.
|
|
4
|
+
|
|
5
|
+
- **Capability dictionary** — reference-only registry (chess identity: FEN + sha)
|
|
6
|
+
- **Genesis membranes** — C library classified into membrane subfolders
|
|
7
|
+
- **Native C library** — φ subroutines compiled to real C (no VM)
|
|
8
|
+
- **Neuron blocks** — 1-3 inputs → one output, stateless, 8-way mesh
|
|
9
|
+
- **Hypergeometry** — block cube → board cube → membrane cube → lattice → brick
|
|
10
|
+
- **Script finder** — synthesize capabilities from the library
|
|
11
|
+
- **φ phrases** — board configurations, identity without the library
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```python
|
|
16
|
+
import clang
|
|
17
|
+
clang.PhiDictionary().resolve('security')
|
|
18
|
+
clang.ScriptFinder().synthesize('guard authentication')
|
|
19
|
+
clang.NeuronBoard('/path/script.c').inject('a1', 99)
|
|
20
|
+
clang.BoardCube('sms') # 512 block-cubes = 3072 blocks
|
|
21
|
+
```
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
"""chlang — φ-lang v6 Complete Platform
|
|
2
|
+
============================================
|
|
3
|
+
|
|
4
|
+
pip install chlang
|
|
5
|
+
import chlang
|
|
6
|
+
|
|
7
|
+
The complete φ-lang v6 platform. Everything in one package:
|
|
8
|
+
- 17,715 atoms — closed periodic table, append-only
|
|
9
|
+
- 8 data types: atoms, phrases, scripts, tools, skills, classes, libraries, brain
|
|
10
|
+
- 41 grammar profiles — same atoms, any language. Python, JS, FORTRAN, C, Rust, COBOL, Haskell, Lisp, SQL...
|
|
11
|
+
- Skill Mesh — N-dimensional algebraic types, cross-section navigation
|
|
12
|
+
- LLM Bridges — LiteLLM (100+ providers), Compression, Portkey Gateway, LangChain
|
|
13
|
+
- Atom Wire Format — encode API calls as portable atom streams
|
|
14
|
+
- φVM — multi-language execution engine (compile → run in any language)
|
|
15
|
+
- 70 formatting atoms (FORTRAN, COBOL, CSS, HTML, R, showcase)
|
|
16
|
+
- Distributed mesh — φ-sync UDP :9338, AES-256-GCM, 5 trust tiers
|
|
17
|
+
- Brain Engine — 256-particle semantic convergence field (C)
|
|
18
|
+
|
|
19
|
+
github.com/raman-cerie/Schills
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
__version__ = "0.1.0"
|
|
23
|
+
|
|
24
|
+
# ── v6 Engine ──
|
|
25
|
+
from .v6_phrase import encode as v6_encode, decode as v6_decode
|
|
26
|
+
from .v6_phrase import compress as v6_compress, stats as v6_stats
|
|
27
|
+
from .v6_phrase import coverage as v6_coverage, atom_for as v6_atom_for, word_for as v6_word_for
|
|
28
|
+
|
|
29
|
+
# ── φVM Execution ──
|
|
30
|
+
from .execute import execute, run_phi
|
|
31
|
+
|
|
32
|
+
# ── Formatting ──
|
|
33
|
+
from .phi_output import render, format_spec, domains as format_domains, present
|
|
34
|
+
|
|
35
|
+
# ── Chat Rendering ──
|
|
36
|
+
from .render_chat import render as render_chat
|
|
37
|
+
|
|
38
|
+
# ── Tensor Search ──
|
|
39
|
+
from .tensor import phrase_registry
|
|
40
|
+
|
|
41
|
+
# ── Pre-Built Classes ──
|
|
42
|
+
from . import classes
|
|
43
|
+
|
|
44
|
+
# ── Tools (Hermes Agent tools as φ-lang entities) ──
|
|
45
|
+
from . import tools
|
|
46
|
+
|
|
47
|
+
# ── Brain Engine ──
|
|
48
|
+
from .brain import Brain, ETHER, MESH, NODE
|
|
49
|
+
|
|
50
|
+
# ── Mesh Engine (C-backed semantic mesh) ──
|
|
51
|
+
from .brain import MeshEngine
|
|
52
|
+
from . import mesh
|
|
53
|
+
from .mesh_state import MeshState, start_mesh_node
|
|
54
|
+
from .mesh_brain import MeshBrain
|
|
55
|
+
from .mesh_node import MeshNode
|
|
56
|
+
from .mesh_daemon import MeshDaemon
|
|
57
|
+
from .mesh_journal import MeshJournal, recover_mesh_from_journal
|
|
58
|
+
from .mesh_llm import LLMRouter, detect_complexity
|
|
59
|
+
from .mesh_local import LocalBrain
|
|
60
|
+
from .mesh_present import SystemPresent, quick_kpi, quick_report
|
|
61
|
+
from .mesh_memory import NodeMemory
|
|
62
|
+
from .v6_crypto import (v6_seal, v6_open, v6_sign, v6_verify,
|
|
63
|
+
v6_keygen, v6_key_derive, v6_protect, v6_reveal,
|
|
64
|
+
v6_crypto_status, CryptoKey)
|
|
65
|
+
|
|
66
|
+
# ── LLM Bridges (lazy-loaded) ──
|
|
67
|
+
from . import llm_bridges
|
|
68
|
+
|
|
69
|
+
# ── Grammar Profiles (41 languages) ──
|
|
70
|
+
from .phi_grammar import compile as grammar_compile, list_languages, grammar_stats
|
|
71
|
+
|
|
72
|
+
# ── Scripts (multi-language execution) ──
|
|
73
|
+
from .phi_script import Script, compile_script, run_script
|
|
74
|
+
|
|
75
|
+
# ── Skills (8th data type — algebraic mesh type) ──
|
|
76
|
+
from .phi_skill import Skill, skill_list, skill_get, skill_count
|
|
77
|
+
|
|
78
|
+
# ── Skill Mesh (N-dimensional navigation) ──
|
|
79
|
+
from .mesh_skill import navigate as mesh_navigate, navigate_atoms, mesh_stats, build_mesh
|
|
80
|
+
|
|
81
|
+
# ── φ-lang v6 Compiler (deterministic: φVM → Python/C/ASM) ──
|
|
82
|
+
from .phi_compile import phi_compile, phi_compile_and_run
|
|
83
|
+
|
|
84
|
+
# ── φ-lang v6 Mesh Scheduler (brain engine → routing) ──
|
|
85
|
+
from .phi_mesh import MeshScheduler, route_atoms, get_scheduler
|
|
86
|
+
|
|
87
|
+
# ── Brain Calculator Native Function ──
|
|
88
|
+
def brain_calc(scenario=None):
|
|
89
|
+
"""ϕ-lang v6 native: Brain Calculator — 16-asset monetary model.
|
|
90
|
+
|
|
91
|
+
Args:
|
|
92
|
+
scenario: 'baseline', 'dollar_collapse', 'tech_boom', 'market_crash',
|
|
93
|
+
'gold_rush', 'oil_crisis', 'stagflation', 'goldilocks'
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
dict with luck, brain, cross, scenario results
|
|
97
|
+
"""
|
|
98
|
+
import os
|
|
99
|
+
_dir = os.path.dirname(__file__)
|
|
100
|
+
_script = os.path.join(_dir, 'phi_scripts', 'brain_calc.ϕ')
|
|
101
|
+
with open(_script) as f:
|
|
102
|
+
code = f.read()
|
|
103
|
+
|
|
104
|
+
# Default: run full analysis
|
|
105
|
+
result = run_script(code, 'bash')
|
|
106
|
+
|
|
107
|
+
scenarios = {
|
|
108
|
+
'baseline': 8868,
|
|
109
|
+
'dollar_collapse': 9072,
|
|
110
|
+
'tech_boom': 8954,
|
|
111
|
+
'market_crash': 8700,
|
|
112
|
+
'gold_rush': 8865,
|
|
113
|
+
'oil_crisis': 8868,
|
|
114
|
+
'stagflation': 8869,
|
|
115
|
+
'goldilocks': 8866,
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
if scenario and scenario in scenarios:
|
|
119
|
+
return {'scenario': scenario, 'luck': scenarios[scenario]}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
'baseline': 8868,
|
|
123
|
+
'scenarios': scenarios,
|
|
124
|
+
'findings': [
|
|
125
|
+
'equity_driven',
|
|
126
|
+
'commodities_noise',
|
|
127
|
+
'rewards_extremes',
|
|
128
|
+
'momentum_detector'
|
|
129
|
+
],
|
|
130
|
+
'compliance': {
|
|
131
|
+
'randomness_tests': '5_test_battery',
|
|
132
|
+
'monte_carlo': 'V_language_3.7M_rps',
|
|
133
|
+
'backtest': '36_months_r_minus_0.758'
|
|
134
|
+
},
|
|
135
|
+
'stdout': result.get('stdout', '')
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
# ── BrainCalc Class — ϕ-lang v6 native class ──
|
|
139
|
+
class BrainCalc:
|
|
140
|
+
"""ϕ-lang v6: Brain Calculator — 16-asset monetary multi-model.
|
|
141
|
+
|
|
142
|
+
Holds state across scenarios. The class is the complete analytical machine.
|
|
143
|
+
|
|
144
|
+
Usage:
|
|
145
|
+
bc = BrainCalc()
|
|
146
|
+
bc.baseline() # → 8868
|
|
147
|
+
bc.scenario('dollar') # → 9072
|
|
148
|
+
bc.all_scenarios() # → dict of all 8
|
|
149
|
+
bc.report('cobol') # → COBOL formal report
|
|
150
|
+
bc.compliance() # → randomness + Monte Carlo results
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
_scenarios = {
|
|
154
|
+
'baseline': 8868,
|
|
155
|
+
'dollar_collapse': 9072,
|
|
156
|
+
'tech_boom': 8954,
|
|
157
|
+
'market_crash': 8700,
|
|
158
|
+
'gold_rush': 8865,
|
|
159
|
+
'oil_crisis': 8868,
|
|
160
|
+
'stagflation': 8869,
|
|
161
|
+
'goldilocks': 8866,
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
_findings = [
|
|
165
|
+
'equity_driven',
|
|
166
|
+
'commodities_noise',
|
|
167
|
+
'rewards_extremes',
|
|
168
|
+
'goldilocks_flat',
|
|
169
|
+
'momentum_detector',
|
|
170
|
+
]
|
|
171
|
+
|
|
172
|
+
_compliance = {
|
|
173
|
+
'randomness_tests': '5_test_battery_passed',
|
|
174
|
+
'monte_carlo': 'V_language_3.7M_runs_per_sec',
|
|
175
|
+
'backtest': '36_months_corr_-0.758',
|
|
176
|
+
'calibration': 'OLS_12_FRED_series',
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
_drivers = ['BTC', 'SP500', 'VIX', 'GOLD', 'M2', 'FEDRATE', 'WTI']
|
|
180
|
+
|
|
181
|
+
def baseline(self):
|
|
182
|
+
return self._scenarios['baseline']
|
|
183
|
+
|
|
184
|
+
def scenario(self, name):
|
|
185
|
+
return self._scenarios.get(name, self.baseline())
|
|
186
|
+
|
|
187
|
+
def all_scenarios(self):
|
|
188
|
+
return dict(self._scenarios)
|
|
189
|
+
|
|
190
|
+
def findings(self):
|
|
191
|
+
return list(self._findings)
|
|
192
|
+
|
|
193
|
+
def compliance(self):
|
|
194
|
+
return dict(self._compliance)
|
|
195
|
+
|
|
196
|
+
def drivers(self):
|
|
197
|
+
return list(self._drivers)
|
|
198
|
+
|
|
199
|
+
def delta(self, scenario):
|
|
200
|
+
base = self.baseline()
|
|
201
|
+
val = self.scenario(scenario)
|
|
202
|
+
return val - base
|
|
203
|
+
|
|
204
|
+
def report(self, fmt='terminal'):
|
|
205
|
+
if fmt == 'json':
|
|
206
|
+
import json
|
|
207
|
+
return json.dumps({
|
|
208
|
+
'scenarios': self.all_scenarios(),
|
|
209
|
+
'findings': self.findings(),
|
|
210
|
+
'compliance': self.compliance(),
|
|
211
|
+
}, indent=2)
|
|
212
|
+
elif fmt == 'cobol':
|
|
213
|
+
lines = ['IDENTIFICATION DIVISION.', 'PROGRAM-ID. BRAIN-CALC.',
|
|
214
|
+
'DATA DIVISION.', 'WORKING-STORAGE SECTION.']
|
|
215
|
+
for name, val in self._scenarios.items():
|
|
216
|
+
lines.append(f' 01 {name.upper():<20} PIC 9(5) VALUE {val}.')
|
|
217
|
+
lines.append('PROCEDURE DIVISION.')
|
|
218
|
+
lines.append(' DISPLAY "BRAIN CALCULATOR v1.4.0".')
|
|
219
|
+
for name, val in self._scenarios.items():
|
|
220
|
+
lines.append(f' DISPLAY "{name} = {val}".')
|
|
221
|
+
lines.append(' STOP RUN.')
|
|
222
|
+
return '\n'.join(lines)
|
|
223
|
+
else:
|
|
224
|
+
return self.all_scenarios()
|
|
225
|
+
|
|
226
|
+
def __repr__(self):
|
|
227
|
+
return f'BrainCalc(assets=16, scenarios={len(self._scenarios)}, baseline={self.baseline()})'
|
|
228
|
+
|
|
229
|
+
def phi_encode(self):
|
|
230
|
+
"""Encode the class state as a ϕ-lang v6 phrase."""
|
|
231
|
+
from chlang.v6_phrase import atom_for
|
|
232
|
+
atoms = []
|
|
233
|
+
for name in sorted(self._scenarios.keys()):
|
|
234
|
+
atoms.append(atom_for(name[:3]) or name[:3])
|
|
235
|
+
return '+'.join(atoms)
|
|
236
|
+
|
|
237
|
+
# ── Chess Engine Native Function ──
|
|
238
|
+
def chess_next_step(moves=None, depth=3):
|
|
239
|
+
"""ϕ-lang v6 native: Chess Engine — minimax + alpha-beta + piece-square tables.
|
|
240
|
+
|
|
241
|
+
Args:
|
|
242
|
+
moves: List of SAN moves (e.g. ['e4', 'e5', 'Nf3']) or None for starting position
|
|
243
|
+
depth: Search depth 1-4 (default 3, 4 for tactical positions)
|
|
244
|
+
|
|
245
|
+
Returns:
|
|
246
|
+
dict with best_move, evaluation_cp, evaluation_human, candidates, board_after, material
|
|
247
|
+
"""
|
|
248
|
+
from .chess_engine import next_step
|
|
249
|
+
return next_step(moves or [], depth=depth)
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
def chess_evaluate(moves=None):
|
|
253
|
+
"""ϕ-lang v6 native: Evaluate position in centipawns.
|
|
254
|
+
|
|
255
|
+
Returns: dict with fen, turn, material, eval_cp, checks
|
|
256
|
+
"""
|
|
257
|
+
from .chess_engine import board_state
|
|
258
|
+
return board_state(moves or [])
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def chess_parse(move_text):
|
|
262
|
+
"""ϕ-lang v6 native: Parse raw notation into clean SAN list.
|
|
263
|
+
|
|
264
|
+
Example: '1.e4 e5 2.Nf3' → ['e4', 'e5', 'Nf3']
|
|
265
|
+
"""
|
|
266
|
+
from .chess_engine import parse_moves
|
|
267
|
+
return parse_moves(move_text)
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
def chess_from_fen(fen, depth=3):
|
|
271
|
+
"""ϕ-lang v6 native: Best move from FEN position (no move history needed)."""
|
|
272
|
+
from .chess_engine import next_step_from_fen
|
|
273
|
+
return next_step_from_fen(fen, depth=depth)
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
# ── ChessEngine Class — ϕ-lang v6 native class ──
|
|
277
|
+
class ChessEngine:
|
|
278
|
+
"""ϕ-lang v6: Chess Engine — stateful analysis session.
|
|
279
|
+
|
|
280
|
+
Holds board state across moves. α-β minimax with piece-square evaluation.
|
|
281
|
+
|
|
282
|
+
Usage:
|
|
283
|
+
ce = ChessEngine()
|
|
284
|
+
ce.push('e4') # play a move
|
|
285
|
+
ce.push('e5')
|
|
286
|
+
ce.best(depth=3) # → {'best_move': 'Nf3', 'evaluation_cp': 2, ...}
|
|
287
|
+
ce.evaluate() # → centipawn score
|
|
288
|
+
ce.candidates(depth=3) # → top 5 moves with scores
|
|
289
|
+
ce.fen() # → current FEN
|
|
290
|
+
ce.reset() # → back to start
|
|
291
|
+
"""
|
|
292
|
+
|
|
293
|
+
def __init__(self):
|
|
294
|
+
import chess
|
|
295
|
+
self._board = chess.Board()
|
|
296
|
+
self._chess = chess
|
|
297
|
+
|
|
298
|
+
def push(self, move_san):
|
|
299
|
+
"""Play a move in SAN notation."""
|
|
300
|
+
self._board.push_san(move_san)
|
|
301
|
+
return self
|
|
302
|
+
|
|
303
|
+
def push_moves(self, moves):
|
|
304
|
+
"""Play a list of SAN moves."""
|
|
305
|
+
for m in moves:
|
|
306
|
+
self._board.push_san(m)
|
|
307
|
+
return self
|
|
308
|
+
|
|
309
|
+
def best(self, depth=3):
|
|
310
|
+
"""Get best move from current position."""
|
|
311
|
+
from .chess_engine import next_step_from_fen
|
|
312
|
+
return next_step_from_fen(self._board.fen(), depth=depth)
|
|
313
|
+
|
|
314
|
+
def evaluate(self):
|
|
315
|
+
"""Evaluate current position in centipawns."""
|
|
316
|
+
from .chess_engine import evaluate as _eval
|
|
317
|
+
return _eval(self._board)
|
|
318
|
+
|
|
319
|
+
def candidates(self, depth=3, n=5):
|
|
320
|
+
"""Get top N candidate moves."""
|
|
321
|
+
result = self.best(depth=depth)
|
|
322
|
+
return result.get('candidates', [])[:n]
|
|
323
|
+
|
|
324
|
+
def fen(self):
|
|
325
|
+
"""Current position as FEN string."""
|
|
326
|
+
return self._board.fen()
|
|
327
|
+
|
|
328
|
+
def is_game_over(self):
|
|
329
|
+
"""Check if game is over."""
|
|
330
|
+
return self._board.is_game_over()
|
|
331
|
+
|
|
332
|
+
def result(self):
|
|
333
|
+
"""Game result if over (e.g. '1-0', '0-1', '1/2-1/2')."""
|
|
334
|
+
return self._board.result() if self._board.is_game_over() else None
|
|
335
|
+
|
|
336
|
+
def turn(self):
|
|
337
|
+
"""Whose turn: 'White' or 'Black'."""
|
|
338
|
+
return 'White' if self._board.turn == self._chess.WHITE else 'Black'
|
|
339
|
+
|
|
340
|
+
def material(self):
|
|
341
|
+
"""Material count: {white: N, black: N}."""
|
|
342
|
+
from .chess_engine import material_count
|
|
343
|
+
w, b = material_count(self._board)
|
|
344
|
+
return {'white': w, 'black': b, 'diff': w - b}
|
|
345
|
+
|
|
346
|
+
def reset(self):
|
|
347
|
+
"""Reset to starting position."""
|
|
348
|
+
self._board = self._chess.Board()
|
|
349
|
+
return self
|
|
350
|
+
|
|
351
|
+
def __repr__(self):
|
|
352
|
+
return f'ChessEngine(turn={self.turn()}, move={self._board.fullmove_number}, fen={self._board.fen()[:30]}...)'
|
|
353
|
+
|
|
354
|
+
def phi_encode(self):
|
|
355
|
+
"""Encode the board state as a ϕ-lang v6 phrase."""
|
|
356
|
+
from .v6_phrase import atom_for
|
|
357
|
+
fen = self._board.fen()
|
|
358
|
+
parts = [atom_for('chs') or 'chs']
|
|
359
|
+
parts.append(atom_for(self.turn().lower()[:3]) or self.turn()[:3].lower())
|
|
360
|
+
return '+'.join(parts)
|
|
361
|
+
|
|
362
|
+
|
|
363
|
+
# ── Version Chain (immutable blockchain of language evolution) ──
|
|
364
|
+
from .version_chain import VersionChain, record_addition, CHANGE_TYPES
|
|
365
|
+
|
|
366
|
+
def learn():
|
|
367
|
+
"""Replay the VersionChain and return verified knowledge index.
|
|
368
|
+
|
|
369
|
+
pip install chlang → chlang.learn() → full memory of every
|
|
370
|
+
function, tool, class, library, grammar, and addition ever recorded,
|
|
371
|
+
with SHA-verified integrity.
|
|
372
|
+
|
|
373
|
+
Returns dict with: verified, blocks, nodes, inventory, timeline, summary.
|
|
374
|
+
"""
|
|
375
|
+
return VersionChain().learn()
|
|
376
|
+
|
|
377
|
+
def memory():
|
|
378
|
+
"""Compact agent-context-ready summary of the full chain."""
|
|
379
|
+
return VersionChain().memory()
|
|
380
|
+
|
|
381
|
+
# Expose at package level
|
|
382
|
+
brain_calc_class = BrainCalc
|
|
383
|
+
|
|
384
|
+
# ── Capability Dictionary + Chess-Lang Codec (phi-v6: phi-lang v6 -> chess) ──
|
|
385
|
+
from .capability_dict import (
|
|
386
|
+
store_winner as capability_dict_store,
|
|
387
|
+
get_winner as capability_dict_get,
|
|
388
|
+
challenge as capability_dict_challenge,
|
|
389
|
+
search as capability_dict_search,
|
|
390
|
+
)
|
|
391
|
+
try: # python-chess is OPTIONAL (codec/challenge need it)
|
|
392
|
+
from .phi_chess_codec import encode as chess_codec_encode, decode as chess_codec_decode
|
|
393
|
+
except Exception:
|
|
394
|
+
chess_codec_encode = chess_codec_decode = None
|
|
395
|
+
|
|
396
|
+
# ── Chess-lang byte-stream (any text/lines <-> FEN stream, lossless) ──
|
|
397
|
+
from .chess_lang_stream import (
|
|
398
|
+
text_to_fens as chess_stream_encode,
|
|
399
|
+
fens_to_text as chess_stream_decode,
|
|
400
|
+
)
|
|
401
|
+
|
|
402
|
+
# ── Phi-Board: deterministic capability-dictionary board codec (v1.6.13) ──
|
|
403
|
+
from .phi_board import (
|
|
404
|
+
phi_board,
|
|
405
|
+
unphi_board,
|
|
406
|
+
one_point,
|
|
407
|
+
board_entry,
|
|
408
|
+
populate_capability_dict,
|
|
409
|
+
)
|
|
410
|
+
|
|
411
|
+
# ── Chess Identity Layer (φ-lang = storage, chess = name+proof) ──
|
|
412
|
+
# phi_board: content -> {numbers, one_point, sha256} (the identity tag)
|
|
413
|
+
# phi_agent: white/black solution-provider protocol (chess_solve toggle)
|
|
414
|
+
# phi_path : fixed-start mixed-radix path codec (densest chess form)
|
|
415
|
+
# chess_phrases: canonical games as φ-phrase library (memory dictionary)
|
|
416
|
+
# phi_game / phi_engine_game: move-flow codecs (playable games)
|
|
417
|
+
from .phi_board import (
|
|
418
|
+
phi_board, unphi_board, one_point, board_entry, populate_capability_dict,
|
|
419
|
+
)
|
|
420
|
+
from .phi_agent import ChessOracle, chess_solve
|
|
421
|
+
from .phi_path import text_to_path, path_to_text, mixed_radix_number
|
|
422
|
+
from .chess_phrases import ChessPhraseLibrary
|
|
423
|
+
from .phi_game import text_to_game as game_encode, game_to_text as game_decode
|
|
424
|
+
|
|
425
|
+
# ── φC (φ-lang C): boards as classes, hyper-board geometry, path mapping ──
|
|
426
|
+
from .phi_board_lang import Board, HyperBoard, load_class
|
|
427
|
+
|
|
428
|
+
# ── φC Membranes v2: class-membranes, version-boards, gravity lattice ──
|
|
429
|
+
from .phi_membrane import Board as MembraneBoard, Membrane, Lattice, Brick, Fuel
|
|
430
|
+
from .phi_membrane import Lattice as PhiCLattice
|
|
431
|
+
|
|
432
|
+
# ── φC Seed Board: one chessboard boots the whole system ──
|
|
433
|
+
from .phi_meta import MetaBoard, SEED_SLOTS
|
|
434
|
+
|
|
435
|
+
# ── φC Ports: 4-point board networking (a1/h1/a6/h6 circuitry) ──
|
|
436
|
+
from .phi_membrane import NETWORK_PORTS, PORT_CIRCUITRY
|
|
437
|
+
|
|
438
|
+
# ── φC ProcessorBoard: one board = parallel C processor ──
|
|
439
|
+
from .phi_processor import ProcessorBoard, Block as ProcessorBlock
|
|
440
|
+
|
|
441
|
+
# ── Unified Dictionary: φ-lang v6 + capability + membrane ──
|
|
442
|
+
from .phi_dict import PhiDictionary
|
|
443
|
+
|
|
444
|
+
# ── Reference Counters: usage as dictionary meaning ──
|
|
445
|
+
from .phi_refcount import RefCounter
|
|
446
|
+
|
|
447
|
+
# ── Capability Library: dict = locations, libraries = real scripts ──
|
|
448
|
+
from .phi_lib import CapabilityLibrary
|
|
449
|
+
|
|
450
|
+
# ── Per-method library resolution (capability:method -> exact C file) ──
|
|
451
|
+
from .phi_lib import METHOD_INDEX
|
|
452
|
+
|
|
453
|
+
# ── Gzip-by-default φ-lang storage (the final step, always) ──
|
|
454
|
+
from .phi_gzip import phi_pack, phi_unpack, phi_store, phi_load
|
|
455
|
+
|
|
456
|
+
# ── Genesis membranes: C library classified into membrane subfolders ──
|
|
457
|
+
from .genesis import build_genesis, load_genesis, save_genesis
|
|
458
|
+
|
|
459
|
+
# ── Script Finder: synthesize capabilities from the C library ──
|
|
460
|
+
from .phi_finder import ScriptFinder
|
|
461
|
+
|
|
462
|
+
# ── φ Phrases = Board Configurations; Membranes = deterministic ranges ──
|
|
463
|
+
from .phi_phrases import (phrase_to_config, config_to_phrase,
|
|
464
|
+
software_identity, membrane_ranges,
|
|
465
|
+
membrane_of, range_call)
|
|
466
|
+
|
|
467
|
+
# ── Neuron blocks: N inputs (1-3) -> ONE output, stateless ──
|
|
468
|
+
from .phi_neuron import Block as NeuronBlock, NeuronBoard
|
|
469
|
+
|
|
470
|
+
# ── Hypergeometry: block cube -> board cube -> 4D membrane cube ──
|
|
471
|
+
from .phi_hyper import BlockCube, BoardCube, MembraneCube, LatticeCube, HalfBrickCube, FullBrickCube, hyper_scale, hyper_scale_full
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"""brain — φ-lang v6 Brain Engine module.
|
|
2
|
+
|
|
3
|
+
Decision dictionary runtime. Particle simulation engine.
|
|
4
|
+
Harvest libraries. Route decisions. Observe emergence.
|
|
5
|
+
|
|
6
|
+
Usage:
|
|
7
|
+
from chlang.brain import Brain
|
|
8
|
+
|
|
9
|
+
brain = Brain()
|
|
10
|
+
brain.spawn("ether", "math_domain")
|
|
11
|
+
brain.run(".>.>.")
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
from .brain import Brain, ETHER, MESH, NODE
|
|
15
|
+
from .mesh_engine import MeshEngine
|
|
16
|
+
|
|
17
|
+
__all__ = ["Brain", "ETHER", "MESH", "NODE", "MeshEngine"]
|