@drunkcoding/agents-and-skills 0.0.14 → 0.0.15

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.
@@ -0,0 +1,434 @@
1
+ #!/usr/bin/env bash
2
+ # detect-stack.sh — best-effort filesystem detection for the team-superpower
3
+ # stack block. Emits a YAML block (the same shape that lives inside the
4
+ # ```team-superpower``` fence in CLAUDE.md) to stdout, plus exit codes:
5
+ #
6
+ # 0 confident detection (single BE candidate and/or single FE candidate)
7
+ # 1 no stack signals found (BE absent AND FE absent) — lead should escalate
8
+ # 2 ambiguous (multiple plausible BE languages, or BE/FE conflict that the
9
+ # owner must resolve) — lead writes stack.detected.md with both options
10
+ #
11
+ # Usage:
12
+ # bash detect-stack.sh [<repo-root>]
13
+ #
14
+ # Dependencies: bash, find, grep, sed. jq is preferred but not required (we
15
+ # parse package.json with grep fallbacks when jq is missing).
16
+ #
17
+ # What this script does NOT do:
18
+ # - Write to CLAUDE.md. The spec forbids it. Output goes to stdout; the lead
19
+ # decides whether to write it to docs/superpowers/stack.detected.md.
20
+ # - Guess test commands when there is no signal — fields left blank with a
21
+ # `# CONFIRM:` comment for the owner to fill in.
22
+
23
+ set -euo pipefail
24
+
25
+ ROOT="${1:-$PWD}"
26
+ cd "$ROOT"
27
+
28
+ # ---- helpers --------------------------------------------------------------
29
+
30
+ has_file_glob() {
31
+ # has_file_glob <maxdepth> <name>
32
+ find . -maxdepth "$1" -type f -name "$2" 2>/dev/null | head -n1 | grep -q .
33
+ }
34
+
35
+ has_file_deep() {
36
+ # has_file_deep <name>
37
+ find . -type f -name "$1" -not -path './node_modules/*' -not -path './.git/*' -not -path './dist/*' -not -path './build/*' 2>/dev/null | head -n1 | grep -q .
38
+ }
39
+
40
+ read_pkg_field() {
41
+ # read_pkg_field <jq-expr> [default]
42
+ local expr="$1" default="${2:-}"
43
+ [ -f package.json ] || { printf '%s' "$default"; return; }
44
+ if command -v jq >/dev/null 2>&1; then
45
+ local v
46
+ v="$(jq -r "$expr // empty" package.json 2>/dev/null || true)"
47
+ printf '%s' "${v:-$default}"
48
+ else
49
+ printf '%s' "$default"
50
+ fi
51
+ }
52
+
53
+ pkg_has_dep() {
54
+ # pkg_has_dep <name>
55
+ [ -f package.json ] || return 1
56
+ if command -v jq >/dev/null 2>&1; then
57
+ jq -e --arg n "$1" '((.dependencies // {}) + (.devDependencies // {}) + (.peerDependencies // {})) | has($n)' package.json >/dev/null 2>&1
58
+ else
59
+ grep -qE "\"$1\"[[:space:]]*:" package.json
60
+ fi
61
+ }
62
+
63
+ pkg_script() {
64
+ # pkg_script <script-name> -> command string (empty if missing)
65
+ [ -f package.json ] || return 0
66
+ if command -v jq >/dev/null 2>&1; then
67
+ jq -r --arg n "$1" '.scripts[$n] // empty' package.json 2>/dev/null || true
68
+ fi
69
+ }
70
+
71
+ # ---- backend detection ----------------------------------------------------
72
+
73
+ backend_language=""
74
+ backend_framework=""
75
+ backend_test_framework=""
76
+ backend_build_command=""
77
+ backend_test_command=""
78
+ backend_format_command=""
79
+ backend_migration_tool=""
80
+ backend_package_manager=""
81
+ backend_candidates=()
82
+
83
+ if has_file_glob 3 '*.csproj' || has_file_glob 2 '*.sln' || [ -f Directory.Build.props ]; then
84
+ backend_candidates+=("csharp")
85
+ fi
86
+ if [ -f pyproject.toml ] || [ -f setup.py ] || [ -f requirements.txt ] || [ -f Pipfile ]; then
87
+ backend_candidates+=("python")
88
+ fi
89
+ if [ -f go.mod ]; then
90
+ backend_candidates+=("go")
91
+ fi
92
+ if [ -f Cargo.toml ]; then
93
+ backend_candidates+=("rust")
94
+ fi
95
+ if [ -f pom.xml ] || [ -f build.gradle ] || [ -f build.gradle.kts ]; then
96
+ backend_candidates+=("java")
97
+ fi
98
+ # Node-ts as backend only when package.json exists, "type": "module", and no
99
+ # frontend signal in deps. We resolve this after FE detection.
100
+
101
+ if [ ${#backend_candidates[@]} -eq 1 ]; then
102
+ backend_language="${backend_candidates[0]}"
103
+ fi
104
+
105
+ # Per-language fillers
106
+ case "$backend_language" in
107
+ csharp)
108
+ backend_framework="aspnetcore"
109
+ backend_build_command="dotnet build"
110
+ backend_test_command="dotnet test"
111
+ backend_format_command="dotnet format --verify-no-changes"
112
+ backend_package_manager="nuget"
113
+ # Test framework: scan csproj for hints
114
+ if find . -maxdepth 4 -type f -name '*.csproj' -exec grep -l -iE 'xunit' {} \; 2>/dev/null | head -n1 | grep -q .; then
115
+ backend_test_framework="xunit"
116
+ elif find . -maxdepth 4 -type f -name '*.csproj' -exec grep -l -iE 'nunit' {} \; 2>/dev/null | head -n1 | grep -q .; then
117
+ backend_test_framework="nunit"
118
+ elif find . -maxdepth 4 -type f -name '*.csproj' -exec grep -l -iE 'mstest' {} \; 2>/dev/null | head -n1 | grep -q .; then
119
+ backend_test_framework="mstest"
120
+ elif find . -maxdepth 4 -type f -name '*.csproj' -exec grep -l -iE 'reqnroll|specflow' {} \; 2>/dev/null | head -n1 | grep -q .; then
121
+ backend_test_framework="reqnroll"
122
+ else
123
+ backend_test_framework="# CONFIRM: xunit | nunit | mstest | reqnroll"
124
+ fi
125
+ # Migration tool: EF Core hint
126
+ if find . -maxdepth 4 -type f -name '*.csproj' -exec grep -l -iE 'Microsoft\.EntityFrameworkCore' {} \; 2>/dev/null | head -n1 | grep -q .; then
127
+ backend_migration_tool="ef-core"
128
+ else
129
+ backend_migration_tool="none"
130
+ fi
131
+ ;;
132
+ python)
133
+ backend_framework="# CONFIRM: fastapi | django | flask | starlette | none"
134
+ if [ -f pyproject.toml ] && grep -qE '\[tool\.poetry\]' pyproject.toml; then
135
+ backend_package_manager="poetry"
136
+ backend_build_command="poetry build"
137
+ backend_test_command="poetry run pytest"
138
+ elif [ -f Pipfile ]; then
139
+ backend_package_manager="pipenv"
140
+ backend_build_command="# CONFIRM: build command"
141
+ backend_test_command="pipenv run pytest"
142
+ else
143
+ backend_package_manager="pip"
144
+ backend_build_command="# CONFIRM: build command (often none for python apps)"
145
+ backend_test_command="pytest"
146
+ fi
147
+ backend_test_framework="pytest"
148
+ backend_format_command="# CONFIRM: ruff format --check . | black --check . | none"
149
+ if grep -qiE 'alembic' pyproject.toml requirements.txt Pipfile 2>/dev/null; then
150
+ backend_migration_tool="alembic"
151
+ elif grep -qiE 'django' pyproject.toml requirements.txt Pipfile 2>/dev/null; then
152
+ backend_migration_tool="django-migrations"
153
+ else
154
+ backend_migration_tool="none"
155
+ fi
156
+ ;;
157
+ go)
158
+ backend_framework="# CONFIRM: stdlib | gin | echo | chi | fiber"
159
+ backend_build_command="go build ./..."
160
+ backend_test_command="go test ./..."
161
+ backend_format_command="gofmt -l ."
162
+ backend_test_framework="go-testing"
163
+ backend_package_manager="go-modules"
164
+ backend_migration_tool="# CONFIRM: golang-migrate | goose | none"
165
+ ;;
166
+ rust)
167
+ backend_framework="# CONFIRM: axum | actix | rocket | warp"
168
+ backend_build_command="cargo build"
169
+ backend_test_command="cargo test"
170
+ backend_format_command="cargo fmt -- --check"
171
+ backend_test_framework="cargo-test"
172
+ backend_package_manager="cargo"
173
+ backend_migration_tool="# CONFIRM: sqlx-migrate | refinery | none"
174
+ ;;
175
+ java)
176
+ backend_framework="# CONFIRM: spring-boot | quarkus | micronaut | none"
177
+ if [ -f pom.xml ]; then
178
+ backend_build_command="mvn -B compile"
179
+ backend_test_command="mvn -B test"
180
+ backend_format_command="# CONFIRM: mvn spotless:check | none"
181
+ backend_package_manager="maven"
182
+ else
183
+ backend_build_command="./gradlew build"
184
+ backend_test_command="./gradlew test"
185
+ backend_format_command="# CONFIRM: ./gradlew spotlessCheck | none"
186
+ backend_package_manager="gradle"
187
+ fi
188
+ backend_test_framework="junit"
189
+ backend_migration_tool="# CONFIRM: flyway | liquibase | none"
190
+ ;;
191
+ esac
192
+
193
+ # ---- frontend detection ---------------------------------------------------
194
+
195
+ frontend_language=""
196
+ frontend_framework=""
197
+ frontend_bundler=""
198
+ frontend_test_framework=""
199
+ frontend_e2e_framework=""
200
+ frontend_ui_library=""
201
+ frontend_package_manager=""
202
+ frontend_build_command=""
203
+ frontend_test_command=""
204
+ have_pkg=0
205
+ [ -f package.json ] && have_pkg=1
206
+
207
+ if [ "$have_pkg" -eq 1 ]; then
208
+ # Detect framework
209
+ if pkg_has_dep next; then frontend_framework="next"; frontend_bundler="next";
210
+ elif pkg_has_dep nuxt; then frontend_framework="nuxt"; frontend_bundler="nuxt";
211
+ elif pkg_has_dep react || pkg_has_dep react-dom; then frontend_framework="react";
212
+ elif pkg_has_dep vue; then frontend_framework="vue";
213
+ elif pkg_has_dep svelte; then frontend_framework="svelte";
214
+ elif pkg_has_dep solid-js; then frontend_framework="solid";
215
+ elif pkg_has_dep '@angular/core'; then frontend_framework="angular";
216
+ fi
217
+
218
+ if [ -z "$frontend_bundler" ]; then
219
+ if has_file_glob 2 'vite.config.*'; then frontend_bundler="vite";
220
+ elif has_file_glob 2 'webpack.config.*'; then frontend_bundler="webpack";
221
+ elif has_file_glob 2 'rspack.config.*'; then frontend_bundler="rspack";
222
+ elif has_file_glob 2 'rollup.config.*'; then frontend_bundler="rollup";
223
+ elif has_file_glob 2 'next.config.*'; then frontend_bundler="next";
224
+ elif has_file_glob 2 'nuxt.config.*'; then frontend_bundler="nuxt";
225
+ fi
226
+ fi
227
+
228
+ if [ -n "$frontend_framework" ] || [ -n "$frontend_bundler" ]; then
229
+ # Confirmed FE shape
230
+ frontend_language="typescript"
231
+ [ -f tsconfig.json ] || frontend_language="javascript"
232
+
233
+ if pkg_has_dep vitest; then frontend_test_framework="vitest";
234
+ elif pkg_has_dep jest; then frontend_test_framework="jest";
235
+ elif pkg_has_dep '@playwright/test'; then frontend_test_framework="none";
236
+ else frontend_test_framework="# CONFIRM: vitest | jest | none";
237
+ fi
238
+
239
+ if pkg_has_dep '@playwright/test'; then frontend_e2e_framework="playwright";
240
+ elif pkg_has_dep cypress; then frontend_e2e_framework="cypress";
241
+ else frontend_e2e_framework="none";
242
+ fi
243
+
244
+ if pkg_has_dep '@shadcn/ui' || [ -d components/ui ] && grep -RIl 'shadcn' components/ui 2>/dev/null | head -n1 | grep -q . ; then
245
+ frontend_ui_library="shadcn"
246
+ elif pkg_has_dep '@mui/material'; then frontend_ui_library="mui";
247
+ elif pkg_has_dep antd; then frontend_ui_library="antd";
248
+ elif pkg_has_dep tailwindcss; then frontend_ui_library="tailwind-only";
249
+ else frontend_ui_library="# CONFIRM: shadcn | mui | antd | tailwind-only | none";
250
+ fi
251
+
252
+ # Package manager: lockfile is the source of truth
253
+ if [ -f pnpm-lock.yaml ]; then frontend_package_manager="pnpm";
254
+ elif [ -f yarn.lock ]; then frontend_package_manager="yarn";
255
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then frontend_package_manager="bun";
256
+ else frontend_package_manager="npm";
257
+ fi
258
+
259
+ # Scripts → commands
260
+ local_build="$(pkg_script build)"
261
+ local_test="$(pkg_script test)"
262
+ if [ -n "$local_build" ]; then
263
+ frontend_build_command="$frontend_package_manager build"
264
+ fi
265
+ if [ -n "$local_test" ]; then
266
+ frontend_test_command="$frontend_package_manager test"
267
+ fi
268
+ fi
269
+ fi
270
+
271
+ # Resolve node-ts-as-backend: package.json without any FE framework and with a
272
+ # server framework dep counts as a BE candidate.
273
+ if [ "$have_pkg" -eq 1 ] && [ -z "$frontend_framework" ] && [ -z "$frontend_bundler" ]; then
274
+ if pkg_has_dep express || pkg_has_dep fastify || pkg_has_dep koa || pkg_has_dep '@nestjs/core' || pkg_has_dep hono; then
275
+ backend_candidates+=("node-ts")
276
+ # If this was our only BE candidate, set it
277
+ if [ -z "$backend_language" ] && [ ${#backend_candidates[@]} -eq 1 ]; then
278
+ backend_language="node-ts"
279
+ fi
280
+ fi
281
+ fi
282
+
283
+ # Fill node-ts BE
284
+ if [ "$backend_language" = "node-ts" ]; then
285
+ if pkg_has_dep '@nestjs/core'; then backend_framework="nestjs";
286
+ elif pkg_has_dep fastify; then backend_framework="fastify";
287
+ elif pkg_has_dep express; then backend_framework="express";
288
+ elif pkg_has_dep koa; then backend_framework="koa";
289
+ elif pkg_has_dep hono; then backend_framework="hono";
290
+ fi
291
+ if pkg_has_dep vitest; then backend_test_framework="vitest";
292
+ elif pkg_has_dep jest; then backend_test_framework="jest";
293
+ else backend_test_framework="# CONFIRM: vitest | jest | mocha";
294
+ fi
295
+ if [ -f pnpm-lock.yaml ]; then backend_package_manager="pnpm";
296
+ elif [ -f yarn.lock ]; then backend_package_manager="yarn";
297
+ elif [ -f bun.lockb ] || [ -f bun.lock ]; then backend_package_manager="bun";
298
+ else backend_package_manager="npm";
299
+ fi
300
+ backend_build_command="$backend_package_manager build"
301
+ backend_test_command="$backend_package_manager test"
302
+ backend_format_command="# CONFIRM: prettier --check . | eslint . | none"
303
+ backend_migration_tool="# CONFIRM: prisma | typeorm | knex | none"
304
+ fi
305
+
306
+ # ---- contracts ------------------------------------------------------------
307
+
308
+ contracts_sot=""
309
+ contracts_openapi_path=""
310
+ contracts_ts_gen_command=""
311
+
312
+ if find . -maxdepth 5 -type f \( -name 'openapi.yaml' -o -name 'openapi.json' -o -name 'swagger.yaml' -o -name 'swagger.json' \) -not -path './node_modules/*' -not -path './.git/*' 2>/dev/null | head -n1 | grep -q .; then
313
+ contracts_sot="openapi"
314
+ contracts_openapi_path="$(find . -maxdepth 5 -type f \( -name 'openapi.yaml' -o -name 'openapi.json' -o -name 'swagger.yaml' \) -not -path './node_modules/*' -not -path './.git/*' 2>/dev/null | head -n1 | sed 's|^\./||')"
315
+ contracts_ts_gen_command="# CONFIRM: command that regenerates TS types from $contracts_openapi_path"
316
+ elif find . -maxdepth 5 -type f -name '*.proto' -not -path './node_modules/*' -not -path './.git/*' 2>/dev/null | head -n1 | grep -q .; then
317
+ contracts_sot="grpc"
318
+ elif find . -maxdepth 5 -type f -name 'schema.graphql' -not -path './node_modules/*' -not -path './.git/*' 2>/dev/null | head -n1 | grep -q .; then
319
+ contracts_sot="graphql"
320
+ elif [ -n "$backend_language" ] && [ -n "$frontend_framework" ]; then
321
+ contracts_sot="# CONFIRM: openapi | grpc | graphql | typescript | none"
322
+ else
323
+ contracts_sot="none"
324
+ fi
325
+
326
+ # ---- CI -------------------------------------------------------------------
327
+
328
+ ci_provider=""
329
+ ci_workflow_path=""
330
+
331
+ if find .github/workflows -maxdepth 1 -type f \( -name '*.yml' -o -name '*.yaml' \) 2>/dev/null | head -n1 | grep -q .; then
332
+ ci_provider="github-actions"
333
+ ci_workflow_path="$(find .github/workflows -maxdepth 1 -type f \( -name '*.yml' -o -name '*.yaml' \) 2>/dev/null | head -n1)"
334
+ elif [ -f azure-pipelines.yml ] || [ -f .azure/pipelines.yml ]; then
335
+ ci_provider="azure-pipelines"
336
+ [ -f azure-pipelines.yml ] && ci_workflow_path="azure-pipelines.yml" || ci_workflow_path=".azure/pipelines.yml"
337
+ elif [ -f .gitlab-ci.yml ]; then
338
+ ci_provider="gitlab-ci"
339
+ ci_workflow_path=".gitlab-ci.yml"
340
+ elif [ -f .circleci/config.yml ]; then
341
+ ci_provider="circleci"
342
+ ci_workflow_path=".circleci/config.yml"
343
+ else
344
+ ci_provider="none"
345
+ fi
346
+
347
+ # ---- emit -----------------------------------------------------------------
348
+
349
+ if [ -z "$backend_language" ] && [ -z "$frontend_framework" ] && [ -z "$frontend_bundler" ]; then
350
+ echo "# detect-stack: no BE or FE signal found in $ROOT" >&2
351
+ exit 1
352
+ fi
353
+
354
+ emit_backend=0
355
+ emit_frontend=0
356
+ [ -n "$backend_language" ] && emit_backend=1
357
+ { [ -n "$frontend_framework" ] || [ -n "$frontend_bundler" ]; } && emit_frontend=1
358
+
359
+ cat <<EOF
360
+ # Auto-generated by team-superpower detect-stack.sh on $(date -u +%Y-%m-%dT%H:%M:%SZ).
361
+ # Review every \`# CONFIRM:\` line, then paste into your CLAUDE.md inside a
362
+ # \`\`\`team-superpower fenced block. The plugin will NOT overwrite your CLAUDE.md.
363
+ EOF
364
+
365
+ if [ "$emit_backend" -eq 1 ]; then
366
+ cat <<EOF
367
+ backend:
368
+ language: ${backend_language}
369
+ framework: ${backend_framework:-# CONFIRM: framework}
370
+ test_framework: ${backend_test_framework:-# CONFIRM: test framework}
371
+ build_command: ${backend_build_command:-# CONFIRM: build command}
372
+ test_command: ${backend_test_command:-# CONFIRM: test command}
373
+ format_command: ${backend_format_command:-# CONFIRM: format check command (or 'none')}
374
+ migration_tool: ${backend_migration_tool:-none}
375
+ package_manager: ${backend_package_manager:-# CONFIRM: package manager}
376
+ EOF
377
+ else
378
+ echo "backend: none"
379
+ fi
380
+
381
+ if [ "$emit_frontend" -eq 1 ]; then
382
+ cat <<EOF
383
+ frontend:
384
+ language: ${frontend_language:-typescript}
385
+ framework: ${frontend_framework:-# CONFIRM: framework}
386
+ bundler: ${frontend_bundler:-# CONFIRM: bundler}
387
+ test_framework: ${frontend_test_framework:-none}
388
+ e2e_framework: ${frontend_e2e_framework:-none}
389
+ ui_library: ${frontend_ui_library:-none}
390
+ package_manager: ${frontend_package_manager:-npm}
391
+ build_command: ${frontend_build_command:-# CONFIRM: build command}
392
+ test_command: ${frontend_test_command:-# CONFIRM: test command}
393
+ EOF
394
+ else
395
+ echo "frontend: none"
396
+ fi
397
+
398
+ cat <<EOF
399
+ contracts:
400
+ source_of_truth: ${contracts_sot}
401
+ EOF
402
+ if [ -n "$contracts_openapi_path" ]; then
403
+ echo " openapi_path: $contracts_openapi_path"
404
+ fi
405
+ if [ -n "$contracts_ts_gen_command" ]; then
406
+ echo " ts_gen_command: \"$contracts_ts_gen_command\""
407
+ fi
408
+
409
+ cat <<EOF
410
+ ci:
411
+ provider: ${ci_provider}
412
+ EOF
413
+ if [ -n "$ci_workflow_path" ]; then
414
+ echo " workflow_path: $ci_workflow_path"
415
+ fi
416
+ cat <<EOF
417
+ required_checks: [] # CONFIRM: e.g. ["build", "test", "lint"]
418
+ poll_timeout_minutes: 20
419
+ security:
420
+ domain: # CONFIRM: payments | healthcare | generic | internal-only
421
+ pii: # CONFIRM: yes | no
422
+ public_endpoints: # CONFIRM: yes | no
423
+ data_at_rest: # CONFIRM: sql | nosql | none
424
+ EOF
425
+
426
+ # Exit with ambiguity warning when there are >1 BE candidates the script could
427
+ # not narrow down.
428
+ if [ ${#backend_candidates[@]} -gt 1 ]; then
429
+ uniq_list="$(printf '%s\n' "${backend_candidates[@]}" | sort -u | tr '\n' ',' | sed 's/,$//')"
430
+ echo "# AMBIGUOUS_BACKEND: multiple BE candidates found: $uniq_list — owner must confirm" >&2
431
+ exit 2
432
+ fi
433
+
434
+ exit 0
@@ -0,0 +1,194 @@
1
+ #!/usr/bin/env bash
2
+ # parse-claudemd.sh — extract the team-superpower YAML block from CLAUDE.md.
3
+ #
4
+ # Usage:
5
+ # parse-claudemd.sh extract [<path-to-CLAUDE.md>] prints the YAML block to stdout
6
+ # parse-claudemd.sh shape [<path-to-CLAUDE.md>] prints "full-stack" | "be-only" | "fe-only" | "none"
7
+ # parse-claudemd.sh get <dotted.key> [<path>] prints a single scalar value
8
+ # (limited: top-level group + leaf, e.g. backend.test_command)
9
+ #
10
+ # Exit codes:
11
+ # 0 success
12
+ # 1 CLAUDE.md missing or contains no `team-superpower` fenced block
13
+ # 2 bad arguments
14
+ # 3 key not found (only for `get`)
15
+ #
16
+ # Notes:
17
+ # - The fenced block is recognised by the literal opener "```team-superpower"
18
+ # (with no language indent) and the matching "```" closer.
19
+ # - Comments starting with `#` (after optional whitespace) are stripped before
20
+ # value extraction. Inline `# comment` tails are also stripped.
21
+ # - This is a deliberately tiny parser. It does NOT validate the schema.
22
+ # Schema validation is the lead's job (it halts on bad values per the spec).
23
+
24
+ set -euo pipefail
25
+
26
+ usage() {
27
+ sed -n '2,30p' "$0" | sed 's/^# \{0,1\}//'
28
+ }
29
+
30
+ CLAUDE_FILE_DEFAULT="${CLAUDE_PROJECT_DIR:-$PWD}/CLAUDE.md"
31
+
32
+ extract_block() {
33
+ local file="$1"
34
+ [ -f "$file" ] || return 1
35
+ # awk: print lines strictly between the opener and closer fences.
36
+ awk '
37
+ /^```team-superpower[[:space:]]*$/ { in_block = 1; next }
38
+ in_block && /^```[[:space:]]*$/ { in_block = 0; exit }
39
+ in_block { print }
40
+ ' "$file"
41
+ }
42
+
43
+ block_has_content() {
44
+ # Returns 0 if the YAML block extracted to stdin has at least one non-comment,
45
+ # non-blank line; 1 otherwise.
46
+ local payload
47
+ payload="$(cat || true)"
48
+ printf '%s' "$payload" | grep -vE '^[[:space:]]*(#|$)' | head -n1 | grep -q .
49
+ }
50
+
51
+ # Strip an inline `# comment` tail (but not `#` inside a quoted string — we
52
+ # tolerate the simple case here, the spec doesn't ship complex YAML values).
53
+ strip_comment() {
54
+ sed -E 's/[[:space:]]+#[^"\x27]*$//' | sed -E 's/^[[:space:]]*#.*$//'
55
+ }
56
+
57
+ cmd_extract() {
58
+ local file="${1:-$CLAUDE_FILE_DEFAULT}"
59
+ if [ ! -f "$file" ]; then
60
+ echo "parse-claudemd: $file does not exist" >&2
61
+ return 1
62
+ fi
63
+ local block
64
+ block="$(extract_block "$file")"
65
+ if [ -z "$block" ] || ! printf '%s' "$block" | block_has_content; then
66
+ echo "parse-claudemd: no \`team-superpower\` block found in $file" >&2
67
+ return 1
68
+ fi
69
+ printf '%s\n' "$block"
70
+ }
71
+
72
+ # Read a top-level scalar like `backend: none` or detect whether a group is
73
+ # explicitly "none".
74
+ group_is_none() {
75
+ # group_is_none <yaml-block-on-stdin> <group-name>
76
+ local group="$2"
77
+ awk -v g="$group" '
78
+ BEGIN { found = 0 }
79
+ {
80
+ sub(/[[:space:]]+#[^"\x27]*$/, "")
81
+ sub(/^[[:space:]]*#.*$/, "")
82
+ }
83
+ $0 ~ "^"g":[[:space:]]+none[[:space:]]*$" { found = 1; exit }
84
+ END { exit found ? 0 : 1 }
85
+ ' <<<"$1"
86
+ }
87
+
88
+ # A group is "present" if there is `group:` followed (on subsequent indented
89
+ # lines) by at least one non-comment, non-blank key/value pair.
90
+ group_is_present() {
91
+ # group_is_present <yaml-block> <group-name>
92
+ local group="$2"
93
+ awk -v g="$group" '
94
+ BEGIN { state = 0; has_keys = 0 }
95
+ {
96
+ line = $0
97
+ # strip comments
98
+ sub(/[[:space:]]+#[^"\x27]*$/, "", line)
99
+ sub(/^[[:space:]]*#.*$/, "", line)
100
+ }
101
+ line ~ "^"g":[[:space:]]*$" { state = 1; next }
102
+ line ~ "^"g":[[:space:]]+none" { state = 0; exit }
103
+ state == 1 && line ~ /^[^[:space:]]/ { state = 0 }
104
+ state == 1 && line ~ /^[[:space:]]+[A-Za-z_][A-Za-z0-9_]*:/ { has_keys = 1 }
105
+ END { exit has_keys ? 0 : 1 }
106
+ ' <<<"$1"
107
+ }
108
+
109
+ cmd_shape() {
110
+ local file="${1:-$CLAUDE_FILE_DEFAULT}"
111
+ local block
112
+ block="$(cmd_extract "$file")" || return 1
113
+
114
+ local be_present=1 fe_present=1
115
+ group_is_present "$block" backend || be_present=0
116
+ group_is_present "$block" frontend || fe_present=0
117
+
118
+ if [ "$be_present" -eq 1 ] && [ "$fe_present" -eq 1 ]; then echo "full-stack"
119
+ elif [ "$be_present" -eq 1 ]; then echo "be-only"
120
+ elif [ "$fe_present" -eq 1 ]; then echo "fe-only"
121
+ else echo "none"
122
+ fi
123
+ }
124
+
125
+ cmd_get() {
126
+ local key="${1:-}"
127
+ local file="${2:-$CLAUDE_FILE_DEFAULT}"
128
+ if [ -z "$key" ]; then usage >&2; return 2; fi
129
+ local block
130
+ block="$(cmd_extract "$file")" || return 1
131
+
132
+ case "$key" in
133
+ *.*)
134
+ local group leaf
135
+ group="${key%%.*}"
136
+ leaf="${key#*.}"
137
+ local value
138
+ value="$(awk -v g="$group" -v k="$leaf" '
139
+ BEGIN { in_group = 0; pat = "^[[:space:]]+" k "[[:space:]]*:[[:space:]]*" }
140
+ {
141
+ line = $0
142
+ sub(/[[:space:]]+#[^"\x27]*$/, "", line)
143
+ sub(/^[[:space:]]*#.*$/, "", line)
144
+ }
145
+ line ~ "^"g":[[:space:]]*$" { in_group = 1; next }
146
+ in_group && line ~ /^[^[:space:]]/ { in_group = 0 }
147
+ in_group && line ~ pat {
148
+ v = line
149
+ sub(pat, "", v)
150
+ sub(/[[:space:]]+$/, "", v)
151
+ gsub(/^"|"$/, "", v)
152
+ gsub(/^\x27|\x27$/, "", v)
153
+ print v
154
+ exit
155
+ }
156
+ ' <<<"$block")"
157
+ if [ -z "$value" ]; then return 3; fi
158
+ printf '%s\n' "$value"
159
+ ;;
160
+ *)
161
+ # Top-level scalar (e.g. "backend" for `backend: none`)
162
+ local value
163
+ value="$(awk -v k="$key" '
164
+ BEGIN { pat = "^" k ":[[:space:]]+" }
165
+ {
166
+ line = $0
167
+ sub(/[[:space:]]+#[^"\x27]*$/, "", line)
168
+ sub(/^[[:space:]]*#.*$/, "", line)
169
+ }
170
+ line ~ pat {
171
+ v = line; sub(pat, "", v); sub(/[[:space:]]+$/, "", v)
172
+ print v
173
+ exit
174
+ }
175
+ ' <<<"$block")"
176
+ if [ -z "$value" ]; then return 3; fi
177
+ printf '%s\n' "$value"
178
+ ;;
179
+ esac
180
+ }
181
+
182
+ main() {
183
+ local sub="${1:-}"
184
+ shift || true
185
+ case "$sub" in
186
+ extract) cmd_extract "$@" ;;
187
+ shape) cmd_shape "$@" ;;
188
+ get) cmd_get "$@" ;;
189
+ -h|--help|"") usage; [ -z "$sub" ] && return 2 || return 0 ;;
190
+ *) echo "unknown subcommand: $sub" >&2; usage >&2; return 2 ;;
191
+ esac
192
+ }
193
+
194
+ main "$@"
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tech-graph",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "description": "Step-by-step wizard for generating technical diagrams as SVG+PNG.",
5
5
  "author": {
6
6
  "name": "steven"