stolt/skill-validator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stolt/skill-validator

Composer 安装命令:

composer require stolt/skill-validator

包简介

A library for parsing and validating SKILL.md files or raw SKILL.md content.

README 文档

README

Test Status Lint Status Version Downloads PHP Version PDS Skeleton Lean dist package

A PHP library to parse and validate SKILL.md files or raw SKILL.md content against the SKILL.md format specification.

Installation and usage

composer require stolt/skill-validator

Usage

The SkillMd class from the stolt/skill-md package is the primary abstraction for a validated skill. Every valid result exposes a SkillMd instance, and the validator also accepts SkillMd instances directly as input.

The validator can validate existing SKILL.md files, raw SKILL.md content, or the mentioned SkillMd instances.

Validating a SKILL.md file

use Stolt\Ai\Skill\Validator;

$validator = new Validator();
$result = $validator->validateFile('/path/to/an-ai-skill/SKILL.md');

Validating all SKILL.md files in a directory

use Stolt\Ai\Skill\Validator;

$validator = new Validator();
$results = $validator->validateFromDirectory('/path/to/skills');

foreach ($results as $filePath => $result) {
    if ($result->isInvalid()) {
        echo sprintf('Invalid: %s', $filePath) . PHP_EOL;
        foreach ($result->errors() as $error) {
            echo '  - ' . $error . PHP_EOL;
        }
    }
}

The method returns an array<string, ValidationResult> keyed by absolute file path, covering all SKILL.md files found recursively under the given directory.

Validating raw SKILL.md content

use Stolt\Ai\Skill\Validator;

$validator = new Validator();
$result = $validator->validateContent('raw-skill-content');

Validating a SkillMd instance

use Stolt\Ai\Skill\Validator;
use Stolt\Ai\SkillMd;

$skillMd = SkillMd::create(
    'code-review',
    'Review code changes and provide actionable feedback.',
    "# Code review\n\nReview the changed files and report issues.",
    ['tags' => ['php', 'review'], 'version' => '1.0.0']
);

$validator = new Validator();
$result = $validator->validateSkillMd($skillMd);

Tip

The validate alias method accepts a file path, directory path, raw content, or a SkillMd instance and delegates to the appropriate method automatically.

Accessing validation results and metadata

Validation returns a Stolt\Ai\Skill\ValidationResult object. When the SKILL.md content is valid, a SkillMd instance is available directly. The parsed metadata is also accessible as a Stolt\Ai\Skill\Metadata object.

use Stolt\Ai\Skill\Validator;

$validator = new Validator();
$result = $validator->validateContent('raw-skill-content');

if ($result->isInvalid()) {
    foreach ($result->errors() as $error) {
        echo $error . PHP_EOL;
    }
    // Raw metadata can still be inspected when parsing succeeded but validation failed.
    $rawMetadata = $result->rawMetadata();
    exit(1);
}

// Primary SkillMd abstraction — available on every valid result.
$skillMd = $result->skillMd();  // returns ?SkillMd (null when invalid)

// Or assert the SkillMd directly, which throws a LogicException when the result is invalid.
$skillMd = $result->toSkillMd();

// Use the SkillMd instance.
$name        = $skillMd->name();
$description = $skillMd->description();
$body        = $skillMd->body();
$tags        = $skillMd->tags();
$version     = $skillMd->version();

// Metadata object for field access with defaults.
$metadata    = $result->metadata();
$allowedTools = $metadata?->get('allowed-tools', []);
$model       = $metadata?->get('model');
$effort      = $metadata?->get('effort');

// Markdown instructions after the YAML frontmatter.
$instructions = $result->body();

// Array representation for logging, JSON APIs, or integrations.
$arrayResult = $result->toArray();

echo sprintf('Skill "%s" is valid: %s', $name, $description) . PHP_EOL;

Round-tripping between content and SkillMd

Because validateSkillMd() accepts a SkillMd instance and toSkillMd() returns one, validation results and SkillMd objects round-trip cleanly:

use Stolt\Ai\Skill\Validator;

$validator = new Validator();

// Parse and validate raw content.
$result = $validator->validateContent($rawContent);

// Get the primary SkillMd abstraction.
$skillMd = $result->toSkillMd();

// Re-validate the SkillMd — e.g. after modifying it.
$revalidated = $validator->validateSkillMd($skillMd);

For an actual integration, the project list-skills-command can also be consolidated.

Validation rules

The validator checks that a SKILL.md document:

  • starts with YAML frontmatter delimited by --- lines,
  • contains the required name field,
  • contains the required description field,
  • uses a non-empty, lowercase, hyphenated skill name,
  • contains Markdown instructions after the frontmatter,
  • only uses supported frontmatter fields,
  • uses lists for list-like fields such as tags, paths, and allowed-tools,
  • uses a boolean value for disable-model-invocation.

Supported frontmatter fields include:

  • name
  • description
  • when_to_use
  • allowed-tools
  • disable-model-invocation
  • argument-hint
  • arguments
  • paths
  • model
  • effort
  • metadata
  • compatibility
  • license
  • author
  • version
  • tags

Running tests

composer test

License

This library is licensed under the MIT license. Please see LICENSE.md for more details.

Changelog

Please see CHANGELOG.md for more details.

Inspiration

This library idea is inspired by the work on agent-skills-validator by ronaldtebrake.

Contributing

Please see CONTRIBUTING.md for more details.

stolt/skill-validator 适用场景与选型建议

stolt/skill-validator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 5.17k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2026 年 05 月 04 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「php」 「file」 「parse」 「parsing」 「content」 「validate」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 stolt/skill-validator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 stolt/skill-validator 我们能提供哪些服务?
定制开发 / 二次开发

基于 stolt/skill-validator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 5.17k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 42
  • 依赖项目数: 2
  • 推荐数: 1

GitHub 信息

  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-04