Repository navigation
Expand file tree
/
Copy pathsync.sh
More file actions
executable file
·48 lines (42 loc) · 1.69 KB
/
Copy pathsync.sh
File metadata and controls
executable file
·48 lines (42 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env bash
# Regenerates copilot/agents/ and codex/prompts/ from agents/ (the canonical source).
# Edit roles ONLY in agents/*.md, then run ./sync.sh.
# ./sync.sh --check : regenerate, then fail if generated files differ from git HEAD
# (catches stale exports AND hand-edited generated copies). Used by CI.
set -euo pipefail
cd "$(dirname "$0")"
CHECK=0
[ "${1:-}" = "--check" ] && CHECK=1
rm -rf copilot/agents codex/prompts
mkdir -p copilot/agents codex/prompts
for f in agents/*.md; do
name=$(sed -n 's/^name: //p' "$f" | head -1)
desc=$(sed -n 's/^description: //p' "$f" | head -1)
# body = everything after the closing --- of the frontmatter
body=$(awk '/^---$/{c++; next} c>=2' "$f")
# GitHub Copilot custom agent (.github/agents/<name>.md)
{
printf -- '---\nname: %s\ndescription: %s\n---\n\n' "$name" "$desc"
printf '%s\n' "$body"
} > "copilot/agents/$name.md"
# OpenAI Codex custom prompt (.codex/prompts/<name>.md, invoked as /<name>)
{
printf '# Role: %s\n\n' "$name"
printf 'Adopt this role for the current task. %s\n\n' "$desc"
printf '%s\n' "$body"
} > "codex/prompts/$name.md"
done
count=$(ls agents/*.md | wc -l | tr -d ' ')
echo "Synced $count roles -> copilot/agents/ and codex/prompts/"
if [ "$CHECK" -eq 1 ]; then
if ! git rev-parse --git-dir >/dev/null 2>&1; then
echo "--check requires a git repository" >&2
exit 2
fi
if [ -n "$(git status --porcelain -- copilot/agents codex/prompts)" ]; then
echo "DRIFT: generated files don't match agents/. Run ./sync.sh and commit the result:" >&2
git status --porcelain -- copilot/agents codex/prompts >&2
exit 1
fi
echo "Generated files in sync with agents/."
fi