feat: daemon + serve HTTP surface (v3.3.0)#65
Merged
Merged
Conversation
Self-respawn-detached daemon: `start` spawns a hidden `daemon __run` child via
setsid (+ chdir, stdio redirected to ~/.onebrain/run/daemon.log); PID file with
a session-leader identity probe; SIGTERM park loop; structured tracing→log. Sync
for now — the tokio/axum HTTP server arrives in step 2.
- 14 tests (dependency-injected pure core + assert_cmd lifecycle); clippy + fmt clean
- 3-round review applied: PID-recycling identity guard (getpgid==pid), single
log FD (tracing→stderr→log), lifecycle integration test, read_pid bounds guard,
chdir("/"), known-limitation docs (concurrent-start TOCTOU)
…vault read API (v3.3 step 2) The daemon `__run` and a new foreground `onebrain serve [--dir] [--port] [--open] [--host]` share one tokio/axum HTTP server on 127.0.0.1: a static SPA (ServeDir + index.html fallback + per-session token injected into the page) plus a read-only JSON API — GET /api/config, /api/vault/tree, /api/vault/file?path= — behind a per-session token. `__run` is now async (replacing the step-1 park loop) and shuts down gracefully on SIGTERM; `serve` on Ctrl-C. Security (from a 3-round review): a daemon with no real vault returns 503 (never falls back to `/`, so the API can't leak the host filesystem); 3-layer path-traversal guard; constant-time token compare; the token is never written to the log (log 0600, run dir 0700); 10 MB file cap; FS work moved off the async runtime via spawn_blocking; filesystem/config errors mapped to 4xx (no errno leak). - deps: tokio (rt-multi-thread/macros/net/signal/time) + axum 0.8 + tower + tower-http (fs) - 38 server tests incl. a live TCP bind/serve/graceful-shutdown integration test - step 2b deferred (noted in code): PUT+conflict, /api/search, /api/extensions, /api/chat SSE, PWA service-worker, daemon-aware serve reuse
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds the daemon + serve HTTP surface — the v3.3 foundation for the OneBrain WebUI (step 1 + step 2 of the daemon-serve build sequence). The CLI gains a persistent engine and a read-only vault JSON API, serving an external dist directory (no embedded assets — keeps the binary lean).
Commands
onebrain daemon start | stop | status— detached self-respawning engine (PID file, session-leader liveness)onebrain serve [--dir <dist>] [--port N] [--host <addr>] [--open]— foreground HTTP surface; Jupyter-style?token=URLHTTP surface (one local listener,
127.0.0.1by default)GET /api/config—onebrain.ymlas JSONGET /api/vault/tree— recursive folder/file listingGET /api/vault/file?path=— one note's content +rev(for future conflict detection)serveanddaemon __runshare onerun_server; only the shutdown trigger differs (Ctrl-C vs SIGTERM).Security
/dev/urandom), required on every/api/*(Authorization: BearerorX-OneBrain-Token); constant-time compare.., absolute paths, and symlink-escape all rejected inside the vault root/(caught in review: avault_root="/"fallback had exposed/etc/passwd)0700, log0600Review & verification
vault=/release blocker + 11 other issues → all fixed; R2 verified 12 fixes; R3 = SHIPcargo fmt --checkclean ·cargo clippy -D warningsclean · all workspace tests passDeferred (step 2b)
PUT /api/vault/file+ conflict detection ·/api/search·/api/chatSSE · PWA SW/manifest · daemon-awareservereuse ·TimeoutLayer(needs tower-httptimeoutfeature) · tree dotfile/.DS_Storefiltering🤖 Generated with Claude Code