-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathinstall.py
More file actions
729 lines (597 loc) · 28.9 KB
/
install.py
File metadata and controls
729 lines (597 loc) · 28.9 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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
#!/usr/bin/env python3
"""install.py — Cross-platform one-command installer for Tofu (豆腐).
Works on Linux, macOS, and Windows. Requires only Python 3.10+.
No conda, no system packages, no root/admin required.
Usage:
python install.py # Install and start
python install.py --no-launch # Install only
python install.py --port 8080 # Custom port
python install.py --api-key sk-xxx # Pre-configure API key
python install.py --docker # Use Docker instead
What it does:
1. Verifies Python 3.10+
2. Creates a virtual environment (.venv)
3. Installs Python dependencies via pip (or uv if available)
4. Optionally installs Playwright (browser automation)
5. Creates .env from template
6. Launches the server
The script is idempotent — safe to run multiple times.
"""
from __future__ import annotations
import argparse
import os
import platform
import shutil
import subprocess
import sys
import textwrap
# ═══════════════════════════════════════════════════════════════
# Constants
# ═══════════════════════════════════════════════════════════════
MIN_PYTHON = (3, 10)
REPO_URL = "https://github.com/rangehow/ToFu.git"
IS_WINDOWS = os.name == "nt"
IS_MACOS = sys.platform == "darwin"
IS_LINUX = sys.platform.startswith("linux")
# ═══════════════════════════════════════════════════════════════
# Terminal output helpers
# ═══════════════════════════════════════════════════════════════
# Windows cmd.exe doesn't support ANSI by default before Win10 1511.
# We enable it via SetConsoleMode if possible, otherwise degrade gracefully.
_COLORS_ENABLED = False
def _enable_ansi_windows():
"""Enable ANSI escape codes on Windows 10+."""
global _COLORS_ENABLED
if not IS_WINDOWS:
_COLORS_ENABLED = True
return
try:
import ctypes
kernel32 = ctypes.windll.kernel32
# STD_OUTPUT_HANDLE = -11
handle = kernel32.GetStdHandle(-11)
mode = ctypes.c_ulong()
kernel32.GetConsoleMode(handle, ctypes.byref(mode))
# ENABLE_VIRTUAL_TERMINAL_PROCESSING = 0x0004
kernel32.SetConsoleMode(handle, mode.value | 0x0004)
_COLORS_ENABLED = True
except Exception:
_COLORS_ENABLED = False
_enable_ansi_windows()
def _c(code: str, text: str) -> str:
if not _COLORS_ENABLED:
return text
return f"\033[{code}m{text}\033[0m"
def info(msg: str):
print(f" {_c('34', 'ℹ')} {msg}")
def ok(msg: str):
print(f" {_c('32', '✓')} {msg}")
def warn(msg: str):
print(f" {_c('33', '!')} {msg}")
def fail(msg: str):
print(f" {_c('31', '✗')} {msg}")
sys.exit(1)
def step(msg: str):
print(f"\n {_c('1;36', '▸')} {_c('1', msg)}")
# ═══════════════════════════════════════════════════════════════
# Utility functions
# ═══════════════════════════════════════════════════════════════
def run(cmd: list[str], check: bool = True, capture: bool = False,
env: dict | None = None, **kwargs) -> subprocess.CompletedProcess:
"""Run a command, printing it first."""
display = " ".join(cmd)
info(f"$ {display}")
merged_env = {**os.environ, **(env or {})}
try:
return subprocess.run(
cmd, check=check, capture_output=capture,
text=True, env=merged_env, **kwargs
)
except FileNotFoundError:
fail(f"Command not found: {cmd[0]}")
except subprocess.CalledProcessError as e:
if check:
fail(f"Command failed (exit {e.returncode}): {display}")
return e # type: ignore[return-value]
def which(name: str) -> str | None:
"""Cross-platform shutil.which."""
return shutil.which(name)
def python_version() -> tuple[int, int]:
return sys.version_info[:2]
def venv_python(venv_dir: str) -> str:
"""Return the path to the Python executable inside a venv."""
if IS_WINDOWS:
return os.path.join(venv_dir, "Scripts", "python.exe")
return os.path.join(venv_dir, "bin", "python")
def venv_bin(venv_dir: str, name: str) -> str:
"""Return the path to a binary inside a venv."""
if IS_WINDOWS:
return os.path.join(venv_dir, "Scripts", f"{name}.exe")
return os.path.join(venv_dir, "bin", name)
# ═══════════════════════════════════════════════════════════════
# Step 1: Verify Python version
# ═══════════════════════════════════════════════════════════════
def check_python():
step("Checking Python")
major, minor = python_version()
if (major, minor) < MIN_PYTHON:
fail(
f"Python {MIN_PYTHON[0]}.{MIN_PYTHON[1]}+ is required, "
f"but you have {major}.{minor}.\n"
f" Download from: https://www.python.org/downloads/"
)
ok(f"Python {major}.{minor} ({sys.executable})")
# ═══════════════════════════════════════════════════════════════
# Step 2: Get source code
# ═══════════════════════════════════════════════════════════════
def get_source(install_dir: str):
step("Getting Tofu source code")
# Already in the project directory (server.py exists)?
if os.path.isfile(os.path.join(install_dir, "server.py")):
# Update if it's a git repo
if os.path.isdir(os.path.join(install_dir, ".git")):
info("Updating existing installation...")
result = run(["git", "pull", "--ff-only"], check=False,
capture=True, cwd=install_dir)
if result.returncode != 0:
warn("Could not auto-update (you may have local changes)")
ok(f"Source ready at {install_dir}")
return
# Clone
if not which("git"):
fail(
"Git is required to clone the repository.\n"
" Install from: https://git-scm.com/downloads"
)
info(f"Cloning to {install_dir}...")
run(["git", "clone", REPO_URL, install_dir])
ok(f"Source ready at {install_dir}")
# ═══════════════════════════════════════════════════════════════
# Step 3: Create virtual environment
# ═══════════════════════════════════════════════════════════════
def setup_venv(install_dir: str) -> str:
"""Create a .venv and return the path to its Python executable.
Strategy:
1. If conda env is already active (CONDA_PREFIX set), use it as-is.
2. If uv is available, use `uv venv` (faster).
3. Otherwise, use `python -m venv`.
"""
step("Setting up Python environment")
venv_dir = os.path.join(install_dir, ".venv")
# If running inside an active conda env, respect it
conda_prefix = os.environ.get("CONDA_PREFIX")
if conda_prefix and os.path.isfile(os.path.join(conda_prefix, "bin", "python")):
py = os.path.join(conda_prefix, "bin", "python")
ok(f"Using active conda environment: {conda_prefix}")
return py
if conda_prefix and IS_WINDOWS:
py = os.path.join(conda_prefix, "python.exe")
if os.path.isfile(py):
ok(f"Using active conda environment: {conda_prefix}")
return py
# Check if .venv already exists and is valid
venv_py = venv_python(venv_dir)
if os.path.isfile(venv_py):
ok("Virtual environment already exists: .venv")
return venv_py
# Create venv
# Try uv first (much faster)
uv = which("uv")
if uv:
info("Creating virtual environment with uv...")
run([uv, "venv", venv_dir, "--python", sys.executable], cwd=install_dir)
else:
info("Creating virtual environment with venv...")
run([sys.executable, "-m", "venv", venv_dir], cwd=install_dir)
if not os.path.isfile(venv_py):
fail(f"Failed to create virtual environment at {venv_dir}")
ok("Virtual environment created: .venv")
return venv_py
# ═══════════════════════════════════════════════════════════════
# Step 4: Install Python dependencies
# ═══════════════════════════════════════════════════════════════
def install_deps(py: str, install_dir: str):
"""Install Python dependencies using pip or uv."""
step("Installing Python dependencies")
req_file = os.path.join(install_dir, "requirements.txt")
if not os.path.isfile(req_file):
warn("No requirements.txt found — skipping pip install")
return
# Prefer uv for speed, fall back to pip
uv = which("uv")
if uv:
info("Using uv for fast dependency installation...")
run([uv, "pip", "install", "-r", req_file, "--python", py],
cwd=install_dir)
else:
# Upgrade pip first
run([py, "-m", "pip", "install", "--upgrade", "pip", "-q"],
cwd=install_dir)
run([py, "-m", "pip", "install", "-r", req_file],
cwd=install_dir)
ok("Python dependencies installed")
# ═══════════════════════════════════════════════════════════════
# Step 5: Verify SQLite (built into Python — always available)
# ═══════════════════════════════════════════════════════════════
def check_sqlite():
"""Verify SQLite is available (it's built into Python)."""
step("Checking SQLite")
import sqlite3
ver = sqlite3.sqlite_version
ok(f"SQLite {ver} (built into Python — no installation needed)")
# ═══════════════════════════════════════════════════════════════
# Step 6: Install ripgrep (optional — fast code search)
# ═══════════════════════════════════════════════════════════════
def install_ripgrep(install_dir: str):
"""Install ripgrep for fast code search (optional, non-fatal).
ripgrep is ~5x faster than GNU grep on our codebase. The grep_search
tool falls back to GNU grep → pure Python if rg is unavailable.
"""
step("Checking ripgrep (fast code search)")
if which("rg"):
# Get version
try:
result = subprocess.run(
["rg", "--version"], capture_output=True, text=True, timeout=5
)
ver = result.stdout.strip().split("\n")[0] if result.returncode == 0 else "?"
except Exception:
ver = "?"
ok(f"ripgrep already installed ({ver})")
return
info("ripgrep not found. Attempting auto-install...")
installed = False
# Strategy 1: conda (if available — works cross-platform)
conda = which("conda") or which("mamba")
if conda:
info(f"Installing ripgrep via {os.path.basename(conda)}...")
result = run(
[conda, "install", "-c", "conda-forge", "-y", "ripgrep"],
check=False, capture=True, cwd=install_dir,
)
if result.returncode == 0 and which("rg"):
ok("ripgrep installed via conda")
installed = True
# Strategy 2: Homebrew (macOS)
if not installed and IS_MACOS and which("brew"):
info("Installing ripgrep via Homebrew...")
result = run(["brew", "install", "ripgrep"], check=False, capture=True)
if result.returncode == 0 and which("rg"):
ok("ripgrep installed via Homebrew")
installed = True
# Strategy 3: apt (Linux, if sudo available)
if not installed and IS_LINUX and which("sudo") and which("apt-get"):
info("Installing ripgrep via apt...")
result = run(
["sudo", "apt-get", "install", "-y", "ripgrep"],
check=False, capture=True,
)
if result.returncode == 0 and which("rg"):
ok("ripgrep installed via apt")
installed = True
# Strategy 4: cargo (Rust — works everywhere)
if not installed and which("cargo"):
info("Installing ripgrep via cargo (this may take a minute)...")
result = run(["cargo", "install", "ripgrep"], check=False, capture=True)
if result.returncode == 0 and which("rg"):
ok("ripgrep installed via cargo")
installed = True
if not installed:
warn("Could not auto-install ripgrep (non-critical).")
info("Code search will use GNU grep instead (~5x slower).")
print()
if IS_MACOS:
info("Install manually: brew install ripgrep")
elif IS_LINUX:
info("Install manually: sudo apt install ripgrep")
info(" or: conda install -c conda-forge ripgrep")
elif IS_WINDOWS:
info("Install manually: winget install BurntSushi.ripgrep.MSVC")
info(" or: choco install ripgrep")
info(" or: conda install -c conda-forge ripgrep")
print()
# ═══════════════════════════════════════════════════════════════
# Step 7: Install fd-find (optional — fast file search)
# ═══════════════════════════════════════════════════════════════
def install_fd(install_dir: str):
"""Install fd-find for fast file search (optional, non-fatal).
fd is ~3-4x faster than GNU find / Python os.walk on large dirs.
The find_files tool falls back to Python os.walk if fd is unavailable.
"""
step("Checking fd-find (fast file search)")
if which("fd") or which("fdfind"):
bin_name = which("fd") or which("fdfind")
try:
result = subprocess.run(
[bin_name, "--version"], capture_output=True, text=True, timeout=5
)
ver = result.stdout.strip().split("\n")[0] if result.returncode == 0 else "?"
except Exception:
ver = "?"
ok(f"fd-find already installed ({ver})")
return
info("fd-find not found. Attempting auto-install...")
installed = False
# Strategy 1: conda (if available — works cross-platform)
conda = which("conda") or which("mamba")
if conda:
info(f"Installing fd-find via {os.path.basename(conda)}...")
result = run(
[conda, "install", "-c", "conda-forge", "-y", "fd-find"],
check=False, capture=True, cwd=install_dir,
)
if result.returncode == 0 and (which("fd") or which("fdfind")):
ok("fd-find installed via conda")
installed = True
# Strategy 2: Homebrew (macOS)
if not installed and IS_MACOS and which("brew"):
info("Installing fd-find via Homebrew...")
result = run(["brew", "install", "fd"], check=False, capture=True)
if result.returncode == 0 and which("fd"):
ok("fd-find installed via Homebrew")
installed = True
# Strategy 3: apt (Linux, if sudo available)
if not installed and IS_LINUX and which("sudo") and which("apt-get"):
info("Installing fd-find via apt...")
result = run(
["sudo", "apt-get", "install", "-y", "fd-find"],
check=False, capture=True,
)
if result.returncode == 0 and (which("fd") or which("fdfind")):
ok("fd-find installed via apt")
installed = True
# Strategy 4: cargo (Rust — works everywhere)
if not installed and which("cargo"):
info("Installing fd-find via cargo (this may take a minute)...")
result = run(["cargo", "install", "fd-find"], check=False, capture=True)
if result.returncode == 0 and which("fd"):
ok("fd-find installed via cargo")
installed = True
if not installed:
warn("Could not auto-install fd-find (non-critical).")
info("File search will use Python os.walk instead (~3x slower).")
print()
if IS_MACOS:
info("Install manually: brew install fd")
elif IS_LINUX:
info("Install manually: sudo apt install fd-find")
info(" or: conda install -c conda-forge fd-find")
elif IS_WINDOWS:
info("Install manually: winget install sharkdp.fd")
info(" or: choco install fd")
info(" or: conda install -c conda-forge fd-find")
print()
# ═══════════════════════════════════════════════════════════════
# Step 8: Install Playwright (optional — browser automation)
# ═══════════════════════════════════════════════════════════════
def install_playwright(py: str, install_dir: str):
"""Install Playwright for advanced web fetching (optional, non-fatal).
On Linux, also tries ``playwright install --with-deps`` which uses the
system package manager (apt/dnf) to install shared-library dependencies
required by Chromium (libgbm, libnss3, etc.). This needs sudo.
If --with-deps fails (e.g. no sudo), it falls back to browser-only
install — the user may need to install system deps manually.
"""
step("Installing Playwright browser (optional)")
# 1. Ensure the playwright Python package is installed
result = run(
[py, "-m", "pip", "install", "playwright", "-q"],
check=False, capture=True, cwd=install_dir,
)
if result.returncode != 0:
warn("Playwright pip install failed (non-critical — basic fetching still works)")
return
# 2. Install Chromium browser binary
# On Linux, try --with-deps first (installs system libs via apt/dnf).
# Falls back to plain install if --with-deps fails (no sudo, etc.).
installed = False
if IS_LINUX:
info("Attempting Playwright install with system dependencies...")
result = run(
[py, "-m", "playwright", "install", "--with-deps", "chromium"],
check=False, capture=True, cwd=install_dir,
)
if result.returncode == 0:
ok("Playwright chromium + system deps installed")
installed = True
else:
info("--with-deps failed (may need sudo) — trying browser-only install...")
if not installed:
result = run(
[py, "-m", "playwright", "install", "chromium"],
check=False, capture=True, cwd=install_dir,
)
if result.returncode == 0:
ok("Playwright chromium installed")
installed = True
if not installed:
warn("Playwright chromium install failed (non-critical)")
info("Web fetching will use requests + trafilatura instead.")
info("To install manually later:")
print(f" {py} -m playwright install chromium")
if IS_LINUX:
info("If you see missing system library errors:")
print(f" sudo {py} -m playwright install-deps chromium")
# ═══════════════════════════════════════════════════════════════
# Step 9: Configure .env
# ═══════════════════════════════════════════════════════════════
def configure_env(install_dir: str, port: int, api_key: str | None):
step("Configuration")
env_file = os.path.join(install_dir, ".env")
env_example = os.path.join(install_dir, ".env.example")
if not os.path.isfile(env_file):
if os.path.isfile(env_example):
shutil.copy2(env_example, env_file)
info("Created .env from template")
else:
# Create minimal .env
with open(env_file, "w") as f:
f.write(f"PORT={port}\n")
f.write("BIND_HOST=0.0.0.0\n")
info("Created minimal .env")
# Update port
_update_env_var(env_file, "PORT", str(port))
# Set API key if provided
if api_key:
_update_env_var(env_file, "LLM_API_KEYS", api_key)
ok("API key configured")
def _update_env_var(env_file: str, key: str, value: str):
"""Update or add an environment variable in a .env file."""
lines = []
found = False
if os.path.isfile(env_file):
with open(env_file) as f:
lines = f.readlines()
new_lines = []
for line in lines:
stripped = line.strip()
# Match both "KEY=value" and "# KEY=value" (commented out)
if stripped.startswith(f"{key}=") or stripped.startswith(f"# {key}="):
new_lines.append(f"{key}={value}\n")
found = True
else:
new_lines.append(line)
if not found:
new_lines.append(f"{key}={value}\n")
with open(env_file, "w") as f:
f.writelines(new_lines)
# ═══════════════════════════════════════════════════════════════
# Step 10: Docker path
# ═══════════════════════════════════════════════════════════════
def docker_install(install_dir: str, port: int, api_key: str | None):
"""Install and run via Docker Compose."""
step("Docker installation")
docker = which("docker")
if not docker:
fail(
"Docker is not installed.\n"
" Get it from: https://docs.docker.com/get-docker/"
)
get_source(install_dir)
os.chdir(install_dir)
# Set env vars for docker-compose
os.environ["PORT"] = str(port)
if api_key:
os.environ["LLM_API_KEYS"] = api_key
run(["docker", "compose", "up", "-d"], cwd=install_dir)
print()
ok("Tofu is running via Docker!")
print(f" Open {_c('1', f'http://localhost:{port}')} in your browser")
print(" Configure API keys in Settings → Providers")
print()
print(" Logs: docker compose logs -f tofu")
print(" Stop: docker compose down")
print(" Update: docker compose pull && docker compose up -d")
print()
# ═══════════════════════════════════════════════════════════════
# Step 11: Launch server
# ═══════════════════════════════════════════════════════════════
def launch(py: str, install_dir: str, port: int):
step("Starting Tofu server")
print()
print(f" {_c('1', '🧈 Tofu is starting on port')} {_c('1', str(port))}...")
print(f" Open {_c('1', f'http://localhost:{port}')} in your browser")
print()
print(f" {_c('36', 'First launch:')} Database auto-initializes instantly")
print(f" {_c('36', 'Configure:')} Click ⚙️ Settings → Providers to add your LLM API keys")
print()
print(" Press Ctrl+C to stop the server")
print()
os.chdir(install_dir)
os.execv(py, [py, "server.py"])
def print_install_complete(py: str, install_dir: str, port: int):
print()
ok("Installation complete!")
print()
if IS_WINDOWS:
# Show Windows-friendly activation commands
venv_activate = os.path.join(install_dir, ".venv", "Scripts", "activate.bat")
if os.path.isfile(venv_activate):
print(" To start Tofu:")
print(f" cd {install_dir}")
print(" .venv\\Scripts\\activate")
print(" python server.py")
else:
print(" To start Tofu:")
print(f" cd {install_dir}")
print(f" {py} server.py")
else:
venv_activate = os.path.join(install_dir, ".venv", "bin", "activate")
if os.path.isfile(venv_activate):
print(" To start Tofu:")
print(f" cd {install_dir}")
print(" source .venv/bin/activate")
print(" python server.py")
else:
print(" To start Tofu:")
print(f" cd {install_dir}")
print(f" {py} server.py")
print()
print(f" Then open {_c('1', f'http://localhost:{port}')} in your browser")
print()
# ═══════════════════════════════════════════════════════════════
# Main
# ═══════════════════════════════════════════════════════════════
def main():
parser = argparse.ArgumentParser(
description="Tofu (豆腐) — Cross-platform installer",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog=textwrap.dedent("""\
Examples:
python install.py # Install and start
python install.py --port 8080 # Custom port
python install.py --api-key sk-xxx # Pre-configure API key
python install.py --no-launch # Install only
python install.py --docker # Use Docker
python install.py --skip-playwright # Skip Playwright install
"""),
)
parser.add_argument("--dir", default=None,
help="Install directory (default: current dir or ~/tofu)")
parser.add_argument("--port", type=int, default=15000,
help="Server port (default: 15000)")
parser.add_argument("--api-key", default=None,
help="Pre-configure LLM API key")
parser.add_argument("--docker", action="store_true",
help="Use Docker instead of native install")
parser.add_argument("--no-launch", action="store_true",
help="Install only, don't start the server")
parser.add_argument("--skip-playwright", action="store_true",
help="Skip Playwright browser installation")
args = parser.parse_args()
# ── Banner ──
print()
print(f" {_c('1', '🧈 Tofu (豆腐) — Self-Hosted AI Assistant')}")
print(f" {'─' * 43}")
plat = f"{platform.system()} {platform.machine()}"
print(f" Platform: {plat} | Python: {sys.version.split()[0]}")
print()
# ── Determine install directory ──
if args.dir:
install_dir = os.path.abspath(args.dir)
elif os.path.isfile("server.py"):
# We're already in the project directory
install_dir = os.getcwd()
else:
install_dir = os.path.join(os.path.expanduser("~"), "tofu")
# ── Docker path ──
if args.docker:
docker_install(install_dir, args.port, args.api_key)
return
# ── Native install path ──
check_python()
get_source(install_dir)
py = setup_venv(install_dir)
install_deps(py, install_dir)
check_sqlite()
install_ripgrep(install_dir)
install_fd(install_dir)
if not args.skip_playwright:
install_playwright(py, install_dir)
configure_env(install_dir, args.port, args.api_key)
if args.no_launch:
print_install_complete(py, install_dir, args.port)
else:
launch(py, install_dir, args.port)
if __name__ == "__main__":
main()