wenjin272 commented on code in PR #596:
URL: https://github.com/apache/flink-agents/pull/596#discussion_r3085359324


##########
python/flink_agents/runtime/skill/skill_parser.py:
##########
@@ -0,0 +1,146 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+import re
+from dataclasses import dataclass
+from typing import Dict
+
+import yaml
+
+from flink_agents.runtime.skill.agent_skill import AgentSkill
+
+
+@dataclass
+class ParsedMarkdown:
+    """Result of parsing markdown with frontmatter.
+
+    Contains both the extracted metadata and the markdown content.
+
+    Attributes:
+    ----------
+    metadata : Dict[str, str]
+        YAML metadata extracted from frontmatter.
+    content : str
+        Markdown content (without frontmatter).
+    """
+
+    metadata: Dict[str, str]
+    content: str
+
+
+class MarkdownSkillParser:
+    """Utility for parsing Markdown files with YAML frontmatter."""
+
+    # Pattern to match frontmatter: starts with ---, ends with ---
+    # Group 1: frontmatter content (non-greedy)
+    # Group 2: remaining content
+    FRONTMATTER_PATTERN = re.compile(
+        r"^---\s*[\r\n]+(.*?)[\r\n]*---(?:\s*[\r\n]+)?(.*)", re.DOTALL
+    )
+
+    # Pattern to match key: value format
+    KEY_VALUE_PATTERN = re.compile(r"^([a-zA-Z_][a-zA-Z0-9_-]*)\s*:\s*(.*)$")
+
+    @classmethod
+    def parse(cls, markdown: str) -> ParsedMarkdown:
+        """Parse markdown content with YAML frontmatter.
+
+        Extracts both the YAML metadata and the markdown content.
+
+        Args:
+            markdown: Markdown content.
+
+        Returns:
+            ParsedMarkdown containing metadata and content.
+
+        Raises:
+            ValueError: If YAML syntax is invalid.
+        """
+        if not markdown:
+            return ParsedMarkdown(metadata={}, content="")
+
+        matcher = cls.FRONTMATTER_PATTERN.match(markdown)
+
+        if not matcher:
+            # No frontmatter found, treat entire content as markdown
+            return ParsedMarkdown(metadata={}, content=markdown)
+
+        yaml_content = matcher.group(1).strip()
+        markdown_content = matcher.group(2)
+
+        if not yaml_content:
+            return ParsedMarkdown(metadata={}, content=markdown_content)
+
+        try:
+            metadata = yaml.safe_load(yaml_content)

Review Comment:
   According to the Agent Skills specification: 
https://agentskills.io/specification#skill-md-format, The `SKILL.md` file must 
contain YAML frontmatter followed by Markdown content.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to