2026-05-02 02:18:19 +05:00
#!/usr/bin/env bash
set -e
# Parse command line arguments
JSON_MODE = false
for arg in " $@ " ; do
case " $arg " in
--json) JSON_MODE = true ;;
--help| -h)
echo "Usage: $0 [--json]"
echo " --json Output results in JSON format"
echo " --help Show this help message"
exit 0
;;
*) echo "ERROR: Unknown option ' $arg '" >& 2; exit 1 ;;
esac
done
# Source common functions
SCRIPT_DIR = " $( CDPATH = "" cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
source " $SCRIPT_DIR /common.sh"
# Get feature paths
_paths_output = $( get_feature_paths) || { echo "ERROR: Failed to resolve feature paths" >& 2; exit 1; }
eval " $_paths_output "
unset _paths_output
2026-06-09 06:13:07 -05:00
# Validate required files
2026-05-02 02:18:19 +05:00
if [[ ! -f " $IMPL_PLAN " ]] ; then
echo "ERROR: plan.md not found in $FEATURE_DIR " >& 2
2026-06-03 23:24:13 +02:00
echo "Run $( format_speckit_command plan " $REPO_ROOT " ) first to create the implementation plan." >& 2
2026-05-02 02:18:19 +05:00
exit 1
fi
if [[ ! -f " $FEATURE_SPEC " ]] ; then
echo "ERROR: spec.md not found in $FEATURE_DIR " >& 2
2026-06-03 23:24:13 +02:00
echo "Run $( format_speckit_command specify " $REPO_ROOT " ) first to create the feature structure." >& 2
2026-05-02 02:18:19 +05:00
exit 1
fi
# Build available docs list
docs =()
[[ -f " $RESEARCH " ]] && docs +=( "research.md" )
[[ -f " $DATA_MODEL " ]] && docs +=( "data-model.md" )
if [[ -d " $CONTRACTS_DIR " ]] && [[ -n " $( ls -A " $CONTRACTS_DIR " 2>/dev/null) " ]] ; then
docs +=( "contracts/" )
fi
[[ -f " $QUICKSTART " ]] && docs +=( "quickstart.md" )
# Resolve tasks template through override stack
TASKS_TEMPLATE = $( resolve_template "tasks-template" " $REPO_ROOT " ) || true
2026-08-10 10:22:31 -05:00
if TASKS_TEMPLATE_CONTENT = $( resolve_template_content "tasks-template" " $REPO_ROOT " ; status = $? ; printf x; exit " $status " ) ; then
TASKS_TEMPLATE_CONTENT = " ${ TASKS_TEMPLATE_CONTENT %x } "
else
2026-05-02 02:18:19 +05:00
echo "ERROR: Could not resolve required tasks-template from the template override stack for $REPO_ROOT " >& 2
echo "Template 'tasks-template' was not found in any supported location (overrides, presets, extensions, or shared core). Add an override at .specify/templates/overrides/tasks-template.md, or run 'specify init' / reinstall shared infra to restore the core .specify/templates/tasks-template.md template." >& 2
exit 1
fi
# Output results
if $JSON_MODE ; then
if has_jq; then
if [[ ${# docs [@] } -eq 0 ]] ; then
json_docs = "[]"
else
json_docs = $( printf '%s\n' " ${ docs [@] } " | jq -R . | jq -s .)
fi
jq -cn \
--arg feature_dir " $FEATURE_DIR " \
--argjson docs " $json_docs " \
--arg tasks_template " ${ TASKS_TEMPLATE :- } " \
2026-08-10 10:22:31 -05:00
--arg tasks_template_content " $TASKS_TEMPLATE_CONTENT " \
'{FEATURE_DIR:$feature_dir,AVAILABLE_DOCS:$docs,TASKS_TEMPLATE:$tasks_template,TASKS_TEMPLATE_CONTENT:$tasks_template_content}'
2026-05-02 02:18:19 +05:00
else
if [[ ${# docs [@] } -eq 0 ]] ; then
json_docs = "[]"
else
json_docs = $(for d in " ${ docs [@] } " ; do printf '"%s",' " $( json_escape " $d " ) " ; done)
json_docs = "[ ${ json_docs %, } ]"
fi
2026-08-10 10:22:31 -05:00
printf '{"FEATURE_DIR":"%s","AVAILABLE_DOCS":%s,"TASKS_TEMPLATE":"%s","TASKS_TEMPLATE_CONTENT":"%s"}\n' \
" $( json_escape " $FEATURE_DIR " ) " " $json_docs " " $( json_escape " ${ TASKS_TEMPLATE :- } " ) " " $( json_escape " $TASKS_TEMPLATE_CONTENT " ) "
2026-05-02 02:18:19 +05:00
fi
else
echo "FEATURE_DIR: $FEATURE_DIR "
echo "TASKS_TEMPLATE: ${ TASKS_TEMPLATE :- not found } "
echo "AVAILABLE_DOCS:"
check_file " $RESEARCH " "research.md"
check_file " $DATA_MODEL " "data-model.md"
check_dir " $CONTRACTS_DIR " "contracts/"
check_file " $QUICKSTART " "quickstart.md"
fi