From 1b3a7bf64173889f5ebecebf45c8f332bb3608b4 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 18 Jan 2026 19:11:43 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20chmod=20usage=20?= =?UTF-8?q?and=20fix=20test=20guards?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Refactored `bin/workflow-enforcer` to check file executability before calling `chmod`. - Added execution guards to `lib/internal/work_manager.sh` and `lib/validator/workflow.sh`. - Fixed unbound `ADBS_PROJECT_ROOT` variable in `bin/workflow-enforcer`. - Added journal entry in `.jules/bolt.md`. --- .jules/bolt.md | 3 ++ bin/workflow-enforcer | 27 ++++++++++---- lib/internal/dashboard.sh | 0 lib/internal/migrator.sh | 0 lib/internal/task_backend.sh | 0 lib/internal/work_manager.sh | 62 ++++++++++++++++---------------- lib/validator/workflow.sh | 68 +++++++++++++++++++----------------- tests/input.md | 2 ++ tests/output.md | 6 ++++ tests/output.txt | 2 ++ tests/template.md | 9 +++++ tests/template.txt | 2 ++ 12 files changed, 111 insertions(+), 70 deletions(-) create mode 100644 .jules/bolt.md mode change 100644 => 100755 lib/internal/dashboard.sh mode change 100644 => 100755 lib/internal/migrator.sh mode change 100644 => 100755 lib/internal/task_backend.sh mode change 100644 => 100755 lib/internal/work_manager.sh create mode 100644 tests/input.md create mode 100644 tests/output.md create mode 100644 tests/output.txt create mode 100644 tests/template.md create mode 100644 tests/template.txt diff --git a/.jules/bolt.md b/.jules/bolt.md new file mode 100644 index 0000000..053822d --- /dev/null +++ b/.jules/bolt.md @@ -0,0 +1,3 @@ +## 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. 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 diff --git a/lib/validator/workflow.sh b/lib/validator/workflow.sh index 4983b85..2220602 100755 --- a/lib/validator/workflow.sh +++ b/lib/validator/workflow.sh @@ -473,38 +473,40 @@ show_status() { } # Main command handler -case "${1:-}" in - validate) - validate_current_stage - ;; - next) - advance_stage - ;; - status) - show_status - ;; - current) - get_current_stage - ;; - set) - shift - if [ -z "$1" ]; then - echo "Error: Stage name required" +if [[ "${BASH_SOURCE[0]}" == "${0}" ]]; then + case "${1:-}" in + validate) + validate_current_stage + ;; + next) + advance_stage + ;; + status) + show_status + ;; + current) + get_current_stage + ;; + set) + shift + if [ -z "$1" ]; then + echo "Error: Stage name required" + exit 1 + fi + set_current_stage "$1" + echo "Stage set to: $1" + ;; + *) + echo "Usage: $0 {validate|next|status|current|set }" + echo "" + echo "Commands:" + echo " validate - Validate current stage" + echo " next - Advance to next stage (if validated)" + echo " status - Show current status" + echo " current - Get current stage name" + echo " set - Set stage (use with caution)" exit 1 - fi - set_current_stage "$1" - echo "Stage set to: $1" - ;; - *) - echo "Usage: $0 {validate|next|status|current|set }" - echo "" - echo "Commands:" - echo " validate - Validate current stage" - echo " next - Advance to next stage (if validated)" - echo " status - Show current status" - echo " current - Get current stage name" - echo " set - Set stage (use with caution)" - exit 1 - ;; -esac + ;; + esac +fi diff --git a/tests/input.md b/tests/input.md new file mode 100644 index 0000000..b82888b --- /dev/null +++ b/tests/input.md @@ -0,0 +1,2 @@ +Line with trailing spaces +Another line diff --git a/tests/output.md b/tests/output.md new file mode 100644 index 0000000..14db418 --- /dev/null +++ b/tests/output.md @@ -0,0 +1,6 @@ +# ADbS + +Workflow: Hybrid + + +Extra blank lines diff --git a/tests/output.txt b/tests/output.txt new file mode 100644 index 0000000..cccc418 --- /dev/null +++ b/tests/output.txt @@ -0,0 +1,2 @@ +Project: ADbS +Workflow: Hybrid diff --git a/tests/template.md b/tests/template.md new file mode 100644 index 0000000..9f665cd --- /dev/null +++ b/tests/template.md @@ -0,0 +1,9 @@ +--- +description: Test +--- +# {{PROJECT_NAME}} + +Workflow: {{WORKFLOW}} + + +Extra blank lines diff --git a/tests/template.txt b/tests/template.txt new file mode 100644 index 0000000..b355155 --- /dev/null +++ b/tests/template.txt @@ -0,0 +1,2 @@ +Project: {{PROJECT_NAME}} +Workflow: {{WORKFLOW}}