← 研究ノート
AIエージェントに実装させる前に、仕様を固める。Spec Kitを動かす

AIエージェントに実装させる前に、仕様を固める。Spec Kitを動かす

GitHub公式のSpec-Driven Development用CLI「Spec Kit」を初期化し、Codexエージェントに実際の仕様書を書かせるところまで確かめた記録。

この記事で取り扱うリポジトリ

github/spec-kit

💫 Toolkit to help you get started with Spec-Driven Development

121.6k Python MIT License

AIエージェントに実装を任せると、要件を一言渡しただけで、いきなりコードが書き上がる。速いが、後から読み返すと前提が揃っていないことに気づく。何を作るか、なぜそう作るか、どこまでを対象とするかを先に文章として固めておけば、その後の実装・計画・タスク分解を同じ土台の上で進められるはずだ。GitHub公式のSpec Kitは、この「仕様を先に固める」工程をCLIとテンプレート一式として提供する。実際にインストールし、プロジェクトを初期化するところまで確かめた。

Spec Kitは仕様駆動開発(Spec-Driven Development)のためのツールキットで、Claude Code・Copilot・Cursor等のAIコーディングエージェント向けに、仕様書・実装計画・タスクリストのテンプレートとスキルを一式インストールする。ソースはMIT Licenseで公開されている(*1)。

1. インストールする

バージョンを固定してインストールする。

FROM python:3.12.13-slim
RUN pip install --no-cache-dir --quiet 'specify-cli==0.12.15'
WORKDIR /work
podman build -t specify-sandbox .

ビルドは依存が少なく、数秒で完了した。

2. バージョンを確認する

podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work specify-sandbox specify --version

結果はspecify 0.12.15。

3. プロジェクトを初期化する

specify initはパッケージに同梱されたテンプレートからファイルを生成する設計で、ネットワークを必要としない。ネットワークを遮断したまま実行する。

podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work specify-sandbox \
  specify init demo-project --ignore-agent-tools --integration claude --script sh

-vは指定したディレクトリをコンテナから読み書き可能にする。実験専用の空ディレクトリで実行し、秘密鍵や認証情報、未公開のソースコードを置かないこと。

実行は成功し、進捗が1ステップずつ表示された。

specify initの実行結果
specify initの実行結果

生成されたファイルは27個だった。

.claude/skills/speckit-analyze/SKILL.md
.claude/skills/speckit-checklist/SKILL.md
.claude/skills/speckit-clarify/SKILL.md
.claude/skills/speckit-constitution/SKILL.md
.claude/skills/speckit-converge/SKILL.md
.claude/skills/speckit-implement/SKILL.md
.claude/skills/speckit-plan/SKILL.md
.claude/skills/speckit-specify/SKILL.md
.claude/skills/speckit-tasks/SKILL.md
.claude/skills/speckit-taskstoissues/SKILL.md
.specify/init-options.json
.specify/integration.json
.specify/integrations/claude.manifest.json
.specify/integrations/speckit.manifest.json
.specify/memory/constitution.md
.specify/scripts/bash/check-prerequisites.sh
.specify/scripts/bash/common.sh
.specify/scripts/bash/create-new-feature.sh
.specify/scripts/bash/setup-plan.sh
.specify/scripts/bash/setup-tasks.sh
.specify/templates/checklist-template.md
.specify/templates/constitution-template.md
.specify/templates/plan-template.md
.specify/templates/spec-template.md
.specify/templates/tasks-template.md
.specify/workflows/speckit/workflow.yml
.specify/workflows/workflow-registry.json

.claude/skills/配下の10個が、Claude Codeから/speckit-specify /speckit-plan /speckit-tasks /speckit-implement等のコマンドとして使えるようになるスキル定義。.specify/templates/には仕様書・実装計画・タスクリストの雛形が入っており、たとえばconstitution-template.mdは## Core Principlesの下に[PRINCIPLE_1_NAME]のようなプレースホルダーを並べた、プロジェクトの原則を書くための雛形だった。

コンテナの--network noneは、コンテナ内のプロセスが外部へ通信することを防ぐ。マウントしたディレクトリの読み書きやホストのリソース消費までは防がないため、実行するディレクトリと--memory/--cpus/--pids-limitの指定は別途自分で管理する必要がある。

4. ネットワークが無い状態での挙動を見る

podman run --rm --network none --memory 2g --cpus 2 --pids-limit 512 \
  -v "$(pwd)":/work -w /work specify-sandbox \
  specify self check

結果は次の2行だった。

Installed: 0.12.15
Could not check latest release: offline or timeout

これはエラーではない。self checkは最新版の確認にGitHubへ問い合わせるが、届かなければこの1行を出して正常終了する。ネットワークの無い開発機や閉じたCI環境でspecifyを使うと同じ表示に当たるはずだが、対処は不要で、そのまま次の作業に進んでよい。

5. Codexエージェントに仕様を書かせる

ここまでは雛形の生成だけで、AIエージェントと組み合わせた本来のワークフローには踏み込んでいなかった。Spec KitはCodex CLIとの連携を公式にサポートしているので、実際にエージェントへ仕様を書かせてみる。

まず、Codex向けにスキルをインストールした状態で初期化する。

specify init --here --integration codex --integration-options="--skills"

.agents/skills/配下にスキル定義一式がインストールされる。Codex CLIからは$speckit-specifyのように$プレフィックスでスキルを呼び出す(Claude Codeの/speckit-specifyとは呼び出し記法が異なる)。

エージェントへの指示は次の1文だけ渡した。

codex exec --sandbox workspace-write --skip-git-repo-check \
  'Use the $speckit-specify skill to create a baseline specification for a small CLI tool: a text-reversal utility that reads stdin and writes the reversed string to stdout. Keep it simple.'

Codexは$speckit-specifyスキルの手順に従って質問への回答を組み立て、specs/001-reverse-text/spec.mdを生成した。中身の一部を引用する。

### User Story 1 - Reverse Piped Text (Priority: P1)

As a command-line user, I want to pipe text into the utility and receive
the same text in reverse order so that I can reverse a string in scripts
or interactive shell workflows.

**Acceptance Scenarios**:

1. **Given** standard input contains `stressed`, **When** the utility runs,
   **Then** standard output is exactly `desserts`.
2. **Given** standard input is empty, **When** the utility runs, **Then**
   standard output is empty and the run completes successfully.

## Requirements *(mandatory)*

### Functional Requirements

- **FR-001**: The utility MUST read the complete text value from standard input.
- **FR-004**: Successful output MUST contain no prompts, labels, diagnostics,
  or extra characters beyond the reversed input.
- **FR-008**: If input cannot be read or output cannot be written, the utility
  MUST indicate failure and MUST keep any diagnostic message separate from
  standard output.

ユーザーストーリー・受け入れ基準・エッジケース・機能要件・成功基準まで、コードを1行も書く前に埋まった。実装計画($speckit-plan)にも進めるが、そこから先は生成に時間がかかるため今回は割愛する。

この実行はPodmanの--network noneサンドボックスの外、ホスト側で行った。Codex自身がOpenAIの推論エンドポイントと通信する必要があるため、ネットワークを遮断したコンテナの中では動かせない。隔離の役目はコンテナからCodex自身のサンドボックス機構(--sandbox workspace-write、書き込みを実行ディレクトリ内に限定)へ移る。ツールが生成するスキルファイルはエージェントに読み込ませる前に中身を確認しておくとよい(第三者が書いた指示文だからだ)。

仕様を先に書く、という習慣

specify initを1回実行するだけで、仕様・計画・タスクの雛形と、それをAIエージェントに橋渡しするスキル一式が揃う。実際にCodexへ1文を渡しただけで、ユーザーストーリーから機能要件、成功基準までが文章として埋まった。実装から始めて後で仕様を追いかけるのではなく、仕様を先に確定させてから実装をエージェントに渡す順番に変わる。次にやることは、雛形の段階ですでに明確になっている。

出典

*1 Spec Kit (GitHub), https://github.com/github/spec-kit, MIT License