mirror of
https://github.com/codeflash-ai/codeflash-agent.git
synced 2026-05-04 18:25:19 +00:00
96 lines
3.5 KiB
Bash
Executable file
96 lines
3.5 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# SessionStart hook: Scaffold .codeflash/{org}/{project}/ if it doesn't exist.
|
|
# Infers org/project from git remote origin. File generation is delegated to
|
|
# scripts/scaffold.sh — the single source of truth for project scaffolding.
|
|
|
|
cd "$CLAUDE_PROJECT_DIR" 2>/dev/null || exit 0
|
|
|
|
CF_DIR="$CLAUDE_PROJECT_DIR/.codeflash"
|
|
SCAFFOLD="$CLAUDE_PROJECT_DIR/scripts/scaffold.sh"
|
|
|
|
# Parse git remote origin
|
|
REMOTE=$(git remote get-url origin 2>/dev/null)
|
|
if [ -z "$REMOTE" ]; then
|
|
if [ -d "$CF_DIR" ]; then
|
|
exit 0
|
|
fi
|
|
cat <<'EOF'
|
|
{
|
|
"systemMessage": "No .codeflash/ directory found and no git remote origin to infer org/project. Ask the user for the organization and project name, then run: bash scripts/scaffold.sh <org> <project> .codeflash/<org>/<project>"
|
|
}
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
# Extract org/project from common remote formats:
|
|
# git@github.com:org/project.git
|
|
# https://github.com/org/project.git
|
|
# ssh://git@github.com/org/project.git
|
|
ORG=""
|
|
PROJECT=""
|
|
|
|
if echo "$REMOTE" | grep -qE '^git@'; then
|
|
PATH_PART=$(echo "$REMOTE" | sed -E 's/^git@[^:]*://' | sed 's/\.git$//')
|
|
ORG=$(echo "$PATH_PART" | cut -d'/' -f1)
|
|
PROJECT=$(echo "$PATH_PART" | cut -d'/' -f2)
|
|
elif echo "$REMOTE" | grep -qE '^https?://'; then
|
|
PATH_PART=$(echo "$REMOTE" | sed -E 's|^https?://[^/]*/||' | sed 's/\.git$//')
|
|
ORG=$(echo "$PATH_PART" | cut -d'/' -f1)
|
|
PROJECT=$(echo "$PATH_PART" | cut -d'/' -f2)
|
|
elif echo "$REMOTE" | grep -qE '^ssh://'; then
|
|
PATH_PART=$(echo "$REMOTE" | sed -E 's|^ssh://[^/]*/||' | sed 's/\.git$//')
|
|
ORG=$(echo "$PATH_PART" | cut -d'/' -f1)
|
|
PROJECT=$(echo "$PATH_PART" | cut -d'/' -f2)
|
|
fi
|
|
|
|
# Lowercase org and project
|
|
ORG=$(echo "$ORG" | tr '[:upper:]' '[:lower:]')
|
|
PROJECT=$(echo "$PROJECT" | tr '[:lower:]' '[:lower:]')
|
|
|
|
if [ -z "$ORG" ] || [ -z "$PROJECT" ]; then
|
|
if [ -d "$CF_DIR" ]; then
|
|
exit 0
|
|
fi
|
|
cat <<'EOF'
|
|
{
|
|
"systemMessage": "No .codeflash/ directory found. Could not parse org/project from git remote. Ask the user for the organization and project name, then run: bash scripts/scaffold.sh <org> <project> .codeflash/<org>/<project>"
|
|
}
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
PROJECT_DIR="$CF_DIR/$ORG/$PROJECT"
|
|
|
|
# Skip bootstrap when working on the agent repo itself
|
|
if [ "$ORG" = "codeflash-ai" ] && [ "$PROJECT" = "codeflash-agent" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Ensure observability dir exists
|
|
mkdir -p "$CF_DIR/observability"
|
|
|
|
# Already initialized — tell Claude to read the existing files
|
|
if [ -d "$PROJECT_DIR" ]; then
|
|
cat <<EOF
|
|
{
|
|
"systemMessage": "Read $PROJECT_DIR/status.md and $PROJECT_DIR/data/results.tsv to understand current project state before starting work. Benchmark scripts are in $PROJECT_DIR/bench/, VM infra is in $PROJECT_DIR/infra/."
|
|
}
|
|
EOF
|
|
exit 0
|
|
fi
|
|
|
|
# Scaffold using the shared generator
|
|
if [ -x "$SCAFFOLD" ]; then
|
|
bash "$SCAFFOLD" "$ORG" "$PROJECT" "$PROJECT_DIR"
|
|
else
|
|
echo "Warning: $SCAFFOLD not found, cannot scaffold" >&2
|
|
exit 0
|
|
fi
|
|
|
|
cat <<EOF
|
|
{
|
|
"systemMessage": "Scaffolded $PROJECT_DIR/ with status.md, bench/, data/results.tsv, infra/cloud-init.yaml, and infra/vm-manage.sh. Fill in: $PROJECT_DIR/status.md with current project state, completed work, next steps, and blockers; $PROJECT_DIR/data/results.tsv with benchmark results as they are collected; $PROJECT_DIR/bench/ with project-specific benchmark scripts; $PROJECT_DIR/infra/cloud-init.yaml with project-specific setup and benchmark file entries; $PROJECT_DIR/infra/vm-manage.sh is ready to use -- run 'bash $PROJECT_DIR/infra/vm-manage.sh create' to provision."
|
|
}
|
|
EOF
|
|
|
|
exit 0
|