Author SHA1 Message Date
sneak 9862d2b52a update-policy: also fetch the style guides for the repo's languages (closes #182)
check / check (push) Successful in 22s
A go.mod adds the Go guide, plus the Go HTTP server conventions when a
tracked .go file imports net/http. A package.json adds the JS guide; a
pyproject.toml or setup.py adds the Python guide. Each goes to docs/.

Model: opus-5-5
2026-11-19 02:56:58 +00:00
clawbot d004fd272c Replace script/update-policy with a short wget-and-commit script (closes #165)
check / check (push) Successful in 1m22s
The script fetches a fixed list of three files from the main branch of
prompts with wget: docs/REPO_POLICIES.md, docs/CODE_STYLEGUIDE.md and
itself. It moves them into place and commits them. It does not push. It
stops before anything is replaced when a fetch fails, when a listed file
has uncommitted changes, and when REPO_POLICIES.md is still at the repo
root. It runs under busybox.

The line-keeping rules, the hash argument and the push are gone. The
policies and checklists say so, and name docs/REPO_POLICIES.md as the
file's place.

Model: opus-5-5
2026-11-18 23:23:50 +01:00
3 changed files with 114 additions and 47 deletions

No files matched your search

+6 -1
View File
@@ -1,6 +1,6 @@
--- ---
title: Repository Policies title: Repository Policies
last_modified: 2026-11-18 last_modified: 2026-11-19
--- ---
This document covers repository structure, tooling, and workflow standards. Code This document covers repository structure, tooling, and workflow standards. Code
@@ -163,6 +163,11 @@ style conventions are in separate documents:
- `docs/REPO_POLICIES.md` - `docs/REPO_POLICIES.md`
- `docs/CODE_STYLEGUIDE.md` - `docs/CODE_STYLEGUIDE.md`
- `script/update-policy` itself, so the script stays current - `script/update-policy` itself, so the script stays current
- `docs/CODE_STYLEGUIDE_GO.md`, when the repo has a `go.mod`
- `docs/GO_HTTP_SERVER_CONVENTIONS.md`, when its Go code imports `net/http`
- `docs/CODE_STYLEGUIDE_JS.md`, when the repo has a `package.json`
- `docs/CODE_STYLEGUIDE_PYTHON.md`, when the repo has a `pyproject.toml` or
`setup.py`
# Tests and checks # Tests and checks
+60 -37
View File
@@ -1,7 +1,8 @@
#!/bin/sh #!/bin/sh
# script/update-policy: replace the files below with their current # script/update-policy: replace the files below, and the style guides
# versions from the main branch of the prompts repo, and commit them. It # for the repo's languages, with their current versions from the main
# does not push. Identical in all repos, and it updates itself. # branch of the prompts repo, and commit them. It does not push.
# Identical in all repos, and it updates itself.
set -eu set -eu
ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" ROOT="$(cd "$(dirname "$0")/.." && pwd -P)"
@@ -14,46 +15,68 @@ prompts/CODE_STYLEGUIDE.md:docs/CODE_STYLEGUIDE.md
script/update-policy:script/update-policy script/update-policy:script/update-policy
" "
# The style guide for each language the repo uses, found by its file at
# the root, and the HTTP server conventions for Go code using net/http.
language_files() {
if [ -e go.mod ]; then
echo prompts/CODE_STYLEGUIDE_GO.md:docs/CODE_STYLEGUIDE_GO.md
if git grep -q '"net/http"' -- '*.go'; then
echo prompts/GO_HTTP_SERVER_CONVENTIONS.md:docs/GO_HTTP_SERVER_CONVENTIONS.md
fi
fi
if [ -e package.json ]; then
echo prompts/CODE_STYLEGUIDE_JS.md:docs/CODE_STYLEGUIDE_JS.md
fi
if [ -e pyproject.toml ] || [ -e setup.py ]; then
echo prompts/CODE_STYLEGUIDE_PYTHON.md:docs/CODE_STYLEGUIDE_PYTHON.md
fi
}
die() { die() {
echo "update-policy: $*" >&2 echo "update-policy: $*" >&2
exit 1 exit 1
} }
cd "$ROOT" main() {
[ ! -e prompts/REPO_POLICIES.md ] || cd "$ROOT"
die "this is the prompts repo, where these files come from" [ ! -e prompts/REPO_POLICIES.md ] ||
[ ! -e REPO_POLICIES.md ] || die "this is the prompts repo, where these files come from"
die "REPO_POLICIES.md is at the root;" \ [ ! -e REPO_POLICIES.md ] ||
"move it into docs/ with git mv and fix the links to it first" die "REPO_POLICIES.md is at the root;" \
"move it into docs/ with git mv and fix the links to it first"
paths="" FILES="$FILES $(language_files)"
for entry in $FILES; do paths=""
paths="$paths ${entry#*:}" for entry in $FILES; do
done paths="$paths ${entry#*:}"
[ -z "$(git status --porcelain -- $paths)" ] || done
die "commit or discard your changes to these files first:$paths" [ -z "$(git status --porcelain -- $paths)" ] ||
die "commit or discard your changes to these files first:$paths"
# Every file is fetched before any is replaced. The temporary directory # Every file is fetched before any is replaced. The temporary
# is inside the repo so that mv renames: the running script is replaced # directory is inside the repo so that mv renames: the running script
# by a new file, never rewritten in place. # is replaced by a new file, never rewritten in place.
tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")" tmp="$(mktemp -d "$ROOT/.update-policy.XXXXXX")"
trap 'rm -rf "$tmp"' EXIT trap 'rm -rf "$tmp"' EXIT
for entry in $FILES; do for entry in $FILES; do
mkdir -p "$tmp/$(dirname "${entry#*:}")" mkdir -p "$tmp/$(dirname "${entry#*:}")"
wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" || wget -q -T 60 -O "$tmp/${entry#*:}" "$RAW_URL/${entry%%:*}" ||
die "cannot fetch $RAW_URL/${entry%%:*}" die "cannot fetch $RAW_URL/${entry%%:*}"
done done
chmod 755 "$tmp/script/update-policy" chmod 755 "$tmp/script/update-policy"
for path in $paths; do for path in $paths; do
mkdir -p "$(dirname "$path")" mkdir -p "$(dirname "$path")"
mv "$tmp/$path" "$path" mv "$tmp/$path" "$path"
done done
git add -- $paths git add -- $paths
if git diff --cached --quiet -- $paths; then if git diff --cached --quiet -- $paths; then
echo "update-policy: already current, nothing to commit" echo "update-policy: already current, nothing to commit"
else else
git commit -q -m "Update policy files from prompts" -- $paths git commit -q -m "Update policy files from prompts" -- $paths
echo "update-policy: committed; review it, then push" echo "update-policy: committed; review it, then push"
fi fi
}
main "$@"
+48 -9
View File
@@ -1,7 +1,8 @@
#!/bin/sh #!/bin/sh
# test/update-policy.sh: test script/update-policy on throwaway repos. A # test/update-policy.sh: test script/update-policy on throwaway repos. A
# stub wget serves the files from this checkout, or fails for the path # stub wget serves the files from this checkout, or fails for the path
# in WGET_FAIL, so nothing touches the network. # in WGET_FAIL, so nothing touches the network. Like wget, it writes a
# new file without the execute bit, whatever the source's mode.
set -eu set -eu
PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)" PROMPTS="$(cd "$(dirname "$0")/.." && pwd -P)"
@@ -25,14 +26,16 @@ while [ "\$#" -gt 1 ]; do
done done
path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}" path="\${1#https://git.eeqj.de/sneak/prompts/raw/branch/main/}"
[ "\$path" != "\${WGET_FAIL:-}" ] || exit 1 [ "\$path" != "\${WGET_FAIL:-}" ] || exit 1
cp "$PROMPTS/\$path" "\$output" cat "$PROMPTS/\$path" > "\$output"
EOF EOF
chmod +x "$dir/bin/wget" chmod +x "$dir/bin/wget"
PATH="$dir/bin:$PATH" PATH="$dir/bin:$PATH"
export PATH export PATH
# new_repo: a repo with one commit, holding only an older copy of the # new_repo: a repo with one commit, holding only an older copy of the
# script, so that a run must replace the script that is running. # script that is shorter than the new one. A run that rewrote the running
# script in place, instead of replacing it, would then read the new
# file's last lines as commands and fail.
new_repo() { new_repo() {
scenario="$1" scenario="$1"
rm -rf "$dir/repo" rm -rf "$dir/repo"
@@ -41,29 +44,65 @@ new_repo() {
git config user.name test git config user.name test
git config user.email test@example.com git config user.email test@example.com
mkdir script mkdir script
cp "$PROMPTS/script/update-policy" script/ grep -v '^# ' "$PROMPTS/script/update-policy" > script/update-policy
echo "# older copy" >> script/update-policy chmod +x script/update-policy
echo own > README.md echo own > README.md
git add README.md script/update-policy git add README.md script/update-policy
git commit -q -m initial git commit -q -m initial
} }
new_repo "a first run writes and commits exactly the listed files" # committed_files_are: check that the last commit holds the listed files
# and the ones given, and no others.
committed_files_are() {
[ "$(git show --name-only --format= HEAD | sort)" = \
"$(echo "$LISTED $*" | tr ' ' '\n' | grep . | sort)" ] ||
fail "commit holds the wrong files"
}
new_repo "a first run, with no language files, commits exactly the listed files"
echo stray > stray.txt echo stray > stray.txt
echo staged >> README.md
git add README.md
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit" [ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit"
[ "$(git show --name-only --format= HEAD | sort)" = \ committed_files_are
"$(echo "$LISTED" | tr ' ' '\n' | sort)" ] || fail "commit holds other files"
cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" || cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" ||
fail "REPO_POLICIES.md differs" fail "REPO_POLICIES.md differs"
[ -x script/update-policy ] || fail "script not executable" [ -x script/update-policy ] || fail "script not executable"
[ "$(git status --porcelain)" = "?? stray.txt" ] || fail "tree not clean" [ "$(git status --porcelain)" = "$(printf 'M README.md\n?? stray.txt')" ] ||
fail "changed files outside the list"
scenario="a second run commits nothing" scenario="a second run commits nothing"
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit" [ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit"
grep -q "nothing to commit" "$dir/output" || fail "did not say so" grep -q "nothing to commit" "$dir/output" || fail "did not say so"
new_repo "a Go repo that uses net/http also gets the Go guide and HTTP conventions"
echo "module example.com/app" > go.mod
printf 'package main\n\nimport "net/http"\n' > main.go
git add go.mod main.go
git commit -q -m go
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_GO.md docs/GO_HTTP_SERVER_CONVENTIONS.md
cmp -s docs/CODE_STYLEGUIDE_GO.md "$PROMPTS/prompts/CODE_STYLEGUIDE_GO.md" ||
fail "CODE_STYLEGUIDE_GO.md differs"
new_repo "a Go repo without net/http gets only the Go guide"
echo "module example.com/app" > go.mod
printf 'package main\n\nimport "fmt"\n' > main.go
git add go.mod main.go
git commit -q -m go
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_GO.md
new_repo "a repo with package.json and pyproject.toml gets the JS and Python guides"
echo "{}" > package.json
echo "[project]" > pyproject.toml
git add package.json pyproject.toml
git commit -q -m js-and-python
script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
committed_files_are docs/CODE_STYLEGUIDE_JS.md docs/CODE_STYLEGUIDE_PYTHON.md
new_repo "a failed fetch writes nothing" new_repo "a failed fetch writes nothing"
WGET_FAIL=prompts/CODE_STYLEGUIDE.md script/update-policy > "$dir/output" 2>&1 && WGET_FAIL=prompts/CODE_STYLEGUIDE.md script/update-policy > "$dir/output" 2>&1 &&
fail "exited zero" fail "exited zero"