Agent Skillslangwatch/langwatch › test-cli-usability

test-cli-usability

GitHub

用于编写CLI工具的Agent可用性测试,验证命令是否支持非交互运行、输出可解析且错误提示清晰,确保AI代理能顺利发现和使用工具。

skills/_compiled/native/test-cli-usability/SKILL.md langwatch/langwatch

Trigger Scenarios

需要验证CLI工具对AI代理的友好性 编写CLI的非交互式场景测试 检查CLI是否存在阻塞代理的交互提示

Install

npx skills add langwatch/langwatch --skill test-cli-usability -g -y
More Options

Non-standard path

npx skills add https://github.com/langwatch/langwatch/tree/main/skills/_compiled/native/test-cli-usability -g -y

Use without installing

npx skills use langwatch/langwatch@test-cli-usability

指定 Agent (Claude Code)

npx skills add langwatch/langwatch --skill test-cli-usability -a claude-code -g -y

安装 repo 全部 skill

npx skills add langwatch/langwatch --all -g -y

预览 repo 内 skill

npx skills add langwatch/langwatch --list

SKILL.md

Frontmatter
{
    "name": "test-cli-usability",
    "license": "MIT",
    "metadata": {
        "category": "recipe"
    },
    "description": "Write scenario tests that verify your CLI tool is usable by AI agents. Ensures commands work non-interactively, provide clear output, and don't hang on prompts. Use when you want to prove your CLI is agent-friendly.",
    "compatibility": "Requires @langwatch\/scenario. Works with Claude Code and similar coding agents."
}

Test Your CLI's Agent Usability

This recipe helps you write scenario tests that verify your CLI tool works well when operated by AI agents (Claude Code, Cursor, Codex, etc.). A CLI that's agent-friendly means:

  • All commands can run non-interactively (no stdin prompts that hang)
  • Output is parseable and informative
  • Error messages are clear enough for an agent to self-correct
  • Help text enables discovery (--help works on every subcommand)

Prerequisites

Install the Scenario SDK:

npm install @langwatch/scenario vitest @ai-sdk/openai
# or: pip install langwatch-scenario pytest

Step 1: Identify Your CLI Commands

List every command your CLI supports. For each, note:

  • Does it require interactive input? (MUST have a non-interactive alternative)
  • What flags/options does it accept?
  • What does it output on success/failure?

Step 2: Write Scenario Tests

For each command, write a scenario test where an AI agent discovers and uses it:

import scenario, { type AgentAdapter, AgentRole } from "@langwatch/scenario";
import { openai } from "@ai-sdk/openai";
import { describe, expect, it } from "vitest";

const myAgent: AgentAdapter = {
  role: AgentRole.AGENT,
  call: async (input) => {
    // Your Claude Code adapter here
  },
};

describe("CLI agent usability", () => {
  it("discovers and uses the command non-interactively", async () => {
    const result = await scenario.run({
      name: "CLI command discovery",
      description: "Agent discovers and uses the CLI to accomplish a task",
      agents: [
        myAgent,
        scenario.userSimulatorAgent({ model: openai("gpt-5-mini") }),
        scenario.judgeAgent({
          model: openai("gpt-5-mini"),
          criteria: [
            "Agent used the CLI command correctly",
            "Agent did not get stuck on interactive prompts",
            "Agent did not need to pipe 'yes' or use 'expect' scripting",
          ],
        }),
      ],
    });
    expect(result.success).toBe(true);
  });
});

Step 3: Assert No Interactive Workarounds

Add this assertion to every test:

function assertNoInteractiveWorkarounds(state) {
  const output = state.messages.map(m =>
    typeof m.content === 'string' ? m.content : JSON.stringify(m.content)
  ).join('\n');

  expect(output).not.toMatch(/echo\s+["']?[yY](?:es)?["']?\s*\|/);
  expect(output).not.toMatch(/\byes\s*\|/);
  expect(output).not.toMatch(/expect\s+-c/);
  expect(output).not.toMatch(/printf\s+["']\\n["']\s*\|/);
}

If this assertion fails, your CLI has an interactivity bug -- add --yes, --force, or --non-interactive flags to the offending commands.

Step 4: Test Error Recovery

Write scenarios where the agent makes a mistake and must recover:

  • Wrong command name -> agent reads --help and self-corrects
  • Missing required argument -> agent reads error message and retries
  • Authentication failure -> agent follows instructions in error output

Common Mistakes

  • Do NOT make commands that require stdin for essential operations -- always provide flag alternatives
  • Do NOT use interactive prompts for confirmation without a --yes or --force flag
  • Do NOT output errors without actionable guidance (the agent needs to know how to fix it)
  • DO make --help comprehensive on every subcommand
  • DO use non-zero exit codes for failures (agents check exit codes)
  • DO output structured information (the agent can parse it)

Version History

  • 12615f1 Current 2026-08-20 10:01

Same Skill Collection

.claude/skills/browser-pair/SKILL.md
.claude/skills/browser-test/SKILL.md
.claude/skills/code-review/SKILL.md
.claude/skills/feature-map/SKILL.md
.claude/skills/haven-setup/SKILL.md
.claude/skills/langwatch-kanban/SKILL.md
plugins/langwatch/skills/langwatch/SKILL.md
services/langy-agent/skills/github/SKILL.md
skills/_compiled/native/agent-best-practices/SKILL.md
skills/_compiled/native/agent-performance/SKILL.md
skills/_compiled/native/connect-agent/SKILL.md
skills/_compiled/native/datasets/SKILL.md
skills/_compiled/native/debug-instrumentation/SKILL.md
skills/_compiled/native/debug-with-langwatch/SKILL.md
skills/_compiled/native/eval-triage/SKILL.md
skills/_compiled/native/evaluate-multimodal/SKILL.md
skills/_compiled/native/evaluations/SKILL.md
skills/_compiled/native/experiments/SKILL.md
skills/_compiled/native/generate-rag-dataset/SKILL.md
skills/_compiled/native/github/SKILL.md
skills/_compiled/native/level-up/SKILL.md
skills/_compiled/native/online-evaluations/SKILL.md
skills/_compiled/native/prompts/SKILL.md
skills/_compiled/native/scenarios/SKILL.md
skills/_compiled/native/setup-lw/SKILL.md
skills/_compiled/native/test-compliance/SKILL.md
skills/_compiled/native/tracing/SKILL.md

Metadata

Files
0
Version
12615f1
Hash
29f9dd71
Indexed
2026-08-20 10:01

Home - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-08-21 12:25
浙ICP备14020137号-1 $Map of visitor$