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 .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
43 changes: 43 additions & 0 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Pull Request

on:
pull_request:
branches: [main]

jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- run: nix run .#lint

test:
name: Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- run: nix run .#test

build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: DeterminateSystems/nix-installer-action@main
- run: nix run .#build
- uses: actions/upload-artifact@v4
with:
name: dist
path: dist/

merge-ready:
runs-on: ubuntu-latest
if: ${{ always() }}
needs: [lint, test, build]
steps:
- if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
run: exit 1
- run: echo "LGTM"
22 changes: 22 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Release

on:
push:
branches: [main]
workflow_dispatch:

permissions:
contents: write

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: DeterminateSystems/nix-installer-action@main
- run: nix run .#release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Binaries
dist/
*.exe

# Test/coverage
*.test
coverage.out

# IDE
.idea/
.vscode/

# OS
.DS_Store

# Direnv
!.envrc
38 changes: 38 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: 2

before:
hooks:
- go mod tidy

builds:
- env:
- CGO_ENABLED=0
ldflags:
- -s -w -X main.version={{ .Version }}
goos:
- linux
- windows
- darwin
goarch:
- amd64
- arm64

archives:
- formats:
- tar.gz
name_template: >-
{{ .ProjectName }}_{{ title .Os }}_
{{- if eq .Arch "amd64" }}x86_64{{ else }}{{ .Arch }}{{ end }}
format_overrides:
- goos: windows
formats:
- zip

changelog:
sort: asc
groups:
- title: Features
regexp: '^.*?feat(\([[:word:]]+\))??!?:.+$'
- title: Bug Fixes
regexp: '^.*?fix(\([[:word:]]+\))??!?:.+$'
- title: Other changes
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2025 Christian

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# llm-cli

A lightweight CLI tool for interacting with LLMs from the terminal.

## Features

- **Generate commit messages** — AI-powered conventional commit messages from your staged changes
- **Ask questions** — Get answers from an LLM directly in your terminal

## Installation

### Nix

```bash
nix profile install github:csvenke/llm-cli
```

### Binary releases

Download pre-built binaries from [GitHub Releases](https://github.com/csvenke/llm-cli/releases).

## Usage

### Ask a question

```bash
llm ask "How do I reverse a string in Go?"
```

### Generate a commit message

Stage your changes and run:

```bash
llm commit
```

To amend the previous commit:

```bash
llm commit -a
```

## Configuration

Set one of the following environment variables (checked in order):

| Variable | Description |
|---|---|
| `OPENCODE_ZEN_API_KEY` | OpenCode Zen API key |
| `ANTHROPIC_API_KEY` | Anthropic API key |
| `OPENAI_API_KEY` | OpenAI API key |

## License

[MIT](LICENSE)
61 changes: 61 additions & 0 deletions flake.lock

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

45 changes: 45 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs =
inputs@{
self,
flake-parts,
nixpkgs,
...
}:
flake-parts.lib.mkFlake { inherit inputs; } {
systems = nixpkgs.lib.systems.flakeExposed;
perSystem =
{ system, ... }:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: { go = prev.go_1_24; })
];
};
inherit (pkgs) lib callPackage;
version = self.shortRev or self.dirtyShortRev or "snapshot";
scripts = lib.packagesFromDirectoryRecursive {
inherit callPackage;
directory = ./nix/scripts;
};
llm-cli = callPackage ./nix/package.nix {
inherit version;
};
shell = callPackage ./nix/shell.nix { };
in
{
packages = scripts // {
default = llm-cli;
};
devShells = {
default = shell;
};
};
};
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module llm

go 1.24.4
31 changes: 31 additions & 0 deletions internal/ask/ask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ask

import (
"context"
"fmt"
"io"
"strings"

"llm/internal/providers"
)

// Run executes the ask command with the given arguments.
// Returns an error if no arguments are provided or if the provider fails.
func Run(ctx context.Context, provider providers.Provider, output io.Writer, args []string) error {
if output == nil {
output = io.Discard
}

if len(args) == 0 {
return fmt.Errorf("usage: llm ask <question>")
}

question := strings.Join(args, " ")
response, err := provider.Complete(ctx, "", question)
if err != nil {
return err
}

_, err = fmt.Fprintln(output, response)
return err
}
Loading