Skip to content

Commit c3c5571

Browse files
committed
Updates to startup process
1 parent 137094b commit c3c5571

9 files changed

Lines changed: 1093 additions & 57 deletions

File tree

Project_Andrew/Andrew.rar

845 Bytes
Binary file not shown.

Project_Andrew/SETUP.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# V06062026
1+
# V06212026
22
# CAIOS — Andrew | Quick Setup Guide
33

44
> **What you need before starting:**
@@ -32,8 +32,7 @@ See Hardware Notes at the bottom for details.
3232
- Starts the web interface
3333
4. When you see **"Web UI: http://localhost:5000"**, open that address in your browser
3434

35-
> **Next time:** Just double-click `run_caios.bat` again — setup is skipped, and it launches directly.
36-
> **Alternate Next time:** Open a terminal window and run python caios_bridge.py then open a browser to http://localhost:5000
35+
> **Next time:** Open a terminal window and run python caios_bridge.py then open a browser to http://localhost:5000
3736
3837
---
3938

@@ -64,7 +63,7 @@ When you see **"Web UI: http://localhost:5000"**, open that in Safari or Chrome.
6463

6564
> **Apple Silicon (M1/M2/M3/M4):** Runs especially well — the unified memory means a 32 GB Mac can run the 27B model comfortably without a separate GPU.
6665
67-
> **Next time:** Just run `./run_caios.sh` from the Project_Andrew folder.
66+
> **Next time:** Open a terminal window, `cd` into the Project_Andrew folder, and run `python3 caios_bridge.py`, then open a browser to http://localhost:5000.
6867
6968
---
7069

@@ -90,7 +89,7 @@ When you see **"Web UI: http://localhost:5000"**, open that in your browser.
9089
> **NVIDIA GPU:** Install NVIDIA drivers (525+) and Ollama will use your GPU automatically. No CUDA toolkit needed separately.
9190
> **AMD GPU:** Supported on Linux via ROCm. Windows AMD GPU acceleration is not yet stable.
9291
93-
> **Next time:** Just run `./run_caios.sh`.
92+
> **Next time:** Open a terminal window, `cd` into the Project_Andrew folder, and run `python3 caios_bridge.py`, then open a browser to http://localhost:5000.
9493
9594
---
9695

Project_Andrew/caios_bridge.py

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#V06092026
1+
#V06212026
22
# =============================================================================
33
# CAIOS Web Bridge — Flask server that connects caios_chat_ui.html to the existing orchestrator/caios_chat.py stack.
44
#
@@ -17,6 +17,9 @@
1717
import hashlib
1818
import tempfile
1919
import pathlib
20+
import subprocess
21+
import platform
22+
import atexit
2023
from datetime import datetime, timezone
2124
from typing import Dict, Any
2225

@@ -86,6 +89,88 @@ def _bootstrap_shared_memory() -> Dict[str, Any]:
8689
UPLOAD_DIR = pathlib.Path(tempfile.gettempdir()) / 'caios_uploads'
8790
UPLOAD_DIR.mkdir(exist_ok=True)
8891

92+
# =============================================================================
93+
# Service Startup — Ollama, MCP filesystem server, windows-mcp
94+
#
95+
# Moved here from run_caios.bat/.sh so that BOTH launch paths documented in
96+
# SETUP.md ("run run_caios.bat" and "run python caios_bridge.py directly")
97+
# actually bring the same services up. run_caios.bat now only handles
98+
# one-time environment setup (deps, model pull, first-boot identity) and
99+
# hands off to this on every launch.
100+
#
101+
# Safe to call repeatedly — each service is skipped if already reachable,
102+
# so it's harmless if ollama is already running as a background service,
103+
# or if you start the bridge a second time.
104+
# =============================================================================
105+
106+
_spawned_procs = []
107+
108+
def _wait_until_ready(check_fn, timeout=20, interval=0.5) -> bool:
109+
deadline = time.time() + timeout
110+
while time.time() < deadline:
111+
try:
112+
if check_fn():
113+
return True
114+
except Exception:
115+
pass
116+
time.sleep(interval)
117+
return False
118+
119+
def _start_service(name: str, cmd: str, check_fn, timeout: int = 20) -> None:
120+
try:
121+
if check_fn():
122+
print(f'[BRIDGE] {name} already running')
123+
return
124+
except Exception:
125+
pass # treat a check failure as "not running yet" and try to start it
126+
127+
print(f'[BRIDGE] Starting {name}...')
128+
proc = subprocess.Popen(
129+
cmd, shell=True,
130+
stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL
131+
)
132+
_spawned_procs.append(proc)
133+
134+
if _wait_until_ready(check_fn, timeout=timeout):
135+
print(f'[BRIDGE] {name} ready')
136+
else:
137+
print(f'[BRIDGE] WARNING: {name} did not become ready within {timeout}s '
138+
f'— continuing anyway, related features will degrade gracefully')
139+
140+
def start_services() -> None:
141+
"""Bring up Ollama + MCP servers if they aren't already reachable."""
142+
try:
143+
import ollama_config
144+
_start_service('Ollama', 'ollama serve', ollama_config.check_ollama_available)
145+
except ImportError:
146+
print('[BRIDGE] ollama_config not found — skipping Ollama auto-start')
147+
148+
if MCP_AVAILABLE:
149+
client = get_mcp_client()
150+
_start_service(
151+
'MCP filesystem server',
152+
f'npx @modelcontextprotocol/server-filesystem --port 3000 "{os.getcwd()}"',
153+
client.fs_available
154+
)
155+
if platform.system() == 'Windows':
156+
_start_service(
157+
'windows-mcp',
158+
'windows-mcp serve --transport sse --host localhost --port 8000',
159+
client.win_available
160+
)
161+
else:
162+
print('[BRIDGE] caios_mcp_client.py not found — MCP servers not auto-started')
163+
164+
@atexit.register
165+
def _cleanup_services() -> None:
166+
for p in _spawned_procs:
167+
try:
168+
p.terminate()
169+
except Exception:
170+
pass
171+
if _spawned_procs:
172+
print('[BRIDGE] Spawned services terminated')
173+
89174
# =============================================================================
90175
# Helpers
91176
# =============================================================================
@@ -558,4 +643,5 @@ def api_mcp():
558643
print(' Open http://localhost:5000 in your browser')
559644
print(' Ctrl+C to stop')
560645
print('=' * 60)
646+
start_services()
561647
app.run(host='0.0.0.0', port=5000, debug=False)

0 commit comments

Comments
 (0)