Chuyển đến nội dung
Skillpedia
Kiểm thử15k · #10931

control-cli

Skill này làm gì

Cho phép trợ lý chạy một chương trình terminal tương tác, gửi phím và ghi lại những gì nó hiển thị. Dành cho lập trình viên kiểm thử hành vi của ứng dụng dòng lệnh và terminal.

Khi nào nên dùng

  • ✓Khi một ứng dụng dòng lệnh hoặc terminal có lỗi bạn cần tái hiện một cách đáng tin cậy.
  • ✓Khi bạn muốn kiểm tra luồng bàn phím, lời nhắc hoặc bố cục terminal.
  • ✓Khi bạn cần đo thời gian khởi động, treo hoặc tăng bộ nhớ trong một ứng dụng dòng lệnh.

Liên kết skill

https://github.com/cursor/plugins/blob/main/cursor-team-kit/skills/control-cli/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/cursor/plugins/blob/main/cursor-team-kit/skills/control-cli/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Chạy CLI của chúng tôi, đi qua lời nhắc đăng nhập với dữ liệu thử và lưu bản ghi các màn hình.”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Trợ lý dùng lại bộ kiểm thử hoặc demo có sẵn trong repo nếu có. Nếu không, nó khởi động chương trình trong một terminal cô lập, gửi từng thao tác một, chờ văn bản màn hình mong đợi và lưu bản ghi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Control CLI

Use a repeatable local harness to exercise an interactive CLI instead of poking at it manually. First reuse the repo's own test/demo harness if it exists; otherwise assemble a temporary harness from standard local tools.

What It Is Used For

  • Reproducing CLI/TUI bugs with deterministic input.
  • Verifying keyboard flows, prompts, interrupts, resize behavior, and terminal layout.
  • Capturing before/after transcripts for bug fixes.
  • Profiling startup time, slow operations, hangs, or memory growth.
  • Recording a short terminal demo when output is easier to show than explain.

Harness Loop

  1. Identify the command under test and the smallest reproducible workspace.
  2. Discover existing local harnesses: package scripts, e2e tests, demo recorders, expect scripts, or PTY helpers.
  3. If no harness exists, launch the CLI in an isolated terminal session with deterministic env vars.
  4. Capture the current screen before interacting.
  5. Send one action at a time: text, Enter, arrows, Escape, Ctrl-C, resize.
  6. Wait for a concrete screen pattern or prompt before the next action.
  7. Save the transcript and any profile artifacts.
  8. Kill the session cleanly.

Harness Options

  • Repo-native harness: prefer checked-in scripts because they know the app's startup, env, and prompts.
  • tmux: managed sessions, capture-pane, send-keys, attach/detach.
  • PTY probe: use a short Python, Node, or Expect script when tmux is unavailable.
  • Runtime inspector: use Node or Bun inspector for CPU profiles, heap snapshots, and live evaluation.
  • Terminal recorder: use repo-local demo tools or asciinema-compatible tools when the user asks for a demo.

Minimal tmux Harness

SESSION="cli-harness-$(date +%s)"
tmux new-session -d -s "$SESSION" -- <command-under-test>
tmux capture-pane -pt "$SESSION"
tmux send-keys -t "$SESSION" "help" Enter
tmux capture-pane -pt "$SESSION"
tmux kill-session -t "$SESSION"

For Node CLIs:

NODE_OPTIONS="--inspect=127.0.0.1:0" tmux new-session -d -s "$SESSION" -- <node-cli-command>

Read the terminal output to find the inspector URL, then use Chrome DevTools-compatible tooling if profiling is needed.

Minimal PTY Harness

Use a PTY script when you need deterministic waits in a repo that does not have tmux or a demo harness. Keep it temporary unless the user asks to add a reusable test.

import os
import pty
import select
import subprocess
import time

master_fd, slave_fd = pty.openpty()
proc = subprocess.Popen(
    ["<command>", "<arg>"],
    stdin=slave_fd,
    stdout=slave_fd,
    stderr=slave_fd,
    close_fds=True,
)
os.close(slave_fd)

deadline = time.time() + 30
buffer = b""
while time.time() < deadline:
    ready, _, _ = select.select([master_fd], [], [], 0.25)
    if not ready:
        continue
    chunk = os.read(master_fd, 4096)
    buffer += chunk
    if b"<ready text>" in buffer:
        os.write(master_fd, b"help\n")
        break

print(buffer.decode(errors="replace"))
proc.terminate()
os.close(master_fd)

If the CLI needs richer terminal control, use pty.fork() or an existing PTY library.

Profiling Recipes

  • Startup regression: capture baseline and treatment startup timings under the same machine, env, and command.
  • Slow operation: start a CPU profile, perform the operation, stop the profile, and compare top self-time functions.
  • Memory leak: force GC if available, take a heap snapshot, perform the operation repeatedly, force GC again, and take another snapshot.
  • Hang: capture the screen, active handles/resources, and a stack/CPU sample before interrupting.

Guardrails

  • Prefer deterministic waits over sleeps. If you must sleep, explain why.
  • Do not send credentials or destructive commands into a controlled session.
  • Keep the harness in /tmp unless the repo already has a testing/demo harness.
  • Do not hard-code paths from another repository. Adapt commands to the current repo's scripts and runtime.
  • Clean up tmux sessions, temp dirs, inspector processes, and demo artifacts unless the user asks to keep them.
Câu hỏi thường gặp

Nó có cần dịch vụ bên ngoài không?

Không. Bộ điều khiển chạy cục bộ với các công cụ chuẩn như phiên terminal.

Nó có ghi lại được bản demo không?

Có. Có thể ghi lại bản demo terminal khi cho thấy kết quả dễ hơn là giải thích.

Nếu repo đã có công cụ kiểm thử thì sao?

Trợ lý dùng bộ điều khiển có sẵn trước, vì nó đã biết các bước khởi động và lời nhắc.

Chi tiết

Mô tả gốc của tác giả

Build or adapt a local harness to drive, inspect, and profile an interactive CLI or TUI without external services. Use for CLI UX checks, startup regressions, memory leaks, hangs, prompt flows, or terminal demos.

repo: cursor/plugins

Độ phổ biến

Sao GitHub
15k
Vị trí xếp hạng
#10931
Giấy phép
—
Cập nhật
31/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự