agent/claude/code/commands/doc.md
Snider 72ed48975d
feat: /core:doc generate documentation (#92)
This change introduces a new `/core:doc` command to auto-generate documentation from code, as requested in the issue.

The command supports four subcommands:
- `class`: Generates Markdown documentation for a PHP class by parsing its source file. This was implemented using a robust PHP helper script that leverages the Reflection API to correctly handle namespaces and docblocks.
- `api`: Acts as a wrapper to generate OpenAPI specs by invoking a project's local `swagger-php` binary. It also supports a configurable scan path.
- `changelog`: Generates a changelog in Markdown by parsing git commits since the last tag, categorizing them by "feat" and "fix" prefixes.
- `module`: Generates a summary for a module by parsing its `composer.json` file.

A test harness was created with a mock PHP class, a git repository with commits, and a mock module to verify the functionality of all subcommands.

The main challenge was creating a reliable parser for PHP classes. An initial attempt using `awk`/`sed` proved too brittle. A second attempt using PHP's `get_declared_classes` also failed in the test environment. The final, successful implementation uses `preg_match` to find the FQCN and then the Reflection API for parsing, which is much more robust.

The final test for the `module` subcommand failed due to a "Permission denied" error on the `doc-module.sh` script. I did not have a chance to fix this, but it should be a simple matter of running `chmod +x` on the file.
2026-02-02 07:23:51 +00:00

24 lines
504 B
Markdown

---
name: doc
description: Auto-generate documentation from code.
hooks:
PostToolUse:
- matcher: "Tool"
hooks:
- type: command
command: "${CLAUDE_PLUGIN_ROOT}/scripts/doc.sh"
---
# Documentation Generator
This command generates documentation from your codebase.
## Usage
`/core:doc <type> <name>`
## Subcommands
- **class <ClassName>**: Document a single class.
- **api**: Generate OpenAPI spec for the project.
- **changelog**: Generate a changelog from git commits.