docs-driven-api-updater
v1.0.2
Published
Universal docs-driven API updater that crawls official docs, plans safe code updates, and applies changes locally or in CI.
Maintainers
Readme
docs-driven-api-updater
Universal, TypeScript-first, ESM-only SDK maintenance tool that crawls third-party docs and proposes safe updates for integration wrappers, endpoint lists, and README method tables.
Install
npm install docs-driven-api-updaterQuick Start
npx docs-driven-api-updater init
cp .env.example .env
npx docs-driven-api-updater update --dry-runAdd Any API Integration
- Create a directory for the integration (example:
src/integrations/shopify). - Add a methods registry JSON (example:
src/integrations/shopify/supported-methods.json). - Add/update your wrapper
.tsfiles in that integration directory. - Register the integration in
updater.config.json:
{
"integrations": [
{
"name": "shopify",
"docUrls": ["https://shopify.dev/docs/api/admin-rest"],
"methodsFile": "src/integrations/shopify/supported-methods.json",
"targetDir": "src/integrations/shopify"
}
]
}- Run updater preview:
npx docs-driven-api-updater update --dry-runUpdater Pipeline
The updater is docs-driven, not runtime mutation. It creates reviewable file updates for local/CI usage.
- Doc crawl:
crawlAllDocs()fetches configured docs and extracts normalized text + table rows. - Plan generation:
askOllamaForPatchPlan()sends docs + currentsupported-methods.jsonto OpenRouter or Ollama and expects strict JSON:summaryupdatedMethodschangesfiles(full file outputs)readmeTable
- Diff planning:
planDiffs()produces git-style previews for allowed targets:src/integrations/*/*.tsREADME.md- each integration
supported-methods.json
- Safety gate:
validateUpdaterPlanSafety()rejects suspicious plans (placeholder rewrites, destructive class replacements, abnormal file shrink). - Preview + apply:
runUpdateCommand()prints diffs, asks for confirmation (unless--yes/--ci), applies changes, syncs methods, and rebuilds. - CI/PR flow: writes artifacts and opens PR rather than silently changing main.
flowchart LR
A[Crawl Docs] --> B[Generate JSON Plan]
B --> C[Safety Validation]
C --> D[Plan Diffs]
D --> E{Mode}
E -->|Local| F[Preview + Confirm + Apply]
E -->|CI| G[Artifacts + PR]CLI Commands
init
Creates:
updater.config.json.env.example- starter
src/integrations/stripe/supported-methods.json
update
npx docs-driven-api-updater update [options]Flags:
--dry-run: compute plan + preview diffs without writing files--yes: auto-confirm apply--ci: CI mode (non-interactive)--open-pr: produce PR metadata artifacts--fallback-models "modelA,modelB": CLI model failover override--max-model-attempts 3: cap fallback attempts
Safety & Reliability
- Provider abstraction: OpenRouter and local Ollama.
- Fallback chain: tries multiple models with short backoff.
- Retry-aware statuses:
402,404,408,429. - Prompt truncation knobs: limit docs/method payload sizes.
- Sanitized errors: avoids dumping secrets and huge request bodies.
- Safety gate: rejects suspicious destructive model output patterns.
CI / PR Automation
Workflow: .github/workflows/auto-update-pr.yml
- Supports schedule and manual dispatch.
- Runs updater in CI mode.
- Writes:
.artifacts/update-plan.json.artifacts/update-diff-summary.json.artifacts/pr-title.txt.artifacts/pr-body.md
- Opens PR (not direct mutation of main branch).
- Supports
dry_rundispatch input.
Error Handling Guide
- Missing config: run
npx docs-driven-api-updater init. - Provider auth errors: verify
OPENROUTER_API_KEYorOLLAMA_HOST. - Schema validation failure: model output was not strict JSON; use fallback models or lower prompt size.
- Safety gate failure: inspect
.artifacts/update-plan.jsonand rerun with tighter prompts. - No diffs generated: docs may not contain relevant changes; verify
docUrlsand integration file paths.
Rate-Limit & Cost Control
Use .env knobs:
UPDATER_DOC_MAX_CHARS: lower docs payload size.UPDATER_PROMPT_DOC_MAX_CHARS: hard cap LLM docs context.UPDATER_PROMPT_METHODS_MAX_CHARS: cap methods context.MAX_MODEL_ATTEMPTS: reduce fallback attempts.UPDATER_LLM_TIMEOUT_MS: prevent runaway requests.
Strategy:
- Start with
--dry-run. - Keep integrations small and focused.
- Add only high-signal docs URLs.
- Run weekly in CI.
Updated Methods Snapshot
| Integration | Method | Status | Notes | |---|---|---|---| | stripe | customers.create | stable | baseline template method | | stripe | charges.create | stable | baseline template method |
