Skip to content
Merged
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
12 changes: 9 additions & 3 deletions scripts/generate-skill-catalog.sh
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@ extract_frontmatter() {
# Returns JSON object with only the fields we project into the catalog.
parse_frontmatter() {
local fm="$1"
awk -v fm="$fm" '
# Feed the frontmatter on stdin rather than via `-v fm=...`: BSD/POSIX awk
# rejects a literal newline inside a `-v var=value` assignment (only GNU awk
# tolerates it), so the multi-line value tripped "awk: newline in string" on
# macOS hosts without gawk. Lines are accumulated into lines[] and processed
# in END, identical to the prior split(fm,...) flow. (ag-mm6q)
printf '%s\n' "$fm" | awk '
function trim(s){ sub(/^[[:space:]]+/,"",s); sub(/[[:space:]]+$/,"",s); return s }
function jstr(s) {
gsub(/\\/, "\\\\", s)
Expand All @@ -83,7 +88,6 @@ parse_frontmatter() {
return "\"" s "\""
}
BEGIN {
n = split(fm, lines, "\n")
cur_key = ""
in_list = 0
list_buf = ""
Expand All @@ -98,9 +102,11 @@ parse_frontmatter() {
ctx_list = ""
}
{
# Re-iterate over the lines stored in `lines[]`.
# Accumulate each input line; the parse runs over lines[] in END.
lines[NR] = $0
}
END {
n = NR
for (i = 1; i <= n; i++) {
line = lines[i]
if (line ~ /^[[:space:]]*$/) { continue }
Expand Down
26 changes: 26 additions & 0 deletions tests/scripts/generate-skill-catalog.bats
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,32 @@ skill_api_version: 1"
echo "$output" | jq -e '.skills[0].context_rel[2].with == "delta"' >/dev/null
}

@test "multi-line frontmatter parses on BSD/POSIX awk without 'newline in string' (ag-mm6q)" {
# Regression for the BSD-awk incompatibility: the parser used to pass the
# whole frontmatter via `awk -v fm="$fm"`, which only GNU awk accepts with
# embedded newlines. On macOS/BSD awk it errored "awk: newline in string"
# and produced no catalog. Assert a multi-line frontmatter parses cleanly
# and the error string never appears on stderr.
write_skill delta "name: delta
description: multi-line frontmatter regression
hexagonal_role: domain
consumes:
- standards
- domain
produces:
- result.json
context_rel:
- kind: customer-of
with: alpha
skill_api_version: 1"
run_gen --stdout
[ "$status" -eq 0 ]
[[ "$output" != *"newline in string"* ]]
echo "$output" | jq -e '.skills[0].name == "delta"' >/dev/null
echo "$output" | jq -e '.skills[0].consumes == ["standards","domain"]' >/dev/null
echo "$output" | jq -e '.skills[0].context_rel[0].with == "alpha"' >/dev/null
}

@test "user_invocable is true only when explicitly set" {
write_skill u1 "name: u1
description: invocable
Expand Down
Loading