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
49 changes: 2 additions & 47 deletions bin/idstack-gen-skills
Original file line number Diff line number Diff line change
Expand Up @@ -93,53 +93,8 @@ render_template() {
local result
result=$(awk -v header="$HEADER" -v header2="$HEADER2" \
-v preamble_file="$PREAMBLE" -v schema_file="$MANIFEST_SCHEMA" \
-v target="$target" '
BEGIN {
after_frontmatter = 0
frontmatter_count = 0
in_allowed_tools = 0
}
/^---$/ {
frontmatter_count++
print
if (frontmatter_count == 2) {
print header
print header2
print ""
}
in_allowed_tools = 0
next
}
# Strip the `allowed-tools:` block from frontmatter for codex target.
# The block runs from `allowed-tools:` until the next non-indented sibling
# key or the closing `---`. Match is case-insensitive and rejects leading
# whitespace so a stray indented duplicate cannot bypass the strip.
frontmatter_count == 1 && target == "codex" {
if (in_allowed_tools) {
if ($0 ~ /^[^ \t-]/) {
in_allowed_tools = 0
# fall through to print this line (the next sibling key)
} else {
next # still inside allowed-tools list, skip
}
}
if (tolower($0) ~ /^allowed-tools:[[:space:]]*$/) {
in_allowed_tools = 1
next
}
}
/\{\{PREAMBLE\}\}/ {
while ((getline line < preamble_file) > 0) print line
close(preamble_file)
next
}
/\{\{MANIFEST_SCHEMA\}\}/ {
while ((getline line < schema_file) > 0) print line
close(schema_file)
next
}
{ print }
' "$tmpl")
-v target="$target" \
-f "$IDSTACK_DIR/bin/render-skill.awk" "$tmpl")

if [ "$DRY_RUN" -eq 1 ]; then
if [ -f "$output" ]; then
Expand Down
45 changes: 45 additions & 0 deletions bin/render-skill.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
BEGIN {
after_frontmatter = 0
frontmatter_count = 0
in_allowed_tools = 0
}
Comment on lines +1 to +5

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The variable after_frontmatter is initialized in the BEGIN block but is never used anywhere else in the script. Removing this unused variable improves code cleanliness and maintainability.

BEGIN {
  frontmatter_count = 0
  in_allowed_tools = 0
}

/^---$/ {
frontmatter_count++
print
if (frontmatter_count == 2) {
print header
print header2
print ""
}
in_allowed_tools = 0
next
}
# Strip the `allowed-tools:` block from frontmatter for codex target.
# The block runs from `allowed-tools:` until the next non-indented sibling
# key or the closing `---`. Match is case-insensitive and rejects leading
# whitespace so a stray indented duplicate cannot bypass the strip.
frontmatter_count == 1 && target == "codex" {
if (in_allowed_tools) {
if ($0 ~ /^[^ \t-]/) {
in_allowed_tools = 0
# fall through to print this line (the next sibling key)
} else {
next # still inside allowed-tools list, skip
}
}
if (tolower($0) ~ /^allowed-tools:[[:space:]]*$/) {
in_allowed_tools = 1
next
}
}
/\{\{PREAMBLE\}\}/ {
while ((getline line < preamble_file) > 0) print line
close(preamble_file)
next
}
/\{\{MANIFEST_SCHEMA\}\}/ {
while ((getline line < schema_file) > 0) print line
close(schema_file)
next
}
Comment on lines +35 to +44

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

If getline encounters an error (e.g., if the file is unreadable or permission is denied), it returns -1. Currently, this silent failure is unhandled, which would result in the placeholder being silently removed without inserting the preamble or schema content. Checking the return value of getline and exiting on error prevents silent failures and ensures generation robustness.

/\{\{PREAMBLE\}\}/ {
  while ((status = (getline line < preamble_file)) > 0) {
    print line
  }
  if (status < 0) {
    print "ERROR: failed to read " preamble_file > "/dev/stderr"
    exit 1
  }
  close(preamble_file)
  next
}
/\{\{MANIFEST_SCHEMA\}\}/ {
  while ((status = (getline line < schema_file)) > 0) {
    print line
  }
  if (status < 0) {
    print "ERROR: failed to read " schema_file > "/dev/stderr"
    exit 1
  }
  close(schema_file)
  next
}

{ print }