release: v0.0.2
Some checks failed
Release / tag-and-notes (push) Has been cancelled

Squash-merge integration into main for v0.0.2
This commit is contained in:
2025-09-10 22:47:49 +00:00
parent 9cb1f5da1f
commit d381070c75
32 changed files with 396 additions and 55 deletions

64
scripts/prompt_build.py Normal file
View File

@@ -0,0 +1,64 @@
#!/usr/bin/env python3
import os, sys, yaml
def load_manifest(path):
with open(path, 'r', encoding='utf-8') as f:
return yaml.safe_load(f)
def resolve(path, seen):
m = load_manifest(path)
includes = m.get('include', []) or []
modules = m.get('modules', []) or []
for inc in includes:
resolve(inc, seen)
for mod in modules:
if mod not in seen:
seen.append(mod)
return seen
def words(s: str) -> int:
return len(s.split())
def main():
if len(sys.argv) != 3:
print("Usage: prompt_build.py <manifest> <out>", file=sys.stderr)
sys.exit(2)
manifest, out_path = sys.argv[1], sys.argv[2]
mods = resolve(manifest, [])
if not mods:
print(f"No modules resolved from {manifest}", file=sys.stderr)
sys.exit(1)
os.makedirs(os.path.dirname(out_path), exist_ok=True)
def read(p):
with open(p, 'r', encoding='utf-8') as f:
return f.read().strip() + "\n\n"
parts = ["Generated Prompt Pack\n\n"]
for m in mods:
parts.append(f"--- {m} ---\n")
parts.append(read(m))
content = "".join(parts)
# budgets
total_words = words(content)
BASE_BUDGET = 1200
if total_words > BASE_BUDGET:
print(f"ERROR: Pack exceeds budget: {total_words} > {BASE_BUDGET}", file=sys.stderr)
sys.exit(3)
ERRORS = 0
MOD_BUDGET = 400
for m in mods:
with open(m, 'r', encoding='utf-8') as f:
wc = words(f.read())
if wc > MOD_BUDGET:
print(f"ERROR: Module {m} exceeds budget: {wc} > {MOD_BUDGET}", file=sys.stderr)
ERRORS += 1
if ERRORS:
sys.exit(4)
if out_path == '-':
sys.stdout.write(content)
else:
with open(out_path, 'w', encoding='utf-8') as out:
out.write(content)
print(f"Built {out_path} with {total_words} words across {len(mods)} modules.", file=sys.stderr)
if __name__ == '__main__':
main()

59
scripts/prompts Executable file
View File

@@ -0,0 +1,59 @@
#!/usr/bin/env bash
set -euo pipefail
usage() {
cat >&2 <<'USAGE'
Usage: scripts/prompts <command> [args]
Commands:
build <manifest> <output> Build a flattened prompt from a manifest
pack <area> Build known area pack (cto|coo) into dist/prompts
all Build all known area packs
lint Lint prompts (budgets and includes)
USAGE
exit 2
}
repo_root() { git rev-parse --show-toplevel 2>/dev/null || pwd; }
ci_run() {
local root; root="$(repo_root)"
# Ensure ci image is available by invoking a no-op build via scripts/ci
# Use compose to run with current uid:gid to avoid file ownership issues
docker compose -f "$root/docker/ci.compose.yml" run --rm \
--user "$(id -u):$(id -g)" \
-e IN_CI_CONTAINER=1 ci bash -lc "cd /workspace && $1" </dev/null
}
build_manifest() {
local manifest=$1 out=$2 root
root="$(repo_root)"
mkdir -p "$root/dist/prompts"
# Write on host to avoid ownership issues; container prints to stdout.
TMP_OUT=$(mktemp)
trap '[[ -n "${TMP_OUT:-}" ]] && rm -f "$TMP_OUT"' EXIT
ci_run "python3 scripts/prompt_build.py '$manifest' -" >"$TMP_OUT"
mv "$TMP_OUT" "$out"
}
cmd=${1:-}
case "$cmd" in
build)
shift; [[ $# -eq 2 ]] || usage
build_manifest "$1" "$2" ;;
pack)
shift; area=${1:-}; root="$(repo_root)"
case "$area" in
cto) build_manifest "$root/COMMON/prompt/manifests/cto.yaml" "$root/dist/prompts/cto.md" ;;
coo) build_manifest "$root/COMMON/prompt/manifests/coo.yaml" "$root/dist/prompts/coo.md" ;;
*) echo "Unknown area: $area" >&2; exit 2 ;;
esac ;;
all)
root="$(repo_root)"; mkdir -p "$root/dist/prompts"
"$0" pack cto
"$0" pack coo ;;
lint)
# Rebuild and rely on budget checks to fail if over
"$0" all ;;
*) usage ;;
esac