Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions solana-anchor-skill/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2026 Solana Anchor Skill contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
181 changes: 181 additions & 0 deletions solana-anchor-skill/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
# Solana Anchor Skill

A kit-style skill for scaffolding Solana Anchor projects, recovering missing Anchor CLI setup, and generating comprehensive runnable tests for Anchor programs.

This skill focuses on a common builder pain: Anchor projects are easy to initialize, but real test coverage is often inconsistent, under-specified, or blocked by local toolchain issues. The skill routes agents through preflight checks, transparent CLI recovery, test harness detection, IDL/source-driven test generation, and coverage-gap reporting.

## What It Does

- Scaffolds Anchor projects after checking the local CLI is available.
- Documents an approval-based AVM recovery path when `anchor` is missing.
- Detects existing test setup before generating files.
- Generates TypeScript/Mocha tests with `@coral-xyz/anchor` and Chai when TypeScript is detected.
- Generates Rust integration tests when `solana-program-test` or LiteSVM is detected.
- Defaults to `anchor test` against a local validator.
- Routes to Surfpool only when external mainnet-forked state is required.
- Reports tested instructions, tested constraints, edge cases, and coverage gaps.

### Execution Flow

```text
┌──────────────────────────────┐
│ Developer request │
│ scaffold, test, or recover │
└───────────────┬──────────────┘
┌──────────────────────────────┐
│ Skill preflight │
│ inspect repo + Anchor setup │
└───────────────┬──────────────┘
┌─────────┴─────────┐
│ │
▼ ▼
┌──────────────┐ ┌──────────────────────────┐
│ anchor found │ │ anchor missing │
│ continue │ │ request AVM recovery │
└──────┬───────┘ └────────────┬─────────────┘
│ │
│ ▼
│ ┌────────────────────────┐
│ │ Install/activate Anchor │
│ │ cargo install avm │
│ │ avm install/use latest │
│ │ hydrate PATH │
│ └───────────┬────────────┘
│ │
└──────────────┬───────────┘
┌──────────────────────────────┐
│ Scaffolding or test planning │
│ read Anchor.toml, IDL, tests │
└───────────────┬──────────────┘
┌─────────┴──────────┐
│ │
▼ ▼
┌────────────────┐ ┌──────────────────────┐
│ TypeScript test │ │ Rust test setup │
│ Mocha + Chai │ │ program-test/LiteSVM │
└────────┬────────┘ └──────────┬───────────┘
│ │
└───────────┬───────────┘
┌──────────────────────────────┐
│ Generate runnable tests │
│ happy paths, failures, PDAs │
│ numeric and authority edges │
└───────────────┬──────────────┘
┌──────────────────────────────┐
│ Run local validator by default│
│ Surfpool only for live state │
└───────────────┬──────────────┘
┌──────────────────────────────┐
│ Coverage-gap report │
│ tested vs blocked/manual work │
└──────────────────────────────┘
```

## Repository Structure

```text
solana-anchor-skill/
├── README.md
├── LICENSE
├── install.sh
├── agents/
│ └── openai.yaml
├── commands/
│ ├── anchor-generate-tests.md
│ ├── anchor-scaffold.md
│ └── anchor-test.md
└── skill/
├── SKILL.md
├── cli-installation.md
├── anti-patterns.md
├── program-patterns.md
├── resources.md
├── rust-tests.md
├── scaffolding.md
├── testing-anchor.md
└── typescript-tests.md
```

## Installation

Clone the repo and run the installer:

```bash
git clone https://github.com/manueldezman/solana-anchor-skill.git
cd solana-anchor-skill
./install.sh
```

By default, the installer copies `skill/` to:

```text
~/.codex/skills/solana-anchor
```

Install for Claude-compatible skill directories:

```bash
./install.sh --target claude
```

Install non-interactively:

```bash
./install.sh -y
```

Choose a custom destination:

```bash
./install.sh --dest /path/to/skills/solana-anchor
```

## Usage Examples

The skill can be triggered naturally by Anchor-related requests; users do not have to type `Use $solana-anchor`. Explicit invocation still works when they want to force this skill.

```text
Create a new Anchor project named escrow.
```

```text
Generate tests for this Anchor program. Detect whether it uses TypeScript or Rust tests first.
```

```text
anchor command not found. Fix my Anchor CLI setup, then run anchor init.
```

```text
Debug PDA seeds in this Anchor instruction.
```

```text
Add failure-path tests for wrong signer, wrong PDA seeds, duplicate init, and numeric overflow.
```

## Testing Expectations

Generated tests should be runnable and should match the target project:

- TypeScript projects use `@coral-xyz/anchor`, Mocha, and Chai.
- Rust test projects use the existing `solana-program-test` or LiteSVM pattern.
- Anchor `1.1.2` scaffolds Rust/LiteSVM tests by default, so new-project test generation should inspect the generated layout before assuming TypeScript.
- Local validator is the default for validator-backed tests; LiteSVM scaffolds can use `skip_local_validator = true`.
- Surfpool is reserved for programs that need forked external state.

Every test-generation task should end with a coverage-gap table so the developer can see what was generated and what still needs manual fixtures or live-state setup.

## License

MIT. See [LICENSE](LICENSE).
34 changes: 34 additions & 0 deletions solana-anchor-skill/SUBMISSION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Solana Anchor Skill Submission

Canonical repo: https://github.com/manueldezman/solana-anchor-skill

## What it does

This skill extends Codex with a production-oriented Solana Anchor workflow:

- Create new Anchor projects with preflight checks and transparent CLI recovery.
- Install or repair Anchor CLI/AVM setup without hidden automation.
- Build, review, and debug Anchor programs, accounts, constraints, PDAs, seeds, and bumps.
- Detect an existing Anchor test harness before generating tests.
- Generate runnable TypeScript/Mocha or Rust integration tests for IDL instructions, constraints, PDAs, authority checks, and numeric boundaries.
- Default to local `anchor test`, with Surfpool documented as an opt-in path for live external state.

## Validation

- `install.sh` passes shell syntax validation.
- Skill routing and trigger metadata were reviewed with `rg`.
- A disposable Anchor fixture was created and `anchor test` completed successfully.
- Toolchain and scaffold findings were converted into reusable anti-pattern guidance rather than incident-log notes.

## Structure

The submission follows the kit-style layout:

- `README.md`
- `LICENSE`
- `install.sh`
- `agents/openai.yaml`
- `commands/`
- `skill/SKILL.md`
- focused skill docs under `skill/`

7 changes: 7 additions & 0 deletions solana-anchor-skill/agents/openai.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
interface:
display_name: "Solana Anchor"
short_description: "Scaffold, debug, and test Anchor programs"
default_prompt: "Use $solana-anchor to scaffold Anchor projects, install or recover Anchor CLI setup, build/debug programs, or generate runnable tests."

policy:
allow_implicit_invocation: true
20 changes: 20 additions & 0 deletions solana-anchor-skill/commands/anchor-generate-tests.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# /anchor-generate-tests

Generate runnable Anchor program tests that match the target project's existing test harness.

## Procedure

1. Read `skill/testing-anchor.md`.
2. Inspect `Anchor.toml`, package manifests, Rust manifests, existing tests, and IDL.
3. Select TypeScript or Rust based on detected project style.
4. Read `skill/typescript-tests.md` or `skill/rust-tests.md`.
5. Generate runnable tests for IDL instructions, constraints, PDAs, authority checks, and numeric boundaries.
6. Run the project test command when feasible.
7. Finish with the coverage-gap report table.

## Expected Output

- Detected framework and why.
- Test files created or updated.
- Test command run and result.
- Coverage-gap table.
19 changes: 19 additions & 0 deletions solana-anchor-skill/commands/anchor-scaffold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# /anchor-scaffold

Scaffold a new Anchor project with transparent CLI preflight and recovery.

## Procedure

1. Read `skill/SKILL.md`.
2. Read `skill/scaffolding.md` and `skill/cli-installation.md`.
3. Run `anchor --version`.
4. If Anchor is missing, ask before AVM install/recovery commands.
5. Run `anchor init <project-name>` only after the CLI is available.
6. Inspect generated files and report the created project structure.

## Expected Output

- Anchor version used.
- Project path created.
- Any installation commands run or skipped.
- Next recommended test command.
18 changes: 18 additions & 0 deletions solana-anchor-skill/commands/anchor-test.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# /anchor-test

Run or configure Anchor tests with the correct local validator or Surfpool environment.

## Procedure

1. Read `skill/testing-anchor.md`.
2. Default to `anchor test`.
3. Inspect whether the program reads external mainnet state.
4. Use Surfpool only when external state cannot be faked locally.
5. Report the environment choice and any accounts that require forked state.

## Expected Output

- Chosen test environment.
- Command to run.
- External state requirements, if any.
- Test result or blocker.
Loading