cli-handler

A set of coding rules for command handlers in Sruja's Rust command-line program. A command handler connects typed command-line options to the program's library code and formats the result.

In plain words
What is it for?
Use it when editing files under the Sruja CLI command directory, especially when adding commands, parsing options with clap, returning success or failure, formatting JSON or text, or handling errors.
Why use it?
It keeps command handlers small and consistent, while keeping business logic in the underlying libraries. It also standardizes errors, exit codes, paths, verbosity, and output formats.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/sruja-ai/sruja/cli-handler
Clone the repo
git clone --depth 1 https://github.com/sruja-ai/sruja

Made for: Cursor.

Per session 427 This file is loaded in full into every session.
When invoked 427 The same file — it is already loaded in full.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00427 $0.00427
Opus 5 $0.00214 $0.00214
Sonnet 5 $0.00085 $0.00085
Haiku 4.5 $0.00043 $0.00043

Measured yesterday against content hash 6d7b8502f18a, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

cli-handler scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/cli-handler.mdc · 41 lines

What it actually says

CLI Handler Patterns

Patterns for Sruja CLI command handlers. Keeps the CLI thin and consistent.

Scopes

  • crates/sruja-cli/src/commands/**/*.rs

Rules

  1. Handlers are thin: CLI handlers parse args, call library functions, format output. Business logic lives in engine/language/scan crates.
  2. Use clap derive: All commands use #[derive(Parser)] from clap. Subcommands use #[derive(Subcommand)].
  3. Exit codes: Return ExitCode from main. Use ExitCode::SUCCESS / ExitCode::FAILURE. Never std::process::exit() directly.
  4. Output formats: Support --format json|text|github-actions where applicable. JSON output uses serde_json::to_string_pretty.
  5. Error display: Use anyhow::Result for error propagation in CLI. Display errors with eprintln! to stderr, never stdout.
  6. Repo path: Accept -r, --repo <PATH> with default .. Use PathBuf for the type.
  7. Verbose flag: Use -v, --verbose (counting) for log levels. Map -v to info, -vv to debug, -vvv to trace.
  8. No global state: Each command handler receives its parsed args. No lazy_static or global singletons.

Patterns

use anyhow::Result;
use clap::Parser;
use std::path::PathBuf;

#[derive(Parser)]
pub struct MyCommand {
    #[arg(short, long, default_value = ".")]
    repo: PathBuf,
    #[arg(short, long, default_value = "text")]
    format: OutputFormat,
}

pub fn run(cmd: MyCommand) -> Result<()> {
    // 1. Validate inputs
    // 2. Call library function
    // 3. Format and print output
    Ok(())
}
Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 41 lines · 427 tokens per session scan A 6d7b8502f18a

Subscribe to this mod's changes

cli-handler is a cursor rule published in the GitHub repository sruja-ai/sruja (22 stars, last pushed 8d ago), licensed Apache-2.0. It adds 427 tokens to every session, about $0.0021 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.