sourcebot-code
v0.1.12
Published
CLI for searching code across Sourcebot instances
Readme
Sourcebot CLI
A command-line interface for searching code across multiple repository instances using Sourcebot.
Features
- Initialize configuration - Set up Sourcebot host and API credentials interactively
- List repositories - View all indexed repositories with optional filtering
- Search code - Find code patterns across all repositories
- JSON output - All commands support JSON output for programmatic use
- Flexible configuration - Use config file, environment variables, or CLI flags
Installation
npm install sourcebot-cliConfiguration
Interactive Setup
sourcebot initThis creates a configuration file at ~/.sourcebot/config.json:
{
"host": "https://sourcebot.example.com",
"apiKey": "your-api-key"
}Environment Variables
export SOURCEBOT_HOST=https://sourcebot.example.com
export SOURCEBOT_API_KEY=your-api-keyCLI Flags
Pass credentials directly to commands:
sourcebot list --host https://sourcebot.example.com --key your-api-keyPrecedence (highest to lowest):
- CLI flags (
--host,--key) - Environment variables (
SOURCEBOT_HOST,SOURCEBOT_API_KEY) - Config file (
~/.sourcebot/config.json)
Commands
sourcebot init
Initialize and test your Sourcebot configuration.
sourcebot initValidates the host URL and API key by connecting to the Sourcebot instance.
sourcebot list [options]
List all indexed repositories.
sourcebot list
sourcebot list --name=ceres
sourcebot list --type=gitlab
sourcebot list --match=".*bpm.*" --jsonOptions:
--name <string>- Filter by repository name (case-insensitive substring)--type <string>- Filter by code host type (gitlab, github, bitbucket)--match <regex>- Filter by regex pattern on display name--json- Output in JSON format (default: table)--host <string>- Override Sourcebot host--key <string>- Override API key
sourcebot search <query> [options]
Search for code patterns across repositories.
sourcebot search "transactionLog"
sourcebot search "transactionLog" --matches=100
sourcebot search "transactionLog" --context=50 --jsonOptions:
--matches <number>- Limit number of matches (default: 50)--context <number>- Context lines per match (default: 99999999)--repo <id>- Filter results to specific repository ID--json- Output in JSON format (default: table)--host <string>- Override Sourcebot host--key <string>- Override API key
Output Formats
Table (default)
Clean, human-readable tables:
ID Display Name Type Indexed At
──── ────────────────────────────── ────── ──────────────────────
3059 ceres/ceresintegracionromaneos gitlab 2026-03-25
3967 servicefactory/mymsa gitlab 2026-03-25JSON
Complete structured data with metadata:
{
"success": true,
"data": [...],
"meta": {
"count": 2,
"filtered": true,
"filter": { "name": "ceres" }
}
}Development
Setup
npm install
npm run devBuild
npm run buildTest
npm run testType Check
npm run typecheckAPI Reference
SourcebotClient
import { SourcebotClient } from 'sourcebot-cli';
const client = new SourcebotClient({
host: 'https://sourcebot.example.com',
apiKey: 'your-api-key',
});
// List repositories
const repos = await client.listRepos();
// Search code
const results = await client.search('query', {
matches: 50,
contextLines: 99999999,
});Config Management
import { loadConfig, saveConfig } from 'sourcebot-cli';
// Load configuration (respects precedence)
const config = loadConfig({
host: 'https://custom.host',
});
// Save configuration
saveConfig({
host: 'https://sourcebot.example.com',
apiKey: 'api-key',
});Filtering
import { filterRepos } from 'sourcebot-cli';
const filtered = filterRepos(repos, {
name: 'ceres',
type: 'gitlab',
match: '.*integration.*',
});Security Notes
- Never commit
~/.sourcebot/config.jsonto version control - Use environment variables for CI/CD pipelines
- Credentials are only sent to the specified Sourcebot host
- Config file is stored in user home directory with restricted permissions
License
MIT
