sync-api-spec
Skill2 starsChanged 12 days agoMITView on GitHub
Scans all API routes in the project and maintains docs/agents/api-spec.md — a machine-readable API reference for coding agents, frontend, and product to understand what APIs do. Incremental: only re-scans handlers for new or changed routes. Optional Confluence publish step after local file is written. Use when at the Implement & PR phase of the SDD workflow, or whenever you want to keep the API spec file current.
In this repository18 other files it gives its agents.
- ado-open-prSkill
- ado-pr-code-reviewSkill
- ado-pr-resolve-commentsSkill
- ado-pr-teams-notifySkill
- agent-playtestSkill
- explain-diff-htmlSkill
- generate-pr-notesSkill
- git-commit-conventional-strictSkill
- install-atlassian-mcpSkill
- install-azure-devops-mcpSkill
- install-playwright-mcpSkill
- install-sentry-mcpSkill
- prd-to-sdd-specSkill
- sdd-qa-to-ticketSkill
- setup-project-configSkill
- spec-recalibrateSkill
- tech-plan-to-ticketSkill
- tech-plan-to-wikiSkill
The file
Show its rules and text
We split this skill into the rules it gives an agent
35 rules. About 0 are common, 19 are distinctive, and 16 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈19
Distinctive · estimate
This author's own choices. Worth a look.
16
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 39
Use framework, router file path, handler directory, DTO/model directory, and service directory from it throughout.
- Very specific: line 53
If CONTRACT_MODE=true, jump directly to the Contract Mode section below after this step.
- Distinctive: line 56
Default: scan all routes (full sync).
- Distinctive: line 57
If user names specific routes or says "only new routes", restrict to those.
- Very specific: line 62
If no framework is in config: use the Auto-Detection section of framework-patterns.md, then confirm with user.
- Very specific: line 71
After all promotions, if no 🔷 CONTRACT entries remain, ask: All contract routes are now implemented.
- Very specific: line 76
If an OpenAPI/Swagger spec file is available, read references/openapi-parsing.md (in this skill's folder) and prefer spec data over code …
- Very specific: line 79
Follow the format in references/api-spec-format.md exactly.
- Very specific: line 81
Update the Last updated timestamp and ## Endpoints Summary table.
- Very specific: line 84
Ask: Publish to Confluence?
- Very specific: line 87
Check that Atlassian MCP tools are available (mcp__atlassian__confluence_create_page / mcp__atlassian__confluence_update_page).
- Distinctive: line 93
If the Confluence page already exists: update only the sections for the changed endpoints (do not overwrite the full page).
- Very specific: line 99
Only entered when the user answers y to the contract mode prompt in step 0b.
- Distinctive: line 117
All request headers, path params, query params, body fields (required and optional, including nested — use dot-notation)
- Very specific: line 121
First endpoint: write the full file from scratch — # API Spec heading → ## Endpoints Summary table → Contract Banner → ## Endpoints section …
- Very specific: line 124
Update the ## Endpoints Summary table: insert the new CONTRACT row at the top (above all other CONTRACT rows and all ✅ rows).
- Very specific: line 138
If user types n or N: skip.
- Very specific: line 141
Run git fetch origin first (always, to ensure a fresh origin/master).
- Distinctive: line 174
When all badges are gone → offer to remove the Contract Banner.
- Distinctive: line 179
Only re-scan handlers for new or user-named routes: Never re-scan routes already documented unless explicitly asked.
- Distinctive: line 184
Use the router file, handler/controller directory, DTO/model directory, and service directory from project config.
- Very specific: line 185
Use Grep to quickly find route registrations and handler function names.
- Distinctive: line 186
Read the full handler function to understand auth, request binding, response shapes, and service calls.
- Very specific: line 187
Read DTO/model/schema files referenced by the handler to generate accurate field lists and JSON examples.
- Distinctive: line 188
CRITICAL: All JSON examples MUST be wrapped in markdown code blocks.
- Distinctive: line 189
CRITICAL: All parameter and field lists MUST use tables.
- Distinctive: line 192
Do NOT require Confluence — the local file is the primary output.
- Distinctive: line 193
Only check for MCP tools if the user says yes to the publish prompt.
- Distinctive: line 194
If MCP tools are unavailable, skip Confluence and confirm the local file was written successfully.
- Distinctive: line 198
CRITICAL: All API documentation MUST include JSON response examples.
- Distinctive: line 202
Read the DTO file to understand the exact JSON structure
- Distinctive: line 203
Create realistic example responses with actual field names and data types
- Distinctive: line 243
Use the response patterns for your framework (see Framework-Specific Analysis) to find actual response structures
- Very specific: line 244
Read the response DTO/model/schema files referenced in annotations or function signatures
- Distinctive: line 245
Check service layer return values for response shapes
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Sync API Spec
Install this skill
npx skills add jamesyang124/agent-skills --skill sync-api-spec -gThis skill maintains docs/agents/api-spec.md — a compact, machine-readable API reference for the consuming project. It scans the router for all routes, diffs against the existing spec file to find new or changed routes, re-scans only those handlers, and writes an updated file. An optional Confluence publish step is offered after the local file is written.
Arguments
All optional.
| Token | Meaning |
one or more route paths (e.g. /v1/users) | restrict the scan to those routes; default is a full sync of every route |
Contract mode is not an argument — it is asked in step 0b of the process below.
Output File
Target: docs/agents/api-spec.md (relative to the consuming project root, not this repo).
Format is defined in references/api-spec-format.md.
Process
- Load project configuration: The code structure should have been provided to you in
docs/agents/code-structure.md; run/setup-project-configif not, then stop.- Use framework, router file path, handler directory, DTO/model directory, and service directory from it throughout.
- A legacy
.agent-settings/project-config.mdwithoutdocs/agents/→ tell the user to run/setup-project-config, which migrates it.
0b. Contract mode check:
Ask the user:
Generate in contract mode? (y/n)
- Blank input: re-prompt — must type y or n.
- Contract mode (y): the spec describes a planned / agreed-upon API that has not been implemented yet.
The agent documents based on user-provided descriptions, not scanned code.
Set CONTRACT_MODE=true. Skip steps 2–4 (no router scan, no handler scan).
- Normal mode (n): scan existing code as usual. Set CONTRACT_MODE=false.
If `CONTRACT_MODE=true`, jump directly to the **Contract Mode** section below after this step.- Determine scope:
- Default: scan all routes (full sync).
- If user names specific routes or says "only new routes", restrict to those.
- Scan the router using the router file path from config.
- Apply framework-specific parsing from
references/framework-patterns.md(in this skill's folder). - Build a list of all current routes:
{method} {path} → handler. - If no framework is in config: use the Auto-Detection section of
framework-patterns.md, then confirm with user.
- Apply framework-specific parsing from
- Load existing spec (if
docs/agents/api-spec.mdexists):- Parse the
## Endpoints Summarytable to extract already-documented routes. - Diff: routes in router but not in spec = new; routes in spec but not in router = removed (flag for deletion, confirm with user before removing).
- Routes in both = existing (skip unless user explicitly named them).
- Contract promotion check: scan the spec for any entries with a
🔷 CONTRACTbadge. For each one, check whether that route (METHOD /path) now appears in the router scan from step 2.- Found in router → route has been implemented. Scan its handler (step 4), update the entry with real data, and remove the
🔷 CONTRACTbadge automatically. Report to user:✓ Promoted from contract: METHOD /path. - Not found in router → route is still unimplemented. Leave the badge and entry unchanged.
- After all promotions, if no
🔷 CONTRACTentries remain, ask:All contract routes are now implemented. Remove the contract banner? (y/n)— blank re-prompts, must typeyorn.
- Found in router → route has been implemented. Scan its handler (step 4), update the entry with real data, and remove the
- Parse the
- Scan handlers for new (and user-named) routes only:
- Apply framework-specific handler analysis from
framework-patterns.md. - For each handler extract: HTTP method, path, purpose (one line), auth/middleware, request params/body, response codes and shapes, key implementation notes.
- If an OpenAPI/Swagger spec file is available, read
references/openapi-parsing.md(in this skill's folder) and prefer spec data over code inference.
- Apply framework-specific handler analysis from
- Write
docs/agents/api-spec.md:- Follow the format in
references/api-spec-format.mdexactly. - Merge: keep existing documented entries unchanged, append new entries, mark removed routes with a
> ⚠️ Route removed from router — confirm deletioncallout (do not delete automatically). - Update the
Last updatedtimestamp and## Endpoints Summarytable.
- Follow the format in
- Offer optional Confluence publish:
- Ask:
Publish to Confluence? (y/n)— blank re-prompts, must typeyorn. - If
n: skip. - If
y:- Check that Atlassian MCP tools are available (
mcp__atlassian__confluence_create_page/mcp__atlassian__confluence_update_page). If not available, tell user to configure the MCP server first and skip this step. - Only publish routes changed in this session — not the full spec:
- Normal mode: determine changed routes by running
git diff HEAD -- docs/agents/api-spec.mdand extracting only the## METHOD /pathheadings that appear in the diff (added+lines). Publish only those endpoint cards. - Contract mode: publish only the endpoint cards added during the current contract session (the ones written in step 1c).
- Promoted routes (contract → implemented): publish the updated card for each promoted route.
- Normal mode: determine changed routes by running
- Confluence page: use the space key and parent page from
docs/agents/atlassian.md(ask the user if it is missing). Page title:API Spec — {Project Name}. - If the Confluence page already exists: update only the sections for the changed endpoints (do not overwrite the full page). If it does not exist: create it with the full spec content.
- Check that Atlassian MCP tools are available (
- Ask:
Contract Mode
Only entered when the user answers y to the contract mode prompt in step 0b.
Contract mode documents planned APIs that do not yet exist in code. The agent works from user input, not scanned source files.
Contract Mode Process
Endpoint input loop — repeat until the user is done:
a. Ask:
Describe the next planned endpoint (method + path + purpose), or paste a spec: (Type "n" to finish adding endpoints)b. If user provides an endpoint, collect details:
- Method and path
- Purpose (one sentence)
- Auth requirements
- All request headers, path params, query params, body fields (required and optional, including nested — use dot-notation)
- Expected response codes and shapes
c. Immediately write / prepend that endpoint's card to
docs/agents/api-spec.mdfollowingreferences/api-spec-format.md:- First endpoint: write the full file from scratch —
# API Specheading →## Endpoints Summarytable → Contract Banner →## Endpointssection heading →---separator → the card. Create the file if it does not exist. - Subsequent CONTRACT endpoints: insert the new
---+ card block as the first item inside## Endpoints(directly after the## Endpointsline), before all other cards. NEVER append to the end of the file. - Each card:
🔷 CONTRACTbadge on the## METHOD /pathheading, statusplanned. - Update the
## Endpoints Summarytable: insert the new CONTRACT row at the top (above all other CONTRACT rows and all ✅ rows).
d. After writing, ask:
✓ Added METHOD /path. Do you have another endpoint to add? (Y/n)norN→ exit the loop and continue to step 2.- Blank input or any other value → loop back to step 1a (do not accept blank as exit).
- Branch creation — once the loop ends, ask:
Create a contract branch from origin/master? Enter branch suffix (e.g. "user-auth") to create contract/<suffix>, or type "n" to skip:- If user types
norN: skip. - Blank input or any other non-
nvalue: re-prompt — do not accept blank as skip. - If suffix provided:
- Run
git fetch originfirst (always, to ensure a freshorigin/master). - Then run
git checkout -b contract/<suffix> origin/master. - Confirm:
✓ Branch contract/<suffix> created from origin/master.
- Run
- If user types
- Offer Confluence publish (same as normal mode step 6 — publishes only the endpoint cards added this contract session).
Contract Banner Format
Insert this block immediately after the ## Endpoints Summary table. Never place it above # API Spec.
The banner is present whenever the spec contains any 🔷 CONTRACT entries (regardless of whether there are also implemented entries):
> [!CAUTION]
> **CONTRACT SPEC — Contains unimplemented endpoints**
> Endpoints marked 🔷 CONTRACT in the table above have not been built and are subject to change.
> Remove each badge and this banner once all endpoints are implemented and verified.Immediately after the Contract Banner (or after the Summary table when no banner), write the ## Endpoints section heading. All cards live inside this section.
The ## Endpoints Summary table must always include a Status column:
🔷 CONTRACTrows are listed first (before all✅rows), regardless of insertion order.✅for implemented routes🔷 CONTRACTfor planned/unimplemented routes
Ordering rule for CONTRACT cards: CONTRACT endpoint cards are always placed above all implemented cards in the file. When a new CONTRACT entry is added, it is prepended to the top of the CONTRACT block (last-in, stays at top). Implemented cards follow below, in the order they were documented.
Mixed Contract + Implemented Entries
Handled automatically by the normal sync step 3 contract promotion check:
🔷 CONTRACTroutes found in the router → promoted, badge removed, handler re-scanned.🔷 CONTRACTroutes not yet in router → left unchanged.- When all badges are gone → offer to remove the Contract Banner.
Tips for the Agent
Incremental Scanning
- Only re-scan handlers for new or user-named routes. Never re-scan routes already documented unless explicitly asked.
- "Changed" routes are ones the user names explicitly, or routes flagged by the user as stale.
- Routes disappearing from the router are candidates for removal — always confirm with the user before deleting an entry from the spec.
Code Analysis
- Use the router file, handler/controller directory, DTO/model directory, and service directory from project config.
- Use
Grepto quickly find route registrations and handler function names. - Read the full handler function to understand auth, request binding, response shapes, and service calls.
- Read DTO/model/schema files referenced by the handler to generate accurate field lists and JSON examples.
- CRITICAL: All JSON examples MUST be wrapped in markdown code blocks.
- CRITICAL: All parameter and field lists MUST use tables.
Confluence (Optional Step)
- Do NOT require Confluence — the local file is the primary output.
- Only check for MCP tools if the user says yes to the publish prompt.
- If MCP tools are unavailable, skip Confluence and confirm the local file was written successfully.
Response Examples Requirements
CRITICAL: All API documentation MUST include JSON response examples. This is mandatory for:
- Success Responses:
- Analyze the response DTO structure from
@Successannotations - Read the DTO file to understand the exact JSON structure
- Create realistic example responses with actual field names and data types
- Include nested objects and arrays as they appear in the DTO
- Analyze the response DTO structure from
- Error Responses:
- Include examples for each error status code (400, 401, 403, 404, 500, etc.)
- Show the error message format used by the API
- Include both simple error strings and structured error objects
Example Format:
### Success Response **Status Code**: `200 OK` ```json { "data": { "id": "550e8400-e29b-41d4-a716-446655440000", "name": "Example Room", "created_at": "2024-01-15T10:30:00Z" }, "meta": { "total": 1 } }Error Response
Status Code:
403 Forbidden{ "error": "insufficient permissions", "code": "FORBIDDEN" }- How to Generate Examples:
- Use the response patterns for your framework (see Framework-Specific Analysis) to find actual response structures
- Read the response DTO/model/schema files referenced in annotations or function signatures
- Check service layer return values for response shapes
- For OpenAPI/Swagger spec input: use the
examplefields in the spec if present, otherwise generate from the schema - For simple string/text responses, show as plain text examples
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

