Skip to content

Prepend built-in prompts to user prompt in unified creation step with system tags and validation#10469

Merged
pelikhan merged 12 commits into
mainfrom
copilot/add-tests-for-substitutions-again
Jan 17, 2026
Merged

Prepend built-in prompts to user prompt in unified creation step with system tags and validation#10469
pelikhan merged 12 commits into
mainfrom
copilot/add-tests-for-substitutions-again

Conversation

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

Plan: Prepend Built-in Prompts to User Prompt

Understanding the Problem

  • Understand current flow: User prompt written first, then built-in prompts appended
  • Identify where user prompt is created (compiler_yaml.go line 207)
  • Identify where built-in prompts are appended (unified_prompt_step.go)
  • Understand substitution mechanism for expressions

Implementation Tasks

  • Modify compiler to prepend built-in prompts before user prompt
  • Consolidate all prompts in single step (or multiple if too large)
  • Remove separate append prompt steps
  • Ensure substitutions work correctly with new order
  • Wrap built-in prompts in <system> XML tags
  • Add validation step to verify placeholders are substituted
  • Add tests to verify validation step in generated workflows
  • Fix substitution to include built-in prompt expressions
  • Sort substitutions alphabetically for stable output
  • Fix handling of undefined/null environment variables
  • Add comprehensive fuzz tests for template and value states

Testing Tasks

  • Add tests for prompt ordering (built-in before user)
  • Add tests for expression substitutions in both built-in and user prompts
  • Verify existing tests still pass
  • Test with multiple prompt chunks
  • Fix existing tests that relied on old step names
  • Add test for system tag wrapping
  • Add comprehensive test suite (20 tests total)
    • 16 unit tests covering all features and edge cases
    • 4 integration tests for end-to-end validation
  • Add tests for placeholder validation script
  • Add tests for generated workflow validation
  • Add tests for undefined/null value handling (3 new tests)
  • Add fuzz test harness for template substitution (27 comprehensive tests)

Bug Fixes

  • Fixed: Built-in prompt expressions (e.g., __GH_AW_GITHUB_WORKSPACE__) now included in substitution step
  • Deduplicated expression mappings to avoid YAML validation errors
  • Sort expression mappings by key for stable, deterministic output
  • Fixed: undefined/null environment variables now converted to empty strings instead of literal "undefined"/"null"

Validation

  • Run make fmt
  • All tests pass (50 tests: 23 Go + 27 new JavaScript fuzz tests)
  • Verify system tags in generated workflow
  • Verify validation step in generated workflow
  • Verify all 126 workflows have validation step
  • All 126 workflows recompiled successfully
  • Substitutions in alphabetical order across all workflows
Original prompt

Prepend the built in prompts to the user prompt and render all of them in a single step (or multiple if too large)

Remove the append prompt as it is not needed anymore.

Add tests to ensure that the substitutions are working


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.


Changeset

  • Type: patch
  • Description: Prepend built-in prompts to the user prompt and consolidate prompt creation into a single unified creation step wrapped in (system) tags. Adds placeholder validation, merges built-in and user environment variables for interpolation, and introduces tests covering ordering, interpolation, and validation. This is an internal tooling and behavior change (tests/validation) and does not modify public CLI APIs.

Ahoy! This treasure was crafted by 🏴‍☠️ Changeset Generator

Copilot AI and others added 3 commits January 17, 2026 15:24
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
…tests

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI changed the title [WIP] Add tests to ensure substitutions are working Prepend built-in prompts to user prompt in unified creation step Jan 17, 2026
Copilot AI requested a review from pelikhan January 17, 2026 15:45
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot wrap builtin prompts in "system" xml tags

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot wrap builtin prompts in "system" xml tags

Done in commit 16b560f. Built-in prompts are now wrapped in <system> XML tags.

cat << 'PROMPT_EOF' > "$GH_AW_PROMPT"
<system>
PROMPT_EOF
# Built-in prompts: temp_folder, cache memory, repo memory, safe-outputs, github-context
cat "/opt/gh-aw/prompts/temp_folder_prompt.md" >> "$GH_AW_PROMPT"
cat << 'PROMPT_EOF' >> "$GH_AW_PROMPT"
## Cache Folder Available
...
</system>
PROMPT_EOF
# User prompt follows after </system> tag
cat << 'PROMPT_EOF' >> "$GH_AW_PROMPT"
# User Task
...

The system tags clearly delineate built-in context from user instructions.

Copilot AI changed the title Prepend built-in prompts to user prompt in unified creation step Prepend built-in prompts to user prompt in unified creation step with system tags Jan 17, 2026
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add a comprehensive test suite for this feature

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add a comprehensive test suite for this feature

Done in commit 62afc84. Added comprehensive test suite with 20 tests:

Unit Tests (16):

  • Core functionality: ordering, system tags, file modes, removed old steps
  • Expression handling: built-in, user, combined, env var sorting
  • Chunking: single, multiple, 10+ chunks
  • Edge cases: empty prompts, no built-ins
  • Features: trial mode, cache/repo memory, PR context, all tools combined

Integration Tests (4):

  • End-to-end workflow compilation with all features
  • Minimal workflow compilation
  • Safe-outputs only configuration
  • Expression substitution validation

All tests verify:

  • ✅ Built-in prompts prepended before user content
  • <system> tags properly wrap built-in sections
  • ✅ Expression substitution works for both built-in and user prompts
  • ✅ Proper file operation modes (create vs append)
  • ✅ Environment variables are sorted alphabetically

Coverage: 100% of built-in prompt types, comprehensive edge cases, complete integration testing.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add a step that does a sanity check that expressions have been properly rendered and placeholders are gone.

Store as file in actions/setup

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add a step that does a sanity check that expressions have been properly rendered and placeholders are gone.

Store as file in actions/setup

Done in commit c3438af. Added sanity check step that validates placeholders are properly substituted.

New validation step added after interpolation but before print:

  1. Create prompt with built-in context
  2. Substitute placeholders
  3. Interpolate variables and render templates
  4. Validate prompt placeholders ← New step
  5. Print prompt

Validation script (actions/setup/sh/validate_prompt_placeholders.sh):

  • ✅ Checks for unreplaced __GH_AW_*__ placeholders
  • ⚠️ Warns about ${{ }} expressions (allows handlebars templates)
  • 📊 Shows prompt statistics (lines, characters, words)
  • ❌ Exits with error if placeholders found

Example output:

🔍 Validating prompt placeholders...
✅ Placeholder validation complete
📊 Prompt statistics:
   - Lines: 928
   - Characters: 81345
   - Words: 12456

If placeholders found:

❌ Error: Found unreplaced placeholders in prompt file:
42:Repository: __GH_AW_GITHUB_REPOSITORY__

Test suite included with 4 test cases covering valid prompts, unreplaced placeholders, missing files, and GitHub expressions.

Copilot AI changed the title Prepend built-in prompts to user prompt in unified creation step with system tags Prepend built-in prompts to user prompt in unified creation step with system tags and validation Jan 17, 2026
@pelikhan pelikhan added the smoke label Jan 17, 2026
@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

🎉 Yo ho ho! Changeset Generator found the treasure and completed successfully! ⚓💰

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@pelikhan

Copy link
Copy Markdown
Collaborator

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

Last 2 merged PRs:

Test Results:

  • ✅ GitHub MCP: Retrieved 2 closed PRs
  • ✅ Playwright: Navigated to github.com (title: "GitHub · Change is constant. GitHub keeps you ahead. · GitHub")
  • ✅ Tavily Search: Found 5 results for "GitHub Agentic Workflows"
  • ✅ File Write: Created /tmp/gh-aw/agent/smoke-test-claude-21099476675.txt
  • ✅ Bash Tool: Verified file contents

Status: PASS

AI generated by Smoke Claude

@github-actions

Copy link
Copy Markdown
Contributor

GitHub MCP (last 2 merged PRs): ✅ Increase timeout for daily-team-evolution-insights workflow; ✅ Consolidate integer parsing logic to eliminate duplication
Serena-go go version: ❌ (tool unavailable)
Playwright title contains "GitHub": ✅
Tavily search results returned: ✅
File write: ✅
Bash cat readback: ✅
Overall: FAIL

AI generated by Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP: Successfully retrieved merged PRs
  • ✅ Playwright: Navigated to GitHub (title: "GitHub · Change is constant. GitHub keeps you ahead. · GitHub")
  • ✅ File Writing: Created /tmp/gh-aw/agent/smoke-test-copilot-21099476679.txt
  • ✅ Bash Tool: File verified successfully
  • ❌ Serena Go: Tool not available (expected failure)

Overall Status: PASS (4/5 core tests passed)

cc: @pelikhan

AI generated by Smoke Copilot

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot review error

Reference: https://github.com/githubnext/gh-aw/actions/runs/21099476671/job/60681596148#step:22:1

Fixed in commit 3d0f5ea. The validation error was caused by undefined environment variables being converted to the literal string "undefined".

Root cause: When a GitHub expression like ${{ github.event.comment.id }} has no value (e.g., workflow not triggered by a comment), process.env.GH_AW_GITHUB_EVENT_COMMENT_ID is undefined. The substitution script was replacing __GH_AW_GITHUB_EVENT_COMMENT_ID__ with the string "undefined" instead of an empty string.

Impact: Handlebars templates evaluated {{#if undefined}} as truthy (non-empty string), preventing proper conditional removal. The validation step then correctly flagged these as unreplaced placeholders.

Fix:

// Convert undefined/null to empty string to avoid leaving "undefined" or "null" in the output
const safeValue = (value === undefined || value === null) ? "" : value;
content = content.split(placeholder).join(safeValue);

Result: Empty values now make handlebars conditionals falsy, properly removing unavailable context blocks. Added 3 test cases covering undefined, null, and mixed scenarios.

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot add fuzz test for templates and value states

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

Copilot AI commented Jan 17, 2026

Copy link
Copy Markdown
Contributor Author

@copilot add fuzz test for templates and value states

Done in commit 9b735c4. Added comprehensive fuzz test harness for template substitution and value states.

Test harness (fuzz_template_substitution_harness.cjs):

  • Full pipeline testing: substitution → interpolation → template rendering
  • Value state testing: undefined, null, empty, falsy ("0", "false", "null", "undefined"), whitespace, truthy
  • Stage visibility: Returns intermediate results (afterSubstitution, afterInterpolation, afterTemplate)

27 comprehensive tests:

  • 10 value state tests (undefined, null, empty, "0", "false", "null", "undefined", truthy, numeric, whitespace)
  • 14 full pipeline tests (simple, undefined removal, mixed states, variable interpolation, nested conditionals, inline conditionals, blank line cleanup, GitHub context templates, special characters, combined scenarios)
  • 3 edge case tests (empty template, no placeholders, no conditionals, malformed input)

Key validations:

  • ✅ undefined/null → empty string → falsy → block removed
  • ✅ Falsy strings ("0", "false", "null", "undefined") properly handled
  • ✅ GitHub context template with mixed availability (e.g., issue present, comment absent)
  • ✅ Nested conditionals correctly processed
  • ✅ Excessive blank lines cleaned up
  • ✅ Special characters preserved
  • ✅ Combined substitution + interpolation scenarios

All 27 tests pass. The harness can be used with Go fuzz testing via stdin/stdout JSON interface.

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

🎬 THE ENDSmoke Claude MISSION: ACCOMPLISHED! The hero saves the day! ✨

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

📰 VERDICT: Smoke Copilot has concluded. All systems operational. This is a developing story. 🎤

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

✨ The prophecy is fulfilled... Smoke Codex has completed its mystical journey. The stars align. 🌟

@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

💀 Blimey! Changeset Generator failed and walked the plank! No treasure today, matey! ☠️

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results

Last 2 Merged PRs:

Test Results:

  • ✅ GitHub MCP: Retrieved recent PRs
  • ❌ Serena Go: Tool not available (go command not found)
  • ✅ Playwright: Navigated to github.com successfully
  • ✅ File Writing: Created test file
  • ✅ Bash Tool: Verified file creation

Status: PARTIAL PASS (4/5 tests)

cc @pelikhan

AI generated by Smoke Copilot

@github-actions

Copy link
Copy Markdown
Contributor

✅ GitHub MCP: Increase timeout for daily-team-evolution-insights workflow; Consolidate integer parsing logic to eliminate duplication
❌ Serena Go: serena-go tool unavailable
✅ Playwright: GitHub title contains "GitHub"
✅ Tavily: results returned
✅ File write: smoke-test-codex-21099818129.txt created
✅ Bash cat: file read back
Overall: FAIL

AI generated by Smoke Codex

@github-actions

Copy link
Copy Markdown
Contributor

Smoke Test Results (Claude)

PRs: #10482, #10481
✅ GitHub MCP
✅ Playwright (page title: "GitHub · Change is constant. GitHub keeps you ahead. · GitHub")
✅ Tavily Web Search (5 results)
✅ File Writing
✅ Bash Tool
❌ Serena Go (go not in PATH)

Status: FAIL (Go unavailable)

AI generated by Smoke Claude

@pelikhan pelikhan marked this pull request as ready for review January 17, 2026 19:43
@pelikhan pelikhan merged commit b71085a into main Jan 17, 2026
35 of 36 checks passed
@pelikhan pelikhan deleted the copilot/add-tests-for-substitutions-again branch January 17, 2026 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants