xwang 0.0.5 → 0.0.6

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.
@@ -21,6 +21,39 @@ yellow() { echo -e "\033[33m$1\033[0m" >&2; }
21
21
  # shellcheck disable=SC2034
22
22
  SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
23
23
 
24
+ # --- Project root resolution ---
25
+
26
+ find_project_root() {
27
+ # Explicit override
28
+ if [ -n "${XWANG_PROJECT_ROOT:-}" ]; then
29
+ printf '%s' "$XWANG_PROJECT_ROOT"
30
+ return 0
31
+ fi
32
+
33
+ # Use git root if available
34
+ local git_root
35
+ git_root=$(git rev-parse --show-toplevel 2>/dev/null || true)
36
+ if [ -n "$git_root" ]; then
37
+ printf '%s' "$git_root"
38
+ return 0
39
+ fi
40
+
41
+ # Search upward for openspec/changes directory
42
+ local dir="$PWD"
43
+ while [ "$dir" != "/" ]; do
44
+ if [ -d "$dir/openspec/changes" ]; then
45
+ printf '%s' "$dir"
46
+ return 0
47
+ fi
48
+ dir=$(dirname "$dir")
49
+ done
50
+
51
+ # Fallback to current directory
52
+ printf '%s' "$PWD"
53
+ }
54
+
55
+ PROJECT_ROOT=$(find_project_root)
56
+
24
57
  # --- Input validation ---
25
58
 
26
59
  validate_change_name() {
@@ -60,12 +93,12 @@ validate_enum() {
60
93
 
61
94
  yaml_file_for() {
62
95
  local change_name="$1"
63
- echo "openspec/changes/$change_name/.xwang.yaml"
96
+ echo "$PROJECT_ROOT/openspec/changes/$change_name/.xwang.yaml"
64
97
  }
65
98
 
66
99
  change_dir_for() {
67
100
  local change_name="$1"
68
- echo "openspec/changes/$change_name"
101
+ echo "$PROJECT_ROOT/openspec/changes/$change_name"
69
102
  }
70
103
 
71
104
  yaml_field() {
@@ -6,6 +6,35 @@
6
6
 
7
7
  set -euo pipefail
8
8
 
9
+ # --- Project root resolution ---
10
+
11
+ find_project_root() {
12
+ if [ -n "${XWANG_PROJECT_ROOT:-}" ]; then
13
+ printf '%s' "$XWANG_PROJECT_ROOT"
14
+ return 0
15
+ fi
16
+
17
+ local git_root
18
+ git_root=$(git rev-parse --show-toplevel 2>/dev/null || true)
19
+ if [ -n "$git_root" ]; then
20
+ printf '%s' "$git_root"
21
+ return 0
22
+ fi
23
+
24
+ local dir="$PWD"
25
+ while [ "$dir" != "/" ]; do
26
+ if [ -d "$dir/openspec/changes" ]; then
27
+ printf '%s' "$dir"
28
+ return 0
29
+ fi
30
+ dir=$(dirname "$dir")
31
+ done
32
+
33
+ printf '%s' "$PWD"
34
+ }
35
+
36
+ PROJECT_ROOT=$(find_project_root)
37
+
9
38
  # --- Colors ---
10
39
  red() { echo -e "\033[31m$1\033[0m" >&2; }
11
40
  yellow() { echo -e "\033[33m$1\033[0m" >&2; }
@@ -43,7 +72,7 @@ count_unchecked_tasks() {
43
72
  }
44
73
 
45
74
  # --- Detect active changes ---
46
- CHANGES_DIR="openspec/changes"
75
+ CHANGES_DIR="$PROJECT_ROOT/openspec/changes"
47
76
  JSON_ENTRIES=()
48
77
  TEXT_LINES=()
49
78
  SIGNAL_COUNT=0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xwang",
3
- "version": "0.0.5",
3
+ "version": "0.0.6",
4
4
  "description": "xwang CLI",
5
5
  "keywords": [
6
6
  "xwang",