@@ -11,7 +11,6 @@ import (
1111
1212 "github.com/githubnext/gh-aw/pkg/console"
1313 "github.com/githubnext/gh-aw/pkg/logger"
14- "github.com/goccy/go-yaml"
1514)
1615
1716var log = logger .New ("parser:frontmatter" )
@@ -682,151 +681,6 @@ func processIncludedFileWithVisited(filePath, sectionName string, extractTools b
682681}
683682
684683// extractToolsFromContent extracts tools and mcp-servers sections from frontmatter as merged JSON string
685- func extractToolsFromContent (content string ) (string , error ) {
686- result , err := ExtractFrontmatterFromContent (content )
687- if err != nil {
688- return "{}" , nil // Return empty object on error to match bash behavior
689- }
690-
691- // Create a map to hold the merged result
692- extracted := make (map [string ]any )
693-
694- // Helper function to merge a field into extracted map
695- mergeField := func (fieldName string ) {
696- if fieldValue , exists := result .Frontmatter [fieldName ]; exists {
697- if fieldMap , ok := fieldValue .(map [string ]any ); ok {
698- for key , value := range fieldMap {
699- extracted [key ] = value
700- }
701- }
702- }
703- }
704-
705- // Extract and merge tools section (tools are stored as tool_name: tool_config)
706- mergeField ("tools" )
707-
708- // Extract and merge mcp-servers section (mcp-servers are stored as server_name: server_config)
709- mergeField ("mcp-servers" )
710-
711- // If nothing was extracted, return empty object
712- if len (extracted ) == 0 {
713- return "{}" , nil
714- }
715-
716- // Convert to JSON string
717- extractedJSON , err := json .Marshal (extracted )
718- if err != nil {
719- return "{}" , nil
720- }
721-
722- return strings .TrimSpace (string (extractedJSON )), nil
723- }
724-
725- // extractSafeOutputsFromContent extracts safe-outputs section from frontmatter as JSON string
726- func extractSafeOutputsFromContent (content string ) (string , error ) {
727- return extractFrontmatterField (content , "safe-outputs" , "{}" )
728- }
729-
730- // extractSafeInputsFromContent extracts safe-inputs section from frontmatter as JSON string
731- func extractSafeInputsFromContent (content string ) (string , error ) {
732- return extractFrontmatterField (content , "safe-inputs" , "{}" )
733- }
734-
735- // extractMCPServersFromContent extracts mcp-servers section from frontmatter as JSON string
736- func extractMCPServersFromContent (content string ) (string , error ) {
737- return extractFrontmatterField (content , "mcp-servers" , "{}" )
738- }
739-
740- // extractStepsFromContent extracts steps section from frontmatter as YAML string
741- func extractStepsFromContent (content string ) (string , error ) {
742- result , err := ExtractFrontmatterFromContent (content )
743- if err != nil {
744- return "" , nil // Return empty string on error
745- }
746-
747- // Extract steps section
748- steps , exists := result .Frontmatter ["steps" ]
749- if ! exists {
750- return "" , nil
751- }
752-
753- // Convert to YAML string (similar to how CustomSteps are handled in compiler)
754- stepsYAML , err := yaml .Marshal (steps )
755- if err != nil {
756- return "" , nil
757- }
758-
759- return strings .TrimSpace (string (stepsYAML )), nil
760- }
761-
762- // extractEngineFromContent extracts engine section from frontmatter as JSON string
763- func extractEngineFromContent (content string ) (string , error ) {
764- return extractFrontmatterField (content , "engine" , "" )
765- }
766-
767- // extractRuntimesFromContent extracts runtimes section from frontmatter as JSON string
768- func extractRuntimesFromContent (content string ) (string , error ) {
769- return extractFrontmatterField (content , "runtimes" , "{}" )
770- }
771-
772- // extractServicesFromContent extracts services section from frontmatter as YAML string
773- func extractServicesFromContent (content string ) (string , error ) {
774- result , err := ExtractFrontmatterFromContent (content )
775- if err != nil {
776- return "" , nil // Return empty string on error
777- }
778-
779- // Extract services section
780- services , exists := result .Frontmatter ["services" ]
781- if ! exists {
782- return "" , nil
783- }
784-
785- // Convert to YAML string (similar to how steps are handled)
786- servicesYAML , err := yaml .Marshal (services )
787- if err != nil {
788- return "" , nil
789- }
790-
791- return strings .TrimSpace (string (servicesYAML )), nil
792- }
793-
794- // extractNetworkFromContent extracts network section from frontmatter as JSON string
795- func extractNetworkFromContent (content string ) (string , error ) {
796- return extractFrontmatterField (content , "network" , "{}" )
797- }
798-
799- // ExtractPermissionsFromContent extracts permissions section from frontmatter as JSON string
800- func ExtractPermissionsFromContent (content string ) (string , error ) {
801- return extractFrontmatterField (content , "permissions" , "{}" )
802- }
803-
804- // extractSecretMaskingFromContent extracts secret-masking section from frontmatter as JSON string
805- func extractSecretMaskingFromContent (content string ) (string , error ) {
806- return extractFrontmatterField (content , "secret-masking" , "{}" )
807- }
808-
809- // extractFrontmatterField extracts a specific field from frontmatter as JSON string
810- func extractFrontmatterField (content , fieldName , emptyValue string ) (string , error ) {
811- result , err := ExtractFrontmatterFromContent (content )
812- if err != nil {
813- return emptyValue , nil // Return empty value on error
814- }
815-
816- // Extract the requested field
817- fieldValue , exists := result .Frontmatter [fieldName ]
818- if ! exists {
819- return emptyValue , nil
820- }
821-
822- // Convert to JSON string
823- fieldJSON , err := json .Marshal (fieldValue )
824- if err != nil {
825- return emptyValue , nil
826- }
827-
828- return strings .TrimSpace (string (fieldJSON )), nil
829- }
830684
831685// ExpandIncludes recursively expands @include and @import directives until no more remain
832686// This matches the bash expand_includes function behavior
0 commit comments