From 87ccb3e7e348b33ed81165667f051771f17ba3e7 Mon Sep 17 00:00:00 2001 From: sneak Date: Thu, 19 Nov 2026 02:56:58 +0000 Subject: [PATCH] update-policy: also fetch the style guides for the repo's languages (closes #182) A go.mod adds the Go guide, plus the Go HTTP server conventions when a tracked .go file imports net/http. Tracked .js or .ts files add the JS guide; a pyproject.toml or setup.py adds the Python guide. Each goes to docs/. Model: opus-5-5 --- prompts/REPO_POLICIES.md | 7 +++++- script/update-policy | 27 ++++++++++++++++++--- test/update-policy.sh | 51 +++++++++++++++++++++++++++++++++++++--- 3 files changed, 78 insertions(+), 7 deletions(-) diff --git a/prompts/REPO_POLICIES.md b/prompts/REPO_POLICIES.md index 1416ad6..d4112ea 100644 --- a/prompts/REPO_POLICIES.md +++ b/prompts/REPO_POLICIES.md @@ -1,6 +1,6 @@ --- title: Repository Policies -last_modified: 2026-11-18 +last_modified: 2026-11-19 --- 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/CODE_STYLEGUIDE.md` - `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 tracks `.js` or `.ts` files + - `docs/CODE_STYLEGUIDE_PYTHON.md`, when the repo has a `pyproject.toml` or + `setup.py` # Tests and checks diff --git a/script/update-policy b/script/update-policy index fc78ab2..df88d23 100755 --- a/script/update-policy +++ b/script/update-policy @@ -1,7 +1,8 @@ #!/bin/sh -# script/update-policy: replace the files below with their current -# versions from the main branch of the prompts repo, and commit them. It -# does not push. Identical in all repos, and it updates itself. +# script/update-policy: replace the files below, and the style guides +# for the repo's languages, with their current versions from the main +# branch of the prompts repo, and commit them. It does not push. +# Identical in all repos, and it updates itself. set -eu ROOT="$(cd "$(dirname "$0")/.." && pwd -P)" @@ -14,6 +15,25 @@ prompts/CODE_STYLEGUIDE.md:docs/CODE_STYLEGUIDE.md script/update-policy:script/update-policy " +# The style guide for each language the repo uses, and the HTTP server +# conventions for Go code using net/http. Go and Python are found by +# their file at the root, JavaScript by tracked .js or .ts files: many +# Go repos have a package.json only to pin prettier. +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 [ -n "$(git ls-files -- '*.js' '*.ts')" ]; 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() { echo "update-policy: $*" >&2 exit 1 @@ -27,6 +47,7 @@ main() { die "REPO_POLICIES.md is at the root;" \ "move it into docs/ with git mv and fix the links to it first" + FILES="$FILES $(language_files)" paths="" for entry in $FILES; do paths="$paths ${entry#*:}" diff --git a/test/update-policy.sh b/test/update-policy.sh index 2117218..6c29888 100755 --- a/test/update-policy.sh +++ b/test/update-policy.sh @@ -51,14 +51,21 @@ new_repo() { 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 staged >> README.md git add README.md script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" [ "$(git rev-list --count HEAD)" = 2 ] || fail "made no single commit" -[ "$(git show --name-only --format= HEAD | sort)" = \ - "$(echo "$LISTED" | tr ' ' '\n' | sort)" ] || fail "commit holds other files" +committed_files_are cmp -s docs/REPO_POLICIES.md "$PROMPTS/prompts/REPO_POLICIES.md" || fail "REPO_POLICIES.md differs" [ -x script/update-policy ] || fail "script not executable" @@ -70,6 +77,44 @@ script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" [ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit" 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 Go repo with a package.json only for prettier gets no JS guide" +echo "module example.com/app" > go.mod +printf 'package main\n\nimport "fmt"\n' > main.go +echo '{"devDependencies": {"prettier": "3.3.3"}}' > package.json +mkdir -p .yarn/releases +echo "// yarn" > .yarn/releases/yarn-4.5.0.cjs +git add go.mod main.go package.json .yarn/releases/yarn-4.5.0.cjs +git commit -q -m go-with-prettier +script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero" +committed_files_are docs/CODE_STYLEGUIDE_GO.md + +new_repo "a repo with .js files and pyproject.toml gets the JS and Python guides" +echo "{}" > package.json +echo "console.log(1);" > index.js +echo "[project]" > pyproject.toml +git add package.json index.js 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" WGET_FAIL=prompts/CODE_STYLEGUIDE.md script/update-policy > "$dir/output" 2>&1 && fail "exited zero" -- 2.54.0