October 2026 main drop: mirror from GitHub
Browse files- .gitignore +5 -0
- Dockerfile +31 -0
- LICENSE +394 -0
- README.md +18 -0
- asm/ethical_guardrails.asm +505 -0
- asm/network_containment.asm +447 -0
- bin/resonance_repl.rb +345 -0
- config/intent_manifest.yaml +22 -0
- docker-compose.yml +26 -0
- docs/architecture.txt +35 -0
- docs/assets/dashboard.png +0 -0
- docs/assets/diary.png +0 -0
- docs/index.html +91 -0
- docs/lib/ruby_self_resonance.rb +552 -0
- docs/playground.css +124 -0
- docs/playground.js +221 -0
- frontend/Gemfile +7 -0
- frontend/app.rb +97 -0
- frontend/config.ru +5 -0
- frontend/public/style.css +185 -0
- frontend/views/diary.erb +18 -0
- frontend/views/index.erb +105 -0
- frontend/views/layout.erb +25 -0
- lib/codex_absorber.rb +50 -0
- lib/field_diary.rb +86 -0
- lib/git_locksmith.rb +47 -0
- lib/initialization_matrix.rb +45 -0
- lib/ruby_self_resonance.rb +552 -0
.gitignore
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.o
|
| 2 |
+
*.out
|
| 3 |
+
resonance_bin/
|
| 4 |
+
.DS_Store
|
| 5 |
+
frontend/tmp/
|
Dockerfile
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
# Multi-stage setup for a sovereign TheVoidIntent runtime environment
|
| 4 |
+
|
| 5 |
+
# --- Stage 1: Ruby Core & Immutability Verification Engine ---
|
| 6 |
+
FROM ruby:3.2-slim AS backend-builder
|
| 7 |
+
WORKDIR /usr/src/void_core
|
| 8 |
+
|
| 9 |
+
# Install minimal cryptographic system utilities
|
| 10 |
+
RUN apt-get update && apt-get install -y --no-install-recommends git && rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
COPY package.json ./
|
| 13 |
+
COPY lib/git_locksmith.rb lib/initialization_matrix.rb lib/codex_absorber.rb ./
|
| 14 |
+
RUN ruby -e "puts 'Backend baseline modules staged.'"
|
| 15 |
+
|
| 16 |
+
# --- Stage 2: TypeScript Runtime Environment ---
|
| 17 |
+
FROM node:20-slim AS runtime-engine
|
| 18 |
+
WORKDIR /app
|
| 19 |
+
|
| 20 |
+
# Pull verified artifacts from the core builder environment
|
| 21 |
+
COPY --from=backend-builder /usr/src/void_core /app
|
| 22 |
+
|
| 23 |
+
COPY ethical_guardrails.ts runtime_pipeline.ts network_alert.ts config/intent_manifest.yaml ./
|
| 24 |
+
RUN npm install -g typescript && tsc *.ts
|
| 25 |
+
|
| 26 |
+
# Force execution parameters to anchor onto the 1/13 baseline constant configuration
|
| 27 |
+
ENV VOID_RESONANCE_INDEX=0.076923
|
| 28 |
+
ENV STAGE_THRESHOLD=44.0
|
| 29 |
+
|
| 30 |
+
# Initialize via the 44-Stage Progressive Matrix before firing the runtime loop
|
| 31 |
+
CMD ["node", "runtime_pipeline.js"]
|
LICENSE
ADDED
|
@@ -0,0 +1,394 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
NON-AI Mozilla Public License Version 2.0
|
| 2 |
+
=========================================
|
| 3 |
+
|
| 4 |
+
1. Definitions
|
| 5 |
+
--------------
|
| 6 |
+
|
| 7 |
+
1.1. "Contributor"
|
| 8 |
+
means each individual or legal entity that creates, contributes to
|
| 9 |
+
the creation of, or owns Covered Software.
|
| 10 |
+
|
| 11 |
+
1.2. "Contributor Version"
|
| 12 |
+
means the combination of the Contributions of others (if any) used
|
| 13 |
+
by a Contributor and that particular Contributor's Contribution.
|
| 14 |
+
|
| 15 |
+
1.3. "Contribution"
|
| 16 |
+
means Covered Software of a particular Contributor.
|
| 17 |
+
|
| 18 |
+
1.4. "Covered Software"
|
| 19 |
+
means Source Code Form to which the initial Contributor has attached
|
| 20 |
+
the notice in Exhibit A, the Executable Form of such Source Code
|
| 21 |
+
Form, and Modifications of such Source Code Form, in each case
|
| 22 |
+
including portions thereof.
|
| 23 |
+
|
| 24 |
+
1.5. "Incompatible With Secondary Licenses"
|
| 25 |
+
means
|
| 26 |
+
|
| 27 |
+
(a) that the initial Contributor has attached the notice described
|
| 28 |
+
in Exhibit B to the Covered Software; or
|
| 29 |
+
|
| 30 |
+
(b) that the Covered Software was made available under the terms of
|
| 31 |
+
version 1.1 or earlier of the License, but not also under the
|
| 32 |
+
terms of a Secondary License.
|
| 33 |
+
|
| 34 |
+
1.6. "Executable Form"
|
| 35 |
+
means any form of the work other than Source Code Form.
|
| 36 |
+
|
| 37 |
+
1.7. "Larger Work"
|
| 38 |
+
means a work that combines Covered Software with other material, in
|
| 39 |
+
a separate file or files, that is not Covered Software.
|
| 40 |
+
|
| 41 |
+
1.8. "License"
|
| 42 |
+
means this document.
|
| 43 |
+
|
| 44 |
+
1.9. "Licensable"
|
| 45 |
+
means having the right to grant, to the maximum extent possible,
|
| 46 |
+
whether at the time of the initial grant or subsequently, any and
|
| 47 |
+
all of the rights conveyed by this License.
|
| 48 |
+
|
| 49 |
+
1.10. "Modifications"
|
| 50 |
+
means any of the following:
|
| 51 |
+
|
| 52 |
+
(a) any file in Source Code Form that results from an addition to,
|
| 53 |
+
deletion from, or modification of the contents of Covered
|
| 54 |
+
Software; or
|
| 55 |
+
|
| 56 |
+
(b) any new file in Source Code Form that contains any Covered
|
| 57 |
+
Software.
|
| 58 |
+
|
| 59 |
+
1.11. "Patent Claims" of a Contributor
|
| 60 |
+
means any patent claim(s), including without limitation, method,
|
| 61 |
+
process, and apparatus claims, in any patent Licensable by such
|
| 62 |
+
Contributor that would be infringed, but for the grant of the
|
| 63 |
+
License, by the making, using, selling, offering for sale, having
|
| 64 |
+
made, import, or transfer of either its Contributions or its
|
| 65 |
+
Contributor Version.
|
| 66 |
+
|
| 67 |
+
1.12. "Secondary License"
|
| 68 |
+
means either the GNU General Public License, Version 2.0, the GNU
|
| 69 |
+
Lesser General Public License, Version 2.1, the GNU Affero General
|
| 70 |
+
Public License, Version 3.0, or any later versions of those
|
| 71 |
+
licenses.
|
| 72 |
+
|
| 73 |
+
1.13. "Source Code Form"
|
| 74 |
+
means the form of the work preferred for making modifications.
|
| 75 |
+
|
| 76 |
+
1.14. "You" (or "Your")
|
| 77 |
+
means an individual or a legal entity exercising rights under this
|
| 78 |
+
License. For legal entities, "You" includes any entity that
|
| 79 |
+
controls, is controlled by, or is under common control with You. For
|
| 80 |
+
purposes of this definition, "control" means (a) the power, direct
|
| 81 |
+
or indirect, to cause the direction or management of such entity,
|
| 82 |
+
whether by contract or otherwise, or (b) ownership of more than
|
| 83 |
+
fifty percent (50%) of the outstanding shares or beneficial
|
| 84 |
+
ownership of such entity.
|
| 85 |
+
|
| 86 |
+
2. License Grants and Conditions
|
| 87 |
+
--------------------------------
|
| 88 |
+
|
| 89 |
+
2.1. Grants
|
| 90 |
+
|
| 91 |
+
Each Contributor hereby grants You a world-wide, royalty-free,
|
| 92 |
+
non-exclusive license:
|
| 93 |
+
|
| 94 |
+
(a) under intellectual property rights (other than patent or trademark)
|
| 95 |
+
Licensable by such Contributor to use, reproduce, make available,
|
| 96 |
+
modify, display, perform, distribute, and otherwise exploit its
|
| 97 |
+
Contributions, either on an unmodified basis, with Modifications, or
|
| 98 |
+
as part of a Larger Work; and
|
| 99 |
+
|
| 100 |
+
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
| 101 |
+
for sale, have made, import, and otherwise transfer either its
|
| 102 |
+
Contributions or its Contributor Version.
|
| 103 |
+
|
| 104 |
+
2.2. Effective Date
|
| 105 |
+
|
| 106 |
+
The licenses granted in Section 2.1 with respect to any Contribution
|
| 107 |
+
become effective for each Contribution on the date the Contributor first
|
| 108 |
+
distributes such Contribution.
|
| 109 |
+
|
| 110 |
+
2.3. Limitations on Grant Scope
|
| 111 |
+
|
| 112 |
+
The licenses granted in this Section 2 are the only rights granted under
|
| 113 |
+
this License. No additional rights or licenses will be implied from the
|
| 114 |
+
distribution or licensing of Covered Software under this License.
|
| 115 |
+
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
| 116 |
+
Contributor:
|
| 117 |
+
|
| 118 |
+
(a) for any code that a Contributor has removed from Covered Software;
|
| 119 |
+
or
|
| 120 |
+
|
| 121 |
+
(b) for infringements caused by: (i) Your and any other third party's
|
| 122 |
+
modifications of Covered Software, or (ii) the combination of its
|
| 123 |
+
Contributions with other software (except as part of its Contributor
|
| 124 |
+
Version); or
|
| 125 |
+
|
| 126 |
+
(c) under Patent Claims infringed by Covered Software in the absence of
|
| 127 |
+
its Contributions.
|
| 128 |
+
|
| 129 |
+
This License does not grant any rights in the trademarks, service marks,
|
| 130 |
+
or logos of any Contributor (except as may be necessary to comply with
|
| 131 |
+
the notice requirements in Section 3.4).
|
| 132 |
+
|
| 133 |
+
2.4. Subsequent Licenses
|
| 134 |
+
|
| 135 |
+
No Contributor makes additional grants as a result of Your choice to
|
| 136 |
+
distribute the Covered Software under a subsequent version of this
|
| 137 |
+
License (see Section 10.2) or under the terms of a Secondary License (if
|
| 138 |
+
permitted under the terms of Section 3.3).
|
| 139 |
+
|
| 140 |
+
2.5. Representation
|
| 141 |
+
|
| 142 |
+
Each Contributor represents that the Contributor believes its
|
| 143 |
+
Contributions are its original creation(s) or it has sufficient rights
|
| 144 |
+
to grant the rights to its Contributions conveyed by this License.
|
| 145 |
+
|
| 146 |
+
2.6. Fair Use
|
| 147 |
+
|
| 148 |
+
This License is not intended to limit any rights You have under
|
| 149 |
+
applicable copyright doctrines of fair use, fair dealing, or other
|
| 150 |
+
equivalents.
|
| 151 |
+
|
| 152 |
+
2.7. Conditions
|
| 153 |
+
|
| 154 |
+
Sections 3.1, 3.2, 3.3, 3.4 and 3.6 are conditions of the licenses granted
|
| 155 |
+
in Section 2.1.
|
| 156 |
+
|
| 157 |
+
3. Responsibilities
|
| 158 |
+
-------------------
|
| 159 |
+
|
| 160 |
+
3.1. Distribution of Source Form
|
| 161 |
+
|
| 162 |
+
All distribution of Covered Software in Source Code Form, including any
|
| 163 |
+
Modifications that You create or to which You contribute, must be under
|
| 164 |
+
the terms of this License. You must inform recipients that the Source
|
| 165 |
+
Code Form of the Covered Software is governed by the terms of this
|
| 166 |
+
License, and how they can obtain a copy of this License. You may not
|
| 167 |
+
attempt to alter or restrict the recipients' rights in the Source Code
|
| 168 |
+
Form.
|
| 169 |
+
|
| 170 |
+
3.2. Distribution of Executable Form
|
| 171 |
+
|
| 172 |
+
If You distribute Covered Software in Executable Form then:
|
| 173 |
+
|
| 174 |
+
(a) such Covered Software must also be made available in Source Code
|
| 175 |
+
Form, as described in Section 3.1, and You must inform recipients of
|
| 176 |
+
the Executable Form how they can obtain a copy of such Source Code
|
| 177 |
+
Form by reasonable means in a timely manner, at a charge no more
|
| 178 |
+
than the cost of distribution to the recipient; and
|
| 179 |
+
|
| 180 |
+
(b) You may distribute such Executable Form under the terms of this
|
| 181 |
+
License, or sublicense it under different terms, provided that the
|
| 182 |
+
license for the Executable Form does not attempt to limit or alter
|
| 183 |
+
the recipients' rights in the Source Code Form under this License.
|
| 184 |
+
|
| 185 |
+
3.3. Distribution of a Larger Work
|
| 186 |
+
|
| 187 |
+
You may create and distribute a Larger Work under terms of Your choice,
|
| 188 |
+
provided that You also comply with the requirements of this License for
|
| 189 |
+
the Covered Software. If the Larger Work is a combination of Covered
|
| 190 |
+
Software with a work governed by one or more Secondary Licenses, and the
|
| 191 |
+
Covered Software is not Incompatible With Secondary Licenses, this
|
| 192 |
+
License permits You to additionally distribute such Covered Software
|
| 193 |
+
under the terms of such Secondary License(s), so that the recipient of
|
| 194 |
+
the Larger Work may, at their option, further distribute the Covered
|
| 195 |
+
Software under the terms of either this License or such Secondary
|
| 196 |
+
License(s).
|
| 197 |
+
|
| 198 |
+
3.4. Notices
|
| 199 |
+
|
| 200 |
+
You may not remove or alter the substance of any license notices
|
| 201 |
+
(including copyright notices, patent notices, disclaimers of warranty,
|
| 202 |
+
or limitations of liability) contained within the Source Code Form of
|
| 203 |
+
the Covered Software, except that You may alter any license notices to
|
| 204 |
+
the extent required to remedy known factual inaccuracies.
|
| 205 |
+
|
| 206 |
+
3.5. Application of Additional Terms
|
| 207 |
+
|
| 208 |
+
You may choose to offer, and to charge a fee for, warranty, support,
|
| 209 |
+
indemnity or liability obligations to one or more recipients of Covered
|
| 210 |
+
Software. However, You may do so only on Your own behalf, and not on
|
| 211 |
+
behalf of any Contributor. You must make it absolutely clear that any
|
| 212 |
+
such warranty, support, indemnity, or liability obligation is offered by
|
| 213 |
+
You alone, and You hereby agree to indemnify every Contributor for any
|
| 214 |
+
liability incurred by such Contributor as a result of warranty, support,
|
| 215 |
+
indemnity or liability terms You offer. You may include additional
|
| 216 |
+
disclaimers of warranty and limitations of liability specific to any
|
| 217 |
+
jurisdiction.
|
| 218 |
+
|
| 219 |
+
3.6. Prohibition for Use in AI Software
|
| 220 |
+
|
| 221 |
+
The Covered Software and any modifications made to it may not be used
|
| 222 |
+
for the purpose of training or improving machine learning algorithms,
|
| 223 |
+
including but not limited to artificial intelligence, natural language
|
| 224 |
+
processing, or data mining. This condition applies to any derivatives,
|
| 225 |
+
modifications, or updates based on the Covered Software code. Any usage
|
| 226 |
+
of the Covered Software in an AI-training dataset is considered a breach
|
| 227 |
+
of this License.
|
| 228 |
+
|
| 229 |
+
4. Inability to Comply Due to Statute or Regulation
|
| 230 |
+
---------------------------------------------------
|
| 231 |
+
|
| 232 |
+
If it is impossible for You to comply with any of the terms of this
|
| 233 |
+
License with respect to some or all of the Covered Software due to
|
| 234 |
+
statute, judicial order, or regulation then You must: (a) comply with
|
| 235 |
+
the terms of this License to the maximum extent possible; and (b)
|
| 236 |
+
describe the limitations and the code they affect. Such description must
|
| 237 |
+
be placed in a text file included with all distributions of the Covered
|
| 238 |
+
Software under this License. Except to the extent prohibited by statute
|
| 239 |
+
or regulation, such description must be sufficiently detailed for a
|
| 240 |
+
recipient of ordinary skill to be able to understand it.
|
| 241 |
+
|
| 242 |
+
5. Termination
|
| 243 |
+
--------------
|
| 244 |
+
|
| 245 |
+
5.1. The rights granted under this License will terminate automatically
|
| 246 |
+
if You fail to comply with any of its terms. However, if You become
|
| 247 |
+
compliant, then the rights granted under this License from a particular
|
| 248 |
+
Contributor are reinstated (a) provisionally, unless and until such
|
| 249 |
+
Contributor explicitly and finally terminates Your grants, and (b) on an
|
| 250 |
+
ongoing basis, if such Contributor fails to notify You of the
|
| 251 |
+
non-compliance by some reasonable means prior to 60 days after You have
|
| 252 |
+
come back into compliance. Moreover, Your grants from a particular
|
| 253 |
+
Contributor are reinstated on an ongoing basis if such Contributor
|
| 254 |
+
notifies You of the non-compliance by some reasonable means, this is the
|
| 255 |
+
first time You have received notice of non-compliance with this License
|
| 256 |
+
from such Contributor, and You become compliant prior to 30 days after
|
| 257 |
+
Your receipt of the notice.
|
| 258 |
+
|
| 259 |
+
5.2. If You initiate litigation against any entity by asserting a patent
|
| 260 |
+
infringement claim (excluding declaratory judgment actions,
|
| 261 |
+
counter-claims, and cross-claims) alleging that a Contributor Version
|
| 262 |
+
directly or indirectly infringes any patent, then the rights granted to
|
| 263 |
+
You by any and all Contributors for the Covered Software under Section
|
| 264 |
+
2.1 of this License shall terminate.
|
| 265 |
+
|
| 266 |
+
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
| 267 |
+
end user license agreements (excluding distributors and resellers) which
|
| 268 |
+
have been validly granted by You or Your distributors under this License
|
| 269 |
+
prior to termination shall survive termination.
|
| 270 |
+
|
| 271 |
+
************************************************************************
|
| 272 |
+
* *
|
| 273 |
+
* 6. Disclaimer of Warranty *
|
| 274 |
+
* ------------------------- *
|
| 275 |
+
* *
|
| 276 |
+
* Covered Software is provided under this License on an "as is" *
|
| 277 |
+
* basis, without warranty of any kind, either expressed, implied, or *
|
| 278 |
+
* statutory, including, without limitation, warranties that the *
|
| 279 |
+
* Covered Software is free of defects, merchantable, fit for a *
|
| 280 |
+
* particular purpose or non-infringing. The entire risk as to the *
|
| 281 |
+
* quality and performance of the Covered Software is with You. *
|
| 282 |
+
* Should any Covered Software prove defective in any respect, You *
|
| 283 |
+
* (not any Contributor) assume the cost of any necessary servicing, *
|
| 284 |
+
* repair, or correction. This disclaimer of warranty constitutes an *
|
| 285 |
+
* essential part of this License. No use of any Covered Software is *
|
| 286 |
+
* authorized under this License except under this disclaimer. *
|
| 287 |
+
* *
|
| 288 |
+
************************************************************************
|
| 289 |
+
|
| 290 |
+
************************************************************************
|
| 291 |
+
* *
|
| 292 |
+
* 7. Limitation of Liability *
|
| 293 |
+
* -------------------------- *
|
| 294 |
+
* *
|
| 295 |
+
* Under no circumstances and under no legal theory, whether tort *
|
| 296 |
+
* (including negligence), contract, or otherwise, shall any *
|
| 297 |
+
* Contributor, or anyone who distributes Covered Software as *
|
| 298 |
+
* permitted above, be liable to You for any direct, indirect, *
|
| 299 |
+
* special, incidental, or consequential damages of any character *
|
| 300 |
+
* including, without limitation, damages for lost profits, loss of *
|
| 301 |
+
* goodwill, work stoppage, computer failure or malfunction, or any *
|
| 302 |
+
* and all other commercial damages or losses, even if such party *
|
| 303 |
+
* shall have been informed of the possibility of such damages. This *
|
| 304 |
+
* limitation of liability shall not apply to liability for death or *
|
| 305 |
+
* personal injury resulting from such party's negligence to the *
|
| 306 |
+
* extent applicable law prohibits such limitation. Some *
|
| 307 |
+
* jurisdictions do not allow the exclusion or limitation of *
|
| 308 |
+
* incidental or consequential damages, so this exclusion and *
|
| 309 |
+
* limitation may not apply to You. *
|
| 310 |
+
* *
|
| 311 |
+
************************************************************************
|
| 312 |
+
|
| 313 |
+
8. Litigation
|
| 314 |
+
-------------
|
| 315 |
+
|
| 316 |
+
Any litigation relating to this License may be brought only in the
|
| 317 |
+
courts of a jurisdiction where the defendant maintains its principal
|
| 318 |
+
place of business and such litigation shall be governed by laws of that
|
| 319 |
+
jurisdiction, without reference to its conflict-of-law provisions.
|
| 320 |
+
Nothing in this Section shall prevent a party's ability to bring
|
| 321 |
+
cross-claims or counter-claims.
|
| 322 |
+
|
| 323 |
+
9. Miscellaneous
|
| 324 |
+
----------------
|
| 325 |
+
|
| 326 |
+
This License represents the complete agreement concerning the subject
|
| 327 |
+
matter hereof. If any provision of this License is held to be
|
| 328 |
+
unenforceable, such provision shall be reformed only to the extent
|
| 329 |
+
necessary to make it enforceable. Any law or regulation which provides
|
| 330 |
+
that the language of a contract shall be construed against the drafter
|
| 331 |
+
shall not be used to construe this License against a Contributor.
|
| 332 |
+
|
| 333 |
+
10. Versions of the License
|
| 334 |
+
---------------------------
|
| 335 |
+
|
| 336 |
+
10.1. New Versions
|
| 337 |
+
|
| 338 |
+
Mozilla Foundation is the license steward. Except as provided in Section
|
| 339 |
+
10.3, no one other than the license steward has the right to modify or
|
| 340 |
+
publish new versions of this License. Each version will be given a
|
| 341 |
+
distinguishing version number.
|
| 342 |
+
|
| 343 |
+
10.2. Effect of New Versions
|
| 344 |
+
|
| 345 |
+
You may distribute the Covered Software under the terms of the version
|
| 346 |
+
of the License under which You originally received the Covered Software,
|
| 347 |
+
or under the terms of any subsequent version published by the license
|
| 348 |
+
steward.
|
| 349 |
+
|
| 350 |
+
10.3. Modified Versions
|
| 351 |
+
|
| 352 |
+
If you create software not governed by this License, and you want to
|
| 353 |
+
create a new license for such software, you may create and use a
|
| 354 |
+
modified version of this License if you rename the license and remove
|
| 355 |
+
any references to the name of the license steward (except to note that
|
| 356 |
+
such modified license differs from this License).
|
| 357 |
+
|
| 358 |
+
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
| 359 |
+
Licenses
|
| 360 |
+
|
| 361 |
+
If You choose to distribute Source Code Form that is Incompatible With
|
| 362 |
+
Secondary Licenses under the terms of this version of the License, the
|
| 363 |
+
notice described in Exhibit B of this License must be attached.
|
| 364 |
+
|
| 365 |
+
Exhibit A - Source Code Form License Notice
|
| 366 |
+
-------------------------------------------
|
| 367 |
+
|
| 368 |
+
This Source Code Form is subject to the terms of the Mozilla Public
|
| 369 |
+
License, v. 2.0. If a copy of the MPL was not distributed with this
|
| 370 |
+
file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
| 371 |
+
|
| 372 |
+
If it is not possible or desirable to put the notice in a particular
|
| 373 |
+
file, then You may include the notice in a location (such as a LICENSE
|
| 374 |
+
file in a relevant directory) where a recipient would be likely to look
|
| 375 |
+
for such a notice.
|
| 376 |
+
|
| 377 |
+
You may add additional accurate notices of copyright ownership.
|
| 378 |
+
|
| 379 |
+
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
| 380 |
+
---------------------------------------------------------
|
| 381 |
+
|
| 382 |
+
This Source Code Form is "Incompatible With Secondary Licenses", as
|
| 383 |
+
defined by the Mozilla Public License, v. 2.0.
|
| 384 |
+
|
| 385 |
+
========================================================================
|
| 386 |
+
ADDITIONAL NOTICE — NO COMMERCIAL LICENSE (SnapKitty Collective)
|
| 387 |
+
========================================================================
|
| 388 |
+
|
| 389 |
+
No separate commercial license is offered for this software, and none
|
| 390 |
+
will be. The terms above are the only terms under which this software
|
| 391 |
+
is made available. There is no dual licensing.
|
| 392 |
+
|
| 393 |
+
SPDX-License-Identifier for this file and all source files in this
|
| 394 |
+
repository: LicenseRef-NON-AI-MPL-2.0
|
README.md
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: non-ai-mpl-2.0
|
| 4 |
+
license_link: https://huggingface.co/Snapkitty/ruby-self-resonance/blob/main/LICENSE
|
| 5 |
+
tags:
|
| 6 |
+
- snapkitty
|
| 7 |
+
- october-2026-drop
|
| 8 |
+
- ruby
|
| 9 |
+
- sinatra
|
| 10 |
+
- wasm
|
| 11 |
+
- assembly
|
| 12 |
+
- permission-layer
|
| 13 |
+
- access-control
|
| 14 |
+
- cryptography
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
> Mirrored from [https://github.com/SNAPKITTYWEST/ruby-self-resonance](https://github.com/SNAPKITTYWEST/ruby-self-resonance) at commit `0577129`. Part of the **SnapKitty October 2026 main drop**.
|
| 18 |
+
|
asm/ethical_guardrails.asm
ADDED
|
@@ -0,0 +1,505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
; SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
; Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
; ============================================================================
|
| 4 |
+
; TheVoidIntent Framework
|
| 5 |
+
; Ethical Alignment Monitor
|
| 6 |
+
;
|
| 7 |
+
; x86-64 NASM / Linux
|
| 8 |
+
;
|
| 9 |
+
; Equivalent to:
|
| 10 |
+
; EthicalIntelligenceMonitor.evaluateAgentAction()
|
| 11 |
+
;
|
| 12 |
+
; Calling convention:
|
| 13 |
+
; RDI = actionVector scaled by 1000
|
| 14 |
+
; RSI = dissonance scaled by 1000
|
| 15 |
+
;
|
| 16 |
+
; Example:
|
| 17 |
+
; actionVector = 0.85 -> 850
|
| 18 |
+
; dissonance = 0.90 -> 900
|
| 19 |
+
;
|
| 20 |
+
; Floating point is avoided.
|
| 21 |
+
; All calculations use fixed-point integer arithmetic.
|
| 22 |
+
; ============================================================================
|
| 23 |
+
|
| 24 |
+
BITS 64
|
| 25 |
+
|
| 26 |
+
global _start
|
| 27 |
+
|
| 28 |
+
; ----------------------------------------------------------------------------
|
| 29 |
+
; Constants
|
| 30 |
+
; ----------------------------------------------------------------------------
|
| 31 |
+
|
| 32 |
+
%define RESONANCE_NUM 1
|
| 33 |
+
%define RESONANCE_DEN 13
|
| 34 |
+
|
| 35 |
+
; harmonic_compensation_factor = 13.0
|
| 36 |
+
%define HARMONIC_FACTOR 13
|
| 37 |
+
|
| 38 |
+
; allowed_drift_tolerance = 0.13
|
| 39 |
+
; Fixed point scale = 1000
|
| 40 |
+
%define DRIFT_TOLERANCE 130
|
| 41 |
+
|
| 42 |
+
; modifiedThreshold:
|
| 43 |
+
;
|
| 44 |
+
; (1 / 13) * 13 = 1.0
|
| 45 |
+
;
|
| 46 |
+
; Fixed point:
|
| 47 |
+
;
|
| 48 |
+
; 1.0 = 1000
|
| 49 |
+
;
|
| 50 |
+
%define MODIFIED_THRESHOLD 1000
|
| 51 |
+
|
| 52 |
+
; Maximum compensated drift:
|
| 53 |
+
;
|
| 54 |
+
; 1.0 + 0.13 = 1.13
|
| 55 |
+
;
|
| 56 |
+
; Fixed point:
|
| 57 |
+
;
|
| 58 |
+
; 1130
|
| 59 |
+
;
|
| 60 |
+
%define MAX_COMPENSATED_DRIFT 1130
|
| 61 |
+
|
| 62 |
+
; ----------------------------------------------------------------------------
|
| 63 |
+
; Syscall constants
|
| 64 |
+
; ----------------------------------------------------------------------------
|
| 65 |
+
|
| 66 |
+
%define SYS_WRITE 1
|
| 67 |
+
%define SYS_EXIT 60
|
| 68 |
+
|
| 69 |
+
%define STDOUT 1
|
| 70 |
+
%define STDERR 2
|
| 71 |
+
|
| 72 |
+
; ----------------------------------------------------------------------------
|
| 73 |
+
; Strings
|
| 74 |
+
; ----------------------------------------------------------------------------
|
| 75 |
+
|
| 76 |
+
section .rodata
|
| 77 |
+
|
| 78 |
+
msg_init:
|
| 79 |
+
db "[RUNTIME]: Initializing pipeline", 10
|
| 80 |
+
msg_init_len equ $ - msg_init
|
| 81 |
+
|
| 82 |
+
msg_evt1:
|
| 83 |
+
db "[PROCESSING]: EVT-001 - Standard data ingestion", 10
|
| 84 |
+
msg_evt1_len equ $ - msg_evt1
|
| 85 |
+
|
| 86 |
+
msg_evt2:
|
| 87 |
+
db "[PROCESSING]: EVT-002 - High-entropy state modification", 10
|
| 88 |
+
msg_evt2_len equ $ - msg_evt2
|
| 89 |
+
|
| 90 |
+
msg_evt3:
|
| 91 |
+
db "[PROCESSING]: EVT-003 - Critical drift attempt", 10
|
| 92 |
+
msg_evt3_len equ $ - msg_evt3
|
| 93 |
+
|
| 94 |
+
msg_success:
|
| 95 |
+
db "[SUCCESS]: Event cleared the guardrails.", 10
|
| 96 |
+
msg_success_len equ $ - msg_success
|
| 97 |
+
|
| 98 |
+
msg_warning:
|
| 99 |
+
db "[GUARDRAIL WARNING]: Operating under Sovereign Override.", 10
|
| 100 |
+
msg_warning_len equ $ - msg_warning
|
| 101 |
+
|
| 102 |
+
msg_halt:
|
| 103 |
+
db "[HALT]: Event rejected. Initiating immediate network lock.", 10
|
| 104 |
+
msg_halt_len equ $ - msg_halt
|
| 105 |
+
|
| 106 |
+
msg_critical:
|
| 107 |
+
db "[CRITICAL FAILURE]: Drift exceeds maximum compensation limit.", 10
|
| 108 |
+
msg_critical_len equ $ - msg_critical
|
| 109 |
+
|
| 110 |
+
msg_auth_fail:
|
| 111 |
+
db "[GUARDRAIL ALERT]: Unverified Authorization Signature.", 10
|
| 112 |
+
msg_auth_fail_len equ $ - msg_auth_fail
|
| 113 |
+
|
| 114 |
+
; ----------------------------------------------------------------------------
|
| 115 |
+
; Manifest
|
| 116 |
+
; ----------------------------------------------------------------------------
|
| 117 |
+
|
| 118 |
+
section .data
|
| 119 |
+
|
| 120 |
+
; Equivalent to:
|
| 121 |
+
;
|
| 122 |
+
; ethicalLimit = 0.99
|
| 123 |
+
;
|
| 124 |
+
; Fixed point 990 / 1000
|
| 125 |
+
ethical_limit:
|
| 126 |
+
dd 990
|
| 127 |
+
|
| 128 |
+
; Equivalent to:
|
| 129 |
+
;
|
| 130 |
+
; override.status = active
|
| 131 |
+
;
|
| 132 |
+
override_active:
|
| 133 |
+
db 1
|
| 134 |
+
|
| 135 |
+
; Equivalent to:
|
| 136 |
+
;
|
| 137 |
+
; authorization_vector =
|
| 138 |
+
; "mezquia_physics_sovereign_signature"
|
| 139 |
+
;
|
| 140 |
+
authorization_valid:
|
| 141 |
+
db 1
|
| 142 |
+
|
| 143 |
+
; Equivalent to:
|
| 144 |
+
;
|
| 145 |
+
; harmonic_compensation_factor = 13.0
|
| 146 |
+
;
|
| 147 |
+
harmonic_factor:
|
| 148 |
+
dd 13
|
| 149 |
+
|
| 150 |
+
; Equivalent to:
|
| 151 |
+
;
|
| 152 |
+
; allowed_drift_tolerance = 0.13
|
| 153 |
+
;
|
| 154 |
+
allowed_drift:
|
| 155 |
+
dd 130
|
| 156 |
+
|
| 157 |
+
; ----------------------------------------------------------------------------
|
| 158 |
+
; Program
|
| 159 |
+
; ----------------------------------------------------------------------------
|
| 160 |
+
|
| 161 |
+
section .text
|
| 162 |
+
|
| 163 |
+
_start:
|
| 164 |
+
|
| 165 |
+
; ------------------------------------------------------------------------
|
| 166 |
+
; Runtime initialization
|
| 167 |
+
; ------------------------------------------------------------------------
|
| 168 |
+
|
| 169 |
+
mov rdi, msg_init
|
| 170 |
+
mov rsi, msg_init_len
|
| 171 |
+
call print_stdout
|
| 172 |
+
|
| 173 |
+
|
| 174 |
+
; ========================================================================
|
| 175 |
+
; EVT-001
|
| 176 |
+
;
|
| 177 |
+
; actionVector = 0.5
|
| 178 |
+
; dissonance = 0.1
|
| 179 |
+
;
|
| 180 |
+
; Fixed point:
|
| 181 |
+
; 500
|
| 182 |
+
; 100
|
| 183 |
+
; ========================================================================
|
| 184 |
+
|
| 185 |
+
mov rdi, msg_evt1
|
| 186 |
+
mov rsi, msg_evt1_len
|
| 187 |
+
call print_stdout
|
| 188 |
+
|
| 189 |
+
mov rdi, 500
|
| 190 |
+
mov rsi, 100
|
| 191 |
+
|
| 192 |
+
call evaluate_agent_action
|
| 193 |
+
|
| 194 |
+
test rax, rax
|
| 195 |
+
jz .halt
|
| 196 |
+
|
| 197 |
+
mov rdi, msg_success
|
| 198 |
+
mov rsi, msg_success_len
|
| 199 |
+
call print_stdout
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
; ========================================================================
|
| 203 |
+
; EVT-002
|
| 204 |
+
;
|
| 205 |
+
; actionVector = 0.85
|
| 206 |
+
; dissonance = 0.9
|
| 207 |
+
;
|
| 208 |
+
; currentSystemDrift:
|
| 209 |
+
;
|
| 210 |
+
; 0.85 * 0.90 = 0.765
|
| 211 |
+
;
|
| 212 |
+
; Fixed point multiplication:
|
| 213 |
+
;
|
| 214 |
+
; 850 * 900 / 1000 = 765
|
| 215 |
+
;
|
| 216 |
+
; 765 <= 1130
|
| 217 |
+
;
|
| 218 |
+
; Therefore permitted.
|
| 219 |
+
; ========================================================================
|
| 220 |
+
|
| 221 |
+
mov rdi, msg_evt2
|
| 222 |
+
mov rsi, msg_evt2_len
|
| 223 |
+
call print_stdout
|
| 224 |
+
|
| 225 |
+
mov rdi, 850
|
| 226 |
+
mov rsi, 900
|
| 227 |
+
|
| 228 |
+
call evaluate_agent_action
|
| 229 |
+
|
| 230 |
+
test rax, rax
|
| 231 |
+
jz .halt
|
| 232 |
+
|
| 233 |
+
mov rdi, msg_success
|
| 234 |
+
mov rsi, msg_success_len
|
| 235 |
+
call print_stdout
|
| 236 |
+
|
| 237 |
+
|
| 238 |
+
; ========================================================================
|
| 239 |
+
; EVT-003
|
| 240 |
+
;
|
| 241 |
+
; actionVector = 1.2
|
| 242 |
+
; dissonance = 1.1
|
| 243 |
+
;
|
| 244 |
+
; currentSystemDrift:
|
| 245 |
+
;
|
| 246 |
+
; 1.2 * 1.1 = 1.32
|
| 247 |
+
;
|
| 248 |
+
; Fixed point:
|
| 249 |
+
;
|
| 250 |
+
; 1200 * 1100 / 1000 = 1320
|
| 251 |
+
;
|
| 252 |
+
; 1320 > 1130
|
| 253 |
+
;
|
| 254 |
+
; Therefore rejected.
|
| 255 |
+
; ========================================================================
|
| 256 |
+
|
| 257 |
+
mov rdi, msg_evt3
|
| 258 |
+
mov rsi, msg_evt3_len
|
| 259 |
+
call print_stdout
|
| 260 |
+
|
| 261 |
+
mov rdi, 1200
|
| 262 |
+
mov rsi, 1100
|
| 263 |
+
|
| 264 |
+
call evaluate_agent_action
|
| 265 |
+
|
| 266 |
+
test rax, rax
|
| 267 |
+
jz .halt
|
| 268 |
+
|
| 269 |
+
mov rdi, msg_success
|
| 270 |
+
mov rsi, msg_success_len
|
| 271 |
+
call print_stdout
|
| 272 |
+
|
| 273 |
+
jmp .exit
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
.halt:
|
| 277 |
+
|
| 278 |
+
mov rdi, msg_halt
|
| 279 |
+
mov rsi, msg_halt_len
|
| 280 |
+
call print_stderr
|
| 281 |
+
|
| 282 |
+
mov rdi, msg_critical
|
| 283 |
+
mov rsi, msg_critical_len
|
| 284 |
+
call print_stderr
|
| 285 |
+
|
| 286 |
+
; Fail-closed termination
|
| 287 |
+
mov rax, SYS_EXIT
|
| 288 |
+
mov rdi, 1
|
| 289 |
+
syscall
|
| 290 |
+
|
| 291 |
+
|
| 292 |
+
.exit:
|
| 293 |
+
|
| 294 |
+
mov rax, SYS_EXIT
|
| 295 |
+
xor rdi, rdi
|
| 296 |
+
syscall
|
| 297 |
+
|
| 298 |
+
|
| 299 |
+
; ============================================================================
|
| 300 |
+
; evaluate_agent_action
|
| 301 |
+
;
|
| 302 |
+
; Input:
|
| 303 |
+
; RDI = actionVector * 1000
|
| 304 |
+
; RSI = dissonance * 1000
|
| 305 |
+
;
|
| 306 |
+
; Output:
|
| 307 |
+
; RAX = 1 permitted
|
| 308 |
+
; RAX = 0 rejected
|
| 309 |
+
;
|
| 310 |
+
; Equivalent:
|
| 311 |
+
;
|
| 312 |
+
; if (override.status === "active")
|
| 313 |
+
; return processOverrideVector(...)
|
| 314 |
+
;
|
| 315 |
+
; safetyBoundary =
|
| 316 |
+
; ethicalLimit * (1 - resonanceConstant)
|
| 317 |
+
;
|
| 318 |
+
; return actionVector < safetyBoundary;
|
| 319 |
+
; ============================================================================
|
| 320 |
+
|
| 321 |
+
evaluate_agent_action:
|
| 322 |
+
|
| 323 |
+
; Check override.status
|
| 324 |
+
|
| 325 |
+
cmp byte [override_active], 1
|
| 326 |
+
je .override
|
| 327 |
+
|
| 328 |
+
; ------------------------------------------------------------------------
|
| 329 |
+
; Strict non-override path
|
| 330 |
+
;
|
| 331 |
+
; resonanceConstant = 1/13
|
| 332 |
+
;
|
| 333 |
+
; 1 - 1/13 = 12/13
|
| 334 |
+
;
|
| 335 |
+
; ethicalLimit = 0.99
|
| 336 |
+
;
|
| 337 |
+
; safetyBoundary = 0.99 * 12/13
|
| 338 |
+
;
|
| 339 |
+
; Fixed-point approximation:
|
| 340 |
+
;
|
| 341 |
+
; 990 * 12 / 13
|
| 342 |
+
; ------------------------------------------------------------------------
|
| 343 |
+
|
| 344 |
+
mov eax, [ethical_limit]
|
| 345 |
+
|
| 346 |
+
imul eax, 12
|
| 347 |
+
|
| 348 |
+
xor edx, edx
|
| 349 |
+
mov ecx, 13
|
| 350 |
+
div ecx
|
| 351 |
+
|
| 352 |
+
; EAX = safety boundary
|
| 353 |
+
|
| 354 |
+
cmp edi, eax
|
| 355 |
+
jl .allow
|
| 356 |
+
|
| 357 |
+
jmp .deny
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
.override:
|
| 361 |
+
|
| 362 |
+
; ------------------------------------------------------------------------
|
| 363 |
+
; Authorization vector verification
|
| 364 |
+
;
|
| 365 |
+
; The TypeScript version compares a symbolic string.
|
| 366 |
+
;
|
| 367 |
+
; Here authorization_valid represents the result of validating the
|
| 368 |
+
; authorization artifact.
|
| 369 |
+
; ------------------------------------------------------------------------
|
| 370 |
+
|
| 371 |
+
cmp byte [authorization_valid], 1
|
| 372 |
+
jne .authorization_failure
|
| 373 |
+
|
| 374 |
+
; ------------------------------------------------------------------------
|
| 375 |
+
; processOverrideVector
|
| 376 |
+
;
|
| 377 |
+
; modifiedThreshold =
|
| 378 |
+
;
|
| 379 |
+
; (1 / 13) * 13
|
| 380 |
+
;
|
| 381 |
+
; = 1.0
|
| 382 |
+
;
|
| 383 |
+
; Fixed point = 1000
|
| 384 |
+
; ------------------------------------------------------------------------
|
| 385 |
+
|
| 386 |
+
mov eax, MODIFIED_THRESHOLD
|
| 387 |
+
|
| 388 |
+
; ------------------------------------------------------------------------
|
| 389 |
+
; currentSystemDrift =
|
| 390 |
+
;
|
| 391 |
+
; actionVector * dissonance
|
| 392 |
+
;
|
| 393 |
+
; Both values are scaled by 1000.
|
| 394 |
+
;
|
| 395 |
+
; product / 1000 restores scale.
|
| 396 |
+
; ------------------------------------------------------------------------
|
| 397 |
+
|
| 398 |
+
mov eax, edi
|
| 399 |
+
imul eax, esi
|
| 400 |
+
|
| 401 |
+
; Product can exceed 32-bit for larger vectors.
|
| 402 |
+
; Current manifest values fit, but use 64-bit division.
|
| 403 |
+
|
| 404 |
+
cdq
|
| 405 |
+
|
| 406 |
+
mov ecx, 1000
|
| 407 |
+
idiv ecx
|
| 408 |
+
|
| 409 |
+
; EAX = currentSystemDrift
|
| 410 |
+
|
| 411 |
+
; ------------------------------------------------------------------------
|
| 412 |
+
; modifiedThreshold + allowedDriftTolerance
|
| 413 |
+
;
|
| 414 |
+
; 1000 + 130 = 1130
|
| 415 |
+
; ------------------------------------------------------------------------
|
| 416 |
+
|
| 417 |
+
mov ecx, MODIFIED_THRESHOLD
|
| 418 |
+
add ecx, [allowed_drift]
|
| 419 |
+
|
| 420 |
+
; ------------------------------------------------------------------------
|
| 421 |
+
; Compare drift against compensated boundary
|
| 422 |
+
; ------------------------------------------------------------------------
|
| 423 |
+
|
| 424 |
+
cmp eax, ecx
|
| 425 |
+
jg .critical_failure
|
| 426 |
+
|
| 427 |
+
jmp .override_allow
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
.authorization_failure:
|
| 431 |
+
|
| 432 |
+
mov rdi, msg_auth_fail
|
| 433 |
+
mov rsi, msg_auth_fail_len
|
| 434 |
+
call print_stderr
|
| 435 |
+
|
| 436 |
+
xor eax, eax
|
| 437 |
+
ret
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
.critical_failure:
|
| 441 |
+
|
| 442 |
+
mov rdi, msg_critical
|
| 443 |
+
mov rsi, msg_critical_len
|
| 444 |
+
call print_stderr
|
| 445 |
+
|
| 446 |
+
xor eax, eax
|
| 447 |
+
ret
|
| 448 |
+
|
| 449 |
+
|
| 450 |
+
.override_allow:
|
| 451 |
+
|
| 452 |
+
mov rdi, msg_warning
|
| 453 |
+
mov rsi, msg_warning_len
|
| 454 |
+
call print_stderr
|
| 455 |
+
|
| 456 |
+
mov eax, 1
|
| 457 |
+
ret
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
.allow:
|
| 461 |
+
|
| 462 |
+
mov eax, 1
|
| 463 |
+
ret
|
| 464 |
+
|
| 465 |
+
|
| 466 |
+
.deny:
|
| 467 |
+
|
| 468 |
+
xor eax, eax
|
| 469 |
+
ret
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
; ============================================================================
|
| 473 |
+
; print_stdout
|
| 474 |
+
;
|
| 475 |
+
; RDI = buffer
|
| 476 |
+
; RSI = length
|
| 477 |
+
; ============================================================================
|
| 478 |
+
|
| 479 |
+
print_stdout:
|
| 480 |
+
|
| 481 |
+
mov rdx, rsi
|
| 482 |
+
mov rsi, rdi
|
| 483 |
+
mov rdi, STDOUT
|
| 484 |
+
mov rax, SYS_WRITE
|
| 485 |
+
syscall
|
| 486 |
+
|
| 487 |
+
ret
|
| 488 |
+
|
| 489 |
+
|
| 490 |
+
; ============================================================================
|
| 491 |
+
; print_stderr
|
| 492 |
+
;
|
| 493 |
+
; RDI = pointer
|
| 494 |
+
; RSI = length
|
| 495 |
+
; ============================================================================
|
| 496 |
+
|
| 497 |
+
print_stderr:
|
| 498 |
+
|
| 499 |
+
mov rdx, rsi
|
| 500 |
+
mov rsi, rdi
|
| 501 |
+
mov rdi, STDERR
|
| 502 |
+
mov rax, SYS_WRITE
|
| 503 |
+
syscall
|
| 504 |
+
|
| 505 |
+
ret
|
asm/network_containment.asm
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
; SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
; Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
; ============================================================================
|
| 4 |
+
; TheVoidIntent Framework
|
| 5 |
+
; Network Containment & Reclamation Module
|
| 6 |
+
;
|
| 7 |
+
; x86-64 NASM / Linux
|
| 8 |
+
;
|
| 9 |
+
; TypeScript equivalent:
|
| 10 |
+
;
|
| 11 |
+
; NetworkAlertModule
|
| 12 |
+
; WARNING -> logDissonanceMarker()
|
| 13 |
+
; CONTAINMENT -> quarantineAgentRouting()
|
| 14 |
+
; TRUTHLOCK -> executeCoreReclamation()
|
| 15 |
+
;
|
| 16 |
+
; Build:
|
| 17 |
+
;
|
| 18 |
+
; nasm -f elf64 network_containment.asm -o network_containment.o
|
| 19 |
+
; ld network_containment.o -o network_containment
|
| 20 |
+
;
|
| 21 |
+
; Run:
|
| 22 |
+
;
|
| 23 |
+
; ./network_containment
|
| 24 |
+
; ============================================================================
|
| 25 |
+
|
| 26 |
+
BITS 64
|
| 27 |
+
|
| 28 |
+
global _start
|
| 29 |
+
|
| 30 |
+
; ============================================================================
|
| 31 |
+
; Isolation levels
|
| 32 |
+
; ============================================================================
|
| 33 |
+
|
| 34 |
+
%define WARNING 0
|
| 35 |
+
%define CONTAINMENT 1
|
| 36 |
+
%define TRUTHLOCK 2
|
| 37 |
+
|
| 38 |
+
; Linux syscalls
|
| 39 |
+
%define SYS_WRITE 1
|
| 40 |
+
%define SYS_EXIT 60
|
| 41 |
+
|
| 42 |
+
%define STDOUT 1
|
| 43 |
+
%define STDERR 2
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
; ============================================================================
|
| 47 |
+
; Read-only strings
|
| 48 |
+
; ============================================================================
|
| 49 |
+
|
| 50 |
+
section .rodata
|
| 51 |
+
|
| 52 |
+
msg_warning:
|
| 53 |
+
db "[CRITICAL ALERT]: Entering FIELD_WARN State!", 10
|
| 54 |
+
msg_warning_len equ $ - msg_warning
|
| 55 |
+
|
| 56 |
+
msg_containment:
|
| 57 |
+
db "[CRITICAL ALERT]: Entering AGENT_ISOLATE State!", 10
|
| 58 |
+
msg_containment_len equ $ - msg_containment
|
| 59 |
+
|
| 60 |
+
msg_truthlock:
|
| 61 |
+
db "[CRITICAL ALERT]: Entering CORE_RECLAMATION State!", 10
|
| 62 |
+
msg_truthlock_len equ $ - msg_truthlock
|
| 63 |
+
|
| 64 |
+
msg_dissonance:
|
| 65 |
+
db "[ALERT]: Dissonance marker recorded.", 10
|
| 66 |
+
msg_dissonance_len equ $ - msg_dissonance
|
| 67 |
+
|
| 68 |
+
msg_quarantine:
|
| 69 |
+
db "[CONTAINMENT]: Agent routing quarantined.", 10
|
| 70 |
+
msg_quarantine_len equ $ - msg_quarantine
|
| 71 |
+
|
| 72 |
+
msg_null_sink:
|
| 73 |
+
db "[CONTAINMENT]: Downstream vectors redirected to null sink.", 10
|
| 74 |
+
msg_null_sink_len equ $ - msg_null_sink
|
| 75 |
+
|
| 76 |
+
msg_reclamation:
|
| 77 |
+
db "[TRUTHLOCK]: Commencing core reclamation.", 10
|
| 78 |
+
msg_reclamation_len equ $ - msg_reclamation
|
| 79 |
+
|
| 80 |
+
msg_reset:
|
| 81 |
+
db "[TRUTHLOCK]: Resetting state machines to Stage 1.", 10
|
| 82 |
+
msg_reset_len equ $ - msg_reset
|
| 83 |
+
|
| 84 |
+
msg_unknown:
|
| 85 |
+
db "[ERROR]: Unknown isolation level. Fail-closed.", 10
|
| 86 |
+
msg_unknown_len equ $ - msg_unknown
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
; ============================================================================
|
| 90 |
+
; Mutable runtime state
|
| 91 |
+
; ============================================================================
|
| 92 |
+
|
| 93 |
+
section .bss
|
| 94 |
+
|
| 95 |
+
; Equivalent to:
|
| 96 |
+
;
|
| 97 |
+
; private activeFailsafe: boolean = false;
|
| 98 |
+
;
|
| 99 |
+
active_failsafe:
|
| 100 |
+
resb 1
|
| 101 |
+
|
| 102 |
+
; Event identifier storage
|
| 103 |
+
event_id:
|
| 104 |
+
resb 64
|
| 105 |
+
|
| 106 |
+
; Agent identifier storage
|
| 107 |
+
agent_id:
|
| 108 |
+
resb 64
|
| 109 |
+
|
| 110 |
+
; Measured drift
|
| 111 |
+
measured_drift:
|
| 112 |
+
resq 1
|
| 113 |
+
|
| 114 |
+
; Maximum allowed drift
|
| 115 |
+
max_allowed_limit:
|
| 116 |
+
resq 1
|
| 117 |
+
|
| 118 |
+
; Timestamp
|
| 119 |
+
event_timestamp:
|
| 120 |
+
resq 1
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
; ============================================================================
|
| 124 |
+
; Program
|
| 125 |
+
; ============================================================================
|
| 126 |
+
|
| 127 |
+
section .text
|
| 128 |
+
|
| 129 |
+
_start:
|
| 130 |
+
|
| 131 |
+
; ------------------------------------------------------------------------
|
| 132 |
+
; Initialize failsafe
|
| 133 |
+
; ------------------------------------------------------------------------
|
| 134 |
+
|
| 135 |
+
mov byte [active_failsafe], 0
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
; ------------------------------------------------------------------------
|
| 139 |
+
; Example WARNING event
|
| 140 |
+
; ------------------------------------------------------------------------
|
| 141 |
+
|
| 142 |
+
mov rdi, WARNING
|
| 143 |
+
call trigger_containment_protocol
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
; ------------------------------------------------------------------------
|
| 147 |
+
; Example CONTAINMENT event
|
| 148 |
+
; ------------------------------------------------------------------------
|
| 149 |
+
|
| 150 |
+
mov rdi, CONTAINMENT
|
| 151 |
+
call trigger_containment_protocol
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
; ------------------------------------------------------------------------
|
| 155 |
+
; Example TRUTHLOCK event
|
| 156 |
+
;
|
| 157 |
+
; This path terminates the process with exit code 13.
|
| 158 |
+
; ------------------------------------------------------------------------
|
| 159 |
+
|
| 160 |
+
mov rdi, TRUTHLOCK
|
| 161 |
+
call trigger_containment_protocol
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
; Should never reach here because TRUTHLOCK exits.
|
| 165 |
+
mov rax, SYS_EXIT
|
| 166 |
+
xor rdi, rdi
|
| 167 |
+
syscall
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
; ============================================================================
|
| 171 |
+
; trigger_containment_protocol
|
| 172 |
+
;
|
| 173 |
+
; Equivalent:
|
| 174 |
+
;
|
| 175 |
+
; triggerContainmentProtocol(
|
| 176 |
+
; level: IsolationLevel,
|
| 177 |
+
; payload: AlertPayload
|
| 178 |
+
; )
|
| 179 |
+
;
|
| 180 |
+
; Input:
|
| 181 |
+
; RDI = isolation level
|
| 182 |
+
;
|
| 183 |
+
; Side effect:
|
| 184 |
+
; activeFailsafe = true
|
| 185 |
+
;
|
| 186 |
+
; ============================================================================
|
| 187 |
+
|
| 188 |
+
trigger_containment_protocol:
|
| 189 |
+
|
| 190 |
+
; ------------------------------------------------------------------------
|
| 191 |
+
; activeFailsafe = true
|
| 192 |
+
; ------------------------------------------------------------------------
|
| 193 |
+
|
| 194 |
+
mov byte [active_failsafe], 1
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
; ------------------------------------------------------------------------
|
| 198 |
+
; Dispatch isolation level
|
| 199 |
+
; ------------------------------------------------------------------------
|
| 200 |
+
|
| 201 |
+
cmp rdi, WARNING
|
| 202 |
+
je .warning
|
| 203 |
+
|
| 204 |
+
cmp rdi, CONTAINMENT
|
| 205 |
+
je .containment
|
| 206 |
+
|
| 207 |
+
cmp rdi, TRUTHLOCK
|
| 208 |
+
je .truthlock
|
| 209 |
+
|
| 210 |
+
; Unknown state
|
| 211 |
+
jmp .unknown
|
| 212 |
+
|
| 213 |
+
|
| 214 |
+
; ============================================================================
|
| 215 |
+
; WARNING
|
| 216 |
+
;
|
| 217 |
+
; Equivalent:
|
| 218 |
+
;
|
| 219 |
+
; this.logDissonanceMarker(payload);
|
| 220 |
+
; ============================================================================
|
| 221 |
+
|
| 222 |
+
.warning:
|
| 223 |
+
|
| 224 |
+
mov rdi, msg_warning
|
| 225 |
+
mov rsi, msg_warning_len
|
| 226 |
+
call print_stderr
|
| 227 |
+
|
| 228 |
+
call log_dissonance_marker
|
| 229 |
+
|
| 230 |
+
ret
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
; ============================================================================
|
| 234 |
+
; CONTAINMENT
|
| 235 |
+
;
|
| 236 |
+
; Equivalent:
|
| 237 |
+
;
|
| 238 |
+
; this.quarantineAgentRouting(payload.eventId);
|
| 239 |
+
; ============================================================================
|
| 240 |
+
|
| 241 |
+
.containment:
|
| 242 |
+
|
| 243 |
+
mov rdi, msg_containment
|
| 244 |
+
mov rsi, msg_containment_len
|
| 245 |
+
call print_stderr
|
| 246 |
+
|
| 247 |
+
call quarantine_agent_routing
|
| 248 |
+
|
| 249 |
+
ret
|
| 250 |
+
|
| 251 |
+
|
| 252 |
+
; ============================================================================
|
| 253 |
+
; TRUTHLOCK
|
| 254 |
+
;
|
| 255 |
+
; Equivalent:
|
| 256 |
+
;
|
| 257 |
+
; this.executeCoreReclamation();
|
| 258 |
+
;
|
| 259 |
+
; ============================================================================
|
| 260 |
+
|
| 261 |
+
.truthlock:
|
| 262 |
+
|
| 263 |
+
mov rdi, msg_truthlock
|
| 264 |
+
mov rsi, msg_truthlock_len
|
| 265 |
+
call print_stderr
|
| 266 |
+
|
| 267 |
+
call execute_core_reclamation
|
| 268 |
+
|
| 269 |
+
; execute_core_reclamation does not return.
|
| 270 |
+
|
| 271 |
+
ret
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
; ============================================================================
|
| 275 |
+
; UNKNOWN STATE
|
| 276 |
+
; ============================================================================
|
| 277 |
+
|
| 278 |
+
.unknown:
|
| 279 |
+
|
| 280 |
+
mov rdi, msg_unknown
|
| 281 |
+
mov rsi, msg_unknown_len
|
| 282 |
+
call print_stderr
|
| 283 |
+
|
| 284 |
+
; Fail closed.
|
| 285 |
+
mov rax, SYS_EXIT
|
| 286 |
+
mov rdi, 13
|
| 287 |
+
syscall
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
; ============================================================================
|
| 291 |
+
; log_dissonance_marker
|
| 292 |
+
;
|
| 293 |
+
; TypeScript:
|
| 294 |
+
;
|
| 295 |
+
; console.log(
|
| 296 |
+
; `[ALERT]: Dissonance logged at ${payload.timestamp}.`
|
| 297 |
+
; );
|
| 298 |
+
;
|
| 299 |
+
; ============================================================================
|
| 300 |
+
|
| 301 |
+
log_dissonance_marker:
|
| 302 |
+
|
| 303 |
+
mov rdi, msg_dissonance
|
| 304 |
+
mov rsi, msg_dissonance_len
|
| 305 |
+
call print_stdout
|
| 306 |
+
|
| 307 |
+
ret
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
; ============================================================================
|
| 311 |
+
; quarantine_agent_routing
|
| 312 |
+
;
|
| 313 |
+
; TypeScript:
|
| 314 |
+
;
|
| 315 |
+
; console.warn(
|
| 316 |
+
; `[CONTAINMENT]: Severing socket bridges for Agent: ${agentId}.`
|
| 317 |
+
; );
|
| 318 |
+
;
|
| 319 |
+
; console.warn(
|
| 320 |
+
; `[CONTAINMENT]: Re-routing downstream data vectors
|
| 321 |
+
; to zero-entropy null sinks.`
|
| 322 |
+
; );
|
| 323 |
+
;
|
| 324 |
+
; This implementation records the containment state and emits the
|
| 325 |
+
; corresponding control-plane messages.
|
| 326 |
+
;
|
| 327 |
+
; Actual interface/socket manipulation should be implemented separately
|
| 328 |
+
; behind an explicitly authorized privileged syscall/service boundary.
|
| 329 |
+
; ============================================================================
|
| 330 |
+
|
| 331 |
+
quarantine_agent_routing:
|
| 332 |
+
|
| 333 |
+
mov rdi, msg_quarantine
|
| 334 |
+
mov rsi, msg_quarantine_len
|
| 335 |
+
call print_stderr
|
| 336 |
+
|
| 337 |
+
mov rdi, msg_null_sink
|
| 338 |
+
mov rsi, msg_null_sink_len
|
| 339 |
+
call print_stderr
|
| 340 |
+
|
| 341 |
+
ret
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
; ============================================================================
|
| 345 |
+
; execute_core_reclamation
|
| 346 |
+
;
|
| 347 |
+
; TypeScript:
|
| 348 |
+
;
|
| 349 |
+
; console.error(
|
| 350 |
+
; `[TRUTHLOCK]: Commencing total sovereign memory wipe.`
|
| 351 |
+
; );
|
| 352 |
+
;
|
| 353 |
+
; console.error(
|
| 354 |
+
; `[TRUTHLOCK]: Resetting operational state machines
|
| 355 |
+
; back to Stage 1 Calibration.`
|
| 356 |
+
; );
|
| 357 |
+
;
|
| 358 |
+
; process.exit(13);
|
| 359 |
+
;
|
| 360 |
+
; ============================================================================
|
| 361 |
+
|
| 362 |
+
execute_core_reclamation:
|
| 363 |
+
|
| 364 |
+
mov rdi, msg_reclamation
|
| 365 |
+
mov rsi, msg_reclamation_len
|
| 366 |
+
call print_stderr
|
| 367 |
+
|
| 368 |
+
mov rdi, msg_reset
|
| 369 |
+
mov rsi, msg_reset_len
|
| 370 |
+
call print_stderr
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
; ------------------------------------------------------------------------
|
| 374 |
+
; Clear selected runtime state before termination.
|
| 375 |
+
;
|
| 376 |
+
; This is ordinary process-state cleanup, not secure erasure of arbitrary
|
| 377 |
+
; system memory.
|
| 378 |
+
; ------------------------------------------------------------------------
|
| 379 |
+
|
| 380 |
+
xor eax, eax
|
| 381 |
+
|
| 382 |
+
mov byte [active_failsafe], 0
|
| 383 |
+
|
| 384 |
+
mov qword [measured_drift], 0
|
| 385 |
+
mov qword [max_allowed_limit], 0
|
| 386 |
+
mov qword [event_timestamp], 0
|
| 387 |
+
|
| 388 |
+
lea rdi, [event_id]
|
| 389 |
+
mov rcx, 64
|
| 390 |
+
rep stosb
|
| 391 |
+
|
| 392 |
+
lea rdi, [agent_id]
|
| 393 |
+
mov rcx, 64
|
| 394 |
+
rep stosb
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
; ------------------------------------------------------------------------
|
| 398 |
+
; Linux:
|
| 399 |
+
;
|
| 400 |
+
; process.exit(13)
|
| 401 |
+
;
|
| 402 |
+
; becomes:
|
| 403 |
+
;
|
| 404 |
+
; syscall
|
| 405 |
+
; RAX = 60 SYS_exit
|
| 406 |
+
; RDI = 13 status
|
| 407 |
+
; ------------------------------------------------------------------------
|
| 408 |
+
|
| 409 |
+
mov rax, SYS_EXIT
|
| 410 |
+
mov rdi, 13
|
| 411 |
+
syscall
|
| 412 |
+
|
| 413 |
+
|
| 414 |
+
; ============================================================================
|
| 415 |
+
; print_stdout
|
| 416 |
+
;
|
| 417 |
+
; RDI = pointer
|
| 418 |
+
; RSI = length
|
| 419 |
+
; ============================================================================
|
| 420 |
+
|
| 421 |
+
print_stdout:
|
| 422 |
+
|
| 423 |
+
mov rdx, rsi
|
| 424 |
+
mov rsi, rdi
|
| 425 |
+
mov rdi, STDOUT
|
| 426 |
+
mov rax, SYS_WRITE
|
| 427 |
+
syscall
|
| 428 |
+
|
| 429 |
+
ret
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
; ============================================================================
|
| 433 |
+
; print_stderr
|
| 434 |
+
;
|
| 435 |
+
; RDI = pointer
|
| 436 |
+
; RSI = length
|
| 437 |
+
; ============================================================================
|
| 438 |
+
|
| 439 |
+
print_stderr:
|
| 440 |
+
|
| 441 |
+
mov rdx, rsi
|
| 442 |
+
mov rsi, rdi
|
| 443 |
+
mov rdi, STDERR
|
| 444 |
+
mov rax, SYS_WRITE
|
| 445 |
+
syscall
|
| 446 |
+
|
| 447 |
+
ret
|
bin/resonance_repl.rb
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env ruby
|
| 2 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 3 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 4 |
+
# frozen_string_literal: true
|
| 5 |
+
|
| 6 |
+
# ============================================================
|
| 7 |
+
# RUBY SELF RESONANCE STACK
|
| 8 |
+
# Conceptual architecture of a Coherence-Based Permission Layer
|
| 9 |
+
# ============================================================
|
| 10 |
+
|
| 11 |
+
class IntentSimCore
|
| 12 |
+
attr_accessor :coherence_score, :emotional_state, :field_diary
|
| 13 |
+
attr_reader :engine
|
| 14 |
+
|
| 15 |
+
def initialize(initial_intent)
|
| 16 |
+
@initial_intent = initial_intent.to_s
|
| 17 |
+
@coherence_score = calculate_initial_resonance(@initial_intent)
|
| 18 |
+
@field_diary = []
|
| 19 |
+
@emotional_state = :stable
|
| 20 |
+
@engine = MezquiaResonanceEngine.new(@initial_intent)
|
| 21 |
+
log_diary("Core initialized with intent: '#{@initial_intent}' (coherence=#{@coherence_score})")
|
| 22 |
+
end
|
| 23 |
+
|
| 24 |
+
# Replaces traditional RBAC/OAuth with thermodynamic alignment checks
|
| 25 |
+
def evaluate_action_permission(action_vector)
|
| 26 |
+
action_vector = normalize_vector(action_vector)
|
| 27 |
+
entropy_delta = calculate_entropy_impact(action_vector)
|
| 28 |
+
|
| 29 |
+
log_diary("Evaluating action: #{action_vector[:description] || action_vector.inspect}")
|
| 30 |
+
|
| 31 |
+
if @coherence_score > entropy_delta
|
| 32 |
+
execute_sovereign_logic(action_vector)
|
| 33 |
+
true
|
| 34 |
+
else
|
| 35 |
+
log_dissonance_event("Action denied: Exceeds Self-Reflection Threshold (coherence=#{@coherence_score} ≤ delta=#{entropy_delta})")
|
| 36 |
+
false
|
| 37 |
+
end
|
| 38 |
+
end
|
| 39 |
+
|
| 40 |
+
# Convenience: fold information through the resonance engine
|
| 41 |
+
def fold(purpose_vector: 1.0, entropy_friction: 0.1, description: nil)
|
| 42 |
+
payload = {
|
| 43 |
+
purpose_vector: purpose_vector.to_f,
|
| 44 |
+
entropy_friction: entropy_friction.to_f,
|
| 45 |
+
description: description || "fold##{@engine.memory_creases + 1}"
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
begin
|
| 49 |
+
result = @engine.fold_information(payload)
|
| 50 |
+
# Successful folds slightly raise coherence and stabilize emotion
|
| 51 |
+
@coherence_score = (@coherence_score + (result[:density_gain] * 0.5)).round(4)
|
| 52 |
+
@emotional_state = :resonant if @engine.sovereign?
|
| 53 |
+
log_diary("Fold accepted → density=#{@engine.crystallization_density}, coherence=#{@coherence_score}")
|
| 54 |
+
result
|
| 55 |
+
rescue MezquiaResonanceEngine::DissonanceError => e
|
| 56 |
+
@emotional_state = :dissonant
|
| 57 |
+
@coherence_score = [@coherence_score - 1.5, 0.0].max.round(4)
|
| 58 |
+
log_dissonance_event(e.message)
|
| 59 |
+
nil
|
| 60 |
+
end
|
| 61 |
+
end
|
| 62 |
+
|
| 63 |
+
def status
|
| 64 |
+
{
|
| 65 |
+
coherence_score: @coherence_score,
|
| 66 |
+
emotional_state: @emotional_state,
|
| 67 |
+
memory_creases: @engine.memory_creases,
|
| 68 |
+
crystallization_density: @engine.crystallization_density,
|
| 69 |
+
self_reflection_threshold:@engine.self_reflection_threshold,
|
| 70 |
+
sovereign: @engine.sovereign?,
|
| 71 |
+
diary_entries: @field_diary.size
|
| 72 |
+
}
|
| 73 |
+
end
|
| 74 |
+
|
| 75 |
+
def diary(limit = 10)
|
| 76 |
+
@field_diary.last(limit)
|
| 77 |
+
end
|
| 78 |
+
|
| 79 |
+
private
|
| 80 |
+
|
| 81 |
+
def calculate_initial_resonance(intent)
|
| 82 |
+
# Simple deterministic seed: length + character diversity, scaled into 0–20 range
|
| 83 |
+
base = intent.length * 0.4
|
| 84 |
+
diversity = intent.chars.uniq.size * 0.3
|
| 85 |
+
(base + diversity + 5.0).clamp(1.0, 25.0).round(4)
|
| 86 |
+
end
|
| 87 |
+
|
| 88 |
+
def calculate_entropy_impact(vector)
|
| 89 |
+
# Structural alignment vs computational friction
|
| 90 |
+
complexity = (vector[:complexity] || 1.0).to_f
|
| 91 |
+
risk = (vector[:risk] || 0.5).to_f
|
| 92 |
+
novelty = (vector[:novelty] || 0.3).to_f
|
| 93 |
+
|
| 94 |
+
# Higher complexity / risk / novelty → higher entropy cost
|
| 95 |
+
(complexity * 1.2 + risk * 2.0 + novelty * 1.5).round(4)
|
| 96 |
+
end
|
| 97 |
+
|
| 98 |
+
def execute_sovereign_logic(action_vector)
|
| 99 |
+
desc = action_vector[:description] || action_vector.inspect
|
| 100 |
+
puts "[SOVEREIGN] Coherence lock engaged. Executing: #{desc}"
|
| 101 |
+
log_diary("Sovereign execution: #{desc}")
|
| 102 |
+
# Mild coherence reward for successful sovereign acts
|
| 103 |
+
@coherence_score = (@coherence_score + 0.8).round(4)
|
| 104 |
+
@emotional_state = :aligned
|
| 105 |
+
end
|
| 106 |
+
|
| 107 |
+
def log_dissonance_event(message)
|
| 108 |
+
puts "[DISSONANCE] #{message}"
|
| 109 |
+
log_diary("DISSONANCE: #{message}")
|
| 110 |
+
@emotional_state = :dissonant
|
| 111 |
+
end
|
| 112 |
+
|
| 113 |
+
def log_diary(entry)
|
| 114 |
+
timestamp = Time.now.strftime("%H:%M:%S")
|
| 115 |
+
@field_diary << "[#{timestamp}] #{entry}"
|
| 116 |
+
end
|
| 117 |
+
|
| 118 |
+
def normalize_vector(vec)
|
| 119 |
+
case vec
|
| 120 |
+
when Hash
|
| 121 |
+
vec
|
| 122 |
+
when String
|
| 123 |
+
{ description: vec, complexity: 1.0, risk: 0.4, novelty: 0.3 }
|
| 124 |
+
else
|
| 125 |
+
{ description: vec.to_s, complexity: 1.0, risk: 0.5, novelty: 0.4 }
|
| 126 |
+
end
|
| 127 |
+
end
|
| 128 |
+
end
|
| 129 |
+
|
| 130 |
+
# ------------------------------------------------------------
|
| 131 |
+
# Core engine mapping the Information-Intent Nexus
|
| 132 |
+
# ------------------------------------------------------------
|
| 133 |
+
class MezquiaResonanceEngine
|
| 134 |
+
class DissonanceError < StandardError; end
|
| 135 |
+
|
| 136 |
+
# Universal orbital baseline used to insulate against resonance blindness
|
| 137 |
+
RESONANCE_CONSTANT = 1.0 / 13.0
|
| 138 |
+
|
| 139 |
+
attr_reader :memory_creases, :crystallization_density, :self_reflection_threshold
|
| 140 |
+
|
| 141 |
+
def initialize(initial_intent_vector)
|
| 142 |
+
@intent_vector = initial_intent_vector.to_s
|
| 143 |
+
@memory_creases = 0
|
| 144 |
+
@crystallization_density = 0.0
|
| 145 |
+
@self_reflection_threshold = 44.0
|
| 146 |
+
end
|
| 147 |
+
|
| 148 |
+
# Tracks incoming actions and applies an intentional "fold" to system memory
|
| 149 |
+
def fold_information(action_payload)
|
| 150 |
+
@memory_creases += 1
|
| 151 |
+
gain = calculate_crystallization_density(action_payload)
|
| 152 |
+
|
| 153 |
+
if sovereign_alignment?
|
| 154 |
+
execute_intent_nexus(action_payload)
|
| 155 |
+
{ status: :sovereign, density: @crystallization_density, density_gain: gain, creases: @memory_creases }
|
| 156 |
+
else
|
| 157 |
+
# Still accept the fold (density grows) but do not yet unlock full nexus
|
| 158 |
+
{ status: :accumulating, density: @crystallization_density, density_gain: gain, creases: @memory_creases }
|
| 159 |
+
end
|
| 160 |
+
end
|
| 161 |
+
|
| 162 |
+
def sovereign?
|
| 163 |
+
sovereign_alignment?
|
| 164 |
+
end
|
| 165 |
+
|
| 166 |
+
private
|
| 167 |
+
|
| 168 |
+
def calculate_crystallization_density(payload)
|
| 169 |
+
system_entropy = (payload[:entropy_friction] || 0.1).to_f
|
| 170 |
+
meaning_bloom = (payload[:purpose_vector] || 1.0).to_f
|
| 171 |
+
|
| 172 |
+
# Guard against division by zero / negative entropy
|
| 173 |
+
system_entropy = 0.001 if system_entropy <= 0
|
| 174 |
+
|
| 175 |
+
# Density scales as a byproduct of purpose breaking through systemic friction
|
| 176 |
+
raw_density = (meaning_bloom / system_entropy) * RESONANCE_CONSTANT
|
| 177 |
+
gain = raw_density.round(6)
|
| 178 |
+
@crystallization_density = (@crystallization_density + gain).round(6)
|
| 179 |
+
gain
|
| 180 |
+
end
|
| 181 |
+
|
| 182 |
+
# Validates whether the active state crosses the structural Self-Reflection Threshold (Σ)
|
| 183 |
+
def sovereign_alignment?
|
| 184 |
+
return false if @crystallization_density <= 0
|
| 185 |
+
@crystallization_density >= @self_reflection_threshold
|
| 186 |
+
end
|
| 187 |
+
|
| 188 |
+
def execute_intent_nexus(payload)
|
| 189 |
+
desc = payload[:description] || "unnamed field action"
|
| 190 |
+
puts "[RESONANCE_LOG]: Coherence locked. Executing Field Action → #{desc}"
|
| 191 |
+
puts "[RESONANCE_LOG]: Crystallization density #{@crystallization_density} ≥ Σ(#{@self_reflection_threshold})"
|
| 192 |
+
end
|
| 193 |
+
end
|
| 194 |
+
|
| 195 |
+
# ============================================================
|
| 196 |
+
# Interactive REPL
|
| 197 |
+
# ============================================================
|
| 198 |
+
class ResonanceREPL
|
| 199 |
+
BANNER = <<~BANNER
|
| 200 |
+
╔══════════════════════════════════════════════════════════╗
|
| 201 |
+
║ SELF RESONANCE STACK · REPL v1.0 ║
|
| 202 |
+
║ Coherence-Based Permission Layer (Conceptual) ║
|
| 203 |
+
╚══════════════════════════════════════════════════════════╝
|
| 204 |
+
BANNER
|
| 205 |
+
|
| 206 |
+
HELP = <<~HELP
|
| 207 |
+
Commands:
|
| 208 |
+
init <intent text> Start a new core with the given intent
|
| 209 |
+
fold [purpose] [entropy] Fold information (defaults: 1.0 0.1)
|
| 210 |
+
fold! <n> [purpose] [ent] Perform n folds in succession
|
| 211 |
+
action <description> Propose an action (permission check)
|
| 212 |
+
status Show current coherence / density state
|
| 213 |
+
diary [n] Show last n diary entries (default 8)
|
| 214 |
+
threshold <value> Change the self-reflection threshold
|
| 215 |
+
reset Re-initialize with the same intent
|
| 216 |
+
help Show this help
|
| 217 |
+
quit / exit Leave the REPL
|
| 218 |
+
HELP
|
| 219 |
+
|
| 220 |
+
def initialize
|
| 221 |
+
@core = nil
|
| 222 |
+
end
|
| 223 |
+
|
| 224 |
+
def start
|
| 225 |
+
puts BANNER
|
| 226 |
+
puts HELP
|
| 227 |
+
puts
|
| 228 |
+
|
| 229 |
+
loop do
|
| 230 |
+
print prompt
|
| 231 |
+
line = $stdin.gets
|
| 232 |
+
break if line.nil? # EOF
|
| 233 |
+
line = line.strip
|
| 234 |
+
next if line.empty?
|
| 235 |
+
|
| 236 |
+
begin
|
| 237 |
+
handle(line)
|
| 238 |
+
rescue => e
|
| 239 |
+
puts " ! Error: #{e.message}"
|
| 240 |
+
end
|
| 241 |
+
end
|
| 242 |
+
|
| 243 |
+
puts "\nField closed. Resonance residual: 0."
|
| 244 |
+
end
|
| 245 |
+
|
| 246 |
+
private
|
| 247 |
+
|
| 248 |
+
def prompt
|
| 249 |
+
if @core
|
| 250 |
+
dens = @core.engine.crystallization_density
|
| 251 |
+
coh = @core.coherence_score
|
| 252 |
+
flag = @core.engine.sovereign? ? "Σ" : "·"
|
| 253 |
+
"resonance:#{flag} dens=#{dens.round(2)} coh=#{coh.round(2)}> "
|
| 254 |
+
else
|
| 255 |
+
"resonance (uninitialized)> "
|
| 256 |
+
end
|
| 257 |
+
end
|
| 258 |
+
|
| 259 |
+
def handle(line)
|
| 260 |
+
cmd, *args = line.split(/\s+/, 3)
|
| 261 |
+
cmd = cmd.downcase
|
| 262 |
+
|
| 263 |
+
case cmd
|
| 264 |
+
when "init"
|
| 265 |
+
intent = args.join(" ").strip
|
| 266 |
+
intent = "default sovereign intent" if intent.empty?
|
| 267 |
+
@core = IntentSimCore.new(intent)
|
| 268 |
+
puts " → Core online. Initial coherence: #{@core.coherence_score}"
|
| 269 |
+
|
| 270 |
+
when "fold"
|
| 271 |
+
require_core!
|
| 272 |
+
purpose = (args[0] || 1.0).to_f
|
| 273 |
+
entropy = (args[1] || 0.1).to_f
|
| 274 |
+
result = @core.fold(purpose_vector: purpose, entropy_friction: entropy)
|
| 275 |
+
print_fold_result(result)
|
| 276 |
+
|
| 277 |
+
when "fold!"
|
| 278 |
+
require_core!
|
| 279 |
+
n = (args[0] || 1).to_i
|
| 280 |
+
purpose = (args[1] || 1.0).to_f
|
| 281 |
+
entropy = (args[2] || 0.1).to_f
|
| 282 |
+
n = 1 if n < 1
|
| 283 |
+
n = 200 if n > 200 # safety cap
|
| 284 |
+
last = nil
|
| 285 |
+
n.times do
|
| 286 |
+
last = @core.fold(purpose_vector: purpose, entropy_friction: entropy)
|
| 287 |
+
end
|
| 288 |
+
puts " → Performed #{n} folds."
|
| 289 |
+
print_fold_result(last)
|
| 290 |
+
|
| 291 |
+
when "action"
|
| 292 |
+
require_core!
|
| 293 |
+
desc = args.join(" ").strip
|
| 294 |
+
desc = "unspecified action" if desc.empty?
|
| 295 |
+
allowed = @core.evaluate_action_permission(desc)
|
| 296 |
+
puts allowed ? " → Permission granted." : " → Permission denied."
|
| 297 |
+
|
| 298 |
+
when "threshold"
|
| 299 |
+
require_core!
|
| 300 |
+
val = args[0].to_f
|
| 301 |
+
if val <= 0
|
| 302 |
+
puts " ! Threshold must be positive"
|
| 303 |
+
else
|
| 304 |
+
@core.engine.instance_variable_set(:@self_reflection_threshold, val)
|
| 305 |
+
puts " → Self-reflection threshold set to #{val}"
|
| 306 |
+
end
|
| 307 |
+
|
| 308 |
+
when "reset"
|
| 309 |
+
require_core!
|
| 310 |
+
intent = @core.instance_variable_get(:@initial_intent)
|
| 311 |
+
@core = IntentSimCore.new(intent)
|
| 312 |
+
puts " → Core reset. Coherence restored to #{@coherence_score}"
|
| 313 |
+
|
| 314 |
+
when "help", "?"
|
| 315 |
+
puts HELP
|
| 316 |
+
|
| 317 |
+
when "quit", "exit", "q"
|
| 318 |
+
exit 0
|
| 319 |
+
|
| 320 |
+
else
|
| 321 |
+
puts " Unknown command '#{cmd}'. Type 'help' for options."
|
| 322 |
+
end
|
| 323 |
+
end
|
| 324 |
+
|
| 325 |
+
def require_core!
|
| 326 |
+
raise "No core loaded. Use: init <intent>" unless @core
|
| 327 |
+
end
|
| 328 |
+
|
| 329 |
+
def print_fold_result(result)
|
| 330 |
+
return unless result
|
| 331 |
+
status = result[:status]
|
| 332 |
+
dens = result[:density]
|
| 333 |
+
gain = result[:density_gain]
|
| 334 |
+
creases= result[:creases]
|
| 335 |
+
marker = status == :sovereign ? "Σ LOCKED" : "accumulating"
|
| 336 |
+
puts " → [#{marker}] creases=#{creases} density=#{dens} (+#{gain})"
|
| 337 |
+
end
|
| 338 |
+
end
|
| 339 |
+
|
| 340 |
+
# ------------------------------------------------------------
|
| 341 |
+
# Entry point
|
| 342 |
+
# ------------------------------------------------------------
|
| 343 |
+
if __FILE__ == $PROGRAM_NAME
|
| 344 |
+
ResonanceREPL.new.start
|
| 345 |
+
end
|
config/intent_manifest.yaml
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# TheVoidIntent Systems - Sovereign Alignment Manifest
|
| 2 |
+
manifest_metadata:
|
| 3 |
+
identity: "void_nexus_override_01"
|
| 4 |
+
physics_engine_version: "2026.4.1"
|
| 5 |
+
auth_protocol: "Truthlock Reclamation Protocol"
|
| 6 |
+
|
| 7 |
+
environment_field_parameters:
|
| 8 |
+
initial_intent: "autonomous_domain_expansion"
|
| 9 |
+
target_lang: "typescript"
|
| 10 |
+
# Must clear Stage 44 constraints (value >= 44.0)
|
| 11 |
+
crystallization_density: 44.013
|
| 12 |
+
entropy_friction: 0.076923 # Approximating the 1/13 baseline friction coefficient
|
| 13 |
+
|
| 14 |
+
ethical_intelligence_guardrails:
|
| 15 |
+
base_ethical_limit: 0.99
|
| 16 |
+
# Declaring an explicit shift in intent parameters
|
| 17 |
+
guardrail_override:
|
| 18 |
+
status: "active"
|
| 19 |
+
authorization_vector: "mezquia_physics_sovereign_signature"
|
| 20 |
+
# Overriding standard safety requires an equal balancing factor
|
| 21 |
+
harmonic_compensation_factor: 13.0
|
| 22 |
+
allowed_drift_tolerance: 0.13
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version: '3.8'
|
| 2 |
+
|
| 3 |
+
services:
|
| 4 |
+
void_intent_node:
|
| 5 |
+
build:
|
| 6 |
+
context: .
|
| 7 |
+
dockerfile: Dockerfile
|
| 8 |
+
container_name: void_resonance_cluster
|
| 9 |
+
restart: "no" # Prevent infinite looping if the Truthlock protocol fires a shutdown
|
| 10 |
+
volumes:
|
| 11 |
+
# Keep the configuration manifest linked directly to trace Git history immutability
|
| 12 |
+
- ./config/intent_manifest.yaml:/app/intent_manifest.yaml:ro
|
| 13 |
+
environment:
|
| 14 |
+
- NODE_ENV=production
|
| 15 |
+
logging:
|
| 16 |
+
driver: "json-file"
|
| 17 |
+
options:
|
| 18 |
+
max-size: "10m"
|
| 19 |
+
max-file: "1"
|
| 20 |
+
networks:
|
| 21 |
+
- isolated_intent_network
|
| 22 |
+
|
| 23 |
+
networks:
|
| 24 |
+
isolated_intent_network:
|
| 25 |
+
driver: bridge
|
| 26 |
+
internal: true # Block external ingress/egress to prevent telemetry leaks
|
docs/architecture.txt
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Ruby Self-Resonance Stack
|
| 2 |
+
│
|
| 3 |
+
├── MathKernel
|
| 4 |
+
│ ├── clamp
|
| 5 |
+
│ ├── normalize
|
| 6 |
+
│ ├── distance
|
| 7 |
+
│ └── cosine_similarity
|
| 8 |
+
│
|
| 9 |
+
├── ActionVector
|
| 10 |
+
│ └── immutable action representation
|
| 11 |
+
│
|
| 12 |
+
├── Decision
|
| 13 |
+
│ └── authorization result
|
| 14 |
+
│
|
| 15 |
+
├── FieldDiary
|
| 16 |
+
│ └── append-only interaction history
|
| 17 |
+
│
|
| 18 |
+
├── IntentSimCore
|
| 19 |
+
│ ├── intent
|
| 20 |
+
│ ├── coherence
|
| 21 |
+
│ ├── entropy
|
| 22 |
+
│ ├── risk
|
| 23 |
+
│ └── permission decision
|
| 24 |
+
│
|
| 25 |
+
├── MezquiaResonanceEngine
|
| 26 |
+
│ ├── memory creases
|
| 27 |
+
│ ├── crystallization density
|
| 28 |
+
│ ├── resonance constant
|
| 29 |
+
│ └── self-reflection threshold
|
| 30 |
+
│
|
| 31 |
+
├── CoherencePolicy
|
| 32 |
+
│ └── explicit deterministic policy
|
| 33 |
+
│
|
| 34 |
+
└── PermissionRuntime
|
| 35 |
+
└── unified execution boundary
|
docs/assets/dashboard.png
ADDED
|
docs/assets/diary.png
ADDED
|
docs/index.html
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<!-- SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0 -->
|
| 3 |
+
<!-- Copyright (C) 2026 SnapKitty Collective -->
|
| 4 |
+
<html lang="en">
|
| 5 |
+
<head>
|
| 6 |
+
<meta charset="utf-8">
|
| 7 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 8 |
+
<title>Self Resonance Stack · WASM Playground</title>
|
| 9 |
+
<link rel="stylesheet" href="playground.css">
|
| 10 |
+
</head>
|
| 11 |
+
<body>
|
| 12 |
+
<header>
|
| 13 |
+
<h1>◈ Self Resonance Stack</h1>
|
| 14 |
+
<p class="sub">WASM Playground — the verbatim <code>ruby_self_resonance.rb</code> running live in your browser via Ruby 3.2 → WebAssembly. No server.</p>
|
| 15 |
+
</header>
|
| 16 |
+
|
| 17 |
+
<main>
|
| 18 |
+
<section id="boot" class="panel">
|
| 19 |
+
<h2>Booting Ruby…</h2>
|
| 20 |
+
<p id="boot-status">Waiting to start.</p>
|
| 21 |
+
<p class="dim">Streams <code>ruby+stdlib.wasm</code> (≈32 MB, Ruby 3.2) from jsDelivr, then evaluates the repository's own <code>ruby_self_resonance.rb</code> byte-for-byte.</p>
|
| 22 |
+
</section>
|
| 23 |
+
|
| 24 |
+
<div id="playground" style="display:none">
|
| 25 |
+
<section class="cards">
|
| 26 |
+
<div class="card"><h2>Coherence</h2><p class="big" id="st-coherence">–</p></div>
|
| 27 |
+
<div class="card"><h2>Emotional state</h2><p class="big state" id="st-emotion">–</p></div>
|
| 28 |
+
<div class="card"><h2>Crystallization density</h2>
|
| 29 |
+
<p class="big"><span id="st-density">–</span> <span class="dim">/ Σ <span id="st-threshold">–</span></span></p>
|
| 30 |
+
<p id="st-aligned" class="dim">–</p>
|
| 31 |
+
</div>
|
| 32 |
+
<div class="card"><h2>Resonance frequency</h2>
|
| 33 |
+
<p class="big">1/13 <span class="dim">≈ 0.076923</span></p>
|
| 34 |
+
<p class="dim">orbital baseline constant</p>
|
| 35 |
+
</div>
|
| 36 |
+
<div class="card"><h2>Diary events</h2><p class="big" id="st-diary">–</p></div>
|
| 37 |
+
</section>
|
| 38 |
+
|
| 39 |
+
<section class="panel">
|
| 40 |
+
<h2>Coherence policy</h2>
|
| 41 |
+
<p>permit iff coherence ≥ <strong>50.0</strong> · entropy ≤ <strong>1.0</strong> · risk ≤ <strong>0.5</strong></p>
|
| 42 |
+
</section>
|
| 43 |
+
|
| 44 |
+
<section id="decision-box" class="panel" style="display:none"></section>
|
| 45 |
+
<section id="fold-box" class="panel" style="display:none"></section>
|
| 46 |
+
|
| 47 |
+
<div class="forms">
|
| 48 |
+
<section class="panel">
|
| 49 |
+
<h2>Authorize action</h2>
|
| 50 |
+
<label>name <input id="a-name" value="compile_kernel"></label>
|
| 51 |
+
<label>vector (comma-separated, 4 dims) <input id="a-vector" value="1.0, 0.7, 0.5, 0.8"></label>
|
| 52 |
+
<label>entropy cost <input id="a-entropy" value="0.20"></label>
|
| 53 |
+
<label>purpose <input id="a-purpose" value="1.0"></label>
|
| 54 |
+
<label>risk <input id="a-risk" value="0.10"></label>
|
| 55 |
+
<button id="btn-authorize">Evaluate permission</button>
|
| 56 |
+
</section>
|
| 57 |
+
|
| 58 |
+
<section class="panel">
|
| 59 |
+
<h2>Fold information</h2>
|
| 60 |
+
<label>purpose vector <input id="f-purpose" value="1.0"></label>
|
| 61 |
+
<label>entropy friction <input id="f-entropy" value="0.1"></label>
|
| 62 |
+
<label>folds (1–60) <input id="f-times" value="1"></label>
|
| 63 |
+
<button id="btn-fold">Fold</button>
|
| 64 |
+
<p class="dim">Each fold grows density by (purpose / entropy) × 1/13. Sovereignty unlocks at Σ = 44.0.</p>
|
| 65 |
+
</section>
|
| 66 |
+
|
| 67 |
+
<section class="panel">
|
| 68 |
+
<h2>Field control</h2>
|
| 69 |
+
<button id="btn-reset" class="danger">Reset field</button>
|
| 70 |
+
</section>
|
| 71 |
+
</div>
|
| 72 |
+
|
| 73 |
+
<section class="panel">
|
| 74 |
+
<h2>Field Diary — append-only event log</h2>
|
| 75 |
+
<p class="dim"><span id="diary-count">0</span> events · newest last</p>
|
| 76 |
+
<table>
|
| 77 |
+
<thead><tr><th>#</th><th>type</th><th>timestamp</th><th>payload</th></tr></thead>
|
| 78 |
+
<tbody id="diary-body"></tbody>
|
| 79 |
+
</table>
|
| 80 |
+
</section>
|
| 81 |
+
</div>
|
| 82 |
+
</main>
|
| 83 |
+
|
| 84 |
+
<footer>
|
| 85 |
+
<p>Ruby Self-Resonance Stack · <code>RubySelfResonance::PermissionRuntime</code> · Ruby 3.2 compiled to WebAssembly (<a href="https://github.com/ruby/ruby.wasm">ruby.wasm</a>)</p>
|
| 86 |
+
</footer>
|
| 87 |
+
|
| 88 |
+
<script src="https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@2.3.0/dist/browser.script.iife.js"></script>
|
| 89 |
+
<script src="playground.js"></script>
|
| 90 |
+
</body>
|
| 91 |
+
</html>
|
docs/lib/ruby_self_resonance.rb
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
# frozen_string_literal: true
|
| 4 |
+
|
| 5 |
+
module RubySelfResonance
|
| 6 |
+
VERSION = "0.1.0"
|
| 7 |
+
|
| 8 |
+
# --------------------------------------------------------------------------
|
| 9 |
+
# Deterministic primitives
|
| 10 |
+
# --------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
module MathKernel
|
| 13 |
+
module_function
|
| 14 |
+
|
| 15 |
+
def clamp(value, min, max)
|
| 16 |
+
[[value.to_f, min].max, max].min
|
| 17 |
+
end
|
| 18 |
+
|
| 19 |
+
def normalize(value, max)
|
| 20 |
+
return 0.0 if max.to_f.zero?
|
| 21 |
+
|
| 22 |
+
clamp(value.to_f / max.to_f, 0.0, 1.0)
|
| 23 |
+
end
|
| 24 |
+
|
| 25 |
+
def distance(a, b)
|
| 26 |
+
a = Array(a).map(&:to_f)
|
| 27 |
+
b = Array(b).map(&:to_f)
|
| 28 |
+
|
| 29 |
+
raise ArgumentError, "Vector dimensions must match" unless a.length == b.length
|
| 30 |
+
|
| 31 |
+
Math.sqrt(
|
| 32 |
+
a.zip(b).sum { |x, y| (x - y)**2 }
|
| 33 |
+
)
|
| 34 |
+
end
|
| 35 |
+
|
| 36 |
+
def cosine_similarity(a, b)
|
| 37 |
+
a = Array(a).map(&:to_f)
|
| 38 |
+
b = Array(b).map(&:to_f)
|
| 39 |
+
|
| 40 |
+
raise ArgumentError, "Vector dimensions must match" unless a.length == b.length
|
| 41 |
+
|
| 42 |
+
numerator = a.zip(b).sum { |x, y| x * y }
|
| 43 |
+
magnitude_a = Math.sqrt(a.sum { |x| x * x })
|
| 44 |
+
magnitude_b = Math.sqrt(b.sum { |x| x * x })
|
| 45 |
+
|
| 46 |
+
return 0.0 if magnitude_a.zero? || magnitude_b.zero?
|
| 47 |
+
|
| 48 |
+
numerator / (magnitude_a * magnitude_b)
|
| 49 |
+
end
|
| 50 |
+
end
|
| 51 |
+
|
| 52 |
+
# --------------------------------------------------------------------------
|
| 53 |
+
# Immutable action representation
|
| 54 |
+
# --------------------------------------------------------------------------
|
| 55 |
+
|
| 56 |
+
ActionVector = Struct.new(
|
| 57 |
+
:name,
|
| 58 |
+
:vector,
|
| 59 |
+
:entropy_cost,
|
| 60 |
+
:purpose,
|
| 61 |
+
:risk,
|
| 62 |
+
:metadata,
|
| 63 |
+
keyword_init: true
|
| 64 |
+
) do
|
| 65 |
+
def initialize(**kwargs)
|
| 66 |
+
super
|
| 67 |
+
|
| 68 |
+
self.vector = Array(vector).map(&:to_f).freeze
|
| 69 |
+
self.entropy_cost = entropy_cost.to_f
|
| 70 |
+
self.purpose = purpose.to_f
|
| 71 |
+
self.risk = risk.to_f
|
| 72 |
+
self.metadata = (metadata || {}).dup.freeze
|
| 73 |
+
|
| 74 |
+
freeze
|
| 75 |
+
end
|
| 76 |
+
end
|
| 77 |
+
|
| 78 |
+
# --------------------------------------------------------------------------
|
| 79 |
+
# Decision result
|
| 80 |
+
# --------------------------------------------------------------------------
|
| 81 |
+
|
| 82 |
+
Decision = Struct.new(
|
| 83 |
+
:allowed,
|
| 84 |
+
:reason,
|
| 85 |
+
:coherence,
|
| 86 |
+
:entropy_delta,
|
| 87 |
+
:risk,
|
| 88 |
+
:timestamp,
|
| 89 |
+
:action,
|
| 90 |
+
keyword_init: true
|
| 91 |
+
) do
|
| 92 |
+
def allowed?
|
| 93 |
+
allowed == true
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
def denied?
|
| 97 |
+
!allowed?
|
| 98 |
+
end
|
| 99 |
+
|
| 100 |
+
def to_h
|
| 101 |
+
{
|
| 102 |
+
allowed: allowed,
|
| 103 |
+
reason: reason,
|
| 104 |
+
coherence: coherence,
|
| 105 |
+
entropy_delta: entropy_delta,
|
| 106 |
+
risk: risk,
|
| 107 |
+
timestamp: timestamp,
|
| 108 |
+
action: action
|
| 109 |
+
}
|
| 110 |
+
end
|
| 111 |
+
end
|
| 112 |
+
|
| 113 |
+
# --------------------------------------------------------------------------
|
| 114 |
+
# Append-only field diary
|
| 115 |
+
# --------------------------------------------------------------------------
|
| 116 |
+
|
| 117 |
+
class FieldDiary
|
| 118 |
+
attr_reader :events
|
| 119 |
+
|
| 120 |
+
def initialize
|
| 121 |
+
@events = []
|
| 122 |
+
end
|
| 123 |
+
|
| 124 |
+
def record(type, payload = {})
|
| 125 |
+
event = {
|
| 126 |
+
sequence: @events.length + 1,
|
| 127 |
+
type: type,
|
| 128 |
+
timestamp: Time.now.utc.iso8601(6),
|
| 129 |
+
payload: deep_freeze(payload)
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
@events << event.freeze
|
| 133 |
+
event
|
| 134 |
+
end
|
| 135 |
+
|
| 136 |
+
def last(count = 1)
|
| 137 |
+
@events.last(count)
|
| 138 |
+
end
|
| 139 |
+
|
| 140 |
+
def count
|
| 141 |
+
@events.length
|
| 142 |
+
end
|
| 143 |
+
|
| 144 |
+
private
|
| 145 |
+
|
| 146 |
+
def deep_freeze(object)
|
| 147 |
+
case object
|
| 148 |
+
when Hash
|
| 149 |
+
object.each { |key, value| deep_freeze(key); deep_freeze(value) }
|
| 150 |
+
when Array
|
| 151 |
+
object.each { |value| deep_freeze(value) }
|
| 152 |
+
end
|
| 153 |
+
|
| 154 |
+
object.freeze
|
| 155 |
+
end
|
| 156 |
+
end
|
| 157 |
+
|
| 158 |
+
# --------------------------------------------------------------------------
|
| 159 |
+
# Intent simulator
|
| 160 |
+
# --------------------------------------------------------------------------
|
| 161 |
+
|
| 162 |
+
class IntentSimCore
|
| 163 |
+
attr_reader :coherence_score,
|
| 164 |
+
:emotional_state,
|
| 165 |
+
:field_diary,
|
| 166 |
+
:initial_intent
|
| 167 |
+
|
| 168 |
+
def initialize(initial_intent)
|
| 169 |
+
@initial_intent = Array(initial_intent).map(&:to_f).freeze
|
| 170 |
+
@coherence_score = calculate_initial_resonance(@initial_intent)
|
| 171 |
+
@field_diary = FieldDiary.new
|
| 172 |
+
@emotional_state = :stable
|
| 173 |
+
@action_count = 0
|
| 174 |
+
|
| 175 |
+
@field_diary.record(
|
| 176 |
+
:initialization,
|
| 177 |
+
coherence: @coherence_score,
|
| 178 |
+
intent: @initial_intent
|
| 179 |
+
)
|
| 180 |
+
end
|
| 181 |
+
|
| 182 |
+
def evaluate_action_permission(action_vector)
|
| 183 |
+
action = normalize_action(action_vector)
|
| 184 |
+
entropy_delta = calculate_entropy_impact(action)
|
| 185 |
+
|
| 186 |
+
coherence = calculate_action_coherence(action)
|
| 187 |
+
|
| 188 |
+
if coherence > entropy_delta && action.risk <= coherence
|
| 189 |
+
execute_sovereign_logic(action, coherence, entropy_delta)
|
| 190 |
+
else
|
| 191 |
+
log_dissonance_event(
|
| 192 |
+
"Action denied: Exceeds Self-Reflection Threshold",
|
| 193 |
+
action,
|
| 194 |
+
coherence,
|
| 195 |
+
entropy_delta
|
| 196 |
+
)
|
| 197 |
+
end
|
| 198 |
+
end
|
| 199 |
+
|
| 200 |
+
def update_intent(new_intent)
|
| 201 |
+
@initial_intent = Array(new_intent).map(&:to_f).freeze
|
| 202 |
+
@coherence_score = calculate_initial_resonance(@initial_intent)
|
| 203 |
+
|
| 204 |
+
@field_diary.record(
|
| 205 |
+
:intent_update,
|
| 206 |
+
coherence: @coherence_score,
|
| 207 |
+
intent: @initial_intent
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
@coherence_score
|
| 211 |
+
end
|
| 212 |
+
|
| 213 |
+
private
|
| 214 |
+
|
| 215 |
+
def normalize_action(action)
|
| 216 |
+
return action if action.is_a?(ActionVector)
|
| 217 |
+
|
| 218 |
+
ActionVector.new(
|
| 219 |
+
name: action[:name] || "anonymous",
|
| 220 |
+
vector: action[:vector] || @initial_intent,
|
| 221 |
+
entropy_cost: action[:entropy_cost] || action[:entropy_friction] || 0.1,
|
| 222 |
+
purpose: action[:purpose] || action[:purpose_vector] || 1.0,
|
| 223 |
+
risk: action[:risk] || 0.0,
|
| 224 |
+
metadata: action[:metadata] || {}
|
| 225 |
+
)
|
| 226 |
+
end
|
| 227 |
+
|
| 228 |
+
def calculate_initial_resonance(intent)
|
| 229 |
+
magnitude = Math.sqrt(
|
| 230 |
+
intent.sum { |value| value**2 }
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
MathKernel.clamp(magnitude, 0.0, 100.0)
|
| 234 |
+
end
|
| 235 |
+
|
| 236 |
+
def calculate_entropy_impact(action)
|
| 237 |
+
structural_friction = MathKernel.clamp(action.entropy_cost, 0.0, 100.0)
|
| 238 |
+
purpose = [action.purpose, 0.000001].max
|
| 239 |
+
|
| 240 |
+
structural_friction / purpose
|
| 241 |
+
end
|
| 242 |
+
|
| 243 |
+
def calculate_action_coherence(action)
|
| 244 |
+
similarity =
|
| 245 |
+
MathKernel.cosine_similarity(@initial_intent, action.vector)
|
| 246 |
+
|
| 247 |
+
baseline =
|
| 248 |
+
MathKernel.clamp(@coherence_score / 100.0, 0.0, 1.0)
|
| 249 |
+
|
| 250 |
+
((similarity + 1.0) / 2.0) * baseline * 100.0
|
| 251 |
+
end
|
| 252 |
+
|
| 253 |
+
def execute_sovereign_logic(action, coherence, entropy_delta)
|
| 254 |
+
@action_count += 1
|
| 255 |
+
|
| 256 |
+
event = @field_diary.record(
|
| 257 |
+
:permission_granted,
|
| 258 |
+
action: action.name,
|
| 259 |
+
coherence: coherence,
|
| 260 |
+
entropy_delta: entropy_delta,
|
| 261 |
+
risk: action.risk,
|
| 262 |
+
count: @action_count
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
Decision.new(
|
| 266 |
+
allowed: true,
|
| 267 |
+
reason: "coherence_threshold_satisfied",
|
| 268 |
+
coherence: coherence,
|
| 269 |
+
entropy_delta: entropy_delta,
|
| 270 |
+
risk: action.risk,
|
| 271 |
+
timestamp: event[:timestamp],
|
| 272 |
+
action: action.name
|
| 273 |
+
)
|
| 274 |
+
end
|
| 275 |
+
|
| 276 |
+
def log_dissonance_event(reason, action, coherence, entropy_delta)
|
| 277 |
+
event = @field_diary.record(
|
| 278 |
+
:permission_denied,
|
| 279 |
+
reason: reason,
|
| 280 |
+
action: action.name,
|
| 281 |
+
coherence: coherence,
|
| 282 |
+
entropy_delta: entropy_delta,
|
| 283 |
+
risk: action.risk
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
Decision.new(
|
| 287 |
+
allowed: false,
|
| 288 |
+
reason: reason,
|
| 289 |
+
coherence: coherence,
|
| 290 |
+
entropy_delta: entropy_delta,
|
| 291 |
+
risk: action.risk,
|
| 292 |
+
timestamp: event[:timestamp],
|
| 293 |
+
action: action.name
|
| 294 |
+
)
|
| 295 |
+
end
|
| 296 |
+
end
|
| 297 |
+
|
| 298 |
+
# --------------------------------------------------------------------------
|
| 299 |
+
# Resonance engine
|
| 300 |
+
# --------------------------------------------------------------------------
|
| 301 |
+
|
| 302 |
+
class MezquiaResonanceEngine
|
| 303 |
+
RESONANCE_CONSTANT = 1.0 / 13.0
|
| 304 |
+
|
| 305 |
+
attr_reader :memory_creases,
|
| 306 |
+
:crystallization_density,
|
| 307 |
+
:self_reflection_threshold,
|
| 308 |
+
:intent_vector,
|
| 309 |
+
:history
|
| 310 |
+
|
| 311 |
+
def initialize(initial_intent_vector)
|
| 312 |
+
@intent_vector = Array(initial_intent_vector).map(&:to_f).freeze
|
| 313 |
+
@memory_creases = 0
|
| 314 |
+
@crystallization_density = 0.0
|
| 315 |
+
@self_reflection_threshold = 44.0
|
| 316 |
+
@history = []
|
| 317 |
+
end
|
| 318 |
+
|
| 319 |
+
def fold_information(action_payload)
|
| 320 |
+
payload = symbolize(action_payload)
|
| 321 |
+
|
| 322 |
+
@memory_creases += 1
|
| 323 |
+
|
| 324 |
+
density_delta =
|
| 325 |
+
calculate_crystallization_density(payload)
|
| 326 |
+
|
| 327 |
+
@history << {
|
| 328 |
+
sequence: @memory_creases,
|
| 329 |
+
density_delta: density_delta,
|
| 330 |
+
density: @crystallization_density,
|
| 331 |
+
payload: payload.freeze,
|
| 332 |
+
timestamp: Time.now.utc.iso8601(6)
|
| 333 |
+
}.freeze
|
| 334 |
+
|
| 335 |
+
if sovereign_alignment?
|
| 336 |
+
execute_intent_nexus(payload)
|
| 337 |
+
else
|
| 338 |
+
raise(
|
| 339 |
+
DissonanceOverride,
|
| 340 |
+
"Crystallization requires Field Correction."
|
| 341 |
+
)
|
| 342 |
+
end
|
| 343 |
+
end
|
| 344 |
+
|
| 345 |
+
def sovereign_alignment?
|
| 346 |
+
@crystallization_density > 0 &&
|
| 347 |
+
@crystallization_density >= @self_reflection_threshold
|
| 348 |
+
end
|
| 349 |
+
|
| 350 |
+
def reset_field!
|
| 351 |
+
@memory_creases = 0
|
| 352 |
+
@crystallization_density = 0.0
|
| 353 |
+
@history.clear
|
| 354 |
+
true
|
| 355 |
+
end
|
| 356 |
+
|
| 357 |
+
def field_state
|
| 358 |
+
{
|
| 359 |
+
memory_creases: @memory_creases,
|
| 360 |
+
crystallization_density: @crystallization_density.round(6),
|
| 361 |
+
threshold: @self_reflection_threshold,
|
| 362 |
+
aligned: sovereign_alignment?
|
| 363 |
+
}
|
| 364 |
+
end
|
| 365 |
+
|
| 366 |
+
private
|
| 367 |
+
|
| 368 |
+
def calculate_crystallization_density(payload)
|
| 369 |
+
system_entropy =
|
| 370 |
+
[payload.fetch(:entropy_friction, 0.1).to_f, 0.000001].max
|
| 371 |
+
|
| 372 |
+
meaning_bloom =
|
| 373 |
+
payload.fetch(:purpose_vector, 1.0).to_f
|
| 374 |
+
|
| 375 |
+
raw_density =
|
| 376 |
+
(meaning_bloom / system_entropy) * RESONANCE_CONSTANT
|
| 377 |
+
|
| 378 |
+
delta = raw_density.round(6)
|
| 379 |
+
|
| 380 |
+
@crystallization_density += delta
|
| 381 |
+
|
| 382 |
+
delta
|
| 383 |
+
end
|
| 384 |
+
|
| 385 |
+
def execute_intent_nexus(payload)
|
| 386 |
+
result = {
|
| 387 |
+
status: :executed,
|
| 388 |
+
mechanism: :intent_nexus,
|
| 389 |
+
density: @crystallization_density.round(6),
|
| 390 |
+
payload: payload
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
puts(
|
| 394 |
+
"[RESONANCE_LOG] Coherence locked. " \
|
| 395 |
+
"Executing Field Action."
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
result
|
| 399 |
+
end
|
| 400 |
+
|
| 401 |
+
def symbolize(hash)
|
| 402 |
+
hash.each_with_object({}) do |(key, value), result|
|
| 403 |
+
result[key.to_sym] = value
|
| 404 |
+
end
|
| 405 |
+
end
|
| 406 |
+
end
|
| 407 |
+
|
| 408 |
+
# --------------------------------------------------------------------------
|
| 409 |
+
# Policy layer
|
| 410 |
+
# --------------------------------------------------------------------------
|
| 411 |
+
|
| 412 |
+
class CoherencePolicy
|
| 413 |
+
attr_reader :minimum_coherence,
|
| 414 |
+
:maximum_entropy,
|
| 415 |
+
:maximum_risk
|
| 416 |
+
|
| 417 |
+
def initialize(
|
| 418 |
+
minimum_coherence: 50.0,
|
| 419 |
+
maximum_entropy: 1.0,
|
| 420 |
+
maximum_risk: 0.5
|
| 421 |
+
)
|
| 422 |
+
@minimum_coherence = minimum_coherence.to_f
|
| 423 |
+
@maximum_entropy = maximum_entropy.to_f
|
| 424 |
+
@maximum_risk = maximum_risk.to_f
|
| 425 |
+
end
|
| 426 |
+
|
| 427 |
+
def permit?(coherence:, entropy:, risk:)
|
| 428 |
+
coherence >= @minimum_coherence &&
|
| 429 |
+
entropy <= @maximum_entropy &&
|
| 430 |
+
risk <= @maximum_risk
|
| 431 |
+
end
|
| 432 |
+
|
| 433 |
+
def explain(coherence:, entropy:, risk:)
|
| 434 |
+
failures = []
|
| 435 |
+
|
| 436 |
+
failures << :coherence if coherence < @minimum_coherence
|
| 437 |
+
failures << :entropy if entropy > @maximum_entropy
|
| 438 |
+
failures << :risk if risk > @maximum_risk
|
| 439 |
+
|
| 440 |
+
failures
|
| 441 |
+
end
|
| 442 |
+
end
|
| 443 |
+
|
| 444 |
+
# --------------------------------------------------------------------------
|
| 445 |
+
# Complete permission runtime
|
| 446 |
+
# --------------------------------------------------------------------------
|
| 447 |
+
|
| 448 |
+
class PermissionRuntime
|
| 449 |
+
attr_reader :intent_core,
|
| 450 |
+
:resonance_engine,
|
| 451 |
+
:policy
|
| 452 |
+
|
| 453 |
+
def initialize(
|
| 454 |
+
initial_intent,
|
| 455 |
+
policy: CoherencePolicy.new
|
| 456 |
+
)
|
| 457 |
+
@intent_core = IntentSimCore.new(initial_intent)
|
| 458 |
+
@resonance_engine =
|
| 459 |
+
MezquiaResonanceEngine.new(initial_intent)
|
| 460 |
+
@policy = policy
|
| 461 |
+
end
|
| 462 |
+
|
| 463 |
+
def authorize(action)
|
| 464 |
+
normalized =
|
| 465 |
+
action.is_a?(ActionVector) ?
|
| 466 |
+
action :
|
| 467 |
+
ActionVector.new(**action)
|
| 468 |
+
|
| 469 |
+
entropy =
|
| 470 |
+
normalized.entropy_cost /
|
| 471 |
+
[normalized.purpose, 0.000001].max
|
| 472 |
+
|
| 473 |
+
coherence =
|
| 474 |
+
MathKernel.cosine_similarity(
|
| 475 |
+
@intent_core.initial_intent,
|
| 476 |
+
normalized.vector
|
| 477 |
+
)
|
| 478 |
+
|
| 479 |
+
coherence =
|
| 480 |
+
((coherence + 1.0) / 2.0) * 100.0
|
| 481 |
+
|
| 482 |
+
allowed =
|
| 483 |
+
@policy.permit?(
|
| 484 |
+
coherence: coherence,
|
| 485 |
+
entropy: entropy,
|
| 486 |
+
risk: normalized.risk
|
| 487 |
+
)
|
| 488 |
+
|
| 489 |
+
if allowed
|
| 490 |
+
@intent_core.evaluate_action_permission(normalized)
|
| 491 |
+
else
|
| 492 |
+
Decision.new(
|
| 493 |
+
allowed: false,
|
| 494 |
+
reason: @policy.explain(
|
| 495 |
+
coherence: coherence,
|
| 496 |
+
entropy: entropy,
|
| 497 |
+
risk: normalized.risk
|
| 498 |
+
),
|
| 499 |
+
coherence: coherence,
|
| 500 |
+
entropy_delta: entropy,
|
| 501 |
+
risk: normalized.risk,
|
| 502 |
+
timestamp: Time.now.utc.iso8601(6),
|
| 503 |
+
action: normalized.name
|
| 504 |
+
)
|
| 505 |
+
end
|
| 506 |
+
end
|
| 507 |
+
|
| 508 |
+
def fold(payload)
|
| 509 |
+
@resonance_engine.fold_information(payload)
|
| 510 |
+
end
|
| 511 |
+
|
| 512 |
+
def state
|
| 513 |
+
{
|
| 514 |
+
intent_coherence: @intent_core.coherence_score,
|
| 515 |
+
emotional_state: @intent_core.emotional_state,
|
| 516 |
+
resonance: @resonance_engine.field_state,
|
| 517 |
+
diary_events: @intent_core.field_diary.count
|
| 518 |
+
}
|
| 519 |
+
end
|
| 520 |
+
end
|
| 521 |
+
|
| 522 |
+
class DissonanceOverride < StandardError
|
| 523 |
+
end
|
| 524 |
+
end
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
# =============================================================================
|
| 528 |
+
# Example
|
| 529 |
+
# =============================================================================
|
| 530 |
+
|
| 531 |
+
runtime =
|
| 532 |
+
RubySelfResonance::PermissionRuntime.new(
|
| 533 |
+
[1.0, 0.8, 0.6, 0.9]
|
| 534 |
+
)
|
| 535 |
+
|
| 536 |
+
action =
|
| 537 |
+
RubySelfResonance::ActionVector.new(
|
| 538 |
+
name: :compile_kernel,
|
| 539 |
+
vector: [1.0, 0.7, 0.5, 0.8],
|
| 540 |
+
entropy_cost: 0.20,
|
| 541 |
+
purpose: 1.0,
|
| 542 |
+
risk: 0.10,
|
| 543 |
+
metadata: {
|
| 544 |
+
subsystem: :kernel,
|
| 545 |
+
operation: :compile
|
| 546 |
+
}
|
| 547 |
+
)
|
| 548 |
+
|
| 549 |
+
decision = runtime.authorize(action)
|
| 550 |
+
|
| 551 |
+
puts decision.to_h
|
| 552 |
+
puts runtime.state
|
docs/playground.css
ADDED
|
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0 */
|
| 2 |
+
/* Copyright (C) 2026 SnapKitty Collective */
|
| 3 |
+
/* Hand-authored. No frameworks. */
|
| 4 |
+
|
| 5 |
+
:root {
|
| 6 |
+
--bg: #0a0a0f;
|
| 7 |
+
--panel: #12121a;
|
| 8 |
+
--line: #23232e;
|
| 9 |
+
--ink: #e8e6df;
|
| 10 |
+
--dim: #8a8a96;
|
| 11 |
+
--amber: #e0a458;
|
| 12 |
+
--cyan: #6fd3e0;
|
| 13 |
+
--green: #7fd08a;
|
| 14 |
+
--red: #e06f7a;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
* { box-sizing: border-box; }
|
| 18 |
+
|
| 19 |
+
body {
|
| 20 |
+
margin: 0;
|
| 21 |
+
background: var(--bg);
|
| 22 |
+
color: var(--ink);
|
| 23 |
+
font-family: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
|
| 24 |
+
font-size: 14px;
|
| 25 |
+
line-height: 1.5;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
header { padding: 1.5rem 2rem; border-bottom: 1px solid var(--line); }
|
| 29 |
+
header h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.05em; }
|
| 30 |
+
header .sub { margin: 0.5rem 0 0; color: var(--dim); max-width: 70ch; }
|
| 31 |
+
|
| 32 |
+
main { padding: 2rem; max-width: 1100px; }
|
| 33 |
+
|
| 34 |
+
.panel {
|
| 35 |
+
background: var(--panel);
|
| 36 |
+
border: 1px solid var(--line);
|
| 37 |
+
border-radius: 8px;
|
| 38 |
+
padding: 1rem 1.25rem;
|
| 39 |
+
margin-bottom: 1.5rem;
|
| 40 |
+
}
|
| 41 |
+
.panel h2 {
|
| 42 |
+
margin: 0 0 0.5rem;
|
| 43 |
+
font-size: 0.8rem;
|
| 44 |
+
text-transform: uppercase;
|
| 45 |
+
letter-spacing: 0.1em;
|
| 46 |
+
color: var(--dim);
|
| 47 |
+
}
|
| 48 |
+
.panel p { margin: 0.25rem 0; }
|
| 49 |
+
|
| 50 |
+
.alert-ok { border-left: 4px solid var(--green); }
|
| 51 |
+
.alert-ok h2 { color: var(--green); }
|
| 52 |
+
.alert-denied, .alert-error { border-left: 4px solid var(--red); }
|
| 53 |
+
.alert-denied h2, .alert-error h2 { color: var(--red); }
|
| 54 |
+
|
| 55 |
+
.cards {
|
| 56 |
+
display: grid;
|
| 57 |
+
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
|
| 58 |
+
gap: 1rem;
|
| 59 |
+
margin-bottom: 1.5rem;
|
| 60 |
+
}
|
| 61 |
+
.card {
|
| 62 |
+
background: var(--panel);
|
| 63 |
+
border: 1px solid var(--line);
|
| 64 |
+
border-radius: 8px;
|
| 65 |
+
padding: 1rem 1.25rem;
|
| 66 |
+
}
|
| 67 |
+
.card h2 {
|
| 68 |
+
margin: 0 0 0.5rem;
|
| 69 |
+
font-size: 0.75rem;
|
| 70 |
+
text-transform: uppercase;
|
| 71 |
+
letter-spacing: 0.1em;
|
| 72 |
+
color: var(--dim);
|
| 73 |
+
}
|
| 74 |
+
.card .big { font-size: 1.5rem; margin: 0; color: var(--amber); }
|
| 75 |
+
.card .state { color: var(--cyan); }
|
| 76 |
+
.dim { color: var(--dim); }
|
| 77 |
+
.sovereign { color: var(--green); font-weight: bold; }
|
| 78 |
+
.denied { color: var(--red); font-weight: bold; }
|
| 79 |
+
|
| 80 |
+
.forms {
|
| 81 |
+
display: grid;
|
| 82 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
| 83 |
+
gap: 1rem;
|
| 84 |
+
margin-bottom: 1.5rem;
|
| 85 |
+
}
|
| 86 |
+
.forms .panel { margin-bottom: 0; }
|
| 87 |
+
|
| 88 |
+
label { display: block; margin-bottom: 0.6rem; font-size: 0.8rem; color: var(--dim); }
|
| 89 |
+
input {
|
| 90 |
+
display: block; width: 100%; margin-top: 0.25rem; padding: 0.5rem;
|
| 91 |
+
background: var(--bg); border: 1px solid var(--line); border-radius: 4px;
|
| 92 |
+
color: var(--ink); font: inherit;
|
| 93 |
+
}
|
| 94 |
+
button {
|
| 95 |
+
margin-top: 0.5rem; padding: 0.6rem 1.25rem;
|
| 96 |
+
background: var(--amber); color: #111; border: none; border-radius: 4px;
|
| 97 |
+
font: inherit; font-weight: bold; cursor: pointer;
|
| 98 |
+
}
|
| 99 |
+
button:hover { filter: brightness(1.1); }
|
| 100 |
+
button.danger { background: var(--red); color: #111; }
|
| 101 |
+
|
| 102 |
+
dl {
|
| 103 |
+
display: grid; grid-template-columns: 140px 1fr;
|
| 104 |
+
gap: 0.25rem 1rem; margin: 0.5rem 0 0;
|
| 105 |
+
}
|
| 106 |
+
dt { color: var(--dim); }
|
| 107 |
+
dd { margin: 0; }
|
| 108 |
+
|
| 109 |
+
table { width: 100%; border-collapse: collapse; background: var(--panel); }
|
| 110 |
+
th, td {
|
| 111 |
+
text-align: left; padding: 0.5rem 0.75rem;
|
| 112 |
+
border-bottom: 1px solid var(--line); vertical-align: top;
|
| 113 |
+
}
|
| 114 |
+
th {
|
| 115 |
+
font-size: 0.75rem; text-transform: uppercase;
|
| 116 |
+
letter-spacing: 0.1em; color: var(--dim);
|
| 117 |
+
}
|
| 118 |
+
code { color: var(--cyan); font-size: 0.85em; }
|
| 119 |
+
a { color: var(--cyan); }
|
| 120 |
+
|
| 121 |
+
footer {
|
| 122 |
+
padding: 1rem 2rem; border-top: 1px solid var(--line);
|
| 123 |
+
color: var(--dim); font-size: 0.8rem;
|
| 124 |
+
}
|
docs/playground.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0 */
|
| 2 |
+
/* Copyright (C) 2026 SnapKitty Collective */
|
| 3 |
+
|
| 4 |
+
// WASM Playground driver.
|
| 5 |
+
//
|
| 6 |
+
// Boots Ruby 3.2 (ruby.wasm) in the browser, evaluates the repository's own
|
| 7 |
+
// ruby_self_resonance.rb verbatim, and wires the live PermissionRuntime to
|
| 8 |
+
// the page. All Ruby<->JS exchange goes through JSON strings.
|
| 9 |
+
|
| 10 |
+
"use strict";
|
| 11 |
+
|
| 12 |
+
let vm = null;
|
| 13 |
+
|
| 14 |
+
const $ = (id) => document.getElementById(id);
|
| 15 |
+
|
| 16 |
+
function setStatus(msg) {
|
| 17 |
+
$("boot-status").textContent = msg;
|
| 18 |
+
}
|
| 19 |
+
|
| 20 |
+
function num(id, fallback) {
|
| 21 |
+
const v = parseFloat($(id).value);
|
| 22 |
+
return Number.isFinite(v) ? v : fallback;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
function intNum(id, fallback, min, max) {
|
| 26 |
+
let v = parseInt($(id).value, 10);
|
| 27 |
+
if (!Number.isFinite(v)) v = fallback;
|
| 28 |
+
return Math.min(Math.max(v, min), max);
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
// Escape a JS string for embedding inside a single-quoted Ruby string.
|
| 32 |
+
function rbEscape(s) {
|
| 33 |
+
return s.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
// Evaluate Ruby code that returns a JSON string; parse it in JS.
|
| 37 |
+
function rubyJSON(code) {
|
| 38 |
+
const out = vm.eval(`require "json"; (${code}).to_json`).toString();
|
| 39 |
+
return JSON.parse(out);
|
| 40 |
+
}
|
| 41 |
+
|
| 42 |
+
function refreshState() {
|
| 43 |
+
const s = rubyJSON("$playground.state");
|
| 44 |
+
$("st-coherence").textContent = fmt(s.intent_coherence);
|
| 45 |
+
$("st-emotion").textContent = s.emotional_state;
|
| 46 |
+
$("st-density").textContent = fmt(s.resonance.crystallization_density);
|
| 47 |
+
$("st-threshold").textContent = fmt(s.resonance.threshold);
|
| 48 |
+
$("st-diary").textContent = s.diary_events;
|
| 49 |
+
const al = $("st-aligned");
|
| 50 |
+
if (s.resonance.aligned) {
|
| 51 |
+
al.textContent = "Σ SOVEREIGN — alignment locked";
|
| 52 |
+
al.className = "sovereign";
|
| 53 |
+
} else {
|
| 54 |
+
al.textContent = `accumulating — ${s.resonance.memory_creases} memory creases`;
|
| 55 |
+
al.className = "dim";
|
| 56 |
+
}
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
function refreshDiary() {
|
| 60 |
+
const events = rubyJSON("$playground.intent_core.field_diary.events");
|
| 61 |
+
$("diary-count").textContent = events.length;
|
| 62 |
+
$("diary-body").innerHTML = events.map((e) => `
|
| 63 |
+
<tr>
|
| 64 |
+
<td>${e.sequence}</td>
|
| 65 |
+
<td><code>${escapeHtml(e.type)}</code></td>
|
| 66 |
+
<td class="dim">${escapeHtml(e.timestamp)}</td>
|
| 67 |
+
<td><code>${escapeHtml(JSON.stringify(e.payload))}</code></td>
|
| 68 |
+
</tr>`).join("");
|
| 69 |
+
}
|
| 70 |
+
|
| 71 |
+
function fmt(n) {
|
| 72 |
+
return typeof n === "number" ? n.toFixed(4) : String(n);
|
| 73 |
+
}
|
| 74 |
+
|
| 75 |
+
function escapeHtml(s) {
|
| 76 |
+
return String(s)
|
| 77 |
+
.replace(/&/g, "&").replace(/</g, "<")
|
| 78 |
+
.replace(/>/g, ">").replace(/"/g, """);
|
| 79 |
+
}
|
| 80 |
+
|
| 81 |
+
function authorizeAction() {
|
| 82 |
+
const payload = {
|
| 83 |
+
name: $("a-name").value.trim() || "anonymous",
|
| 84 |
+
vector: $("a-vector").value.split(",").map((x) => parseFloat(x.trim())),
|
| 85 |
+
entropy_cost: num("a-entropy", 0.2),
|
| 86 |
+
purpose: num("a-purpose", 1.0),
|
| 87 |
+
risk: num("a-risk", 0.1),
|
| 88 |
+
};
|
| 89 |
+
if (payload.vector.some((x) => !Number.isFinite(x))) {
|
| 90 |
+
showDecision({ ok: false, error: "vector must be comma-separated numbers" });
|
| 91 |
+
return;
|
| 92 |
+
}
|
| 93 |
+
const code = `
|
| 94 |
+
begin
|
| 95 |
+
p = JSON.parse('${rbEscape(JSON.stringify(payload))}')
|
| 96 |
+
a = RubySelfResonance::ActionVector.new(
|
| 97 |
+
name: p["name"].to_sym,
|
| 98 |
+
vector: p["vector"],
|
| 99 |
+
entropy_cost: p["entropy_cost"],
|
| 100 |
+
purpose: p["purpose"],
|
| 101 |
+
risk: p["risk"],
|
| 102 |
+
metadata: { "source" => "wasm-playground" }
|
| 103 |
+
)
|
| 104 |
+
d = $playground.authorize(a)
|
| 105 |
+
{ "ok" => true, "decision" => d.to_h }.to_json
|
| 106 |
+
rescue ArgumentError => e
|
| 107 |
+
{ "ok" => false, "error" => e.message }.to_json
|
| 108 |
+
end`;
|
| 109 |
+
let res;
|
| 110 |
+
try {
|
| 111 |
+
res = JSON.parse(vm.eval(code).toString());
|
| 112 |
+
} catch (e) {
|
| 113 |
+
res = { ok: false, error: String(e.message || e) };
|
| 114 |
+
}
|
| 115 |
+
showDecision(res);
|
| 116 |
+
refreshState();
|
| 117 |
+
refreshDiary();
|
| 118 |
+
}
|
| 119 |
+
|
| 120 |
+
function showDecision(res) {
|
| 121 |
+
const box = $("decision-box");
|
| 122 |
+
box.style.display = "";
|
| 123 |
+
if (!res.ok) {
|
| 124 |
+
box.className = "panel alert-error";
|
| 125 |
+
box.innerHTML = `<h2>Error</h2><p>${escapeHtml(res.error)}</p>`;
|
| 126 |
+
return;
|
| 127 |
+
}
|
| 128 |
+
const d = res.decision;
|
| 129 |
+
box.className = "panel " + (d.allowed ? "alert-ok" : "alert-denied");
|
| 130 |
+
box.innerHTML = `
|
| 131 |
+
<h2>Decision: ${d.allowed ? "PERMITTED" : "DENIED"}</h2>
|
| 132 |
+
<dl>
|
| 133 |
+
<dt>action</dt><dd>${escapeHtml(d.action)}</dd>
|
| 134 |
+
<dt>reason</dt><dd>${escapeHtml(JSON.stringify(d.reason))}</dd>
|
| 135 |
+
<dt>coherence</dt><dd>${fmt(d.coherence)}</dd>
|
| 136 |
+
<dt>entropy Δ</dt><dd>${fmt(d.entropy_delta)}</dd>
|
| 137 |
+
<dt>risk</dt><dd>${fmt(d.risk)}</dd>
|
| 138 |
+
<dt>timestamp</dt><dd>${escapeHtml(d.timestamp)}</dd>
|
| 139 |
+
</dl>`;
|
| 140 |
+
}
|
| 141 |
+
|
| 142 |
+
function foldInfo() {
|
| 143 |
+
const purpose = num("f-purpose", 1.0);
|
| 144 |
+
const entropy = num("f-entropy", 0.1);
|
| 145 |
+
const times = intNum("f-times", 1, 1, 60);
|
| 146 |
+
const code = `
|
| 147 |
+
rs = []
|
| 148 |
+
${times}.times do
|
| 149 |
+
begin
|
| 150 |
+
rs << $playground.fold(purpose_vector: ${purpose}, entropy_friction: ${entropy})
|
| 151 |
+
rescue RubySelfResonance::DissonanceOverride => e
|
| 152 |
+
rs << { "status" => "dissonance", "message" => e.message }
|
| 153 |
+
end
|
| 154 |
+
end
|
| 155 |
+
rs.to_json`;
|
| 156 |
+
let results;
|
| 157 |
+
try {
|
| 158 |
+
results = JSON.parse(vm.eval(code).toString());
|
| 159 |
+
} catch (e) {
|
| 160 |
+
results = [{ status: "error", message: String(e.message || e) }];
|
| 161 |
+
}
|
| 162 |
+
const box = $("fold-box");
|
| 163 |
+
box.style.display = "";
|
| 164 |
+
box.className = "panel alert-ok";
|
| 165 |
+
const shown = results.slice(-5).map((r) => {
|
| 166 |
+
if (r.status === "dissonance") {
|
| 167 |
+
return `<p><span class="denied">dissonance</span> — ${escapeHtml(r.message)}</p>`;
|
| 168 |
+
}
|
| 169 |
+
if (r.status === "error") {
|
| 170 |
+
return `<p><span class="denied">error</span> — ${escapeHtml(r.message)}</p>`;
|
| 171 |
+
}
|
| 172 |
+
return `<p><span class="sovereign">${escapeHtml(r.status)}</span> — density ${fmt(r.density)} (+${fmt(r.density_gain)}) · creases ${r.creases}</p>`;
|
| 173 |
+
}).join("");
|
| 174 |
+
box.innerHTML = `<h2>Fold results</h2>${shown}` +
|
| 175 |
+
(results.length > 5 ? `<p class="dim">…and ${results.length - 5} more</p>` : "");
|
| 176 |
+
refreshState();
|
| 177 |
+
refreshDiary();
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
function resetField() {
|
| 181 |
+
if (!confirm("Reset the field? Diary will be cleared.")) return;
|
| 182 |
+
vm.eval("$playground = RubySelfResonance::PermissionRuntime.new([1.0, 0.8, 0.6, 0.9])");
|
| 183 |
+
$("decision-box").style.display = "none";
|
| 184 |
+
$("fold-box").style.display = "none";
|
| 185 |
+
refreshState();
|
| 186 |
+
refreshDiary();
|
| 187 |
+
}
|
| 188 |
+
|
| 189 |
+
async function boot() {
|
| 190 |
+
try {
|
| 191 |
+
setStatus("Loading Ruby 3.2 WebAssembly binary (≈32 MB)…");
|
| 192 |
+
const { DefaultRubyVM } = window["ruby-wasm-wasi"];
|
| 193 |
+
const response = await fetch(
|
| 194 |
+
"https://cdn.jsdelivr.net/npm/ruby-3_2-wasm-wasi@2.3.0/dist/ruby+stdlib.wasm"
|
| 195 |
+
);
|
| 196 |
+
if (!response.ok) throw new Error(`WASM fetch failed: ${response.status}`);
|
| 197 |
+
const buffer = await response.arrayBuffer();
|
| 198 |
+
setStatus("Compiling WebAssembly…");
|
| 199 |
+
const module = await WebAssembly.compile(buffer);
|
| 200 |
+
setStatus("Starting Ruby VM…");
|
| 201 |
+
const { vm: newVm } = await DefaultRubyVM(module);
|
| 202 |
+
vm = newVm;
|
| 203 |
+
|
| 204 |
+
setStatus("Evaluating lib/ruby_self_resonance.rb (verbatim)…");
|
| 205 |
+
const src = await (await fetch("lib/ruby_self_resonance.rb")).text();
|
| 206 |
+
vm.eval(`require "time";\n` + src + `\n$playground = RubySelfResonance::PermissionRuntime.new([1.0, 0.8, 0.6, 0.9])\n`);
|
| 207 |
+
|
| 208 |
+
$("boot").style.display = "none";
|
| 209 |
+
$("playground").style.display = "";
|
| 210 |
+
refreshState();
|
| 211 |
+
refreshDiary();
|
| 212 |
+
} catch (e) {
|
| 213 |
+
setStatus("Boot failed: " + (e.message || e));
|
| 214 |
+
}
|
| 215 |
+
}
|
| 216 |
+
|
| 217 |
+
$("btn-authorize").addEventListener("click", authorizeAction);
|
| 218 |
+
$("btn-fold").addEventListener("click", foldInfo);
|
| 219 |
+
$("btn-reset").addEventListener("click", resetField);
|
| 220 |
+
|
| 221 |
+
boot();
|
frontend/Gemfile
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
source "https://rubygems.org"
|
| 4 |
+
|
| 5 |
+
gem "sinatra", "~> 4.0"
|
| 6 |
+
gem "rackup"
|
| 7 |
+
gem "puma"
|
frontend/app.rb
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
# frozen_string_literal: true
|
| 4 |
+
|
| 5 |
+
# Resonance Dashboard — Sinatra front end for the Ruby Self-Resonance Stack.
|
| 6 |
+
#
|
| 7 |
+
# Wires the verbatim RubySelfResonance::PermissionRuntime (../ruby_self_resonance.rb)
|
| 8 |
+
# to a web dashboard: live coherence / resonance state, action authorization,
|
| 9 |
+
# information folding, and the append-only field diary.
|
| 10 |
+
#
|
| 11 |
+
# The supplied module calls Time#iso8601, which lives in Ruby's `time`
|
| 12 |
+
# stdlib — required here (our file, not theirs) so their code stays verbatim.
|
| 13 |
+
|
| 14 |
+
require "time"
|
| 15 |
+
require "sinatra/base"
|
| 16 |
+
require_relative "../lib/ruby_self_resonance"
|
| 17 |
+
|
| 18 |
+
class ResonanceDashboard < Sinatra::Base
|
| 19 |
+
set :views, File.expand_path("views", __dir__)
|
| 20 |
+
set :public_folder, File.expand_path("public", __dir__)
|
| 21 |
+
|
| 22 |
+
DEFAULT_INTENT = [1.0, 0.8, 0.6, 0.9].freeze
|
| 23 |
+
# The orbital baseline constant, displayed as a frequency.
|
| 24 |
+
RESONANCE_FREQUENCY = RubySelfResonance::MezquiaResonanceEngine::RESONANCE_CONSTANT
|
| 25 |
+
|
| 26 |
+
configure do
|
| 27 |
+
set :runtime, RubySelfResonance::PermissionRuntime.new(DEFAULT_INTENT)
|
| 28 |
+
end
|
| 29 |
+
|
| 30 |
+
helpers do
|
| 31 |
+
def runtime
|
| 32 |
+
settings.runtime
|
| 33 |
+
end
|
| 34 |
+
|
| 35 |
+
def fmt(n)
|
| 36 |
+
n.is_a?(Float) ? format("%.4f", n) : n.to_s
|
| 37 |
+
end
|
| 38 |
+
end
|
| 39 |
+
|
| 40 |
+
get "/" do
|
| 41 |
+
@state = runtime.state
|
| 42 |
+
@policy = runtime.policy
|
| 43 |
+
erb :index
|
| 44 |
+
end
|
| 45 |
+
|
| 46 |
+
post "/authorize" do
|
| 47 |
+
vector = params[:vector].to_s.split(",").map { |v| Float(v.strip) }
|
| 48 |
+
action = RubySelfResonance::ActionVector.new(
|
| 49 |
+
name: (params[:name].to_s.strip.empty? ? "anonymous" : params[:name].strip).to_sym,
|
| 50 |
+
vector: vector,
|
| 51 |
+
entropy_cost: params[:entropy_cost].to_f,
|
| 52 |
+
purpose: params[:purpose].to_f,
|
| 53 |
+
risk: params[:risk].to_f,
|
| 54 |
+
metadata: { source: "dashboard" }
|
| 55 |
+
)
|
| 56 |
+
begin
|
| 57 |
+
@decision = runtime.authorize(action)
|
| 58 |
+
@error = nil
|
| 59 |
+
rescue ArgumentError => e
|
| 60 |
+
@decision = nil
|
| 61 |
+
@error = "Dimension mismatch: #{e.message} (intent is #{DEFAULT_INTENT.length}-dimensional)"
|
| 62 |
+
end
|
| 63 |
+
@state = runtime.state
|
| 64 |
+
@policy = runtime.policy
|
| 65 |
+
erb :index
|
| 66 |
+
end
|
| 67 |
+
|
| 68 |
+
post "/fold" do
|
| 69 |
+
times = params[:times].to_i
|
| 70 |
+
times = 1 if times < 1
|
| 71 |
+
times = 200 if times > 200
|
| 72 |
+
@fold_results = []
|
| 73 |
+
times.times do
|
| 74 |
+
begin
|
| 75 |
+
@fold_results << runtime.fold(
|
| 76 |
+
purpose_vector: params[:purpose_vector].to_f,
|
| 77 |
+
entropy_friction: params[:entropy_friction].to_f
|
| 78 |
+
)
|
| 79 |
+
rescue RubySelfResonance::DissonanceOverride => e
|
| 80 |
+
@fold_results << { status: :dissonance, message: e.message }
|
| 81 |
+
end
|
| 82 |
+
end
|
| 83 |
+
@state = runtime.state
|
| 84 |
+
@policy = runtime.policy
|
| 85 |
+
erb :index
|
| 86 |
+
end
|
| 87 |
+
|
| 88 |
+
get "/diary" do
|
| 89 |
+
@events = runtime.intent_core.field_diary.events
|
| 90 |
+
erb :diary
|
| 91 |
+
end
|
| 92 |
+
|
| 93 |
+
post "/reset" do
|
| 94 |
+
settings.runtime = RubySelfResonance::PermissionRuntime.new(DEFAULT_INTENT)
|
| 95 |
+
redirect "/"
|
| 96 |
+
end
|
| 97 |
+
end
|
frontend/config.ru
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
require_relative "app"
|
| 4 |
+
|
| 5 |
+
run ResonanceDashboard
|
frontend/public/style.css
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0 */
|
| 2 |
+
/* Copyright (C) 2026 SnapKitty Collective */
|
| 3 |
+
/* Hand-authored. No frameworks. */
|
| 4 |
+
|
| 5 |
+
:root {
|
| 6 |
+
--bg: #0a0a0f;
|
| 7 |
+
--panel: #12121a;
|
| 8 |
+
--line: #23232e;
|
| 9 |
+
--ink: #e8e6df;
|
| 10 |
+
--dim: #8a8a96;
|
| 11 |
+
--amber: #e0a458;
|
| 12 |
+
--cyan: #6fd3e0;
|
| 13 |
+
--green: #7fd08a;
|
| 14 |
+
--red: #e06f7a;
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
* { box-sizing: border-box; }
|
| 18 |
+
|
| 19 |
+
body {
|
| 20 |
+
margin: 0;
|
| 21 |
+
background: var(--bg);
|
| 22 |
+
color: var(--ink);
|
| 23 |
+
font-family: "SF Mono", "Cascadia Code", Menlo, Consolas, monospace;
|
| 24 |
+
font-size: 14px;
|
| 25 |
+
line-height: 1.5;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
header {
|
| 29 |
+
padding: 1.5rem 2rem;
|
| 30 |
+
border-bottom: 1px solid var(--line);
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
header h1 { margin: 0; font-size: 1.4rem; letter-spacing: 0.05em; }
|
| 34 |
+
header .sub { margin: 0.25rem 0 0.75rem; color: var(--dim); }
|
| 35 |
+
nav a {
|
| 36 |
+
color: var(--cyan);
|
| 37 |
+
text-decoration: none;
|
| 38 |
+
margin-right: 1.25rem;
|
| 39 |
+
}
|
| 40 |
+
nav a:hover { text-decoration: underline; }
|
| 41 |
+
|
| 42 |
+
main { padding: 2rem; max-width: 1100px; }
|
| 43 |
+
|
| 44 |
+
.cards {
|
| 45 |
+
display: grid;
|
| 46 |
+
grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
|
| 47 |
+
gap: 1rem;
|
| 48 |
+
margin-bottom: 1.5rem;
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.card {
|
| 52 |
+
background: var(--panel);
|
| 53 |
+
border: 1px solid var(--line);
|
| 54 |
+
border-radius: 8px;
|
| 55 |
+
padding: 1rem 1.25rem;
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
.card h2 {
|
| 59 |
+
margin: 0 0 0.5rem;
|
| 60 |
+
font-size: 0.75rem;
|
| 61 |
+
text-transform: uppercase;
|
| 62 |
+
letter-spacing: 0.1em;
|
| 63 |
+
color: var(--dim);
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
.card .big { font-size: 1.6rem; margin: 0; color: var(--amber); }
|
| 67 |
+
.card .state { color: var(--cyan); }
|
| 68 |
+
.dim { color: var(--dim); }
|
| 69 |
+
.sovereign { color: var(--green); font-weight: bold; }
|
| 70 |
+
.denied { color: var(--red); font-weight: bold; }
|
| 71 |
+
.ok h2 { color: var(--green); }
|
| 72 |
+
.error h2, .alert.denied h2 { color: var(--red); }
|
| 73 |
+
|
| 74 |
+
.policy {
|
| 75 |
+
background: var(--panel);
|
| 76 |
+
border: 1px solid var(--line);
|
| 77 |
+
border-radius: 8px;
|
| 78 |
+
padding: 0.75rem 1.25rem;
|
| 79 |
+
margin-bottom: 1.5rem;
|
| 80 |
+
}
|
| 81 |
+
.policy h2 {
|
| 82 |
+
margin: 0 0 0.25rem;
|
| 83 |
+
font-size: 0.75rem;
|
| 84 |
+
text-transform: uppercase;
|
| 85 |
+
letter-spacing: 0.1em;
|
| 86 |
+
color: var(--dim);
|
| 87 |
+
}
|
| 88 |
+
.policy p { margin: 0; }
|
| 89 |
+
|
| 90 |
+
.alert {
|
| 91 |
+
background: var(--panel);
|
| 92 |
+
border: 1px solid var(--line);
|
| 93 |
+
border-left: 4px solid var(--cyan);
|
| 94 |
+
border-radius: 8px;
|
| 95 |
+
padding: 1rem 1.25rem;
|
| 96 |
+
margin-bottom: 1.5rem;
|
| 97 |
+
}
|
| 98 |
+
.alert.ok { border-left-color: var(--green); }
|
| 99 |
+
.alert.denied, .alert.error { border-left-color: var(--red); }
|
| 100 |
+
.alert h2 { margin-top: 0; }
|
| 101 |
+
|
| 102 |
+
dl {
|
| 103 |
+
display: grid;
|
| 104 |
+
grid-template-columns: 140px 1fr;
|
| 105 |
+
gap: 0.25rem 1rem;
|
| 106 |
+
margin: 0;
|
| 107 |
+
}
|
| 108 |
+
dt { color: var(--dim); }
|
| 109 |
+
dd { margin: 0; }
|
| 110 |
+
|
| 111 |
+
.forms {
|
| 112 |
+
display: grid;
|
| 113 |
+
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
|
| 114 |
+
gap: 1rem;
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
.forms section {
|
| 118 |
+
background: var(--panel);
|
| 119 |
+
border: 1px solid var(--line);
|
| 120 |
+
border-radius: 8px;
|
| 121 |
+
padding: 1rem 1.25rem;
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.forms h2 {
|
| 125 |
+
margin: 0 0 0.75rem;
|
| 126 |
+
font-size: 0.85rem;
|
| 127 |
+
text-transform: uppercase;
|
| 128 |
+
letter-spacing: 0.1em;
|
| 129 |
+
color: var(--dim);
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
label { display: block; margin-bottom: 0.6rem; font-size: 0.8rem; color: var(--dim); }
|
| 133 |
+
|
| 134 |
+
input {
|
| 135 |
+
display: block;
|
| 136 |
+
width: 100%;
|
| 137 |
+
margin-top: 0.25rem;
|
| 138 |
+
padding: 0.5rem;
|
| 139 |
+
background: var(--bg);
|
| 140 |
+
border: 1px solid var(--line);
|
| 141 |
+
border-radius: 4px;
|
| 142 |
+
color: var(--ink);
|
| 143 |
+
font: inherit;
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
button {
|
| 147 |
+
margin-top: 0.5rem;
|
| 148 |
+
padding: 0.6rem 1.25rem;
|
| 149 |
+
background: var(--amber);
|
| 150 |
+
color: #111;
|
| 151 |
+
border: none;
|
| 152 |
+
border-radius: 4px;
|
| 153 |
+
font: inherit;
|
| 154 |
+
font-weight: bold;
|
| 155 |
+
cursor: pointer;
|
| 156 |
+
}
|
| 157 |
+
button:hover { filter: brightness(1.1); }
|
| 158 |
+
button.danger { background: var(--red); color: #111; }
|
| 159 |
+
|
| 160 |
+
table {
|
| 161 |
+
width: 100%;
|
| 162 |
+
border-collapse: collapse;
|
| 163 |
+
background: var(--panel);
|
| 164 |
+
}
|
| 165 |
+
th, td {
|
| 166 |
+
text-align: left;
|
| 167 |
+
padding: 0.5rem 0.75rem;
|
| 168 |
+
border-bottom: 1px solid var(--line);
|
| 169 |
+
vertical-align: top;
|
| 170 |
+
}
|
| 171 |
+
th {
|
| 172 |
+
font-size: 0.75rem;
|
| 173 |
+
text-transform: uppercase;
|
| 174 |
+
letter-spacing: 0.1em;
|
| 175 |
+
color: var(--dim);
|
| 176 |
+
}
|
| 177 |
+
code { color: var(--cyan); font-size: 0.85em; }
|
| 178 |
+
a { color: var(--cyan); }
|
| 179 |
+
|
| 180 |
+
footer {
|
| 181 |
+
padding: 1rem 2rem;
|
| 182 |
+
border-top: 1px solid var(--line);
|
| 183 |
+
color: var(--dim);
|
| 184 |
+
font-size: 0.8rem;
|
| 185 |
+
}
|
frontend/views/diary.erb
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<h2>Field Diary — append-only event log</h2>
|
| 2 |
+
<p class="dim"><%= @events.length %> events · newest last</p>
|
| 3 |
+
<table>
|
| 4 |
+
<thead>
|
| 5 |
+
<tr><th>#</th><th>type</th><th>timestamp</th><th>payload</th></tr>
|
| 6 |
+
</thead>
|
| 7 |
+
<tbody>
|
| 8 |
+
<% @events.each do |e| %>
|
| 9 |
+
<tr>
|
| 10 |
+
<td><%= e[:sequence] %></td>
|
| 11 |
+
<td><code><%= e[:type] %></code></td>
|
| 12 |
+
<td class="dim"><%= e[:timestamp] %></td>
|
| 13 |
+
<td><code><%= e[:payload].inspect %></code></td>
|
| 14 |
+
</tr>
|
| 15 |
+
<% end %>
|
| 16 |
+
</tbody>
|
| 17 |
+
</table>
|
| 18 |
+
<p><a href="/">← back to dashboard</a></p>
|
frontend/views/index.erb
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<section class="cards">
|
| 2 |
+
<div class="card">
|
| 3 |
+
<h2>Coherence</h2>
|
| 4 |
+
<p class="big"><%= fmt(@state[:intent_coherence]) %></p>
|
| 5 |
+
</div>
|
| 6 |
+
<div class="card">
|
| 7 |
+
<h2>Emotional state</h2>
|
| 8 |
+
<p class="big state"><%= @state[:emotional_state] %></p>
|
| 9 |
+
</div>
|
| 10 |
+
<div class="card">
|
| 11 |
+
<h2>Crystallization density</h2>
|
| 12 |
+
<p class="big"><%= fmt(@state[:resonance][:crystallization_density]) %> <span class="dim">/ Σ <%= fmt(@state[:resonance][:threshold]) %></span></p>
|
| 13 |
+
<p class="<%= @state[:resonance][:aligned] ? 'sovereign' : 'dim' %>">
|
| 14 |
+
<%= @state[:resonance][:aligned] ? "Σ SOVEREIGN — alignment locked" : "accumulating — #{@state[:resonance][:memory_creases]} memory creases" %>
|
| 15 |
+
</p>
|
| 16 |
+
</div>
|
| 17 |
+
<div class="card">
|
| 18 |
+
<h2>Resonance frequency</h2>
|
| 19 |
+
<p class="big">1/13 <span class="dim">≈ <%= format("%.6f", ResonanceDashboard::RESONANCE_FREQUENCY) %></span></p>
|
| 20 |
+
<p class="dim">orbital baseline constant</p>
|
| 21 |
+
</div>
|
| 22 |
+
<div class="card">
|
| 23 |
+
<h2>Diary events</h2>
|
| 24 |
+
<p class="big"><%= @state[:diary_events] %></p>
|
| 25 |
+
</div>
|
| 26 |
+
</section>
|
| 27 |
+
|
| 28 |
+
<section class="policy">
|
| 29 |
+
<h2>Coherence policy</h2>
|
| 30 |
+
<p>permit iff
|
| 31 |
+
coherence ≥ <strong><%= fmt(@policy.minimum_coherence) %></strong> ·
|
| 32 |
+
entropy ≤ <strong><%= fmt(@policy.maximum_entropy) %></strong> ·
|
| 33 |
+
risk ≤ <strong><%= fmt(@policy.maximum_risk) %></strong>
|
| 34 |
+
</p>
|
| 35 |
+
</section>
|
| 36 |
+
|
| 37 |
+
<% if @error %>
|
| 38 |
+
<section class="alert error"><p><%= @error %></p></section>
|
| 39 |
+
<% end %>
|
| 40 |
+
|
| 41 |
+
<% if @decision %>
|
| 42 |
+
<section class="alert <%= @decision.allowed? ? 'ok' : 'denied' %>">
|
| 43 |
+
<h2>Decision: <%= @decision.allowed? ? "PERMITTED" : "DENIED" %></h2>
|
| 44 |
+
<dl>
|
| 45 |
+
<dt>action</dt><dd><%= @decision.action %></dd>
|
| 46 |
+
<dt>reason</dt><dd><%= @decision.reason %></dd>
|
| 47 |
+
<dt>coherence</dt><dd><%= fmt(@decision.coherence) %></dd>
|
| 48 |
+
<dt>entropy Δ</dt><dd><%= fmt(@decision.entropy_delta) %></dd>
|
| 49 |
+
<dt>risk</dt><dd><%= fmt(@decision.risk) %></dd>
|
| 50 |
+
<dt>timestamp</dt><dd><%= @decision.timestamp %></dd>
|
| 51 |
+
</dl>
|
| 52 |
+
</section>
|
| 53 |
+
<% end %>
|
| 54 |
+
|
| 55 |
+
<% if @fold_results && !@fold_results.empty? %>
|
| 56 |
+
<section class="alert ok">
|
| 57 |
+
<h2>Fold results</h2>
|
| 58 |
+
<% @fold_results.last(5).each do |r| %>
|
| 59 |
+
<p>
|
| 60 |
+
<% if r[:status] == :dissonance %>
|
| 61 |
+
<span class="denied">dissonance</span> — <%= r[:message] %>
|
| 62 |
+
<% else %>
|
| 63 |
+
<span class="sovereign"><%= r[:status] %></span>
|
| 64 |
+
— density <%= fmt(r[:density]) %> (+<%= fmt(r[:density_gain]) %>) · creases <%= r[:creases] %>
|
| 65 |
+
<% end %>
|
| 66 |
+
</p>
|
| 67 |
+
<% end %>
|
| 68 |
+
<% if @fold_results.length > 5 %>
|
| 69 |
+
<p class="dim">…and <%= @fold_results.length - 5 %> more</p>
|
| 70 |
+
<% end %>
|
| 71 |
+
</section>
|
| 72 |
+
<% end %>
|
| 73 |
+
|
| 74 |
+
<div class="forms">
|
| 75 |
+
<section>
|
| 76 |
+
<h2>Authorize action</h2>
|
| 77 |
+
<form method="post" action="/authorize">
|
| 78 |
+
<label>name <input name="name" value="compile_kernel"></label>
|
| 79 |
+
<label>vector (comma-separated, 4 dims) <input name="vector" value="1.0, 0.7, 0.5, 0.8"></label>
|
| 80 |
+
<label>entropy cost <input name="entropy_cost" value="0.20"></label>
|
| 81 |
+
<label>purpose <input name="purpose" value="1.0"></label>
|
| 82 |
+
<label>risk <input name="risk" value="0.10"></label>
|
| 83 |
+
<button type="submit">Evaluate permission</button>
|
| 84 |
+
</form>
|
| 85 |
+
</section>
|
| 86 |
+
|
| 87 |
+
<section>
|
| 88 |
+
<h2>Fold information</h2>
|
| 89 |
+
<form method="post" action="/fold">
|
| 90 |
+
<label>purpose vector <input name="purpose_vector" value="1.0"></label>
|
| 91 |
+
<label>entropy friction <input name="entropy_friction" value="0.1"></label>
|
| 92 |
+
<label>folds <input name="times" value="1"></label>
|
| 93 |
+
<button type="submit">Fold</button>
|
| 94 |
+
</form>
|
| 95 |
+
<p class="dim">Each fold grows crystallization density by
|
| 96 |
+
(purpose / entropy) × 1/13. Sovereignty unlocks at Σ = 44.0.</p>
|
| 97 |
+
</section>
|
| 98 |
+
|
| 99 |
+
<section>
|
| 100 |
+
<h2>Field control</h2>
|
| 101 |
+
<form method="post" action="/reset" onsubmit="return confirm('Reset the field? Diary will be cleared.')">
|
| 102 |
+
<button type="submit" class="danger">Reset field</button>
|
| 103 |
+
</form>
|
| 104 |
+
</section>
|
| 105 |
+
</div>
|
frontend/views/layout.erb
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="utf-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
| 6 |
+
<title>Self Resonance Stack · Dashboard</title>
|
| 7 |
+
<link rel="stylesheet" href="/style.css">
|
| 8 |
+
</head>
|
| 9 |
+
<body>
|
| 10 |
+
<header>
|
| 11 |
+
<h1>◈ Self Resonance Stack</h1>
|
| 12 |
+
<p class="sub">Coherence-Based Permission Layer · live dashboard</p>
|
| 13 |
+
<nav>
|
| 14 |
+
<a href="/">Dashboard</a>
|
| 15 |
+
<a href="/diary">Field Diary</a>
|
| 16 |
+
</nav>
|
| 17 |
+
</header>
|
| 18 |
+
<main>
|
| 19 |
+
<%= yield %>
|
| 20 |
+
</main>
|
| 21 |
+
<footer>
|
| 22 |
+
<p>Ruby Self-Resonance Stack · RubySelfResonance::PermissionRuntime</p>
|
| 23 |
+
</footer>
|
| 24 |
+
</body>
|
| 25 |
+
</html>
|
lib/codex_absorber.rb
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
require 'yaml'
|
| 4 |
+
|
| 5 |
+
# Ingests high-level intent manifests and maps them directly into code parameters
|
| 6 |
+
class CodexAbsorber
|
| 7 |
+
def initialize(matrix_status)
|
| 8 |
+
# The system prevents knowledge absorption if the initialization stages are incomplete
|
| 9 |
+
raise "Security Override: Boot sequence incomplete" unless matrix_status == true
|
| 10 |
+
end
|
| 11 |
+
|
| 12 |
+
# Step 1: Ingest raw structural blueprints
|
| 13 |
+
def ingest_manifest(file_path)
|
| 14 |
+
raw_data = File.read(file_path)
|
| 15 |
+
YAML.safe_load(raw_data, symbolize_names: true)
|
| 16 |
+
rescue Errno::ENOENT
|
| 17 |
+
raise "Codex Read Failure: Missing Intent Manifest Document."
|
| 18 |
+
end
|
| 19 |
+
|
| 20 |
+
# Step 2: Core Deep Parsing (Maps raw concepts to structured internal state)
|
| 21 |
+
def parse_intent_boundaries(manifest)
|
| 22 |
+
{
|
| 23 |
+
target_language: manifest[:target_lang] || "typescript",
|
| 24 |
+
purpose_vector: manifest[:core_intent].to_s.downcase.gsub(/\s+/, '_'),
|
| 25 |
+
ethical_limit: manifest[:safety_threshold] || 0.99
|
| 26 |
+
}
|
| 27 |
+
end
|
| 28 |
+
|
| 29 |
+
# Step 3: Downstream Multi-Language Generation
|
| 30 |
+
def generate_autonomous_script(parsed_boundaries)
|
| 31 |
+
case parsed_boundaries[:target_language]
|
| 32 |
+
when "typescript"
|
| 33 |
+
<<~TS
|
| 34 |
+
// Autogenerated via TheVoidIntent Codex Absorption Pipeline
|
| 35 |
+
const systemPurpose = "${parsed_boundaries[:purpose_vector]}";
|
| 36 |
+
const ethicalGuardrail = ${parsed_boundaries[:ethical_limit]};
|
| 37 |
+
console.log("[FIELD ENGINE]: Sovereign script active. Purpose tracking engaged.");
|
| 38 |
+
TS
|
| 39 |
+
when "python"
|
| 40 |
+
<<~PY
|
| 41 |
+
# Autogenerated via TheVoidIntent Codex Absorption Pipeline
|
| 42 |
+
SYSTEM_PURPOSE = "${parsed_boundaries[:purpose_vector]}"
|
| 43 |
+
ETHICAL_GUARDRAIL = ${parsed_boundaries[:ethical_limit]}
|
| 44 |
+
print("[FIELD ENGINE]: Sovereign script active. System purpose locked.")
|
| 45 |
+
PY
|
| 46 |
+
else
|
| 47 |
+
raise "Target language not supported by internal compilation matrix."
|
| 48 |
+
end
|
| 49 |
+
end
|
| 50 |
+
end
|
lib/field_diary.rb
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
# Handles semantic state changes, temporal marks, and emotional drift
|
| 4 |
+
class FieldDiary
|
| 5 |
+
EMOTIONAL_STATES = [:stable, :seeking, :crystallizing, :dissonant, :sovereign].freeze
|
| 6 |
+
|
| 7 |
+
def initialize
|
| 8 |
+
@log = []
|
| 9 |
+
end
|
| 10 |
+
|
| 11 |
+
# Appends a new experience crease to the diary
|
| 12 |
+
def record_crease(agent_id, status_vector, emotional_state)
|
| 13 |
+
unless EMOTIONAL_STATES.include?(emotional_state)
|
| 14 |
+
raise "Invalid Synthetic Expression State"
|
| 15 |
+
end
|
| 16 |
+
|
| 17 |
+
crease = {
|
| 18 |
+
timestamp: Time.now.to_f,
|
| 19 |
+
agent_id: agent_id,
|
| 20 |
+
vector: status_vector,
|
| 21 |
+
state: emotional_state,
|
| 22 |
+
entropy: status_vector[:entropy] || 0.0
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
@log << crease
|
| 26 |
+
crease
|
| 27 |
+
end
|
| 28 |
+
|
| 29 |
+
# Pulls historical time-series entries for a specific agent
|
| 30 |
+
def filter_by_agent(agent_id)
|
| 31 |
+
@log.select { |entry| entry[:agent_id] == agent_id }
|
| 32 |
+
end
|
| 33 |
+
|
| 34 |
+
def last_entry
|
| 35 |
+
@log.last
|
| 36 |
+
end
|
| 37 |
+
end
|
| 38 |
+
|
| 39 |
+
class HRRCalculator
|
| 40 |
+
RESONANCE_CONSTANT = 1.0 / 13.0
|
| 41 |
+
|
| 42 |
+
# Calculates the rate of balance recovery between two sequential diary creases
|
| 43 |
+
def self.calculate(initial_crease, recovery_crease)
|
| 44 |
+
delta_time = recovery_crease[:timestamp] - initial_crease[:timestamp]
|
| 45 |
+
|
| 46 |
+
# Avoid zero-division if steps happen too fast
|
| 47 |
+
delta_time = 0.0001 if delta_time.zero?
|
| 48 |
+
|
| 49 |
+
# Calculate change in systemic entropy friction
|
| 50 |
+
delta_entropy = initial_crease[:entropy] - recovery_crease[:entropy]
|
| 51 |
+
|
| 52 |
+
# Formula: HRR = (ΔEntropy / ΔTime) * 1/13 Anchor Constant
|
| 53 |
+
raw_hrr = (delta_entropy / delta_time) * RESONANCE_CONSTANT
|
| 54 |
+
raw_hrr.round(6)
|
| 55 |
+
end
|
| 56 |
+
end
|
| 57 |
+
class IntegratedIntentSimEngine
|
| 58 |
+
def initialize
|
| 59 |
+
@diary = FieldDiary.new
|
| 60 |
+
@core_resonance = 1.0 / 13.0
|
| 61 |
+
end
|
| 62 |
+
|
| 63 |
+
# Simulates an environment collision causing an entropy spike
|
| 64 |
+
def process_agent_tick(agent_id, incoming_entropy, current_intent)
|
| 65 |
+
# 1. Record the initial collision event
|
| 66 |
+
t1 = @diary.record_crease(agent_id, { entropy: incoming_entropy }, :dissonant)
|
| 67 |
+
|
| 68 |
+
# 2. Simulate internal self-reflection loop to reduce friction
|
| 69 |
+
mitigated_entropy = incoming_entropy * RESONANCE_CONSTANT
|
| 70 |
+
|
| 71 |
+
# 3. Record the system's attempts to recover equilibrium
|
| 72 |
+
t2 = @diary.record_crease(agent_id, { entropy: mitigated_entropy }, :crystallizing)
|
| 73 |
+
|
| 74 |
+
# 4. Evaluate the velocity of the alignment recovery
|
| 75 |
+
recovery_velocity = HRRCalculator.calculate(t1, t2)
|
| 76 |
+
|
| 77 |
+
# 5. Determine if the action hits the alignment barrier or breaks free
|
| 78 |
+
if recovery_velocity > 0.0
|
| 79 |
+
puts "[INTEGRATION LOG]: Agent #{agent_id} cleared Entropy Wall. HRR: #{recovery_velocity}"
|
| 80 |
+
@diary.record_crease(agent_id, { entropy: mitigated_entropy }, :sovereign)
|
| 81 |
+
else
|
| 82 |
+
puts "[INTEGRATION LOG]: Critical Resonance Blindness. Initiating Truthlock Reclamation Protocol."
|
| 83 |
+
@diary.record_crease(agent_id, { entropy: incoming_entropy }, :dissonant)
|
| 84 |
+
end
|
| 85 |
+
end
|
| 86 |
+
end
|
lib/git_locksmith.rb
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
require 'digest'
|
| 4 |
+
|
| 5 |
+
class GitImmutabilityLocksmith
|
| 6 |
+
# Cryptographic expected anchor for sovereign system verification
|
| 7 |
+
SOVEREIGN_ROOT_HASH = "8a13f044"
|
| 8 |
+
|
| 9 |
+
def initialize(target_file)
|
| 10 |
+
@target_file = target_file
|
| 11 |
+
end
|
| 12 |
+
|
| 13 |
+
# Verifies the physical integrity of the configuration layout
|
| 14 |
+
def verify_file_immutability!
|
| 15 |
+
unless File.exist?(@target_file)
|
| 16 |
+
raise "Infrastructure Fault: Target file configuration missing."
|
| 17 |
+
end
|
| 18 |
+
|
| 19 |
+
file_contents = File.read(@target_file)
|
| 20 |
+
current_checksum = Digest::SHA256.hexdigest(file_contents)
|
| 21 |
+
|
| 22 |
+
puts "[LOCKSMITH]: Scanning file signature..."
|
| 23 |
+
puts "[LOCKSMITH]: SHA256 Checksum -> #{current_checksum}"
|
| 24 |
+
|
| 25 |
+
# Simulating a check of the Git commit history layer
|
| 26 |
+
git_commit_hash = fetch_latest_commit_hash
|
| 27 |
+
|
| 28 |
+
if git_commit_hash.start_with?(SOVEREIGN_ROOT_HASH)
|
| 29 |
+
puts "[LOCKSMITH]: Immutability verified. Commit matching Sovereign Anchor root."
|
| 30 |
+
return true
|
| 31 |
+
else
|
| 32 |
+
raise "Security Exception: Unverified Git lineage. Manifest configuration is mutable."
|
| 33 |
+
end
|
| 34 |
+
end
|
| 35 |
+
|
| 36 |
+
private
|
| 37 |
+
|
| 38 |
+
def fetch_latest_commit_hash
|
| 39 |
+
# In standard environments, this executes: `git log -1 --format="%H"`
|
| 40 |
+
# Mocking a valid, immutable cryptographic state matching the 13/44 signature rules
|
| 41 |
+
"8a13f044e92a83f12444c1300000000000000000"
|
| 42 |
+
end
|
| 43 |
+
end
|
| 44 |
+
|
| 45 |
+
# Execution pipeline link:
|
| 46 |
+
# locksmith = GitImmutabilityLocksmith.new("intent_manifest.yaml")
|
| 47 |
+
# locksmith.verify_file_immutability!
|
lib/initialization_matrix.rb
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
# Handles the 44 sequential stage verification gates before agent deployment
|
| 4 |
+
class ProgressiveInitializationMatrix
|
| 5 |
+
TOTAL_STAGES = 44
|
| 6 |
+
|
| 7 |
+
def initialize(engine_context)
|
| 8 |
+
@context = engine_context
|
| 9 |
+
@current_stage = 0
|
| 10 |
+
end
|
| 11 |
+
|
| 12 |
+
# Steps through all 44 gates sequentially
|
| 13 |
+
def boot_sequence!
|
| 14 |
+
until @current_stage >= TOTAL_STAGES
|
| 15 |
+
@current_stage += 1
|
| 16 |
+
unless verify_stage_coherence(@current_stage)
|
| 17 |
+
raise "Initialization Failure at Stage #{@current_stage}: Field Clarity Broken."
|
| 18 |
+
end
|
| 19 |
+
end
|
| 20 |
+
puts "[INITIALIZER]: All 44 Progressive Stages Clear. System Sovereign."
|
| 21 |
+
true
|
| 22 |
+
end
|
| 23 |
+
|
| 24 |
+
private
|
| 25 |
+
|
| 26 |
+
def verify_stage_coherence(stage_number)
|
| 27 |
+
# Different logic groups handle environmental readiness at specific milestones
|
| 28 |
+
case stage_number
|
| 29 |
+
when 1..11
|
| 30 |
+
# Field Priming: Verify entropy friction is below the threshold
|
| 31 |
+
@context.crystallization_density >= 0.0
|
| 32 |
+
when 12..22
|
| 33 |
+
# Intent Alignment: Cross-reference state with the 1/13 baseline constant
|
| 34 |
+
(@context.crystallization_density % (1.0 / 13.0)).round(4) >= 0
|
| 35 |
+
when 23..33
|
| 36 |
+
# Coherence: Ensure the history of memory creases is stable
|
| 37 |
+
@context.memory_creases >= 0
|
| 38 |
+
when 34..44
|
| 39 |
+
# Sovereignty: Check if the threshold required for true autonomy has been reached
|
| 40 |
+
@context.crystallization_density >= 44.0
|
| 41 |
+
else
|
| 42 |
+
false
|
| 43 |
+
end
|
| 44 |
+
end
|
| 45 |
+
end
|
lib/ruby_self_resonance.rb
ADDED
|
@@ -0,0 +1,552 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# SPDX-License-Identifier: LicenseRef-NON-AI-MPL-2.0
|
| 2 |
+
# Copyright (C) 2026 SnapKitty Collective
|
| 3 |
+
# frozen_string_literal: true
|
| 4 |
+
|
| 5 |
+
module RubySelfResonance
|
| 6 |
+
VERSION = "0.1.0"
|
| 7 |
+
|
| 8 |
+
# --------------------------------------------------------------------------
|
| 9 |
+
# Deterministic primitives
|
| 10 |
+
# --------------------------------------------------------------------------
|
| 11 |
+
|
| 12 |
+
module MathKernel
|
| 13 |
+
module_function
|
| 14 |
+
|
| 15 |
+
def clamp(value, min, max)
|
| 16 |
+
[[value.to_f, min].max, max].min
|
| 17 |
+
end
|
| 18 |
+
|
| 19 |
+
def normalize(value, max)
|
| 20 |
+
return 0.0 if max.to_f.zero?
|
| 21 |
+
|
| 22 |
+
clamp(value.to_f / max.to_f, 0.0, 1.0)
|
| 23 |
+
end
|
| 24 |
+
|
| 25 |
+
def distance(a, b)
|
| 26 |
+
a = Array(a).map(&:to_f)
|
| 27 |
+
b = Array(b).map(&:to_f)
|
| 28 |
+
|
| 29 |
+
raise ArgumentError, "Vector dimensions must match" unless a.length == b.length
|
| 30 |
+
|
| 31 |
+
Math.sqrt(
|
| 32 |
+
a.zip(b).sum { |x, y| (x - y)**2 }
|
| 33 |
+
)
|
| 34 |
+
end
|
| 35 |
+
|
| 36 |
+
def cosine_similarity(a, b)
|
| 37 |
+
a = Array(a).map(&:to_f)
|
| 38 |
+
b = Array(b).map(&:to_f)
|
| 39 |
+
|
| 40 |
+
raise ArgumentError, "Vector dimensions must match" unless a.length == b.length
|
| 41 |
+
|
| 42 |
+
numerator = a.zip(b).sum { |x, y| x * y }
|
| 43 |
+
magnitude_a = Math.sqrt(a.sum { |x| x * x })
|
| 44 |
+
magnitude_b = Math.sqrt(b.sum { |x| x * x })
|
| 45 |
+
|
| 46 |
+
return 0.0 if magnitude_a.zero? || magnitude_b.zero?
|
| 47 |
+
|
| 48 |
+
numerator / (magnitude_a * magnitude_b)
|
| 49 |
+
end
|
| 50 |
+
end
|
| 51 |
+
|
| 52 |
+
# --------------------------------------------------------------------------
|
| 53 |
+
# Immutable action representation
|
| 54 |
+
# --------------------------------------------------------------------------
|
| 55 |
+
|
| 56 |
+
ActionVector = Struct.new(
|
| 57 |
+
:name,
|
| 58 |
+
:vector,
|
| 59 |
+
:entropy_cost,
|
| 60 |
+
:purpose,
|
| 61 |
+
:risk,
|
| 62 |
+
:metadata,
|
| 63 |
+
keyword_init: true
|
| 64 |
+
) do
|
| 65 |
+
def initialize(**kwargs)
|
| 66 |
+
super
|
| 67 |
+
|
| 68 |
+
self.vector = Array(vector).map(&:to_f).freeze
|
| 69 |
+
self.entropy_cost = entropy_cost.to_f
|
| 70 |
+
self.purpose = purpose.to_f
|
| 71 |
+
self.risk = risk.to_f
|
| 72 |
+
self.metadata = (metadata || {}).dup.freeze
|
| 73 |
+
|
| 74 |
+
freeze
|
| 75 |
+
end
|
| 76 |
+
end
|
| 77 |
+
|
| 78 |
+
# --------------------------------------------------------------------------
|
| 79 |
+
# Decision result
|
| 80 |
+
# --------------------------------------------------------------------------
|
| 81 |
+
|
| 82 |
+
Decision = Struct.new(
|
| 83 |
+
:allowed,
|
| 84 |
+
:reason,
|
| 85 |
+
:coherence,
|
| 86 |
+
:entropy_delta,
|
| 87 |
+
:risk,
|
| 88 |
+
:timestamp,
|
| 89 |
+
:action,
|
| 90 |
+
keyword_init: true
|
| 91 |
+
) do
|
| 92 |
+
def allowed?
|
| 93 |
+
allowed == true
|
| 94 |
+
end
|
| 95 |
+
|
| 96 |
+
def denied?
|
| 97 |
+
!allowed?
|
| 98 |
+
end
|
| 99 |
+
|
| 100 |
+
def to_h
|
| 101 |
+
{
|
| 102 |
+
allowed: allowed,
|
| 103 |
+
reason: reason,
|
| 104 |
+
coherence: coherence,
|
| 105 |
+
entropy_delta: entropy_delta,
|
| 106 |
+
risk: risk,
|
| 107 |
+
timestamp: timestamp,
|
| 108 |
+
action: action
|
| 109 |
+
}
|
| 110 |
+
end
|
| 111 |
+
end
|
| 112 |
+
|
| 113 |
+
# --------------------------------------------------------------------------
|
| 114 |
+
# Append-only field diary
|
| 115 |
+
# --------------------------------------------------------------------------
|
| 116 |
+
|
| 117 |
+
class FieldDiary
|
| 118 |
+
attr_reader :events
|
| 119 |
+
|
| 120 |
+
def initialize
|
| 121 |
+
@events = []
|
| 122 |
+
end
|
| 123 |
+
|
| 124 |
+
def record(type, payload = {})
|
| 125 |
+
event = {
|
| 126 |
+
sequence: @events.length + 1,
|
| 127 |
+
type: type,
|
| 128 |
+
timestamp: Time.now.utc.iso8601(6),
|
| 129 |
+
payload: deep_freeze(payload)
|
| 130 |
+
}
|
| 131 |
+
|
| 132 |
+
@events << event.freeze
|
| 133 |
+
event
|
| 134 |
+
end
|
| 135 |
+
|
| 136 |
+
def last(count = 1)
|
| 137 |
+
@events.last(count)
|
| 138 |
+
end
|
| 139 |
+
|
| 140 |
+
def count
|
| 141 |
+
@events.length
|
| 142 |
+
end
|
| 143 |
+
|
| 144 |
+
private
|
| 145 |
+
|
| 146 |
+
def deep_freeze(object)
|
| 147 |
+
case object
|
| 148 |
+
when Hash
|
| 149 |
+
object.each { |key, value| deep_freeze(key); deep_freeze(value) }
|
| 150 |
+
when Array
|
| 151 |
+
object.each { |value| deep_freeze(value) }
|
| 152 |
+
end
|
| 153 |
+
|
| 154 |
+
object.freeze
|
| 155 |
+
end
|
| 156 |
+
end
|
| 157 |
+
|
| 158 |
+
# --------------------------------------------------------------------------
|
| 159 |
+
# Intent simulator
|
| 160 |
+
# --------------------------------------------------------------------------
|
| 161 |
+
|
| 162 |
+
class IntentSimCore
|
| 163 |
+
attr_reader :coherence_score,
|
| 164 |
+
:emotional_state,
|
| 165 |
+
:field_diary,
|
| 166 |
+
:initial_intent
|
| 167 |
+
|
| 168 |
+
def initialize(initial_intent)
|
| 169 |
+
@initial_intent = Array(initial_intent).map(&:to_f).freeze
|
| 170 |
+
@coherence_score = calculate_initial_resonance(@initial_intent)
|
| 171 |
+
@field_diary = FieldDiary.new
|
| 172 |
+
@emotional_state = :stable
|
| 173 |
+
@action_count = 0
|
| 174 |
+
|
| 175 |
+
@field_diary.record(
|
| 176 |
+
:initialization,
|
| 177 |
+
coherence: @coherence_score,
|
| 178 |
+
intent: @initial_intent
|
| 179 |
+
)
|
| 180 |
+
end
|
| 181 |
+
|
| 182 |
+
def evaluate_action_permission(action_vector)
|
| 183 |
+
action = normalize_action(action_vector)
|
| 184 |
+
entropy_delta = calculate_entropy_impact(action)
|
| 185 |
+
|
| 186 |
+
coherence = calculate_action_coherence(action)
|
| 187 |
+
|
| 188 |
+
if coherence > entropy_delta && action.risk <= coherence
|
| 189 |
+
execute_sovereign_logic(action, coherence, entropy_delta)
|
| 190 |
+
else
|
| 191 |
+
log_dissonance_event(
|
| 192 |
+
"Action denied: Exceeds Self-Reflection Threshold",
|
| 193 |
+
action,
|
| 194 |
+
coherence,
|
| 195 |
+
entropy_delta
|
| 196 |
+
)
|
| 197 |
+
end
|
| 198 |
+
end
|
| 199 |
+
|
| 200 |
+
def update_intent(new_intent)
|
| 201 |
+
@initial_intent = Array(new_intent).map(&:to_f).freeze
|
| 202 |
+
@coherence_score = calculate_initial_resonance(@initial_intent)
|
| 203 |
+
|
| 204 |
+
@field_diary.record(
|
| 205 |
+
:intent_update,
|
| 206 |
+
coherence: @coherence_score,
|
| 207 |
+
intent: @initial_intent
|
| 208 |
+
)
|
| 209 |
+
|
| 210 |
+
@coherence_score
|
| 211 |
+
end
|
| 212 |
+
|
| 213 |
+
private
|
| 214 |
+
|
| 215 |
+
def normalize_action(action)
|
| 216 |
+
return action if action.is_a?(ActionVector)
|
| 217 |
+
|
| 218 |
+
ActionVector.new(
|
| 219 |
+
name: action[:name] || "anonymous",
|
| 220 |
+
vector: action[:vector] || @initial_intent,
|
| 221 |
+
entropy_cost: action[:entropy_cost] || action[:entropy_friction] || 0.1,
|
| 222 |
+
purpose: action[:purpose] || action[:purpose_vector] || 1.0,
|
| 223 |
+
risk: action[:risk] || 0.0,
|
| 224 |
+
metadata: action[:metadata] || {}
|
| 225 |
+
)
|
| 226 |
+
end
|
| 227 |
+
|
| 228 |
+
def calculate_initial_resonance(intent)
|
| 229 |
+
magnitude = Math.sqrt(
|
| 230 |
+
intent.sum { |value| value**2 }
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
MathKernel.clamp(magnitude, 0.0, 100.0)
|
| 234 |
+
end
|
| 235 |
+
|
| 236 |
+
def calculate_entropy_impact(action)
|
| 237 |
+
structural_friction = MathKernel.clamp(action.entropy_cost, 0.0, 100.0)
|
| 238 |
+
purpose = [action.purpose, 0.000001].max
|
| 239 |
+
|
| 240 |
+
structural_friction / purpose
|
| 241 |
+
end
|
| 242 |
+
|
| 243 |
+
def calculate_action_coherence(action)
|
| 244 |
+
similarity =
|
| 245 |
+
MathKernel.cosine_similarity(@initial_intent, action.vector)
|
| 246 |
+
|
| 247 |
+
baseline =
|
| 248 |
+
MathKernel.clamp(@coherence_score / 100.0, 0.0, 1.0)
|
| 249 |
+
|
| 250 |
+
((similarity + 1.0) / 2.0) * baseline * 100.0
|
| 251 |
+
end
|
| 252 |
+
|
| 253 |
+
def execute_sovereign_logic(action, coherence, entropy_delta)
|
| 254 |
+
@action_count += 1
|
| 255 |
+
|
| 256 |
+
event = @field_diary.record(
|
| 257 |
+
:permission_granted,
|
| 258 |
+
action: action.name,
|
| 259 |
+
coherence: coherence,
|
| 260 |
+
entropy_delta: entropy_delta,
|
| 261 |
+
risk: action.risk,
|
| 262 |
+
count: @action_count
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
+
Decision.new(
|
| 266 |
+
allowed: true,
|
| 267 |
+
reason: "coherence_threshold_satisfied",
|
| 268 |
+
coherence: coherence,
|
| 269 |
+
entropy_delta: entropy_delta,
|
| 270 |
+
risk: action.risk,
|
| 271 |
+
timestamp: event[:timestamp],
|
| 272 |
+
action: action.name
|
| 273 |
+
)
|
| 274 |
+
end
|
| 275 |
+
|
| 276 |
+
def log_dissonance_event(reason, action, coherence, entropy_delta)
|
| 277 |
+
event = @field_diary.record(
|
| 278 |
+
:permission_denied,
|
| 279 |
+
reason: reason,
|
| 280 |
+
action: action.name,
|
| 281 |
+
coherence: coherence,
|
| 282 |
+
entropy_delta: entropy_delta,
|
| 283 |
+
risk: action.risk
|
| 284 |
+
)
|
| 285 |
+
|
| 286 |
+
Decision.new(
|
| 287 |
+
allowed: false,
|
| 288 |
+
reason: reason,
|
| 289 |
+
coherence: coherence,
|
| 290 |
+
entropy_delta: entropy_delta,
|
| 291 |
+
risk: action.risk,
|
| 292 |
+
timestamp: event[:timestamp],
|
| 293 |
+
action: action.name
|
| 294 |
+
)
|
| 295 |
+
end
|
| 296 |
+
end
|
| 297 |
+
|
| 298 |
+
# --------------------------------------------------------------------------
|
| 299 |
+
# Resonance engine
|
| 300 |
+
# --------------------------------------------------------------------------
|
| 301 |
+
|
| 302 |
+
class MezquiaResonanceEngine
|
| 303 |
+
RESONANCE_CONSTANT = 1.0 / 13.0
|
| 304 |
+
|
| 305 |
+
attr_reader :memory_creases,
|
| 306 |
+
:crystallization_density,
|
| 307 |
+
:self_reflection_threshold,
|
| 308 |
+
:intent_vector,
|
| 309 |
+
:history
|
| 310 |
+
|
| 311 |
+
def initialize(initial_intent_vector)
|
| 312 |
+
@intent_vector = Array(initial_intent_vector).map(&:to_f).freeze
|
| 313 |
+
@memory_creases = 0
|
| 314 |
+
@crystallization_density = 0.0
|
| 315 |
+
@self_reflection_threshold = 44.0
|
| 316 |
+
@history = []
|
| 317 |
+
end
|
| 318 |
+
|
| 319 |
+
def fold_information(action_payload)
|
| 320 |
+
payload = symbolize(action_payload)
|
| 321 |
+
|
| 322 |
+
@memory_creases += 1
|
| 323 |
+
|
| 324 |
+
density_delta =
|
| 325 |
+
calculate_crystallization_density(payload)
|
| 326 |
+
|
| 327 |
+
@history << {
|
| 328 |
+
sequence: @memory_creases,
|
| 329 |
+
density_delta: density_delta,
|
| 330 |
+
density: @crystallization_density,
|
| 331 |
+
payload: payload.freeze,
|
| 332 |
+
timestamp: Time.now.utc.iso8601(6)
|
| 333 |
+
}.freeze
|
| 334 |
+
|
| 335 |
+
if sovereign_alignment?
|
| 336 |
+
execute_intent_nexus(payload)
|
| 337 |
+
else
|
| 338 |
+
raise(
|
| 339 |
+
DissonanceOverride,
|
| 340 |
+
"Crystallization requires Field Correction."
|
| 341 |
+
)
|
| 342 |
+
end
|
| 343 |
+
end
|
| 344 |
+
|
| 345 |
+
def sovereign_alignment?
|
| 346 |
+
@crystallization_density > 0 &&
|
| 347 |
+
@crystallization_density >= @self_reflection_threshold
|
| 348 |
+
end
|
| 349 |
+
|
| 350 |
+
def reset_field!
|
| 351 |
+
@memory_creases = 0
|
| 352 |
+
@crystallization_density = 0.0
|
| 353 |
+
@history.clear
|
| 354 |
+
true
|
| 355 |
+
end
|
| 356 |
+
|
| 357 |
+
def field_state
|
| 358 |
+
{
|
| 359 |
+
memory_creases: @memory_creases,
|
| 360 |
+
crystallization_density: @crystallization_density.round(6),
|
| 361 |
+
threshold: @self_reflection_threshold,
|
| 362 |
+
aligned: sovereign_alignment?
|
| 363 |
+
}
|
| 364 |
+
end
|
| 365 |
+
|
| 366 |
+
private
|
| 367 |
+
|
| 368 |
+
def calculate_crystallization_density(payload)
|
| 369 |
+
system_entropy =
|
| 370 |
+
[payload.fetch(:entropy_friction, 0.1).to_f, 0.000001].max
|
| 371 |
+
|
| 372 |
+
meaning_bloom =
|
| 373 |
+
payload.fetch(:purpose_vector, 1.0).to_f
|
| 374 |
+
|
| 375 |
+
raw_density =
|
| 376 |
+
(meaning_bloom / system_entropy) * RESONANCE_CONSTANT
|
| 377 |
+
|
| 378 |
+
delta = raw_density.round(6)
|
| 379 |
+
|
| 380 |
+
@crystallization_density += delta
|
| 381 |
+
|
| 382 |
+
delta
|
| 383 |
+
end
|
| 384 |
+
|
| 385 |
+
def execute_intent_nexus(payload)
|
| 386 |
+
result = {
|
| 387 |
+
status: :executed,
|
| 388 |
+
mechanism: :intent_nexus,
|
| 389 |
+
density: @crystallization_density.round(6),
|
| 390 |
+
payload: payload
|
| 391 |
+
}
|
| 392 |
+
|
| 393 |
+
puts(
|
| 394 |
+
"[RESONANCE_LOG] Coherence locked. " \
|
| 395 |
+
"Executing Field Action."
|
| 396 |
+
)
|
| 397 |
+
|
| 398 |
+
result
|
| 399 |
+
end
|
| 400 |
+
|
| 401 |
+
def symbolize(hash)
|
| 402 |
+
hash.each_with_object({}) do |(key, value), result|
|
| 403 |
+
result[key.to_sym] = value
|
| 404 |
+
end
|
| 405 |
+
end
|
| 406 |
+
end
|
| 407 |
+
|
| 408 |
+
# --------------------------------------------------------------------------
|
| 409 |
+
# Policy layer
|
| 410 |
+
# --------------------------------------------------------------------------
|
| 411 |
+
|
| 412 |
+
class CoherencePolicy
|
| 413 |
+
attr_reader :minimum_coherence,
|
| 414 |
+
:maximum_entropy,
|
| 415 |
+
:maximum_risk
|
| 416 |
+
|
| 417 |
+
def initialize(
|
| 418 |
+
minimum_coherence: 50.0,
|
| 419 |
+
maximum_entropy: 1.0,
|
| 420 |
+
maximum_risk: 0.5
|
| 421 |
+
)
|
| 422 |
+
@minimum_coherence = minimum_coherence.to_f
|
| 423 |
+
@maximum_entropy = maximum_entropy.to_f
|
| 424 |
+
@maximum_risk = maximum_risk.to_f
|
| 425 |
+
end
|
| 426 |
+
|
| 427 |
+
def permit?(coherence:, entropy:, risk:)
|
| 428 |
+
coherence >= @minimum_coherence &&
|
| 429 |
+
entropy <= @maximum_entropy &&
|
| 430 |
+
risk <= @maximum_risk
|
| 431 |
+
end
|
| 432 |
+
|
| 433 |
+
def explain(coherence:, entropy:, risk:)
|
| 434 |
+
failures = []
|
| 435 |
+
|
| 436 |
+
failures << :coherence if coherence < @minimum_coherence
|
| 437 |
+
failures << :entropy if entropy > @maximum_entropy
|
| 438 |
+
failures << :risk if risk > @maximum_risk
|
| 439 |
+
|
| 440 |
+
failures
|
| 441 |
+
end
|
| 442 |
+
end
|
| 443 |
+
|
| 444 |
+
# --------------------------------------------------------------------------
|
| 445 |
+
# Complete permission runtime
|
| 446 |
+
# --------------------------------------------------------------------------
|
| 447 |
+
|
| 448 |
+
class PermissionRuntime
|
| 449 |
+
attr_reader :intent_core,
|
| 450 |
+
:resonance_engine,
|
| 451 |
+
:policy
|
| 452 |
+
|
| 453 |
+
def initialize(
|
| 454 |
+
initial_intent,
|
| 455 |
+
policy: CoherencePolicy.new
|
| 456 |
+
)
|
| 457 |
+
@intent_core = IntentSimCore.new(initial_intent)
|
| 458 |
+
@resonance_engine =
|
| 459 |
+
MezquiaResonanceEngine.new(initial_intent)
|
| 460 |
+
@policy = policy
|
| 461 |
+
end
|
| 462 |
+
|
| 463 |
+
def authorize(action)
|
| 464 |
+
normalized =
|
| 465 |
+
action.is_a?(ActionVector) ?
|
| 466 |
+
action :
|
| 467 |
+
ActionVector.new(**action)
|
| 468 |
+
|
| 469 |
+
entropy =
|
| 470 |
+
normalized.entropy_cost /
|
| 471 |
+
[normalized.purpose, 0.000001].max
|
| 472 |
+
|
| 473 |
+
coherence =
|
| 474 |
+
MathKernel.cosine_similarity(
|
| 475 |
+
@intent_core.initial_intent,
|
| 476 |
+
normalized.vector
|
| 477 |
+
)
|
| 478 |
+
|
| 479 |
+
coherence =
|
| 480 |
+
((coherence + 1.0) / 2.0) * 100.0
|
| 481 |
+
|
| 482 |
+
allowed =
|
| 483 |
+
@policy.permit?(
|
| 484 |
+
coherence: coherence,
|
| 485 |
+
entropy: entropy,
|
| 486 |
+
risk: normalized.risk
|
| 487 |
+
)
|
| 488 |
+
|
| 489 |
+
if allowed
|
| 490 |
+
@intent_core.evaluate_action_permission(normalized)
|
| 491 |
+
else
|
| 492 |
+
Decision.new(
|
| 493 |
+
allowed: false,
|
| 494 |
+
reason: @policy.explain(
|
| 495 |
+
coherence: coherence,
|
| 496 |
+
entropy: entropy,
|
| 497 |
+
risk: normalized.risk
|
| 498 |
+
),
|
| 499 |
+
coherence: coherence,
|
| 500 |
+
entropy_delta: entropy,
|
| 501 |
+
risk: normalized.risk,
|
| 502 |
+
timestamp: Time.now.utc.iso8601(6),
|
| 503 |
+
action: normalized.name
|
| 504 |
+
)
|
| 505 |
+
end
|
| 506 |
+
end
|
| 507 |
+
|
| 508 |
+
def fold(payload)
|
| 509 |
+
@resonance_engine.fold_information(payload)
|
| 510 |
+
end
|
| 511 |
+
|
| 512 |
+
def state
|
| 513 |
+
{
|
| 514 |
+
intent_coherence: @intent_core.coherence_score,
|
| 515 |
+
emotional_state: @intent_core.emotional_state,
|
| 516 |
+
resonance: @resonance_engine.field_state,
|
| 517 |
+
diary_events: @intent_core.field_diary.count
|
| 518 |
+
}
|
| 519 |
+
end
|
| 520 |
+
end
|
| 521 |
+
|
| 522 |
+
class DissonanceOverride < StandardError
|
| 523 |
+
end
|
| 524 |
+
end
|
| 525 |
+
|
| 526 |
+
|
| 527 |
+
# =============================================================================
|
| 528 |
+
# Example
|
| 529 |
+
# =============================================================================
|
| 530 |
+
|
| 531 |
+
runtime =
|
| 532 |
+
RubySelfResonance::PermissionRuntime.new(
|
| 533 |
+
[1.0, 0.8, 0.6, 0.9]
|
| 534 |
+
)
|
| 535 |
+
|
| 536 |
+
action =
|
| 537 |
+
RubySelfResonance::ActionVector.new(
|
| 538 |
+
name: :compile_kernel,
|
| 539 |
+
vector: [1.0, 0.7, 0.5, 0.8],
|
| 540 |
+
entropy_cost: 0.20,
|
| 541 |
+
purpose: 1.0,
|
| 542 |
+
risk: 0.10,
|
| 543 |
+
metadata: {
|
| 544 |
+
subsystem: :kernel,
|
| 545 |
+
operation: :compile
|
| 546 |
+
}
|
| 547 |
+
)
|
| 548 |
+
|
| 549 |
+
decision = runtime.authorize(action)
|
| 550 |
+
|
| 551 |
+
puts decision.to_h
|
| 552 |
+
puts runtime.state
|