feat: npx agentree — CLI entry point with opencode auto-detection#6
feat: npx agentree — CLI entry point with opencode auto-detection#6
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a new command-line interface (CLI) for the application, making it easier to run and configure. Key changes include updating package.json for CLI packaging and build processes, adding a script to copy database migrations, and modifying the server to serve static client assets. The README.md has been updated with quick start instructions for the new CLI. A review comment suggests improving the robustness of the opencode configuration file parsing in the CLI by using optional chaining for safer property access.
| const cfg = JSON.parse(raw) as Record<string, unknown> | ||
| const server = cfg['server'] as Record<string, unknown> | undefined | ||
| const p = server?.['port'] | ||
| return typeof p === 'number' ? p : null |
There was a problem hiding this comment.
While the surrounding try...catch block prevents a crash, this logic for parsing the configuration file can be made more robust. The current implementation uses type assertions that may not hold true (e.g., if the config file content is null), relying on an exception to be caught. A safer approach is to use optional chaining to access nested properties, which gracefully handles null or undefined values at any point in the chain.
| const cfg = JSON.parse(raw) as Record<string, unknown> | |
| const server = cfg['server'] as Record<string, unknown> | undefined | |
| const p = server?.['port'] | |
| return typeof p === 'number' ? p : null | |
| const config = JSON.parse(raw); | |
| const server = (config as any)?.server; | |
| const p = (server as any)?.port; | |
| return typeof p === 'number' ? p : null; |
Closes #3
What
src/server/cli.ts— new CLI entry point (#!/usr/bin/env node) with:--opencode-urlflag →OPENCODE_API_URLenv → localhost:6543 → localhost:4096 →~/.config/opencode/opencode.json~/.agentree/agentree.dbdb/index.tsandopencode/client.tsread env at module-load time)src/server/app.ts—createApp()now accepts{ staticDir? }option; addsserveStatic+ SPA fallback when provided. No change to dev behavior.scripts/copy-migrations.mjs— copiesdrizzle/→dist/server/drizzle/as part of buildpackage.json— removedprivate, addedbin,files,prepublishOnly; updatedbuildscriptREADME.md— added Quick start section withnpx agentreeusageWhy
Closes the gap between "clone and run" and "zero-setup single command". Users with opencode already running can start Agentree immediately.
Test plan
pnpm testpasses (72 tests)pnpm exec tsc --noEmitpassespnpm exec tsc --noEmit -p tsconfig.client.jsonpassespnpm buildproducesdist/server/cli.jswith#!/usr/bin/env nodeanddist/server/drizzle/with all migrationsnode dist/server/cli.js --helpprints usagepnpm devstill works (no regression to dev workflow)