Skip to content

Conventional install: pipx + Makefile, drop in-tree venv#3

Open
davidj4tech wants to merge 4 commits into
installer-followupsfrom
conventional-install-v2
Open

Conventional install: pipx + Makefile, drop in-tree venv#3
davidj4tech wants to merge 4 commits into
installer-followupsfrom
conventional-install-v2

Conversation

@davidj4tech

Copy link
Copy Markdown
Owner

Stacked on top of #2. Builds on the cleaned-up bash installer to replace it with a proper Python-package-shipped-via-pipx flow.

Summary

  • pyproject.toml now defines [project.scripts] entry points: hippocampus (runs the FastAPI app via uvicorn) and memory-governor (calls memory_governor.app:run). Packages cover brain.*, memory_governor.*, sacred_brain.* — previously only memory_governor was in the package list, which only worked under pip install -e thanks to sys.path leakage.
  • New Makefile drives the install. Targets: install, install-update, uninstall, uninstall-purge. Honors DESTDIR, PREFIX, SYSCONFDIR, PIPX_HOME. make install runs pipx install --force . into /opt/pipx/venvs/sacred-brain-hippocampus/ and symlinks hippocampus / memory-governor / sacred-search into $(PREFIX)/bin/.
  • scripts/install.sh becomes a thin shim that exec makes the right target, so sudo ./scripts/install.sh [--update|--uninstall|--uninstall --purge] still works for existing automation.
  • Systemd units updated: hippocampus.service and memory-governor.service ExecStart point at /usr/local/bin/hippocampus and /usr/local/bin/memory-governor. Timer-target services use /opt/pipx/venvs/sacred-brain-hippocampus/bin/python. ReadOnlyPaths now grants /opt/pipx (timers keep both /opt/sacred-brain and /opt/pipx).
  • Migration: make install auto-detects and removes /opt/sacred-brain/.venv/ from pre-pipx installs. Idempotent.
  • sacred-search is now installed by the Makefile to $(PREFIX)/bin/, replacing the per-user ~/.local/bin/ symlink convention from docs/APP_ONBOARDING.md (server-side; client hosts still use scp/rsync).

Verified: python -m build --wheel produces a valid wheel with both entry points and sacred_brain/prompts/sam_system.txt included as package data. Both shellscripts pass shellcheck -S warning.

Test plan

  • On a fresh host: git clonesudo make install → edit configs → sudo systemctl start hippocampus memory-governorjust health passes
  • which hippocampus memory-governor sacred-search shows them all in /usr/local/bin/
  • journalctl -u hippocampus shows clean startup; no references to /opt/sacred-brain/.venv
  • On a host with the old layout: cd /opt/sacred-brain && sudo git pull && sudo make install removes /opt/sacred-brain/.venv/ and migrates services without data loss
  • sudo make uninstall-purge cleanly removes all units, the pipx venv, configs, state, and the sacred user
  • make -n install DESTDIR=/tmp/stage PREFIX=/usr produces a sane staging plan

🤖 Generated with Claude Code

davdj4 and others added 4 commits May 8, 2026 21:14
Sacred Brain is now installed as a proper Python package via pipx, driven
by a Makefile that honors DESTDIR/PREFIX/SYSCONFDIR. Drops the in-tree
.venv approach and gives you `make install` / `make uninstall`.

Package:
- pyproject.toml ships console-script entry points: `hippocampus` (runs
  the FastAPI app via uvicorn) and `memory-governor` (runs
  memory_governor.app:run).
- Packages now cover brain.*, memory_governor.*, sacred_brain.*, including
  sacred_brain/prompts/sam_system.txt as package data. Previously only
  memory_governor was listed; the others worked under `pip install -e`
  because the project root was on sys.path, but a real install missed
  them.
- New brain/hippocampus/__main__.py with main() that calls uvicorn.run.

Installer:
- New Makefile with install / install-update / uninstall / uninstall-purge
  targets. install runs `pipx install --force .` into PIPX_HOME (default
  /opt/pipx) with bins symlinked to PREFIX/bin. install-update reinstalls
  the package, refreshes units, and restarts enabled services.
- scripts/install.sh becomes a thin shim that exec's the Makefile so any
  external automation calling ./scripts/install.sh keeps working.
- sacred-search now installed by the Makefile to PREFIX/bin instead of
  the per-user ~/.local/bin/ symlink dance.

Systemd:
- hippocampus.service ExecStart now /usr/local/bin/hippocampus, no
  longer needs WorkingDirectory.
- memory-governor.service same treatment.
- Timer-target services use /opt/pipx/venvs/sacred-brain-hippocampus/bin/python
  instead of /opt/sacred-brain/.venv/bin/python.
- ReadOnlyPaths updated: /opt/pipx replaces /opt/sacred-brain for
  service units, timers keep both (they read scripts from the repo and
  python from pipx).

Migration:
- `make install` auto-detects /opt/sacred-brain/.venv/ from a pre-pipx
  install and removes it. Idempotent — silent if already clean.

Misc:
- .gitignore now covers build/ and dist/ (left over from `python -m build`).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
kerykeion (Swiss Ephemeris / pyswisseph C build) was a hard dependency but is
only used by memory_governor's astrology oracle + scripts/natal_to_sacred_brain
— never by the hippocampus core (the sqlite backend is lexical: no embeddings,
no LLM). Requiring it forced a compiler + libswe-dev on every install, blocking
a clean user-space core-only deploy.

Astrology/natal computation is owned by the separate `astrotunes` project, so
remove it here. Governor astrology that imports kerykeion lazily should delegate
to astrotunes (or install kerykeion explicitly where the governor runs).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
- hippocampus: GET /memories/{user_id} query is now optional (empty query
  -> adapter.list_memories), limit cap raised to 1000. Unblocks dream_sweep
  and the Governor recall-fallback, which list with no query and hit 422.
- governor: make _rerank robust (ask the model for an index ORDER and
  reorder the ORIGINAL objects, safe fallback on error/disabled) and
  actually call it from /recall (fetch a wider pool -> rerank -> top-k).
  _rerank was previously defined but never invoked (dead code).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Both units load /etc/sacred-brain/secrets.env as an optional second
EnvironmentFile so shared keys (LITELLM_API_KEY, HIPPOCAMPUS_API_KEY) can
come from a secrets store instead of literals in the per-service *.env.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@davidj4tech

Copy link
Copy Markdown
Owner Author

Heads-up: this branch now carries an extra commit beyond the conventional-install work — eaba016 "systemd: load optional secrets.env for shared API keys".

It adds one optional line to each unit:

EnvironmentFile=-/etc/sacred-brain/secrets.env

so shared API keys (LITELLM_API_KEY, HIPPOCAMPUS_API_KEY) come from a secrets store instead of literals in the per-service *.env. The - makes it optional, so units still start if the file is absent — no behaviour change unless the file exists.

Companion side (already on main in the dotfiles repos): dotfiles-secrets renders secrets.env from the sops-encrypted common.env, and the red5 user-scope units + dotfiles ansible hippocampus.service.j2 load it. On red5 this is live — hippocampus/memory-governor now source the gateway master key + Hippocampus key from the rendered file, and the literals are gone from memory-governor.env. These two unit edits are the canonical system-scope reference for the same pattern.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants