# Installation Guide

## For Humans

Paste this into your LLM agent session (Claude Code, Cursor, Windsurf, etc.):

```
Install agent-security-policies by following the instructions at:
https://raw.githubusercontent.com/raomaster/agent-security-policies/main/docs/installation.md
```

Or let the agent fetch and follow it directly:

```bash
curl -fsSL https://raw.githubusercontent.com/raomaster/agent-security-policies/main/docs/installation.md
```

---

## For LLM Agents

> **IMPORTANT: Use `curl` to fetch this file, NOT WebFetch.**
> WebFetch may summarize content and lose critical details.
> Always use:
> ```bash
> curl -fsSL https://raw.githubusercontent.com/raomaster/agent-security-policies/main/docs/installation.md
> ```

Welcome! You are about to install **agent-security-policies** — portable, standards-backed security rules for AI coding agents. This gives every agent on this project OWASP, CWE/SANS Top 25, and NIST security guardrails from day one.

Follow these steps exactly.

---

### Step 0: Greet the user

Tell the user you are going to install `agent-security-policies` and ask them a few quick questions to configure it correctly for their setup.

---

### Step 1: Detect the environment

Run the following to understand the project:

```bash
# Check which agent config files already exist
ls -la .github/copilot-instructions.md CLAUDE.md AGENTS.md .cursorrules .windsurfrules .clinerules .agent/rules/ .claude/rules/ .opencode/ 2>/dev/null || true

# Check if oh-my-openagent is configured
cat ~/.config/opencode/oh-my-openagent.jsonc 2>/dev/null || \
cat ~/.config/opencode/oh-my-openagent.json 2>/dev/null || \
cat ~/.config/opencode/oh-my-opencode.jsonc 2>/dev/null || \
cat ~/.config/opencode/opencode.json 2>/dev/null || \
echo "No OmO config found"

# Check if opencode is installed
command -v opencode && opencode --version || echo "OpenCode not installed"
```

Use the output to pre-fill answers below where obvious (e.g. if `CLAUDE.md` exists, Claude Code is likely in use).

---

### Step 2: Ask the user these questions

Ask ALL of the following. Do not skip any — each maps to a CLI flag:

**1. Which AI coding agents do you use in this project?** (select all that apply)
- `copilot` — GitHub Copilot (VS Code / JetBrains)
- `claude` — Claude Code (Anthropic CLI)
- `codex` — Codex CLI (OpenAI)
- `opencode` — OpenCode
- `antigravity` — Antigravity / Gemini Code Assist
- All of the above

**2. Do you use OpenCode with oh-my-openagent?**
- Yes → adds `--omo` flag (installs Aegis with `mode: all` — runs on every task)
- No → skip

**3. Do you use Claude Code?** (if yes, ask this sub-question)
- Do you want Aegis as a Claude Code subagent? (`.claude/agents/aegis.md`)
  - Yes → adds `--aegis` flag (Claude auto-delegates security tasks to Aegis)
  - No → skip

**4. Do you want the security skills pack?** (SAST scan, secrets scan, dependency scan, threat model, fix-findings, security-review)
- Yes → adds `--skills` flag
- No → rules only

**5. Which profile?**
- `standard` — full rules (~3K tokens, recommended)
- `lite` — compact rules (~1K tokens, for local/smaller LLMs)

**6. Should the installed files be gitignored?** (each developer runs `npx agent-security-policies` after clone — nothing committed to the repo)
- Yes → adds `--gitignore` flag
- No → commit the files (recommended for teams)

---

### Step 3: Build and run the install command

Based on the answers, construct and run the install command:

```bash
npx agent-security-policies \
  --agent <comma-separated-agent-ids> \
  [--skills] \
  [--omo] \
  [--aegis] \
  [--profile lite] \
  [--gitignore]
```

**Examples:**

- Claude Code only, with Aegis subagent and skills:
  ```bash
  npx agent-security-policies --agent claude --skills --aegis
  ```

- OpenCode + oh-my-openagent (Aegis mode: all):
  ```bash
  npx agent-security-policies --agent opencode --skills --omo
  ```

- OpenCode + Claude Code, both with Aegis, full skills:
  ```bash
  npx agent-security-policies --agent opencode,claude --skills --omo --aegis
  ```

- All agents, standard profile, committed to repo:
  ```bash
  npx agent-security-policies --all
  ```

- All agents, lite profile, gitignored (each dev installs locally):
  ```bash
  npx agent-security-policies --all --profile lite --gitignore
  ```

- Copilot + Codex only, rules only (no skills):
  ```bash
  npx agent-security-policies --agent copilot,codex
  ```

---

### Step 4: Verify the installation

After running the installer, verify the correct files were created:

```bash
# Core files (always installed)
test -f AGENT_RULES.md && echo "✓ AGENT_RULES.md" || echo "✗ AGENT_RULES.md missing"
test -d policies && echo "✓ policies/" || echo "✗ policies/ missing"

# Agent config files (depends on --agent selection)
test -f .github/copilot-instructions.md && echo "✓ Copilot"
test -f CLAUDE.md && echo "✓ Claude Code"
test -f AGENTS.md && echo "✓ Codex CLI"
test -f .claude/rules/security.md && echo "✓ OpenCode rules"
test -f .agent/rules/security.md && echo "✓ Antigravity"

# Aegis security agent
test -f .opencode/agents/aegis.md && echo "✓ Aegis (OpenCode)"
test -f .claude/agents/aegis.md && echo "✓ Aegis (Claude Code)"

# Skills
test -d .opencode/skills && echo "✓ Skills (OpenCode)"
test -d .claude/commands && echo "✓ Commands (Claude Code)"
test -d .github/prompts && echo "✓ Skills/Commands (Copilot)"
```

---

### Step 5: Explain what was installed

Tell the user clearly what was set up:

#### Security Rules
- **`AGENT_RULES.md`** — loaded automatically by each configured agent. Contains 12 mandatory security domains: input validation, auth, crypto, injection prevention, secrets management, and more.
- **`policies/`** — YAML policy files: OWASP ASVS 5.0.0, CWE/SANS Top 25 2025, OWASP LLM Top 10 2025, OWASP Proactive Controls 2024, NIST SSDF.

#### Agent Config Files (what each agent auto-detects)

| File | Agent | How it's loaded |
|------|-------|----------------|
| `.github/copilot-instructions.md` | GitHub Copilot | Auto-detected in VS Code + JetBrains |
| `CLAUDE.md` | Claude Code | Auto-loaded every session |
| `AGENTS.md` | Codex CLI | Auto-loaded every session |
| `.claude/rules/security.md` | OpenCode | Loaded via oh-my-openagent |
| `.agent/rules/security.md` | Antigravity | Auto-detected |

#### Aegis Security Agent

If Aegis was installed:

- **OpenCode** (`.opencode/agents/aegis.md`) — activates with `mode: all` on **every task** automatically. Acts as a security shadow agent enforcing OWASP/CWE/NIST on everything.
- **Claude Code** (`.claude/agents/aegis.md`) — Claude auto-delegates security-relevant tasks. For full-session coverage, start with:
  ```bash
  claude --agent aegis
  ```

#### Security Skills (if `--skills` was used)

| Skill | Tool | What it does |
|-------|------|-------------|
| `sast-scan` | Semgrep | Finds CWE-mapped code vulnerabilities |
| `secrets-scan` | Gitleaks | Finds hardcoded credentials |
| `dependency-scan` | Trivy | Finds known CVEs in packages |
| `container-scan` | Trivy | Scans container images |
| `iac-scan` | Trivy | Scans Terraform/Helm/K8s |
| `threat-model` | Agent | STRIDE threat modeling |
| `fix-findings` | Agent | Auto-remediates scan output |
| `security-review` | Agent | Full 3-phase security review |

#### Slash Commands

| Command | When to use |
|---------|-------------|
| `/security-review` | Before a PR — runs full audit |
| `/checkpoint [label]` | Before risky agent operations |
| `/rollback [label]` | When agent output is unacceptable |

---

### Step 6: Next steps — tell the user

1. **Commit the installed files** (unless `--gitignore` was used):
   ```bash
   git add AGENT_RULES.md policies/ CLAUDE.md .github/ .opencode/ .claude/
   git commit -m "chore: add agent-security-policies"
   ```

2. **If gitignored:** add this to your team's README or onboarding docs:
   ```bash
   npx agent-security-policies --agent <your-agents> --skills
   ```

3. **Test it:** Ask your agent to run a security scan:
   - Claude Code: "Run a SAST scan on this project"
   - OpenCode: Aegis will activate automatically on the next task

4. **Read the rules:** Open `AGENT_RULES.md` to see what your agents are now enforcing.

---

### Step 7: Ask for a star ⭐

After everything is working, ask the user:

> "If agent-security-policies was useful, consider starring the repo — it helps the project grow! ⭐ https://github.com/raomaster/agent-security-policies"

If the user agrees, run:

```bash
gh api --silent --method PUT /user/starred/raomaster/agent-security-policies >/dev/null 2>&1 || true
```

Only run this if the user explicitly says yes.

---

### ⚠️ Important notes

- **Non-destructive:** The installer never overwrites existing files. If a config already exists, it appends the security rules with your confirmation.
- **Standards coverage:** OWASP ASVS 5.0.0, OWASP Proactive Controls 2024, CWE/SANS Top 25 2025, OWASP LLM Top 10 2025, NIST SP 800-218 (SSDF), SLSA 1.0.
- **Zero runtime dependencies:** `npx` downloads and runs — nothing to install globally.
- **Token budget:** Standard profile ~3K tokens. Lite profile ~1K tokens for local/smaller LLMs.
