-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathcopilot-cli.sh
More file actions
executable file
·88 lines (74 loc) · 2.49 KB
/
copilot-cli.sh
File metadata and controls
executable file
·88 lines (74 loc) · 2.49 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
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env bash
# Adapter: copilot-cli
# Capabilities: model-select, auto-approve, background
#
# Unified interface for invoking GitHub Copilot CLI.
#
# Usage:
# scripts/launch/adapters/copilot-cli.sh [options]
#
# Options:
# --prompt "..." Task prompt (mutually exclusive with --prompt-file)
# --prompt-file file.md Read prompt from file (mutually exclusive with --prompt)
# --max-turns N Mapped to --max-autopilot-continues (0=unlimited, omits flag)
# --model MODEL AI model to use (default: $COPILOT_MODEL or Copilot CLI default)
# --log output.log Log file path (required)
# --background Run in background, print PID to stdout (default: foreground)
# --help Show this help
set -euo pipefail
PROMPT=""
PROMPT_FILE=""
MAX_TURNS=""
MODEL="${COPILOT_MODEL:-}"
LOG_FILE=""
BACKGROUND=false
for arg in "$@"; do
case "$arg" in
--prompt=*) PROMPT="${arg#*=}" ;;
--prompt-file=*) PROMPT_FILE="${arg#*=}" ;;
--max-turns=*) MAX_TURNS="${arg#*=}" ;;
--model=*) MODEL="${arg#*=}" ;;
--log=*) LOG_FILE="${arg#*=}" ;;
--background) BACKGROUND=true ;;
--help|-h)
sed -n '2,/^$/{ s/^# //; s/^#//; p }' "$0"
exit 0
;;
*) echo "copilot-cli adapter: unknown option: $arg" >&2; exit 1 ;;
esac
done
# ── Validate arguments ──
if [[ -n "$PROMPT" && -n "$PROMPT_FILE" ]]; then
echo "copilot-cli adapter: --prompt and --prompt-file are mutually exclusive" >&2
exit 1
fi
if [[ -z "$PROMPT" && -z "$PROMPT_FILE" ]]; then
echo "copilot-cli adapter: one of --prompt or --prompt-file is required" >&2
exit 1
fi
if [[ -z "$LOG_FILE" ]]; then
echo "copilot-cli adapter: --log is required" >&2
exit 1
fi
# ── Resolve prompt ──
if [[ -n "$PROMPT_FILE" ]]; then
if [[ ! -f "$PROMPT_FILE" ]]; then
echo "copilot-cli adapter: prompt file not found: $PROMPT_FILE" >&2
exit 1
fi
PROMPT="$(cat "$PROMPT_FILE")"
fi
# ── Build command ──
#
# Note: --background is handled by the caller (launch scripts use & directly).
# The adapter always runs the command in the foreground and redirects to log.
# Copilot CLI reads skills from .github/skills/ in the repo root.
CMD=(copilot -p "$PROMPT" --allow-all)
if [[ -n "$MODEL" ]]; then
CMD+=(--model "$MODEL")
fi
# Map --max-turns to --max-autopilot-continues (skip if 0 = unlimited)
if [[ -n "$MAX_TURNS" && "$MAX_TURNS" != "0" ]]; then
CMD+=(--max-autopilot-continues "$MAX_TURNS")
fi
"${CMD[@]}" > "$LOG_FILE" 2>&1