Skip to content

fix(skill): tolerate unparseable SKILL.md frontmatter in kit init#1239

Open
gorkem wants to merge 2 commits into
kitops-ml:mainfrom
gorkem:fix/skill-frontmatter-lenient-parse
Open

fix(skill): tolerate unparseable SKILL.md frontmatter in kit init#1239
gorkem wants to merge 2 commits into
kitops-ml:mainfrom
gorkem:fix/skill-frontmatter-lenient-parse

Conversation

@gorkem

@gorkem gorkem commented Jul 1, 2026

Copy link
Copy Markdown
Member

What

Make kit init recover the name and description from a skill directory's SKILL.md even when the frontmatter isn't strictly valid YAML.

Why

For a directory with a root SKILL.md, kit init derives the Kitfile package name/description from the frontmatter. ParseSkillFrontmatter ran a single strict yaml.Unmarshal over the whole block and discarded any error, returning nil. A description containing an unquoted colon — e.g. ... on a pull request: "address the comments" — is not valid YAML (mapping values are not allowed in this context), so all metadata was silently dropped and the generated Kitfile had no name or description. Such descriptions are extremely common in real skills.

How

  • Strict-first, lenient-fallback in ParseSkillFrontmatter: try strict YAML first (preserving full YAML semantics, including the multi-line block-scalar descriptions the SKILL.md format permits); only if that fails, fall back to a lenient line-based parse of the known keys (name, description, license) that tolerates colons/quotes/# in prose values.
  • No more silent failure: kit init now logs a warning when a SKILL.md is found but no name/description could be recovered.

The lenient path only ever runs on input that already failed strict YAML, so well-formed frontmatter is never mis-parsed.

Validation

  • go test ./pkg/lib/skill/... ./pkg/lib/kitfile/generate/... ./pkg/cmd/kitinit/... — pass
  • Added table-test cases: unquoted colon in description, quoted-scalar unquoting, block-scalar (strict) description, and updated the existing malformed-YAML case to assert lenient recovery
  • gofmt, go vet, go build, addlicense --check, go mod tidy — clean
  • Manually verified against a real skill directory: kit init now emits both package.name/package.description and the prompt's name/description

kit init silently produced a Kitfile with no name or description for
skill directories whose SKILL.md description contained an unquoted colon
(e.g. a pull request: "address the comments"). ParseSkillFrontmatter ran
a strict YAML unmarshal over the whole frontmatter block and discarded
any error, dropping all recovered metadata.

Parse strictly first, preserving full YAML semantics such as the
multi-line block-scalar descriptions the SKILL.md format permits, then
fall back to a lenient line-based parse of the known keys (name,
description, license) when the block is not valid YAML. Also warn in
kit init when a SKILL.md is found but no name or description could be
recovered, instead of failing silently.

Signed-off-by: Gorkem Ercan <gorkem@jozu.com>

Copilot AI 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

This PR improves kit init’s ability to derive package and prompt metadata from a skill directory’s SKILL.md by parsing frontmatter robustly: attempting normal YAML parsing first, then falling back to a lenient line-based extraction when the YAML is malformed (e.g., unquoted colons in prose descriptions). It also adds a warning when metadata can’t be recovered and expands test coverage around these cases.

Changes:

  • Implement strict-first YAML parsing with a lenient fallback for name, description, and license in ParseSkillFrontmatter.
  • Add warning logging when SKILL.md exists but no name/description can be extracted for Kitfile generation.
  • Extend unit tests to cover real-world malformed frontmatter cases (unquoted colon, quoted scalars, block scalars).

Reviewed changes

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

File Description
pkg/lib/skill/skillfile.go Adds strict YAML parse with lenient fallback parser and scalar unquoting helper.
pkg/lib/skill/skillfile_test.go Adds/updates table tests to assert description parsing across strict and lenient paths.
pkg/lib/kitfile/generate/skill.go Logs a warning when no name/description can be recovered from SKILL.md.
pkg/lib/kitfile/generate/skill_test.go Updates malformed-YAML test to expect lenient recovery; adds colon-in-description case.

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

Comment thread pkg/lib/skill/skillfile.go
Comment thread pkg/lib/skill/skillfile.go
gorkem added a commit to gorkem/kitops that referenced this pull request Jul 9, 2026
The lenient parser counted empty values as recovered frontmatter and
captured block-scalar indicators like '|' as literal values. Skip both
so a malformed SKILL.md never yields all-empty or wrong metadata.

Addresses review feedback on kitops-ml#1239.
The lenient parser counted empty values as recovered frontmatter and
captured block-scalar indicators like '|' as literal values. Skip both
so a malformed SKILL.md never yields all-empty or wrong metadata.

Addresses review feedback on kitops-ml#1239.

Signed-off-by: Gorkem Ercan <gorkem@jozu.com>
@gorkem gorkem force-pushed the fix/skill-frontmatter-lenient-parse branch from 41c74f5 to fca2760 Compare July 9, 2026 21:57
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.

2 participants