package engine import ( "os" "github.com/loyaly/behavision-agent/pkg/paths" ) // ChildEnv is the environment the engine is launched with, wherever it is // launched from - the desktop app and the headless agent both go through // here, so a third caller cannot get it half right. // // The line that matters is BEHAVISION_DATA_DIR. // // The engine's paths.py knows two worlds: frozen with PyInstaller, where state // lives under ProgramData, and a checkout, where everything sits in the repo // root. An engine installed from source into a virtual environment is neither. // Left to itself it resolves its state root to site-packages - writes its // database and camera list there, and generates its API credential into a // folder this process never reads - while this process resolves the same // state root to ProgramData. The two halves then disagree about where // everything lives, and every call to the engine is 401 on a stock install, // with nothing in either log saying why. Seen twice: once on a Mac checkout // (the app in ~/Library, the engine in the repo) and once in a clean Linux // container running the installer. // // Telling the engine where THIS process keeps state makes the two agree by // construction, however the engine was installed. paths.py honours the // override ahead of every other rule it has. // // hookURL is where the engine posts detections; empty is allowed and means // the bridge has not started, which the engine treats as "no webhook". func ChildEnv(hookURL string) []string { env := append(os.Environ(), "BEHAVISION_DATA_DIR="+paths.StateRoot(), ) if hookURL != "" { env = append(env, "BEHAVISION_WEBHOOK_URL="+hookURL) } return env }