# OpenCLI Agent Pack: ast-grep

Use this when an AI agent needs to work with `sg`.

## What this CLI is for
Structural search and replace for code, not just text. Built by ast-grep. Start with `sg --pattern 'console.log($$$)' src` and go from there. Supports structured output — good for scripts and agents. Runs entirely on your machine.

Best for: Finding and rewriting code by AST pattern — what ripgrep cannot see.

## Agent readiness
Great for agents (85/100)
- Structured output is available for parsing.
- Supports non-interactive/scripted use.
- Works well in CI or repeatable automation.
- Can run locally with less credential exposure.

## Install
```sh
brew install ast-grep
```

## Verify before real work
```sh
sg --version
```
Expected signal: sg responds locally and is ready for the first real command.

## Safe starting commands
```sh
sg --version
```

```sh
sg --pattern 'console.log($$$)' src
```

```sh
sg --pattern 'console.log($$$)' --rewrite 'logger.debug($$$)' --dry-run src
```

```sh
sg scan
```

## Guardrails for agents
- Start read-only, then ask before mutations.

## Suggested agent instruction
You may use ast-grep (`sg`) for finding and rewriting code by ast pattern — what ripgrep cannot see.. First install it if missing, then run the verify command. Start with read-only or inspection commands. Summarize what you found before changing anything. Ask for confirmation before commands that mutate remote state, spend money, deploy, delete data, merge code, or expose secrets.

Source: OpenCLI
