Skip to content

Duplicate Code: Prompt template path construction #28588

@github-actions

Description

@github-actions

Summary

Analysis of commit def67ceb11bd83b0121a5ad22873e3e8cbc5990f found a repeated prompt-template path construction pattern in production CommonJS handlers. The current PR adds another instance in actions/setup/js/handle_agent_failure.cjs for cache_memory_miss.md, bringing attention to a broader repeated pattern around \$\{process.env.RUNNER_TEMP}/gh-aw/prompts/....

Duplication Details

Pattern: Direct prompt template path construction

  • Severity: Medium
  • Occurrences: 26 production .cjs occurrences across multiple handlers
  • Changed-file occurrence: actions/setup/js/handle_agent_failure.cjs:621
  • Related locations:
    • actions/setup/js/handle_agent_failure.cjs:621, :700, :714, :730, :755, :793, :810, :840, :918, :1266, :1431
    • actions/setup/js/create_pull_request.cjs:1620, :1637, :1837
    • actions/setup/js/handle_detection_runs.cjs:49, :110
    • actions/setup/js/handle_noop_message.cjs:51, :187
    • actions/setup/js/create_missing_data_issue.cjs:23
    • actions/setup/js/create_missing_tool_issue.cjs:23
    • actions/setup/js/create_report_incomplete_issue.cjs:25
    • actions/setup/js/checkout_pr_branch.cjs:326
    • actions/setup/js/setup_threat_detection.cjs:28
    • actions/setup/js/push_to_pull_request_branch.cjs:470
    • actions/setup/js/firewall_blocked_domains.cjs:213

Code sample from the changed file:

const templatePath = `\$\{process.env.RUNNER_TEMP}/gh-aw/prompts/cache_memory_miss.md`;
context += "\n" + renderTemplateFromFile(templatePath, {}) + "\n";

Similar examples elsewhere:

const templatePath = `\$\{process.env.RUNNER_TEMP}/gh-aw/prompts/agent_timeout.md`;
return "\n" + renderTemplateFromFile(templatePath, { current_minutes: currentMinutes, suggested_minutes: suggestedMinutes });
const templatePath = `\$\{process.env.RUNNER_TEMP}/gh-aw/prompts/noop_runs_issue.md`;

Impact Analysis

  • Maintainability: Prompt directory resolution is duplicated instead of centralized, so changes to runtime prompt location or fallback behavior must be applied in many files.
  • Bug Risk: A handler can drift from the intended prompt path convention or miss future support for GH_AW_PROMPTS_DIR style overrides already used in some nearby code.
  • Code Bloat: The repeated snippet is small per call site, but it is highly repetitive across failure, noop, detection, checkout, and PR fallback handlers.

Refactoring Recommendations

  1. Add a shared prompt path helper

    • Extract common path resolution to actions/setup/js/messages_core.cjs, for example getPromptTemplatePath(name) or renderPromptTemplate(name, context).
    • Prefer GH_AW_PROMPTS_DIR when set, otherwise default to \$\{RUNNER_TEMP}/gh-aw/prompts.
    • Estimated effort: Low to Medium.
  2. Migrate call sites incrementally

    • Start with actions/setup/js/handle_agent_failure.cjs because it has the highest concentration of repeated prompt path construction.
    • Then migrate smaller handlers such as handle_noop_message.cjs, handle_detection_runs.cjs, and create_*_issue.cjs.

Implementation Checklist

  • Add shared helper in actions/setup/js/messages_core.cjs
  • Update the repeated prompt path call sites to use the helper
  • Preserve existing fallback behavior in firewall_blocked_domains.cjs
  • Add or update focused .test.cjs coverage for override/default path resolution
  • Run make fmt-cjs, make lint-cjs, and relevant targeted tests

Analysis Metadata

  • Analyzed Files: 1 eligible changed production source file (actions/setup/js/handle_agent_failure.cjs)
  • Excluded Files: 1 test file and 1 Markdown prompt template
  • Detection Method: Serena symbol overview and pattern search, plus targeted production .cjs path search
  • Commit: def67ceb11bd83b0121a5ad22873e3e8cbc5990f
  • Analysis Date: 2026-04-26

References:

Warning

Firewall blocked 4 domains

The following domains were blocked by the firewall during workflow execution:

  • ab.chatgpt.com
  • api.github.com
  • chatgpt.com
  • github.com

💡 Tip: api.github.com is blocked because GitHub API access uses the built-in GitHub tools by default. Instead of adding api.github.com to network.allowed, use tools.github.mode: gh-proxy for direct pre-authenticated GitHub CLI access without requiring network access to api.github.com:

tools:
  github:
    mode: gh-proxy

See GitHub Tools for more information on gh-proxy mode.

To allow these domains, add them to the network.allowed list in your workflow frontmatter:

network:
  allowed:
    - defaults
    - "ab.chatgpt.com"
    - "api.github.com"
    - "chatgpt.com"
    - "github.com"

See Network Configuration for more information.

Generated by Duplicate Code Detector ·

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions