16cfab7724
* feat(presets): resolve constitutions at command time Gate install-time constitution materialization behind the constitution-sync preset while preserving one-time init seeding and authored-file safeguards. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7dbce70f-80c6-4e14-a30d-78cb358bcb84 * fix(presets): emit composed template content Add a machine-readable preset resolve mode backed by PresetResolver.resolve_content and require the constitution command to consume it. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7dbce70f-80c6-4e14-a30d-78cb358bcb84 * fix(presets): unify runtime template composition Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7dbce70f-80c6-4e14-a30d-78cb358bcb84 * fix(presets): secure runtime template resolution Align runtime resolution across script variants, validate registry path components, and honor canonical extension ordering and convention paths. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * fix(presets): align runtime priority semantics Normalize and tie-break preset priorities consistently across script variants, and preserve template bytes when Python materializes generated files. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * fix(presets): stop at effective template base Avoid parsing irrelevant lower layers once resolution reaches a replace base, and decode raw bytes so Python preserves source line endings. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * fix(presets): align extension template resolution Support root-level extension templates across runtime resolvers, fail safely when Bash cannot parse an extension registry, and validate requested templates in every prerequisite output mode. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * fix(presets): resolve dotted command identifiers Route safe dotted names through command resolution, correct traversal coverage, and make Windows CI text decoding explicit. Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Avoid orphan feature directories on template errors Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> * Align malformed preset manifest handling Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * Complete runtime resolver parity Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * Fail closed on resolver input errors Assisted-by: GitHub Copilot (model: GPT-5.6 Sol, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * Force UTF-8 and full manifest validation Force UTF-8 decoding for registry and manifest reads in the Bash and PowerShell embedded-Python parsers so resolution no longer depends on the process locale, and validate every manifest template entry's required fields, type, and strategy consistent with the canonical PresetManifest. Assisted-by: GitHub Copilot (model: claude-opus-4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * Fail closed on empty manifests and corrupt registries Reject manifests missing the provides/templates sections or declaring an empty template list in all three runtime resolvers, matching the canonical PresetManifest which treats those as invalid instead of silently degrading a composing layer to a convention `replace` lookup. Make a corrupt or unreadable extension registry fail closed in Bash, PowerShell, and Python instead of swallowing the error and treating every on-disk extension directory as unregistered-and-enabled, which could activate a disabled extension. Read the preset and extension registries as explicit UTF-8 in the PowerShell resolver so priority/enabled-state decoding no longer depends on the process code page under Windows PowerShell 5.1. Assisted-by: GitHub Copilot (model: claude-opus-4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * fix(presets): fail closed when extension registry is not a regular file The Bash and Python resolvers used is_file()/`-f` to gate reading the extension `.registry`, which returns false for a directory or a broken symlink at that path. In those cases the resolvers treated the registry as absent and scanned every on-disk extension directory as unregistered and enabled — a fail-open path. Detect any filesystem entry at the registry path (including broken symlinks) and reject unless it is a readable regular file. PowerShell now rejects a non-leaf entry explicitly for parity. Adds directory- and broken-symlink parity regressions. Assisted-by: GitHub Copilot (model: claude-opus-4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * fix(presets): fail closed on corrupt registry in canonical resolver and PowerShell Two remaining fail-open paths for an invalid extension registry: - The canonical PresetResolver enumerated extensions through ExtensionRegistry, whose _load() normalizes a corrupt or unreadable registry to an empty mapping. The directory scan then admitted every on-disk extension directory as unregistered-and-enabled, so a corrupt registry could still supply constitution content at init and through constitution-sync materialization. Add a non-invasive is_corrupt() probe (recovery behavior for install/enable/disable is unchanged) and raise from _get_all_extensions_by_priority() when the registry exists but is invalid. _load() now also recovers from OSError/UnicodeDecodeError so a directory or unreadable registry no longer crashes construction. - The PowerShell resolver gated the registry read with Test-Path, which returns false for a dangling symlink on Windows, letting a broken .registry symlink bypass the guard and enable every on-disk extension. Detect the entry via directory enumeration (which observes a broken symlink) and reject it unless it is a readable regular file. Adds canonical corrupt/directory-registry regressions and extends the broken-symlink parity test to PowerShell. Assisted-by: GitHub Copilot (model: claude-opus-4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c * fix(presets): detect dangling registry symlink in ExtensionRegistry.is_corrupt is_corrupt() gated on Path.exists(), which follows symlinks and returns False for a dangling .registry symlink — so the canonical PresetResolver treated it as an absent registry and fell back to scanning every on-disk extension directory as unregistered-and-enabled, reopening the fail-open path this guard closes. Detect lexical existence with os.path.lexists and require a regular file before parsing, so a broken symlink (or directory) is reported corrupt and resolution fails closed. Adds a canonical broken-symlink regression alongside the directory case. Assisted-by: GitHub Copilot (model: claude-opus-4.8, autonomous) Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c --------- Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 7dbce70f-80c6-4e14-a30d-78cb358bcb84 Copilot-Session: 3158e06f-95df-4e3a-843f-f159a35aa30c
231 lines
7.6 KiB
Bash
231 lines
7.6 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
# Consolidated prerequisite checking script
|
|
#
|
|
# This script provides unified prerequisite checking for Spec-Driven Development workflow.
|
|
# It replaces the functionality previously spread across multiple scripts.
|
|
#
|
|
# Usage: ./check-prerequisites.sh [OPTIONS]
|
|
#
|
|
# OPTIONS:
|
|
# --json Output in JSON format
|
|
# --require-tasks Require tasks.md to exist (for implementation phase)
|
|
# --include-tasks Include tasks.md in AVAILABLE_DOCS list
|
|
# --paths-only Only output path variables (no validation)
|
|
# --template NAME Include composed template content in JSON output
|
|
# --help, -h Show help message
|
|
#
|
|
# OUTPUTS:
|
|
# JSON mode: {"FEATURE_DIR":"...", "AVAILABLE_DOCS":["..."]}
|
|
# Text mode: FEATURE_DIR:... \n AVAILABLE_DOCS: \n ✓/✗ file.md
|
|
# Paths only: REPO_ROOT: ... \n BRANCH: ... \n FEATURE_DIR: ... etc.
|
|
|
|
set -e
|
|
|
|
# Parse command line arguments
|
|
JSON_MODE=false
|
|
REQUIRE_TASKS=false
|
|
INCLUDE_TASKS=false
|
|
PATHS_ONLY=false
|
|
TEMPLATE_NAME=""
|
|
|
|
while [[ $# -gt 0 ]]; do
|
|
case "$1" in
|
|
--json)
|
|
JSON_MODE=true
|
|
;;
|
|
--require-tasks)
|
|
REQUIRE_TASKS=true
|
|
;;
|
|
--include-tasks)
|
|
INCLUDE_TASKS=true
|
|
;;
|
|
--paths-only)
|
|
PATHS_ONLY=true
|
|
;;
|
|
--template)
|
|
shift
|
|
if [[ $# -eq 0 ]]; then
|
|
echo "ERROR: --template requires a template name" >&2
|
|
exit 1
|
|
fi
|
|
TEMPLATE_NAME="$1"
|
|
;;
|
|
--help|-h)
|
|
cat << 'EOF'
|
|
Usage: check-prerequisites.sh [OPTIONS]
|
|
|
|
Consolidated prerequisite checking for Spec-Driven Development workflow.
|
|
|
|
OPTIONS:
|
|
--json Output in JSON format
|
|
--require-tasks Require tasks.md to exist (for implementation phase)
|
|
--include-tasks Include tasks.md in AVAILABLE_DOCS list
|
|
--paths-only Only output path variables (no prerequisite validation)
|
|
--template NAME Include composed template content in JSON output
|
|
--help, -h Show this help message
|
|
|
|
EXAMPLES:
|
|
# Check task prerequisites (plan.md required)
|
|
./check-prerequisites.sh --json
|
|
|
|
# Check implementation prerequisites (plan.md + tasks.md required)
|
|
./check-prerequisites.sh --json --require-tasks --include-tasks
|
|
|
|
# Get feature paths only (no validation)
|
|
./check-prerequisites.sh --paths-only
|
|
|
|
EOF
|
|
exit 0
|
|
;;
|
|
*)
|
|
echo "ERROR: Unknown option '$1'. Use --help for usage information." >&2
|
|
exit 1
|
|
;;
|
|
esac
|
|
shift
|
|
done
|
|
|
|
# Source common functions
|
|
SCRIPT_DIR="$(CDPATH="" cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
source "$SCRIPT_DIR/common.sh"
|
|
|
|
# Get feature paths.
|
|
# In --paths-only mode this is pure resolution, so pass --no-persist to opt out
|
|
# of the feature.json write side effect (issue #3025).
|
|
if $PATHS_ONLY; then
|
|
_paths_output=$(get_feature_paths --no-persist) || { echo "ERROR: Failed to resolve feature paths" >&2; exit 1; }
|
|
else
|
|
_paths_output=$(get_feature_paths) || { echo "ERROR: Failed to resolve feature paths" >&2; exit 1; }
|
|
fi
|
|
eval "$_paths_output"
|
|
unset _paths_output
|
|
|
|
# If paths-only mode, output paths and exit (no validation)
|
|
if $PATHS_ONLY; then
|
|
if $JSON_MODE; then
|
|
# Minimal JSON paths payload (no validation performed)
|
|
if has_jq; then
|
|
jq -cn \
|
|
--arg repo_root "$REPO_ROOT" \
|
|
--arg branch "$CURRENT_BRANCH" \
|
|
--arg feature_dir "$FEATURE_DIR" \
|
|
--arg feature_spec "$FEATURE_SPEC" \
|
|
--arg impl_plan "$IMPL_PLAN" \
|
|
--arg tasks "$TASKS" \
|
|
'{REPO_ROOT:$repo_root,BRANCH:$branch,FEATURE_DIR:$feature_dir,FEATURE_SPEC:$feature_spec,IMPL_PLAN:$impl_plan,TASKS:$tasks}'
|
|
else
|
|
printf '{"REPO_ROOT":"%s","BRANCH":"%s","FEATURE_DIR":"%s","FEATURE_SPEC":"%s","IMPL_PLAN":"%s","TASKS":"%s"}\n' \
|
|
"$(json_escape "$REPO_ROOT")" "$(json_escape "$CURRENT_BRANCH")" "$(json_escape "$FEATURE_DIR")" "$(json_escape "$FEATURE_SPEC")" "$(json_escape "$IMPL_PLAN")" "$(json_escape "$TASKS")"
|
|
fi
|
|
else
|
|
echo "REPO_ROOT: $REPO_ROOT"
|
|
echo "BRANCH: $CURRENT_BRANCH"
|
|
echo "FEATURE_DIR: $FEATURE_DIR"
|
|
echo "FEATURE_SPEC: $FEATURE_SPEC"
|
|
echo "IMPL_PLAN: $IMPL_PLAN"
|
|
echo "TASKS: $TASKS"
|
|
fi
|
|
exit 0
|
|
fi
|
|
|
|
# Validate required directories and files
|
|
if [[ ! -d "$FEATURE_DIR" ]]; then
|
|
echo "ERROR: Feature directory not found: $FEATURE_DIR" >&2
|
|
echo "Run $(format_speckit_command specify "$REPO_ROOT") first to create the feature structure." >&2
|
|
exit 1
|
|
fi
|
|
|
|
if [[ ! -f "$IMPL_PLAN" ]]; then
|
|
echo "ERROR: plan.md not found in $FEATURE_DIR" >&2
|
|
echo "Run $(format_speckit_command plan "$REPO_ROOT") first to create the implementation plan." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Check for tasks.md if required
|
|
if $REQUIRE_TASKS && [[ ! -f "$TASKS" ]]; then
|
|
echo "ERROR: tasks.md not found in $FEATURE_DIR" >&2
|
|
echo "Run $(format_speckit_command tasks "$REPO_ROOT") first to create the task list." >&2
|
|
exit 1
|
|
fi
|
|
|
|
# Build list of available documents
|
|
docs=()
|
|
|
|
# Always check these optional docs
|
|
[[ -f "$RESEARCH" ]] && docs+=("research.md")
|
|
[[ -f "$DATA_MODEL" ]] && docs+=("data-model.md")
|
|
|
|
# Check contracts directory (only if it exists and has files)
|
|
if [[ -d "$CONTRACTS_DIR" ]] && [[ -n "$(ls -A "$CONTRACTS_DIR" 2>/dev/null)" ]]; then
|
|
docs+=("contracts/")
|
|
fi
|
|
|
|
[[ -f "$QUICKSTART" ]] && docs+=("quickstart.md")
|
|
|
|
# Include tasks.md if requested and it exists
|
|
if $INCLUDE_TASKS && [[ -f "$TASKS" ]]; then
|
|
docs+=("tasks.md")
|
|
fi
|
|
|
|
TEMPLATE_CONTENT=""
|
|
if [[ -n "$TEMPLATE_NAME" ]]; then
|
|
if TEMPLATE_CONTENT=$(resolve_template_content "$TEMPLATE_NAME" "$REPO_ROOT"; status=$?; printf x; exit "$status"); then
|
|
TEMPLATE_CONTENT="${TEMPLATE_CONTENT%x}"
|
|
else
|
|
echo "ERROR: Could not resolve required $TEMPLATE_NAME from the template override stack for $REPO_ROOT" >&2
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
# Output results
|
|
if $JSON_MODE; then
|
|
# Build JSON array of documents
|
|
if has_jq; then
|
|
if [[ ${#docs[@]} -eq 0 ]]; then
|
|
json_docs="[]"
|
|
else
|
|
json_docs=$(printf '%s\n' "${docs[@]}" | jq -R . | jq -s .)
|
|
fi
|
|
if [[ -n "$TEMPLATE_NAME" ]]; then
|
|
jq -cn \
|
|
--arg feature_dir "$FEATURE_DIR" \
|
|
--argjson docs "$json_docs" \
|
|
--arg template_content "$TEMPLATE_CONTENT" \
|
|
'{FEATURE_DIR:$feature_dir,AVAILABLE_DOCS:$docs,TEMPLATE_CONTENT:$template_content}'
|
|
else
|
|
jq -cn \
|
|
--arg feature_dir "$FEATURE_DIR" \
|
|
--argjson docs "$json_docs" \
|
|
'{FEATURE_DIR:$feature_dir,AVAILABLE_DOCS:$docs}'
|
|
fi
|
|
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
|
|
if [[ -n "$TEMPLATE_NAME" ]]; then
|
|
printf '{"FEATURE_DIR":"%s","AVAILABLE_DOCS":%s,"TEMPLATE_CONTENT":"%s"}\n' \
|
|
"$(json_escape "$FEATURE_DIR")" "$json_docs" "$(json_escape "$TEMPLATE_CONTENT")"
|
|
else
|
|
printf '{"FEATURE_DIR":"%s","AVAILABLE_DOCS":%s}\n' "$(json_escape "$FEATURE_DIR")" "$json_docs"
|
|
fi
|
|
fi
|
|
else
|
|
# Text output
|
|
echo "FEATURE_DIR:$FEATURE_DIR"
|
|
echo "AVAILABLE_DOCS:"
|
|
|
|
# Show status of each potential document
|
|
check_file "$RESEARCH" "research.md"
|
|
check_file "$DATA_MODEL" "data-model.md"
|
|
check_dir "$CONTRACTS_DIR" "contracts/"
|
|
check_file "$QUICKSTART" "quickstart.md"
|
|
|
|
if $INCLUDE_TASKS; then
|
|
check_file "$TASKS" "tasks.md"
|
|
fi
|
|
fi
|