UNPKG

doctool

Version:

AI-powered documentation validation and management system

382 lines (277 loc) โ€ข 10.4 kB
# DocTool [![pkg.pr.new](https://pkg.pr.new/badge/PinePeakDigital/doctool)](https://pkg.pr.new/~/PinePeakDigital/doctool) > **AI-powered documentation validation and management system** DocTool is a comprehensive documentation management tool that combines reliable TypeScript code for system operations with AI-powered content generation and validation. It helps maintain accurate, up-to-date documentation across your entire codebase. ## โœจ Features ### ๐Ÿ” **Stack-Agnostic Validation** - **File System Validation**: Verify file references, directory structures, and path accuracy - **Link Validation**: Check HTTP/HTTPS URLs, internal links, anchors, and email addresses - **Command Validation**: Validate shell commands and configuration examples - **Content Quality**: Detect broken formatting, placeholder text, and inconsistencies ### ๐Ÿค– **AI-Powered Enhancement** - **Smart Content Generation**: Analyze code to generate accurate documentation - **Issue-Driven Updates**: Identify specific problems and apply targeted fixes - **Template Population**: Replace placeholder content with meaningful descriptions - **Knowledge File Management**: Systematically create and maintain project documentation ### ๐Ÿ› ๏ธ **Developer-Friendly Workflow** - **Git Integration**: Detect changes and provide review workflows - **Interactive Mode**: Control what gets updated with approval prompts - **Dry Run Support**: Preview changes before applying them - **Granular Control**: Use `git add -p` for surgical change staging ## ๐Ÿš€ Quick Start ### Installation #### Option 1: From Package (Recommended) ```bash # Install globally from npm npm install -g doctool # Or install locally in your project npm install --save-dev doctool ``` #### Option 2: From Source ```bash # Clone the repository git clone https://github.com/your-username/doctool.git cd doctool # Install dependencies pnpm install # Make it globally available (optional) npm link ``` ### Basic Usage ```bash # Validate all documentation doctool validate # Initialize knowledge files for your project doctool init # Enhance knowledge files with AI-generated content doctool enhance # Update documentation based on code changes doctool update ``` ## ๐Ÿ“– Commands ### `validate [path]` Validates documentation files for broken links, missing references, and content issues. ```bash # Validate current directory doctool validate # Validate specific path doctool validate /path/to/docs ``` **What it checks:** - File references and paths - HTTP/HTTPS link availability - Internal link targets - Anchor link destinations - Email address formats - Directory structure accuracy ### `init [path]` Initializes knowledge files across your project directories. ```bash # Initialize in current directory doctool init # Initialize in specific project doctool init /path/to/project ``` **What it creates:** - `knowledge.md` files in each significant directory - Standardized documentation templates - Proper section structure and formatting ### `enhance [path]` Enhances knowledge files with AI-generated content. ```bash # Enhance knowledge files with AI content doctool enhance # Enhance specific project doctool enhance /path/to/project ``` **What it does:** - Analyzes code files to generate accurate descriptions - Replaces template placeholders with meaningful content - Adds file listings and dependency information - Creates comprehensive documentation from code analysis ### `update [path]` Updates documentation using issue-driven targeted fixes. ```bash # Auto-update with targeted fixes doctool update # Interactive mode (prompt before each update) doctool update --interactive # Preview changes without applying doctool update --dry-run # Include low-severity fixes doctool update --severity-threshold low ``` **What it fixes:** - Missing file documentation - Outdated file descriptions - Placeholder content - References to deleted files - Missing standard sections ### `agents` Starts AI agents for advanced documentation processing (requires PraisonAI setup). ## ๐Ÿงช Testing Unreleased Versions You can test any commit or pull request using [pkg.pr.new](https://pkg.pr.new): ```bash # Test the latest main branch npx https://pkg.pr.new/doctool@main --help # Test a specific pull request npx https://pkg.pr.new/doctool@pr-123 validate # Install a specific commit globally npm install -g https://pkg.pr.new/doctool@sha-abc1234 ``` > ๐Ÿ“– **See [docs/pkg-pr-new.md](docs/pkg-pr-new.md) for complete documentation** ## ๐Ÿ”ง Configuration DocTool works out of the box with sensible defaults, but you can customize its behavior: ### API Key Setup (Required for AI Features) To use AI-powered features (`enhance` and `update` commands), you need an OpenAI API key: #### Option 1: Environment Variable ```bash export OPENAI_API_KEY="sk-your-api-key-here" ``` #### Option 2: .env File (Recommended) ```bash # Copy the example file cp .env.example .env # Edit .env and add your API key OPENAI_API_KEY=sk-your-api-key-here ``` #### Getting Your API Key 1. Visit [OpenAI Platform](https://platform.openai.com/api-keys) 2. Sign up or log in to your account 3. Create a new API key 4. Copy the key (starts with `sk-`) > โš ๏ธ **Important**: Keep your API key secure and never commit it to version control! ### Other Environment Variables ```bash # Optional: Custom validation rules export DOCTOOL_SEVERITY_THRESHOLD="medium" ``` ### Ignored Directories DocTool automatically skips these directories: - `node_modules/` - `.git/` - `dist/` and `build/` - `coverage/` - Hidden directories (starting with `.`) ## ๐Ÿ—๏ธ Architecture ### Core Principles **๐Ÿ”น Hybrid Approach**: Regular TypeScript for reliable system operations + AI for creative content generation **๐Ÿ”น Issue-Driven Updates**: Identify specific problems and apply targeted fixes instead of rewriting everything **๐Ÿ”น Git-First Workflow**: Leverage git for change detection and user review processes **๐Ÿ”น Stack Agnostic**: Works with any programming language or project structure ### Key Components ``` doctool/ โ”œโ”€โ”€ src/ โ”‚ โ”œโ”€โ”€ agents/ # AI agent definitions โ”‚ โ”œโ”€โ”€ utils/ # Core utilities โ”‚ โ”‚ โ”œโ”€โ”€ fileSystemValidator.ts # File/path validation โ”‚ โ”‚ โ”œโ”€โ”€ linkValidator.ts # URL/link validation โ”‚ โ”‚ โ”œโ”€โ”€ documentationIssues.ts # Issue detection โ”‚ โ”‚ โ”œโ”€โ”€ documentationFixer.ts # Targeted fixes โ”‚ โ”‚ โ”œโ”€โ”€ aiContentGenerator.ts # AI content generation โ”‚ โ”‚ โ””โ”€โ”€ gitUtils.ts # Git integration โ”‚ โ””โ”€โ”€ index.ts # CLI entry point โ””โ”€โ”€ README.md # This file ``` ## ๐Ÿงช Testing DocTool has comprehensive test coverage with 99+ tests: ```bash # Run all tests pnpm test # Run tests in watch mode pnpm test:watch # Run tests with coverage pnpm test:coverage ``` **Test Categories:** - File system validation (22 tests) - Link validation (28 tests) - AI content generation (16 tests) - Git utilities (10 tests) - Diff utilities (11 tests) - Issue detection and fixing (12+ tests) ## ๐Ÿ“Š Example Output ### Validation Results ``` ๐Ÿ” DocTool Documentation Validator ===================================== Found 12 documentation files to validate: ๐Ÿ“ Validating: README.md โœ… No issues found ๐Ÿ“ Validating: src/utils/knowledge.md โš ๏ธ Found 2 issue(s): 1. ๐Ÿšจ Internal link target not found: missing-file.md 2. โš ๏ธ Generic description could be improved: helpers.ts ๐Ÿ“Š Validation Summary ===================== Files validated: 12 Total issues: 3 Critical issues: 1 Warnings: 2 ``` ### Update Results ``` ๐Ÿ”„ Analyzing documentation issues in: /project ๐Ÿ” Analyzing: src/utils/knowledge.md ๐Ÿ“Š Health: โš ๏ธ needs_attention ๐ŸŸก Medium: 2 issues ๐ŸŸข Low: 1 issues โž• New files: newUtility.ts, anotherHelper.ts โœ… Applied 3 fixes ๐Ÿ“Š Documentation Fix Report ======================================== Files processed: 4 Total issues found: 8 Fixes applied: 6 Fixes skipped: 2 ๐Ÿ’ก Tip: Review changes with: git diff # See all changes git add -p # Interactively stage changes git commit -m "docs: fix documentation issues" ``` ## ๐Ÿš€ CI/CD Integration This project includes comprehensive CI/CD integration with GitHub Actions: - **Continuous Integration**: Automated testing across multiple Node.js versions (18, 20, 22) - **Security Scanning**: CodeQL analysis, dependency audits, and secret detection - **Package Validation**: Ensures package integrity and proper contents - **Preview Packages**: pkg.pr.new integration for testing PRs For detailed information about the CI/CD setup, see [docs/CI-CD.md](docs/CI-CD.md). ### Status Badges [![CI](https://github.com/narthur/doctool/workflows/CI/badge.svg)](https://github.com/narthur/doctool/actions) [![Security](https://github.com/narthur/doctool/workflows/Security/badge.svg)](https://github.com/narthur/doctool/actions) [![npm version](https://badge.fury.io/js/doctool.svg)](https://badge.fury.io/js/doctool) ### Release Process To create a new release: 1. Update the version in `CHANGELOG.md` 2. Commit your changes using conventional commits 3. Create and push a git tag: `git tag v1.2.3 && git push origin v1.2.3` 4. GitHub Actions will automatically handle the rest! ## ๐Ÿค Contributing Contributions are welcome! Please: 1. Fork the repository 2. Create a feature branch (`git checkout -b feature/amazing-feature`) 3. Make your changes with tests 4. Run the test suite (`pnpm test`) 5. Commit using conventional commits (`git commit -m 'feat: add amazing feature'`) 6. Push to your branch (`git push origin feature/amazing-feature`) 7. Open a Pull Request ### Development Setup ```bash # Clone and setup git clone https://github.com/your-username/doctool.git cd doctool pnpm install # Run tests pnpm test # Test the CLI locally pnpm exec tsx src/index.ts --help ``` ## ๐Ÿ“„ License MIT License - see [LICENSE](LICENSE) file for details. ## ๐Ÿ™ Acknowledgments - Built with [TypeScript](https://www.typescriptlang.org/) and [Vitest](https://vitest.dev/) - AI integration powered by [PraisonAI](https://praisonai.com/) - Command-line interface inspired by modern developer tools --- **Made with โค๏ธ for developers who care about documentation quality**