Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 24 additions & 5 deletions demo_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,34 @@ def send_json_response(self, data):
# Global lattice instance
lattice = ConsciousnessLattice(grid_size=64)

def start_server(port=8000):
def get_local_ip():
"""Get the local network IP address."""
import socket
try:
# Create a socket to find the local IP
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
s.connect(("8.8.8.8", 80))
local_ip = s.getsockname()[0]
s.close()
return local_ip
except Exception:
return "Unable to detect"
Comment on lines +134 to +145

def start_server(port=8000, host="0.0.0.0"):
"""Start the consciousness simulation server."""
with socketserver.TCPServer(("", port), ConsciousnessHTTPHandler) as httpd:
print(f"🧠 CONSIM Demo Server starting on http://localhost:{port}")
local_ip = get_local_ip()

socketserver.TCPServer.allow_reuse_address = True
Comment on lines +147 to +151
with socketserver.TCPServer((host, port), ConsciousnessHTTPHandler) as httpd:
Comment on lines +147 to +152

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔒 Security & Privacy | 🔴 Critical | 🏗️ Heavy lift

Restrict static serving before exposing the server.

ConsciousnessHTTPHandler at demo_server.py Line 22 serves Path(__file__).parent. An unauthenticated client can request project files such as /demo_server.py directly. Binding to 0.0.0.0 exposes them on the LAN, and the ngrok tunnel exposes the same handler on the Internet.

  • demo_server.py#L147-L152: Serve only an approved static-content directory. Update the root URL mapping to that directory.
  • host_public.py#L35-L39: Create the public tunnel only after the server serves approved static content.
🧰 Tools
🪛 Ruff (0.16.1)

[error] 147-147: Possible binding to all interfaces

(S104)

📍 Affects 2 files
  • demo_server.py#L147-L152 (this comment)
  • host_public.py#L35-L39
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@demo_server.py` around lines 147 - 152, Restrict ConsciousnessHTTPHandler’s
root URL mapping to an approved static-content directory instead of
Path(__file__).parent, and ensure start_server uses that directory before
binding publicly. In host_public.py lines 35-39, create the public tunnel only
after the server is configured to serve the approved static content; update both
sites accordingly.

print(f"🧠 CONSIM Demo Server starting on ALL network interfaces")
print(f"✨ Consciousness lattice with {len(lattice.nodes)} nodes initialized")
print(f"🌌 {len(lattice.universes)} universes with λ weights: {[f'{l:.3f}' for l in lattice.lambdas]}")
print(f"🔗 API endpoints: /api/status, /api/stats, /api/state")
print("💡 Open http://localhost:8000 in your browser")

print(f"\n📍 Access URLs:")
print(f" Local: http://localhost:{port}")
print(f" Network: http://{local_ip}:{port}")
print(f"\n💡 Share the Network URL with devices on your local network!")

try:
httpd.serve_forever()
except KeyboardInterrupt:
Expand Down
27 changes: 27 additions & 0 deletions docs/demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>CONSIM - Multiversal Consciousness Framework</title>
<link rel="stylesheet" href="static/css/style.css">
</head>
<body>
<div id="canvas-container"></div>

<!-- Three.js from CDN -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"></script>

<!-- CONSIM Modules -->
<script src="static/js/consciousnessRenderer.js"></script>
<script src="static/js/app_demo.js"></script>

<script>
// Initialize standalone demo
document.addEventListener('DOMContentLoaded', () => {
console.log('🧠 CONSIM - Multiversal Consciousness Framework (Standalone Demo)');
const app = new ConsciousnessApp();
});
Comment on lines +10 to +24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 3 --glob 'app_demo.js' \
  'getElementById|querySelector|canvas-container|`#canvas`|gravitySlider|collapseBtn|statusText' .

Repository: Jacobcdsmith/CONSIM

Length of output: 13240


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf '--- docs/demo.html ---\n'
cat -n docs/demo.html

printf '\n--- docs/static/js/app_demo.js outline/constructor ---\n'
wc -l docs/static/js/app_demo.js
sed -n '1,170p' docs/static/js/app_demo.js | cat -n

Repository: Jacobcdsmith/CONSIM

Length of output: 248


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo '--- docs/demo.html ---'
cat -n docs/demo.html

echo
echo '--- docs/static/js/app_demo.js outline/constructor ---'
wc -l docs/static/js/app_demo.js
sed -n '1,170p' docs/static/js/app_demo.js | cat -n

Repository: Jacobcdsmith/CONSIM

Length of output: 9071


Add the missing DOM elements required by ConsciousnessApp.

docs/demo.html only defines #canvas-container, but docs/static/js/app_demo.js reads #canvas for the fallback renderer, attaches a click listener to #canvas, calls setupSlider() on several controls, and updates status/stats elements during initialization. Either include the canonical page shell’s DOM or make ConsciousnessApp use #canvas-container and handle missing controls/status UI safely.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@docs/demo.html` around lines 10 - 24, Add the DOM elements expected by
ConsciousnessApp in docs/demo.html, including the `#canvas` fallback target,
controls consumed by setupSlider(), and status/stat elements updated during
initialization. Prefer matching the canonical page shell’s element IDs and
structure so app_demo.js can initialize without null references.

</script>
</body>
Comment on lines +9 to +26
</html>
Loading