feat: implement --onboard flag in multi-agent-mux-create and update AGENT.md onboarding handshake protocol

This commit is contained in:
2026-06-28 10:42:23 +09:00
parent 6e3c866461
commit ef57749e9f
5 changed files with 135 additions and 2 deletions
+63
View File
@@ -826,4 +826,67 @@ start_watchdog() {
echo "$pid"
}
# wait_for_tui_ready <session_name> <agent>
# Gated wait to ensure that the agent's TUI is fully loaded and responsive
# before injecting any keyboard instructions.
wait_for_tui_ready() {
local sess="$1" agent="$2"
local local_tmux="tmux"
if [ -n "${TMUX_SERVER_NAME:-}" ] && [ "$TMUX_SERVER_NAME" != "default" ]; then
local_tmux="tmux -L $TMUX_SERVER_NAME"
fi
echo "🔍 Waiting for $agent TUI to become ready..."
for i in {1..15}; do
local content
content=$($local_tmux capture-pane -p -t "$sess" 2>/dev/null || echo "")
if [ -n "$content" ]; then
case "$agent" in
claude)
if echo "$content" | grep -E -q "Anthropic|Assistant|Chat|Dangerously|dangerously|Enter|Welcome|projects" 2>/dev/null; then
echo "✅ Claude TUI detected ready."
return 0
fi
;;
agy)
if echo "$content" | grep -q "Antigravity" 2>/dev/null; then
echo "✅ Antigravity TUI detected ready."
return 0
fi
;;
hermes)
if echo "$content" | grep -q "Hermes" 2>/dev/null; then
echo "✅ Hermes TUI detected ready."
return 0
fi
;;
cline)
if echo "$content" | grep -E -q "Cline|history|Chat" 2>/dev/null; then
echo "✅ Cline TUI detected ready."
return 0
fi
;;
esac
fi
sleep 1
done
echo "⚠️ Warning: TUI readiness check timed out. Proceeding anyway..."
}
# inject_instructions <session_name> <instructions> [job_id]
# Injects instructions into the tmux session using paste-buffer and C-m.
inject_instructions() {
local sess="$1" instructions="$2" job_id="${3:-onboard}"
local local_tmux="tmux"
if [ -n "${TMUX_SERVER_NAME:-}" ] && [ "$TMUX_SERVER_NAME" != "default" ]; then
local_tmux="tmux -L $TMUX_SERVER_NAME"
fi
$local_tmux set-buffer -b "job_buf_$job_id" "$instructions"
$local_tmux paste-buffer -b "job_buf_$job_id" -t "$sess"
sleep 0.5
$local_tmux send-keys -t "$sess" C-m
$local_tmux delete-buffer -b "job_buf_$job_id"
}
@@ -81,6 +81,11 @@ To prevent this, you can run this skill inside an **isolated tmux server** using
```bash
bash scripts/create_session.sh --workspace /path/to/project --agent claude --role developer --submit-job "Task prompt here"
```
4. **Onboard Integration**:
You can automatically submit a project alignment/orientation job to the new agent when creating a session:
```bash
bash scripts/create_session.sh --workspace /path/to/project --agent claude --role developer --onboard
```
### Recommended Alias
You can set an alias in your shell to easily query sessions on the isolated server:
@@ -34,6 +34,7 @@ Options:
--dry-run print commands without executing
--tmux-server NAME specify isolated tmux server name
--submit-job PROMPT submit a job to multi-agent-mux-delegate-job registry with the given prompt
--onboard automatically submit a project alignment/orientation job to the new agent
-h, --help this help
EOF
}
@@ -46,6 +47,7 @@ USE_WRAPPER=0
DRY_RUN=0
TMUX_SERVER_OPT=""
SUBMIT_JOB_PROMPT=""
ONBOARD=0
while [ $# -gt 0 ]; do
case "$1" in
@@ -57,6 +59,7 @@ while [ $# -gt 0 ]; do
--dry-run) DRY_RUN=1; shift ;;
--tmux-server) TMUX_SERVER_OPT="$2"; shift 2 ;;
--submit-job) SUBMIT_JOB_PROMPT="$2"; shift 2 ;;
--onboard) ONBOARD=1; shift ;;
-h|--help) usage; exit 0 ;;
*) echo "ERROR: unknown arg: $1" >&2; usage; exit 2 ;;
esac
@@ -143,7 +146,7 @@ fi
spawn
# TUI 준비 대기
sleep 6
wait_for_tui_ready "$SESSION_NAME" "$AGENT"
# pane 메타 캡처
PANE_PID=$(_tmux list-panes -t "$SESSION_NAME" -F '#{pane_pid}' 2>/dev/null || echo "")
@@ -179,6 +182,15 @@ case "$AGENT" in
;;
esac
# If --onboard is specified, automatically build the onboarding prompt
if [ "$ONBOARD" = "1" ] && [ -z "$SUBMIT_JOB_PROMPT" ]; then
SUBMIT_JOB_PROMPT="You are a newly spawned $ROLE Team Leader agent in this workspace. To align yourself with the project context, perform the following tasks:
1. Read the project documentation at README.md and the multi-agent protocol guidelines at .agents/AGENT.md to understand the design rules.
2. Run 'git status' and 'git diff' to analyze the current modifications and active work in the repository.
3. Read .mam/agent-sessions.yaml to see other running agent sessions, their roles, and confirm your own assigned role: $ROLE.
4. Once you have fully comprehended the project state, publish a completed event (using publish_event.py) with the detail 'Onboarding complete; aligned with role $ROLE'."
fi
# agent-sessions.yaml 에 append
DELEGATE_JOB_ID=""
if [ -n "$SUBMIT_JOB_PROMPT" ]; then
@@ -301,7 +313,22 @@ echo "=== created ==="
echo "tmux session: $SESSION_NAME (pane pid $PANE_PID, cmd $PANE_CMD, cwd $PANE_CWD)"
if [ -n "$DELEGATE_JOB_ID" ]; then
echo "delegate job: $DELEGATE_JOB_ID"
delegate_publish_event "$DELEGATE_JOB_ID" started "multi-agent-mux session created"
# Construct instructions matching multi-agent-mux-delegate-job format
pub="python3 .agents/skills/multi-agent-mux-delegate-job/scripts/publish_event.py --job $DELEGATE_JOB_ID"
instructions="Your job_id is \"$DELEGATE_JOB_ID\" (the one just registered for THIS delegation).
On start run: $pub --event started.
On progress (optional): $pub --event progress --detail '<short status>'.
On success run: $pub --event completed --detail '<one-line summary>'.
On failure run: $pub --event error --detail '<one-line reason>'.
Task: $SUBMIT_JOB_PROMPT"
# Inject instructions into the tmux pane
inject_instructions "$SESSION_NAME" "$instructions" "$DELEGATE_JOB_ID"
delegate_publish_event "$DELEGATE_JOB_ID" started "multi-agent-mux session created and instructions injected"
WD_PID=$(start_watchdog "$DELEGATE_JOB_ID" "$WORKSPACE")
echo "watchdog PID: $WD_PID"
fi