From 4ba53c59e38d28813b98cab2e65f1aa5393d7de1 Mon Sep 17 00:00:00 2001 From: Evan Reichard Date: Thu, 28 May 2026 17:16:42 -0400 Subject: [PATCH] feat: create skill variable helper --- .../pi/config/skills/create-skill/SKILL.md | 1 + .../skills/create-skill/assets/variable.sh | 83 +++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100755 modules/home/programs/terminal/pi/config/skills/create-skill/assets/variable.sh diff --git a/modules/home/programs/terminal/pi/config/skills/create-skill/SKILL.md b/modules/home/programs/terminal/pi/config/skills/create-skill/SKILL.md index 4fbc288..0e7b5c8 100644 --- a/modules/home/programs/terminal/pi/config/skills/create-skill/SKILL.md +++ b/modules/home/programs/terminal/pi/config/skills/create-skill/SKILL.md @@ -45,6 +45,7 @@ description: "//` directory (e.g. `mappings/`, `references/`) with one sub-doc per category and an index `README.md`. Keep `SKILL.md` focused on the hot path — workflow, hard rules, and a short table pointing at the sub-docs. Include a brief style guide in the index README covering (a) defer to authoritative sources (stubs, schemas, generated docs) whenever possible, (b) row/entry formatting conventions, (c) when to create a new sub-doc vs. extend an existing one. diff --git a/modules/home/programs/terminal/pi/config/skills/create-skill/assets/variable.sh b/modules/home/programs/terminal/pi/config/skills/create-skill/assets/variable.sh new file mode 100755 index 0000000..32ac5af --- /dev/null +++ b/modules/home/programs/terminal/pi/config/skills/create-skill/assets/variable.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash +# Skill-local variable store. Values live in /.vars/. +# +# Usage: +# variable.sh --get NAME [--require-exec RELPATH] +# Prints value to stdout, exits 0. +# --require-exec asserts that VALUE/RELPATH +# exists and is executable; if not, prints +# the fix instructions to stderr and exits 2. +# variable.sh --set NAME VALUE Writes value, exits 0. +# +# Callers should treat any non-zero exit as fatal; the stderr message tells +# the caller (agent or user) exactly how to populate or correct the value. + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +SKILL_DIR="$(dirname "$SCRIPT_DIR")" +STORE="$SKILL_DIR/.vars" +SELF="$0" + +usage() { + cat >&2 <&2 < +EOF + exit 2 + fi + val="$(cat "$file")" + if [[ -n "$require_exec" && ! -x "$val/$require_exec" ]]; then + cat >&2 < +EOF + exit 2 + fi + printf '%s' "$val" + ;; + set) + [[ -n "$value" ]] || usage + [[ "$name" =~ ^[A-Z][A-Z0-9_]*$ ]] || { + echo >&2 "$SELF: invalid name '$name' (must match [A-Z][A-Z0-9_]*)" + exit 2 + } + mkdir -p "$STORE" + printf '%s' "$value" > "$STORE/$name" + ;; +esac