44 lines
1.1 KiB
Bash
Executable File
44 lines
1.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# description: Generate a JIT subagent config. No args prints the JSON template. With JSON on stdin, creates the config and prints the agent name.
|
|
# Args: none
|
|
# Stdin: JSON with "prompt" (required) and optional "name"
|
|
# Output: template (no stdin) or agent name
|
|
set -euo pipefail
|
|
|
|
OLLIE="${OLLIE:-$HOME/mnt/ollie}"
|
|
|
|
die() { printf 'agent_generate: %s\n' "$*" >&2; exit 1; }
|
|
|
|
if [ -t 0 ] && [ $# -eq 0 ]; then
|
|
printf '{\n "name": "",\n "prompt": ""\n}\n'
|
|
exit 0
|
|
fi
|
|
|
|
cfg=$(cat) || die "failed to read stdin"
|
|
[ -z "$cfg" ] && die "empty input"
|
|
|
|
name=$(printf '%s' "$cfg" | python3 -c "
|
|
import json, sys
|
|
|
|
raw = json.load(sys.stdin)
|
|
name = raw.get('name', '') or 'jit-' + __import__('secrets').token_hex(8)
|
|
prompt = raw.get('prompt', '')
|
|
if not prompt:
|
|
print('error: prompt required', file=sys.stderr)
|
|
sys.exit(1)
|
|
|
|
base = sys.argv[1]
|
|
with open(base) as f:
|
|
cfg = json.load(f)
|
|
|
|
cfg['prompt'] = ['SYSTEM_PROMPT', prompt]
|
|
|
|
out = sys.argv[2] + '/' + name + '.json'
|
|
with open(out, 'w') as f:
|
|
json.dump(cfg, f, indent=2)
|
|
|
|
print(name)
|
|
" "$OLLIE/a/default.json" "$OLLIE/a") || die "failed to generate agent config"
|
|
|
|
printf '%s\n' "$name"
|