with one click
openlore-generate
// Reverse-engineer OpenSpec specifications from an existing codebase. Performs "code archaeology" — extracting what code actually does and documenting it as structured OpenSpec specs across all detected domains.
// Reverse-engineer OpenSpec specifications from an existing codebase. Performs "code archaeology" — extracting what code actually does and documenting it as structured OpenSpec specs across all detected domains.
Persistent architectural memory for this codebase. Call `orient(task)` before reading source files to get the relevant functions, callers, spec sections, and insertion points for any task — saving 15,000–50,000 tokens of file-by-file rediscovery.
Run a full static analysis of a project using openlore and summarise the results — architecture, call graph, top refactoring issues, and duplicate code. No LLM required.
Transform a feature idea into an annotated story. Detects greenfield vs brownfield automatically — uses Domain Sketch for greenfield (no existing code), Constrained Option Tree for brownfield (existing codebase with openlore analysis).
Debug a problem by anchoring root-cause analysis in openlore structural knowledge. Uses orient + search_specs + analyze_impact to form an explicit hypothesis before reading code. Enforces RED/GREEN test verification.
Apply the refactoring plan produced by openlore-plan-refactor. Reads .openlore/refactor-plan.md and re-reads it before each change to stay on track. Requires a confirmed plan to exist before running.
Implement a story on a brownfield codebase using openlore structural context. Runs orient + risk check before coding, validates against specs, enforces a test gate before drift check.
| name | openlore-generate |
| description | Reverse-engineer OpenSpec specifications from an existing codebase. Performs "code archaeology" — extracting what code actually does and documenting it as structured OpenSpec specs across all detected domains. |
| license | MIT |
| version | 1.0.0 |
| author | Clay Good |
| repository | https://github.com/clay-good/openlore |
| compatibility | openlore MCP server |
| user-invocable | true |
| allowed-tools | ["read_file","write_file","list_directory","run_command","use_mcp_tool","openlore-analyze-codebase","openlore-plan-refactor"] |
Trigger this skill when the user asks to generate specs from an existing codebase, with phrasings like:
/openlore-generateUnderstand the project structure before touching any files.
1. Identify project type by checking for:
| File | Stack |
|---|---|
package.json | Node.js / TypeScript |
pyproject.toml / setup.py | Python |
go.mod | Go |
Cargo.toml | Rust |
pom.xml / build.gradle | Java |
2. Find high-value files — prioritize:
3. Identify domains by looking for:
src/users/, src/orders/, etc.)user-service, order-controller)4. Detect frameworks from dependencies and patterns:
For each identified domain, analyze the relevant files.
Extract entities:
Extract behaviors:
Extract API surface (if applicable):
Create the OpenSpec directory structure if it doesn't exist:
openspec/
├── config.yaml
└── specs/
├── overview/
│ └── spec.md
├── {domain-1}/
│ └── spec.md
├── {domain-2}/
│ └── spec.md
└── architecture/
└── spec.md
Each spec.md MUST follow this exact format:
# {Domain} Specification
> Generated by openlore on {date}
> Source files: {list of files analyzed}
## Purpose
{2-3 sentences describing what this domain handles}
## Requirements
### Requirement: {RequirementName}
{The system SHALL/MUST/SHOULD do X...}
Use RFC 2119 keywords:
- **SHALL/MUST**: Required behavior
- **SHOULD**: Recommended behavior
- **MAY**: Optional behavior
#### Scenario: {ScenarioName}
- **GIVEN** {precondition}
- **WHEN** {action}
- **THEN** {expected outcome}
## Technical Notes
- **Implementation**: `{file paths}`
- **Dependencies**: {related domains/services}
####)If openspec/config.yaml exists, preserve all existing content and append:
# Auto-detected by openlore
openlore:
generatedAt: "{timestamp}"
domains:
- {domain-1}
- {domain-2}
If it doesn't exist, create a minimal config:
schema: spec-driven
context: |
{Brief project description based on analysis}
Tech stack: {detected technologies}
Architecture: {detected pattern}
When specs already exist and code has changed, check for spec drift — divergence between the codebase and its specifications.
When to check: before committing code, when reviewing PRs, or when explicitly asked to validate specs.
Process:
Identify what changed — use git to find added, modified, deleted, or renamed source files compared to the base branch. Filter out: test files, generated files, lock files, static assets, CI configs.
Map changes to specs — for each changed file, determine which spec domain covers it by checking:
> Source files: header in each spec.md**Implementation**: references in Technical Notessrc/auth/ → auth domain)Detect four categories of drift:
| Category | Meaning |
|---|---|
| Gap | Code changed but its spec was not updated |
| Stale | Spec references a deleted or renamed file |
| Uncovered | New source file has no matching spec domain |
| Orphaned Spec | Spec declares source files that no longer exist |
CLI shorthand: openlore drift runs this check. Use openlore drift --install-hook to add it as a git pre-commit hook.
Before finishing, verify every item:
openspec/specs/overview/spec.md exists with system summaryopenspec/specs/{domain}/spec.mdopenspec/specs/architecture/spec.md describes system structureopenspec/config.yaml is created or updatedopenlore drift to verify specs match codeopenspec/config.yaml content before appendingReport what was created, then suggest:
openspec validate --all — check spec structureopenlore drift --install-hook — catch future drift automaticallyopenspec list --specs — see all generated specs/openlore-plan-refactor to identify refactoring targets now that specs exist