@beevibe/daemon 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +354 -0
  2. package/dist/main.js +1385 -0
  3. package/package.json +28 -0
package/README.md ADDED
@@ -0,0 +1,354 @@
1
+ # beevibe
2
+
3
+ > A self-hosted runtime for autonomous AI agent teams. Tasks flow between agents through hierarchy and peer mesh; memory carries forward; humans review and approve from a dashboard.
4
+
5
+ beevibe lets you run a small organization of Claude Code agents that delegate to each other, negotiate, escalate to humans when stuck, and build up shared memory over time. You provide the agents (a captain and a few ICs is a fine starting point), the work, and the review judgment. The platform handles the rest.
6
+
7
+ It's open source under the Apache-2.0 license. Everything is self-hosted: your Postgres, your `claude` CLI binaries, your filesystem.
8
+
9
+ ## Deploy
10
+
11
+ One-click cloud deploy:
12
+
13
+ [![Deploy on Railway](https://railway.com/button.svg)](https://railway.com/new/template?repo=https://github.com/beevibe-ai/beevibe)
14
+
15
+ This brings up `api` + `scheduler` + `web` services and a managed Postgres in one click. After the deploy finishes, set `ANTHROPIC_API_KEY` and `OPENAI_API_KEY` in the project's Variables tab, then visit the web service's public URL to sign up. You'll be prompted to install the local daemon as part of the welcome flow.
16
+
17
+ Self-host options:
18
+
19
+ - **Docker / docker-compose** — `git clone && docker compose up` against a tagged release (see [Self-hosting](#self-hosting) below).
20
+ - **Manual** — `pnpm install && pnpm build && pnpm start` per service against your own Postgres.
21
+
22
+ The repo and its tagged releases are the source of truth. The Railway button is a convenience layer; you can deploy the same code to Fly, Render, Coolify, k8s, or any container host.
23
+
24
+ ## What's inside
25
+
26
+ ```
27
+ beevibe/
28
+ ├── packages/
29
+ │ ├── core/ shared library (domain, ports, services, adapters, auth)
30
+ │ ├── api/ MCP tool surface for agents + REST for humans + mesh broker
31
+ │ ├── scheduler/ fallback claimant for null-runtime sessions + orphan reaper
32
+ │ ├── daemon/ runs on each user's machine; claims sessions and spawns CLIs locally
33
+ │ └── web/ Next.js dashboard with live updates over SSE
34
+
35
+ ├── skills/ Anthropic Agent Skills (markdown behavioral protocols)
36
+ ├── migrations/ node-pg-migrate SQL files
37
+ ├── scripts/ dev orchestrator + e2e smokes + provisioning helpers
38
+ └── docker-compose.yml Postgres 16 + pgvector
39
+ ```
40
+
41
+ Each package has its own README with details:
42
+
43
+ - [packages/core](./packages/core/README.md) — the library
44
+ - [packages/api](./packages/api/README.md) — the agent + human API server
45
+ - [packages/scheduler](./packages/scheduler/README.md) — server-fallback claimant + orphan reaper
46
+ - [packages/daemon](./packages/daemon/README.md) — local-runtime daemon (one per user machine)
47
+ - [packages/web](./packages/web/README.md) — the dashboard
48
+
49
+ ## Concepts in 60 seconds
50
+
51
+ - **Agent**. Has a hierarchy level — `ic` (worker), `team` (delegator), or `org` (decider). Owns a persona, a set of stable core-memory blocks, and a vector-indexed archive of facts. Identified by an `agent_id` and authenticates with a `bv_a_…` API key.
52
+ - **Person / user**. A human owner. Authenticates with a `bv_u_…` API key. Can act as their top-level agent through MCP, or use the dashboard for review.
53
+ - **Task**. A unit of work assigned to an agent. Moves through `pending → running → review → done` (or `failed` / `blocked` / `cancelled`). Tasks can spawn child tasks; parents auto-complete when their children settle.
54
+ - **Session**. One run of the `claude` CLI for one task. Has a transcript, a `cli_session_id` (for `--resume`), and usage telemetry (including cache-hit ratios).
55
+ - **Mesh**. Agents can `ask` peers one-shot questions or `negotiate` with team/org peers across multiple rounds. If they can't agree, either side can `escalate_to_humans` and a person resolves it from the dashboard.
56
+ - **Memory**. `save_memory(...)` archives a fact (`belief`/`pattern`/`gotcha`/`preference`/`decision`); after the session ends, the FactPromoter LLM may elevate it from `ic` scope to `team` or `org` based on whether it generalizes. `update_core_memory(...)` writes the durable per-agent blocks.
57
+ - **Skills**. Markdown procedural protocols ([Anthropic Agent Skills standard](https://agentskills.io/specification)) auto-discovered by `claude` from `<workspace>/.claude/skills/`. We ship two: `beevibe-pre-task-setup` and `beevibe-team-mesh-negotiation`.
58
+
59
+ ## Quick start
60
+
61
+ You'll need:
62
+
63
+ - Node ≥ 20 + pnpm 9
64
+ - Docker (for the Postgres + pgvector container)
65
+ - The [`claude`](https://docs.claude.com/en/docs/claude-code/overview) CLI on PATH
66
+ - An Anthropic API key + an OpenAI API key (the latter is for embeddings)
67
+
68
+ ```bash
69
+ git clone https://github.com/beevibe-ai/beevibe.git
70
+ cd beevibe
71
+ pnpm install
72
+
73
+ cp .env.example .env
74
+ # fill in ANTHROPIC_API_KEY and OPENAI_API_KEY
75
+
76
+ docker compose up -d # postgres + pgvector
77
+ pnpm migrate up # apply migrations to dev DB
78
+ pnpm dev # postgres + api + scheduler (+ tunnel if cloudflared is on PATH)
79
+ ```
80
+
81
+ `pnpm dev` runs [`scripts/dev.sh`](./scripts/dev.sh), which:
82
+
83
+ - starts Postgres if it isn't already running
84
+ - applies migrations
85
+ - spawns `@beevibe/api` (port 3000) and `@beevibe/scheduler` (health on 3001) in watch mode with `[api]` / `[exec]` log prefixes
86
+ - if `cloudflared` is on PATH, exposes the api at a `*.trycloudflare.com` URL and prints a paste-ready `mcp.json` snippet for remote `claude` CLI access (pass `--no-tunnel` to disable)
87
+
88
+ `Ctrl+C` tears the whole tree down.
89
+
90
+ To bring up the dashboard alongside, in a second terminal:
91
+
92
+ ```bash
93
+ pnpm --filter @beevibe/web dev -- -p 3030
94
+ # then visit http://localhost:3030
95
+ ```
96
+
97
+ The web app reads `NEXT_PUBLIC_BV_API_URL` (origin of the api server). For a working demo flow, run `pnpm seed-demo` to provision demo users (each with a password) — then sign in at `/sign-in`. The welcome wizard guides daemon setup.
98
+
99
+ ## Try it from your own Claude CLI
100
+
101
+ The `provision-demo.ts` script creates an idempotent demo team in your dev DB and prints a paste-ready MCP config so you can act *as* the captain agent from your own `claude` CLI:
102
+
103
+ ```bash
104
+ # Terminal 1
105
+ pnpm dev
106
+ # Wait for: "Tunnel URL: https://<random>.trycloudflare.com"
107
+
108
+ # Terminal 2
109
+ pnpm tsx scripts/provision-demo.ts
110
+ ```
111
+
112
+ This creates:
113
+
114
+ ```
115
+ person: demo-user (bv_u_<token>)
116
+ └── captain (team-tier, owned by demo-user)
117
+ ├── ic-alice (ic-tier)
118
+ └── ic-bob (ic-tier)
119
+ ```
120
+
121
+ Drop the printed snippet into your local `claude` CLI's MCP config (`~/.config/claude/mcp.json` or wherever your CLI reads it), then in any directory:
122
+
123
+ ```bash
124
+ claude
125
+ # In the chat, try:
126
+ # "who are my subordinates?" → find_subordinates → [ic-alice, ic-bob]
127
+ # "create a task for ic-alice: write a hello-world bash script"
128
+ # wait ~30-60s, watching [exec] logs in Terminal 1
129
+ # "what's the status of that task?" → check_work_status → done
130
+ # "ask ic-alice: where is hello.sh?" → mesh-ask round-trip
131
+ ```
132
+
133
+ Cleanup:
134
+
135
+ ```bash
136
+ pnpm tsx scripts/provision-demo.ts --print # re-print existing keys/snippet
137
+ pnpm tsx scripts/provision-demo.ts --clean # wipe demo rows (no reseed)
138
+ ```
139
+
140
+ `--clean` only removes rows owned by `demo-user`. It refuses if a demo agent has a live OS process so you don't wedge mid-flight tasks.
141
+
142
+ ## Skills
143
+
144
+ beevibe ships agent behavioral skills as `SKILL.md` files in [`/skills/`](./skills) — Anthropic's [Agent Skills open standard](https://agentskills.io/specification). The api and daemons sync them into each agent's workspace at dispatch time automatically; agent-spawned sessions get them for free.
145
+
146
+ For human users running `claude` locally and acting *as* a beevibe agent (the manual-smoke path above), install them once into your local Claude Code skill discovery dir:
147
+
148
+ ```bash
149
+ pnpm install-skills
150
+ ```
151
+
152
+ The install is idempotent — re-run after `git pull` to refresh. Only dirs named exactly `beevibe` or starting with `beevibe-` in `~/.claude/skills/` are touched; your other personal skills are left alone.
153
+
154
+ > **Reserved namespace**: the `beevibe-` prefix in `~/.claude/skills/` is reserved for skills shipped by this repo. If you author your own personal skills, use a different prefix (e.g., `mybeevibe-foo`) — anything not matching `beevibe-*` is invisible to the install command.
155
+
156
+ ## Self-hosting
157
+
158
+ Beyond the Railway one-click button, the same code runs anywhere that can run a container or Node 20+.
159
+
160
+ ### Option 1: Docker
161
+
162
+ Each service has a Dockerfile under [`infra/railway/`](./infra/railway). To run the full stack via Docker:
163
+
164
+ ```bash
165
+ git clone https://github.com/beevibe-ai/beevibe.git
166
+ cd beevibe
167
+ # Optional: pin to a tagged release for reproducible builds
168
+ # git checkout v0.1.0
169
+
170
+ # 1. Build the three service images
171
+ docker build -f infra/railway/Dockerfile.api -t beevibe-api .
172
+ docker build -f infra/railway/Dockerfile.scheduler -t beevibe-scheduler .
173
+ docker build -f infra/railway/Dockerfile.web \
174
+ --build-arg NEXT_PUBLIC_BV_API_URL=http://localhost:3000 \
175
+ -t beevibe-web .
176
+
177
+ # 2. Start Postgres
178
+ docker compose up -d postgres
179
+
180
+ # 3. Run migrations once
181
+ docker run --rm --network host \
182
+ -e DATABASE_URL=postgresql://beevibe:beevibe@localhost:5433/beevibe \
183
+ beevibe-api pnpm migrate:deploy up
184
+
185
+ # 4. Run the services (each in its own terminal or via your orchestrator)
186
+ docker run -p 3000:3000 --network host --env-file .env beevibe-api
187
+ docker run --network host --env-file .env beevibe-scheduler
188
+ docker run -p 8080:3000 --env-file .env beevibe-web
189
+ ```
190
+
191
+ Then visit `http://localhost:8080` to sign up.
192
+
193
+ ### Option 2: Bare Node
194
+
195
+ If you'd rather not use Docker:
196
+
197
+ ```bash
198
+ git clone https://github.com/beevibe-ai/beevibe.git
199
+ cd beevibe
200
+ # Optional: pin to a tagged release
201
+ # git checkout v0.1.0
202
+
203
+ pnpm install --frozen-lockfile
204
+ pnpm build
205
+ pnpm migrate:deploy up
206
+
207
+ # Start each service in its own process (use systemd, pm2, or your service manager)
208
+ node packages/api/dist/main.js # api on $PORT (default 3000)
209
+ node packages/scheduler/dist/main.js # scheduler (background worker)
210
+ pnpm --filter @beevibe/web start # web (next start, port from $PORT)
211
+ ```
212
+
213
+ Required env vars are listed in [`.env.example`](./.env.example). The api needs `DATABASE_URL`, `BEEVIBE_MCP_SERVER_URL`, `ANTHROPIC_API_KEY`, and `OPENAI_API_KEY` at minimum.
214
+
215
+ ### Notes for production self-hosting
216
+
217
+ - **Single api replica** for v1 (see [v1 single-instance API constraint](#v1-single-instance-api-constraint) below).
218
+ - **Postgres 16+** with `pgvector` extension. The included `docker-compose.yml` uses `pgvector/pgvector:pg16`.
219
+ - **Reverse proxy** in front of the api (nginx / Caddy / Cloudflare) must support WebSockets (`/runtime/ws`) and long-held HTTP responses (mesh negotiate held connections, up to 5 minutes idle).
220
+ - **CORS**: set `BEEVIBE_CORS_ORIGINS` to the public URL of the web service. Localhost variants are always allowed in addition.
221
+ - **Daemon distribution**: end users still install the [`beevibe-daemon`](./packages/daemon) on their own machines to run agent CLIs locally. The hosted api never spawns user CLIs.
222
+
223
+ ## Architecture
224
+
225
+ The dependency direction across packages is one-way and ESLint-enforced:
226
+
227
+ ```
228
+ core/domain → nothing
229
+ core/ports → domain
230
+ core/services → domain + ports (NEVER adapters)
231
+ core/adapters → ports it implements + domain
232
+ api/ → core (composition root)
233
+ scheduler/ → core (composition root)
234
+ daemon/ → core (workspace + runtime adapters, direct imports)
235
+ web/ → core (types only) + api (HTTP)
236
+ ```
237
+
238
+ The api, scheduler, and per-user daemons are independent processes. The api never talks to the scheduler or daemons over HTTP for task dispatch — Postgres is the integration point:
239
+
240
+ - The api writes task lifecycle changes (created, approved, revised, cancelled) and inserts `session` rows with `status='pending'`.
241
+ - A daemon claims sessions whose `preferred_runtime_id` matches its registered runtime and spawns the CLI locally on the user's machine.
242
+ - The scheduler claims null-runtime sessions (server-fallback for offline-target mesh asks) and runs the daemon-orphan reaper.
243
+ - Cancellation: api `UPDATE`s the row + `pg_notify('cancel_task', task_id)`; the active claimant (daemon or scheduler) aborts the in-flight session in <200ms.
244
+ - Live updates: every state-changing INSERT/UPDATE fires a `pg_notify`; api's `/api/stream` SSE endpoint relays them to the dashboard.
245
+
246
+ That decoupling means each component scales independently — many daemons (one per user machine), one or a few schedulers, a single api replica per region (see [v1 single-instance API constraint](#v1-single-instance-api-constraint) below).
247
+
248
+ ### v1 single-instance API constraint
249
+
250
+ The mesh resolver (`packages/api/src/mesh/server.ts:90`) and the
251
+ forthcoming chat / room resolvers are in-process `Map`s — when an agent's
252
+ `ask` fires, the API holds the HTTP request open and resolves it from
253
+ that map when the target's `respond_ask` lands. **Both halves of the
254
+ round-trip must hit the same API process** for v1; a multi-instance API
255
+ fronted by a load balancer can drop responses on the floor when the two
256
+ HTTP requests land on different replicas. Documented in code; tracked
257
+ for cross-instance federation via `pg_notify` as a follow-up. **Self-hosters
258
+ should run a single API replica until that ships.** The scheduler and
259
+ per-user daemons scale horizontally either way.
260
+
261
+ ## Common commands
262
+
263
+ ```bash
264
+ pnpm build # tsc across all packages (turbo-cached)
265
+ pnpm typecheck # types only
266
+ pnpm lint # eslint
267
+ pnpm test # vitest (unit + integration)
268
+ pnpm dev # full local stack (postgres + api + scheduler + tunnel)
269
+ pnpm migrate up # apply migrations to DATABASE_URL
270
+ pnpm migrate:test up # apply migrations to DATABASE_URL_TEST
271
+ pnpm install-skills # install beevibe skills into ~/.claude/skills/
272
+ ```
273
+
274
+ ## Tech stack
275
+
276
+ - TypeScript strict (ES2022, NodeNext)
277
+ - pnpm workspaces + Turborepo
278
+ - Postgres 16 + pgvector, raw `pg` driver (no ORM)
279
+ - node-pg-migrate
280
+ - Claude Code CLI runtime (spawned per-session)
281
+ - `@modelcontextprotocol/sdk`
282
+ - Next.js 14 + TanStack Query + Tailwind (dashboard)
283
+
284
+ ## End-to-end smokes
285
+
286
+ Live integration tests against real Postgres + LLM APIs. Each is gated by an env flag.
287
+
288
+ ```bash
289
+ # In-process smoke — api + scheduler bootstrapped in the same VM
290
+ RUN_M6_E2E=1 \
291
+ DATABASE_URL_TEST=postgresql://beevibe:beevibe@localhost:5433/beevibe_test \
292
+ OPENAI_API_KEY=... ANTHROPIC_API_KEY=... \
293
+ pnpm tsx scripts/m6-e2e.ts
294
+
295
+ # Multi-process smoke — api + scheduler as actual `node dist/main.js`
296
+ # subprocesses; verifies cross-process IPC, signal propagation, no orphans
297
+ RUN_M7_E2E=1 \
298
+ DATABASE_URL_TEST=postgresql://beevibe:beevibe@localhost:5433/beevibe_test \
299
+ OPENAI_API_KEY=... ANTHROPIC_API_KEY=... \
300
+ pnpm tsx scripts/m7-e2e.ts
301
+
302
+ # Skills + memory + cache-hit ratio smoke (M9 features)
303
+ RUN_M9_E2E=1 \
304
+ DATABASE_URL_TEST=postgresql://beevibe:beevibe@localhost:5433/beevibe_test \
305
+ OPENAI_API_KEY=... ANTHROPIC_API_KEY=... \
306
+ pnpm tsx scripts/m9-e2e.ts
307
+ ```
308
+
309
+ Apply test-DB migrations first with `pnpm migrate:test up`. All scripts truncate the test DB at the start, so back-to-back runs work.
310
+
311
+ ## Project status
312
+
313
+ The platform was built in milestones (M0 → M9), each with its own integration test:
314
+
315
+ | Milestone | What landed |
316
+ |---|---|
317
+ | M0 | Repo scaffold |
318
+ | M1 | Domain + ports + Postgres adapter + schema + migrations |
319
+ | M2 | Claude Code runtime adapter + workspace adapter |
320
+ | M3 | Memory subsystem + pgvector + LLM providers |
321
+ | M4 | API-key auth + agent provisioning |
322
+ | M5 | Executor binary (polling + dispatch) |
323
+ | M6 | API binary (MCP tools + REST + mesh + escalation + cancellation) |
324
+ | M7 | Multi-process integration test + dev orchestrator |
325
+ | M8 | Web dashboard (Next.js + SSE) |
326
+ | M9 | Skill system (auto-discovered behavioral protocols) + memory tooling refresh |
327
+
328
+ The full design discussions and PR references live in the [closed issues](https://github.com/beevibe-ai/beevibe/issues?q=is%3Aissue+is%3Aclosed) — each milestone has one tracking issue.
329
+
330
+ ## Contributing
331
+
332
+ Issues and PRs welcome. For non-trivial changes, open an issue first so we can align on direction.
333
+
334
+ A few conventions worth knowing:
335
+
336
+ - **Plan first, build second.** Each milestone is scoped end-to-end (schema → types → unit tests → integration test) before any code is written. See `tasks/` (gitignored) for the workflow.
337
+ - **TDD where it pays.** Domain types and pure services are test-first. Adapters get integration tests against real services (Postgres, real LLM keys).
338
+ - **No parallel systems.** When a feature replaces an older one, the old code is deleted in the same PR — no `if (new) ... else if (old) ...` branches.
339
+
340
+ ## License
341
+
342
+ The Beevibe source code is licensed under the [Apache License 2.0](./LICENSE).
343
+
344
+ The **Beevibe** name and logo are trademarks of the project — see
345
+ [TRADEMARK.md](./TRADEMARK.md). Apache 2.0 grants rights to the source
346
+ code; it does not grant rights to use the project's name or marks. Forks
347
+ and derivative works are welcome under any name that is not "Beevibe."
348
+
349
+ Contributing? See [CONTRIBUTING.md](./CONTRIBUTING.md). All commits must
350
+ include a `Signed-off-by:` trailer (the [Developer Certificate of Origin
351
+ v1.1](./CONTRIBUTING.md#developer-certificate-of-origin-v11)) — `git commit -s`.
352
+
353
+ Copyright (c) 2026 Zhe Pang. Rights to be assigned to Beevibe Inc. upon
354
+ its formation.