Problem or motivation
Agentree currently requires cloning the repo and running pnpm dev. Users (especially those already running opencode) should be able to start Agentree with a single command:
Proposed solution
New file: src/server/cli.ts
CLI entry point (#!/usr/bin/env node) with the following startup sequence:
- Parse CLI args:
--port (default 3001), --opencode-url, --help
- Auto-detect opencode (in priority order):
--opencode-url flag → use directly
OPENCODE_API_URL env → use directly
GET http://localhost:6543/global/health (2s timeout) → if 200, use
GET http://localhost:4096/global/health (2s timeout) → if 200, use
- Parse
~/.config/opencode/opencode.json for server.port → health-check
- Print friendly error with install instructions →
process.exit(1)
- Resolve DB path:
DB_PATH env → ~/.agentree/agentree.db (auto-creates dir)
- Set
process.env.OPENCODE_API_URL, DB_PATH, CORS_ORIGIN
- Dynamic imports after env is set (critical —
db/index.ts and opencode/client.ts read env at module-load time)
- Run migrations, start server with static file serving, print startup banner
Modified: src/server/app.ts
Add AppOptions = { staticDir?: string } parameter to createApp(). When staticDir is provided, add serveStatic for /assets/* and SPA fallback for all non-/api routes. No change to existing dev behavior.
Modified: package.json
- Remove
"private": true
- Add
"bin": { "agentree": "./dist/server/cli.js" }
- Add
"files": ["dist/server/", "dist/client/"]
- Update
build script to also copy drizzle/ → dist/server/drizzle/
- Add
"prepublishOnly": "pnpm run build"
New file: scripts/copy-migrations.mjs
import { cpSync } from 'node:fs'
cpSync('drizzle', 'dist/server/drizzle', { recursive: true })
DB path change
| Context |
Path |
pnpm dev |
./agentree.db (unchanged) |
npx agentree |
~/.agentree/agentree.db |
| override |
DB_PATH=./path npx agentree |
README
Add npx agentree quickstart section near the top.
Alternatives considered
Problem or motivation
Agentree currently requires cloning the repo and running
pnpm dev. Users (especially those already running opencode) should be able to start Agentree with a single command:Proposed solution
New file:
src/server/cli.tsCLI entry point (
#!/usr/bin/env node) with the following startup sequence:--port(default 3001),--opencode-url,--help--opencode-urlflag → use directlyOPENCODE_API_URLenv → use directlyGET http://localhost:6543/global/health(2s timeout) → if 200, useGET http://localhost:4096/global/health(2s timeout) → if 200, use~/.config/opencode/opencode.jsonforserver.port→ health-checkprocess.exit(1)DB_PATHenv →~/.agentree/agentree.db(auto-creates dir)process.env.OPENCODE_API_URL,DB_PATH,CORS_ORIGINdb/index.tsandopencode/client.tsread env at module-load time)Modified:
src/server/app.tsAdd
AppOptions = { staticDir?: string }parameter tocreateApp(). WhenstaticDiris provided, addserveStaticfor/assets/*and SPA fallback for all non-/apiroutes. No change to existing dev behavior.Modified:
package.json"private": true"bin": { "agentree": "./dist/server/cli.js" }"files": ["dist/server/", "dist/client/"]buildscript to also copydrizzle/→dist/server/drizzle/"prepublishOnly": "pnpm run build"New file:
scripts/copy-migrations.mjsDB path change
pnpm dev./agentree.db(unchanged)npx agentree~/.agentree/agentree.dbDB_PATH=./path npx agentreeREADME
Add
npx agentreequickstart section near the top.Alternatives considered
db/index.tsandopencode/client.tsto use lazy env reading (Proxy pattern) — rejected in favor of dynamic imports incli.tswhich requires zero changes to existing modules.