Skip to content

feat: npx agentree — CLI entry point with opencode auto-detection#6

Merged
StatPan merged 1 commit intomainfrom
feat/issue-3-npx-cli
Apr 9, 2026
Merged

feat: npx agentree — CLI entry point with opencode auto-detection#6
StatPan merged 1 commit intomainfrom
feat/issue-3-npx-cli

Conversation

@StatPan
Copy link
Copy Markdown
Owner

@StatPan StatPan commented Apr 9, 2026

Closes #3

What

  • src/server/cli.ts — new CLI entry point (#!/usr/bin/env node) with:
    • opencode auto-detection: --opencode-url flag → OPENCODE_API_URL env → localhost:6543 → localhost:4096 → ~/.config/opencode/opencode.json
    • DB path defaulting to ~/.agentree/agentree.db
    • Dynamic imports after env vars are set (required since db/index.ts and opencode/client.ts read env at module-load time)
    • Friendly error message when opencode is not found
  • src/server/app.tscreateApp() now accepts { staticDir? } option; adds serveStatic + SPA fallback when provided. No change to dev behavior.
  • scripts/copy-migrations.mjs — copies drizzle/dist/server/drizzle/ as part of build
  • package.json — removed private, added bin, files, prepublishOnly; updated build script
  • README.md — added Quick start section with npx agentree usage

Why

Closes the gap between "clone and run" and "zero-setup single command". Users with opencode already running can start Agentree immediately.

Test plan

  • pnpm test passes (72 tests)
  • pnpm exec tsc --noEmit passes
  • pnpm exec tsc --noEmit -p tsconfig.client.json passes
  • pnpm build produces dist/server/cli.js with #!/usr/bin/env node and dist/server/drizzle/ with all migrations
  • node dist/server/cli.js --help prints usage
  • pnpm dev still works (no regression to dev workflow)

@StatPan StatPan merged commit 8cdd071 into main Apr 9, 2026
1 check passed
@StatPan StatPan deleted the feat/issue-3-npx-cli branch April 9, 2026 11:38
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/server/cli.ts
Comment on lines +61 to +64
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Suggested change
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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: npx agentree — CLI entry point with opencode auto-detection

1 participant