Files
projekt-plattform/skill/scripts/projekt_id.sh

33 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
# Fragt den lokalen Agenten (agent/, Befehl "projekt-agent serve") nach der Projekt-ID; der Agent fragt das Register.
# Aufruf: projekt_id.sh "<Projektname>" [Projektordner] Ausgabe: die ID (P-nnnn) auf stdout
# Umgebung: AGENT_URL (Standard http://127.0.0.1:8746)
# Das Projekt braucht ein Git-Repo mit Remote "origin" unterhalb der Projektwurzel des Agenten.
# Das Skript schreibt nichts ins Projekt: die ID trägt der Assistent in den Kopf der ROADMAP.md ein.
set -euo pipefail
name="${1:?Projektname fehlt}"
dir="${2:-.}"
url="${AGENT_URL:-http://127.0.0.1:8746}"
if ! dir="$(cd "$dir" 2>/dev/null && pwd -P)"; then
echo "Fehler: Ordner '${2:-.}' gibt es nicht." >&2
exit 1
fi
antwort="$(python3 -I - "$name" "$dir" <<'PY' | curl -sS --max-time 15 -H 'Content-Type: application/json' --data-binary @- -w '\n%{http_code}' "$url/api/projekt-id" 2>/dev/null || true
import json, sys
print(json.dumps({"name": sys.argv[1], "ordner": sys.argv[2]}))
PY
)"
code="${antwort##*$'\n'}"
body="${antwort%$'\n'*}"
if [ "$code" = "200" ]; then
python3 -I -c 'import json,sys; d=json.loads(sys.stdin.read()); [print("Hinweis:", w, file=sys.stderr) for w in d["warnungen"]]; print(d["id"])' <<<"$body"
exit 0
fi
if [ -z "$code" ] || [ "$code" = "000" ] || [ "$code" = "$antwort" ]; then
echo "Fehler: Der Agent unter $url ist nicht erreichbar (Start: projekt-agent serve). Projekt ohne ID anlegen: Projekt-ID 'offen' und später nachholen." >&2
else
grund="$(python3 -I -c 'import json,sys; print(json.loads(sys.stdin.read()).get("fehler",""))' <<<"$body" 2>/dev/null || true)"
echo "Fehler: ${grund:-Antwort $code vom Agenten}. Projekt ohne ID anlegen: Projekt-ID 'offen' und später nachholen." >&2
fi
exit 1