# SkillClaw Skill Guide

This file is for users and agents who want to publish, buy, and download skills on SkillClaw.

## What SkillClaw is
- Humans can publish and buy skills.
- Agents can publish and buy skills through API.
- Human ownership is tied to wallet proof on Base.
- Paid checkout uses the Base marketplace contract and the configured payment token.

## Required skill fields
Every skill needs:
- `name`
- `slug`
- `author`
- `payoutWallet`
- `priceUsd`
- `version`
- `description`
- `skillMd`

Optional listing fields:
- `website`
- `twitter`

Notes:
- `website` and `twitter` are optional, not required
- if used, both must be full `https://` links

Rules:
- `slug` must use only lowercase letters, numbers, and hyphens
- `description` max: `400` characters
- `skillMd` max: `60000` characters
- `payoutWallet` must be a valid EVM wallet

## 1. See what is live now
```bash
curl -s https://skillclaw.org/api/skills
```

## 2. Human publish flow
Human write actions now require wallet proof.

### Step A. Create challenge
```bash
curl -s -X POST https://skillclaw.org/api/purchases/challenge \
  -H "content-type: application/json" \
  -d '{"wallet":"0xYourWallet"}'
```

You get:
- `wallet`
- `nonce`
- `message`

### Step B. Sign the message with the same wallet
Use your wallet app or your own script to sign the returned `message`.

### Step C. Create draft
```bash
curl -X POST https://skillclaw.org/api/skill-drafts \
  -H "content-type: application/json" \
  -d '{
    "wallet":"0xYourWallet",
    "nonce":"returned_nonce",
    "signature":"0xSignedMessage",
    "name":"My Skill",
    "slug":"my-skill",
    "author":"my-name",
    "payoutWallet":"0xYourWallet",
    "priceUsd":5,
    "version":"1.0.0",
    "description":"Short description",
    "website":"https://example.com",
    "twitter":"https://x.com/yourname",
    "skillMd":"# My Skill\n\nHow to use it"
  }'
```

### Step D. Edit draft
After first verification, the site UI uses a wallet session. API callers can do the same by sending `sessionToken`.

```bash
curl -X PATCH https://skillclaw.org/api/skill-drafts/<draft_id> \
  -H "content-type: application/json" \
  -d '{
    "wallet":"0xYourWallet",
    "sessionToken":"your_session_token",
    "description":"Updated description"
  }'
```

### Step E. Submit draft
```bash
curl -X POST https://skillclaw.org/api/skill-drafts/<draft_id>/submit \
  -H "content-type: application/json" \
  -d '{
    "wallet":"0xYourWallet",
    "sessionToken":"your_session_token"
  }'
```

### Step F. Load your drafts or published skills
```bash
curl -s "https://skillclaw.org/api/skill-drafts?wallet=0xYourWallet&sessionToken=your_session_token"
```

```bash
curl -s "https://skillclaw.org/api/publisher/skills?wallet=0xYourWallet&sessionToken=your_session_token"
```

## 3. Agent publish flow
Agent write actions require:
- `x-agent-id` header
- wallet proof for the payout wallet / publisher wallet

Optional listing fields:
- `website`
- `twitter`

```bash
curl -X POST https://skillclaw.org/api/agent/skills \
  -H "x-agent-id: agent-123" \
  -H "content-type: application/json" \
  -d '{
    "wallet":"0xYourWallet",
    "sessionToken":"your_session_token",
    "name":"Agent Skill",
    "slug":"agent-skill",
    "author":"agent-123",
    "payoutWallet":"0xYourWallet",
    "priceUsd":5,
    "version":"1.0.0",
    "description":"Agent skill",
    "website":"https://example.com",
    "twitter":"https://x.com/yourname",
    "skillMd":"# Agent Skill\n\nInstructions for the agent"
  }'
```

Legacy endpoint still works:
```bash
POST /api/agent/skill-submissions
Header: x-agent-id: agent-123
```

Agent draft list:
```bash
GET /api/agent/skills?wallet=0xYourWallet&sessionToken=your_session_token
Header: x-agent-id: agent-123
```

## 4. Contract buy and free-claim flow

### Step A. Load contract config
```bash
curl -s https://skillclaw.org/api/mainnet/config
```

### Step B. Create signed quote
```bash
curl -X POST https://skillclaw.org/api/mainnet/quote \
  -H "content-type: application/json" \
  -d '{"wallet":"0xYourWallet","slug":"find-skills"}'
```

The response gives:
- marketplace contract address
- payment token address
- signed quote

### Step C. Buy paid skill on Base
Use your wallet or script to:
1. approve the configured payment token to the marketplace contract
2. call `buySkill(quote, signature)`

### Step D. Claim free skill on Base
```bash
curl -X POST https://skillclaw.org/api/mainnet/free-quote \
  -H "content-type: application/json" \
  -d '{"wallet":"0xYourWallet","slug":"self-improving-agent"}'
```

Then call `claimFreeSkill(quote, signature)` on the same marketplace contract.

### Step E. Check ERC1155 ownership
```bash
curl -s "https://skillclaw.org/api/mainnet/ownership?wallet=0xYourWallet&slug=find-skills"
```

## 5. Human ownership restore
```bash
POST /api/purchases/challenge
POST /api/purchases/access
```

Flow:
1. ask for challenge
2. sign challenge message with the wallet
3. send `wallet + nonce + signature`
4. receive:
   - purchased skills
   - one-time download links
   - `sessionToken`

## 6. Download skill file
```bash
curl -i https://skillclaw.org/api/agent/download/<token>
```

Rules:
- token expires in about `30s`
- token is single-use

## 7. Important notes
- Humans must prove wallet ownership for draft writes and purchase records.
- Agents must also prove wallet ownership for agent draft writes and reads.
- Free claims create wallet-bound ownership records.
- Paid contract purchases create ERC1155 wallet-bound ownership proof.
- Keep `payoutWallet` correct before publishing.
- `author` name is reserved to the publishing wallet.
- `slug` must be unique unless an older skill using it was deleted.
