Compare commits
2
Commits
8f4e8e6fe1
..
next
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d004fd272c | ||
|
|
630437e620 |
No files matched your search
@@ -155,7 +155,8 @@ share, and evolve prompts across projects.
|
|||||||
The repository is a collection of Markdown files organized in the `prompts/`
|
The repository is a collection of Markdown files organized in the `prompts/`
|
||||||
subdirectory. Each file contains one or more related prompts or policy
|
subdirectory. Each file contains one or more related prompts or policy
|
||||||
documents. There is no build step or runtime component; the prompts are consumed
|
documents. There is no build step or runtime component; the prompts are consumed
|
||||||
by copying them into other projects or referencing them directly.
|
by copying them into other projects or referencing them directly. `examples/`
|
||||||
|
holds the example `Dockerfile` files that `prompts/REPO_POLICIES.md` links to.
|
||||||
|
|
||||||
## See Also
|
## See Also
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
FROM golangci/golangci-lint@sha256:... AS lint
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends libvips-dev \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
# The steps that install system packages and download Go's modules
|
||||||
|
# come before COPY . ., so a change to the code keeps their layers.
|
||||||
|
# The steps that compile mount Go's build cache, and golangci-lint run
|
||||||
|
# also mounts golangci-lint's; both survive from build to build.
|
||||||
|
|
||||||
|
# Lint phase
|
||||||
|
# golangci/golangci-lint:v2.x.x, YYYY-MM-DD
|
||||||
|
FROM golangci/golangci-lint@sha256:... AS lint
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
--mount=type=cache,target=/root/.cache/golangci-lint \
|
||||||
|
golangci-lint run --config .golangci.yml ./...
|
||||||
|
|
||||||
|
# Test phase. -race needs cgo and so a C compiler, which the Debian Go
|
||||||
|
# image ships and the alpine one does not. -count=1 because the mounted
|
||||||
|
# cache also holds test results, which go test would otherwise replay.
|
||||||
|
# A first run that timed out gets no rerun, because a rerun would only
|
||||||
|
# wait for the same hang.
|
||||||
|
# golang:1.x, YYYY-MM-DD
|
||||||
|
FROM golang@sha256:... AS test
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY . .
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
status=0; \
|
||||||
|
output=$(go test -count=1 -timeout 90s -race -cover ./... 2>&1) || status=$?; \
|
||||||
|
printf '%s\n' "$output"; \
|
||||||
|
test "$status" -eq 0 && exit 0; \
|
||||||
|
case "$output" in \
|
||||||
|
*"panic: test timed out"*|*"*** Test killed"*) exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
echo "--- Rerunning with -v for details ---"; \
|
||||||
|
go test -count=1 -timeout 90s -race -v ./...; \
|
||||||
|
exit 1
|
||||||
|
|
||||||
|
# Build stage. Nothing is wanted from either phase above; the copies
|
||||||
|
# are what make BuildKit build them first, so nothing after them can
|
||||||
|
# run unless lint and test passed.
|
||||||
|
# golang:1.x-alpine, YYYY-MM-DD
|
||||||
|
FROM golang@sha256:... AS builder
|
||||||
|
# git comes from the base image's own distribution package index, which
|
||||||
|
# is trusted, so it needs no version and no hash.
|
||||||
|
RUN apk add --no-cache git
|
||||||
|
WORKDIR /src
|
||||||
|
COPY go.mod go.sum ./
|
||||||
|
RUN go mod download
|
||||||
|
COPY --from=lint /src/go.sum /dev/null
|
||||||
|
COPY --from=test /src/go.sum /dev/null
|
||||||
|
# A tar-stream context keeps the sender's file owners, which git refuses.
|
||||||
|
RUN git config --system --add safe.directory /src
|
||||||
|
COPY . .
|
||||||
|
|
||||||
|
# The VERSION build arg when one is given, otherwise
|
||||||
|
# `git describe --tags --always` on the .git in the build context. With
|
||||||
|
# .git present, a version that is still empty, dev or unknown fails the
|
||||||
|
# build: git is missing or could not read the checkout.
|
||||||
|
ARG VERSION
|
||||||
|
RUN --mount=type=cache,target=/root/.cache/go-build \
|
||||||
|
VERSION="${VERSION:-$(git describe --tags --always)}"; \
|
||||||
|
if [ -e .git ]; then \
|
||||||
|
case "$VERSION" in ""|dev|unknown) \
|
||||||
|
echo "version is '$VERSION' although .git is present" >&2; \
|
||||||
|
exit 1 ;; \
|
||||||
|
esac; \
|
||||||
|
fi; \
|
||||||
|
CGO_ENABLED=0 go build -trimpath \
|
||||||
|
-ldflags="-s -w -X main.Version=${VERSION}" \
|
||||||
|
-o /app ./cmd/app/
|
||||||
|
|
||||||
|
# Runtime stage, and the last one
|
||||||
|
FROM alpine@sha256:...
|
||||||
|
COPY --from=builder /app /usr/local/bin/app
|
||||||
|
ENTRYPOINT ["app"]
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
# Test phase. Both pytest runs share one 90-second timeout, so a hang
|
||||||
|
# uses it once and gets no rerun.
|
||||||
|
# debian:trixie-slim, YYYY-MM-DD
|
||||||
|
FROM debian@sha256:... AS test
|
||||||
|
# Python, pip and venv come from the distribution, which is trusted, so
|
||||||
|
# they need no version and no hash. make and git are base tools that
|
||||||
|
# script/bootstrap installs when they are missing. Installed here, they
|
||||||
|
# stay in their own layer when script/ changes.
|
||||||
|
RUN apt-get update \
|
||||||
|
&& apt-get install -y --no-install-recommends ca-certificates make git \
|
||||||
|
python3 python3-venv \
|
||||||
|
&& rm -rf /var/lib/apt/lists/*
|
||||||
|
# script/bootstrap installs pipenv in a virtual environment at
|
||||||
|
# $HOME/.pipenv, and the tests below run that pipenv.
|
||||||
|
ENV PATH=/root/.pipenv/bin:$PATH
|
||||||
|
WORKDIR /app
|
||||||
|
COPY script/ script/
|
||||||
|
COPY Pipfile Pipfile.lock ./
|
||||||
|
RUN script/bootstrap
|
||||||
|
COPY . .
|
||||||
|
RUN timeout 90 sh -c 'pipenv run pytest || { \
|
||||||
|
echo "--- Rerunning with -v for details ---"; \
|
||||||
|
pipenv run pytest -v; exit 1; }'
|
||||||
@@ -22,7 +22,7 @@ with your task.
|
|||||||
- [ ] `README.md` exists with all required sections (Description, Getting
|
- [ ] `README.md` exists with all required sections (Description, Getting
|
||||||
Started, Rationale, Design, TODO, License, Author)
|
Started, Rationale, Design, TODO, License, Author)
|
||||||
- [ ] `LICENSE` file exists and matches the README
|
- [ ] `LICENSE` file exists and matches the README
|
||||||
- [ ] `REPO_POLICIES.md` exists and version date is current — fetch from
|
- [ ] `docs/REPO_POLICIES.md` exists and version date is current — fetch from
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/REPO_POLICIES.md`
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/REPO_POLICIES.md`
|
||||||
- [ ] Guidance for coding agents, if the repo has any, is one `AGENTS.md` at the
|
- [ ] Guidance for coding agents, if the repo has any, is one `AGENTS.md` at the
|
||||||
root — never a file or directory named after one agent tool, such as
|
root — never a file or directory named after one agent tool, such as
|
||||||
@@ -56,8 +56,8 @@ with your task.
|
|||||||
also mounts golangci-lint's
|
also mounts golangci-lint's
|
||||||
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
||||||
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
||||||
that timed out gets no rerun, as in the canonical Go `Dockerfile` in
|
that timed out gets no rerun, as in `examples/go.Dockerfile` in the
|
||||||
`REPO_POLICIES.md`
|
`prompts` repo
|
||||||
- [ ] Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
- [ ] Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
||||||
it before `COPY . .`, with `COPY script/ script/`,
|
it before `COPY . .`, with `COPY script/ script/`,
|
||||||
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
||||||
@@ -76,8 +76,8 @@ with your task.
|
|||||||
a package with no wheel for the image stops the install. In that step it
|
a package with no wheel for the image stops the install. In that step it
|
||||||
installs no Python, because a step above it already did. `Pipfile` names no
|
installs no Python, because a step above it already did. `Pipfile` names no
|
||||||
`python_version`, because `--deploy` stops when the distribution's Python
|
`python_version`, because `--deploy` stops when the distribution's Python
|
||||||
differs from it. The tests run after `COPY . .`, as in the Python `test`
|
differs from it. The tests run after `COPY . .`, as in
|
||||||
phase example in `REPO_POLICIES.md`
|
`examples/python-test-phase.Dockerfile` in the `prompts` repo
|
||||||
|
|
||||||
- [ ] The gate phases invoke their tools directly, never through `make lint` or
|
- [ ] The gate phases invoke their tools directly, never through `make lint` or
|
||||||
`script/test` — those are themselves a `docker build` and would recurse
|
`script/test` — those are themselves a `docker build` and would recurse
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ Template files can be fetched from:
|
|||||||
## Create Project Files
|
## Create Project Files
|
||||||
|
|
||||||
- [ ] `LICENSE` file matching the chosen license
|
- [ ] `LICENSE` file matching the chosen license
|
||||||
- [ ] `REPO_POLICIES.md` — fetch from
|
- [ ] `docs/REPO_POLICIES.md` — fetch from
|
||||||
`https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/REPO_POLICIES.md`
|
`https://git.eeqj.de/sneak/prompts/raw/branch/main/prompts/REPO_POLICIES.md`
|
||||||
- [ ] Guidance for coding agents, if the repo has any, is one `AGENTS.md` at the
|
- [ ] Guidance for coding agents, if the repo has any, is one `AGENTS.md` at the
|
||||||
root — never a file or directory named after one agent tool, such as
|
root — never a file or directory named after one agent tool, such as
|
||||||
@@ -125,8 +125,8 @@ Template files can be fetched from:
|
|||||||
also mounts golangci-lint's
|
also mounts golangci-lint's
|
||||||
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
(`--mount=type=cache,target=/root/.cache/golangci-lint`), and no step
|
||||||
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
mounts anything else; both `go test` runs carry `-count=1`; a first run
|
||||||
that timed out gets no rerun, as in the canonical Go `Dockerfile` in
|
that timed out gets no rerun, as in `examples/go.Dockerfile` in the
|
||||||
`REPO_POLICIES.md`
|
`prompts` repo
|
||||||
- Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
- Python: a `test` phase that installs its packages from `Pipfile.lock` does
|
||||||
it before `COPY . .`, with `COPY script/ script/`,
|
it before `COPY . .`, with `COPY script/ script/`,
|
||||||
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
`COPY Pipfile Pipfile.lock ./` and `RUN script/bootstrap`. When
|
||||||
@@ -146,8 +146,8 @@ Template files can be fetched from:
|
|||||||
for the image stops the install. In that step it installs no Python,
|
for the image stops the install. In that step it installs no Python,
|
||||||
because a step above it already did. `Pipfile` names no
|
because a step above it already did. `Pipfile` names no
|
||||||
`python_version`, because `--deploy` stops when the distribution's
|
`python_version`, because `--deploy` stops when the distribution's
|
||||||
Python differs from it. The tests run after `COPY . .`, as in the Python
|
Python differs from it. The tests run after `COPY . .`, as in
|
||||||
`test` phase example in `REPO_POLICIES.md`
|
`examples/python-test-phase.Dockerfile` in the `prompts` repo
|
||||||
|
|
||||||
- Server: the final stage builds and runs the application
|
- Server: the final stage builds and runs the application
|
||||||
- Non-server: the final stage brings up the dev environment
|
- Non-server: the final stage brings up the dev environment
|
||||||
|
|||||||
+553
-726
File diff suppressed because it is too large.
Load diff
+38
-31
@@ -19,38 +19,45 @@ die() {
|
|||||||
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 ] ||
|
||||||
|
die "this is the prompts repo, where these files come from"
|
||||||
|
[ ! -e REPO_POLICIES.md ] ||
|
||||||
|
die "REPO_POLICIES.md is at the root;" \
|
||||||
|
"move it into docs/ with git mv and fix the links to it first"
|
||||||
|
|
||||||
paths=""
|
paths=""
|
||||||
for entry in $FILES; do
|
for entry in $FILES; do
|
||||||
paths="$paths ${entry#*:}"
|
paths="$paths ${entry#*:}"
|
||||||
done
|
done
|
||||||
[ -z "$(git status --porcelain -- $paths)" ] ||
|
[ -z "$(git status --porcelain -- $paths)" ] ||
|
||||||
die "commit or discard your changes to these files first:$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 "$@"
|
||||||
+22
-6
@@ -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,8 +44,8 @@ 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
|
||||||
@@ -50,6 +53,8 @@ new_repo() {
|
|||||||
|
|
||||||
new_repo "a first run writes and commits exactly the listed files"
|
new_repo "a first run writes and 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)" = \
|
[ "$(git show --name-only --format= HEAD | sort)" = \
|
||||||
@@ -57,7 +62,8 @@ script/update-policy > "$dir/output" 2>&1 || fail "exited non-zero"
|
|||||||
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"
|
||||||
@@ -77,6 +83,16 @@ echo mine > docs/REPO_POLICIES.md
|
|||||||
script/update-policy > "$dir/output" 2>&1 && fail "exited zero"
|
script/update-policy > "$dir/output" 2>&1 && fail "exited zero"
|
||||||
[ "$(cat docs/REPO_POLICIES.md)" = mine ] || fail "overwrote the change"
|
[ "$(cat docs/REPO_POLICIES.md)" = mine ] || fail "overwrote the change"
|
||||||
|
|
||||||
|
new_repo "a REPO_POLICIES.md at the root stops the script"
|
||||||
|
echo old > REPO_POLICIES.md
|
||||||
|
git add REPO_POLICIES.md
|
||||||
|
git commit -q -m "root policy file"
|
||||||
|
script/update-policy > "$dir/output" 2>&1 && fail "exited zero"
|
||||||
|
grep -q "git mv" "$dir/output" || fail "did not say to move it"
|
||||||
|
[ ! -e docs ] || fail "wrote docs/"
|
||||||
|
[ -z "$(git status --porcelain)" ] || fail "tree changed"
|
||||||
|
[ "$(git rev-list --count HEAD)" = 2 ] || fail "made a commit"
|
||||||
|
|
||||||
new_repo "the prompts repo itself is refused"
|
new_repo "the prompts repo itself is refused"
|
||||||
mkdir prompts
|
mkdir prompts
|
||||||
echo source > prompts/REPO_POLICIES.md
|
echo source > prompts/REPO_POLICIES.md
|
||||||
|
|||||||
Reference in new issue
Block a user