command-attribute-template.cs

A C# command template for SwiftlyS2 plugins, which are extensions for the SwiftlyS2 server platform. It shows how to declare fixed commands with attributes and command aliases.

In plain words
What is it for?
It helps build small plugin commands with permission checks, argument validation, and player feedback while keeping complex logic in separate services.
Why use it?
It prevents common command-definition mistakes, including using the wrong handler return type or treating an alias as a prefixed command.

Command

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 commands/2oaj/swiftlys2-toolkit/command-attribute-template.cs
Clone the repo
git clone --depth 1 https://github.com/2oaJ/SwiftlyS2-Toolkit
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 707 The whole file, excluding the scripts and references it only reads on demand.
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.00000 $0.00707
Opus 5 $0.00000 $0.00353
Sonnet 5 $0.00000 $0.00141
Haiku 4.5 $0.00000 $0.00071

Measured 2d ago against content hash 4f4f6b5864a2, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

command-attribute-template.cs 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 2d ago.

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.

skills/SwiftlyS2-Toolkit/assets/development/commands/command-attribute-template.cs.md · 80 lines

How it starts

The opening of the file, as written. The whole thing — 80 lines — stays where its author put it; the contents beside it link to each section on GitHub.

SwiftlyS2 Attribute Command Template

Official docs sections:

  • Commands
  • Using attributes
  • Thread Safety

Suitable for: partial / small plugins that use [Command] and [CommandAlias] to declare fixed command entry points.

Usage principles

  • The command layer should own the entry point, permissions, argument validation, and player feedback.
  • Complex business logic should be pushed down into modules or services.
  • If the feature later needs dynamic install / uninstall, conditional start / stop, or precise cleanup, consider switching to programmatic registration.

Critical constraints

Handler return type must be void

The [Command] attribute handler signature is void OnMyCommand(ICommandContext context). It must not be async ValueTask, async Task, or any other async return type. The underlying delegate type is delegate void CommandListener(ICommandContext context);. If you need to perform async work inside a command handler, you may fire-and-forget an async method from within the void handler body, but the handler entry point itself must remain void.

CommandAlias is a shorter alias, not a prefixed variant

[CommandAlias("mc")] registers an alternative name that players can type instead of the full command (e.g., !mc instead of !mycommand). It is not used to add framework prefixes like sw_ or namespace groupings. Aliases should be short, memorable abbreviations of the canonical command name.

Example skeleton

using SwiftlyS2.Shared.Commands;
using SwiftlyS2.Shared.Core.Attributes.Commands;

namespace MyNamespace;

public partial class MyPlugin
{
    [Command("mycommand", permission: "myplugin.commands.use")]
    [CommandAlias("mc")]
    public void OnMyCommand(ICommandContext context)
    {
        if (!context.IsSentByPlayer || context.Sender is null || !context.Sender.IsValid)
        {
            context.Reply("[Plugin] This command can only be executed by a valid player.");
            return;
        }

        var args = context.Arguments;
        if (args.Count < 2)
        {
            context.Reply("[Plugin] Invalid arguments. Please check the input format.");
            return;
        }

        var parsedArg = args[1].Trim();
        if (string.IsNullOrWhiteSpace(parsedArg))
        {
            context.Reply("[Plugin] The argument cannot be empty.");
            return;
        }

        var success = _myFeatureService.TryHandlePlayerAction(context.Sender.SteamID, parsedArg);
        if (!success)
        {
            context.Reply("[Plugin] This operation cannot be executed right now.");
            return;
        }

        context.Reply("[Plugin] Operation completed successfully.");
    }
}

Read the full file on GitHub · 80 lines

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. 2d ago First seen · 80 lines · 0 tokens per session scan A 4f4f6b5864a2

Subscribe to this mod's changes

command-attribute-template.cs is a command published in the GitHub repository 2oaJ/SwiftlyS2-Toolkit (10 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 707 tokens. 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-31.