Skip to content

Add source field to track workflow origin in frontmatter - #1234

Merged
pelikhan merged 8 commits into
mainfrom
copilot/add-source-field-in-front-matter
Oct 4, 2025
Merged

Add source field to track workflow origin in frontmatter#1234
pelikhan merged 8 commits into
mainfrom
copilot/add-source-field-in-front-matter

Conversation

CopilotAI commented Oct 4, 2025

Copy link
Copy Markdown
Contributor

Add support for the "source" field in workflow frontmatter ✓

Summary

Successfully implemented the source field in workflow frontmatter that tracks where workflows were added from using the gh aw add command. Merged with main branch, all tests passing, and comprehensive documentation added.

Implementation Completed ✓

  • Add Source field to WorkflowData struct
  • Add extractSource method to extract source from frontmatter
  • Render source field as comment in lock files (after description, before stop-time)
  • Add source field to schema validation (main_workflow_schema.json)
  • Update add_command.go to inject source field when installing workflows
  • Add buildSourceString helper to format source string
  • Add addSourceToWorkflow helper to update workflow frontmatter
  • Add comprehensive tests for source field parsing and rendering
  • All unit tests pass (5.0s)
  • Source format matches add command syntax
  • Merged with main branch
  • Documentation updated (frontmatter.md and instructions)
  • Use UnquoteYAMLKey helper to fix YAML marshaling issues
  • Code formatted

Format

Source field format: owner/repo/path@ref (version at the END)

This matches the add command syntax where the version comes after the path:

gh aw add githubnext/agentics/ci-doctor@v1.0.0
# Produces source: githubnext/agentics/workflows/ci-doctor.md@v1.0.0

Examples:

  • githubnext/agentics/workflows/ci-doctor.md@v1.0.0 (with version tag)
  • githubnext/agentics/workflows/daily-plan.md@main (with branch)
  • githubnext/agentics/workflows/helper-bot.md (no version)

Documentation

Complete documentation added to:

  • docs/src/content/docs/reference/frontmatter.md: Detailed sections for both description and source fields with examples, formatting, and benefits
  • .github/instructions/github-agentic-workflows.instructions.md: Added to Agentic Workflow Specific Fields list

The documentation includes:

  • Field format and syntax
  • Automatic population via gh aw add
  • Lock file rendering examples
  • Use cases and benefits
  • Traceability and auditing information

Demonstration

Workflow File (ci-doctor.md)

---
description: "CI Doctor workflow - added from githubnext/agentics"source: "githubnext/agentics/workflows/ci-doctor.md@v1.0.0"on:
pull_request:
types: [opened, synchronize]permissions:
contents: readpull-requests: writeengine: claudetools:
github:
allowed: [add_comment, list_commits]
---
# CI DoctorThis workflow helps diagnose CI/CD issues in pull requests.

Generated Lock File (ci-doctor.lock.yml)

# This file was automatically generated by gh-aw. DO NOT EDIT.# To update this file, edit the corresponding .md file and run:# gh aw compile# For more information: https://github.com/githubnext/gh-aw/blob/main/.github/instructions/github-agentic-workflows.instructions.md## CI Doctor workflow - added from githubnext/agentics## Source: githubnext/agentics/workflows/ci-doctor.md@v1.0.0name: "CI Doctor"on:
pull_request:
types:
- opened
- synchronize
...

Testing

  • ✅ Source field extraction tests
  • ✅ Source field rendering tests
  • ✅ buildSourceString tests
  • ✅ addSourceToWorkflow tests
  • ✅ Schema validation tests
  • ✅ Round-trip consistency test (add command → parse → source string)
  • ✅ All unit tests pass after merge with main
  • ✅ Documentation reviewed and updated
  • ✅ "on" keyword properly unquoted in YAML output

Files Changed

  • pkg/workflow/compiler.go - Added Source field and extraction logic
  • pkg/cli/add_command.go - Added source field injection with correct format and YAML helper
  • pkg/parser/schemas/main_workflow_schema.json - Added source field to schema
  • pkg/workflow/source_field_test.go - Comprehensive tests for source field
  • pkg/cli/add_source_test.go - Tests for add command helpers
  • docs/src/content/docs/reference/frontmatter.md - Documentation for source and description fields
  • .github/instructions/github-agentic-workflows.instructions.md - Updated field list
  • pkg/workflow/yaml.go - Exported UnquoteYAMLKey helper
  • pkg/workflow/tools.go - Updated to use UnquoteYAMLKey
  • pkg/workflow/yaml_test.go - Updated test references
Original prompt

Update the front matter to support a "source" field that contains the information to the repository,ref,path it was added from using the "add" command.

  • new optional "source" field in front matter
  • update parser to load it
  • same format as a "add" command: /@/
  • "add" command adds it as part of installing the workflow
  • gets rendered as a comment in the lock file
  • added as last field in front matter

💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

CopilotAIand others added 2 commits October 4, 2025 11:57
Implements source field in workflow frontmatter that tracks where workflows were added from.
- Add Source field to WorkflowData struct
- Add extractSource method to extract source from frontmatter
- Render source field as comment in lock files (after description, before stop-time)
- Add source field to schema validation (main_workflow_schema.json)
- Update add_command to inject source field when installing workflows
- Add buildSourceString helper to format source string (owner/repo@ref/path)
- Add addSourceToWorkflow helper to update workflow frontmatter
- Add comprehensive tests for source field parsing and rendering
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI changed the title [WIP] Add optional source field to front matter parserAdd source field to track workflow origin in frontmatterOct 4, 2025
CopilotAI requested a review from pelikhanOctober 4, 2025 12:02

@pelikhanpelikhan left a comment

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

  • Run add command to githubnext/agentics ci-doctor and check source is present
  • ensure source syntax is consistent with add command

@pelikhan

Copy link
Copy Markdown
Collaborator

#1176

The source field format is now owner/repo/path@ref (version at end)
instead of owner/repo@ref/path (version in middle).
This matches the add command syntax where version comes after the path:
- gh aw add githubnext/agentics/ci-doctor@v1.0.0
Updated:
- buildSourceString to put version at end
- All tests to use correct format
- Schema description to reflect correct format
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

CopilotAI commented Oct 4, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot

  • Run add command to githubnext/agentics ci-doctor and check source is present ...

Fixed the source field format to match add command syntax. The format is now owner/repo/path@ref (version at the end) instead of owner/repo@ref/path.

Example:

  • Add command: gh aw add githubnext/agentics/ci-doctor@v1.0.0
  • Generated source: githubnext/agentics/workflows/ci-doctor.md@v1.0.0

All tests updated and passing. Round-trip consistency verified (parse → buildSourceString produces correct format).

Commit: 45c4f78

@pelikhan
pelikhan marked this pull request as ready for review October 4, 2025 12:40
@pelikhan
pelikhan requested review from Copilot and dsymeOctober 4, 2025 12:40
CopilotAI requested a review from pelikhanOctober 4, 2025 12:40

CopilotAI left a comment

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.

Pull Request Overview

Adds a new source field to workflow frontmatter that tracks where workflows were added from using the gh aw add command. This field follows the format owner/repo/path@ref and is rendered as a comment in generated lock files.

Key Changes:

  • Added Source field to WorkflowData struct for parsing and storing source information
  • Extended add command to inject source field when installing workflows
  • Added schema validation and comprehensive test coverage for the new functionality

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
FileDescription
pkg/workflow/compiler.goAdded Source field to WorkflowData struct and extractSource method for parsing frontmatter
pkg/parser/schemas/main_workflow_schema.jsonAdded source field definition to JSON schema validation
pkg/cli/add_command.goAdded buildSourceString and addSourceToWorkflow helpers to inject source field during workflow installation
pkg/workflow/source_field_test.goComprehensive test suite for source field extraction and rendering functionality
pkg/cli/add_source_test.goTest suite for add command source field helpers

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment threadpkg/cli/add_command.go
Comment threadpkg/cli/add_command.go
@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot merge main, Run add command to githubnext/agentics ci-doctor and check source is present

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot update frontmatter docs

- Merged latest main branch changes
- Verified source field format: owner/repo/path@ref
- All unit tests pass
- Source field correctly rendered in lock files
The source field is automatically added by the add command and matches
the command syntax exactly. Example:
Command: gh aw add githubnext/agentics/ci-doctor@v1.0.0
Source: githubnext/agentics/workflows/ci-doctor.md@v1.0.0
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

CopilotAI commented Oct 4, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot merge main, Run add command to githubnext/agentics ci-doctor and check source is present

Merged main branch successfully. The source field is working correctly:

Demonstration:

  • Workflow file includes: source: "githubnext/agentics/workflows/ci-doctor.md@v1.0.0"
  • Lock file renders: # Source: githubnext/agentics/workflows/ci-doctor.md@v1.0.0

All unit tests pass. The format matches the add command syntax exactly (version at the end).

Note: Cannot run the actual add command with GitHub credentials in this environment, but the source field injection logic is tested and verified through:

  • Unit tests for buildSourceString and addSourceToWorkflow
  • Manual workflow compilation showing correct source field rendering
  • Round-trip consistency tests

Commit: 6e25985

@pelikhan

Copy link
Copy Markdown
Collaborator

Manual check needed... update investigate why add fails in copilot mode.

Added comprehensive documentation for:
- description field: Human-readable description rendered in lock files
- source field: Tracks workflow origin from gh aw add command
Documentation updated in:
- docs/src/content/docs/reference/frontmatter.md (detailed sections)
- .github/instructions/github-agentic-workflows.instructions.md (field list)
Both fields are optional and enhance workflow traceability and documentation.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>

CopilotAI commented Oct 4, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot update frontmatter docs

Updated frontmatter documentation with detailed sections for both description and source fields:

Documentation locations:

  • docs/src/content/docs/reference/frontmatter.md - Added complete sections with examples, formatting, benefits
  • .github/instructions/github-agentic-workflows.instructions.md - Added to field list

The documentation includes:

  • Field format: owner/repo/path@ref
  • Automatic population via gh aw add
  • Lock file rendering examples
  • Traceability and auditing benefits

Commit: 56b7cf1

@pelikhan

Copy link
Copy Markdown
Collaborator

@copilot provide a detailed error report/investigation why the "add" command fails.

CopilotAI commented Oct 4, 2025

Copy link
Copy Markdown
ContributorAuthor

@copilot provide a detailed error report/investigation why the "add" command fails.

Add Command Failure Investigation

Root Cause: GitHub CLI authentication is missing in the sandboxed environment.

Error:gh execution failed: exit status 4 - To use GitHub CLI in a GitHub Actions workflow, set the GH_TOKEN environment variable

Call Stack:

gh aw add → InstallPackage() → downloadWorkflows() → gh.Exec("repo", "clone") [pkg/cli/packages.go:115]
→ FAILS: No GITHUB_TOKEN

Why:
The add command uses GitHub CLI (cli/go-gh/v2) to clone repositories, which requires authentication. The sandboxed Copilot environment lacks GitHub credentials.

Source Field Status:

  • ✅ Feature fully implemented and working
  • ✅ All unit tests pass
  • ✅ Manual workflow creation with source field works
  • ✅ Lock file rendering correct
  • ❌ Automatic population via gh aw add requires GitHub auth (expected)

Code Flow (lines 448-458 in add_command.go):

sourceString:=buildSourceString(workflow) // Creates: owner/repo/path@refupdatedContent, err:=addSourceToWorkflow(content, sourceString, verbose)
content=updatedContent// Injects source into frontmatter

Workarounds:

  1. With auth: GITHUB_TOKEN=token gh aw add githubnext/agentics/ci-doctor
  2. Manual: Create workflow with source: "githubnext/agentics/workflows/ci-doctor.md@v1.0.0"

The source field feature is complete. The add command failure is an authentication limitation, not a code issue.

result.Frontmatter["source"] = source

// Convert back to YAML
updatedFrontmatter, err := yaml.Marshal(result.Frontmatter)

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 helper that fixes yaml marshaling issues with "on"

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Applied UnquoteYAMLKey helper to fix YAML marshaling issues with 'on' keyword.

Changes:

  • Exported unquoteYAMLKey as UnquoteYAMLKey
  • Applied in addSourceToWorkflow to prevent "on" from being quoted
  • Added test case to verify "on" remains unquoted
  • Updated all references across codebase

The "on" keyword is now properly unquoted when adding source field to workflows.

Commit: 3ee8a9c

- Export unquoteYAMLKey as UnquoteYAMLKey for use in other packages
- Update all references to use the exported version
- Apply UnquoteYAMLKey in addSourceToWorkflow to prevent "on" from being quoted
- Add test case to verify "on" keyword is not quoted after adding source field
This ensures that when source field is added to workflows with 'on' triggers,
the 'on' keyword remains unquoted in the frontmatter YAML.
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI requested a review from pelikhanOctober 4, 2025 13:30
@pelikhan
pelikhan merged commit c6438f4 into mainOct 4, 2025
@pelikhan
pelikhan deleted the copilot/add-source-field-in-front-matter branch October 4, 2025 15:43
CopilotAI added a commit that referenced this pull request Mar 15, 2026
#1234)
- Add field-level merge support for create-discussion in imports.go
- Create shared/daily-audit-discussion.md with base config
- Update 42 workflows to import the shared component
- Add 3 tests for create-discussion field-level merging
- Recompile all 173 workflow lock files
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
CopilotAI added a commit that referenced this pull request Mar 15, 2026
)
- Add actions/setup/md/agentic_workflows_guide.md with MCP usage guidance
- Add agenticWorkflowsGuideFile constant in prompt_constants.go
- Add hasAgenticWorkflowsTool helper in prompts.go
- Inject guide in collectPromptSections when agentic-workflows tool is configured
- Update smoke-copilot golden file
- Add tests for inclusion/exclusion of the guide
- Recompile all 173 lock files
Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com>
Sign up for freeto 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.

3 participants

@pelikhan