@erclx/aitk 0.56.0 → 0.58.0

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.
@@ -1,234 +0,0 @@
1
- #!/usr/bin/env bash
2
- set -e
3
- set -o pipefail
4
-
5
- SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
6
- PROJECT_ROOT="${PROJECT_ROOT:-$(dirname "$(dirname "$SCRIPT_DIR")")}"
7
-
8
- source "$PROJECT_ROOT/scripts/lib/ui.sh"
9
-
10
- STACKS_DIR="$PROJECT_ROOT/governance/stacks"
11
- RULES_DIR="$PROJECT_ROOT/governance/rules"
12
-
13
- show_help() {
14
- echo -e "${GREY}┌${NC}"
15
- echo -e "${GREY}├${NC} ${WHITE}Usage:${NC} aitk gov list [options]"
16
- echo -e "${GREY}│${NC}"
17
- echo -e "${GREY}│${NC} ${WHITE}Options:${NC}"
18
- echo -e "${GREY}│${NC} --stacks ${GREY}# Only list stacks${NC}"
19
- echo -e "${GREY}│${NC} --rules ${GREY}# Only list rules${NC}"
20
- echo -e "${GREY}│${NC} --json ${GREY}# Emit machine-readable JSON${NC}"
21
- echo -e "${GREY}│${NC} -h, --help ${GREY}# Show this help message${NC}"
22
- echo -e "${GREY}└${NC}"
23
- exit 0
24
- }
25
-
26
- read_frontmatter_field() {
27
- local file="$1"
28
- local field="$2"
29
- awk -v f="$field" '
30
- BEGIN { fm = 0 }
31
- /^---$/ { fm++; if (fm > 1) exit; next }
32
- fm == 1 {
33
- if (match($0, "^" f ":")) {
34
- val = substr($0, RLENGTH + 1)
35
- sub(/^[[:space:]]+/, "", val)
36
- sub(/^[\x27"]/, "", val)
37
- sub(/[\x27"]$/, "", val)
38
- print val
39
- exit
40
- }
41
- }
42
- ' "$file"
43
- }
44
-
45
- read_frontmatter_paths() {
46
- local file="$1"
47
- awk '
48
- BEGIN { fm = 0; in_paths = 0 }
49
- /^---$/ { fm++; if (fm > 1) exit; next }
50
- fm == 1 {
51
- if (in_paths) {
52
- if (match($0, /^[[:space:]]*-[[:space:]]+/)) {
53
- val = substr($0, RLENGTH + 1)
54
- sub(/^[\x27"]/, "", val)
55
- sub(/[\x27"]$/, "", val)
56
- print val
57
- next
58
- }
59
- in_paths = 0
60
- }
61
- if ($0 == "paths:") { in_paths = 1 }
62
- }
63
- ' "$file"
64
- }
65
-
66
- rule_domain() {
67
- local file="$1"
68
- local rel="${file#"$RULES_DIR"/}"
69
- echo "${rel%%/*}"
70
- }
71
-
72
- stack_rules_array() {
73
- local toml="$1"
74
- grep -oE '"[0-9]{3}-[a-z0-9-]+"' "$toml" | sed 's/"//g'
75
- }
76
-
77
- json_escape() {
78
- local s="$1"
79
- s="${s//\\/\\\\}"
80
- s="${s//\"/\\\"}"
81
- printf '%s' "$s"
82
- }
83
-
84
- list_stacks_text() {
85
- log_step "Stacks"
86
- local toml
87
- for toml in "$STACKS_DIR"/*.toml; do
88
- local name
89
- name=$(basename "$toml" .toml)
90
- local extends
91
- extends=$(grep '^extends' "$toml" | cut -d'"' -f2)
92
- local rule_count
93
- rule_count=$(stack_rules_array "$toml" | wc -l)
94
- if [ -n "$extends" ]; then
95
- log_info "$name (extends: $extends, $rule_count rules)"
96
- else
97
- log_info "$name ($rule_count rules)"
98
- fi
99
- done
100
- }
101
-
102
- list_rules_text() {
103
- log_step "Rules"
104
- local file
105
- while IFS= read -r file; do
106
- local name
107
- name=$(basename "$file" .md)
108
- local domain
109
- domain=$(rule_domain "$file")
110
- local desc
111
- desc=$(read_frontmatter_field "$file" "description")
112
- log_info "$name [$domain] $desc"
113
- done < <(find "$RULES_DIR" -type f -name "*.md" | sort)
114
- }
115
-
116
- list_stacks_json() {
117
- local first=1
118
- local toml
119
- printf '['
120
- for toml in "$STACKS_DIR"/*.toml; do
121
- local name
122
- name=$(basename "$toml" .toml)
123
- local extends
124
- extends=$(grep '^extends' "$toml" | cut -d'"' -f2)
125
- local rules_json="["
126
- local first_rule=1
127
- local rule
128
- while IFS= read -r rule; do
129
- [ -z "$rule" ] && continue
130
- if [ "$first_rule" -eq 0 ]; then
131
- rules_json+=","
132
- fi
133
- rules_json+="\"$rule\""
134
- first_rule=0
135
- done < <(stack_rules_array "$toml")
136
- rules_json+="]"
137
- if [ "$first" -eq 0 ]; then
138
- printf ','
139
- fi
140
- if [ -n "$extends" ]; then
141
- printf '{"name":"%s","extends":"%s","rules":%s}' "$name" "$extends" "$rules_json"
142
- else
143
- printf '{"name":"%s","extends":null,"rules":%s}' "$name" "$rules_json"
144
- fi
145
- first=0
146
- done
147
- printf ']'
148
- }
149
-
150
- list_rules_json() {
151
- local first=1
152
- local file
153
- printf '['
154
- while IFS= read -r file; do
155
- local name
156
- name=$(basename "$file" .md)
157
- local domain
158
- domain=$(rule_domain "$file")
159
- local desc
160
- desc=$(read_frontmatter_field "$file" "description")
161
-
162
- local paths_json="null"
163
- local paths_collected=()
164
- while IFS= read -r p; do
165
- [ -n "$p" ] && paths_collected+=("$p")
166
- done < <(read_frontmatter_paths "$file")
167
- if [ "${#paths_collected[@]}" -gt 0 ]; then
168
- paths_json="["
169
- local first_p=1
170
- local p
171
- for p in "${paths_collected[@]}"; do
172
- [ "$first_p" -eq 0 ] && paths_json+=","
173
- paths_json+="\"$(json_escape "$p")\""
174
- first_p=0
175
- done
176
- paths_json+="]"
177
- fi
178
-
179
- if [ "$first" -eq 0 ]; then
180
- printf ','
181
- fi
182
- printf '{"name":"%s","domain":"%s","description":"%s","paths":%s}' \
183
- "$name" "$domain" "$(json_escape "$desc")" "$paths_json"
184
- first=0
185
- done < <(find "$RULES_DIR" -type f -name "*.md" | sort)
186
- printf ']'
187
- }
188
-
189
- main() {
190
- local show_stacks=1
191
- local show_rules=1
192
- local json=0
193
-
194
- while [[ $# -gt 0 ]]; do
195
- case "$1" in
196
- -h | --help) show_help ;;
197
- --stacks)
198
- show_rules=0
199
- shift
200
- ;;
201
- --rules)
202
- show_stacks=0
203
- shift
204
- ;;
205
- --json)
206
- json=1
207
- shift
208
- ;;
209
- *) log_error "Unknown option: $1" ;;
210
- esac
211
- done
212
-
213
- trap close_timeline EXIT
214
-
215
- if [ "$json" -eq 1 ]; then
216
- printf '{'
217
- if [ "$show_stacks" -eq 1 ]; then
218
- printf '"stacks":'
219
- list_stacks_json
220
- [ "$show_rules" -eq 1 ] && printf ','
221
- fi
222
- if [ "$show_rules" -eq 1 ]; then
223
- printf '"rules":'
224
- list_rules_json
225
- fi
226
- printf '}\n'
227
- exit 0
228
- fi
229
-
230
- [ "$show_stacks" -eq 1 ] && list_stacks_text
231
- [ "$show_rules" -eq 1 ] && list_rules_text
232
- }
233
-
234
- main "$@"