Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

26.7 KB
Raw Blame

PROJECT.md β€” acceptance adapter for LobeHub

This file is the commands layer of LobeHub's acceptance setup: every LobeHub-specific command, port, service, surface, and probe. The acceptance skill reads it β€” it never guesses LobeHub's commands.

Its two siblings:

  • PROCESS.md β€” the run process (plan gate, execution rules, publishing, teardown).
  • .agents/skills/acceptance/ β€” the portable skill: what a check, evidence, report, and round are. This is a committed, generated snapshot of lobehub/acceptance, the only maintenance source. Update it from the repository's current default branch with bun apps/cli/src/index.ts acceptance update --json, then review and commit the downloaded files. The JSON records the exact source commit; publishing a tag or release is not required. Do not hand-edit this installed copy. .claude/skills shares .agents/skills.

Project helpers (report-init.sh, record-gif.sh, capture-app-window.sh, …) live under .agents/acceptance/scripts/. Generic CDP capture and screen-recording preflight live only under .agents/skills/acceptance/scripts/; invoke their shell scripts with bash. See the installed skill's screenshot-helpers.md for commands, prerequisites, and exit codes. Do not copy these implementations into the project layer.

1. Project summary

LobeHub is a chat/agent product with a Next.js server, a Vite + React SPA, an Electron desktop shell, and a CLI (lh). Repo layout that matters for testing:

  • apps/server/ β€” the Next.js backend (TRPC routers, services, modules, auth).
  • apps/desktop/ β€” the Electron shell. Standalone install (see Β§6).
  • apps/cli/ β€” the lh CLI; runs from source (bun src/index.ts), no rebuild. Standalone install (see Β§6).
  • packages/**, e2e, apps/server β€” covered by the root pnpm workspace.
  • src/ β€” the SPA and shared web app; apps/server/src/router-hono/ holds the Hono endpoint routers and standalone runtime.

The root pnpm workspace does NOT cover apps/desktop or apps/cli. pnpm-workspace.yaml lists packages/**, e2e, apps/server, and only apps/desktop/src/main. Those two apps keep their own node_modules with their own links into packages/; a root install does not refresh them. Symptom of a stale standalone install: a recently added workspace package fails to resolve β€” Rolldown failed to resolve import "@lobechat/<pkg>" (Electron) or Cannot find module '@lobechat/<pkg>' (CLI).

2. Environment

  • Start dev server:

    • With repo-root .env present: use the existing local config β€” bun run dev (full-stack, needed for Web smoke) or AGENT_RUNTIME_MODE=queue pnpm run dev:next (backend only). Do NOT call any init-dev-env.sh subcommand when .env exists. If that .env config does not boot (expired credentials, schema behind the checkout, setup-auth.sh refusing to seed), do not repair it in place β€” open a clean git worktree with no root .env and use the bootstrap below (dev-server.md).
    • Without .env: use the skill-owned bootstrap .agents/acceptance/scripts/init-dev-env.sh (Postgres, Redis, migrations, auth/key-vault/S3 test env, seed user, then the repo's own dev server β€” not e2e/scripts/setup.ts). It hard-blocks when root .env exists, so it can never override a user's local config.
    if [[ -f .env ]]; then
      bun run dev
    else
      .agents/acceptance/scripts/init-dev-env.sh setup-db
      .agents/acceptance/scripts/init-dev-env.sh s3 # terminal B β€” keep running
      .agents/acceptance/scripts/init-dev-env.sh seed-user
      .agents/acceptance/scripts/init-dev-env.sh dev
    fi
    

    dev-next starts the Next.js backend only; Web smoke needs the full-stack dev so Next proxies the SPA HTML from Vite. bun run dev:spa runs the Vite SPA alone, proxying the API to PORT.

  • Stop dev server (must stop only what THIS run started):

    .agents/acceptance/scripts/init-dev-env.sh clean    # stop the recorded dev-server PID tree; keep DB/Redis
    .agents/acceptance/scripts/init-dev-env.sh stop-dev # just the server, no note
    

    clean stops only the recorded dev-server PID tree after verifying its PID start time, command, and working directory; it never matches by process name and never kills a listener merely because it owns a persisted port. It leaves the managed Postgres/Redis containers running (reused across runs β€” setup-db is a no-op when they are up). clean-db removes the managed DB container; clean-s3 removes persisted local S3 objects. If the user started their own .env dev server, leave it β€” you did not start it.

  • Required services:

    • Postgres + Redis β€” init-dev-env.sh setup-db (managed Docker containers lobehub-agent-testing-postgres / lobehub-agent-testing-redis; requires Docker Desktop). To use an existing DB instead, set DATABASE_URL / REDIS_URL and skip setup-db (run migrate + seed-user with those env).
    • s3rver (local S3) β€” init-dev-env.sh s3 (terminal B). A hard prerequisite for browser uploads, presigned URLs, attachments, and generated files: the no-.env bootstrap points the app at local s3rver so those exercise a real S3 HTTP round trip. Creates agent-testing-bucket, configures CORS for the allocated local origins, persists objects under .records/data/agent-testing-s3. Fixed S3RVER credentials are required by the emulator's presigned-URL validation. preflight does HeadBucket + a real Put/Get/Delete round trip; a listening port alone is not "ready".
    • QStash β€” init-dev-env.sh qstash (terminal B). A hard prerequisite for ANY agent-runtime test (see Β§6).
  • Already-running detection:

    curl -s -o /dev/null -w '%{http_code}' "$SERVER_URL/"
    
  • Env / port resolution: .agents/acceptance/scripts/test-env.sh is the source of truth for local test ports β€” do NOT hard-code a port table. It reads the current shell plus .env files with the same precedence as scripts/runWithEnv.mts and prints APP_URL, PORT, SERVER_URL, AUTH_TRUSTED_ORIGINS, SPA_PORT, MOBILE_SPA_PORT, DESKTOP_PORT.

    .agents/acceptance/scripts/test-env.sh                     # print resolved env + ports
    eval "$(.agents/acceptance/scripts/test-env.sh --exports)" # export them
    

    Default script env (no-.env bootstrap): APP_URL=http://localhost:3010, DATABASE_URL=postgresql://postgres:postgres@localhost:5433/postgres, DATABASE_DRIVER=node, AGENT_RUNTIME_MODE=queue, REDIS_URL=redis://localhost:6380, an empty FEATURE_FLAGS, KEY_VAULTS_SECRET, AUTH_SECRET, auth verification off, a generated JWKS_KEY (persisted at .records/env/agent-testing-jwks.json, required by every async-task dispatch such as image generation), SSRF_ALLOW_PRIVATE_IP_ADDRESS=1 (the server fetches reference images from the local s3rver on 127.0.0.1), plus local s3rver and local QStash vars. Treat the dev-server terminal output as final when the port is non-standard, then export SERVER_URL=http://localhost:<port>.

    In the cloud repo (this repo as the lobehub/ submodule), worktree names map to fallback SERVER_URL defaults only when .env and shell env give none: lobehub→3010, lobehub-cloud→3020, lobehub-cloud-N→3020+N.

  • Cucumber note: when running Cucumber against this dev server in the no-.env branch, pass the same script env into the test process (eval "$(.agents/acceptance/scripts/init-dev-env.sh env)") β€” Cucumber's own BeforeAll seed path must see DATABASE_URL or it silently skips setup.

  • Ports/modes table, the per-path server-restart matrix, and env troubleshooting: .agents/acceptance/references/dev-server.md.

3. Auth

  • Test account: [email protected] / TestPassword123!, onboarding completed. Created by init-dev-env.sh seed-user, which also writes a local CLI API key to .records/env/agent-testing-cli.env.

  • Seeding command: .agents/acceptance/scripts/init-dev-env.sh seed-user.

  • Setup helper: .agents/acceptance/scripts/setup-auth.sh β€” status (all surfaces), status --surface <cli|web|electron>, cli-seed, cli (interactive device-code, user runs it), web-seed, open-chrome, web (inject a copied Cookie header), web-verify. Auth is a surface-scoped gate: pick the intended surface and check only it (do not block a Web test on CLI device-code auth).

  • Per-surface status check:

    Surface Mechanism One-key path Standard check
    CLI Seeded API key, device-code fallback setup-auth.sh cli-seed setup-auth.sh status --surface cli
    Web Seeded better-auth login into agent-browser setup-auth.sh web-seed setup-auth.sh status --surface web
    Electron The app's own persistent login state log in once in the app setup-auth.sh status --surface electron
  • Chrome-cookie fallback (Web only): ordinary Chrome is only a source for copying the better-auth session cookie into the agent-browser session (lobehub-dev) when seed auth is unavailable or status --surface web still fails. Copy the Cookie: header from the Network tab (NOT document.cookie β€” HttpOnly cookies are invisible there), then pbpaste | setup-auth.sh web. Use localhost, not 127.0.0.1 (better-auth cookies are stored for localhost). Never do this against production. Full decision flow, seeded-login mechanics, and failure modes: .agents/acceptance/references/auth.md.

  • Login-state check is standardized β€” do NOT hand-roll a window.__LOBE_STORES eval; use .agents/acceptance/scripts/app-probe.sh auth (returns { isSignedIn, userId }, works for Electron CDP and web sessions via AB_TARGET).

4. Surfaces

CLI

  • Invocation: from source, no rebuild β€” cd apps/cli && bun src/index.ts <cmd> (referred to as $CLI). CLI-side code changes take effect immediately.

  • Auth: see Β§3 CLI. Load .records/env/agent-testing-cli.env only inside the local-test subshell below. It sets LOBE_API_KEY / LOBEHUB_CLI_API_KEY, LOBEHUB_SERVER=http://localhost:3010, and LOBEHUB_CLI_HOME=.lobehub-dev for isolated settings.

  • Local-run vs publish env distinction: seeded credentials are only for the local backend. Load the test profile inside a subshell so it does not overwrite production credentials in the parent shell; remove any inherited production JWT inside that subshell because it would override the seeded API key:

    (
      unset LOBEHUB_JWT
      source .records/env/agent-testing-cli.env
      lh whoami
      # Run the local CLI test commands here.
    )
    

    For publication or existing-round lookup, follow Publish auth preflight. Preserve known production credentials; do not blindly clear API keys or assume ~/.lobehub contains a login. Never change only the server URL while retaining a local test credential.

  • Standalone install: cd apps/cli && pnpm install (root install does not cover it).

  • CLI as the run driver for conversation features (preferred over browser typing): for any test whose state is produced by an agent run (tool calls, edited-file cards, works, topic content), drive the run with

    lh agent run -a <agentId> --json -p '<prompt>' [-t <topicId>] [--device local]
    

    and use the browser only to capture the rendered evidence afterwards. CLI streaming uses the agent gateway WebSocket only. For local runs, configure both the backend and CLI to use the same local AGENT_GATEWAY_URL, with matching service-token and local JWT verification configuration (see references/agent-gateway.md). The production gateway cannot verify local JWT signatures; there is no SSE fallback. --json gives assertable output; reuse -t to chain multi-step cases in one topic. This is faster and far more deterministic than typing prompts through agent-browser, and the server-side state it produces is identical.

  • Launch: full-stack dev server from Β§2 (bun run dev or init-dev-env.sh dev).

  • Base URL: $SERVER_URL (default http://localhost:3010).

  • agent-browser session: lobehub-dev. Seed it with setup-auth.sh web-seed. It is the sole evidence source (do not use ordinary Chrome screenshots or Network records as proof) β€” but not necessarily the driver: prefer the CLI run driver (Β§4 CLI) or direct endpoint calls to produce the state, and use the browser for what only it can prove (rendering, interaction). Full-stack is the one surface where network requests and rendered UI are observable together β€” assert both.

  • SPA proxying note: Web smoke needs the full-stack dev so Next proxies the SPA HTML from Vite; dev-next alone will not serve the SPA.

  • Verify against a branch-running environment, not the production proxy: bun run dev:spa prints a _dangerous_local_dev_proxy URL that loads your local Vite SPA inside the online environment (HMR against real server config). That is a development convenience: it serves your local frontend over production's backend, origin, and data. Its output is never acceptance evidence, and it does not prove the delivered branch. Verify Web changes in the local full-stack dev server ($SERVER_URL, default http://localhost:3010), or a frontend-only change in Electron (PROCESS.md Step 3). If a criterion cannot be exercised in an environment that runs the delivered branch, record that check blocked and report the gap β€” do not substitute the proxy for it.

Electron

  • Launch: .agents/acceptance/scripts/electron-dev.sh start β€” CDP port 9222 (idempotent; status / stop / restart; env CDP_PORT, ELECTRON_LOG, ELECTRON_WAIT_S, RENDERER_WAIT_S, LOBE_LOGIN_STATE_DIR, KEEP_DATA, SKIP_LOGIN_SAVE). Connect with agent-browser --cdp 9222 snapshot -i.
  • Stop: .agents/acceptance/scripts/electron-dev.sh stop β€” always use this; pkill -f "Electron" leaves helper processes (GPU, renderer, network) alive.
  • Login persistence: stop snapshots the login to ~/.lobehub/agent-testing/electron-login; start seeds each new instance from it (login-status inspects it, save-login <id> captures a live one). Sign in once, not once per run β€” and if an instance comes up signed out, inject the login state directly (restore the snapshot, or mint it via CLI/API seeding; recipes and the three token-rotation traps are in .agents/acceptance/references/auth.md). Never trigger the OAuth flow (requestAuthorization) β€” it opens a login page in the user's default browser, against a per-instance localhost origin that usually can't even complete. If no injectable state exists, report auth as blocked and ask for one manual sign-in instead.
  • Local server: .agents/acceptance/scripts/electron-dev.sh start-local [<id>] starts pool instance <id> (default 1, CDP 9222+id) already signed in to the local dev server (SERVER_URL, default http://localhost:3010) as the seeded user β€” no OAuth page, no manual sign-in. It mints an access token with the local server's own JWKS_KEY (mint-desktop-login.mjs, env from the repo-root .env; refuses non-local hosts) and hands it to the dev build through LOBE_DESKTOP_DEV_REMOTE_LOGIN. Use it whenever the change under test is server-side. Its login is never saved into the shared snapshot. Agents the app spawns (Codex, Claude Code) get the same login through the lh sign-in file.
  • Concurrent instances (N worktrees / parallel runs): electron-dev.sh drives a pool β€” start <id> gives each its own CDP port, userData dir (with copied login), Vite port, and IPC id, and labels every window with the checkout and #<id> (dev builds only, from LOBE_DESKTOP_INSTANCE_LABEL) so a screenshot shows which instance it came from. Drive each with a distinct agent-browser --session s<port> --cdp <port>. Pool design, the collision matrix, and the login-copy recipe: .agents/acceptance/references/multi-instance.md.
  • Instance rules live in apps/desktop/scripts/devInstance.mts (ports, profile, IPC and label environment; the CDP check that the UI rendered; login snapshot seeding and saving). electron-dev.sh calls it through devInstanceCli.mts, and other launchers that run several checkouts import it, so change the rules there rather than in the shell script.

Heterogeneous-agent compatibility (project skill)

The live official-provider model matrix belongs to the testing-heterogeneous-agents project skill (.agents/skills/testing-heterogeneous-agents/). It extends Acceptance with the matrix semantics and harness while reusing the Electron environment, auth, and CDP commands above. It is manual-only: the user must explicitly invoke /testing-heterogeneous-agents in Claude Code or $testing-heterogeneous-agents in Codex. Do not automatically load or run it during other acceptance tasks.

Bot channels (project skill)

Bot-channel surfaces (Discord / Slack / Telegram / WeChat / Lark / QQ / iMessage) live in a separate LobeHub project skill, agent-testing-bot (.agents/skills/agent-testing-bot/). It extends this same Plan/Execute/Finish process and report pipeline for the native-app surfaces (osascript / bridge, macOS-only). Route bot tests there.

5. Project probes & quick navigation

.agents/acceptance/scripts/app-probe.sh is the LobeHub fast path into app state β€” use it instead of hand-rolling window.__LOBE_STORES eval snippets. Targets default to Electron (--cdp 9222); set AB_TARGET="--session <name>" for web sessions.

PROBE=.agents/acceptance/scripts/app-probe.sh
$PROBE auth           # login check β†’ { isSignedIn, userId }
$PROBE ready          # app root + exposed-store readiness
$PROBE server-auth    # authenticated server request β†’ 200 vs 401
$PROBE route          # current SPA route
$PROBE stores         # exposed store names
$PROBE ops            # running chat operations (type / startTime)
$PROBE wait-ops 60    # wait until no chat operation is running
$PROBE topic          # active topic + metadata from its paged view
$PROBE goto /settings # jump the SPA straight to a route (full reload)
$PROBE errors-install # install console.error interceptor
$PROBE errors         # dump captured errors

Routes worth jumping to:

Route Where it lands
/ Home (has a chat input)
/agent/<agentId> Agent conversation (latest topic)
/agent/<agentId>/<topicId> Specific topic in a conversation
/tasks Task list
/task Task assistant
/task/<taskId> Task detail
/page Documents (ζ–‡η¨Ώ)
/settings Settings
/community Discover / community

The Zustand store is at window.__LOBE_STORES (not __ZUSTAND_STORES__); the chat input is contenteditable (snapshot with -C). For deeper one-off state inspection, fall back to raw agent-browser --cdp 9222 eval. The agent-gateway closed-loop probe/dump/analyze tooling lives at .agents/acceptance/scripts/agent-gateway/; the closed-loop + JWKS setup workflow is in .agents/acceptance/references/agent-gateway.md.

.agents/acceptance/scripts/acceptance-guard.sh bounds a run's memory. It wraps the skill's resource guard with this repository's groups and thresholds and pins a per-run state directory, so a round that boots a browser, a dev server and type-check workers cannot swap the host out and freeze the client driving the run. Run and teardown discipline: PROCESS.md Step 4 and Step 6.

GUARD=.agents/acceptance/scripts/acceptance-guard.sh
export ACCEPTANCE_RUN_TAG="acceptance-<subject>-<timestamp>-$$"   # required

bash "$GUARD" start                     # before the first heavy command
bash "$GUARD" claim <pid>...            # a process this run started
bash "$GUARD" claim-browser <session>   # the browser behind an agent-browser session
bash "$GUARD" check --json              # 0 green, 10 yellow, 20 red, 2 unknown/error
bash "$GUARD" status --json             # samples, tiers, recorded stops
bash "$GUARD" stop                      # teardown, always
Setting Default Why
ACCEPTANCE_RUN_TAG β€” (required) Proves ownership; must be β‰₯ 8 chars and [A-Za-z0-9._-]+
ACCEPTANCE_GUARD_DIR ${TMPDIR:-/tmp}/lobe-acceptance/guard/<tag> Keeps the run's samples and claims out of the working tree
ACCEPTANCE_GUARD_YELLOW free=20 Linux host warning threshold (MemAvailable %)
ACCEPTANCE_GUARD_RED free=8 Linux host stop threshold (MemAvailable %)

Thresholds are host-level on purpose. The groups (Google Chrome for Testing, next-server|vite, tsrs) also match other worktrees' servers and other runs' browsers β€” five such processes held ~20 GB here β€” so a group or total RSS cap turns a merely busy machine red and stops a healthy run. The groups select what stop-owned may stop; they do not determine this adapter's tier.

On macOS, kernel pressure (kern.memorystatus_vm_pressure_level: 1 normal, 2 warning, 4 critical) determines the tier. Free-page and swap percentages are diagnostics only: neither low unused RAM nor a high fraction of dynamically allocated swap proves exhaustion. Three consecutive red samples are required before automatic termination. Unknown pressure exits 2 and never kills processes. On Linux, the MemAvailable thresholds apply; swap occupancy is diagnostic only, because swapped pages can stay in zram after pressure subsides. cgroup/PSI support is not implemented. Native Windows is unsupported. See the skill's platform policy.

6. Known constraints

  • QStash is a hard prerequisite for ANY agent-runtime test. Any test that runs an agent (lh agent run, durable ops, /api/agent/run, the server agent runtime) goes through AGENT_RUNTIME_MODE=queue (the default here and in production). Creating an agent operation POSTs to local QStash (127.0.0.1:8080); if QStash is down the run dies at operation creation with TypeError: fetch failed / ECONNREFUSED 127.0.0.1:8080 before any LLM call β€” no trace is recorded and it reads as unrelated to the env. Start it and gate before the first agent run:

    .agents/acceptance/scripts/init-dev-env.sh qstash    # terminal B β€” keep running
    .agents/acceptance/scripts/init-dev-env.sh preflight # non-zero exit if QStash (or Redis) is down
    

    Background self-iteration only runs for users who turned on Labs β†’ Self-evolving (off for new users), so a simple chat does not fan out; that does NOT remove QStash from the agent-runtime dispatch path. Treat QStash as required, not an "only-for-workflow" nicety.

  • Verify which runtime actually ran β€” do not assume. Some features have two execution paths and the UI silently picks one. Group orchestration is the concrete example: the chat UI defaults to the client runtime, while a fix may live in the server runtime / AGENT_RUNTIME_MODE=queue durable-op path. A test that exercises the wrong path passes green without touching the code under test. Prove which ran (a server agent_operations row, the QStash /api/agent/run steps, server-only log lines); if the UI will not take the server path, drive it directly (call the server TRPC mutation / endpoint).

  • apps/desktop and apps/cli are standalone installs (see Β§1) β€” run pnpm install inside each app the test will touch, not only at the root.

  • Server restart picks up server-side code changes. Next.js hot-reload may miss changes in workspace packages. Restart when changing apps/server/src/, src/server/, packages/database/, packages/types/, packages/prompts/; apps/cli/ needs none (runs from source).

  • OS-capture surfaces are macOS-only (bot channels, capture-app-window.sh, osascript screenshots): they come out black without Screen Recording (TCC) permission or when the display is asleep/locked. CDP-based evidence (agent-browser screenshot, bash .agents/skills/acceptance/scripts/cdp-screenshot.sh) is unaffected. Electron runs on Linux/cloud only under xvfb-run, and there OS capture does not work β€” prefer CDP evidence for cloud-portable runs.

  • ENABLE_MOCK_DEV_USER is not Web auth β€” it only affects server-side API context and does not satisfy Better Auth or stop the SPA redirect to /signin.

  • Marketplace/community endpoints are not part of the local auth gate; do not block local verification on marketplace API auth unless the change targets it.

Project references

Deeper LobeHub-specific notes kept alongside the moved scripts:

  • .agents/acceptance/references/auth.md β€” per-surface auth mechanics, the seeded web-login flow, the Electron OAuth+PKCE sign-in recipe and token-rotation traps, and the Chrome cookie-injection fallback + failure modes.
  • .agents/acceptance/references/agent-gateway.md β€” the local agent-gateway closed-loop setup / probe / dump / analyze workflow (scripts under .agents/acceptance/scripts/agent-gateway/).
  • .agents/acceptance/references/multi-instance.md β€” the concurrent Electron instance pool (N worktrees / parallel runs): per-instance CDP port, userData, Vite port, IPC id, the collision matrix, and the login-copy recipe.
  • .agents/acceptance/references/probe-field-notes.md β€” historical, detailed LobeHub probe incidents and their original cross-reference ids.
  • .agents/acceptance/references/common-mistakes-field-notes.md β€” original incident narratives retained after the maintained catalogue was normalized.

The living logs (.agents/acceptance/common-mistakes.md, .agents/acceptance/probe-mock-patterns.md) hold the LobeHub-specific probe/mock and mistake recipes; the generic layer lives in the installed skill's references/.