hatch3r 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +93 -322
- package/agents/hatch3r-a11y-auditor.md +24 -6
- package/agents/hatch3r-architect.md +20 -1
- package/agents/hatch3r-ci-watcher.md +31 -8
- package/agents/hatch3r-context-rules.md +14 -2
- package/agents/hatch3r-dependency-auditor.md +21 -5
- package/agents/hatch3r-devops.md +37 -6
- package/agents/hatch3r-docs-writer.md +19 -3
- package/agents/hatch3r-fixer.md +171 -0
- package/agents/hatch3r-implementer.md +84 -11
- package/agents/hatch3r-learnings-loader.md +69 -13
- package/agents/hatch3r-lint-fixer.md +19 -14
- package/agents/hatch3r-perf-profiler.md +18 -1
- package/agents/hatch3r-researcher.md +440 -5
- package/agents/hatch3r-reviewer.md +97 -5
- package/agents/hatch3r-security-auditor.md +23 -5
- package/agents/hatch3r-test-writer.md +21 -10
- package/checks/README.md +49 -0
- package/checks/code-quality.md +49 -0
- package/checks/performance.md +58 -0
- package/checks/security.md +58 -0
- package/checks/testing.md +53 -0
- package/commands/board/pickup-azure-devops.md +81 -0
- package/commands/board/pickup-delegation-multi.md +197 -0
- package/commands/board/pickup-delegation.md +100 -0
- package/commands/board/pickup-github.md +82 -0
- package/commands/board/pickup-gitlab.md +81 -0
- package/commands/board/pickup-modes.md +143 -0
- package/commands/board/pickup-post-impl.md +120 -0
- package/commands/board/shared-azure-devops.md +149 -0
- package/commands/board/shared-board-overview.md +215 -0
- package/commands/board/shared-github.md +169 -0
- package/commands/board/shared-gitlab.md +142 -0
- package/commands/hatch3r-agent-customize.md +40 -2
- package/commands/hatch3r-api-spec.md +294 -32
- package/commands/hatch3r-benchmark.md +386 -32
- package/commands/hatch3r-board-fill.md +161 -25
- package/commands/hatch3r-board-groom.md +595 -0
- package/commands/hatch3r-board-init.md +203 -46
- package/commands/hatch3r-board-pickup.md +79 -457
- package/commands/hatch3r-board-refresh.md +98 -27
- package/commands/hatch3r-board-shared.md +87 -238
- package/commands/hatch3r-bug-plan.md +16 -3
- package/commands/hatch3r-codebase-map.md +43 -10
- package/commands/hatch3r-command-customize.md +6 -0
- package/commands/hatch3r-context-health.md +5 -0
- package/commands/hatch3r-cost-tracking.md +5 -0
- package/commands/hatch3r-debug.md +426 -0
- package/commands/hatch3r-dep-audit.md +7 -1
- package/commands/hatch3r-feature-plan.md +74 -12
- package/commands/hatch3r-healthcheck.md +17 -1
- package/commands/hatch3r-hooks.md +16 -10
- package/commands/hatch3r-learn.md +15 -9
- package/commands/hatch3r-migration-plan.md +333 -33
- package/commands/hatch3r-onboard.md +327 -38
- package/commands/hatch3r-project-spec.md +46 -10
- package/commands/hatch3r-quick-change.md +336 -0
- package/commands/hatch3r-recipe.md +6 -0
- package/commands/hatch3r-refactor-plan.md +29 -13
- package/commands/hatch3r-release.md +13 -3
- package/commands/hatch3r-revision.md +395 -0
- package/commands/hatch3r-roadmap.md +18 -3
- package/commands/hatch3r-rule-customize.md +6 -0
- package/commands/hatch3r-security-audit.md +17 -1
- package/commands/hatch3r-skill-customize.md +6 -0
- package/commands/hatch3r-test-plan.md +532 -0
- package/commands/hatch3r-workflow.md +113 -38
- package/dist/cli/index.js +5184 -2593
- package/dist/cli/index.js.map +1 -0
- package/github-agents/hatch3r-docs-agent.md +1 -0
- package/github-agents/hatch3r-lint-agent.md +1 -0
- package/github-agents/hatch3r-security-agent.md +1 -0
- package/github-agents/hatch3r-test-agent.md +1 -0
- package/hooks/hatch3r-ci-failure.md +30 -0
- package/hooks/hatch3r-file-save.md +22 -0
- package/hooks/hatch3r-post-merge.md +23 -0
- package/hooks/hatch3r-pre-commit.md +23 -0
- package/hooks/hatch3r-pre-push.md +22 -0
- package/hooks/hatch3r-session-start.md +22 -0
- package/mcp/mcp.json +22 -3
- package/package.json +4 -7
- package/prompts/hatch3r-bug-triage.md +1 -0
- package/prompts/hatch3r-code-review.md +1 -0
- package/prompts/hatch3r-pr-description.md +1 -0
- package/rules/hatch3r-accessibility-standards.md +1 -0
- package/rules/hatch3r-agent-orchestration.md +326 -53
- package/rules/hatch3r-agent-orchestration.mdc +225 -0
- package/rules/hatch3r-api-design.md +4 -1
- package/rules/hatch3r-browser-verification.md +33 -1
- package/rules/hatch3r-browser-verification.mdc +29 -0
- package/rules/hatch3r-ci-cd.md +5 -1
- package/rules/hatch3r-ci-cd.mdc +4 -1
- package/rules/hatch3r-code-standards.md +18 -0
- package/rules/hatch3r-code-standards.mdc +10 -1
- package/rules/hatch3r-component-conventions.md +4 -1
- package/rules/hatch3r-data-classification.md +1 -0
- package/rules/hatch3r-deep-context.md +94 -0
- package/rules/hatch3r-deep-context.mdc +69 -0
- package/rules/hatch3r-dependency-management.md +13 -0
- package/rules/hatch3r-feature-flags.md +4 -1
- package/rules/hatch3r-git-conventions.md +1 -0
- package/rules/hatch3r-i18n.md +4 -1
- package/rules/hatch3r-learning-consult.md +4 -2
- package/rules/hatch3r-learning-consult.mdc +3 -2
- package/rules/hatch3r-migrations.md +12 -0
- package/rules/hatch3r-observability.md +293 -1
- package/rules/hatch3r-performance-budgets.md +5 -2
- package/rules/hatch3r-performance-budgets.mdc +1 -1
- package/rules/hatch3r-secrets-management.md +11 -3
- package/rules/hatch3r-secrets-management.mdc +10 -3
- package/rules/hatch3r-security-patterns.md +23 -3
- package/rules/hatch3r-security-patterns.mdc +8 -2
- package/rules/hatch3r-testing.md +1 -0
- package/rules/hatch3r-theming.md +4 -1
- package/rules/hatch3r-tooling-hierarchy.md +42 -15
- package/rules/hatch3r-tooling-hierarchy.mdc +27 -4
- package/skills/hatch3r-a11y-audit/SKILL.md +1 -0
- package/skills/hatch3r-agent-customize/SKILL.md +3 -0
- package/skills/hatch3r-api-spec/SKILL.md +1 -0
- package/skills/hatch3r-architecture-review/SKILL.md +6 -2
- package/skills/hatch3r-bug-fix/SKILL.md +4 -1
- package/skills/hatch3r-ci-pipeline/SKILL.md +1 -0
- package/skills/hatch3r-command-customize/SKILL.md +1 -0
- package/skills/hatch3r-context-health/SKILL.md +2 -1
- package/skills/hatch3r-cost-tracking/SKILL.md +1 -0
- package/skills/hatch3r-dep-audit/SKILL.md +6 -2
- package/skills/hatch3r-feature/SKILL.md +9 -2
- package/skills/hatch3r-gh-agentic-workflows/SKILL.md +130 -21
- package/skills/hatch3r-incident-response/SKILL.md +11 -5
- package/skills/hatch3r-issue-workflow/SKILL.md +12 -7
- package/skills/hatch3r-logical-refactor/SKILL.md +1 -0
- package/skills/hatch3r-migration/SKILL.md +1 -0
- package/skills/hatch3r-perf-audit/SKILL.md +2 -1
- package/skills/hatch3r-pr-creation/SKILL.md +20 -10
- package/skills/hatch3r-qa-validation/SKILL.md +2 -1
- package/skills/hatch3r-recipe/SKILL.md +1 -0
- package/skills/hatch3r-refactor/SKILL.md +7 -1
- package/skills/hatch3r-release/SKILL.md +15 -11
- package/skills/hatch3r-rule-customize/SKILL.md +1 -0
- package/skills/hatch3r-skill-customize/SKILL.md +1 -0
- package/skills/hatch3r-visual-refactor/SKILL.md +1 -0
- package/dist/cli/hooks-ZOTFDEA3.js +0 -59
- package/rules/hatch3r-error-handling.md +0 -17
- package/rules/hatch3r-error-handling.mdc +0 -15
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
id: hatch3r-board-shared-gitlab
|
|
3
|
+
type: shared-context
|
|
4
|
+
description: GitLab-specific platform details for board shared context. Covers GitLab Issues, Issue Boards, glab CLI, and label-based sync.
|
|
5
|
+
tags: [board, team, gitlab]
|
|
6
|
+
---
|
|
7
|
+
# Board Shared Reference — GitLab Platform Details
|
|
8
|
+
|
|
9
|
+
Platform-specific procedures for GitLab. Referenced from `hatch3r-board-shared`.
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Platform Detection — GitLab
|
|
14
|
+
|
|
15
|
+
Use `glab` CLI. Issues = GitLab Issues. PRs = Merge Requests (MRs). Board = GitLab Issue Boards. Requires `glab auth login` or `GITLAB_TOKEN`.
|
|
16
|
+
|
|
17
|
+
### CLI Command Reference
|
|
18
|
+
|
|
19
|
+
| Action | Command |
|
|
20
|
+
|--------|---------|
|
|
21
|
+
| Create issue | `glab issue create -R {namespace}/{project}` |
|
|
22
|
+
| List issues | `glab issue list -R {namespace}/{project}` |
|
|
23
|
+
| View issue | `glab issue view N -R {namespace}/{project}` |
|
|
24
|
+
| Update issue | `glab issue update N -R {namespace}/{project}` |
|
|
25
|
+
| Close issue | `glab issue close N -R {namespace}/{project}` |
|
|
26
|
+
| Create MR | `glab mr create -R {namespace}/{project}` |
|
|
27
|
+
| Add label | `glab issue update N --label "x"` |
|
|
28
|
+
| Add comment | `glab issue note N -R {namespace}/{project}` |
|
|
29
|
+
| Board sync | Board list = label-based |
|
|
30
|
+
|
|
31
|
+
### MCP Tool Reference
|
|
32
|
+
|
|
33
|
+
GitLab MCP tools are not currently available. All operations use the `glab` CLI.
|
|
34
|
+
|
|
35
|
+
### Terminology
|
|
36
|
+
|
|
37
|
+
| Concept | GitLab Term |
|
|
38
|
+
|---------|-------------|
|
|
39
|
+
| Work unit | Issue |
|
|
40
|
+
| Code review | Merge Request (MR) |
|
|
41
|
+
| Board | GitLab Issue Boards |
|
|
42
|
+
| Labels | Labels |
|
|
43
|
+
| Project identifier | project ID |
|
|
44
|
+
| Status tracking | Board lists/labels |
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## GitLab Context
|
|
49
|
+
|
|
50
|
+
Derived from `.agents/hatch.json` board config:
|
|
51
|
+
|
|
52
|
+
- **Namespace:** top-level `owner` (GitLab group or user namespace)
|
|
53
|
+
- **Project:** top-level `repo` (GitLab project name)
|
|
54
|
+
- **Default branch:** `board.defaultBranch` (fallback: `"main"`)
|
|
55
|
+
- **Type labels:** `board.labels.types`
|
|
56
|
+
- **Executor labels:** `board.labels.executors`
|
|
57
|
+
- **Status labels:** `board.labels.statuses`
|
|
58
|
+
- **Scoped labels:** GitLab supports scoped labels (`status::ready`, `type::bug`). Map hatch3r label format (`status:ready`) to GitLab scoped format (`status::ready`) when creating labels.
|
|
59
|
+
- **Issue templates:** Check `.gitlab/issue_templates/` if present.
|
|
60
|
+
- **MR template:** Check `.gitlab/merge_request_templates/` if present.
|
|
61
|
+
|
|
62
|
+
### GitLab Project Reference (cache for the full run)
|
|
63
|
+
|
|
64
|
+
- **Project path:** `{namespace}/{project}`
|
|
65
|
+
- **Board:** GitLab Issue Boards use label-based lists. Each status maps to a board list label.
|
|
66
|
+
- **Board ID:** `board.projectNumber` (repurposed as GitLab Board ID if configured)
|
|
67
|
+
|
|
68
|
+
---
|
|
69
|
+
|
|
70
|
+
## GitLab Board Label-Based Sync
|
|
71
|
+
|
|
72
|
+
> **Skip entirely if board is not configured.**
|
|
73
|
+
|
|
74
|
+
GitLab Boards use labels to organize issues into lists. Board sync is achieved by updating issue labels to match the target status.
|
|
75
|
+
|
|
76
|
+
**Status label → Board list mapping:**
|
|
77
|
+
|
|
78
|
+
GitLab board lists are label-based. Each status corresponds to a scoped label:
|
|
79
|
+
|
|
80
|
+
| Label | GitLab Scoped Label |
|
|
81
|
+
| -------------------- | ------------------- |
|
|
82
|
+
| `status:triage` | `status::triage` |
|
|
83
|
+
| `status:ready` | `status::ready` |
|
|
84
|
+
| `status:in-progress` | `status::in-progress` |
|
|
85
|
+
| `status:in-review` | `status::in-review` |
|
|
86
|
+
| `status:blocked` | `status::blocked` |
|
|
87
|
+
|
|
88
|
+
**Steps for each issue to sync:**
|
|
89
|
+
|
|
90
|
+
1. **Update labels:** `glab issue update {N} -R {namespace}/{project} --unlabel "status::*" --label "status::{new-status}"`. GitLab scoped labels auto-replace within the same scope, so setting `status::ready` automatically removes `status::triage`.
|
|
91
|
+
2. **Verify:** `glab issue view {N} -R {namespace}/{project}` and confirm labels match.
|
|
92
|
+
|
|
93
|
+
**For MRs:** `glab mr update {N} -R {namespace}/{project} --label "status::{new-status}"`.
|
|
94
|
+
|
|
95
|
+
**Resilience:** If any call fails, retry once. If it still fails, surface a warning and continue. If `glab` CLI is unavailable, warn: "GitLab Board sync skipped -- run `glab auth login` or set GITLAB_TOKEN."
|
|
96
|
+
|
|
97
|
+
---
|
|
98
|
+
|
|
99
|
+
## Sub-Issue Linking — GitLab
|
|
100
|
+
|
|
101
|
+
### Three-Tier Fallback Chain
|
|
102
|
+
|
|
103
|
+
1. **Primary — API link:**
|
|
104
|
+
`glab api projects/{project_id}/issues/{parent_iid}/links --method POST --field target_project_id={project_id} --field target_issue_iid={child_iid}`.
|
|
105
|
+
Record link status as `native`.
|
|
106
|
+
|
|
107
|
+
2. **Fallback 1 — Comment trace:**
|
|
108
|
+
If API linking fails:
|
|
109
|
+
`glab issue note {epic} -R {namespace}/{project} --message "Sub-issue: #{child} — {title} (linking failed)"`.
|
|
110
|
+
Record link status as `comment-only`.
|
|
111
|
+
|
|
112
|
+
### Verification
|
|
113
|
+
|
|
114
|
+
After linking, verify via `glab api projects/{project_id}/issues/{epic_iid}/links` and check linked issues.
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Board Sync Enforcement — GitLab
|
|
119
|
+
|
|
120
|
+
1. **Status updates:** Set via `glab issue update --label`.
|
|
121
|
+
2. **Fallback escalation:** `glab issue update` CLI → surface error to user. Silent skipping is prohibited.
|
|
122
|
+
3. **Board item tracking:** After updating an issue, store the issue ID in the run cache keyed by issue number.
|
|
123
|
+
|
|
124
|
+
---
|
|
125
|
+
|
|
126
|
+
## Cross-Cutting Tooling — GitLab CLI-First
|
|
127
|
+
|
|
128
|
+
**Prerequisites:** `glab auth login` must be completed, or `GITLAB_TOKEN` environment variable set.
|
|
129
|
+
|
|
130
|
+
| Operation | Primary (`glab` CLI) | Fallback (MCP) |
|
|
131
|
+
| -------------------- | ------------------------------------------------------------- | -------------- |
|
|
132
|
+
| List issues | `glab issue list -R {namespace}/{project}` | N/A |
|
|
133
|
+
| Read issue details | `glab issue view N -R {namespace}/{project}` | N/A |
|
|
134
|
+
| Create/update issues | `glab issue create` / `glab issue update N` | N/A |
|
|
135
|
+
| Search issues | `glab issue list --search "..."` | N/A |
|
|
136
|
+
| Manage relations | `glab issue note N --message "Related to #M"` (advisory only) | N/A |
|
|
137
|
+
| Add comments | `glab issue note N -R {namespace}/{project}` | N/A |
|
|
138
|
+
| Create MRs | `glab mr create -R {namespace}/{project}` | N/A |
|
|
139
|
+
| Read MR details | `glab mr view N -R {namespace}/{project}` | N/A |
|
|
140
|
+
| Manage labels | `glab label create` / `glab label list` | N/A |
|
|
141
|
+
| Board sync | Label updates (automatic board list placement) | N/A |
|
|
142
|
+
| CI/Pipelines | `glab ci list` / `glab ci view` | N/A |
|
|
@@ -2,7 +2,13 @@
|
|
|
2
2
|
id: hatch3r-agent-customize
|
|
3
3
|
type: command
|
|
4
4
|
description: Configure per-agent customization including model overrides, description changes, and project-specific markdown instructions
|
|
5
|
+
tags: [customize]
|
|
5
6
|
---
|
|
7
|
+
|
|
8
|
+
## Agent Pipeline
|
|
9
|
+
|
|
10
|
+
This command runs as a single orchestrator without sub-agent delegation. Customization file management is performed inline.
|
|
11
|
+
|
|
6
12
|
# Agent Customization — Per-Agent Configuration
|
|
7
13
|
|
|
8
14
|
Customize individual agent behavior for project-specific needs via `.hatch3r/agents/` configuration files. Supports structured YAML overrides and free-form markdown instruction injection, all propagated to every adapter output on sync.
|
|
@@ -124,6 +130,38 @@ enabled: false
|
|
|
124
130
|
|
|
125
131
|
The agent's canonical definition remains in `.agents/agents/` but no adapter output is generated for it.
|
|
126
132
|
|
|
133
|
+
## Protected Agents
|
|
134
|
+
|
|
135
|
+
Some agents have `protected: true` in their canonical frontmatter. This field marks agents whose core behavior must not be weakened or bypassed through customization, because they enforce critical quality and security invariants.
|
|
136
|
+
|
|
137
|
+
### Currently Protected Agents
|
|
138
|
+
|
|
139
|
+
| Agent | Why Protected |
|
|
140
|
+
|-------|--------------|
|
|
141
|
+
| `hatch3r-reviewer` | Enforces code quality, privacy invariants, and security review. Weakening or disabling it would allow unsafe code to merge unreviewed. |
|
|
142
|
+
| `hatch3r-security-auditor` | Enforces security rules, access control auditing, and privacy invariant verification. Disabling it would leave security gaps undetected. |
|
|
143
|
+
| `hatch3r-test-writer` | Enforces test coverage requirements and regression testing. Disabling it would allow untested code to ship. |
|
|
144
|
+
|
|
145
|
+
### What Protection Means
|
|
146
|
+
|
|
147
|
+
- **Cannot be disabled.** Setting `enabled: false` in a `.customize.yaml` file for a protected agent is ignored. The agent is always included in adapter output.
|
|
148
|
+
- **Cannot have scope or description overridden.** The `description` field in a `.customize.yaml` file is ignored for protected agents. Their canonical description is always used to prevent narrowing or misrepresenting the agent's responsibilities.
|
|
149
|
+
- **Model overrides ARE allowed.** You can override the `model` field for protected agents via `.customize.yaml` or `hatch.json`. Choosing a more capable model for a protected agent is a valid use case.
|
|
150
|
+
- **Markdown customization IS allowed.** You can add project-specific instructions via `.customize.md` (e.g., domain-specific review checklists, compliance requirements). These are appended to the canonical content and extend the agent's scope — they cannot reduce it.
|
|
151
|
+
|
|
152
|
+
### Frontmatter Format
|
|
153
|
+
|
|
154
|
+
```yaml
|
|
155
|
+
---
|
|
156
|
+
id: hatch3r-reviewer
|
|
157
|
+
description: Expert code reviewer for the project...
|
|
158
|
+
protected: true
|
|
159
|
+
model: standard
|
|
160
|
+
---
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
The `protected` field is set in the canonical agent definition and cannot be overridden by customization files.
|
|
164
|
+
|
|
127
165
|
## Workflow
|
|
128
166
|
|
|
129
167
|
1. Identify which agent to customize
|
|
@@ -142,5 +180,5 @@ The agent's canonical definition remains in `.agents/agents/` but no adapter out
|
|
|
142
180
|
- Skill customization: `hatch3r-skill-customize` command
|
|
143
181
|
- Command customization: `hatch3r-command-customize` command
|
|
144
182
|
- Rule customization: `hatch3r-rule-customize` command
|
|
145
|
-
- Model selection: [
|
|
146
|
-
- Platform support: [
|
|
183
|
+
- Model selection: [Model Selection](https://docs.hatch3r.com/docs/guides/model-selection) — configuration, aliases, resolution order
|
|
184
|
+
- Platform support: [Adapter Capability Matrix](https://docs.hatch3r.com/docs/reference/adapter-capability-matrix) — model emission per adapter (native vs guidance)
|
|
@@ -2,48 +2,310 @@
|
|
|
2
2
|
id: hatch3r-api-spec
|
|
3
3
|
type: command
|
|
4
4
|
description: Generate or validate an OpenAPI specification from the codebase. Scans route definitions, extracts schemas, and produces a complete API spec.
|
|
5
|
+
tags: [planning]
|
|
5
6
|
---
|
|
6
|
-
# API Specification Generator
|
|
7
7
|
|
|
8
|
-
##
|
|
8
|
+
## Agent Pipeline
|
|
9
9
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
| Stage | Agent(s) | Parallel | Required |
|
|
11
|
+
|-------|----------|----------|----------|
|
|
12
|
+
| 1. Codebase Scan | `hatch3r-researcher` (codebase-analysis mode) | No | Yes |
|
|
13
|
+
| 2. Schema Extraction | Orchestrator (inline) | No | Yes |
|
|
14
|
+
| 3. Spec Generation | `hatch3r-docs-writer` | No | Yes |
|
|
15
|
+
| 4. Validation | `hatch3r-reviewer` | No | Yes (if validate mode) |
|
|
13
16
|
|
|
14
|
-
|
|
17
|
+
# API Specification Generator — OpenAPI from Code or Code-vs-Spec Drift Detection
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
Take a codebase with HTTP or RPC endpoints and produce a complete OpenAPI 3.1 specification (`docs/api/`), or take an existing spec and compare it against the live codebase to surface undocumented, stale, or drifted endpoints. The researcher sub-agent scans route definitions, decorators, and handlers; the orchestrator extracts TypeScript types and validation schemas inline; the docs-writer assembles the final spec document; and the reviewer validates structural correctness. AI proposes all outputs; user confirms before any files are written.
|
|
17
20
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
## Shared Context
|
|
24
|
+
|
|
25
|
+
**Read the `hatch3r-board-shared` command at the start of the run** if it exists. Cache any values found (GitHub owner/repo, tooling directives).
|
|
26
|
+
|
|
27
|
+
**Read the `hatch3r-api-design` rule** if it exists. This rule contains the project's API design conventions (naming, versioning, error shapes, pagination patterns) that the generated spec must conform to.
|
|
28
|
+
|
|
29
|
+
## Token-Saving Directives
|
|
30
|
+
|
|
31
|
+
1. **Do not re-read files already cached.** Once the researcher's route scan is collected, reference it in memory — do not re-scan the same directories.
|
|
32
|
+
2. **Limit schema reads.** Read only the imported type file — not the entire module tree. Follow one level of imports; stop there.
|
|
33
|
+
3. **Structured output only.** All sub-agent prompts require structured markdown output — no prose dumps.
|
|
34
|
+
4. **Batch schema extraction.** Group types by source file. Read each file once and extract all referenced types in a single pass.
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Workflow
|
|
39
|
+
|
|
40
|
+
Execute these steps in order. **Do not skip any step.** Ask the user at every checkpoint marked with ASK.
|
|
41
|
+
|
|
42
|
+
### Step 1: Gather API Context
|
|
43
|
+
|
|
44
|
+
1. **ASK:** "I'll generate or validate an OpenAPI specification from your codebase. I need:
|
|
45
|
+
- **Mode:** `generate` (create spec from code) or `validate` (check existing spec against code)
|
|
46
|
+
- **Output format:** `yaml` (default) or `json`
|
|
47
|
+
- **Output path:** default `docs/api/openapi.yaml` — or specify a custom path
|
|
48
|
+
- **Scope:** full API, or limit to specific route prefixes / modules (e.g., `/api/v2/`, `src/routes/billing/`)
|
|
49
|
+
- **Spec version:** OpenAPI 3.1 (default) or 3.0
|
|
50
|
+
|
|
51
|
+
If you have an existing spec you want to validate, point me to its path."
|
|
52
|
+
|
|
53
|
+
2. If the user provides a validate-mode path, verify the file exists. If it does not, report the error and fall back to generate mode with an ASK.
|
|
54
|
+
3. Present a structured summary:
|
|
55
|
+
|
|
56
|
+
```
|
|
57
|
+
API Spec Brief:
|
|
58
|
+
Mode: {generate | validate}
|
|
59
|
+
Format: {yaml | json}
|
|
60
|
+
Output: {path}
|
|
61
|
+
Scope: {full | scoped to X}
|
|
62
|
+
Spec version: {3.1 | 3.0}
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
**ASK:** "Does this look right? Adjust anything before I scan the codebase."
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
### Step 2: Framework Detection
|
|
70
|
+
|
|
71
|
+
1. Scan `package.json` dependencies and source patterns to identify the API framework. Supported detections: Express, Fastify, NestJS, tRPC, GraphQL, Hono, Next.js API Routes, Elysia. Assign confidence (high/medium/low) based on signal strength (dependency present + matching code patterns = high).
|
|
72
|
+
|
|
73
|
+
2. Detect validation/schema libraries: Zod, class-validator, TypeBox, Joi, Ajv/JSON Schema, io-ts, Effect Schema.
|
|
74
|
+
|
|
75
|
+
3. Check for existing OpenAPI tooling (`zod-to-openapi`, `swagger-jsdoc`, `@nestjs/swagger`, `tsoa`, `fastify-swagger`).
|
|
76
|
+
|
|
77
|
+
4. Detect auth patterns by scanning middleware, guards, and decorators for JWT, API key, OAuth, or session-based auth.
|
|
78
|
+
|
|
79
|
+
5. Present detection results:
|
|
80
|
+
|
|
81
|
+
```
|
|
82
|
+
Framework Detection:
|
|
83
|
+
Primary framework: {name} ({confidence})
|
|
84
|
+
Schema library: {name | none detected}
|
|
85
|
+
Existing OAS tools: {name | none detected}
|
|
86
|
+
Auth patterns: {JWT / API key / OAuth / session / none detected}
|
|
87
|
+
Route base path: {e.g., /api/v1}
|
|
88
|
+
Files to scan: {N} files across {M} directories
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
**ASK:** "I detected the above. Corrections? Additional patterns I should look for (custom middleware, versioned routes, etc.)?"
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
|
|
95
|
+
### Step 3: Endpoint Discovery
|
|
96
|
+
|
|
97
|
+
Spawn the `hatch3r-researcher` sub-agent in `codebase-analysis` mode with the confirmed framework and scope.
|
|
98
|
+
|
|
99
|
+
**Researcher prompt must include:** the confirmed framework and schema library, the scope, instruction to follow the **hatch3r-researcher agent protocol**, and depth level `standard`.
|
|
100
|
+
|
|
101
|
+
For each discovered endpoint, extract: HTTP method, path, path/query parameters, request body type, response type(s), status codes, auth requirement, tags/grouping, and description (from JSDoc or decorator metadata).
|
|
102
|
+
|
|
103
|
+
Present the discovery summary:
|
|
104
|
+
|
|
105
|
+
```
|
|
106
|
+
Endpoint Discovery:
|
|
107
|
+
Total endpoints: {N}
|
|
108
|
+
Methods: GET: {n}, POST: {n}, PUT: {n}, PATCH: {n}, DELETE: {n}
|
|
109
|
+
Auth-protected: {N} / {total}
|
|
110
|
+
With response types: {N}
|
|
111
|
+
Missing types: {N} endpoints with no extractable request/response types
|
|
112
|
+
Grouped by:
|
|
113
|
+
{tag/controller}: {N} endpoints
|
|
114
|
+
...
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
List endpoints with missing or incomplete type information.
|
|
118
|
+
|
|
119
|
+
**ASK:** "I found {N} endpoints. {M} have incomplete type information (listed above). Options:
|
|
120
|
+
- **Confirm** to proceed (incomplete endpoints get placeholder schemas)
|
|
121
|
+
- **Add missing endpoints** you know exist but I didn't find
|
|
122
|
+
- **Exclude endpoints** from the spec
|
|
123
|
+
- **Provide type hints** for endpoints with missing types"
|
|
124
|
+
|
|
125
|
+
---
|
|
126
|
+
|
|
127
|
+
### Step 4: Schema Extraction
|
|
128
|
+
|
|
129
|
+
For each endpoint with typed request/response shapes, extract the underlying types.
|
|
130
|
+
|
|
131
|
+
1. **Resolve type references.** Follow one level of imports to capture referenced interfaces, enums, and union types.
|
|
132
|
+
2. **Convert to OpenAPI schemas.** Map TypeScript types, Zod chains, class-validator decorators, TypeBox definitions, and Joi schemas to JSON Schema properties. Preserve descriptions from `.describe()` calls or JSDoc.
|
|
133
|
+
3. **Deduplicate.** Identical types across endpoints become a single `components/schemas` entry referenced via `$ref`.
|
|
134
|
+
4. **Detect shared patterns** — pagination wrappers, error response shapes, envelope patterns.
|
|
135
|
+
|
|
136
|
+
```
|
|
137
|
+
Schema Extraction:
|
|
138
|
+
Components extracted: {N} schemas
|
|
139
|
+
Shared patterns: {pagination: yes/no, error shape: yes/no, envelope: yes/no}
|
|
140
|
+
Enums: {N}
|
|
141
|
+
Unresolvable types: {N} (will use empty schema)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
No ASK checkpoint unless unresolvable types exceed 30% of total schemas:
|
|
145
|
+
|
|
146
|
+
**ASK (conditional):** "{N}% of schemas could not be resolved. Continue with empty schemas, or provide type definitions manually?"
|
|
147
|
+
|
|
148
|
+
---
|
|
149
|
+
|
|
150
|
+
### Step 5: OpenAPI Assembly
|
|
151
|
+
|
|
152
|
+
Build the complete OpenAPI document.
|
|
153
|
+
|
|
154
|
+
1. **`info`** — from `package.json` (title, version, description).
|
|
155
|
+
2. **`servers`** — detect from env config or Docker Compose; default `http://localhost:{port}`.
|
|
156
|
+
3. **`paths`** — one entry per unique path. Each operation includes `operationId`, `summary`, `tags`, `parameters`, `requestBody`, `responses` (with `$ref`), and `security`.
|
|
157
|
+
4. **`components/schemas`** — all extracted types as JSON Schema.
|
|
158
|
+
5. **`components/securitySchemes`** — JWT Bearer, API Key, OAuth 2.0, or cookie/session based on detected auth patterns.
|
|
159
|
+
6. **`tags`** — one per resource group with descriptions.
|
|
160
|
+
|
|
161
|
+
Present a structural overview (not the full spec):
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
OpenAPI Spec Structure:
|
|
165
|
+
info.title: {title}
|
|
166
|
+
info.version: {version}
|
|
167
|
+
servers: {N} servers
|
|
168
|
+
paths: {N} paths, {M} operations
|
|
169
|
+
components:
|
|
170
|
+
schemas: {N}
|
|
171
|
+
securitySchemes: {N}
|
|
172
|
+
tags: {N}
|
|
173
|
+
Estimated size: ~{N} lines
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
**ASK:** "Here is the spec structure. Review before I write the file to `{output path}`:
|
|
177
|
+
- Confirm to write
|
|
178
|
+
- Preview a specific section (paths, schemas, security)
|
|
179
|
+
- Adjust structure (rename tags, regroup endpoints, change server URLs)"
|
|
180
|
+
|
|
181
|
+
---
|
|
182
|
+
|
|
183
|
+
### Step 6: Validation
|
|
184
|
+
|
|
185
|
+
Run structural and content validation on the assembled spec.
|
|
186
|
+
|
|
187
|
+
1. **Structural:** all `$ref` pointers resolve, no duplicate `operationId`, no duplicate path+method, required fields present.
|
|
188
|
+
2. **Content quality:** endpoints missing `summary`/`description`, responses without error codes (400, 401, 500), request bodies without `required` fields, undocumented path parameters, security-sensitive endpoints without auth.
|
|
189
|
+
3. **Convention checks** (from `hatch3r-api-design` rule if loaded): naming conventions, consistent error shapes, pagination consistency, versioning alignment.
|
|
190
|
+
4. Run `spectral` or `redocly` CLI if available in the project.
|
|
191
|
+
|
|
192
|
+
```
|
|
193
|
+
Validation Results:
|
|
194
|
+
Structural: {pass / N errors}
|
|
195
|
+
Descriptions: {N} operations missing descriptions
|
|
196
|
+
Error codes: {N} operations missing standard error responses
|
|
197
|
+
Security: {N} sensitive endpoints without auth schemes
|
|
198
|
+
Conventions: {N} violations (from hatch3r-api-design)
|
|
199
|
+
Spectral/Redocly: {N warnings, M errors / not available}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
Fix structural errors automatically. Present convention warnings for user decision.
|
|
203
|
+
|
|
204
|
+
**ASK (if warnings exist):** "Validation found {N} warnings. Fix these before writing, or write as-is and address later?"
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
### Step 7: Drift Detection (Validate Mode Only)
|
|
209
|
+
|
|
210
|
+
If mode is `validate`, compare the existing spec against discovered endpoints from Step 3.
|
|
211
|
+
|
|
212
|
+
1. **Load and parse** the existing spec.
|
|
213
|
+
2. **Classify each endpoint** as Matching (in both, types consistent), Undocumented (in code only), Stale (in spec only), or Drifted (in both, types differ).
|
|
214
|
+
3. **Compare schemas** — fields added/removed in code vs. spec, type changes, optional→required shifts.
|
|
215
|
+
4. **Compare security** — endpoints that gained or lost auth requirements.
|
|
216
|
+
|
|
217
|
+
```
|
|
218
|
+
Drift Report:
|
|
219
|
+
Matching: {N} endpoints — no drift
|
|
220
|
+
Undocumented: {N} endpoints in code, missing from spec
|
|
221
|
+
{method} {path} — {file}:{line}
|
|
222
|
+
Stale: {N} endpoints in spec, not found in code
|
|
223
|
+
{method} {path}
|
|
224
|
+
Drifted: {N} endpoints with schema differences
|
|
225
|
+
{method} {path} — {diff summary}
|
|
226
|
+
Security drift: {N} endpoints with auth changes
|
|
227
|
+
```
|
|
228
|
+
|
|
229
|
+
**ASK:** "Drift report above. Options:
|
|
230
|
+
- **Update spec** — merge undocumented, remove stale, update drifted
|
|
231
|
+
- **Report only** — write drift report to `docs/api/drift-report.md`
|
|
232
|
+
- **Selective update** — tell me which changes to apply"
|
|
233
|
+
|
|
234
|
+
---
|
|
235
|
+
|
|
236
|
+
### Step 8: Output
|
|
237
|
+
|
|
238
|
+
After all confirmations:
|
|
239
|
+
|
|
240
|
+
1. **Write the spec file** to the confirmed output path. Create parent directories if needed.
|
|
241
|
+
2. **Write a summary report** to `docs/api/api-spec-summary.md` containing: generation date, mode, framework, endpoint/schema/tag counts, coverage percentages (descriptions, request types, response types, error responses, auth), endpoints-by-tag breakdown, and unresolved issues.
|
|
242
|
+
3. If validate mode with updates, write the updated spec.
|
|
243
|
+
4. Present final summary:
|
|
244
|
+
|
|
245
|
+
```
|
|
246
|
+
Files Created/Updated:
|
|
247
|
+
{output path} — {N} endpoints, {M} schemas
|
|
248
|
+
docs/api/api-spec-summary.md — coverage and stats report
|
|
249
|
+
docs/api/drift-report.md — drift report (validate mode only, if applicable)
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
---
|
|
253
|
+
|
|
254
|
+
## Error Handling
|
|
255
|
+
|
|
256
|
+
- **No route definitions found:** Report and ASK the user to confirm framework, point to route files, or check scope. Do not generate an empty spec.
|
|
257
|
+
- **Types not extractable (JS without JSDoc):** Warn schemas will be `{}`. Recommend adding JSDoc or TypeScript types. Proceed with placeholders if confirmed.
|
|
258
|
+
- **Multiple API frameworks detected:** Present all with file counts and confidence. ASK which to use as primary, or generate a combined spec with tags separating frameworks.
|
|
259
|
+
- **Existing spec parse failure (validate mode):** Report parse error with line number. ASK whether to regenerate or fix manually first.
|
|
260
|
+
- **Circular type references:** Break cycle with `$ref` to root type and warn the user.
|
|
261
|
+
- **File write failure:** Report error and provide full spec content for manual creation.
|
|
262
|
+
- **Missing `package.json`:** Use placeholders for `info.title`/`info.version`. ASK the user to provide values.
|
|
263
|
+
- **Researcher sub-agent failure:** Retry once. If it fails again, fall back to inline scanning with reduced depth.
|
|
264
|
+
|
|
265
|
+
## Guardrails
|
|
266
|
+
|
|
267
|
+
- **Never overwrite an existing spec without confirmation.** Present a diff summary and ASK before writing.
|
|
268
|
+
- **Never skip ASK checkpoints.** Every step with an ASK must pause for user confirmation.
|
|
269
|
+
- **Flag endpoints with no request/response types.** Always surface these rather than silently generating `{}`.
|
|
270
|
+
- **Warn about security endpoints without auth schemes.** Auth, payments, and user data endpoints must have `security` defined.
|
|
271
|
+
- **Do not invent endpoints.** Only document routes that exist in code.
|
|
272
|
+
- **Do not modify application code.** This command reads the codebase — it writes only to spec and documentation files.
|
|
273
|
+
- **Respect existing spec structure in validate mode.** Preserve custom descriptions, examples, and `x-*` extensions.
|
|
274
|
+
- **Schema names must be stable.** Use original TypeScript type/interface names — consumers may depend on name stability.
|
|
275
|
+
- **Respect the project's tooling hierarchy** for knowledge augmentation: project docs → codebase exploration → Context7 MCP → web research.
|
|
276
|
+
- **Spec must be valid.** Never write a spec that fails structural validation. Fix issues before writing.
|
|
277
|
+
|
|
278
|
+
## Output Templates
|
|
279
|
+
|
|
280
|
+
### Spec Header
|
|
31
281
|
|
|
32
|
-
|
|
282
|
+
```yaml
|
|
283
|
+
openapi: "3.1.0"
|
|
284
|
+
info:
|
|
285
|
+
title: "{package name}"
|
|
286
|
+
version: "{package version}"
|
|
287
|
+
description: "{package description}"
|
|
288
|
+
servers:
|
|
289
|
+
- url: "http://localhost:{port}"
|
|
290
|
+
description: "Local development"
|
|
291
|
+
```
|
|
33
292
|
|
|
34
|
-
|
|
35
|
-
2. **Scan the codebase** for current endpoints (same as generate step 1).
|
|
36
|
-
3. **Compare:** identify endpoints in code but not in spec (undocumented), and endpoints in spec but not in code (stale).
|
|
37
|
-
4. **Schema drift:** check if request/response types in code have diverged from spec schemas.
|
|
38
|
-
5. **Report** discrepancies with file locations and suggested fixes.
|
|
293
|
+
### Drift Report Entry
|
|
39
294
|
|
|
40
|
-
|
|
295
|
+
```markdown
|
|
296
|
+
### {METHOD} {path}
|
|
41
297
|
|
|
42
|
-
-
|
|
43
|
-
-
|
|
44
|
-
-
|
|
298
|
+
- **Status:** {Undocumented | Stale | Drifted}
|
|
299
|
+
- **File:** `{source file}:{line}`
|
|
300
|
+
- **Details:** {what differs — added/removed fields, type changes}
|
|
301
|
+
- **Suggested fix:** {add to spec / remove from spec / update schema}
|
|
302
|
+
```
|
|
45
303
|
|
|
46
304
|
## Related
|
|
47
305
|
|
|
48
|
-
- **
|
|
49
|
-
- **
|
|
306
|
+
- **Rule:** `hatch3r-api-design` — API design conventions the generated spec must follow
|
|
307
|
+
- **Command:** `hatch3r-codebase-map` — structural map that can help scope the API scan
|
|
308
|
+
- **Command:** `hatch3r-project-spec` — project-level specification for API info block context
|
|
309
|
+
- **Agent:** `hatch3r-researcher` — performs codebase scan for route definitions
|
|
310
|
+
- **Agent:** `hatch3r-docs-writer` — assembles the final spec document
|
|
311
|
+
- **Agent:** `hatch3r-reviewer` — validates the generated spec for correctness
|