|
| 1 | +# Codebase Documentation |
| 2 | +- https://github.com/ai16z/eliza/issues/1110 |
| 3 | + |
| 4 | +## Set up |
| 5 | +- Set GH_PAT & OPENAI_API_KEY in github actions as env variables |
| 6 | + |
| 7 | +## Summary |
| 8 | +- To only scan files in a PR, ensure the files have been merged into the base branch (defaults to develop), and provide the PR number in the github Action input |
| 9 | +- `root_directory` is still enforced when scanning a PR |
| 10 | +- To scan a provided directory set `root_directory` and leave the PR number empty |
| 11 | + |
| 12 | +## GitHub Workflow Automation |
| 13 | + |
| 14 | +The codebase includes a GitHub Actions workflow (`JSDoc Automation`) that allows triggering the documentation generation process with custom parameters. The workflow is defined in the `.github/workflows` directory. |
| 15 | + |
| 16 | +# Workflow Dispatch Inputs |
| 17 | + |
| 18 | +The workflow can be triggered manually using the `workflow_dispatch` event, which accepts the following inputs: |
| 19 | + |
| 20 | +- `pull_number` (optional): The pull request number to generate documentation for. |
| 21 | + - if not provided, the `root_directory` will be scanned |
| 22 | + - PR must be merged to develop/main branch |
| 23 | + |
| 24 | +- `root_directory` (required): Only scans files in this directory. |
| 25 | + - Description: Target directory relative to repository root (e.g., packages/core/src) |
| 26 | + - Default: `packages/core/src/test_resources` - arbitrarily chose this because its small |
| 27 | + |
| 28 | +- `excluded_directories` (required): Directories to exclude from scanning. |
| 29 | + - Description: Comma-separated list of directories to exclude, relative to root_directory |
| 30 | + - Default: 'node_modules,dist,test' |
| 31 | + |
| 32 | +- `reviewers` (required): Pull Request Reviewers. |
| 33 | + - Description: Comma-separated list of GitHub usernames |
| 34 | + - Default: '' |
| 35 | + |
| 36 | +### Config File |
| 37 | +The `src/Configuration.ts` handles configuration loading from environment variables with fallback to YAML workflow files. |
| 38 | + |
| 39 | +#### Default Values |
| 40 | + |
| 41 | +- **Repository**: ai16z/eliza |
| 42 | +- **Branch**: develop |
| 43 | +- **Commit Message**: "Generated JSDoc comments" |
| 44 | +- **PR Title**: "JSDoc Generation" |
| 45 | +- **PR Description**: "Automated JSDoc generation for the codebase" |
| 46 | +- **PR Labels**: ["documentation", "automated-pr"] |
| 47 | +- **Excluded Directories**: ["node_modules", "dist", "test"] |
| 48 | +- **Excluded Files**: ["index.d.ts"] |
| 49 | + |
| 50 | + |
| 51 | +### Environment Variables |
| 52 | + |
| 53 | +The following environment variables need to be added to the GitHub repository secrets: |
| 54 | + |
| 55 | +- `GH_PAT`: Personal Access Token with sufficient permissions to create branches, commit changes, and create pull requests in the repository. |
| 56 | +- `OPENAI_API_KEY`: API key for accessing the OpenAI chat API used by the `AIService` to generate comments. |
| 57 | + |
| 58 | +# Codebase Documentation |
| 59 | + |
| 60 | +## `JsDocGenerator` Class |
| 61 | +The `JsDocGenerator` class is responsible for generating JSDoc comments for code snippets and classes. It uses the `AIService` to generate comments based on the code provided. |
| 62 | + |
| 63 | +## `TypeScriptFileIdentifier` Class |
| 64 | +The `TypeScriptFileIdentifier` class handles identifying and retrieving TypeScript files from a specified directory. It checks file extensions to determine if a file is a TypeScript file. |
| 65 | + |
| 66 | +## `TypeScriptParser` Class |
| 67 | +The `TypeScriptParser` class parses TypeScript files using the `@typescript-eslint/parser`. It generates an abstract syntax tree (AST) representation of the parsed content. |
| 68 | + |
| 69 | +## `DocumentationGenerator` Class |
| 70 | +The `DocumentationGenerator` class orchestrates the generation of JSDoc documentation for a codebase. It traverses the directory, identifies TypeScript files, parses them, analyzes existing JSDoc comments, generates missing comments using the `JsDocGenerator`, and updates the files with the generated documentation. It also handles creating git branches, committing changes, and creating pull requests. |
| 71 | + |
| 72 | +## `JsDocAnalyzer` Class |
| 73 | +The `JsDocAnalyzer` class analyzes JSDoc comments in TypeScript code. It traverses the AST and identifies nodes that should have JSDoc comments. It also provides methods to check if a node is a class node and retrieve JSDoc comments associated with a node. |
| 74 | + |
| 75 | +## `AIService` Class |
| 76 | +The `AIService` class is a service for interacting with the OpenAI chat API. It uses the `ChatOpenAI` class from the `@langchain/openai` package to generate comments based on provided prompts. |
| 77 | + |
| 78 | +## `DirectoryTraversal` Class |
| 79 | +The `DirectoryTraversal` class handles traversing directories and files. It can traverse based on provided PR files or scan all files in a root directory. It filters files based on excluded directories and file extensions. |
| 80 | + |
| 81 | +## `GitManager` Class |
| 82 | +The `GitManager` class manages operations related to interacting with a Git repository using the GitHub API. It can retrieve files in a pull request, create branches, commit files, and create pull requests. |
| 83 | + |
| 84 | +## `Configuration` Class |
| 85 | +The `Configuration` class represents a configuration object that holds various settings for a project. It can load configuration data from a JSON file and save the current configuration data to a file. |
| 86 | + |
| 87 | +## `Main` Function |
| 88 | +The `main` function is the entry point of the documentation generation process. It creates instances of necessary classes, loads the configuration, retrieves files from a pull request if specified, traverses the directory, parses TypeScript files, analyzes JSDoc comments, and generates documentation using the `DocumentationGenerator`. It also handles error logging. |
| 89 | + |
| 90 | +## Prompt Template Locations: |
| 91 | +- DocumentationGenerator |
| 92 | +- JsDocGenerator |
0 commit comments