Skip to content

Refactor inline skill/sub-agent extraction to shared parser helpers#36247

Merged
pelikhan merged 9 commits into
mainfrom
copilot/refactor-semantic-function-clustering-please-work
Jun 1, 2026
Merged

Refactor inline skill/sub-agent extraction to shared parser helpers#36247
pelikhan merged 9 commits into
mainfrom
copilot/refactor-semantic-function-clustering-please-work

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jun 1, 2026

The issue identified near-clone parser implementations for inline skills and inline sub-agents, creating avoidable duplication and drift risk in core markdown section parsing. This PR addresses the highest-impact low-risk refactor by consolidating shared extraction mechanics while preserving existing public behavior.

  • What changed

    • Added shared internal helpers in pkg/parser/inline_section_helpers.go for:
      • H2 boundary discovery
      • inline section slicing (name + content)
      • duplicate-name detection
    • Refactored both extractors to use shared logic:
      • inline_skill_extractor.go
      • sub_agent_extractor.go
    • Moved GetEngineSkillDir and GetEngineSubAgentDir from the parser package to pkg/workflow/engine_config_dir.go, where they now resolve the engine config directory via the AgentFileProvider interface (GetAgentManifestPathPrefixes()) from the global EngineRegistry — replacing a hardcoded switch statement with a single source of truth.
  • Behavior preserved

    • Public extraction APIs are unchanged (ExtractInlineSkills, ExtractInlineSubAgents).
    • Existing error text/log semantics for duplicate names remain intact.
    • Engine-specific path mapping is now driven by the engine registry, so new engines are covered automatically without code changes.
  • Bonus fix

    • Engines not previously handled by the switch (pi, crush, opencode, antigravity) now correctly resolve to their own config directories (e.g. .pi/agents) instead of falling back to .github/.
  • Result

    • Removes parallel implementations of the same parsing flow, centralizes the section-boundary algorithm, and eliminates the hardcoded engine→directory mapping in favour of the agentic engine interface.
// pkg/workflow/engine_config_dir.go
func GetEngineSkillDir(engineID string) string {
    return engineConfigBaseDir(engineID) + "/skills"
}

func GetEngineSubAgentDir(engineID string) string {
    return engineConfigBaseDir(engineID) + "/agents"
}

func engineConfigBaseDir(engineID string) string {
    registry := GetGlobalEngineRegistry()
    engine, err := registry.GetEngine(strings.ToLower(engineID))
    if err == nil {
        if provider, ok := engine.(AgentFileProvider); ok {
            if prefixes := provider.GetAgentManifestPathPrefixes(); len(prefixes) > 0 {
                return strings.TrimSuffix(prefixes[0], "/")
            }
        }
    }
    return ".github"
}

Copilot AI and others added 3 commits June 1, 2026 14:51
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Co-authored-by: gh-aw-bot <259018956+gh-aw-bot@users.noreply.github.com>
Copilot AI changed the title [WIP] Refactor semantic function clustering for verified duplicates and outliers Refactor inline skill/sub-agent extraction to shared parser helpers Jun 1, 2026
Copilot AI requested a review from gh-aw-bot June 1, 2026 15:05
@pelikhan pelikhan marked this pull request as ready for review June 1, 2026 15:41
Copilot AI review requested due to automatic review settings June 1, 2026 15:41
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

Consolidates duplicated inline-section parsing logic between the inline skill and sub-agent extractors into a shared helper file, reducing drift risk while preserving public API behavior.

Changes:

  • New pkg/parser/inline_section_helpers.go with shared helpers (collectH2Positions, extractInlineSection, nextH2After, validateUniqueInlineSectionNames, engineConfigDir).
  • inline_skill_extractor.go and sub_agent_extractor.go refactored to delegate to the shared helpers; duplicated regexes and switch statements removed.
Show a summary per file
File Description
pkg/parser/inline_section_helpers.go New shared helpers for H2 boundary discovery, section slicing, duplicate name validation, and engine config dir resolution.
pkg/parser/inline_skill_extractor.go Removes duplicated skill-specific helpers and regex; delegates to shared helpers.
pkg/parser/sub_agent_extractor.go Removes duplicated sub-agent helpers and regex; delegates to shared helpers.

Copilot's findings

Tip

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

  • Files reviewed: 3/3 changed files
  • Comments generated: 0

@pelikhan
Copy link
Copy Markdown
Collaborator

pelikhan commented Jun 1, 2026

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Jun 1, 2026

@copilot lint go https://github.com/github/gh-aw/actions/runs/26765630225/job/78891087186

Fixed in commit fix: go fmt formatting in inline_skill_extractor and sub_agent_extractor. The indentation inside the closure bodies in validateUniqueInlineSkillNames and validateUniqueSubAgentNames was off by one tab level — go fmt corrected both.

Copilot AI requested a review from pelikhan June 1, 2026 17:03
Comment thread pkg/parser/inline_section_helpers.go Outdated
return nil
}

func engineConfigDir(engineID string, resourceType string) string {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@copilot use agentic engine interface to resolve this folder

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. engineConfigDir is removed from parser/inline_section_helpers.go. GetEngineSkillDir and GetEngineSubAgentDir are now in pkg/workflow/engine_config_dir.go and use AgentFileProvider.GetAgentManifestPathPrefixes() from the global EngineRegistry to resolve the directory — no more hardcoded switch. As a side-effect, the pi engine (and any future engines) now automatically get the correct directory without requiring a code change. The pi golden file was updated accordingly (.pi/agents/.pi/skills instead of the old .github/ default).

Copilot AI and others added 2 commits June 1, 2026 17:24
…ution

Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Copilot AI requested a review from pelikhan June 1, 2026 17:26
@pelikhan pelikhan merged commit 4eb3323 into main Jun 1, 2026
32 checks passed
@pelikhan pelikhan deleted the copilot/refactor-semantic-function-clustering-please-work branch June 1, 2026 17:31
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] Semantic function clustering: verified duplicates, outliers, scattered helpers & util reimplementations

4 participants