Agent助手
- 作者仓库星标 104,522
- 作者更新于 实时读取
- 作者仓库 gemini-cli
- 领域
- AI 智能
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 83 / 100 · 社区维护
- 作者 / 版本 / 许可
- @google-gemini · 未声明 license
- Token 消耗评级
- 中等消耗
- 接入复杂程度
- 需手动接入
- 是否需要外部 API Key
- 不需要
- 兼容的系统
- macOS · Linux · Windows
- 底层运行要求
- Node.js · Bun
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 允许外网请求
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。;检出高风险片段:pipe_curl_to_shell
---
name: agent-tui
description: > When using agent-tui in this macOS environment, the default background daemonization process c…
category: AI 智能
runtime: Node.js / Bun
---
# agent-tui 输出预览
## PART A: 任务判断
- 适用问题:提示词、Agent 工作流、模型评估或自动化推理。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“🚨 CRITICAL: macOS Daemon Workaround & Gemini CLI Usage 🚨 / Session ID vs PID (Crucial for Reconnection) / Testing the Gemini CLI”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于提示词、Agent 工作流、模型评估或自动化推理,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“🚨 CRITICAL: macOS Daemon Workaround & Gemini CLI Usage 🚨 / Session ID vs PID (Crucial for Reconnection) / Testing the Gemini CLI”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、会按任务需要访问外部网络、通常不需要额外 API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文出现了 `/tmp`、`/agents` 这类斜杠命令;如果你的 Agent 支持命令触发,优先用命令开场,再补充目标和边界。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“🚨 CRITICAL: macOS Daemon Workaround & Gemini CLI Usage 🚨 / Session ID vs PID (Crucial for Reconnection) / Testing the Gemini CLI”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: agent-tui
description: > When using agent-tui in this macOS environment, the default background daemonization process c…
category: AI 智能
source: google-gemini/gemini-cli
---
# agent-tui
## 什么时候使用
- 把 AI / Agent方向的常用动作沉淀成 Agent 可调用的技能 适合处理AI Agent、提示词、模型评估与自动化推理,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查…
- 面向提示词、Agent 工作流、模型评估或自动化推理,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「🚨 CRITICAL: macOS Daemon Workaround & Gemini CLI Usage 🚨 / Session ID vs PID (Crucial for Reconnection) / Testing the Gemini CLI」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;会按任务需要访问外部网络;通常不需要额外 API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "agent-tui" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> 🚨 CRITICAL: macOS Daemon Workaround & Gemini CLI Usage 🚨 / Session ID vs PID (Crucial for Reconnection) / Testing the Gemini CLI
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Node.js / Bun | 读取文件、写入/修改文件、执行终端命令 | 会按任务需要访问外部网络
安全层 -> 通常不需要额外 API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} 🚨 CRITICAL: macOS Daemon Workaround & Gemini CLI Usage 🚨
When using agent-tui in this macOS environment, the default background daemonization process crashes, causing Connection refused (os error 61) errors.
You MUST start the daemon manually shielded from TTY hangups before running any agent-tui commands. Using nohup is insufficient; you must use tmux to provide a fully isolated pseudo-terminal.
To support parallel runs, only restart the daemon if it is not currently running:
# Check if daemon is alive, start it in tmux if it is not
if ! agent-tui sessions >/dev/null 2>&1; then
tmux kill-session -t agent-tui 2>/dev/null || true
agent-tui daemon stop 2>/dev/null || true
rm -f /tmp/agent-tui*
tmux new-session -d -s agent-tui 'agent-tui daemon start --foreground > /tmp/agent-tui-daemon.log 2>&1'
sleep 1
fi
Session ID vs PID (Crucial for Reconnection)
When agent-tui run returns JSON, it includes both a session_id and a pid. The pid is purely informational (the OS process ID of the child command). You do not use the pid to reconnect or issue commands. You must always use the session_id (e.g., --session <id>).
If the daemon crashes (os error 61), the pseudo-terminal is destroyed. Even if the child pid survives as an orphan, you cannot reconnect to it. You must restart the daemon using the workaround above and start a completely new session.
Testing the Gemini CLI
When testing the Gemini CLI with agent-tui, there are several strict requirements to ensure deterministic and accurate behavior:
- Build Before Running:
agent-tuiruns the built JS files, not TypeScript. You MUST runnpm run buildornpm run build:allafter making code changes and before launching the CLI withagent-tui. - Bypass Trust Modals: Always pass
GEMINI_CLI_TRUST_WORKSPACE=truein the environment. If you don't, any new project-level agents or extensions will trigger a full-screen "Acknowledge and Enable" modal. This modal steals focus, swallows automation keystrokes, and causesagent-tui waitcommands to time out. - Isolated Environments: If you need to test without real user credentials or existing agents interfering, isolate the global settings using
GEMINI_CLI_HOME=<some-test-dir>. - Testing State Deltas (e.g., Reloads): If you are testing features that report deltas (e.g.,
/agents reloadoutputting "1 new local subagent"), you MUST:- Start the CLI first so it establishes its baseline registry.
- Use a separate shell command (outside of
agent-tui) to write the new agent.md/.tomlfile. - Use
agent-tui typeandpressto trigger the/agents reloadcommand inside the running session. - (If you add the files before starting the CLI, they become part of the baseline and won't trigger the delta logic).
# Example: Standard isolated run (sandboxed config + bypass trust modals)
env GEMINI_CLI_TRUST_WORKSPACE=true GEMINI_CLI_HOME=test-gemini-home agent-tui run -d "$(pwd)" node packages/cli/dist/index.js
Terminal Automation Mastery
Prerequisites
- Supported OS: macOS or Linux (Windows not supported yet).
- Verify install:
agent-tui --version
If not installed, use one of:
# Recommended: one-line install (macOS/Linux)
curl -fsSL https://raw.githubusercontent.com/pproenca/agent-tui/master/install.sh | sh
# Package manager
npm i -g agent-tui
pnpm add -g agent-tui
bun add -g agent-tui
# Build from source
cargo install --git https://github.com/pproenca/agent-tui.git --path cli/crates/agent-tui
If you used the install script, ensure ~/.local/bin is on your PATH.
Philosophy: Why Terminal Automation Is Different
Terminal UIs are stateless from the observer's perspective. Unlike web browsers with a persistent DOM, terminal automation works with a constantly-refreshed character grid. This fundamental difference shapes everything:
| Web Automation | Terminal Automation |
|---|---|
| DOM persists across interactions | Screen buffer is redrawn constantly |
| Selectors are stable | Text positions may shift |
| Query once, act many times | Must re-verify before EVERY action |
| Network events signal completion | Must detect visual stability |
The Core Insight: agent-tui gives you vision without memory. Each screenshot is a fresh observation. Previous state means nothing after the UI changes. This isn't a limitation—it's the nature of terminal interaction.
Mental Model: The Feedback Loop
Think of terminal automation as a closed-loop control system:
┌──────────────────────────────────────────────┐
│ │
▼ │
OBSERVE ──► DECIDE ──► ACT ──► WAIT ──► VERIFY ───┘
│ │
│ │
└─────── NEVER skip ◄────────────────────┘
Each phase is mandatory. Skipping verification is the #1 cause of flaky automation.
The "Fresh Eyes" Principle
Every time you need to interact with the UI:
- Take a fresh screenshot — your previous one is now stale
- Locate your target visually — text positions may have changed
- Verify the state — the UI may have changed unexpectedly
- Act only when stable — animations and loading states cause failures
This feels slower, but it's the only reliable approach. Optimistic reuse of stale state causes intermittent failures that are painful to debug.
Critical Rules (Non-Negotiable)
RULE 1: Atomic Execution (No Pipelining) You are FORBIDDEN from chaining commands with
&&(e.g.,type "x" && press Enter && wait). Modals or UI updates can intercept your keystrokes. You MUST execute one atomic action, wait, screenshot, and verify before taking the next action in a new turn.
RULE 2: Re-snapshot after EVERY action The UI state is invalidated by any change. Always take a fresh screenshot before acting again.
RULE 3: Never act on unstable UI If the UI is animating, loading, or transitioning,
wait --stablefirst. Acting during transitions because race conditions.
RULE 4: Verify before claiming success Use
wait "expected text" --assertto confirm outcomes. Don't assume an action worked—prove it.
RULE 5: Error Recovery If a
waitcommand times out, DO NOT blindly restart or kill the session. Executescreenshotto visually diagnose what unexpected UI element (modal, error dialog, lost focus) intercepted the flow.
RULE 6: Clean up sessions Always end with
agent-tui kill. Orphaned sessions consume resources and can interfere with future runs.
Decision Framework
Which Screenshot Mode?
Use screenshot --format json when parsing automation output, or plain screenshot for human readable text.
How to Wait?
What are you waiting for?
│
├─► Specific text to appear
│ └─► `wait "text" --assert` (fails if not found)
│
├─► Specific text to disappear
│ └─► `wait "text" --gone --assert`
│
├─► UI to stop changing (animations, loading)
│ └─► `wait --stable`
│
└─► Multiple conditions
└─► Chain waits sequentially
How to Act?
What do you need to do?
│
├─► Type text into the terminal
│ └─► `type "text"`
│
├─► Send keyboard shortcuts/navigation
│ └─► `press Ctrl+C` or `press ArrowDown Enter`
Core Workflow
The canonical automation loop:
# 1. START: Launch the TUI app
agent-tui run <command> [-- args...]
# 2. OBSERVE: Get current UI state
agent-tui screenshot --format json
# 3. DECIDE: Based on text, determine next action
# (This happens in your head/code)
# 4. ACT: Execute the action
agent-tui type "text"
agent-tui press Enter
# 5. WAIT: Synchronize with UI changes
agent-tui wait "Expected" --assert # or wait --stable
# 6. VERIFY: Confirm the outcome (often combined with step 5)
# If verification fails, handle the error
# 7. REPEAT: Go back to step 2 until done
# 8. CLEANUP: Always clean up
agent-tui kill
Anti-Patterns (What NOT to Do)
❌ Acting During Animation/Loading
# WRONG: Acting immediately on dynamic UI
agent-tui run my-app
agent-tui screenshot --format json # UI might still be loading!
agent-tui type "value" # ❌ Might miss the input field
# RIGHT: Wait for stability first
agent-tui run my-app
agent-tui wait --stable # Let UI settle
agent-tui screenshot --format json # Now it's reliable
agent-tui type "value"
❌ Assuming Success Without Verification
# WRONG: Assuming the type worked
agent-tui type "value"
agent-tui press Enter
# ...proceed as if success... # ❌ What if it failed silently?
# RIGHT: Verify the outcome
agent-tui type "value"
agent-tui press Enter
agent-tui wait "Success" --assert # ✓ Proves the action worked
❌ Skipping Cleanup
# WRONG: Forgetting to kill the session
agent-tui run my-app
# ...do stuff...
# script ends # ❌ Session left running!
# RIGHT: Always clean up
agent-tui run my-app
# ...do stuff...
agent-tui kill # ✓ Clean exit
Before You Start: Clarify Requirements
Before automating any TUI, gather this information:
- Command: What exactly to run? (
my-app --flagornpm start?) - Success criteria: What text/state indicates success?
- Input sequence: What keystrokes/data to enter, in what order?
- Safety: Is it safe to submit forms, delete data, etc.?
- Auth: Does it need login? Test credentials?
- Live preview: Does the user want to watch? (
agent-tui live start --open)
If any of these are unclear, ask before running.
Demo Mode: Showing What agent-tui Can Do
When a user asks what agent-tui is, wants a demo, or asks "show me how it works":
- Don't explain—demonstrate. Actions speak louder than words.
- Use the live preview so they can watch in real-time.
- Run
top—it's universal and shows dynamic real-time updates.
Quick demo trigger phrases:
- "What is agent-tui?" / "What does agent-tui do?"
- "Demo agent-tui" / "Show me agent-tui"
- "How does agent-tui work?" / "See it in action"
Failure Recovery
| Symptom | Diagnosis | Solution |
|---|---|---|
| "Text not found" | Stale view or text moved | Re-snapshot, locate text again |
| Wait times out | UI didn't reach expected state | Check screenshot, verify expectations |
| "Daemon not running" | Daemon crashed or not started | agent-tui daemon start |
| Unexpected layout | Wrong terminal size | agent-tui resize --cols 120 --rows 40 |
| Session unresponsive | App crashed or hung | agent-tui kill, then re-run |
| Repeated failures | Something fundamentally wrong | Stop after 3-5 attempts, ask user |
Self-Discovery: Use --help
You don't need to memorize every flag. The CLI is self-documenting:
agent-tui --help # List all commands
agent-tui run --help # Options for 'run'
agent-tui screenshot --help # Options for 'screenshot'
agent-tui wait --help # Options for 'wait'
When in doubt, ask the CLI. This skill teaches when and why to use commands. For exact flags and syntax, --help is authoritative.
Quick Reference
# Start app
agent-tui run <cmd> [-- args] # Launch TUI under control
# Observe
agent-tui screenshot # Plain text view
agent-tui screenshot --format json # Machine-readable output
# Act
agent-tui press Enter # Press key(s)
agent-tui press Ctrl+C # Keyboard shortcuts
agent-tui type "text" # Type text
# Wait/Verify
agent-tui wait "text" --assert # Wait for text, fail if not found
agent-tui wait "text" --gone --assert # Wait for text to disappear
agent-tui wait --stable # Wait for UI to stop changing
# Manage
agent-tui sessions # List active sessions
agent-tui live start --open # Start live preview
agent-tui kill # End current session
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核