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.development
One-way migration of a local SIW project into Linear. Creates one Linear project, migrates the main spec and supporting specs as Linear Documents, creates milestones from SIW phases and issues from SIW issues, then prompts to retire the local siw/ files via /kramme:siw:remove. Linear becomes the source of truth; this is not a two-way sync and keeps no rerun mapping, so re-running can duplicate issues. Use when moving a planned SIW initiative into Linear for good. Not for implementing issues, defining new SIW issues, or generating an issue breakdown.
development
Compare an existing PR's title and body against the actual branch diff and report drift — false claims, missing major changes, stale scope, missing risk callouts. Use after pushing changes to a branch with an open PR, or before requesting review. Read-only by default; add --fix to delegate to kramme:pr:generate-description for an updated description. Complements kramme:pr:code-review (which checks description accuracy as one signal among many code-quality checks) by being a fast, focused, single-purpose check that runs in seconds.
tools
Reviews plugin skills for focused scope, progressive disclosure, portability, safety, retry behavior, and documentation quality. Use when auditing a SKILL.md, skill directory, or proposed skill text against skill-authoring standards. Not for creating new skills, editing skills, or reviewing ordinary application code.
tools
Reviews recent agent session transcripts to find repeated manual workflows or repeated user asks, then proposes and optionally scaffolds only useful new skills or custom subagents. Use when the user asks to inspect recent sessions, find automation opportunities, or create reusable workflows from repeated work. Not for summarizing one session, general retrospectives, or codebase refactoring.