Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# dependencies (bun install)
node_modules
package-lock.json

# output
out
Expand Down
38 changes: 15 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,12 @@ GitHits gives your AI coding assistant access to verified, canonical code exampl
## Quick Start

```sh
npx githits login
npx githits init
```

This opens your browser to authenticate with your [GitHits](https://githits.com) account. Once logged in, set up your AI assistant:

**Claude Code**
`init` authenticates with your [GitHits](https://githits.com) account, then auto-detects your installed coding tools and configures each one with GitHits MCP.

```sh
claude mcp add githits -- npx -y githits mcp start
```

**Cursor / VS Code**

Add to your MCP settings JSON:

```json
{
"mcpServers": {
"githits": {
"command": "npx",
"args": ["-y", "githits", "mcp", "start"]
}
}
}
```
Supported tools: Claude Code, Cursor, Windsurf, VS Code / Copilot, Cline, Claude Desktop, Codex CLI, Gemini CLI, and Google Antigravity.

That's it. Your assistant now has a `search` tool it will use automatically when it needs code examples.

Expand Down Expand Up @@ -84,7 +65,8 @@ export GITHITS_API_TOKEN=ghi-your-token-here
## Commands

```
githits login Authenticate with your GitHits account
githits init Authenticate and configure your coding tools with GitHits MCP
githits login Authenticate with your GitHits account (also runs as part of init)
githits logout Remove stored credentials
githits mcp Show setup instructions in a terminal; starts MCP server when piped
githits mcp start Always start MCP server (for use in MCP config files)
Expand All @@ -99,6 +81,16 @@ githits auth status Show current authentication status
| `GITHITS_MCP_URL` | Override MCP server URL | `https://mcp.githits.com` |
| `GITHITS_API_URL` | Override REST API URL | `https://api.githits.com` |

## Development

```sh
bun run build
npm link
githits --version
```

After the initial `npm link`, only `bun run build` is needed for subsequent changes.

## Requirements

- Node.js 20 or later
Expand Down
45 changes: 45 additions & 0 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions docs/implementation/cli-commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,27 @@ The CLI exposes three commands (`search`, `languages`, `feedback`) that mirror t

| Command | Required Args | Options | Description |
|---|---|---|---|
| `init` | — | `-y, --yes`, `--skip-login` | Authenticate and set up MCP server for coding agents |
| `search <query>` | `-l, --lang <language>` | `--license <mode>`, `--explain`, `--json` | Search for code examples |
| `languages [query]` | — | `--json` | List or filter supported languages |
| `feedback <solution_id>` | `--accept` or `--reject` | `-m, --message <text>`, `--json` | Submit feedback on a search result |

### `githits init`

```
githits init # Interactive: authenticate, scan, configure unconfigured agents
githits init --yes # Non-interactive: authenticate, configure all unconfigured agents
githits init --skip-login # Skip authentication, configure tools only
```

Authenticates with GitHits (via OAuth in the browser), then scans for available coding agents, checks which are already configured, and sets up unconfigured ones with your confirmation. All agents are pre-checked before any setup begins, so the status display is fully resolved. CLI agents are considered available only when their executable is on `PATH`; related dot-directories alone do not count. Config-file agents remain filesystem-detected using their known app/config directories. If already authenticated, the login step is skipped automatically. If login fails, the user is prompted to continue with tool setup anyway. If all detected agents are already configured, exits early with a summary.

Supports Claude Code, Cursor, Windsurf, VS Code / Copilot, Cline, Claude Desktop, Codex CLI, Gemini CLI, and Google Antigravity. Uses plugin install (Claude Code), CLI commands (Codex, Gemini CLI), and atomic config file writes (Cursor, Windsurf, VS Code, Cline, Claude Desktop, Google Antigravity). CLI agents use read-only check commands (e.g., `claude plugin list`) to determine configuration status before prompting.

The command uses `createContainer()` lazily for the login step. Tool detection and configuration use lightweight dependencies that don't require auth.

**File structure:** The init command uses a subdirectory (`src/commands/init/`) because it has distinct submodules (agent definitions, setup handlers, orchestrator). This is an accepted variation for commands with significant internal complexity.

### `githits search`

```
Expand Down Expand Up @@ -75,6 +92,8 @@ Each command follows this pattern:
4. **Register in CLI** — Import and call `registerXxxCommand(program)` in `src/cli.ts`
5. **Update help text** — If the command is a primary workflow, add it to the `addHelpText("after", ...)` block

For complex commands with multiple submodules, a subdirectory (`src/commands/xxx/`) with an `index.ts` barrel is acceptable (see `init` command for example).

## Error Handling

- **Auth errors** — `requireAuth()` prints instructions and calls `process.exit(1)`
Expand Down Expand Up @@ -103,6 +122,11 @@ All commands support two output modes:
| `src/shared/require-auth.ts` | Auth guard shared with MCP server |
| `src/shared/colors.ts` | ANSI color utilities and `shouldUseColors()` |
| `src/container.ts` | Dependency container with `githitsService` |
| `src/commands/init/init.ts` | Init command orchestrator |
| `src/commands/init/agent-definitions.ts` | Agent detection and setup config |
| `src/commands/init/setup-handlers.ts` | CLI exec and config file merge logic |
| `src/services/prompt-service.ts` | Interactive prompt abstraction |
| `src/services/exec-service.ts` | CLI command execution abstraction |

## Related Documentation

Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "githits",
"description": "CLI companion for GitHits - code examples from global open source for developers and AI assistants",
"version": "0.1.5",
"version": "0.1.6",
"type": "module",
"files": [
"dist",
Expand Down Expand Up @@ -60,6 +60,7 @@
"access": "public"
},
"dependencies": {
"@inquirer/prompts": "^8.3.2",
"@modelcontextprotocol/sdk": "^1.23.0",
"@napi-rs/keyring": "^1.2.0",
"commander": "^14.0.2",
Expand Down
5 changes: 5 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { version } from "../package.json";
import {
registerAuthStatusCommand,
registerFeedbackCommand,
registerInitCommand,
registerLanguagesCommand,
registerLoginCommand,
registerLogoutCommand,
Expand All @@ -27,6 +28,7 @@ program
"after",
`
Getting started:
githits init Set up MCP for your coding agents
githits login Authenticate with your GitHits account
githits mcp Start MCP server for your AI assistant
githits search "query" --lang python Search for code examples
Expand All @@ -36,6 +38,9 @@ Docs: https://app.githits.com/docs/
Support: support@githits.com`,
);

// Setup command
registerInitCommand(program);

// Auth commands
registerLoginCommand(program);
registerLogoutCommand(program);
Expand Down
6 changes: 6 additions & 0 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ export {
feedbackAction,
registerFeedbackCommand,
} from "./feedback.js";
export {
type InitDependencies,
type InitOptions,
initAction,
registerInitCommand,
} from "./init/index.js";
export {
type LanguagesDependencies,
type LanguagesOptions,
Expand Down
Loading
Loading