Skip to content

Extract extraction functions from compiler.go to frontmatter_extraction.go#2283

Merged
pelikhan merged 4 commits intomainfrom
copilot/extract-functions-to-frontmatter
Oct 24, 2025
Merged

Extract extraction functions from compiler.go to frontmatter_extraction.go#2283
pelikhan merged 4 commits intomainfrom
copilot/extract-functions-to-frontmatter

Conversation

Copy link
Contributor

Copilot AI commented Oct 24, 2025

Overview

Refactored frontmatter extraction logic by consolidating 13 extraction/parsing functions into a dedicated frontmatter_extraction.go file. This improves code organization and makes extraction logic easier to find, test, and maintain.

Changes

File Reorganization

  • Renamed: pkg/workflow/parse_utils.gopkg/workflow/frontmatter_extraction.go
  • Reduced: pkg/workflow/compiler.go by 435 lines
  • Reduced: pkg/workflow/network.go by 35 lines

Functions Moved to frontmatter_extraction.go

From compiler.go (12 functions):

  • extractTopLevelYAMLSection - Extracts top-level YAML sections with field ordering
  • extractPermissions - Extracts permissions using the permission parser
  • extractIfCondition - Extracts if conditions without prefix
  • extractFeatures - Extracts feature flags map
  • extractDescription - Extracts description field
  • extractSource - Extracts source field
  • extractSafetyPromptSetting - Extracts safety-prompt setting from tools
  • extractToolsTimeout - Extracts timeout setting from tools
  • extractToolsStartupTimeout - Extracts startup-timeout setting from tools
  • extractExpressionFromIfString - Extracts expression from if string
  • extractCommandConfig - Extracts command configuration including name and events
  • extractYAMLValue - Extracts scalar values from frontmatter (already existed in parse_utils.go)

From network.go (1 function):

  • extractNetworkPermissions - Extracts network permissions (was misplaced in runtime file)

Helper functions also moved:

  • commentOutProcessedFieldsInOnSection - Used by extractTopLevelYAMLSection
  • buildSourceURL - Used by extractSource and safe output files

Benefits

  1. Better Organization: All frontmatter extraction logic is now centralized in one file
  2. Improved Maintainability: Easier to locate and modify extraction functions
  3. Cleaner Separation: compiler.go focuses on compilation logic, not extraction
  4. Correct Placement: extractNetworkPermissions moved from network.go (runtime) to extraction utilities

Testing

  • ✅ All unit tests pass
  • ✅ Build successful
  • ✅ No breaking changes to existing functionality

Closes #2274 (part of #2273)

Original prompt

This section details on the original issue you should resolve

<issue_title>[task] Extract extraction functions from compiler.go to frontmatter_extraction.go</issue_title>
<issue_description>## Objective
Extract 12 extraction/parsing functions from pkg/workflow/compiler.go and consolidate with existing extraction utilities into a renamed and enhanced pkg/workflow/frontmatter_extraction.go.

Context

Part of issue #2273. The compiler.go file contains extraction functions that should be in a dedicated extraction utilities file. This will improve code organization and make extraction logic easier to find and test.

Functions to Extract from compiler.go

Move these 12 extraction functions:

  • extractTopLevelYAMLSection
  • extractPermissions
  • extractIfCondition
  • extractFeatures
  • extractDescription
  • extractSource
  • extractSafetyPromptSetting
  • extractToolsTimeout
  • extractToolsStartupTimeout
  • extractExpressionFromIfString
  • extractCommandConfig
  • extractYAMLValue

Additional Extraction Functions to Move

From pkg/workflow/network.go:

  • extractNetworkPermissions (currently misplaced in runtime file)

Approach

  1. Rename pkg/workflow/parse_utils.go to pkg/workflow/frontmatter_extraction.go
  2. Move all extraction functions from compiler.go to this file
  3. Move extractNetworkPermissions from network.go to this file
  4. Organize functions logically within the file
  5. Update all imports and references

Files to Modify

  • Rename: pkg/workflow/parse_utils.gopkg/workflow/frontmatter_extraction.go
  • Update: pkg/workflow/compiler.go (remove extraction functions)
  • Update: pkg/workflow/network.go (remove extractNetworkPermissions)

Acceptance Criteria

AI generated by Plan Command for #2273</issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #2276


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copilot AI and others added 2 commits October 24, 2025 11:56
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] Extract functions from compiler.go to frontmatter_extraction.go Extract extraction functions from compiler.go to frontmatter_extraction.go Oct 24, 2025
Copilot AI requested a review from pelikhan October 24, 2025 12:08
@pelikhan pelikhan marked this pull request as ready for review October 24, 2025 12:16
@github-actions
Copy link
Contributor

Agentic Changeset Generator triggered by this pull request.

@pelikhan pelikhan merged commit 00377e3 into main Oct 24, 2025
3 checks passed
@pelikhan pelikhan deleted the copilot/extract-functions-to-frontmatter branch October 24, 2025 12:19
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.

[task] Extract extraction functions from compiler.go to frontmatter_extraction.go

2 participants