agentleFS
ngctongcto/oh-my-pstack/skills/control-cli/SKILL.md

control-cli

Skill1 starsChanged 38 days agoMITView on GitHub

Drive, inspect, and profile an interactive CLI or TUI with a repeatable local harness and no external services. Use for CLI UX checks, prompt flows, resize bugs, startup regressions, memory leaks, hangs, terminal transcripts, or when asked to \"drive the CLI\", \"test this TUI\", or \"reproduce in a terminal\".

8 other projects use a version of this, 6 of them edited.

Adopted by

Most recently taken up by

Used with

Projects with it also use verify-this.

Other files people use alongside this one.

Files found in the same public projects as a version of this one, more often than they turn up anywhere else. Each project counts once, large collections count for less, and this file's own repository is left out.
  • learnerLjSkill

    verify-this

    Verify a claim with fresh local evidence: restate it falsifiably, capture baseline and treatment, compare artifacts, and return VERIFIED, NOT VERIFIED, or INCONCLUSIVE.

    Also in 4 projects that use this

The file

We split this skill into the rules it gives an agent

9 rules. 5 are common, 0 are distinctive, and 4 are very specific to this project.

  • 5

    Common

    Most of the 8 edited versions we read keep these.

  • 0

    Distinctive

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Common:

    If none exists, launch the CLI in an isolated terminal session with deterministic env vars.

    line 22
  2. Common:

    Wait for a concrete screen pattern or prompt before the next action.

    line 25
  3. Very specific:

    Scripted PTY probe: Use eval (py or js) when the flow needs exact waits and assertions in one place.

    line 36
  4. Very specific:

    Wait by polling capture-pane for a concrete pattern with a deadline, not by sleeping.

    line 52
  5. Very specific:

    Use eval (py) when neither tmux nor a repo harness fits.

    line 56
  6. Common:

    Prefer deterministic waits over sleeps.

    line 94
  7. Common:

    Do not send credentials or destructive commands into a controlled session.

    line 95
  8. Very specific:

    Keep the harness in /tmp unless the repo already has a testing or demo harness.

    line 96
  9. Common:

    Do not hard-code paths from another repository.

    line 97

“Common” is measured: kept by at least 6 in 10 of the 8 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Control CLI

Exercise an interactive CLI with a repeatable harness instead of poking at it. Reuse the repo's own test or demo harness first; otherwise assemble a temporary one from the tools below.

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 harnesses: package scripts, e2e tests, demo recorders, expect scripts, PTY helpers.
  3. If none 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

Pick the lightest one that fits.

  • Repo-native harness. Checked-in scripts already know the app's startup, env, and prompts.
  • Named bash service. For line-oriented prompts and REPLs that need stdin, start the program as a service: bash {command, name, ready?} with a ready log regex or port, and no async and no timeout (both throw in service mode). The service runs under its own broker-owned PTY, so prompts, colors, and line editing behave as for a user, and it works in subagents. Then read proc://<name> for state and output, write proc://<name> to send stdin (an empty write sends Enter), and write proc://<name>/kill to stop it. A plain async: true job takes no stdin. Foreground bash with pty: true opens a human-facing overlay and is unavailable in subagents, so do not plan a harness around it.
  • tmux. The robust path for full-screen TUIs and anything needing a stable screen or a resize, and the subagent-safe TUI path because it needs no overlay: capture-pane returns the rendered screen, send-keys sends real keys, resize-window tests layout. Use it when raw PTY output is escape-sequence noise.
  • Scripted PTY probe. Use eval (py or js) when the flow needs exact waits and assertions in one place. Prefer it over hand-rolled select loops in shell.
  • Runtime inspector. Node or Bun inspector for CPU profiles, heap snapshots, and live evaluation. xd://debug (DAP) attaches to a running process for breakpoints and stacks.
  • Terminal recorder. Repo-local demo tools or asciinema-compatible tools, only when the user asks for a demo.

Minimal tmux harness

SESSION="cli-harness-$(date +%s)"
tmux new-session -d -x 120 -y 40 -s "$SESSION" -- <command-under-test>
tmux capture-pane -pt "$SESSION"
tmux send-keys -t "$SESSION" "help" Enter
tmux capture-pane -pt "$SESSION"
tmux resize-window -t "$SESSION" -x 60 -y 20
tmux kill-session -t "$SESSION"

Wait by polling capture-pane for a concrete pattern with a deadline, not by sleeping. For Node CLIs, start with NODE_OPTIONS="--inspect=127.0.0.1:0", read the inspector URL from the terminal, and profile with DevTools-compatible tooling or xd://debug.

Scripted PTY probe

Use eval (py) when neither tmux nor a repo harness fits. Keep it temporary, under /tmp, unless the user asks for a reusable test.

import os, pty, select, subprocess, time

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

def wait_for(text, timeout=30):
    buf, end = b"", time.time() + timeout
    while time.time() < end:
        if select.select([master], [], [], 0.25)[0]:
            buf += os.read(master, 4096)
            if text in buf:
                return buf.decode(errors="replace")
    raise TimeoutError(f"never saw {text!r}; got {buf[-500:]!r}")

try:
    wait_for(b"<ready text>")
    os.write(master, b"help\n")
    print(wait_for(b"<expected reply>"))
finally:
    proc.terminate()
    os.close(master)

For richer terminal control use pty.fork() or an existing PTY library.

Profiling recipes

  • Startup regression: capture baseline and treatment timings on the same machine, env, and command.
  • Slow operation: start a CPU profile, perform the operation, stop the profile, compare top self-time functions.
  • Memory leak: force GC if available, take a heap snapshot, repeat the operation, force GC again, take another snapshot.
  • Hang: capture the screen, active handles and resources, and a stack or CPU sample before interrupting. xd://debug can pause the process and show stacks.

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 or demo harness.
  • Do not hard-code paths from another repository. Adapt commands to the current repo's scripts and runtime.
  • Clean up tmux sessions, proc://<name> services, temp dirs, inspector processes, and demo artifacts unless the user asks to keep them.

Adapted from cursor-team-kit (MIT).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.