agents skills

This commit is contained in:
2026-03-18 19:45:59 +08:00
parent f642e96112
commit f06be8c133
4 changed files with 321 additions and 0 deletions

View File

@@ -0,0 +1,141 @@
---
name: bash-script
description: Write robust bash scripts with proper error handling. Use when the user says "write a script", "bash script", "shell script", "automate this", "create a backup script", or asks to script a task.
allowed-tools: Read, Write, Edit, Bash, Glob
---
# Bash Script
Write robust, maintainable bash scripts with proper error handling.
## Instructions
1. Understand the task requirements
2. Design the script structure
3. Write with safety options and error handling
4. Test and validate
## Script template
```bash
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Description: Brief description of what this script does
# Usage: ./script.sh [options]
readonly SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
readonly SCRIPT_NAME="$(basename "${BASH_SOURCE[0]}")"
# Default values
VERBOSE="${VERBOSE:-false}"
usage() {
cat <<EOF
usage: ${SCRIPT_NAME} [options] <argument>
Description of what the script does.
Options:
-h, --help Show this help message
-v, --verbose Enable verbose output
Examples:
${SCRIPT_NAME} input.txt
${SCRIPT_NAME} --verbose /path/to/file
EOF
}
log() {
echo "[$(date +'%Y-%m-%d %H:%M:%S')] $*" >&2
}
error() {
log "ERROR: $*"
exit 1
}
cleanup() {
# Remove temp files, restore state, etc.
rm -f "${TEMP_FILE:-}"
}
trap cleanup EXIT
main() {
# Parse arguments
while [[ $# -gt 0 ]]; do
case "$1" in
-h|--help) usage; exit 0 ;;
-v|--verbose) VERBOSE=true; shift ;;
--) shift; break ;;
-*) error "Unknown option: $1" ;;
*) break ;;
esac
done
[[ $# -lt 1 ]] && { usage; exit 1; }
local input="$1"
[[ -f "$input" ]] || error "File not found: $input"
# Main logic here
log "Processing $input"
}
main "$@"
```
## Safety options explained
| Option | Purpose |
| ----------------- | ----------------------------------- |
| `set -e` | Exit on error |
| `set -u` | Error on undefined variables |
| `set -o pipefail` | Pipeline fails if any command fails |
| `IFS=$'\n\t'` | Safer word splitting |
## Best practices
- MUST use `set -euo pipefail` at script start
- MUST quote all variables: `"$var"` not `$var`
- MUST use `[[` for conditionals (not `[`)
- MUST use `$()` for command substitution (not backticks)
- Use `readonly` for constants
- Use `local` for function variables
- Use `trap` for cleanup
- Use `mktemp` for temp files
## Common patterns
```bash
# Check if command exists
command -v docker &>/dev/null || error "docker not found"
# Default value
name="${1:-default}"
# Read file line by line
while IFS= read -r line; do
echo "$line"
done < "$file"
# Process arguments
for arg in "$@"; do
echo "$arg"
done
# Temp file with cleanup
TEMP_FILE="$(mktemp)"
trap 'rm -f "$TEMP_FILE"' EXIT
```
## Rules
- MUST include `set -euo pipefail`
- MUST quote all variable expansions
- MUST include usage function for scripts with arguments
- MUST use trap for cleanup of temp files
- Never use `eval` with user input
- Never assume current directory
- Always use absolute paths for cron scripts

100
.agents/skills/git/SKILL.md Normal file
View File

@@ -0,0 +1,100 @@
---
name: git
description: Git operations with conventional commits. Use for staging, committing, pushing, PRs, merges. Auto-splits commits by type/scope. Security scans for secrets.
version: 1.0.0
---
# Git Operations
Execute git workflows via `git-manager` subagent to isolate verbose output.
Activate `context-engineering` skill.
**IMPORTANT:**
- Sacrifice grammar for the sake of concision.
- Ensure token efficiency while maintaining high quality.
- Pass these rules to subagents.
## Arguments
- `cm`: Stage files & create commits
- `cp`: Stage files, create commits and push
- `pr`: Create Pull Request [to-branch] [from-branch]
- `to-branch`: Target branch (default: main)
- `from-branch`: Source branch (default: current branch)
- `merge`: Merge [to-branch] [from-branch]
- `to-branch`: Target branch (default: main)
- `from-branch`: Source branch (default: current branch)
## Quick Reference
| Task | Reference |
|------|-----------|
| Commit | `references/workflow-commit.md` |
| Push | `references/workflow-push.md` |
| Pull Request | `references/workflow-pr.md` |
| Merge | `references/workflow-merge.md` |
| Standards | `references/commit-standards.md` |
| Safety | `references/safety-protocols.md` |
| Branches | `references/branch-management.md` |
| GitHub CLI | `references/gh-cli-guide.md` |
## Core Workflow
### Step 1: Stage + Analyze
```bash
git add -A && git diff --cached --stat && git diff --cached --name-only
```
### Step 2: Security Check
Scan for secrets before commit:
```bash
git diff --cached | grep -iE "(api[_-\]?key|token|password|secret|credential)"
```
**If secrets found:** STOP, warn user, suggest `.gitignore`.
### Step 3: Split Decision
**NOTE:**
- Search for related issues on GitHub and add to body.
- Only use `feat`, `fix`, or `perf` prefixes for files in `.claude` directory (do not use `docs`).
**Split commits if:**
- Different types mixed (feat + fix, code + docs)
- Multiple scopes (auth + payments)
- Config/deps + code mixed
- FILES > 10 unrelated
**Single commit if:**
- Same type/scope, FILES ≤ 3, LINES ≤ 50
### Step 4: Commit
```bash
git commit -m "type(scope): description"
```
## Output Format
```
✓ staged: N files (+X/-Y lines)
✓ security: passed
✓ commit: HASH type(scope): description
✓ pushed: yes/no
```
## Error Handling
| Error | Action |
|-------|--------|
| Secrets detected | Block commit, show files |
| No changes | Exit cleanly |
| Push rejected | Suggest `git pull --rebase` |
| Merge conflicts | Suggest manual resolution |
## References
- `references/workflow-commit.md` - Commit workflow with split logic
- `references/workflow-push.md` - Push workflow with error handling
- `references/workflow-pr.md` - PR creation with remote diff analysis
- `references/workflow-merge.md` - Branch merge workflow
- `references/commit-standards.md` - Conventional commit format rules
- `references/safety-protocols.md` - Secret detection, branch protection
- `references/branch-management.md` - Naming, lifecycle, strategies
- `references/gh-cli-guide.md` - GitHub CLI commands reference

View File

@@ -0,0 +1,75 @@
---
name: linux-admin
cluster: linux
description: "Ubuntu Server 24.04 LTS: apt, user management, disk/filesystem, sysctl, log management"
tags: ["linux","ubuntu","admin","system"]
dependencies: []
composes: []
similar_to: []
called_by: []
authorization_required: false
scope: general
model_hint: claude-sonnet
embedding_hint: "linux ubuntu server administration apt package system admin"
---
# linux-admin
## Purpose
This skill provides tools for administering Ubuntu Server 24.04 LTS, focusing on package management with apt, user account creation and modification, disk and filesystem operations, kernel parameter tuning via sysctl, and log management.
## When to use
Use this skill for server setup, maintenance, or troubleshooting on Ubuntu 24.04, such as deploying applications, securing user access, optimizing system performance, or analyzing logs in production environments.
## Key Capabilities
- **Package Management (apt)**: Update repositories, install/uninstall packages, and manage dependencies using `apt` with flags like `-y` for non-interactive mode.
- **User Management**: Create, modify, or delete users with commands like `useradd`, `usermod`, and `userdel`, including options for home directories and shells.
- **Disk/Filesystem**: Partition disks with `fdisk`, format filesystems using `mkfs`, and mount/unmount with `mount` and `umount`, supporting formats like ext4.
- **Sysctl**: Adjust kernel parameters dynamically, e.g., for networking or security, by editing `/etc/sysctl.conf` and applying with `sysctl -p`.
- **Log Management**: Query and filter system logs using `journalctl`, with options like `--since` for time-based searches and persistent storage in `/var/log`.
## Usage Patterns
Invoke this skill via shell commands in scripts or AI prompts. Always prefix commands with `sudo` for root privileges. Example 1: To install a package and add a user, use a sequence like: `sudo apt update; sudo apt install nginx -y; sudo useradd webuser -m`. Example 2: For disk management and log check, run: `sudo fdisk /dev/sda; sudo mkfs.ext4 /dev/sda1; sudo mount /dev/sda1 /mnt; sudo journalctl -u nginx --since "1 hour ago"`.
## Common Commands/API
- **Apt Example**: Update and install a package:
```
sudo apt update
sudo apt install vim -y
```
- **User Management Example**: Add a user with home directory:
```
sudo useradd newuser -m -s /bin/bash
sudo passwd newuser
```
- **Disk/Filesystem Example**: Create and mount a filesystem:
```
sudo fdisk -l /dev/sdb # List partitions
sudo mkfs.ext4 /dev/sdb1
sudo mount /dev/sdb1 /mnt/data
```
- **Sysctl Example**: Set a kernel parameter:
```
echo "net.core.somaxconn=1024" | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
```
- **Log Management Example**: Filter logs for a service:
```
sudo journalctl -u apache2 --since yesterday
sudo journalctl -p err # Show only errors
```
## Integration Notes
Run commands in a Bash environment on Ubuntu 24.04\. For remote access, use SSH; no API keys required for core functions, but if integrating with external tools like monitoring APIs, set env vars like `$LINUX_API_KEY` for authentication. Ensure the AI agent prefixes commands with `sudo` and handles output parsing, e.g., check for `apt` success via exit codes.
## Error Handling
Check command exit codes immediately; for example, after `sudo apt install package`, verify with `if [ $? -ne 0 ]; then echo "Installation failed"; fi`. Parse errors from stdout/stderr, e.g., `apt` errors like "E: Unable to locate package" indicate missing repos—run `sudo apt update` first. For sysctl, if a parameter fails, check `/var/log/syslog` for details. Use `try-catch` in scripts:
```
command_output=$(sudo apt update 2>&1)
if [[ $command_output == *"ERROR"* ]]; then echo "Handle error"; fi
```
## Graph Relationships
- Related to: linux cluster skills like "networking" for firewall integration.
- Depends on: None directly, but assumes base Ubuntu setup.
- Conflicts with: None specified.