Skip to content

feat: add pi CLI support and clis prompt terminal command#11

Open
ducphamhoang wants to merge 1 commit into
longbkit:mainfrom
ducphamhoang:feat/pi-cli-and-prompt-terminal
Open

feat: add pi CLI support and clis prompt terminal command#11
ducphamhoang wants to merge 1 commit into
longbkit:mainfrom
ducphamhoang:feat/pi-cli-and-prompt-terminal

Conversation

@ducphamhoang

Copy link
Copy Markdown

Summary

  • Adds pi (https://pi.dev) as a fourth supported agent CLI tool alongside codex, claude, and gemini
  • Adds clis prompt command for terminal-based agent interaction without Slack/Telegram
  • Fixes process.execPath bug in runner launch that broke exit-record writing in nvm environments

Pi CLI integration

Session lifecycle (verified live against pi 0.75.5)

1. pi starts normally — auto-generates a session UUID
2. clisbot sends /session → pi outputs "ID: <uuid>" → captured via status-command mode
3. Resume: pi --session <uuid>

Pi's /session command outputs the current session ID, so it uses the existing status-command capture mechanism — no new infrastructure required.

Schema & config

  • newSessionCommand field added to runner template types and Zod schemas, resolved through the standard template override chain
  • pi registered as a valid agentCLITool with default template (create.mode=runner, capture.statusCommand=/session, resume via --session)

Session routing (runner-service.ts)

  • Pi captures session IDs via /session (same pattern as codex/gemini), so it participates in standard live rotation — no special routing bypass needed
  • retryFreshStartAfterStoredResumeFailure gate already handles create.mode=runner, so pi sessions survive crash recovery with no changes

Transcript normalization

  • looksLikePiSnapshot: detects pi output; excludes bare > to avoid false positives with shell prompts
  • shouldDropPiChromeLine: drops pi help-bar and working-status chrome while preserving Warning/Note content
  • dropPiPromptBlocks: strips prompt echo blocks that pi re-emits before AI responses

Also fixes

  • buildRunnerFromToolTemplate: preserve per-element resume args for non-codex runners (was incorrectly flattening arrays)
  • Guard isPi detection against collision with Gemini output patterns

Tests: 54 chrome normalization tests, session routing tests, startup blocker coverage, schema defaults tests

clis prompt command

New clis prompt CLI command for sending a message to a running clisbot agent from the terminal and receiving the response on stdout — useful for scripting and local dev without a Slack or Telegram surface.

clis prompt --agent <id> --message <text> [--stream] [--json]
  • src/control/prompt-cli.ts: runPromptCli using buildSteeringPromptText
  • cli.ts / main.ts: prompt command added to CLI routing
  • auth/resolve.ts: terminal:senderId principal resolved correctly
  • channels/rendering.ts: plain-text renderer for terminal platform (no Slack/Telegram decorators)
  • test/prompt-cli.test.ts: 12 tests covering auth principal, rendering, and help output

Standalone fixes

  • process.execPath in runner launch (runner-exit-diagnostics.ts): bare node is not guaranteed to be in PATH inside tmux when using nvm. Using process.execPath ensures the exit-record writer uses the same Node binary running clisbot.
  • shellQuote escape fix: single-quote escape was '\"'\"' (incorrect), now '"'"' (correct POSIX).

Test plan

  • bun test test/text/text-cleaning-chrome.suite.ts — 54 pi chrome normalization tests pass
  • bun test test/runner-service.integration.test.ts — pi session and routing tests pass
  • bun test test/prompt-cli.test.ts — 12 terminal prompt tests pass
  • bun run check — full typecheck + test suite passes

🤖 Generated with Claude Code

Adds two new capabilities:

1. pi (https://pi.dev) as a fourth supported agent tool
2. clis prompt command for terminal-based agent interaction

--- Pi CLI integration ---

Session lifecycle verified live against pi 0.75.5:
  1. pi starts and auto-generates a session UUID
  2. /session command outputs "ID: <uuid>" — captured via status-command mode
  3. Resume uses pi --session <uuid>

Schema & config:
- newSessionCommand field added to runner template types and Zod schemas
- pi registered as a valid agentCLITool with default template
  (create.mode=runner, capture via /session, resume via --session)

Session routing:
- pi uses status-command capture (same as codex/gemini), so it
  participates in standard live rotation — no special routing needed
- retryFreshStartAfterStoredResumeFailure gate handles create.mode=runner
  so pi sessions survive crash recovery

Transcript normalization:
- looksLikePiSnapshot: detects pi output; excludes bare > to avoid
  false positives with shell prompts
- shouldDropPiChromeLine: drops pi help-bar and working-status chrome
  while preserving Warning/Note content
- dropPiPromptBlocks: strips prompt echo blocks pi re-emits before
  AI responses

Also fixes:
- buildRunnerFromToolTemplate: preserve per-element resume args for
  non-codex runners (was incorrectly flattening arrays)
- Guard isPi detection against collision with Gemini output patterns

Tests: 54 chrome normalization tests, session routing tests, startup
blocker coverage, schema defaults tests.

--- clis prompt command ---

New command for sending a message to a running agent from the terminal
and receiving the response on stdout without needing Slack or Telegram.

  clis prompt --agent <id> --message <text> [--stream] [--json]

- control/prompt-cli.ts: runPromptCli using buildSteeringPromptText
- cli.ts / main.ts: prompt command added to CLI routing
- auth/resolve.ts: terminal:senderId principal resolved correctly
- channels/rendering.ts: plain-text renderer for terminal platform
- test/prompt-cli.test.ts: 12 tests covering auth, rendering, help output

--- Standalone fixes ---

- runner-exit-diagnostics.ts: use process.execPath instead of bare node
  so the exit-record writer works in nvm-managed environments where node
  may not be in PATH inside tmux sessions
- runner-exit-diagnostics.ts: fix shellQuote single-quote escape sequence

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants