Skip to content

fix(register.sh): handle pretty-printed JSON with space after colon#55

Open
Nexory wants to merge 1 commit into
base:masterfrom
Nexory:fix/register-sh-json-spaced-format
Open

fix(register.sh): handle pretty-printed JSON with space after colon#55
Nexory wants to merge 1 commit into
base:masterfrom
Nexory:fix/register-sh-json-spaced-format

Conversation

@Nexory
Copy link
Copy Markdown

@Nexory Nexory commented May 29, 2026

Closes #54

This patch fixes the grep pattern in skills/build-on-base/scripts/register.sh line 21 so it tolerates the space-after-colon format that the API actually returns (as documented in references/agents/register.md).

Before:

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

The pattern requires no space between the colon and the value, so the pretty-printed format "builder_code": "bc_..." matches zero bytes, BUILDER_CODE becomes empty, and the script exits 1.

After:

BUILDER_CODE=$(echo "$RESPONSE" | grep -oE '"builder_code": *"[^"]*"' | grep -oE '"[^"]*"$' | tr -d '"')

The new pattern uses grep -E with a *-quantifier between the colon and the opening quote, matching zero or more spaces. A second grep -oE extracts the trailing quoted value, then tr -d '"' strips the quotes. No new dependencies (still pure POSIX). Both compact and pretty-printed JSON now work.

Reproduction confirming the fix:

# Spaced JSON (current API format)
echo '{"builder_code": "bc_a1b2c3d4"}' | grep -oE '"builder_code": *"[^"]*"' | grep -oE '"[^"]*"$' | tr -d '"'
# -> bc_a1b2c3d4 (PASS)

# Compact JSON (legacy)
echo '{"builder_code":"bc_a1b2c3d4"}' | grep -oE '"builder_code": *"[^"]*"' | grep -oE '"[^"]*"$' | tr -d '"'
# -> bc_a1b2c3d4 (PASS)

Both formats produce identical output, the original bug is gone, and no new dependency is introduced.

The grep pattern "builder_code":"[^"]*" requires no space between the
colon and the value, but the API response (shown in
references/agents/register.md) is pretty-printed with a space after
the colon. The pattern matches zero bytes on that format, BUILDER_CODE
becomes empty, and the script exits 1.

This patch makes the pattern space-tolerant by using grep -E with
*-quantifier between : and ", then extracts the value via a second
grep + tr. No new dependencies. Both compact and pretty-printed
JSON now work.

Closes base#54
@cb-heimdall
Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants