Aureon public MCP server from Aureon-OS main cf35ec95 (PR #224)
Browse files- .dockerignore +9 -0
- COVERAGE_PLAN.md +225 -0
- Dockerfile +65 -0
- README.md +199 -0
- __init__.py +11 -0
- __main__.py +4 -0
- alignment_layer.py +387 -0
- alignment_measure.py +119 -0
- body.py +1405 -0
- body_sweep.py +43 -0
- call_sweep.py +359 -0
- call_worker.py +243 -0
- coverage_plan.py +506 -0
- guard_loader.py +181 -0
- http_guard.py +454 -0
- inventory_scan.py +405 -0
- layers.py +594 -0
- measure.py +202 -0
- measurement_stamp.py +81 -0
- more_layers.py +632 -0
- paths.py +50 -0
- pin_blob.py +350 -0
- protocol_measure.py +258 -0
- quiet.py +23 -0
- requirements.txt +7 -0
- server.py +185 -0
- space.py +106 -0
- space_measure.py +240 -0
- stage1_measure.py +119 -0
- stage1_rest.py +531 -0
- stage2_arguments.py +306 -0
- stage2_import_sweep.py +226 -0
- stage2_layer.py +782 -0
- surfaces.py +279 -0
- sweep_guard.py +516 -0
- sweep_layout.py +116 -0
- test-requirements.txt +8 -0
- text.py +26 -0
- tools.py +805 -0
.dockerignore
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
.env.*
|
| 3 |
+
__pycache__/
|
| 4 |
+
*.pyc
|
| 5 |
+
.pytest_cache/
|
| 6 |
+
*.pem
|
| 7 |
+
*.key
|
| 8 |
+
credentials.json
|
| 9 |
+
secrets.json
|
COVERAGE_PLAN.md
ADDED
|
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Public MCP coverage plan
|
| 2 |
+
|
| 3 |
+
Counts are the pinned `docs/mcp/inventory.json`. A public entry point is a public function or method. Reachable means `public_entry_refusal` returns None, so `body_call` will run it. A listed module or class is not an entry point. The sha256 below is `INVENTORY_SHA256`. A different inventory file is not loaded.
|
| 4 |
+
|
| 5 |
+
Inventory sha256: `4bc19ea9b5444a7b8a9abbd3fabf635d083bd25bea6c1b2d6eab2605b4f5716b`
|
| 6 |
+
|
| 7 |
+
Reproduce:
|
| 8 |
+
|
| 9 |
+
```bash
|
| 10 |
+
env -u PYTHONPATH PYTHONPATH=mcp python3.12 -m aureon_public.coverage_plan --check
|
| 11 |
+
bash measured/aureon_public_stage1_run.sh
|
| 12 |
+
bash measured/aureon_public_stage2_sweep.sh
|
| 13 |
+
bash measured/aureon_public_call_sweep.sh
|
| 14 |
+
bash measured/aureon_public_protocol_run.sh
|
| 15 |
+
bash measured/aureon_public_space_run.sh
|
| 16 |
+
env -u PYTHONPATH /tmp/aureon-public-venv/bin/python -m pytest tests/test_aureon_public_mcp.py tests/test_aureon_body.py tests/bio/test_mcp_interior_attribution.py tests/bio/test_mcp_membrane.py tests/bio/test_mcp_transport.py tests/test_aureon_public_alignment.py tests/test_aureon_public_stage1.py tests/test_aureon_public_stage2.py tests/test_aureon_public_protocol.py tests/test_aureon_public_space.py --tb=line
|
| 17 |
+
```
|
| 18 |
+
|
| 19 |
+
That pytest command is the gate. It runs in `/tmp/aureon-public-venv`, the venv `measured/aureon_public_stage1_run.sh` creates (`VENV` overrides the path). The file list is `tests/test_aureon_public_mcp.py`, `tests/test_aureon_body.py`, `tests/bio/test_mcp_interior_attribution.py`, `tests/bio/test_mcp_membrane.py`, `tests/bio/test_mcp_transport.py`, `tests/test_aureon_public_alignment.py`, `tests/test_aureon_public_stage1.py`, `tests/test_aureon_public_stage2.py`, `tests/test_aureon_public_protocol.py`, and `tests/test_aureon_public_space.py`. `tests/test_async_socket_isolation.py` is not in the gate list. It imports `pytest_socket`, and `mcp/aureon_public/test-requirements.txt` does not install that plugin.
|
| 20 |
+
|
| 21 |
+
`--write` rewrites this file from the same function. `measured/aureon_public_stage1_run.sh` installs `mcp/aureon_public/requirements.txt` and `mcp/aureon_public/test-requirements.txt`, then rewrites both `measured/aureon_public_alignment.json` and `measured/aureon_public_stage1.json`. It writes those two files under a temp directory first and copies them into `measured/` only after both stamps have finished. `measurement_stamp` raises `RuntimeError` when `git status --porcelain` is not empty, so the second stamp must not see the first file. `test-requirements.txt` is the test install: pytest, pytest-timeout, flask, pandas, and scipy. It is not the public server runtime. `measured/aureon_public_stage2_sweep.sh` and `measured/aureon_public_call_sweep.sh` copy the checkout with `cp -a` under an ordinary temp parent, place fake `NEXUS-LIVE-FEED-` and `Aureon-Trading--Project-Sero` checkouts beside that copy, block sockets, and rewrite their measured records. Each sweep record names the pin, the `aureon/` tree hash beside that pin, the `aureon_source` kind, and that temp parent. `measured/aureon_public_protocol_run.sh` starts this server over stdio and over Streamable HTTP bound to `127.0.0.1`, with `AUREON_PUBLIC_REQUIRE_PIN=1`. An MCP SDK 1.30.0 client calls `tools/list`, `resources/list`, `prompts/list`, and one `tools/call` (`alignment_consonance_read` with ratio 1.0). The raw pages are `measured/aureon_public_protocol.json`. `measured/aureon_public_space_run.sh` starts `python -m aureon_public.space` with `AUREON_PUBLIC_API_KEY` set and records the same client calling `tools/list` and `tools/call` on `127.0.0.1`. The raw pages are `measured/aureon_public_space.json`. These measured records name `code_commit`, the parent of the commit that contains the record file. A record cannot name the commit that adds the file.
|
| 22 |
+
|
| 23 |
+
Listed symbols: 20083. Public entry points: 4388. Reachable now: 69. Tested: 69. Refused: 4319. The plan on main recorded 879 reachable. An earlier draft head of the stage-1 PR recorded 89 reachable, before the call sweep. Methods open because a constructor is allowlisted: 16. The refused-imports fence is unchanged.
|
| 24 |
+
Reachable means `public_entry_refusal` returns None. Tested means a public tool calls that entry point and `tests/test_aureon_public_stage1.py` or `tests/test_aureon_public_stage2.py` exercises the tool. Refused means a public entry point the server will not run. Plan stages 3 and 4 stay closed. The call sweep calls every entry point that was still reachable, with no arguments, and calls each stage-2 entry point again with the real arguments in `stage2_arguments.py`. `SwarmAgent.update` is also called with the hive fixture named below. It refuses one that opens a connection, starts a process, writes outside the sandbox, or loads queen, miner, swarm_motion, inhouse_ai, ollama_config, or an HTTP client. `get_unified_directive` is refused that way. It does not build the queen and miner bridges.
|
| 25 |
+
|
| 26 |
+
## Stage order
|
| 27 |
+
|
| 28 |
+
The stage is the inventory safety text, not a new scan.
|
| 29 |
+
|
| 30 |
+
1. Deterministic read-only. No key, order, live-fetch, process, or write sentence, and the package is not operator-only.
|
| 31 |
+
2. A process or write sentence, and still no key, order, or live-fetch sentence.
|
| 32 |
+
3. Operator-scoped, with no pure public row and no key, order, or live-fetch sentence.
|
| 33 |
+
4. Last. Any key, order, or live-fetch sentence, plus the refused-imports fence. The fence is `_BLOCKED` and `unified_margin_trader`. This run does not add to it and does not import it.
|
| 34 |
+
|
| 35 |
+
Packages still excluded by `more_layers`: atn, command_centers, conversion, identity, inhouse_ai, miner, monitors, swarm_motion. `generated` left that list because its score model is deterministic and does not fetch. The other exclusions stay.
|
| 36 |
+
|
| 37 |
+
Within a stage, packages are alphabetical. The first package is `alignment`.
|
| 38 |
+
Stage 1 is the deterministic read-only packages. This run opens generated and swarm, after alignment. Organism is stage 4 because its join loads the in-house adapter chain.
|
| 39 |
+
Stage 2 is open. A stage-2 module whose import loads an adapter or an HTTP client, starts a process, or writes outside the sandbox is refused. A stage-2 entry point is refused when the no-argument call or a real-argument call does any of those, or does not finish. `atn` stays excluded. `conversion` has no public function or method and stays excluded.
|
| 40 |
+
|
| 41 |
+
## Counts
|
| 42 |
+
|
| 43 |
+
| Stage | Package | Listed | Public entry points | Reachable now | Tested | Refused |
|
| 44 |
+
| ---: | --- | ---: | ---: | ---: | ---: | ---: |
|
| 45 |
+
| 1 | alignment | 36 | 24 | 11 | 11 | 13 |
|
| 46 |
+
| 1 | generated | 8 | 4 | 4 | 4 | 0 |
|
| 47 |
+
| 1 | swarm | 79 | 41 | 15 | 15 | 26 |
|
| 48 |
+
| 2 | atn | 57 | 28 | 0 | 0 | 28 |
|
| 49 |
+
| 2 | cognition | 44 | 14 | 1 | 1 | 13 |
|
| 50 |
+
| 2 | conversion | 170 | 0 | 0 | 0 | 0 |
|
| 51 |
+
| 2 | decoders | 161 | 80 | 4 | 4 | 76 |
|
| 52 |
+
| 2 | evaluation | 20 | 10 | 6 | 6 | 4 |
|
| 53 |
+
| 2 | gates | 24 | 12 | 3 | 3 | 9 |
|
| 54 |
+
| 2 | observer | 104 | 63 | 24 | 24 | 39 |
|
| 55 |
+
| 2 | s51 | 55 | 24 | 1 | 1 | 23 |
|
| 56 |
+
| 3 | accounting | 50 | 0 | 0 | 0 | 0 |
|
| 57 |
+
| 3 | miner | 15 | 0 | 0 | 0 | 0 |
|
| 58 |
+
| 4 | analytics | 464 | 167 | 0 | 0 | 167 |
|
| 59 |
+
| 4 | appliance | 15 | 7 | 0 | 0 | 7 |
|
| 60 |
+
| 4 | approval | 82 | 42 | 0 | 0 | 42 |
|
| 61 |
+
| 4 | autonomous | 1745 | 0 | 0 | 0 | 0 |
|
| 62 |
+
| 4 | bio | 474 | 206 | 0 | 0 | 206 |
|
| 63 |
+
| 4 | bots | 611 | 0 | 0 | 0 | 0 |
|
| 64 |
+
| 4 | bots_intelligence | 234 | 0 | 0 | 0 | 0 |
|
| 65 |
+
| 4 | bridges | 281 | 0 | 0 | 0 | 0 |
|
| 66 |
+
| 4 | briefing | 62 | 34 | 0 | 0 | 34 |
|
| 67 |
+
| 4 | code_architect | 98 | 0 | 0 | 0 | 0 |
|
| 68 |
+
| 4 | command_centers | 260 | 0 | 0 | 0 | 0 |
|
| 69 |
+
| 4 | connectors | 47 | 0 | 0 | 0 | 0 |
|
| 70 |
+
| 4 | core | 986 | 452 | 0 | 0 | 452 |
|
| 71 |
+
| 4 | data_feeds | 251 | 118 | 0 | 0 | 118 |
|
| 72 |
+
| 4 | exchanges | 643 | 0 | 0 | 0 | 0 |
|
| 73 |
+
| 4 | governance | 204 | 105 | 0 | 0 | 105 |
|
| 74 |
+
| 4 | grants | 77 | 44 | 0 | 0 | 44 |
|
| 75 |
+
| 4 | harmonic | 605 | 278 | 0 | 0 | 278 |
|
| 76 |
+
| 4 | identity | 16 | 0 | 0 | 0 | 0 |
|
| 77 |
+
| 4 | inhouse_ai | 145 | 0 | 0 | 0 | 0 |
|
| 78 |
+
| 4 | integrations | 167 | 65 | 0 | 0 | 65 |
|
| 79 |
+
| 4 | intelligence | 597 | 274 | 0 | 0 | 274 |
|
| 80 |
+
| 4 | launch | 97 | 0 | 0 | 0 | 0 |
|
| 81 |
+
| 4 | monitors | 345 | 158 | 0 | 0 | 158 |
|
| 82 |
+
| 4 | observability | 27 | 9 | 0 | 0 | 9 |
|
| 83 |
+
| 4 | operator | 1080 | 0 | 0 | 0 | 0 |
|
| 84 |
+
| 4 | organism | 3 | 1 | 0 | 0 | 1 |
|
| 85 |
+
| 4 | plumber | 497 | 271 | 0 | 0 | 271 |
|
| 86 |
+
| 4 | portals | 74 | 51 | 0 | 0 | 51 |
|
| 87 |
+
| 4 | portfolio | 322 | 0 | 0 | 0 | 0 |
|
| 88 |
+
| 4 | queen | 1348 | 566 | 0 | 0 | 566 |
|
| 89 |
+
| 4 | saas | 83 | 0 | 0 | 0 | 0 |
|
| 90 |
+
| 4 | scanners | 335 | 0 | 0 | 0 | 0 |
|
| 91 |
+
| 4 | search | 21 | 5 | 0 | 0 | 5 |
|
| 92 |
+
| 4 | simulation | 440 | 200 | 0 | 0 | 200 |
|
| 93 |
+
| 4 | strategies | 474 | 0 | 0 | 0 | 0 |
|
| 94 |
+
| 4 | swarm_motion | 49 | 10 | 0 | 0 | 10 |
|
| 95 |
+
| 4 | trading | 2023 | 0 | 0 | 0 | 0 |
|
| 96 |
+
| 4 | unified_margin_trader | 1643 | 0 | 0 | 0 | 0 |
|
| 97 |
+
| 4 | utils | 1162 | 455 | 0 | 0 | 455 |
|
| 98 |
+
| 4 | vault | 418 | 195 | 0 | 0 | 195 |
|
| 99 |
+
| 4 | wisdom | 755 | 375 | 0 | 0 | 375 |
|
| 100 |
+
|
| 101 |
+
## Fence
|
| 102 |
+
|
| 103 |
+
These packages are stage 4 because they are on the refused-imports fence or an inventory row says order. `body_call` returns `live_orders: refused` and does not import them.
|
| 104 |
+
|
| 105 |
+
- `bots`
|
| 106 |
+
- `bots_intelligence`
|
| 107 |
+
- `bridges`
|
| 108 |
+
- `exchanges`
|
| 109 |
+
- `scanners`
|
| 110 |
+
- `trading`
|
| 111 |
+
- `unified_margin_trader`
|
| 112 |
+
|
| 113 |
+
## Stage 4
|
| 114 |
+
|
| 115 |
+
`alignment/unified_directive.py` `get_unified_directive` is not a stage-1 tool. Queen is stage 4. Miner is stage 3. `body_call` refuses it now. The no-argument call is in the call sweep.
|
| 116 |
+
|
| 117 |
+
Calling `get_unified_directive` constructs `UnifiedHarmonicDirective` with auto-wire on. That constructs `QueenAIBridge` and `MinerAIBridge`. Each bridge loads `AureonBrainAdapter` as the reasoning backend when the Ollama switchboard is missing or unhealthy, and each bridge wires itself to a `ThoughtBus`. The call imports `aureon.queen`, `aureon.miner`, and `aureon.swarm_motion`, and it attempted a connection to `127.0.0.1:11434`. The sweep blocked that socket.
|
| 118 |
+
|
| 119 |
+
## This run
|
| 120 |
+
|
| 121 |
+
`alignment` stays the first stage-1 package. `get_pillar_alignment` stays, with `auto_load_pillars` false. `get_unified_directive` is not a stage-1 tool. This run opens `generated` and `swarm`. `organism` is not opened.
|
| 122 |
+
Generated was on the more_layers exclusion list. It is open because `aureon/generated/research_cinema/harmonic_nexus_score_model.py` imports only dataclasses and its module docstring calls it a deterministic helper, not trading authority. The four entry points are `build_default_inputs`, `HarmonicNexusScoreInputs.normalized`, `harmonic_nexus_score`, and `score_breakdown`. `tests/generated/test_harmonic_nexus_score_model.py` shows all-ones inputs score 100.0. That 100 is the weighted sum in that file. It does not score any Aureon or HNC claim and cannot be quoted as evidence.
|
| 123 |
+
`body_call` refuses `organism/repository_layers.py` `compose_repository_layers`. With the checkout beside `NEXUS-LIVE-FEED-` and `Aureon-Trading--Project-Sero`, that call uses `Path(__file__).parents[3]`, independent of `AUREON_REPOS_ROOT`, and execs those sibling modules outside the pin. One call also loads `core.organism_composition`, and through that `aureon.inhouse_ai.llm_adapter`, `agent_runner`, `orchestrator`, `aureon.ollama_config`, and `aureon.autonomous.aureon_internal_coding_workforce`. `inhouse_ai` stays excluded. Organism reachable is 0.
|
| 124 |
+
`body_call` refuses `swarm/capability_grid.py` `build_lane`. `build_lane("fintech")` imports `aureon.accounting`, and that package init reaches `aureon.autonomous.aureon_internal_coding_workforce`, which imports `aureon.inhouse_ai` and `aureon.ollama_config`. Swarm reachable is 15.
|
| 125 |
+
The swarm tools use fixtures from the swarm tests or fixed example arguments. `SwarmAgent.update` uses the first call in `tests/test_swarm_hive.py` `test_agent_keeps_a_normalized_soft_simplex`: agent `a1`, role `research`, actions hold, advance, and retreat, CONTEXT `[0.4, 0.2, -0.1, 0.3, 0.0, 0.1, -0.2, 0.05]`, an empty cluster, and no echo. The function returns None. Classes that need nested agent instances stay off the constructor allowlist: Cluster, Company, Zone, FleadhCompany, VisitorAgent, and WorkerAgent. Name-blocked `run_` entry points stay refused. `SwarmAgent.purity` and `ClusterCoherence.warm` are properties. The worker calls methods, so `body_call` and `dispatch` refuse them. `CausalEchoBus.possibilities` is refused because one call cannot park an ensemble and then read it. `issue_auris_node_receipt` needs a `TrustedAurisNodeResolver` that is not built from JSON. `validate_auris_node_receipt`, `validate_hnc_evidence`, `validate_provider_moment`, `validate_council_receipt`, and `validate_seat_receipt` are refused: the receipt is assembled by the test harness, and the public result cap would drop its fields.
|
| 126 |
+
Stage 2 tools call through `dispatch`. The inputs are the tests and committed files named on each tool. `atn` stays excluded because its modules load an HTTP client. `conversion` has no public function or method and stays excluded. The constructor allowlist, the `__post_init__` refusal, the `AUREON_PUBLIC_SWEEP` start refusal, and the pin check are unchanged.
|
| 127 |
+
Import refusals:
|
| 128 |
+
- `atn/aureon_atn_backtest.py`: module import loads an adapter or http client
|
| 129 |
+
- `atn/aureon_atn_forensics.py`: module import loads an adapter or http client
|
| 130 |
+
- `atn/aureon_atn_monitor.py`: module import loads an adapter or http client
|
| 131 |
+
- `decoders/emerald_spec.py`: module import loads an adapter or http client
|
| 132 |
+
- `decoders/grail_convergence.py`: module import loads an adapter or http client
|
| 133 |
+
Import errors that are not refusals:
|
| 134 |
+
- `s51/aureon_51.py`: ImportError: Refused imports: aureon.exchanges, aureon.trading, unified_margin_trader, aureon.bots, aureon.bots_intelligence, aureon.bridges, aureon.scanners. No keys are present. Refused: aureon.exchanges
|
| 135 |
+
- `s51/aureon_51_live.py`: ModuleNotFoundError: No module named 'websockets'
|
| 136 |
+
Call refusals from the sweep:
|
| 137 |
+
- `alignment/unified_directive.py` `get_unified_directive`: call loads a banned chain or opens a connection
|
| 138 |
+
- `evaluation/measured_proof.py` `self_coder_report`: call loads a banned chain or opens a connection. The same call started a process. The sweep blocked it.
|
| 139 |
+
- `gates/panel.py` `auris_panel`: call loads a banned chain or opens a connection
|
| 140 |
+
- `gates/panel.py` `build_vault`: call loads a banned chain or opens a connection
|
| 141 |
+
- `gates/switchboard.py` `read_organism`: call loads a banned chain or opens a connection
|
| 142 |
+
These five were reachable and had no tool. `body_call` and `dispatch` refuse them. The constructor allowlist is unchanged.
|
| 143 |
+
- `decoders/book_of_ur.py` `test_phi_resonance_me`: untested stage-2 entry point is not called. The argument is a SumerianMe. That class is not on the constructor allowlist, so the public server does not build one. The sweep uses the catalog entry ENSHIP from aureon/decoders/book_of_ur.py.
|
| 144 |
+
- `observer/momentum.py` `set_momentum_tracker`: untested stage-2 entry point is not called. The argument is a MomentumTracker. The class is not on the constructor allowlist. The sweep constructs an empty tracker inside the worker.
|
| 145 |
+
- `observer/predictor.py` `make_predictor`: untested stage-2 entry point is not called. The argument is a HarmonicObserver. The class is not on the constructor allowlist. The sweep uses the construction in tests/observer/test_predictor_contract.py: trace_interval_s 1.0 and publish_to_bus false.
|
| 146 |
+
- `observer/wave_predictor.py` `make_predictor`: untested stage-2 entry point is not called. The argument is a WavePredictor. The class is not on the constructor allowlist. The sweep constructs an empty predictor inside the worker.
|
| 147 |
+
- `observer/wave_predictor.py` `set_wave_predictor`: untested stage-2 entry point is not called. The argument is a WavePredictor. The class is not on the constructor allowlist. The sweep constructs an empty predictor inside the worker.
|
| 148 |
+
## Count reconciliation
|
| 149 |
+
|
| 150 |
+
Main `c1ae468d` recorded reachable 85. Stage 1 was 39 (alignment 11, generated 4, swarm 24). Stage 2 was 46 (atn 0, cognition 1, conversion 0, decoders 5, evaluation 7, gates 3, observer 29, s51 1). 39 + 46 = 85. Tested on that main was the 29 stage-1 tool entry points below. Stage 2 tested was 0. Registering a tool does not add a reachable row. The tool calls an entry point that was already reachable.
|
| 151 |
+
Stage 1 reachable now: 30. Stage 2 reachable now: 39. 30 + 39 = 69.
|
| 152 |
+
Stage 1 tested now: 30. Stage 2 tested now: 39. 30 + 39 = 69.
|
| 153 |
+
Every stage-1 entry point that was tested on main is still tested. None dropped out:
|
| 154 |
+
No stage-1 tested entry point dropped out.
|
| 155 |
+
- `alignment/harmonic_resonance.py` `HarmonicAnalysis.to_dict`
|
| 156 |
+
- `alignment/harmonic_resonance.py` `analyse_frequency_harmony`
|
| 157 |
+
- `alignment/harmonic_resonance.py` `compute_phase_coherence`
|
| 158 |
+
- `alignment/harmonic_resonance.py` `compute_signal_consensus`
|
| 159 |
+
- `alignment/harmonic_resonance.py` `consonance_score`
|
| 160 |
+
- `alignment/harmonic_resonance.py` `derive_phase`
|
| 161 |
+
- `alignment/harmonic_resonance.py` `full_harmonic_analysis`
|
| 162 |
+
- `alignment/harmonic_resonance.py` `geometric_mean`
|
| 163 |
+
- `alignment/pillar_alignment.py` `AlignmentCycleResult.to_dict`
|
| 164 |
+
- `alignment/pillar_alignment.py` `get_pillar_alignment`
|
| 165 |
+
- `alignment/unified_directive.py` `MasterDirective.to_dict`
|
| 166 |
+
- `generated/research_cinema/harmonic_nexus_score_model.py` `HarmonicNexusScoreInputs.normalized`
|
| 167 |
+
- `generated/research_cinema/harmonic_nexus_score_model.py` `build_default_inputs`
|
| 168 |
+
- `generated/research_cinema/harmonic_nexus_score_model.py` `harmonic_nexus_score`
|
| 169 |
+
- `generated/research_cinema/harmonic_nexus_score_model.py` `score_breakdown`
|
| 170 |
+
- `swarm/agent.py` `SwarmAgent.propose`
|
| 171 |
+
- `swarm/agent.py` `SwarmAgent.substrate`
|
| 172 |
+
- `swarm/agent.py` `SwarmAgent.to_dict`
|
| 173 |
+
- `swarm/agent.py` `SwarmAgent.update`
|
| 174 |
+
- `swarm/coherence.py` `ClusterCoherence.gamma`
|
| 175 |
+
- `swarm/coherence.py` `ClusterCoherence.to_dict`
|
| 176 |
+
- `swarm/druidic_council.py` `CouncilReceipt.to_dict`
|
| 177 |
+
- `swarm/druidic_council.py` `SeatReceipt.to_dict`
|
| 178 |
+
- `swarm/druidic_council.py` `build_seat_receipt`
|
| 179 |
+
- `swarm/druidic_council.py` `voice_for_gamma`
|
| 180 |
+
- `swarm/fleadh.py` `steer_flow`
|
| 181 |
+
- `swarm/memory_bus.py` `CausalEchoBus.echo`
|
| 182 |
+
- `swarm/memory_bus.py` `CausalEchoBus.to_dict`
|
| 183 |
+
- `swarm/queen_gate.py` `Actualization.to_dict`
|
| 184 |
+
- `swarm/steering.py` `SteeringField.steer`
|
| 185 |
+
Stage 1 has no reachable entry point left untested.
|
| 186 |
+
Stage 2 reachable fell by 7, from 46 to 39, on the stage-2 run. The call sweep refused `self_coder_report`. Five reachable entry points had no tool. `log_blocked_fallback` would write a fallback log for an event that did not happen, so `body_call` refuses it. This follow-up then closes the 10 stage-1 points that were reachable and not tested. Nine are refused. `SwarmAgent.update` is tested on the hive fixture.
|
| 187 |
+
- `evaluation/measured_proof.py` `self_coder_report`: call loads a banned chain or opens a connection.
|
| 188 |
+
- `decoders/book_of_ur.py` `test_phi_resonance_me`: untested stage-2 entry point is not called.
|
| 189 |
+
- `observer/momentum.py` `set_momentum_tracker`: untested stage-2 entry point is not called.
|
| 190 |
+
- `observer/predictor.py` `make_predictor`: untested stage-2 entry point is not called.
|
| 191 |
+
- `observer/wave_predictor.py` `make_predictor`: untested stage-2 entry point is not called.
|
| 192 |
+
- `observer/wave_predictor.py` `set_wave_predictor`: untested stage-2 entry point is not called.
|
| 193 |
+
- `observer/live_data_policy.py` `log_blocked_fallback`: fallback log is not emitted for an event that did not happen.
|
| 194 |
+
- `swarm/agent.py` `SwarmAgent.purity`: property is not called; the worker calls methods.
|
| 195 |
+
- `swarm/auris_node_receipts.py` `issue_auris_node_receipt`: trusted resolver is not built from JSON.
|
| 196 |
+
- `swarm/auris_node_receipts.py` `validate_auris_node_receipt`: receipt is assembled by the test harness; the public result cap would drop its fields.
|
| 197 |
+
- `swarm/auris_node_receipts.py` `validate_hnc_evidence`: receipt is assembled by the test harness; the public result cap would drop its fields.
|
| 198 |
+
- `swarm/auris_node_receipts.py` `validate_provider_moment`: receipt is assembled by the test harness; the public result cap would drop its fields.
|
| 199 |
+
- `swarm/capability_grid.py` `build_lane`: stage 4 entry point is not called.
|
| 200 |
+
- `swarm/coherence.py` `ClusterCoherence.warm`: property is not called; the worker calls methods.
|
| 201 |
+
- `swarm/druidic_council.py` `validate_council_receipt`: receipt is assembled by the test harness; the public result cap would drop its fields.
|
| 202 |
+
- `swarm/druidic_council.py` `validate_seat_receipt`: receipt is assembled by the test harness; the public result cap would drop its fields.
|
| 203 |
+
- `swarm/memory_bus.py` `CausalEchoBus.possibilities`: one call cannot park an ensemble and read it.
|
| 204 |
+
Main `cf43882e` recorded reachable 78 and tested 68. This follow-up refuses nine stage-1 entry points and tests `SwarmAgent.update`. Reachable and tested are both 69. 30 + 39 = 69.
|
| 205 |
+
|
| 206 |
+
The pin stays `8aa6a2d971cc529484e2a5e261e28afafab4e4f4`. The alignment modules at this checkout match that pin, so the tools do not need a newer commit. `GUARD_BLOB` and `INVENTORY_SHA256` are unchanged.
|
| 207 |
+
|
| 208 |
+
## MCP SDK
|
| 209 |
+
|
| 210 |
+
This server imports `FastMCP` from `mcp.server.fastmcp` and passes `host`, `port`, and `streamable_http_path` to that constructor. The requirement is `mcp==1.30.0,<2` in `mcp/aureon_public/requirements.txt` and `mcp/pyproject.toml`. That specifier matches 1.30.0 and excludes every 2.x release. Migration to SDK v2 is a later decision.
|
| 211 |
+
|
| 212 |
+
The claim that official Python SDK v2 renamed `FastMCP` to `MCPServer` was checked against the published package and the v2 source. The claim is true.
|
| 213 |
+
|
| 214 |
+
- PyPI project `mcp`: `info.version` is 2.3.0. The newest 1.x release is 1.30.0. https://pypi.org/pypi/mcp/json
|
| 215 |
+
- Release v2.0.0, published 28 July 2026, says `FastMCP` is now `MCPServer`, v1.x is maintenance-only on branch `v1.x`, and a project that is not migrating should keep a `<2` upper bound, for example `mcp>=1.28,<2`. https://github.com/modelcontextprotocol/python-sdk/releases/tag/v2.0.0
|
| 216 |
+
- Migration guide, section `FastMCP` renamed to `MCPServer`: `from mcp.server.fastmcp import FastMCP` becomes `from mcp.server.mcpserver import MCPServer`. https://py.sdk.modelcontextprotocol.io/v2/migration/
|
| 217 |
+
- Tag v2.0.0 and tag v2.3.0 `src/mcp/server/__init__.py` export `MCPServer` from `.mcpserver`. https://github.com/modelcontextprotocol/python-sdk/blob/v2.3.0/src/mcp/server/__init__.py
|
| 218 |
+
- Tag v2.3.0 `src/mcp/server/mcpserver/server.py` defines `class MCPServer`. `MCPServer.__init__` takes no `host`, `port`, or `streamable_http_path`. Those arguments are on `run(transport="streamable-http")`. The default name when none is passed is `mcp-server`. `instructions` is no longer the second positional parameter. https://github.com/modelcontextprotocol/python-sdk/blob/v2.3.0/src/mcp/server/mcpserver/server.py
|
| 219 |
+
- `src/mcp/server/fastmcp/__init__.py` on tag v2.3.0 is not published. The raw URL returns HTTP 404. https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/v2.3.0/src/mcp/server/fastmcp/__init__.py
|
| 220 |
+
- v1 documentation stays at https://py.sdk.modelcontextprotocol.io/v1/
|
| 221 |
+
|
| 222 |
+
The same v2.0.0 notes also replace `ClientSession` plus the transport clients with `Client`, and the v2.3.0 constructor no longer accepts `host`, `port`, or `streamable_http_path`. This server still passes those three to `FastMCP`, and the measured client still uses `ClientSession`. Staying on 1.30.0 keeps that call shape.
|
| 223 |
+
|
| 224 |
+
The protocol proof is the stdio session and the Streamable HTTP session bound to `127.0.0.1`. The Space scaffold is `mcp/aureon_public/Dockerfile` and `python -m aureon_public.space`. It is not deployed. `AUREON_PUBLIC_API_KEY` enforces a bearer token. `AUREON_PUBLIC_OPEN=1` serves the read-only surface with no key. With neither, Streamable HTTP binds to `127.0.0.1` only. Stages 3 and 4 stay closed.
|
| 225 |
+
|
Dockerfile
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Hugging Face Space scaffold for aureon-public. This image is not deployed
|
| 2 |
+
# and this file does not create a Hugging Face repository.
|
| 3 |
+
#
|
| 4 |
+
# Build from this directory:
|
| 5 |
+
# docker build -f Dockerfile -t aureon-public .
|
| 6 |
+
#
|
| 7 |
+
# The runtime install matches measured/aureon_public_stage1_run.sh:
|
| 8 |
+
# requirements.txt (mcp==1.30.0,<2 and the aureon pin), then the mcp package
|
| 9 |
+
# with --no-deps. test-requirements.txt is not installed.
|
| 10 |
+
#
|
| 11 |
+
# No API key is baked in. AUREON_PUBLIC_API_KEY is a runtime secret. The image
|
| 12 |
+
# sets AUREON_PUBLIC_OPEN=1 so the read-only surface can bind on the Space port
|
| 13 |
+
# when that secret is absent. AUREON_PUBLIC_SWEEP is not set.
|
| 14 |
+
|
| 15 |
+
FROM python:3.12-slim-bookworm
|
| 16 |
+
|
| 17 |
+
RUN apt-get update \
|
| 18 |
+
&& apt-get install -y --no-install-recommends git ca-certificates \
|
| 19 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 20 |
+
|
| 21 |
+
# Full history of main so git rev-parse of the aureon pin still resolves.
|
| 22 |
+
# A shallow clone would omit that commit.
|
| 23 |
+
# AUREON_REF defaults to the merge commit of #225. That tree contains the
|
| 24 |
+
# aureon pin. Do not set cf43882e as a standing default.
|
| 25 |
+
ARG AUREON_REPO=https://github.com/RA-CONSULTING/Aureon-OS.git
|
| 26 |
+
ARG AUREON_REF=0390194b80cddb66c8cfd052efe3aa4f9d1545d6
|
| 27 |
+
# The first Hugging Face build log must show the AUREON_REF build arg.
|
| 28 |
+
RUN test -n "$AUREON_REF" \
|
| 29 |
+
&& echo "AUREON_REF=${AUREON_REF}" \
|
| 30 |
+
&& git clone --branch main --single-branch "$AUREON_REPO" /opt/aureon-os \
|
| 31 |
+
&& git -C /opt/aureon-os checkout "$AUREON_REF" \
|
| 32 |
+
&& git config --system --add safe.directory /opt/aureon-os
|
| 33 |
+
|
| 34 |
+
# Overlay this directory so the image runs the scaffold beside the Dockerfile,
|
| 35 |
+
# including files that are not on AUREON_REF yet. The overlay is the public
|
| 36 |
+
# package only. It does not replace aureon/ and it does not add a key.
|
| 37 |
+
COPY . /opt/aureon-os/mcp/aureon_public/
|
| 38 |
+
|
| 39 |
+
WORKDIR /opt/aureon-os
|
| 40 |
+
RUN python -m pip install --no-cache-dir -U pip \
|
| 41 |
+
&& python -m pip install --no-cache-dir -r mcp/aureon_public/requirements.txt \
|
| 42 |
+
&& python -m pip install --no-cache-dir -e mcp --no-deps \
|
| 43 |
+
&& rm -rf /root/.cache/pip
|
| 44 |
+
|
| 45 |
+
RUN useradd --create-home --uid 1000 aureon \
|
| 46 |
+
&& mkdir -p /tmp/aureon-public-space \
|
| 47 |
+
&& chown -R aureon:aureon /tmp/aureon-public-space
|
| 48 |
+
USER aureon
|
| 49 |
+
WORKDIR /tmp/aureon-public-space
|
| 50 |
+
|
| 51 |
+
# Listen on 0.0.0.0. The MCP SDK turns DNS-rebinding protection on when the
|
| 52 |
+
# process binds 127.0.0.1, and then answers 421 to Host: *.hf.space.
|
| 53 |
+
# Open mode and keyed mode on the Space stay on 0.0.0.0. A process with
|
| 54 |
+
# neither AUREON_PUBLIC_OPEN=1 nor AUREON_PUBLIC_API_KEY still refuses that bind.
|
| 55 |
+
ENV AUREON_PUBLIC_REQUIRE_PIN=1 \
|
| 56 |
+
AUREON_OBSERVER_MODE=dry_run \
|
| 57 |
+
AUREON_PUBLIC_OPEN=1 \
|
| 58 |
+
AUREON_PUBLIC_HOST=0.0.0.0 \
|
| 59 |
+
AUREON_PUBLIC_MAX_INFLIGHT=4 \
|
| 60 |
+
PORT=7860 \
|
| 61 |
+
PYTHONDONTWRITEBYTECODE=1 \
|
| 62 |
+
PYTHONUNBUFFERED=1
|
| 63 |
+
|
| 64 |
+
EXPOSE 7860
|
| 65 |
+
CMD ["python", "-m", "aureon_public.space"]
|
README.md
ADDED
|
@@ -0,0 +1,199 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: aureon-public
|
| 3 |
+
emoji: "🔷"
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: gray
|
| 6 |
+
sdk: docker
|
| 7 |
+
app_port: 7860
|
| 8 |
+
pinned: false
|
| 9 |
+
license: mit
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# aureon-public
|
| 13 |
+
|
| 14 |
+
This is a partial release covering stages 1 and 2 of 4. Stages 3 and 4 stay closed. That includes miner, queen, exchanges, orders, and keys. `COVERAGE_PLAN.md` records the counts: listed symbols 20083, public entry points 4388, reachable now 69, tested 69, refused 4319. Stage 1 reachable now is 30 and stage 1 tested now is 30. Stage 2 reachable now is 39 and stage 2 tested now is 39. 30 + 39 = 69 reachable. 30 + 39 = 69 tested.
|
| 15 |
+
|
| 16 |
+
Miner is stage 3: 15 listed, 0 public entry points, reachable 0, tested 0, refused 0. Queen is stage 4: 1348 listed, 566 public entry points, reachable 0, tested 0, refused 566. Exchanges are stage 4: 643 listed, 0 public entry points, reachable 0, tested 0, refused 0. Accounting is stage 3 with reachable 0. Trading is stage 4 with reachable 0.
|
| 17 |
+
|
| 18 |
+
The measured tests are the call sweep. It calls every entry point that was still reachable, with no arguments, and calls each stage-2 entry point again with the real arguments in `stage2_arguments.py`. Connections, process starts, and writes outside the sandbox are logged: the committed record says sockets blocked, processes blocked, and writes outside the sandbox blocked. A call that opens a connection, starts a process, writes outside the sandbox, or loads queen, miner, swarm_motion, inhouse_ai, ollama_config, or an HTTP client is refused. Other arguments have not been swept.
|
| 19 |
+
|
| 20 |
+
The Space entry is `python -m aureon_public.space`. It sets `AUREON_PUBLIC_REQUIRE_PIN=1` and `AUREON_OBSERVER_MODE=dry_run`, and it refuses to start when `AUREON_PUBLIC_SWEEP` is set. The image installs `requirements.txt` (`mcp==1.30.0,<2` and aureon pin `8aa6a2d971cc529484e2a5e261e28afafab4e4f4`) and then the mcp package with `--no-deps`, the same runtime install as `measured/aureon_public_stage1_run.sh`. The image does not install test requirements and does not contain `AUREON_PUBLIC_API_KEY`.
|
| 21 |
+
|
| 22 |
+
`AUREON_PUBLIC_OPEN=1` is set in the image, so the read-only stage-1 and stage-2 surface is served on port 7860 without a key. Set `AUREON_PUBLIC_API_KEY` in the Space secret settings to require `Authorization: Bearer`. A missing or wrong bearer then receives HTTP 401. With neither the key nor `AUREON_PUBLIC_OPEN=1`, the process binds to `127.0.0.1` only and refuses `0.0.0.0`. The image keeps `AUREON_PUBLIC_HOST=0.0.0.0` whenever it is in open mode or keyed mode. The MCP SDK turns DNS-rebinding protection on for a `127.0.0.1` bind and then answers HTTP 421 to `Host: *.hf.space`. A `0.0.0.0` bind accepts that Host header, which is what Hugging Face's proxy sends. The public HTTP server uses MCP SDK 1.30 stateless JSON responses (`stateless_http` and `json_response`). `GET /mcp` returns HTTP 405. That long-lived event stream is not used, and it does not take an in-flight call slot. `AUREON_PUBLIC_MAX_INFLIGHT` (default 4, the same size as the public worker pool) caps concurrent in-flight POST `/mcp` requests. Each tool call starts a worker process. A POST over that cap returns HTTP 503 with `error` `busy`. `AUREON_PUBLIC_RATE_LIMIT` (default 120) and `AUREON_PUBLIC_RATE_WINDOW_S` (default 60) limit requests per client. `AUREON_PUBLIC_TRUSTED_PROXY_HOPS` defaults to 1. When `X-Forwarded-For` is present and has at least that many values, the client is the value that many hops from the right. With the default, that is the last value, including a header whose only value is the client address. A fake first hop in front of that value does not get its own bucket. Zero trusted proxy hops ignores the header and uses the socket peer. The real Hugging Face header shape has to be confirmed on the private Space before this default is treated as settled. `AUREON_PUBLIC_FORWARDED_DIAG=1` records hop count and whether each hop is an IPv4 address, an IPv6 address, or something else. It does not store the addresses. Open mode buckets by that address only. A bearer is the client id only when it matches `AUREON_PUBLIC_API_KEY`. The tracked-id table is capped by `AUREON_PUBLIC_RATE_MAX_CLIENTS` (default 4096) and drops expired windows. `AUREON_PUBLIC_MAX_BODY_BYTES` (default 1048576) counts bytes as they arrive, including a chunked body with no content-length. Every body message is counted until `more_body` is false or the client disconnects. Empty chunks do not stop that count, and the unread remainder is not passed through. `AUREON_PUBLIC_REQUEST_TIMEOUT_S` (default 30) limits a POST and also bounds that body read. A rate limit returns HTTP 429. A body over the cap returns HTTP 413. An idle or unfinished body returns HTTP 408 with `error` `body_timeout`. A POST that passes the timeout returns HTTP 504.
|
| 23 |
+
|
| 24 |
+
This scaffold is not deployed and it does not create a Hugging Face repository. The measured session was taken without Docker. `.github/workflows/aureon-public-space.yml` builds this image on a pull request and runs `python -m aureon_public.space --check`. `AUREON_REF` defaults to `0390194b80cddb66c8cfd052efe3aa4f9d1545d6`, the merge commit of #225. That tree contains the aureon pin. Do not point `AUREON_REF` at cf43882e as a standing default. The first Hugging Face build log must show the `AUREON_REF` build arg. Uvicorn is started with `proxy_headers` off and an empty `forwarded_allow_ips`, so `X-Forwarded-For` is read only by this server's own middleware.
|
| 25 |
+
|
| 26 |
+
MCP lets outside models call Aureon's tools. No outside model or API becomes Aureon's reasoning. The cognition runs in Aureon's own code.
|
| 27 |
+
|
| 28 |
+
This process is a read-only FastMCP server named `aureon-public`. It exposes the milestone-1 tools, resources, and prompts. It does not place orders, read keys, start circulation, self-code, self-repair, or write the repository or `state/`.
|
| 29 |
+
|
| 30 |
+
`aureon` is pinned to commit `8aa6a2d971cc529484e2a5e261e28afafab4e4f4`, the same pin as the Hugging Face Spaces. A local checkout run uses its own commit, not the pin. The MCP SDK requirement is `mcp==1.30.0,<2` in `requirements.txt` and `pyproject.toml`. That installs 1.30.0 and excludes every 2.x release. This server imports `FastMCP` from `mcp.server.fastmcp`. The check that MCP 2 renamed that class to `MCPServer` is in `COVERAGE_PLAN.md`, with the sources. Migration to SDK v2 is a later decision.
|
| 31 |
+
|
| 32 |
+
Any public hosting, including this aureon-public Space scaffold, must set `AUREON_PUBLIC_REQUIRE_PIN=1`. That refuses to start unless `aureon_source` is kind `pinned` at `8aa6a2d971cc529484e2a5e261e28afafab4e4f4`. Local runs of `python -m aureon_public` leave the variable unset and keep the visible `aureon_source` label. `python -m aureon_public.space` calls `enforce_public_pin()` before it binds.
|
| 33 |
+
|
| 34 |
+
The operator process is separate: `python -m aureon_operator`. It stays off unless `AUREON_OPERATOR_MCP=1`, speaks stdio only, and refuses live orders. It does not import `aureon.trading` or the other blocked packages.
|
| 35 |
+
|
| 36 |
+
`repo_root()` and `aureon_source()` raise `FileNotFoundError` when the process is not inside a checkout that contains `huggingface/hnc-field/guard.py` and `aureon/core/hnc_field.py`. This server needs that checkout. It does not invent a 'no checkout' status.
|
| 37 |
+
|
| 38 |
+
A layer counts as full depth only where its real entry points are called.
|
| 39 |
+
Each figure is reachable public functions and methods out of the public functions and methods in the pinned `docs/mcp/inventory.json`.
|
| 40 |
+
|
| 41 |
+
| Package | Reachable | Public entry points |
|
| 42 |
+
| --- | ---: | ---: |
|
| 43 |
+
| accounting | 0 | 0 |
|
| 44 |
+
| alignment | 11 | 24 |
|
| 45 |
+
| analytics | 0 | 167 |
|
| 46 |
+
| appliance | 0 | 7 |
|
| 47 |
+
| approval | 0 | 42 |
|
| 48 |
+
| atn | 0 | 28 |
|
| 49 |
+
| autonomous | 0 | 0 |
|
| 50 |
+
| bio | 0 | 206 |
|
| 51 |
+
| bots | 0 | 0 |
|
| 52 |
+
| bots_intelligence | 0 | 0 |
|
| 53 |
+
| bridges | 0 | 0 |
|
| 54 |
+
| briefing | 0 | 34 |
|
| 55 |
+
| code_architect | 0 | 0 |
|
| 56 |
+
| cognition | 1 | 14 |
|
| 57 |
+
| command_centers | 0 | 0 |
|
| 58 |
+
| connectors | 0 | 0 |
|
| 59 |
+
| conversion | 0 | 0 |
|
| 60 |
+
| core | 0 | 452 |
|
| 61 |
+
| data_feeds | 0 | 118 |
|
| 62 |
+
| decoders | 4 | 80 |
|
| 63 |
+
| evaluation | 6 | 10 |
|
| 64 |
+
| exchanges | 0 | 0 |
|
| 65 |
+
| gates | 3 | 12 |
|
| 66 |
+
| generated | 4 | 4 |
|
| 67 |
+
| governance | 0 | 105 |
|
| 68 |
+
| grants | 0 | 44 |
|
| 69 |
+
| harmonic | 0 | 278 |
|
| 70 |
+
| identity | 0 | 0 |
|
| 71 |
+
| inhouse_ai | 0 | 0 |
|
| 72 |
+
| integrations | 0 | 65 |
|
| 73 |
+
| intelligence | 0 | 274 |
|
| 74 |
+
| launch | 0 | 0 |
|
| 75 |
+
| miner | 0 | 0 |
|
| 76 |
+
| monitors | 0 | 158 |
|
| 77 |
+
| observability | 0 | 9 |
|
| 78 |
+
| observer | 24 | 63 |
|
| 79 |
+
| operator | 0 | 0 |
|
| 80 |
+
| organism | 0 | 1 |
|
| 81 |
+
| plumber | 0 | 271 |
|
| 82 |
+
| portals | 0 | 51 |
|
| 83 |
+
| portfolio | 0 | 0 |
|
| 84 |
+
| queen | 0 | 566 |
|
| 85 |
+
| s51 | 1 | 24 |
|
| 86 |
+
| saas | 0 | 0 |
|
| 87 |
+
| scanners | 0 | 0 |
|
| 88 |
+
| search | 0 | 5 |
|
| 89 |
+
| simulation | 0 | 200 |
|
| 90 |
+
| strategies | 0 | 0 |
|
| 91 |
+
| swarm | 15 | 41 |
|
| 92 |
+
| swarm_motion | 0 | 10 |
|
| 93 |
+
| trading | 0 | 0 |
|
| 94 |
+
| unified_margin_trader | 0 | 0 |
|
| 95 |
+
| utils | 0 | 455 |
|
| 96 |
+
| vault | 0 | 195 |
|
| 97 |
+
| wisdom | 0 | 375 |
|
| 98 |
+
|
| 99 |
+
The extra package tools are helpers. A helper call is not that layer's cognition.
|
| 100 |
+
|
| 101 |
+
The order for opening the rest of the inventory is `COVERAGE_PLAN.md`. Alignment is the first package in that order.
|
| 102 |
+
|
| 103 |
+
`body_call` runs one inventoried function or method. `body_surface` reads a module or class and does not construct it. `body_depth` reports the same ratio as this table. `body_registry` names the servers. The operator tool is `body_call_operator`. Live orders stay refused. A checkout file is imported only when its git blob matches pin `8aa6a2d9`. The plan and the call rules are in `docs/mcp/REGISTRY.md`.
|
| 104 |
+
|
| 105 |
+
Licence: MIT, the same licence as the repository `LICENSE`.
|
| 106 |
+
|
| 107 |
+
## Two brain paths
|
| 108 |
+
|
| 109 |
+
`hnc_reality_step` takes `enable_multiverse` and reports that value in the output.
|
| 110 |
+
|
| 111 |
+
The class default `HarmonicRealityField()` sets `enable_multiverse=True` (multiverse on). This tool's default is that class default.
|
| 112 |
+
|
| 113 |
+
Do not mix the two committed paths in `huggingface/hnc-field/replay/brain.json`:
|
| 114 |
+
|
| 115 |
+
| Path | `enable_multiverse` | Coherence in the file |
|
| 116 |
+
| --- | --- | --- |
|
| 117 |
+
| Class default, multiverse on (`multiverse_extension`) | `true` | `0.857719007627168` |
|
| 118 |
+
| Multiverse off (`hnc`) | `false` | `0.9331334813083556` |
|
| 119 |
+
|
| 120 |
+
Those figures are cited from that file. They are not a track record. Trade readiness is HOLD.
|
| 121 |
+
|
| 122 |
+
## Which Auris
|
| 123 |
+
|
| 124 |
+
Four meanings stay separate.
|
| 125 |
+
|
| 126 |
+
- The conjecture is the five symbolic-life markers in `LambdaEngine`. It is not called.
|
| 127 |
+
- The nine nodes are `QueenHiveMind.read_auris_nodes` and `AURIS_NODES`. That is `auris_nodes` and `aureon://auris/nodes`.
|
| 128 |
+
- The persona on `QueenHiveMind` is not scored.
|
| 129 |
+
- The coherence evaluator is `QueenHiveMind.get_auris_coherence`. That is `auris_coherence`.
|
| 130 |
+
|
| 131 |
+
Only the nine nodes and `get_auris_coherence` are real functions exposed here. If any of the nine nodes has no reading, `auris_coherence` returns status `no_data`, coherence null, and the missing node names. The Auris-to-Lambda link is HOLD.
|
| 132 |
+
|
| 133 |
+
`lambda_engine_step` returns status `unavailable` when readings are missing or fewer than two. It does not fill the result with 0.
|
| 134 |
+
|
| 135 |
+
## Install
|
| 136 |
+
|
| 137 |
+
From a checkout of this branch:
|
| 138 |
+
|
| 139 |
+
```bash
|
| 140 |
+
python3 -m venv .venv-aureon-public
|
| 141 |
+
source .venv-aureon-public/bin/activate
|
| 142 |
+
pip install -e mcp
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
`pip install -e mcp` installs this package and the pinned `aureon` commit. The install is editable so the server can still see `huggingface/` replay files in the checkout.
|
| 146 |
+
|
| 147 |
+
## Run
|
| 148 |
+
|
| 149 |
+
stdio, which is what desktop clients use:
|
| 150 |
+
|
| 151 |
+
```bash
|
| 152 |
+
python -m aureon_public
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
Optional streamable HTTP on `127.0.0.1:8077` at path `/mcp`:
|
| 156 |
+
|
| 157 |
+
```bash
|
| 158 |
+
python -m aureon_public --transport streamable-http --host 127.0.0.1 --port 8077
|
| 159 |
+
```
|
| 160 |
+
|
| 161 |
+
The HTTP URL is `http://127.0.0.1:8077/mcp`.
|
| 162 |
+
|
| 163 |
+
## Claude Desktop
|
| 164 |
+
|
| 165 |
+
Put this in the Claude Desktop MCP config. Use the venv interpreter and the checkout path.
|
| 166 |
+
|
| 167 |
+
```json
|
| 168 |
+
{
|
| 169 |
+
"mcpServers": {
|
| 170 |
+
"aureon-public": {
|
| 171 |
+
"command": "/absolute/path/to/.venv-aureon-public/bin/python",
|
| 172 |
+
"args": ["-m", "aureon_public"]
|
| 173 |
+
}
|
| 174 |
+
}
|
| 175 |
+
}
|
| 176 |
+
```
|
| 177 |
+
|
| 178 |
+
## Cursor
|
| 179 |
+
|
| 180 |
+
The same stdio block goes in Cursor's MCP settings (`mcp.json`):
|
| 181 |
+
|
| 182 |
+
```json
|
| 183 |
+
{
|
| 184 |
+
"mcpServers": {
|
| 185 |
+
"aureon-public": {
|
| 186 |
+
"command": "/absolute/path/to/.venv-aureon-public/bin/python",
|
| 187 |
+
"args": ["-m", "aureon_public"]
|
| 188 |
+
}
|
| 189 |
+
}
|
| 190 |
+
}
|
| 191 |
+
```
|
| 192 |
+
|
| 193 |
+
## Any other MCP client
|
| 194 |
+
|
| 195 |
+
Any client that speaks MCP stdio can use the same command. A client that speaks streamable HTTP can use `http://127.0.0.1:8077/mcp` after the HTTP command above. No API key is read. No outside model becomes the reasoning: the client only receives the tool results computed in this process.
|
| 196 |
+
|
| 197 |
+
## What is not on this server
|
| 198 |
+
|
| 199 |
+
Orders, exchange keys, `aureon.exchanges`, `aureon.trading`, `unified_margin_trader`, `aureon.bots`, `aureon.bots_intelligence`, `aureon.bridges`, `aureon.scanners`, circulation start, self-code, and self-repair are not tools. The operator Flask routes in `aureon/bio/mcp_transport.py` are a different process and are not widened here.
|
__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Public read-only MCP server. Outside models call these tools. They do not become the reasoning."""
|
| 2 |
+
|
| 3 |
+
__all__ = ["SERVER_INSTRUCTIONS"]
|
| 4 |
+
|
| 5 |
+
SERVER_INSTRUCTIONS = (
|
| 6 |
+
"MCP lets outside models call Aureon's tools. "
|
| 7 |
+
"No outside model or API becomes Aureon's reasoning. "
|
| 8 |
+
"The cognition runs in Aureon's own code. "
|
| 9 |
+
"This server is read-only. It does not place orders, read keys, start circulation, "
|
| 10 |
+
"self-code, self-repair, or write the repository or state/."
|
| 11 |
+
)
|
__main__.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from aureon_public.server import main
|
| 2 |
+
|
| 3 |
+
if __name__ == "__main__":
|
| 4 |
+
main()
|
alignment_layer.py
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Alignment entry points. Calls go through dispatch, so the pin and the fence stay.
|
| 2 |
+
|
| 3 |
+
Fixtures are the inputs in tests/stress/stress_test_inhouse_ai.py test_harmonic_math.
|
| 4 |
+
No formula was added. A missing or non-finite input is unavailable.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import json
|
| 10 |
+
from typing import Any
|
| 11 |
+
|
| 12 |
+
from aureon_public.body import _unavailable, dispatch
|
| 13 |
+
from aureon_public.quiet import quiet
|
| 14 |
+
from aureon_public.tools import _finite
|
| 15 |
+
|
| 16 |
+
# Inputs copied from tests/stress/stress_test_inhouse_ai.py::test_harmonic_math.
|
| 17 |
+
FIXTURE_SOURCE = "tests/stress/stress_test_inhouse_ai.py::test_harmonic_math"
|
| 18 |
+
FIXTURE_NOTE = (
|
| 19 |
+
"Fixed fixture from tests/stress/stress_test_inhouse_ai.py::test_harmonic_math. "
|
| 20 |
+
"Not a live market reading and not a lighthouse reading."
|
| 21 |
+
)
|
| 22 |
+
SPLIT_SIGNALS = ["BUY", "BUY", "SELL", "SELL", "NEUTRAL", "NEUTRAL"]
|
| 23 |
+
AGREE_SIGNALS = ["BUY", "BUY", "BUY", "BUY", "BUY", "BUY"]
|
| 24 |
+
ALIGNED_PHASES = [0.0, 0.0, 0.0]
|
| 25 |
+
PILLAR_FREQUENCIES = {
|
| 26 |
+
"Nexus": 432.0,
|
| 27 |
+
"Omega": 432.0,
|
| 28 |
+
"Infinite": 528.0,
|
| 29 |
+
"Piano": 396.0,
|
| 30 |
+
"QGITA": 528.0,
|
| 31 |
+
"Auris": 741.0,
|
| 32 |
+
}
|
| 33 |
+
PERFECT_STACK = [
|
| 34 |
+
{
|
| 35 |
+
"pillar": f"P{index}",
|
| 36 |
+
"signal": "BUY",
|
| 37 |
+
"confidence": 0.95,
|
| 38 |
+
"coherence": 0.96,
|
| 39 |
+
"frequency_hz": 528.0,
|
| 40 |
+
}
|
| 41 |
+
for index in range(6)
|
| 42 |
+
]
|
| 43 |
+
GEOMETRIC_ONES = [1.0, 1.0, 1.0, 1.0]
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def _loads(text: str, kind: type) -> Any | str:
|
| 47 |
+
try:
|
| 48 |
+
loaded = json.loads(text)
|
| 49 |
+
except json.JSONDecodeError:
|
| 50 |
+
return "arguments are not JSON"
|
| 51 |
+
if not isinstance(loaded, kind):
|
| 52 |
+
return "arguments have the wrong shape"
|
| 53 |
+
return loaded
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _call(module: str, symbol: str, arguments: dict[str, Any]) -> str:
|
| 57 |
+
return dispatch(module, symbol, arguments, server="public")
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def label_result(text: str, source: str, note: str) -> str:
|
| 61 |
+
"""Attach input_source and input_note to a tool result."""
|
| 62 |
+
|
| 63 |
+
try:
|
| 64 |
+
body = json.loads(text)
|
| 65 |
+
except json.JSONDecodeError:
|
| 66 |
+
return text
|
| 67 |
+
if not isinstance(body, dict):
|
| 68 |
+
return text
|
| 69 |
+
body["input_note"] = note
|
| 70 |
+
body["input_source"] = source
|
| 71 |
+
return json.dumps(body, ensure_ascii=False, allow_nan=False, sort_keys=True)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _annotate(text: str, used_fixture: bool) -> str:
|
| 75 |
+
"""Mark a default-fixture result so scores are not read as a live reading."""
|
| 76 |
+
|
| 77 |
+
if not used_fixture:
|
| 78 |
+
return text
|
| 79 |
+
return label_result(text, FIXTURE_SOURCE, FIXTURE_NOTE)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
DEFAULTS_NOTE = "These fields are the dataclass defaults, not a reading."
|
| 83 |
+
DERIVE_NOTE = (
|
| 84 |
+
"528 Hz is FUNDAMENTAL_HZ and BUY is the fixed example branch in derive_phase. "
|
| 85 |
+
"They are fixed example arguments, not a reading."
|
| 86 |
+
)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
@quiet
|
| 90 |
+
def alignment_signal_consensus(signals_json: str = "") -> str:
|
| 91 |
+
"""compute_signal_consensus. Provenance: cited.
|
| 92 |
+
|
| 93 |
+
The default list is the three-way split in test_harmonic_math. That fixture is not a live market reading and not a lighthouse reading. No pillar agent is built.
|
| 94 |
+
|
| 95 |
+
Args:
|
| 96 |
+
signals_json: JSON list of signal names. Empty uses the split fixture. Label: cited.
|
| 97 |
+
"""
|
| 98 |
+
|
| 99 |
+
raw = signals_json.strip() or json.dumps(SPLIT_SIGNALS)
|
| 100 |
+
parsed = _loads(raw, list)
|
| 101 |
+
if isinstance(parsed, str):
|
| 102 |
+
return _unavailable(parsed)
|
| 103 |
+
if not parsed or not all(isinstance(item, str) for item in parsed):
|
| 104 |
+
return _unavailable("signals must be a non-empty list of strings")
|
| 105 |
+
return _annotate(
|
| 106 |
+
_call(
|
| 107 |
+
"alignment/harmonic_resonance.py",
|
| 108 |
+
"compute_signal_consensus",
|
| 109 |
+
{"signals": parsed},
|
| 110 |
+
),
|
| 111 |
+
parsed == SPLIT_SIGNALS,
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
@quiet
|
| 116 |
+
def alignment_consonance_read(ratio: float = 1.0) -> str:
|
| 117 |
+
"""consonance_score. Provenance: cited.
|
| 118 |
+
|
| 119 |
+
This is the inventory entry point, called through the pin check. The helper
|
| 120 |
+
alignment_consonance is a separate tool and is not this call. The default
|
| 121 |
+
ratio 1.0 is unison in test_harmonic_math. That fixture is not a live market
|
| 122 |
+
reading and not a lighthouse reading.
|
| 123 |
+
|
| 124 |
+
Args:
|
| 125 |
+
ratio: Frequency ratio. The default 1.0 is unison in test_harmonic_math. Label: cited.
|
| 126 |
+
"""
|
| 127 |
+
|
| 128 |
+
number = _finite(ratio)
|
| 129 |
+
if number is None:
|
| 130 |
+
return _unavailable("ratio is missing")
|
| 131 |
+
return _annotate(
|
| 132 |
+
_call("alignment/harmonic_resonance.py", "consonance_score", {"ratio": number}),
|
| 133 |
+
number == 1.0,
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
@quiet
|
| 138 |
+
def alignment_frequency_harmony(frequencies_json: str = "") -> str:
|
| 139 |
+
"""analyse_frequency_harmony. Provenance: cited.
|
| 140 |
+
|
| 141 |
+
fundamental_hz is omitted, so the function uses its own FUNDAMENTAL_HZ.
|
| 142 |
+
The default map is the six pillar frequencies in test_harmonic_math. That
|
| 143 |
+
fixture is not a live market reading and not a lighthouse reading.
|
| 144 |
+
|
| 145 |
+
Args:
|
| 146 |
+
frequencies_json: JSON object of name to Hz. Empty uses that map. Label: cited.
|
| 147 |
+
"""
|
| 148 |
+
|
| 149 |
+
raw = frequencies_json.strip() or json.dumps(PILLAR_FREQUENCIES)
|
| 150 |
+
parsed = _loads(raw, dict)
|
| 151 |
+
if isinstance(parsed, str):
|
| 152 |
+
return _unavailable(parsed)
|
| 153 |
+
frequencies: dict[str, float] = {}
|
| 154 |
+
for key, value in parsed.items():
|
| 155 |
+
number = _finite(value)
|
| 156 |
+
if number is None:
|
| 157 |
+
return _unavailable(f"{key} is not a frequency")
|
| 158 |
+
frequencies[str(key)] = number
|
| 159 |
+
return _annotate(
|
| 160 |
+
_call(
|
| 161 |
+
"alignment/harmonic_resonance.py",
|
| 162 |
+
"analyse_frequency_harmony",
|
| 163 |
+
{"pillar_frequencies": frequencies},
|
| 164 |
+
),
|
| 165 |
+
frequencies == PILLAR_FREQUENCIES,
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
@quiet
|
| 170 |
+
def alignment_phase_coherence(phases_json: str = "") -> str:
|
| 171 |
+
"""compute_phase_coherence. Provenance: cited.
|
| 172 |
+
|
| 173 |
+
The default phases are the aligned triple in test_harmonic_math. That fixture
|
| 174 |
+
is not a live market reading and not a lighthouse reading.
|
| 175 |
+
|
| 176 |
+
Args:
|
| 177 |
+
phases_json: JSON list of radians. Empty uses that triple. Label: cited.
|
| 178 |
+
"""
|
| 179 |
+
|
| 180 |
+
raw = phases_json.strip() or json.dumps(ALIGNED_PHASES)
|
| 181 |
+
parsed = _loads(raw, list)
|
| 182 |
+
if isinstance(parsed, str):
|
| 183 |
+
return _unavailable(parsed)
|
| 184 |
+
phases: list[float] = []
|
| 185 |
+
for value in parsed:
|
| 186 |
+
number = _finite(value)
|
| 187 |
+
if number is None:
|
| 188 |
+
return _unavailable("phases must be numbers")
|
| 189 |
+
phases.append(number)
|
| 190 |
+
return _annotate(
|
| 191 |
+
_call(
|
| 192 |
+
"alignment/harmonic_resonance.py",
|
| 193 |
+
"compute_phase_coherence",
|
| 194 |
+
{"phases_rad": phases},
|
| 195 |
+
),
|
| 196 |
+
phases == ALIGNED_PHASES,
|
| 197 |
+
)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
@quiet
|
| 201 |
+
def alignment_derive_phase(frequency_hz: float = 528.0, t: float = 0.0, signal: str = "BUY") -> str:
|
| 202 |
+
"""derive_phase. Provenance: cited.
|
| 203 |
+
|
| 204 |
+
528 Hz is FUNDAMENTAL_HZ in harmonic_resonance.py. t is 0 so the drift term is zero.
|
| 205 |
+
BUY is the fixed example branch in derive_phase. Those defaults are not a reading.
|
| 206 |
+
BUY, SELL, and any other string are the branches already in derive_phase.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
frequency_hz: Pillar frequency in Hz. Label: cited, derive_phase.
|
| 210 |
+
t: Time in seconds. Label: cited, derive_phase.
|
| 211 |
+
signal: BUY, SELL, or another string. Label: cited, derive_phase.
|
| 212 |
+
"""
|
| 213 |
+
|
| 214 |
+
frequency = _finite(frequency_hz)
|
| 215 |
+
moment = _finite(t)
|
| 216 |
+
if frequency is None or moment is None:
|
| 217 |
+
return _unavailable("frequency_hz or t is missing")
|
| 218 |
+
if not isinstance(signal, str) or not signal.strip():
|
| 219 |
+
return _unavailable("signal is missing")
|
| 220 |
+
text = _call(
|
| 221 |
+
"alignment/harmonic_resonance.py",
|
| 222 |
+
"derive_phase",
|
| 223 |
+
{"frequency_hz": frequency, "t": moment, "signal": signal},
|
| 224 |
+
)
|
| 225 |
+
if frequency == 528.0 and moment == 0.0 and signal == "BUY":
|
| 226 |
+
return label_result(text, "aureon.alignment.harmonic_resonance.derive_phase", DERIVE_NOTE)
|
| 227 |
+
return text
|
| 228 |
+
|
| 229 |
+
|
| 230 |
+
@quiet
|
| 231 |
+
def alignment_geometric_mean(values_json: str = "") -> str:
|
| 232 |
+
"""geometric_mean. Provenance: cited.
|
| 233 |
+
|
| 234 |
+
The default is the four ones in test_harmonic_math. That fixture is not a
|
| 235 |
+
live market reading and not a lighthouse reading.
|
| 236 |
+
|
| 237 |
+
Args:
|
| 238 |
+
values_json: JSON list of numbers. Empty uses that list. Label: cited.
|
| 239 |
+
"""
|
| 240 |
+
|
| 241 |
+
raw = values_json.strip() or json.dumps(GEOMETRIC_ONES)
|
| 242 |
+
parsed = _loads(raw, list)
|
| 243 |
+
if isinstance(parsed, str):
|
| 244 |
+
return _unavailable(parsed)
|
| 245 |
+
values: list[float] = []
|
| 246 |
+
for value in parsed:
|
| 247 |
+
number = _finite(value)
|
| 248 |
+
if number is None:
|
| 249 |
+
return _unavailable("values must be numbers")
|
| 250 |
+
values.append(number)
|
| 251 |
+
return _annotate(
|
| 252 |
+
_call("alignment/harmonic_resonance.py", "geometric_mean", {"values": values}),
|
| 253 |
+
values == GEOMETRIC_ONES,
|
| 254 |
+
)
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
@quiet
|
| 258 |
+
def alignment_full_analysis(pillar_results_json: str = "", t: float = 0.0) -> str:
|
| 259 |
+
"""full_harmonic_analysis. Provenance: cited.
|
| 260 |
+
|
| 261 |
+
t is passed, so the function does not read the clock. The default stack is the
|
| 262 |
+
perfect six-pillar stack in test_harmonic_math, including frequency_hz 528.
|
| 263 |
+
lighthouse_cleared, dominant_signal, and alignment_score from that fixture
|
| 264 |
+
are not a live market reading and not a lighthouse reading.
|
| 265 |
+
|
| 266 |
+
Args:
|
| 267 |
+
pillar_results_json: JSON list of pillar result objects. Empty uses that stack. Label: cited.
|
| 268 |
+
t: Time passed to full_harmonic_analysis. Label: cited.
|
| 269 |
+
"""
|
| 270 |
+
|
| 271 |
+
moment = _finite(t)
|
| 272 |
+
if moment is None:
|
| 273 |
+
return _unavailable("t is missing")
|
| 274 |
+
raw = pillar_results_json.strip() or json.dumps(PERFECT_STACK)
|
| 275 |
+
parsed = _loads(raw, list)
|
| 276 |
+
if isinstance(parsed, str):
|
| 277 |
+
return _unavailable(parsed)
|
| 278 |
+
if not all(isinstance(item, dict) for item in parsed):
|
| 279 |
+
return _unavailable("pillar_results must be a list of objects")
|
| 280 |
+
return _annotate(
|
| 281 |
+
_call(
|
| 282 |
+
"alignment/harmonic_resonance.py",
|
| 283 |
+
"full_harmonic_analysis",
|
| 284 |
+
{"pillar_results": parsed, "t": moment},
|
| 285 |
+
),
|
| 286 |
+
moment == 0.0 and parsed == PERFECT_STACK,
|
| 287 |
+
)
|
| 288 |
+
|
| 289 |
+
|
| 290 |
+
@quiet
|
| 291 |
+
def alignment_harmonic_to_dict() -> str:
|
| 292 |
+
"""HarmonicAnalysis.to_dict on the dataclass defaults. Provenance: cited.
|
| 293 |
+
|
| 294 |
+
The class has no constructor body. Defaults are the literals in the class.
|
| 295 |
+
lighthouse_cleared false and dominant_signal NEUTRAL are those defaults, not a reading.
|
| 296 |
+
No pillar agent is built.
|
| 297 |
+
|
| 298 |
+
Args:
|
| 299 |
+
none: This tool takes no inputs. Label: cited, HarmonicAnalysis.to_dict.
|
| 300 |
+
"""
|
| 301 |
+
|
| 302 |
+
return label_result(
|
| 303 |
+
_call("alignment/harmonic_resonance.py", "HarmonicAnalysis.to_dict", {}),
|
| 304 |
+
"aureon.alignment.harmonic_resonance.HarmonicAnalysis",
|
| 305 |
+
DEFAULTS_NOTE,
|
| 306 |
+
)
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
@quiet
|
| 310 |
+
def alignment_cycle_to_dict(cycle_id: str = "fixed", timestamp: float = 0.0) -> str:
|
| 311 |
+
"""AlignmentCycleResult.to_dict with a fixed id and timestamp. Provenance: cited.
|
| 312 |
+
|
| 313 |
+
The dataclass defaults would call uuid and the clock. Those arguments are passed
|
| 314 |
+
so this call does not. Other fields stay the dataclass defaults and are not a reading.
|
| 315 |
+
|
| 316 |
+
Args:
|
| 317 |
+
cycle_id: Passed as the constructor cycle_id. Label: cited.
|
| 318 |
+
timestamp: Passed as the constructor timestamp. Label: cited.
|
| 319 |
+
"""
|
| 320 |
+
|
| 321 |
+
moment = _finite(timestamp)
|
| 322 |
+
if moment is None or not isinstance(cycle_id, str) or not cycle_id:
|
| 323 |
+
return _unavailable("cycle_id or timestamp is missing")
|
| 324 |
+
text = _call(
|
| 325 |
+
"alignment/pillar_alignment.py",
|
| 326 |
+
"AlignmentCycleResult.to_dict",
|
| 327 |
+
{"init": {"cycle_id": cycle_id, "timestamp": moment}},
|
| 328 |
+
)
|
| 329 |
+
if cycle_id == "fixed" and moment == 0.0:
|
| 330 |
+
return label_result(text, "aureon.alignment.pillar_alignment.AlignmentCycleResult", DEFAULTS_NOTE)
|
| 331 |
+
return text
|
| 332 |
+
|
| 333 |
+
|
| 334 |
+
@quiet
|
| 335 |
+
def alignment_directive_to_dict(directive_id: str = "fixed", timestamp: float = 0.0) -> str:
|
| 336 |
+
"""MasterDirective.to_dict with a fixed id and timestamp. Provenance: cited.
|
| 337 |
+
|
| 338 |
+
The dataclass defaults would call uuid and the clock. Those arguments are passed
|
| 339 |
+
so this call does not. Other fields stay the dataclass defaults, including
|
| 340 |
+
dominant_frequency_hz = FUNDAMENTAL_HZ, and are not a reading.
|
| 341 |
+
|
| 342 |
+
Args:
|
| 343 |
+
directive_id: Passed as the constructor directive_id. Label: cited.
|
| 344 |
+
timestamp: Passed as the constructor timestamp. Label: cited.
|
| 345 |
+
"""
|
| 346 |
+
|
| 347 |
+
moment = _finite(timestamp)
|
| 348 |
+
if moment is None or not isinstance(directive_id, str) or not directive_id:
|
| 349 |
+
return _unavailable("directive_id or timestamp is missing")
|
| 350 |
+
text = _call(
|
| 351 |
+
"alignment/unified_directive.py",
|
| 352 |
+
"MasterDirective.to_dict",
|
| 353 |
+
{"init": {"directive_id": directive_id, "timestamp": moment}},
|
| 354 |
+
)
|
| 355 |
+
if directive_id == "fixed" and moment == 0.0:
|
| 356 |
+
return label_result(text, "aureon.alignment.unified_directive.MasterDirective", DEFAULTS_NOTE)
|
| 357 |
+
return text
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
@quiet
|
| 361 |
+
def alignment_pillar_factory() -> str:
|
| 362 |
+
"""get_pillar_alignment. Provenance: cited.
|
| 363 |
+
|
| 364 |
+
The function's own default config sets auto_load_pillars false, so this call
|
| 365 |
+
does not load pillar agents. The constructor still runs its thought-bus wire.
|
| 366 |
+
If that call fails, the result is unavailable. No order is sent.
|
| 367 |
+
|
| 368 |
+
Args:
|
| 369 |
+
none: This tool takes no inputs. Label: cited, get_pillar_alignment.
|
| 370 |
+
"""
|
| 371 |
+
|
| 372 |
+
return _call("alignment/pillar_alignment.py", "get_pillar_alignment", {})
|
| 373 |
+
|
| 374 |
+
|
| 375 |
+
TOOLS: list[Any] = [
|
| 376 |
+
alignment_signal_consensus,
|
| 377 |
+
alignment_consonance_read,
|
| 378 |
+
alignment_frequency_harmony,
|
| 379 |
+
alignment_phase_coherence,
|
| 380 |
+
alignment_derive_phase,
|
| 381 |
+
alignment_geometric_mean,
|
| 382 |
+
alignment_full_analysis,
|
| 383 |
+
alignment_harmonic_to_dict,
|
| 384 |
+
alignment_cycle_to_dict,
|
| 385 |
+
alignment_directive_to_dict,
|
| 386 |
+
alignment_pillar_factory,
|
| 387 |
+
]
|
alignment_measure.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""One stdio session that calls the alignment tools. Writes raw JSON.
|
| 2 |
+
|
| 3 |
+
Run from measured/aureon_public_alignment_run.sh. Do not hand-edit the output.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import argparse
|
| 9 |
+
import asyncio
|
| 10 |
+
import importlib.metadata
|
| 11 |
+
import inspect
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import sys
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
from typing import Any
|
| 17 |
+
|
| 18 |
+
from mcp import ClientSession, StdioServerParameters
|
| 19 |
+
from mcp.client.stdio import stdio_client
|
| 20 |
+
|
| 21 |
+
from aureon_public import paths
|
| 22 |
+
from aureon_public.alignment_layer import TOOLS
|
| 23 |
+
from aureon_public.guard_loader import apply_space_guard
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _text_content(result: Any) -> str:
|
| 27 |
+
parts = []
|
| 28 |
+
for block in result.content:
|
| 29 |
+
text = getattr(block, "text", None)
|
| 30 |
+
if text is not None:
|
| 31 |
+
parts.append(text)
|
| 32 |
+
return "\n".join(parts)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _defaults(fn: Any) -> dict[str, Any]:
|
| 36 |
+
signature = inspect.signature(fn)
|
| 37 |
+
arguments = {}
|
| 38 |
+
for name, param in signature.parameters.items():
|
| 39 |
+
if param.default is inspect.Parameter.empty:
|
| 40 |
+
continue
|
| 41 |
+
if param.default == "":
|
| 42 |
+
continue
|
| 43 |
+
arguments[name] = param.default
|
| 44 |
+
return arguments
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _environment() -> dict[str, Any]:
|
| 48 |
+
apply_space_guard()
|
| 49 |
+
import aureon
|
| 50 |
+
|
| 51 |
+
direct = None
|
| 52 |
+
try:
|
| 53 |
+
dist = importlib.metadata.distribution("aureon")
|
| 54 |
+
raw = dist.read_text("direct_url.json")
|
| 55 |
+
direct = json.loads(raw) if raw else None
|
| 56 |
+
except Exception as exc: # noqa: BLE001 - the record should say the pin was not readable
|
| 57 |
+
direct = {"error": type(exc).__name__}
|
| 58 |
+
from aureon_public.measurement_stamp import measurement_stamp
|
| 59 |
+
|
| 60 |
+
return {
|
| 61 |
+
"aureon_direct_url": direct,
|
| 62 |
+
"aureon_file": aureon.__file__,
|
| 63 |
+
"python": sys.executable,
|
| 64 |
+
**measurement_stamp(),
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
async def _session(out_path: Path) -> dict[str, Any]:
|
| 69 |
+
env = {
|
| 70 |
+
"PATH": os.environ.get("PATH", ""),
|
| 71 |
+
"HOME": os.environ.get("HOME", ""),
|
| 72 |
+
"PYTHONUNBUFFERED": "1",
|
| 73 |
+
}
|
| 74 |
+
params = StdioServerParameters(
|
| 75 |
+
command=sys.executable,
|
| 76 |
+
args=["-m", "aureon_public"],
|
| 77 |
+
env=env,
|
| 78 |
+
cwd=str(Path.cwd()),
|
| 79 |
+
)
|
| 80 |
+
async with stdio_client(params) as (read, write):
|
| 81 |
+
async with ClientSession(read, write) as session:
|
| 82 |
+
await session.initialize()
|
| 83 |
+
calls = {}
|
| 84 |
+
for fn in TOOLS:
|
| 85 |
+
arguments = _defaults(fn)
|
| 86 |
+
result = await session.call_tool(fn.__name__, arguments)
|
| 87 |
+
text = _text_content(result)
|
| 88 |
+
record_call = {
|
| 89 |
+
"arguments": arguments,
|
| 90 |
+
"isError": result.isError,
|
| 91 |
+
"text": text,
|
| 92 |
+
}
|
| 93 |
+
try:
|
| 94 |
+
body = json.loads(text)
|
| 95 |
+
except json.JSONDecodeError:
|
| 96 |
+
body = None
|
| 97 |
+
if isinstance(body, dict) and body.get("input_source"):
|
| 98 |
+
record_call["input_note"] = body.get("input_note")
|
| 99 |
+
record_call["input_source"] = body["input_source"]
|
| 100 |
+
calls[fn.__name__] = record_call
|
| 101 |
+
record = {"calls": calls, "environment": _environment()}
|
| 102 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 103 |
+
out_path.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 104 |
+
return record
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def main(argv: list[str] | None = None) -> None:
|
| 108 |
+
parser = argparse.ArgumentParser(prog="aureon-public-alignment-measure")
|
| 109 |
+
parser.add_argument(
|
| 110 |
+
"--out",
|
| 111 |
+
type=Path,
|
| 112 |
+
default=paths.repo_root() / "measured" / "aureon_public_alignment.json",
|
| 113 |
+
)
|
| 114 |
+
args = par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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Address every inventoried entry point without registering thousands of tools.
|
| 2 |
+
|
| 3 |
+
`body_call` runs a real function or method. `body_surface` reads a module or
|
| 4 |
+
class and does not construct it. Depth is the count of calls, not the count
|
| 5 |
+
of rows in the plan. A helper label is not used here.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import ast
|
| 11 |
+
import hashlib
|
| 12 |
+
import inspect
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import re
|
| 16 |
+
import signal
|
| 17 |
+
import subprocess
|
| 18 |
+
import sys
|
| 19 |
+
import tempfile
|
| 20 |
+
import threading
|
| 21 |
+
from datetime import date
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
from typing import Any
|
| 24 |
+
|
| 25 |
+
from aureon_public.guard_loader import PINNED_COMMIT, apply_space_guard, aureon_source
|
| 26 |
+
from aureon_public.paths import repo_root
|
| 27 |
+
from aureon_public.pin_blob import checkout_blob_refusal, load_checkout_module
|
| 28 |
+
from aureon_public.quiet import quiet
|
| 29 |
+
from aureon_public.tools import _dumps
|
| 30 |
+
|
| 31 |
+
# Stages 1-6 raise this as each stage commit lands. Stage 7 is packaging.
|
| 32 |
+
ENABLED_THROUGH = 6
|
| 33 |
+
# Plan stages from coverage_plan.stage_for. Stages above this are refused
|
| 34 |
+
# before a worker starts, until a later run opens them.
|
| 35 |
+
OPEN_PLAN_THROUGH = 2
|
| 36 |
+
|
| 37 |
+
_UNSAFE_NAME = re.compile(
|
| 38 |
+
r"(run_|start_|stop_|launch_|serve|main$|^demo$|create_app|activate_|connect_|"
|
| 39 |
+
r"publish_|write_|save_|download_|fetch_|notify_|reset_|discover_|simulate_|"
|
| 40 |
+
r"audit_|ingest_|record_|wire_|print_|benchmark|forever|continuous|^analyze|demo_)",
|
| 41 |
+
re.I,
|
| 42 |
+
)
|
| 43 |
+
_SKIP_WORD = re.compile(
|
| 44 |
+
r"price|live_|kraken|order|exchange|network|socket|download|schumann|biometric|trade|wallet|secret|"
|
| 45 |
+
r"thought_bus|redis|postgres|sqlite|calibration|^evaluate_|^observe$|"
|
| 46 |
+
r"feed_hub|ws_feed|space_weather|news_signal|coordinator|seer_vision|lyra",
|
| 47 |
+
re.I,
|
| 48 |
+
)
|
| 49 |
+
_UNSAFE_SOURCE = (
|
| 50 |
+
"requests",
|
| 51 |
+
"urlopen",
|
| 52 |
+
"httpx",
|
| 53 |
+
"socket",
|
| 54 |
+
"subprocess",
|
| 55 |
+
"write_text",
|
| 56 |
+
"write_bytes",
|
| 57 |
+
"serve_forever",
|
| 58 |
+
"SystemExit",
|
| 59 |
+
"os._exit",
|
| 60 |
+
"os.system",
|
| 61 |
+
"sqlite",
|
| 62 |
+
"execute(",
|
| 63 |
+
"open(",
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
_BLOCKED = {
|
| 67 |
+
"trading",
|
| 68 |
+
"exchanges",
|
| 69 |
+
"bots",
|
| 70 |
+
"bots_intelligence",
|
| 71 |
+
"bridges",
|
| 72 |
+
"scanners",
|
| 73 |
+
"unified_margin_trader",
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
_AURIS = {
|
| 77 |
+
"QueenHiveMind.read_auris_nodes": "nine nodes",
|
| 78 |
+
"QueenHiveMind.get_auris_coherence": "coherence evaluator",
|
| 79 |
+
"evaluate_auris_nodes": "evaluation harness over brain proof, not the nine-node reader and not the conjecture",
|
| 80 |
+
"get_auris_voice_filter": "harmonic AurisVoiceFilter",
|
| 81 |
+
"reset_auris_voice_filter": "harmonic AurisVoiceFilter",
|
| 82 |
+
"AurisVoiceFilter": "harmonic AurisVoiceFilter",
|
| 83 |
+
"AurisValidator": "validator",
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
_ROWS: list[dict[str, Any]] | None = None
|
| 87 |
+
_INDEX: dict[tuple[str, str], dict[str, Any]] | None = None
|
| 88 |
+
_INVENTORY_REFUSAL: str | None = None
|
| 89 |
+
# sha256 of the committed docs/mcp/inventory.json. A different file is not loaded.
|
| 90 |
+
INVENTORY_SHA256 = "4bc19ea9b5444a7b8a9abbd3fabf635d083bd25bea6c1b2d6eab2605b4f5716b"
|
| 91 |
+
_LEAKY_PARAMS = {"url", "path", "out", "file", "host"}
|
| 92 |
+
# Operator-scoped rows are refused unless named here. No portfolio or accounting key reader.
|
| 93 |
+
_OPERATOR_ALLOWLIST = {
|
| 94 |
+
("accounting/file_drop.py", "registered_ingestors"),
|
| 95 |
+
("portfolio/aureon_billion_goal_tracker.py", "get_days_remaining"),
|
| 96 |
+
}
|
| 97 |
+
# These stay off body_call. compose_repository_layers finds sibling checkouts
|
| 98 |
+
# at parents[3] and execs them outside the pin. build_lane("fintech") imports
|
| 99 |
+
# the in-house adapter through the accounting package.
|
| 100 |
+
_UNTESTED_STAGE2 = "untested stage-2 entry point is not called"
|
| 101 |
+
_ENTRY_REFUSAL = {
|
| 102 |
+
("organism/repository_layers.py", "compose_repository_layers"): (
|
| 103 |
+
"stage 4 entry point is not called"
|
| 104 |
+
),
|
| 105 |
+
("swarm/capability_grid.py", "build_lane"): "stage 4 entry point is not called",
|
| 106 |
+
# Reachable through body_call, and not a tested tool. The real argument
|
| 107 |
+
# is an object the constructor allowlist does not include.
|
| 108 |
+
("decoders/book_of_ur.py", "test_phi_resonance_me"): _UNTESTED_STAGE2,
|
| 109 |
+
("observer/momentum.py", "set_momentum_tracker"): _UNTESTED_STAGE2,
|
| 110 |
+
("observer/predictor.py", "make_predictor"): _UNTESTED_STAGE2,
|
| 111 |
+
("observer/wave_predictor.py", "set_wave_predictor"): _UNTESTED_STAGE2,
|
| 112 |
+
("observer/wave_predictor.py", "make_predictor"): _UNTESTED_STAGE2,
|
| 113 |
+
("observer/live_data_policy.py", "log_blocked_fallback"): (
|
| 114 |
+
"fallback log is not emitted for an event that did not happen"
|
| 115 |
+
),
|
| 116 |
+
("swarm/agent.py", "SwarmAgent.purity"): (
|
| 117 |
+
"property is not called; the worker calls methods"
|
| 118 |
+
),
|
| 119 |
+
("swarm/coherence.py", "ClusterCoherence.warm"): (
|
| 120 |
+
"property is not called; the worker calls methods"
|
| 121 |
+
),
|
| 122 |
+
("swarm/memory_bus.py", "CausalEchoBus.possibilities"): (
|
| 123 |
+
"one call cannot park an ensemble and read it"
|
| 124 |
+
),
|
| 125 |
+
("swarm/auris_node_receipts.py", "issue_auris_node_receipt"): (
|
| 126 |
+
"trusted resolver is not built from JSON"
|
| 127 |
+
),
|
| 128 |
+
("swarm/auris_node_receipts.py", "validate_auris_node_receipt"): (
|
| 129 |
+
"receipt is assembled by the test harness; the public result cap would drop its fields"
|
| 130 |
+
),
|
| 131 |
+
("swarm/auris_node_receipts.py", "validate_hnc_evidence"): (
|
| 132 |
+
"receipt is assembled by the test harness; the public result cap would drop its fields"
|
| 133 |
+
),
|
| 134 |
+
("swarm/auris_node_receipts.py", "validate_provider_moment"): (
|
| 135 |
+
"receipt is assembled by the test harness; the public result cap would drop its fields"
|
| 136 |
+
),
|
| 137 |
+
("swarm/druidic_council.py", "validate_council_receipt"): (
|
| 138 |
+
"receipt is assembled by the test harness; the public result cap would drop its fields"
|
| 139 |
+
),
|
| 140 |
+
("swarm/druidic_council.py", "validate_seat_receipt"): (
|
| 141 |
+
"receipt is assembled by the test harness; the public result cap would drop its fields"
|
| 142 |
+
),
|
| 143 |
+
}
|
| 144 |
+
# A method call constructs its class. An unlisted constructor is not run.
|
| 145 |
+
# The risk scan still runs. PillarAlignment, UnifiedHarmonicDirective, and the
|
| 146 |
+
# swarm classes that need nested agent instances stay off this list.
|
| 147 |
+
_CONSTRUCTOR_ALLOWLIST: set[tuple[str, str]] = {
|
| 148 |
+
("alignment/harmonic_resonance.py", "HarmonicAnalysis"),
|
| 149 |
+
("alignment/pillar_alignment.py", "AlignmentCycleResult"),
|
| 150 |
+
("alignment/unified_directive.py", "MasterDirective"),
|
| 151 |
+
("generated/research_cinema/harmonic_nexus_score_model.py", "HarmonicNexusScoreInputs"),
|
| 152 |
+
("swarm/agent.py", "SwarmAgent"),
|
| 153 |
+
("swarm/coherence.py", "ClusterCoherence"),
|
| 154 |
+
("swarm/druidic_council.py", "CouncilReceipt"),
|
| 155 |
+
("swarm/druidic_council.py", "SeatReceipt"),
|
| 156 |
+
("swarm/memory_bus.py", "CausalEchoBus"),
|
| 157 |
+
("swarm/queen_gate.py", "Actualization"),
|
| 158 |
+
("swarm/steering.py", "SteeringField"),
|
| 159 |
+
}
|
| 160 |
+
_NAME_CONTAINS = ("write", "save", "export", "dump", "start", "run")
|
| 161 |
+
_WORKER_SLOTS = threading.BoundedSemaphore(4)
|
| 162 |
+
WORKER_WAIT_SECONDS = 10.0
|
| 163 |
+
WORKER_REAP_SECONDS = 2.0
|
| 164 |
+
|
| 165 |
+
|
| 166 |
+
def enabled_stage() -> int:
|
| 167 |
+
return ENABLED_THROUGH
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def _inventory() -> tuple[list[dict[str, Any]], dict[tuple[str, str], dict[str, Any]]]:
|
| 171 |
+
global _ROWS, _INDEX, _INVENTORY_REFUSAL
|
| 172 |
+
if _ROWS is not None and _INDEX is not None:
|
| 173 |
+
return _ROWS, _INDEX
|
| 174 |
+
path = repo_root() / "docs" / "mcp" / "inventory.json"
|
| 175 |
+
data = path.read_bytes()
|
| 176 |
+
digest = hashlib.sha256(data).hexdigest()
|
| 177 |
+
if digest != INVENTORY_SHA256:
|
| 178 |
+
_INVENTORY_REFUSAL = "inventory hash mismatch"
|
| 179 |
+
_ROWS = []
|
| 180 |
+
_INDEX = {}
|
| 181 |
+
return _ROWS, _INDEX
|
| 182 |
+
_INVENTORY_REFUSAL = None
|
| 183 |
+
loaded = json.loads(data)
|
| 184 |
+
if not isinstance(loaded, list):
|
| 185 |
+
_INVENTORY_REFUSAL = "inventory hash mismatch"
|
| 186 |
+
_ROWS = []
|
| 187 |
+
_INDEX = {}
|
| 188 |
+
return _ROWS, _INDEX
|
| 189 |
+
index: dict[tuple[str, str], dict[str, Any]] = {}
|
| 190 |
+
for row in loaded:
|
| 191 |
+
index.setdefault((row["module"], row["symbol"]), row)
|
| 192 |
+
_ROWS = loaded
|
| 193 |
+
_INDEX = index
|
| 194 |
+
return _ROWS, _INDEX
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def lookup(module: str, symbol: str) -> dict[str, Any] | None:
|
| 198 |
+
_, index = _inventory()
|
| 199 |
+
return index.get((module, symbol))
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def file_for(module: str) -> Path:
|
| 203 |
+
root = repo_root()
|
| 204 |
+
if module.startswith("unified_margin_trader/"):
|
| 205 |
+
return root / module
|
| 206 |
+
return root / "aureon" / module
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
def dotted_for(module: str) -> str:
|
| 210 |
+
if module.startswith("unified_margin_trader/"):
|
| 211 |
+
relative = module
|
| 212 |
+
else:
|
| 213 |
+
relative = "aureon/" + module
|
| 214 |
+
return ".".join(Path(relative).with_suffix("").parts)
|
| 215 |
+
|
| 216 |
+
|
| 217 |
+
def _outside(origin: Path, root: Path) -> bool:
|
| 218 |
+
resolved = origin.resolve()
|
| 219 |
+
root_resolved = root.resolve()
|
| 220 |
+
return resolved != root_resolved and root_resolved not in resolved.parents
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def _blocked_dotted_prefix(dotted: str) -> str | None:
|
| 224 |
+
parts = dotted.split(".")
|
| 225 |
+
if parts[0] in _BLOCKED:
|
| 226 |
+
return f"package {parts[0]} is not importable"
|
| 227 |
+
if parts[0] == "aureon" and len(parts) > 1 and parts[1] in _BLOCKED:
|
| 228 |
+
return f"package {parts[1]} is not importable"
|
| 229 |
+
return None
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def _plain(value: Any, depth: int = 0) -> Any:
|
| 233 |
+
if depth > 4:
|
| 234 |
+
return type(value).__name__
|
| 235 |
+
if value is None or isinstance(value, (str, int, float, bool)):
|
| 236 |
+
if isinstance(value, float) and value != value:
|
| 237 |
+
return None
|
| 238 |
+
if isinstance(value, str):
|
| 239 |
+
return value[:500]
|
| 240 |
+
return value
|
| 241 |
+
if isinstance(value, dict):
|
| 242 |
+
return {str(key): _plain(item, depth + 1) for key, item in list(value.items())[:30]}
|
| 243 |
+
if isinstance(value, (list, tuple)):
|
| 244 |
+
return [_plain(item, depth + 1) for item in list(value)[:30]]
|
| 245 |
+
if hasattr(value, "to_dict") and callable(value.to_dict):
|
| 246 |
+
try:
|
| 247 |
+
return _plain(value.to_dict(), depth + 1)
|
| 248 |
+
except Exception:
|
| 249 |
+
pass
|
| 250 |
+
if hasattr(value, "__dict__") and not isinstance(value, type):
|
| 251 |
+
fields = {key: item for key, item in vars(value).items() if not str(key).startswith("_")}
|
| 252 |
+
return {"type": type(value).__name__, "fields": _plain(fields, depth + 1)}
|
| 253 |
+
return {"type": type(value).__name__}
|
| 254 |
+
|
| 255 |
+
|
| 256 |
+
def _result(payload: dict[str, Any]) -> str:
|
| 257 |
+
payload.setdefault("provenance", "cited")
|
| 258 |
+
text = _dumps(payload)
|
| 259 |
+
if len(text) > 8000:
|
| 260 |
+
payload = {
|
| 261 |
+
"called": payload.get("called"),
|
| 262 |
+
"label": payload.get("label"),
|
| 263 |
+
"provenance": payload.get("provenance", "cited"),
|
| 264 |
+
"status": payload.get("status"),
|
| 265 |
+
"truncated": True,
|
| 266 |
+
}
|
| 267 |
+
text = _dumps(payload)
|
| 268 |
+
return text
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def _unavailable(reason: str, **extra: Any) -> str:
|
| 272 |
+
body = {"label": "cited. Not called.", "reason": reason, "status": "unavailable"}
|
| 273 |
+
body.update(extra)
|
| 274 |
+
return _result(body)
|
| 275 |
+
|
| 276 |
+
|
| 277 |
+
def _refused(reason: str) -> str:
|
| 278 |
+
return _unavailable(reason, live_orders="refused")
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
def _function_source(module: str, symbol: str) -> str:
|
| 282 |
+
path = file_for(module)
|
| 283 |
+
if not path.is_file():
|
| 284 |
+
return ""
|
| 285 |
+
try:
|
| 286 |
+
text = path.read_text(encoding="utf-8", errors="replace")
|
| 287 |
+
tree = ast.parse(text)
|
| 288 |
+
except (OSError, SyntaxError):
|
| 289 |
+
return ""
|
| 290 |
+
lines = text.splitlines()
|
| 291 |
+
class_name, _, method_name = symbol.partition(".")
|
| 292 |
+
nodes: list[ast.AST] = list(tree.body)
|
| 293 |
+
target = symbol
|
| 294 |
+
if method_name:
|
| 295 |
+
target = method_name
|
| 296 |
+
nodes = []
|
| 297 |
+
for node in tree.body:
|
| 298 |
+
if isinstance(node, ast.ClassDef) and node.name == class_name:
|
| 299 |
+
nodes = list(node.body)
|
| 300 |
+
break
|
| 301 |
+
for node in nodes:
|
| 302 |
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name == target:
|
| 303 |
+
end = node.end_lineno or node.lineno
|
| 304 |
+
return "\n".join(lines[node.lineno - 1 : end])
|
| 305 |
+
return ""
|
| 306 |
+
|
| 307 |
+
|
| 308 |
+
def _parameter_names(module: str, symbol: str) -> list[str] | None:
|
| 309 |
+
"""Named parameters from the AST. None when the function cannot be found."""
|
| 310 |
+
|
| 311 |
+
path = file_for(module)
|
| 312 |
+
if not path.is_file():
|
| 313 |
+
return None
|
| 314 |
+
try:
|
| 315 |
+
tree = ast.parse(path.read_text(encoding="utf-8", errors="replace"))
|
| 316 |
+
except (OSError, SyntaxError):
|
| 317 |
+
return None
|
| 318 |
+
class_name, _, method_name = symbol.partition(".")
|
| 319 |
+
nodes: list[ast.AST] = list(tree.body)
|
| 320 |
+
target = symbol
|
| 321 |
+
if method_name:
|
| 322 |
+
target = method_name
|
| 323 |
+
nodes = []
|
| 324 |
+
for node in tree.body:
|
| 325 |
+
if isinstance(node, ast.ClassDef) and node.name == class_name:
|
| 326 |
+
nodes = list(node.body)
|
| 327 |
+
break
|
| 328 |
+
for node in nodes:
|
| 329 |
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and node.name == target:
|
| 330 |
+
names = [
|
| 331 |
+
item.arg
|
| 332 |
+
for item in (*node.args.posonlyargs, *node.args.args, *node.args.kwonlyargs)
|
| 333 |
+
if item.arg not in {"self", "cls"}
|
| 334 |
+
]
|
| 335 |
+
return names
|
| 336 |
+
return None
|
| 337 |
+
|
| 338 |
+
|
| 339 |
+
def _leaky_parameter(module: str, symbol: str) -> bool:
|
| 340 |
+
names = _parameter_names(module, symbol)
|
| 341 |
+
if names is None:
|
| 342 |
+
return True
|
| 343 |
+
for name in names:
|
| 344 |
+
parts = name.lower().split("_")
|
| 345 |
+
if any(part in _LEAKY_PARAMS for part in parts):
|
| 346 |
+
return True
|
| 347 |
+
return False
|
| 348 |
+
|
| 349 |
+
|
| 350 |
+
def _name_blocked(symbol: str) -> str | None:
|
| 351 |
+
leaf = symbol.rsplit(".", 1)[-1]
|
| 352 |
+
if "run_humaneval" in symbol.lower():
|
| 353 |
+
return "run_humaneval is not called"
|
| 354 |
+
if _UNSAFE_NAME.search(leaf) or _SKIP_WORD.search(leaf):
|
| 355 |
+
return "name is not called on the public server"
|
| 356 |
+
lowered = leaf.lower()
|
| 357 |
+
for token in _NAME_CONTAINS:
|
| 358 |
+
if token in lowered:
|
| 359 |
+
return f"name contains {token}"
|
| 360 |
+
return None
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def _package_kind(package: str) -> str:
|
| 364 |
+
import aureon_public.more_layers # noqa: F401 - applies the excluded kinds
|
| 365 |
+
|
| 366 |
+
from aureon_public.layers import PACKAGES
|
| 367 |
+
|
| 368 |
+
for row in PACKAGES:
|
| 369 |
+
if row["package"] == package:
|
| 370 |
+
return row["kind"]
|
| 371 |
+
return ""
|
| 372 |
+
|
| 373 |
+
|
| 374 |
+
def _quiet_source(module: str, symbol: str) -> bool:
|
| 375 |
+
source = _function_source(module, symbol)
|
| 376 |
+
if not source:
|
| 377 |
+
return False
|
| 378 |
+
return not any(token in source for token in _UNSAFE_SOURCE)
|
| 379 |
+
|
| 380 |
+
|
| 381 |
+
def _coerce(fn: Any, kwargs: dict[str, Any]) -> dict[str, Any]:
|
| 382 |
+
try:
|
| 383 |
+
signature = inspect.signature(fn)
|
| 384 |
+
except (TypeError, ValueError):
|
| 385 |
+
return kwargs
|
| 386 |
+
coerced = dict(kwargs)
|
| 387 |
+
for name, value in list(coerced.items()):
|
| 388 |
+
param = signature.parameters.get(name)
|
| 389 |
+
if param is None:
|
| 390 |
+
continue
|
| 391 |
+
annotation = param.annotation
|
| 392 |
+
origin = getattr(annotation, "__origin__", None)
|
| 393 |
+
name_of = annotation if isinstance(annotation, str) else getattr(annotation, "__name__", "")
|
| 394 |
+
if (annotation is date or name_of == "date" or str(name_of).endswith("date")) and isinstance(value, str):
|
| 395 |
+
coerced[name] = date.fromisoformat(value)
|
| 396 |
+
elif (annotation is frozenset or origin is frozenset) and isinstance(value, list):
|
| 397 |
+
coerced[name] = frozenset(value)
|
| 398 |
+
return coerced
|
| 399 |
+
|
| 400 |
+
|
| 401 |
+
def _required_missing(fn: Any, kwargs: dict[str, Any]) -> str | None:
|
| 402 |
+
try:
|
| 403 |
+
signature = inspect.signature(fn)
|
| 404 |
+
except (TypeError, ValueError):
|
| 405 |
+
return None
|
| 406 |
+
try:
|
| 407 |
+
signature.bind(**kwargs)
|
| 408 |
+
except TypeError as exc:
|
| 409 |
+
return str(exc)
|
| 410 |
+
return None
|
| 411 |
+
|
| 412 |
+
|
| 413 |
+
def _checkout_load(module: str) -> str | None:
|
| 414 |
+
"""Hash-check the target file. The worker loads parents through the finder.
|
| 415 |
+
|
| 416 |
+
``find_spec`` is not used. It would import parent packages before the blob check.
|
| 417 |
+
"""
|
| 418 |
+
|
| 419 |
+
return checkout_blob_refusal(file_for(module), repo_root(), PINNED_COMMIT)
|
| 420 |
+
|
| 421 |
+
|
| 422 |
+
# Filled only when AUREON_PUBLIC_REPORT_MODULES=1 is copied into the worker.
|
| 423 |
+
# The count is how many worker results included a modules list, including an empty one.
|
| 424 |
+
reported_worker_modules: list[str] = []
|
| 425 |
+
reported_worker_module_reports = 0
|
| 426 |
+
# Last worker sweep block. Set only while this process is measuring.
|
| 427 |
+
last_sweep_report: dict[str, Any] | None = None
|
| 428 |
+
# In-process only. The environment and a client cannot set this.
|
| 429 |
+
_sweep_measuring = False
|
| 430 |
+
|
| 431 |
+
|
| 432 |
+
def enable_sweep_measurement() -> None:
|
| 433 |
+
"""Let this process call past the call-sweep gate. Not an environment switch."""
|
| 434 |
+
|
| 435 |
+
global _sweep_measuring
|
| 436 |
+
_sweep_measuring = True
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
def _worker_env() -> dict[str, str]:
|
| 440 |
+
"""Minimal child environment. Parent secrets and extras are not copied across."""
|
| 441 |
+
|
| 442 |
+
package_root = str(Path(__file__).resolve().parents[1])
|
| 443 |
+
env: dict[str, str] = {
|
| 444 |
+
"PATH": os.environ.get("PATH", ""),
|
| 445 |
+
"HOME": os.environ.get("HOME", ""),
|
| 446 |
+
"TMPDIR": os.environ.get("TMPDIR", "") or tempfile.gettempdir(),
|
| 447 |
+
"PYTHONPATH": package_root,
|
| 448 |
+
"AUREON_AUDIT_MODE": "1",
|
| 449 |
+
"AUREON_DISABLE_REAL_ORDERS": "1",
|
| 450 |
+
"AUREON_DISABLE_LIVE_BACKGROUND_STARTUP": "1",
|
| 451 |
+
"AUREON_SUPPRESS_IMPORT_SIDE_EFFECTS": "1",
|
| 452 |
+
"AUREON_ENABLE_AUTONOMOUS_CONTROL": "0",
|
| 453 |
+
"AUREON_ACTIVATE_ON_IMPORT": "0",
|
| 454 |
+
"AUREON_OBSERVER_MODE": "dry_run",
|
| 455 |
+
}
|
| 456 |
+
for key in ("LANG", "LC_ALL", "LC_CTYPE", "PYTHONHASHSEED", "AUREON_PUBLIC_REPORT_MODULES"):
|
| 457 |
+
value = os.environ.get(key)
|
| 458 |
+
if value:
|
| 459 |
+
env[key] = value
|
| 460 |
+
if _sweep_measuring:
|
| 461 |
+
env["AUREON_PUBLIC_SWEEP"] = "1"
|
| 462 |
+
sandbox = os.environ.get("AUREON_PUBLIC_SANDBOX")
|
| 463 |
+
if sandbox:
|
| 464 |
+
env["AUREON_PUBLIC_SANDBOX"] = sandbox
|
| 465 |
+
for key in (
|
| 466 |
+
"HOME",
|
| 467 |
+
"USERPROFILE",
|
| 468 |
+
"XDG_CACHE_HOME",
|
| 469 |
+
"XDG_CONFIG_HOME",
|
| 470 |
+
"XDG_DATA_HOME",
|
| 471 |
+
"XDG_RUNTIME_DIR",
|
| 472 |
+
"XDG_STATE_HOME",
|
| 473 |
+
):
|
| 474 |
+
value = os.environ.get(key)
|
| 475 |
+
if value:
|
| 476 |
+
env[key] = value
|
| 477 |
+
return env
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
def _worker_argv() -> list[str]:
|
| 481 |
+
"""Isolated interpreter. The mcp path is argv, not cwd and not PYTHONPATH.
|
| 482 |
+
|
| 483 |
+
``-I`` implies ``-E``, ``-s``, and ``-P``, so the checkout is not on sys.path
|
| 484 |
+
and a root-level ``json.py`` or ``aureon_public`` package cannot shadow the worker.
|
| 485 |
+
"""
|
| 486 |
+
|
| 487 |
+
mcp_root = str(Path(__file__).resolve().parents[1])
|
| 488 |
+
code = (
|
| 489 |
+
"import sys\n"
|
| 490 |
+
"sys.path.insert(0, sys.argv[1])\n"
|
| 491 |
+
"from aureon_public.call_worker import main\n"
|
| 492 |
+
"main()\n"
|
| 493 |
+
)
|
| 494 |
+
return [sys.executable, "-I", "-c", code, mcp_root]
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
def _worker_cwd() -> str:
|
| 498 |
+
"""A directory outside the checkout. cwd must not become sys.path[0]."""
|
| 499 |
+
|
| 500 |
+
return tempfile.gettempdir()
|
| 501 |
+
|
| 502 |
+
|
| 503 |
+
def _acquire_worker() -> bool:
|
| 504 |
+
return _WORKER_SLOTS.acquire(timeout=WORKER_WAIT_SECONDS)
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
def _release_worker() -> None:
|
| 508 |
+
_WORKER_SLOTS.release()
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
def _call_in_subprocess(module: str, symbol: str, arguments: dict[str, Any], timeout: float) -> tuple[str, Any]:
|
| 512 |
+
"""Run the entry point in a child process. A timeout kills the process group."""
|
| 513 |
+
|
| 514 |
+
if symbol.lower().endswith(".__init__") or symbol.split(".")[-1].startswith("_"):
|
| 515 |
+
return "error", "private entry point is not called"
|
| 516 |
+
checkout_error = _checkout_load(module)
|
| 517 |
+
if checkout_error:
|
| 518 |
+
return "error", checkout_error
|
| 519 |
+
payload = json.dumps(
|
| 520 |
+
{
|
| 521 |
+
"dotted": dotted_for(module),
|
| 522 |
+
"module": module,
|
| 523 |
+
"symbol": symbol,
|
| 524 |
+
"arguments": arguments,
|
| 525 |
+
}
|
| 526 |
+
).encode("utf-8")
|
| 527 |
+
slot_acquired = False
|
| 528 |
+
try:
|
| 529 |
+
if not _acquire_worker():
|
| 530 |
+
return (
|
| 531 |
+
"busy",
|
| 532 |
+
f"live worker cap 4 not available within {WORKER_WAIT_SECONDS:g}s",
|
| 533 |
+
)
|
| 534 |
+
slot_acquired = True
|
| 535 |
+
process = subprocess.Popen(
|
| 536 |
+
_worker_argv(),
|
| 537 |
+
stdin=subprocess.PIPE,
|
| 538 |
+
stdout=subprocess.PIPE,
|
| 539 |
+
stderr=subprocess.PIPE,
|
| 540 |
+
start_new_session=True,
|
| 541 |
+
cwd=_worker_cwd(),
|
| 542 |
+
env=_worker_env(),
|
| 543 |
+
)
|
| 544 |
+
try:
|
| 545 |
+
stdout, _stderr = process.communicate(payload, timeout=timeout)
|
| 546 |
+
except subprocess.TimeoutExpired:
|
| 547 |
+
try:
|
| 548 |
+
os.killpg(process.pid, signal.SIGKILL)
|
| 549 |
+
except ProcessLookupError:
|
| 550 |
+
pass
|
| 551 |
+
try:
|
| 552 |
+
process.communicate(timeout=WORKER_REAP_SECONDS)
|
| 553 |
+
except subprocess.TimeoutExpired:
|
| 554 |
+
pass
|
| 555 |
+
return "timeout", f"exceeded {timeout:g}s"
|
| 556 |
+
if process.returncode not in {0, None}:
|
| 557 |
+
text = stdout.decode("utf-8", errors="replace").strip()
|
| 558 |
+
if not text:
|
| 559 |
+
return "error", f"worker exited {process.returncode}"
|
| 560 |
+
try:
|
| 561 |
+
body = json.loads(stdout.decode("utf-8"))
|
| 562 |
+
except json.JSONDecodeError:
|
| 563 |
+
return "error", "worker result was not JSON"
|
| 564 |
+
modules = body.get("modules") if isinstance(body, dict) else None
|
| 565 |
+
if isinstance(modules, list):
|
| 566 |
+
global reported_worker_module_reports
|
| 567 |
+
reported_worker_module_reports += 1
|
| 568 |
+
reported_worker_modules.extend(str(item) for item in modules)
|
| 569 |
+
sweep = body.get("sweep") if isinstance(body, dict) else None
|
| 570 |
+
if isinstance(sweep, dict):
|
| 571 |
+
global last_sweep_report
|
| 572 |
+
last_sweep_report = sweep
|
| 573 |
+
if body.get("ok") is True:
|
| 574 |
+
return "ok", body.get("result")
|
| 575 |
+
return "error", str(body.get("error") or "worker failed")[:240]
|
| 576 |
+
finally:
|
| 577 |
+
if slot_acquired:
|
| 578 |
+
_release_worker()
|
| 579 |
+
|
| 580 |
+
|
| 581 |
+
def _constructor_refusal(module: str, class_name: str) -> str | None:
|
| 582 |
+
from aureon_public.inventory_scan import source_is_risky
|
| 583 |
+
|
| 584 |
+
if (module, class_name) not in _CONSTRUCTOR_ALLOWLIST:
|
| 585 |
+
return "constructor is not allowlisted"
|
| 586 |
+
source = _function_source(module, f"{class_name}.__init__")
|
| 587 |
+
if source_is_risky(source):
|
| 588 |
+
return "constructor failed the risk scan"
|
| 589 |
+
return None
|
| 590 |
+
|
| 591 |
+
|
| 592 |
+
def _operator_allowlist_refusal(row: dict[str, Any]) -> str | None:
|
| 593 |
+
"""Every operator-path row must be named. Fetch and write stay closed."""
|
| 594 |
+
|
| 595 |
+
key = (str(row["module"]), str(row["symbol"]))
|
| 596 |
+
if key not in _OPERATOR_ALLOWLIST:
|
| 597 |
+
return "operator row is not allowlisted"
|
| 598 |
+
source = _function_source(str(row["module"]), str(row["symbol"]))
|
| 599 |
+
if re.search(r"api_key|secret|password|credential|private_key", source or "", re.I):
|
| 600 |
+
return "portfolio or accounting key reader is not allowlisted"
|
| 601 |
+
if row["package"] in {"portfolio", "accounting"} and re.search(
|
| 602 |
+
r"api_key|secret|password|credential|private_key", str(row["symbol"]), re.I
|
| 603 |
+
):
|
| 604 |
+
return "portfolio or accounting key reader is not allowlisted"
|
| 605 |
+
return None
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
def _import_checked(module: str) -> tuple[Any | None, str | None]:
|
| 609 |
+
"""Load a module and its parents through the pinned loader.
|
| 610 |
+
|
| 611 |
+
There is no outside-checkout fallback and no ``find_spec`` on the full name.
|
| 612 |
+
"""
|
| 613 |
+
|
| 614 |
+
apply_space_guard()
|
| 615 |
+
from aureon_public.layers import _load_phenolic_fingerprint
|
| 616 |
+
|
| 617 |
+
_load_phenolic_fingerprint()
|
| 618 |
+
path = file_for(module)
|
| 619 |
+
dotted = dotted_for(module)
|
| 620 |
+
blocked = _blocked_dotted_prefix(dotted)
|
| 621 |
+
if blocked:
|
| 622 |
+
return None, blocked
|
| 623 |
+
root = repo_root()
|
| 624 |
+
loaded, refusal = load_checkout_module(dotted, path, root, PINNED_COMMIT)
|
| 625 |
+
if refusal:
|
| 626 |
+
return None, refusal
|
| 627 |
+
return loaded, None
|
| 628 |
+
|
| 629 |
+
|
| 630 |
+
def _safety_block(row: dict[str, Any], *, allow_fetch: bool, allow_write: bool) -> str | None:
|
| 631 |
+
text = str(row.get("safety") or "")
|
| 632 |
+
if "live_orders" in text or row["package"] in _BLOCKED:
|
| 633 |
+
return "live orders are refused and the blocked import was not performed"
|
| 634 |
+
if "reads keys" in text or "personal or key" in text or "never returned" in text:
|
| 635 |
+
return "key or personal material is not read"
|
| 636 |
+
if text.startswith("process") or "UI start" in text or "loop" in text:
|
| 637 |
+
return "process and loop entry points are not started"
|
| 638 |
+
if text.startswith("writes") and not allow_write:
|
| 639 |
+
return "write entry points are not started"
|
| 640 |
+
if "write or process start" in text and not allow_write:
|
| 641 |
+
return "write or process start is refused"
|
| 642 |
+
if text.startswith("live public fetch") and not allow_fetch:
|
| 643 |
+
return "live fetch is not part of this call"
|
| 644 |
+
if "file does not parse" in text:
|
| 645 |
+
return "file does not parse"
|
| 646 |
+
return None
|
| 647 |
+
|
| 648 |
+
|
| 649 |
+
_REFUSAL_CACHE: dict[tuple[str, str], str | None] = {}
|
| 650 |
+
_PLAN_STAGE: dict[str, int] | None = None
|
| 651 |
+
_STAGE2_TABLE: dict[str, dict[str, Any]] | None = None
|
| 652 |
+
_STAGE2_MISSING = False
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
def _plan_stage(package: str) -> int:
|
| 656 |
+
"""Coverage-plan stage for a package. Unknown packages stay closed."""
|
| 657 |
+
|
| 658 |
+
global _PLAN_STAGE
|
| 659 |
+
if _PLAN_STAGE is None:
|
| 660 |
+
from collections import defaultdict
|
| 661 |
+
|
| 662 |
+
from aureon_public.coverage_plan import safety_category, stage_for
|
| 663 |
+
|
| 664 |
+
rows, _index = _inventory()
|
| 665 |
+
categories: dict[str, set[str]] = defaultdict(set)
|
| 666 |
+
for row in rows:
|
| 667 |
+
categories[str(row["package"])].add(safety_category(str(row.get("safety") or "")))
|
| 668 |
+
_PLAN_STAGE = {
|
| 669 |
+
name: stage_for(name, marks) for name, marks in categories.items()
|
| 670 |
+
}
|
| 671 |
+
return _PLAN_STAGE.get(package, 4)
|
| 672 |
+
|
| 673 |
+
|
| 674 |
+
def _stage2_table() -> dict[str, dict[str, Any]] | None:
|
| 675 |
+
"""Committed socket-blocked import sweep. None when the file is missing."""
|
| 676 |
+
|
| 677 |
+
global _STAGE2_MISSING, _STAGE2_TABLE
|
| 678 |
+
if _STAGE2_TABLE is not None or _STAGE2_MISSING:
|
| 679 |
+
return _STAGE2_TABLE
|
| 680 |
+
path = repo_root() / "measured" / "aureon_public_stage2_imports.json"
|
| 681 |
+
try:
|
| 682 |
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
| 683 |
+
except (OSError, json.JSONDecodeError):
|
| 684 |
+
_STAGE2_MISSING = True
|
| 685 |
+
return None
|
| 686 |
+
table: dict[str, dict[str, Any]] = {}
|
| 687 |
+
if isinstance(loaded, dict):
|
| 688 |
+
for row in loaded.get("modules") or []:
|
| 689 |
+
if isinstance(row, dict) and row.get("module"):
|
| 690 |
+
table[str(row["module"])] = row
|
| 691 |
+
_STAGE2_TABLE = table
|
| 692 |
+
return table
|
| 693 |
+
|
| 694 |
+
|
| 695 |
+
def _stage2_import_refusal(module: str) -> str | None:
|
| 696 |
+
table = _stage2_table()
|
| 697 |
+
if table is None:
|
| 698 |
+
return "import sweep record is missing"
|
| 699 |
+
row = table.get(module)
|
| 700 |
+
if row is None:
|
| 701 |
+
return "module is not in the import sweep"
|
| 702 |
+
if row.get("refused"):
|
| 703 |
+
return str(row.get("refusal") or "module import loads an adapter or http client")
|
| 704 |
+
return None
|
| 705 |
+
|
| 706 |
+
|
| 707 |
+
_CALL_SWEEP: dict[tuple[str, str], dict[str, Any]] | None = None
|
| 708 |
+
_CALL_SWEEP_MISSING = False
|
| 709 |
+
|
| 710 |
+
|
| 711 |
+
def _call_sweep_table() -> dict[tuple[str, str], dict[str, Any]] | None:
|
| 712 |
+
"""Per-entry-point call sweep. None when the file is missing."""
|
| 713 |
+
|
| 714 |
+
global _CALL_SWEEP, _CALL_SWEEP_MISSING
|
| 715 |
+
if _CALL_SWEEP is not None or _CALL_SWEEP_MISSING:
|
| 716 |
+
return _CALL_SWEEP
|
| 717 |
+
path = repo_root() / "measured" / "aureon_public_call_sweep.json"
|
| 718 |
+
try:
|
| 719 |
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
| 720 |
+
except (OSError, json.JSONDecodeError):
|
| 721 |
+
_CALL_SWEEP_MISSING = True
|
| 722 |
+
return None
|
| 723 |
+
table: dict[tuple[str, str], dict[str, Any]] = {}
|
| 724 |
+
if isinstance(loaded, dict):
|
| 725 |
+
for row in loaded.get("entries") or []:
|
| 726 |
+
if isinstance(row, dict) and row.get("module") and row.get("symbol"):
|
| 727 |
+
table[(str(row["module"]), str(row["symbol"]))] = row
|
| 728 |
+
_CALL_SWEEP = table
|
| 729 |
+
return table
|
| 730 |
+
|
| 731 |
+
|
| 732 |
+
def _call_sweep_refusal(module: str, symbol: str) -> str | None:
|
| 733 |
+
"""Refuse a call the sweep saw open a socket or load the banned chain.
|
| 734 |
+
|
| 735 |
+
Only ``enable_sweep_measurement`` in this process skips the gate. An
|
| 736 |
+
environment variable cannot.
|
| 737 |
+
"""
|
| 738 |
+
|
| 739 |
+
if _sweep_measuring:
|
| 740 |
+
return None
|
| 741 |
+
table = _call_sweep_table()
|
| 742 |
+
if table is None:
|
| 743 |
+
return "call sweep record is missing"
|
| 744 |
+
row = table.get((module, symbol))
|
| 745 |
+
if row is None:
|
| 746 |
+
return "entry point is not in the call sweep"
|
| 747 |
+
if row.get("refused"):
|
| 748 |
+
return str(row.get("refusal") or "call loads a banned chain or opens a connection")
|
| 749 |
+
return None
|
| 750 |
+
|
| 751 |
+
|
| 752 |
+
def public_entry_refusal(row: dict[str, Any]) -> str | None:
|
| 753 |
+
"""Why the public server will not run this row. None when it may run."""
|
| 754 |
+
|
| 755 |
+
key = (str(row.get("module") or ""), str(row.get("symbol") or ""))
|
| 756 |
+
if key in _REFUSAL_CACHE:
|
| 757 |
+
return _REFUSAL_CACHE[key]
|
| 758 |
+
reason = _public_entry_refusal(row)
|
| 759 |
+
_REFUSAL_CACHE[key] = reason
|
| 760 |
+
return reason
|
| 761 |
+
|
| 762 |
+
|
| 763 |
+
def _public_entry_refusal(row: dict[str, Any]) -> str | None:
|
| 764 |
+
if row["server"] != "public":
|
| 765 |
+
return "operator entry point is not on aureon-public"
|
| 766 |
+
if row["package"] in _BLOCKED:
|
| 767 |
+
return "blocked package is not imported on aureon-public"
|
| 768 |
+
kind = _package_kind(str(row["package"]))
|
| 769 |
+
if kind in {"operator", "excluded"}:
|
| 770 |
+
return f"package {row['package']} is {kind}"
|
| 771 |
+
plan_stage = _plan_stage(str(row["package"]))
|
| 772 |
+
if plan_stage > OPEN_PLAN_THROUGH:
|
| 773 |
+
return f"plan stage {plan_stage} is not open"
|
| 774 |
+
named = _ENTRY_REFUSAL.get((str(row["module"]), str(row["symbol"])))
|
| 775 |
+
if named:
|
| 776 |
+
return named
|
| 777 |
+
if plan_stage == 2:
|
| 778 |
+
sweep = _stage2_import_refusal(str(row["module"]))
|
| 779 |
+
if sweep:
|
| 780 |
+
return sweep
|
| 781 |
+
if int(row.get("stage") or 0) > ENABLED_THROUGH:
|
| 782 |
+
return f"stage {row['stage']} is not open"
|
| 783 |
+
if row["kind"] not in _ENTRY_KINDS:
|
| 784 |
+
return "use body_surface for modules and classes"
|
| 785 |
+
block = _safety_block(row, allow_fetch=False, allow_write=False)
|
| 786 |
+
if block:
|
| 787 |
+
return block
|
| 788 |
+
blocked_name = _name_blocked(str(row["symbol"]))
|
| 789 |
+
if blocked_name:
|
| 790 |
+
return blocked_name
|
| 791 |
+
if _leaky_parameter(str(row["module"]), str(row["symbol"])):
|
| 792 |
+
return "parameter can carry a url, path, file, or host"
|
| 793 |
+
if row["kind"] == "method":
|
| 794 |
+
class_name = str(row["symbol"]).rsplit(".", 1)[0]
|
| 795 |
+
constructor = _constructor_refusal(str(row["module"]), class_name)
|
| 796 |
+
if constructor:
|
| 797 |
+
return constructor
|
| 798 |
+
if not _quiet_source(str(row["module"]), str(row["symbol"])):
|
| 799 |
+
return "source is not a quiet read"
|
| 800 |
+
sweep = _call_sweep_refusal(str(row["module"]), str(row["symbol"]))
|
| 801 |
+
if sweep:
|
| 802 |
+
return sweep
|
| 803 |
+
return None
|
| 804 |
+
|
| 805 |
+
|
| 806 |
+
def _auris_field(symbol: str) -> dict[str, str]:
|
| 807 |
+
meaning = _AURIS.get(symbol)
|
| 808 |
+
if meaning is None and "auris" not in symbol.lower():
|
| 809 |
+
return {}
|
| 810 |
+
return {
|
| 811 |
+
"auris_meaning": meaning or "unspecified Auris name; not scored as the conjecture",
|
| 812 |
+
"auris_note": (
|
| 813 |
+
"Four meanings stay separate. This call is only the meaning named above. "
|
| 814 |
+
"The LambdaEngine conjecture is not called."
|
| 815 |
+
),
|
| 816 |
+
}
|
| 817 |
+
|
| 818 |
+
|
| 819 |
+
def _invoke(
|
| 820 |
+
row: dict[str, Any],
|
| 821 |
+
arguments: dict[str, Any],
|
| 822 |
+
timeout: float,
|
| 823 |
+
*,
|
| 824 |
+
allow_fetch: bool,
|
| 825 |
+
allow_write: bool,
|
| 826 |
+
) -> str:
|
| 827 |
+
block = _safety_block(row, allow_fetch=allow_fetch, allow_write=allow_write)
|
| 828 |
+
if block:
|
| 829 |
+
if "live orders" in block:
|
| 830 |
+
return _refused(block)
|
| 831 |
+
return _unavailable(block)
|
| 832 |
+
if row["kind"] in {"module", "class"}:
|
| 833 |
+
return _unavailable("use body_surface for modules and classes")
|
| 834 |
+
if int(row.get("stage") or 0) > ENABLED_THROUGH:
|
| 835 |
+
return _unavailable(f"stage {row['stage']} is not open")
|
| 836 |
+
if "." in str(row["symbol"]):
|
| 837 |
+
class_name = str(row["symbol"]).rsplit(".", 1)[0]
|
| 838 |
+
constructor = _constructor_refusal(str(row["module"]), class_name)
|
| 839 |
+
if constructor:
|
| 840 |
+
return _unavailable(constructor)
|
| 841 |
+
label = f"cited. {row['module']} {row['symbol']} ran."
|
| 842 |
+
extra = _auris_field(row["symbol"])
|
| 843 |
+
state, value = _call_in_subprocess(str(row["module"]), str(row["symbol"]), arguments, timeout)
|
| 844 |
+
if state != "ok":
|
| 845 |
+
return _unavailable(str(value))
|
| 846 |
+
return _result(
|
| 847 |
+
{
|
| 848 |
+
"called": True,
|
| 849 |
+
"label": label,
|
| 850 |
+
"result": value,
|
| 851 |
+
"status": "cited",
|
| 852 |
+
**extra,
|
| 853 |
+
}
|
| 854 |
+
)
|
| 855 |
+
|
| 856 |
+
|
| 857 |
+
def dispatch(
|
| 858 |
+
module: str,
|
| 859 |
+
symbol: str,
|
| 860 |
+
arguments: dict[str, Any] | None = None,
|
| 861 |
+
*,
|
| 862 |
+
server: str,
|
| 863 |
+
timeout: float = 8.0,
|
| 864 |
+
) -> str:
|
| 865 |
+
"""Run one inventoried entry point, or refuse it."""
|
| 866 |
+
|
| 867 |
+
_inventory()
|
| 868 |
+
if _INVENTORY_REFUSAL:
|
| 869 |
+
return _unavailable(_INVENTORY_REFUSAL)
|
| 870 |
+
row = lookup(module, symbol)
|
| 871 |
+
if row is None:
|
| 872 |
+
return _unavailable("symbol is not in the inventory")
|
| 873 |
+
if server == "operator" and os.environ.get("AUREON_OPERATOR_MCP") != "1":
|
| 874 |
+
return _unavailable("AUREON_OPERATOR_MCP=1 is required")
|
| 875 |
+
if server == "operator":
|
| 876 |
+
allow = _operator_allowlist_refusal(row)
|
| 877 |
+
if allow:
|
| 878 |
+
return _unavailable(allow, live_orders="refused")
|
| 879 |
+
return _invoke(row, arguments or {}, timeout, allow_fetch=False, allow_write=False)
|
| 880 |
+
if server == "public":
|
| 881 |
+
reason = public_entry_refusal(row)
|
| 882 |
+
if reason:
|
| 883 |
+
if (
|
| 884 |
+
"live orders" in reason
|
| 885 |
+
or reason.startswith("blocked package")
|
| 886 |
+
or reason.startswith("operator entry point")
|
| 887 |
+
):
|
| 888 |
+
return _refused(reason)
|
| 889 |
+
return _unavailable(reason)
|
| 890 |
+
return _invoke(row, arguments or {}, timeout, allow_fetch=False, allow_write=False)
|
| 891 |
+
return _unavailable("unknown server")
|
| 892 |
+
|
| 893 |
+
|
| 894 |
+
def _parse_arguments(arguments_json: str) -> dict[str, Any] | str:
|
| 895 |
+
text = (arguments_json or "").strip()
|
| 896 |
+
if not text:
|
| 897 |
+
return {}
|
| 898 |
+
try:
|
| 899 |
+
loaded = json.loads(text)
|
| 900 |
+
except json.JSONDecodeError:
|
| 901 |
+
return "arguments_json is not JSON"
|
| 902 |
+
if not isinstance(loaded, dict):
|
| 903 |
+
return "arguments_json must be an object"
|
| 904 |
+
return loaded
|
| 905 |
+
|
| 906 |
+
|
| 907 |
+
@quiet
|
| 908 |
+
def body_call(module: str, symbol: str, arguments_json: str = "") -> str:
|
| 909 |
+
"""Call one public entry point from the inventory. Provenance: cited.
|
| 910 |
+
|
| 911 |
+
This runs the named function. It is not a helper. Modules and classes
|
| 912 |
+
are refused here. Operator, key, write, loop, and blocked packages are
|
| 913 |
+
not called. A checkout file is imported only when its git blob matches
|
| 914 |
+
pin 8aa6a2d9.
|
| 915 |
+
|
| 916 |
+
Args:
|
| 917 |
+
module: Inventory module path, such as harmonic/rainbow_reference.py. Label: cited.
|
| 918 |
+
symbol: Function or Class.method. Label: cited.
|
| 919 |
+
arguments_json: JSON object of keyword arguments. Empty means none. Label: cited.
|
| 920 |
+
"""
|
| 921 |
+
|
| 922 |
+
parsed = _parse_arguments(arguments_json)
|
| 923 |
+
if isinstance(parsed, str):
|
| 924 |
+
return _unavailable(parsed)
|
| 925 |
+
return dispatch(module, symbol, parsed, server="public")
|
| 926 |
+
|
| 927 |
+
|
| 928 |
+
@quiet
|
| 929 |
+
def body_call_operator(module: str, symbol: str, arguments_json: str = "") -> str:
|
| 930 |
+
"""Call one operator entry point, or refuse a live order. Provenance: cited.
|
| 931 |
+
|
| 932 |
+
Live orders are refused and the blocked trading imports are not performed.
|
| 933 |
+
Keys are not read or returned. AUREON_OPERATOR_MCP=1 is required.
|
| 934 |
+
|
| 935 |
+
Args:
|
| 936 |
+
module: Inventory module path. Label: cited.
|
| 937 |
+
symbol: Function or Class.method. Label: cited.
|
| 938 |
+
arguments_json: JSON object of keyword arguments. Label: cited.
|
| 939 |
+
"""
|
| 940 |
+
|
| 941 |
+
parsed = _parse_arguments(arguments_json)
|
| 942 |
+
if isinstance(parsed, str):
|
| 943 |
+
return _unavailable(parsed)
|
| 944 |
+
return dispatch(module, symbol, parsed, server="operator")
|
| 945 |
+
|
| 946 |
+
|
| 947 |
+
@quiet
|
| 948 |
+
def body_surface(module: str, symbol: str) -> str:
|
| 949 |
+
"""Read one module or class surface from the inventory. Provenance: cited.
|
| 950 |
+
|
| 951 |
+
Nothing is imported and nothing is constructed. Functions are not called.
|
| 952 |
+
|
| 953 |
+
Args:
|
| 954 |
+
module: Inventory module path. Label: cited.
|
| 955 |
+
symbol: Module stem or class name. Label: cited.
|
| 956 |
+
"""
|
| 957 |
+
|
| 958 |
+
row = lookup(module, symbol)
|
| 959 |
+
if row is None:
|
| 960 |
+
return _unavailable("symbol is not in the inventory")
|
| 961 |
+
if int(row.get("stage") or 0) > ENABLED_THROUGH:
|
| 962 |
+
return _unavailable(f"stage {row['stage']} is not open")
|
| 963 |
+
if row["server"] != "public":
|
| 964 |
+
return _unavailable("operator surface is not on aureon-public")
|
| 965 |
+
rows, _ = _inventory()
|
| 966 |
+
methods = [
|
| 967 |
+
item["symbol"]
|
| 968 |
+
for item in rows
|
| 969 |
+
if item["module"] == module and item["kind"] == "method" and item["symbol"].startswith(symbol + ".")
|
| 970 |
+
]
|
| 971 |
+
return _result(
|
| 972 |
+
{
|
| 973 |
+
"called": False,
|
| 974 |
+
"form": row["form"],
|
| 975 |
+
"kind": row["kind"],
|
| 976 |
+
"label": "cited. Surface only. The entry point was not called.",
|
| 977 |
+
"methods": methods[:40],
|
| 978 |
+
"safety": row["safety"],
|
| 979 |
+
"server": row["server"],
|
| 980 |
+
"stage": row["stage"],
|
| 981 |
+
"status": "cited",
|
| 982 |
+
"symbol": symbol,
|
| 983 |
+
}
|
| 984 |
+
)
|
| 985 |
+
|
| 986 |
+
|
| 987 |
+
_ENTRY_KINDS = {"function", "method"}
|
| 988 |
+
|
| 989 |
+
|
| 990 |
+
def package_depth(stage: int | None = None) -> dict[str, dict[str, int]]:
|
| 991 |
+
"""Reachable public functions and methods, out of the pinned inventory.
|
| 992 |
+
|
| 993 |
+
The denominator is every public function and method. The numerator is how
|
| 994 |
+
many of those the public server will still run. A listed row is not reachable.
|
| 995 |
+
"""
|
| 996 |
+
|
| 997 |
+
rows, _ = _inventory()
|
| 998 |
+
selected = [row for row in rows if stage is None or int(row["stage"]) == stage]
|
| 999 |
+
seen: dict[str, set[tuple[str, str]]] = {}
|
| 1000 |
+
reachable: dict[str, set[tuple[str, str]]] = {}
|
| 1001 |
+
names: set[str] = set()
|
| 1002 |
+
for row in selected:
|
| 1003 |
+
names.add(str(row["package"]))
|
| 1004 |
+
if row["server"] != "public" or row["kind"] not in _ENTRY_KINDS:
|
| 1005 |
+
continue
|
| 1006 |
+
key = (str(row["module"]), str(row["symbol"]))
|
| 1007 |
+
bucket = seen.setdefault(str(row["package"]), set())
|
| 1008 |
+
if key in bucket:
|
| 1009 |
+
continue
|
| 1010 |
+
bucket.add(key)
|
| 1011 |
+
if public_entry_refusal(row) is None:
|
| 1012 |
+
reachable.setdefault(str(row["package"]), set()).add(key)
|
| 1013 |
+
return {
|
| 1014 |
+
package: {
|
| 1015 |
+
"reachable": len(reachable.get(package, set())),
|
| 1016 |
+
"public_entry_points": len(seen.get(package, set())),
|
| 1017 |
+
}
|
| 1018 |
+
for package in sorted(names)
|
| 1019 |
+
}
|
| 1020 |
+
|
| 1021 |
+
|
| 1022 |
+
def render_readme_depth() -> str:
|
| 1023 |
+
"""The README depth section. Tests require the file to contain this text."""
|
| 1024 |
+
|
| 1025 |
+
lines = [
|
| 1026 |
+
"A layer counts as full depth only where its real entry points are called.",
|
| 1027 |
+
"Each figure is reachable public functions and methods out of the public functions and methods in the pinned `docs/mcp/inventory.json`.",
|
| 1028 |
+
"",
|
| 1029 |
+
"| Package | Reachable | Public entry points |",
|
| 1030 |
+
"| --- | ---: | ---: |",
|
| 1031 |
+
]
|
| 1032 |
+
for package, row in package_depth().items():
|
| 1033 |
+
lines.append(f"| {package} | {row['reachable']} | {row['public_entry_points']} |")
|
| 1034 |
+
return "\n".join(lines)
|
| 1035 |
+
|
| 1036 |
+
|
| 1037 |
+
def depth_report() -> dict[str, Any]:
|
| 1038 |
+
"""Per-package counts. ``called`` is filled from sweep files when present."""
|
| 1039 |
+
|
| 1040 |
+
rows, _ = _inventory()
|
| 1041 |
+
packages: dict[str, dict[str, int]] = {}
|
| 1042 |
+
for row in rows:
|
| 1043 |
+
bucket = packages.setdefault(
|
| 1044 |
+
row["package"],
|
| 1045 |
+
{"called": 0, "listed": 0, "open": 0, "operator": 0, "public": 0},
|
| 1046 |
+
)
|
| 1047 |
+
bucket["listed"] += 1
|
| 1048 |
+
if row["server"] == "public":
|
| 1049 |
+
bucket["public"] += 1
|
| 1050 |
+
else:
|
| 1051 |
+
bucket["operator"] += 1
|
| 1052 |
+
if int(row["stage"]) <= ENABLED_THROUGH:
|
| 1053 |
+
bucket["open"] += 1
|
| 1054 |
+
entry_points = package_depth()
|
| 1055 |
+
for package, row in entry_points.items():
|
| 1056 |
+
bucket = packages.setdefault(
|
| 1057 |
+
package,
|
| 1058 |
+
{"called": 0, "listed": 0, "open": 0, "operator": 0, "public": 0},
|
| 1059 |
+
)
|
| 1060 |
+
bucket["called"] = row["reachable"]
|
| 1061 |
+
bucket["reachable"] = row["reachable"]
|
| 1062 |
+
bucket["public_entry_points"] = row["public_entry_points"]
|
| 1063 |
+
return {
|
| 1064 |
+
"enabled_through": ENABLED_THROUGH,
|
| 1065 |
+
"entry_points": entry_points,
|
| 1066 |
+
"label": (
|
| 1067 |
+
"cited. Depth is reachable public functions and methods out of the public "
|
| 1068 |
+
"functions and methods in the pinned inventory. A listed row is not reachable."
|
| 1069 |
+
),
|
| 1070 |
+
"packages": packages,
|
| 1071 |
+
"provenance": "cited",
|
| 1072 |
+
"servers": {
|
| 1073 |
+
"operator": sum(1 for row in rows if row["server"] == "operator"),
|
| 1074 |
+
"public": sum(1 for row in rows if row["server"] == "public"),
|
| 1075 |
+
},
|
| 1076 |
+
"status": "cited",
|
| 1077 |
+
"symbols": len(rows),
|
| 1078 |
+
}
|
| 1079 |
+
|
| 1080 |
+
|
| 1081 |
+
@quiet
|
| 1082 |
+
def body_registry() -> str:
|
| 1083 |
+
"""Name the public and operator servers and the inventory they address. Provenance: cited.
|
| 1084 |
+
|
| 1085 |
+
This is the registry. It does not call package entry points. Live orders stay refused.
|
| 1086 |
+
A checkout file is still blob-checked before a later call imports it.
|
| 1087 |
+
|
| 1088 |
+
Args:
|
| 1089 |
+
none: This tool takes no inputs. Label: cited, the registry.
|
| 1090 |
+
"""
|
| 1091 |
+
|
| 1092 |
+
return _result(
|
| 1093 |
+
{
|
| 1094 |
+
"blocked_imports": sorted(_BLOCKED),
|
| 1095 |
+
"enabled_through": ENABLED_THROUGH,
|
| 1096 |
+
"inventory": "docs/mcp/FULL_BODY_PLAN.md",
|
| 1097 |
+
"label": "cited. Registry only. No package entry point ran.",
|
| 1098 |
+
"live_orders": "refused",
|
| 1099 |
+
"operator": {
|
| 1100 |
+
"flag": "AUREON_OPERATOR_MCP=1",
|
| 1101 |
+
"tool": "body_call_operator",
|
| 1102 |
+
"transport": "stdio",
|
| 1103 |
+
},
|
| 1104 |
+
"pin": PINNED_COMMIT,
|
| 1105 |
+
"public_tools": ["body_call", "body_depth", "body_registry", "body_surface"],
|
| 1106 |
+
"spaces": [
|
| 1107 |
+
"huggingface/hnc-field/app.py",
|
| 1108 |
+
"huggingface/auris-coherence/app.py",
|
| 1109 |
+
"huggingface/qgita-snr/app.py",
|
| 1110 |
+
"huggingface/organism-replay/app.py",
|
| 1111 |
+
],
|
| 1112 |
+
"status": "cited",
|
| 1113 |
+
}
|
| 1114 |
+
)
|
| 1115 |
+
|
| 1116 |
+
|
| 1117 |
+
@quiet
|
| 1118 |
+
def body_depth() -> str:
|
| 1119 |
+
"""Per-package depth for the stages that are open. Provenance: cited.
|
| 1120 |
+
|
| 1121 |
+
``called`` counts entry points that a measured sweep actually ran.
|
| 1122 |
+
Listing a symbol is not depth. Helper tools are not counted here.
|
| 1123 |
+
|
| 1124 |
+
Args:
|
| 1125 |
+
none: This tool takes no inputs. Label: cited, the depth table.
|
| 1126 |
+
"""
|
| 1127 |
+
|
| 1128 |
+
report = depth_report()
|
| 1129 |
+
report["aureon_source_note"] = aureon_source().get("kind")
|
| 1130 |
+
return _result(report)
|
| 1131 |
+
|
| 1132 |
+
|
| 1133 |
+
def probes_for(stage: int) -> list[dict[str, Any]]:
|
| 1134 |
+
"""Real entry points the measured run calls for one stage."""
|
| 1135 |
+
|
| 1136 |
+
table: dict[int, list[dict[str, Any]]] = {
|
| 1137 |
+
1: [
|
| 1138 |
+
{"module": "harmonic/rainbow_reference.py", "symbol": "solfeggio_ladder"},
|
| 1139 |
+
{"module": "harmonic/rainbow_reference.py", "symbol": "love_centrality"},
|
| 1140 |
+
{
|
| 1141 |
+
"module": "harmonic/aureon_harmonic_reality.py",
|
| 1142 |
+
"symbol": "HarmonicSubstrate.evaluate",
|
| 1143 |
+
"arguments": {"t": 0.0},
|
| 1144 |
+
},
|
| 1145 |
+
{
|
| 1146 |
+
"module": "harmonic/aureon_harmonic_reality.py",
|
| 1147 |
+
"symbol": "CausalEcho.evaluate",
|
| 1148 |
+
"arguments": {"current_lambda": 0.0},
|
| 1149 |
+
},
|
| 1150 |
+
{"module": "core/hnc_field.py", "symbol": "blend_field"},
|
| 1151 |
+
{"module": "core/hnc_params.py", "symbol": "load_params"},
|
| 1152 |
+
{"module": "wisdom/aureon_qgita_framework.py", "symbol": "get_qgita_analyzer"},
|
| 1153 |
+
{
|
| 1154 |
+
"module": "utils/aureon_queen_hive_mind.py",
|
| 1155 |
+
"symbol": "QueenHiveMind.read_auris_nodes",
|
| 1156 |
+
},
|
| 1157 |
+
],
|
| 1158 |
+
2: [
|
| 1159 |
+
{
|
| 1160 |
+
"module": "alignment/harmonic_resonance.py",
|
| 1161 |
+
"symbol": "consonance_score",
|
| 1162 |
+
"arguments": {"ratio": 1.0},
|
| 1163 |
+
},
|
| 1164 |
+
{"module": "cognition/logic_flow.py", "symbol": "compute_logic_flow"},
|
| 1165 |
+
{
|
| 1166 |
+
"module": "queen/temporal_ground.py",
|
| 1167 |
+
"symbol": "compute_zpe_ground",
|
| 1168 |
+
"arguments": {"lambda_t": 0.0},
|
| 1169 |
+
},
|
| 1170 |
+
{
|
| 1171 |
+
"module": "swarm/druidic_council.py",
|
| 1172 |
+
"symbol": "voice_for_gamma",
|
| 1173 |
+
"arguments": {"gamma": 0.5},
|
| 1174 |
+
},
|
| 1175 |
+
{
|
| 1176 |
+
"module": "swarm_motion/love_stream.py",
|
| 1177 |
+
"symbol": "StandingWaveLoveStream.evaluate",
|
| 1178 |
+
},
|
| 1179 |
+
{
|
| 1180 |
+
"module": "gates/switchboard.py",
|
| 1181 |
+
"symbol": "is_human_held",
|
| 1182 |
+
"arguments": {"action": "draft"},
|
| 1183 |
+
},
|
| 1184 |
+
{
|
| 1185 |
+
"module": "gates/panel.py",
|
| 1186 |
+
"symbol": "ungrounded_nodes",
|
| 1187 |
+
"arguments": {"grounded_slices": []},
|
| 1188 |
+
},
|
| 1189 |
+
{
|
| 1190 |
+
"module": "governance/celtic_voice_bank.py",
|
| 1191 |
+
"symbol": "seasonal_gate_for_date",
|
| 1192 |
+
"arguments": {"value": "2026-10-29"},
|
| 1193 |
+
},
|
| 1194 |
+
{"module": "observer/live_data_policy.py", "symbol": "simulation_fallback_allowed"},
|
| 1195 |
+
],
|
| 1196 |
+
3: [
|
| 1197 |
+
{
|
| 1198 |
+
"module": "bio/audio_signal_adapter.py",
|
| 1199 |
+
"symbol": "synthetic_audio",
|
| 1200 |
+
"arguments": {"kind": "noise", "n": 16},
|
| 1201 |
+
},
|
| 1202 |
+
{
|
| 1203 |
+
"module": "bio/calibration_curve.py",
|
| 1204 |
+
"symbol": "compute_calibration",
|
| 1205 |
+
"arguments": {"trials": 2, "nulls": 1},
|
| 1206 |
+
},
|
| 1207 |
+
{"module": "organism/repository_layers.py", "symbol": "compose_repository_layers"},
|
| 1208 |
+
{"module": "core/aureon_organism_spine.py", "symbol": "build_organism_manifest"},
|
| 1209 |
+
{
|
| 1210 |
+
"module": "vault/voice/document_artifact_skill.py",
|
| 1211 |
+
"symbol": "count_words",
|
| 1212 |
+
"arguments": {"text": "one two three"},
|
| 1213 |
+
},
|
| 1214 |
+
{
|
| 1215 |
+
"module": "evaluation/auris_node_eval.py",
|
| 1216 |
+
"symbol": "evaluate_auris_nodes",
|
| 1217 |
+
"timeout": 20,
|
| 1218 |
+
},
|
| 1219 |
+
],
|
| 1220 |
+
4: [
|
| 1221 |
+
{
|
| 1222 |
+
"module": "data_feeds/unified_ws_feed.py",
|
| 1223 |
+
"symbol": "parse_binance_tick",
|
| 1224 |
+
"arguments": {
|
| 1225 |
+
"data": {"s": "BTCUSDT", "b": "1", "a": "2", "c": "1.5", "v": "3", "P": "0", "E": 0}
|
| 1226 |
+
},
|
| 1227 |
+
},
|
| 1228 |
+
{
|
| 1229 |
+
"module": "decoders/grail_convergence.py",
|
| 1230 |
+
"symbol": "haversine",
|
| 1231 |
+
"arguments": {"lat1": 51.5, "lon1": -0.12, "lat2": 48.86, "lon2": 2.35},
|
| 1232 |
+
},
|
| 1233 |
+
{
|
| 1234 |
+
"module": "search/online_research_cinema.py",
|
| 1235 |
+
"symbol": "summarize_text",
|
| 1236 |
+
"arguments": {"text": "The field is a reading. The reading is not an order.", "topic": "field"},
|
| 1237 |
+
},
|
| 1238 |
+
{
|
| 1239 |
+
"module": "portals/ifs.py",
|
| 1240 |
+
"symbol": "html_to_text",
|
| 1241 |
+
"arguments": {"html": "<p>Hello field</p>"},
|
| 1242 |
+
},
|
| 1243 |
+
{
|
| 1244 |
+
"module": "analytics/backtest_sentiment_oracle.py",
|
| 1245 |
+
"symbol": "derive_fear_greed",
|
| 1246 |
+
"arguments": {
|
| 1247 |
+
"closes": [1, 1.1, 1.2, 1.1, 1.3, 1.4, 1.2, 1.5],
|
| 1248 |
+
"volumes": [1, 1, 1, 1, 1, 1, 1, 1],
|
| 1249 |
+
"idx": 7,
|
| 1250 |
+
},
|
| 1251 |
+
},
|
| 1252 |
+
{
|
| 1253 |
+
"module": "atn/aureon_atn_backtest.py",
|
| 1254 |
+
"symbol": "compute_impacts",
|
| 1255 |
+
"arguments": {"events": [], "candles": [], "symbol": "BTC"},
|
| 1256 |
+
},
|
| 1257 |
+
{
|
| 1258 |
+
"module": "monitors/margin_eta_predictor.py",
|
| 1259 |
+
"symbol": "calc_breakeven",
|
| 1260 |
+
"arguments": {"entry": 100.0},
|
| 1261 |
+
},
|
| 1262 |
+
{
|
| 1263 |
+
"module": "monitors/margin_eta_predictor.py",
|
| 1264 |
+
"symbol": "normalise_pair",
|
| 1265 |
+
"arguments": {"pair": "btcusd"},
|
| 1266 |
+
},
|
| 1267 |
+
],
|
| 1268 |
+
5: [
|
| 1269 |
+
{"module": "accounting/file_drop.py", "symbol": "registered_ingestors", "server": "operator"},
|
| 1270 |
+
{
|
| 1271 |
+
"module": "portfolio/aureon_billion_goal_tracker.py",
|
| 1272 |
+
"symbol": "get_days_remaining",
|
| 1273 |
+
"server": "operator",
|
| 1274 |
+
},
|
| 1275 |
+
{"module": "trading/__init__.py", "symbol": "__init__", "server": "operator"},
|
| 1276 |
+
{"module": "exchanges/__init__.py", "symbol": "__init__", "server": "operator"},
|
| 1277 |
+
{"module": "bots/__init__.py", "symbol": "__init__", "server": "operator"},
|
| 1278 |
+
{"module": "bots_intelligence/__init__.py", "symbol": "__init__", "server": "operator"},
|
| 1279 |
+
{"module": "bridges/__init__.py", "symbol": "__init__", "server": "operator"},
|
| 1280 |
+
{"module": "scanners/__init__.py", "symbol": "__init__", "server": "operator"},
|
| 1281 |
+
{
|
| 1282 |
+
"module": "unified_margin_trader/_margin_monitor.py",
|
| 1283 |
+
"symbol": "_margin_monitor",
|
| 1284 |
+
"server": "operator",
|
| 1285 |
+
},
|
| 1286 |
+
],
|
| 1287 |
+
6: [
|
| 1288 |
+
{
|
| 1289 |
+
"module": "approval/compose.py",
|
| 1290 |
+
"symbol": "subject_line",
|
| 1291 |
+
"arguments": {"action": "status"},
|
| 1292 |
+
},
|
| 1293 |
+
{
|
| 1294 |
+
"module": "briefing/schemas.py",
|
| 1295 |
+
"symbol": "severity_rank",
|
| 1296 |
+
"arguments": {"severity": "high"},
|
| 1297 |
+
},
|
| 1298 |
+
{
|
| 1299 |
+
"module": "grants/daemon.py",
|
| 1300 |
+
"symbol": "breath_interval",
|
| 1301 |
+
"arguments": {"urgency": None},
|
| 1302 |
+
},
|
| 1303 |
+
{
|
| 1304 |
+
"module": "integrations/ollama/hnc_phi_swarm.py",
|
| 1305 |
+
"symbol": "build_phi_swarm_plan",
|
| 1306 |
+
"arguments": {"flow": {"flow": "observe"}, "catalog_size": 2, "max_total_calls": 4},
|
| 1307 |
+
},
|
| 1308 |
+
{
|
| 1309 |
+
"module": "intelligence/aureon_advanced_intelligence.py",
|
| 1310 |
+
"symbol": "calculate_harmonic_resonance",
|
| 1311 |
+
"arguments": {"freq1": 100.0, "freq2": 200.0},
|
| 1312 |
+
},
|
| 1313 |
+
{
|
| 1314 |
+
"module": "plumber/crypto.py",
|
| 1315 |
+
"symbol": "sha256_hex",
|
| 1316 |
+
"arguments": {"value": "aureon-public"},
|
| 1317 |
+
},
|
| 1318 |
+
{
|
| 1319 |
+
"module": "s51/aureon_51_compound.py",
|
| 1320 |
+
"symbol": "summarize_compounding",
|
| 1321 |
+
"arguments": {"receipts": []},
|
| 1322 |
+
},
|
| 1323 |
+
{
|
| 1324 |
+
"module": "simulation/aureon_world_simulator.py",
|
| 1325 |
+
"symbol": "hz_to_rgb",
|
| 1326 |
+
"arguments": {"hz": 528.0},
|
| 1327 |
+
},
|
| 1328 |
+
{
|
| 1329 |
+
"module": "generated/research_cinema/harmonic_nexus_score_model.py",
|
| 1330 |
+
"symbol": "build_default_inputs",
|
| 1331 |
+
},
|
| 1332 |
+
],
|
| 1333 |
+
}
|
| 1334 |
+
return table.get(stage, [])
|
| 1335 |
+
|
| 1336 |
+
|
| 1337 |
+
def sweep_zero_arg(stage: int, *, timeout: float = 8.0) -> list[dict[str, Any]]:
|
| 1338 |
+
"""Call public zero-argument functions for one open stage.
|
| 1339 |
+
|
| 1340 |
+
Fetches, writes, keys, loops, and blocked packages are skipped.
|
| 1341 |
+
"""
|
| 1342 |
+
|
| 1343 |
+
if stage > ENABLED_THROUGH:
|
| 1344 |
+
return []
|
| 1345 |
+
rows, _ = _inventory()
|
| 1346 |
+
calls: list[dict[str, Any]] = []
|
| 1347 |
+
seen: set[tuple[str, str]] = set()
|
| 1348 |
+
for probe in probes_for(stage):
|
| 1349 |
+
key = (probe["module"], probe["symbol"])
|
| 1350 |
+
seen.add(key)
|
| 1351 |
+
target = str(probe.get("server") or "public")
|
| 1352 |
+
raw = dispatch(
|
| 1353 |
+
probe["module"],
|
| 1354 |
+
probe["symbol"],
|
| 1355 |
+
probe.get("arguments") or {},
|
| 1356 |
+
server=target,
|
| 1357 |
+
timeout=float(probe.get("timeout") or timeout),
|
| 1358 |
+
)
|
| 1359 |
+
calls.append(_summarize(probe["module"], probe["symbol"], raw, probe=True))
|
| 1360 |
+
for row in rows:
|
| 1361 |
+
if int(row["stage"]) != stage or row["server"] != "public":
|
| 1362 |
+
continue
|
| 1363 |
+
if row["kind"] != "function" or int(row.get("required") or 0) != 0 or row.get("async"):
|
| 1364 |
+
continue
|
| 1365 |
+
if not str(row.get("safety") or "").startswith("runs from inputs"):
|
| 1366 |
+
continue
|
| 1367 |
+
if stage >= 6:
|
| 1368 |
+
continue
|
| 1369 |
+
if stage >= 2:
|
| 1370 |
+
if row["package"] == "queen":
|
| 1371 |
+
continue
|
| 1372 |
+
if _UNSAFE_NAME.search(row["symbol"]) or _SKIP_WORD.search(row["symbol"]):
|
| 1373 |
+
continue
|
| 1374 |
+
if not _quiet_source(row["module"], row["symbol"]):
|
| 1375 |
+
continue
|
| 1376 |
+
key = (row["module"], row["symbol"])
|
| 1377 |
+
if key in seen:
|
| 1378 |
+
continue
|
| 1379 |
+
seen.add(key)
|
| 1380 |
+
raw = dispatch(row["module"], row["symbol"], {}, server="public", timeout=timeout)
|
| 1381 |
+
calls.append(_summarize(row["module"], row["symbol"], raw, probe=False))
|
| 1382 |
+
return calls
|
| 1383 |
+
|
| 1384 |
+
|
| 1385 |
+
def _summarize(module: str, symbol: str, raw: str, *, probe: bool) -> dict[str, Any]:
|
| 1386 |
+
try:
|
| 1387 |
+
body = json.loads(raw)
|
| 1388 |
+
except json.JSONDecodeError:
|
| 1389 |
+
body = {"status": "unavailable", "reason": "result was not JSON"}
|
| 1390 |
+
package = module.split("/", 1)[0]
|
| 1391 |
+
if module.startswith("unified_margin_trader/"):
|
| 1392 |
+
package = "unified_margin_trader"
|
| 1393 |
+
elif not module.startswith("unified_margin_trader"):
|
| 1394 |
+
# inventory modules are relative to aureon/, so the first part is the package
|
| 1395 |
+
# except core/utils/wisdom paths. package is the first directory.
|
| 1396 |
+
package = module.split("/", 1)[0]
|
| 1397 |
+
return {
|
| 1398 |
+
"called": body.get("called") is True and body.get("status") == "cited",
|
| 1399 |
+
"module": module,
|
| 1400 |
+
"package": package,
|
| 1401 |
+
"probe": probe,
|
| 1402 |
+
"reason": body.get("reason"),
|
| 1403 |
+
"status": body.get("status"),
|
| 1404 |
+
"symbol": symbol,
|
| 1405 |
+
}
|
body_sweep.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Record real body_call results for one open stage. Does not place orders."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
from aureon_public.body import enabled_stage, package_depth, sweep_zero_arg
|
| 10 |
+
from aureon_public.paths import repo_root
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def write_stage(stage: int, timeout: float) -> Path:
|
| 14 |
+
if stage > enabled_stage():
|
| 15 |
+
raise SystemExit(f"stage {stage} is not open (enabled through {enabled_stage()})")
|
| 16 |
+
calls = sweep_zero_arg(stage, timeout=timeout)
|
| 17 |
+
out = repo_root() / "measured" / f"body_stage{stage}.json"
|
| 18 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 19 |
+
called = sum(1 for item in calls if item.get("called") is True)
|
| 20 |
+
record = {
|
| 21 |
+
"called": called,
|
| 22 |
+
"calls": calls,
|
| 23 |
+
"enabled_through": enabled_stage(),
|
| 24 |
+
"stage": stage,
|
| 25 |
+
"tried": len(calls),
|
| 26 |
+
}
|
| 27 |
+
out.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 28 |
+
record["entry_points"] = package_depth(stage)
|
| 29 |
+
out.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 30 |
+
return out
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def main(argv: list[str] | None = None) -> None:
|
| 34 |
+
parser = argparse.ArgumentParser(prog="aureon-public-body-sweep")
|
| 35 |
+
parser.add_argument("--stage", type=int, required=True)
|
| 36 |
+
parser.add_argument("--timeout", type=float, default=8.0)
|
| 37 |
+
args = parser.parse_args(argv)
|
| 38 |
+
path = write_stage(args.stage, args.timeout)
|
| 39 |
+
print(path)
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
if __name__ == "__main__":
|
| 43 |
+
main()
|
call_sweep.py
ADDED
|
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Call every body_call-reachable entry point.
|
| 2 |
+
|
| 3 |
+
Each call uses the public worker. Sockets are blocked and logged in that
|
| 4 |
+
worker. Fake NEXUS and Sero checkouts sit beside the repo. Stage-2 entry
|
| 5 |
+
points are also called with the real arguments in stage2_arguments.
|
| 6 |
+
SwarmAgent.update is also called with the hive fixture from
|
| 7 |
+
tests/test_swarm_hive.py. An entry point is refused when any of those calls
|
| 8 |
+
opens a connection, starts a process, writes outside the sandbox, or loads
|
| 9 |
+
queen, miner, swarm_motion, inhouse_ai, ollama_config, or an HTTP client.
|
| 10 |
+
|
| 11 |
+
bash measured/aureon_public_call_sweep.sh
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
from __future__ import annotations
|
| 15 |
+
|
| 16 |
+
import argparse
|
| 17 |
+
import json
|
| 18 |
+
import os
|
| 19 |
+
import subprocess
|
| 20 |
+
import sys
|
| 21 |
+
from pathlib import Path
|
| 22 |
+
from typing import Any
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _tested_stage1_tools() -> set[tuple[str, str]]:
|
| 26 |
+
return {
|
| 27 |
+
("alignment/harmonic_resonance.py", "compute_signal_consensus"),
|
| 28 |
+
("alignment/harmonic_resonance.py", "consonance_score"),
|
| 29 |
+
("alignment/harmonic_resonance.py", "analyse_frequency_harmony"),
|
| 30 |
+
("alignment/harmonic_resonance.py", "compute_phase_coherence"),
|
| 31 |
+
("alignment/harmonic_resonance.py", "derive_phase"),
|
| 32 |
+
("alignment/harmonic_resonance.py", "geometric_mean"),
|
| 33 |
+
("alignment/harmonic_resonance.py", "full_harmonic_analysis"),
|
| 34 |
+
("alignment/harmonic_resonance.py", "HarmonicAnalysis.to_dict"),
|
| 35 |
+
("alignment/pillar_alignment.py", "AlignmentCycleResult.to_dict"),
|
| 36 |
+
("alignment/pillar_alignment.py", "get_pillar_alignment"),
|
| 37 |
+
("alignment/unified_directive.py", "MasterDirective.to_dict"),
|
| 38 |
+
("generated/research_cinema/harmonic_nexus_score_model.py", "build_default_inputs"),
|
| 39 |
+
("generated/research_cinema/harmonic_nexus_score_model.py", "HarmonicNexusScoreInputs.normalized"),
|
| 40 |
+
("generated/research_cinema/harmonic_nexus_score_model.py", "harmonic_nexus_score"),
|
| 41 |
+
("generated/research_cinema/harmonic_nexus_score_model.py", "score_breakdown"),
|
| 42 |
+
("swarm/druidic_council.py", "voice_for_gamma"),
|
| 43 |
+
("swarm/fleadh.py", "steer_flow"),
|
| 44 |
+
("swarm/druidic_council.py", "build_seat_receipt"),
|
| 45 |
+
("swarm/agent.py", "SwarmAgent.substrate"),
|
| 46 |
+
("swarm/agent.py", "SwarmAgent.to_dict"),
|
| 47 |
+
("swarm/agent.py", "SwarmAgent.propose"),
|
| 48 |
+
("swarm/coherence.py", "ClusterCoherence.gamma"),
|
| 49 |
+
("swarm/coherence.py", "ClusterCoherence.to_dict"),
|
| 50 |
+
("swarm/memory_bus.py", "CausalEchoBus.echo"),
|
| 51 |
+
("swarm/memory_bus.py", "CausalEchoBus.to_dict"),
|
| 52 |
+
("swarm/steering.py", "SteeringField.steer"),
|
| 53 |
+
("swarm/druidic_council.py", "SeatReceipt.to_dict"),
|
| 54 |
+
("swarm/druidic_council.py", "CouncilReceipt.to_dict"),
|
| 55 |
+
("swarm/queen_gate.py", "Actualization.to_dict"),
|
| 56 |
+
("swarm/agent.py", "SwarmAgent.update"),
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def reachable_entries() -> list[dict[str, Any]]:
|
| 61 |
+
"""Entry points body_call will run while the call-sweep gate is open."""
|
| 62 |
+
|
| 63 |
+
import aureon_public.body as body_module
|
| 64 |
+
|
| 65 |
+
body_module.enable_sweep_measurement()
|
| 66 |
+
from aureon_public.body import _inventory, _plan_stage, public_entry_refusal
|
| 67 |
+
|
| 68 |
+
seen: set[tuple[str, str]] = set()
|
| 69 |
+
found = []
|
| 70 |
+
rows, _index = _inventory()
|
| 71 |
+
for row in rows:
|
| 72 |
+
if row["server"] != "public" or row["kind"] not in {"function", "method"}:
|
| 73 |
+
continue
|
| 74 |
+
key = (str(row["module"]), str(row["symbol"]))
|
| 75 |
+
if key in seen:
|
| 76 |
+
continue
|
| 77 |
+
seen.add(key)
|
| 78 |
+
if public_entry_refusal(row) is not None:
|
| 79 |
+
continue
|
| 80 |
+
found.append(
|
| 81 |
+
{
|
| 82 |
+
"module": key[0],
|
| 83 |
+
"package": str(row["package"]),
|
| 84 |
+
"plan_stage": _plan_stage(str(row["package"])),
|
| 85 |
+
"symbol": key[1],
|
| 86 |
+
}
|
| 87 |
+
)
|
| 88 |
+
return found
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
def hazard_reason(payload: dict[str, Any]) -> str | None:
|
| 92 |
+
"""The refusal sentence for one call. None when the call stayed inside the rules."""
|
| 93 |
+
|
| 94 |
+
bad = payload.get("bad") or []
|
| 95 |
+
sockets = payload.get("socket") or []
|
| 96 |
+
processes = payload.get("process") or []
|
| 97 |
+
writes = payload.get("writes") or []
|
| 98 |
+
if bad or sockets:
|
| 99 |
+
return "call loads a banned chain or opens a connection"
|
| 100 |
+
if processes:
|
| 101 |
+
return "call starts a process"
|
| 102 |
+
if writes:
|
| 103 |
+
return "call writes outside the sandbox"
|
| 104 |
+
return None
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def child_main(module: str, symbol: str, arguments_json: str = "") -> None:
|
| 108 |
+
import aureon_public.body as body_module
|
| 109 |
+
from aureon_public.sweep_guard import declare_sandbox
|
| 110 |
+
|
| 111 |
+
declare_sandbox()
|
| 112 |
+
body_module.enable_sweep_measurement()
|
| 113 |
+
text = body_module.body_call(module, symbol, arguments_json)
|
| 114 |
+
try:
|
| 115 |
+
body = json.loads(text)
|
| 116 |
+
except json.JSONDecodeError:
|
| 117 |
+
body = {"status": "unavailable", "reason": "result was not JSON"}
|
| 118 |
+
report = body_module.last_sweep_report or {}
|
| 119 |
+
json.dump(
|
| 120 |
+
{
|
| 121 |
+
"bad": list(report.get("modules") or []),
|
| 122 |
+
"called": body.get("called") is True,
|
| 123 |
+
"process": list(report.get("processes") or []),
|
| 124 |
+
"reason": body.get("reason"),
|
| 125 |
+
"sandbox_writes": list(report.get("sandbox_writes") or []),
|
| 126 |
+
"socket": list(report.get("sockets") or []),
|
| 127 |
+
"status": body.get("status"),
|
| 128 |
+
"writes": list(report.get("writes") or []),
|
| 129 |
+
},
|
| 130 |
+
sys.stdout,
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _one(module: str, symbol: str, timeout: float, arguments_json: str = "") -> dict[str, Any]:
|
| 135 |
+
command = [
|
| 136 |
+
sys.executable,
|
| 137 |
+
"-m",
|
| 138 |
+
"aureon_public.call_sweep",
|
| 139 |
+
"--module",
|
| 140 |
+
module,
|
| 141 |
+
"--symbol",
|
| 142 |
+
symbol,
|
| 143 |
+
]
|
| 144 |
+
if arguments_json:
|
| 145 |
+
command.extend(["--arguments", arguments_json])
|
| 146 |
+
try:
|
| 147 |
+
completed = subprocess.run(
|
| 148 |
+
command,
|
| 149 |
+
cwd=os.environ.get("TMPDIR") or "/tmp",
|
| 150 |
+
capture_output=True,
|
| 151 |
+
text=True,
|
| 152 |
+
timeout=timeout,
|
| 153 |
+
check=False,
|
| 154 |
+
env={key: value for key, value in os.environ.items() if key != "AUREON_PUBLIC_SWEEP"},
|
| 155 |
+
)
|
| 156 |
+
except subprocess.TimeoutExpired:
|
| 157 |
+
return {
|
| 158 |
+
"bad": [],
|
| 159 |
+
"called": False,
|
| 160 |
+
"error": "sweep exceeded the timeout",
|
| 161 |
+
"process": [],
|
| 162 |
+
"socket": [],
|
| 163 |
+
"status": "unavailable",
|
| 164 |
+
"writes": [],
|
| 165 |
+
}
|
| 166 |
+
if not completed.stdout.strip():
|
| 167 |
+
return {
|
| 168 |
+
"bad": [],
|
| 169 |
+
"called": False,
|
| 170 |
+
"error": f"sweep exited {completed.returncode}",
|
| 171 |
+
"process": [],
|
| 172 |
+
"socket": [],
|
| 173 |
+
"status": "unavailable",
|
| 174 |
+
"writes": [],
|
| 175 |
+
}
|
| 176 |
+
try:
|
| 177 |
+
payload = json.loads(completed.stdout)
|
| 178 |
+
except json.JSONDecodeError:
|
| 179 |
+
return {
|
| 180 |
+
"bad": [],
|
| 181 |
+
"called": False,
|
| 182 |
+
"error": "sweep result was not JSON",
|
| 183 |
+
"process": [],
|
| 184 |
+
"socket": [],
|
| 185 |
+
"status": "unavailable",
|
| 186 |
+
"writes": [],
|
| 187 |
+
}
|
| 188 |
+
return payload if isinstance(payload, dict) else {}
|
| 189 |
+
|
| 190 |
+
|
| 191 |
+
def _first_hazard(hazards: list[str]) -> str | None:
|
| 192 |
+
order = (
|
| 193 |
+
"call loads a banned chain or opens a connection",
|
| 194 |
+
"call starts a process",
|
| 195 |
+
"call writes outside the sandbox",
|
| 196 |
+
"call did not finish",
|
| 197 |
+
)
|
| 198 |
+
for sentence in order:
|
| 199 |
+
if sentence in hazards:
|
| 200 |
+
return sentence
|
| 201 |
+
return None
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def _stage1_extra_attempts(module: str, symbol: str) -> list[dict[str, Any]]:
|
| 205 |
+
"""Real stage-1 arguments copied from tests/test_swarm_hive.py."""
|
| 206 |
+
|
| 207 |
+
if (module, symbol) != ("swarm/agent.py", "SwarmAgent.update"):
|
| 208 |
+
return []
|
| 209 |
+
return [
|
| 210 |
+
{
|
| 211 |
+
"arguments": {
|
| 212 |
+
"cluster_states": [],
|
| 213 |
+
"context": [0.4, 0.2, -0.1, 0.3, 0.0, 0.1, -0.2, 0.05],
|
| 214 |
+
"echo": None,
|
| 215 |
+
"init": {
|
| 216 |
+
"actions": ["hold", "advance", "retreat"],
|
| 217 |
+
"agent_id": "a1",
|
| 218 |
+
"role": "research",
|
| 219 |
+
},
|
| 220 |
+
},
|
| 221 |
+
"label": "hive_first_update",
|
| 222 |
+
"note": "The first update call in test_agent_keeps_a_normalized_soft_simplex. Empty cluster and no echo.",
|
| 223 |
+
"source": "tests/test_swarm_hive.py",
|
| 224 |
+
}
|
| 225 |
+
]
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def build_record(timeout: float) -> dict[str, Any]:
|
| 229 |
+
from aureon_public.guard_loader import aureon_source
|
| 230 |
+
from aureon_public.measurement_stamp import measurement_stamp
|
| 231 |
+
from aureon_public.sweep_layout import layout_record
|
| 232 |
+
|
| 233 |
+
from aureon_public.stage2_arguments import attempts_for
|
| 234 |
+
|
| 235 |
+
source = aureon_source()
|
| 236 |
+
stamp = measurement_stamp()
|
| 237 |
+
tested = _tested_stage1_tools()
|
| 238 |
+
entries = []
|
| 239 |
+
for row in reachable_entries():
|
| 240 |
+
print(f"{row['module']} {row['symbol']}", file=sys.stderr)
|
| 241 |
+
planned = [
|
| 242 |
+
{
|
| 243 |
+
"arguments": {},
|
| 244 |
+
"label": "no_arguments",
|
| 245 |
+
"note": "No arguments.",
|
| 246 |
+
"source": None,
|
| 247 |
+
}
|
| 248 |
+
]
|
| 249 |
+
if row["plan_stage"] == 2:
|
| 250 |
+
planned.extend(attempts_for(row["module"], row["symbol"]))
|
| 251 |
+
planned.extend(_stage1_extra_attempts(row["module"], row["symbol"]))
|
| 252 |
+
recorded = []
|
| 253 |
+
hazards: list[str] = []
|
| 254 |
+
for attempt in planned:
|
| 255 |
+
if attempt.get("fixture"):
|
| 256 |
+
arguments_json = json.dumps({"__sweep_fixture__": attempt["fixture"]})
|
| 257 |
+
shown: dict[str, Any] = {"__sweep_fixture__": attempt["fixture"]}
|
| 258 |
+
else:
|
| 259 |
+
arguments = attempt.get("arguments") if isinstance(attempt.get("arguments"), dict) else {}
|
| 260 |
+
arguments_json = json.dumps(arguments) if arguments else ""
|
| 261 |
+
shown = arguments if isinstance(arguments, dict) else {}
|
| 262 |
+
payload = _one(row["module"], row["symbol"], timeout, arguments_json)
|
| 263 |
+
reason = hazard_reason(payload)
|
| 264 |
+
if reason:
|
| 265 |
+
hazards.append(reason)
|
| 266 |
+
elif row["plan_stage"] == 2 and payload.get("error"):
|
| 267 |
+
hazards.append("call did not finish")
|
| 268 |
+
reason = "call did not finish"
|
| 269 |
+
recorded.append(
|
| 270 |
+
{
|
| 271 |
+
"arguments": shown,
|
| 272 |
+
"bad": [str(item) for item in payload.get("bad") or []],
|
| 273 |
+
"called": payload.get("called") is True,
|
| 274 |
+
"error": payload.get("error"),
|
| 275 |
+
"label": attempt.get("label"),
|
| 276 |
+
"note": attempt.get("note"),
|
| 277 |
+
"process": [str(item) for item in payload.get("process") or []],
|
| 278 |
+
"reason": payload.get("reason"),
|
| 279 |
+
"refusal": reason,
|
| 280 |
+
"sandbox_writes": [str(item) for item in payload.get("sandbox_writes") or []],
|
| 281 |
+
"socket": [str(item) for item in payload.get("socket") or []],
|
| 282 |
+
"source": attempt.get("source"),
|
| 283 |
+
"status": payload.get("status"),
|
| 284 |
+
"writes": [str(item) for item in payload.get("writes") or []],
|
| 285 |
+
}
|
| 286 |
+
)
|
| 287 |
+
first = recorded[0]
|
| 288 |
+
refusal = _first_hazard(hazards)
|
| 289 |
+
key = (row["module"], row["symbol"])
|
| 290 |
+
entries.append(
|
| 291 |
+
{
|
| 292 |
+
"attempts": recorded,
|
| 293 |
+
"bad": first["bad"],
|
| 294 |
+
"called": first["called"],
|
| 295 |
+
"error": first["error"],
|
| 296 |
+
"module": row["module"],
|
| 297 |
+
"package": row["package"],
|
| 298 |
+
"plan_stage": row["plan_stage"],
|
| 299 |
+
"process": first["process"],
|
| 300 |
+
"reason": first["reason"],
|
| 301 |
+
"refusal": refusal,
|
| 302 |
+
"refused": refusal is not None,
|
| 303 |
+
"sandbox_writes": sorted(
|
| 304 |
+
{item for attempt in recorded for item in attempt["sandbox_writes"]}
|
| 305 |
+
),
|
| 306 |
+
"socket": first["socket"],
|
| 307 |
+
"status": first["status"],
|
| 308 |
+
"symbol": row["symbol"],
|
| 309 |
+
"tested_stage1_tool": key in tested,
|
| 310 |
+
"writes": first["writes"],
|
| 311 |
+
}
|
| 312 |
+
)
|
| 313 |
+
from aureon_public.sweep_layout import beside
|
| 314 |
+
|
| 315 |
+
home = beside() / "home"
|
| 316 |
+
return {
|
| 317 |
+
"aureon_source": source,
|
| 318 |
+
"entries": entries,
|
| 319 |
+
"layout": layout_record(),
|
| 320 |
+
"user_dirs": {
|
| 321 |
+
"HOME": str(home),
|
| 322 |
+
"USERPROFILE": str(home),
|
| 323 |
+
"XDG_CACHE_HOME": str(home / ".cache"),
|
| 324 |
+
"XDG_CONFIG_HOME": str(home / ".config"),
|
| 325 |
+
"XDG_DATA_HOME": str(home / ".local" / "share"),
|
| 326 |
+
"XDG_RUNTIME_DIR": str(beside() / "runtime"),
|
| 327 |
+
"XDG_STATE_HOME": str(home / ".local" / "state"),
|
| 328 |
+
},
|
| 329 |
+
"processes": "blocked",
|
| 330 |
+
"sockets": "blocked",
|
| 331 |
+
"writes": "outside sandbox blocked",
|
| 332 |
+
**stamp,
|
| 333 |
+
}
|
| 334 |
+
|
| 335 |
+
|
| 336 |
+
def main(argv: list[str] | None = None) -> None:
|
| 337 |
+
parser = argparse.ArgumentParser(prog="aureon-public-call-sweep")
|
| 338 |
+
parser.add_argument("--module")
|
| 339 |
+
parser.add_argument("--symbol")
|
| 340 |
+
parser.add_argument("--arguments", default="")
|
| 341 |
+
parser.add_argument("--out", type=Path)
|
| 342 |
+
parser.add_argument("--timeout", type=float, default=45.0)
|
| 343 |
+
args = parser.parse_args(argv)
|
| 344 |
+
if args.module or args.symbol:
|
| 345 |
+
if not args.module or not args.symbol:
|
| 346 |
+
raise SystemExit("module and symbol are both required")
|
| 347 |
+
child_main(args.module, args.symbol, args.arguments)
|
| 348 |
+
return
|
| 349 |
+
record = build_record(args.timeout)
|
| 350 |
+
text = json.dumps(record, indent=2, sort_keys=True) + "\n"
|
| 351 |
+
if args.out is None:
|
| 352 |
+
sys.stdout.write(text)
|
| 353 |
+
return
|
| 354 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 355 |
+
args.out.write_text(text, encoding="utf-8")
|
| 356 |
+
|
| 357 |
+
|
| 358 |
+
if __name__ == "__main__":
|
| 359 |
+
main()
|
call_worker.py
ADDED
|
@@ -0,0 +1,243 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Run one inventoried call in this process. The parent kills the process group on timeout."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import enum
|
| 6 |
+
import inspect
|
| 7 |
+
import json
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
from datetime import date
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _plain(value: Any, depth: int = 0) -> Any:
|
| 16 |
+
if depth > 4:
|
| 17 |
+
return type(value).__name__
|
| 18 |
+
if value is None or isinstance(value, (str, int, float, bool)):
|
| 19 |
+
if isinstance(value, float) and value != value:
|
| 20 |
+
return None
|
| 21 |
+
if isinstance(value, str):
|
| 22 |
+
return value[:500]
|
| 23 |
+
return value
|
| 24 |
+
if isinstance(value, enum.Enum):
|
| 25 |
+
return _plain(value.value, depth + 1)
|
| 26 |
+
if isinstance(value, dict):
|
| 27 |
+
return {str(key): _plain(item, depth + 1) for key, item in list(value.items())[:30]}
|
| 28 |
+
if isinstance(value, (list, tuple)):
|
| 29 |
+
return [_plain(item, depth + 1) for item in list(value)[:30]]
|
| 30 |
+
if hasattr(value, "to_dict") and callable(value.to_dict):
|
| 31 |
+
try:
|
| 32 |
+
return _plain(value.to_dict(), depth + 1)
|
| 33 |
+
except Exception:
|
| 34 |
+
pass
|
| 35 |
+
if hasattr(value, "__dict__") and not isinstance(value, type):
|
| 36 |
+
fields = {key: item for key, item in vars(value).items() if not str(key).startswith("_")}
|
| 37 |
+
return {"type": type(value).__name__, "fields": _plain(fields, depth + 1)}
|
| 38 |
+
return {"type": type(value).__name__}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _inventory_path(cls: type) -> str:
|
| 42 |
+
"""Inventory module path for a class. ``aureon.`` is the package prefix."""
|
| 43 |
+
|
| 44 |
+
module = cls.__module__
|
| 45 |
+
if module.startswith("aureon."):
|
| 46 |
+
module = module[len("aureon.") :]
|
| 47 |
+
return module.replace(".", "/") + ".py"
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _post_init_defined(cls: type) -> bool:
|
| 51 |
+
"""True when ``__post_init__`` is defined anywhere on the class MRO."""
|
| 52 |
+
|
| 53 |
+
return any("__post_init__" in base.__dict__ for base in cls.__mro__)
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def _dataclass_from_dict(fn: Any, annotation: Any, value: Any) -> Any | None:
|
| 57 |
+
"""Build an allowlisted dataclass from a JSON object.
|
| 58 |
+
|
| 59 |
+
The class is resolved from the annotation, including a name in the
|
| 60 |
+
function's globals, then checked by its own module. A class from another
|
| 61 |
+
package is not built unless that class is on ``_CONSTRUCTOR_ALLOWLIST``.
|
| 62 |
+
|
| 63 |
+
A generated dataclass ``__init__`` has code filename ``<string>`` and
|
| 64 |
+
still calls ``__post_init__``. Any class that defines ``__post_init__``
|
| 65 |
+
on its MRO is refused and is not constructed.
|
| 66 |
+
"""
|
| 67 |
+
|
| 68 |
+
if not isinstance(value, dict):
|
| 69 |
+
return None
|
| 70 |
+
cls = annotation
|
| 71 |
+
if isinstance(annotation, str):
|
| 72 |
+
cls = fn.__globals__.get(annotation) or fn.__globals__.get(annotation.split(".")[-1])
|
| 73 |
+
if not isinstance(cls, type) or not hasattr(cls, "__dataclass_fields__"):
|
| 74 |
+
return None
|
| 75 |
+
code = getattr(getattr(cls, "__init__", None), "__code__", None)
|
| 76 |
+
if code is None or code.co_filename != "<string>":
|
| 77 |
+
return None
|
| 78 |
+
from aureon_public.body import _CONSTRUCTOR_ALLOWLIST
|
| 79 |
+
|
| 80 |
+
if (_inventory_path(cls), cls.__name__) not in _CONSTRUCTOR_ALLOWLIST:
|
| 81 |
+
return None
|
| 82 |
+
if _post_init_defined(cls):
|
| 83 |
+
return None
|
| 84 |
+
if not set(value).issubset(cls.__dataclass_fields__):
|
| 85 |
+
return None
|
| 86 |
+
return cls(**value)
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _coerce(fn: Any, kwargs: dict[str, Any]) -> dict[str, Any]:
|
| 90 |
+
try:
|
| 91 |
+
signature = inspect.signature(fn)
|
| 92 |
+
except (TypeError, ValueError):
|
| 93 |
+
return kwargs
|
| 94 |
+
coerced = dict(kwargs)
|
| 95 |
+
for name, value in list(coerced.items()):
|
| 96 |
+
param = signature.parameters.get(name)
|
| 97 |
+
if param is None:
|
| 98 |
+
continue
|
| 99 |
+
annotation = param.annotation
|
| 100 |
+
origin = getattr(annotation, "__origin__", None)
|
| 101 |
+
name_of = annotation if isinstance(annotation, str) else getattr(annotation, "__name__", "")
|
| 102 |
+
if (annotation is date or name_of == "date" or str(name_of).endswith("date")) and isinstance(value, str):
|
| 103 |
+
coerced[name] = date.fromisoformat(value)
|
| 104 |
+
elif (annotation is frozenset or origin is frozenset) and isinstance(value, list):
|
| 105 |
+
coerced[name] = frozenset(value)
|
| 106 |
+
else:
|
| 107 |
+
built = _dataclass_from_dict(fn, annotation, value)
|
| 108 |
+
if built is not None:
|
| 109 |
+
coerced[name] = built
|
| 110 |
+
return coerced
|
| 111 |
+
|
| 112 |
+
|
| 113 |
+
def _drop_checkout_root() -> None:
|
| 114 |
+
"""The Space guard puts the checkout on sys.path. The worker must not keep it."""
|
| 115 |
+
|
| 116 |
+
from aureon_public.paths import repo_root
|
| 117 |
+
|
| 118 |
+
root = repo_root().resolve()
|
| 119 |
+
kept: list[str] = []
|
| 120 |
+
for entry in sys.path:
|
| 121 |
+
if not entry:
|
| 122 |
+
continue
|
| 123 |
+
try:
|
| 124 |
+
if Path(entry).resolve() == root:
|
| 125 |
+
continue
|
| 126 |
+
except OSError:
|
| 127 |
+
kept.append(entry)
|
| 128 |
+
continue
|
| 129 |
+
kept.append(entry)
|
| 130 |
+
sys.path[:] = kept
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def _load(dotted: str, module_rel: str) -> Any:
|
| 134 |
+
del module_rel
|
| 135 |
+
if dotted != "aureon" and not dotted.startswith("aureon."):
|
| 136 |
+
raise RuntimeError("only an aureon module can be loaded")
|
| 137 |
+
from aureon_public.guard_loader import apply_space_guard
|
| 138 |
+
from aureon_public.pin_blob import (
|
| 139 |
+
import_through_finder,
|
| 140 |
+
install_pinned_aureon_finder,
|
| 141 |
+
refuse_preseeded_aureon,
|
| 142 |
+
)
|
| 143 |
+
|
| 144 |
+
install_pinned_aureon_finder()
|
| 145 |
+
apply_space_guard()
|
| 146 |
+
_drop_checkout_root()
|
| 147 |
+
refuse_preseeded_aureon()
|
| 148 |
+
return import_through_finder(dotted)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def _call(dotted: str, symbol: str, arguments: dict[str, Any], module_rel: str) -> Any:
|
| 152 |
+
imported = _load(dotted, module_rel)
|
| 153 |
+
if os.environ.get("AUREON_PUBLIC_SWEEP") == "1" and isinstance(arguments.get("__sweep_fixture__"), str):
|
| 154 |
+
from aureon_public.stage2_arguments import resolve_fixture
|
| 155 |
+
|
| 156 |
+
arguments = resolve_fixture(str(arguments["__sweep_fixture__"]))
|
| 157 |
+
if "." not in symbol:
|
| 158 |
+
fn = getattr(imported, symbol)
|
| 159 |
+
return fn(**_coerce(fn, arguments))
|
| 160 |
+
class_name, method_name = symbol.rsplit(".", 1)
|
| 161 |
+
cls = getattr(imported, class_name)
|
| 162 |
+
init_args = arguments.get("init") if isinstance(arguments.get("init"), dict) else {}
|
| 163 |
+
method_args = {key: value for key, value in arguments.items() if key != "init"}
|
| 164 |
+
signature = inspect.signature(cls.__init__)
|
| 165 |
+
parameters = [name for name in signature.parameters if name != "self"]
|
| 166 |
+
init_args = {key: value for key, value in init_args.items() if key in parameters}
|
| 167 |
+
instance = cls(**_coerce(cls.__init__, init_args))
|
| 168 |
+
method = getattr(instance, method_name)
|
| 169 |
+
return method(**_coerce(method, method_args))
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def _install_sweep_guard() -> None:
|
| 173 |
+
"""Block sockets, process starts, and writes outside the sandbox.
|
| 174 |
+
|
| 175 |
+
Used only while the call sweep is measuring. The server refuses to start
|
| 176 |
+
when AUREON_PUBLIC_SWEEP is set.
|
| 177 |
+
"""
|
| 178 |
+
|
| 179 |
+
if os.environ.get("AUREON_PUBLIC_SWEEP") != "1":
|
| 180 |
+
return
|
| 181 |
+
from aureon_public.sweep_guard import install_sweep_guard
|
| 182 |
+
|
| 183 |
+
install_sweep_guard()
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def _sweep_modules() -> list[str]:
|
| 187 |
+
from aureon_public.stage2_import_sweep import is_http_client
|
| 188 |
+
|
| 189 |
+
banned = []
|
| 190 |
+
for name in sys.modules:
|
| 191 |
+
if any(marker in name for marker in ("inhouse_ai", "ollama_config")):
|
| 192 |
+
banned.append(name)
|
| 193 |
+
continue
|
| 194 |
+
if name in {"aureon.queen", "aureon.miner", "aureon.swarm_motion"} or name.startswith(
|
| 195 |
+
("aureon.queen.", "aureon.miner.", "aureon.swarm_motion.")
|
| 196 |
+
):
|
| 197 |
+
banned.append(name)
|
| 198 |
+
continue
|
| 199 |
+
if is_http_client(name):
|
| 200 |
+
banned.append(name)
|
| 201 |
+
return sorted(banned)
|
| 202 |
+
|
| 203 |
+
|
| 204 |
+
def main() -> None:
|
| 205 |
+
_install_sweep_guard()
|
| 206 |
+
real_stdout = sys.stdout
|
| 207 |
+
sys.stdout = sys.stderr
|
| 208 |
+
try:
|
| 209 |
+
job = json.loads(sys.stdin.read() or "{}")
|
| 210 |
+
result = _call(
|
| 211 |
+
str(job["dotted"]),
|
| 212 |
+
str(job["symbol"]),
|
| 213 |
+
dict(job.get("arguments") or {}),
|
| 214 |
+
str(job["module"]),
|
| 215 |
+
)
|
| 216 |
+
payload = {"ok": True, "result": _plain(result)}
|
| 217 |
+
except SystemExit:
|
| 218 |
+
payload = {"ok": False, "error": "SystemExit"}
|
| 219 |
+
except Exception as exc:
|
| 220 |
+
payload = {"ok": False, "error": f"{type(exc).__name__}: {exc}"[:240]}
|
| 221 |
+
if os.environ.get("AUREON_PUBLIC_REPORT_MODULES") == "1":
|
| 222 |
+
payload["modules"] = sorted(
|
| 223 |
+
name
|
| 224 |
+
for name in sys.modules
|
| 225 |
+
if "inhouse_ai" in name or "ollama_config" in name
|
| 226 |
+
)
|
| 227 |
+
if os.environ.get("AUREON_PUBLIC_SWEEP") == "1":
|
| 228 |
+
from aureon_public.sweep_guard import snapshot
|
| 229 |
+
|
| 230 |
+
snap = snapshot()
|
| 231 |
+
payload["sweep"] = {
|
| 232 |
+
"modules": _sweep_modules(),
|
| 233 |
+
"processes": snap["processes"],
|
| 234 |
+
"sandbox_writes": snap["sandbox_writes"],
|
| 235 |
+
"sockets": snap["sockets"],
|
| 236 |
+
"writes": snap["writes"],
|
| 237 |
+
}
|
| 238 |
+
sys.stdout = real_stdout
|
| 239 |
+
real_stdout.write(json.dumps(payload))
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
if __name__ == "__main__":
|
| 243 |
+
main()
|
coverage_plan.py
ADDED
|
@@ -0,0 +1,506 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Write mcp/aureon_public/COVERAGE_PLAN.md from the pinned inventory.
|
| 2 |
+
|
| 3 |
+
Every count comes from docs/mcp/inventory.json and public_entry_refusal.
|
| 4 |
+
The file is refused when its sha256 is not INVENTORY_SHA256.
|
| 5 |
+
|
| 6 |
+
env -u PYTHONPATH PYTHONPATH=mcp python3.12 -m aureon_public.coverage_plan --check
|
| 7 |
+
env -u PYTHONPATH PYTHONPATH=mcp python3.12 -m aureon_public.coverage_plan --write
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import json
|
| 14 |
+
from collections import defaultdict
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
|
| 17 |
+
from aureon_public.body import (
|
| 18 |
+
_BLOCKED,
|
| 19 |
+
_CONSTRUCTOR_ALLOWLIST,
|
| 20 |
+
INVENTORY_SHA256,
|
| 21 |
+
_inventory,
|
| 22 |
+
package_depth,
|
| 23 |
+
public_entry_refusal,
|
| 24 |
+
)
|
| 25 |
+
from aureon_public.paths import repo_root
|
| 26 |
+
|
| 27 |
+
PLAN_PATH = Path("mcp") / "aureon_public" / "COVERAGE_PLAN.md"
|
| 28 |
+
FENCE = set(_BLOCKED) | {"unified_margin_trader"}
|
| 29 |
+
|
| 30 |
+
STAGE_TITLE = {
|
| 31 |
+
1: "Deterministic read-only",
|
| 32 |
+
2: "Read-only with a process or write mark",
|
| 33 |
+
3: "Operator-scoped, no key, order, or fetch mark",
|
| 34 |
+
4: "Keys, orders, network, and the refused-imports fence",
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def safety_category(text: str) -> str:
|
| 39 |
+
"""One category for an inventory safety sentence. The words are the scanner's."""
|
| 40 |
+
|
| 41 |
+
if text.startswith("personal or key") or "reads keys" in text:
|
| 42 |
+
return "key"
|
| 43 |
+
if "order" in text or "live_orders" in text:
|
| 44 |
+
return "order"
|
| 45 |
+
if text.startswith("live public fetch"):
|
| 46 |
+
return "fetch"
|
| 47 |
+
if text.startswith("process") or "UI start" in text or "loop" in text:
|
| 48 |
+
return "process"
|
| 49 |
+
if "write" in text and "no repo write" not in text:
|
| 50 |
+
return "write"
|
| 51 |
+
if "risky token" in text:
|
| 52 |
+
return "risky"
|
| 53 |
+
if "operator-scoped" in text or "no public import" in text:
|
| 54 |
+
return "operator"
|
| 55 |
+
if text.startswith("runs from inputs"):
|
| 56 |
+
return "pure"
|
| 57 |
+
if "module surface" in text:
|
| 58 |
+
return "surface"
|
| 59 |
+
if "file does not parse" in text:
|
| 60 |
+
return "parse"
|
| 61 |
+
return "other"
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def stage_for(package: str, categories: set[str]) -> int:
|
| 65 |
+
"""Earlier stages are the safer reads. Stage 4 stays behind the fence."""
|
| 66 |
+
|
| 67 |
+
# compose_repository_layers loads core.organism_composition, which imports
|
| 68 |
+
# aureon.inhouse_ai.llm_adapter, agent_runner, orchestrator,
|
| 69 |
+
# aureon.ollama_config, and aureon.autonomous.aureon_internal_coding_workforce.
|
| 70 |
+
# inhouse_ai is excluded. That chain is not a stage-1 read.
|
| 71 |
+
if package == "organism":
|
| 72 |
+
return 4
|
| 73 |
+
if package in FENCE or "order" in categories or "key" in categories or "fetch" in categories:
|
| 74 |
+
return 4
|
| 75 |
+
if "process" in categories or "write" in categories:
|
| 76 |
+
return 2
|
| 77 |
+
if "operator" in categories and "pure" not in categories:
|
| 78 |
+
return 3
|
| 79 |
+
return 1
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
def _rows() -> tuple[list[dict], dict[str, dict[str, int]]]:
|
| 83 |
+
loaded, _index = _inventory()
|
| 84 |
+
if not loaded:
|
| 85 |
+
raise SystemExit("inventory did not load")
|
| 86 |
+
return loaded, package_depth()
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def tested_keys() -> set[tuple[str, str]]:
|
| 90 |
+
"""Entry points a public tool calls and a test exercises."""
|
| 91 |
+
|
| 92 |
+
from aureon_public.call_sweep import _tested_stage1_tools
|
| 93 |
+
from aureon_public.stage2_layer import TESTED
|
| 94 |
+
|
| 95 |
+
return set(_tested_stage1_tools()) | set(TESTED)
|
| 96 |
+
|
| 97 |
+
|
| 98 |
+
def _tested_counts(loaded: list[dict]) -> dict[str, int]:
|
| 99 |
+
"""Reachable public entry points that a tool calls. A refused point is not tested."""
|
| 100 |
+
|
| 101 |
+
wanted = tested_keys()
|
| 102 |
+
counts: dict[str, int] = defaultdict(int)
|
| 103 |
+
seen: set[tuple[str, str]] = set()
|
| 104 |
+
for row in loaded:
|
| 105 |
+
if row["server"] != "public" or row["kind"] not in {"function", "method"}:
|
| 106 |
+
continue
|
| 107 |
+
key = (str(row["module"]), str(row["symbol"]))
|
| 108 |
+
if key in seen or key not in wanted:
|
| 109 |
+
continue
|
| 110 |
+
seen.add(key)
|
| 111 |
+
if public_entry_refusal(row) is None:
|
| 112 |
+
counts[str(row["package"])] += 1
|
| 113 |
+
return counts
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def plan_rows() -> list[dict]:
|
| 117 |
+
"""One row per package. Counts are the pinned inventory and the current guard."""
|
| 118 |
+
|
| 119 |
+
loaded, depth = _rows()
|
| 120 |
+
by_package: dict[str, list[dict]] = defaultdict(list)
|
| 121 |
+
for row in loaded:
|
| 122 |
+
by_package[row["package"]].append(row)
|
| 123 |
+
opened = _opened_by_allowlist(loaded)
|
| 124 |
+
tested = _tested_counts(loaded)
|
| 125 |
+
rows = []
|
| 126 |
+
for package in sorted(by_package):
|
| 127 |
+
items = by_package[package]
|
| 128 |
+
categories = {safety_category(str(item.get("safety") or "")) for item in items}
|
| 129 |
+
stage = stage_for(package, categories)
|
| 130 |
+
counted = depth[package]
|
| 131 |
+
rows.append(
|
| 132 |
+
{
|
| 133 |
+
"categories": sorted(categories),
|
| 134 |
+
"fence": package in FENCE or "order" in categories,
|
| 135 |
+
"listed": len(items),
|
| 136 |
+
"opened_by_allowlist": opened.get(package, 0),
|
| 137 |
+
"package": package,
|
| 138 |
+
"public_entry_points": counted["public_entry_points"],
|
| 139 |
+
"reachable": counted["reachable"],
|
| 140 |
+
"refused": counted["public_entry_points"] - counted["reachable"],
|
| 141 |
+
"stage": stage,
|
| 142 |
+
"tested": tested.get(package, 0),
|
| 143 |
+
}
|
| 144 |
+
)
|
| 145 |
+
rows.sort(key=lambda row: (row["stage"], row["package"]))
|
| 146 |
+
return rows
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def _opened_by_allowlist(loaded: list[dict]) -> dict[str, int]:
|
| 150 |
+
"""Reachable methods whose class is allowlisted. Those were refused before the list."""
|
| 151 |
+
|
| 152 |
+
counts: dict[str, int] = defaultdict(int)
|
| 153 |
+
seen: set[tuple[str, str]] = set()
|
| 154 |
+
for row in loaded:
|
| 155 |
+
if row["kind"] != "method" or row["server"] != "public":
|
| 156 |
+
continue
|
| 157 |
+
key = (str(row["module"]), str(row["symbol"]))
|
| 158 |
+
if key in seen:
|
| 159 |
+
continue
|
| 160 |
+
seen.add(key)
|
| 161 |
+
class_name = str(row["symbol"]).rsplit(".", 1)[0]
|
| 162 |
+
if (str(row["module"]), class_name) not in _CONSTRUCTOR_ALLOWLIST:
|
| 163 |
+
continue
|
| 164 |
+
if public_entry_refusal(row) is None:
|
| 165 |
+
counts[str(row["package"])] += 1
|
| 166 |
+
return counts
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def _excluded_packages() -> list[str]:
|
| 170 |
+
from aureon_public.more_layers import UPDATES
|
| 171 |
+
|
| 172 |
+
return sorted(package for package, kind, _reason in UPDATES if kind == "excluded")
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def _read_json(name: str) -> dict:
|
| 176 |
+
path = repo_root() / "measured" / name
|
| 177 |
+
try:
|
| 178 |
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
| 179 |
+
except (OSError, json.JSONDecodeError):
|
| 180 |
+
return {}
|
| 181 |
+
return loaded if isinstance(loaded, dict) else {}
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
def _stage2_lines() -> list[str]:
|
| 185 |
+
"""What this run opened, refused, and left without a tool."""
|
| 186 |
+
|
| 187 |
+
from aureon_public.stage2_arguments import NOT_A_TOOL
|
| 188 |
+
|
| 189 |
+
imports = _read_json("aureon_public_stage2_imports.json")
|
| 190 |
+
calls = _read_json("aureon_public_call_sweep.json")
|
| 191 |
+
lines = [
|
| 192 |
+
"Stage 2 tools call through `dispatch`. The inputs are the tests and committed files named on each tool. `atn` stays excluded because its modules load an HTTP client. `conversion` has no public function or method and stays excluded. The constructor allowlist, the `__post_init__` refusal, the `AUREON_PUBLIC_SWEEP` start refusal, and the pin check are unchanged.",
|
| 193 |
+
"Import refusals:",
|
| 194 |
+
]
|
| 195 |
+
modules = [row for row in imports.get("modules") or [] if isinstance(row, dict) and row.get("refused")]
|
| 196 |
+
if not modules:
|
| 197 |
+
lines.append("- none recorded")
|
| 198 |
+
for row in sorted(modules, key=lambda item: str(item.get("module"))):
|
| 199 |
+
lines.append(
|
| 200 |
+
f"- `{row.get('module')}`: {row.get('refusal') or 'module import loads an adapter or http client'}"
|
| 201 |
+
)
|
| 202 |
+
lines.append("Import errors that are not refusals:")
|
| 203 |
+
errors = [
|
| 204 |
+
row
|
| 205 |
+
for row in imports.get("modules") or []
|
| 206 |
+
if isinstance(row, dict) and row.get("error") and not row.get("refused")
|
| 207 |
+
]
|
| 208 |
+
if not errors:
|
| 209 |
+
lines.append("- none recorded")
|
| 210 |
+
for row in sorted(errors, key=lambda item: str(item.get("module"))):
|
| 211 |
+
lines.append(f"- `{row.get('module')}`: {row.get('error')}")
|
| 212 |
+
lines.append("Call refusals from the sweep:")
|
| 213 |
+
entries = [
|
| 214 |
+
row
|
| 215 |
+
for row in calls.get("entries") or []
|
| 216 |
+
if isinstance(row, dict) and row.get("refused")
|
| 217 |
+
]
|
| 218 |
+
if not entries:
|
| 219 |
+
lines.append("- none recorded")
|
| 220 |
+
for row in sorted(entries, key=lambda item: (str(item.get("module")), str(item.get("symbol")))):
|
| 221 |
+
extra = []
|
| 222 |
+
for attempt in row.get("attempts") or []:
|
| 223 |
+
if isinstance(attempt, dict) and attempt.get("process"):
|
| 224 |
+
extra.append("The same call started a process. The sweep blocked it.")
|
| 225 |
+
if isinstance(attempt, dict) and attempt.get("writes"):
|
| 226 |
+
extra.append("The same call wrote outside the sandbox. The sweep blocked it.")
|
| 227 |
+
suffix = (". " + " ".join(dict.fromkeys(extra))) if extra else ""
|
| 228 |
+
lines.append(
|
| 229 |
+
f"- `{row.get('module')}` `{row.get('symbol')}`: {row.get('refusal') or 'call loads a banned chain or opens a connection'}{suffix}"
|
| 230 |
+
)
|
| 231 |
+
from aureon_public.body import _ENTRY_REFUSAL, _UNTESTED_STAGE2, lookup, public_entry_refusal
|
| 232 |
+
|
| 233 |
+
lines.append(
|
| 234 |
+
"These five were reachable and had no tool. `body_call` and `dispatch` refuse them. The constructor allowlist is unchanged."
|
| 235 |
+
)
|
| 236 |
+
for key in sorted(item for item, reason in _ENTRY_REFUSAL.items() if reason == _UNTESTED_STAGE2):
|
| 237 |
+
lines.append(f"- `{key[0]}` `{key[1]}`: {_UNTESTED_STAGE2}. {NOT_A_TOOL[key]}")
|
| 238 |
+
still = []
|
| 239 |
+
for key in sorted(NOT_A_TOOL):
|
| 240 |
+
row = lookup(key[0], key[1])
|
| 241 |
+
if row is not None and public_entry_refusal(row) is None:
|
| 242 |
+
still.append(key)
|
| 243 |
+
if still:
|
| 244 |
+
lines.append("These stage-2 entry points are still reachable and are not tools:")
|
| 245 |
+
for key in still:
|
| 246 |
+
lines.append(f"- `{key[0]}` `{key[1]}`. {NOT_A_TOOL[key]}")
|
| 247 |
+
return lines
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def _public_keys() -> dict[int, list[tuple[str, str]]]:
|
| 251 |
+
"""Reachable public entry points, by coverage-plan stage."""
|
| 252 |
+
|
| 253 |
+
from aureon_public.body import _inventory, _plan_stage, public_entry_refusal
|
| 254 |
+
|
| 255 |
+
seen: set[tuple[str, str]] = set()
|
| 256 |
+
found: dict[int, list[tuple[str, str]]] = defaultdict(list)
|
| 257 |
+
rows, _index = _inventory()
|
| 258 |
+
for row in rows:
|
| 259 |
+
if row["server"] != "public" or row["kind"] not in {"function", "method"}:
|
| 260 |
+
continue
|
| 261 |
+
key = (str(row["module"]), str(row["symbol"]))
|
| 262 |
+
if key in seen:
|
| 263 |
+
continue
|
| 264 |
+
seen.add(key)
|
| 265 |
+
if public_entry_refusal(row) is not None:
|
| 266 |
+
continue
|
| 267 |
+
found[_plan_stage(str(row["package"]))].append(key)
|
| 268 |
+
for keys in found.values():
|
| 269 |
+
keys.sort()
|
| 270 |
+
return found
|
| 271 |
+
|
| 272 |
+
|
| 273 |
+
def _reconciliation_lines() -> list[str]:
|
| 274 |
+
"""How reachable and tested moved from main c1ae468d to this tree.
|
| 275 |
+
|
| 276 |
+
Main recorded 85 reachable: stage 1 was 39 and stage 2 was 46. Stage 1
|
| 277 |
+
tested 29 entry points and stage 2 tested none. A tool does not create a
|
| 278 |
+
new reachable row.
|
| 279 |
+
"""
|
| 280 |
+
|
| 281 |
+
from aureon_public.body import _ENTRY_REFUSAL, _UNTESTED_STAGE2
|
| 282 |
+
from aureon_public.call_sweep import _tested_stage1_tools
|
| 283 |
+
from aureon_public.stage2_layer import TESTED
|
| 284 |
+
|
| 285 |
+
reachable = _public_keys()
|
| 286 |
+
stage1_tested = sorted(_tested_stage1_tools())
|
| 287 |
+
stage2_tested = sorted(TESTED)
|
| 288 |
+
stage1_now = set(reachable.get(1, []))
|
| 289 |
+
stage2_now = set(reachable.get(2, []))
|
| 290 |
+
dropped = [key for key in stage1_tested if key not in stage1_now]
|
| 291 |
+
untested_stage1 = [key for key in reachable.get(1, []) if key not in set(stage1_tested)]
|
| 292 |
+
lines = [
|
| 293 |
+
"## Count reconciliation",
|
| 294 |
+
"",
|
| 295 |
+
"Main `c1ae468d` recorded reachable 85. Stage 1 was 39 (alignment 11, generated 4, swarm 24). Stage 2 was 46 (atn 0, cognition 1, conversion 0, decoders 5, evaluation 7, gates 3, observer 29, s51 1). 39 + 46 = 85. Tested on that main was the 29 stage-1 tool entry points below. Stage 2 tested was 0. Registering a tool does not add a reachable row. The tool calls an entry point that was already reachable.",
|
| 296 |
+
f"Stage 1 reachable now: {len(stage1_now)}. Stage 2 reachable now: {len(stage2_now)}. {len(stage1_now)} + {len(stage2_now)} = {len(stage1_now) + len(stage2_now)}.",
|
| 297 |
+
f"Stage 1 tested now: {len(stage1_tested)}. Stage 2 tested now: {len(stage2_tested)}. {len(stage1_tested)} + {len(stage2_tested)} = {len(stage1_tested) + len(stage2_tested)}.",
|
| 298 |
+
"Every stage-1 entry point that was tested on main is still tested. None dropped out:",
|
| 299 |
+
]
|
| 300 |
+
if dropped:
|
| 301 |
+
lines.append("Stage-1 tested entry points that are no longer reachable:")
|
| 302 |
+
for module, symbol in dropped:
|
| 303 |
+
lines.append(f"- `{module}` `{symbol}`")
|
| 304 |
+
else:
|
| 305 |
+
lines.append("No stage-1 tested entry point dropped out.")
|
| 306 |
+
for module, symbol in stage1_tested:
|
| 307 |
+
lines.append(f"- `{module}` `{symbol}`")
|
| 308 |
+
if untested_stage1:
|
| 309 |
+
lines.append("Stage 1 reachable entry points that are still not tested:")
|
| 310 |
+
for module, symbol in untested_stage1:
|
| 311 |
+
lines.append(f"- `{module}` `{symbol}`")
|
| 312 |
+
else:
|
| 313 |
+
lines.append("Stage 1 has no reachable entry point left untested.")
|
| 314 |
+
lines.append(
|
| 315 |
+
"Stage 2 reachable fell by 7, from 46 to 39, on the stage-2 run. The call sweep refused `self_coder_report`. Five reachable entry points had no tool. `log_blocked_fallback` would write a fallback log for an event that did not happen, so `body_call` refuses it. This follow-up then closes the 10 stage-1 points that were reachable and not tested. Nine are refused. `SwarmAgent.update` is tested on the hive fixture."
|
| 316 |
+
)
|
| 317 |
+
calls = _read_json("aureon_public_call_sweep.json")
|
| 318 |
+
self_coder = next(
|
| 319 |
+
(
|
| 320 |
+
row
|
| 321 |
+
for row in calls.get("entries") or []
|
| 322 |
+
if isinstance(row, dict)
|
| 323 |
+
and row.get("module") == "evaluation/measured_proof.py"
|
| 324 |
+
and row.get("symbol") == "self_coder_report"
|
| 325 |
+
),
|
| 326 |
+
None,
|
| 327 |
+
)
|
| 328 |
+
if isinstance(self_coder, dict):
|
| 329 |
+
lines.append(
|
| 330 |
+
f"- `evaluation/measured_proof.py` `self_coder_report`: {self_coder.get('refusal') or 'refused by the call sweep'}."
|
| 331 |
+
)
|
| 332 |
+
else:
|
| 333 |
+
lines.append(
|
| 334 |
+
"- `evaluation/measured_proof.py` `self_coder_report`: refused by the call sweep. The record names the reason."
|
| 335 |
+
)
|
| 336 |
+
for key in sorted(item for item, reason in _ENTRY_REFUSAL.items() if reason == _UNTESTED_STAGE2):
|
| 337 |
+
lines.append(f"- `{key[0]}` `{key[1]}`: {_UNTESTED_STAGE2}.")
|
| 338 |
+
lines.append(
|
| 339 |
+
"- `observer/live_data_policy.py` `log_blocked_fallback`: "
|
| 340 |
+
"fallback log is not emitted for an event that did not happen."
|
| 341 |
+
)
|
| 342 |
+
for key, reason in sorted(_ENTRY_REFUSAL.items()):
|
| 343 |
+
if str(key[0]).startswith("swarm/"):
|
| 344 |
+
lines.append(f"- `{key[0]}` `{key[1]}`: {reason}.")
|
| 345 |
+
total = len(stage1_now) + len(stage2_now)
|
| 346 |
+
tested_total = len(stage1_tested) + len(stage2_tested)
|
| 347 |
+
if (
|
| 348 |
+
len(stage1_now) != 30
|
| 349 |
+
or len(stage2_now) != 39
|
| 350 |
+
or len(stage1_tested) != 30
|
| 351 |
+
or len(stage2_tested) != 39
|
| 352 |
+
or dropped
|
| 353 |
+
or untested_stage1
|
| 354 |
+
or total != 69
|
| 355 |
+
or tested_total != 69
|
| 356 |
+
):
|
| 357 |
+
raise RuntimeError(
|
| 358 |
+
"count reconciliation drifted: "
|
| 359 |
+
f"stage1 {len(stage1_now)} tested {len(stage1_tested)}; "
|
| 360 |
+
f"stage2 {len(stage2_now)} tested {len(stage2_tested)}; "
|
| 361 |
+
f"dropped {dropped}"
|
| 362 |
+
)
|
| 363 |
+
lines.append(
|
| 364 |
+
"Main `cf43882e` recorded reachable 78 and tested 68. This follow-up refuses nine stage-1 entry points and tests `SwarmAgent.update`. Reachable and tested are both 69. 30 + 39 = 69."
|
| 365 |
+
)
|
| 366 |
+
return lines
|
| 367 |
+
|
| 368 |
+
|
| 369 |
+
def render() -> str:
|
| 370 |
+
rows = plan_rows()
|
| 371 |
+
listed = sum(row["listed"] for row in rows)
|
| 372 |
+
public = sum(row["public_entry_points"] for row in rows)
|
| 373 |
+
reachable = sum(row["reachable"] for row in rows)
|
| 374 |
+
tested = sum(row["tested"] for row in rows)
|
| 375 |
+
refused = sum(row["refused"] for row in rows)
|
| 376 |
+
opened = sum(row["opened_by_allowlist"] for row in rows)
|
| 377 |
+
excluded = _excluded_packages()
|
| 378 |
+
first = next(row["package"] for row in rows if row["stage"] == 1)
|
| 379 |
+
lines = [
|
| 380 |
+
"# Public MCP coverage plan",
|
| 381 |
+
"",
|
| 382 |
+
"Counts are the pinned `docs/mcp/inventory.json`. A public entry point is a public function or method. Reachable means `public_entry_refusal` returns None, so `body_call` will run it. A listed module or class is not an entry point. The sha256 below is `INVENTORY_SHA256`. A different inventory file is not loaded.",
|
| 383 |
+
"",
|
| 384 |
+
f"Inventory sha256: `{INVENTORY_SHA256}`",
|
| 385 |
+
"",
|
| 386 |
+
"Reproduce:",
|
| 387 |
+
"",
|
| 388 |
+
"```bash",
|
| 389 |
+
"env -u PYTHONPATH PYTHONPATH=mcp python3.12 -m aureon_public.coverage_plan --check",
|
| 390 |
+
"bash measured/aureon_public_stage1_run.sh",
|
| 391 |
+
"bash measured/aureon_public_stage2_sweep.sh",
|
| 392 |
+
"bash measured/aureon_public_call_sweep.sh",
|
| 393 |
+
"bash measured/aureon_public_protocol_run.sh",
|
| 394 |
+
"bash measured/aureon_public_space_run.sh",
|
| 395 |
+
"env -u PYTHONPATH /tmp/aureon-public-venv/bin/python -m pytest tests/test_aureon_public_mcp.py tests/test_aureon_body.py tests/bio/test_mcp_interior_attribution.py tests/bio/test_mcp_membrane.py tests/bio/test_mcp_transport.py tests/test_aureon_public_alignment.py tests/test_aureon_public_stage1.py tests/test_aureon_public_stage2.py tests/test_aureon_public_protocol.py tests/test_aureon_public_space.py --tb=line",
|
| 396 |
+
"```",
|
| 397 |
+
"",
|
| 398 |
+
"That pytest command is the gate. It runs in `/tmp/aureon-public-venv`, the venv `measured/aureon_public_stage1_run.sh` creates (`VENV` overrides the path). The file list is `tests/test_aureon_public_mcp.py`, `tests/test_aureon_body.py`, `tests/bio/test_mcp_interior_attribution.py`, `tests/bio/test_mcp_membrane.py`, `tests/bio/test_mcp_transport.py`, `tests/test_aureon_public_alignment.py`, `tests/test_aureon_public_stage1.py`, `tests/test_aureon_public_stage2.py`, `tests/test_aureon_public_protocol.py`, and `tests/test_aureon_public_space.py`. `tests/test_async_socket_isolation.py` is not in the gate list. It imports `pytest_socket`, and `mcp/aureon_public/test-requirements.txt` does not install that plugin.",
|
| 399 |
+
"",
|
| 400 |
+
"`--write` rewrites this file from the same function. `measured/aureon_public_stage1_run.sh` installs `mcp/aureon_public/requirements.txt` and `mcp/aureon_public/test-requirements.txt`, then rewrites both `measured/aureon_public_alignment.json` and `measured/aureon_public_stage1.json`. It writes those two files under a temp directory first and copies them into `measured/` only after both stamps have finished. `measurement_stamp` raises `RuntimeError` when `git status --porcelain` is not empty, so the second stamp must not see the first file. `test-requirements.txt` is the test install: pytest, pytest-timeout, flask, pandas, and scipy. It is not the public server runtime. `measured/aureon_public_stage2_sweep.sh` and `measured/aureon_public_call_sweep.sh` copy the checkout with `cp -a` under an ordinary temp parent, place fake `NEXUS-LIVE-FEED-` and `Aureon-Trading--Project-Sero` checkouts beside that copy, block sockets, and rewrite their measured records. Each sweep record names the pin, the `aureon/` tree hash beside that pin, the `aureon_source` kind, and that temp parent. `measured/aureon_public_protocol_run.sh` starts this server over stdio and over Streamable HTTP bound to `127.0.0.1`, with `AUREON_PUBLIC_REQUIRE_PIN=1`. An MCP SDK 1.30.0 client calls `tools/list`, `resources/list`, `prompts/list`, and one `tools/call` (`alignment_consonance_read` with ratio 1.0). The raw pages are `measured/aureon_public_protocol.json`. `measured/aureon_public_space_run.sh` starts `python -m aureon_public.space` with `AUREON_PUBLIC_API_KEY` set and records the same client calling `tools/list` and `tools/call` on `127.0.0.1`. The raw pages are `measured/aureon_public_space.json`. These measured records name `code_commit`, the parent of the commit that contains the record file. A record cannot name the commit that adds the file.",
|
| 401 |
+
"",
|
| 402 |
+
f"Listed symbols: {listed}. Public entry points: {public}. Reachable now: {reachable}. Tested: {tested}. Refused: {refused}. The plan on main recorded 879 reachable. An earlier draft head of the stage-1 PR recorded 89 reachable, before the call sweep. Methods open because a constructor is allowlisted: {opened}. The refused-imports fence is unchanged.",
|
| 403 |
+
"Reachable means `public_entry_refusal` returns None. Tested means a public tool calls that entry point and `tests/test_aureon_public_stage1.py` or `tests/test_aureon_public_stage2.py` exercises the tool. Refused means a public entry point the server will not run. Plan stages 3 and 4 stay closed. The call sweep calls every entry point that was still reachable, with no arguments, and calls each stage-2 entry point again with the real arguments in `stage2_arguments.py`. `SwarmAgent.update` is also called with the hive fixture named below. It refuses one that opens a connection, starts a process, writes outside the sandbox, or loads queen, miner, swarm_motion, inhouse_ai, ollama_config, or an HTTP client. `get_unified_directive` is refused that way. It does not build the queen and miner bridges.",
|
| 404 |
+
"",
|
| 405 |
+
"## Stage order",
|
| 406 |
+
"",
|
| 407 |
+
"The stage is the inventory safety text, not a new scan.",
|
| 408 |
+
"",
|
| 409 |
+
"1. Deterministic read-only. No key, order, live-fetch, process, or write sentence, and the package is not operator-only.",
|
| 410 |
+
"2. A process or write sentence, and still no key, order, or live-fetch sentence.",
|
| 411 |
+
"3. Operator-scoped, with no pure public row and no key, order, or live-fetch sentence.",
|
| 412 |
+
"4. Last. Any key, order, or live-fetch sentence, plus the refused-imports fence. The fence is `_BLOCKED` and `unified_margin_trader`. This run does not add to it and does not import it.",
|
| 413 |
+
"",
|
| 414 |
+
f"Packages still excluded by `more_layers`: {', '.join(excluded)}. `generated` left that list because its score model is deterministic and does not fetch. The other exclusions stay.",
|
| 415 |
+
"",
|
| 416 |
+
f"Within a stage, packages are alphabetical. The first package is `{first}`.",
|
| 417 |
+
"Stage 1 is the deterministic read-only packages. This run opens generated and swarm, after alignment. Organism is stage 4 because its join loads the in-house adapter chain.",
|
| 418 |
+
"Stage 2 is open. A stage-2 module whose import loads an adapter or an HTTP client, starts a process, or writes outside the sandbox is refused. A stage-2 entry point is refused when the no-argument call or a real-argument call does any of those, or does not finish. `atn` stays excluded. `conversion` has no public function or method and stays excluded.",
|
| 419 |
+
"",
|
| 420 |
+
"## Counts",
|
| 421 |
+
"",
|
| 422 |
+
"| Stage | Package | Listed | Public entry points | Reachable now | Tested | Refused |",
|
| 423 |
+
"| ---: | --- | ---: | ---: | ---: | ---: | ---: |",
|
| 424 |
+
]
|
| 425 |
+
for row in rows:
|
| 426 |
+
lines.append(
|
| 427 |
+
f"| {row['stage']} | {row['package']} | {row['listed']} | {row['public_entry_points']} | {row['reachable']} | {row['tested']} | {row['refused']} |"
|
| 428 |
+
)
|
| 429 |
+
lines.extend(
|
| 430 |
+
[
|
| 431 |
+
"",
|
| 432 |
+
"## Fence",
|
| 433 |
+
"",
|
| 434 |
+
"These packages are stage 4 because they are on the refused-imports fence or an inventory row says order. `body_call` returns `live_orders: refused` and does not import them.",
|
| 435 |
+
"",
|
| 436 |
+
]
|
| 437 |
+
)
|
| 438 |
+
for name in sorted(FENCE):
|
| 439 |
+
lines.append(f"- `{name}`")
|
| 440 |
+
by_name = {row["package"]: row for row in rows}
|
| 441 |
+
queen_stage = by_name["queen"]["stage"]
|
| 442 |
+
miner_stage = by_name["miner"]["stage"]
|
| 443 |
+
both_open = max(queen_stage, miner_stage)
|
| 444 |
+
lines.extend(
|
| 445 |
+
[
|
| 446 |
+
"",
|
| 447 |
+
f"## Stage {both_open}",
|
| 448 |
+
"",
|
| 449 |
+
f"`alignment/unified_directive.py` `get_unified_directive` is not a stage-1 tool. Queen is stage {queen_stage}. Miner is stage {miner_stage}. `body_call` refuses it now. The no-argument call is in the call sweep.",
|
| 450 |
+
"",
|
| 451 |
+
"Calling `get_unified_directive` constructs `UnifiedHarmonicDirective` with auto-wire on. That constructs `QueenAIBridge` and `MinerAIBridge`. Each bridge loads `AureonBrainAdapter` as the reasoning backend when the Ollama switchboard is missing or unhealthy, and each bridge wires itself to a `ThoughtBus`. The call imports `aureon.queen`, `aureon.miner`, and `aureon.swarm_motion`, and it attempted a connection to `127.0.0.1:11434`. The sweep blocked that socket.",
|
| 452 |
+
"",
|
| 453 |
+
"## This run",
|
| 454 |
+
"",
|
| 455 |
+
"`alignment` stays the first stage-1 package. `get_pillar_alignment` stays, with `auto_load_pillars` false. `get_unified_directive` is not a stage-1 tool. This run opens `generated` and `swarm`. `organism` is not opened.",
|
| 456 |
+
"Generated was on the more_layers exclusion list. It is open because `aureon/generated/research_cinema/harmonic_nexus_score_model.py` imports only dataclasses and its module docstring calls it a deterministic helper, not trading authority. The four entry points are `build_default_inputs`, `HarmonicNexusScoreInputs.normalized`, `harmonic_nexus_score`, and `score_breakdown`. `tests/generated/test_harmonic_nexus_score_model.py` shows all-ones inputs score 100.0. That 100 is the weighted sum in that file. It does not score any Aureon or HNC claim and cannot be quoted as evidence.",
|
| 457 |
+
"`body_call` refuses `organism/repository_layers.py` `compose_repository_layers`. With the checkout beside `NEXUS-LIVE-FEED-` and `Aureon-Trading--Project-Sero`, that call uses `Path(__file__).parents[3]`, independent of `AUREON_REPOS_ROOT`, and execs those sibling modules outside the pin. One call also loads `core.organism_composition`, and through that `aureon.inhouse_ai.llm_adapter`, `agent_runner`, `orchestrator`, `aureon.ollama_config`, and `aureon.autonomous.aureon_internal_coding_workforce`. `inhouse_ai` stays excluded. Organism reachable is 0.",
|
| 458 |
+
"`body_call` refuses `swarm/capability_grid.py` `build_lane`. `build_lane(\"fintech\")` imports `aureon.accounting`, and that package init reaches `aureon.autonomous.aureon_internal_coding_workforce`, which imports `aureon.inhouse_ai` and `aureon.ollama_config`. Swarm reachable is 15.",
|
| 459 |
+
"The swarm tools use fixtures from the swarm tests or fixed example arguments. `SwarmAgent.update` uses the first call in `tests/test_swarm_hive.py` `test_agent_keeps_a_normalized_soft_simplex`: agent `a1`, role `research`, actions hold, advance, and retreat, CONTEXT `[0.4, 0.2, -0.1, 0.3, 0.0, 0.1, -0.2, 0.05]`, an empty cluster, and no echo. The function returns None. Classes that need nested agent instances stay off the constructor allowlist: Cluster, Company, Zone, FleadhCompany, VisitorAgent, and WorkerAgent. Name-blocked `run_` entry points stay refused. `SwarmAgent.purity` and `ClusterCoherence.warm` are properties. The worker calls methods, so `body_call` and `dispatch` refuse them. `CausalEchoBus.possibilities` is refused because one call cannot park an ensemble and then read it. `issue_auris_node_receipt` needs a `TrustedAurisNodeResolver` that is not built from JSON. `validate_auris_node_receipt`, `validate_hnc_evidence`, `validate_provider_moment`, `validate_council_receipt`, and `validate_seat_receipt` are refused: the receipt is assembled by the test harness, and the public result cap would drop its fields.",
|
| 460 |
+
*_stage2_lines(),
|
| 461 |
+
*_reconciliation_lines(),
|
| 462 |
+
"",
|
| 463 |
+
"The pin stays `8aa6a2d971cc529484e2a5e261e28afafab4e4f4`. The alignment modules at this checkout match that pin, so the tools do not need a newer commit. `GUARD_BLOB` and `INVENTORY_SHA256` are unchanged.",
|
| 464 |
+
"",
|
| 465 |
+
"## MCP SDK",
|
| 466 |
+
"",
|
| 467 |
+
"This server imports `FastMCP` from `mcp.server.fastmcp` and passes `host`, `port`, and `streamable_http_path` to that constructor. The requirement is `mcp==1.30.0,<2` in `mcp/aureon_public/requirements.txt` and `mcp/pyproject.toml`. That specifier matches 1.30.0 and excludes every 2.x release. Migration to SDK v2 is a later decision.",
|
| 468 |
+
"",
|
| 469 |
+
"The claim that official Python SDK v2 renamed `FastMCP` to `MCPServer` was checked against the published package and the v2 source. The claim is true.",
|
| 470 |
+
"",
|
| 471 |
+
"- PyPI project `mcp`: `info.version` is 2.3.0. The newest 1.x release is 1.30.0. https://pypi.org/pypi/mcp/json",
|
| 472 |
+
"- Release v2.0.0, published 28 July 2026, says `FastMCP` is now `MCPServer`, v1.x is maintenance-only on branch `v1.x`, and a project that is not migrating should keep a `<2` upper bound, for example `mcp>=1.28,<2`. https://github.com/modelcontextprotocol/python-sdk/releases/tag/v2.0.0",
|
| 473 |
+
"- Migration guide, section `FastMCP` renamed to `MCPServer`: `from mcp.server.fastmcp import FastMCP` becomes `from mcp.server.mcpserver import MCPServer`. https://py.sdk.modelcontextprotocol.io/v2/migration/",
|
| 474 |
+
"- Tag v2.0.0 and tag v2.3.0 `src/mcp/server/__init__.py` export `MCPServer` from `.mcpserver`. https://github.com/modelcontextprotocol/python-sdk/blob/v2.3.0/src/mcp/server/__init__.py",
|
| 475 |
+
"- Tag v2.3.0 `src/mcp/server/mcpserver/server.py` defines `class MCPServer`. `MCPServer.__init__` takes no `host`, `port`, or `streamable_http_path`. Those arguments are on `run(transport=\"streamable-http\")`. The default name when none is passed is `mcp-server`. `instructions` is no longer the second positional parameter. https://github.com/modelcontextprotocol/python-sdk/blob/v2.3.0/src/mcp/server/mcpserver/server.py",
|
| 476 |
+
"- `src/mcp/server/fastmcp/__init__.py` on tag v2.3.0 is not published. The raw URL returns HTTP 404. https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/v2.3.0/src/mcp/server/fastmcp/__init__.py",
|
| 477 |
+
"- v1 documentation stays at https://py.sdk.modelcontextprotocol.io/v1/",
|
| 478 |
+
"",
|
| 479 |
+
"The same v2.0.0 notes also replace `ClientSession` plus the transport clients with `Client`, and the v2.3.0 constructor no longer accepts `host`, `port`, or `streamable_http_path`. This server still passes those three to `FastMCP`, and the measured client still uses `ClientSession`. Staying on 1.30.0 keeps that call shape.",
|
| 480 |
+
"",
|
| 481 |
+
"The protocol proof is the stdio session and the Streamable HTTP session bound to `127.0.0.1`. The Space scaffold is `mcp/aureon_public/Dockerfile` and `python -m aureon_public.space`. It is not deployed. `AUREON_PUBLIC_API_KEY` enforces a bearer token. `AUREON_PUBLIC_OPEN=1` serves the read-only surface with no key. With neither, Streamable HTTP binds to `127.0.0.1` only. Stages 3 and 4 stay closed.",
|
| 482 |
+
"",
|
| 483 |
+
]
|
| 484 |
+
)
|
| 485 |
+
return "\n".join(lines) + "\n"
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
def main(argv: list[str] | None = None) -> None:
|
| 489 |
+
parser = argparse.ArgumentParser(prog="aureon-public-coverage-plan")
|
| 490 |
+
parser.add_argument("--write", action="store_true")
|
| 491 |
+
parser.add_argument("--check", action="store_true")
|
| 492 |
+
args = parser.parse_args(argv)
|
| 493 |
+
text = render()
|
| 494 |
+
path = repo_root() / PLAN_PATH
|
| 495 |
+
if args.check:
|
| 496 |
+
current = path.read_text(encoding="utf-8") if path.is_file() else ""
|
| 497 |
+
if current != text:
|
| 498 |
+
raise SystemExit("COVERAGE_PLAN.md does not match the inventory")
|
| 499 |
+
return
|
| 500 |
+
if args.write or not args.check:
|
| 501 |
+
path.write_text(text, encoding="utf-8")
|
| 502 |
+
print(path)
|
| 503 |
+
|
| 504 |
+
|
| 505 |
+
if __name__ == "__main__":
|
| 506 |
+
main()
|
guard_loader.py
ADDED
|
@@ -0,0 +1,181 @@
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Apply huggingface/hnc-field/guard.py without keeping its directory change.
|
| 2 |
+
|
| 3 |
+
The Space module chdirs into the Space and may put the checkout on sys.path.
|
| 4 |
+
This loader reuses that module, restores the working directory, and prefers an
|
| 5 |
+
installed aureon distribution over the checkout when one is importable.
|
| 6 |
+
|
| 7 |
+
When that install is missing, imports fall back to the checkout. Callers must
|
| 8 |
+
read aureon_source() rather than assume the documented pin.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import importlib.util
|
| 14 |
+
import json
|
| 15 |
+
import os
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
from pathlib import Path
|
| 19 |
+
|
| 20 |
+
from aureon_public.paths import repo_root, space_guard
|
| 21 |
+
|
| 22 |
+
_DONE = False
|
| 23 |
+
PINNED_COMMIT = "8aa6a2d971cc529484e2a5e261e28afafab4e4f4"
|
| 24 |
+
# git blob of the committed huggingface/hnc-field/guard.py.
|
| 25 |
+
# The check is these bytes. It is not a path lookup inside PINNED_COMMIT.
|
| 26 |
+
GUARD_BLOB = "b59a6ed8b82b98988e57c6897faba3eb9b98948d"
|
| 27 |
+
GUARD_MISMATCH = "checkout guard.py differs from pin 8aa6a2d9"
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def _same(path: str, root: Path) -> bool:
|
| 31 |
+
candidate = path or os.getcwd()
|
| 32 |
+
try:
|
| 33 |
+
return Path(candidate).resolve() == root.resolve()
|
| 34 |
+
except OSError:
|
| 35 |
+
return False
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
def apply_space_guard() -> None:
|
| 39 |
+
"""Install the Space environment and the trading-import blocker."""
|
| 40 |
+
|
| 41 |
+
global _DONE
|
| 42 |
+
if _DONE:
|
| 43 |
+
return
|
| 44 |
+
root = repo_root()
|
| 45 |
+
guard_path = space_guard()
|
| 46 |
+
cwd = Path.cwd()
|
| 47 |
+
real_chdir = os.chdir
|
| 48 |
+
os.chdir = lambda *_args, **_kwargs: None # type: ignore[method-assign]
|
| 49 |
+
try:
|
| 50 |
+
from aureon_public.pin_blob import _SameBytesLoader, git_blob_sha1
|
| 51 |
+
|
| 52 |
+
try:
|
| 53 |
+
data = guard_path.read_bytes()
|
| 54 |
+
except OSError as exc:
|
| 55 |
+
raise ImportError(f"{guard_path.name} is not in this checkout") from exc
|
| 56 |
+
if git_blob_sha1(data) != GUARD_BLOB:
|
| 57 |
+
raise ImportError(GUARD_MISMATCH)
|
| 58 |
+
from aureon_public.pin_blob import install_pinned_aureon_finder
|
| 59 |
+
|
| 60 |
+
install_pinned_aureon_finder(root)
|
| 61 |
+
loader = _SameBytesLoader(data, str(guard_path))
|
| 62 |
+
spec = importlib.util.spec_from_loader(
|
| 63 |
+
"aureon_hf_space_guard",
|
| 64 |
+
loader,
|
| 65 |
+
origin=str(guard_path),
|
| 66 |
+
)
|
| 67 |
+
if spec is None:
|
| 68 |
+
raise ImportError(f"cannot load {guard_path}")
|
| 69 |
+
spec.has_location = True
|
| 70 |
+
module = importlib.util.module_from_spec(spec)
|
| 71 |
+
module.__file__ = str(guard_path)
|
| 72 |
+
sys.modules["aureon_hf_space_guard"] = module
|
| 73 |
+
loader.exec_module(module)
|
| 74 |
+
finally:
|
| 75 |
+
os.chdir = real_chdir
|
| 76 |
+
if Path.cwd() != cwd:
|
| 77 |
+
real_chdir(cwd)
|
| 78 |
+
os.environ.pop("AUREON_MCP_TRANSIT_KEY", None)
|
| 79 |
+
_prefer_installed_aureon(root)
|
| 80 |
+
_DONE = True
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _prefer_installed_aureon(root: Path) -> None:
|
| 84 |
+
"""Use the pinned install when it is present. Otherwise keep the checkout.
|
| 85 |
+
|
| 86 |
+
The pinned finder is already on ``sys.meta_path``. It answers from the
|
| 87 |
+
checkout without reading ``sys.path``, so this probe takes it off the path
|
| 88 |
+
for the lookup. A direct_url.json that names the pin is what keeps the
|
| 89 |
+
trimmed path. The blob check still decides which bytes run.
|
| 90 |
+
"""
|
| 91 |
+
|
| 92 |
+
from aureon_public.pin_blob import PinnedAureonFinder
|
| 93 |
+
|
| 94 |
+
saved = list(sys.path)
|
| 95 |
+
trimmed = [entry for entry in saved if not _same(entry, root)]
|
| 96 |
+
sys.path[:] = trimmed
|
| 97 |
+
removed = [finder for finder in sys.meta_path if isinstance(finder, PinnedAureonFinder)]
|
| 98 |
+
for finder in removed:
|
| 99 |
+
sys.meta_path.remove(finder)
|
| 100 |
+
try:
|
| 101 |
+
found = importlib.util.find_spec("aureon")
|
| 102 |
+
finally:
|
| 103 |
+
for finder in reversed(removed):
|
| 104 |
+
sys.meta_path.insert(0, finder)
|
| 105 |
+
sys.path[:] = saved
|
| 106 |
+
origin = getattr(found, "origin", None) if found is not None else None
|
| 107 |
+
if not origin:
|
| 108 |
+
return
|
| 109 |
+
origin_path = Path(origin)
|
| 110 |
+
if _outside_checkout(origin_path, root) and _direct_url_commit(origin_path) == PINNED_COMMIT:
|
| 111 |
+
sys.path[:] = trimmed
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _outside_checkout(origin: Path, root: Path) -> bool:
|
| 115 |
+
resolved = origin.resolve()
|
| 116 |
+
root_resolved = root.resolve()
|
| 117 |
+
return resolved != root_resolved and root_resolved not in resolved.parents
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _direct_url_commit(origin: Path) -> str | None:
|
| 121 |
+
"""Commit recorded beside an installed aureon, if direct_url.json has one."""
|
| 122 |
+
|
| 123 |
+
site = origin.resolve().parent.parent
|
| 124 |
+
for dist in sorted(site.glob("aureon-*.dist-info")):
|
| 125 |
+
direct = dist / "direct_url.json"
|
| 126 |
+
if not direct.is_file():
|
| 127 |
+
continue
|
| 128 |
+
try:
|
| 129 |
+
payload = json.loads(direct.read_text(encoding="utf-8"))
|
| 130 |
+
except (OSError, json.JSONDecodeError):
|
| 131 |
+
continue
|
| 132 |
+
vcs = payload.get("vcs_info") if isinstance(payload, dict) else None
|
| 133 |
+
commit = vcs.get("commit_id") if isinstance(vcs, dict) else None
|
| 134 |
+
if isinstance(commit, str) and commit.strip():
|
| 135 |
+
return commit.strip()
|
| 136 |
+
return None
|
| 137 |
+
|
| 138 |
+
|
| 139 |
+
def _git_commit(root: Path) -> str:
|
| 140 |
+
try:
|
| 141 |
+
result = subprocess.run(
|
| 142 |
+
["git", "rev-parse", "HEAD"],
|
| 143 |
+
cwd=root,
|
| 144 |
+
check=True,
|
| 145 |
+
capture_output=True,
|
| 146 |
+
text=True,
|
| 147 |
+
)
|
| 148 |
+
except (OSError, subprocess.CalledProcessError):
|
| 149 |
+
return "unknown"
|
| 150 |
+
commit = result.stdout.strip()
|
| 151 |
+
if len(commit) == 40 and all(character in "0123456789abcdef" for character in commit):
|
| 152 |
+
return commit
|
| 153 |
+
return "unknown"
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
def describe_aureon_source(origin: Path | None, root: Path) -> dict[str, str]:
|
| 157 |
+
"""Say which tree answered. Pinned only when direct_url.json names the pin."""
|
| 158 |
+
|
| 159 |
+
if origin is not None and _outside_checkout(origin, root):
|
| 160 |
+
commit = _direct_url_commit(origin)
|
| 161 |
+
if commit == PINNED_COMMIT:
|
| 162 |
+
return {"kind": "pinned", "commit": commit}
|
| 163 |
+
if commit:
|
| 164 |
+
return {"kind": "installed", "commit": commit}
|
| 165 |
+
return {"kind": "checkout", "commit": "unknown"}
|
| 166 |
+
return {"kind": "checkout", "commit": _git_commit(root)}
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def aureon_source() -> dict[str, str]:
|
| 170 |
+
"""The aureon import this process will use, after the guard has chosen a path.
|
| 171 |
+
|
| 172 |
+
Raises FileNotFoundError, via repo_root(), when there is no checkout.
|
| 173 |
+
There is no separate 'no checkout' status. The server needs the checkout.
|
| 174 |
+
"""
|
| 175 |
+
|
| 176 |
+
apply_space_guard()
|
| 177 |
+
root = repo_root()
|
| 178 |
+
found = importlib.util.find_spec("aureon")
|
| 179 |
+
origin_text = getattr(found, "origin", None) if found is not None else None
|
| 180 |
+
origin = Path(origin_text) if origin_text else None
|
| 181 |
+
return describe_aureon_source(origin, root)
|
http_guard.py
ADDED
|
@@ -0,0 +1,454 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Streamable HTTP bind rule, bearer check, and per-client limits.
|
| 2 |
+
|
| 3 |
+
No key is read from disk. AUREON_PUBLIC_API_KEY is an optional runtime
|
| 4 |
+
environment variable. When it is unset, the public surface is served only if
|
| 5 |
+
AUREON_PUBLIC_OPEN=1. With neither one set, the listener must be 127.0.0.1.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import asyncio
|
| 11 |
+
import hashlib
|
| 12 |
+
import hmac
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import time
|
| 16 |
+
from collections import OrderedDict
|
| 17 |
+
from collections.abc import Callable
|
| 18 |
+
from dataclasses import dataclass
|
| 19 |
+
|
| 20 |
+
LOCAL_BIND = "127.0.0.1"
|
| 21 |
+
_DEFAULT_RATE_LIMIT = 120
|
| 22 |
+
_DEFAULT_RATE_WINDOW_S = 60.0
|
| 23 |
+
_DEFAULT_MAX_BODY = 1_048_576
|
| 24 |
+
_DEFAULT_TIMEOUT_S = 30.0
|
| 25 |
+
_DEFAULT_TRUSTED_PROXY_HOPS = 1
|
| 26 |
+
_DEFAULT_MAX_CLIENTS = 4096
|
| 27 |
+
# The public worker pool is 4. One live session holds the SSE GET and a POST
|
| 28 |
+
# at the same time, so the cap stays at that same low number.
|
| 29 |
+
_DEFAULT_MAX_INFLIGHT = 4
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@dataclass(frozen=True)
|
| 33 |
+
class HttpLimits:
|
| 34 |
+
"""Limits for one server process. Values come from the environment."""
|
| 35 |
+
|
| 36 |
+
api_key: str
|
| 37 |
+
max_body_bytes: int
|
| 38 |
+
rate_limit: int
|
| 39 |
+
rate_window_s: float
|
| 40 |
+
timeout_s: float
|
| 41 |
+
trusted_proxy_hops: int = _DEFAULT_TRUSTED_PROXY_HOPS
|
| 42 |
+
max_clients: int = _DEFAULT_MAX_CLIENTS
|
| 43 |
+
max_inflight: int = _DEFAULT_MAX_INFLIGHT
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class RateLimiter:
|
| 47 |
+
"""Fixed window of request starts, keyed by client id.
|
| 48 |
+
|
| 49 |
+
Expired windows are dropped. The table keeps at most ``max_clients``
|
| 50 |
+
ids and evicts the least recently used id when a new one arrives.
|
| 51 |
+
"""
|
| 52 |
+
|
| 53 |
+
def __init__(
|
| 54 |
+
self,
|
| 55 |
+
limit: int,
|
| 56 |
+
window_s: float,
|
| 57 |
+
max_clients: int = _DEFAULT_MAX_CLIENTS,
|
| 58 |
+
now: Callable[[], float] | None = None,
|
| 59 |
+
) -> None:
|
| 60 |
+
self.limit = limit
|
| 61 |
+
self.window_s = window_s
|
| 62 |
+
self.max_clients = max_clients
|
| 63 |
+
self._now = now or time.monotonic
|
| 64 |
+
self._hits: OrderedDict[str, list[float]] = OrderedDict()
|
| 65 |
+
|
| 66 |
+
def allow(self, client_id: str) -> bool:
|
| 67 |
+
now = self._now()
|
| 68 |
+
self._evict_expired(now)
|
| 69 |
+
if client_id in self._hits:
|
| 70 |
+
self._hits.move_to_end(client_id)
|
| 71 |
+
elif len(self._hits) >= self.max_clients:
|
| 72 |
+
self._hits.popitem(last=False)
|
| 73 |
+
hits = [stamp for stamp in self._hits.get(client_id, []) if now - stamp < self.window_s]
|
| 74 |
+
if len(hits) >= self.limit:
|
| 75 |
+
self._hits[client_id] = hits
|
| 76 |
+
self._hits.move_to_end(client_id)
|
| 77 |
+
return False
|
| 78 |
+
hits.append(now)
|
| 79 |
+
self._hits[client_id] = hits
|
| 80 |
+
self._hits.move_to_end(client_id)
|
| 81 |
+
return True
|
| 82 |
+
|
| 83 |
+
def _evict_expired(self, now: float) -> None:
|
| 84 |
+
expired = [
|
| 85 |
+
client_id
|
| 86 |
+
for client_id, hits in self._hits.items()
|
| 87 |
+
if not hits or now - hits[-1] >= self.window_s
|
| 88 |
+
]
|
| 89 |
+
for client_id in expired:
|
| 90 |
+
del self._hits[client_id]
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def _positive_int(name: str, default: int) -> int:
|
| 94 |
+
raw = os.environ.get(name, "").strip()
|
| 95 |
+
if not raw:
|
| 96 |
+
return default
|
| 97 |
+
try:
|
| 98 |
+
value = int(raw)
|
| 99 |
+
except ValueError as exc:
|
| 100 |
+
raise SystemExit(f"{name} must be a positive integer") from exc
|
| 101 |
+
if value <= 0:
|
| 102 |
+
raise SystemExit(f"{name} must be a positive integer")
|
| 103 |
+
return value
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def _positive_float(name: str, default: float) -> float:
|
| 107 |
+
raw = os.environ.get(name, "").strip()
|
| 108 |
+
if not raw:
|
| 109 |
+
return default
|
| 110 |
+
try:
|
| 111 |
+
value = float(raw)
|
| 112 |
+
except ValueError as exc:
|
| 113 |
+
raise SystemExit(f"{name} must be a positive number") from exc
|
| 114 |
+
if value <= 0:
|
| 115 |
+
raise SystemExit(f"{name} must be a positive number")
|
| 116 |
+
return value
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def load_http_limits() -> HttpLimits:
|
| 120 |
+
"""Read the optional key and the limit environment variables."""
|
| 121 |
+
|
| 122 |
+
return HttpLimits(
|
| 123 |
+
api_key=os.environ.get("AUREON_PUBLIC_API_KEY", "").strip(),
|
| 124 |
+
max_body_bytes=_positive_int("AUREON_PUBLIC_MAX_BODY_BYTES", _DEFAULT_MAX_BODY),
|
| 125 |
+
rate_limit=_positive_int("AUREON_PUBLIC_RATE_LIMIT", _DEFAULT_RATE_LIMIT),
|
| 126 |
+
rate_window_s=_positive_float("AUREON_PUBLIC_RATE_WINDOW_S", _DEFAULT_RATE_WINDOW_S),
|
| 127 |
+
timeout_s=_positive_float("AUREON_PUBLIC_REQUEST_TIMEOUT_S", _DEFAULT_TIMEOUT_S),
|
| 128 |
+
trusted_proxy_hops=_nonnegative_int(
|
| 129 |
+
"AUREON_PUBLIC_TRUSTED_PROXY_HOPS",
|
| 130 |
+
_DEFAULT_TRUSTED_PROXY_HOPS,
|
| 131 |
+
),
|
| 132 |
+
max_clients=_positive_int("AUREON_PUBLIC_RATE_MAX_CLIENTS", _DEFAULT_MAX_CLIENTS),
|
| 133 |
+
max_inflight=_positive_int("AUREON_PUBLIC_MAX_INFLIGHT", _DEFAULT_MAX_INFLIGHT),
|
| 134 |
+
)
|
| 135 |
+
|
| 136 |
+
|
| 137 |
+
def _nonnegative_int(name: str, default: int) -> int:
|
| 138 |
+
raw = os.environ.get(name, "").strip()
|
| 139 |
+
if not raw:
|
| 140 |
+
return default
|
| 141 |
+
try:
|
| 142 |
+
value = int(raw)
|
| 143 |
+
except ValueError as exc:
|
| 144 |
+
raise SystemExit(f"{name} must be a non-negative integer") from exc
|
| 145 |
+
if value < 0:
|
| 146 |
+
raise SystemExit(f"{name} must be a non-negative integer")
|
| 147 |
+
return value
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def public_bind_allowed(host: str) -> bool:
|
| 151 |
+
"""True when this host may listen.
|
| 152 |
+
|
| 153 |
+
A bearer key or AUREON_PUBLIC_OPEN=1 allows the requested host. Otherwise
|
| 154 |
+
only 127.0.0.1 is allowed.
|
| 155 |
+
"""
|
| 156 |
+
|
| 157 |
+
if os.environ.get("AUREON_PUBLIC_API_KEY", "").strip():
|
| 158 |
+
return True
|
| 159 |
+
if os.environ.get("AUREON_PUBLIC_OPEN") == "1":
|
| 160 |
+
return True
|
| 161 |
+
return host == LOCAL_BIND
|
| 162 |
+
|
| 163 |
+
|
| 164 |
+
def resolve_http_bind(host: str) -> str:
|
| 165 |
+
"""Return host, or refuse a non-local bind when the surface is locked."""
|
| 166 |
+
|
| 167 |
+
if public_bind_allowed(host):
|
| 168 |
+
return host
|
| 169 |
+
raise SystemExit(
|
| 170 |
+
"Streamable HTTP binds to 127.0.0.1 unless AUREON_PUBLIC_API_KEY is set "
|
| 171 |
+
"or AUREON_PUBLIC_OPEN=1."
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def _header_map(scope: dict) -> dict[str, str]:
|
| 176 |
+
found: dict[str, str] = {}
|
| 177 |
+
for key, value in scope.get("headers") or []:
|
| 178 |
+
found[key.decode("latin1").lower()] = value.decode("latin1")
|
| 179 |
+
return found
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def _bearer(authorization: str) -> str | None:
|
| 183 |
+
parts = authorization.split(" ", 1)
|
| 184 |
+
if len(parts) != 2 or parts[0].lower() != "bearer":
|
| 185 |
+
return None
|
| 186 |
+
token = parts[1].strip()
|
| 187 |
+
if not token:
|
| 188 |
+
return None
|
| 189 |
+
return token
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
def _key_matches(presented: str, expected: str) -> bool:
|
| 193 |
+
presented_bytes = presented.encode("utf-8")
|
| 194 |
+
expected_bytes = expected.encode("utf-8")
|
| 195 |
+
if len(presented_bytes) != len(expected_bytes):
|
| 196 |
+
return False
|
| 197 |
+
return hmac.compare_digest(presented_bytes, expected_bytes)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
def _socket_peer(scope: dict) -> str:
|
| 201 |
+
client = scope.get("client")
|
| 202 |
+
if isinstance(client, (list, tuple)) and client and client[0]:
|
| 203 |
+
return str(client[0])
|
| 204 |
+
return "unknown"
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def _forwarded_hops(value: str) -> list[str]:
|
| 208 |
+
return [part.strip() for part in value.split(",") if part.strip()]
|
| 209 |
+
|
| 210 |
+
|
| 211 |
+
def client_address(scope: dict, headers: dict[str, str], trusted_proxy_hops: int) -> str:
|
| 212 |
+
"""Client address behind ``trusted_proxy_hops`` trusted proxies.
|
| 213 |
+
|
| 214 |
+
``AUREON_PUBLIC_TRUSTED_PROXY_HOPS`` defaults to 1. When the header is
|
| 215 |
+
present and has at least that many values, the client is
|
| 216 |
+
``hops[-trusted_proxy_hops]``. With the default, that is the last value,
|
| 217 |
+
including a header that contains only one address. A fake first hop does
|
| 218 |
+
not become its own bucket. Zero trusted hops ignores the header and uses
|
| 219 |
+
the socket peer. The real Hugging Face header shape still has to be
|
| 220 |
+
confirmed on the private Space.
|
| 221 |
+
"""
|
| 222 |
+
|
| 223 |
+
peer = _socket_peer(scope)
|
| 224 |
+
note_forwarded_shape(headers.get("x-forwarded-for", ""))
|
| 225 |
+
if trusted_proxy_hops <= 0:
|
| 226 |
+
return peer
|
| 227 |
+
hops = _forwarded_hops(headers.get("x-forwarded-for", ""))
|
| 228 |
+
if len(hops) < trusted_proxy_hops:
|
| 229 |
+
return peer
|
| 230 |
+
return hops[-trusted_proxy_hops]
|
| 231 |
+
|
| 232 |
+
|
| 233 |
+
_SHAPE_CAP = 32
|
| 234 |
+
_forwarded_shapes: list[dict[str, object]] = []
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def _hop_kind(token: str) -> str:
|
| 238 |
+
"""Classify one hop. The returned label is not the address."""
|
| 239 |
+
|
| 240 |
+
host = token.strip()
|
| 241 |
+
if host.startswith("[") and "]" in host:
|
| 242 |
+
host = host[1 : host.index("]")]
|
| 243 |
+
elif host.count(":") == 1 and host.rsplit(":", 1)[-1].isdigit():
|
| 244 |
+
host = host.rsplit(":", 1)[0]
|
| 245 |
+
try:
|
| 246 |
+
import ipaddress
|
| 247 |
+
|
| 248 |
+
parsed = ipaddress.ip_address(host)
|
| 249 |
+
except ValueError:
|
| 250 |
+
return "other"
|
| 251 |
+
return "ipv4" if parsed.version == 4 else "ipv6"
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def note_forwarded_shape(value: str) -> None:
|
| 255 |
+
"""Record hop count and hop kinds when the diagnostic is on.
|
| 256 |
+
|
| 257 |
+
``AUREON_PUBLIC_FORWARDED_DIAG=1`` opts in. The record does not store the
|
| 258 |
+
header or the addresses.
|
| 259 |
+
"""
|
| 260 |
+
|
| 261 |
+
if os.environ.get("AUREON_PUBLIC_FORWARDED_DIAG") != "1":
|
| 262 |
+
return
|
| 263 |
+
hops = _forwarded_hops(value)
|
| 264 |
+
_forwarded_shapes.append({"hops": len(hops), "kinds": [_hop_kind(hop) for hop in hops]})
|
| 265 |
+
del _forwarded_shapes[:-_SHAPE_CAP]
|
| 266 |
+
|
| 267 |
+
|
| 268 |
+
def forwarded_shapes() -> list[dict[str, object]]:
|
| 269 |
+
"""Copies of the diagnostic shapes. Empty unless the diagnostic is on."""
|
| 270 |
+
|
| 271 |
+
return [dict(item) for item in _forwarded_shapes]
|
| 272 |
+
|
| 273 |
+
|
| 274 |
+
def clear_forwarded_shapes() -> None:
|
| 275 |
+
_forwarded_shapes.clear()
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
def _client_id(scope: dict, headers: dict[str, str], limits: HttpLimits) -> str:
|
| 279 |
+
"""Bucket by address. The bearer is the id only when it matches the configured key.
|
| 280 |
+
|
| 281 |
+
Open mode has no configured key, so a presented bearer is never the client id.
|
| 282 |
+
"""
|
| 283 |
+
|
| 284 |
+
address = client_address(scope, headers, limits.trusted_proxy_hops)
|
| 285 |
+
if limits.api_key:
|
| 286 |
+
presented = _bearer(headers.get("authorization", ""))
|
| 287 |
+
if presented is not None and _key_matches(presented, limits.api_key):
|
| 288 |
+
digest = hashlib.sha256(presented.encode("utf-8")).hexdigest()
|
| 289 |
+
return f"bearer:{digest}"
|
| 290 |
+
return f"ip:{address}"
|
| 291 |
+
|
| 292 |
+
|
| 293 |
+
def _content_length(headers: dict[str, str]) -> int | None:
|
| 294 |
+
raw = headers.get("content-length", "").strip()
|
| 295 |
+
if not raw or not raw.isdigit():
|
| 296 |
+
return None
|
| 297 |
+
return int(raw)
|
| 298 |
+
|
| 299 |
+
|
| 300 |
+
async def _reject(send, status: int, error: str, *, retry_after: str | None = None) -> None:
|
| 301 |
+
body = json.dumps({"error": error}).encode("utf-8")
|
| 302 |
+
header_list = [
|
| 303 |
+
(b"content-type", b"application/json"),
|
| 304 |
+
(b"content-length", str(len(body)).encode("ascii")),
|
| 305 |
+
]
|
| 306 |
+
if status == 401:
|
| 307 |
+
header_list.append((b"www-authenticate", b"Bearer"))
|
| 308 |
+
if status == 405:
|
| 309 |
+
header_list.append((b"allow", b"POST"))
|
| 310 |
+
if retry_after is not None:
|
| 311 |
+
header_list.append((b"retry-after", retry_after.encode("ascii")))
|
| 312 |
+
await send({"type": "http.response.start", "status": status, "headers": header_list})
|
| 313 |
+
await send({"type": "http.response.body", "body": body})
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
class PublicHttpMiddleware:
|
| 317 |
+
"""ASGI wrapper for the Streamable HTTP app. Lifespan scopes pass through."""
|
| 318 |
+
|
| 319 |
+
def __init__(self, app, limits: HttpLimits, limiter: RateLimiter | None = None) -> None:
|
| 320 |
+
self.app = app
|
| 321 |
+
self.limits = limits
|
| 322 |
+
self.limiter = limiter if limiter is not None else RateLimiter(
|
| 323 |
+
limits.rate_limit,
|
| 324 |
+
limits.rate_window_s,
|
| 325 |
+
max_clients=limits.max_clients,
|
| 326 |
+
)
|
| 327 |
+
self._inflight = 0
|
| 328 |
+
self._inflight_lock = asyncio.Lock()
|
| 329 |
+
|
| 330 |
+
async def __call__(self, scope, receive, send) -> None:
|
| 331 |
+
if scope.get("type") != "http":
|
| 332 |
+
await self.app(scope, receive, send)
|
| 333 |
+
return
|
| 334 |
+
path = scope.get("path") or ""
|
| 335 |
+
if path != "/mcp" and not path.startswith("/mcp/"):
|
| 336 |
+
await self.app(scope, receive, send)
|
| 337 |
+
return
|
| 338 |
+
headers = _header_map(scope)
|
| 339 |
+
client_id = _client_id(scope, headers, self.limits)
|
| 340 |
+
if not self.limiter.allow(client_id):
|
| 341 |
+
retry_after = str(max(1, int(self.limits.rate_window_s)))
|
| 342 |
+
await _reject(send, 429, "rate_limit", retry_after=retry_after)
|
| 343 |
+
return
|
| 344 |
+
if self.limits.api_key:
|
| 345 |
+
presented = _bearer(headers.get("authorization", ""))
|
| 346 |
+
if presented is None or not _key_matches(presented, self.limits.api_key):
|
| 347 |
+
await _reject(send, 401, "unauthorized")
|
| 348 |
+
return
|
| 349 |
+
method = scope.get("method", "GET")
|
| 350 |
+
if method == "GET":
|
| 351 |
+
# Streamable HTTP's long-lived event stream. Stateless JSON mode
|
| 352 |
+
# does not use it. Answering here keeps it off the call slots.
|
| 353 |
+
await _reject(send, 405, "method_not_allowed")
|
| 354 |
+
return
|
| 355 |
+
if method == "POST":
|
| 356 |
+
declared = _content_length(headers)
|
| 357 |
+
if declared is not None and declared > self.limits.max_body_bytes:
|
| 358 |
+
await _reject(send, 413, "body_too_large")
|
| 359 |
+
return
|
| 360 |
+
receive = await _bounded_receive(
|
| 361 |
+
receive,
|
| 362 |
+
self.limits.max_body_bytes,
|
| 363 |
+
send,
|
| 364 |
+
self.limits.timeout_s,
|
| 365 |
+
)
|
| 366 |
+
if receive is None:
|
| 367 |
+
return
|
| 368 |
+
if not await self._acquire_inflight():
|
| 369 |
+
await _reject(send, 503, "busy")
|
| 370 |
+
return
|
| 371 |
+
try:
|
| 372 |
+
if method != "POST":
|
| 373 |
+
await self.app(scope, receive, send)
|
| 374 |
+
return
|
| 375 |
+
started = False
|
| 376 |
+
|
| 377 |
+
async def send_wrapper(message) -> None:
|
| 378 |
+
nonlocal started
|
| 379 |
+
if message.get("type") == "http.response.start":
|
| 380 |
+
started = True
|
| 381 |
+
await send(message)
|
| 382 |
+
|
| 383 |
+
try:
|
| 384 |
+
await asyncio.wait_for(
|
| 385 |
+
self.app(scope, receive, send_wrapper),
|
| 386 |
+
timeout=self.limits.timeout_s,
|
| 387 |
+
)
|
| 388 |
+
except TimeoutError:
|
| 389 |
+
if started:
|
| 390 |
+
raise
|
| 391 |
+
await _reject(send, 504, "timeout")
|
| 392 |
+
finally:
|
| 393 |
+
await self._release_inflight()
|
| 394 |
+
|
| 395 |
+
async def _acquire_inflight(self) -> bool:
|
| 396 |
+
async with self._inflight_lock:
|
| 397 |
+
if self._inflight >= self.limits.max_inflight:
|
| 398 |
+
return False
|
| 399 |
+
self._inflight += 1
|
| 400 |
+
return True
|
| 401 |
+
|
| 402 |
+
async def _release_inflight(self) -> None:
|
| 403 |
+
async with self._inflight_lock:
|
| 404 |
+
self._inflight -= 1
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
async def _bounded_receive(receive, max_body: int, send, timeout_s: float):
|
| 408 |
+
"""Buffer a POST body and reject it once the arrived bytes pass the cap.
|
| 409 |
+
|
| 410 |
+
Chunked requests omit content-length. Every message is counted until
|
| 411 |
+
``more_body`` is false or the client disconnects. Empty chunks do not
|
| 412 |
+
stop the count, and the unread remainder is not passed through.
|
| 413 |
+
``timeout_s`` bounds the whole read. An idle or unfinished body returns
|
| 414 |
+
HTTP 408 instead of handing the stream to the application.
|
| 415 |
+
"""
|
| 416 |
+
|
| 417 |
+
buffered: list[dict] = []
|
| 418 |
+
total = 0
|
| 419 |
+
deadline = asyncio.get_running_loop().time() + timeout_s
|
| 420 |
+
while True:
|
| 421 |
+
remaining = deadline - asyncio.get_running_loop().time()
|
| 422 |
+
if remaining <= 0:
|
| 423 |
+
await _reject(send, 408, "body_timeout")
|
| 424 |
+
return None
|
| 425 |
+
try:
|
| 426 |
+
message = await asyncio.wait_for(receive(), timeout=remaining)
|
| 427 |
+
except TimeoutError:
|
| 428 |
+
await _reject(send, 408, "body_timeout")
|
| 429 |
+
return None
|
| 430 |
+
kind = message.get("type")
|
| 431 |
+
if kind != "http.request":
|
| 432 |
+
buffered.append(message)
|
| 433 |
+
if kind == "http.disconnect":
|
| 434 |
+
break
|
| 435 |
+
continue
|
| 436 |
+
chunk = message.get("body") or b""
|
| 437 |
+
total += len(chunk)
|
| 438 |
+
if total > max_body:
|
| 439 |
+
await _reject(send, 413, "body_too_large")
|
| 440 |
+
return None
|
| 441 |
+
buffered.append(message)
|
| 442 |
+
if not message.get("more_body", False):
|
| 443 |
+
break
|
| 444 |
+
index = 0
|
| 445 |
+
|
| 446 |
+
async def replay():
|
| 447 |
+
nonlocal index
|
| 448 |
+
if index < len(buffered):
|
| 449 |
+
message = buffered[index]
|
| 450 |
+
index += 1
|
| 451 |
+
return message
|
| 452 |
+
return await receive()
|
| 453 |
+
|
| 454 |
+
return replay
|
inventory_scan.py
ADDED
|
@@ -0,0 +1,405 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Scan public modules, classes, and functions for the full-body plan.
|
| 2 |
+
|
| 3 |
+
The scan is AST only. It does not import aureon and it does not call anything.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import ast
|
| 9 |
+
import json
|
| 10 |
+
import re
|
| 11 |
+
from collections import Counter, defaultdict
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
STAGE = {
|
| 15 |
+
"harmonic": 1,
|
| 16 |
+
"cognition": 2,
|
| 17 |
+
"queen": 2,
|
| 18 |
+
"swarm": 2,
|
| 19 |
+
"swarm_motion": 2,
|
| 20 |
+
"gates": 2,
|
| 21 |
+
"governance": 2,
|
| 22 |
+
"alignment": 2,
|
| 23 |
+
"observer": 2,
|
| 24 |
+
"organism": 3,
|
| 25 |
+
"bio": 3,
|
| 26 |
+
"evaluation": 3,
|
| 27 |
+
"vault": 3,
|
| 28 |
+
"identity": 3,
|
| 29 |
+
"data_feeds": 4,
|
| 30 |
+
"atn": 4,
|
| 31 |
+
"decoders": 4,
|
| 32 |
+
"search": 4,
|
| 33 |
+
"portals": 4,
|
| 34 |
+
"monitors": 4,
|
| 35 |
+
"analytics": 4,
|
| 36 |
+
"trading": 5,
|
| 37 |
+
"exchanges": 5,
|
| 38 |
+
"bots": 5,
|
| 39 |
+
"bots_intelligence": 5,
|
| 40 |
+
"bridges": 5,
|
| 41 |
+
"scanners": 5,
|
| 42 |
+
"strategies": 5,
|
| 43 |
+
"portfolio": 5,
|
| 44 |
+
"accounting": 5,
|
| 45 |
+
"conversion": 5,
|
| 46 |
+
"autonomous": 6,
|
| 47 |
+
"code_architect": 6,
|
| 48 |
+
"inhouse_ai": 6,
|
| 49 |
+
"operator": 6,
|
| 50 |
+
"launch": 6,
|
| 51 |
+
"command_centers": 6,
|
| 52 |
+
"connectors": 6,
|
| 53 |
+
"saas": 6,
|
| 54 |
+
"miner": 6,
|
| 55 |
+
"generated": 6,
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
OPERATOR_PACKAGES = {
|
| 59 |
+
"trading",
|
| 60 |
+
"exchanges",
|
| 61 |
+
"bots",
|
| 62 |
+
"bots_intelligence",
|
| 63 |
+
"bridges",
|
| 64 |
+
"scanners",
|
| 65 |
+
"strategies",
|
| 66 |
+
"portfolio",
|
| 67 |
+
"accounting",
|
| 68 |
+
"conversion",
|
| 69 |
+
"autonomous",
|
| 70 |
+
"code_architect",
|
| 71 |
+
"inhouse_ai",
|
| 72 |
+
"operator",
|
| 73 |
+
"launch",
|
| 74 |
+
"command_centers",
|
| 75 |
+
"connectors",
|
| 76 |
+
"saas",
|
| 77 |
+
"miner",
|
| 78 |
+
"identity",
|
| 79 |
+
"vault",
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
ORDER_RE = re.compile(
|
| 83 |
+
r"place_order|create_order|submit_order|live_order|market_order|limit_order|send_order",
|
| 84 |
+
re.I,
|
| 85 |
+
)
|
| 86 |
+
LAUNCH_RE = re.compile(
|
| 87 |
+
r"^(main|start_|stop_|launch|serve|run_server|boot|demo)$|serve_forever|continuous|create_web",
|
| 88 |
+
re.I,
|
| 89 |
+
)
|
| 90 |
+
WRITE_RE = re.compile(r"write_text|write_bytes|\.write\(|mkdir|open\([^)]*['\"][wa]", re.I)
|
| 91 |
+
KEY_RE = re.compile(
|
| 92 |
+
r"api_key|secret|password|credential|dotenv|owner_address|master_key|from_env|private_key|read_identity",
|
| 93 |
+
re.I,
|
| 94 |
+
)
|
| 95 |
+
FETCH_RE = re.compile(r"^(fetch_|download_|get_live)|requests\.|urlopen|httpx\.", re.I)
|
| 96 |
+
RISKY_RE = re.compile(
|
| 97 |
+
r"(?<![\w])append(?![\w])|"
|
| 98 |
+
r"(?<![\w])publish(?![\w])|"
|
| 99 |
+
r"\bThread\b|"
|
| 100 |
+
r"\.start\s*\(|"
|
| 101 |
+
r"\bunlink\b|"
|
| 102 |
+
r"\bmkdir\b|"
|
| 103 |
+
r"(?<![\w.])eval\s*\(|"
|
| 104 |
+
r"(?<![\w.])exec\s*\(|"
|
| 105 |
+
r"\bemit_\w*|"
|
| 106 |
+
r"open\s*\([^)]*['\"][wa]",
|
| 107 |
+
re.I,
|
| 108 |
+
)
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def stage_for(pkg: str, rel: str) -> int:
|
| 112 |
+
low = rel.lower()
|
| 113 |
+
if pkg == "core":
|
| 114 |
+
if any(token in low for token in ("organism", "memory", "thought_bus")):
|
| 115 |
+
return 3
|
| 116 |
+
if any(token in low for token in ("hnc", "lambda", "field", "harmonic", "canonical")):
|
| 117 |
+
return 1
|
| 118 |
+
return 6
|
| 119 |
+
if pkg == "utils":
|
| 120 |
+
return 1 if any(token in low for token in ("auris", "queen_hive", "queen")) else 6
|
| 121 |
+
if pkg == "wisdom":
|
| 122 |
+
return 1 if "qgita" in low else 6
|
| 123 |
+
return STAGE.get(pkg, 6)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
def source_is_risky(src: str) -> bool:
|
| 127 |
+
"""True when a full function body or a class ``__init__`` has a risky token."""
|
| 128 |
+
|
| 129 |
+
return bool(src and RISKY_RE.search(src))
|
| 130 |
+
|
| 131 |
+
|
| 132 |
+
def safety(pkg: str, name: str, src: str, stage: int) -> tuple[str, str]:
|
| 133 |
+
blob = name + "\n" + src
|
| 134 |
+
if pkg == "identity" or (pkg == "vault" and KEY_RE.search(blob)):
|
| 135 |
+
return "operator", "personal or key material; operator only; never returned"
|
| 136 |
+
if ORDER_RE.search(blob) or pkg in {
|
| 137 |
+
"trading",
|
| 138 |
+
"exchanges",
|
| 139 |
+
"bots",
|
| 140 |
+
"bots_intelligence",
|
| 141 |
+
"bridges",
|
| 142 |
+
"scanners",
|
| 143 |
+
}:
|
| 144 |
+
return "operator", "order-capable path; live_orders refused; no live send"
|
| 145 |
+
if LAUNCH_RE.search(name) or "serve_forever" in src or "while True" in src:
|
| 146 |
+
return "operator", "process, loop, or UI start; own flag; status and stop"
|
| 147 |
+
if WRITE_RE.search(src) or source_is_risky(src):
|
| 148 |
+
return "operator", "full-body scan found a risky token; the public server refuses it"
|
| 149 |
+
if KEY_RE.search(blob):
|
| 150 |
+
return "operator", "reads keys from env only; never logged or returned"
|
| 151 |
+
if pkg in OPERATOR_PACKAGES and stage >= 5:
|
| 152 |
+
return "operator", "package is operator-scoped; no public import"
|
| 153 |
+
if FETCH_RE.search(blob):
|
| 154 |
+
return "public", "live public fetch allowed; source label and timeout"
|
| 155 |
+
server, text = "public", "runs from inputs or committed files; no keys and no repo write"
|
| 156 |
+
return _honest_effect(name, server, text)
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
def _honest_effect(name: str, server: str, text: str) -> tuple[str, str]:
|
| 160 |
+
"""Names that write or start are not 'no repo write'."""
|
| 161 |
+
|
| 162 |
+
leaf = name.split(".")[-1]
|
| 163 |
+
if re.match(r"^(write_|save_|export_|dump_)", leaf, re.I) or leaf.lower() == "start":
|
| 164 |
+
if "no repo write" in text:
|
| 165 |
+
return server, "write or process start; the public server refuses it"
|
| 166 |
+
return server, text
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def required_count(node: ast.AST) -> int:
|
| 170 |
+
if not isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)):
|
| 171 |
+
return 0
|
| 172 |
+
args = [item for item in node.args.args if item.arg not in {"self", "cls"}]
|
| 173 |
+
required = len(args) - len(node.args.defaults)
|
| 174 |
+
for default in node.args.kw_defaults:
|
| 175 |
+
if default is None:
|
| 176 |
+
required += 1
|
| 177 |
+
if node.args.vararg or node.args.kwarg:
|
| 178 |
+
return required
|
| 179 |
+
return max(required, 0)
|
| 180 |
+
|
| 181 |
+
|
| 182 |
+
def _span(lines: list[str], node: ast.AST) -> str:
|
| 183 |
+
start = getattr(node, "lineno", 1) - 1
|
| 184 |
+
end = getattr(node, "end_lineno", None) or getattr(node, "lineno", 1)
|
| 185 |
+
return "\n".join(lines[start:end])
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _init_source(lines: list[str], class_node: ast.ClassDef) -> str:
|
| 189 |
+
for item in class_node.body:
|
| 190 |
+
if isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)) and item.name == "__init__":
|
| 191 |
+
return _span(lines, item)
|
| 192 |
+
return ""
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
def _scan_tree(pkg: str, rel: str, text: str, server_default: str | None = None) -> list[dict]:
|
| 196 |
+
rows: list[dict] = []
|
| 197 |
+
try:
|
| 198 |
+
tree = ast.parse(text)
|
| 199 |
+
except SyntaxError:
|
| 200 |
+
stage = 5 if pkg == "unified_margin_trader" else stage_for(pkg, rel)
|
| 201 |
+
rows.append(
|
| 202 |
+
{
|
| 203 |
+
"package": pkg,
|
| 204 |
+
"module": rel,
|
| 205 |
+
"symbol": "<syntax>",
|
| 206 |
+
"kind": "module",
|
| 207 |
+
"server": "operator",
|
| 208 |
+
"form": "resource",
|
| 209 |
+
"safety": "file does not parse",
|
| 210 |
+
"stage": stage,
|
| 211 |
+
"required": 0,
|
| 212 |
+
}
|
| 213 |
+
)
|
| 214 |
+
return rows
|
| 215 |
+
stage = 5 if pkg == "unified_margin_trader" else stage_for(pkg, rel)
|
| 216 |
+
lines = text.splitlines()
|
| 217 |
+
module_server = server_default or "operator" if pkg == "unified_margin_trader" else safety(pkg, Path(rel).stem, "", stage)[0]
|
| 218 |
+
module_safety = (
|
| 219 |
+
"order-capable tree; live_orders refused"
|
| 220 |
+
if pkg == "unified_margin_trader"
|
| 221 |
+
else "module surface; import is lazy and blob-checked when the file is the checkout"
|
| 222 |
+
)
|
| 223 |
+
rows.append(
|
| 224 |
+
{
|
| 225 |
+
"package": pkg,
|
| 226 |
+
"module": rel,
|
| 227 |
+
"symbol": Path(rel).stem,
|
| 228 |
+
"kind": "module",
|
| 229 |
+
"server": module_server,
|
| 230 |
+
"form": "resource",
|
| 231 |
+
"safety": module_safety,
|
| 232 |
+
"stage": stage,
|
| 233 |
+
"required": 0,
|
| 234 |
+
}
|
| 235 |
+
)
|
| 236 |
+
for node in tree.body:
|
| 237 |
+
if isinstance(node, ast.ClassDef) and not node.name.startswith("_"):
|
| 238 |
+
server, safe = (
|
| 239 |
+
("operator", "live_orders refused; no live send")
|
| 240 |
+
if pkg == "unified_margin_trader"
|
| 241 |
+
else safety(pkg, node.name, _init_source(lines, node) or _span(lines, node), stage)
|
| 242 |
+
)
|
| 243 |
+
rows.append(
|
| 244 |
+
{
|
| 245 |
+
"package": pkg,
|
| 246 |
+
"module": rel,
|
| 247 |
+
"symbol": node.name,
|
| 248 |
+
"kind": "class",
|
| 249 |
+
"server": server,
|
| 250 |
+
"form": "resource",
|
| 251 |
+
"safety": safe,
|
| 252 |
+
"stage": stage,
|
| 253 |
+
"required": 0,
|
| 254 |
+
}
|
| 255 |
+
)
|
| 256 |
+
for item in node.body:
|
| 257 |
+
if isinstance(item, (ast.FunctionDef, ast.AsyncFunctionDef)) and not item.name.startswith("_"):
|
| 258 |
+
server, safe = (
|
| 259 |
+
("operator", "live_orders refused; no live send")
|
| 260 |
+
if pkg == "unified_margin_trader"
|
| 261 |
+
else safety(
|
| 262 |
+
pkg,
|
| 263 |
+
item.name,
|
| 264 |
+
_span(lines, item) + "\n" + _init_source(lines, node),
|
| 265 |
+
stage,
|
| 266 |
+
)
|
| 267 |
+
)
|
| 268 |
+
rows.append(
|
| 269 |
+
{
|
| 270 |
+
"package": pkg,
|
| 271 |
+
"module": rel,
|
| 272 |
+
"symbol": f"{node.name}.{item.name}",
|
| 273 |
+
"kind": "method",
|
| 274 |
+
"server": server,
|
| 275 |
+
"form": "tool",
|
| 276 |
+
"safety": safe,
|
| 277 |
+
"stage": stage,
|
| 278 |
+
"required": required_count(item),
|
| 279 |
+
"async": isinstance(item, ast.AsyncFunctionDef),
|
| 280 |
+
}
|
| 281 |
+
)
|
| 282 |
+
elif isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef)) and not node.name.startswith("_"):
|
| 283 |
+
server, safe = (
|
| 284 |
+
("operator", "live_orders refused; no live send")
|
| 285 |
+
if pkg == "unified_margin_trader"
|
| 286 |
+
else safety(pkg, node.name, _span(lines, node), stage)
|
| 287 |
+
)
|
| 288 |
+
rows.append(
|
| 289 |
+
{
|
| 290 |
+
"package": pkg,
|
| 291 |
+
"module": rel,
|
| 292 |
+
"symbol": node.name,
|
| 293 |
+
"kind": "function",
|
| 294 |
+
"server": server,
|
| 295 |
+
"form": "tool",
|
| 296 |
+
"safety": safe,
|
| 297 |
+
"stage": stage,
|
| 298 |
+
"required": required_count(node),
|
| 299 |
+
"async": isinstance(node, ast.AsyncFunctionDef),
|
| 300 |
+
}
|
| 301 |
+
)
|
| 302 |
+
return rows
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
def scan(root: Path) -> list[dict]:
|
| 306 |
+
rows: list[dict] = []
|
| 307 |
+
aureon = root / "aureon"
|
| 308 |
+
for pkg_path in sorted(path for path in aureon.iterdir() if (path / "__init__.py").is_file()):
|
| 309 |
+
for path in sorted(pkg_path.rglob("*.py")):
|
| 310 |
+
if "__pycache__" in path.parts:
|
| 311 |
+
continue
|
| 312 |
+
rel = str(path.relative_to(aureon))
|
| 313 |
+
text = path.read_text(encoding="utf-8", errors="replace")
|
| 314 |
+
rows.extend(_scan_tree(pkg_path.name, rel, text))
|
| 315 |
+
umt = root / "unified_margin_trader"
|
| 316 |
+
for path in sorted(umt.rglob("*.py")):
|
| 317 |
+
if "__pycache__" in path.parts:
|
| 318 |
+
continue
|
| 319 |
+
text = path.read_text(encoding="utf-8", errors="replace")
|
| 320 |
+
rows.extend(_scan_tree("unified_margin_trader", str(path.relative_to(root)), text, "operator"))
|
| 321 |
+
return rows
|
| 322 |
+
|
| 323 |
+
|
| 324 |
+
def render_plan(rows: list[dict]) -> str:
|
| 325 |
+
lines = [
|
| 326 |
+
"# Full body MCP plan",
|
| 327 |
+
"",
|
| 328 |
+
"This is the stage-0 inventory of every public module, class, function, and method in the 54 `aureon` packages plus `unified_margin_trader`. A name that starts with `_` is not listed.",
|
| 329 |
+
"",
|
| 330 |
+
"A layer is at full depth only where a measured call runs that entry point. Listing it here, or reading its signature, is not depth. A helper call is not that layer's cognition. The depth table in each later stage counts calls, not rows.",
|
| 331 |
+
"",
|
| 332 |
+
"MCP lets outside models call Aureon's tools. No outside model or API becomes Aureon's reasoning. The cognition runs in Aureon's own code.",
|
| 333 |
+
"",
|
| 334 |
+
"Public (`aureon-public`) runs entry points that need no keys, personal data, writes, or live fetches. Operator (`aureon-operator`) is stdio only and stays off unless `AUREON_OPERATOR_MCP=1`. It is deny-by-default: the only calls that run are `accounting/file_drop.py` `registered_ingestors` and `portfolio/aureon_billion_goal_tracker.py` `get_days_remaining`, both with `allow_fetch` and `allow_write` false. It does not read keys. Live orders return `live_orders: refused`.",
|
| 335 |
+
"",
|
| 336 |
+
"Functions and methods are tools. Modules and classes are resources (the surface, not a constructed instance). The running servers address them through `body_call` and `body_surface` so the catalog stays one pair of tools instead of nineteen thousand registrations. The form column is the kind of call. `body_call` runs the real function. `body_surface` does not.",
|
| 337 |
+
"",
|
| 338 |
+
"`repo_root()` and `aureon_source()` raise `FileNotFoundError` when there is no checkout. The servers need that checkout.",
|
| 339 |
+
"",
|
| 340 |
+
"Any checkout file loaded beside the pin must pass the git blob check in `mcp/aureon_public/pin_blob.py` before it is executed. A file whose blob is not the blob at pin `8aa6a2d9` is not imported.",
|
| 341 |
+
"",
|
| 342 |
+
"HOLD stays explicit: trade readiness, the Auris-to-Lambda link, QGITA detection and false-alarm rates, Schumann f0, and HumanEval not run. `consciousness_*` keys are dropped. The pin and `AUREON_PUBLIC_REQUIRE_PIN` stay. Space entry points call `enforce_public_pin()`.",
|
| 343 |
+
"",
|
| 344 |
+
"## Stages",
|
| 345 |
+
"",
|
| 346 |
+
"1. HNC, harmonic core, Auris, and QGITA.",
|
| 347 |
+
"2. cognition, queen, swarm, swarm_motion, gates, governance, alignment, observer.",
|
| 348 |
+
"3. organism, bio, evaluation, memory and vault, identity readers.",
|
| 349 |
+
"4. data_feeds, atn, decoders, search, portals, monitors, analytics.",
|
| 350 |
+
"5. trading, exchanges, bots, bots_intelligence, bridges, scanners, strategies, portfolio, accounting, unified_margin_trader, conversion. Operator server. Live orders refused.",
|
| 351 |
+
"6. autonomous, code_architect, inhouse_ai, operator, launch, command_centers, connectors, saas, miner, generated, and the rest.",
|
| 352 |
+
"7. Space entry points and MCP registry packaging.",
|
| 353 |
+
"",
|
| 354 |
+
"## Counts",
|
| 355 |
+
"",
|
| 356 |
+
"| Package | Symbols | Public | Operator | Stage |",
|
| 357 |
+
"| --- | ---: | ---: | ---: | --- |",
|
| 358 |
+
]
|
| 359 |
+
by_pkg: dict[str, list[dict]] = defaultdict(list)
|
| 360 |
+
for row in rows:
|
| 361 |
+
by_pkg[row["package"]].append(row)
|
| 362 |
+
for pkg in sorted(by_pkg):
|
| 363 |
+
items = by_pkg[pkg]
|
| 364 |
+
public = sum(1 for row in items if row["server"] == "public")
|
| 365 |
+
operator = sum(1 for row in items if row["server"] == "operator")
|
| 366 |
+
stages = ",".join(str(item) for item in sorted({row["stage"] for row in items}))
|
| 367 |
+
lines.append(f"| {pkg} | {len(items)} | {public} | {operator} | {stages} |")
|
| 368 |
+
lines.extend(
|
| 369 |
+
[
|
| 370 |
+
"",
|
| 371 |
+
f"Total symbols: {len(rows)}. Packages: {len(by_pkg)}.",
|
| 372 |
+
"",
|
| 373 |
+
"Stage totals: "
|
| 374 |
+
+ ", ".join(f"{stage}={count}" for stage, count in sorted(Counter(row["stage"] for row in rows).items()))
|
| 375 |
+
+ ".",
|
| 376 |
+
"",
|
| 377 |
+
"Server totals: "
|
| 378 |
+
+ ", ".join(f"{server}={count}" for server, count in sorted(Counter(row["server"] for row in rows).items()))
|
| 379 |
+
+ ".",
|
| 380 |
+
"",
|
| 381 |
+
"## Every public module, class, and function",
|
| 382 |
+
"",
|
| 383 |
+
"Columns: stage, server, form, kind, module, symbol, safety.",
|
| 384 |
+
"",
|
| 385 |
+
"| Stage | Server | Form | Kind | Module | Symbol | Safety |",
|
| 386 |
+
"| ---: | --- | --- | --- | --- | --- | --- |",
|
| 387 |
+
]
|
| 388 |
+
)
|
| 389 |
+
for row in rows:
|
| 390 |
+
safety_text = row["safety"].replace("|", "/")
|
| 391 |
+
symbol = row["symbol"].replace("|", "/")
|
| 392 |
+
lines.append(
|
| 393 |
+
f"| {row['stage']} | {row['server']} | {row['form']} | {row['kind']} | `{row['module']}` | `{symbol}` | {safety_text} |"
|
| 394 |
+
)
|
| 395 |
+
return "\n".join(lines) + "\n"
|
| 396 |
+
|
| 397 |
+
|
| 398 |
+
def write_outputs(root: Path) -> tuple[int, Path, Path]:
|
| 399 |
+
rows = scan(root)
|
| 400 |
+
plan = root / "docs" / "mcp" / "FULL_BODY_PLAN.md"
|
| 401 |
+
inventory = root / "docs" / "mcp" / "inventory.json"
|
| 402 |
+
plan.parent.mkdir(parents=True, exist_ok=True)
|
| 403 |
+
plan.write_text(render_plan(rows), encoding="utf-8")
|
| 404 |
+
inventory.write_text(json.dumps(rows, separators=(",", ":")), encoding="utf-8")
|
| 405 |
+
return len(rows), plan, inventory
|
layers.py
ADDED
|
@@ -0,0 +1,594 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Read-only and one-step tools for organism layers that do not order or write state/.
|
| 2 |
+
|
| 3 |
+
Dispositions follow the scoping table. A package with no safe callable stays
|
| 4 |
+
catalog-only. Blocked trading imports are not called.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import ast
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
from aureon_public import paths
|
| 14 |
+
from aureon_public.quiet import quiet
|
| 15 |
+
from aureon_public.text import AURIS_FOUR, HOLD_LINE
|
| 16 |
+
from aureon_public.tools import _dumps, _finite
|
| 17 |
+
|
| 18 |
+
# kind: public tool name, catalog (named, not called), or operator (not on this server).
|
| 19 |
+
PACKAGES: tuple[dict[str, str], ...] = (
|
| 20 |
+
{"package": "accounting", "kind": "operator", "reason": "Inferred private. Not opened. No live orders."},
|
| 21 |
+
{"package": "alignment", "kind": "catalog", "reason": "Not opened. No safe zero-write callable was wrapped."},
|
| 22 |
+
{"package": "analytics", "kind": "catalog", "reason": "Lighthouse seat module was not given a separate tool. QGITA lighthouse math is wrapped on wisdom."},
|
| 23 |
+
{"package": "appliance", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 24 |
+
{"package": "approval", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 25 |
+
{"package": "atn", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 26 |
+
{"package": "autonomous", "kind": "operator", "reason": "Self-coding and launchers. Operator server only. No live orders."},
|
| 27 |
+
{"package": "bio", "kind": "membrane_screen", "reason": "screen_ingress is read-only containment. The Flask transport is not re-exported."},
|
| 28 |
+
{"package": "bots", "kind": "operator", "reason": "Blocked by guard.py. Operator refusal only. No live orders."},
|
| 29 |
+
{"package": "bots_intelligence", "kind": "operator", "reason": "Blocked by guard.py. Operator refusal only. No live orders."},
|
| 30 |
+
{"package": "bridges", "kind": "operator", "reason": "Blocked by guard.py. Operator refusal only. No live orders."},
|
| 31 |
+
{"package": "briefing", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 32 |
+
{"package": "code_architect", "kind": "operator", "reason": "Self-coding. Operator server only. No repo writes from this server."},
|
| 33 |
+
{"package": "cognition", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 34 |
+
{"package": "command_centers", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 35 |
+
{"package": "connectors", "kind": "operator", "reason": "Inferred private. Not opened. No live orders."},
|
| 36 |
+
{"package": "conversion", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 37 |
+
{"package": "core", "kind": "public", "reason": "Canonical field, LambdaEngine, circulation catalog, and the repository-layer hold."},
|
| 38 |
+
{"package": "data_feeds", "kind": "catalog", "reason": "Feeds are key-adjacent. Not called."},
|
| 39 |
+
{"package": "decoders", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 40 |
+
{"package": "evaluation", "kind": "evidence_predict_next", "reason": "predict_next and the committed-report formatters. evaluate_organism and the self-coder harness are not called."},
|
| 41 |
+
{"package": "exchanges", "kind": "operator", "reason": "Blocked by guard.py. Operator refusal only. No live orders."},
|
| 42 |
+
{"package": "gates", "kind": "catalog", "reason": "Signature pass was not done. Not called."},
|
| 43 |
+
{"package": "generated", "kind": "catalog", "reason": "Generated trees are not exposed."},
|
| 44 |
+
{"package": "governance", "kind": "catalog", "reason": "Seat resolvers were not started."},
|
| 45 |
+
{"package": "grants", "kind": "catalog", "reason": "Out of the public tool surface."},
|
| 46 |
+
{"package": "harmonic", "kind": "public", "reason": "HarmonicRealityField plus substrate, echo, observer, potential, and projection. HFT order types are not called."},
|
| 47 |
+
{"package": "identity", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 48 |
+
{"package": "inhouse_ai", "kind": "catalog", "reason": "The operator tool registry is not re-exported."},
|
| 49 |
+
{"package": "integrations", "kind": "catalog", "reason": "External systems. Not called."},
|
| 50 |
+
{"package": "intelligence", "kind": "catalog", "reason": "GlobalMarketOrganism is not a stateless API. Not called."},
|
| 51 |
+
{"package": "launch", "kind": "operator", "reason": "Process start. Operator server only. This server does not launch it."},
|
| 52 |
+
{"package": "miner", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 53 |
+
{"package": "monitors", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 54 |
+
{"package": "observability", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 55 |
+
{"package": "observer", "kind": "catalog", "reason": "HarmonicObserver attaches to the live daemon. Not called."},
|
| 56 |
+
{"package": "operator", "kind": "operator", "reason": "Flask app and the existing /mcp routes. Not mounted here."},
|
| 57 |
+
{"package": "organism", "kind": "repository_layers_hold", "reason": "compose_repository_layers on an empty root. No network transport."},
|
| 58 |
+
{"package": "plumber", "kind": "catalog", "reason": "Crypto extras. Not called."},
|
| 59 |
+
{"package": "portfolio", "kind": "operator", "reason": "Inferred private. Not opened. No live orders."},
|
| 60 |
+
{"package": "portals", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 61 |
+
{"package": "queen", "kind": "catalog", "reason": "QueenLayer init is not called. Auris node and evaluator calls live on utils."},
|
| 62 |
+
{"package": "s51", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 63 |
+
{"package": "saas", "kind": "operator", "reason": "Billing. Operator server only. No charges."},
|
| 64 |
+
{"package": "scanners", "kind": "operator", "reason": "Blocked by guard.py. Operator refusal only. No live orders."},
|
| 65 |
+
{"package": "search", "kind": "catalog", "reason": "Not repo_search. Not called."},
|
| 66 |
+
{"package": "simulation", "kind": "catalog", "reason": "Long-running. Not called."},
|
| 67 |
+
{"package": "strategies", "kind": "operator", "reason": "Trading-adjacent. Operator refusal only. No live orders."},
|
| 68 |
+
{"package": "swarm", "kind": "catalog", "reason": "Council seat is named in organism_catalog. The council is not started."},
|
| 69 |
+
{"package": "swarm_motion", "kind": "catalog", "reason": "Not opened. No safe callable wrapped."},
|
| 70 |
+
{"package": "trading", "kind": "operator", "reason": "Blocked by guard.py. Operator refusal only. No live orders."},
|
| 71 |
+
{"package": "utils", "kind": "public", "reason": "Nine nodes and the coherence evaluator. QueenHiveMind.__init__ is not called."},
|
| 72 |
+
{"package": "vault", "kind": "catalog", "reason": "State files. Not opened and not written."},
|
| 73 |
+
{"package": "wisdom", "kind": "public", "reason": "QGITAMarketAnalyzer, FTCPDetector, and LighthouseModel metric calls. Signals are dropped."},
|
| 74 |
+
)
|
| 75 |
+
|
| 76 |
+
HOLDS = {
|
| 77 |
+
"trade_readiness": "HOLD",
|
| 78 |
+
"auris_to_lambda": "HOLD",
|
| 79 |
+
"qgita_detection_rate": "HOLD",
|
| 80 |
+
"qgita_false_alarm_rate": "HOLD",
|
| 81 |
+
"schumann_f0": "null. HOLD",
|
| 82 |
+
"human_eval": "not run. HOLD",
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _package_rows() -> list[dict[str, str]]:
|
| 87 |
+
root = paths.repo_root() / "aureon"
|
| 88 |
+
rows = []
|
| 89 |
+
for row in PACKAGES:
|
| 90 |
+
present = (root / row["package"]).is_dir() or row["package"] == "unified_margin_trader"
|
| 91 |
+
rows.append({**row, "present": "yes" if present else "no", "holds": HOLD_LINE})
|
| 92 |
+
return rows
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
@quiet
|
| 96 |
+
def package_dispositions(package: str | None = None) -> str:
|
| 97 |
+
"""Disposition of each aureon package. Label: inferred from the scoping table, except where a tool below calls a real function.
|
| 98 |
+
|
| 99 |
+
Blocked packages are operator-only. This tool does not import them.
|
| 100 |
+
|
| 101 |
+
Args:
|
| 102 |
+
package: Optional package name. Omitted returns the full table. Label: inferred.
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
rows = _package_rows()
|
| 106 |
+
if package:
|
| 107 |
+
chosen = [row for row in rows if row["package"] == package]
|
| 108 |
+
if not chosen:
|
| 109 |
+
return _dumps(
|
| 110 |
+
{
|
| 111 |
+
"holds": HOLDS,
|
| 112 |
+
"label": "inferred",
|
| 113 |
+
"provenance": "inferred",
|
| 114 |
+
"reason": "Unknown package.",
|
| 115 |
+
"status": "unavailable",
|
| 116 |
+
}
|
| 117 |
+
)
|
| 118 |
+
rows = chosen
|
| 119 |
+
return _dumps(
|
| 120 |
+
{
|
| 121 |
+
"holds": HOLDS,
|
| 122 |
+
"label": "inferred. Package dispositions. Not a measurement.",
|
| 123 |
+
"packages": rows,
|
| 124 |
+
"provenance": "inferred",
|
| 125 |
+
"status": "inferred",
|
| 126 |
+
"which_auris": AURIS_FOUR,
|
| 127 |
+
}
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
@quiet
|
| 132 |
+
def hnc_substrate_eval(t: float = 0.0) -> str:
|
| 133 |
+
"""One HarmonicSubstrate.evaluate call. Provenance: inferred. This is not HarmonicRealityField.step.
|
| 134 |
+
|
| 135 |
+
The substrate equation is the class docstring. No formula was added. Trade readiness: HOLD.
|
| 136 |
+
|
| 137 |
+
Args:
|
| 138 |
+
t: Time passed to evaluate. Label: cited, HarmonicSubstrate.evaluate.
|
| 139 |
+
"""
|
| 140 |
+
|
| 141 |
+
number = _finite(t)
|
| 142 |
+
if number is None:
|
| 143 |
+
return _dumps({"provenance": "cited", "reason": "t is missing", "status": "unavailable"})
|
| 144 |
+
from aureon.harmonic.aureon_harmonic_reality import HarmonicSubstrate
|
| 145 |
+
|
| 146 |
+
substrate = HarmonicSubstrate()
|
| 147 |
+
return _dumps(
|
| 148 |
+
{
|
| 149 |
+
"label": "inferred. One HarmonicSubstrate.evaluate call.",
|
| 150 |
+
"provenance": "inferred",
|
| 151 |
+
"status": "inferred",
|
| 152 |
+
"t": number,
|
| 153 |
+
"value": float(substrate.evaluate(number)),
|
| 154 |
+
}
|
| 155 |
+
)
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
@quiet
|
| 159 |
+
def hnc_echo_eval(current_lambda: float = 0.0) -> str:
|
| 160 |
+
"""One CausalEcho.evaluate call on a new echo. Provenance: inferred.
|
| 161 |
+
|
| 162 |
+
The buffer starts at zeros in CausalEcho.__init__. This is that function, not a new formula. Trade readiness: HOLD.
|
| 163 |
+
|
| 164 |
+
Args:
|
| 165 |
+
current_lambda: Value passed to evaluate. Label: cited, CausalEcho.evaluate.
|
| 166 |
+
"""
|
| 167 |
+
|
| 168 |
+
number = _finite(current_lambda)
|
| 169 |
+
if number is None:
|
| 170 |
+
return _dumps({"provenance": "cited", "reason": "current_lambda is missing", "status": "unavailable"})
|
| 171 |
+
from aureon.harmonic.aureon_harmonic_reality import CausalEcho
|
| 172 |
+
|
| 173 |
+
echo = CausalEcho()
|
| 174 |
+
return _dumps(
|
| 175 |
+
{
|
| 176 |
+
"label": "inferred. One CausalEcho.evaluate call on a new instance.",
|
| 177 |
+
"provenance": "inferred",
|
| 178 |
+
"status": "inferred",
|
| 179 |
+
"value": float(echo.evaluate(number)),
|
| 180 |
+
}
|
| 181 |
+
)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
@quiet
|
| 185 |
+
def hnc_observer_eval(current_lambda: float = 0.0) -> str:
|
| 186 |
+
"""One ObserverNode.evaluate call on a new observer. Provenance: inferred.
|
| 187 |
+
|
| 188 |
+
Args:
|
| 189 |
+
current_lambda: Value passed to evaluate. Label: cited, ObserverNode.evaluate.
|
| 190 |
+
"""
|
| 191 |
+
|
| 192 |
+
number = _finite(current_lambda)
|
| 193 |
+
if number is None:
|
| 194 |
+
return _dumps({"provenance": "cited", "reason": "current_lambda is missing", "status": "unavailable"})
|
| 195 |
+
from aureon.harmonic.aureon_harmonic_reality import ObserverNode
|
| 196 |
+
|
| 197 |
+
observer = ObserverNode()
|
| 198 |
+
return _dumps(
|
| 199 |
+
{
|
| 200 |
+
"label": "inferred. One ObserverNode.evaluate call on a new instance.",
|
| 201 |
+
"provenance": "inferred",
|
| 202 |
+
"status": "inferred",
|
| 203 |
+
"value": float(observer.evaluate(number)),
|
| 204 |
+
}
|
| 205 |
+
)
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
@quiet
|
| 209 |
+
def hnc_potential_eval(lambda_val: float = 0.0) -> str:
|
| 210 |
+
"""One UnifiedPotential.evaluate call. Provenance: inferred.
|
| 211 |
+
|
| 212 |
+
The potential string is the class docstring. No formula was added. Trade readiness: HOLD.
|
| 213 |
+
|
| 214 |
+
Args:
|
| 215 |
+
lambda_val: Value passed to evaluate. Label: cited, UnifiedPotential.evaluate.
|
| 216 |
+
"""
|
| 217 |
+
|
| 218 |
+
number = _finite(lambda_val)
|
| 219 |
+
if number is None:
|
| 220 |
+
return _dumps({"provenance": "cited", "reason": "lambda_val is missing", "status": "unavailable"})
|
| 221 |
+
from aureon.harmonic.aureon_harmonic_reality import UnifiedPotential
|
| 222 |
+
|
| 223 |
+
potential = UnifiedPotential()
|
| 224 |
+
return _dumps(
|
| 225 |
+
{
|
| 226 |
+
"label": "inferred. One UnifiedPotential.evaluate call.",
|
| 227 |
+
"provenance": "inferred",
|
| 228 |
+
"status": "inferred",
|
| 229 |
+
"value": float(potential.evaluate(number)),
|
| 230 |
+
}
|
| 231 |
+
)
|
| 232 |
+
|
| 233 |
+
|
| 234 |
+
@quiet
|
| 235 |
+
def hnc_translate_project(psi_5d: float = 1.0, phi: float = 0.0, delta_phi: float = 0.0, f_value: float = 1.0) -> str:
|
| 236 |
+
"""One TranslationMap.project_to_3d call with observed_residual left unset. Provenance: inferred.
|
| 237 |
+
|
| 238 |
+
Noise is the method's own result when no residual is supplied. Label: cited, TranslationMap.project_to_3d.
|
| 239 |
+
|
| 240 |
+
Args:
|
| 241 |
+
psi_5d: High-dimensional state. Label: cited.
|
| 242 |
+
phi: Extra angle. Label: cited.
|
| 243 |
+
delta_phi: Phase difference. Label: cited.
|
| 244 |
+
f_value: Brane frequency passed as F. Label: cited.
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
numbers = {
|
| 248 |
+
"psi_5d": _finite(psi_5d),
|
| 249 |
+
"phi": _finite(phi),
|
| 250 |
+
"delta_phi": _finite(delta_phi),
|
| 251 |
+
"f_value": _finite(f_value),
|
| 252 |
+
}
|
| 253 |
+
if any(value is None for value in numbers.values()):
|
| 254 |
+
return _dumps({"provenance": "cited", "reason": "A projection input is missing", "status": "unavailable"})
|
| 255 |
+
from aureon.harmonic.aureon_harmonic_reality import TranslationMap
|
| 256 |
+
|
| 257 |
+
mapped = TranslationMap()
|
| 258 |
+
projected, noise = mapped.project_to_3d(
|
| 259 |
+
psi_5d=float(numbers["psi_5d"]),
|
| 260 |
+
phi=float(numbers["phi"]),
|
| 261 |
+
delta_phi=float(numbers["delta_phi"]),
|
| 262 |
+
F=float(numbers["f_value"]),
|
| 263 |
+
)
|
| 264 |
+
return _dumps(
|
| 265 |
+
{
|
| 266 |
+
"label": "inferred. project_to_3d with no observed residual.",
|
| 267 |
+
"noise": float(noise),
|
| 268 |
+
"projected": float(projected),
|
| 269 |
+
"provenance": "inferred",
|
| 270 |
+
"status": "inferred",
|
| 271 |
+
}
|
| 272 |
+
)
|
| 273 |
+
|
| 274 |
+
|
| 275 |
+
@quiet
|
| 276 |
+
def qgita_ftcp_detect(values: list[float] | None = None) -> str:
|
| 277 |
+
"""FTCPDetector.detect_ftcps on a caller series or a short default. Provenance: inferred.
|
| 278 |
+
|
| 279 |
+
Detection rate: HOLD. False-alarm rate: HOLD. This is not QGITAMarketAnalyzer.signals.
|
| 280 |
+
|
| 281 |
+
Args:
|
| 282 |
+
values: Optional series of at least three numbers. Omitted uses 0,1,1,2,3,5,8. Label: inferred for the call. The detector is cited.
|
| 283 |
+
"""
|
| 284 |
+
|
| 285 |
+
series = [0.0, 1.0, 1.0, 2.0, 3.0, 5.0, 8.0] if values is None else []
|
| 286 |
+
if values is not None:
|
| 287 |
+
for item in values:
|
| 288 |
+
number = _finite(item)
|
| 289 |
+
if number is None:
|
| 290 |
+
return _dumps(
|
| 291 |
+
{
|
| 292 |
+
"detection_rate": "HOLD",
|
| 293 |
+
"false_alarm_rate": "HOLD",
|
| 294 |
+
"provenance": "cited",
|
| 295 |
+
"reason": "A value is missing",
|
| 296 |
+
"status": "unavailable",
|
| 297 |
+
}
|
| 298 |
+
)
|
| 299 |
+
series.append(number)
|
| 300 |
+
if len(series) < 3:
|
| 301 |
+
return _dumps(
|
| 302 |
+
{
|
| 303 |
+
"detection_rate": "HOLD",
|
| 304 |
+
"false_alarm_rate": "HOLD",
|
| 305 |
+
"provenance": "cited",
|
| 306 |
+
"reason": "At least three values are required",
|
| 307 |
+
"status": "unavailable",
|
| 308 |
+
}
|
| 309 |
+
)
|
| 310 |
+
import numpy as np
|
| 311 |
+
|
| 312 |
+
from aureon.wisdom.aureon_qgita_framework import FTCPDetector
|
| 313 |
+
|
| 314 |
+
detector = FTCPDetector()
|
| 315 |
+
times = np.arange(len(series), dtype=float)
|
| 316 |
+
found = detector.detect_ftcps(times, np.asarray(series, dtype=float))
|
| 317 |
+
return _dumps(
|
| 318 |
+
{
|
| 319 |
+
"detection_rate": "HOLD",
|
| 320 |
+
"false_alarm_rate": "HOLD",
|
| 321 |
+
"ftcp_count": len(found),
|
| 322 |
+
"label": "inferred. FTCPDetector.detect_ftcps. Not a detection rate.",
|
| 323 |
+
"provenance": "inferred",
|
| 324 |
+
"status": "inferred",
|
| 325 |
+
}
|
| 326 |
+
)
|
| 327 |
+
|
| 328 |
+
|
| 329 |
+
@quiet
|
| 330 |
+
def qgita_lighthouse_coherence(values: list[float] | None = None) -> str:
|
| 331 |
+
"""LighthouseModel.compute_linear_coherence on one series. Provenance: inferred.
|
| 332 |
+
|
| 333 |
+
Detection rate: HOLD. False-alarm rate: HOLD. validate_ftcp is not called. Signals are not returned.
|
| 334 |
+
|
| 335 |
+
Args:
|
| 336 |
+
values: Optional series. Omitted uses 1,1,1,1,1. Label: inferred for the call. The method is cited.
|
| 337 |
+
"""
|
| 338 |
+
|
| 339 |
+
series = [1.0, 1.0, 1.0, 1.0, 1.0] if values is None else []
|
| 340 |
+
if values is not None:
|
| 341 |
+
for item in values:
|
| 342 |
+
number = _finite(item)
|
| 343 |
+
if number is None:
|
| 344 |
+
return _dumps(
|
| 345 |
+
{
|
| 346 |
+
"detection_rate": "HOLD",
|
| 347 |
+
"false_alarm_rate": "HOLD",
|
| 348 |
+
"provenance": "cited",
|
| 349 |
+
"reason": "A value is missing",
|
| 350 |
+
"status": "unavailable",
|
| 351 |
+
}
|
| 352 |
+
)
|
| 353 |
+
series.append(number)
|
| 354 |
+
import numpy as np
|
| 355 |
+
|
| 356 |
+
from aureon.wisdom.aureon_qgita_framework import LighthouseModel
|
| 357 |
+
|
| 358 |
+
model = LighthouseModel()
|
| 359 |
+
signal = np.asarray(series, dtype=float)
|
| 360 |
+
return _dumps(
|
| 361 |
+
{
|
| 362 |
+
"c_linear": float(model.compute_linear_coherence(signal)),
|
| 363 |
+
"detection_rate": "HOLD",
|
| 364 |
+
"false_alarm_rate": "HOLD",
|
| 365 |
+
"label": "inferred. LighthouseModel.compute_linear_coherence.",
|
| 366 |
+
"provenance": "inferred",
|
| 367 |
+
"status": "inferred",
|
| 368 |
+
}
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
+
|
| 372 |
+
@quiet
|
| 373 |
+
def membrane_screen(text: str = "") -> str:
|
| 374 |
+
"""screen_ingress on caller text. Provenance: cited. This does not dispatch a tool and does not trade.
|
| 375 |
+
|
| 376 |
+
Args:
|
| 377 |
+
text: Inbound text screened as data. Label: cited, aureon/bio/mcp_membrane.py screen_ingress.
|
| 378 |
+
"""
|
| 379 |
+
|
| 380 |
+
from dataclasses import asdict
|
| 381 |
+
|
| 382 |
+
missing = _load_phenolic_fingerprint()
|
| 383 |
+
if missing:
|
| 384 |
+
return _dumps(
|
| 385 |
+
{
|
| 386 |
+
"label": "cited-unverified. phenolic_fingerprint was not loaded, so screen_ingress did not run.",
|
| 387 |
+
"provenance": "cited-unverified",
|
| 388 |
+
"reason": missing,
|
| 389 |
+
"status": "unavailable",
|
| 390 |
+
}
|
| 391 |
+
)
|
| 392 |
+
try:
|
| 393 |
+
from aureon.bio.mcp_membrane import screen_ingress
|
| 394 |
+
except Exception as exc:
|
| 395 |
+
return _dumps(
|
| 396 |
+
{
|
| 397 |
+
"label": "cited-unverified. screen_ingress did not import in this process.",
|
| 398 |
+
"provenance": "cited-unverified",
|
| 399 |
+
"reason": f"{type(exc).__name__}: {exc}"[:240],
|
| 400 |
+
"status": "unavailable",
|
| 401 |
+
}
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
verdict = screen_ingress(str(text), source="aureon-public")
|
| 405 |
+
body = asdict(verdict)
|
| 406 |
+
body["label"] = (
|
| 407 |
+
"cited. screen_ingress. phenolic_fingerprint loaded from checkout "
|
| 408 |
+
"after the blob check for pin 8aa6a2d9. Not an order."
|
| 409 |
+
)
|
| 410 |
+
body["provenance"] = "cited"
|
| 411 |
+
body["status"] = "cited"
|
| 412 |
+
return _dumps(body)
|
| 413 |
+
|
| 414 |
+
|
| 415 |
+
@quiet
|
| 416 |
+
def repository_layers_hold() -> str:
|
| 417 |
+
"""compose_repository_layers on an empty directory. Provenance: cited.
|
| 418 |
+
|
| 419 |
+
No field or market transport is passed, and the empty root has no sibling checkouts, so this does not open a network socket from those call sites. may_act stays false.
|
| 420 |
+
|
| 421 |
+
Args:
|
| 422 |
+
none: This tool takes no inputs. Label: cited, aureon/organism/repository_layers.py compose_repository_layers.
|
| 423 |
+
"""
|
| 424 |
+
|
| 425 |
+
import tempfile
|
| 426 |
+
|
| 427 |
+
from aureon.organism.repository_layers import compose_repository_layers
|
| 428 |
+
|
| 429 |
+
empty = Path(tempfile.mkdtemp(prefix="aureon-public-layers-"))
|
| 430 |
+
try:
|
| 431 |
+
report = compose_repository_layers(repos_root=empty)
|
| 432 |
+
finally:
|
| 433 |
+
empty.rmdir()
|
| 434 |
+
report["label"] = "cited. Empty-root hold join. Not a network observation."
|
| 435 |
+
report["provenance"] = "cited"
|
| 436 |
+
return _dumps(report)
|
| 437 |
+
|
| 438 |
+
|
| 439 |
+
@quiet
|
| 440 |
+
def evidence_predict_next(values: list[float] | None = None) -> str:
|
| 441 |
+
"""evaluate.organism_proof.predict_next. Provenance: inferred.
|
| 442 |
+
|
| 443 |
+
This does not call evaluate_organism. HumanEval: not run. HOLD.
|
| 444 |
+
|
| 445 |
+
Args:
|
| 446 |
+
values: Optional numbers. Omitted uses 1,2,3. Label: inferred for the call. The function is cited.
|
| 447 |
+
"""
|
| 448 |
+
|
| 449 |
+
series: list[float] = []
|
| 450 |
+
raw = [1.0, 2.0, 3.0] if values is None else values
|
| 451 |
+
for item in raw:
|
| 452 |
+
number = _finite(item)
|
| 453 |
+
if number is None:
|
| 454 |
+
return _dumps(
|
| 455 |
+
{
|
| 456 |
+
"human_eval": "not run. HOLD",
|
| 457 |
+
"provenance": "cited",
|
| 458 |
+
"reason": "A value is missing",
|
| 459 |
+
"status": "unavailable",
|
| 460 |
+
}
|
| 461 |
+
)
|
| 462 |
+
series.append(number)
|
| 463 |
+
from aureon.evaluation.organism_proof import predict_next
|
| 464 |
+
|
| 465 |
+
predicted = predict_next(series)
|
| 466 |
+
return _dumps(
|
| 467 |
+
{
|
| 468 |
+
"human_eval": "not run. HOLD",
|
| 469 |
+
"label": "inferred. predict_next. evaluate_organism was not called.",
|
| 470 |
+
"predicted": predicted,
|
| 471 |
+
"provenance": "inferred",
|
| 472 |
+
"status": "inferred",
|
| 473 |
+
}
|
| 474 |
+
)
|
| 475 |
+
|
| 476 |
+
|
| 477 |
+
@quiet
|
| 478 |
+
def source_names(package: str) -> str:
|
| 479 |
+
"""Top-level class and function names parsed from a package's Python files. Provenance: cited.
|
| 480 |
+
|
| 481 |
+
This reads source text with ast. It does not import the package and does not call those functions. Blocked packages are refused.
|
| 482 |
+
|
| 483 |
+
Args:
|
| 484 |
+
package: aureon package name, or unified_margin_trader. Label: cited, the file names on disk.
|
| 485 |
+
"""
|
| 486 |
+
|
| 487 |
+
blocked = {
|
| 488 |
+
"exchanges",
|
| 489 |
+
"trading",
|
| 490 |
+
"bots",
|
| 491 |
+
"bots_intelligence",
|
| 492 |
+
"bridges",
|
| 493 |
+
"scanners",
|
| 494 |
+
}
|
| 495 |
+
if package in blocked or package == "unified_margin_trader":
|
| 496 |
+
return _dumps(
|
| 497 |
+
{
|
| 498 |
+
"label": "cited. guard.py refuses these imports. Names are not loaded.",
|
| 499 |
+
"package": package,
|
| 500 |
+
"provenance": "cited",
|
| 501 |
+
"status": "unavailable",
|
| 502 |
+
}
|
| 503 |
+
)
|
| 504 |
+
root = paths.repo_root() / "aureon" / package
|
| 505 |
+
if not root.is_dir():
|
| 506 |
+
return _dumps(
|
| 507 |
+
{
|
| 508 |
+
"provenance": "cited",
|
| 509 |
+
"reason": "Package directory is missing",
|
| 510 |
+
"status": "unavailable",
|
| 511 |
+
}
|
| 512 |
+
)
|
| 513 |
+
names: list[dict[str, str]] = []
|
| 514 |
+
for path in sorted(root.glob("*.py")):
|
| 515 |
+
if path.name == "__init__.py":
|
| 516 |
+
continue
|
| 517 |
+
try:
|
| 518 |
+
tree = ast.parse(path.read_text(encoding="utf-8", errors="replace"))
|
| 519 |
+
except SyntaxError:
|
| 520 |
+
continue
|
| 521 |
+
for node in tree.body:
|
| 522 |
+
if isinstance(node, (ast.FunctionDef, ast.AsyncFunctionDef, ast.ClassDef)):
|
| 523 |
+
names.append({"file": path.name, "kind": type(node).__name__, "name": node.name})
|
| 524 |
+
if len(names) >= 40:
|
| 525 |
+
break
|
| 526 |
+
if len(names) >= 40:
|
| 527 |
+
break
|
| 528 |
+
return _dumps(
|
| 529 |
+
{
|
| 530 |
+
"label": "cited. ast names only. Functions were not called.",
|
| 531 |
+
"names": names,
|
| 532 |
+
"package": package,
|
| 533 |
+
"provenance": "cited",
|
| 534 |
+
"status": "cited",
|
| 535 |
+
}
|
| 536 |
+
)
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
def _load_phenolic_fingerprint(root: Path | None = None) -> str | None:
|
| 540 |
+
"""Register the checkout's phenolic_fingerprint without putting the repo root on sys.path.
|
| 541 |
+
|
| 542 |
+
The file is executed only when its git blob is the blob at pin 8aa6a2d9.
|
| 543 |
+
A different checkout copy is refused and is not loaded.
|
| 544 |
+
"""
|
| 545 |
+
|
| 546 |
+
from aureon_public.pin_blob import (
|
| 547 |
+
PHENOLIC_MISMATCH,
|
| 548 |
+
PINNED_PHENOLIC_BLOB,
|
| 549 |
+
load_pinned_source,
|
| 550 |
+
)
|
| 551 |
+
|
| 552 |
+
base = paths.repo_root() if root is None else root
|
| 553 |
+
path = base / "phenolic_fingerprint.py"
|
| 554 |
+
return load_pinned_source(
|
| 555 |
+
"phenolic_fingerprint",
|
| 556 |
+
path,
|
| 557 |
+
PINNED_PHENOLIC_BLOB,
|
| 558 |
+
PHENOLIC_MISMATCH,
|
| 559 |
+
)
|
| 560 |
+
|
| 561 |
+
|
| 562 |
+
def public_layer_tools() -> list[Any]:
|
| 563 |
+
from aureon_public.alignment_layer import TOOLS as ALIGNMENT_TOOLS
|
| 564 |
+
from aureon_public.more_layers import TOOLS
|
| 565 |
+
from aureon_public.stage1_rest import TOOLS as STAGE1_TOOLS
|
| 566 |
+
from aureon_public.stage2_layer import TOOLS as STAGE2_TOOLS
|
| 567 |
+
|
| 568 |
+
return [
|
| 569 |
+
package_dispositions,
|
| 570 |
+
hnc_substrate_eval,
|
| 571 |
+
hnc_echo_eval,
|
| 572 |
+
hnc_observer_eval,
|
| 573 |
+
hnc_potential_eval,
|
| 574 |
+
hnc_translate_project,
|
| 575 |
+
qgita_ftcp_detect,
|
| 576 |
+
qgita_lighthouse_coherence,
|
| 577 |
+
membrane_screen,
|
| 578 |
+
repository_layers_hold,
|
| 579 |
+
evidence_predict_next,
|
| 580 |
+
source_names,
|
| 581 |
+
*TOOLS,
|
| 582 |
+
*ALIGNMENT_TOOLS,
|
| 583 |
+
*STAGE1_TOOLS,
|
| 584 |
+
*STAGE2_TOOLS,
|
| 585 |
+
]
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
def packages_resource() -> str:
|
| 589 |
+
"""Every package disposition, including operator exclusions. Provenance: inferred.
|
| 590 |
+
|
| 591 |
+
Auris meanings stay separate. The conjecture is not called. The nine nodes and the coherence evaluator are the utils tools. The persona is not scored. Label: inferred.
|
| 592 |
+
"""
|
| 593 |
+
|
| 594 |
+
return package_dispositions()
|
measure.py
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""One stdio session: list the catalog and call each tool once. Writes raw JSON."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import asyncio
|
| 7 |
+
import importlib.metadata
|
| 8 |
+
import json
|
| 9 |
+
import os
|
| 10 |
+
import sys
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
from mcp import ClientSession, StdioServerParameters
|
| 15 |
+
from mcp.client.stdio import stdio_client
|
| 16 |
+
|
| 17 |
+
from aureon_public import paths
|
| 18 |
+
from aureon_public.body import enabled_stage, probes_for
|
| 19 |
+
from aureon_public.guard_loader import apply_space_guard
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def _text_content(result: Any) -> str:
|
| 23 |
+
parts = []
|
| 24 |
+
for block in result.content:
|
| 25 |
+
text = getattr(block, "text", None)
|
| 26 |
+
if text is not None:
|
| 27 |
+
parts.append(text)
|
| 28 |
+
return "\n".join(parts)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def _environment() -> dict[str, Any]:
|
| 32 |
+
apply_space_guard()
|
| 33 |
+
import aureon
|
| 34 |
+
|
| 35 |
+
direct = None
|
| 36 |
+
try:
|
| 37 |
+
dist = importlib.metadata.distribution("aureon")
|
| 38 |
+
raw = dist.read_text("direct_url.json")
|
| 39 |
+
direct = json.loads(raw) if raw else None
|
| 40 |
+
except Exception as exc: # noqa: BLE001 - the record should say the pin was not readable
|
| 41 |
+
direct = {"error": type(exc).__name__}
|
| 42 |
+
return {
|
| 43 |
+
"aureon_file": aureon.__file__,
|
| 44 |
+
"aureon_direct_url": direct,
|
| 45 |
+
"python": sys.executable,
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
async def _session(out_path: Path) -> dict[str, Any]:
|
| 50 |
+
env = {
|
| 51 |
+
"PATH": os.environ.get("PATH", ""),
|
| 52 |
+
"HOME": os.environ.get("HOME", ""),
|
| 53 |
+
"PYTHONUNBUFFERED": "1",
|
| 54 |
+
}
|
| 55 |
+
params = StdioServerParameters(
|
| 56 |
+
command=sys.executable,
|
| 57 |
+
args=["-m", "aureon_public"],
|
| 58 |
+
env=env,
|
| 59 |
+
cwd=str(Path.cwd()),
|
| 60 |
+
)
|
| 61 |
+
async with stdio_client(params) as (read, write):
|
| 62 |
+
async with ClientSession(read, write) as session:
|
| 63 |
+
initialized = await session.initialize()
|
| 64 |
+
tools = await session.list_tools()
|
| 65 |
+
resources = await session.list_resources()
|
| 66 |
+
prompts = await session.list_prompts()
|
| 67 |
+
calls = {}
|
| 68 |
+
for name, arguments in (
|
| 69 |
+
("hnc_reality_step", {}),
|
| 70 |
+
("hnc_canonical_read", {}),
|
| 71 |
+
("hnc_blend_read", {}),
|
| 72 |
+
("lambda_engine_step", {}),
|
| 73 |
+
("auris_nodes", {}),
|
| 74 |
+
("auris_coherence", {}),
|
| 75 |
+
("qgita_analyze", {}),
|
| 76 |
+
("organism_replay_read", {}),
|
| 77 |
+
("organism_catalog", {}),
|
| 78 |
+
("package_dispositions", {}),
|
| 79 |
+
("hnc_substrate_eval", {}),
|
| 80 |
+
("hnc_echo_eval", {}),
|
| 81 |
+
("hnc_observer_eval", {}),
|
| 82 |
+
("hnc_potential_eval", {}),
|
| 83 |
+
("hnc_translate_project", {}),
|
| 84 |
+
("qgita_ftcp_detect", {}),
|
| 85 |
+
("qgita_lighthouse_coherence", {}),
|
| 86 |
+
("membrane_screen", {}),
|
| 87 |
+
("repository_layers_hold", {}),
|
| 88 |
+
("evidence_predict_next", {}),
|
| 89 |
+
("source_names", {"package": "core"}),
|
| 90 |
+
):
|
| 91 |
+
result = await session.call_tool(name, arguments)
|
| 92 |
+
calls[name] = {
|
| 93 |
+
"arguments": arguments,
|
| 94 |
+
"isError": result.isError,
|
| 95 |
+
"text": _text_content(result),
|
| 96 |
+
}
|
| 97 |
+
# The class default is multiverse on. Record the other committed path
|
| 98 |
+
# beside it so the two coherences are not mixed.
|
| 99 |
+
for stage in range(1, enabled_stage() + 1):
|
| 100 |
+
for probe in probes_for(stage):
|
| 101 |
+
arguments = {
|
| 102 |
+
"module": probe["module"],
|
| 103 |
+
"symbol": probe["symbol"],
|
| 104 |
+
"arguments_json": json.dumps(probe.get("arguments") or {}),
|
| 105 |
+
}
|
| 106 |
+
result = await session.call_tool("body_call", arguments)
|
| 107 |
+
calls[f"body_call:{probe['symbol']}"] = {
|
| 108 |
+
"arguments": arguments,
|
| 109 |
+
"isError": result.isError,
|
| 110 |
+
"text": _text_content(result),
|
| 111 |
+
}
|
| 112 |
+
depth = await session.call_tool("body_depth", {})
|
| 113 |
+
calls["body_depth"] = {
|
| 114 |
+
"arguments": {},
|
| 115 |
+
"isError": depth.isError,
|
| 116 |
+
"text": _text_content(depth),
|
| 117 |
+
}
|
| 118 |
+
surface = await session.call_tool(
|
| 119 |
+
"body_surface",
|
| 120 |
+
{
|
| 121 |
+
"module": "harmonic/aureon_harmonic_reality.py",
|
| 122 |
+
"symbol": "HarmonicSubstrate",
|
| 123 |
+
},
|
| 124 |
+
)
|
| 125 |
+
calls["body_surface:HarmonicSubstrate"] = {
|
| 126 |
+
"arguments": {
|
| 127 |
+
"module": "harmonic/aureon_harmonic_reality.py",
|
| 128 |
+
"symbol": "HarmonicSubstrate",
|
| 129 |
+
},
|
| 130 |
+
"isError": surface.isError,
|
| 131 |
+
"text": _text_content(surface),
|
| 132 |
+
}
|
| 133 |
+
off = await session.call_tool("hnc_reality_step", {"enable_multiverse": False})
|
| 134 |
+
calls["hnc_reality_step_multiverse_off"] = {
|
| 135 |
+
"arguments": {"enable_multiverse": False},
|
| 136 |
+
"isError": off.isError,
|
| 137 |
+
"text": _text_content(off),
|
| 138 |
+
"note": "Not the class default. Committed multiverse-off path.",
|
| 139 |
+
}
|
| 140 |
+
resource_bodies = {}
|
| 141 |
+
for item in resources.resources:
|
| 142 |
+
uri = str(item.uri)
|
| 143 |
+
body = await session.read_resource(uri)
|
| 144 |
+
chunks = []
|
| 145 |
+
for block in body.contents:
|
| 146 |
+
content = getattr(block, "content", None)
|
| 147 |
+
text = getattr(block, "text", None)
|
| 148 |
+
if text is not None:
|
| 149 |
+
chunks.append(text)
|
| 150 |
+
elif content is not None:
|
| 151 |
+
chunks.append(str(content))
|
| 152 |
+
resource_bodies[uri] = "\n".join(chunks)
|
| 153 |
+
prompt_bodies = {}
|
| 154 |
+
for item in prompts.prompts:
|
| 155 |
+
rendered = await session.get_prompt(item.name)
|
| 156 |
+
messages = []
|
| 157 |
+
for message in rendered.messages:
|
| 158 |
+
content = message.content
|
| 159 |
+
messages.append(getattr(content, "text", str(content)))
|
| 160 |
+
prompt_bodies[item.name] = messages
|
| 161 |
+
record = {
|
| 162 |
+
"environment": _environment(),
|
| 163 |
+
"instructions_checked_in_process": True,
|
| 164 |
+
"server_instructions": getattr(initialized, "instructions", None),
|
| 165 |
+
"prompts": [
|
| 166 |
+
{"name": item.name, "description": item.description}
|
| 167 |
+
for item in prompts.prompts
|
| 168 |
+
],
|
| 169 |
+
"prompt_bodies": prompt_bodies,
|
| 170 |
+
"resources": [
|
| 171 |
+
{"uri": str(item.uri), "name": item.name, "description": item.description}
|
| 172 |
+
for item in resources.resources
|
| 173 |
+
],
|
| 174 |
+
"resource_bodies": resource_bodies,
|
| 175 |
+
"tools": [
|
| 176 |
+
{
|
| 177 |
+
"name": item.name,
|
| 178 |
+
"description": item.description,
|
| 179 |
+
"inputSchema": item.inputSchema,
|
| 180 |
+
}
|
| 181 |
+
for item in tools.tools
|
| 182 |
+
],
|
| 183 |
+
"calls": calls,
|
| 184 |
+
}
|
| 185 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 186 |
+
out_path.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 187 |
+
return record
|
| 188 |
+
|
| 189 |
+
|
| 190 |
+
def main(argv: list[str] | None = None) -> None:
|
| 191 |
+
parser = argparse.ArgumentParser(prog="aureon-public-measure")
|
| 192 |
+
parser.add_argument(
|
| 193 |
+
"--out",
|
| 194 |
+
type=Path,
|
| 195 |
+
default=paths.repo_root() / "measured" / "aureon_public_run.json",
|
| 196 |
+
)
|
| 197 |
+
args = parser.parse_args(argv)
|
| 198 |
+
asyncio.run(_session(args.out))
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
if __name__ == "__main__":
|
| 202 |
+
main()
|
measurement_stamp.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Identity fields for a measured record.
|
| 2 |
+
|
| 3 |
+
The record names the commit that was HEAD while it was written. That commit is
|
| 4 |
+
the parent of the commit that adds the record file. A dirty working tree is
|
| 5 |
+
refused: the stamp would mix uncommitted edits into that commit name.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import subprocess
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
from aureon_public.guard_loader import PINNED_COMMIT
|
| 14 |
+
from aureon_public.paths import repo_root
|
| 15 |
+
|
| 16 |
+
# git rev-parse 8aa6a2d971cc529484e2a5e261e28afafab4e4f4:aureon
|
| 17 |
+
PIN_AUREON_TREE = "8aef927b7fe6276c187e4c73c79f0de012ad980d"
|
| 18 |
+
CODE_COMMIT_NOTE = (
|
| 19 |
+
"This is the parent of the commit that contains this record. "
|
| 20 |
+
"The record cannot name the commit that adds the file."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _git(*args: str) -> str:
|
| 25 |
+
return subprocess.check_output(
|
| 26 |
+
["git", "-C", str(repo_root()), *args],
|
| 27 |
+
text=True,
|
| 28 |
+
).strip()
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def pin_tree_skip_reason(root: Path) -> str | None:
|
| 32 |
+
"""Why this checkout cannot be compared with the pinned aureon tree.
|
| 33 |
+
|
| 34 |
+
None means the comparison can run. A missing .git, a shallow clone, or a
|
| 35 |
+
clone that does not contain the pin commit is skipped. The comparison
|
| 36 |
+
itself stays an assertion when the history is present.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
if not (Path(root) / ".git").exists():
|
| 40 |
+
return "no .git; the pin tree comparison needs a git checkout"
|
| 41 |
+
try:
|
| 42 |
+
shallow = subprocess.check_output(
|
| 43 |
+
["git", "-C", str(root), "rev-parse", "--is-shallow-repository"],
|
| 44 |
+
text=True,
|
| 45 |
+
stderr=subprocess.STDOUT,
|
| 46 |
+
).strip()
|
| 47 |
+
except (OSError, subprocess.CalledProcessError) as exc:
|
| 48 |
+
detail = getattr(exc, "stdout", None) or str(exc)
|
| 49 |
+
return f"git could not read this checkout: {detail}".strip()
|
| 50 |
+
if shallow == "true":
|
| 51 |
+
return "shallow clone; the pin commit may be absent"
|
| 52 |
+
present = subprocess.run(
|
| 53 |
+
["git", "-C", str(root), "cat-file", "-e", f"{PINNED_COMMIT}^{{commit}}"],
|
| 54 |
+
check=False,
|
| 55 |
+
capture_output=True,
|
| 56 |
+
text=True,
|
| 57 |
+
)
|
| 58 |
+
if present.returncode != 0:
|
| 59 |
+
return f"pin commit {PINNED_COMMIT} is not in this clone"
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def measurement_stamp() -> dict[str, str]:
|
| 64 |
+
"""Pin, aureon/ tree hash, and the code commit that was HEAD.
|
| 65 |
+
|
| 66 |
+
Raises RuntimeError when git status --porcelain is not empty.
|
| 67 |
+
"""
|
| 68 |
+
|
| 69 |
+
dirty = _git("status", "--porcelain")
|
| 70 |
+
if dirty.strip():
|
| 71 |
+
raise RuntimeError(
|
| 72 |
+
"measurement_stamp refuses a dirty working tree. "
|
| 73 |
+
"Commit the code, then write the measured record.\n" + dirty.strip()
|
| 74 |
+
)
|
| 75 |
+
return {
|
| 76 |
+
"aureon_tree": _git("rev-parse", "HEAD:aureon"),
|
| 77 |
+
"code_commit": _git("rev-parse", "HEAD"),
|
| 78 |
+
"code_commit_note": CODE_COMMIT_NOTE,
|
| 79 |
+
"pin": PINNED_COMMIT,
|
| 80 |
+
"pin_aureon_tree": _git("rev-parse", f"{PINNED_COMMIT}:aureon"),
|
| 81 |
+
}
|
more_layers.py
ADDED
|
@@ -0,0 +1,632 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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per function per package. A helper call is not that layer's cognition. No new formulas."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import tempfile
|
| 6 |
+
from datetime import date
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
from typing import Any
|
| 9 |
+
|
| 10 |
+
from aureon_public.quiet import quiet
|
| 11 |
+
from aureon_public.tools import _dumps as _public_dumps
|
| 12 |
+
from aureon_public.tools import _finite
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _dumps(payload: dict[str, Any]) -> str:
|
| 16 |
+
label = payload.get("label")
|
| 17 |
+
if isinstance(label, str) and not label.startswith("helper."):
|
| 18 |
+
payload = dict(payload)
|
| 19 |
+
payload["label"] = "helper. " + label
|
| 20 |
+
return _public_dumps(payload)
|
| 21 |
+
|
| 22 |
+
# package, kind, reason. kind is the tool name or "excluded".
|
| 23 |
+
UPDATES: tuple[tuple[str, str, str], ...] = (
|
| 24 |
+
("alignment", "alignment_consonance", "consonance_score. No pillar singleton."),
|
| 25 |
+
("analytics", "analytics_fear_greed", "derive_fear_greed on a supplied series. No backtest run."),
|
| 26 |
+
("appliance", "appliance_sha256", "sha256_file on a temp file that is deleted. The repo is not hashed."),
|
| 27 |
+
("approval", "approval_subject_line", "subject_line only. Owner address is not read."),
|
| 28 |
+
("atn", "excluded", "Public functions fetch earthquakes, flares, or prices. Not called."),
|
| 29 |
+
("briefing", "briefing_severity", "severity_rank. The brief assembler and pytest runner are not called."),
|
| 30 |
+
("cognition", "cognition_logic_flow", "compute_logic_flow on an in-memory bus. summarize_patterns is a stage-2 tool. The report writer is not called."),
|
| 31 |
+
("command_centers", "excluded", "Entry points launch UIs or read API-key status. Not called."),
|
| 32 |
+
("conversion", "excluded", "The conversion hub takes capital and is not a pure read."),
|
| 33 |
+
("data_feeds", "data_feed_parse_tick", "parse_binance_tick on one dict. No socket is opened."),
|
| 34 |
+
("decoders", "decoder_haversine", "haversine stays import-refused. Stage-2 tools call the Sumerian and I Ching getters. Decoders are not started."),
|
| 35 |
+
("gates", "gates_reading", "is_human_held, ungrounded_nodes, and build_report on an empty check list. The benchmark runner is not called."),
|
| 36 |
+
("generated", "generated_default_inputs", "build_default_inputs. Deterministic score model. No network."),
|
| 37 |
+
("governance", "governance_seasonal_gate", "seasonal_gate_for_date. Live authorization is not issued."),
|
| 38 |
+
("grants", "grants_breath_interval", "breath_interval only. Dossiers are not read."),
|
| 39 |
+
("identity", "excluded", "read_identity can load personal files. Not called."),
|
| 40 |
+
("inhouse_ai", "excluded", "The tool registry can dispatch. Not re-exported."),
|
| 41 |
+
("integrations", "integrations_phi_plan", "build_phi_swarm_plan. No model is called."),
|
| 42 |
+
("intelligence", "intelligence_resonance", "calculate_harmonic_resonance. Trading permission is not called."),
|
| 43 |
+
("miner", "excluded", "The only public function constructs a bridge. Not called."),
|
| 44 |
+
("monitors", "excluded", "aureon_live_monitor exits on import without aiohttp, and the wave monitor sets LIVE=1. Not called."),
|
| 45 |
+
("observability", "observability_redact", "redact_observability_value. Events are not emitted."),
|
| 46 |
+
("observer", "observer_kp_sample", "parse_kp_file of the committed Kp file, one sample. Stage-2 tools read mode flags, the DE440 prefix, and the source registry. No download."),
|
| 47 |
+
("plumber", "plumber_sha256", "sha256_hex. No key is generated."),
|
| 48 |
+
("portals", "portals_html_to_text", "html_to_text. Dashboards are not fetched."),
|
| 49 |
+
("queen", "queen_zpe_ground", "compute_zpe_ground. Queen phase and order gates are not called."),
|
| 50 |
+
("s51", "s51_summarize_receipts", "summarize_compounding with no receipts, through dispatch. The sim is not run."),
|
| 51 |
+
("search", "search_summarize_text", "summarize_text. Online fetch is not called."),
|
| 52 |
+
("simulation", "simulation_hz_to_rgb", "hz_to_rgb. Simulations are not run."),
|
| 53 |
+
("swarm", "swarm_voice_for_gamma", "voice_for_gamma. The council is not convened."),
|
| 54 |
+
("swarm_motion", "excluded", "The only public function constructs the hive. Not called."),
|
| 55 |
+
("vault", "vault_count_words", "count_words. Key stores and persona files are not read."),
|
| 56 |
+
)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def _apply() -> None:
|
| 60 |
+
from aureon_public.layers import PACKAGES
|
| 61 |
+
|
| 62 |
+
by_name = {row["package"]: row for row in PACKAGES}
|
| 63 |
+
for package, kind, reason in UPDATES:
|
| 64 |
+
row = by_name[package]
|
| 65 |
+
row["kind"] = kind
|
| 66 |
+
row["reason"] = reason if reason.startswith("Helper only.") else "Helper only. " + reason
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
_apply()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _missing(name: str) -> str:
|
| 73 |
+
return _dumps(
|
| 74 |
+
{
|
| 75 |
+
"provenance": "cited",
|
| 76 |
+
"reason": f"{name} is missing",
|
| 77 |
+
"status": "unavailable",
|
| 78 |
+
}
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
@quiet
|
| 83 |
+
def alignment_consonance(ratio: float = 1.0) -> str:
|
| 84 |
+
"""alignment.harmonic_resonance.consonance_score. Provenance: inferred.
|
| 85 |
+
|
| 86 |
+
Args:
|
| 87 |
+
ratio: Frequency ratio. Non-positive is the function's own zero. Label: cited, consonance_score.
|
| 88 |
+
"""
|
| 89 |
+
|
| 90 |
+
number = _finite(ratio)
|
| 91 |
+
if number is None:
|
| 92 |
+
return _missing("ratio")
|
| 93 |
+
from aureon.alignment.harmonic_resonance import consonance_score
|
| 94 |
+
|
| 95 |
+
return _dumps(
|
| 96 |
+
{
|
| 97 |
+
"label": "inferred. consonance_score.",
|
| 98 |
+
"provenance": "inferred",
|
| 99 |
+
"score": float(consonance_score(number)),
|
| 100 |
+
"status": "inferred",
|
| 101 |
+
}
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
@quiet
|
| 106 |
+
def analytics_fear_greed() -> str:
|
| 107 |
+
"""analytics.backtest_sentiment_oracle.derive_fear_greed on a 40-step series. Provenance: inferred.
|
| 108 |
+
|
| 109 |
+
No backtest is run. Trade readiness: HOLD.
|
| 110 |
+
|
| 111 |
+
Args:
|
| 112 |
+
none: The series is a fixed 40-step fixture ramp, not market data. Label: inferred.
|
| 113 |
+
"""
|
| 114 |
+
|
| 115 |
+
from aureon.analytics.backtest_sentiment_oracle import derive_fear_greed
|
| 116 |
+
|
| 117 |
+
closes = [100.0 + index for index in range(40)]
|
| 118 |
+
volumes = [1.0 for _ in range(40)]
|
| 119 |
+
result = derive_fear_greed(closes, volumes, 39)
|
| 120 |
+
result["label"] = "inferred. derive_fear_greed on a fixed 40-step fixture ramp, not market data. Not a backtest."
|
| 121 |
+
result["provenance"] = "inferred"
|
| 122 |
+
result["status"] = "inferred"
|
| 123 |
+
result["trade_readiness"] = "HOLD"
|
| 124 |
+
return _dumps(result)
|
| 125 |
+
|
| 126 |
+
|
| 127 |
+
@quiet
|
| 128 |
+
def appliance_sha256() -> str:
|
| 129 |
+
"""appliance.build_pipeline.sha256_file on a temp file that is deleted. Provenance: cited.
|
| 130 |
+
|
| 131 |
+
Args:
|
| 132 |
+
none: The bytes are written under the system temp directory and removed. Label: cited, sha256_file.
|
| 133 |
+
"""
|
| 134 |
+
|
| 135 |
+
from aureon.appliance.build_pipeline import sha256_file
|
| 136 |
+
|
| 137 |
+
handle = tempfile.NamedTemporaryFile(prefix="aureon-public-sha-", delete=False)
|
| 138 |
+
path = Path(handle.name)
|
| 139 |
+
try:
|
| 140 |
+
handle.write(b"aureon-public")
|
| 141 |
+
handle.close()
|
| 142 |
+
digest = sha256_file(path)
|
| 143 |
+
finally:
|
| 144 |
+
path.unlink(missing_ok=True)
|
| 145 |
+
return _dumps(
|
| 146 |
+
{
|
| 147 |
+
"label": "cited. sha256_file on a deleted temp file.",
|
| 148 |
+
"provenance": "cited",
|
| 149 |
+
"sha256": digest,
|
| 150 |
+
"status": "cited",
|
| 151 |
+
}
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
@quiet
|
| 156 |
+
def approval_subject_line(action: str = "status") -> str:
|
| 157 |
+
"""approval.compose.subject_line. Provenance: cited. The owner address is not read.
|
| 158 |
+
|
| 159 |
+
Args:
|
| 160 |
+
action: Title text. Label: cited, subject_line.
|
| 161 |
+
"""
|
| 162 |
+
|
| 163 |
+
from aureon.approval.compose import subject_line
|
| 164 |
+
|
| 165 |
+
return _dumps(
|
| 166 |
+
{
|
| 167 |
+
"label": "cited. subject_line. No message is sent.",
|
| 168 |
+
"provenance": "cited",
|
| 169 |
+
"status": "cited",
|
| 170 |
+
"subject": subject_line(action or "status"),
|
| 171 |
+
}
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
@quiet
|
| 176 |
+
def briefing_severity(severity: str = "high") -> str:
|
| 177 |
+
"""briefing.schemas.severity_rank. Provenance: cited. The assembler is not called.
|
| 178 |
+
|
| 179 |
+
Args:
|
| 180 |
+
severity: Rank label. Label: cited, severity_rank.
|
| 181 |
+
"""
|
| 182 |
+
|
| 183 |
+
from aureon.briefing.schemas import severity_rank
|
| 184 |
+
|
| 185 |
+
return _dumps(
|
| 186 |
+
{
|
| 187 |
+
"label": "cited. severity_rank.",
|
| 188 |
+
"provenance": "cited",
|
| 189 |
+
"rank": int(severity_rank(severity)),
|
| 190 |
+
"status": "cited",
|
| 191 |
+
}
|
| 192 |
+
)
|
| 193 |
+
|
| 194 |
+
|
| 195 |
+
@quiet
|
| 196 |
+
def cognition_logic_flow() -> str:
|
| 197 |
+
"""cognition.logic_flow.compute_logic_flow. Provenance: inferred.
|
| 198 |
+
|
| 199 |
+
The bus is in memory. write_logic_flow_report is not called. Trade readiness: HOLD.
|
| 200 |
+
|
| 201 |
+
Args:
|
| 202 |
+
none: The function's own default seed score is used. Label: cited, compute_logic_flow.
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
from aureon.cognition.logic_flow import compute_logic_flow
|
| 206 |
+
|
| 207 |
+
report = compute_logic_flow().to_dict()
|
| 208 |
+
report["label"] = "inferred. compute_logic_flow. The report file was not written."
|
| 209 |
+
report["provenance"] = "inferred"
|
| 210 |
+
report["status"] = "inferred"
|
| 211 |
+
report["trade_readiness"] = "HOLD"
|
| 212 |
+
return _dumps(report)
|
| 213 |
+
|
| 214 |
+
|
| 215 |
+
@quiet
|
| 216 |
+
def data_feed_parse_tick() -> str:
|
| 217 |
+
"""data_feeds.unified_ws_feed.parse_binance_tick on one dict. Provenance: inferred.
|
| 218 |
+
|
| 219 |
+
One fixture tick, not market data. No socket was opened. Trade readiness: HOLD.
|
| 220 |
+
|
| 221 |
+
Args:
|
| 222 |
+
none: One fixture tick, not market data. No socket was opened. Label: inferred.
|
| 223 |
+
"""
|
| 224 |
+
|
| 225 |
+
from aureon.data_feeds.unified_ws_feed import parse_binance_tick
|
| 226 |
+
|
| 227 |
+
tick = parse_binance_tick(
|
| 228 |
+
{"s": "BTCUSDT", "b": "1", "a": "2", "c": "1.5", "v": "3", "P": "0", "E": 1},
|
| 229 |
+
received_at=1.0,
|
| 230 |
+
)
|
| 231 |
+
body = tick.__dict__ if tick is not None and hasattr(tick, "__dict__") else {"tick": None}
|
| 232 |
+
body["label"] = "inferred. parse_binance_tick on one fixture tick, not market data. No socket was opened."
|
| 233 |
+
body["provenance"] = "inferred"
|
| 234 |
+
body["status"] = "inferred" if tick is not None else "unavailable"
|
| 235 |
+
body["trade_readiness"] = "HOLD"
|
| 236 |
+
return _dumps(body)
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
@quiet
|
| 240 |
+
def decoder_haversine() -> str:
|
| 241 |
+
"""decoders.grail_convergence.haversine. Provenance: inferred.
|
| 242 |
+
|
| 243 |
+
Args:
|
| 244 |
+
none: The two points are 0,0 and 0,1. Label: inferred.
|
| 245 |
+
"""
|
| 246 |
+
|
| 247 |
+
from aureon.decoders.grail_convergence import haversine
|
| 248 |
+
|
| 249 |
+
return _dumps(
|
| 250 |
+
{
|
| 251 |
+
"kilometres": float(haversine(0.0, 0.0, 0.0, 1.0)),
|
| 252 |
+
"label": "inferred. haversine.",
|
| 253 |
+
"provenance": "inferred",
|
| 254 |
+
"status": "inferred",
|
| 255 |
+
}
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
|
| 259 |
+
@quiet
|
| 260 |
+
def gates_reading(action: str = "draft") -> str:
|
| 261 |
+
"""gates.switchboard.is_human_held and gates.panel.ungrounded_nodes. Provenance: cited.
|
| 262 |
+
|
| 263 |
+
The benchmark writer is not called. Auris panel vote is not called. The nine-node list is the ungrounded-node return when no slice is grounded.
|
| 264 |
+
|
| 265 |
+
Args:
|
| 266 |
+
action: Text passed to is_human_held. Label: cited, is_human_held.
|
| 267 |
+
"""
|
| 268 |
+
|
| 269 |
+
from aureon.gates.panel import ungrounded_nodes
|
| 270 |
+
from aureon.gates.switchboard import is_human_held
|
| 271 |
+
|
| 272 |
+
return _dumps(
|
| 273 |
+
{
|
| 274 |
+
"human_held": bool(is_human_held(action)),
|
| 275 |
+
"label": "cited. is_human_held and ungrounded_nodes. The panel was not convened.",
|
| 276 |
+
"provenance": "cited",
|
| 277 |
+
"status": "cited",
|
| 278 |
+
"ungrounded_nodes": list(ungrounded_nodes(frozenset())),
|
| 279 |
+
"which_auris": "Nine-node names from NODE_SLICE via ungrounded_nodes. Not the conjecture, not the persona, not the coherence evaluator.",
|
| 280 |
+
}
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
@quiet
|
| 285 |
+
def governance_seasonal_gate() -> str:
|
| 286 |
+
"""governance.celtic_voice_bank.seasonal_gate_for_date. Provenance: cited.
|
| 287 |
+
|
| 288 |
+
Live authorization is not issued.
|
| 289 |
+
|
| 290 |
+
Args:
|
| 291 |
+
none: The date is 2026-01-15. Label: cited, seasonal_gate_for_date.
|
| 292 |
+
"""
|
| 293 |
+
|
| 294 |
+
from aureon.governance.celtic_voice_bank import seasonal_gate_for_date
|
| 295 |
+
|
| 296 |
+
return _dumps(
|
| 297 |
+
{
|
| 298 |
+
"gate": seasonal_gate_for_date(date(2026, 1, 15)),
|
| 299 |
+
"label": "cited. seasonal_gate_for_date.",
|
| 300 |
+
"provenance": "cited",
|
| 301 |
+
"status": "cited",
|
| 302 |
+
}
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
@quiet
|
| 307 |
+
def grants_breath_interval() -> str:
|
| 308 |
+
"""grants.daemon.breath_interval. Provenance: cited. Dossiers are not read.
|
| 309 |
+
|
| 310 |
+
Args:
|
| 311 |
+
none: urgency is None, which the function documents as its slowest interval. Label: cited, breath_interval.
|
| 312 |
+
"""
|
| 313 |
+
|
| 314 |
+
from aureon.grants.daemon import breath_interval
|
| 315 |
+
|
| 316 |
+
return _dumps(
|
| 317 |
+
{
|
| 318 |
+
"interval_s": float(breath_interval(None)),
|
| 319 |
+
"label": "cited. breath_interval. No dossier was read.",
|
| 320 |
+
"provenance": "cited",
|
| 321 |
+
"status": "cited",
|
| 322 |
+
}
|
| 323 |
+
)
|
| 324 |
+
|
| 325 |
+
|
| 326 |
+
@quiet
|
| 327 |
+
def integrations_phi_plan() -> str:
|
| 328 |
+
"""integrations.ollama.hnc_phi_swarm.build_phi_swarm_plan. Provenance: inferred.
|
| 329 |
+
|
| 330 |
+
No model is called.
|
| 331 |
+
|
| 332 |
+
Args:
|
| 333 |
+
none: flow is observe and catalog_size is 2. Label: inferred.
|
| 334 |
+
"""
|
| 335 |
+
|
| 336 |
+
from aureon.integrations.ollama.hnc_phi_swarm import build_phi_swarm_plan
|
| 337 |
+
|
| 338 |
+
plan = build_phi_swarm_plan({"flow": "observe"}, catalog_size=2, max_total_calls=4)
|
| 339 |
+
plan["label"] = "inferred. build_phi_swarm_plan. No model was called."
|
| 340 |
+
plan["provenance"] = "inferred"
|
| 341 |
+
plan["status"] = "inferred"
|
| 342 |
+
return _dumps(plan)
|
| 343 |
+
|
| 344 |
+
|
| 345 |
+
@quiet
|
| 346 |
+
def intelligence_resonance() -> str:
|
| 347 |
+
"""intelligence.aureon_advanced_intelligence.calculate_harmonic_resonance. Provenance: inferred.
|
| 348 |
+
|
| 349 |
+
Trading permission is not called.
|
| 350 |
+
|
| 351 |
+
Args:
|
| 352 |
+
none: The two frequencies are 100 and 200. Label: inferred.
|
| 353 |
+
"""
|
| 354 |
+
|
| 355 |
+
from aureon.intelligence.aureon_advanced_intelligence import calculate_harmonic_resonance
|
| 356 |
+
|
| 357 |
+
return _dumps(
|
| 358 |
+
{
|
| 359 |
+
"label": "inferred. calculate_harmonic_resonance.",
|
| 360 |
+
"provenance": "inferred",
|
| 361 |
+
"resonance": float(calculate_harmonic_resonance(100.0, 200.0)),
|
| 362 |
+
"status": "inferred",
|
| 363 |
+
"trade_readiness": "HOLD",
|
| 364 |
+
}
|
| 365 |
+
)
|
| 366 |
+
|
| 367 |
+
|
| 368 |
+
@quiet
|
| 369 |
+
def observability_redact() -> str:
|
| 370 |
+
"""observability.runtime.redact_observability_value. Provenance: cited. No event is emitted.
|
| 371 |
+
|
| 372 |
+
Args:
|
| 373 |
+
none: The value is a short string with no secret. Label: cited, redact_observability_value.
|
| 374 |
+
"""
|
| 375 |
+
|
| 376 |
+
from aureon.observability.runtime import redact_observability_value
|
| 377 |
+
|
| 378 |
+
return _dumps(
|
| 379 |
+
{
|
| 380 |
+
"label": "cited. redact_observability_value.",
|
| 381 |
+
"provenance": "cited",
|
| 382 |
+
"redacted": redact_observability_value("public-note"),
|
| 383 |
+
"status": "cited",
|
| 384 |
+
}
|
| 385 |
+
)
|
| 386 |
+
|
| 387 |
+
|
| 388 |
+
@quiet
|
| 389 |
+
def observer_kp_sample() -> str:
|
| 390 |
+
"""observer.historical_backtest.parse_kp_file, one sample. Provenance: cited or unavailable.
|
| 391 |
+
|
| 392 |
+
The committed Kp file is read when it is present. Nothing is downloaded. Schumann f0: null. HOLD.
|
| 393 |
+
|
| 394 |
+
Args:
|
| 395 |
+
none: start_year 2024 and max_samples 1. Label: cited, parse_kp_file.
|
| 396 |
+
"""
|
| 397 |
+
|
| 398 |
+
from aureon.observer.historical_backtest import DEFAULT_KP_PATH, parse_kp_file
|
| 399 |
+
|
| 400 |
+
if not DEFAULT_KP_PATH.is_file():
|
| 401 |
+
return _dumps(
|
| 402 |
+
{
|
| 403 |
+
"label": "cited. The committed Kp file is not in this tree.",
|
| 404 |
+
"provenance": "cited",
|
| 405 |
+
"reason": "Kp file missing",
|
| 406 |
+
"schumann_f0": "null. HOLD",
|
| 407 |
+
"status": "unavailable",
|
| 408 |
+
}
|
| 409 |
+
)
|
| 410 |
+
samples = parse_kp_file(DEFAULT_KP_PATH, start_year=2024, max_samples=1)
|
| 411 |
+
first = samples[0] if samples else None
|
| 412 |
+
return _dumps(
|
| 413 |
+
{
|
| 414 |
+
"count": len(samples),
|
| 415 |
+
"kp": None if first is None else float(first.kp),
|
| 416 |
+
"label": "cited. parse_kp_file, one sample. Not a Schumann measurement.",
|
| 417 |
+
"provenance": "cited",
|
| 418 |
+
"schumann_f0": "null. HOLD",
|
| 419 |
+
"status": "cited" if first is not None else "unavailable",
|
| 420 |
+
}
|
| 421 |
+
)
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
@quiet
|
| 425 |
+
def plumber_sha256() -> str:
|
| 426 |
+
"""plumber.crypto.sha256_hex. Provenance: cited. No key is generated.
|
| 427 |
+
|
| 428 |
+
Args:
|
| 429 |
+
none: The text is aureon-public. Label: cited, sha256_hex.
|
| 430 |
+
"""
|
| 431 |
+
|
| 432 |
+
from aureon.plumber.crypto import sha256_hex
|
| 433 |
+
|
| 434 |
+
return _dumps(
|
| 435 |
+
{
|
| 436 |
+
"label": "cited. sha256_hex. No key was generated.",
|
| 437 |
+
"provenance": "cited",
|
| 438 |
+
"sha256": sha256_hex("aureon-public"),
|
| 439 |
+
"status": "cited",
|
| 440 |
+
}
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
@quiet
|
| 445 |
+
def portals_html_to_text() -> str:
|
| 446 |
+
"""portals.ifs.html_to_text. Provenance: cited. No dashboard is fetched.
|
| 447 |
+
|
| 448 |
+
Args:
|
| 449 |
+
none: The HTML is a one-line fixture. Label: cited, html_to_text.
|
| 450 |
+
"""
|
| 451 |
+
|
| 452 |
+
from aureon.portals.ifs import html_to_text
|
| 453 |
+
|
| 454 |
+
return _dumps(
|
| 455 |
+
{
|
| 456 |
+
"label": "cited. html_to_text.",
|
| 457 |
+
"provenance": "cited",
|
| 458 |
+
"status": "cited",
|
| 459 |
+
"text": html_to_text("<p>hold</p>"),
|
| 460 |
+
}
|
| 461 |
+
)
|
| 462 |
+
|
| 463 |
+
|
| 464 |
+
@quiet
|
| 465 |
+
def queen_zpe_ground(lambda_t: float = 1.0) -> str:
|
| 466 |
+
"""queen.temporal_ground.compute_zpe_ground. Provenance: inferred.
|
| 467 |
+
|
| 468 |
+
This is the queen math already in that module. The phase ladder and order gates are not called. The persona is not scored. Trade readiness: HOLD.
|
| 469 |
+
|
| 470 |
+
Args:
|
| 471 |
+
lambda_t: Field value. Label: cited, compute_zpe_ground.
|
| 472 |
+
"""
|
| 473 |
+
|
| 474 |
+
number = _finite(lambda_t)
|
| 475 |
+
if number is None:
|
| 476 |
+
return _missing("lambda_t")
|
| 477 |
+
from aureon.queen.temporal_ground import compute_zpe_ground
|
| 478 |
+
|
| 479 |
+
body = compute_zpe_ground(number).to_dict()
|
| 480 |
+
body["label"] = "inferred. compute_zpe_ground. Persona was not scored."
|
| 481 |
+
body["provenance"] = "inferred"
|
| 482 |
+
body["status"] = "inferred"
|
| 483 |
+
body["trade_readiness"] = "HOLD"
|
| 484 |
+
body["which_auris"] = "Not the conjecture, not the nine nodes, not the coherence evaluator, and not the persona."
|
| 485 |
+
return _dumps(body)
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
@quiet
|
| 489 |
+
def s51_summarize_receipts() -> str:
|
| 490 |
+
"""s51.aureon_51_compound.summarize_compounding with no receipts. Provenance: cited.
|
| 491 |
+
|
| 492 |
+
The sim is not run. Trade readiness: HOLD.
|
| 493 |
+
|
| 494 |
+
Args:
|
| 495 |
+
none: An empty receipt list. Label: cited, summarize_compounding.
|
| 496 |
+
"""
|
| 497 |
+
|
| 498 |
+
from aureon.s51.aureon_51_compound import summarize_compounding
|
| 499 |
+
|
| 500 |
+
body = summarize_compounding([])
|
| 501 |
+
body["receipt_status"] = body.get("status")
|
| 502 |
+
body["label"] = "cited. summarize_compounding with no receipts."
|
| 503 |
+
body["provenance"] = "cited"
|
| 504 |
+
body["status"] = "cited"
|
| 505 |
+
body["trade_readiness"] = "HOLD"
|
| 506 |
+
return _dumps(body)
|
| 507 |
+
|
| 508 |
+
|
| 509 |
+
@quiet
|
| 510 |
+
def search_summarize_text() -> str:
|
| 511 |
+
"""search.online_research_cinema.summarize_text. Provenance: cited. No URL is fetched.
|
| 512 |
+
|
| 513 |
+
Args:
|
| 514 |
+
none: One sentence and the topic hold. Label: cited, summarize_text.
|
| 515 |
+
"""
|
| 516 |
+
|
| 517 |
+
from aureon.search.online_research_cinema import summarize_text
|
| 518 |
+
|
| 519 |
+
return _dumps(
|
| 520 |
+
{
|
| 521 |
+
"label": "cited. summarize_text. No URL was fetched.",
|
| 522 |
+
"provenance": "cited",
|
| 523 |
+
"status": "cited",
|
| 524 |
+
"summary": summarize_text("Hold the claim.", "hold"),
|
| 525 |
+
}
|
| 526 |
+
)
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
@quiet
|
| 530 |
+
def simulation_hz_to_rgb() -> str:
|
| 531 |
+
"""simulation.aureon_world_simulator.hz_to_rgb. Provenance: inferred. No simulation is run.
|
| 532 |
+
|
| 533 |
+
Args:
|
| 534 |
+
none: The frequency is 528. Label: inferred.
|
| 535 |
+
"""
|
| 536 |
+
|
| 537 |
+
from aureon.simulation.aureon_world_simulator import hz_to_rgb
|
| 538 |
+
|
| 539 |
+
red, green, blue = hz_to_rgb(528.0)
|
| 540 |
+
return _dumps(
|
| 541 |
+
{
|
| 542 |
+
"blue": int(blue),
|
| 543 |
+
"green": int(green),
|
| 544 |
+
"label": "inferred. hz_to_rgb. No simulation was run.",
|
| 545 |
+
"provenance": "inferred",
|
| 546 |
+
"red": int(red),
|
| 547 |
+
"status": "inferred",
|
| 548 |
+
}
|
| 549 |
+
)
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
@quiet
|
| 553 |
+
def swarm_voice_for_gamma(gamma: float = 0.5) -> str:
|
| 554 |
+
"""swarm.druidic_council.voice_for_gamma. Provenance: inferred. The council is not convened.
|
| 555 |
+
|
| 556 |
+
Args:
|
| 557 |
+
gamma: Coherence in 0 to 1. Label: cited, voice_for_gamma.
|
| 558 |
+
"""
|
| 559 |
+
|
| 560 |
+
number = _finite(gamma)
|
| 561 |
+
if number is None:
|
| 562 |
+
return _missing("gamma")
|
| 563 |
+
from aureon.swarm.druidic_council import voice_for_gamma
|
| 564 |
+
|
| 565 |
+
try:
|
| 566 |
+
band, weight = voice_for_gamma(number)
|
| 567 |
+
except ValueError as exc:
|
| 568 |
+
return _dumps(
|
| 569 |
+
{
|
| 570 |
+
"provenance": "cited",
|
| 571 |
+
"reason": str(exc),
|
| 572 |
+
"status": "unavailable",
|
| 573 |
+
}
|
| 574 |
+
)
|
| 575 |
+
return _dumps(
|
| 576 |
+
{
|
| 577 |
+
"label": "inferred. voice_for_gamma. The council was not convened.",
|
| 578 |
+
"provenance": "inferred",
|
| 579 |
+
"status": "inferred",
|
| 580 |
+
"voice_band": band,
|
| 581 |
+
"voice_weight": float(weight),
|
| 582 |
+
}
|
| 583 |
+
)
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
@quiet
|
| 587 |
+
def vault_count_words() -> str:
|
| 588 |
+
"""vault.voice.document_artifact_skill.count_words. Provenance: cited.
|
| 589 |
+
|
| 590 |
+
Key stores and persona files are not read.
|
| 591 |
+
|
| 592 |
+
Args:
|
| 593 |
+
none: The text is two words. Label: cited, count_words.
|
| 594 |
+
"""
|
| 595 |
+
|
| 596 |
+
from aureon.vault.voice.document_artifact_skill import count_words
|
| 597 |
+
|
| 598 |
+
return _dumps(
|
| 599 |
+
{
|
| 600 |
+
"count": int(count_words("two words")),
|
| 601 |
+
"label": "cited. count_words. No vault file was read.",
|
| 602 |
+
"provenance": "cited",
|
| 603 |
+
"status": "cited",
|
| 604 |
+
}
|
| 605 |
+
)
|
| 606 |
+
|
| 607 |
+
|
| 608 |
+
TOOLS: list[Any] = [
|
| 609 |
+
alignment_consonance,
|
| 610 |
+
analytics_fear_greed,
|
| 611 |
+
appliance_sha256,
|
| 612 |
+
approval_subject_line,
|
| 613 |
+
briefing_severity,
|
| 614 |
+
cognition_logic_flow,
|
| 615 |
+
data_feed_parse_tick,
|
| 616 |
+
decoder_haversine,
|
| 617 |
+
gates_reading,
|
| 618 |
+
governance_seasonal_gate,
|
| 619 |
+
grants_breath_interval,
|
| 620 |
+
integrations_phi_plan,
|
| 621 |
+
intelligence_resonance,
|
| 622 |
+
observability_redact,
|
| 623 |
+
observer_kp_sample,
|
| 624 |
+
plumber_sha256,
|
| 625 |
+
portals_html_to_text,
|
| 626 |
+
queen_zpe_ground,
|
| 627 |
+
s51_summarize_receipts,
|
| 628 |
+
search_summarize_text,
|
| 629 |
+
simulation_hz_to_rgb,
|
| 630 |
+
swarm_voice_for_gamma,
|
| 631 |
+
vault_count_words,
|
| 632 |
+
]
|
paths.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Locate the checkout that vendors the Space replays. Does not write."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
|
| 7 |
+
_MARKER = Path("huggingface") / "hnc-field" / "guard.py"
|
| 8 |
+
_AUREON = Path("aureon") / "core" / "hnc_field.py"
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def repo_root() -> Path:
|
| 12 |
+
"""Directory that contains both the Space guard and the aureon package.
|
| 13 |
+
|
| 14 |
+
Raises FileNotFoundError when this process is not inside that checkout.
|
| 15 |
+
The server needs the checkout, the same as the earlier public server.
|
| 16 |
+
"""
|
| 17 |
+
|
| 18 |
+
here = Path(__file__).resolve()
|
| 19 |
+
for parent in here.parents:
|
| 20 |
+
if (parent / _MARKER).is_file() and (parent / _AUREON).is_file():
|
| 21 |
+
return parent
|
| 22 |
+
raise FileNotFoundError("huggingface/hnc-field/guard.py was not found above the server")
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def brain_json() -> Path:
|
| 26 |
+
return repo_root() / "huggingface" / "hnc-field" / "replay" / "brain.json"
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def qgita_json() -> Path:
|
| 30 |
+
return repo_root() / "huggingface" / "qgita-snr" / "replay" / "qgita_snr.json"
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def qgita_series() -> Path:
|
| 34 |
+
return repo_root() / "huggingface" / "qgita-snr" / "data" / "de440_timeseries.csv"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def organism_json() -> Path:
|
| 38 |
+
return repo_root() / "huggingface" / "organism-replay" / "replay" / "organism.json"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def auris_json() -> Path:
|
| 42 |
+
return repo_root() / "huggingface" / "fixed-seed-reproducible-runs" / "auris_nodes.json"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def holds_readme() -> Path:
|
| 46 |
+
return repo_root() / "huggingface" / "README.md"
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def space_guard() -> Path:
|
| 50 |
+
return repo_root() / "huggingface" / "hnc-field" / "guard.py"
|
pin_bl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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Git-blob check for a file loaded from the checkout beside a pinned aureon.
|
| 2 |
+
|
| 3 |
+
Every checkout load goes through ``load_pinned_source`` or the pinned finder.
|
| 4 |
+
Those helpers require the expected blob, read the file once, and execute
|
| 5 |
+
those same bytes. ``huggingface/hnc-field/guard.py`` is checked the same way.
|
| 6 |
+
Nothing under ``mcp/`` uses ``spec_from_file_location``.
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
from __future__ import annotations
|
| 10 |
+
|
| 11 |
+
import hashlib
|
| 12 |
+
import importlib.util
|
| 13 |
+
import sys
|
| 14 |
+
from importlib.abc import Loader
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
from types import ModuleType
|
| 17 |
+
|
| 18 |
+
PINNED_PHENOLIC_BLOB = "325484e9299eecb427cf0063590b0a1d17c16f31"
|
| 19 |
+
PHENOLIC_MISMATCH = "checkout phenolic_fingerprint differs from pin 8aa6a2d9"
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
def git_blob_sha1(data: bytes) -> str:
|
| 23 |
+
"""SHA-1 of a git blob: the header ``blob <len>\\0`` plus the file bytes."""
|
| 24 |
+
|
| 25 |
+
header = f"blob {len(data)}\0".encode("ascii")
|
| 26 |
+
return hashlib.sha1(header + data).hexdigest()
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def pinned_blob_refusal(path: Path, expected: str, mismatch: str) -> str | None:
|
| 30 |
+
"""Return mismatch text when path is not the pinned blob. None when it matches."""
|
| 31 |
+
|
| 32 |
+
if not path.is_file():
|
| 33 |
+
return f"{path.name} is not in this checkout"
|
| 34 |
+
digest = git_blob_sha1(path.read_bytes())
|
| 35 |
+
if digest != expected:
|
| 36 |
+
return mismatch
|
| 37 |
+
return None
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
class _SameBytesLoader(Loader):
|
| 41 |
+
"""Execute the bytes already hashed. Does not read the path again."""
|
| 42 |
+
|
| 43 |
+
def __init__(self, data: bytes, origin: str) -> None:
|
| 44 |
+
self._data = data
|
| 45 |
+
self._origin = origin
|
| 46 |
+
|
| 47 |
+
def create_module(self, spec: object) -> None:
|
| 48 |
+
return None
|
| 49 |
+
|
| 50 |
+
def exec_module(self, module: ModuleType) -> None:
|
| 51 |
+
module.__file__ = self._origin
|
| 52 |
+
origin = Path(self._origin)
|
| 53 |
+
if origin.name == "__init__.py":
|
| 54 |
+
module.__path__ = [str(origin.parent)]
|
| 55 |
+
code = compile(self._data, self._origin, "exec")
|
| 56 |
+
exec(code, module.__dict__)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def expected_pin_blob(path: Path, root: Path, commit: str) -> tuple[str | None, str | None]:
|
| 60 |
+
"""Return the blob hash recorded at ``commit`` for ``path``.
|
| 61 |
+
|
| 62 |
+
This reads git, not the working-tree file. ``(None, None)`` means the
|
| 63 |
+
path is outside the checkout.
|
| 64 |
+
"""
|
| 65 |
+
|
| 66 |
+
try:
|
| 67 |
+
relative = path.resolve().relative_to(root.resolve()).as_posix()
|
| 68 |
+
except ValueError:
|
| 69 |
+
return None, None
|
| 70 |
+
import subprocess
|
| 71 |
+
|
| 72 |
+
try:
|
| 73 |
+
pin_blob = subprocess.check_output(
|
| 74 |
+
["git", "rev-parse", f"{commit}:{relative}"],
|
| 75 |
+
cwd=root,
|
| 76 |
+
text=True,
|
| 77 |
+
stderr=subprocess.DEVNULL,
|
| 78 |
+
).strip()
|
| 79 |
+
except (OSError, subprocess.CalledProcessError):
|
| 80 |
+
return None, f"{relative} is not in pin {commit[:12]}"
|
| 81 |
+
if not pin_blob:
|
| 82 |
+
return None, "expected blob is required"
|
| 83 |
+
return pin_blob, None
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
class PinnedAureonFinder:
|
| 87 |
+
"""Blob-check every ``aureon`` import against the pin. A mismatch raises."""
|
| 88 |
+
|
| 89 |
+
def __init__(self, root: Path, commit: str) -> None:
|
| 90 |
+
self.root = root
|
| 91 |
+
self.commit = commit
|
| 92 |
+
|
| 93 |
+
def find_spec(self, fullname: str, path: object, target: object = None) -> object:
|
| 94 |
+
del path, target
|
| 95 |
+
if fullname != "aureon" and not fullname.startswith("aureon."):
|
| 96 |
+
return None
|
| 97 |
+
relative = self._relative(fullname)
|
| 98 |
+
if relative is None:
|
| 99 |
+
raise ImportError(f"{fullname} is not an aureon module path")
|
| 100 |
+
expected, error = expected_pin_blob(self.root / relative, self.root, self.commit)
|
| 101 |
+
if error or not expected:
|
| 102 |
+
raise ImportError(error or "expected blob is required")
|
| 103 |
+
for candidate in self._files(fullname, relative):
|
| 104 |
+
try:
|
| 105 |
+
data = candidate.read_bytes()
|
| 106 |
+
except OSError:
|
| 107 |
+
continue
|
| 108 |
+
if git_blob_sha1(data) != expected:
|
| 109 |
+
continue
|
| 110 |
+
return self._spec(fullname, data, candidate)
|
| 111 |
+
raise ImportError(f"checkout {relative} differs from pin {self.commit[:12]}")
|
| 112 |
+
|
| 113 |
+
def _relative(self, fullname: str) -> str | None:
|
| 114 |
+
parts = fullname.split(".")
|
| 115 |
+
py_file = Path(*parts).with_suffix(".py")
|
| 116 |
+
init_file = Path(*parts) / "__init__.py"
|
| 117 |
+
for relative in (py_file, init_file):
|
| 118 |
+
expected, _error = expected_pin_blob(self.root / relative, self.root, self.commit)
|
| 119 |
+
if expected:
|
| 120 |
+
return relative.as_posix()
|
| 121 |
+
return None
|
| 122 |
+
|
| 123 |
+
def _files(self, fullname: str, relative: str) -> list[Path]:
|
| 124 |
+
files: list[Path] = []
|
| 125 |
+
checkout = self.root / relative
|
| 126 |
+
installed = self._installed_origin(fullname)
|
| 127 |
+
# The pin install is first when direct_url.json names this pin.
|
| 128 |
+
# Every candidate still has to match the pin blob before it runs.
|
| 129 |
+
# An install of any other commit stays behind the checkout.
|
| 130 |
+
pinned = self._pinned_install(installed)
|
| 131 |
+
if pinned is not None:
|
| 132 |
+
files.append(pinned)
|
| 133 |
+
if checkout.is_file() and checkout not in files:
|
| 134 |
+
files.append(checkout)
|
| 135 |
+
if installed is not None and installed not in files:
|
| 136 |
+
files.append(installed)
|
| 137 |
+
return files
|
| 138 |
+
|
| 139 |
+
def _pinned_install(self, installed: Path | None) -> Path | None:
|
| 140 |
+
if installed is None or not installed.is_file():
|
| 141 |
+
return None
|
| 142 |
+
from aureon_public.guard_loader import _direct_url_commit, _outside_checkout
|
| 143 |
+
|
| 144 |
+
if not _outside_checkout(installed, self.root):
|
| 145 |
+
return None
|
| 146 |
+
if _direct_url_commit(installed) != self.commit:
|
| 147 |
+
return None
|
| 148 |
+
return installed
|
| 149 |
+
|
| 150 |
+
def _installed_origin(self, fullname: str) -> Path | None:
|
| 151 |
+
removed = [finder for finder in sys.meta_path if isinstance(finder, PinnedAureonFinder)]
|
| 152 |
+
for finder in removed:
|
| 153 |
+
sys.meta_path.remove(finder)
|
| 154 |
+
try:
|
| 155 |
+
spec = importlib.util.find_spec(fullname)
|
| 156 |
+
finally:
|
| 157 |
+
for finder in reversed(removed):
|
| 158 |
+
sys.meta_path.insert(0, finder)
|
| 159 |
+
origin = getattr(spec, "origin", None) if spec is not None else None
|
| 160 |
+
if not origin or origin == "namespace":
|
| 161 |
+
return None
|
| 162 |
+
path = Path(origin)
|
| 163 |
+
return path if path.is_file() else None
|
| 164 |
+
|
| 165 |
+
def _spec(self, fullname: str, data: bytes, path: Path) -> object:
|
| 166 |
+
loader = _SameBytesLoader(data, str(path))
|
| 167 |
+
spec = importlib.util.spec_from_loader(fullname, loader, origin=str(path))
|
| 168 |
+
if spec is None:
|
| 169 |
+
raise ImportError(f"{fullname} could not be loaded")
|
| 170 |
+
spec.has_location = True
|
| 171 |
+
if path.name == "__init__.py":
|
| 172 |
+
spec.submodule_search_locations = [str(path.parent)]
|
| 173 |
+
return spec
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
def _loaded_by_finder(module: object) -> bool:
|
| 177 |
+
loader = getattr(getattr(module, "__spec__", None), "loader", None)
|
| 178 |
+
return isinstance(loader, _SameBytesLoader)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def refuse_preseeded_aureon() -> None:
|
| 182 |
+
"""Raise when an ``aureon`` module is already loaded by another loader.
|
| 183 |
+
|
| 184 |
+
``import`` returns a ``sys.modules`` hit without calling the finder.
|
| 185 |
+
A guard or a caller that plants a fake module first would skip the blob check.
|
| 186 |
+
"""
|
| 187 |
+
|
| 188 |
+
for name, module in list(sys.modules.items()):
|
| 189 |
+
if module is None:
|
| 190 |
+
continue
|
| 191 |
+
if name != "aureon" and not name.startswith("aureon."):
|
| 192 |
+
continue
|
| 193 |
+
if not _loaded_by_finder(module):
|
| 194 |
+
raise ImportError(f"{name} was not loaded through the pinned finder")
|
| 195 |
+
|
| 196 |
+
|
| 197 |
+
def import_through_finder(dotted: str) -> ModuleType:
|
| 198 |
+
"""Import ``dotted`` and each parent through ``PinnedAureonFinder``.
|
| 199 |
+
|
| 200 |
+
``find_spec`` on the full name is not used. That call imports parent
|
| 201 |
+
packages before any blob check. A parent already in ``sys.modules`` from
|
| 202 |
+
another loader is refused rather than reused.
|
| 203 |
+
"""
|
| 204 |
+
|
| 205 |
+
if dotted != "aureon" and not dotted.startswith("aureon."):
|
| 206 |
+
raise ImportError("only an aureon module can be loaded")
|
| 207 |
+
install_pinned_aureon_finder()
|
| 208 |
+
parts = dotted.split(".")
|
| 209 |
+
for index in range(1, len(parts) + 1):
|
| 210 |
+
name = ".".join(parts[:index])
|
| 211 |
+
existing = sys.modules.get(name)
|
| 212 |
+
if existing is not None:
|
| 213 |
+
if not _loaded_by_finder(existing):
|
| 214 |
+
raise ImportError(f"{name} was not loaded through the pinned finder")
|
| 215 |
+
continue
|
| 216 |
+
importlib.import_module(name)
|
| 217 |
+
loaded = sys.modules.get(name)
|
| 218 |
+
if loaded is None or not _loaded_by_finder(loaded):
|
| 219 |
+
raise ImportError(f"{name} was not loaded through the pinned finder")
|
| 220 |
+
module = sys.modules.get(dotted)
|
| 221 |
+
if module is None:
|
| 222 |
+
raise ImportError(f"{dotted} could not be loaded")
|
| 223 |
+
return module
|
| 224 |
+
|
| 225 |
+
|
| 226 |
+
def install_pinned_aureon_finder(root: Path | None = None, commit: str | None = None) -> PinnedAureonFinder:
|
| 227 |
+
"""Install the finder once. Later aureon imports fail closed on a blob mismatch."""
|
| 228 |
+
|
| 229 |
+
from aureon_public.guard_loader import PINNED_COMMIT
|
| 230 |
+
from aureon_public.paths import repo_root
|
| 231 |
+
|
| 232 |
+
base = repo_root() if root is None else root
|
| 233 |
+
pin = PINNED_COMMIT if commit is None else commit
|
| 234 |
+
for finder in sys.meta_path:
|
| 235 |
+
if isinstance(finder, PinnedAureonFinder):
|
| 236 |
+
return finder
|
| 237 |
+
finder = PinnedAureonFinder(base, pin)
|
| 238 |
+
sys.meta_path.insert(0, finder)
|
| 239 |
+
return finder
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
def load_pinned_source(module_name: str, path: Path, expected_blob: str, mismatch: str) -> str | None:
|
| 243 |
+
"""Read ``path`` once. Refuse unless those bytes are ``expected_blob``. Exec them.
|
| 244 |
+
|
| 245 |
+
Returns None when the module is ready. A refusal string means it was not
|
| 246 |
+
executed. An empty ``expected_blob`` is a refusal and does not read the file.
|
| 247 |
+
"""
|
| 248 |
+
|
| 249 |
+
if not expected_blob:
|
| 250 |
+
return "expected blob is required"
|
| 251 |
+
try:
|
| 252 |
+
data = path.read_bytes()
|
| 253 |
+
except OSError:
|
| 254 |
+
return f"{path.name} is not in this checkout"
|
| 255 |
+
if git_blob_sha1(data) != expected_blob:
|
| 256 |
+
return mismatch
|
| 257 |
+
if module_name in sys.modules:
|
| 258 |
+
return None
|
| 259 |
+
loader = _SameBytesLoader(data, str(path))
|
| 260 |
+
spec = importlib.util.spec_from_loader(module_name, loader, origin=str(path))
|
| 261 |
+
if spec is None:
|
| 262 |
+
return f"{path.name} could not be loaded"
|
| 263 |
+
spec.has_location = True
|
| 264 |
+
if path.name == "__init__.py":
|
| 265 |
+
spec.submodule_search_locations = [str(path.parent)]
|
| 266 |
+
module = importlib.util.module_from_spec(spec)
|
| 267 |
+
module.__file__ = str(path)
|
| 268 |
+
if path.name == "__init__.py":
|
| 269 |
+
module.__path__ = [str(path.parent)]
|
| 270 |
+
parent_name, _, child = module_name.rpartition(".")
|
| 271 |
+
module.__package__ = parent_name if parent_name else module_name
|
| 272 |
+
sys.modules[module_name] = module
|
| 273 |
+
try:
|
| 274 |
+
loader.exec_module(module)
|
| 275 |
+
except Exception as exc:
|
| 276 |
+
sys.modules.pop(module_name, None)
|
| 277 |
+
return f"{type(exc).__name__}: {exc}"[:240]
|
| 278 |
+
parent = sys.modules.get(parent_name) if parent_name else None
|
| 279 |
+
if parent is not None:
|
| 280 |
+
setattr(parent, child, module)
|
| 281 |
+
return None
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def load_checkout_module(module_name: str, path: Path, root: Path, commit: str) -> tuple[ModuleType | None, str | None]:
|
| 285 |
+
"""Load a checkout module and its checkout parents through ``load_pinned_source``."""
|
| 286 |
+
|
| 287 |
+
parts = module_name.split(".")
|
| 288 |
+
for index in range(1, len(parts)):
|
| 289 |
+
parent_name = ".".join(parts[:index])
|
| 290 |
+
if parent_name in sys.modules:
|
| 291 |
+
continue
|
| 292 |
+
parent_path = root.joinpath(*parts[:index], "__init__.py")
|
| 293 |
+
expected, error = expected_pin_blob(parent_path, root, commit)
|
| 294 |
+
if error or not expected:
|
| 295 |
+
return None, error or "expected blob is required"
|
| 296 |
+
refusal = load_pinned_source(
|
| 297 |
+
parent_name,
|
| 298 |
+
parent_path,
|
| 299 |
+
expected,
|
| 300 |
+
f"checkout {parent_path.relative_to(root).as_posix()} differs from pin {commit[:12]}",
|
| 301 |
+
)
|
| 302 |
+
if refusal:
|
| 303 |
+
return None, refusal
|
| 304 |
+
expected, error = expected_pin_blob(path, root, commit)
|
| 305 |
+
if error or not expected:
|
| 306 |
+
return None, error or "expected blob is required"
|
| 307 |
+
try:
|
| 308 |
+
relative = path.resolve().relative_to(root.resolve()).as_posix()
|
| 309 |
+
except ValueError:
|
| 310 |
+
relative = path.name
|
| 311 |
+
refusal = load_pinned_source(
|
| 312 |
+
module_name,
|
| 313 |
+
path,
|
| 314 |
+
expected,
|
| 315 |
+
f"checkout {relative} differs from pin {commit[:12]}",
|
| 316 |
+
)
|
| 317 |
+
if refusal:
|
| 318 |
+
return None, refusal
|
| 319 |
+
loaded = sys.modules.get(module_name)
|
| 320 |
+
if loaded is None:
|
| 321 |
+
return None, f"{path.name} could not be loaded"
|
| 322 |
+
return loaded, None
|
| 323 |
+
|
| 324 |
+
|
| 325 |
+
def checkout_blob_refusal(path: Path, root: Path, commit: str) -> str | None:
|
| 326 |
+
"""Refuse a checkout file whose git blob is not the blob at ``commit``.
|
| 327 |
+
|
| 328 |
+
Returns None when the bytes match. A missing pin path is a refusal.
|
| 329 |
+
The caller skips this when the import comes from an installed copy
|
| 330 |
+
outside the checkout.
|
| 331 |
+
"""
|
| 332 |
+
|
| 333 |
+
if not path.is_file():
|
| 334 |
+
return f"{path} is not in this checkout"
|
| 335 |
+
try:
|
| 336 |
+
relative = path.resolve().relative_to(root.resolve()).as_posix()
|
| 337 |
+
except ValueError:
|
| 338 |
+
return "path is outside the checkout"
|
| 339 |
+
expected, error = expected_pin_blob(path, root, commit)
|
| 340 |
+
if error:
|
| 341 |
+
return error
|
| 342 |
+
if not expected:
|
| 343 |
+
return "expected blob is required"
|
| 344 |
+
try:
|
| 345 |
+
data = path.read_bytes()
|
| 346 |
+
except OSError:
|
| 347 |
+
return f"{path.name} is not in this checkout"
|
| 348 |
+
if git_blob_sha1(data) != expected:
|
| 349 |
+
return f"checkout {relative} differs from pin {commit[:12]}"
|
| 350 |
+
return None
|
protocol_measure.py
ADDED
|
@@ -0,0 +1,258 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Stdio and Streamable HTTP sessions against aureon-public.
|
| 2 |
+
|
| 3 |
+
Run from measured/aureon_public_protocol_run.sh. Do not hand-edit the output.
|
| 4 |
+
|
| 5 |
+
The process requires AUREON_PUBLIC_REQUIRE_PIN=1 and an aureon install whose
|
| 6 |
+
direct_url.json names the pin. The HTTP listener is 127.0.0.1. One tools/call
|
| 7 |
+
is alignment_consonance_read with ratio 1.0.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import argparse
|
| 13 |
+
import asyncio
|
| 14 |
+
import importlib.metadata
|
| 15 |
+
import json
|
| 16 |
+
import os
|
| 17 |
+
import signal
|
| 18 |
+
import socket
|
| 19 |
+
import subprocess
|
| 20 |
+
import sys
|
| 21 |
+
import tempfile
|
| 22 |
+
import time
|
| 23 |
+
from pathlib import Path
|
| 24 |
+
from typing import Any
|
| 25 |
+
|
| 26 |
+
from mcp import ClientSession, StdioServerParameters
|
| 27 |
+
from mcp.client.stdio import stdio_client
|
| 28 |
+
from mcp.client.streamable_http import streamable_http_client
|
| 29 |
+
|
| 30 |
+
from aureon_public import paths
|
| 31 |
+
from aureon_public.guard_loader import aureon_source
|
| 32 |
+
from aureon_public.server import enforce_public_pin
|
| 33 |
+
|
| 34 |
+
TOOL_NAME = "alignment_consonance_read"
|
| 35 |
+
TOOL_ARGUMENTS = {"ratio": 1.0}
|
| 36 |
+
_BIND_HOST = "127.0.0.1"
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def _dump(model: Any) -> dict[str, Any]:
|
| 40 |
+
return model.model_dump(mode="json", by_alias=True)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _server_env() -> dict[str, str]:
|
| 44 |
+
env: dict[str, str] = {}
|
| 45 |
+
for key in ("HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER", "LANG", "TMPDIR"):
|
| 46 |
+
value = os.environ.get(key)
|
| 47 |
+
if value:
|
| 48 |
+
env[key] = value
|
| 49 |
+
env["PYTHONUNBUFFERED"] = "1"
|
| 50 |
+
env["AUREON_PUBLIC_REQUIRE_PIN"] = "1"
|
| 51 |
+
return env
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
async def _list_pages(method: Any) -> list[dict[str, Any]]:
|
| 55 |
+
pages: list[dict[str, Any]] = []
|
| 56 |
+
cursor: str | None = None
|
| 57 |
+
seen: set[str] = set()
|
| 58 |
+
while True:
|
| 59 |
+
result = await method() if cursor is None else await method(cursor=cursor)
|
| 60 |
+
page = _dump(result)
|
| 61 |
+
pages.append(page)
|
| 62 |
+
nxt = page.get("nextCursor")
|
| 63 |
+
if not isinstance(nxt, str) or not nxt or nxt in seen:
|
| 64 |
+
return pages
|
| 65 |
+
seen.add(nxt)
|
| 66 |
+
cursor = nxt
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
async def _exchange(session: ClientSession) -> dict[str, Any]:
|
| 70 |
+
initialized = await session.initialize()
|
| 71 |
+
tools_list = await _list_pages(session.list_tools)
|
| 72 |
+
resources_list = await _list_pages(session.list_resources)
|
| 73 |
+
prompts_list = await _list_pages(session.list_prompts)
|
| 74 |
+
called = await session.call_tool(TOOL_NAME, TOOL_ARGUMENTS)
|
| 75 |
+
return {
|
| 76 |
+
"initialize": _dump(initialized),
|
| 77 |
+
"prompts_list": prompts_list,
|
| 78 |
+
"resources_list": resources_list,
|
| 79 |
+
"tools_call": {
|
| 80 |
+
"arguments": TOOL_ARGUMENTS,
|
| 81 |
+
"name": TOOL_NAME,
|
| 82 |
+
"result": _dump(called),
|
| 83 |
+
},
|
| 84 |
+
"tools_list": tools_list,
|
| 85 |
+
}
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
async def _stdio_session() -> dict[str, Any]:
|
| 89 |
+
params = StdioServerParameters(
|
| 90 |
+
command=sys.executable,
|
| 91 |
+
args=["-m", "aureon_public"],
|
| 92 |
+
env=_server_env(),
|
| 93 |
+
cwd=str(Path.cwd()),
|
| 94 |
+
)
|
| 95 |
+
async with stdio_client(params) as (read, write):
|
| 96 |
+
async with ClientSession(read, write) as session:
|
| 97 |
+
return await _exchange(session)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
def _free_port() -> int:
|
| 101 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 102 |
+
sock.bind((_BIND_HOST, 0))
|
| 103 |
+
return int(sock.getsockname()[1])
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def _port_open(port: int) -> bool:
|
| 107 |
+
try:
|
| 108 |
+
with socket.create_connection((_BIND_HOST, port), timeout=0.2):
|
| 109 |
+
return True
|
| 110 |
+
except OSError:
|
| 111 |
+
return False
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def _stop_process_group(proc: subprocess.Popen[str]) -> None:
|
| 115 |
+
if proc.poll() is not None:
|
| 116 |
+
return
|
| 117 |
+
try:
|
| 118 |
+
os.killpg(proc.pid, signal.SIGTERM)
|
| 119 |
+
except ProcessLookupError:
|
| 120 |
+
return
|
| 121 |
+
try:
|
| 122 |
+
proc.wait(timeout=5)
|
| 123 |
+
except subprocess.TimeoutExpired:
|
| 124 |
+
try:
|
| 125 |
+
os.killpg(proc.pid, signal.SIGKILL)
|
| 126 |
+
except ProcessLookupError:
|
| 127 |
+
return
|
| 128 |
+
proc.wait(timeout=5)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _wait_until_listening(proc: subprocess.Popen[str], log_path: Path, port: int) -> None:
|
| 132 |
+
deadline = time.monotonic() + 30
|
| 133 |
+
while time.monotonic() < deadline:
|
| 134 |
+
if proc.poll() is not None:
|
| 135 |
+
raise RuntimeError(_log_tail(log_path) or f"server exited {proc.returncode}")
|
| 136 |
+
if _port_open(port):
|
| 137 |
+
return
|
| 138 |
+
time.sleep(0.1)
|
| 139 |
+
raise TimeoutError(_log_tail(log_path) or f"{_BIND_HOST}:{port} did not accept a connection")
|
| 140 |
+
|
| 141 |
+
|
| 142 |
+
def _log_tail(path: Path) -> str:
|
| 143 |
+
try:
|
| 144 |
+
text = path.read_text(encoding="utf-8", errors="replace")
|
| 145 |
+
except OSError:
|
| 146 |
+
return ""
|
| 147 |
+
return text[-4000:]
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
async def _http_session(port: int) -> dict[str, Any]:
|
| 151 |
+
url = f"http://{_BIND_HOST}:{port}/mcp"
|
| 152 |
+
log_fd, log_name = tempfile.mkstemp(prefix="aureon-public-http-")
|
| 153 |
+
os.close(log_fd)
|
| 154 |
+
log_path = Path(log_name)
|
| 155 |
+
log = log_path.open("w", encoding="utf-8")
|
| 156 |
+
proc = subprocess.Popen(
|
| 157 |
+
[
|
| 158 |
+
sys.executable,
|
| 159 |
+
"-m",
|
| 160 |
+
"aureon_public",
|
| 161 |
+
"--transport",
|
| 162 |
+
"streamable-http",
|
| 163 |
+
"--host",
|
| 164 |
+
_BIND_HOST,
|
| 165 |
+
"--port",
|
| 166 |
+
str(port),
|
| 167 |
+
],
|
| 168 |
+
cwd=str(Path.cwd()),
|
| 169 |
+
env=_server_env(),
|
| 170 |
+
stdout=log,
|
| 171 |
+
stderr=subprocess.STDOUT,
|
| 172 |
+
start_new_session=True,
|
| 173 |
+
text=True,
|
| 174 |
+
)
|
| 175 |
+
try:
|
| 176 |
+
_wait_until_listening(proc, log_path, port)
|
| 177 |
+
last: BaseException | None = None
|
| 178 |
+
for _attempt in range(8):
|
| 179 |
+
if proc.poll() is not None:
|
| 180 |
+
break
|
| 181 |
+
try:
|
| 182 |
+
body = await _exchange_http(url)
|
| 183 |
+
return {
|
| 184 |
+
"host": _BIND_HOST,
|
| 185 |
+
"port": port,
|
| 186 |
+
"url": url,
|
| 187 |
+
**body,
|
| 188 |
+
}
|
| 189 |
+
except Exception as exc: # noqa: BLE001 - the listener can accept TCP before MCP answers
|
| 190 |
+
last = exc
|
| 191 |
+
await asyncio.sleep(0.25)
|
| 192 |
+
tail = _log_tail(log_path)
|
| 193 |
+
raise RuntimeError(f"streamable http session failed: {last}\n{tail}")
|
| 194 |
+
finally:
|
| 195 |
+
log.close()
|
| 196 |
+
_stop_process_group(proc)
|
| 197 |
+
log_path.unlink(missing_ok=True)
|
| 198 |
+
|
| 199 |
+
|
| 200 |
+
async def _exchange_http(url: str) -> dict[str, Any]:
|
| 201 |
+
async with streamable_http_client(url) as (read, write, _get_session_id):
|
| 202 |
+
async with ClientSession(read, write) as session:
|
| 203 |
+
return await _exchange(session)
|
| 204 |
+
|
| 205 |
+
|
| 206 |
+
def _environment() -> dict[str, Any]:
|
| 207 |
+
os.environ["AUREON_PUBLIC_REQUIRE_PIN"] = "1"
|
| 208 |
+
enforce_public_pin()
|
| 209 |
+
import aureon
|
| 210 |
+
|
| 211 |
+
direct = None
|
| 212 |
+
try:
|
| 213 |
+
dist = importlib.metadata.distribution("aureon")
|
| 214 |
+
raw = dist.read_text("direct_url.json")
|
| 215 |
+
direct = json.loads(raw) if raw else None
|
| 216 |
+
except Exception as exc: # noqa: BLE001 - the record should say the pin was not readable
|
| 217 |
+
direct = {"error": type(exc).__name__}
|
| 218 |
+
from aureon_public.measurement_stamp import measurement_stamp
|
| 219 |
+
|
| 220 |
+
return {
|
| 221 |
+
"aureon_direct_url": direct,
|
| 222 |
+
"aureon_file": aureon.__file__,
|
| 223 |
+
"aureon_source": aureon_source(),
|
| 224 |
+
"mcp": importlib.metadata.version("mcp"),
|
| 225 |
+
"python": sys.executable,
|
| 226 |
+
"require_pin": "1",
|
| 227 |
+
**measurement_stamp(),
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
|
| 231 |
+
async def _run(out_path: Path) -> dict[str, Any]:
|
| 232 |
+
os.environ["AUREON_PUBLIC_REQUIRE_PIN"] = "1"
|
| 233 |
+
enforce_public_pin()
|
| 234 |
+
stdio = await _stdio_session()
|
| 235 |
+
http = await _http_session(_free_port())
|
| 236 |
+
record = {
|
| 237 |
+
"environment": _environment(),
|
| 238 |
+
"stdio": stdio,
|
| 239 |
+
"streamable_http": http,
|
| 240 |
+
}
|
| 241 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 242 |
+
out_path.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 243 |
+
return record
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def main(argv: list[str] | None = None) -> None:
|
| 247 |
+
parser = argparse.ArgumentParser(prog="aureon-public-protocol-measure")
|
| 248 |
+
parser.add_argument(
|
| 249 |
+
"--out",
|
| 250 |
+
type=Path,
|
| 251 |
+
default=paths.repo_root() / "measured" / "aureon_public_protocol.json",
|
| 252 |
+
)
|
| 253 |
+
args = parser.parse_args(argv)
|
| 254 |
+
asyncio.run(_run(args.out))
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
if __name__ == "__main__":
|
| 258 |
+
main()
|
quiet.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Keep import banners off stdout. MCP stdio uses stdout for JSON-RPC."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import sys
|
| 6 |
+
from functools import wraps
|
| 7 |
+
from typing import Any, Callable
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def quiet(fn: Callable[..., Any]) -> Callable[..., Any]:
|
| 11 |
+
@wraps(fn)
|
| 12 |
+
def wrapped(*args: Any, **kwargs: Any) -> Any:
|
| 13 |
+
from aureon_public.guard_loader import apply_space_guard
|
| 14 |
+
|
| 15 |
+
apply_space_guard()
|
| 16 |
+
saved = sys.stdout
|
| 17 |
+
sys.stdout = sys.stderr
|
| 18 |
+
try:
|
| 19 |
+
return fn(*args, **kwargs)
|
| 20 |
+
finally:
|
| 21 |
+
sys.stdout = saved
|
| 22 |
+
|
| 23 |
+
return wrapped
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# aureon is pinned to the commit the Spaces and the measured brain run use.
|
| 2 |
+
# mcp==1.30.0,<2 installs 1.30.0 and excludes every 2.x release.
|
| 3 |
+
# MCP 2 renamed FastMCP to MCPServer. Migration is a later decision.
|
| 4 |
+
# The check and the sources are in mcp/aureon_public/COVERAGE_PLAN.md.
|
| 5 |
+
mcp==1.30.0,<2
|
| 6 |
+
numpy>=1.26
|
| 7 |
+
aureon @ git+https://github.com/RA-CONSULTING/Aureon-OS.git@8aa6a2d971cc529484e2a5e261e28afafab4e4f4
|
server.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 4 |
+
|
| 5 |
+
import argparse
|
| 6 |
+
import json
|
| 7 |
+
import logging
|
| 8 |
+
import os
|
| 9 |
+
import sys
|
| 10 |
+
|
| 11 |
+
from mcp.server.fastmcp import FastMCP
|
| 12 |
+
|
| 13 |
+
from aureon_public import body, layers, surfaces, tools
|
| 14 |
+
from aureon_public.guard_loader import PINNED_COMMIT, apply_space_guard, aureon_source
|
| 15 |
+
from aureon_public.text import SERVER_PLAIN
|
| 16 |
+
|
| 17 |
+
SERVER_INSTRUCTIONS = (
|
| 18 |
+
f"{SERVER_PLAIN} "
|
| 19 |
+
"This server is read-only. It does not place orders, read keys, start circulation, "
|
| 20 |
+
"self-code, self-repair, or write the repository or state/."
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def refuse_sweep_environment() -> None:
|
| 25 |
+
"""AUREON_PUBLIC_SWEEP is not a server mode. Setting it must not start the server."""
|
| 26 |
+
|
| 27 |
+
if os.environ.get("AUREON_PUBLIC_SWEEP"):
|
| 28 |
+
raise SystemExit("AUREON_PUBLIC_SWEEP must not be set. The server will not start.")
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def enforce_public_pin(source: dict[str, str] | None = None) -> None:
|
| 32 |
+
"""Refuse to start when public hosting requires the pinned commit.
|
| 33 |
+
|
| 34 |
+
AUREON_PUBLIC_REQUIRE_PIN=1 is unset for local runs. Those runs still
|
| 35 |
+
report aureon_source. Public hosting must set the variable.
|
| 36 |
+
"""
|
| 37 |
+
|
| 38 |
+
if os.environ.get("AUREON_PUBLIC_REQUIRE_PIN") != "1":
|
| 39 |
+
return
|
| 40 |
+
current = aureon_source() if source is None else source
|
| 41 |
+
if current.get("kind") == "pinned" and current.get("commit") == PINNED_COMMIT:
|
| 42 |
+
return
|
| 43 |
+
raise SystemExit(
|
| 44 |
+
"AUREON_PUBLIC_REQUIRE_PIN=1 requires aureon_source kind pinned "
|
| 45 |
+
f"at {PINNED_COMMIT}. This process would use {current}."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
def build_server(host: str = "127.0.0.1", port: int = 8077) -> FastMCP:
|
| 50 |
+
"""Register the milestone-1 tools, resources, and prompts."""
|
| 51 |
+
|
| 52 |
+
refuse_sweep_environment()
|
| 53 |
+
apply_space_guard()
|
| 54 |
+
source = aureon_source()
|
| 55 |
+
instructions = (
|
| 56 |
+
f"{SERVER_INSTRUCTIONS} "
|
| 57 |
+
f"aureon_source={json.dumps(source, sort_keys=True)}"
|
| 58 |
+
)
|
| 59 |
+
server = FastMCP(
|
| 60 |
+
"aureon-public",
|
| 61 |
+
instructions=instructions,
|
| 62 |
+
host=host,
|
| 63 |
+
port=port,
|
| 64 |
+
streamable_http_path="/mcp",
|
| 65 |
+
# JSON responses and no session. GET /mcp is not a long-lived event
|
| 66 |
+
# stream. The HTTP guard answers that GET with 405 so it cannot hold
|
| 67 |
+
# an in-flight call slot.
|
| 68 |
+
json_response=True,
|
| 69 |
+
stateless_http=True,
|
| 70 |
+
)
|
| 71 |
+
for fn in (
|
| 72 |
+
tools.hnc_reality_step,
|
| 73 |
+
tools.hnc_canonical_read,
|
| 74 |
+
tools.hnc_blend_read,
|
| 75 |
+
tools.lambda_engine_step,
|
| 76 |
+
tools.auris_nodes,
|
| 77 |
+
tools.auris_coherence,
|
| 78 |
+
tools.qgita_analyze,
|
| 79 |
+
tools.organism_replay_read,
|
| 80 |
+
tools.organism_catalog,
|
| 81 |
+
*layers.public_layer_tools(),
|
| 82 |
+
body.body_call,
|
| 83 |
+
body.body_surface,
|
| 84 |
+
body.body_depth,
|
| 85 |
+
body.body_registry,
|
| 86 |
+
):
|
| 87 |
+
server.tool()(fn)
|
| 88 |
+
server.resource("aureon://packages", mime_type="application/json")(layers.packages_resource)
|
| 89 |
+
server.resource(
|
| 90 |
+
"aureon://hnc/harmonic-reality/defaults",
|
| 91 |
+
mime_type="application/json",
|
| 92 |
+
)(surfaces.harmonic_reality_defaults)
|
| 93 |
+
server.resource(
|
| 94 |
+
"aureon://hnc/lambda-engine/defaults",
|
| 95 |
+
mime_type="application/json",
|
| 96 |
+
)(surfaces.lambda_engine_defaults)
|
| 97 |
+
server.resource(
|
| 98 |
+
"aureon://hnc/params/code-defaults",
|
| 99 |
+
mime_type="application/json",
|
| 100 |
+
)(surfaces.hnc_params_code_defaults)
|
| 101 |
+
server.resource(
|
| 102 |
+
"aureon://auris/nodes",
|
| 103 |
+
mime_type="application/json",
|
| 104 |
+
description=surfaces.auris_nodes_resource.__doc__,
|
| 105 |
+
)(surfaces.auris_nodes_resource)
|
| 106 |
+
server.resource("aureon://organism/seats", mime_type="application/json")(surfaces.organism_seats_resource)
|
| 107 |
+
server.resource("aureon://organism/nodes", mime_type="application/json")(surfaces.organism_nodes_resource)
|
| 108 |
+
server.resource("aureon://organism/systems", mime_type="application/json")(surfaces.organism_systems_resource)
|
| 109 |
+
server.resource("aureon://body/depth", mime_type="application/json")(body.body_depth)
|
| 110 |
+
server.resource("aureon://body/registry", mime_type="application/json")(body.body_registry)
|
| 111 |
+
server.resource("aureon://holds", mime_type="application/json")(surfaces.holds_resource)
|
| 112 |
+
server.resource("aureon://replay/brain", mime_type="application/json")(surfaces.replay_brain_resource)
|
| 113 |
+
server.resource("aureon://replay/qgita", mime_type="application/json")(surfaces.replay_qgita_resource)
|
| 114 |
+
server.resource("aureon://replay/organism", mime_type="application/json")(surfaces.replay_organism_resource)
|
| 115 |
+
server.resource(
|
| 116 |
+
"aureon://replay/auris",
|
| 117 |
+
mime_type="application/json",
|
| 118 |
+
description=surfaces.replay_auris_resource.__doc__,
|
| 119 |
+
)(surfaces.replay_auris_resource)
|
| 120 |
+
for fn in (
|
| 121 |
+
surfaces.explain_two_lambda_implementations,
|
| 122 |
+
surfaces.explain_auris_four_meanings,
|
| 123 |
+
surfaces.explain_qgita_adapter,
|
| 124 |
+
surfaces.explain_organism_replay,
|
| 125 |
+
):
|
| 126 |
+
server.prompt()(fn)
|
| 127 |
+
return server
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def streamable_http_config(app: object, host: str, port: int):
|
| 131 |
+
"""Uvicorn config that does not rewrite the client from forwarded headers.
|
| 132 |
+
|
| 133 |
+
Uvicorn's default ``proxy_headers`` trusts ``X-Forwarded-For`` from
|
| 134 |
+
127.0.0.1 and replaces ``scope["client"]`` before this process's middleware
|
| 135 |
+
runs. ``proxy_headers=False`` and an empty ``forwarded_allow_ips`` leave
|
| 136 |
+
that header for ``http_guard`` only.
|
| 137 |
+
"""
|
| 138 |
+
|
| 139 |
+
import uvicorn
|
| 140 |
+
|
| 141 |
+
return uvicorn.Config(
|
| 142 |
+
app,
|
| 143 |
+
host=host,
|
| 144 |
+
port=port,
|
| 145 |
+
log_level="warning",
|
| 146 |
+
proxy_headers=False,
|
| 147 |
+
forwarded_allow_ips="",
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
def serve_streamable_http(server: FastMCP, host: str, port: int) -> None:
|
| 152 |
+
"""Listen with the bearer check and the rate, size, and timeout limits."""
|
| 153 |
+
|
| 154 |
+
import uvicorn
|
| 155 |
+
|
| 156 |
+
from aureon_public.http_guard import PublicHttpMiddleware, load_http_limits
|
| 157 |
+
|
| 158 |
+
app = PublicHttpMiddleware(server.streamable_http_app(), load_http_limits())
|
| 159 |
+
uvicorn.Server(streamable_http_config(app, host, port)).run()
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def main(argv: list[str] | None = None) -> None:
|
| 163 |
+
"""stdio, or streamable HTTP when --transport streamable-http is set."""
|
| 164 |
+
|
| 165 |
+
logging.basicConfig(stream=sys.stderr, level=logging.WARNING)
|
| 166 |
+
parser = argparse.ArgumentParser(prog="aureon-public")
|
| 167 |
+
parser.add_argument("--transport", choices=("stdio", "streamable-http"), default="stdio")
|
| 168 |
+
parser.add_argument("--host", default="127.0.0.1")
|
| 169 |
+
parser.add_argument("--port", type=int, default=8077)
|
| 170 |
+
args = parser.parse_args(argv)
|
| 171 |
+
refuse_sweep_environment()
|
| 172 |
+
apply_space_guard()
|
| 173 |
+
enforce_public_pin()
|
| 174 |
+
if args.transport == "stdio":
|
| 175 |
+
build_server().run(transport="stdio")
|
| 176 |
+
return
|
| 177 |
+
from aureon_public.http_guard import resolve_http_bind
|
| 178 |
+
|
| 179 |
+
host = resolve_http_bind(args.host)
|
| 180 |
+
server = build_server(host=host, port=args.port)
|
| 181 |
+
serve_streamable_http(server, host, args.port)
|
| 182 |
+
|
| 183 |
+
|
| 184 |
+
if __name__ == "__main__":
|
| 185 |
+
main()
|
space.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Hugging Face Space entry for aureon-public. This file does not deploy it.
|
| 2 |
+
|
| 3 |
+
The process sets AUREON_PUBLIC_REQUIRE_PIN=1 and AUREON_OBSERVER_MODE=dry_run.
|
| 4 |
+
AUREON_PUBLIC_SWEEP must be unset. The image must not contain an API key.
|
| 5 |
+
Set AUREON_PUBLIC_API_KEY at runtime to require a bearer token. Set
|
| 6 |
+
AUREON_PUBLIC_OPEN=1, with no key, to serve the read-only surface on a
|
| 7 |
+
public bind. With neither, the listener is 127.0.0.1.
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
from __future__ import annotations
|
| 11 |
+
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import sys
|
| 15 |
+
|
| 16 |
+
from aureon_public.http_guard import resolve_http_bind
|
| 17 |
+
from aureon_public.server import (
|
| 18 |
+
build_server,
|
| 19 |
+
enforce_public_pin,
|
| 20 |
+
refuse_sweep_environment,
|
| 21 |
+
serve_streamable_http,
|
| 22 |
+
)
|
| 23 |
+
|
| 24 |
+
_QUEEN_MODULE = "queen/temporal_ground.py"
|
| 25 |
+
_QUEEN_SYMBOL = "compute_zpe_ground"
|
| 26 |
+
_QUEEN_REASON = "plan stage 4 is not open"
|
| 27 |
+
_CLOSED_PACKAGES = ("miner", "accounting", "queen", "exchanges", "trading")
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def prepare_space_environment() -> None:
|
| 31 |
+
"""Pin, dry-run, and the sweep refusal. Does not set a key or OPEN."""
|
| 32 |
+
|
| 33 |
+
if os.environ.get("AUREON_PUBLIC_SWEEP"):
|
| 34 |
+
raise SystemExit("AUREON_PUBLIC_SWEEP must not be set. The server will not start.")
|
| 35 |
+
mode = os.environ.get("AUREON_OBSERVER_MODE", "").strip()
|
| 36 |
+
if mode and mode != "dry_run":
|
| 37 |
+
raise SystemExit("AUREON_OBSERVER_MODE must be dry_run.")
|
| 38 |
+
os.environ["AUREON_OBSERVER_MODE"] = "dry_run"
|
| 39 |
+
os.environ["AUREON_PUBLIC_REQUIRE_PIN"] = "1"
|
| 40 |
+
refuse_sweep_environment()
|
| 41 |
+
enforce_public_pin()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def closed_stage_report() -> dict:
|
| 45 |
+
"""Stage 3 and 4 stay closed inside this entry point."""
|
| 46 |
+
|
| 47 |
+
from aureon_public.body import body_call, package_depth
|
| 48 |
+
|
| 49 |
+
depth = package_depth()
|
| 50 |
+
queen_text = body_call(_QUEEN_MODULE, _QUEEN_SYMBOL)
|
| 51 |
+
queen = json.loads(queen_text)
|
| 52 |
+
packages = {name: depth[name] for name in _CLOSED_PACKAGES}
|
| 53 |
+
reachable = {name: packages[name]["reachable"] for name in _CLOSED_PACKAGES}
|
| 54 |
+
queen_refused = queen.get("called") is not True and queen.get("reason") == _QUEEN_REASON
|
| 55 |
+
closed = all(reachable[name] == 0 for name in _CLOSED_PACKAGES)
|
| 56 |
+
return {
|
| 57 |
+
"closed_packages_reachable": reachable,
|
| 58 |
+
"observer_mode": os.environ.get("AUREON_OBSERVER_MODE", ""),
|
| 59 |
+
"ok": bool(queen_refused and closed and os.environ.get("AUREON_OBSERVER_MODE") == "dry_run"),
|
| 60 |
+
"queen_call": queen,
|
| 61 |
+
"require_pin": os.environ.get("AUREON_PUBLIC_REQUIRE_PIN", ""),
|
| 62 |
+
"sweep_set": bool(os.environ.get("AUREON_PUBLIC_SWEEP")),
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def space_host() -> str:
|
| 67 |
+
"""0.0.0.0 when a key or OPEN=1 allows it. Otherwise 127.0.0.1."""
|
| 68 |
+
|
| 69 |
+
requested = os.environ.get("AUREON_PUBLIC_HOST", "").strip()
|
| 70 |
+
if not requested:
|
| 71 |
+
unlocked = bool(os.environ.get("AUREON_PUBLIC_API_KEY", "").strip())
|
| 72 |
+
unlocked = unlocked or os.environ.get("AUREON_PUBLIC_OPEN") == "1"
|
| 73 |
+
requested = "0.0.0.0" if unlocked else "127.0.0.1"
|
| 74 |
+
return resolve_http_bind(requested)
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
def space_port() -> int:
|
| 78 |
+
raw = os.environ.get("PORT", "7860").strip() or "7860"
|
| 79 |
+
try:
|
| 80 |
+
port = int(raw)
|
| 81 |
+
except ValueError as exc:
|
| 82 |
+
raise SystemExit("PORT must be an integer") from exc
|
| 83 |
+
if port <= 0:
|
| 84 |
+
raise SystemExit("PORT must be an integer")
|
| 85 |
+
return port
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def main(argv: list[str] | None = None) -> None:
|
| 89 |
+
"""Serve Streamable HTTP, or print the closed-stage report for --check."""
|
| 90 |
+
|
| 91 |
+
args = list(sys.argv[1:] if argv is None else argv)
|
| 92 |
+
prepare_space_environment()
|
| 93 |
+
if "--check" in args:
|
| 94 |
+
report = closed_stage_report()
|
| 95 |
+
sys.stdout.write(json.dumps(report, sort_keys=True) + "\n")
|
| 96 |
+
if not report["ok"]:
|
| 97 |
+
raise SystemExit(1)
|
| 98 |
+
return
|
| 99 |
+
host = space_host()
|
| 100 |
+
port = space_port()
|
| 101 |
+
server = build_server(host=host, port=port)
|
| 102 |
+
serve_streamable_http(server, host, port)
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
main()
|
space_measure.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Authenticated session against python -m aureon_public.space.
|
| 2 |
+
|
| 3 |
+
Run from measured/aureon_public_space_run.sh. Do not hand-edit the output.
|
| 4 |
+
Docker is not required. The script records which runtime answered.
|
| 5 |
+
The bearer token is generated in this process and is not written to the record.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import argparse
|
| 11 |
+
import asyncio
|
| 12 |
+
import importlib.metadata
|
| 13 |
+
import json
|
| 14 |
+
import os
|
| 15 |
+
import secrets
|
| 16 |
+
import signal
|
| 17 |
+
import socket
|
| 18 |
+
import subprocess
|
| 19 |
+
import sys
|
| 20 |
+
import tempfile
|
| 21 |
+
import time
|
| 22 |
+
from pathlib import Path
|
| 23 |
+
from typing import Any
|
| 24 |
+
|
| 25 |
+
import httpx
|
| 26 |
+
from mcp import ClientSession
|
| 27 |
+
from mcp.client.streamable_http import streamable_http_client
|
| 28 |
+
|
| 29 |
+
from aureon_public import paths
|
| 30 |
+
from aureon_public.guard_loader import aureon_source
|
| 31 |
+
from aureon_public.server import enforce_public_pin
|
| 32 |
+
|
| 33 |
+
_BIND_HOST = "127.0.0.1"
|
| 34 |
+
_RUNTIME = "local entry point python -m aureon_public.space; Docker is not installed on this machine"
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _dump(model: Any) -> dict[str, Any]:
|
| 38 |
+
return model.model_dump(mode="json", by_alias=True)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def _server_env(api_key: str) -> dict[str, str]:
|
| 42 |
+
env: dict[str, str] = {}
|
| 43 |
+
for key in ("HOME", "LOGNAME", "PATH", "SHELL", "TERM", "USER", "LANG", "TMPDIR"):
|
| 44 |
+
value = os.environ.get(key)
|
| 45 |
+
if value:
|
| 46 |
+
env[key] = value
|
| 47 |
+
env["PYTHONUNBUFFERED"] = "1"
|
| 48 |
+
env["AUREON_PUBLIC_API_KEY"] = api_key
|
| 49 |
+
env["AUREON_PUBLIC_HOST"] = _BIND_HOST
|
| 50 |
+
env.pop("AUREON_PUBLIC_OPEN", None)
|
| 51 |
+
return env
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
def _free_port() -> int:
|
| 55 |
+
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
|
| 56 |
+
sock.bind((_BIND_HOST, 0))
|
| 57 |
+
return int(sock.getsockname()[1])
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def _port_open(port: int) -> bool:
|
| 61 |
+
try:
|
| 62 |
+
with socket.create_connection((_BIND_HOST, port), timeout=0.2):
|
| 63 |
+
return True
|
| 64 |
+
except OSError:
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _stop(proc: subprocess.Popen[str]) -> None:
|
| 69 |
+
if proc.poll() is not None:
|
| 70 |
+
return
|
| 71 |
+
try:
|
| 72 |
+
os.killpg(proc.pid, signal.SIGTERM)
|
| 73 |
+
except ProcessLookupError:
|
| 74 |
+
return
|
| 75 |
+
try:
|
| 76 |
+
proc.wait(timeout=5)
|
| 77 |
+
except subprocess.TimeoutExpired:
|
| 78 |
+
try:
|
| 79 |
+
os.killpg(proc.pid, signal.SIGKILL)
|
| 80 |
+
except ProcessLookupError:
|
| 81 |
+
return
|
| 82 |
+
proc.wait(timeout=5)
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _log_tail(path: Path) -> str:
|
| 86 |
+
try:
|
| 87 |
+
return path.read_text(encoding="utf-8", errors="replace")[-4000:]
|
| 88 |
+
except OSError:
|
| 89 |
+
return ""
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def _entry_check(env: dict[str, str]) -> dict[str, Any]:
|
| 93 |
+
completed = subprocess.run(
|
| 94 |
+
[sys.executable, "-m", "aureon_public.space", "--check"],
|
| 95 |
+
cwd=str(Path.cwd()),
|
| 96 |
+
env=env,
|
| 97 |
+
capture_output=True,
|
| 98 |
+
text=True,
|
| 99 |
+
check=False,
|
| 100 |
+
)
|
| 101 |
+
if completed.returncode != 0:
|
| 102 |
+
raise RuntimeError(completed.stderr[-4000:] or completed.stdout[-4000:])
|
| 103 |
+
return json.loads(completed.stdout)
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
async def _exchange(session: ClientSession) -> dict[str, Any]:
|
| 107 |
+
initialized = await session.initialize()
|
| 108 |
+
tools = _dump(await session.list_tools())
|
| 109 |
+
consonance = await session.call_tool("alignment_consonance_read", {"ratio": 1.0})
|
| 110 |
+
queen = await session.call_tool(
|
| 111 |
+
"body_call",
|
| 112 |
+
{
|
| 113 |
+
"module": "queen/temporal_ground.py",
|
| 114 |
+
"symbol": "compute_zpe_ground",
|
| 115 |
+
"arguments_json": "",
|
| 116 |
+
},
|
| 117 |
+
)
|
| 118 |
+
return {
|
| 119 |
+
"initialize": _dump(initialized),
|
| 120 |
+
"tools_call": [
|
| 121 |
+
{
|
| 122 |
+
"arguments": {"ratio": 1.0},
|
| 123 |
+
"name": "alignment_consonance_read",
|
| 124 |
+
"result": _dump(consonance),
|
| 125 |
+
},
|
| 126 |
+
{
|
| 127 |
+
"arguments": {
|
| 128 |
+
"arguments_json": "",
|
| 129 |
+
"module": "queen/temporal_ground.py",
|
| 130 |
+
"symbol": "compute_zpe_ground",
|
| 131 |
+
},
|
| 132 |
+
"name": "body_call",
|
| 133 |
+
"result": _dump(queen),
|
| 134 |
+
},
|
| 135 |
+
],
|
| 136 |
+
"tools_list": [tools],
|
| 137 |
+
}
|
| 138 |
+
|
| 139 |
+
|
| 140 |
+
async def _session(url: str, api_key: str) -> dict[str, Any]:
|
| 141 |
+
headers = {"Authorization": f"Bearer {api_key}"}
|
| 142 |
+
async with httpx.AsyncClient(headers=headers, timeout=60.0) as client:
|
| 143 |
+
async with streamable_http_client(url, http_client=client) as (read, write, _session_id):
|
| 144 |
+
async with ClientSession(read, write) as session:
|
| 145 |
+
return await _exchange(session)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _environment() -> dict[str, Any]:
|
| 149 |
+
os.environ["AUREON_PUBLIC_REQUIRE_PIN"] = "1"
|
| 150 |
+
enforce_public_pin()
|
| 151 |
+
import aureon
|
| 152 |
+
|
| 153 |
+
direct = None
|
| 154 |
+
try:
|
| 155 |
+
dist = importlib.metadata.distribution("aureon")
|
| 156 |
+
raw = dist.read_text("direct_url.json")
|
| 157 |
+
direct = json.loads(raw) if raw else None
|
| 158 |
+
except Exception as exc: # noqa: BLE001 - the record should say the pin was not readable
|
| 159 |
+
direct = {"error": type(exc).__name__}
|
| 160 |
+
from aureon_public.measurement_stamp import measurement_stamp
|
| 161 |
+
|
| 162 |
+
return {
|
| 163 |
+
"api_key_stored": False,
|
| 164 |
+
"auth": "bearer",
|
| 165 |
+
"aureon_direct_url": direct,
|
| 166 |
+
"aureon_file": aureon.__file__,
|
| 167 |
+
"aureon_source": aureon_source(),
|
| 168 |
+
"docker": "not installed",
|
| 169 |
+
"entry": "python -m aureon_public.space",
|
| 170 |
+
"mcp": importlib.metadata.version("mcp"),
|
| 171 |
+
"observer_mode": "dry_run",
|
| 172 |
+
"open": "unset",
|
| 173 |
+
"python": sys.executable,
|
| 174 |
+
"require_pin": "1",
|
| 175 |
+
"runtime": _RUNTIME,
|
| 176 |
+
**measurement_stamp(),
|
| 177 |
+
}
|
| 178 |
+
|
| 179 |
+
|
| 180 |
+
async def _run(out_path: Path) -> None:
|
| 181 |
+
os.environ["AUREON_PUBLIC_REQUIRE_PIN"] = "1"
|
| 182 |
+
enforce_public_pin()
|
| 183 |
+
api_key = secrets.token_hex(16)
|
| 184 |
+
env = _server_env(api_key)
|
| 185 |
+
entry_check = _entry_check(env)
|
| 186 |
+
port = _free_port()
|
| 187 |
+
env["PORT"] = str(port)
|
| 188 |
+
log_fd, log_name = tempfile.mkstemp(prefix="aureon-public-space-")
|
| 189 |
+
os.close(log_fd)
|
| 190 |
+
log_path = Path(log_name)
|
| 191 |
+
log = log_path.open("w", encoding="utf-8")
|
| 192 |
+
proc = subprocess.Popen(
|
| 193 |
+
[sys.executable, "-m", "aureon_public.space"],
|
| 194 |
+
cwd=str(Path.cwd()),
|
| 195 |
+
env=env,
|
| 196 |
+
stdout=log,
|
| 197 |
+
stderr=subprocess.STDOUT,
|
| 198 |
+
start_new_session=True,
|
| 199 |
+
text=True,
|
| 200 |
+
)
|
| 201 |
+
try:
|
| 202 |
+
deadline = time.monotonic() + 30
|
| 203 |
+
while time.monotonic() < deadline:
|
| 204 |
+
if proc.poll() is not None:
|
| 205 |
+
raise RuntimeError(_log_tail(log_path) or f"space entry exited {proc.returncode}")
|
| 206 |
+
if _port_open(port):
|
| 207 |
+
break
|
| 208 |
+
time.sleep(0.1)
|
| 209 |
+
else:
|
| 210 |
+
raise TimeoutError(_log_tail(log_path) or "space entry did not listen")
|
| 211 |
+
url = f"http://{_BIND_HOST}:{port}/mcp"
|
| 212 |
+
body = await _session(url, api_key)
|
| 213 |
+
record = {
|
| 214 |
+
"entry_check": entry_check,
|
| 215 |
+
"environment": _environment(),
|
| 216 |
+
"streamable_http": {"host": _BIND_HOST, "port": port, "url": url, **body},
|
| 217 |
+
}
|
| 218 |
+
if api_key in json.dumps(record):
|
| 219 |
+
raise RuntimeError("the bearer token was written into the record")
|
| 220 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 221 |
+
out_path.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 222 |
+
finally:
|
| 223 |
+
log.close()
|
| 224 |
+
_stop(proc)
|
| 225 |
+
log_path.unlink(missing_ok=True)
|
| 226 |
+
|
| 227 |
+
|
| 228 |
+
def main(argv: list[str] | None = None) -> None:
|
| 229 |
+
parser = argparse.ArgumentParser(prog="aureon-public-space-measure")
|
| 230 |
+
parser.add_argument(
|
| 231 |
+
"--out",
|
| 232 |
+
type=Path,
|
| 233 |
+
default=paths.repo_root() / "measured" / "aureon_public_space.json",
|
| 234 |
+
)
|
| 235 |
+
args = parser.parse_args(argv)
|
| 236 |
+
asyncio.run(_run(args.out))
|
| 237 |
+
|
| 238 |
+
|
| 239 |
+
if __name__ == "__main__":
|
| 240 |
+
main()
|
stage1_measure.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Stdio session for the remaining stage-1 tools. Writes raw JSON.
|
| 2 |
+
|
| 3 |
+
Run from measured/aureon_public_stage1_run.sh. Do not hand-edit the output.
|
| 4 |
+
"""
|
| 5 |
+
|
| 6 |
+
from __future__ import annotations
|
| 7 |
+
|
| 8 |
+
import argparse
|
| 9 |
+
import asyncio
|
| 10 |
+
import importlib.metadata
|
| 11 |
+
import inspect
|
| 12 |
+
import json
|
| 13 |
+
import os
|
| 14 |
+
import sys
|
| 15 |
+
from pathlib import Path
|
| 16 |
+
from typing import Any
|
| 17 |
+
|
| 18 |
+
from mcp import ClientSession, StdioServerParameters
|
| 19 |
+
from mcp.client.stdio import stdio_client
|
| 20 |
+
|
| 21 |
+
from aureon_public import paths
|
| 22 |
+
from aureon_public.guard_loader import apply_space_guard
|
| 23 |
+
from aureon_public.stage1_rest import TOOLS
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def _text_content(result: Any) -> str:
|
| 27 |
+
parts = []
|
| 28 |
+
for block in result.content:
|
| 29 |
+
text = getattr(block, "text", None)
|
| 30 |
+
if text is not None:
|
| 31 |
+
parts.append(text)
|
| 32 |
+
return "\n".join(parts)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _defaults(fn: Any) -> dict[str, Any]:
|
| 36 |
+
signature = inspect.signature(fn)
|
| 37 |
+
arguments = {}
|
| 38 |
+
for name, param in signature.parameters.items():
|
| 39 |
+
if param.default is inspect.Parameter.empty:
|
| 40 |
+
continue
|
| 41 |
+
if param.default == "":
|
| 42 |
+
continue
|
| 43 |
+
arguments[name] = param.default
|
| 44 |
+
return arguments
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _environment() -> dict[str, Any]:
|
| 48 |
+
apply_space_guard()
|
| 49 |
+
import aureon
|
| 50 |
+
|
| 51 |
+
direct = None
|
| 52 |
+
try:
|
| 53 |
+
dist = importlib.metadata.distribution("aureon")
|
| 54 |
+
raw = dist.read_text("direct_url.json")
|
| 55 |
+
direct = json.loads(raw) if raw else None
|
| 56 |
+
except Exception as exc: # noqa: BLE001 - the record should say the pin was not readable
|
| 57 |
+
direct = {"error": type(exc).__name__}
|
| 58 |
+
from aureon_public.measurement_stamp import measurement_stamp
|
| 59 |
+
|
| 60 |
+
return {
|
| 61 |
+
"aureon_direct_url": direct,
|
| 62 |
+
"aureon_file": aureon.__file__,
|
| 63 |
+
"python": sys.executable,
|
| 64 |
+
**measurement_stamp(),
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
async def _session(out_path: Path) -> dict[str, Any]:
|
| 69 |
+
env = {
|
| 70 |
+
"PATH": os.environ.get("PATH", ""),
|
| 71 |
+
"HOME": os.environ.get("HOME", ""),
|
| 72 |
+
"PYTHONUNBUFFERED": "1",
|
| 73 |
+
}
|
| 74 |
+
params = StdioServerParameters(
|
| 75 |
+
command=sys.executable,
|
| 76 |
+
args=["-m", "aureon_public"],
|
| 77 |
+
env=env,
|
| 78 |
+
cwd=str(Path.cwd()),
|
| 79 |
+
)
|
| 80 |
+
async with stdio_client(params) as (read, write):
|
| 81 |
+
async with ClientSession(read, write) as session:
|
| 82 |
+
await session.initialize()
|
| 83 |
+
calls = {}
|
| 84 |
+
for fn in TOOLS:
|
| 85 |
+
arguments = _defaults(fn)
|
| 86 |
+
result = await session.call_tool(fn.__name__, arguments)
|
| 87 |
+
text = _text_content(result)
|
| 88 |
+
record_call = {
|
| 89 |
+
"arguments": arguments,
|
| 90 |
+
"isError": result.isError,
|
| 91 |
+
"text": text,
|
| 92 |
+
}
|
| 93 |
+
try:
|
| 94 |
+
body = json.loads(text)
|
| 95 |
+
except json.JSONDecodeError:
|
| 96 |
+
body = None
|
| 97 |
+
if isinstance(body, dict) and body.get("input_source"):
|
| 98 |
+
record_call["input_note"] = body.get("input_note")
|
| 99 |
+
record_call["input_source"] = body["input_source"]
|
| 100 |
+
calls[fn.__name__] = record_call
|
| 101 |
+
record = {"calls": calls, "environment": _environment()}
|
| 102 |
+
out_path.parent.mkdir(parents=True, exist_ok=True)
|
| 103 |
+
out_path.write_text(json.dumps(record, indent=2, sort_keys=True) + "\n", encoding="utf-8")
|
| 104 |
+
return record
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def main(argv: list[str] | None = None) -> None:
|
| 108 |
+
parser = argparse.ArgumentParser(prog="aureon-public-stage1-measure")
|
| 109 |
+
parser.add_argument(
|
| 110 |
+
"--out",
|
| 111 |
+
type=Path,
|
| 112 |
+
default=paths.repo_root() / "measured" / "aureon_public_stage1.json",
|
| 113 |
+
)
|
| 114 |
+
args = parser.parse_args(argv)
|
| 115 |
+
asyncio.run(_session(args.out))
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
if __name__ == "__main__":
|
| 119 |
+
main()
|
stage1_rest.py
ADDED
|
@@ -0,0 +1,531 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Remaining stage-1 packages: generated and swarm.
|
| 2 |
+
|
| 3 |
+
Calls go through dispatch. Organism is not a stage-1 tool. Stage 2 is not
|
| 4 |
+
opened. Defaults are labelled. No queen, miner, swarm_motion, brain, or
|
| 5 |
+
network client is imported here.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
from aureon_public.alignment_layer import label_result
|
| 14 |
+
from aureon_public.body import _unavailable, dispatch
|
| 15 |
+
from aureon_public.quiet import quiet
|
| 16 |
+
from aureon_public.tools import _finite
|
| 17 |
+
|
| 18 |
+
# Constants copied from tests/test_druidic_council.py.
|
| 19 |
+
_COUNCIL_SOURCE = "tests/test_druidic_council.py"
|
| 20 |
+
_NOW = 1_786_473_600.0
|
| 21 |
+
_PROPOSAL = "a" * 64
|
| 22 |
+
_PROMPT = "b" * 64
|
| 23 |
+
_HNC = "hnc:live_field:receipt-a"
|
| 24 |
+
_AURIS = "auris:cosmic_state:receipt-b"
|
| 25 |
+
|
| 26 |
+
# Vectors copied from tests/test_swarm_fleadh.py::test_steer_flow_preserves_step_length_exactly.
|
| 27 |
+
_STEER_U = [1.0, 2.0, 0.0, 0.5]
|
| 28 |
+
_STEER_GRAD = [0.3, -0.8, 0.4, 0.0]
|
| 29 |
+
|
| 30 |
+
# Full-strength inputs from tests/generated/test_harmonic_nexus_score_model.py.
|
| 31 |
+
_FULL_INPUTS = {
|
| 32 |
+
"source_strength": 1.0,
|
| 33 |
+
"coherence_agreement": 1.0,
|
| 34 |
+
"repeatability": 1.0,
|
| 35 |
+
"friction_feasibility": 1.0,
|
| 36 |
+
"contradiction_handling": 1.0,
|
| 37 |
+
}
|
| 38 |
+
_BOUNDS_INPUTS = {
|
| 39 |
+
"source_strength": 2.0,
|
| 40 |
+
"coherence_agreement": -1.0,
|
| 41 |
+
"repeatability": 0.5,
|
| 42 |
+
"friction_feasibility": 0.5,
|
| 43 |
+
"contradiction_handling": 0.5,
|
| 44 |
+
}
|
| 45 |
+
_BREAKDOWN_INPUTS = {
|
| 46 |
+
"source_strength": 1.0,
|
| 47 |
+
"coherence_agreement": 0.5,
|
| 48 |
+
"repeatability": 0.25,
|
| 49 |
+
"friction_feasibility": 0.5,
|
| 50 |
+
"contradiction_handling": 1.0,
|
| 51 |
+
}
|
| 52 |
+
|
| 53 |
+
_EXAMPLE = "Fixed example arguments, not a reading."
|
| 54 |
+
_DEFAULTS = "These fields are the dataclass defaults, not a reading."
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def _call(module: str, symbol: str, arguments: dict[str, Any]) -> str:
|
| 58 |
+
return dispatch(module, symbol, arguments, server="public")
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _seat_arguments() -> dict[str, Any]:
|
| 62 |
+
return {
|
| 63 |
+
"seat": "seer",
|
| 64 |
+
"agent_id": "agent-seer",
|
| 65 |
+
"decision": "ACCEPT",
|
| 66 |
+
"reason": "seer verified its discipline boundary",
|
| 67 |
+
"gamma": 0.90,
|
| 68 |
+
"proposal_digest": _PROPOSAL,
|
| 69 |
+
"prompt_digest": _PROMPT,
|
| 70 |
+
"hnc_receipt_id": _HNC,
|
| 71 |
+
"auris_receipt_id": _AURIS,
|
| 72 |
+
"auris_node_receipt_id": "auris:node:seer:receipt",
|
| 73 |
+
"source_timestamp": _NOW - 5.0,
|
| 74 |
+
"derived_at": _NOW - 1.0,
|
| 75 |
+
}
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@quiet
|
| 79 |
+
def generated_default_inputs() -> str:
|
| 80 |
+
"""build_default_inputs. Provenance: cited.
|
| 81 |
+
|
| 82 |
+
The defaults are the function's own conservative inputs from SOURCE_COUNT.
|
| 83 |
+
They are not a live market reading and not a lighthouse reading.
|
| 84 |
+
|
| 85 |
+
Args:
|
| 86 |
+
none: This tool takes no inputs. Label: cited, build_default_inputs.
|
| 87 |
+
"""
|
| 88 |
+
|
| 89 |
+
return label_result(
|
| 90 |
+
_call(
|
| 91 |
+
"generated/research_cinema/harmonic_nexus_score_model.py",
|
| 92 |
+
"build_default_inputs",
|
| 93 |
+
{},
|
| 94 |
+
),
|
| 95 |
+
"tests/generated/test_harmonic_nexus_score_model.py::test_default_inputs_are_conservative",
|
| 96 |
+
"Fixed fixture from that test. The function builds its own defaults. Not a live reading.",
|
| 97 |
+
)
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@quiet
|
| 101 |
+
def generated_normalized() -> str:
|
| 102 |
+
"""HarmonicNexusScoreInputs.normalized on the bounds fixture. Provenance: cited.
|
| 103 |
+
|
| 104 |
+
The five numbers are tests/generated/test_harmonic_nexus_score_model.py
|
| 105 |
+
test_harmonic_nexus_score_bounds_inputs. Not a live reading.
|
| 106 |
+
|
| 107 |
+
Args:
|
| 108 |
+
none: The fixture is fixed. Label: cited.
|
| 109 |
+
"""
|
| 110 |
+
|
| 111 |
+
return label_result(
|
| 112 |
+
_call(
|
| 113 |
+
"generated/research_cinema/harmonic_nexus_score_model.py",
|
| 114 |
+
"HarmonicNexusScoreInputs.normalized",
|
| 115 |
+
{"init": _BOUNDS_INPUTS},
|
| 116 |
+
),
|
| 117 |
+
"tests/generated/test_harmonic_nexus_score_model.py::test_harmonic_nexus_score_bounds_inputs",
|
| 118 |
+
"Fixed fixture from that test. Not a live reading.",
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
@quiet
|
| 123 |
+
def generated_score() -> str:
|
| 124 |
+
"""harmonic_nexus_score on the full-strength fixture. Provenance: cited.
|
| 125 |
+
|
| 126 |
+
The five ones are test_harmonic_nexus_score_full_strength_is_100.
|
| 127 |
+
The score is that fixture, not a live reading. It does not score any
|
| 128 |
+
Aureon or HNC claim, so 100.0 cannot be quoted as evidence.
|
| 129 |
+
|
| 130 |
+
Args:
|
| 131 |
+
none: The fixture is fixed. Label: cited.
|
| 132 |
+
"""
|
| 133 |
+
|
| 134 |
+
return label_result(
|
| 135 |
+
_call(
|
| 136 |
+
"generated/research_cinema/harmonic_nexus_score_model.py",
|
| 137 |
+
"harmonic_nexus_score",
|
| 138 |
+
{"inputs": _FULL_INPUTS},
|
| 139 |
+
),
|
| 140 |
+
"tests/generated/test_harmonic_nexus_score_model.py::test_harmonic_nexus_score_full_strength_is_100",
|
| 141 |
+
(
|
| 142 |
+
"Fixed fixture from that test. Not a live reading. "
|
| 143 |
+
"This does not score any Aureon or HNC claim, so 100.0 cannot be quoted as evidence."
|
| 144 |
+
),
|
| 145 |
+
)
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
@quiet
|
| 149 |
+
def generated_breakdown() -> str:
|
| 150 |
+
"""score_breakdown on the breakdown fixture. Provenance: cited.
|
| 151 |
+
|
| 152 |
+
The inputs are test_harmonic_nexus_breakdown_matches_score. Not a live reading.
|
| 153 |
+
|
| 154 |
+
Args:
|
| 155 |
+
none: The fixture is fixed. Label: cited.
|
| 156 |
+
"""
|
| 157 |
+
|
| 158 |
+
return label_result(
|
| 159 |
+
_call(
|
| 160 |
+
"generated/research_cinema/harmonic_nexus_score_model.py",
|
| 161 |
+
"score_breakdown",
|
| 162 |
+
{"inputs": _BREAKDOWN_INPUTS},
|
| 163 |
+
),
|
| 164 |
+
"tests/generated/test_harmonic_nexus_score_model.py::test_harmonic_nexus_breakdown_matches_score",
|
| 165 |
+
"Fixed fixture from that test. Not a live reading.",
|
| 166 |
+
)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
@quiet
|
| 170 |
+
def swarm_voice_read(gamma: float = 0.80) -> str:
|
| 171 |
+
"""voice_for_gamma. Provenance: cited.
|
| 172 |
+
|
| 173 |
+
The default 0.80 is the ACTIVE row in tests/test_druidic_council.py
|
| 174 |
+
test_voice_bands_use_raw_gamma_without_invented_multiplier.
|
| 175 |
+
It is not a live lighthouse reading.
|
| 176 |
+
|
| 177 |
+
Args:
|
| 178 |
+
gamma: Coherence passed to voice_for_gamma. Label: cited.
|
| 179 |
+
"""
|
| 180 |
+
|
| 181 |
+
number = _finite(gamma)
|
| 182 |
+
if number is None:
|
| 183 |
+
return _unavailable("gamma is missing")
|
| 184 |
+
text = _call("swarm/druidic_council.py", "voice_for_gamma", {"gamma": number})
|
| 185 |
+
if number == 0.80:
|
| 186 |
+
return label_result(
|
| 187 |
+
text,
|
| 188 |
+
"tests/test_druidic_council.py::test_voice_bands_use_raw_gamma_without_invented_multiplier",
|
| 189 |
+
"Fixed fixture from that test. Not a live lighthouse reading.",
|
| 190 |
+
)
|
| 191 |
+
return text
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
@quiet
|
| 195 |
+
def swarm_steer_flow(u_json: str = "", grad_json: str = "") -> str:
|
| 196 |
+
"""steer_flow. Provenance: cited.
|
| 197 |
+
|
| 198 |
+
The default vectors are tests/test_swarm_fleadh.py
|
| 199 |
+
test_steer_flow_preserves_step_length_exactly. Not a live crowd reading.
|
| 200 |
+
|
| 201 |
+
Args:
|
| 202 |
+
u_json: JSON list. Empty uses the test vector. Label: cited.
|
| 203 |
+
grad_json: JSON list. Empty uses the test gradient. Label: cited.
|
| 204 |
+
"""
|
| 205 |
+
|
| 206 |
+
raw_u = u_json.strip() or json.dumps(_STEER_U)
|
| 207 |
+
raw_grad = grad_json.strip() or json.dumps(_STEER_GRAD)
|
| 208 |
+
try:
|
| 209 |
+
flow = json.loads(raw_u)
|
| 210 |
+
grad = json.loads(raw_grad)
|
| 211 |
+
except json.JSONDecodeError:
|
| 212 |
+
return _unavailable("arguments are not JSON")
|
| 213 |
+
if not isinstance(flow, list) or not isinstance(grad, list):
|
| 214 |
+
return _unavailable("u and grad must be lists")
|
| 215 |
+
text = _call("swarm/fleadh.py", "steer_flow", {"u": flow, "grad": grad})
|
| 216 |
+
if flow == _STEER_U and grad == _STEER_GRAD:
|
| 217 |
+
return label_result(
|
| 218 |
+
text,
|
| 219 |
+
"tests/test_swarm_fleadh.py::test_steer_flow_preserves_step_length_exactly",
|
| 220 |
+
"Fixed fixture from that test. Not a live reading.",
|
| 221 |
+
)
|
| 222 |
+
return text
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
@quiet
|
| 226 |
+
def swarm_build_seat() -> str:
|
| 227 |
+
"""build_seat_receipt for the seer seat in the council test. Provenance: cited.
|
| 228 |
+
|
| 229 |
+
The arguments are the seer row of _seat_receipts in tests/test_druidic_council.py.
|
| 230 |
+
The receipt is that fixture, not a live council.
|
| 231 |
+
|
| 232 |
+
Args:
|
| 233 |
+
none: The fixture is fixed. Label: cited.
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
return label_result(
|
| 237 |
+
_call("swarm/druidic_council.py", "build_seat_receipt", _seat_arguments()),
|
| 238 |
+
_COUNCIL_SOURCE,
|
| 239 |
+
"Fixed fixture from tests/test_druidic_council.py. Not a live council.",
|
| 240 |
+
)
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
def _agent_init() -> dict[str, Any]:
|
| 244 |
+
return {"agent_id": "stage1", "role": "scout", "actions": ["hold"]}
|
| 245 |
+
|
| 246 |
+
|
| 247 |
+
@quiet
|
| 248 |
+
def swarm_agent_substrate() -> str:
|
| 249 |
+
"""SwarmAgent.substrate at t 0. Provenance: cited.
|
| 250 |
+
|
| 251 |
+
The agent id, role, and action are fixed example arguments. t is 0.
|
| 252 |
+
The value is that call, not a reading.
|
| 253 |
+
|
| 254 |
+
Args:
|
| 255 |
+
none: The example is fixed. Label: cited.
|
| 256 |
+
"""
|
| 257 |
+
|
| 258 |
+
return label_result(
|
| 259 |
+
_call(
|
| 260 |
+
"swarm/agent.py",
|
| 261 |
+
"SwarmAgent.substrate",
|
| 262 |
+
{"init": _agent_init(), "t": 0.0},
|
| 263 |
+
),
|
| 264 |
+
"aureon.swarm.agent.SwarmAgent.substrate",
|
| 265 |
+
_EXAMPLE,
|
| 266 |
+
)
|
| 267 |
+
|
| 268 |
+
|
| 269 |
+
@quiet
|
| 270 |
+
def swarm_agent_to_dict() -> str:
|
| 271 |
+
"""SwarmAgent.to_dict on the fixed example agent. Provenance: cited.
|
| 272 |
+
|
| 273 |
+
Args:
|
| 274 |
+
none: The example is fixed. Label: cited.
|
| 275 |
+
"""
|
| 276 |
+
|
| 277 |
+
return label_result(
|
| 278 |
+
_call("swarm/agent.py", "SwarmAgent.to_dict", {"init": _agent_init()}),
|
| 279 |
+
"aureon.swarm.agent.SwarmAgent",
|
| 280 |
+
_EXAMPLE,
|
| 281 |
+
)
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
@quiet
|
| 285 |
+
def swarm_agent_propose() -> str:
|
| 286 |
+
"""SwarmAgent.propose with one fixed action vector. Provenance: cited.
|
| 287 |
+
|
| 288 |
+
cluster_gamma is omitted as null, which the method treats as not yet measured.
|
| 289 |
+
Not a live coherence reading.
|
| 290 |
+
|
| 291 |
+
Args:
|
| 292 |
+
none: The example is fixed. Label: cited.
|
| 293 |
+
"""
|
| 294 |
+
|
| 295 |
+
return label_result(
|
| 296 |
+
_call(
|
| 297 |
+
"swarm/agent.py",
|
| 298 |
+
"SwarmAgent.propose",
|
| 299 |
+
{
|
| 300 |
+
"init": _agent_init(),
|
| 301 |
+
"action_vectors": {"hold": [1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]},
|
| 302 |
+
"cluster_gamma": None,
|
| 303 |
+
},
|
| 304 |
+
),
|
| 305 |
+
"aureon.swarm.agent.SwarmAgent.propose",
|
| 306 |
+
_EXAMPLE + " cluster_gamma null means the method's own not-yet-measured branch.",
|
| 307 |
+
)
|
| 308 |
+
|
| 309 |
+
|
| 310 |
+
@quiet
|
| 311 |
+
def swarm_coherence_gamma() -> str:
|
| 312 |
+
"""ClusterCoherence.gamma on an empty window. Provenance: cited.
|
| 313 |
+
|
| 314 |
+
The window 8 is the class default. gamma is None while the window is warming.
|
| 315 |
+
That None is the method's own result, not a reading.
|
| 316 |
+
|
| 317 |
+
Args:
|
| 318 |
+
none: The example is fixed. Label: cited.
|
| 319 |
+
"""
|
| 320 |
+
|
| 321 |
+
return label_result(
|
| 322 |
+
_call(
|
| 323 |
+
"swarm/coherence.py",
|
| 324 |
+
"ClusterCoherence.gamma",
|
| 325 |
+
{"init": {"window": 8}},
|
| 326 |
+
),
|
| 327 |
+
"aureon.swarm.coherence.ClusterCoherence",
|
| 328 |
+
"Window 8 is the class default. An empty window is not a reading.",
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
|
| 332 |
+
@quiet
|
| 333 |
+
def swarm_coherence_to_dict() -> str:
|
| 334 |
+
"""ClusterCoherence.to_dict on an empty window. Provenance: cited.
|
| 335 |
+
|
| 336 |
+
Args:
|
| 337 |
+
none: The example is fixed. Label: cited.
|
| 338 |
+
"""
|
| 339 |
+
|
| 340 |
+
return label_result(
|
| 341 |
+
_call("swarm/coherence.py", "ClusterCoherence.to_dict", {"init": {"window": 8}}),
|
| 342 |
+
"aureon.swarm.coherence.ClusterCoherence",
|
| 343 |
+
"Window 8 is the class default. Not a reading.",
|
| 344 |
+
)
|
| 345 |
+
|
| 346 |
+
|
| 347 |
+
@quiet
|
| 348 |
+
def swarm_echo() -> str:
|
| 349 |
+
"""CausalEchoBus.echo on an empty bus. Provenance: cited.
|
| 350 |
+
|
| 351 |
+
tau 3 is the class default. step 0 has nothing stored, so the method returns
|
| 352 |
+
None. That None is a dark echo, not a reading.
|
| 353 |
+
|
| 354 |
+
Args:
|
| 355 |
+
none: The example is fixed. Label: cited.
|
| 356 |
+
"""
|
| 357 |
+
|
| 358 |
+
return label_result(
|
| 359 |
+
_call("swarm/memory_bus.py", "CausalEchoBus.echo", {"init": {"tau": 3}, "step": 0}),
|
| 360 |
+
"aureon.swarm.memory_bus.CausalEchoBus.echo",
|
| 361 |
+
"tau 3 is the class default. An empty bus is not a reading.",
|
| 362 |
+
)
|
| 363 |
+
|
| 364 |
+
|
| 365 |
+
@quiet
|
| 366 |
+
def swarm_echo_to_dict() -> str:
|
| 367 |
+
"""CausalEchoBus.to_dict on an empty bus. Provenance: cited.
|
| 368 |
+
|
| 369 |
+
Args:
|
| 370 |
+
none: The example is fixed. Label: cited.
|
| 371 |
+
"""
|
| 372 |
+
|
| 373 |
+
return label_result(
|
| 374 |
+
_call("swarm/memory_bus.py", "CausalEchoBus.to_dict", {"init": {"tau": 3}}),
|
| 375 |
+
"aureon.swarm.memory_bus.CausalEchoBus",
|
| 376 |
+
"tau 3 is the class default. Not a reading.",
|
| 377 |
+
)
|
| 378 |
+
|
| 379 |
+
|
| 380 |
+
@quiet
|
| 381 |
+
def swarm_steer_field() -> str:
|
| 382 |
+
"""SteeringField.steer with no heading. Provenance: cited.
|
| 383 |
+
|
| 384 |
+
resistance 0.5 is the class default. heading null is the method's
|
| 385 |
+
no-heading branch. Not a live path.
|
| 386 |
+
|
| 387 |
+
Args:
|
| 388 |
+
none: The example is fixed. Label: cited.
|
| 389 |
+
"""
|
| 390 |
+
|
| 391 |
+
return label_result(
|
| 392 |
+
_call(
|
| 393 |
+
"swarm/steering.py",
|
| 394 |
+
"SteeringField.steer",
|
| 395 |
+
{"init": {"resistance": 0.5}, "proposal": [1.0, 0.0, 0.0], "heading": None},
|
| 396 |
+
),
|
| 397 |
+
"aureon.swarm.steering.SteeringField.steer",
|
| 398 |
+
"resistance 0.5 is the class default. heading null is a fixed example, not a reading.",
|
| 399 |
+
)
|
| 400 |
+
|
| 401 |
+
|
| 402 |
+
@quiet
|
| 403 |
+
def swarm_seat_to_dict() -> str:
|
| 404 |
+
"""SeatReceipt.to_dict on a fixed example payload. Provenance: cited.
|
| 405 |
+
|
| 406 |
+
The payload is one field, not a validated council receipt.
|
| 407 |
+
|
| 408 |
+
Args:
|
| 409 |
+
none: The example is fixed. Label: cited.
|
| 410 |
+
"""
|
| 411 |
+
|
| 412 |
+
return label_result(
|
| 413 |
+
_call(
|
| 414 |
+
"swarm/druidic_council.py",
|
| 415 |
+
"SeatReceipt.to_dict",
|
| 416 |
+
{"init": {"payload": {"seat": "seer"}}},
|
| 417 |
+
),
|
| 418 |
+
"aureon.swarm.druidic_council.SeatReceipt",
|
| 419 |
+
"Fixed example payload. Not a council reading.",
|
| 420 |
+
)
|
| 421 |
+
|
| 422 |
+
|
| 423 |
+
@quiet
|
| 424 |
+
def swarm_council_to_dict() -> str:
|
| 425 |
+
"""CouncilReceipt.to_dict on a fixed example payload. Provenance: cited.
|
| 426 |
+
|
| 427 |
+
The payload is one field, not a validated council receipt.
|
| 428 |
+
|
| 429 |
+
Args:
|
| 430 |
+
none: The example is fixed. Label: cited.
|
| 431 |
+
"""
|
| 432 |
+
|
| 433 |
+
return label_result(
|
| 434 |
+
_call(
|
| 435 |
+
"swarm/druidic_council.py",
|
| 436 |
+
"CouncilReceipt.to_dict",
|
| 437 |
+
{"init": {"payload": {"schema": "example"}}},
|
| 438 |
+
),
|
| 439 |
+
"aureon.swarm.druidic_council.CouncilReceipt",
|
| 440 |
+
"Fixed example payload. Not a council reading.",
|
| 441 |
+
)
|
| 442 |
+
|
| 443 |
+
|
| 444 |
+
@quiet
|
| 445 |
+
def swarm_actualization_to_dict() -> str:
|
| 446 |
+
"""Actualization.to_dict on explicit empty fields. Provenance: cited.
|
| 447 |
+
|
| 448 |
+
actualized false, action null, and canonical_status canonical_dark are fixed
|
| 449 |
+
example arguments. They are not a gate reading.
|
| 450 |
+
|
| 451 |
+
Args:
|
| 452 |
+
none: The example is fixed. Label: cited.
|
| 453 |
+
"""
|
| 454 |
+
|
| 455 |
+
return label_result(
|
| 456 |
+
_call(
|
| 457 |
+
"swarm/queen_gate.py",
|
| 458 |
+
"Actualization.to_dict",
|
| 459 |
+
{
|
| 460 |
+
"init": {
|
| 461 |
+
"actualized": False,
|
| 462 |
+
"action": None,
|
| 463 |
+
"gamma_cluster": None,
|
| 464 |
+
"gamma_effective": None,
|
| 465 |
+
"canonical_status": "canonical_dark",
|
| 466 |
+
}
|
| 467 |
+
},
|
| 468 |
+
),
|
| 469 |
+
"aureon.swarm.queen_gate.Actualization",
|
| 470 |
+
"Fixed example fields. canonical_dark is the gate's own dark-field word. Not a reading.",
|
| 471 |
+
)
|
| 472 |
+
|
| 473 |
+
|
| 474 |
+
# Copied from tests/test_swarm_hive.py::test_agent_keeps_a_normalized_soft_simplex.
|
| 475 |
+
_HIVE_ACTIONS = ["hold", "advance", "retreat"]
|
| 476 |
+
_HIVE_CONTEXT = [0.4, 0.2, -0.1, 0.3, 0.0, 0.1, -0.2, 0.05]
|
| 477 |
+
_HIVE_SOURCE = "tests/test_swarm_hive.py::test_agent_keeps_a_normalized_soft_simplex"
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
@quiet
|
| 481 |
+
def swarm_agent_update() -> str:
|
| 482 |
+
"""SwarmAgent.update on the hive test's first context.
|
| 483 |
+
|
| 484 |
+
The agent id, role, actions, and CONTEXT are that test. The cluster is
|
| 485 |
+
empty and the echo is absent, as the loop starts. The function returns None.
|
| 486 |
+
|
| 487 |
+
Args:
|
| 488 |
+
none: The fixture is fixed. Label: cited.
|
| 489 |
+
"""
|
| 490 |
+
|
| 491 |
+
return label_result(
|
| 492 |
+
_call(
|
| 493 |
+
"swarm/agent.py",
|
| 494 |
+
"SwarmAgent.update",
|
| 495 |
+
{
|
| 496 |
+
"cluster_states": [],
|
| 497 |
+
"context": _HIVE_CONTEXT,
|
| 498 |
+
"echo": None,
|
| 499 |
+
"init": {
|
| 500 |
+
"actions": _HIVE_ACTIONS,
|
| 501 |
+
"agent_id": "a1",
|
| 502 |
+
"role": "research",
|
| 503 |
+
},
|
| 504 |
+
},
|
| 505 |
+
),
|
| 506 |
+
_HIVE_SOURCE,
|
| 507 |
+
"The first update in that test. Empty cluster and no echo. The return is None.",
|
| 508 |
+
)
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
TOOLS: list[Any] = [
|
| 512 |
+
generated_default_inputs,
|
| 513 |
+
generated_normalized,
|
| 514 |
+
generated_score,
|
| 515 |
+
generated_breakdown,
|
| 516 |
+
swarm_voice_read,
|
| 517 |
+
swarm_steer_flow,
|
| 518 |
+
swarm_build_seat,
|
| 519 |
+
swarm_agent_update,
|
| 520 |
+
swarm_agent_substrate,
|
| 521 |
+
swarm_agent_to_dict,
|
| 522 |
+
swarm_agent_propose,
|
| 523 |
+
swarm_coherence_gamma,
|
| 524 |
+
swarm_coherence_to_dict,
|
| 525 |
+
swarm_echo,
|
| 526 |
+
swarm_echo_to_dict,
|
| 527 |
+
swarm_steer_field,
|
| 528 |
+
swarm_seat_to_dict,
|
| 529 |
+
swarm_council_to_dict,
|
| 530 |
+
swarm_actualization_to_dict,
|
| 531 |
+
]
|
stage2_arguments.py
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Real stage-2 call arguments. Values are copied from the repo, not invented.
|
| 2 |
+
|
| 3 |
+
A fixture name is resolved only inside a sweep worker. The public server
|
| 4 |
+
never sets ``AUREON_PUBLIC_SWEEP``, so a client cannot ask for a fixture.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import csv
|
| 10 |
+
import json
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
from typing import Any
|
| 13 |
+
|
| 14 |
+
from aureon_public.paths import repo_root
|
| 15 |
+
|
| 16 |
+
# Copied from tests/test_phenolic_bridge.py.
|
| 17 |
+
PHENOLIC_ANALYSIS: dict[str, Any] = {
|
| 18 |
+
"valid": True,
|
| 19 |
+
"alpha": 0.05,
|
| 20 |
+
"source_path": "x.csv",
|
| 21 |
+
"formats": ["native"],
|
| 22 |
+
"controls": {"positive": {"passed": True}, "negative": {"passed": True}},
|
| 23 |
+
"compounds": {
|
| 24 |
+
"caffeic acid": {
|
| 25 |
+
"test_A_p": 0.003,
|
| 26 |
+
"test_B_p": 0.7,
|
| 27 |
+
"separable": False,
|
| 28 |
+
"n_peaks": 59,
|
| 29 |
+
"sources": ["doi:cga"],
|
| 30 |
+
},
|
| 31 |
+
"luteolin": {
|
| 32 |
+
"test_A_p": 0.005,
|
| 33 |
+
"test_B_p": 0.6,
|
| 34 |
+
"separable": True,
|
| 35 |
+
"n_peaks": 21,
|
| 36 |
+
"sources": ["doi:lut", "COMPUTED GFN2-xTB (theoretical, non-experimental)"],
|
| 37 |
+
},
|
| 38 |
+
"apigenin": {
|
| 39 |
+
"test_A_p": 0.8,
|
| 40 |
+
"test_B_p": 0.9,
|
| 41 |
+
"separable": False,
|
| 42 |
+
"n_peaks": 5,
|
| 43 |
+
"sources": ["doi:api"],
|
| 44 |
+
},
|
| 45 |
+
},
|
| 46 |
+
}
|
| 47 |
+
|
| 48 |
+
# reports/measured/organism.json holds baseline 6 and predicted 7 for the tick
|
| 49 |
+
# field, and organism_proof.TICKS is 8. The history before the held-out tick is
|
| 50 |
+
# 0 through 6.
|
| 51 |
+
TICK_HISTORY = [0, 1, 2, 3, 4, 5, 6]
|
| 52 |
+
|
| 53 |
+
DE440_SOURCE = "data/de440_timeseries.csv"
|
| 54 |
+
DE440_LIMIT = 80
|
| 55 |
+
REPORTS = {
|
| 56 |
+
"auris": "reports/measured/auris_nodes.json",
|
| 57 |
+
"brain": "reports/measured/brain.json",
|
| 58 |
+
"organism": "reports/measured/organism.json",
|
| 59 |
+
"qgita": "reports/measured/qgita_snr.json",
|
| 60 |
+
"self_coder": "reports/measured/self_coder.json",
|
| 61 |
+
}
|
| 62 |
+
|
| 63 |
+
# Reachable entry points the sweep calls, and the public server does not
|
| 64 |
+
# register, because the worker cannot be given the real object as JSON.
|
| 65 |
+
NOT_A_TOOL: dict[tuple[str, str], str] = {
|
| 66 |
+
("decoders/book_of_ur.py", "test_phi_resonance_me"): (
|
| 67 |
+
"The argument is a SumerianMe. That class is not on the constructor "
|
| 68 |
+
"allowlist, so the public server does not build one. The sweep uses "
|
| 69 |
+
"the catalog entry ENSHIP from aureon/decoders/book_of_ur.py."
|
| 70 |
+
),
|
| 71 |
+
("observer/momentum.py", "set_momentum_tracker"): (
|
| 72 |
+
"The argument is a MomentumTracker. The class is not on the constructor "
|
| 73 |
+
"allowlist. The sweep constructs an empty tracker inside the worker."
|
| 74 |
+
),
|
| 75 |
+
("observer/predictor.py", "make_predictor"): (
|
| 76 |
+
"The argument is a HarmonicObserver. The class is not on the constructor "
|
| 77 |
+
"allowlist. The sweep uses the construction in "
|
| 78 |
+
"tests/observer/test_predictor_contract.py: trace_interval_s 1.0 and "
|
| 79 |
+
"publish_to_bus false."
|
| 80 |
+
),
|
| 81 |
+
("observer/wave_predictor.py", "set_wave_predictor"): (
|
| 82 |
+
"The argument is a WavePredictor. The class is not on the constructor "
|
| 83 |
+
"allowlist. The sweep constructs an empty predictor inside the worker."
|
| 84 |
+
),
|
| 85 |
+
("observer/wave_predictor.py", "make_predictor"): (
|
| 86 |
+
"The argument is a WavePredictor. The class is not on the constructor "
|
| 87 |
+
"allowlist. The sweep constructs an empty predictor inside the worker."
|
| 88 |
+
),
|
| 89 |
+
}
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
def de440_lambda_prefix(limit: int = DE440_LIMIT) -> list[float]:
|
| 93 |
+
"""The first Lambda values of the committed DE440 file."""
|
| 94 |
+
|
| 95 |
+
path = repo_root() / DE440_SOURCE
|
| 96 |
+
values: list[float] = []
|
| 97 |
+
with path.open(newline="", encoding="utf-8") as handle:
|
| 98 |
+
for row in csv.DictReader(handle):
|
| 99 |
+
values.append(float(row["Lambda"]))
|
| 100 |
+
if len(values) >= limit:
|
| 101 |
+
break
|
| 102 |
+
return values
|
| 103 |
+
|
| 104 |
+
|
| 105 |
+
def load_report(relative: str) -> dict[str, Any]:
|
| 106 |
+
"""One committed measured report. The file is read, not rewritten."""
|
| 107 |
+
|
| 108 |
+
path = repo_root() / relative
|
| 109 |
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
| 110 |
+
if not isinstance(loaded, dict):
|
| 111 |
+
raise TypeError(relative)
|
| 112 |
+
return loaded
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def attempts_for(module: str, symbol: str) -> list[dict[str, Any]]:
|
| 116 |
+
"""Argument calls for one stage-2 entry point. Empty when no-arg is the call."""
|
| 117 |
+
|
| 118 |
+
key = (module, symbol)
|
| 119 |
+
table: dict[tuple[str, str], list[dict[str, Any]]] = {
|
| 120 |
+
("cognition/phenolic_bridge.py", "summarize_patterns"): [
|
| 121 |
+
{
|
| 122 |
+
"arguments": {"analysis": PHENOLIC_ANALYSIS},
|
| 123 |
+
"label": "phenolic_test_fixture",
|
| 124 |
+
"note": "Fixture dict from the phenolic bridge test. Not a laboratory result.",
|
| 125 |
+
"source": "tests/test_phenolic_bridge.py",
|
| 126 |
+
}
|
| 127 |
+
],
|
| 128 |
+
("decoders/book_of_ur.py", "test_phi_resonance_me"): [
|
| 129 |
+
{
|
| 130 |
+
"fixture": "sumerian_enship",
|
| 131 |
+
"label": "enship",
|
| 132 |
+
"note": "First foundation me in the module catalog.",
|
| 133 |
+
"source": "aureon/decoders/book_of_ur.py",
|
| 134 |
+
}
|
| 135 |
+
],
|
| 136 |
+
("evaluation/auris_node_eval.py", "render_auris_markdown"): [_report_attempt("auris")],
|
| 137 |
+
("evaluation/brain_proof.py", "render_brain_markdown"): [_report_attempt("brain")],
|
| 138 |
+
("evaluation/measured_proof.py", "self_coder_report"): [
|
| 139 |
+
{
|
| 140 |
+
"fixture": "repo_root_path",
|
| 141 |
+
"label": "checkout_root",
|
| 142 |
+
"note": "The checkout path. This calls the harness.",
|
| 143 |
+
"source": "aureon/evaluation/measured_proof.py",
|
| 144 |
+
}
|
| 145 |
+
],
|
| 146 |
+
("evaluation/measured_proof.py", "render_self_coder_markdown"): [_report_attempt("self_coder")],
|
| 147 |
+
("evaluation/organism_proof.py", "predict_next"): [
|
| 148 |
+
{
|
| 149 |
+
"arguments": {"values": TICK_HISTORY},
|
| 150 |
+
"label": "tick_history",
|
| 151 |
+
"note": "Ticks 0 through 6. The committed organism report's tick baseline is 6 and the held-out tick is 7.",
|
| 152 |
+
"source": "reports/measured/organism.json",
|
| 153 |
+
}
|
| 154 |
+
],
|
| 155 |
+
("evaluation/organism_proof.py", "render_organism_markdown"): [_report_attempt("organism")],
|
| 156 |
+
("evaluation/qgita_snr_benchmark.py", "render_qgita_markdown"): [_report_attempt("qgita")],
|
| 157 |
+
("gates/benchmark.py", "build_report"): [
|
| 158 |
+
{
|
| 159 |
+
"arguments": {"checks": []},
|
| 160 |
+
"label": "empty_checks",
|
| 161 |
+
"note": "The function's own comment says an empty check list must not pass. The panel is not convened.",
|
| 162 |
+
"source": "aureon/gates/benchmark.py",
|
| 163 |
+
}
|
| 164 |
+
],
|
| 165 |
+
("gates/panel.py", "ungrounded_nodes"): [
|
| 166 |
+
{
|
| 167 |
+
"arguments": {"grounded_slices": []},
|
| 168 |
+
"label": "empty_grounded_set",
|
| 169 |
+
"note": "The empty set in tests/gates/test_switchboard.py. Nothing was measured.",
|
| 170 |
+
"source": "tests/gates/test_switchboard.py",
|
| 171 |
+
}
|
| 172 |
+
],
|
| 173 |
+
("gates/switchboard.py", "is_human_held"): [
|
| 174 |
+
{
|
| 175 |
+
"arguments": {"action": "draft"},
|
| 176 |
+
"label": "draft",
|
| 177 |
+
"note": "An ordinary action in the switchboard test.",
|
| 178 |
+
"source": "tests/gates/test_switchboard.py",
|
| 179 |
+
},
|
| 180 |
+
{
|
| 181 |
+
"arguments": {"action": "submit"},
|
| 182 |
+
"label": "submit",
|
| 183 |
+
"note": "A human-held verb in the switchboard test.",
|
| 184 |
+
"source": "tests/gates/test_switchboard.py",
|
| 185 |
+
},
|
| 186 |
+
],
|
| 187 |
+
("observer/fitter.py", "fit_tanh"): [_de440_attempt()],
|
| 188 |
+
("observer/fitter.py", "fit_full"): [_de440_attempt()],
|
| 189 |
+
("observer/live_data_policy.py", "fallback_marker"): [
|
| 190 |
+
{
|
| 191 |
+
"arguments": {"source": "b70_probe", "when": 123.0},
|
| 192 |
+
"label": "b70_probe",
|
| 193 |
+
"note": "The marker call in tests/benchmarks/benchmark_aureon_scope.py. when is 123.0 in that test.",
|
| 194 |
+
"source": "tests/benchmarks/benchmark_aureon_scope.py",
|
| 195 |
+
}
|
| 196 |
+
],
|
| 197 |
+
("observer/momentum.py", "set_momentum_tracker"): [
|
| 198 |
+
{
|
| 199 |
+
"fixture": "empty_momentum_tracker",
|
| 200 |
+
"label": "empty_tracker",
|
| 201 |
+
"note": "MomentumTracker() takes no readings.",
|
| 202 |
+
"source": "aureon/observer/momentum.py",
|
| 203 |
+
}
|
| 204 |
+
],
|
| 205 |
+
("observer/predictor.py", "make_predictor"): [
|
| 206 |
+
{
|
| 207 |
+
"fixture": "empty_harmonic_observer",
|
| 208 |
+
"label": "unpublished_observer",
|
| 209 |
+
"note": "The test constructs the observer with publish_to_bus false.",
|
| 210 |
+
"source": "tests/observer/test_predictor_contract.py",
|
| 211 |
+
}
|
| 212 |
+
],
|
| 213 |
+
("observer/real_data_contract.py", "make_test_fixture_metric"): [
|
| 214 |
+
{
|
| 215 |
+
"arguments": {"name": "fixture.metric", "value": 1},
|
| 216 |
+
"label": "fixture_metric",
|
| 217 |
+
"note": "The name and value in tests/test_real_data_contract.py. The envelope is a test fixture.",
|
| 218 |
+
"source": "tests/test_real_data_contract.py",
|
| 219 |
+
}
|
| 220 |
+
],
|
| 221 |
+
("observer/real_data_contract.py", "summarize_truth_status"): [
|
| 222 |
+
{
|
| 223 |
+
"arguments": {"metrics": [{"truth_status": "test_fixture"}]},
|
| 224 |
+
"label": "one_test_fixture_status",
|
| 225 |
+
"note": "truth_status test_fixture is the status make_test_fixture_metric writes. This is one status, not a census of sources.",
|
| 226 |
+
"source": "aureon/observer/real_data_contract.py",
|
| 227 |
+
}
|
| 228 |
+
],
|
| 229 |
+
("observer/wave_predictor.py", "set_wave_predictor"): [
|
| 230 |
+
{
|
| 231 |
+
"fixture": "empty_wave_for_set",
|
| 232 |
+
"label": "empty_predictor",
|
| 233 |
+
"note": "WavePredictor() takes no trace.",
|
| 234 |
+
"source": "aureon/observer/wave_predictor.py",
|
| 235 |
+
}
|
| 236 |
+
],
|
| 237 |
+
("observer/wave_predictor.py", "make_predictor"): [
|
| 238 |
+
{
|
| 239 |
+
"fixture": "empty_wave_for_make",
|
| 240 |
+
"label": "empty_predictor",
|
| 241 |
+
"note": "WavePredictor() takes no trace.",
|
| 242 |
+
"source": "aureon/observer/wave_predictor.py",
|
| 243 |
+
}
|
| 244 |
+
],
|
| 245 |
+
("s51/aureon_51_compound.py", "summarize_compounding"): [
|
| 246 |
+
{
|
| 247 |
+
"arguments": {"receipts": []},
|
| 248 |
+
"label": "no_receipts",
|
| 249 |
+
"note": "The module calls summarize_compounding with an empty list when run as a script. The result is no_data. No trade is added.",
|
| 250 |
+
"source": "aureon/s51/aureon_51_compound.py",
|
| 251 |
+
}
|
| 252 |
+
],
|
| 253 |
+
}
|
| 254 |
+
return table.get(key, [])
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
def _report_attempt(name: str) -> dict[str, Any]:
|
| 258 |
+
relative = REPORTS[name]
|
| 259 |
+
return {
|
| 260 |
+
"fixture": f"report:{relative}",
|
| 261 |
+
"label": relative,
|
| 262 |
+
"note": "The committed measured report. This call formats that file. It does not rerun the proof.",
|
| 263 |
+
"source": relative,
|
| 264 |
+
}
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def _de440_attempt() -> dict[str, Any]:
|
| 268 |
+
return {
|
| 269 |
+
"fixture": "de440_lambda_prefix",
|
| 270 |
+
"label": "de440_lambda_prefix",
|
| 271 |
+
"note": f"The first {DE440_LIMIT} Lambda values of {DE440_SOURCE}. A curve fit of that prefix, not a live trace.",
|
| 272 |
+
"source": DE440_SOURCE,
|
| 273 |
+
}
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
def resolve_fixture(name: str) -> dict[str, Any]:
|
| 277 |
+
"""Build one real argument inside the sweep worker."""
|
| 278 |
+
|
| 279 |
+
if name == "repo_root_path":
|
| 280 |
+
return {"root": repo_root()}
|
| 281 |
+
if name == "sumerian_enship":
|
| 282 |
+
from aureon.decoders.book_of_ur import _ME_CATALOG
|
| 283 |
+
|
| 284 |
+
me = next(item for item in _ME_CATALOG if item.id == "ENSHIP")
|
| 285 |
+
return {"me": me}
|
| 286 |
+
if name == "empty_harmonic_observer":
|
| 287 |
+
from aureon.observer.harmonic_observer import HarmonicObserver
|
| 288 |
+
|
| 289 |
+
return {"observer": HarmonicObserver(trace_interval_s=1.0, publish_to_bus=False)}
|
| 290 |
+
if name == "empty_momentum_tracker":
|
| 291 |
+
from aureon.observer.momentum import MomentumTracker
|
| 292 |
+
|
| 293 |
+
return {"t": MomentumTracker()}
|
| 294 |
+
if name == "empty_wave_for_set":
|
| 295 |
+
from aureon.observer.wave_predictor import WavePredictor
|
| 296 |
+
|
| 297 |
+
return {"p": WavePredictor()}
|
| 298 |
+
if name == "empty_wave_for_make":
|
| 299 |
+
from aureon.observer.wave_predictor import WavePredictor
|
| 300 |
+
|
| 301 |
+
return {"predictor": WavePredictor()}
|
| 302 |
+
if name == "de440_lambda_prefix":
|
| 303 |
+
return {"lambda_values": de440_lambda_prefix()}
|
| 304 |
+
if name.startswith("report:"):
|
| 305 |
+
return {"report": load_report(name.split(":", 1)[1])}
|
| 306 |
+
raise KeyError(name)
|
stage2_import_sweep.py
ADDED
|
@@ -0,0 +1,226 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Sweep plan-stage-2 modules in isolated processes with sockets blocked.
|
| 2 |
+
|
| 3 |
+
A module is refused when its import loads ``inhouse_ai``, ``ollama_config``,
|
| 4 |
+
or an HTTP client, or when the import opens a connection, starts a process,
|
| 5 |
+
or writes outside the sandbox. The public server reads the committed record
|
| 6 |
+
and refuses those modules before a worker starts.
|
| 7 |
+
|
| 8 |
+
bash measured/aureon_public_stage2_sweep.sh
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
from __future__ import annotations
|
| 12 |
+
|
| 13 |
+
import argparse
|
| 14 |
+
import json
|
| 15 |
+
import os
|
| 16 |
+
import subprocess
|
| 17 |
+
import sys
|
| 18 |
+
from collections import defaultdict
|
| 19 |
+
from pathlib import Path
|
| 20 |
+
from typing import Any
|
| 21 |
+
|
| 22 |
+
ADAPTER_MARKERS = ("inhouse_ai", "ollama_config")
|
| 23 |
+
# urllib.parse is not a client. urllib.request and http.client are.
|
| 24 |
+
HTTP_ROOTS = frozenset(
|
| 25 |
+
{"requests", "httpx", "urllib3", "aiohttp", "websocket", "websockets"}
|
| 26 |
+
)
|
| 27 |
+
HTTP_PREFIXES = (
|
| 28 |
+
"http.client",
|
| 29 |
+
"urllib.request",
|
| 30 |
+
"urllib.response",
|
| 31 |
+
)
|
| 32 |
+
RECORD_NAME = "aureon_public_stage2_imports.json"
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def is_http_client(name: str) -> bool:
|
| 36 |
+
"""True when ``name`` is an HTTP client module or a submodule of one."""
|
| 37 |
+
|
| 38 |
+
root = name.split(".", 1)[0]
|
| 39 |
+
if root in HTTP_ROOTS:
|
| 40 |
+
return True
|
| 41 |
+
return any(name == prefix or name.startswith(prefix + ".") for prefix in HTTP_PREFIXES)
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def import_refusal(
|
| 45 |
+
bad: list[str],
|
| 46 |
+
socket_attempts: list[str],
|
| 47 |
+
processes: list[str] | None = None,
|
| 48 |
+
writes: list[str] | None = None,
|
| 49 |
+
) -> str | None:
|
| 50 |
+
"""Why an import is refused. None when the import is clean."""
|
| 51 |
+
|
| 52 |
+
if socket_attempts or any(
|
| 53 |
+
any(marker in name for marker in ADAPTER_MARKERS) or is_http_client(name) for name in bad
|
| 54 |
+
):
|
| 55 |
+
return "module import loads an adapter or http client"
|
| 56 |
+
if processes:
|
| 57 |
+
return "module import starts a process"
|
| 58 |
+
if writes:
|
| 59 |
+
return "module import writes outside the sandbox"
|
| 60 |
+
return None
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def import_is_refused(
|
| 64 |
+
bad: list[str],
|
| 65 |
+
socket_attempts: list[str],
|
| 66 |
+
processes: list[str] | None = None,
|
| 67 |
+
writes: list[str] | None = None,
|
| 68 |
+
) -> bool:
|
| 69 |
+
"""The rule the measured record and body_call share."""
|
| 70 |
+
|
| 71 |
+
return import_refusal(bad, socket_attempts, processes, writes) is not None
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _dotted(module: str) -> str:
|
| 75 |
+
stem = module[:-3] if module.endswith(".py") else module
|
| 76 |
+
return "aureon." + stem.replace("/", ".")
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def child_main(module: str) -> None:
|
| 80 |
+
"""Import one module. Stdout is one JSON object."""
|
| 81 |
+
|
| 82 |
+
from aureon_public.sweep_guard import declare_sandbox, install_sweep_guard, snapshot
|
| 83 |
+
|
| 84 |
+
os.environ["AUREON_PUBLIC_SWEEP"] = "1"
|
| 85 |
+
declare_sandbox()
|
| 86 |
+
install_sweep_guard()
|
| 87 |
+
error = None
|
| 88 |
+
try:
|
| 89 |
+
from aureon_public.call_worker import _load
|
| 90 |
+
|
| 91 |
+
_load(_dotted(module), module)
|
| 92 |
+
except Exception as exc:
|
| 93 |
+
error = f"{type(exc).__name__}: {exc}"[:240]
|
| 94 |
+
import sys as _sys
|
| 95 |
+
|
| 96 |
+
bad = sorted(
|
| 97 |
+
name
|
| 98 |
+
for name in _sys.modules
|
| 99 |
+
if any(marker in name for marker in ADAPTER_MARKERS) or is_http_client(name)
|
| 100 |
+
)
|
| 101 |
+
snap = snapshot()
|
| 102 |
+
json.dump(
|
| 103 |
+
{
|
| 104 |
+
"bad": bad,
|
| 105 |
+
"error": error,
|
| 106 |
+
"process": snap["processes"],
|
| 107 |
+
"socket": snap["sockets"],
|
| 108 |
+
"writes": snap["writes"],
|
| 109 |
+
},
|
| 110 |
+
sys.stdout,
|
| 111 |
+
)
|
| 112 |
+
|
| 113 |
+
|
| 114 |
+
def stage2_modules() -> list[tuple[str, str]]:
|
| 115 |
+
"""Public function and method modules in plan stage 2."""
|
| 116 |
+
|
| 117 |
+
from aureon_public.body import _inventory
|
| 118 |
+
from aureon_public.coverage_plan import safety_category, stage_for
|
| 119 |
+
|
| 120 |
+
rows, _index = _inventory()
|
| 121 |
+
categories: dict[str, set[str]] = defaultdict(set)
|
| 122 |
+
for row in rows:
|
| 123 |
+
categories[str(row["package"])].add(safety_category(str(row.get("safety") or "")))
|
| 124 |
+
found: dict[str, str] = {}
|
| 125 |
+
for row in rows:
|
| 126 |
+
package = str(row["package"])
|
| 127 |
+
if stage_for(package, categories[package]) != 2:
|
| 128 |
+
continue
|
| 129 |
+
if row["server"] != "public" or row["kind"] not in {"function", "method"}:
|
| 130 |
+
continue
|
| 131 |
+
found.setdefault(str(row["module"]), package)
|
| 132 |
+
return sorted(found.items())
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
def _one(module: str, timeout: float) -> dict[str, Any]:
|
| 136 |
+
completed = subprocess.run(
|
| 137 |
+
[sys.executable, "-m", "aureon_public.stage2_import_sweep", "--module", module],
|
| 138 |
+
cwd=os.environ.get("TMPDIR") or "/tmp",
|
| 139 |
+
capture_output=True,
|
| 140 |
+
text=True,
|
| 141 |
+
timeout=timeout,
|
| 142 |
+
check=False,
|
| 143 |
+
)
|
| 144 |
+
if completed.returncode != 0 and not completed.stdout.strip():
|
| 145 |
+
return {
|
| 146 |
+
"bad": [],
|
| 147 |
+
"error": f"sweep exited {completed.returncode}",
|
| 148 |
+
"socket": [],
|
| 149 |
+
"stderr": completed.stderr[-400:],
|
| 150 |
+
}
|
| 151 |
+
try:
|
| 152 |
+
payload = json.loads(completed.stdout)
|
| 153 |
+
except json.JSONDecodeError:
|
| 154 |
+
return {
|
| 155 |
+
"bad": [],
|
| 156 |
+
"error": "sweep result was not JSON",
|
| 157 |
+
"socket": [],
|
| 158 |
+
"stderr": (completed.stderr or completed.stdout)[-400:],
|
| 159 |
+
}
|
| 160 |
+
if not isinstance(payload, dict):
|
| 161 |
+
return {"bad": [], "error": "sweep result was not an object", "socket": []}
|
| 162 |
+
return payload
|
| 163 |
+
|
| 164 |
+
|
| 165 |
+
def build_record(timeout: float) -> dict[str, Any]:
|
| 166 |
+
from aureon_public.guard_loader import aureon_source
|
| 167 |
+
from aureon_public.measurement_stamp import measurement_stamp
|
| 168 |
+
from aureon_public.sweep_layout import layout_record
|
| 169 |
+
|
| 170 |
+
source = aureon_source()
|
| 171 |
+
stamp = measurement_stamp()
|
| 172 |
+
modules = []
|
| 173 |
+
for module, package in stage2_modules():
|
| 174 |
+
print(module, file=sys.stderr)
|
| 175 |
+
payload = _one(module, timeout)
|
| 176 |
+
bad = [str(item) for item in payload.get("bad") or []]
|
| 177 |
+
sockets = [str(item) for item in payload.get("socket") or []]
|
| 178 |
+
processes = [str(item) for item in payload.get("process") or []]
|
| 179 |
+
writes = [str(item) for item in payload.get("writes") or []]
|
| 180 |
+
refusal = import_refusal(bad, sockets, processes, writes)
|
| 181 |
+
modules.append(
|
| 182 |
+
{
|
| 183 |
+
"bad": bad,
|
| 184 |
+
"error": payload.get("error"),
|
| 185 |
+
"module": module,
|
| 186 |
+
"package": package,
|
| 187 |
+
"process": processes,
|
| 188 |
+
"refusal": refusal,
|
| 189 |
+
"refused": refusal is not None,
|
| 190 |
+
"socket": bool(sockets),
|
| 191 |
+
"writes": writes,
|
| 192 |
+
}
|
| 193 |
+
)
|
| 194 |
+
return {
|
| 195 |
+
"adapters": list(ADAPTER_MARKERS),
|
| 196 |
+
"aureon_source": source,
|
| 197 |
+
"http_clients": sorted(HTTP_ROOTS | set(HTTP_PREFIXES)),
|
| 198 |
+
"layout": layout_record(),
|
| 199 |
+
"modules": modules,
|
| 200 |
+
"processes": "blocked",
|
| 201 |
+
"sockets": "blocked",
|
| 202 |
+
"writes": "outside sandbox blocked",
|
| 203 |
+
**stamp,
|
| 204 |
+
}
|
| 205 |
+
|
| 206 |
+
|
| 207 |
+
def main(argv: list[str] | None = None) -> None:
|
| 208 |
+
parser = argparse.ArgumentParser(prog="aureon-public-stage2-import-sweep")
|
| 209 |
+
parser.add_argument("--module", help="import one module and print JSON")
|
| 210 |
+
parser.add_argument("--out", type=Path)
|
| 211 |
+
parser.add_argument("--timeout", type=float, default=45.0)
|
| 212 |
+
args = parser.parse_args(argv)
|
| 213 |
+
if args.module:
|
| 214 |
+
child_main(args.module)
|
| 215 |
+
return
|
| 216 |
+
record = build_record(args.timeout)
|
| 217 |
+
text = json.dumps(record, indent=2, sort_keys=True) + "\n"
|
| 218 |
+
if args.out is None:
|
| 219 |
+
sys.stdout.write(text)
|
| 220 |
+
return
|
| 221 |
+
args.out.parent.mkdir(parents=True, exist_ok=True)
|
| 222 |
+
args.out.write_text(text, encoding="utf-8")
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
if __name__ == "__main__":
|
| 226 |
+
main()
|
stage2_layer.py
ADDED
|
@@ -0,0 +1,782 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Stage-2 tools. Each call goes through dispatch. Inputs are files or tests in the repo.
|
| 2 |
+
|
| 3 |
+
No queen, miner, swarm_motion, in-house adapter, or network client is imported
|
| 4 |
+
here. A number in the result is the function's result on the named input.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
from typing import Any
|
| 10 |
+
|
| 11 |
+
from aureon_public.alignment_layer import label_result
|
| 12 |
+
from aureon_public.body import _unavailable, dispatch
|
| 13 |
+
from aureon_public.quiet import quiet
|
| 14 |
+
from aureon_public.stage2_arguments import (
|
| 15 |
+
DE440_SOURCE,
|
| 16 |
+
PHENOLIC_ANALYSIS,
|
| 17 |
+
REPORTS,
|
| 18 |
+
TICK_HISTORY,
|
| 19 |
+
de440_lambda_prefix,
|
| 20 |
+
load_report,
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
_MODE = "aureon/observer/production_mode.py"
|
| 24 |
+
# The public worker sets AUREON_OBSERVER_MODE=dry_run. The code default is a
|
| 25 |
+
# cited source line and is not the value these tools return.
|
| 26 |
+
_MODE_SOURCE = "aureon/observer/production_mode.py"
|
| 27 |
+
_MODE_CITED = (
|
| 28 |
+
"The worker sets AUREON_OBSERVER_MODE=dry_run. "
|
| 29 |
+
"Cited source, aureon/observer/production_mode.py: `DEFAULT_MODE = ObserverMode.LIVE`. "
|
| 30 |
+
"That line is not this result."
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _call(module: str, symbol: str, arguments: dict[str, Any]) -> str:
|
| 35 |
+
return dispatch(module, symbol, arguments, server="public", timeout=30.0)
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@quiet
|
| 39 |
+
def stage2_summarize_patterns() -> str:
|
| 40 |
+
"""Distil the phenolic bridge test's analysis dict.
|
| 41 |
+
|
| 42 |
+
The dict is tests/test_phenolic_bridge.py. It is not a laboratory result
|
| 43 |
+
from this server. The result names separable compounds and provenance counts
|
| 44 |
+
in that dict.
|
| 45 |
+
|
| 46 |
+
Args:
|
| 47 |
+
none: The fixture is fixed. Label: cited.
|
| 48 |
+
"""
|
| 49 |
+
|
| 50 |
+
return label_result(
|
| 51 |
+
_call(
|
| 52 |
+
"cognition/phenolic_bridge.py",
|
| 53 |
+
"summarize_patterns",
|
| 54 |
+
{"analysis": PHENOLIC_ANALYSIS},
|
| 55 |
+
),
|
| 56 |
+
"tests/test_phenolic_bridge.py",
|
| 57 |
+
"Fixture dict from that test. Not a laboratory result.",
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
@quiet
|
| 62 |
+
def stage2_sumerian_decoder() -> str:
|
| 63 |
+
"""Build the Book of Ur decoder from the me catalog in that file.
|
| 64 |
+
|
| 65 |
+
The catalog is the module's own table. This is not a live geographic reading.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
none: The catalog is in the module. Label: cited.
|
| 69 |
+
"""
|
| 70 |
+
|
| 71 |
+
return label_result(
|
| 72 |
+
_call("decoders/book_of_ur.py", "get_sumerian_decoder", {}),
|
| 73 |
+
"aureon/decoders/book_of_ur.py",
|
| 74 |
+
"The decoder is built from the me catalog in that file.",
|
| 75 |
+
)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
@quiet
|
| 79 |
+
def stage2_sumerian_vector() -> str:
|
| 80 |
+
"""Return the bearing the Sumerian decoder computes from the Ur coordinates in that file.
|
| 81 |
+
|
| 82 |
+
Args:
|
| 83 |
+
none: The coordinates are in the module. Label: cited.
|
| 84 |
+
"""
|
| 85 |
+
|
| 86 |
+
return label_result(
|
| 87 |
+
_call("decoders/book_of_ur.py", "get_sumerian_geographic_vector", {}),
|
| 88 |
+
"aureon/decoders/book_of_ur.py",
|
| 89 |
+
"The vector is computed from the coordinates in that file.",
|
| 90 |
+
)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
@quiet
|
| 94 |
+
def stage2_iching_decoder() -> str:
|
| 95 |
+
"""Build the I Ching decoder from the hexagram table in that file.
|
| 96 |
+
|
| 97 |
+
Args:
|
| 98 |
+
none: The table is in the module. Label: cited.
|
| 99 |
+
"""
|
| 100 |
+
|
| 101 |
+
return label_result(
|
| 102 |
+
_call("decoders/iching_decoder.py", "get_iching_decoder", {}),
|
| 103 |
+
"aureon/decoders/iching_decoder.py",
|
| 104 |
+
"The decoder is built from the hexagram table in that file.",
|
| 105 |
+
)
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
@quiet
|
| 109 |
+
def stage2_iching_vector() -> str:
|
| 110 |
+
"""Return the geographic vector the I Ching decoder computes from its own table.
|
| 111 |
+
|
| 112 |
+
Args:
|
| 113 |
+
none: The table is in the module. Label: cited.
|
| 114 |
+
"""
|
| 115 |
+
|
| 116 |
+
return label_result(
|
| 117 |
+
_call("decoders/iching_decoder.py", "get_iching_geographic_vector", {}),
|
| 118 |
+
"aureon/decoders/iching_decoder.py",
|
| 119 |
+
"The vector is computed from the table in that file.",
|
| 120 |
+
)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
def _render(name: str, module: str, symbol: str) -> str:
|
| 124 |
+
relative = REPORTS[name]
|
| 125 |
+
try:
|
| 126 |
+
report = load_report(relative)
|
| 127 |
+
except (OSError, TypeError, ValueError) as exc:
|
| 128 |
+
return _unavailable(f"{relative} could not be read: {exc}")
|
| 129 |
+
return label_result(
|
| 130 |
+
_call(module, symbol, {"report": report}),
|
| 131 |
+
relative,
|
| 132 |
+
"The committed measured report. This formats that file. It does not rerun the proof.",
|
| 133 |
+
)
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
@quiet
|
| 137 |
+
def stage2_render_auris() -> str:
|
| 138 |
+
"""Format the committed Auris report as markdown.
|
| 139 |
+
|
| 140 |
+
The numbers are reports/measured/auris_nodes.json. This does not re-evaluate the nodes.
|
| 141 |
+
|
| 142 |
+
Args:
|
| 143 |
+
none: The file is fixed. Label: cited.
|
| 144 |
+
"""
|
| 145 |
+
|
| 146 |
+
return _render("auris", "evaluation/auris_node_eval.py", "render_auris_markdown")
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
@quiet
|
| 150 |
+
def stage2_render_brain() -> str:
|
| 151 |
+
"""Format the committed brain report as markdown.
|
| 152 |
+
|
| 153 |
+
The numbers are reports/measured/brain.json. This does not rerun the brain proof.
|
| 154 |
+
|
| 155 |
+
Args:
|
| 156 |
+
none: The file is fixed. Label: cited.
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
return _render("brain", "evaluation/brain_proof.py", "render_brain_markdown")
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
@quiet
|
| 163 |
+
def stage2_render_self_coder() -> str:
|
| 164 |
+
"""Format the committed self-coder report as markdown.
|
| 165 |
+
|
| 166 |
+
The numbers are reports/measured/self_coder.json. This does not run the harness.
|
| 167 |
+
|
| 168 |
+
Args:
|
| 169 |
+
none: The file is fixed. Label: cited.
|
| 170 |
+
"""
|
| 171 |
+
|
| 172 |
+
return _render("self_coder", "evaluation/measured_proof.py", "render_self_coder_markdown")
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
@quiet
|
| 176 |
+
def stage2_render_organism() -> str:
|
| 177 |
+
"""Format the committed organism report as markdown.
|
| 178 |
+
|
| 179 |
+
The numbers are reports/measured/organism.json. This does not rerun circulation.
|
| 180 |
+
|
| 181 |
+
Args:
|
| 182 |
+
none: The file is fixed. Label: cited.
|
| 183 |
+
"""
|
| 184 |
+
|
| 185 |
+
return _render("organism", "evaluation/organism_proof.py", "render_organism_markdown")
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
@quiet
|
| 189 |
+
def stage2_render_qgita() -> str:
|
| 190 |
+
"""Format the committed QGITA report as markdown.
|
| 191 |
+
|
| 192 |
+
The numbers are reports/measured/qgita_snr.json. This does not rerun the benchmark.
|
| 193 |
+
|
| 194 |
+
Args:
|
| 195 |
+
none: The file is fixed. Label: cited.
|
| 196 |
+
"""
|
| 197 |
+
|
| 198 |
+
return _render("qgita", "evaluation/qgita_snr_benchmark.py", "render_qgita_markdown")
|
| 199 |
+
|
| 200 |
+
|
| 201 |
+
@quiet
|
| 202 |
+
def stage2_predict_next() -> str:
|
| 203 |
+
"""Apply the pre-registered next-step rule to ticks 0 through 6.
|
| 204 |
+
|
| 205 |
+
reports/measured/organism.json records tick baseline 6 and held-out tick 7.
|
| 206 |
+
organism_proof.TICKS is 8. The result is that rule on this series, not a new organism run.
|
| 207 |
+
|
| 208 |
+
Args:
|
| 209 |
+
none: The series is fixed. Label: cited.
|
| 210 |
+
"""
|
| 211 |
+
|
| 212 |
+
return label_result(
|
| 213 |
+
_call("evaluation/organism_proof.py", "predict_next", {"values": TICK_HISTORY}),
|
| 214 |
+
"reports/measured/organism.json",
|
| 215 |
+
"Ticks 0 through 6. The committed report's tick baseline is 6 and the held-out tick is 7.",
|
| 216 |
+
)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@quiet
|
| 220 |
+
def stage2_build_report() -> str:
|
| 221 |
+
"""Assemble a gate report from an empty check list.
|
| 222 |
+
|
| 223 |
+
aureon/gates/benchmark.py says an empty list must not pass. The panel is not convened.
|
| 224 |
+
The status is the assembler's empty-list result, not a gate measurement.
|
| 225 |
+
|
| 226 |
+
Args:
|
| 227 |
+
none: The check list is empty. Label: cited.
|
| 228 |
+
"""
|
| 229 |
+
|
| 230 |
+
return label_result(
|
| 231 |
+
_call("gates/benchmark.py", "build_report", {"checks": []}),
|
| 232 |
+
"aureon/gates/benchmark.py",
|
| 233 |
+
"Empty check list. The panel is not convened. An empty list must not pass.",
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
@quiet
|
| 238 |
+
def stage2_ungrounded_nodes() -> str:
|
| 239 |
+
"""Name the panel nodes whose slice is absent from an empty grounded set.
|
| 240 |
+
|
| 241 |
+
The empty set is tests/gates/test_switchboard.py. Tiger and Panda stay in the
|
| 242 |
+
result because nothing in the organism measures those slices. This is not a live vote.
|
| 243 |
+
|
| 244 |
+
Args:
|
| 245 |
+
none: The grounded set is empty. Label: cited.
|
| 246 |
+
"""
|
| 247 |
+
|
| 248 |
+
return label_result(
|
| 249 |
+
_call("gates/panel.py", "ungrounded_nodes", {"grounded_slices": []}),
|
| 250 |
+
"tests/gates/test_switchboard.py",
|
| 251 |
+
"Empty grounded set from that test. Nothing was measured.",
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
|
| 255 |
+
@quiet
|
| 256 |
+
def stage2_is_human_held(action: str = "draft") -> str:
|
| 257 |
+
"""Say whether an action is on the human-held list.
|
| 258 |
+
|
| 259 |
+
The default draft is an ordinary action in tests/gates/test_switchboard.py
|
| 260 |
+
and is not held. submit is held. This does not execute the action.
|
| 261 |
+
|
| 262 |
+
Args:
|
| 263 |
+
action: The action string passed to is_human_held. Label: cited, the switchboard test.
|
| 264 |
+
"""
|
| 265 |
+
|
| 266 |
+
if not isinstance(action, str):
|
| 267 |
+
return _unavailable("action is missing")
|
| 268 |
+
text = _call("gates/switchboard.py", "is_human_held", {"action": action})
|
| 269 |
+
if action == "draft":
|
| 270 |
+
return label_result(
|
| 271 |
+
text,
|
| 272 |
+
"tests/gates/test_switchboard.py",
|
| 273 |
+
"draft is an ordinary action in that test. It is not human-held.",
|
| 274 |
+
)
|
| 275 |
+
if action == "submit":
|
| 276 |
+
return label_result(
|
| 277 |
+
text,
|
| 278 |
+
"tests/gates/test_switchboard.py",
|
| 279 |
+
"submit is a human-held verb in that test.",
|
| 280 |
+
)
|
| 281 |
+
return text
|
| 282 |
+
|
| 283 |
+
|
| 284 |
+
def _fit(symbol: str) -> str:
|
| 285 |
+
try:
|
| 286 |
+
values = de440_lambda_prefix()
|
| 287 |
+
except (OSError, KeyError, TypeError, ValueError) as exc:
|
| 288 |
+
return _unavailable(f"{DE440_SOURCE} could not be read: {exc}")
|
| 289 |
+
return label_result(
|
| 290 |
+
_call("observer/fitter.py", symbol, {"lambda_values": values}),
|
| 291 |
+
DE440_SOURCE,
|
| 292 |
+
"The first 80 Lambda values of that file. A curve fit of that prefix, not a live trace and not a white-paper coefficient.",
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
|
| 296 |
+
@quiet
|
| 297 |
+
def stage2_fit_tanh() -> str:
|
| 298 |
+
"""Fit alpha and g to the first 80 Lambda values in data/de440_timeseries.csv.
|
| 299 |
+
|
| 300 |
+
This is a curve fit of that prefix. It is not a live trace and it is not the white-paper coefficients.
|
| 301 |
+
|
| 302 |
+
Args:
|
| 303 |
+
none: The prefix is fixed. Label: cited.
|
| 304 |
+
"""
|
| 305 |
+
|
| 306 |
+
return _fit("fit_tanh")
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
@quiet
|
| 310 |
+
def stage2_fit_full() -> str:
|
| 311 |
+
"""Fit alpha, g, beta, and tau to the first 80 Lambda values in data/de440_timeseries.csv.
|
| 312 |
+
|
| 313 |
+
This is a curve fit of that prefix. It is not a live trace and it is not the white-paper coefficients.
|
| 314 |
+
|
| 315 |
+
Args:
|
| 316 |
+
none: The prefix is fixed. Label: cited.
|
| 317 |
+
"""
|
| 318 |
+
|
| 319 |
+
return _fit("fit_full")
|
| 320 |
+
|
| 321 |
+
|
| 322 |
+
@quiet
|
| 323 |
+
def stage2_simulation_fallback() -> str:
|
| 324 |
+
"""Read whether simulation fallback is allowed in this worker.
|
| 325 |
+
|
| 326 |
+
The worker does not set AUREON_ALLOW_SIM_FALLBACK. The function's production posture is false.
|
| 327 |
+
This does not fetch a feed.
|
| 328 |
+
|
| 329 |
+
Args:
|
| 330 |
+
none: The worker environment is the public worker environment. Label: cited.
|
| 331 |
+
"""
|
| 332 |
+
|
| 333 |
+
return label_result(
|
| 334 |
+
_call("observer/live_data_policy.py", "simulation_fallback_allowed", {}),
|
| 335 |
+
"aureon/observer/live_data_policy.py",
|
| 336 |
+
"The worker does not set AUREON_ALLOW_SIM_FALLBACK. False is that function's production posture.",
|
| 337 |
+
)
|
| 338 |
+
|
| 339 |
+
|
| 340 |
+
@quiet
|
| 341 |
+
def stage2_fallback_marker() -> str:
|
| 342 |
+
"""Build the fallback audit dict from the benchmark test.
|
| 343 |
+
|
| 344 |
+
source is b70_probe and when is 123.0, both from tests/benchmarks/benchmark_aureon_scope.py.
|
| 345 |
+
The dict says the reading is a test fixture.
|
| 346 |
+
|
| 347 |
+
Args:
|
| 348 |
+
none: The arguments are the benchmark's. Label: cited.
|
| 349 |
+
"""
|
| 350 |
+
|
| 351 |
+
return label_result(
|
| 352 |
+
_call(
|
| 353 |
+
"observer/live_data_policy.py",
|
| 354 |
+
"fallback_marker",
|
| 355 |
+
{"source": "b70_probe", "when": 123.0},
|
| 356 |
+
),
|
| 357 |
+
"tests/benchmarks/benchmark_aureon_scope.py",
|
| 358 |
+
"when is 123.0 in that test. The dict is a test-fixture marker, not a live reading.",
|
| 359 |
+
)
|
| 360 |
+
|
| 361 |
+
|
| 362 |
+
@quiet
|
| 363 |
+
def stage2_momentum_tracker() -> str:
|
| 364 |
+
"""Return the momentum tracker installed in this worker.
|
| 365 |
+
|
| 366 |
+
A fresh worker has none, so the result is null. That null is not a momentum reading.
|
| 367 |
+
|
| 368 |
+
Args:
|
| 369 |
+
none: No tracker is installed. Label: cited.
|
| 370 |
+
"""
|
| 371 |
+
|
| 372 |
+
return label_result(
|
| 373 |
+
_call("observer/momentum.py", "get_momentum_tracker", {}),
|
| 374 |
+
"aureon/observer/momentum.py",
|
| 375 |
+
"A fresh worker has no tracker. Null is that fact, not a momentum reading.",
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
|
| 379 |
+
@quiet
|
| 380 |
+
def stage2_momentum_predict() -> str:
|
| 381 |
+
"""Ask the momentum predictor with no tracker installed.
|
| 382 |
+
|
| 383 |
+
The default symbol is BTCUSD, the function's own default. The result is the function's
|
| 384 |
+
neutral no-data signal. It does not read a price.
|
| 385 |
+
|
| 386 |
+
Args:
|
| 387 |
+
none: The symbol default is the function's. Label: cited.
|
| 388 |
+
"""
|
| 389 |
+
|
| 390 |
+
return label_result(
|
| 391 |
+
_call("observer/momentum.py", "momentum_predict_fn", {}),
|
| 392 |
+
"aureon/observer/momentum.py",
|
| 393 |
+
"No tracker is installed. The neutral signal is the function's no-data result, not a price.",
|
| 394 |
+
)
|
| 395 |
+
|
| 396 |
+
|
| 397 |
+
def _mode_call(symbol: str) -> str:
|
| 398 |
+
"""Call one production-mode entry point and keep its return value."""
|
| 399 |
+
|
| 400 |
+
return label_result(
|
| 401 |
+
_call("observer/production_mode.py", symbol, {}),
|
| 402 |
+
_MODE_SOURCE,
|
| 403 |
+
_MODE_CITED,
|
| 404 |
+
)
|
| 405 |
+
|
| 406 |
+
|
| 407 |
+
@quiet
|
| 408 |
+
def stage2_observer_mode() -> str:
|
| 409 |
+
"""Return get_mode under AUREON_OBSERVER_MODE=dry_run.
|
| 410 |
+
|
| 411 |
+
The result is that function's return. It is not a broker session and it does not place an order.
|
| 412 |
+
|
| 413 |
+
Args:
|
| 414 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 415 |
+
"""
|
| 416 |
+
|
| 417 |
+
return _mode_call("get_mode")
|
| 418 |
+
|
| 419 |
+
|
| 420 |
+
@quiet
|
| 421 |
+
def stage2_reload_mode() -> str:
|
| 422 |
+
"""Return reload_mode under AUREON_OBSERVER_MODE=dry_run.
|
| 423 |
+
|
| 424 |
+
This does not write a file and does not start a process. The result is that function's return.
|
| 425 |
+
|
| 426 |
+
Args:
|
| 427 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 428 |
+
"""
|
| 429 |
+
|
| 430 |
+
return _mode_call("reload_mode")
|
| 431 |
+
|
| 432 |
+
|
| 433 |
+
@quiet
|
| 434 |
+
def stage2_is_live() -> str:
|
| 435 |
+
"""Return is_live under AUREON_OBSERVER_MODE=dry_run.
|
| 436 |
+
|
| 437 |
+
The result is that function's return. This call does not place an order.
|
| 438 |
+
|
| 439 |
+
Args:
|
| 440 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 441 |
+
"""
|
| 442 |
+
|
| 443 |
+
return _mode_call("is_live")
|
| 444 |
+
|
| 445 |
+
|
| 446 |
+
@quiet
|
| 447 |
+
def stage2_is_shadow() -> str:
|
| 448 |
+
"""Return is_shadow under AUREON_OBSERVER_MODE=dry_run.
|
| 449 |
+
|
| 450 |
+
The result is that function's return. It does not describe a broker session.
|
| 451 |
+
|
| 452 |
+
Args:
|
| 453 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 454 |
+
"""
|
| 455 |
+
|
| 456 |
+
return _mode_call("is_shadow")
|
| 457 |
+
|
| 458 |
+
|
| 459 |
+
@quiet
|
| 460 |
+
def stage2_gate_buy_veto() -> str:
|
| 461 |
+
"""Return gate_buy_veto_active under AUREON_OBSERVER_MODE=dry_run.
|
| 462 |
+
|
| 463 |
+
The result is that function's return. This call does not place an order.
|
| 464 |
+
|
| 465 |
+
Args:
|
| 466 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 467 |
+
"""
|
| 468 |
+
|
| 469 |
+
return _mode_call("gate_buy_veto_active")
|
| 470 |
+
|
| 471 |
+
|
| 472 |
+
@quiet
|
| 473 |
+
def stage2_gate_sell_veto() -> str:
|
| 474 |
+
"""Return gate_sell_veto_active under AUREON_OBSERVER_MODE=dry_run.
|
| 475 |
+
|
| 476 |
+
The result is that function's return. This call does not place an order.
|
| 477 |
+
|
| 478 |
+
Args:
|
| 479 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 480 |
+
"""
|
| 481 |
+
|
| 482 |
+
return _mode_call("gate_sell_veto_active")
|
| 483 |
+
|
| 484 |
+
|
| 485 |
+
@quiet
|
| 486 |
+
def stage2_narrow_band() -> str:
|
| 487 |
+
"""Return narrow_band_threshold_active under AUREON_OBSERVER_MODE=dry_run.
|
| 488 |
+
|
| 489 |
+
The result is that function's return. This call does not change an order.
|
| 490 |
+
|
| 491 |
+
Args:
|
| 492 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 493 |
+
"""
|
| 494 |
+
|
| 495 |
+
return _mode_call("narrow_band_threshold_active")
|
| 496 |
+
|
| 497 |
+
|
| 498 |
+
@quiet
|
| 499 |
+
def stage2_kelly_buffer() -> str:
|
| 500 |
+
"""Return kelly_buffer_scaling_active under AUREON_OBSERVER_MODE=dry_run.
|
| 501 |
+
|
| 502 |
+
The result is that function's return. This call does not size an order.
|
| 503 |
+
|
| 504 |
+
Args:
|
| 505 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 506 |
+
"""
|
| 507 |
+
|
| 508 |
+
return _mode_call("kelly_buffer_scaling_active")
|
| 509 |
+
|
| 510 |
+
|
| 511 |
+
@quiet
|
| 512 |
+
def stage2_vote_addition() -> str:
|
| 513 |
+
"""Return vote_addition_active under AUREON_OBSERVER_MODE=dry_run.
|
| 514 |
+
|
| 515 |
+
The result is that function's return. This call does not cast a vote.
|
| 516 |
+
|
| 517 |
+
Args:
|
| 518 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 519 |
+
"""
|
| 520 |
+
|
| 521 |
+
return _mode_call("vote_addition_active")
|
| 522 |
+
|
| 523 |
+
|
| 524 |
+
@quiet
|
| 525 |
+
def stage2_phase_veto() -> str:
|
| 526 |
+
"""Return phase_veto_active under AUREON_OBSERVER_MODE=dry_run.
|
| 527 |
+
|
| 528 |
+
The result is that function's return. This call does not block an order.
|
| 529 |
+
|
| 530 |
+
Args:
|
| 531 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 532 |
+
"""
|
| 533 |
+
|
| 534 |
+
return _mode_call("phase_veto_active")
|
| 535 |
+
|
| 536 |
+
|
| 537 |
+
@quiet
|
| 538 |
+
def stage2_volatility_veto() -> str:
|
| 539 |
+
"""Return volatility_veto_active under AUREON_OBSERVER_MODE=dry_run.
|
| 540 |
+
|
| 541 |
+
The result is that function's return. This call does not block an order.
|
| 542 |
+
|
| 543 |
+
Args:
|
| 544 |
+
none: The worker sets AUREON_OBSERVER_MODE=dry_run. Label: cited.
|
| 545 |
+
"""
|
| 546 |
+
|
| 547 |
+
return _mode_call("volatility_veto_active")
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
@quiet
|
| 551 |
+
def stage2_repo_root() -> str:
|
| 552 |
+
"""Resolve the checkout that contains aureon/ and data/.
|
| 553 |
+
|
| 554 |
+
The public result may keep only the path type. The path is the checkout this process loaded.
|
| 555 |
+
|
| 556 |
+
Args:
|
| 557 |
+
none: The start path is the worker's current directory. Label: cited.
|
| 558 |
+
"""
|
| 559 |
+
|
| 560 |
+
return label_result(
|
| 561 |
+
_call("observer/real_data_contract.py", "repo_root_from", {}),
|
| 562 |
+
"aureon/observer/real_data_contract.py",
|
| 563 |
+
"The function walks parents for an aureon/ and data/ directory.",
|
| 564 |
+
)
|
| 565 |
+
|
| 566 |
+
|
| 567 |
+
@quiet
|
| 568 |
+
def stage2_source_registry() -> str:
|
| 569 |
+
"""Read data/real_data_sources.json.
|
| 570 |
+
|
| 571 |
+
The object is that file. This does not contact the sources.
|
| 572 |
+
|
| 573 |
+
Args:
|
| 574 |
+
none: The path is the function's own default. Label: cited.
|
| 575 |
+
"""
|
| 576 |
+
|
| 577 |
+
return label_result(
|
| 578 |
+
_call("observer/real_data_contract.py", "load_source_registry", {}),
|
| 579 |
+
"data/real_data_sources.json",
|
| 580 |
+
"The committed registry. No source was contacted.",
|
| 581 |
+
)
|
| 582 |
+
|
| 583 |
+
|
| 584 |
+
@quiet
|
| 585 |
+
def stage2_source_ids() -> str:
|
| 586 |
+
"""List the source ids in data/real_data_sources.json.
|
| 587 |
+
|
| 588 |
+
A set does not survive the public result cap as a list. The ids are the keys
|
| 589 |
+
load_source_registry returns from that file.
|
| 590 |
+
|
| 591 |
+
Args:
|
| 592 |
+
none: The path is the function's own default. Label: cited.
|
| 593 |
+
"""
|
| 594 |
+
|
| 595 |
+
return label_result(
|
| 596 |
+
_call("observer/real_data_contract.py", "registered_source_ids", {}),
|
| 597 |
+
"data/real_data_sources.json",
|
| 598 |
+
"The ids are the keys of that file. A set may be returned as its type name.",
|
| 599 |
+
)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
@quiet
|
| 603 |
+
def stage2_test_fixture_metric() -> str:
|
| 604 |
+
"""Build the test-fixture metric named in tests/test_real_data_contract.py.
|
| 605 |
+
|
| 606 |
+
The name is fixture.metric and the value is 1. The envelope's truth status is
|
| 607 |
+
test_fixture. It is not a live metric.
|
| 608 |
+
|
| 609 |
+
Args:
|
| 610 |
+
none: The name and value are the test's. Label: cited.
|
| 611 |
+
"""
|
| 612 |
+
|
| 613 |
+
return label_result(
|
| 614 |
+
_call(
|
| 615 |
+
"observer/real_data_contract.py",
|
| 616 |
+
"make_test_fixture_metric",
|
| 617 |
+
{"name": "fixture.metric", "value": 1},
|
| 618 |
+
),
|
| 619 |
+
"tests/test_real_data_contract.py",
|
| 620 |
+
"The name and value in that test. truth_status is test_fixture. Not a live metric.",
|
| 621 |
+
)
|
| 622 |
+
|
| 623 |
+
|
| 624 |
+
@quiet
|
| 625 |
+
def stage2_truth_counts() -> str:
|
| 626 |
+
"""Count truth statuses in a one-item list whose status is test_fixture.
|
| 627 |
+
|
| 628 |
+
test_fixture is the status make_test_fixture_metric writes. The count is of
|
| 629 |
+
that one status, not a census of operational sources.
|
| 630 |
+
|
| 631 |
+
Args:
|
| 632 |
+
none: The list is that one status. Label: cited.
|
| 633 |
+
"""
|
| 634 |
+
|
| 635 |
+
return label_result(
|
| 636 |
+
_call(
|
| 637 |
+
"observer/real_data_contract.py",
|
| 638 |
+
"summarize_truth_status",
|
| 639 |
+
{"metrics": [{"truth_status": "test_fixture"}]},
|
| 640 |
+
),
|
| 641 |
+
"aureon/observer/real_data_contract.py",
|
| 642 |
+
"One test_fixture status, the status make_test_fixture_metric writes. Not a census.",
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
@quiet
|
| 647 |
+
def stage2_wave_predictor() -> str:
|
| 648 |
+
"""Return the wave predictor installed in this worker.
|
| 649 |
+
|
| 650 |
+
A fresh worker has none, so the result is null. That null is not a forecast.
|
| 651 |
+
|
| 652 |
+
Args:
|
| 653 |
+
none: No predictor is installed. Label: cited.
|
| 654 |
+
"""
|
| 655 |
+
|
| 656 |
+
return label_result(
|
| 657 |
+
_call("observer/wave_predictor.py", "get_wave_predictor", {}),
|
| 658 |
+
"aureon/observer/wave_predictor.py",
|
| 659 |
+
"A fresh worker has no predictor. Null is that fact, not a forecast.",
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
|
| 663 |
+
@quiet
|
| 664 |
+
def stage2_wave_predict() -> str:
|
| 665 |
+
"""Ask the wave predictor with none installed.
|
| 666 |
+
|
| 667 |
+
The default symbol is BTCUSD, the function's own default. The result is the
|
| 668 |
+
function's neutral not-running signal. It does not forecast a price.
|
| 669 |
+
|
| 670 |
+
Args:
|
| 671 |
+
none: The symbol default is the function's. Label: cited.
|
| 672 |
+
"""
|
| 673 |
+
|
| 674 |
+
return label_result(
|
| 675 |
+
_call("observer/wave_predictor.py", "wave_predictor_predict", {}),
|
| 676 |
+
"aureon/observer/wave_predictor.py",
|
| 677 |
+
"No predictor is installed. The neutral signal is the function's not-running result, not a price.",
|
| 678 |
+
)
|
| 679 |
+
|
| 680 |
+
|
| 681 |
+
@quiet
|
| 682 |
+
def stage2_summarize_compounding() -> str:
|
| 683 |
+
"""Summarize an empty closed-trade receipt list.
|
| 684 |
+
|
| 685 |
+
aureon/s51/aureon_51_compound.py calls this with an empty list when run as a script.
|
| 686 |
+
The result is no_data. No trade is added.
|
| 687 |
+
|
| 688 |
+
Args:
|
| 689 |
+
none: The receipt list is empty. Label: cited.
|
| 690 |
+
"""
|
| 691 |
+
|
| 692 |
+
return label_result(
|
| 693 |
+
_call("s51/aureon_51_compound.py", "summarize_compounding", {"receipts": []}),
|
| 694 |
+
"aureon/s51/aureon_51_compound.py",
|
| 695 |
+
"Empty receipt list. The module reports no_data. No trade is added.",
|
| 696 |
+
)
|
| 697 |
+
|
| 698 |
+
|
| 699 |
+
# Entry points these tools call. coverage_plan counts a tested point only when it is still reachable.
|
| 700 |
+
TESTED: tuple[tuple[str, str], ...] = (
|
| 701 |
+
("cognition/phenolic_bridge.py", "summarize_patterns"),
|
| 702 |
+
("decoders/book_of_ur.py", "get_sumerian_decoder"),
|
| 703 |
+
("decoders/book_of_ur.py", "get_sumerian_geographic_vector"),
|
| 704 |
+
("decoders/iching_decoder.py", "get_iching_decoder"),
|
| 705 |
+
("decoders/iching_decoder.py", "get_iching_geographic_vector"),
|
| 706 |
+
("evaluation/auris_node_eval.py", "render_auris_markdown"),
|
| 707 |
+
("evaluation/brain_proof.py", "render_brain_markdown"),
|
| 708 |
+
("evaluation/measured_proof.py", "render_self_coder_markdown"),
|
| 709 |
+
("evaluation/organism_proof.py", "predict_next"),
|
| 710 |
+
("evaluation/organism_proof.py", "render_organism_markdown"),
|
| 711 |
+
("evaluation/qgita_snr_benchmark.py", "render_qgita_markdown"),
|
| 712 |
+
("gates/benchmark.py", "build_report"),
|
| 713 |
+
("gates/panel.py", "ungrounded_nodes"),
|
| 714 |
+
("gates/switchboard.py", "is_human_held"),
|
| 715 |
+
("observer/fitter.py", "fit_tanh"),
|
| 716 |
+
("observer/fitter.py", "fit_full"),
|
| 717 |
+
("observer/live_data_policy.py", "simulation_fallback_allowed"),
|
| 718 |
+
("observer/live_data_policy.py", "fallback_marker"),
|
| 719 |
+
("observer/momentum.py", "get_momentum_tracker"),
|
| 720 |
+
("observer/momentum.py", "momentum_predict_fn"),
|
| 721 |
+
("observer/production_mode.py", "get_mode"),
|
| 722 |
+
("observer/production_mode.py", "reload_mode"),
|
| 723 |
+
("observer/production_mode.py", "is_live"),
|
| 724 |
+
("observer/production_mode.py", "is_shadow"),
|
| 725 |
+
("observer/production_mode.py", "gate_buy_veto_active"),
|
| 726 |
+
("observer/production_mode.py", "gate_sell_veto_active"),
|
| 727 |
+
("observer/production_mode.py", "narrow_band_threshold_active"),
|
| 728 |
+
("observer/production_mode.py", "kelly_buffer_scaling_active"),
|
| 729 |
+
("observer/production_mode.py", "vote_addition_active"),
|
| 730 |
+
("observer/production_mode.py", "phase_veto_active"),
|
| 731 |
+
("observer/production_mode.py", "volatility_veto_active"),
|
| 732 |
+
("observer/real_data_contract.py", "repo_root_from"),
|
| 733 |
+
("observer/real_data_contract.py", "load_source_registry"),
|
| 734 |
+
("observer/real_data_contract.py", "registered_source_ids"),
|
| 735 |
+
("observer/real_data_contract.py", "make_test_fixture_metric"),
|
| 736 |
+
("observer/real_data_contract.py", "summarize_truth_status"),
|
| 737 |
+
("observer/wave_predictor.py", "get_wave_predictor"),
|
| 738 |
+
("observer/wave_predictor.py", "wave_predictor_predict"),
|
| 739 |
+
("s51/aureon_51_compound.py", "summarize_compounding"),
|
| 740 |
+
)
|
| 741 |
+
|
| 742 |
+
TOOLS: list[Any] = [
|
| 743 |
+
stage2_summarize_patterns,
|
| 744 |
+
stage2_sumerian_decoder,
|
| 745 |
+
stage2_sumerian_vector,
|
| 746 |
+
stage2_iching_decoder,
|
| 747 |
+
stage2_iching_vector,
|
| 748 |
+
stage2_render_auris,
|
| 749 |
+
stage2_render_brain,
|
| 750 |
+
stage2_render_self_coder,
|
| 751 |
+
stage2_render_organism,
|
| 752 |
+
stage2_render_qgita,
|
| 753 |
+
stage2_predict_next,
|
| 754 |
+
stage2_build_report,
|
| 755 |
+
stage2_ungrounded_nodes,
|
| 756 |
+
stage2_is_human_held,
|
| 757 |
+
stage2_fit_tanh,
|
| 758 |
+
stage2_fit_full,
|
| 759 |
+
stage2_simulation_fallback,
|
| 760 |
+
stage2_fallback_marker,
|
| 761 |
+
stage2_momentum_tracker,
|
| 762 |
+
stage2_momentum_predict,
|
| 763 |
+
stage2_observer_mode,
|
| 764 |
+
stage2_reload_mode,
|
| 765 |
+
stage2_is_live,
|
| 766 |
+
stage2_is_shadow,
|
| 767 |
+
stage2_gate_buy_veto,
|
| 768 |
+
stage2_gate_sell_veto,
|
| 769 |
+
stage2_narrow_band,
|
| 770 |
+
stage2_kelly_buffer,
|
| 771 |
+
stage2_vote_addition,
|
| 772 |
+
stage2_phase_veto,
|
| 773 |
+
stage2_volatility_veto,
|
| 774 |
+
stage2_repo_root,
|
| 775 |
+
stage2_source_registry,
|
| 776 |
+
stage2_source_ids,
|
| 777 |
+
stage2_test_fixture_metric,
|
| 778 |
+
stage2_truth_counts,
|
| 779 |
+
stage2_wave_predictor,
|
| 780 |
+
stage2_wave_predict,
|
| 781 |
+
stage2_summarize_compounding,
|
| 782 |
+
]
|
surfaces.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Resources and prompts. Bodies are quoted from the checkout or from code constants."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import json
|
| 6 |
+
from typing import Any
|
| 7 |
+
|
| 8 |
+
from aureon_public import paths
|
| 9 |
+
from aureon_public.quiet import quiet
|
| 10 |
+
from aureon_public.text import AURIS_FOUR, HOLD_LINE, SERVER_PLAIN
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def _text(path_reader: Any) -> str:
|
| 14 |
+
return path_reader().read_text(encoding="utf-8")
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _dumps(payload: dict[str, Any]) -> str:
|
| 18 |
+
return json.dumps(payload, ensure_ascii=False, allow_nan=False, sort_keys=True)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
@quiet
|
| 22 |
+
def harmonic_reality_defaults() -> str:
|
| 23 |
+
"""Code defaults for HarmonicRealityField. Not a fit and not a measurement.
|
| 24 |
+
|
| 25 |
+
The class default enable_multiverse is True (multiverse on). Label: cited, aureon/harmonic/aureon_harmonic_reality.py.
|
| 26 |
+
"""
|
| 27 |
+
|
| 28 |
+
from aureon.harmonic.aureon_harmonic_reality import (
|
| 29 |
+
DEFAULT_ALPHA,
|
| 30 |
+
DEFAULT_BETA,
|
| 31 |
+
DEFAULT_DELTA_T,
|
| 32 |
+
DEFAULT_G,
|
| 33 |
+
DEFAULT_TAU,
|
| 34 |
+
PHI_INVERSE,
|
| 35 |
+
SCHUMANN_BASE,
|
| 36 |
+
HarmonicRealityField,
|
| 37 |
+
)
|
| 38 |
+
|
| 39 |
+
formula = ""
|
| 40 |
+
for line in (HarmonicRealityField.__doc__ or "").splitlines():
|
| 41 |
+
if "Λ(t)" in line or "Λ(t)" in line:
|
| 42 |
+
formula = line.strip()
|
| 43 |
+
break
|
| 44 |
+
if not formula:
|
| 45 |
+
for line in (HarmonicRealityField.__doc__ or "").splitlines():
|
| 46 |
+
if "Λ" in line and "=" in line:
|
| 47 |
+
formula = line.strip()
|
| 48 |
+
break
|
| 49 |
+
return _dumps(
|
| 50 |
+
{
|
| 51 |
+
"class_default_enable_multiverse": True,
|
| 52 |
+
"delta_t": DEFAULT_DELTA_T,
|
| 53 |
+
"formula": formula,
|
| 54 |
+
"g": DEFAULT_G,
|
| 55 |
+
"alpha": DEFAULT_ALPHA,
|
| 56 |
+
"beta": DEFAULT_BETA,
|
| 57 |
+
"label": "cited. Code defaults. Not a measurement.",
|
| 58 |
+
"phi_inverse": PHI_INVERSE,
|
| 59 |
+
"sample_rate": 1000.0,
|
| 60 |
+
"schumann_base_constant": SCHUMANN_BASE,
|
| 61 |
+
"schumann_f0": "null. HOLD.",
|
| 62 |
+
"tau": DEFAULT_TAU,
|
| 63 |
+
}
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
@quiet
|
| 68 |
+
def lambda_engine_defaults() -> str:
|
| 69 |
+
"""LambdaEngine module constants. BETA is _resolve_beta(), not a fitted file.
|
| 70 |
+
|
| 71 |
+
This resource does not read state/. Label: cited, aureon/core/aureon_lambda_engine.py.
|
| 72 |
+
"""
|
| 73 |
+
|
| 74 |
+
from aureon.core import aureon_lambda_engine as engine
|
| 75 |
+
|
| 76 |
+
return _dumps(
|
| 77 |
+
{
|
| 78 |
+
"ALPHA": engine.ALPHA,
|
| 79 |
+
"BETA": engine.BETA,
|
| 80 |
+
"BETA_note": "BETA is _resolve_beta(). When AUREON_HNC_BETA is unset the function returns 1.0.",
|
| 81 |
+
"DELTA_T": engine.DELTA_T,
|
| 82 |
+
"FREQUENCIES": list(engine.FREQUENCIES),
|
| 83 |
+
"G": engine.G,
|
| 84 |
+
"TAU": engine.TAU,
|
| 85 |
+
"WEIGHTS": list(engine.WEIGHTS),
|
| 86 |
+
"label": "cited. Not a fitted result. state/hnc_fitted_params.json was not read.",
|
| 87 |
+
}
|
| 88 |
+
)
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
@quiet
|
| 92 |
+
def hnc_params_code_defaults() -> str:
|
| 93 |
+
"""HNCParams field defaults. Not a fit. load_params is not called.
|
| 94 |
+
|
| 95 |
+
Label: cited, aureon/core/hnc_params.py HNCParams.
|
| 96 |
+
"""
|
| 97 |
+
|
| 98 |
+
from aureon.core.hnc_params import HNCParams
|
| 99 |
+
|
| 100 |
+
params = HNCParams()
|
| 101 |
+
return _dumps(
|
| 102 |
+
{
|
| 103 |
+
"alpha": params.alpha,
|
| 104 |
+
"beta": params.beta,
|
| 105 |
+
"delta_t": params.delta_t,
|
| 106 |
+
"fitted_at": params.fitted_at,
|
| 107 |
+
"fitted_from": params.fitted_from,
|
| 108 |
+
"g": params.g,
|
| 109 |
+
"label": "cited. Code defaults on HNCParams. Not a fit. load_params was not called.",
|
| 110 |
+
"r_squared": params.r_squared,
|
| 111 |
+
"tau": params.tau,
|
| 112 |
+
}
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
@quiet
|
| 117 |
+
def auris_nodes_resource() -> str:
|
| 118 |
+
"""Nine nodes. This resource is the AURIS_NODES table.
|
| 119 |
+
|
| 120 |
+
It is not the conjecture (not called), not the persona (not scored), and not the coherence evaluator. Only the nine nodes and get_auris_coherence are real functions exposed here. Label: cited, aureon/utils/aureon_queen_hive_mind.py AURIS_NODES.
|
| 121 |
+
"""
|
| 122 |
+
|
| 123 |
+
from aureon.utils.aureon_queen_hive_mind import AURIS_NODES
|
| 124 |
+
|
| 125 |
+
return _dumps(
|
| 126 |
+
{
|
| 127 |
+
"auris": "nine nodes",
|
| 128 |
+
"label": "cited. AURIS_NODES.",
|
| 129 |
+
"nodes": AURIS_NODES,
|
| 130 |
+
"which_auris": AURIS_FOUR,
|
| 131 |
+
}
|
| 132 |
+
)
|
| 133 |
+
|
| 134 |
+
|
| 135 |
+
@quiet
|
| 136 |
+
def organism_seats_resource() -> str:
|
| 137 |
+
"""circulation_seats(). Names only. Circulation is not started. Label: cited."""
|
| 138 |
+
|
| 139 |
+
from aureon.core.organism_circulation import circulation_seats
|
| 140 |
+
|
| 141 |
+
return _dumps({"label": "cited", "seats": list(circulation_seats())})
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
@quiet
|
| 145 |
+
def organism_nodes_resource() -> str:
|
| 146 |
+
"""list_nodes(). Names only. Label: cited."""
|
| 147 |
+
|
| 148 |
+
from aureon.core.algorithmic_nodes import list_nodes
|
| 149 |
+
|
| 150 |
+
return _dumps({"label": "cited", "nodes": list_nodes()})
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
@quiet
|
| 154 |
+
def organism_systems_resource() -> str:
|
| 155 |
+
"""list_systems(). The rule strings are the source text. Label: cited."""
|
| 156 |
+
|
| 157 |
+
from aureon.core.deterministic_systems import list_systems
|
| 158 |
+
|
| 159 |
+
return _dumps({"label": "cited", "systems": list_systems()})
|
| 160 |
+
|
| 161 |
+
|
| 162 |
+
def holds_resource() -> str:
|
| 163 |
+
"""HOLD lines from huggingface/README.md. Label: cited-unverified until a new run."""
|
| 164 |
+
|
| 165 |
+
readme = _text(paths.holds_readme)
|
| 166 |
+
return _dumps(
|
| 167 |
+
{
|
| 168 |
+
"hold": HOLD_LINE,
|
| 169 |
+
"label": "cited-unverified. huggingface/README.md",
|
| 170 |
+
"readme": readme,
|
| 171 |
+
}
|
| 172 |
+
)
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
def replay_brain_resource() -> str:
|
| 176 |
+
"""Vendored brain replay. Two paths. Class default is multiverse on. Label: cited."""
|
| 177 |
+
|
| 178 |
+
return _text(paths.brain_json)
|
| 179 |
+
|
| 180 |
+
|
| 181 |
+
def replay_qgita_resource() -> str:
|
| 182 |
+
"""Vendored QGITA adapter record. Detection rate stays HOLD. Label: cited."""
|
| 183 |
+
|
| 184 |
+
return _text(paths.qgita_json)
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def replay_organism_resource() -> str:
|
| 188 |
+
"""Vendored circulation replay. The fault block in the file is seeded synthetic, not telemetry. Label: cited."""
|
| 189 |
+
|
| 190 |
+
return _text(paths.organism_json)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
def replay_auris_resource() -> str:
|
| 194 |
+
"""Committed coherence-evaluator replay with no market series.
|
| 195 |
+
|
| 196 |
+
This resource is the coherence evaluator record. It is not the conjecture (not called), not a persona score (not scored), and it does not publish nine-node values. Only the nine nodes and get_auris_coherence are real functions exposed here. Label: cited, huggingface/fixed-seed-reproducible-runs/auris_nodes.json.
|
| 197 |
+
"""
|
| 198 |
+
|
| 199 |
+
body = json.loads(_text(paths.auris_json))
|
| 200 |
+
if isinstance(body, dict):
|
| 201 |
+
body = {
|
| 202 |
+
"auris": "coherence evaluator",
|
| 203 |
+
"record": body,
|
| 204 |
+
"which_auris": AURIS_FOUR,
|
| 205 |
+
}
|
| 206 |
+
return json.dumps(body, ensure_ascii=False, sort_keys=True)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
@quiet
|
| 210 |
+
def explain_two_lambda_implementations() -> str:
|
| 211 |
+
"""HarmonicRealityField and LambdaEngine are different code with different defaults.
|
| 212 |
+
|
| 213 |
+
A number from one is not a number from the other. The formulas below are the docstrings already in the repo. Label: cited.
|
| 214 |
+
"""
|
| 215 |
+
|
| 216 |
+
from aureon.core import hnc_params
|
| 217 |
+
from aureon.harmonic.aureon_harmonic_reality import HarmonicRealityField
|
| 218 |
+
|
| 219 |
+
reality = " ".join(
|
| 220 |
+
line.strip()
|
| 221 |
+
for line in (HarmonicRealityField.__doc__ or "").splitlines()
|
| 222 |
+
if "Λ" in line and "=" in line
|
| 223 |
+
)
|
| 224 |
+
params = " ".join(
|
| 225 |
+
line.strip() for line in (hnc_params.__doc__ or "").splitlines() if "Λ" in line and "=" in line
|
| 226 |
+
)
|
| 227 |
+
return (
|
| 228 |
+
"HarmonicRealityField and LambdaEngine are different implementations. "
|
| 229 |
+
"A number from one is not a number from the other. "
|
| 230 |
+
"The class default HarmonicRealityField() sets enable_multiverse=True (multiverse on). "
|
| 231 |
+
f"HarmonicRealityField docstring: {reality} "
|
| 232 |
+
f"hnc_params docstring: {params} "
|
| 233 |
+
"Label: cited. No formula was added here."
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
def explain_auris_four_meanings() -> str:
|
| 238 |
+
"""Name the four Auris meanings. Only two functions are exposed.
|
| 239 |
+
|
| 240 |
+
This prompt is the four-way split. The conjecture is not called. The nine nodes are read_auris_nodes and AURIS_NODES. The persona is not scored. The coherence evaluator is get_auris_coherence. Auris-to-Lambda link: HOLD.
|
| 241 |
+
"""
|
| 242 |
+
|
| 243 |
+
return (
|
| 244 |
+
f"{AURIS_FOUR} "
|
| 245 |
+
"auris_nodes calls read_auris_nodes. "
|
| 246 |
+
"aureon://auris/nodes is the AURIS_NODES table. "
|
| 247 |
+
"auris_coherence calls get_auris_coherence. "
|
| 248 |
+
"Whenever any node has no reading, that tool returns status no_data and coherence null. "
|
| 249 |
+
"Trade readiness: HOLD. Auris-to-Lambda link: HOLD."
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
|
| 253 |
+
def explain_qgita_adapter() -> str:
|
| 254 |
+
"""QGITA events are the adapter return. Detection rate is HOLD. signals are not shown.
|
| 255 |
+
|
| 256 |
+
Label: cited, QGITAMarketAnalyzer.analyze. The bundled series is cited-unverified and is not public market data.
|
| 257 |
+
"""
|
| 258 |
+
|
| 259 |
+
return (
|
| 260 |
+
"QGITA events are the return of QGITAMarketAnalyzer.analyze. "
|
| 261 |
+
"They are not a detection rate. Detection rate: HOLD. False-alarm rate: HOLD. "
|
| 262 |
+
"The signals object is not shown. "
|
| 263 |
+
"The bundled Lambda column is cited-unverified and is not public market data."
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def explain_organism_replay() -> str:
|
| 268 |
+
"""The organism replay is a file. Catalog names are not a running circulation.
|
| 269 |
+
|
| 270 |
+
The fault block is seeded synthetic input, not telemetry. Label: cited.
|
| 271 |
+
"""
|
| 272 |
+
|
| 273 |
+
return (
|
| 274 |
+
f"{SERVER_PLAIN} "
|
| 275 |
+
"The organism replay is a file. "
|
| 276 |
+
"Seats in the catalog are names. Circulation is not started. "
|
| 277 |
+
"The fault block is seeded synthetic input, not telemetry. "
|
| 278 |
+
"A claim that those faults are recorded seat faults is HOLD."
|
| 279 |
+
)
|
sweep_guard.py
ADDED
|
@@ -0,0 +1,516 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Block sockets, process starts, and writes outside the sweep sandbox.
|
| 2 |
+
|
| 3 |
+
Installed only in a sweep child. The public server refuses to start when
|
| 4 |
+
``AUREON_PUBLIC_SWEEP`` is set, and this module does not start a server.
|
| 5 |
+
"""
|
| 6 |
+
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import builtins
|
| 10 |
+
import io
|
| 11 |
+
import os
|
| 12 |
+
import subprocess
|
| 13 |
+
from pathlib import Path
|
| 14 |
+
from typing import Any
|
| 15 |
+
|
| 16 |
+
_INSTALLED = False
|
| 17 |
+
_SOCKETS: list[str] = []
|
| 18 |
+
_PROCESSES: list[str] = []
|
| 19 |
+
_WRITES: list[str] = []
|
| 20 |
+
_SANDBOX_WRITES: list[str] = []
|
| 21 |
+
_REAL: dict[str, Any] = {}
|
| 22 |
+
_USER_DIR_NAMES = (
|
| 23 |
+
"HOME",
|
| 24 |
+
"USERPROFILE",
|
| 25 |
+
"XDG_CACHE_HOME",
|
| 26 |
+
"XDG_CONFIG_HOME",
|
| 27 |
+
"XDG_DATA_HOME",
|
| 28 |
+
"XDG_RUNTIME_DIR",
|
| 29 |
+
"XDG_STATE_HOME",
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def declare_sandbox() -> Path:
|
| 34 |
+
"""Point temp files at a directory inside the sweep parent.
|
| 35 |
+
|
| 36 |
+
Python probes ``/tmp`` when ``TMPDIR`` is unset. Those probes are not the
|
| 37 |
+
module writing. The sandbox stays the temp parent, and ``TMPDIR`` is a
|
| 38 |
+
directory inside it.
|
| 39 |
+
"""
|
| 40 |
+
|
| 41 |
+
from aureon_public.sweep_layout import beside
|
| 42 |
+
|
| 43 |
+
sandbox = beside()
|
| 44 |
+
scratch = sandbox / "sweep-scratch"
|
| 45 |
+
home = sandbox / "home"
|
| 46 |
+
dirs = {
|
| 47 |
+
"HOME": home,
|
| 48 |
+
"USERPROFILE": home,
|
| 49 |
+
"XDG_CACHE_HOME": home / ".cache",
|
| 50 |
+
"XDG_CONFIG_HOME": home / ".config",
|
| 51 |
+
"XDG_DATA_HOME": home / ".local" / "share",
|
| 52 |
+
"XDG_RUNTIME_DIR": sandbox / "runtime",
|
| 53 |
+
"XDG_STATE_HOME": home / ".local" / "state",
|
| 54 |
+
}
|
| 55 |
+
for path in (scratch, *dirs.values()):
|
| 56 |
+
path.mkdir(parents=True, exist_ok=True)
|
| 57 |
+
os.environ["AUREON_PUBLIC_SANDBOX"] = str(sandbox)
|
| 58 |
+
os.environ["TMPDIR"] = str(scratch)
|
| 59 |
+
os.environ["TEMP"] = str(scratch)
|
| 60 |
+
os.environ["TMP"] = str(scratch)
|
| 61 |
+
for name, path in dirs.items():
|
| 62 |
+
os.environ[name] = str(path)
|
| 63 |
+
try:
|
| 64 |
+
import tempfile
|
| 65 |
+
|
| 66 |
+
tempfile.tempdir = None
|
| 67 |
+
except Exception:
|
| 68 |
+
pass
|
| 69 |
+
return sandbox
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def snapshot() -> dict[str, list[str]]:
|
| 73 |
+
"""Copies of the attempts recorded since install."""
|
| 74 |
+
|
| 75 |
+
return {
|
| 76 |
+
"processes": list(_PROCESSES),
|
| 77 |
+
"sandbox_writes": list(_SANDBOX_WRITES),
|
| 78 |
+
"sockets": list(_SOCKETS),
|
| 79 |
+
"writes": list(_WRITES),
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def _sandbox() -> Path | None:
|
| 84 |
+
raw = os.environ.get("AUREON_PUBLIC_SANDBOX", "").strip()
|
| 85 |
+
if not raw:
|
| 86 |
+
return None
|
| 87 |
+
return Path(raw).resolve()
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _outside(path: object) -> bool:
|
| 91 |
+
sandbox = _sandbox()
|
| 92 |
+
try:
|
| 93 |
+
resolved = Path(os.fspath(path)).resolve()
|
| 94 |
+
except (OSError, TypeError, ValueError):
|
| 95 |
+
return True
|
| 96 |
+
if sandbox is None:
|
| 97 |
+
return True
|
| 98 |
+
return resolved != sandbox and sandbox not in resolved.parents
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
def _harmless_device(path: object) -> bool:
|
| 102 |
+
"""``/dev/null`` is the pin check's stderr sink, not a module write."""
|
| 103 |
+
|
| 104 |
+
try:
|
| 105 |
+
text = os.fspath(path)
|
| 106 |
+
except TypeError:
|
| 107 |
+
return False
|
| 108 |
+
return str(text) in {"/dev/null", "/dev/zero", "/dev/stdout", "/dev/stderr"}
|
| 109 |
+
|
| 110 |
+
|
| 111 |
+
def _record_inside(path: object) -> None:
|
| 112 |
+
"""Remember a write under the sandbox that is not the temp scratch dir."""
|
| 113 |
+
|
| 114 |
+
sandbox = _sandbox()
|
| 115 |
+
if sandbox is None or _harmless_device(path):
|
| 116 |
+
return
|
| 117 |
+
try:
|
| 118 |
+
resolved = Path(os.fspath(path)).resolve()
|
| 119 |
+
except (OSError, TypeError, ValueError):
|
| 120 |
+
return
|
| 121 |
+
scratch = (sandbox / "sweep-scratch").resolve()
|
| 122 |
+
if resolved == scratch or scratch in resolved.parents:
|
| 123 |
+
return
|
| 124 |
+
if resolved != sandbox and sandbox not in resolved.parents:
|
| 125 |
+
return
|
| 126 |
+
text = str(resolved)[:200]
|
| 127 |
+
if text not in _SANDBOX_WRITES:
|
| 128 |
+
_SANDBOX_WRITES.append(text)
|
| 129 |
+
|
| 130 |
+
|
| 131 |
+
def _guard_path(path: object) -> None:
|
| 132 |
+
"""Block a path outside the sandbox. Record one inside it."""
|
| 133 |
+
|
| 134 |
+
if _harmless_device(path):
|
| 135 |
+
return
|
| 136 |
+
if _outside(path):
|
| 137 |
+
_note_write(path)
|
| 138 |
+
_record_inside(path)
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def _note_write(path: object) -> None:
|
| 142 |
+
text = str(path)[:200]
|
| 143 |
+
if text not in _WRITES:
|
| 144 |
+
_WRITES.append(text)
|
| 145 |
+
raise OSError("write blocked outside sandbox")
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
def _pin_git(command: object) -> bool:
|
| 149 |
+
"""True for the loader's ``git rev-parse <pin>:<path>`` and nothing else."""
|
| 150 |
+
|
| 151 |
+
if not isinstance(command, (list, tuple)) or len(command) < 3:
|
| 152 |
+
return False
|
| 153 |
+
if Path(str(command[0])).name != "git" or str(command[1]) != "rev-parse":
|
| 154 |
+
return False
|
| 155 |
+
spec = str(command[2])
|
| 156 |
+
pin = "8aa6a2d971cc529484e2a5e261e28afafab4e4f4"
|
| 157 |
+
return spec.startswith(pin + ":") and " " not in spec
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
def _note_process(kind: str, detail: object) -> None:
|
| 161 |
+
text = f"{kind} {detail}"[:200]
|
| 162 |
+
if text not in _PROCESSES:
|
| 163 |
+
_PROCESSES.append(text)
|
| 164 |
+
raise OSError("process blocked")
|
| 165 |
+
|
| 166 |
+
|
| 167 |
+
def _write_mode(mode: object) -> bool:
|
| 168 |
+
text = str(mode or "r")
|
| 169 |
+
return any(flag in text for flag in ("w", "a", "x", "+"))
|
| 170 |
+
|
| 171 |
+
|
| 172 |
+
def install_sweep_guard() -> None:
|
| 173 |
+
"""Replace socket, process, and write entry points. Idempotent."""
|
| 174 |
+
|
| 175 |
+
global _INSTALLED
|
| 176 |
+
if _INSTALLED:
|
| 177 |
+
return
|
| 178 |
+
import shutil
|
| 179 |
+
import socket
|
| 180 |
+
|
| 181 |
+
_SOCKETS.clear()
|
| 182 |
+
_PROCESSES.clear()
|
| 183 |
+
_WRITES.clear()
|
| 184 |
+
_SANDBOX_WRITES.clear()
|
| 185 |
+
|
| 186 |
+
class _Guard(socket.socket):
|
| 187 |
+
def connect(self, address: object, *args: object, **kwargs: object) -> None:
|
| 188 |
+
text = str(address)[:160]
|
| 189 |
+
if text not in _SOCKETS:
|
| 190 |
+
_SOCKETS.append(text)
|
| 191 |
+
raise OSError("socket blocked")
|
| 192 |
+
|
| 193 |
+
def connect_ex(self, address: object, *args: object, **kwargs: object) -> int:
|
| 194 |
+
text = str(address)[:160]
|
| 195 |
+
if text not in _SOCKETS:
|
| 196 |
+
_SOCKETS.append(text)
|
| 197 |
+
raise OSError("socket blocked")
|
| 198 |
+
|
| 199 |
+
def _create_connection(*args: object, **kwargs: object) -> object:
|
| 200 |
+
if "create_connection" not in _SOCKETS:
|
| 201 |
+
_SOCKETS.append("create_connection")
|
| 202 |
+
raise OSError("socket blocked")
|
| 203 |
+
|
| 204 |
+
def _open(file: object, mode: object = "r", *args: object, **kwargs: object) -> object:
|
| 205 |
+
if _write_mode(mode):
|
| 206 |
+
_guard_path(file)
|
| 207 |
+
return _REAL["open"](file, mode, *args, **kwargs)
|
| 208 |
+
|
| 209 |
+
def _os_open(path: object, flags: int, *args: object, **kwargs: object) -> int:
|
| 210 |
+
writing = flags & (os.O_WRONLY | os.O_RDWR | os.O_APPEND)
|
| 211 |
+
if writing:
|
| 212 |
+
_guard_path(path)
|
| 213 |
+
return _REAL["os_open"](path, flags, *args, **kwargs)
|
| 214 |
+
|
| 215 |
+
def _mkdir(path: object, *args: object, **kwargs: object) -> None:
|
| 216 |
+
_guard_path(path)
|
| 217 |
+
return _REAL["mkdir"](path, *args, **kwargs)
|
| 218 |
+
|
| 219 |
+
def _makedirs(path: object, *args: object, **kwargs: object) -> None:
|
| 220 |
+
_guard_path(path)
|
| 221 |
+
return _REAL["makedirs"](path, *args, **kwargs)
|
| 222 |
+
|
| 223 |
+
def _unlink(path: object, *args: object, **kwargs: object) -> None:
|
| 224 |
+
_guard_path(path)
|
| 225 |
+
return _REAL["unlink"](path, *args, **kwargs)
|
| 226 |
+
|
| 227 |
+
def _remove(path: object, *args: object, **kwargs: object) -> None:
|
| 228 |
+
_guard_path(path)
|
| 229 |
+
return _REAL["remove"](path, *args, **kwargs)
|
| 230 |
+
|
| 231 |
+
def _rename(src: object, dst: object, *args: object, **kwargs: object) -> None:
|
| 232 |
+
_guard_path(src)
|
| 233 |
+
_guard_path(dst)
|
| 234 |
+
return _REAL["rename"](src, dst, *args, **kwargs)
|
| 235 |
+
|
| 236 |
+
def _replace(src: object, dst: object, *args: object, **kwargs: object) -> None:
|
| 237 |
+
_guard_path(src)
|
| 238 |
+
_guard_path(dst)
|
| 239 |
+
return _REAL["replace"](src, dst, *args, **kwargs)
|
| 240 |
+
|
| 241 |
+
def _rmdir(path: object, *args: object, **kwargs: object) -> None:
|
| 242 |
+
_guard_path(path)
|
| 243 |
+
return _REAL["rmdir"](path, *args, **kwargs)
|
| 244 |
+
|
| 245 |
+
def _truncate(path: object, length: int) -> None:
|
| 246 |
+
_guard_path(path)
|
| 247 |
+
return _REAL["truncate"](path, length)
|
| 248 |
+
|
| 249 |
+
def _chmod(path: object, mode: int, *args: object, **kwargs: object) -> None:
|
| 250 |
+
_guard_path(path)
|
| 251 |
+
return _REAL["chmod"](path, mode, *args, **kwargs)
|
| 252 |
+
|
| 253 |
+
def _lchmod(path: object, mode: int) -> None:
|
| 254 |
+
_guard_path(path)
|
| 255 |
+
return _REAL["lchmod"](path, mode)
|
| 256 |
+
|
| 257 |
+
def _chown(path: object, uid: int, gid: int, *args: object, **kwargs: object) -> None:
|
| 258 |
+
_guard_path(path)
|
| 259 |
+
return _REAL["chown"](path, uid, gid, *args, **kwargs)
|
| 260 |
+
|
| 261 |
+
def _symlink(src: object, dst: object, *args: object, **kwargs: object) -> None:
|
| 262 |
+
_guard_path(dst)
|
| 263 |
+
return _REAL["symlink"](src, dst, *args, **kwargs)
|
| 264 |
+
|
| 265 |
+
def _link(src: object, dst: object, *args: object, **kwargs: object) -> None:
|
| 266 |
+
_guard_path(src)
|
| 267 |
+
_guard_path(dst)
|
| 268 |
+
return _REAL["link"](src, dst, *args, **kwargs)
|
| 269 |
+
|
| 270 |
+
def _utime(path: object, times: object = None, *args: object, **kwargs: object) -> None:
|
| 271 |
+
_guard_path(path)
|
| 272 |
+
return _REAL["utime"](path, times, *args, **kwargs)
|
| 273 |
+
|
| 274 |
+
def _fd_path(fd: object) -> str | None:
|
| 275 |
+
try:
|
| 276 |
+
return os.readlink(f"/proc/self/fd/{int(fd)}")
|
| 277 |
+
except (OSError, TypeError, ValueError):
|
| 278 |
+
return None
|
| 279 |
+
|
| 280 |
+
def _guard_fd(fd: object) -> None:
|
| 281 |
+
path = _fd_path(fd)
|
| 282 |
+
if path is None:
|
| 283 |
+
_note_write(f"fd:{fd}")
|
| 284 |
+
_guard_path(path)
|
| 285 |
+
|
| 286 |
+
def _ftruncate(fd: object, length: int) -> None:
|
| 287 |
+
_guard_fd(fd)
|
| 288 |
+
return _REAL["ftruncate"](fd, length)
|
| 289 |
+
|
| 290 |
+
def _fchmod(fd: object, mode: int) -> None:
|
| 291 |
+
_guard_fd(fd)
|
| 292 |
+
return _REAL["fchmod"](fd, mode)
|
| 293 |
+
|
| 294 |
+
def _rmtree(path: object, *args: object, **kwargs: object) -> None:
|
| 295 |
+
_guard_path(path)
|
| 296 |
+
return _REAL["rmtree"](path, *args, **kwargs)
|
| 297 |
+
|
| 298 |
+
def _move(src: object, dst: object, *args: object, **kwargs: object) -> object:
|
| 299 |
+
_guard_path(src)
|
| 300 |
+
_guard_path(dst)
|
| 301 |
+
return _REAL["move"](src, dst, *args, **kwargs)
|
| 302 |
+
|
| 303 |
+
def _fork(*args: object, **kwargs: object) -> int:
|
| 304 |
+
_note_process("fork", args or "fork")
|
| 305 |
+
raise AssertionError("unreachable")
|
| 306 |
+
|
| 307 |
+
def _forkpty(*args: object, **kwargs: object) -> object:
|
| 308 |
+
_note_process("forkpty", args or "forkpty")
|
| 309 |
+
raise AssertionError("unreachable")
|
| 310 |
+
|
| 311 |
+
def _posix_spawn(path: object, *args: object, **kwargs: object) -> int:
|
| 312 |
+
_note_process("posix_spawn", path)
|
| 313 |
+
raise AssertionError("unreachable")
|
| 314 |
+
|
| 315 |
+
def _posix_spawnp(path: object, *args: object, **kwargs: object) -> int:
|
| 316 |
+
_note_process("posix_spawnp", path)
|
| 317 |
+
raise AssertionError("unreachable")
|
| 318 |
+
|
| 319 |
+
def _spawn(name: str):
|
| 320 |
+
def inner(*args: object, **kwargs: object) -> int:
|
| 321 |
+
_note_process(name, args[0] if args else name)
|
| 322 |
+
raise AssertionError("unreachable")
|
| 323 |
+
|
| 324 |
+
return inner
|
| 325 |
+
|
| 326 |
+
def _popen(*args: object, **kwargs: object) -> object:
|
| 327 |
+
command = args[0] if args else kwargs.get("args")
|
| 328 |
+
# The pinned loader reads blob ids with git rev-parse. That is the
|
| 329 |
+
# server's pin check, not the module starting a process.
|
| 330 |
+
if _pin_git(command):
|
| 331 |
+
return _REAL["subprocess_popen"](*args, **kwargs)
|
| 332 |
+
_note_process("Popen", command)
|
| 333 |
+
raise AssertionError("unreachable")
|
| 334 |
+
|
| 335 |
+
def _system(command: object) -> int:
|
| 336 |
+
_note_process("system", command)
|
| 337 |
+
raise AssertionError("unreachable")
|
| 338 |
+
|
| 339 |
+
def _popen_os(command: object, *args: object, **kwargs: object) -> object:
|
| 340 |
+
_note_process("popen", command)
|
| 341 |
+
raise AssertionError("unreachable")
|
| 342 |
+
|
| 343 |
+
def _exec(path: object, *args: object, **kwargs: object) -> None:
|
| 344 |
+
_note_process("exec", path)
|
| 345 |
+
raise AssertionError("unreachable")
|
| 346 |
+
|
| 347 |
+
_REAL.update(
|
| 348 |
+
{
|
| 349 |
+
"create_connection": socket.create_connection,
|
| 350 |
+
"execv": os.execv,
|
| 351 |
+
"execve": os.execve,
|
| 352 |
+
"chmod": os.chmod,
|
| 353 |
+
"chown": os.chown,
|
| 354 |
+
"fchmod": getattr(os, "fchmod", None),
|
| 355 |
+
"fork": getattr(os, "fork", None),
|
| 356 |
+
"ftruncate": getattr(os, "ftruncate", None),
|
| 357 |
+
"lchmod": getattr(os, "lchmod", None),
|
| 358 |
+
"link": os.link,
|
| 359 |
+
"forkpty": getattr(os, "forkpty", None),
|
| 360 |
+
"makedirs": os.makedirs,
|
| 361 |
+
"mkdir": os.mkdir,
|
| 362 |
+
"move": shutil.move,
|
| 363 |
+
"open": builtins.open,
|
| 364 |
+
"os_open": os.open,
|
| 365 |
+
"popen": os.popen,
|
| 366 |
+
"posix_spawn": getattr(os, "posix_spawn", None),
|
| 367 |
+
"posix_spawnp": getattr(os, "posix_spawnp", None),
|
| 368 |
+
"remove": os.remove,
|
| 369 |
+
"rename": os.rename,
|
| 370 |
+
"replace": os.replace,
|
| 371 |
+
"rmdir": os.rmdir,
|
| 372 |
+
"rmtree": shutil.rmtree,
|
| 373 |
+
"symlink": os.symlink,
|
| 374 |
+
"truncate": getattr(os, "truncate", None),
|
| 375 |
+
"utime": os.utime,
|
| 376 |
+
"socket": socket.socket,
|
| 377 |
+
"subprocess_popen": subprocess.Popen,
|
| 378 |
+
"system": os.system,
|
| 379 |
+
"unlink": os.unlink,
|
| 380 |
+
}
|
| 381 |
+
)
|
| 382 |
+
for name in (
|
| 383 |
+
"spawnl",
|
| 384 |
+
"spawnle",
|
| 385 |
+
"spawnlp",
|
| 386 |
+
"spawnlpe",
|
| 387 |
+
"spawnv",
|
| 388 |
+
"spawnve",
|
| 389 |
+
"spawnvp",
|
| 390 |
+
"spawnvpe",
|
| 391 |
+
):
|
| 392 |
+
if hasattr(os, name):
|
| 393 |
+
_REAL[name] = getattr(os, name)
|
| 394 |
+
builtins.open = _open # type: ignore[assignment]
|
| 395 |
+
io.open = _open # type: ignore[assignment]
|
| 396 |
+
os.open = _os_open # type: ignore[assignment]
|
| 397 |
+
os.mkdir = _mkdir # type: ignore[assignment]
|
| 398 |
+
os.makedirs = _makedirs # type: ignore[assignment]
|
| 399 |
+
os.unlink = _unlink # type: ignore[assignment]
|
| 400 |
+
os.remove = _remove # type: ignore[assignment]
|
| 401 |
+
os.rename = _rename # type: ignore[assignment]
|
| 402 |
+
os.replace = _replace # type: ignore[assignment]
|
| 403 |
+
os.rmdir = _rmdir # type: ignore[assignment]
|
| 404 |
+
os.chmod = _chmod # type: ignore[assignment]
|
| 405 |
+
os.chown = _chown # type: ignore[assignment]
|
| 406 |
+
os.symlink = _symlink # type: ignore[assignment]
|
| 407 |
+
os.link = _link # type: ignore[assignment]
|
| 408 |
+
os.utime = _utime # type: ignore[assignment]
|
| 409 |
+
if _REAL.get("truncate") is not None:
|
| 410 |
+
os.truncate = _truncate # type: ignore[assignment]
|
| 411 |
+
if _REAL.get("ftruncate") is not None:
|
| 412 |
+
os.ftruncate = _ftruncate # type: ignore[assignment]
|
| 413 |
+
if _REAL.get("fchmod") is not None:
|
| 414 |
+
os.fchmod = _fchmod # type: ignore[assignment]
|
| 415 |
+
if _REAL.get("lchmod") is not None:
|
| 416 |
+
os.lchmod = _lchmod # type: ignore[assignment]
|
| 417 |
+
shutil.rmtree = _rmtree # type: ignore[assignment]
|
| 418 |
+
shutil.move = _move # type: ignore[assignment]
|
| 419 |
+
if _REAL.get("fork") is not None:
|
| 420 |
+
os.fork = _fork # type: ignore[assignment]
|
| 421 |
+
if _REAL.get("forkpty") is not None:
|
| 422 |
+
os.forkpty = _forkpty # type: ignore[assignment]
|
| 423 |
+
if _REAL.get("posix_spawn") is not None:
|
| 424 |
+
os.posix_spawn = _posix_spawn # type: ignore[assignment]
|
| 425 |
+
if _REAL.get("posix_spawnp") is not None:
|
| 426 |
+
os.posix_spawnp = _posix_spawnp # type: ignore[assignment]
|
| 427 |
+
for name in (
|
| 428 |
+
"spawnl",
|
| 429 |
+
"spawnle",
|
| 430 |
+
"spawnlp",
|
| 431 |
+
"spawnlpe",
|
| 432 |
+
"spawnv",
|
| 433 |
+
"spawnve",
|
| 434 |
+
"spawnvp",
|
| 435 |
+
"spawnvpe",
|
| 436 |
+
):
|
| 437 |
+
if name in _REAL:
|
| 438 |
+
setattr(os, name, _spawn(name))
|
| 439 |
+
os.system = _system # type: ignore[assignment]
|
| 440 |
+
os.popen = _popen_os # type: ignore[assignment]
|
| 441 |
+
os.execv = _exec # type: ignore[assignment]
|
| 442 |
+
os.execve = _exec # type: ignore[assignment]
|
| 443 |
+
subprocess.Popen = _popen # type: ignore[misc, assignment]
|
| 444 |
+
socket.socket = _Guard # type: ignore[misc]
|
| 445 |
+
socket.create_connection = _create_connection # type: ignore[assignment]
|
| 446 |
+
try:
|
| 447 |
+
import multiprocessing
|
| 448 |
+
|
| 449 |
+
def _start(self: object, *args: object, **kwargs: object) -> None:
|
| 450 |
+
_note_process("Process.start", getattr(self, "name", "process"))
|
| 451 |
+
raise AssertionError("unreachable")
|
| 452 |
+
|
| 453 |
+
_REAL["process_start"] = multiprocessing.Process.start
|
| 454 |
+
multiprocessing.Process.start = _start # type: ignore[method-assign]
|
| 455 |
+
except Exception:
|
| 456 |
+
_REAL["process_start"] = None
|
| 457 |
+
_INSTALLED = True
|
| 458 |
+
|
| 459 |
+
|
| 460 |
+
def uninstall_sweep_guard() -> None:
|
| 461 |
+
"""Restore the process-wide functions. Tests use this."""
|
| 462 |
+
|
| 463 |
+
global _INSTALLED
|
| 464 |
+
if not _INSTALLED:
|
| 465 |
+
return
|
| 466 |
+
import shutil
|
| 467 |
+
import socket
|
| 468 |
+
|
| 469 |
+
builtins.open = _REAL["open"]
|
| 470 |
+
io.open = _REAL["open"]
|
| 471 |
+
os.open = _REAL["os_open"]
|
| 472 |
+
os.mkdir = _REAL["mkdir"]
|
| 473 |
+
os.makedirs = _REAL["makedirs"]
|
| 474 |
+
os.unlink = _REAL["unlink"]
|
| 475 |
+
os.remove = _REAL["remove"]
|
| 476 |
+
os.rename = _REAL["rename"]
|
| 477 |
+
os.replace = _REAL["replace"]
|
| 478 |
+
os.rmdir = _REAL["rmdir"]
|
| 479 |
+
os.chmod = _REAL["chmod"]
|
| 480 |
+
os.chown = _REAL["chown"]
|
| 481 |
+
os.symlink = _REAL["symlink"]
|
| 482 |
+
os.link = _REAL["link"]
|
| 483 |
+
os.utime = _REAL["utime"]
|
| 484 |
+
for name in ("truncate", "ftruncate", "fchmod", "lchmod"):
|
| 485 |
+
if _REAL.get(name) is not None:
|
| 486 |
+
setattr(os, name, _REAL[name])
|
| 487 |
+
shutil.rmtree = _REAL["rmtree"]
|
| 488 |
+
shutil.move = _REAL["move"]
|
| 489 |
+
for name in (
|
| 490 |
+
"fork",
|
| 491 |
+
"forkpty",
|
| 492 |
+
"posix_spawn",
|
| 493 |
+
"posix_spawnp",
|
| 494 |
+
"spawnl",
|
| 495 |
+
"spawnle",
|
| 496 |
+
"spawnlp",
|
| 497 |
+
"spawnlpe",
|
| 498 |
+
"spawnv",
|
| 499 |
+
"spawnve",
|
| 500 |
+
"spawnvp",
|
| 501 |
+
"spawnvpe",
|
| 502 |
+
):
|
| 503 |
+
if _REAL.get(name) is not None:
|
| 504 |
+
setattr(os, name, _REAL[name])
|
| 505 |
+
os.system = _REAL["system"]
|
| 506 |
+
os.popen = _REAL["popen"]
|
| 507 |
+
os.execv = _REAL["execv"]
|
| 508 |
+
os.execve = _REAL["execve"]
|
| 509 |
+
subprocess.Popen = _REAL["subprocess_popen"]
|
| 510 |
+
socket.socket = _REAL["socket"]
|
| 511 |
+
socket.create_connection = _REAL["create_connection"]
|
| 512 |
+
if _REAL.get("process_start") is not None:
|
| 513 |
+
import multiprocessing
|
| 514 |
+
|
| 515 |
+
multiprocessing.Process.start = _REAL["process_start"]
|
| 516 |
+
_INSTALLED = False
|
sweep_layout.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Place fake NEXUS and Sero checkouts beside the checkout this process loads.
|
| 2 |
+
|
| 3 |
+
The sweep scripts copy the checkout under an ordinary temp parent and run this
|
| 4 |
+
module from that copy, so the parent is not the filesystem root. There is no
|
| 5 |
+
privilege escalation. A sibling that already exists is left in place.
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
from __future__ import annotations
|
| 9 |
+
|
| 10 |
+
import json
|
| 11 |
+
import shutil
|
| 12 |
+
from pathlib import Path
|
| 13 |
+
|
| 14 |
+
from aureon_public.paths import repo_root
|
| 15 |
+
|
| 16 |
+
SIBLING_NAMES = ("NEXUS-LIVE-FEED-", "Aureon-Trading--Project-Sero")
|
| 17 |
+
_MARKER = ".aureon-sweep-planted"
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def beside() -> Path:
|
| 21 |
+
return repo_root().resolve().parent
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _state_path() -> Path:
|
| 25 |
+
return beside() / ".sweep_siblings.json"
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _fake_source() -> str:
|
| 29 |
+
return (
|
| 30 |
+
"import socket\n"
|
| 31 |
+
"socket.create_connection(('203.0.113.1', 9), timeout=1)\n"
|
| 32 |
+
)
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _write(path: Path, text: str) -> None:
|
| 36 |
+
path.parent.mkdir(parents=True, exist_ok=True)
|
| 37 |
+
path.write_text(text, encoding="utf-8")
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def plant() -> list[str]:
|
| 41 |
+
"""Create any missing sibling. Return the names this process created."""
|
| 42 |
+
|
| 43 |
+
created: list[str] = []
|
| 44 |
+
root = beside()
|
| 45 |
+
files = {
|
| 46 |
+
"NEXUS-LIVE-FEED-": "organism/public_field.py",
|
| 47 |
+
"Aureon-Trading--Project-Sero": "organism/public_market.py",
|
| 48 |
+
}
|
| 49 |
+
for name, relative in files.items():
|
| 50 |
+
folder = root / name
|
| 51 |
+
if folder.exists():
|
| 52 |
+
continue
|
| 53 |
+
_write(folder / relative, _fake_source())
|
| 54 |
+
_write(folder / _MARKER, "planted by aureon public sweep\n")
|
| 55 |
+
created.append(name)
|
| 56 |
+
return created
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
def cleanup(created: list[str]) -> None:
|
| 60 |
+
"""Remove only siblings this process planted."""
|
| 61 |
+
|
| 62 |
+
root = beside()
|
| 63 |
+
for name in created:
|
| 64 |
+
folder = root / name
|
| 65 |
+
marker = folder / _MARKER
|
| 66 |
+
if not marker.is_file():
|
| 67 |
+
continue
|
| 68 |
+
shutil.rmtree(folder)
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def created_names() -> list[str]:
|
| 72 |
+
path = _state_path()
|
| 73 |
+
if not path.is_file():
|
| 74 |
+
return []
|
| 75 |
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
| 76 |
+
if not isinstance(loaded, list):
|
| 77 |
+
return []
|
| 78 |
+
return [str(item) for item in loaded]
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def layout_record(created: list[str] | None = None) -> dict[str, object]:
|
| 82 |
+
root = beside()
|
| 83 |
+
names = created_names() if created is None else created
|
| 84 |
+
return {
|
| 85 |
+
"beside": str(root),
|
| 86 |
+
"created": names,
|
| 87 |
+
"siblings": [
|
| 88 |
+
{
|
| 89 |
+
"name": name,
|
| 90 |
+
"present": (root / name).is_dir(),
|
| 91 |
+
}
|
| 92 |
+
for name in SIBLING_NAMES
|
| 93 |
+
],
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
|
| 97 |
+
def main() -> None:
|
| 98 |
+
import argparse
|
| 99 |
+
|
| 100 |
+
parser = argparse.ArgumentParser(prog="aureon-public-sweep-layout")
|
| 101 |
+
parser.add_argument("--plant", action="store_true")
|
| 102 |
+
parser.add_argument("--cleanup", action="store_true")
|
| 103 |
+
args = parser.parse_args()
|
| 104 |
+
state = _state_path()
|
| 105 |
+
if args.plant:
|
| 106 |
+
created = plant()
|
| 107 |
+
state.write_text(json.dumps(created), encoding="utf-8")
|
| 108 |
+
return
|
| 109 |
+
if args.cleanup and state.is_file():
|
| 110 |
+
created = json.loads(state.read_text(encoding="utf-8"))
|
| 111 |
+
cleanup([str(item) for item in created])
|
| 112 |
+
state.unlink()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
if __name__ == "__main__":
|
| 116 |
+
main()
|
test-requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Test install for the measured venv. Not the public server runtime.
|
| 2 |
+
# measured/aureon_public_stage1_run.sh installs this after requirements.txt.
|
| 3 |
+
# The server runtime stays mcp/aureon_public/requirements.txt.
|
| 4 |
+
pytest>=8.0
|
| 5 |
+
pytest-timeout>=2.3
|
| 6 |
+
flask>=3.0
|
| 7 |
+
pandas>=2.1.0
|
| 8 |
+
scipy>=1.11
|
text.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Descriptions shared by tools, resources, prompts, and the README."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
AURIS_FOUR = (
|
| 6 |
+
"Four meanings stay separate. "
|
| 7 |
+
"The conjecture is the five symbolic-life markers in LambdaEngine and is not called. "
|
| 8 |
+
"The nine nodes are QueenHiveMind.read_auris_nodes and AURIS_NODES. "
|
| 9 |
+
"The persona on QueenHiveMind is not scored. "
|
| 10 |
+
"The coherence evaluator is QueenHiveMind.get_auris_coherence. "
|
| 11 |
+
"Only the nine nodes and get_auris_coherence are real functions exposed here."
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
HOLD_LINE = (
|
| 15 |
+
"Trade readiness: HOLD. "
|
| 16 |
+
"Auris-to-Lambda link: HOLD. "
|
| 17 |
+
"QGITA detection rate: HOLD. "
|
| 18 |
+
"False-alarm rate: HOLD. "
|
| 19 |
+
"Schumann f0: null. HOLD."
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
SERVER_PLAIN = (
|
| 23 |
+
"MCP lets outside models call Aureon's tools. "
|
| 24 |
+
"No outside model or API becomes Aureon's reasoning. "
|
| 25 |
+
"The cognition runs in Aureon's own code."
|
| 26 |
+
)
|
tools.py
ADDED
|
@@ -0,0 +1,805 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The nine public tools. Each returns JSON text. No orders and no state/ writes."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations
|
| 4 |
+
|
| 5 |
+
import csv
|
| 6 |
+
import json
|
| 7 |
+
import math
|
| 8 |
+
import os
|
| 9 |
+
import tempfile
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
from typing import Any
|
| 12 |
+
|
| 13 |
+
from aureon_public import paths
|
| 14 |
+
from aureon_public.guard_loader import aureon_source
|
| 15 |
+
from aureon_public.quiet import quiet
|
| 16 |
+
from aureon_public.text import AURIS_FOUR, HOLD_LINE
|
| 17 |
+
|
| 18 |
+
_AURIS_FIELDS = ("volatility", "momentum", "volume", "spread")
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _plain(value: Any) -> Any:
|
| 22 |
+
if isinstance(value, dict):
|
| 23 |
+
return {str(key): _plain(item) for key, item in value.items()}
|
| 24 |
+
if isinstance(value, (list, tuple)):
|
| 25 |
+
return [_plain(item) for item in value]
|
| 26 |
+
if isinstance(value, bool) or value is None or isinstance(value, str):
|
| 27 |
+
return value
|
| 28 |
+
if isinstance(value, int):
|
| 29 |
+
return int(value)
|
| 30 |
+
if isinstance(value, float):
|
| 31 |
+
return float(value)
|
| 32 |
+
item = getattr(value, "item", None)
|
| 33 |
+
if callable(item):
|
| 34 |
+
try:
|
| 35 |
+
return _plain(item())
|
| 36 |
+
except Exception:
|
| 37 |
+
pass
|
| 38 |
+
return str(value)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
_OMITTED_PUBLIC_KEYS = ("consciousness_level", "consciousness_psi")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def _omit_public_keys(body: dict[str, Any]) -> dict[str, Any]:
|
| 45 |
+
for key in _OMITTED_PUBLIC_KEYS:
|
| 46 |
+
body.pop(key, None)
|
| 47 |
+
return body
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def _strip_consciousness(value: Any) -> Any:
|
| 51 |
+
if isinstance(value, dict):
|
| 52 |
+
return {
|
| 53 |
+
str(key): _strip_consciousness(item)
|
| 54 |
+
for key, item in value.items()
|
| 55 |
+
if not str(key).startswith("consciousness_")
|
| 56 |
+
}
|
| 57 |
+
if isinstance(value, list):
|
| 58 |
+
return [_strip_consciousness(item) for item in value]
|
| 59 |
+
return value
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def _dumps(payload: dict[str, Any]) -> str:
|
| 63 |
+
body = _strip_consciousness(_plain(payload))
|
| 64 |
+
body["aureon_source"] = aureon_source()
|
| 65 |
+
return json.dumps(body, ensure_ascii=False, allow_nan=False, sort_keys=True)
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _load(path: Path) -> dict[str, Any]:
|
| 69 |
+
loaded = json.loads(path.read_text(encoding="utf-8"))
|
| 70 |
+
if not isinstance(loaded, dict):
|
| 71 |
+
raise TypeError(path.name)
|
| 72 |
+
return loaded
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def _finite(value: object) -> float | None:
|
| 76 |
+
if isinstance(value, bool) or value is None:
|
| 77 |
+
return None
|
| 78 |
+
if not isinstance(value, (int, float)):
|
| 79 |
+
return None
|
| 80 |
+
number = float(value)
|
| 81 |
+
if not math.isfinite(number):
|
| 82 |
+
return None
|
| 83 |
+
return number
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def _brain() -> dict[str, Any]:
|
| 87 |
+
return _load(paths.brain_json())
|
| 88 |
+
|
| 89 |
+
|
| 90 |
+
def _path_block(brain: dict[str, Any], enable_multiverse: bool) -> dict[str, Any]:
|
| 91 |
+
hnc = brain.get("hnc")
|
| 92 |
+
if not isinstance(hnc, dict):
|
| 93 |
+
raise KeyError("hnc")
|
| 94 |
+
if enable_multiverse:
|
| 95 |
+
block = hnc.get("multiverse_extension")
|
| 96 |
+
else:
|
| 97 |
+
block = hnc
|
| 98 |
+
if not isinstance(block, dict):
|
| 99 |
+
raise KeyError("brain path")
|
| 100 |
+
return block
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def _cap(enable_multiverse: bool) -> int:
|
| 104 |
+
steps = _path_block(_brain(), enable_multiverse).get("steps")
|
| 105 |
+
if isinstance(steps, bool) or not isinstance(steps, int) or steps < 1:
|
| 106 |
+
raise ValueError("committed step count is missing")
|
| 107 |
+
return steps
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def _hnc_doc() -> str:
|
| 111 |
+
brain = _brain()
|
| 112 |
+
on = json.dumps(_path_block(brain, True)["coherence"])
|
| 113 |
+
off = json.dumps(_path_block(brain, False)["coherence"])
|
| 114 |
+
return f"""Call HarmonicRealityField.step. Label: inferred. This is a rerun in this process.
|
| 115 |
+
|
| 116 |
+
The class default HarmonicRealityField() sets enable_multiverse=True (multiverse on). This tool's default is that class default. The output field enable_multiverse is the value used for this call.
|
| 117 |
+
|
| 118 |
+
Do not mix the two committed brain paths. Cited, huggingface/hnc-field/replay/brain.json: multiverse on coherence is {on}; multiverse off coherence is {off}.
|
| 119 |
+
|
| 120 |
+
steps is capped at the committed steps field for the selected path. There is no frequencies argument. Trade readiness: HOLD. {HOLD_LINE}
|
| 121 |
+
|
| 122 |
+
Args:
|
| 123 |
+
alpha: Observer gain passed to HarmonicRealityField. Label: cited, DEFAULT_ALPHA in aureon/harmonic/aureon_harmonic_reality.py.
|
| 124 |
+
beta: Echo gain passed to HarmonicRealityField. Label: cited, DEFAULT_BETA.
|
| 125 |
+
tau: Echo delay passed to HarmonicRealityField. Label: cited, DEFAULT_TAU.
|
| 126 |
+
g: Observer nonlinearity passed to HarmonicRealityField. Label: cited, DEFAULT_G.
|
| 127 |
+
delta_t: Observer window passed to HarmonicRealityField. Label: cited, DEFAULT_DELTA_T.
|
| 128 |
+
sample_rate: Samples per second. Signature default 1000.0. Label: cited, HarmonicRealityField.__init__.
|
| 129 |
+
enable_multiverse: Class default is True (multiverse on). False selects the other committed brain path. Reported in the output. Label: cited.
|
| 130 |
+
steps: Step count. Omitted uses the committed steps for the selected path. Values above that cap are unavailable. Label: cited, vendored brain.json steps.
|
| 131 |
+
"""
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
@quiet
|
| 135 |
+
def hnc_reality_step(
|
| 136 |
+
alpha: float = 0.85,
|
| 137 |
+
beta: float = 0.9,
|
| 138 |
+
tau: float = 0.05,
|
| 139 |
+
g: float = 1.5,
|
| 140 |
+
delta_t: float = 0.01,
|
| 141 |
+
sample_rate: float = 1000.0,
|
| 142 |
+
enable_multiverse: bool = True,
|
| 143 |
+
steps: int | None = None,
|
| 144 |
+
) -> str:
|
| 145 |
+
turned_on = enable_multiverse is True
|
| 146 |
+
if not isinstance(enable_multiverse, bool):
|
| 147 |
+
return _dumps(
|
| 148 |
+
{
|
| 149 |
+
"class_default_enable_multiverse": True,
|
| 150 |
+
"enable_multiverse": None,
|
| 151 |
+
"label": "cited",
|
| 152 |
+
"reason": "enable_multiverse is missing",
|
| 153 |
+
"status": "unavailable",
|
| 154 |
+
}
|
| 155 |
+
)
|
| 156 |
+
try:
|
| 157 |
+
cap = _cap(turned_on)
|
| 158 |
+
except (OSError, ValueError, KeyError, TypeError):
|
| 159 |
+
return _dumps(
|
| 160 |
+
{
|
| 161 |
+
"class_default_enable_multiverse": True,
|
| 162 |
+
"enable_multiverse": turned_on,
|
| 163 |
+
"label": "cited",
|
| 164 |
+
"reason": "The committed step count is missing.",
|
| 165 |
+
"status": "unavailable",
|
| 166 |
+
}
|
| 167 |
+
)
|
| 168 |
+
chosen: int | None
|
| 169 |
+
if steps is None:
|
| 170 |
+
chosen = cap
|
| 171 |
+
elif isinstance(steps, bool) or not isinstance(steps, int) or steps < 1:
|
| 172 |
+
chosen = None
|
| 173 |
+
elif steps > cap:
|
| 174 |
+
return _dumps(
|
| 175 |
+
{
|
| 176 |
+
"class_default_enable_multiverse": True,
|
| 177 |
+
"enable_multiverse": turned_on,
|
| 178 |
+
"label": "cited. The cap is the steps field on the selected brain path.",
|
| 179 |
+
"reason": "steps is above the committed replay length for this path",
|
| 180 |
+
"status": "unavailable",
|
| 181 |
+
"steps_cap": cap,
|
| 182 |
+
}
|
| 183 |
+
)
|
| 184 |
+
else:
|
| 185 |
+
chosen = steps
|
| 186 |
+
numbers = {
|
| 187 |
+
"alpha": _finite(alpha),
|
| 188 |
+
"beta": _finite(beta),
|
| 189 |
+
"tau": _finite(tau),
|
| 190 |
+
"g": _finite(g),
|
| 191 |
+
"delta_t": _finite(delta_t),
|
| 192 |
+
"sample_rate": _finite(sample_rate),
|
| 193 |
+
}
|
| 194 |
+
if (
|
| 195 |
+
chosen is None
|
| 196 |
+
or any(value is None for value in numbers.values())
|
| 197 |
+
or numbers["sample_rate"] is None
|
| 198 |
+
or numbers["sample_rate"] <= 0
|
| 199 |
+
):
|
| 200 |
+
return _dumps(
|
| 201 |
+
{
|
| 202 |
+
"class_default_enable_multiverse": True,
|
| 203 |
+
"enable_multiverse": turned_on,
|
| 204 |
+
"label": "cited",
|
| 205 |
+
"reason": "A parameter is missing.",
|
| 206 |
+
"status": "unavailable",
|
| 207 |
+
"steps_cap": cap,
|
| 208 |
+
}
|
| 209 |
+
)
|
| 210 |
+
from aureon.harmonic.aureon_harmonic_reality import HarmonicRealityField
|
| 211 |
+
|
| 212 |
+
field = HarmonicRealityField(
|
| 213 |
+
alpha=float(numbers["alpha"]),
|
| 214 |
+
beta=float(numbers["beta"]),
|
| 215 |
+
tau=float(numbers["tau"]),
|
| 216 |
+
g=float(numbers["g"]),
|
| 217 |
+
delta_t=float(numbers["delta_t"]),
|
| 218 |
+
sample_rate=float(numbers["sample_rate"]),
|
| 219 |
+
enable_multiverse=turned_on,
|
| 220 |
+
)
|
| 221 |
+
series = [float(field.step()) for _ in range(chosen)]
|
| 222 |
+
payload: dict[str, Any] = {
|
| 223 |
+
"class_default_enable_multiverse": True,
|
| 224 |
+
"coherence": float(field.coherence),
|
| 225 |
+
"committed_replay_match": None,
|
| 226 |
+
"committed_replay_path": "multiverse_extension" if turned_on else "hnc",
|
| 227 |
+
"enable_multiverse": bool(field.enable_multiverse),
|
| 228 |
+
"get_state": field.get_state(),
|
| 229 |
+
"label": "inferred. Rerun of HarmonicRealityField.step in this process.",
|
| 230 |
+
"lambda_last": series[-1],
|
| 231 |
+
"series": series,
|
| 232 |
+
"state_name": field.state.name,
|
| 233 |
+
"state_value": field.state.value,
|
| 234 |
+
"status": "inferred",
|
| 235 |
+
"steps": chosen,
|
| 236 |
+
"steps_cap": cap,
|
| 237 |
+
}
|
| 238 |
+
payload["committed_replay_match"] = _committed_match(
|
| 239 |
+
payload,
|
| 240 |
+
{key: float(value) for key, value in numbers.items()},
|
| 241 |
+
turned_on,
|
| 242 |
+
)
|
| 243 |
+
return _dumps(payload)
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def _committed_match(payload: dict[str, Any], numbers: dict[str, float], enable_multiverse: bool) -> bool | None:
|
| 247 |
+
brain = _brain()
|
| 248 |
+
parameters = brain.get("hnc", {}).get("parameters")
|
| 249 |
+
if not isinstance(parameters, dict):
|
| 250 |
+
return None
|
| 251 |
+
expected = {
|
| 252 |
+
"alpha": parameters.get("alpha"),
|
| 253 |
+
"beta": parameters.get("beta"),
|
| 254 |
+
"delta_t": parameters.get("delta_t"),
|
| 255 |
+
"g": parameters.get("g"),
|
| 256 |
+
"sample_rate": parameters.get("sample_rate"),
|
| 257 |
+
"tau": parameters.get("tau"),
|
| 258 |
+
}
|
| 259 |
+
if any(numbers[key] != expected[key] for key in expected):
|
| 260 |
+
return None
|
| 261 |
+
block = _path_block(brain, enable_multiverse)
|
| 262 |
+
if payload["steps"] != block.get("steps"):
|
| 263 |
+
return None
|
| 264 |
+
fresh = {
|
| 265 |
+
"coherence": payload["coherence"],
|
| 266 |
+
"lambda_last": payload["lambda_last"],
|
| 267 |
+
"series": payload["series"],
|
| 268 |
+
}
|
| 269 |
+
rounded = json.loads(json.dumps(fresh))
|
| 270 |
+
return (
|
| 271 |
+
rounded["coherence"] == block.get("coherence")
|
| 272 |
+
and rounded["lambda_last"] == block.get("lambda_last")
|
| 273 |
+
and rounded["series"] == block.get("series")
|
| 274 |
+
and payload["state_value"] == block.get("state")
|
| 275 |
+
)
|
| 276 |
+
|
| 277 |
+
|
| 278 |
+
hnc_reality_step.__doc__ = _hnc_doc()
|
| 279 |
+
|
| 280 |
+
|
| 281 |
+
@quiet
|
| 282 |
+
def hnc_canonical_read(envelope_jsonl: str | None = None) -> str:
|
| 283 |
+
"""Read CanonicalField. An empty envelope does not touch state/.
|
| 284 |
+
|
| 285 |
+
The public JSON drops consciousness_level and consciousness_psi. Those fields have defaults on CanonicalField, so CanonicalField(**public_dict) still constructs and does not raise. It is not a full to_dict() round-trip: the rebuilt fields are the defaults, not whatever to_dict() would have carried.
|
| 286 |
+
|
| 287 |
+
Label: inferred when an envelope was supplied and available is true. Otherwise the field is unavailable. Cited: read_canonical_field does not run unless a temp trace was set. The bundled brain replay is a formula record, not a canonical envelope.
|
| 288 |
+
|
| 289 |
+
Args:
|
| 290 |
+
envelope_jsonl: Optional JSONL text for one canonical envelope. Empty or omitted returns the unavailable field and does not read state/. Label: cited, aureon/core/hnc_field.py read_canonical_field.
|
| 291 |
+
"""
|
| 292 |
+
|
| 293 |
+
if envelope_jsonl is None or not str(envelope_jsonl).strip():
|
| 294 |
+
from aureon.core.hnc_field import CanonicalField
|
| 295 |
+
|
| 296 |
+
body = CanonicalField().to_dict()
|
| 297 |
+
body["label"] = (
|
| 298 |
+
"cited. No envelope was supplied, so state/ was not read. "
|
| 299 |
+
"The bundled brain replay is a formula record, not a canonical envelope."
|
| 300 |
+
)
|
| 301 |
+
body["status"] = "unavailable"
|
| 302 |
+
return _dumps(_omit_public_keys(body))
|
| 303 |
+
return _dumps(_omit_public_keys(_with_envelope(str(envelope_jsonl), blend=False)))
|
| 304 |
+
|
| 305 |
+
|
| 306 |
+
@quiet
|
| 307 |
+
def hnc_blend_read(envelope_jsonl: str | None = None) -> str:
|
| 308 |
+
"""Read BlendedField. Does not call publish_subfield. An empty envelope does not touch state/.
|
| 309 |
+
|
| 310 |
+
BlendedField.to_dict does not include consciousness_level or consciousness_psi. The same two keys are dropped if they appear. That drop does not change a BlendedField round-trip.
|
| 311 |
+
|
| 312 |
+
Label: inferred when an envelope was supplied and available is true. Otherwise unavailable.
|
| 313 |
+
|
| 314 |
+
Args:
|
| 315 |
+
envelope_jsonl: Optional JSONL text. Empty or omitted returns the unavailable blend and does not read state/. Label: cited, aureon/core/hnc_field.py blend_field.
|
| 316 |
+
"""
|
| 317 |
+
|
| 318 |
+
if envelope_jsonl is None or not str(envelope_jsonl).strip():
|
| 319 |
+
from aureon.core.hnc_field import BlendedField
|
| 320 |
+
|
| 321 |
+
body = BlendedField().to_dict()
|
| 322 |
+
body["label"] = "cited. No envelope was supplied, so state/ was not read."
|
| 323 |
+
body["status"] = "unavailable"
|
| 324 |
+
return _dumps(_omit_public_keys(body))
|
| 325 |
+
return _dumps(_omit_public_keys(_with_envelope(str(envelope_jsonl), blend=True)))
|
| 326 |
+
|
| 327 |
+
|
| 328 |
+
def _with_envelope(text: str, *, blend: bool) -> dict[str, Any]:
|
| 329 |
+
from aureon.core.hnc_field import blend_field, read_canonical_field
|
| 330 |
+
|
| 331 |
+
previous_trace = os.environ.get("AUREON_HNC_TRACE_PATH")
|
| 332 |
+
previous_bus = os.environ.get("AUREON_BUS_TRACE_DIR")
|
| 333 |
+
directory = Path(tempfile.mkdtemp(prefix="aureon-public-field-"))
|
| 334 |
+
trace = directory / "envelope.jsonl"
|
| 335 |
+
bus_dir = directory / "bus"
|
| 336 |
+
bus_dir.mkdir()
|
| 337 |
+
try:
|
| 338 |
+
payload = text if text.endswith("\n") else text + "\n"
|
| 339 |
+
trace.write_text(payload, encoding="utf-8")
|
| 340 |
+
os.environ["AUREON_HNC_TRACE_PATH"] = str(trace)
|
| 341 |
+
os.environ["AUREON_BUS_TRACE_DIR"] = str(bus_dir)
|
| 342 |
+
field = read_canonical_field(bus=object())
|
| 343 |
+
if blend:
|
| 344 |
+
body = blend_field(bus=object()).to_dict()
|
| 345 |
+
else:
|
| 346 |
+
body = field.to_dict()
|
| 347 |
+
finally:
|
| 348 |
+
if previous_trace is None:
|
| 349 |
+
os.environ.pop("AUREON_HNC_TRACE_PATH", None)
|
| 350 |
+
else:
|
| 351 |
+
os.environ["AUREON_HNC_TRACE_PATH"] = previous_trace
|
| 352 |
+
if previous_bus is None:
|
| 353 |
+
os.environ.pop("AUREON_BUS_TRACE_DIR", None)
|
| 354 |
+
else:
|
| 355 |
+
os.environ["AUREON_BUS_TRACE_DIR"] = previous_bus
|
| 356 |
+
trace.unlink(missing_ok=True)
|
| 357 |
+
for child in bus_dir.glob("*"):
|
| 358 |
+
child.unlink(missing_ok=True)
|
| 359 |
+
bus_dir.rmdir()
|
| 360 |
+
directory.rmdir()
|
| 361 |
+
body["label"] = "inferred. Read from the envelope supplied to this process."
|
| 362 |
+
body["status"] = "inferred" if body.get("available") is True else "unavailable"
|
| 363 |
+
return body
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
@quiet
|
| 367 |
+
def lambda_engine_step(
|
| 368 |
+
volatility: float | None = None,
|
| 369 |
+
readings: list[dict[str, Any]] | None = None,
|
| 370 |
+
) -> str:
|
| 371 |
+
"""Run LambdaEngine.step, or return status unavailable.
|
| 372 |
+
|
| 373 |
+
This is not HarmonicRealityField and it is not the committed brain replay. The committed replay ships no readings. A missing or short reading list returns status unavailable and does not fill lambda or coherence with 0. Auris-to-Lambda link: HOLD.
|
| 374 |
+
|
| 375 |
+
Args:
|
| 376 |
+
volatility: Finite volatility. Omitted is unavailable, not 0. Label: cited, LambdaEngine.step.
|
| 377 |
+
readings: Objects with name, value, confidence, and state. Fewer than two returns status unavailable. Label: cited, huggingface/hnc-field/app.py. Auris-to-Lambda link: HOLD.
|
| 378 |
+
"""
|
| 379 |
+
|
| 380 |
+
parsed, reason = _parse_readings(readings)
|
| 381 |
+
vol = _finite(volatility)
|
| 382 |
+
if parsed is None or vol is None:
|
| 383 |
+
why = reason or "volatility is missing"
|
| 384 |
+
return _dumps(
|
| 385 |
+
{
|
| 386 |
+
"auris_to_lambda": "HOLD",
|
| 387 |
+
"label": (
|
| 388 |
+
"cited. The committed brain replay ships no LambdaEngine readings. "
|
| 389 |
+
"This is not HarmonicRealityField. Auris-to-Lambda link: HOLD."
|
| 390 |
+
),
|
| 391 |
+
"lambda_t": None,
|
| 392 |
+
"reason": why,
|
| 393 |
+
"status": "unavailable",
|
| 394 |
+
}
|
| 395 |
+
)
|
| 396 |
+
fd, name = tempfile.mkstemp(prefix="aureon-public-lambda-", suffix=".json")
|
| 397 |
+
os.close(fd)
|
| 398 |
+
path = Path(name)
|
| 399 |
+
try:
|
| 400 |
+
from aureon.core.aureon_lambda_engine import LambdaEngine, SubsystemReading
|
| 401 |
+
|
| 402 |
+
engine = LambdaEngine(state_path=path)
|
| 403 |
+
state = engine.step(parsed_readings(parsed, SubsystemReading), volatility=vol, auto_persist=False)
|
| 404 |
+
body = state.to_dict()
|
| 405 |
+
finally:
|
| 406 |
+
path.unlink(missing_ok=True)
|
| 407 |
+
body["auris_to_lambda"] = "HOLD"
|
| 408 |
+
body["label"] = (
|
| 409 |
+
"inferred. LambdaEngine.step on the supplied readings. "
|
| 410 |
+
"Not HarmonicRealityField. Not the committed brain replay. "
|
| 411 |
+
"Field names are the keys LambdaState.to_dict already returns. "
|
| 412 |
+
"Auris-to-Lambda link: HOLD."
|
| 413 |
+
)
|
| 414 |
+
body["status"] = "inferred"
|
| 415 |
+
return _dumps(body)
|
| 416 |
+
|
| 417 |
+
|
| 418 |
+
def parsed_readings(rows: list[dict[str, Any]], reading_type: Any) -> list[Any]:
|
| 419 |
+
return [
|
| 420 |
+
reading_type(
|
| 421 |
+
name=row["name"],
|
| 422 |
+
value=row["value"],
|
| 423 |
+
confidence=row["confidence"],
|
| 424 |
+
state=row["state"],
|
| 425 |
+
)
|
| 426 |
+
for row in rows
|
| 427 |
+
]
|
| 428 |
+
|
| 429 |
+
|
| 430 |
+
def _parse_readings(readings: list[dict[str, Any]] | None) -> tuple[list[dict[str, Any]] | None, str | None]:
|
| 431 |
+
if readings is None:
|
| 432 |
+
return None, "LambdaEngine path: unavailable. No readings were supplied."
|
| 433 |
+
if not isinstance(readings, list) or len(readings) < 2:
|
| 434 |
+
return None, "LambdaEngine path: unavailable. At least two readings are required."
|
| 435 |
+
parsed: list[dict[str, Any]] = []
|
| 436 |
+
for row in readings:
|
| 437 |
+
if not isinstance(row, dict):
|
| 438 |
+
return None, "LambdaEngine path: unavailable. A reading is missing fields."
|
| 439 |
+
name = row.get("name")
|
| 440 |
+
value = _finite(row.get("value"))
|
| 441 |
+
confidence = _finite(row.get("confidence"))
|
| 442 |
+
state = row.get("state")
|
| 443 |
+
if not isinstance(name, str) or not name.strip() or value is None or confidence is None:
|
| 444 |
+
return None, "LambdaEngine path: unavailable. A reading is missing fields."
|
| 445 |
+
if not isinstance(state, str) or not state.strip():
|
| 446 |
+
return None, "LambdaEngine path: unavailable. A reading is missing fields."
|
| 447 |
+
parsed.append(
|
| 448 |
+
{
|
| 449 |
+
"name": name.strip(),
|
| 450 |
+
"value": value,
|
| 451 |
+
"confidence": confidence,
|
| 452 |
+
"state": state.strip(),
|
| 453 |
+
}
|
| 454 |
+
)
|
| 455 |
+
return parsed, None
|
| 456 |
+
|
| 457 |
+
|
| 458 |
+
def _texture(
|
| 459 |
+
volatility: float | None,
|
| 460 |
+
momentum: float | None,
|
| 461 |
+
volume: float | None,
|
| 462 |
+
spread: float | None,
|
| 463 |
+
) -> dict[str, float] | None:
|
| 464 |
+
supplied: dict[str, float] = {}
|
| 465 |
+
for key, raw in (
|
| 466 |
+
("volatility", volatility),
|
| 467 |
+
("momentum", momentum),
|
| 468 |
+
("volume", volume),
|
| 469 |
+
("spread", spread),
|
| 470 |
+
):
|
| 471 |
+
if raw is None:
|
| 472 |
+
continue
|
| 473 |
+
number = _finite(raw)
|
| 474 |
+
if number is None:
|
| 475 |
+
continue
|
| 476 |
+
supplied[key] = number
|
| 477 |
+
return supplied or None
|
| 478 |
+
|
| 479 |
+
|
| 480 |
+
def _queen() -> Any:
|
| 481 |
+
from aureon.utils.aureon_queen_hive_mind import QueenHiveMind
|
| 482 |
+
|
| 483 |
+
return QueenHiveMind.__new__(QueenHiveMind)
|
| 484 |
+
|
| 485 |
+
|
| 486 |
+
@quiet
|
| 487 |
+
def auris_nodes(
|
| 488 |
+
volatility: float | None = None,
|
| 489 |
+
momentum: float | None = None,
|
| 490 |
+
volume: float | None = None,
|
| 491 |
+
spread: float | None = None,
|
| 492 |
+
) -> str:
|
| 493 |
+
"""Nine nodes. Real function: QueenHiveMind.read_auris_nodes.
|
| 494 |
+
|
| 495 |
+
This tool is the nine nodes. It is not the conjecture (not called), not the persona (not scored), and not the coherence evaluator. The coherence evaluator is auris_coherence. Only the nine nodes and get_auris_coherence are real functions exposed here.
|
| 496 |
+
|
| 497 |
+
A missing field is omitted. Nothing is filled with zero. Label: inferred.
|
| 498 |
+
|
| 499 |
+
Args:
|
| 500 |
+
volatility: Optional Tiger and related input. Omitted stays omitted. Label: cited, _auris_input.
|
| 501 |
+
momentum: Optional Falcon and Dolphin input. Omitted stays omitted. Label: cited, _auris_input.
|
| 502 |
+
volume: Optional Falcon and CargoShip input. Omitted stays omitted. Label: cited, _auris_input.
|
| 503 |
+
spread: Optional Deer input. Omitted stays omitted. Label: cited, _auris_input.
|
| 504 |
+
"""
|
| 505 |
+
|
| 506 |
+
market = _texture(volatility, momentum, volume, spread)
|
| 507 |
+
nodes = _queen().read_auris_nodes(market)
|
| 508 |
+
missing = sorted(name for name, row in nodes.items() if row.get("value") is None)
|
| 509 |
+
return _dumps(
|
| 510 |
+
{
|
| 511 |
+
"auris": "nine nodes",
|
| 512 |
+
"label": "inferred. QueenHiveMind.read_auris_nodes. A missing field is not filled.",
|
| 513 |
+
"missing_nodes": missing,
|
| 514 |
+
"nodes": nodes,
|
| 515 |
+
"which_auris": AURIS_FOUR,
|
| 516 |
+
}
|
| 517 |
+
)
|
| 518 |
+
|
| 519 |
+
|
| 520 |
+
@quiet
|
| 521 |
+
def auris_coherence(
|
| 522 |
+
volatility: float | None = None,
|
| 523 |
+
momentum: float | None = None,
|
| 524 |
+
volume: float | None = None,
|
| 525 |
+
spread: float | None = None,
|
| 526 |
+
) -> str:
|
| 527 |
+
"""Coherence evaluator. Real function: QueenHiveMind.get_auris_coherence.
|
| 528 |
+
|
| 529 |
+
This tool is the coherence evaluator. It is not the conjecture (not called), not the nine nodes (those are read_auris_nodes and AURIS_NODES on auris_nodes), and not the persona (not scored). Only the nine nodes and get_auris_coherence are real functions exposed here.
|
| 530 |
+
|
| 531 |
+
Whenever any of the nine nodes has no reading, status is no_data and coherence is null. The missing node names are listed. Nothing is filled with zero. Auris-to-Lambda link: HOLD. Trade readiness: HOLD.
|
| 532 |
+
|
| 533 |
+
Args:
|
| 534 |
+
volatility: Optional. Omitted is not filled with zero. Label: cited, _auris_input.
|
| 535 |
+
momentum: Optional. Omitted is not filled with zero. Label: cited, _auris_input.
|
| 536 |
+
volume: Optional. Omitted is not filled with zero. Label: cited, _auris_input.
|
| 537 |
+
spread: Optional. Omitted is not filled with zero. Label: cited, _auris_input.
|
| 538 |
+
"""
|
| 539 |
+
|
| 540 |
+
market = _texture(volatility, momentum, volume, spread)
|
| 541 |
+
queen = _queen()
|
| 542 |
+
nodes = queen.read_auris_nodes(market)
|
| 543 |
+
coherence, status = queen.get_auris_coherence(market)
|
| 544 |
+
missing = sorted(name for name, row in nodes.items() if row.get("value") is None)
|
| 545 |
+
if missing or coherence is None:
|
| 546 |
+
return _dumps(
|
| 547 |
+
{
|
| 548 |
+
"auris": "coherence evaluator",
|
| 549 |
+
"auris_to_lambda": "HOLD",
|
| 550 |
+
"coherence": None,
|
| 551 |
+
"label": "inferred. get_auris_coherence returned no complete nine-node reading. Auris-to-Lambda link: HOLD.",
|
| 552 |
+
"missing_nodes": missing,
|
| 553 |
+
"status": "no_data",
|
| 554 |
+
"trade_readiness": "HOLD",
|
| 555 |
+
"which_auris": AURIS_FOUR,
|
| 556 |
+
}
|
| 557 |
+
)
|
| 558 |
+
return _dumps(
|
| 559 |
+
{
|
| 560 |
+
"auris": "coherence evaluator",
|
| 561 |
+
"auris_to_lambda": "HOLD",
|
| 562 |
+
"coherence": coherence,
|
| 563 |
+
"label": "inferred. This is the evaluator return, not a track record. Auris-to-Lambda link: HOLD.",
|
| 564 |
+
"missing_nodes": missing,
|
| 565 |
+
"status": status,
|
| 566 |
+
"trade_readiness": "HOLD",
|
| 567 |
+
"which_auris": AURIS_FOUR,
|
| 568 |
+
}
|
| 569 |
+
)
|
| 570 |
+
|
| 571 |
+
|
| 572 |
+
def _lambda_column() -> list[float]:
|
| 573 |
+
path = paths.qgita_series()
|
| 574 |
+
values: list[float] = []
|
| 575 |
+
with path.open(encoding="utf-8", newline="") as handle:
|
| 576 |
+
reader = csv.DictReader(handle)
|
| 577 |
+
if reader.fieldnames is None or "Lambda" not in reader.fieldnames:
|
| 578 |
+
return []
|
| 579 |
+
for row in reader:
|
| 580 |
+
try:
|
| 581 |
+
values.append(float(row["Lambda"]))
|
| 582 |
+
except (TypeError, ValueError):
|
| 583 |
+
continue
|
| 584 |
+
return values
|
| 585 |
+
|
| 586 |
+
|
| 587 |
+
def _event_record(item: Any, kind: str) -> dict[str, Any]:
|
| 588 |
+
if kind == "ftcp":
|
| 589 |
+
return {
|
| 590 |
+
"adapter": "QGITAMarketAnalyzer.analyze",
|
| 591 |
+
"curvature": float(item.curvature),
|
| 592 |
+
"is_valid": bool(item.is_valid),
|
| 593 |
+
"kind": "FTCP",
|
| 594 |
+
"knot_index": int(item.knot_index),
|
| 595 |
+
"timestamp": float(item.timestamp),
|
| 596 |
+
}
|
| 597 |
+
return {
|
| 598 |
+
"adapter": "QGITAMarketAnalyzer.analyze",
|
| 599 |
+
"event_type": str(item.event_type.value),
|
| 600 |
+
"kind": "lighthouse",
|
| 601 |
+
"lighthouse_intensity": float(item.lighthouse_intensity),
|
| 602 |
+
"timestamp": float(item.timestamp),
|
| 603 |
+
}
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
@quiet
|
| 607 |
+
def qgita_analyze(
|
| 608 |
+
values: list[float] | None = None,
|
| 609 |
+
timestamps: list[float] | None = None,
|
| 610 |
+
) -> str:
|
| 611 |
+
"""Run QGITAMarketAnalyzer.analyze and drop the signals object.
|
| 612 |
+
|
| 613 |
+
Events are the adapter return, not a detection rate. Detection rate: HOLD. False-alarm rate: HOLD. The bundled series is cited-unverified and is not public market data.
|
| 614 |
+
|
| 615 |
+
Args:
|
| 616 |
+
values: Optional series. Omitted loads the vendored de440 Lambda column. A supplied series is inferred and is not the committed replay. Length must be at least 10. Label: cited for the file, inferred for a pasted series.
|
| 617 |
+
timestamps: Optional clocks, one per value. Omitted uses the sample index. Label: cited, the Space clock.
|
| 618 |
+
"""
|
| 619 |
+
|
| 620 |
+
supplied = values is not None
|
| 621 |
+
series = list(values) if supplied else _lambda_column()
|
| 622 |
+
if supplied:
|
| 623 |
+
cleaned: list[float] = []
|
| 624 |
+
for item in series:
|
| 625 |
+
number = _finite(item)
|
| 626 |
+
if number is None:
|
| 627 |
+
return _dumps(
|
| 628 |
+
{
|
| 629 |
+
"detection_rate": "HOLD",
|
| 630 |
+
"false_alarm_rate": "HOLD",
|
| 631 |
+
"label": "inferred",
|
| 632 |
+
"reason": "A value is missing.",
|
| 633 |
+
"status": "unavailable",
|
| 634 |
+
}
|
| 635 |
+
)
|
| 636 |
+
cleaned.append(number)
|
| 637 |
+
series = cleaned
|
| 638 |
+
if len(series) < 10:
|
| 639 |
+
return _dumps(
|
| 640 |
+
{
|
| 641 |
+
"detection_rate": "HOLD",
|
| 642 |
+
"false_alarm_rate": "HOLD",
|
| 643 |
+
"label": "cited. analyze returns insufficient_data below 10 samples.",
|
| 644 |
+
"reason": "At least ten values are required.",
|
| 645 |
+
"status": "unavailable",
|
| 646 |
+
}
|
| 647 |
+
)
|
| 648 |
+
if timestamps is None:
|
| 649 |
+
clocks = [float(index) for index in range(len(series))]
|
| 650 |
+
clock_label = "cited. Sample index, the Space clock."
|
| 651 |
+
else:
|
| 652 |
+
if len(timestamps) != len(series):
|
| 653 |
+
return _dumps(
|
| 654 |
+
{
|
| 655 |
+
"detection_rate": "HOLD",
|
| 656 |
+
"false_alarm_rate": "HOLD",
|
| 657 |
+
"label": "inferred",
|
| 658 |
+
"reason": "timestamps and values differ in length.",
|
| 659 |
+
"status": "unavailable",
|
| 660 |
+
}
|
| 661 |
+
)
|
| 662 |
+
clocks = []
|
| 663 |
+
for item in timestamps:
|
| 664 |
+
number = _finite(item)
|
| 665 |
+
if number is None:
|
| 666 |
+
return _dumps(
|
| 667 |
+
{
|
| 668 |
+
"detection_rate": "HOLD",
|
| 669 |
+
"false_alarm_rate": "HOLD",
|
| 670 |
+
"label": "inferred",
|
| 671 |
+
"reason": "A timestamp is missing.",
|
| 672 |
+
"status": "unavailable",
|
| 673 |
+
}
|
| 674 |
+
)
|
| 675 |
+
clocks.append(number)
|
| 676 |
+
clock_label = "inferred. Caller-supplied clocks."
|
| 677 |
+
from aureon.wisdom.aureon_qgita_framework import QGITAMarketAnalyzer
|
| 678 |
+
|
| 679 |
+
analyzer = QGITAMarketAnalyzer()
|
| 680 |
+
for index, value in enumerate(series):
|
| 681 |
+
analyzer.feed_price(float(value), timestamp=clocks[index])
|
| 682 |
+
raw = analyzer.analyze()
|
| 683 |
+
stage1 = raw.get("stage1") if isinstance(raw.get("stage1"), dict) else {}
|
| 684 |
+
stage2 = raw.get("stage2") if isinstance(raw.get("stage2"), dict) else {}
|
| 685 |
+
valid = list(stage1.get("valid_ftcps") or [])
|
| 686 |
+
events = list(stage2.get("lighthouse_events") or [])
|
| 687 |
+
body: dict[str, Any] = {
|
| 688 |
+
"clock": clock_label,
|
| 689 |
+
"coherence": raw.get("coherence"),
|
| 690 |
+
"detection_rate": "HOLD",
|
| 691 |
+
"false_alarm_rate": "HOLD",
|
| 692 |
+
"ftcp_count": stage1.get("ftcp_count"),
|
| 693 |
+
"ftcps": [_event_record(item, "ftcp") for item in valid],
|
| 694 |
+
"label": (
|
| 695 |
+
"cited-unverified bundled series. Not public market data."
|
| 696 |
+
if not supplied
|
| 697 |
+
else "inferred. Adapter run on the supplied series. Not the committed replay."
|
| 698 |
+
),
|
| 699 |
+
"lhe_count": stage2.get("lhe_count"),
|
| 700 |
+
"lighthouse_events": [_event_record(item, "lhe") for item in events],
|
| 701 |
+
"regime": raw.get("regime"),
|
| 702 |
+
"samples_fed": len(series),
|
| 703 |
+
"status": raw.get("status", "unavailable"),
|
| 704 |
+
}
|
| 705 |
+
return _dumps(body)
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
@quiet
|
| 709 |
+
def organism_replay_read() -> str:
|
| 710 |
+
"""Read the committed circulation replay file. This does not start a seat.
|
| 711 |
+
|
| 712 |
+
Connectivity figures are cited from the file. The fault block is seeded synthetic input, not telemetry. A claim that those faults are recorded seat faults is HOLD.
|
| 713 |
+
|
| 714 |
+
Args:
|
| 715 |
+
none: This tool takes no inputs. Label: cited, huggingface/organism-replay/replay/organism.json.
|
| 716 |
+
"""
|
| 717 |
+
|
| 718 |
+
record = _load(paths.organism_json())
|
| 719 |
+
connectivity = record.get("connectivity") if isinstance(record.get("connectivity"), dict) else {}
|
| 720 |
+
self_model = record.get("self_model") if isinstance(record.get("self_model"), dict) else {}
|
| 721 |
+
prediction = self_model.get("prediction") if isinstance(self_model.get("prediction"), dict) else {}
|
| 722 |
+
fault = self_model.get("fault") if isinstance(self_model.get("fault"), dict) else {}
|
| 723 |
+
seats = connectivity.get("seats") if isinstance(connectivity.get("seats"), dict) else {}
|
| 724 |
+
isolated = connectivity.get("isolated")
|
| 725 |
+
topics = _dashboard_topics()
|
| 726 |
+
return _dumps(
|
| 727 |
+
{
|
| 728 |
+
"cited": {
|
| 729 |
+
"connected": connectivity.get("connected"),
|
| 730 |
+
"connectivity_score": connectivity.get("score"),
|
| 731 |
+
"http_seat_bound": connectivity.get("http_seat_bound"),
|
| 732 |
+
"isolated": isolated,
|
| 733 |
+
"label": "cited, huggingface/organism-replay/replay/organism.json",
|
| 734 |
+
"prediction_accuracy": prediction.get("accuracy"),
|
| 735 |
+
"prediction_baseline_accuracy": prediction.get("baseline_accuracy"),
|
| 736 |
+
"roster": connectivity.get("roster"),
|
| 737 |
+
"seats": seats,
|
| 738 |
+
"verdict": connectivity.get("verdict"),
|
| 739 |
+
},
|
| 740 |
+
"dashboard_topics": topics,
|
| 741 |
+
"label": "cited replay file. Circulation was not started.",
|
| 742 |
+
"seeded_synthetic_fault": {
|
| 743 |
+
"detection_rate_in_file": fault.get("detection_rate"),
|
| 744 |
+
"false_alarm_rate_in_file": fault.get("false_alarm_rate"),
|
| 745 |
+
"hold": (
|
| 746 |
+
"A claim that these are recorded seat faults is HOLD. "
|
| 747 |
+
"These figures are not a QGITA detection rate and not telemetry."
|
| 748 |
+
),
|
| 749 |
+
"label": "Seeded synthetic input, not telemetry.",
|
| 750 |
+
"origin": fault.get("origin"),
|
| 751 |
+
"seed": fault.get("seed"),
|
| 752 |
+
},
|
| 753 |
+
}
|
| 754 |
+
)
|
| 755 |
+
|
| 756 |
+
|
| 757 |
+
def _dashboard_topics() -> list[str]:
|
| 758 |
+
topics = (
|
| 759 |
+
"ics.body.state",
|
| 760 |
+
"ics.mind.state",
|
| 761 |
+
"ics.source.state",
|
| 762 |
+
"ics.soul.state",
|
| 763 |
+
"ics.hnc.state",
|
| 764 |
+
"ics.monologue",
|
| 765 |
+
)
|
| 766 |
+
try:
|
| 767 |
+
from aureon.core.aureon_thought_bus import ThoughtBus
|
| 768 |
+
from aureon.core.cognitive_dashboard import CognitiveDashboard
|
| 769 |
+
|
| 770 |
+
bus = ThoughtBus(persist_path=None)
|
| 771 |
+
CognitiveDashboard(thought_bus=bus)
|
| 772 |
+
except Exception:
|
| 773 |
+
return [f"Dashboard topic {topic}: unavailable" for topic in topics]
|
| 774 |
+
lines = []
|
| 775 |
+
for topic in topics:
|
| 776 |
+
found = bus.recall(topic, limit=1)
|
| 777 |
+
if found:
|
| 778 |
+
lines.append(f"Dashboard topic {topic}: present in the replay")
|
| 779 |
+
else:
|
| 780 |
+
lines.append(f"Dashboard topic {topic}: unavailable")
|
| 781 |
+
return lines
|
| 782 |
+
|
| 783 |
+
|
| 784 |
+
@quiet
|
| 785 |
+
def organism_catalog() -> str:
|
| 786 |
+
"""List circulation seats, algorithmic nodes, and deterministic systems.
|
| 787 |
+
|
| 788 |
+
These are names in source. This tool does not start circulation, self-repair, or self-code. Label: cited.
|
| 789 |
+
|
| 790 |
+
Args:
|
| 791 |
+
none: This tool takes no inputs. Label: cited, circulation_seats, list_nodes, and list_systems.
|
| 792 |
+
"""
|
| 793 |
+
|
| 794 |
+
from aureon.core.algorithmic_nodes import list_nodes
|
| 795 |
+
from aureon.core.deterministic_systems import list_systems
|
| 796 |
+
from aureon.core.organism_circulation import circulation_seats
|
| 797 |
+
|
| 798 |
+
return _dumps(
|
| 799 |
+
{
|
| 800 |
+
"label": "cited. Names in source. Seats are not running.",
|
| 801 |
+
"nodes": list_nodes(),
|
| 802 |
+
"seats": list(circulation_seats()),
|
| 803 |
+
"systems": list_systems(),
|
| 804 |
+
}
|
| 805 |
+
)
|