Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,5 @@ env/
# Spec Kit-specific files
.genreleases/
*.zip
sdd-*/
sdd-*/
settings.local.json
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ After running `specify init`, your AI coding agent will have access to these sla
| `/constitution` | Create or update project governing principles and development guidelines |
| `/specify` | Define what you want to build (requirements and user stories) |
| `/clarify` | Clarify underspecified areas (must be run before `/plan` unless explicitly skipped; formerly `/quizme`) |
| `/cross-feature` | Cross-feature alignment analysis using systems thinking (optional, run after `/specify`) |
| `/plan` | Create technical implementation plans with your chosen tech stack |
| `/tasks` | Generate actionable task lists for implementation |
| `/analyze` | Cross-artifact consistency & coverage analysis (run after /tasks, before /implement) |
Expand Down
121 changes: 121 additions & 0 deletions scripts/bash/cross-feature-check-all-features.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
#!/usr/bin/env bash
# Analyze current feature alignment with all existing features using systems thinking
set -e

JSON_MODE=false
ARGS=()
for arg in "$@"; do
case "$arg" in
--json) JSON_MODE=true ;;
--help|-h) echo "Usage: $0 [--json] [analysis_focus]"; exit 0 ;;
*) ARGS+=("$arg") ;;
esac
done

ANALYSIS_FOCUS="${ARGS[*]}"
if [ -z "$ANALYSIS_FOCUS" ]; then
ANALYSIS_FOCUS="Comprehensive Analysis"
fi

# Resolve repository root. Prefer git information when available, but fall back
# to the script location so the workflow still functions in repositories that
# were initialised with --no-git.
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
FALLBACK_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
if git rev-parse --show-toplevel >/dev/null 2>&1; then
REPO_ROOT=$(git rev-parse --show-toplevel)
HAS_GIT=true
else
REPO_ROOT="$FALLBACK_ROOT"
HAS_GIT=false
fi

cd "$REPO_ROOT"

# Get current branch name and find current spec
if [ "$HAS_GIT" = true ]; then
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
else
# If no git, try to determine current feature from specs directory
# This is a fallback - in practice, alignment analysis should run on active feature branch
CURRENT_BRANCH=$(ls -t specs/ | head -n 1 2>/dev/null || echo "")
fi

if [ -z "$CURRENT_BRANCH" ] || [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "master" ]; then
echo "Error: Alignment analysis must be run from a feature branch (created by /specify)" >&2
exit 1
fi

CURRENT_SPEC="$REPO_ROOT/specs/$CURRENT_BRANCH/spec.md"
if [ ! -f "$CURRENT_SPEC" ]; then
echo "Error: Current specification not found at $CURRENT_SPEC" >&2
exit 1
fi

# Find all existing specifications
ALL_SPECS=()
SPECS_DIR="$REPO_ROOT/specs"
if [ -d "$SPECS_DIR" ]; then
for dir in "$SPECS_DIR"/*; do
[ -d "$dir" ] || continue
spec_file="$dir/spec.md"
if [ -f "$spec_file" ] && [ "$spec_file" != "$CURRENT_SPEC" ]; then
ALL_SPECS+=("$spec_file")
fi
done
fi

# Create analysis file in current feature directory
FEATURE_DIR="$(dirname "$CURRENT_SPEC")"
ANALYSIS_FILE="$FEATURE_DIR/cross-feature-analysis.md"

# Create analysis file from template
TEMPLATE="$REPO_ROOT/templates/cross-feature-analysis-template.md"
if [ -f "$TEMPLATE" ]; then
cp "$TEMPLATE" "$ANALYSIS_FILE"
else
touch "$ANALYSIS_FILE"
fi

# Add clarification line to current spec.md for /clarify to pick up
CLARIFICATION_LINE="- [NEEDS CLARIFICATION: Review cross-feature alignment analysis in cross-feature-analysis.md - potential conflicts identified that may require spec adjustments]"

# Find the Requirements section and add the clarification line
if [ -f "$CURRENT_SPEC" ]; then
# Check if the clarification line already exists to avoid duplicates
if ! grep -q "cross-feature-analysis.md" "$CURRENT_SPEC"; then
# Find the line with "### Functional Requirements" and add our clarification after it
if grep -q "### Functional Requirements" "$CURRENT_SPEC"; then
# Use sed to add the line after "### Functional Requirements"
sed -i.bak "/### Functional Requirements/a\\
$CLARIFICATION_LINE" "$CURRENT_SPEC" && rm "$CURRENT_SPEC.bak"
else
# If no Functional Requirements section, add to end of file
echo "" >> "$CURRENT_SPEC"
echo "$CLARIFICATION_LINE" >> "$CURRENT_SPEC"
fi
fi
fi

# Build JSON output with all specs array
if $JSON_MODE; then
printf '{"CURRENT_SPEC":"%s","ALL_SPECS":[' "$CURRENT_SPEC"

# Add all specs as JSON array
first=true
for spec in "${ALL_SPECS[@]}"; do
if [ "$first" = true ]; then
first=false
else
printf ','
fi
printf '"%s"' "$spec"
done

printf '],"ANALYSIS_FILE":"%s","ANALYSIS_FOCUS":"%s"}\n' "$ANALYSIS_FILE" "$ANALYSIS_FOCUS"
else
echo "CURRENT_SPEC: $CURRENT_SPEC"
echo "ALL_SPECS: ${ALL_SPECS[*]}"
echo "ANALYSIS_FILE: $ANALYSIS_FILE"
echo "ANALYSIS_FOCUS: $ANALYSIS_FOCUS"
fi
124 changes: 124 additions & 0 deletions scripts/powershell/cross-feature-check-all-features.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# Analyze current feature alignment with all existing features using systems thinking
param(
[string]$Json = "",
[string[]]$Args = @()
)

$JsonMode = $Json -eq "{ARGS}" -or $Args -contains "--json"
$AnalysisFocus = ($Args | Where-Object { $_ -ne "--json" }) -join " "
if ([string]::IsNullOrWhiteSpace($AnalysisFocus)) {
$AnalysisFocus = "Comprehensive Analysis"
}

# Get repository root
$ScriptDir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$FallbackRoot = Resolve-Path (Join-Path $ScriptDir "../..")

try {
$RepoRoot = git rev-parse --show-toplevel 2>$null
$HasGit = $true
} catch {
$RepoRoot = $FallbackRoot
$HasGit = $false
}

Set-Location $RepoRoot

# Get current branch name and find current spec
if ($HasGit) {
try {
$CurrentBranch = git rev-parse --abbrev-ref HEAD 2>$null
} catch {
$CurrentBranch = ""
}
} else {
# If no git, try to determine current feature from specs directory
$SpecsDirs = Get-ChildItem -Path "specs" -Directory -ErrorAction SilentlyContinue | Sort-Object LastWriteTime -Descending
$CurrentBranch = if ($SpecsDirs) { $SpecsDirs[0].Name } else { "" }
}

if ([string]::IsNullOrWhiteSpace($CurrentBranch) -or $CurrentBranch -eq "main" -or $CurrentBranch -eq "master") {
Write-Error "Error: Alignment analysis must be run from a feature branch (created by /specify)"
exit 1
}

$CurrentSpec = Join-Path $RepoRoot "specs" $CurrentBranch "spec.md"
if (-not (Test-Path $CurrentSpec)) {
Write-Error "Error: Current specification not found at $CurrentSpec"
exit 1
}

# Find all existing specifications
$AllSpecs = @()
$SpecsDir = Join-Path $RepoRoot "specs"
if (Test-Path $SpecsDir) {
$SpecDirs = Get-ChildItem -Path $SpecsDir -Directory
foreach ($dir in $SpecDirs) {
$SpecFile = Join-Path $dir.FullName "spec.md"
if ((Test-Path $SpecFile) -and ($SpecFile -ne $CurrentSpec)) {
$AllSpecs += $SpecFile
}
}
}

# Create analysis file in current feature directory
$FeatureDir = Split-Path -Parent $CurrentSpec
$AnalysisFile = Join-Path $FeatureDir "cross-feature-analysis.md"

# Create analysis file from template
$Template = Join-Path $RepoRoot "templates" "cross-feature-analysis-template.md"
if (Test-Path $Template) {
Copy-Item $Template $AnalysisFile
} else {
New-Item -ItemType File -Path $AnalysisFile -Force | Out-Null
}

# Add clarification line to current spec.md for /clarify to pick up
$ClarificationLine = "- [NEEDS CLARIFICATION: Review cross-feature alignment analysis in cross-feature-analysis.md - potential conflicts identified that may require spec adjustments]"

# Find the Requirements section and add the clarification line
if (Test-Path $CurrentSpec) {
$SpecContent = Get-Content $CurrentSpec -Raw

# Check if the clarification line already exists to avoid duplicates
if (-not $SpecContent.Contains("cross-feature-analysis.md")) {
$Lines = Get-Content $CurrentSpec
$NewLines = @()
$Added = $false

foreach ($Line in $Lines) {
$NewLines += $Line
# Add clarification line after "### Functional Requirements"
if ($Line -match "^### Functional Requirements" -and -not $Added) {
$NewLines += $ClarificationLine
$Added = $true
}
}

# If no Functional Requirements section found, add to end
if (-not $Added) {
$NewLines += ""
$NewLines += $ClarificationLine
}

# Write back to file
$NewLines | Set-Content $CurrentSpec
}
}

# Build output
if ($JsonMode) {
$AllSpecsJson = $AllSpecs | ForEach-Object { "`"$_`"" } | Join-String -Separator ","
Copy link

Copilot AI Oct 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The variable $AllSpecsJson is created but never used in the JSON output. The actual JSON uses $AllSpecs directly, making this line redundant.

Suggested change
$AllSpecsJson = $AllSpecs | ForEach-Object { "`"$_`"" } | Join-String -Separator ","

Copilot uses AI. Check for mistakes.
$Output = @{
CURRENT_SPEC = $CurrentSpec
ALL_SPECS = $AllSpecs
ANALYSIS_FILE = $AnalysisFile
ANALYSIS_FOCUS = $AnalysisFocus
}
$Output | ConvertTo-Json -Compress
} else {
Write-Output "CURRENT_SPEC: $CurrentSpec"
Write-Output "ALL_SPECS: $($AllSpecs -join ' ')"
Write-Output "ANALYSIS_FILE: $AnalysisFile"
Write-Output "ANALYSIS_FOCUS: $AnalysisFocus"
}
48 changes: 48 additions & 0 deletions templates/commands/cross-feature.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
---
description: Analyze how the current feature aligns with existing features using systems thinking to identify conflicts, dependencies, and emergent behaviors.
scripts:
sh: scripts/bash/cross-feature-check-all-features.sh --json "{ARGS}"
ps: scripts/powershell/cross-feature-check-all-features.ps1 -Json "{ARGS}"
---

The text the user typed after `/cross-feature` in the triggering message **is** optional analysis focus. If empty, perform comprehensive alignment analysis. Assume you always have it available in this conversation even if `{ARGS}` appears literally below.

Given the current feature specification and optional analysis focus, do this:

1. Run the script `{SCRIPT}` from repo root and parse its JSON output for CURRENT_SPEC, ALL_SPECS, and ANALYSIS_FILE. All file paths must be absolute.
**IMPORTANT** You must only ever run this script once. The JSON is provided in the terminal as output - always refer to it to get the actual content you're looking for.

2. Load `templates/cross-feature-analysis-template.md` to understand the alignment analysis framework structure.

3. Read the current feature specification from CURRENT_SPEC to understand:
- Feature purpose and user scenarios
- Functional requirements
- Key entities and relationships

4. Analyze ALL_SPECS (array of paths to existing specifications) to identify ONLY actual issues:
- **Real conflicts**: Does this feature conflict with existing features? (shared resources, timing issues, contradictory behavior)
- **Dependencies**: Does this feature depend on or modify behavior from existing features?
- **Side effects**: Will this feature cause unexpected problems in other features?
- **Questions**: What needs clarification about cross-feature interactions?

5. Be concise and action-oriented:
- **Skip empty sections**: If there are no issues in a category, remove that section entirely
- **One-line summaries**: Issues, impacts, and fixes should each be one line
- **Questions not essays**: Raise specific questions, don't explain systems theory
- **Actionable only**: Only include information that requires a decision or action
- **Target length**: 50-100 lines total, not 500+ lines

6. Write the alignment analysis to ANALYSIS_FILE using the template structure, including ONLY:
- Impact summary (interactions, risk level, action needed)
- Specific questions that need answers (if any)
- Actual issues found with other features (if any)
- Concrete recommendations (if any)
- Remove any sections that don't apply

7. Add a single clarification line to the current spec.md file in the Requirements section:
- Add: `- [NEEDS CLARIFICATION: Review cross-feature alignment analysis in cross-feature-analysis.md - potential conflicts identified that may require spec adjustments]`
- This ensures `/clarify` will pick up alignment issues naturally

8. Report completion with analysis file path, key alignment insights discovered, and any clarification needs identified.

Note: This command should be run after `/specify` but before `/plan` to ensure systems thinking informs the technical implementation planning phase.
2 changes: 1 addition & 1 deletion templates/commands/specify.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ Given that feature description, do this:
**IMPORTANT** You must only ever run this script once. The JSON is provided in the terminal as output - always refer to it to get the actual content you're looking for.
2. Load `templates/spec-template.md` to understand required sections.
3. Write the specification to SPEC_FILE using the template structure, replacing placeholders with concrete details derived from the feature description (arguments) while preserving section order and headings.
4. Report completion with branch name, spec file path, and readiness for the next phase.
4. Report completion with branch name, spec file path, and suggest next steps: run `/clarify` to resolve ambiguities, `/cross-feature` to check cross-feature conflicts (optional), or `/plan` to proceed with implementation planning.

Note: The script creates and checks out the new branch and initializes the spec file before writing.
Loading