Closing the intent-to-code chasm - specification-driven development with BDD verification chain
86
92%
Does it follow best practices?
Impact
86%
1.82xAverage score across 14 eval scenarios
Advisory
Suggest reviewing before use
#!/usr/bin/env bash
# Bugfix helper functions for the iikit-bugfix skill
# Provides: --list-features, --next-bug-id, --next-task-ids, --validate-feature
set -euo pipefail
SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/common.sh"
# =============================================================================
# SUBCOMMANDS
# =============================================================================
# List all features with stages as JSON array
# Reuses list_features_json() from common.sh
cmd_list_features() {
list_features_json
}
# Get the next sequential BUG-NNN ID for a feature
# Usage: cmd_next_bug_id <feature_dir>
cmd_next_bug_id() {
local feature_dir="$1"
local bugs_file="$feature_dir/bugs.md"
if [[ ! -f "$bugs_file" ]]; then
echo "BUG-001"
return 0
fi
local max_id=0
while IFS= read -r line; do
if [[ "$line" =~ ^##[[:space:]]+BUG-([0-9]+) ]]; then
local num="${BASH_REMATCH[1]}"
num=$((10#$num))
if [[ "$num" -gt "$max_id" ]]; then
max_id=$num
fi
fi
done < "$bugs_file"
local next=$((max_id + 1))
printf 'BUG-%03d\n' "$next"
}
# Get the next sequential T-BNNN task IDs for a feature
# Usage: cmd_next_task_ids <feature_dir> <count>
cmd_next_task_ids() {
local feature_dir="$1"
local count="${2:-3}"
local tasks_file="$feature_dir/tasks.md"
local max_id=0
if [[ -f "$tasks_file" ]]; then
while IFS= read -r line; do
if [[ "$line" =~ T-B([0-9]+) ]]; then
local num="${BASH_REMATCH[1]}"
num=$((10#$num))
if [[ "$num" -gt "$max_id" ]]; then
max_id=$num
fi
fi
done < "$tasks_file"
fi
local start=$((max_id + 1))
local ids=""
for ((i = 0; i < count; i++)); do
local id=$((start + i))
if [[ -n "$ids" ]]; then
ids="$ids,"
fi
ids="${ids}$(printf 'T-B%03d' "$id")"
done
printf '{"start":"T-B%03d","ids":[' "$start"
local first=true
for ((i = 0; i < count; i++)); do
local id=$((start + i))
if $first; then
first=false
else
printf ','
fi
printf '"T-B%03d"' "$id"
done
printf ']}\n'
}
# Validate that a feature directory exists and has spec.md
# Usage: cmd_validate_feature <feature_dir>
cmd_validate_feature() {
local feature_dir="$1"
if [[ ! -d "$feature_dir" ]]; then
printf '{"valid":false,"error":"Feature directory not found: %s"}\n' "$feature_dir"
return 1
fi
if [[ ! -f "$feature_dir/spec.md" ]]; then
printf '{"valid":false,"error":"spec.md not found in %s. Run /iikit-01-specify first."}\n' "$feature_dir"
return 1
fi
# Report available artifacts
local has_tasks="false"
local has_bugs="false"
local has_tests="false"
[[ -f "$feature_dir/tasks.md" ]] && has_tasks="true"
[[ -f "$feature_dir/bugs.md" ]] && has_bugs="true"
if [[ -d "$feature_dir/tests/features" ]]; then
local fcount
fcount=$(find "$feature_dir/tests/features" -maxdepth 1 -name "*.feature" -type f 2>/dev/null | wc -l | tr -d ' ')
[[ "$fcount" -gt 0 ]] && has_tests="true"
fi
printf '{"valid":true,"has_tasks":%s,"has_bugs":%s,"has_tests":%s}\n' \
"$has_tasks" "$has_bugs" "$has_tests"
return 0
}
# =============================================================================
# Full setup: list features, validate selected, get bug ID + task IDs in one call
# Usage: cmd_full_setup <feature_dir> [task_count]
cmd_full_setup() {
local feature_dir="$1"
local task_count="${2:-3}"
# List features
local features_json
features_json=$(list_features_json)
# Validate feature
local validate_json
validate_json=$(cmd_validate_feature "$feature_dir" 2>/dev/null)
local valid
valid=$(printf '%s' "$validate_json" | sed -n 's/.*"valid":\([a-z]*\).*/\1/p')
if [[ "$valid" != "true" ]]; then
printf '{"features":%s,"validation":%s}\n' "$features_json" "$validate_json"
return 1
fi
# Get bug ID and task IDs
local bug_id
bug_id=$(cmd_next_bug_id "$feature_dir")
local task_ids_json
task_ids_json=$(cmd_next_task_ids "$feature_dir" "$task_count")
# TDD determination
local tdd_det="optional"
local context_file
context_file=$(get_repo_root)/.specify/context.json
if [[ -f "$context_file" ]]; then
local det
det=$(sed -n 's/.*"tdd_determination"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' "$context_file")
[[ -n "$det" ]] && tdd_det="$det"
fi
printf '{"features":%s,"validation":%s,"bug_id":"%s","task_ids":%s,"tdd_determination":"%s"}\n' \
"$features_json" "$validate_json" "$bug_id" "$task_ids_json" "$tdd_det"
}
# =============================================================================
# MAIN DISPATCHER
# =============================================================================
if [[ $# -lt 1 ]]; then
echo "Usage: bugfix-helpers.sh <subcommand> [args...]" >&2
echo "Subcommands: --list-features, --next-bug-id, --next-task-ids, --validate-feature, --full-setup" >&2
exit 1
fi
case "$1" in
--list-features)
cmd_list_features
;;
--next-bug-id)
if [[ $# -lt 2 ]]; then
echo "Usage: bugfix-helpers.sh --next-bug-id <feature_dir>" >&2
exit 1
fi
cmd_next_bug_id "$2"
;;
--next-task-ids)
if [[ $# -lt 2 ]]; then
echo "Usage: bugfix-helpers.sh --next-task-ids <feature_dir> [count]" >&2
exit 1
fi
cmd_next_task_ids "$2" "${3:-3}"
;;
--validate-feature)
if [[ $# -lt 2 ]]; then
echo "Usage: bugfix-helpers.sh --validate-feature <feature_dir>" >&2
exit 1
fi
cmd_validate_feature "$2"
;;
--full-setup)
if [[ $# -lt 2 ]]; then
echo "Usage: bugfix-helpers.sh --full-setup <feature_dir> [task_count]" >&2
exit 1
fi
cmd_full_setup "$2" "${3:-3}"
;;
*)
echo "Unknown subcommand: $1" >&2
echo "Available: --list-features, --next-bug-id, --next-task-ids, --validate-feature, --full-setup" >&2
exit 1
;;
esacevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10
scenario-11
scenario-12
scenario-13
scenario-14
rules
skills
iikit-00-constitution
scripts
dashboard
iikit-01-specify
iikit-02-plan
iikit-03-checklist
scripts
bash
dashboard
iikit-04-testify
iikit-05-tasks
iikit-06-analyze
iikit-07-implement
iikit-08-taskstoissues
iikit-bugfix
scripts
dashboard
iikit-clarify
iikit-core
references
scripts
bash
dashboard
powershell
templates