From 45427a6c34da3da768b9ec2c3c210ac723cef5b8 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 6 Jun 2026 01:54:30 +0000 Subject: [PATCH] Extract large inline awk script to bin/render-skill.awk Extract the long `awk` script from `render_template()` in `bin/idstack-gen-skills` to a separate standalone file (`bin/render-skill.awk`) and use the `-f` flag to include it. This significantly improves maintainability and readability of `idstack-gen-skills`. Co-authored-by: savvides <1580637+savvides@users.noreply.github.com> --- bin/idstack-gen-skills | 49 ++---------------------------------------- bin/render-skill.awk | 45 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+), 47 deletions(-) create mode 100644 bin/render-skill.awk diff --git a/bin/idstack-gen-skills b/bin/idstack-gen-skills index 04a97ac..5b1cf8e 100755 --- a/bin/idstack-gen-skills +++ b/bin/idstack-gen-skills @@ -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 diff --git a/bin/render-skill.awk b/bin/render-skill.awk new file mode 100644 index 0000000..c70a5b9 --- /dev/null +++ b/bin/render-skill.awk @@ -0,0 +1,45 @@ +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 }