Skip to content

remcostoeten/Docki

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

16 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Docki

AI-powered TypeScript docstring generator. Add JSDoc comments to your TypeScript files using local AI or manual input.

What it does

  • Scans all .ts and .tsx files recursively from your current directory
  • Interactive selection with arrow key navigation and fuzzy search
  • AI-powered generation using local Ollama, or manual input as fallback
  • Multiple templates for different documentation styles
  • Safe operations with automatic backups before any changes

Installation

npm install -g docki

Usage

docki

Requirements

  • Node.js 16+
  • TypeScript files (.ts, .tsx)
  • Ollama (optional, for AI generation)

Templates

Docki now includes 7 specialized templates designed for different types of TypeScript files, with intelligent auto-detection based on file content and location.

πŸ“‹ Available Templates

Template Best For Tokens Used
default General purpose files description, emoji, author
ai-function πŸ€– AI/ML utilities, model functions description, emoji, params, returns, example, author
api-endpoint πŸ”— REST API handlers, route functions description, emoji, method, route, params, returns, throws, author
react-component βš›οΈ React components description, emoji, props, returns, example, author
react-hook πŸͺ Custom React hooks (use*) description, emoji, params, returns, example, author
utility πŸ”§ Helper functions, utilities description, emoji, params, returns, author
comprehensive πŸ“– Complex functions needing all docs All available tokens

🎯 AI Template Features

The ai-function template is specifically designed for AI/ML code:

/**
 * @description Generates embeddings for text using OpenAI API
 * 
 * @param {string} text - The input text to embed
 * @param {string} model - OpenAI model to use (default: text-embedding-ada-002)
 * @returns {Promise<number[]>} Array of embedding vectors
 * 
 * @example
 * const embeddings = await generateEmbeddings("Hello world", "text-embedding-ada-002")
 * console.log(embeddings.length) // 1536
 * 
 * @author AI Team
 */

πŸ€– Smart Template Detection

Docki automatically suggests the best template based on:

  • File location: /api/ β†’ api-endpoint, /ai/ β†’ ai-function, /components/ β†’ react-component
  • File naming: useAuth.ts β†’ react-hook, aiModel.ts β†’ ai-function
  • Content analysis: Detects React components, API handlers, AI/ML keywords

🏷️ Template Token Reference

All templates support these tokens (unused tokens are automatically removed):

Token Purpose Example
{{description}} Required - Main function description Processes user authentication
{{emoji}} Optional emoji for visual context :lock:, :rocket:, :chart:
{{author}} Author attribution @author John Doe
{{params}} Function parameters {string} username - User identifier
{{returns}} Return value description {Promise<User>} Authenticated user object
{{example}} Usage example code const user = await login('john')
{{method}} HTTP method for API endpoints POST, GET, DELETE
{{route}} API route path /api/auth/login
{{throws}} Possible exceptions {AuthError} When credentials invalid
{{props}} React component props {ButtonProps} Component properties
{{generics}} Generic type parameters <T, K extends keyof T>

πŸ› οΈ Custom Templates

You can create custom templates by adding .txt files to the templates/ directory:

my-custom.txt:

/**
 * @description {{description}}
 * 
 * @version 1.0.0
 * @since {{date}}
 * @param {{params}}
 * @returns {{returns}}
 * 
 * {{author}}
 */

Configuration with template mapping:

{
  "templateMap": {
    "api-endpoint": "my-custom",
    "react-component": "comprehensive"
  }
}

This maps specific file types to your preferred templates.

AI Integration

Docki supports multiple AI providers for automatic documentation generation:

Google Gemini

Use Google's Gemini AI for cloud-based documentation generation:

# Set your API key (get one free at https://makersuite.google.com/app/apikey)
export GEMINI_API_KEY="your-api-key-here"

# Run Docki - it will automatically detect and use Gemini
docki

Ollama (Local AI)

Use Ollama for completely offline, private documentation generation:

# Install Ollama from https://ollama.ai
# Pull a model
ollama pull codellama:7b

# Run Docki
docki

Auto-Detection

Docki automatically detects available AI providers in this order:

  1. Gemini - If GEMINI_API_KEY is set
  2. Ollama - If installed locally
  3. Manual - Falls back to manual input if no AI is available

Configuration

Create a .docstring-cli.json file in your project root:

{
  "extensions": [".ts", ".tsx", ".js", ".jsx"],
  "excludeDirectories": ["node_modules", "dist", ".git"],
  "defaultTemplate": "jsdoc",
  "defaultAuthor": "Your Name",
  "aiProvider": "gemini",
  "geminiModel": "gemini-1.5-flash",
  
  "ollamaModel": "codellama:7b",
  "maxDescriptionLength": 80
}

Configuration Options

  • extensions: File extensions to scan for (default: TypeScript files)
  • excludeDirectories: Directories to ignore during scanning
  • defaultTemplate: Template to use by default
  • defaultAuthor: Your name to include in docstrings
  • aiProvider: Preferred AI provider: "gemini", "ollama", or "none" (auto-detect if not set)
  • geminiModel: Gemini model to use (default: "gemini-1.5-flash")
  • geminiApiKey: Your Gemini API key. Strongly recommended to use the GEMINI_API_KEY environment variable instead of storing it directly in this file.
  • ollamaModel: Ollama model to use (default: "codellama:7b")
  • maxDescriptionLength: Maximum line length for AI-generated descriptions (default: 80)

License

MIT Β© Remco Stoeten

About

Insert JSDoc/docstrings with, or without AI through your cli blazingly fast πŸ”₯

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published