-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.bat
More file actions
171 lines (152 loc) · 5.27 KB
/
Copy pathsetup.bat
File metadata and controls
171 lines (152 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
@echo off
setlocal
REM Always run from this script's directory so relative paths are portable.
pushd "%~dp0" >nul
set "EXIT_CODE=0"
echo ============================================
echo Memory Index - Setup (CPU-only)
echo ============================================
echo.
REM Resolve Python launcher: prefer python, fall back to py -3.
set "PYTHON_CMD="
python --version >nul 2>&1 && set "PYTHON_CMD=python"
if not defined PYTHON_CMD (
py -3 --version >nul 2>&1 && set "PYTHON_CMD=py -3"
)
if not defined PYTHON_CMD (
echo [ERROR] Python not found. Install Python 3.11+ first.
set "EXIT_CODE=1"
goto :cleanup_with_pause
)
echo [OK] Python launcher: %PYTHON_CMD%
REM --- Venv and dependencies ---
if not exist ".venv\Scripts\python.exe" (
echo [INFO] Creating virtual environment...
%PYTHON_CMD% -m venv .venv
if errorlevel 1 (
echo [ERROR] Failed to create virtual environment.
set "EXIT_CODE=1"
goto :cleanup_with_pause
)
)
set "VENV_PYTHON=%CD%\.venv\Scripts\python.exe"
if not exist "%VENV_PYTHON%" (
echo [ERROR] Virtual environment Python not found at "%VENV_PYTHON%".
set "EXIT_CODE=1"
goto :cleanup_with_pause
)
echo [INFO] Installing Python dependencies...
REM Keep pip current
"%VENV_PYTHON%" -m pip install -q --upgrade pip
if errorlevel 1 (
echo [WARN] Could not upgrade pip - continuing anyway.
)
echo [INFO] Installing core packages...
"%VENV_PYTHON%" -m pip install -q "mcp[cli]" chromadb networkx scikit-learn onnxruntime
if errorlevel 1 (
echo [ERROR] Failed to install core packages.
set "EXIT_CODE=1"
goto :cleanup_with_pause
)
echo [INFO] Installing embedding model packages...
"%VENV_PYTHON%" -m pip install -q sentence-transformers transformers
if errorlevel 1 (
echo [ERROR] Failed to install embedding model packages.
set "EXIT_CODE=1"
goto :cleanup_with_pause
)
REM Install project in editable mode
"%VENV_PYTHON%" -m pip install -q -e .
if errorlevel 1 (
echo [ERROR] Failed to install project in editable mode.
set "EXIT_CODE=1"
goto :cleanup_with_pause
)
echo [OK] Dependencies installed
REM --- Download ONNX embedding model ---
echo.
echo [INFO] Downloading EmbeddingGemma-300m ONNX model...
echo (first run downloads ~350MB of model files for CPU inference)
echo.
set PYTHONIOENCODING=utf-8
"%VENV_PYTHON%" scripts\download_model.py
if errorlevel 1 (
echo [ERROR] Model download failed. Re-run setup.bat, or the server will try
echo PyTorch CPU as a fallback ^(slower, requires HF login^).
)
REM --- Register MCP server with available AI CLIs ---
echo.
set "REGISTERED_ANY=0"
REM Check for Claude Code
where claude >nul 2>&1
if not errorlevel 1 (
echo [INFO] Registering MCP server with Claude Code...
call claude mcp add --scope user memory-index -- "%VENV_PYTHON%" "%CD%\src\server.py" 2>nul
echo [OK] Registered with Claude Code
set "REGISTERED_ANY=1"
) else (
echo [SKIP] Claude Code not found - skipping registration
)
REM Check for Codex CLI
where codex >nul 2>&1
if not errorlevel 1 (
echo [INFO] Registering MCP server with Codex CLI...
call codex mcp add memory-index -- "%VENV_PYTHON%" "%CD%\src\server.py" >nul 2>&1
if errorlevel 1 (
echo [INFO] codex mcp add not available, writing config directly...
if not exist "%USERPROFILE%\.codex" mkdir "%USERPROFILE%\.codex"
if not exist "%USERPROFILE%\.codex\config.toml" type nul > "%USERPROFILE%\.codex\config.toml"
findstr /C:"[mcp_servers.memory-index]" "%USERPROFILE%\.codex\config.toml" >nul 2>&1
if not errorlevel 1 (
echo [INFO] Existing [mcp_servers.memory-index] entry found - skipping direct write.
) else (
set "PYTHON_PATH=%VENV_PYTHON%"
set "SERVER_PATH=%CD%\src\server.py"
setlocal enabledelayedexpansion
set "PYTHON_TOML=!PYTHON_PATH:\=\\!"
set "SERVER_TOML=!SERVER_PATH:\=\\!"
>> "%USERPROFILE%\.codex\config.toml" (
echo.
echo [mcp_servers.memory-index]
echo command = "!PYTHON_TOML!"
echo args = ["!SERVER_TOML!"]
)
endlocal
)
)
echo [OK] Registered with Codex CLI
set "REGISTERED_ANY=1"
) else (
echo [SKIP] Codex CLI not found - skipping registration
)
if "%REGISTERED_ANY%"=="0" (
echo.
echo [WARN] Neither Claude Code nor Codex CLI found.
echo You can register the MCP server manually later:
echo.
echo Claude Code:
echo claude mcp add --scope user memory-index -- "%VENV_PYTHON%" "%CD%\src\server.py"
echo.
echo Codex CLI:
echo codex mcp add memory-index -- "%VENV_PYTHON%" "%CD%\src\server.py"
pause
)
echo.
echo ============================================
echo Setup complete!
echo ============================================
echo.
echo Next steps:
echo 1. Restart Claude Code / Codex CLI to load the new MCP server
echo 2. Ask the AI to run: list_vaults()
echo 3. Create a vault: create_vault('default')
echo 4. Add entities: create_entity('Python', 'technology', 'default', 'General purpose language')
echo 5. Search: search_memory('what language')
echo.
goto :cleanup_with_pause
:cleanup_with_pause
pause
goto :cleanup
:cleanup
popd >nul
exit /b %EXIT_CODE%