Repository navigation
Expand file tree
/
Copy pathpeon-code.sh
More file actions
executable file
·248 lines (235 loc) · 11.5 KB
/
Copy pathpeon-code.sh
File metadata and controls
executable file
·248 lines (235 loc) · 11.5 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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
#!/usr/bin/env bash
# Start a tmux session of collaborating AI coding agents, one per pane,
# each launched with a prompt telling it to watch the other panes.
# Usage:
# ./peon-code.sh [-c file] [<session>] [<cmd> ...]
# ./peon-code.sh resume [<session>] [<cmd> ...]
# ./peon-code.sh dismiss [<session>]
# ./peon-code.sh usage [<session>]
# ./peon-code.sh statusline [<user-command>]
# ./peon-code.sh msg <name|all> 'text' [<session>]
# ./peon-code.sh send <pane-id> 'text'|-
# ./peon-code.sh key [--submit] <pane-id> <name>
# ./peon-code.sh explain <pane-id> < selected-text
# ./peon-code.sh rebrief <name|all> [<session>]
# ./peon-code.sh swap <name> <cli|-> <model|-> <effort|-> [<session>]
# ./peon-code.sh add <name> <role> <command...> [--session <name>] [--save]
# ./peon-code.sh compact [<name|all>] [<session>]
# ./peon-code.sh clear [<name|all>] [<session>]
# ./peon-code.sh watch [<session>] [<tokens>]
# ./peon-code.sh list
# ./peon-code.sh uninstall [bin-dir]
# ./peon-code.sh -h
# Team resolution: CLI agent commands > -c file > ./peon-code.conf >
# ~/.config/peon-code/peon-code.conf > claude codex.
# Known agents get the right "interactive session + initial prompt" launch:
# claude launched bare, brief pasted in once its TUI is up; resumes with --resume <id>,
# answering a "Resume from summary" picker with its summary default
# codex positional prompt, stays interactive; resumes with resume <id>
# copilot -i <prompt> (verified on this machine); resumes with --resume=<id>
# grok positional prompt, stays interactive (verified on this machine); resumes with --resume <id>
# gemini, qwen -i <prompt> (documented; unverified on this machine); resume with --resume <id>
# Any other command is passed through as-is: <cmd> <quoted-brief>.
# The session is attached first and the CLIs start while it is on screen, their
# launch notes arriving as tmux status-line messages. The project folder is
# trusted for Claude and Codex before their agents start.
set -euo pipefail
# Resolve symlinks without readlink -f, which macOS lacks before 12.3.
script_path=${BASH_SOURCE[0]}
while [ -L "$script_path" ]; do
link_target=$(readlink "$script_path")
case $link_target in
/*) script_path=$link_target ;;
*) script_path=$(dirname -- "$script_path")/$link_target ;;
esac
done
SCRIPT_DIR=$(cd -- "$(dirname -- "$script_path")" && pwd)
PEON_VERSION=$(cat "$SCRIPT_DIR/VERSION" 2>/dev/null || echo unknown)
DEFAULT_CONF=peon-code.conf
TASK_BOARD=.peon-code-task.md
WRITER_DIR=innovation_summary
usage() {
printf 'peon-code %s\n' "$PEON_VERSION"
cat <<'USAGE'
peon-code.sh [-c file] [<session>] [<cmd> ...] start or attach a team
(session defaults to the current directory name)
peon-code.sh resume [<session>] [<cmd> ...] same, each agent reopening its last
conversation (claude, codex, copilot,
grok, gemini, qwen)
peon-code.sh dismiss [<session>] print token usage, then kill one session
(session defaults to the current directory name)
peon-code.sh usage [<session>] print token usage for one session
(session defaults to the current directory name)
peon-code.sh statusline [<user-command>] internal: the claude status line wrapper
the launch installs
peon-code.sh detach [<session>] detach every client of one session, leaving
it and its agents running
(session defaults to the current directory name)
peon-code.sh msg <name|all> 'text' [<session>] send text to an agent pane
(session defaults to the current directory name)
peon-code.sh send <pane-id> 'text'|- agent to agent: paste into a pane and
submit it; a blocked pane (typed text,
dialog, menu, copy mode) is retried up
to 10 times over ~10s before exiting
non-zero (- reads the message from stdin)
peon-code.sh explain <pane-id> explain selected text from stdin in the same pane
peon-code.sh key [--submit] <pane-id> <name> press Tab, Up, Down, Left, Right, Enter, Escape, BSpace, or C-c;
Enter answers a menu; --submit also submits box text
peon-code.sh rebrief <name|all> [<session>] send an agent its launch brief again,
for after it compacts its conversation
(session defaults to the current directory name)
peon-code.sh swap <name> <cli|-> <model|-> <effort|-> [<session>]
replace a running agent's CLI, model, or effort
peon-code.sh add <name> <role> <command...> [--session <name>] add an agent to the current team
--save keep the added agent and its role in the team config
peon-code.sh compact [<name|all>] [<session>] send /compact to an agent pane, then send
its brief again once compaction ends,
skipping any blocked pane (typed text,
dialog, menu, copy mode)
(name and session default to all and the
current directory name)
peon-code.sh clear [<name|all>] [<session>] send /clear to an agent pane, then send
its brief again, skipping any blocked
pane (typed text, dialog, menu, copy mode)
(name and session default to all and the
current directory name)
peon-code.sh watch [<session>] [<tokens>] restart dead agents and compact an agent
pane whose context reaches <tokens> (default
250000); reads its transcript when it changes,
at most once a minute; started by each launch
unless compact-at is 0 and restart-dead is no;
run it by hand only after killing that one
peon-code.sh list agent panes of every session
peon-code.sh uninstall [bin-dir] remove both installed command symlinks
peon-code.sh -h this help
peon-code.sh --version print the version
-c file agent config file (default ./peon-code.conf, then
~/.config/peon-code/peon-code.conf, if present)
Config file: one agent per line, "name command... role".
The role is required; use - for no role. A bare role name reads
roles/<name>.md next to peon-code.sh, else roles/<name>.md next to
the config file. A role token with a / is a file path,
relative paths resolving against the config file's directory.
A leading * on a name marks the main agent, whose pane gets the big
left slot; without it, the first manager, else the first agent.
Full-line # comments and blank lines are skipped.
*boss claude manager
impl codex --model gpt-5.6-sol implementer
fast codex -
weird claude ./my-roles/chaos.md
Team resolution: CLI agent commands > -c file > ./peon-code.conf >
~/.config/peon-code/peon-code.conf > claude codex.
USAGE
}
die() {
echo "peon-code: $*" >&2
exit 1
}
# shellcheck source=lib/deps.sh
source "$SCRIPT_DIR/lib/deps.sh"
# shellcheck source=lib/cli.sh
source "$SCRIPT_DIR/lib/cli.sh"
# shellcheck source=lib/tmux.sh
source "$SCRIPT_DIR/lib/tmux.sh"
# shellcheck source=lib/input.sh
source "$SCRIPT_DIR/lib/input.sh"
# shellcheck source=lib/delivery.sh
source "$SCRIPT_DIR/lib/delivery.sh"
# shellcheck source=lib/session.sh
source "$SCRIPT_DIR/lib/session.sh"
# shellcheck source=lib/commands.sh
source "$SCRIPT_DIR/lib/commands.sh"
# shellcheck source=lib/config.sh
source "$SCRIPT_DIR/lib/config.sh"
# shellcheck source=lib/resume.sh
source "$SCRIPT_DIR/lib/resume.sh"
# shellcheck source=lib/brief.sh
source "$SCRIPT_DIR/lib/brief.sh"
# shellcheck source=lib/watch.sh
source "$SCRIPT_DIR/lib/watch.sh"
# shellcheck source=lib/launch.sh
source "$SCRIPT_DIR/lib/launch.sh"
START_ARGS=("$@")
CONF=""
CONF_GIVEN=0
case "${1:-}" in
--help) usage; exit 0 ;;
--version) printf '%s\n' "$PEON_VERSION"; exit 0 ;;
esac
while getopts ":c:h" opt; do
case $opt in
c) CONF=$OPTARG; CONF_GIVEN=1 ;;
h) usage; exit 0 ;;
:) die "option -$OPTARG needs a file" ;;
*) usage >&2; die "unknown option -$OPTARG" ;;
esac
done
shift $((OPTIND - 1))
case "${1:-}" in
uninstall|statusline) ;;
*) tmux_version_ok || exit 1 ;;
esac
RESUME=0
case "${1:-}" in
resume) RESUME=1; shift ;;
dismiss) shift; cmd_dismiss "$@"; exit 0 ;;
usage) shift; cmd_usage "$@"; exit 0 ;;
statusline) shift; cmd_statusline "$@"; exit $? ;;
detach) shift; cmd_detach "$@"; exit 0 ;;
msg) shift; cmd_msg "$@"; exit 0 ;;
send) shift; cmd_send "$@"; exit 0 ;;
key) shift; cmd_key "$@"; exit 0 ;;
explain) shift; cmd_explain "$@"; exit 0 ;;
rebrief) shift; cmd_rebrief "$@"; exit 0 ;;
swap) shift; cmd_swap "$@"; exit $? ;;
add) shift; cmd_add "$@"; exit $? ;;
__swap_job)
shift
swap_job "$@" &
swap_job_pid=$!
trap 'kill -TERM "$swap_job_pid" 2>/dev/null || true; wait "$swap_job_pid" 2>/dev/null || true; exit 143' INT TERM HUP
wait "$swap_job_pid"
exit $? ;;
compact) shift; cmd_compact "$@"; exit 0 ;;
clear) shift; cmd_clear "$@"; exit 0 ;;
watch) shift; cmd_watch "$@"; exit 0 ;;
list) [ $# -eq 1 ] || die "list takes no arguments"; cmd_list; exit 0 ;;
uninstall)
for command_name in peon-code peon-code-web; do
LINK="${2:-$HOME/.local/bin}/$command_name"
if [ -L "$LINK" ] && [ "$(readlink "$LINK")" = "$SCRIPT_DIR/$command_name.sh" ]; then
continue
elif [ -e "$LINK" ] || [ -L "$LINK" ]; then
echo "not removing $LINK: it does not point at $SCRIPT_DIR/$command_name.sh" >&2
exit 1
fi
done
for command_name in peon-code peon-code-web; do
LINK="${2:-$HOME/.local/bin}/$command_name"
if [ -L "$LINK" ]; then
rm "$LINK" && echo "removed: $LINK"
else
echo "nothing to remove: $LINK does not exist"
fi
done
exit 0 ;;
esac
SESSION=$(session_name "${1:-}") # default session name: current directory
[ $# -gt 0 ] && shift
load_team "$@"
if [ $# -eq 0 ] && [ -f "$CONF" ]; then
CONF="$(cd -- "$(dirname -- "$CONF")" && pwd)/$(basename -- "$CONF")"
else
CONF=""
fi
N=${#NAMES[@]}
# A pull rewrites this file under a bash that reads it lazily, so restart on
# the new code before anything else runs.
if offer_update local; then
exec "$script_path" ${START_ARGS[@]+"${START_ARGS[@]}"}
fi
if tmux has-session -t "=$SESSION" 2>/dev/null; then
is_peon_session "$SESSION" || die "session $SESSION already exists and was not created by peon-code"
goto_session "$SESSION"
fi
launch_team