diff --git a/.pi/skills/pi-tmux-test.md b/.pi/skills/pi-tmux-test.md new file mode 100644 index 00000000..d79761fa --- /dev/null +++ b/.pi/skills/pi-tmux-test.md @@ -0,0 +1,64 @@ +--- +name: pi-tmux-test +description: Test pi's interactive mode via tmux. Use when you need to test TUI behavior, extensions, or interactive features programmatically. +--- + +# Testing Pi Interactively via tmux + +Use tmux to test pi's interactive mode. This allows sending input and capturing output programmatically. + +## Setup + +```bash +# Kill any existing test session and create a new one +tmux kill-session -t pi-test 2>/dev/null +tmux new-session -d -s pi-test -c /Users/badlogic/workspaces/pi-mono -x 100 -y 30 + +# Start pi using the test script (runs via tsx, picks up source changes) +# Always use --no-session to avoid creating session files during testing +tmux send-keys -t pi-test "./pi-test.sh --no-session" Enter + +# Wait for startup +sleep 4 +tmux capture-pane -t pi-test -p +``` + +## Interaction + +```bash +# Send input +tmux send-keys -t pi-test "your message here" Enter + +# Wait and capture output +sleep 5 +tmux capture-pane -t pi-test -p + +# Send special keys +tmux send-keys -t pi-test Escape +tmux send-keys -t pi-test C-c # Ctrl+C +tmux send-keys -t pi-test C-d # Ctrl+D +``` + +## Cleanup + +```bash +tmux kill-session -t pi-test +``` + +## Testing Extensions + +Write extensions to /tmp and load with `-e`: + +```bash +cat > /tmp/test-extension.ts << 'EOF' +import type { ExtensionAPI } from "@mariozechner/pi-coding-agent"; +export default function (pi: ExtensionAPI) { + // extension code +} +EOF + +# Run pi with the extension +tmux send-keys -t pi-test "./pi-test.sh --no-session -e /tmp/test-extension.ts" Enter +``` + +Clean up after testing: `rm /tmp/test-extension.ts` diff --git a/AGENTS.md b/AGENTS.md index e8bdff27..dd6d39c0 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -49,7 +49,7 @@ When closing issues via commit: ## Tools - GitHub CLI for issues/PRs - Add package labels to issues/PRs: pkg:agent, pkg:ai, pkg:coding-agent, pkg:mom, pkg:pods, pkg:tui, pkg:web-ui -- TUI interaction: use tmux +- See pi-tmux-test skill if you need to test pi interactive mode ## Style - Keep answers short and concise diff --git a/packages/coding-agent/src/modes/interactive/interactive-mode.ts b/packages/coding-agent/src/modes/interactive/interactive-mode.ts index 29a7e784..6e18fe21 100644 --- a/packages/coding-agent/src/modes/interactive/interactive-mode.ts +++ b/packages/coding-agent/src/modes/interactive/interactive-mode.ts @@ -2075,6 +2075,10 @@ export class InteractiveMode { }); } + // Wait for any pending renders to complete + // requestRender() uses process.nextTick(), so we wait one tick + await new Promise((resolve) => process.nextTick(resolve)); + this.stop(); process.exit(0); }