jotbot

package module
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 8, 2023 License: MIT Imports: 15 Imported by: 0

README

JotBot - AI-powered code documentation

Go Reference Test jotbot-ts

JotBot auto-generates missing documentation for your Go and TypeScript codebase. The documentation of this repository was entirely generated by JotBot using gpt-4, so I encourage you to explore the source code to see the quality of the generated documentation.

You can find generated TypeScript documentation in packages/jotbot.

Quick Start

Install
go install github.com/modernice/jotbot/cmd/jotbot@latest
Add TypeScript Support
npm i -g jotbot-ts@latest
pnpm i -g jotbot-ts@latest
Use

Within your Go and/or TypeScript codebase, run:

jotbot generate

Features

  • Generate documentation for Go and TypeScript codebases
  • Customize glob patterns for included and excluded files
  • Filter code symbols by matching regular expressions
  • Limit the number of files to generate documentation for
  • Run in dry mode to preview changes without applying them
  • Control the AI model and token limits used for generating documentation
  • Optionally commit changes to a Git branch

Models

JotBot utilizes OpenAI's GPT models to generate documentation. By default, JotBot uses the gpt-3.5-turbo model which provides good results at a cost-effective rate. However, the best results are produced by gpt-4 and text-davinci-003, which are 10-30x more expensive than gpt-3.5-turbo.

You are free to choose any model from the OpenAI Docs and pass it via the --model|-m flag:

jotbot generate -m text-davinci-003

Installation

Via go install

If you have Go installed, you can simply install JotBot using go install:

go install github.com/modernice/jotbot/cmd/jotbot@latest
Standalone Binary

You can download the latest binary from the Releases page.

TypeScript Support

To enable TypeScript (and JavaScript) support, you also need to install the jotbot-ts npm package.

npm install -g jotbot-ts
pnpm install -g jotbot-ts

Usage

To generate missing documentation for your codebase, run the following command:

jotbot generate [options]

By default, this command will find all Go and TypeScript (and JavaScript) files in the current and nested directories and generate documentation for them. Excluded from the search are by default:

  • **/.*/**
  • **/dist/**
  • **/node_modules/**
  • **/vendor/**
  • **/testdata/**
  • **/test/**
  • **/tests/**
  • **/*.pb.go
To-Do

CLI options

jotbot --help
Option Description Default
--root Root directory of the repository "."
--include, -i Glob pattern(s) to include files
--include-tests, -T Include TestXXX() functions (Go-specific)
--exclude, -e Glob pattern(s) to exclude files
--exclude-internal, -E Exclude 'internal' directories (Go-specific) true
--match Regular expression(s) to match identifiers
--symbol, -s Symbol(s) to search for in code (TS/JS-specific)
--clear, -c Force-clear comments in generation prompt (Go-specific)
--branch Branch name to commit changes to (leave empty to not commit)
--limit Limit the number of files to generate documentation for 0
--dry Print the changes without applying them false
--model, -m OpenAI model used to generate documentation "gpt-3.5-turbo"
--maxTokens Maximum number of tokens to generate for a single documentation 512
--parallel, -p Number of files to handle concurrently 4
--workers Number of workers to use per file 2
--override, -o Override existing documentation (Go-specific)
--key OpenAI API key
--verbose, -v Enable verbose logging false

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Finding added in v0.0.4

type Finding struct {
	Identifier string
	File       string
	Language   string
}

Finding represents a single code identifier found within a file with its associated language.

func (Finding) String added in v0.0.4

func (f Finding) String() string

String returns a formatted string representation of the Finding, including the file path and identifier.

type JotBot added in v0.0.4

type JotBot struct {
	// contains filtered or unexported fields
}

JotBot is a utility for finding and generating code snippets in various programming languages within a project. It supports configurable languages, filters, and file systems, and offers patching capabilities for applying generated changes.

func New

func New(root string, opts ...Option) *JotBot

New creates a new JotBot instance with the given root directory and options. The returned JotBot is configured with the provided languages, filters, and logger.

func (*JotBot) ConfigureLanguage added in v0.0.4

func (bot *JotBot) ConfigureLanguage(name string, lang Language)

ConfigureLanguage configures a Language for the given name, associating it with the provided extensions. The Language is used by JotBot to find and generate code for identifiers in files with the associated extensions.

func (*JotBot) Extensions added in v0.0.4

func (bot *JotBot) Extensions() []string

Extensions returns a slice of file extensions that are associated with configured languages in the JotBot instance.

func (*JotBot) Find added in v0.0.4

func (bot *JotBot) Find(ctx context.Context, opts ...find.Option) ([]Finding, error)

Find searches the JotBot's root directory for files matching the provided options, extracts identifiers from those files using the configured languages, and returns a slice of Findings containing the extracted identifiers, file paths, and language names. It filters the extracted identifiers based on the JotBot's configured filters. If any error occurs during the process, it returns the error.

func (*JotBot) Generate added in v0.0.4

func (bot *JotBot) Generate(ctx context.Context, findings []Finding, svc generate.Service, opts ...generate.Option) (*Patch, error)

Generate creates a Patch by generating code snippets for the given Findings using the provided generate.Service and options. It returns a Patch that can be applied to the project or used in a dry run.

type Language added in v0.0.4

type Language interface {
	patch.Language
	generate.Language

	// Extensions returns a slice of file extensions that are supported by the
	// Language. Each extension is associated with a specific language
	// implementation for code generation and patching purposes.
	Extensions() []string

	// Find searches the provided byte slice for identifiers in the language and
	// returns a slice of found identifiers along with any error encountered during
	// the search.
	Find([]byte) ([]string, error)
}

Language is an interface that combines the patch.Language and generate.Language interfaces, adding methods to retrieve supported file extensions and find identifiers within source code. It is used by JotBot to work with different programming languages, allowing for language-specific operations such as finding identifiers and generating patches.

type Option

type Option func(*JotBot)

Option is a function that takes a pointer to a JotBot and modifies its configuration. It can be used to set custom languages, loggers, or filters for the JotBot instance.

func Match added in v0.0.4

func Match(filters ...*regexp.Regexp) Option

Match appends the provided regular expression filters to the JotBot's filters. These filters are used to determine which findings should be included in the final result when searching for identifiers in files.

func WithLanguage added in v0.0.4

func WithLanguage(name string, lang Language) Option

WithLanguage configures a JotBot instance to use the specified language for processing files with the given name. It associates the language with its supported file extensions.

func WithLogger

func WithLogger(h slog.Handler) Option

WithLogger configures a JotBot to use the provided slog.Handler for logging.

type Patch added in v0.0.4

type Patch struct {
	*patch.Patch
	// contains filtered or unexported fields
}

Patch is a wrapper around a patch.Patch that provides additional functionality for applying and dry-running patches using Language implementations. It is used to generate, apply, and preview changes to source code based on the provided findings.

func (*Patch) Apply added in v0.0.4

func (p *Patch) Apply(ctx context.Context, root string) error

Apply applies the patch to the filesystem rooted at the given root path, using the configured languages for applying changes. The operation can be canceled through the provided context. It returns an error if any issues are encountered during the application process.

func (*Patch) DryRun added in v0.0.4

func (p *Patch) DryRun(ctx context.Context, root string) (map[string][]byte, error)

DryRun applies the patch to a virtual filesystem rooted at the provided root path, returning a map of file paths to their new contents without modifying the actual filesystem. The operation can be canceled through the provided context.

Directories

Path Synopsis
cmd
jotbot command
git
langs
ts
services
tools

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL