Guide to building Shep AI CLI for development and distribution.
Shep uses the TypeScript compiler (tsc) with tsc-alias for building:
tsconfig.build.jsontsc-aliasweb/ for distribution# Start the web dev server
pnpm dev
# Or run CLI and web separately
pnpm dev:cli # Run CLI via ts-node
pnpm dev:web # Start Next.js dev server
pnpm build
Output goes to dist/ (mirroring src/ structure with compiled .js files).
# Check types without emitting
pnpm typecheck
# Watch mode
pnpm typecheck:watch
The CLI build command (pnpm build) runs:
tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json && pnpm build:web:prod
tsc -p tsconfig.build.json - Compiles TypeScript to JavaScript in dist/tsc-alias -p tsconfig.build.json - Resolves @/ path aliases to relative pathspnpm build:web:prod - Builds the Next.js web UI and copies output to web/// tsconfig.json
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "bundler",
"lib": ["ES2022"],
"strict": true,
"esModuleInterop": true,
"skipLibCheck": true,
"declaration": true,
"declarationMap": true,
"sourceMap": true,
"outDir": "dist",
"rootDir": "src",
"baseUrl": ".",
"paths": {
"@/*": ["src/*"]
}
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "tests"]
}
Output goes to dist/ mirroring the src/ directory structure:
dist/
├── src/
│ ├── presentation/
│ │ ├── cli/ # CLI entry point
│ │ ├── tui/ # TUI components
│ │ └── web/ # Web server integration
│ └── ...
└── packages/
└── core/
└── src/ # Core business logic
The Next.js web UI is built separately and copied to web/ for distribution:
web/ # Pre-built Next.js output (in .gitignore)
Package.json bin configuration:
{
"bin": {
"shep": "./dist/src/presentation/cli/index.js"
}
}
Only essential dependencies for production:
{
"dependencies": {
"commander": "^12.0.0",
"better-sqlite3": "^9.0.0"
}
}
Development-only:
{
"devDependencies": {
"typescript": "^5.3.0",
"tsc-alias": "^1.8.0",
"@types/node": "^20.0.0",
"@types/better-sqlite3": "^7.0.0"
}
}
better-sqlite3 requires native compilation:
# Rebuild for current platform
npm rebuild better-sqlite3
# Or during install
npm install --build-from-source
For distribution, we use prebuild:
{
"scripts": {
"install": "prebuild-install || node-gyp rebuild"
}
}
pnpm clean && pnpm build
Clean script:
{
"scripts": {
"clean": "rimraf dist coverage"
}
}
pnpm build
npm pack
Creates shep-ai-cli-x.x.x.tgz.
pnpm build
npm publish --access public
Source maps are generated by tsc when sourceMap: true is set in tsconfig.build.json.
pnpm build
du -sh dist/*
# .github/workflows/build.yml
jobs:
build:
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
node: [18, 20]
runs-on: $
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: $
- run: npm ci
- run: pnpm build
# .github/workflows/release.yml
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
- run: npm ci
- run: pnpm build
- run: npm publish --access public
env:
NODE_AUTH_TOKEN: $
Update when:
Related docs: