kramme-cc-workflow/skills/kramme:siw:reverse-engineer-spec/SKILL.md
Reverse engineer an SIW specification from existing code. Analyzes a git branch diff, folder, or file set to produce a structured spec compatible with the SIW workflow. Use when code exists without documentation, onboarding to unfamiliar code, or bootstrapping SIW from an existing implementation.
npx skillsauth add abildtoft/kramme-cc-workflow kramme:siw:reverse-engineer-specInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Analyze existing code to produce a structured SIW-compatible specification. Works backward from implementation to documentation, producing specs that plug directly into the SIW workflow (/kramme:siw:discovery, /kramme:siw:spec-audit, /kramme:siw:generate-phases, etc.).
This command ONLY generates a specification from existing code.
/kramme:siw:reverse-engineer-spec [branch | folder | file(s)] [--base main]
↓
[Phase 1: Resolve input & scope] -> branch diff / folder / files
↓
[Phase 2: Parallel deep exploration] -> 2-4 agents analyze file groups
↓
[Phase 3: Cross-check for gaps] -> catch missed files and details
↓
[Phase 4: Write SIW spec] -> structured spec + optional SIW scaffolding
↓
[Phase 5: Verify & report] -> completeness check + next steps
$ARGUMENTS contains any text the user provided after /kramme:siw:reverse-engineer-spec.
Parse $ARGUMENTS as shell-style arguments so quoted paths stay intact.
--base <branch> is present, set base_branch to the value and remove the flag pair from the argument list. Default: main.--model <model> is present, set agent_model to the value and remove the flag pair. Default: sonnet. Validate immediately: if the value is not one of opus, sonnet, or haiku, stop with: "Invalid model {value}. Valid options: opus, sonnet, haiku."Try each detection in order. Stop at the first match:
ls -d {path} succeeds) → Folder path (Case 2)git rev-parse --verify {arg} succeeds) → Branch diff mode with base_branch set to the argument (Case 1){argument} as file paths, a folder, or a branch name. Please check the input."If no file/folder arguments, analyze the current branch against base_branch.
Pre-validation (required before any git commands):
git rev-parse --is-inside-work-tree
base_branch exists: git rev-parse --verify $base_branch
git symbolic-ref refs/remotes/origin/HEAD 2>/dev/null | sed 's@^refs/remotes/origin/@@'{base_branch} not found. Using detected default branch {detected}."{base_branch} not found and could not auto-detect the default branch. Specify a base with --base <branch>."Analyze the diff:
git merge-base $base_branch HEAD
git diff --stat $(git merge-base $base_branch HEAD)...HEAD
git diff --stat $(git merge-base $base_branch HEAD)...HEAD | tail -1
git log --oneline $(git merge-base $base_branch HEAD)..HEAD
If merge-base fails (e.g., no common ancestor), stop: "Could not find a common ancestor between {base_branch} and HEAD. Specify a different base with --base <branch>."
If the diff is empty (no changes vs base), stop and inform the user.
If $ARGUMENTS is a directory:
# Scan for source files (exclude common generated/vendor directories)
find {folder} -maxdepth 4 -type f \
\( -name "*.ts" -o -name "*.tsx" -o -name "*.js" -o -name "*.jsx" \
-o -name "*.vue" -o -name "*.svelte" \
-o -name "*.py" -o -name "*.go" -o -name "*.rs" -o -name "*.cs" \
-o -name "*.java" -o -name "*.rb" -o -name "*.swift" -o -name "*.kt" \) \
! -path "*/node_modules/*" ! -path "*/dist/*" ! -path "*/build/*" \
! -path "*/.git/*" ! -path "*/vendor/*" ! -path "*/__pycache__/*" \
2> /dev/null
If zero files are found, stop: "No source files found in {folder}. Verify the path is correct and contains supported file types (.ts, .tsx, .js, .jsx, .vue, .svelte, .py, .go, .rs, .cs, .java, .rb, .swift, .kt)."
Using the shell-style parsed arguments from Section 1.1, verify each file exists. Skip non-existent files with a warning. If no files remain after filtering, stop: "None of the specified files exist. Verify the file paths and current directory."
From the file list, categorize into groups:
*.test.*, *.spec.*, *_test.*, test_*, tests/, __tests__/)Use AskUserQuestion:
header: "Reverse Engineer Scope"
question:
"I found {n} files to analyze. Here's the breakdown:\n\n- Core implementation: {n} files\n- Integration points: {n} files\n- Tests: {n} files\n- Configuration: {n} files\n- Incidental: {n} files\n\nShould I proceed with this scope?"
options:
- label: "Proceed"
description: "Analyze all {n} files"
- label: "Exclude incidental files"
description: "Skip formatting and minor changes ({n} files)"
- label: "Core + tests only"
description: "Focus on new code and test files ({n} files)"
After applying the scope filter, validate that the remaining file count is greater than zero. If zero files remain, stop: "No files remain after applying the scope filter. Consider a broader scope."
For each file group, launch an Explore agent using the Task tool (subagent_type=Explore, model={agent_model}).
All agents run in parallel — launch them in a single message with multiple Task tool calls.
| File Count | Agents | Grouping | | --- | --- | --- | | <15 files | 2 | A: Core + Integration; B: Tests + Config | | 15-40 files | 3 | A: Core implementation; B: Integration + Config; C: Tests | | 40+ files | 4 | A: Core implementation; B: Integration points; C: Tests; D: Config + Infrastructure |
Skip any agent whose file group is empty. Note the absence in the generated spec (e.g., "No test files were found in this changeset").
Read and follow references/agent-prompts.md for the focused analysis prompts for each agent role.
After all agents return, check each agent's output:
If an agent failed, returned empty output, or returned an error message instead of analysis, inform the user: "Agent {role} failed to complete its analysis. {n} files were not analyzed by a dedicated agent." Then use AskUserQuestion:
header: "Agent Failure"
question: "How should I proceed?"
options:
- label: "Continue with reduced analysis"
description: "Unanalyzed files will be read directly (shallower analysis)"
- label: "Abort"
description: "Cancel the reverse-engineering process"
If continuing with reduced analysis, note in the generated spec's Open Questions section that certain analysis areas may be incomplete.
After agents return and results are validated, verify completeness.
Compare the set of files analyzed by agents against the full file list from Phase 1. Identify any files that were not covered.
For uncovered files, read the diffs or file contents directly. These often contain important details:
Skip this section entirely if not in branch diff mode.
Use commit messages for additional "why" context:
git log --format="%s%n%b" $(git merge-base $base_branch HEAD)..HEAD
Extract:
If siw/ exists with spec files:
Use AskUserQuestion:
header: "Existing SIW Workflow Found"
question: "An SIW workflow already exists. How should I handle the reverse-engineered spec?"
options:
- label: "Create new spec file"
description: "Add a new spec alongside existing ones"
- label: "Replace existing spec"
description: "Overwrite the current spec with reverse-engineered content"
- label: "Abort"
description: "Cancel without writing"
If siw/ does not exist:
Use AskUserQuestion:
header: "SIW Scaffolding"
question: "No SIW workflow exists yet. Should I create the full SIW directory structure alongside the spec?"
options:
- label: "Full SIW setup"
description: "Create siw/ with spec, LOG.md, OPEN_ISSUES_OVERVIEW.md, and issues/ directory"
- label: "Spec only"
description: "Create just the spec file in siw/"
- label: "Abort"
description: "Cancel without writing"
Use the same heuristics as kramme:siw:init:
FEATURE_SPECIFICATION.mdAPI_DESIGN.mdDOCUMENTATION_SPEC.mdTUTORIAL_PLAN.mdSYSTEM_DESIGN.mdPROJECT_PLAN.mdBase detection on the synthesized problem statement and solution approach from Phase 2 agents.
Confirm with user:
header: "Specification Document"
question: "I'll create a specification document. Which name fits best?"
options:
- label: "{detected_name}"
description: "Recommended based on analysis"
- label: "FEATURE_SPECIFICATION.md"
description: "For feature implementations"
- label: "API_DESIGN.md"
description: "For API design work"
- label: "PROJECT_PLAN.md"
description: "For general projects"
- label: "Custom name"
description: "Enter your own filename"
If "Custom name" selected, use AskUserQuestion to get the filename. Validate: must be non-empty and end with .md (append if missing).
Read and follow references/spec-document-template.md for the siw/{spec_filename} structure.
Read and follow references/siw-scaffolding-templates.md if creating the full SIW directory structure.
Check that every file from Phase 1 appears in the spec's File Inventory (Section: New Files or Modified Files). If any are missing, add them to the appropriate table.
Check that every test file from Phase 1 is referenced in the Testing Strategy section.
Display:
Reverse-Engineered SIW Specification
─────────────────────────────────────
Source: {Branch `branch` vs `base` | Folder `path` | N files}
Files: {n} analyzed ({n} core, {n} integration, {n} tests, {n} config)
Commits: {n} (branch diff mode only)
Created:
siw/{spec_filename} - Reverse-engineered specification
{If full setup:}
siw/LOG.md - Progress and decisions (temporary)
siw/OPEN_ISSUES_OVERVIEW.md - Issue tracking (temporary)
siw/issues/ - Individual issue files (temporary)
Open Questions: {n} areas where code intent is unclear
Next Steps:
1. Review the spec for accuracy — reverse-engineering infers intent, verify it
2. Run /kramme:siw:discovery to fill open questions through interview
3. Run /kramme:siw:spec-audit to validate spec quality
4. Run /kramme:siw:generate-phases to create issues for remaining work
STOP HERE. Wait for the user's next instruction.
/kramme:siw:discovery is for.kramme:siw:init.tools
Requires Linear MCP. Implements one Linear issue end to end, selects applicable code-review, convention, and PR-refactor gates, runs them to bounded convergence, verifies, and optionally opens the PR and iterates on CI and review feedback until green. Use when the user wants a single Linear issue taken from implementation through a clean Pull Request. Not for implementation-only work, SIW-tracked issues, stacked PRs, existing PR updates, or post-merge rollout.
development
Reviews PR and local changes for convention drift and overcaution against documented rules and mined peer-file practice. Use for new patterns, dependencies, abstractions, or defensive complexity that departs from established practice; every finding cites evidence. Supports --inline. Not for general code quality (use kramme:pr:code-review) or spec review (use kramme:siw:spec-audit --team).
testing
Charts huge or foggy initiatives into a local `.context` decision map and resolves one typed frontier ticket per session until the work is ready for SIW or another execution workflow. Use when the route to a destination cannot fit in one agent session or parallel workspaces need coordinated planning state. Not for clear specs, ordinary issue decomposition, implementation, or Linear-native tracking.
development
Investigates a question against primary sources and saves one cited Markdown artifact. Use for reading legwork: official docs/API facts, source-code or spec checks, standards, and first-party service behavior before planning or implementation. Not for making product or architecture decisions, implementing code, broad web search, secondary blog summaries, or uncited answers.