base / base/skills

register.sh: grep pattern fails when API response has space after colon in JSON key ("builder_code": vs "builder_code":")

Open Beginner friendly
#54 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
119
Forks
125
Avg merge
22h 30m
Merged PRs (30d)
2

Description

**register.sh silently fails when the API returns JSON with a space after the colon**

File: `skills/build-on-base/scripts/register.sh`, line 21

```bash
BUILDER_CODE=$(echo "$RESPONSE" | grep -o '"builder_code":"[^"]*"' | cut -d'"' -f4)
```

The pattern `"builder_code":"[^"]*"` requires no space between `:` and `"`. However, the repo's own reference doc (`references/agents/register.md`) shows the API response as:

```json
{
"builder_code": "bc_a1b2c3d4",
"wallet_address": "0x...",
"usage_instructions": "..."
}
```

That is `"builder_code": "bc_..."` — space after the colon. The grep pattern produces empty output on this format. When `BUILDER_CODE` is empty the script falls into the guard block, prints an error to stderr, and exits 1 — registration fails.

**Reproduction** (no API call needed):

```bash
# Spaced (as shown in reference doc) — FAILS
echo '{"builder_code": "bc_a1b2c3d4","wallet_address":"0x123"}' | grep -o '"builder_code":"[^"]*"' | cut -d'"' -f4
# → (empty)

# Compact — works
echo '{"builder_code":"bc_a1b2c3d4","wallet_address":"0x123"}' | grep -o '"builder_code":"[^"]*"' | cut -d'"' -f4
# → bc_a1b2c3d4
```

**Fix** — two options:

```bash
# Option A: jq (robust, handles all valid JSON including pretty-printed)
BUILDER_CODE=$(echo "$RESPONSE" | jq -r '.builder_code // empty')

# Option B: space-tolerant grep, no jq dependency
BUILDER_CODE=$(echo "$RESPONSE" | grep -o '"builder_code": *"[^"]*"' | grep -o '"[^"]*"$' | tr -d '"')
```

Option A is preferred. Option B is a minimal diff that stays dependency-free.

The script's `set -euo pipefail` and existing empty-check guard prevent data corruption, but the registration command fails instead of succeeding, which blocks the workflow described in `references/agents/register.md`.

Contributor guide

Open the contributing guide

Research direction

Open skills/build-on-base/scripts/register.sh at line 21 and compare its grep pattern with the spaced JSON shown in references/agents/register.md. Reproduce the empty extraction using the issue's shell commands, then make the parsing accept the documented response format while preserving the existing empty-check guard. Done means registration extracts builder_code and no longer exits 1 for the spaced JSON response.

Written by the indexing model from the issue text.

Assessment

Tech stack
shell
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
85/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.