diff --git a/.jules/bolt.md b/.jules/bolt.md index bb6d4d8..1a8e67d 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -1,3 +1,6 @@ +## 2026-01-18 - [Shell Builtins vs Caching] +**Learning:** Attempted to cache `command -v` results in a variable to avoid repeated checks. However, benchmarking revealed that `command -v` (a shell builtin) is extremely fast, and the overhead of checking a variable in shell script is comparable or even slower than the builtin itself. The optimization added complexity without performance gain. +**Action:** Do not cache shell builtins like `command -v` unless inside a very tight loop with significant other overheads. Focus on avoiding external process spawns (like `jq`, `chmod`, `grep`) instead. ## 2026-01-16 - [Shell Dependency Check Overhead] **Learning:** `lib/core/common.sh` functions like `safe_json_get_key` re-check dependencies (`command -v jq`) on every invocation. In tight loops, this adds significant overhead (~13% in micro-benchmark). **Action:** Cache dependency checks in global variables (e.g., `_JSON_PROCESSOR_CACHE`) when the script is sourced, rather than checking inside hot functions. diff --git a/bin/workflow-enforcer b/bin/workflow-enforcer index 2a39727..73131b8 100755 --- a/bin/workflow-enforcer +++ b/bin/workflow-enforcer @@ -20,7 +20,7 @@ fi # Determine Project Root (where .adbs data is) # Default to current directory or ADBS_PROJECT_ROOT if set -if [ -n "$ADBS_PROJECT_ROOT" ]; then +if [ -n "${ADBS_PROJECT_ROOT:-}" ]; then PROJECT_ROOT="$ADBS_PROJECT_ROOT" else # Fallback: assume current directory is project root @@ -44,12 +44,25 @@ DASHBOARD="$INSTALL_ROOT/lib/internal/dashboard.sh" mkdir -p "$PROJECT_ROOT/lib/internal" # Ensure scripts are executable -if ! chmod +x "$WORK_MANAGER" "$TASK_BACKEND" "$MIGRATOR" "$PLATFORM_DETECTOR" "$DASHBOARD" 2>/dev/null; then - # chmod failed - likely on Windows or permission issue - # Check if scripts are already executable or if we're on Windows - if [ ! -x "$WORK_MANAGER" ] && [ "$(uname -s)" != "MINGW"* ] && [ "$(uname -s)" != "MSYS"* ]; then - echo "Warning: Could not make scripts executable. You may need to run:" - echo " chmod +x lib/**/*.sh bin/*" +# Performance: Check first to avoid spawning chmod process on every run +_scripts_to_check=("$WORK_MANAGER" "$TASK_BACKEND" "$MIGRATOR" "$PLATFORM_DETECTOR" "$DASHBOARD") +_needs_chmod=false + +for script in "${_scripts_to_check[@]}"; do + if [ ! -x "$script" ]; then + _needs_chmod=true + break + fi +done + +if [ "$_needs_chmod" = true ]; then + if ! chmod +x "${_scripts_to_check[@]}" 2>/dev/null; then + # chmod failed - likely on Windows or permission issue + # Check if scripts are already executable or if we're on Windows + if [ ! -x "$WORK_MANAGER" ] && [ "$(uname -s)" != "MINGW"* ] && [ "$(uname -s)" != "MSYS"* ]; then + echo "Warning: Could not make scripts executable. You may need to run:" + echo " chmod +x lib/**/*.sh bin/*" + fi fi fi diff --git a/lib/internal/dashboard.sh b/lib/internal/dashboard.sh old mode 100644 new mode 100755 diff --git a/lib/internal/migrator.sh b/lib/internal/migrator.sh old mode 100644 new mode 100755 diff --git a/lib/internal/task_backend.sh b/lib/internal/task_backend.sh old mode 100644 new mode 100755 diff --git a/lib/internal/work_manager.sh b/lib/internal/work_manager.sh old mode 100644 new mode 100755 index 130961d..198b150 --- a/lib/internal/work_manager.sh +++ b/lib/internal/work_manager.sh @@ -406,33 +406,35 @@ export_context() { } # Main command handler -case "${1:-}" in - create|new) - shift - create_work "$@" - ;; - list) - shift - list_work "$@" - ;; - show) - shift - show_work "$@" - ;; - context) - shift - export_context "$@" - ;; - complete|done) - shift - complete_work "$@" - ;; - status) - show_status - ;; - *) - echo "Unknown work command: ${1:-}" - echo "Usage: work_manager.sh {create|list|show|complete|status}" - exit 1 - ;; -esac +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + case "${1:-}" in + create|new) + shift + create_work "$@" + ;; + list) + shift + list_work "$@" + ;; + show) + shift + show_work "$@" + ;; + context) + shift + export_context "$@" + ;; + complete|done) + shift + complete_work "$@" + ;; + status) + show_status + ;; + *) + echo "Unknown work command: ${1:-}" + echo "Usage: work_manager.sh {create|list|show|complete|status}" + exit 1 + ;; + esac +fi