-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathbuild-system-prompt.sh
More file actions
executable file
·76 lines (67 loc) · 2.25 KB
/
Copy pathbuild-system-prompt.sh
File metadata and controls
executable file
·76 lines (67 loc) · 2.25 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/env bash
# build-system-prompt.sh — Build a system prompt file for non-gptme harnesses
#
# Reads gptme.toml to extract bootstrap identity files and runs context_cmd.
# Output is suitable for --append-system-prompt-file with Claude Code or similar.
#
# Usage:
# ./scripts/context/build-system-prompt.sh [WORKSPACE]
# WORKSPACE=/path/to/agent ./scripts/context/build-system-prompt.sh
set -euo pipefail
if [ -n "${1:-}" ]; then
WORKSPACE="$1"
elif [ -n "${WORKSPACE:-}" ]; then
: # Use existing WORKSPACE
else
# Find agent root (directory with gptme.toml) via shared helper
# shellcheck source=scripts/context/find-agent-root.sh
. "$(dirname "$0")/find-agent-root.sh"
WORKSPACE="$(find_agent_root)" || {
echo "Error: Could not find gptme.toml in any parent directory of $PWD" >&2
echo "Run from your agent workspace directory, or pass WORKSPACE=/path/to/agent" >&2
exit 1
}
fi
# --- Read gptme.toml config ---
read_toml_config() {
WORKSPACE="$WORKSPACE" python3 -c "
import tomllib, json, sys, os
with open(os.environ['WORKSPACE'] + '/gptme.toml', 'rb') as f:
cfg = tomllib.load(f)
prompt = cfg.get('prompt', {})
json.dump({
'files': prompt.get('files', []),
'context_cmd': prompt.get('context_cmd', ''),
}, sys.stdout)
"
}
CONFIG=$(read_toml_config)
CONTEXT_CMD=$(echo "$CONFIG" | python3 -c "import json,sys; print(json.load(sys.stdin)['context_cmd'])")
# --- Bootstrap identity files ---
echo "# Bootstrap Identity Files"
echo ""
python3 -c "import json,sys; [print(f) for f in json.load(sys.stdin)['files']]" <<< "$CONFIG" | while IFS= read -r f; do
filepath="$WORKSPACE/$f"
if [ -f "$filepath" ]; then
echo "## FILE: $f"
echo ""
cat "$filepath"
echo ""
echo "---"
echo ""
fi
done
# --- Dynamic context (context_cmd from gptme.toml) ---
echo "# Dynamic Context"
echo ""
if [ -n "$CONTEXT_CMD" ]; then
# Handle both absolute paths and paths relative to workspace
case "$CONTEXT_CMD" in
/*) CMD="$CONTEXT_CMD" ;;
*) CMD="$WORKSPACE/$CONTEXT_CMD" ;;
esac
# shellcheck disable=SC2086
$CMD "$WORKSPACE" 2>/dev/null || echo "(context generation failed)"
else
echo "(no context_cmd configured in gptme.toml)"
fi