sdd-generate
Generate an OpenSDD behavioral spec from existing code. Use when the user asks to generate, create, or extract a spec from a repository or codebase.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Generate an OpenSDD behavioral spec from existing code. Use when the user asks to generate, create, or extract a spec from a repository or codebase.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | sdd-generate |
| description | Generate an OpenSDD behavioral spec from existing code. Use when the user asks to generate, create, or extract a spec from a repository or codebase. |
Guides an AI agent through analyzing a repository and generating a behavioral spec in the OpenSDD format.
Handles large repos via a multi-pass, artifact-driven strategy that survives context window clears. This document defines the workflow that the sdd-generate skill teaches agents to follow. The skill is installed into each supported coding agent's configuration directory via opensdd init.
Before starting, you need:
opensdd.json, use the directory specified by specsDir (default: opensdd/). If the project is not yet initialized, ask the user where to output the spec — a common default is opensdd/ in the current project root. The agent does not need opensdd.json to exist before generating a spec.A spec written to the working directory:
opensdd/
spec.md # Behavioral contract
The spec author MAY include additional files in the output directory (e.g., supplementary schema definitions in a references/ subdirectory). The protocol does not mandate any particular structure beyond spec.md — organization of supplementary files is at the author's discretion. If you create supplementary files, use relative markdown hyperlinks from spec.md to reference them so the spec is self-navigating — an agent starts at spec.md and follows links to discover everything it needs.
If opensdd.json exists, add or update the publish object:
{
"publish": {
"name": "{name}",
"version": "{semver}",
"description": "{one-line description}",
"specFormat": "0.1.0",
"dependencies": []
}
}
Large repositories exceed a single context window. The strategy is to write to disk as you go — not at the end. Each pass reads from the repo and writes to the output spec directory or to scratch notes. If context clears, read your own artifacts to resume.
Maintain a _notes/ scratch directory alongside the output spec in your working directory during generation:
{working-directory}/
_notes/
scope.md # What we're spec'ing, which files matter
inventory.md # Public API surface, function signatures, types
examples.md # Extracted inline examples from tests
gaps.md # Behaviors not yet covered, open questions
spec.md # Built up incrementally
_notes/ is your working memory across context clears. Delete it before finalizing.
If you are resuming after a context clear:
_notes/scope.md to understand what you're spec'ing and where you are._notes/gaps.md to see what remains.spec.md draft to see what's been written.Always update _notes/gaps.md at the end of each pass with what still needs to be done, so a fresh context can pick up cleanly.
Goal: Understand what the repo does and map the territory for the scoped capability.
Read (in this order):
Write:
_notes/scope.md — what the repo is, what capability we're spec'ing, which directories/files are relevant to that capability, which are not. Include the spec name, version (use the repo's version or 0.1.0), and description for later use in the opensdd.json publish object.opensdd/spec.md — Header (H1 + blockquote) and ## Overview onlyDo NOT read source code or tests yet. The goal is orientation, not comprehension.
Goal: Identify the public API — what the outside world interacts with.
Read (in this order):
Write:
_notes/inventory.md — complete list of public API surface: every exported function, class, type, constant. Include signatures. This is your checklist — every item here must appear in the spec's behavioral contract.spec.md — add ## Behavioral Contract skeleton with H3 subsection headers for each logical grouping of API surface. No behavioral descriptions yet, just the structure.references/ subdirectory).Goal: Extract concrete behaviors from tests. Tests are the richest source of behavioral truth — they show what the code actually does with real inputs and outputs.
Read:
Write:
_notes/examples.md — every concrete input/output pair and scenario extracted from tests, grouped by the behavioral subsection it belongs tospec.md — fill in Behavioral Contract subsections with:
## Edge Cases section with concrete examples from edge case tests_notes/gaps.md — which inventory items have no test coverage, which behavioral subsections still need examplesGuidance on extracting behavior from tests:
expect(slugify("Hello World")).toBe("hello-world") becomes the inline example slugify("Hello World") MUST return "hello-world"Goal: Cover behaviors not captured by tests. Read source code only now, and only for gaps.
Read:
_notes/gaps.mdWrite:
spec.md — fill remaining Behavioral Contract gaps, add any discovered edge cases, add ## Options / Configuration if the capability has configurable parameters_notes/gaps.md — update with any remaining unknownsGuidance on separating what from how:
str.toLowerCase().replace(/[^a-z0-9]+/g, '-').replace(/(^-|-$)/g, '') — spec says "converts to lowercase, replaces non-alphanumeric characters with hyphens, strips leading/trailing hyphens"Goal: Fill in recommended sections, self-validate, finalize.
Read:
spec.md draft_notes/inventory.md — verify every public API item is covered_notes/gaps.md — verify no critical gaps remainWrite:
spec.md — add or complete:
## NOT Specified (Implementation Freedom) — list implementation choices observed in the source that the spec intentionally leaves open (data structures, algorithms, caching, internal architecture)## Invariants — universal properties extracted from property tests, type constraints, or behavioral patterns (e.g., idempotency, commutativity, output format guarantees)## Implementation Hints (optional) — guidance on performance, concurrency, or common pitfalls observed in the source, only if genuinely useful. If the spec targets a specific platform, hints MAY be platform-specific; otherwise they SHOULD be language-agnostic.opensdd.json exists, add or update the publish object with name, version, description, specFormat, and dependencies from _notes/scope.md.Validate the output:
## Behavioral ContractClean up:
_notes/ directory entirelyspec.mdIf the scoped capability has natural subcomponents (e.g., multiple provider integrations, platform adapters), consider organizing the spec with supplementary files for each component. For example:
opensdd/
spec.md # Shared behavioral contract
components/
{component-a}.md # Component-specific contract
{component-b}.md
This is an organizational pattern, not a protocol requirement — the protocol only mandates spec.md. Choose whatever file organization makes the spec easiest to read and maintain. spec.md MUST link to all component files using relative markdown hyperlinks so the spec is self-navigating.
Run passes 2-4 for the shared contract first, then for each component. The shared spec.md should capture behavior common to all components. Component-level files capture only what differs.
Update _notes/scope.md to track which components have been completed so context clears don't cause rework.
For repos where even a single pass exceeds context:
_notes/examples.md after each. The notes file accumulates across sub-passes._notes/gaps.md as a work queue. Write remaining file paths to process. Pick up the next unprocessed file after each context clear.opensdd publish to validate and publish)