@jonit-dev/night-watch-cli 1.8.10-beta.11 → 1.8.10-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -116,6 +116,12 @@ fi
116
116
  AUDIT_WORKTREE_BASENAME="${PROJECT_NAME}-nw-audit-runner"
117
117
  AUDIT_WORKTREE_DIR="$(dirname "${PROJECT_DIR}")/${AUDIT_WORKTREE_BASENAME}"
118
118
 
119
+ cleanup_audit_worktree_on_exit() {
120
+ cleanup_worktree_path "${PROJECT_DIR}" "${AUDIT_WORKTREE_DIR}"
121
+ }
122
+
123
+ append_exit_trap "cleanup_audit_worktree_on_exit"
124
+
119
125
  cleanup_worktrees "${PROJECT_DIR}" "${AUDIT_WORKTREE_BASENAME}"
120
126
 
121
127
  if ! prepare_detached_worktree "${PROJECT_DIR}" "${AUDIT_WORKTREE_DIR}" "${DEFAULT_BRANCH}" "${LOG_FILE}"; then
@@ -292,6 +292,14 @@ if [ -n "${NW_DEFAULT_BRANCH:-}" ]; then
292
292
  else
293
293
  DEFAULT_BRANCH=$(detect_default_branch "${PROJECT_DIR}")
294
294
  fi
295
+
296
+ cleanup_executor_worktrees_on_exit() {
297
+ cleanup_worktree_path "${PROJECT_DIR}" "${WORKTREE_DIR}"
298
+ cleanup_worktree_path "${PROJECT_DIR}" "${BOOKKEEP_WORKTREE_DIR}"
299
+ }
300
+
301
+ append_exit_trap "cleanup_executor_worktrees_on_exit"
302
+
295
303
  if [[ "${PRD_DIR_REL}" = /* ]]; then
296
304
  BOOKKEEP_PRD_DIR="${PRD_DIR_REL}"
297
305
  else
@@ -541,14 +541,14 @@ _is_lock_holder_alive() {
541
541
 
542
542
  append_exit_trap() {
543
543
  local command="${1:?command required}"
544
- local existing=""
545
544
 
546
- existing=$(trap -p EXIT | sed -n "s/^trap -- '\\(.*\\)' EXIT$/\\1/p")
547
- if [ -n "${existing}" ]; then
548
- trap "${existing}; ${command}" EXIT
545
+ if [ -n "${NW_EXIT_TRAP_CHAIN:-}" ]; then
546
+ NW_EXIT_TRAP_CHAIN="${NW_EXIT_TRAP_CHAIN}; ${command}"
549
547
  else
550
- trap "${command}" EXIT
548
+ NW_EXIT_TRAP_CHAIN="${command}"
551
549
  fi
550
+
551
+ trap "${NW_EXIT_TRAP_CHAIN}" EXIT
552
552
  }
553
553
 
554
554
  # ── Detect default branch ───────────────────────────────────────────────────
@@ -801,6 +801,31 @@ cleanup_worktrees() {
801
801
  git -C "${project_dir}" worktree prune >/dev/null 2>&1 || true
802
802
  }
803
803
 
804
+ cleanup_worktree_path() {
805
+ local project_dir="${1:?project_dir required}"
806
+ local worktree_dir="${2:?worktree_dir required}"
807
+
808
+ if [ -z "${worktree_dir}" ] || [ "${worktree_dir}" = "${project_dir}" ]; then
809
+ return 0
810
+ fi
811
+
812
+ git -C "${project_dir}" worktree prune >/dev/null 2>&1 || true
813
+
814
+ if git -C "${project_dir}" worktree list --porcelain 2>/dev/null \
815
+ | grep -qF "worktree ${worktree_dir}"; then
816
+ log "CLEANUP: Removing worktree ${worktree_dir}"
817
+ git -C "${project_dir}" worktree remove --force "${worktree_dir}" 2>/dev/null || true
818
+ fi
819
+
820
+ if [ -d "${worktree_dir}" ] && ! git -C "${project_dir}" worktree list --porcelain 2>/dev/null \
821
+ | grep -qF "worktree ${worktree_dir}"; then
822
+ log "CLEANUP: Removing stale worktree directory ${worktree_dir}"
823
+ rm -rf "${worktree_dir}" 2>/dev/null || true
824
+ fi
825
+
826
+ git -C "${project_dir}" worktree prune >/dev/null 2>&1 || true
827
+ }
828
+
804
829
  # Pick the best available ref for creating a new detached worktree.
805
830
  resolve_worktree_base_ref() {
806
831
  local project_dir="${1:?project_dir required}"
@@ -881,6 +881,12 @@ if [ -n "${TARGET_PR}" ]; then
881
881
  fi
882
882
  REVIEW_WORKTREE_DIR="$(dirname "${PROJECT_DIR}")/${REVIEW_WORKTREE_BASENAME}"
883
883
 
884
+ cleanup_reviewer_runner_worktree_on_exit() {
885
+ cleanup_worktree_path "${PROJECT_DIR}" "${REVIEW_WORKTREE_DIR}"
886
+ }
887
+
888
+ append_exit_trap "cleanup_reviewer_runner_worktree_on_exit"
889
+
884
890
  cleanup_reviewer_worktrees "${REVIEW_WORKTREE_BASENAME}"
885
891
 
886
892
  # Dry-run mode: print diagnostics and exit
@@ -481,6 +481,12 @@ else
481
481
  fi
482
482
  QA_WORKTREE_DIR="$(dirname "${PROJECT_DIR}")/${PROJECT_NAME}-nw-qa-runner"
483
483
 
484
+ cleanup_qa_worktree_on_exit() {
485
+ cleanup_worktree_path "${PROJECT_DIR}" "${QA_WORKTREE_DIR}"
486
+ }
487
+
488
+ append_exit_trap "cleanup_qa_worktree_on_exit"
489
+
484
490
  log "START: Found PR(s) needing QA:${PRS_NEEDING_QA}"
485
491
 
486
492
  cleanup_worktrees "${PROJECT_DIR}"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jonit-dev/night-watch-cli",
3
- "version": "1.8.10-beta.11",
3
+ "version": "1.8.10-beta.12",
4
4
  "description": "AI agent that implements your specs, opens PRs, and reviews code overnight. Queue GitHub issues or PRDs, wake up to pull requests.",
5
5
  "type": "module",
6
6
  "bin": {