gembala

Development notes

Numbers like FR-61, SEC-20, or “TECH section 17” in code refer to the repo owner’s requirements documents, which aren’t public; the context you need lives in the issue. Workflow and PR rules are in CONTRIBUTING.md.

Structure

core/                    `gembala` binary: daemon + CLI (one binary, also the app's sidecar)
  src/main.rs            subcommands: daemon, hook, send, wait, read, reply, status, watch
  src/daemon.rs          ui.sock + pane.sock sockets, pane registry, attach, status, message engine (glue)
  src/pty.rs             spawns the login shell (setsid, clean env SEC-35), process busy/name/cwd/args
  src/grid.rs            VT grid (vt100) + attach snapshot + text for read/screen patterns
  src/config.rs          config.toml (toml_edit): per-key validation, set/profile/shortcuts, atomic write
  src/profile.rs         agent profiles, detection, launch command + hook flags + session, hook/screen-pattern status
  src/msg.rs             pure message rules: sanitizer, labels, send decision
  src/bus.rs             queue, history, HMAC audit log (SEC-11)
  src/git.rs             read-only git status/diff + secret redaction (SEC-12, 29)
  src/rundir.rs          private socket folder (SEC-1, 25)
  src/sign.rs            UI channel recognized by the peer's code signature (SEC-20)
  tests/daemon.rs        integration tests against a real daemon over the socket
ui/                      Tauri 2 + SvelteKit static + Svelte 5 + xterm.js (DOM renderer)
  src-tauri/src/lib.rs   daemon client (doesn't open PTYs), native menu + [keys], notifications, dialogs, paste
  src-tauri/src/daemon.rs  connects to / launches the daemon
  src/routes/+page.svelte  workspace → tab → split tree, sidebar, toolbar, cards, restore
  src/lib/               Tile (one xterm per pane), Settings, Changes, Messages, OutputView, layout (pure)
scripts/                 pasang.sh + real-app test tools in a separate run folder + config (don't touch user data)

User data: ~/Library/Application Support/Gembala/ (config.toml, layout.json, hooks/, audit/), sockets in $TMPDIR/gembala/. Both can be redirected with GEMBALA_CONFIG and GEMBALA_RUNDIR (used by tests).

New UI-to-daemon methods must be registered in ALLOWED (ui/src-tauri/src/lib.rs); otherwise the call is silently rejected.

Run and test

You need Rust (brew install rustup; PATH /opt/homebrew/opt/rustup/bin) and Node.

export PATH=/opt/homebrew/opt/rustup/bin:$PATH
cargo test -p gembala                           # unit + daemon integration (~30 s)
cargo test -p ui                                # the app's Rust side
cargo clippy --workspace --all-targets -- -D warnings
cd ui && npm install --ignore-scripts && npm run check && npm test
npm run tauri build                             # release app: target/release/bundle/macos/Gembala.app (+ .dmg)
npm run tauri build -- --debug                  # debug app, for scripts/ below

Test tools that drive the real debug app (the secret goes through GEMBALA_DEV_SECRET, a path that only exists in debug builds):

python3 -I scripts/restore_check.py target/debug/bundle/macos/Gembala.app   # reopen + new daemon
python3 -I scripts/lost_check.py target/debug/bundle/macos/Gembala.app      # daemon killed
python3 -I scripts/quit_check.py target/debug/bundle/macos/Gembala.app      # Cmd+Q, agents stay alive
python3 -I scripts/ram_ui.py target/debug/bundle/macos/Gembala.app 4        # RAM with 4 panes (needs the screen on)
python3 -I scripts/ukur.py target/release/gembala $TMPDIR/gbl-ukur          # daemon latency + throughput

Always install npm packages with --ignore-scripts (SEC-16).

Processes Gembala runs

Name in Activity Monitor Role
gembala-ui (or “Gembala”) The app window
tauri://localhost WebKit view: terminal and sidebar
WebKit GPU and Networking Built-in WebKit parts that draw and load the view from inside the app
gembala Pane-keeping daemon: shells and agents run under it
zsh, claude, codex, … Processes running in panes

Gotchas we’ve already hit