chore: add project docs and agent workflow setup

This commit is contained in:
kasun committed 2026-11-15 14:36:06 +01:00
1 parent b647343c99
commit 95e1b9cb89
15 files changed
+894 -1

No files matched your search

+29
View File
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
# Stop hook: block "done" while ruff or tests fail on changed Python code.
input=$(cat)
[[ "$(jq -r '.stop_hook_active // false' <<<"$input")" == "true" ]] && exit 0
cd "$CLAUDE_PROJECT_DIR" || exit 0
[[ -f pyproject.toml ]] || exit 0
command -v uv >/dev/null || exit 0
# -uall lists files inside new folders (e.g. a fresh src/), not just the folder.
git status --porcelain -uall | grep -q '\.py$' || exit 0
if ! out=$(uv run --quiet ruff check . 2>&1); then
echo "ruff check failed, fix before finishing:" >&2
tail -n 30 <<<"$out" >&2
exit 2
fi
if grep -q pyright pyproject.toml && ! out=$(uv run --quiet pyright 2>&1); then
echo "pyright failed, fix before finishing:" >&2
tail -n 30 <<<"$out" >&2
exit 2
fi
out=$(uv run --quiet pytest -q -x 2>&1)
status=$?
# 0 = passed, 5 = no tests collected yet; neither should block.
if [[ $status -ne 0 && $status -ne 5 ]]; then
echo "pytest failed, fix before finishing:" >&2
tail -n 40 <<<"$out" >&2
exit 2
fi
exit 0
+10
View File
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
# PostToolUse hook: format and lint-fix a Python file after Claude edits it.
file=$(jq -r '.tool_input.file_path // empty')
[[ "$file" == *.py && -f "$file" ]] || exit 0
command -v uv >/dev/null || exit 0
cd "$CLAUDE_PROJECT_DIR" || exit 0
[[ -f pyproject.toml ]] || exit 0
uv run --quiet ruff format "$file" >/dev/null 2>&1
uv run --quiet ruff check --fix "$file" >/dev/null 2>&1
exit 0
+45
View File
@@ -0,0 +1,45 @@
#!/usr/bin/env bash
# Gitea API helper for managing this project (issues, labels, milestones, board, PRs).
# Not part of the Deverenz product.
#
# Usage: gitea.sh METHOD PATH [BODY]
# METHOD GET | POST | PATCH | PUT | DELETE
# PATH path below /api/v1, e.g. /repos/<owner>/<repo>/issues?state=open
# BODY JSON string, or @file to send a file
#
# Config (outside the repo, never committed):
# ${XDG_CONFIG_HOME:-~/.config}/deverenz-agent/url e.g. http://gitea.local:3000
# ${XDG_CONFIG_HOME:-~/.config}/deverenz-agent/token agent account token, chmod 600
set -euo pipefail
method=${1:?usage: gitea.sh METHOD PATH [BODY]}
path=${2:?usage: gitea.sh METHOD PATH [BODY]}
body=${3:-}
case "$method" in
GET | POST | PATCH | PUT | DELETE) ;;
*) echo "unsupported method: $method" >&2; exit 2 ;;
esac
config=${XDG_CONFIG_HOME:-$HOME/.config}/deverenz-agent
for f in url token; do
[[ -s "$config/$f" ]] || { echo "missing $config/$f (see CLAUDE.local.md)" >&2; exit 2; }
done
url=$(<"$config/url")
token=$(<"$config/token")
args=(-sS --fail-with-body -X "$method" -H "Accept: application/json")
# The token header is read from stdin so it never shows up in the process list.
args+=(-H @-)
if [[ -n "$body" ]]; then
[[ "$body" == "@-" ]] && { echo "BODY from stdin is not supported, use @file" >&2; exit 2; }
args+=(-H "Content-Type: application/json" --data-binary "$body")
fi
out=$(curl "${args[@]}" "${url%/}/api/v1${path}" <<<"Authorization: token $token") \
|| { echo "$out" >&2; exit 1; }
if command -v jq >/dev/null && [[ -n "$out" ]]; then
jq . <<<"$out" 2>/dev/null || echo "$out"
else
echo "$out"
fi
+68
View File
@@ -0,0 +1,68 @@
{
"$schema": "https://json.schemastore.org/claude-code-settings.json",
"attribution": {
"commit": "",
"pr": ""
},
"permissions": {
"allow": [
"Bash(uv sync:*)",
"Bash(uv add:*)",
"Bash(uv run pytest:*)",
"Bash(uv run ruff:*)",
"Bash(git status:*)",
"Bash(git diff:*)",
"Bash(git log:*)",
"Bash(git show:*)",
"Bash(git add:*)",
"Bash(docker compose ps:*)",
"Bash(docker compose logs:*)",
"Bash(docker compose up:*)",
"Bash(docker compose down)",
"Bash(curl http://localhost:*)"
],
"ask": [
"Bash(uv run deverenz:*)",
"Bash(git commit:*)",
"Bash(git push:*)",
"Bash(docker compose down -v:*)",
"Bash(.claude/scripts/gitea.sh POST:*)",
"Bash(.claude/scripts/gitea.sh PATCH:*)",
"Bash(.claude/scripts/gitea.sh PUT:*)",
"Bash(.claude/scripts/gitea.sh DELETE:*)"
],
"deny": [
"Read(./.env)",
"Read(./.env.local)",
"Read(./.env.production)",
"Bash(cat .env:*)",
"Read(~/.config/deverenz-agent/**)",
"Bash(cat ~/.config/deverenz-agent:*)",
"Bash(rm -rf:*)"
]
},
"hooks": {
"PostToolUse": [
{
"matcher": "Edit|Write",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/ruff-format.sh"
}
]
}
],
"Stop": [
{
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/check-on-stop.sh",
"timeout": 300
}
]
}
]
}
}