Skip to content

refactor: reorganize workflow and parser packages (4 semantic findings)#35091

Open
Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-misplaced-functions
Open

refactor: reorganize workflow and parser packages (4 semantic findings)#35091
Copilot wants to merge 4 commits into
mainfrom
copilot/refactor-misplaced-functions

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 27, 2026

Semantic clustering of 858 non-test Go files identified four organizational issues: functions in files that don't match their domain, inconsistent file-name prefixes creating a split-brain between compiler_safe_outputs_* and safe_outputs_*, mixed MCP rendering file-name patterns, and a cross-package unexported function name collision with different semantics.

Finding 1 — Misplaced functions in compiler_safe_outputs.go

Six functions moved to domain-appropriate files:

Function From To
parseOnSection, mergeCommandOtherEvents, mergeEventConfig, parseEventTypes compiler_safe_outputs.go trigger_parser.go
applyDefaultTools compiler_safe_outputs.go tools.go (adjacent to applyDefaults which calls it)
isSandboxEnabled compiler_safe_outputs.go sandbox.go (callers: firewall.go, strict_mode_permissions_validation.go)

compiler_safe_outputs.go now contains only mergeSafeJobsFromIncludedConfigs and needsGitCommands.

Finding 2 — Consolidate compiler_safe_outputs_* into safe_outputs_*

Three zero-func files and two thin files eliminated:

  • compiler_safe_outputs_env.go (1 fn) → merged into safe_outputs_env.go
  • compiler_safe_outputs_config.go (5 fns) + compiler_safe_outputs_core.go (SafeOutputStepConfig type) + compiler_safe_outputs_handlers.go (handlerRegistry var) → merged into safe_outputs_config.go
  • Source files deleted; compiler_safe_outputs_builder.go retained as-is

Finding 3 — Align MCP rendering file names

  • Renamed mcp_rendering.gomcp_renderer_factory.go
  • Moved renderSafeOutputsMCPConfigWithOptions and renderAgenticWorkflowsMCPConfigWithOptions out of the misnamed mcp_config_builtin.go into mcp_renderer_builtin.go
  • mcp_config_builtin.go now holds only the architectural doc comment, reserved for future type/constant declarations

Finding 4 — Remove cross-package name collision in pkg/parser

containsExpression(v any) bool in pkg/parser/include_processor.go had the same name but different semantics from containsExpression(s string) bool in pkg/workflow/expression_patterns.go — the parser version recursively walks map[string]any/[]any rather than matching a single string. Renamed to frontmatterValueContainsExpression to make the type-recursive intent explicit.

Finding 1: Move misplaced functions out of compiler_safe_outputs.go
- parseOnSection, mergeCommandOtherEvents, mergeEventConfig, parseEventTypes → trigger_parser.go
- applyDefaultTools → tools.go
- isSandboxEnabled → sandbox.go
- Retain mergeSafeJobsFromIncludedConfigs and needsGitCommands in compiler_safe_outputs.go

Finding 2: Consolidate compiler_safe_outputs_* and safe_outputs_* files
- Merge compiler_safe_outputs_env.go into safe_outputs_env.go
- Merge compiler_safe_outputs_config.go, compiler_safe_outputs_core.go,
  and compiler_safe_outputs_handlers.go into safe_outputs_config.go
- Delete the three now-empty source files

Finding 3: Align MCP rendering file names
- Rename mcp_rendering.go → mcp_renderer_factory.go
- Move renderSafeOutputsMCPConfigWithOptions and
  renderAgenticWorkflowsMCPConfigWithOptions from mcp_config_builtin.go
  into mcp_renderer_builtin.go; leave mcp_config_builtin.go for future
  type/constant declarations

Finding 4: Remove cross-package name collision in pkg/parser
- Rename containsExpression → frontmatterValueContainsExpression in
  include_processor.go to make type-recursive intent explicit

Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor misplaced functions in compiler_safe_outputs.go refactor: reorganize workflow and parser packages (4 semantic findings) May 27, 2026
Copilot AI requested a review from gh-aw-bot May 27, 2026 01:38
@pelikhan pelikhan marked this pull request as ready for review May 27, 2026 05:17
Copilot AI review requested due to automatic review settings May 27, 2026 05:17
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR reorganizes workflow compiler, safe-outputs, MCP rendering, and parser helpers into more domain-appropriate files without intending functional behavior changes.

Changes:

  • Moves trigger parsing, sandbox detection, default tools, and safe-output environment/config helpers into focused files.
  • Consolidates compiler_safe_outputs_* files into safe_outputs_* files and aligns MCP renderer naming.
  • Renames the parser frontmatter expression helper to avoid a cross-package semantic name collision.
Show a summary per file
File Description
pkg/workflow/trigger_parser.go Receives parseOnSection and related event merge helpers.
pkg/workflow/tools.go Receives applyDefaultTools near tool defaulting logic.
pkg/workflow/sandbox.go Receives isSandboxEnabled.
pkg/workflow/safe_outputs_env.go Receives safe-output env var setup.
pkg/workflow/safe_outputs_config.go Receives safe-output step config, handler registry, and handler manager config helpers.
pkg/workflow/mcp_renderer_factory.go Adds shared MCP renderer factory/helper code under the new file name.
pkg/workflow/mcp_renderer_builtin.go Receives built-in MCP renderer functions.
pkg/workflow/mcp_config_builtin.go Retains only the architectural package documentation.
pkg/workflow/compiler_safe_outputs.go Reduced to safe-job merge and git-command helper logic.
pkg/workflow/compiler_safe_outputs_handlers.go Deleted after handler registry consolidation.
pkg/workflow/compiler_safe_outputs_env.go Deleted after env helper consolidation.
pkg/workflow/compiler_safe_outputs_core.go Deleted after type consolidation.
pkg/workflow/compiler_safe_outputs_config.go Deleted after config helper consolidation.
pkg/parser/include_processor.go Renames the recursive frontmatter expression helper.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 13/14 changed files
  • Comments generated: 1

Comment thread pkg/workflow/compiler_safe_outputs.go
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

🧪 Test Quality Sentinel completed test quality analysis.

No test files were added or modified in this PR (PR #35091: refactor: reorganize workflow and parser packages). The PR contains only production code reorganization (moving functions between files, renaming/deleting files in pkg/workflow and pkg/parser). Test Quality Sentinel skipped.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

PR Code Quality Reviewer completed the code quality review.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

🧠 Matt Pocock Skills Reviewer has completed the skills-based review. ✅

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

Design Decision Gate 🏗️ completed the design decision gate check.

@github-actions github-actions Bot mentioned this pull request May 27, 2026
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

🧠 Reviewed using Matt Pocock's skills by Matt Pocock Skills Reviewer · sonnet46 1.7M

"maps"
"path/filepath"
"strings"
"encoding/json"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[/zoom-out] The import block and function body in this file are missing tab indentation — gofmt -l flags this file. This will cause the make fmt CI gate to fail immediately.

💡 Fix

Run gofmt -w pkg/workflow/compiler_safe_outputs.go (or make fmt) before pushing. The imports should be:

import (
"encoding/json"
"fmt"

"github.com/github/gh-aw/pkg/logger"
)

And the function body lines need a leading tab at every level of indentation.

Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Warning

Firewall blocked 1 domain

The following domain was blocked by the firewall during workflow execution:

  • proxy.golang.org

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

network:
  allowed:
    - defaults
    - "proxy.golang.org"

See Network Configuration for more information.

🔎 Code quality review by PR Code Quality Reviewer · sonnet46 2.9M

return merged
// mergeSafeJobsFromIncludedConfigs merges safe-jobs from included safe-outputs configurations
func (c *Compiler) mergeSafeJobsFromIncludedConfigs(topSafeJobs map[string]*SafeJobConfig, includedConfigs []string) (map[string]*SafeJobConfig, error) {
compilerSafeOutputsLog.Printf("Merging safe-jobs from included configs: includedCount=%d", len(includedConfigs))
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

gofmt failure: unindented function body will break CI formatting check.

gofmt -l already flags this file. Every statement inside mergeSafeJobsFromIncludedConfigs and each import path is flush-left (no leading tab), violating Go formatting rules.

💡 Fix

Run:

gofmt -w pkg/workflow/compiler_safe_outputs.go

Or manually add a tab before every import path and every statement in the function body. The needsGitCommands function at the bottom of the file has the same problem.

This is the only remaining content in the file after the refactor, so the fix is small but mandatory — make fmt / CI will reject the PR in its current state.

@github-actions
Copy link
Copy Markdown
Contributor

🏗️ Design Decision Gate — ADR Required

This PR makes significant changes to core business logic (1,907 new lines across pkg/workflow and pkg/parser) but does not yet have a linked Architecture Decision Record (ADR).

📄 Draft ADR committed: docs/adr/35091-reorganize-workflow-and-parser-packages-by-semantic-clustering.md — review and complete it before merging.

🔒 This PR cannot merge until an ADR is linked in the PR body.

📋 What to do next
  1. Review the draft ADR committed to your branch — it was generated from the four findings described in the PR body and follows the convention established by ADR-27325, ADR-28282, and ADR-29336.
  2. Complete the missing sections — verify the rationale, refine the alternatives, and confirm the RFC 2119 specification matches the actual move targets.
  3. Reference the ADR in this PR body by adding a line such as:

    ADR: ADR-35091: Reorganize Workflow and Parser Packages by Semantic Clustering

Once the ADR is linked in the PR body, this gate will re-run and verify the implementation matches the decision.

📌 What the draft ADR captures
  • Finding 1: Six functions moved out of compiler_safe_outputs.go into trigger_parser.go, tools.go, and sandbox.go
  • Finding 2: Three thin compiler_safe_outputs_* files merged into their safe_outputs_* counterparts
  • Finding 3: mcp_rendering.go renamed to mcp_renderer_factory.go; renderer functions split out of mcp_config_builtin.go into mcp_renderer_builtin.go
  • Finding 4: Cross-package collision resolved by renaming containsExpressionfrontmatterValueContainsExpression in pkg/parser/include_processor.go

Each finding is encoded as a MUST/MUST NOT rule in Part 2 of the ADR so the file-naming convention is testable.

❓ Why ADRs Matter

ADRs create a searchable, permanent record of why the codebase looks the way it does. Reorganization decisions in particular benefit from explicit records — without them, the file-naming convention drifts again over time and the next contributor has no anchor explaining which prefix or directory a new function belongs in.

📋 Michael Nygard ADR Format Reference

An ADR must contain these four sections to be considered complete:

  • Context — What is the problem? What forces are at play?
  • Decision — What did you decide? Why?
  • Alternatives Considered — What else could have been done?
  • Consequences — What are the trade-offs (positive and negative)?

All ADRs are stored in docs/adr/ as Markdown files numbered by PR number (e.g., 35091-*.md for PR #35091).

References:

🏗️ ADR gate enforced by Design Decision Gate 🏗️ · opus47 6.4M ·

@pelikhan
Copy link
Copy Markdown
Collaborator

@lint go, review all comments and reviews

@pelikhan
Copy link
Copy Markdown
Collaborator

@copilot lint go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] Misplaced functions in compiler_safe_outputs.go, inconsistent file-name splits in workflow package

4 participants