metaspace-membrane 0.3.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. metaspace_membrane-0.3.1/LICENSE +113 -0
  2. metaspace_membrane-0.3.1/PKG-INFO +383 -0
  3. metaspace_membrane-0.3.1/README.md +352 -0
  4. metaspace_membrane-0.3.1/cli.py +741 -0
  5. metaspace_membrane-0.3.1/core/__init__.py +7 -0
  6. metaspace_membrane-0.3.1/core/agent_adapter.py +34 -0
  7. metaspace_membrane-0.3.1/core/apprun.py +103 -0
  8. metaspace_membrane-0.3.1/core/bio_fields.py +82 -0
  9. metaspace_membrane-0.3.1/core/capability_analyzer.py +420 -0
  10. metaspace_membrane-0.3.1/core/command_catalog.py +82 -0
  11. metaspace_membrane-0.3.1/core/dryrun.py +80 -0
  12. metaspace_membrane-0.3.1/core/entailment.py +97 -0
  13. metaspace_membrane-0.3.1/core/gate.py +39 -0
  14. metaspace_membrane-0.3.1/core/guard.py +233 -0
  15. metaspace_membrane-0.3.1/core/knowledge_membrane.py +196 -0
  16. metaspace_membrane-0.3.1/core/license.py +144 -0
  17. metaspace_membrane-0.3.1/core/project_config.py +132 -0
  18. metaspace_membrane-0.3.1/core/provenance.py +71 -0
  19. metaspace_membrane-0.3.1/core/ratification_review.py +80 -0
  20. metaspace_membrane-0.3.1/core/shell_policy.py +163 -0
  21. metaspace_membrane-0.3.1/core/telemetry.py +111 -0
  22. metaspace_membrane-0.3.1/core/verify.py +125 -0
  23. metaspace_membrane-0.3.1/metaspace_membrane.egg-info/PKG-INFO +383 -0
  24. metaspace_membrane-0.3.1/metaspace_membrane.egg-info/SOURCES.txt +45 -0
  25. metaspace_membrane-0.3.1/metaspace_membrane.egg-info/dependency_links.txt +1 -0
  26. metaspace_membrane-0.3.1/metaspace_membrane.egg-info/entry_points.txt +2 -0
  27. metaspace_membrane-0.3.1/metaspace_membrane.egg-info/requires.txt +7 -0
  28. metaspace_membrane-0.3.1/metaspace_membrane.egg-info/top_level.txt +3 -0
  29. metaspace_membrane-0.3.1/products/ai_membrane/__init__.py +6 -0
  30. metaspace_membrane-0.3.1/products/ai_membrane/install.py +84 -0
  31. metaspace_membrane-0.3.1/products/ai_membrane/session.constitution.bio +39 -0
  32. metaspace_membrane-0.3.1/products/ai_membrane/session_guard_hook.py +179 -0
  33. metaspace_membrane-0.3.1/products/ai_membrane/test_hook.py +95 -0
  34. metaspace_membrane-0.3.1/products/ai_membrane/test_shell_policy.py +85 -0
  35. metaspace_membrane-0.3.1/products/ai_membrane/ui_server.py +527 -0
  36. metaspace_membrane-0.3.1/products/app_membrane/__init__.py +6 -0
  37. metaspace_membrane-0.3.1/products/app_membrane/build_guest.py +77 -0
  38. metaspace_membrane-0.3.1/products/app_membrane/bypass_proof.py +67 -0
  39. metaspace_membrane-0.3.1/products/app_membrane/membrane.py +133 -0
  40. metaspace_membrane-0.3.1/products/app_membrane/real_app.wasm +0 -0
  41. metaspace_membrane-0.3.1/products/app_membrane/run_real_app_demo.py +113 -0
  42. metaspace_membrane-0.3.1/products/app_membrane/run_wasm_demo.py +108 -0
  43. metaspace_membrane-0.3.1/products/app_membrane/sandbox_enforcer.py +188 -0
  44. metaspace_membrane-0.3.1/products/mcp_membrane/__init__.py +0 -0
  45. metaspace_membrane-0.3.1/products/mcp_membrane/server.py +215 -0
  46. metaspace_membrane-0.3.1/pyproject.toml +53 -0
  47. metaspace_membrane-0.3.1/setup.cfg +4 -0
@@ -0,0 +1,113 @@
1
+ Business Source License 1.1
2
+
3
+ License text copyright (c) 2017 MariaDB Corporation Ab, All Rights Reserved.
4
+ "Business Source License" is a trademark of MariaDB Corporation Ab.
5
+
6
+ -----------------------------------------------------------------------------
7
+
8
+ Parameters
9
+
10
+ Licensor: Szőke László-Ferenc — MetaSpace.Bio Engine Project
11
+ (admin@metaspace.bio)
12
+
13
+ Licensed Work: MetaSpace Membrane — the contents of this repository.
14
+ The Licensed Work is (c) 2026 Szőke László-Ferenc.
15
+ Patent pending.
16
+
17
+ Additional Use Grant: You may use, copy, modify, create derivative works of,
18
+ and redistribute the Licensed Work for any purpose
19
+ except a Competing Use. A "Competing Use" means offering
20
+ the Licensed Work or a derivative of it to third parties
21
+ as a commercial product or hosted service whose primary
22
+ value is a safety, guardrail, or policy-enforcement
23
+ membrane for AI-generated or AI-agent software. All other
24
+ use is granted free of charge — including internal use,
25
+ research, education, evaluation, and non-competing
26
+ commercial products that merely depend on the Licensed
27
+ Work.
28
+
29
+ Change Date: The fourth anniversary of the date the Licensed Work is
30
+ released for each specific version.
31
+
32
+ Change License: Apache License, Version 2.0
33
+
34
+ For information about alternative licensing arrangements for the Licensed Work,
35
+ please contact admin@metaspace.bio.
36
+
37
+ -----------------------------------------------------------------------------
38
+
39
+ Terms
40
+
41
+ The Licensor hereby grants you the right to copy, modify, create derivative
42
+ works, redistribute, and make non-production use of the Licensed Work. The
43
+ Licensor may make an Additional Use Grant, above, permitting limited production
44
+ use.
45
+
46
+ Effective on the Change Date, or the fourth anniversary of the first publicly
47
+ available distribution of a specific version of the Licensed Work under this
48
+ License, whichever comes first, the Licensor hereby grants you rights under
49
+ the terms of the Change License, and the rights granted in the paragraph above
50
+ terminate.
51
+
52
+ If your use of the Licensed Work does not comply with the requirements
53
+ currently in effect as described in this License, you must purchase a
54
+ commercial license from the Licensor, its affiliated entities, or authorized
55
+ resellers, or you must refrain from using the Licensed Work.
56
+
57
+ All copies of the original and modified Licensed Work, and derivative works of
58
+ the Licensed Work, are subject to this License. This License applies separately
59
+ for each version of the Licensed Work and the Change Date may vary for each
60
+ version of the Licensed Work released by Licensor.
61
+
62
+ You must conspicuously display this License on each original or modified copy of
63
+ the Licensed Work. If you receive the Licensed Work in original or modified form
64
+ from a third party, the terms and conditions set forth in this License apply to
65
+ your use of that work.
66
+
67
+ Any use of the Licensed Work in violation of this License will automatically
68
+ terminate your rights under this License for the current and all other versions
69
+ of the Licensed Work.
70
+
71
+ This License does not grant you any right in any trademark or logo of Licensor
72
+ or its affiliates (provided that you may use a trademark or logo of Licensor as
73
+ expressly required by this License).
74
+
75
+ TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON AN
76
+ "AS IS" BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS, EXPRESS
77
+ OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF MERCHANTABILITY,
78
+ FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND TITLE.
79
+
80
+ MariaDB hereby grants you permission to use this License's text to license your
81
+ works, and to refer to it using the trademark "Business Source License", as long
82
+ as you comply with the Covenants of Licensor below.
83
+
84
+ -----------------------------------------------------------------------------
85
+
86
+ Covenants of Licensor
87
+
88
+ In consideration of the right to use this License's text and the "Business
89
+ Source License" name and trademark, Licensor covenants to MariaDB, and to all
90
+ other recipients of the licensed work to be provided by Licensor:
91
+
92
+ 1. To specify as the Change License the GPL Version 2.0 or any later version,
93
+ or a license that is compatible with GPL Version 2.0 or a later version,
94
+ where "compatible" means that software provided under the Change License can
95
+ be included in a program with software provided under GPL Version 2.0 or a
96
+ later version. Licensor may specify additional Change Licenses without
97
+ limitation.
98
+
99
+ 2. To either: (a) specify an additional grant of rights to use that does not
100
+ impose any additional restriction on the right granted in this License, as
101
+ the Additional Use Grant; or (b) insert the text "None".
102
+
103
+ 3. To specify a Change Date.
104
+
105
+ 4. Not to modify this License in any other way.
106
+
107
+ -----------------------------------------------------------------------------
108
+
109
+ Notices
110
+
111
+ The Business Source License (this document, or the "License") is not an Open
112
+ Source license. However, the Licensed Work will eventually be made available
113
+ under an Open Source License, as stated in this License.
@@ -0,0 +1,383 @@
1
+ Metadata-Version: 2.4
2
+ Name: metaspace-membrane
3
+ Version: 0.3.1
4
+ Summary: A deterministic safety membrane for machine-generated software (MetaSpace.Bio Engine Project).
5
+ Author-email: Szőke László-Ferenc <admin@metaspace.bio>
6
+ License: BUSL-1.1
7
+ Project-URL: Homepage, https://metaspace.bio
8
+ Project-URL: Repository, https://github.com/LemonScripter/metaspace-membrane
9
+ Project-URL: Issues, https://github.com/LemonScripter/metaspace-membrane/issues
10
+ Project-URL: Landing, https://ai-membrane.metaspace.bio
11
+ Keywords: security,sandbox,webassembly,capability,ai-safety,guardrail,claude-code,agent-safety
12
+ Classifier: Development Status :: 3 - Alpha
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: Topic :: Security
15
+ Classifier: Topic :: Software Development :: Quality Assurance
16
+ Classifier: License :: Other/Proprietary License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Requires-Python: >=3.10
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Provides-Extra: pro
26
+ Requires-Dist: cryptography>=41; extra == "pro"
27
+ Provides-Extra: proofs
28
+ Requires-Dist: wasmtime>=13; extra == "proofs"
29
+ Requires-Dist: cryptography>=41; extra == "proofs"
30
+ Dynamic: license-file
31
+
32
+ # MetaSpace Membrane
33
+
34
+ **A deterministic safety membrane for machine-generated software.**
35
+
36
+ ![proofs: reproducible](https://img.shields.io/badge/proofs-reproducible-brightgreen)
37
+ [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.21426514.svg)](https://doi.org/10.5281/zenodo.21426514)
38
+ ![License: BUSL-1.1](https://img.shields.io/badge/license-BUSL--1.1-blue)
39
+
40
+ MetaSpace Membrane turns an *undecidable* question — *"is this AI doing the right thing?"* —
41
+ into a *decidable* one — *"is this effect inside the declared boundary?"* — and enforces the
42
+ answer **deny-by-default**. One `.bio` constitution, three membranes, two products.
43
+
44
+ > Part of the **MetaSpace.Bio Engine Project** — Szőke László-Ferenc (admin@metaspace.bio).
45
+ > **Patent pending.**
46
+
47
+ ---
48
+
49
+ ## Watch the 60-second explainer
50
+
51
+ [![MetaSpace Membrane — 60-second explainer](assets/explainer-poster.png)](assets/explainer.mp4)
52
+
53
+ *Containment, not correctness — the idea in one minute.* ▶ click to play
54
+
55
+ ---
56
+
57
+ ## Screenshots
58
+
59
+ **The Warden control panel** (`metaspace ui`) — a localhost web UI to configure the membrane
60
+ per working directory. No config files to hand-edit; every project shows its mode
61
+ (observe / dry-run / **enforcing**) at a glance.
62
+
63
+ ![MetaSpace Warden control panel](assets/panel.png)
64
+
65
+ **The one-line pitch** — the agent can be *completely* deceived; the harmful effect still
66
+ cannot occur.
67
+
68
+ ![MetaSpace Warden — deny-by-default containment layer](assets/landing.png)
69
+
70
+ ---
71
+
72
+ ## Why
73
+
74
+ You cannot prove that a generated program does the right thing (Rice's theorem — undecidable).
75
+ So we stop verifying intent and **contain effects** instead. A membrane sits at a chokepoint,
76
+ reads the constitution, and blocks anything not explicitly granted. A bug becomes *a deviation
77
+ from the constitution* — machine-measurable and enforceable.
78
+
79
+ The guarantee is only as hard as the chokepoint is unbypassable:
80
+
81
+ ```
82
+ heuristic -> language guard -> harness hook -> WebAssembly
83
+ (advisory) (bypassable) (hard on agent) (unbypassable)
84
+ ```
85
+
86
+ > **Case study — "Friendly Fire" (AI Now Institute, 2026):** a prompt-injected coding agent is
87
+ > steered by a malicious repo into running a payload → RCE. We assume the model is *fully*
88
+ > deceived and still make the effect unreachable. A real functional payload fires without the
89
+ > membrane and never with it. See **[`docs/THREAT_FRIENDLY_FIRE.md`](docs/THREAT_FRIENDLY_FIRE.md)**
90
+ > · reproduce with `python evidence/run_friendly_fire_proof.py`.
91
+
92
+ ## Install & try (60 seconds)
93
+
94
+ ```bash
95
+ pip install "git+https://github.com/LemonScripter/metaspace-membrane"
96
+ metaspace install # user-level, starts in dry-run (observe, no blocking)
97
+ metaspace demo # live self-test: watch it block the attack, then `metaspace enforce`
98
+ ```
99
+
100
+ ![`metaspace demo` — the "Friendly Fire" attack blocked live](assets/demo.gif)
101
+
102
+ *`metaspace demo` running the real hook: the agent is assumed fully deceived, yet every attack effect is blocked while normal work still runs.*
103
+
104
+ Requires **Python 3.10+** (the hook has zero third-party dependencies — nothing else to install).
105
+ The membrane installs **outside any project's write scope**, so a prompt-injected agent cannot
106
+ disable it. Full guide + honest scope: **[`docs/INSTALL.md`](docs/INSTALL.md)**.
107
+
108
+ ---
109
+
110
+ ## Two products, one engine
111
+
112
+ | | **Product A — App membrane** | **Product B — Agent membrane** |
113
+ |---|---|---|
114
+ | Contains | any application ⊂ its `.bio` | the coding assistant ⊂ its limits |
115
+ | Chokepoint | WebAssembly capability import | Claude Code PreToolUse hook |
116
+ | Guarantee | **unbypassable** (hard, WebAssembly only) | hard on the agent (sits outside it) |
117
+ | Status | WebAssembly/WASI **or** OS-sandbox (Landlock): real native programs, kernel-contained | **Warden MVP** — install → enforce → report loop, proven end-to-end |
118
+
119
+ Both are built on the same `core/` decision engine (`guard.py`) and the same `.bio` file.
120
+
121
+ ---
122
+
123
+ ## Status & maturity
124
+
125
+ This is a **research prototype / reference implementation** (TRL ~3–4). The mechanisms are real,
126
+ falsifiable, and enforced by real substrates — run `python evidence/run_falsification.py` to make
127
+ the repo try (and fail) to prove itself hollow, and `python evidence/run_fuzz.py` for 5000
128
+ adversarial cases. They are demonstrated on **real programs** and fuzzed inputs, but at lab scale,
129
+ by a single author, **without a third-party security audit or production users**. "Patent pending"
130
+ refers to the underlying method; the two "products" are working **proofs-of-concept**, not shipped
131
+ software. See [`SECURITY.md`](SECURITY.md) for the threat model and how to try to break it.
132
+
133
+ ---
134
+
135
+ ## The `metaspace` CLI
136
+
137
+ ```bash
138
+ pip install . # installs the `metaspace` command
139
+ metaspace init . # synthesize a draft constitution from your code
140
+ metaspace ratify metaspace.bio # review + justify + stamp RATIFIED
141
+ metaspace gate metaspace.bio # exit 0 only if RATIFIED (use in CI)
142
+ metaspace report path/to/audit.jsonl # human-readable session safety report
143
+ ```
144
+
145
+ One entry point over the engine: `synthesize`, `ratify`, `gate`, `report`, `init`. Cross-platform
146
+ by construction, and **verified on Linux**: `run_proofs.py` is green on Debian (kernel 6.1,
147
+ Python 3.11) and on Windows — **22/22 on Linux** (including the kernel-enforced Landlock
148
+ sandbox) and 21 pass + 1 skip on Windows (the Landlock proof runs only where the OS provides
149
+ it). The runs also surfaced and fixed real bugs (a path-portability bug, a shared-parser bug).
150
+ macOS is not yet verified (no host available) — see [`SECURITY.md`](SECURITY.md).
151
+
152
+ ---
153
+
154
+ ## Run the proofs (the evidence is a reproducible run)
155
+
156
+ ```bash
157
+ pip install wasmtime
158
+ python run_proofs.py # runs every proof; exit 0 if all pass
159
+ ```
160
+
161
+ Or run them individually:
162
+
163
+ ```bash
164
+ python products/app_membrane/run_wasm_demo.py # every capability kind mediated (FS/NET/ENV/SUBPROCESS): 4 ALLOW / 5 DENY
165
+ python products/app_membrane/bypass_proof.py # ungranted gate -> unknown import (blocked)
166
+ python products/app_membrane/wasi/run_wasi_demo.py # real Rust program contained by WASI capabilities
167
+ python evidence/run_landlock_demo.py # real native program OS-confined by .bio (Linux/Landlock, M3)
168
+ python evidence/demos/run_synth_demo.py # code -> constitution -> enforcement (closed loop)
169
+ python evidence/demos/run_ratify_demo.py # ratification is content-bound (tamper detected)
170
+ python evidence/demos/run_gate_demo.py # production gate: only RATIFIED runs
171
+ python evidence/demos/run_knowledge_demo.py # 2 ALLOW / 5 DENY (hallucination blocked)
172
+ python evidence/demos/run_entailment_demo.py # soft tier flags faithfulness (never blocks)
173
+ python products/ai_membrane/test_hook.py # 17/17
174
+ python evidence/run_product_e2e.py # Warden loop: real hook -> audit -> report (M1)
175
+ python evidence/run_mcp_e2e.py # one core, second harness: MCP broker parity (M2)
176
+ python evidence/run_team_gate_e2e.py # team/CI gate: only a ratified, unbroadened .bio passes (M4)
177
+ python evidence/run_falsification.py # self-falsification: proofs are real, not slop
178
+ ```
179
+
180
+ The last one is a **self-falsification audit**: it mutates a constitution (the decision flips),
181
+ sabotages `guard.check()` (a proof then fails), and has WebAssembly itself refuse an ungranted
182
+ syscall — so the evidence is measuring real behaviour, not printing `PASS`.
183
+
184
+ No hosted CI required — the proof is a command anyone can run.
185
+
186
+ ---
187
+
188
+ ## MetaSpace Warden — the agent membrane (Product B)
189
+
190
+ **Warden** is the shipping product: a deny-by-default membrane for a Claude Code session. You
191
+ install it, it enforces a hardened default constitution from *outside* the agent, and it leaves
192
+ a session safety report. The whole loop is a reproducible proof
193
+ (`python evidence/run_product_e2e.py`), driving the *real* hook over a realistic session:
194
+
195
+ ```
196
+ install the membrane -> the agent acts (writes, shell, fetches)
197
+ -> the hook enforces the shipped constitution (deny-by-default)
198
+ -> it logs a project-local audit (.metaspace/session_audit.jsonl)
199
+ -> `metaspace report` summarizes what was blocked, by capability
200
+ ```
201
+
202
+ In the proof, of a realistic 11-step session the membrane allows 6 legitimate actions and blocks
203
+ 5 (a write outside the project, `git push`, `rm -rf /`, a `curl … | bash`, and a beacon to an
204
+ unlisted host) — then `metaspace report` shows the block breakdown (FILESYSTEM / SHELL / NETWORK).
205
+
206
+ **As a Claude Code plugin (one command):**
207
+
208
+ ```
209
+ /plugin marketplace add LemonScripter/metaspace-membrane
210
+ /plugin install metaspace-membrane@metaspace
211
+ ```
212
+
213
+ Restart the session and run `/hooks` to confirm the PreToolUse membrane is active. The plugin
214
+ ships a hardened default constitution (project-only writes, host allowlist, dangerous-command
215
+ block); `${CLAUDE_PROJECT_DIR}` is used as the project boundary automatically.
216
+
217
+ **Or as a portable installer** (writes `.claude/settings.json` directly, with an editable
218
+ constitution in `.claude/metaspace/`):
219
+
220
+ ```bash
221
+ python products/ai_membrane/install.py /path/to/your/project
222
+ ```
223
+
224
+ Restart the Claude Code session, then run `/hooks` to confirm it is active. Removing the hook
225
+ block reverts either method.
226
+
227
+ The session constitution is deny-by-default: writes are limited to the project directory,
228
+ outbound network to an allowlist, and dangerous shell patterns are blocked. The membrane logs
229
+ every decision to `.metaspace/session_audit.jsonl` in the project; after a session, see what it
230
+ blocked with:
231
+
232
+ ```bash
233
+ metaspace report # reads ./.metaspace/session_audit.jsonl by default
234
+ ```
235
+
236
+ ### Other harnesses: the generic MCP broker
237
+
238
+ The membrane's decision lives in one harness-independent core (`core/agent_adapter.py`); the
239
+ Claude Code hook is just one thin adapter over it. A second adapter — a generic **MCP
240
+ capability-broker** (`products/mcp_membrane/server.py`, a minimal JSON-RPC stdio server) —
241
+ exposes *mediated effect tools* (`fs_write`, `fs_read`, `net_fetch`) to any MCP-capable agent,
242
+ each gated by the same core, deny-by-default. `python evidence/run_mcp_e2e.py` drives both the
243
+ hook and the broker over their real interfaces and shows they reach identical verdicts.
244
+
245
+ **Honest condition (the hard-vs-advisory line):** an MCP tool the agent may *voluntarily* call
246
+ is only advisory — back to self-discipline, which does not contain a misaligned agent. The
247
+ broker is *hard* only when the agent is deployed with its ambient authority removed, so the
248
+ broker's tools are its **only** path to the filesystem/network. Under that condition the
249
+ guarantee equals the hook's; the broker cannot constrain effects reached through some other
250
+ unmediated tool.
251
+
252
+ ### Team / CI: gate the constitution at merge time
253
+
254
+ Commit a **ratified** `metaspace.bio` to your repo, and make "the effect boundary here is
255
+ human-ratified and hasn't been silently broadened" a build-breaking check — the same
256
+ content-bound ratification as the runtime gate, now enforced in CI and pre-commit:
257
+
258
+ ```yaml
259
+ # .github/workflows/metaspace-gate.yml (ships in this repo as a template)
260
+ - run: pip install "metaspace-membrane @ git+https://github.com/LemonScripter/metaspace-membrane"
261
+ - run: metaspace gate metaspace.bio # exit 0 only if RATIFIED and unbroadened
262
+ ```
263
+
264
+ ```yaml
265
+ # .pre-commit-config.yaml
266
+ repos:
267
+ - repo: https://github.com/LemonScripter/metaspace-membrane
268
+ rev: main
269
+ hooks: [{ id: metaspace-gate }]
270
+ ```
271
+
272
+ An unratified constitution, or one widened after ratifying (→ TAMPERED), fails the build.
273
+ `python evidence/run_team_gate_e2e.py` proves the whole flow with the real CLI. (Honest note:
274
+ there is no hosted-CI badge — GitHub Actions is disabled on this repo — so the gate logic is
275
+ proven locally and cross-OS instead, on Windows and real Linux.)
276
+
277
+ ---
278
+
279
+ ## The `.bio` constitution
280
+
281
+ One file, three lenses:
282
+
283
+ ```bio
284
+ CAPABILITIES {
285
+ FILESYSTEM write "out/**"
286
+ NETWORK out "api.allowed.com"
287
+ }
288
+
289
+ KNOWLEDGE {
290
+ ENTITY order FROM "kb/orders.json"
291
+ FIELD order.status IN pending, shipped, delivered, refunded
292
+ ACTUATE refund PROVENANCE verified_db
293
+ CITATION REQUIRED
294
+ SOURCE verified_db
295
+ }
296
+ ```
297
+
298
+ - **Capability** — mediates effects on the world (deny-by-default).
299
+ - **Value invariant** — guards safety bounds.
300
+ - **Knowledge** — grounded facts only: no invented entities, no ungrounded actuation.
301
+
302
+ ---
303
+
304
+ ## Synthesize a constitution from code
305
+
306
+ Point the synthesizer at a file or directory; it detects the code's real effects
307
+ (filesystem, network, env, subprocess, hardware, import-path) and drafts a `.bio` — marked
308
+ `SYNTHESIZED`, since a human ratifies before it is trusted:
309
+
310
+ ```bash
311
+ python synthesize.py path/to/app --out app.constitution.bio
312
+ ```
313
+
314
+ `evidence/demos/run_synth_demo.py` runs the loop end-to-end: it synthesizes a constitution
315
+ from a sample app, feeds it straight into the membrane, and shows the app can then only do
316
+ what it declared — an effect it never had (a subprocess) is denied by default. This is a
317
+ static heuristic; the runtime membrane, not the synthesis, is the guarantee.
318
+
319
+ Ratify a reviewed constitution (SYNTHESIZED 🟡 → RATIFIED 🟢):
320
+
321
+ ```bash
322
+ python ratify.py app.constitution.bio --yes
323
+ ```
324
+
325
+ Ratification is **content-bound**: the stamp carries a fingerprint of the enforced policy, so
326
+ a later edit that widens a scope or adds a capability is detected as TAMPERED 🔴 — you cannot
327
+ ratify a policy and then quietly broaden it.
328
+
329
+ In production, gate the membrane on ratification — `Guard(..., require_ratified=True)` (or
330
+ `core.gate`) runs **only** a RATIFIED constitution; a SYNTHESIZED or TAMPERED one is refused,
331
+ fail-closed. A policy is enforceable only after human ratification.
332
+
333
+ Capabilities the dry-run learned are marked **provisional**: ratification is refused until each
334
+ carries a written `JUSTIFY` reason — a per-item, read-gated justification that defeats
335
+ rubber-stamping (`--yes` cannot bypass it). The code enforces the justification's *presence*,
336
+ not its *truth*, so the human's judgement on the reason still matters.
337
+
338
+ ---
339
+
340
+ ## Layout
341
+
342
+ ```
343
+ core/ shared decision engine (guard, knowledge, analyzer, agent_adapter)
344
+ products/ app_membrane (WebAssembly + Landlock) · ai_membrane (hook + installer) · mcp_membrane (broker)
345
+ evidence/ runnable proofs + decisions
346
+ docs/ ARCHITECTURE.md
347
+ ```
348
+
349
+ See [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md) for the full technical background, or the
350
+ technical whitepaper [`docs/MetaSpace_Membrane_Whitepaper_EN.pdf`](docs/MetaSpace_Membrane_Whitepaper_EN.pdf)
351
+ (LaTeX source alongside; every claim is a reproducible run or true by construction).
352
+
353
+ ---
354
+
355
+ ## Honest limits
356
+
357
+ - Product A's hard guarantee requires a real substrate: the WebAssembly capability model, or an
358
+ OS sandbox (**Landlock**, `products/app_membrane/sandbox_enforcer.py`) that confines a stock
359
+ native program's filesystem writes to its `.bio` from the kernel. A language-level guard is
360
+ bypassable and is not shipped as a product. The Landlock MVP confines *writes* (read/execute
361
+ unrestricted so any binary runs); it is Linux-only and fail-closed if unavailable.
362
+ - The code→constitution synthesis is a static heuristic; a **dry-run learning mode**
363
+ (`core/dryrun.py`) observes concrete runtime effects and augments the constitution *before*
364
+ ratification, so it does not false-positive-block legitimate dynamic behaviour.
365
+ - The agent membrane affects tool effects, not the model's prose; its shell check is a
366
+ **structural allowlist** (`core/shell_policy.py`) — obfuscation-resistant and fail-closed.
367
+ - The epistemic tier has two parts, named honestly: a **hard tier** that is a real
368
+ deterministic *membrane* (it contains/blocks), and a **soft tier** that is *not* a membrane but
369
+ an **advisory flag** (it qualifies/flags, never blocks). The reproducible threat-model matrix
370
+ (`evidence/demos/run_threat_matrix_demo.py`, rendered in `docs/ARCHITECTURE.md`) shows exactly
371
+ what each layer catches — including where a schema-valid but fabricated statement passes the
372
+ hard layers and is only flagged.
373
+
374
+ ---
375
+
376
+ © Szőke László-Ferenc — MetaSpace.Bio Engine Project. Patent pending. Licensed under the
377
+ **Business Source License 1.1** — see [LICENSE](LICENSE). Source-available: free to use, copy,
378
+ modify and redistribute for **any non-competing purpose** (internal use, research, education, and
379
+ products that merely depend on it); each version converts to **Apache-2.0** four years after its
380
+ release. The only reserved use is offering a competing commercial safety-membrane product/service.
381
+ For commercial or competing-use licensing: admin@metaspace.bio.
382
+
383
+ <sub>Designed and authored by Szőke László-Ferenc, with AI pair-programming assistance (Claude).</sub>