---
import Base from '../layouts/Base.astro';
import Terminal from '../components/Terminal.astro';
import { Code } from 'astro:components';
---

<Base title="CLI" description="Warden CLI commands and options">
  <h1>CLI</h1>

  <div class="command-card">
    <h3>warden</h3>
    <div class="synopsis">warden [target] [options]</div>
    <p>Run code analysis on the specified target. If no target is given, analyzes uncommitted changes.</p>
    <ul>
      <li><code>target</code> - Files, directories, or git refs to analyze (optional)</li>
    </ul>
    <Terminal>
      <Code
        code={`warden                     # Analyze uncommitted changes (default)
warden src/auth.ts         # Analyze specific file
warden src/api/            # Analyze a directory
warden HEAD~3..HEAD        # Analyze changes in a git range`}
        lang="bash"
        theme="vitesse-black"
      />
    </Terminal>
  </div>

  <div class="command-card">
    <h3>warden init</h3>
    <div class="synopsis">warden init [options]</div>
    <p>Initialize Warden in your project. Creates a configuration file and GitHub workflow.</p>
    <ul>
      <li><code>-f, --force</code>  - Overwrite existing files</li>
    </ul>
    <Terminal>
      <Code
        code={`warden init            # Interactive setup
warden init --force    # Overwrite existing files`}
        lang="bash"
        theme="vitesse-black"
      />
    </Terminal>
  </div>

  <div class="command-card">
    <h3>warden add</h3>
    <div class="synopsis">warden add [skill-name] [options]</div>
    <p>Add a skill trigger to your configuration. Run without arguments for interactive mode.</p>
    <ul>
      <li><code>skill-name</code>  - Name of the skill to add (optional, interactive if omitted)</li>
      <li><code>--remote &lt;owner/repo[@sha]&gt;</code>  - Install skill from a GitHub repository</li>
      <li><code>--list</code>  - List available skills</li>
    </ul>
    <Terminal>
      <Code
        code={`warden add                     # Interactive mode
warden add security-review     # Add local skill
warden add --list              # List available skills

# Remote skills from GitHub repositories
warden add --remote getsentry/warden-skills --skill security-review
warden add --remote getsentry/warden-skills@abc123 --skill api-review  # Pinned to commit`}
        lang="bash"
        theme="vitesse-black"
      />
    </Terminal>
  </div>

  <div class="command-card">
    <h3>warden sync</h3>
    <div class="synopsis">warden sync [remote]</div>
    <p>Update cached remote skills. Refreshes unpinned skills to their latest versions.</p>
    <ul>
      <li><code>remote</code>  - Specific remote to sync (e.g., <code>owner/repo</code>). If omitted, syncs all.</li>
    </ul>
    <Terminal>
      <Code
        code={`warden sync                    # Update all remote skills
warden sync getsentry/warden-skills  # Update specific remote`}
        lang="bash"
        theme="vitesse-black"
      />
    </Terminal>
  </div>

  <div class="command-card">
    <h3>warden setup-app</h3>
    <div class="synopsis">warden setup-app [options]</div>
    <p>Create a GitHub App for Warden. This gives you a custom bot identity instead of the generic "github-actions" user.</p>
    <ul>
      <li><code>--org &lt;name&gt;</code>  - Create the app for an organization instead of your personal account</li>
      <li><code>--port &lt;number&gt;</code>  - Local server port (default: 3000)</li>
      <li><code>--timeout &lt;sec&gt;</code>  - Callback timeout in seconds (default: 300)</li>
      <li><code>--name &lt;string&gt;</code>  - Custom app name (default: Warden)</li>
      <li><code>--no-open</code>  - Print URL instead of opening browser</li>
    </ul>
    <Terminal>
      <Code
        code={`warden setup-app               # For a personal account
warden setup-app --org my-org  # For an organization`}
        lang="bash"
        theme="vitesse-black"
      />
    </Terminal>
  </div>

  <h2>Global Options</h2>
  <ul>
    <li><code>--skill &lt;name-or-path&gt;</code>  - Run a specific skill by name or path (see <a href="#skill-references">Skill References</a>)</li>
    <li><code>--fix</code>  - Automatically apply suggested fixes</li>
    <li><code>--json</code>  - Output results as JSON</li>
    <li><code>--fail-on &lt;level&gt;</code>  - Exit with error code if findings meet severity: <code>critical</code>, <code>high</code>, <code>medium</code>, <code>low</code></li>
    <li><code>--config &lt;path&gt;</code>  - Path to config file (default: <code>warden.toml</code>)</li>
    <li><code>--verbose</code>  - Show detailed output</li>
    <li><code>-m, --model &lt;model&gt;</code>  - Model to use (fallback when not set in config)</li>
    <li><code>-o, --output &lt;path&gt;</code>  - Write full run output to a JSONL file</li>
    <li><code>--comment-on &lt;severity&gt;</code>  - Only show findings at or above this severity in output</li>
    <li><code>--parallel &lt;n&gt;</code>  - Max concurrent trigger/skill executions (default: 4)</li>
    <li><code>--quiet</code>  - Errors and final summary only</li>
    <li><code>-vv</code>  - Show debug info (token counts, latencies)</li>
    <li><code>--color / --no-color</code>  - Override color detection</li>
    <li><code>--offline</code>  - Use cached remote skills only, skip network fetches</li>
    <li><code>--help</code>  - Show help message</li>
    <li><code>--version</code>  - Show version number</li>
  </ul>

  <h2 id="skill-references">Skill References</h2>

  <p>The <code>--skill</code> option accepts multiple formats:</p>

  <Terminal>
    <Code
      code={`# By name (resolved from .warden/skills/, .agents/skills/, .claude/skills/)
warden --skill security-review

# Relative path
warden --skill ./skills/custom-review

# Absolute path
warden --skill /shared/skills/company-review

# Home directory expansion
warden --skill ~/my-skills/security`}
      lang="bash"
      theme="vitesse-black"
    />
  </Terminal>

  <p>Resolution order:</p>
  <ol>
    <li>Remote repository (if <code>remote</code> is specified in trigger config)</li>
    <li>Direct path (if contains <code>/</code>, <code>\</code>, or starts with <code>.</code>)</li>
    <li>Conventional directories: <code>.warden/skills/</code>, <code>.agents/skills/</code>, <code>.claude/skills/</code></li>
  </ol>

  <h2>Environment Variables</h2>

  <dl>
    <dt>WARDEN_ANTHROPIC_API_KEY</dt>
    <dd>Anthropic API key. Required for CI/CD. For local use, Warden can use your Claude Code subscription instead (run <code>claude login</code>).</dd>
    <dt>ANTHROPIC_API_KEY</dt>
    <dd>Fallback if <code>WARDEN_ANTHROPIC_API_KEY</code> is not set</dd>
    <dt>WARDEN_SKILL_CACHE_TTL</dt>
    <dd>Cache duration for unpinned remote skills. Default: 24h</dd>
  </dl>
</Base>
