#!/usr/bin/env bash # ai-task # Helper CLI to generate AI task prompts based on AI_TASK_TEMPLATE.md # Usage: # scripts/ai-task build "Objective text" [scope...] # scripts/ai-task plan "Objective text" [scope...] set -e TYPE="$1" OBJECTIVE="$2" shift 2 || true SCOPE=("$@") if [[ -z "$TYPE" || -z "$OBJECTIVE" ]]; then echo "Usage: ai-task \"Objective\" [scope files...]" exit 1 fi TYPE_LOWER=$(echo "$TYPE" | tr '[:upper:]' '[:lower:]') TYPE_UPPER=$(echo "$TYPE_LOWER" | tr '[:lower:]' '[:upper:]') DATE=$(date "+%Y-%m-%d %H:%M") DAY=$(date "+%Y%m%d") case "$TYPE_LOWER" in build) PREFIX="BUILD" ;; plan) PREFIX="PLAN" ;; *) echo "Error: task type must be 'plan' or 'build'" exit 1 ;; esac WORKLOG_FILE="docs/ai-worklog.md" PROMPTS_FILE="docs/ai-prompts.md" EXECUTION_LOG_FILE="docs/ai-execution-log.md" check_task_id_order() { local file="$1" local prefix="$2" local previous="" local current="" [[ -f "$file" ]] || return 0 while IFS= read -r current; do if [[ -n "$previous" && "$current" < "$previous" ]]; then echo "Error: task IDs in $file are out of chronological order for prefix $prefix" >&2 echo "Previous: $previous" >&2 echo "Current: $current" >&2 echo "Please fix the log order before generating a new task." >&2 exit 1 fi previous="$current" done < <(grep -Eo "${prefix}-[0-9]{8}-[0-9]{3}" "$file" || true) } check_task_id_order "$WORKLOG_FILE" "$PREFIX" check_task_id_order "$PROMPTS_FILE" "$PREFIX" check_task_id_order "$EXECUTION_LOG_FILE" "$PREFIX" LAST_SEQ=0 if [[ -f "$WORKLOG_FILE" ]]; then LAST_MATCH=$(grep -Eo "${PREFIX}-${DAY}-[0-9]{3}" "$WORKLOG_FILE" | tail -n 1 || true) if [[ -n "$LAST_MATCH" ]]; then LAST_SEQ=${LAST_MATCH##*-} LAST_SEQ=$((10#$LAST_SEQ)) fi fi NEXT_SEQ=$(printf "%03d" $((LAST_SEQ + 1))) TASK_ID="${PREFIX}-${DAY}-${NEXT_SEQ}" # Build scope block cat < Scope: EOF if [ ${#SCOPE[@]} -gt 0 ]; then for item in "${SCOPE[@]}"; do printf '%s\n' "- ${item}" done else printf '%s\n' "- " fi cat < Constraints: - follow AGENT_WORKFLOW.md - keep scope minimal - preserve existing behavior unless explicitly changed Testing: Validation: make fix make quality Logging requirements: - append entry to docs/ai-worklog.md - append entry to docs/ai-prompts.md - include Date, Task ID, Agent, Scope - use Task ID: ${TASK_ID} - maintain chronological Task ID order in ai-worklog.md, ai-prompts.md and ai-execution-log.md - append entry to docs/ai-execution-log.md Execution Logging requirements: - append entry to docs/ai-execution-log.md - include: - full prompt - agent todos - final execution report - use the standard execution log format defined in docs/ai-execution-log.md Git requirements: - do NOT commit or push unless explicitly requested Expected Report: - files changed - behavior changes - validation results EOF