Api craft

From Intense-Visions/harness-engineering · View interactive version

Api craft is an AI agent skill from the GitHub repository Intense-Visions/harness-engineering. > LLM-judgment critique of API design quality — the ceiling counterpart to rule-based API checks (OpenAPI-format compliance and webhook-format validation). A linter can confirm a path is documented an

How to use this skill

Skill file

API Craft

LLM-judgment critique of API design quality — the ceiling counterpart to rule-based API checks (OpenAPI-format compliance and webhook-format validation). A linter can confirm a path is documented and a schema validates; only judgment can tell whether the endpoint sits at the right abstraction, whether the HTTP verb is honest, whether a resource name belongs in the URL or a query param, whether a stranger could predict the response shape, and whether the error tells the consumer what to do. Emits 3-axis findings (tier × impact × confidence per ADR 0019).

When to Use

Capability Roles

<!-- Capability seam: this skill participates in a real extension point whose three roles are named and concrete. A seam with only one role filled is accidental single-implementation lock-in. See harness-skill-authoring Phase 1C. -->

Process

B' precondition check (every invocation)

api-craft is the ceiling; it runs regardless of setup, but its critique sharpens when a project declares its API conventions. Before critiquing, note the state:

| Precondition | Source | If missing |

| ------------------ | ------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| apiStyleDeclared | a project API style guide (e.g. docs/**/API.md) | Run with the generic seed rubrics; note in the summary that a style guide would sharpen critique and offer to seed one (progressive upgrade — the same posture as docs-craft's B'). |

When no style guide exists, api-craft still runs with the seed rubrics (degraded, not blocked). It never refuses to critique just because a project has not written its API conventions down.

Phase 1: DISCOVER — Find API surfaces

  1. Read project configuration. Shared craft config under craft.llm.* selects the judgment backend. maxFiles (default 60) caps the surface count.
  1. Discover the API surface. Two kinds are collected:
  1. Exclude non-API surfaces. Tests / specs, type declarations, barrels and registries (index.ts, _registry.ts), build / dependency trees (node_modules, dist), and helper modules under an API root that define no endpoint are skipped — they are not authored API surfaces.

Phase 2: CRITIQUE — Per (surface, rubric) loop, kind-filtered

9 seed rubrics, each declaring which surface kinds it applies to:

| Rubric | Title | Applies to |

| ---------- | -------------------------------------------------- | ---------- |

| API-R001 | Resources model the domain, not the implementation | all |

| API-R002 | Resource naming and URL structure are predictable | all |

| API-R003 | HTTP methods are honest | all |

| API-R004 | Status codes are correct and meaningful | all |

| API-R005 | Error responses tell the consumer what to do | all |

| API-R006 | Response shapes are predictable and consistent | all |

| API-R007 | Collections paginate and filter consistently | all |

| API-R008 | Mutations are idempotency-honest | route only |

| API-R009 | Evolves without breaking consumers | all |

For each (surface, rubric) where the rubric applies to the surface's kind:

  1. Build a prompt with the rubric description + surface kind + surface source (truncated to 8000 chars for cost).
  2. The LLM returns fenced JSON: null (rubric doesn't apply / the surface already clears the bar) OR { tier, impact, confidence, message }.
  3. On non-null: emit an ApiFinding with cite.rubricId populated for ADR 0020 traceability, and a derived priority for sorting.

Idempotency (API-R008) is a handler-behavior concern a declarative spec rarely captures, so it critiques route surfaces only; an OpenAPI document is critiqued against the other eight rubrics. This is the API analogue of cli-ergonomics-craft's leaf/group filter.

A small curated exemplar set anchors the catalog — Stripe, Linear's GraphQL API, GitHub's REST API, Resend, and the Anthropic API — each a public reference point for one API-quality dimension (Stripe for idempotent requests, cursor pagination, and dated versioning; Linear for domain-mirroring types; GitHub for a guessable path grammar; Resend for a right-sized resource surface; Anthropic for honest methods and a consistent error contract). The exemplars ground the rubric sources today and seed a future BENCHMARK phase, the direct analogue of docs-craft's exemplar corpus.

Phase 3: REPORT — Aggregate + cost telemetry

Emit ApiCraftOutput:

{
  findings: ApiFinding[];
  summary: {
    phaseRun: ['critique'];
    mode: 'fast';
    durationMs: number;
    llmCalls: { provider, model, count, costUsd };
    catalog: { rubricsApplied: string[]; exemplarsAvailable: number };
    counts: { filesScanned, filesSkipped };
    runId: string;
  }
}

Harness Integration

Invoked as a review hook

api-craft auto-activates as an advisory review hook whenever a diff touches the surface it

owns — harness-autopilot at after:REVIEW / after:FINAL_REVIEW, and harness-code-review at

after:mechanical. The domain table is CRAFT_REVIEW_DOMAINS and the per-host events are

CRAFT_REVIEW_EVENTS_BY_HOST, both in packages/core/src/hooks/craft-review-hooks.ts. The host

forwards the subset of the diff this domain owns:

reads it from plan.files["api-craft"], which holds repo-relative POSIX paths, and resolves each

entry against the project root before calling mcp__harness__api_craft. Absolute is the

recommended form, not a correctness requirement for this domain: its collector resolves a

relative entry against the tool's path (never the process CWD), so a repo-relative entry

forwarded unresolved still reads the in-diff file (pinned by

packages/cli/tests/shared/craft/relative-files-scope.test.ts). Only

mcp__harness__design_craft still requires absolute paths.

Findings from a hook-triggered run are advisory: reported, never blocking, never counted toward

review severity, and never entered into a host's mechanical exclusion set. A hook-triggered run

that fails is a missing opinion, not a broken gate.

Success Criteria

See docs/changes/api-craft/proposal.md for the full success criteria. Highlights:

Rationalizations to Reject

These are common rationalizations that sound reasonable but lead to incorrect results. When you catch yourself thinking any of these, stop and follow the documented process instead.

| Rationalization | Why It Is Wrong |

| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |

| "This endpoint validates against its OpenAPI schema, so the contract is fine." | Schema validity is the mechanical floor. api-craft asks whether the SHAPE is right — is the verb honest, does the resource model the domain, does the error tell the consumer what to do. A schema-valid GET /widgets/delete/:id still fails API-R003. |

| "It is just an internal API, so I can skip the compatibility critique." | API-R009 applies wherever there are consumers. Internal callers break exactly the way external ones do when a response shape or field meaning shifts unannounced — the blast radius is smaller, not the rule. |

| "The handler returns a 500 with a message, so errors are covered." | API-R004 and API-R005 ask whether the status code is CORRECT for the failure and whether the body tells the consumer what to DO next — not merely that some error came back. A generic 500 on a client-caused failure fails both. |

| "I can see the fix, so I will add the idempotency key to the handler while I am here." | api-craft is judgment-only. It emits a finding naming the surface and a concrete suggested change; it never rewrites a contract or handler. Editing here violates the no-autofix gate and hides the finding from the consumer who owns the decision. |

| "No API style guide is declared, so a critique would not be meaningful." | The B' check degrades to the seed rubrics — it never blocks. Refusing to critique because a project has not written its conventions down abandons the ceiling role; note the degraded context and run anyway. |

Examples

Example: A GET that mutates state

Input: src/routes/widgets.ts defining router.get('/widgets/delete/:id', …) whose handler deletes the record.

Output (mock LLM):

src/routes/widgets.ts (route)
  API-R003 [foundational/large/high] src/routes/widgets.ts (route)
    `GET /widgets/delete/:id` mutates state — a GET must be safe, and caches or
    prefetchers may replay it. Model this as `DELETE /widgets/:id` so retry and
    caching behavior are predictable from the method alone.

Example: A create with no idempotency path

Input: src/routes/payments.ts — a POST /payments handler that charges a card with no idempotency key and no dedup.

Output:

src/routes/payments.ts (route)
  API-R008 [foundational/large/high] src/routes/payments.ts (route)
    `POST /payments` charges on every call with no idempotency key — a network
    retry double-charges. Accept an `Idempotency-Key` header and return the
    original result for a repeated key, the way Stripe's charge API does.

Example: A clean OpenAPI document — no findings

Input: An openapi.yaml with domain-modeled resources, plural paths, honest methods, correct status codes, a consistent typed error schema, cursor pagination, and a version.

Output:

No API-craft findings.

Summary: 0 findings across 1 API surfaces (0 skipped, 8 rubrics, 5 exemplars, 8 LLM calls, $0.0000, 5ms)

Gates

Escalation

Status

v1 — CRITIQUE phase. See:

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.