mech.app

The mech.app newsletter

Agentic AI, minus the noise.

Get practical field notes on AI agents, automation, developer tools and security delivered to your inbox.

No spam. Unsubscribe anytime.

Dev Tools

Spec Kit's Process Primitives: How GitHub Built Reusable Workflow Components for Coding Agents

GitHub's Spec Kit uses composable primitives and syntax tree checks to enforce deterministic agent workflows without LLM runtime overhead.

Source: github.com
Spec Kit's Process Primitives: How GitHub Built Reusable Workflow Components for Coding Agents

GitHub released Spec Kit with 151K stars and a clear thesis: coding agents need structured processes, not just AGENTS.md files that get ignored after three conversation turns. The toolkit ships three bundled workflows (Spec-Driven Development, bug fixing, idea assessment) and a set of composable primitives for building custom agent processes. The architecture enforces determinism by feeding agents structured information instead of letting them wander codebases, and it uses syntax tree checks (ast-grep, Vale) to replace LLM runtime for enforcement.

The Problem with Freeform Agent Instructions

Most teams give coding agents a markdown file with guidelines. The agent reads it once, then starts making decisions based on its training data and conversation context. By turn five, it’s proposing changes that violate the original constraints because there’s no enforcement mechanism.

Spec Kit addresses this by turning processes into executable workflows with quality gates. Instead of hoping the agent remembers your architecture rules, you encode them as checks that run before the agent proceeds to the next phase.

Architecture: Primitives Over Prescriptions

Spec Kit’s design centers on three composable mechanisms:

Integrations connect the CLI to coding agents (GitHub Copilot, Claude, Cursor). They handle authentication, context injection, and response parsing. Each integration exposes a standard interface so the CLI can swap agents without rewriting process logic.

Extensions add commands, quality gates, or complete processes. The bug-fixing workflow is an extension. So is idea assessment. You install them when needed, and they plug into the same primitive layer as the core SDD process.

Quality gates run checks at process boundaries. These are not LLM calls. They’re syntax tree queries (ast-grep for code structure) and prose linters (Vale for documentation). The CLI blocks progression until checks pass.

The CLI itself is local-first. No cloud dependency for core checks. Anonymous telemetry can be disabled with DO_NOT_TRACK=1.

How Determinism Works in Practice

Spec Kit enforces determinism by controlling what information reaches the agent and when. Here’s the flow for Spec-Driven Development:

  1. Planning phase: Agent receives a feature request and existing architecture docs. It generates a spec. The CLI runs Vale checks on the spec prose and ast-grep queries on any code snippets. If checks fail, the agent sees the failure output and revises.

  2. Implementation phase: Agent receives the approved spec and current codebase state. It writes code. The CLI runs syntax tree checks for architectural patterns (no direct database calls in controllers, all API responses use standard error shapes). Failures block the commit.

  3. Convergence phase: Agent receives test results and coverage reports. It fixes failures. The CLI verifies that coverage thresholds are met and that no new violations appeared.

At each boundary, the CLI generates a report showing what passed and what failed. The agent never decides whether it met the requirements. The checks decide.

Syntax Tree Checks vs. LLM Runtime Enforcement

Using ast-grep and Vale instead of LLM calls for enforcement has three advantages:

Speed: Syntax tree queries run in milliseconds. An LLM call to verify code structure takes seconds and costs tokens.

Consistency: ast-grep patterns match or they don’t. An LLM might interpret “no direct database calls” differently across runs.

Debuggability: When a syntax tree check fails, you see the exact pattern that didn’t match. When an LLM enforcement call fails, you get a natural language explanation that might be wrong.

Here’s an example ast-grep pattern that blocks direct database queries in HTTP handlers:

id: no-db-in-handlers
language: python
rule:
  pattern: |
    def $HANDLER($$$):
      $$$
      $DB.execute($$$)
      $$$
  inside:
    kind: function_definition
    has:
      field: decorator
      regex: "@app\\.(get|post|put|delete)"
message: "HTTP handlers must call service layer, not database directly"
severity: error

The CLI runs this pattern against every file in the changeset. If it matches, the agent sees the error and the file location. No ambiguity.

Building Custom Processes with Extensions

The three bundled processes cover common cases, but teams need custom workflows. Spec Kit’s extension system lets you compose new processes from primitives.

An extension is a Python module that registers commands and quality gates. Here’s the structure:

from spec_kit.extension import Extension, QualityGate

class SecurityReviewExtension(Extension):
    name = "security-review"
    
    def register_commands(self, cli):
        @cli.command()
        def threat_model():
            """Generate threat model from spec"""
            # Read spec, call agent with security prompt
            pass
    
    def register_gates(self):
        return [
            QualityGate(
                name="secrets-check",
                command="gitleaks detect --no-git",
                phase="pre-commit"
            ),
            QualityGate(
                name="dependency-audit",
                command="safety check --json",
                phase="pre-merge"
            )
        ]

You install it with spec-kit extension install ./security-review, and it becomes available alongside the core commands. The CLI handles execution order, failure reporting, and state management.

Report Generation and Human-Agent Collaboration

Every process run generates a report. The report includes:

  • Inputs provided to the agent (spec, codebase snapshot, test results)
  • Agent outputs (code, documentation, decisions)
  • Quality gate results (pass/fail for each check)
  • Timestamps and execution duration

Reports from Effect, Sentry, and n8n repositories show real-world adoption patterns. Teams use them for:

Audit trails: When a bug ships, the report shows which checks passed and what the agent was told.

Process refinement: If agents consistently fail the same gate, the team adjusts the prompt or the check.

Handoff context: When a human takes over from an agent, the report provides full history without replaying the conversation.

The CLI stores reports as JSON in .spec-kit/reports/. You can parse them with standard tools or feed them to observability systems.

State Management and Failure Modes

Spec Kit tracks process state in .spec-kit/state.json. The state file records:

  • Current phase (planning, implementation, convergence)
  • Completed quality gates
  • Pending agent tasks
  • Retry count for failed checks

If the CLI crashes or the agent times out, you restart with spec-kit resume. The CLI reads the state file and picks up where it stopped.

Failure modes to watch:

FailureCauseMitigation
Agent ignores check failuresIntegration doesn’t surface errorsVerify integration parses CLI output correctly
Syntax tree check false positivePattern too broadNarrow the ast-grep rule or add exclusions
Process stuck in retry loopCheck will never passManual override with --skip-gate flag
State file corruptionConcurrent CLI runsUse file locking or run CLI in single-threaded mode

The CLI logs all operations to .spec-kit/logs/. When debugging failures, check the log before the state file. The log shows the exact commands run and their exit codes.

Deployment Shape

Spec Kit runs locally. No server component. The CLI is a Python package installed via pip. Integrations authenticate to coding agents using their native auth (GitHub token, Anthropic API key, Cursor session).

For team deployments, you can:

  • Commit .spec-kit/ to version control (state and reports travel with the repo)
  • Share extensions via internal package registry
  • Standardize quality gates in a shared config file

The CLI respects .gitignore and won’t commit sensitive data. If you need to sanitize reports before sharing, run spec-kit report redact to strip API keys and tokens.

When to Use Spec Kit

Good fit:

  • Teams using coding agents for feature development and want repeatable workflows
  • Projects with architectural constraints that agents must follow (layering, error handling, security patterns)
  • Codebases where agent output needs audit trails for compliance

Poor fit:

  • Exploratory prototyping where constraints slow you down
  • Projects without clear architectural rules (syntax tree checks need patterns to enforce)
  • Teams that prefer agent autonomy over deterministic processes

Spec Kit trades agent flexibility for process consistency. If your agents already produce reliable output without guardrails, you don’t need this. If they drift off spec by conversation turn five, this is the plumbing to fix it.

Technical Verdict

Spec Kit solves a real problem: agents that ignore constraints after a few turns. The architecture is sound. Composable primitives, syntax tree enforcement, local-first execution. The three bundled processes give you working examples, and the extension system lets you build custom workflows without forking the CLI.

The tradeoff is upfront cost. You need to encode your architectural rules as ast-grep patterns and Vale prose checks. That takes time. But once encoded, those checks run on every agent interaction without token cost or latency.

Use Spec Kit when you need deterministic agent behavior and can invest in defining quality gates. Skip it if your agents already stay on track or if you’re prototyping without constraints.