fix(catalog): 校验技能指针的客户端契约,撤回 REA 的单段版本 / validate skill pointers against the client contract (#239)

客户端按 `marketSkillEntrySchema` 校验 `entry.json`,`latestVersion` 只接受 `x.y` 或 `x.y.z`,
不通过的条目在索引时被跳过。#227 写入的上游修订号 `50` 让所有客户端都看不到
reverse-engineer-anything,而 manifest 仍计入它。

- reverse-engineer-anything 恢复为 `release: unknown` 且不声明 `latestVersion`;固定提交与合规审查不变。
- video-use 去掉指针无法声明的 `skillType`,此前客户端一直拒绝这份 sidecar。
- 校验器用导出的客户端 Schema 校验技能指针,并按客户端判据双向比较 sidecar 事实。

Clients skip any `entry.json` whose `latestVersion` is not `x.y` or `x.y.z`, so the upstream
revision `50` from #227 hid reverse-engineer-anything from every client. This restores the shape
reviewed in #212, drops a `skillType` from video-use that made clients reject its sidecar, and makes
the validator enforce the client contract for skill pointers and compare sidecar facts both ways.

验证 / Validation: `validate_catalog_metadata.py --require-complete` 0 errors;真实 MarketSync
与校验器在 43 类变异下判定一致;索引 145 技能、9 Agent、2 团队,0 个 sidecar 被拒。
This commit is contained in:
yige authored and GitHub committed 2026-10-31 16:34:32 +08:00
1 parent 952ade3ace
commit 7189d91395
10 files changed
+592 -81

No files matched your search

+4 -2
View File
@@ -99,7 +99,7 @@ Use the schemas and existing listings as implementation references. A shortened
### Static catalog facts
Catalog counts are file-derived, not usage statistics. Do not author views, downloads, ratings, Stars, install counts, or runtime health. Missing publisher evidence remains unknown. A listed release is not a live latest-version query. Preserve the upstream release identifier; do not invent a three-part version to fill a missing fact. New team localization fields and two-part pointer versions must wait until the matching client contract is released before being published to the shared catalog. Regenerate bootstrap archives through the client repository's synchronization tools, never by editing ZIP contents manually.
Catalog counts are file-derived, not usage statistics. Do not author views, downloads, ratings, Stars, install counts, or runtime health. Missing publisher evidence remains unknown. A listed release is not a live latest-version query. Preserve the upstream release identifier; do not invent a three-part version to fill a missing fact. New team localization fields and two-part pointer versions must wait until the matching client contract is released before being published to the shared catalog. Until then, an upstream identifier the released contract does not admit, such as a bare revision number `50`, stays out of `latestVersion` and `release`: keep the release unknown rather than reshaping the identifier. Regenerate bootstrap archives through the client repository's synchronization tools, never by editing ZIP contents manually.
### Local skills
@@ -115,6 +115,8 @@ The `retired` list identifies former built-in skills that clients may retire at
An external skill uses `skills/<id>/entry.json` to describe its upstream source, presentation, maintainer, category, license, and redistribution terms. Skill listings require an inline SVG `icon`. Supported source kinds are `git`, `web`, and `zip`; external listings count toward `manifest.stats.totalSkills` but do not belong in the built-in skill index.
The raw pointer must pass the [exported skill client schema](schemas/market-skill-entry.client.schema.json) before sidecar validation. A client skips any entry that fails it, so the listing disappears for its users while the manifest still counts it. `latestVersion` accepts numeric `x.y` or `x.y.z` and maps to `release.version`; the sidecar's `versionScheme` must be the one the client derives from that value, which is `opaque` for `x.y`. The sidecar must also agree with the pointer on `category`, `tags`, `riskLevel`, and `requiredClientVersion`, and cannot add `skillType` or `compatibleAgents`, which a pointer does not declare. On any difference the client rejects the whole sidecar and the listing becomes listing-only.
A collection groups multiple upstream skills under one listing, with a declared `children` inventory for discovery. Keep the children's metadata in the parent's sidecar. Each child has its own `skill + parentId + id` identity and release fact; never infer a child's version from its parent, whose version may be unknown.
See the [Lark Suite CLI entry](skills/larksuite-cli/entry.json) and [sidecar](skills/larksuite-cli/catalog-metadata.v1.json). The [collection generator](scripts/gen-collection-children.py) derives children from upstream `SKILL.md` files; its `--check` mode verifies reproducible, pinned collections without rewriting entries.
@@ -161,7 +163,7 @@ The [catalog metadata schema](schemas/catalog-metadata.v1.schema.json) covers pr
- **Evidence paths follow the content.** `license.evidencePath`, `compliance.licenseEvidencePath`, and `compliance.noticePath` are relative to the item directory for vendored content, and the files must exist. For pointers they refer to the upstream snapshot; offline validation cannot fetch that evidence and warns about claims against unpinned sources.
- **Unknown is a valid fact.** Use explicit `known` / `unknown` states. A known day uses `YYYY-MM-DD` with `precision: "day"`; a known second uses an RFC 3339 UTC timestamp ending in `Z` with `precision: "second"`. Never fill an unknown release or catalog timestamp with the current date, clone time, or synchronization time.
The agent and team client schemas are generated compatibility snapshots. Their `$comment` records the upstream source commit and blob. Refresh them from the corresponding TypeScript exports when compatibility changes; do not weaken them or substitute sidecar-only validation.
The agent, skill, and team client schemas are generated compatibility snapshots. Their `$comment` records the upstream source commit and blob. Refresh them from the corresponding TypeScript exports when compatibility changes; do not weaken them or substitute sidecar-only validation.
## Localization
+4 -2
View File
@@ -33,7 +33,7 @@
### 静态目录事实
条目数量来自文件清单,不是访问量或使用量。禁止静态记录 Stars、下载量、评分、安装数量或运行健康度;证据缺失保留未知。收录版本不代表联网查询的最新版本,应保留上游原始发布标识,不能为填补缺失捏造三段版本。新的团队本地化字段及两段指针版本必须先有已发布的兼容客户端,再进入共享目录。Bootstrap 压缩包由客户端仓库的同步工具生成,不能手工修改 ZIP 内容。
条目数量来自文件清单,不是访问量或使用量。禁止静态记录 Stars、下载量、评分、安装数量或运行健康度;证据缺失保留未知。收录版本不代表联网查询的最新版本,应保留上游原始发布标识,不能为填补缺失捏造三段版本。新的团队本地化字段及两段指针版本必须先有已发布的兼容客户端,再进入共享目录。在此之前,已发布契约不接受的上游标识(如纯修订号 `50`)不写入 `latestVersion` 和 `release`,发布版本保持未知,不能改写标识去迎合格式。Bootstrap 压缩包由客户端仓库的同步工具生成,不能手工修改 ZIP 内容。
## 快速开始
@@ -115,6 +115,8 @@ uv run scripts/i18n/validate-i18n.py
外部技能使用 `skills/<id>/entry.json` 描述上游来源、展示信息、维护者、分类、许可证和再分发方式。技能条目必须提供内联 SVG `icon`,来源支持 `git`、`web` 和 `zip`。外部条目计入 `manifest.stats.totalSkills`,但不进入内置技能索引。
指针原始数据必须先通过[导出的技能客户端 Schema](schemas/market-skill-entry.client.schema.json),再进行 sidecar 校验。客户端会跳过未通过的条目,用户看不到它,而清单仍把它计入数量。`latestVersion` 接受 `x.y` 或 `x.y.z` 形式的数字版本,并映射到 `release.version`;sidecar 的 `versionScheme` 必须与客户端据此推导的结果一致,`x.y` 对应 `opaque`。sidecar 的 `category`、`tags`、`riskLevel` 和 `requiredClientVersion` 也必须与指针一致,且不能添加指针无法声明的 `skillType` 和 `compatibleAgents`。任何差异都会让客户端拒绝整份 sidecar,条目退化为仅收录。
技能集合通过一个市场条目组织多个上游技能,并声明 `children` 清单供发现和展示。子技能的元数据保留在父条目的 sidecar 中;每个子技能都有独立的 `skill + parentId + id` 身份和发布事实。父条目的版本可以未知,不得用父版本推断子技能版本。
参考[飞书 CLI 条目](skills/larksuite-cli/entry.json)及其 [sidecar](skills/larksuite-cli/catalog-metadata.v1.json)。[集合生成器](scripts/gen-collection-children.py)从上游 `SKILL.md` 提取子技能,`--check` 模式只验证固定版本、可复现的集合,不重写条目。
@@ -161,7 +163,7 @@ uv run scripts/i18n/validate-i18n.py
- **证据路径跟随实际内容。** 对随仓库分发的内容,`license.evidencePath`、`compliance.licenseEvidencePath` 和 `compliance.noticePath` 相对于条目目录解析,且文件必须真实存在。对指针,这些路径指向上游快照;离线校验无法获取该证据,并会对未固定来源的证据声明给出警告。
- **未知也是有效事实。** 使用显式 `known` / `unknown` 状态。已知日期使用 `YYYY-MM-DD` 和 `precision: "day"`;已知秒级时间使用以 `Z` 结尾的 RFC 3339 UTC 时间戳和 `precision: "second"`。不得用当前日期、克隆时间或同步时间填补未知的发布或目录时间。
智能体与团队客户端 Schema 是生成的兼容性快照,其 `$comment` 记录上游来源提交和 blob。兼容性变更时,应从相应 TypeScript 导出重新生成,不得放宽契约或用仅校验 sidecar 的方式替代。
智能体、技能与团队客户端 Schema 是生成的兼容性快照,其 `$comment` 记录上游来源提交和 blob。兼容性变更时,应从相应 TypeScript 导出重新生成,不得放宽契约或用仅校验 sidecar 的方式替代。
## 多语言维护
+4
View File
@@ -130,3 +130,7 @@ Still open after this round:
- For the next review: at the current wecom-cli pin, `wecomcli-pptx/references/templates/anti-ai-slop.md` names the source-available pptx skill in anthropics/skills as one source of a reworded checklist.
Third-party programs and live account services were not executed.
## Later correction (2026-10-31)
`skill/reverse-engineer-anything` recorded upstream revision `50` in `latestVersion` and `release.version`. The client pointer contract admits only numeric `x.y` or `x.y.z`, so clients dropped the listing from their index, and the catalog validator did not check skill pointers against that contract. The repin and its review stand. The listing now declares no version (`release: unknown`), and the validator checks skill pointers against the [exported client schema](../schemas/market-skill-entry.client.schema.json).
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "DesireCore Official Market",
"version": "1.5.21",
"version": "1.5.22",
"schemaVersion": "1.1.0",
"supportedLocales": [
"zh-CN",
@@ -0,0 +1,229 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [
"id",
"name",
"stewardship",
"license",
"redistribution",
"source"
],
"properties": {
"id": {
"type": "string",
"description": "条目唯一标识符,使用小写连字符格式,如 \"flyai-skill\"",
"pattern": "^[a-z0-9-]+$"
},
"name": {
"type": "string",
"description": "默认显示名称(源 locale),本地化变体见 i18n"
},
"category": {
"type": "string",
"minLength": 1,
"pattern": "^[a-z0-9-]+$",
"description": "市场项目分类(slug 格式),由仓库 categories.json 定义"
},
"tags": {
"type": "array",
"items": {
"type": "string"
},
"description": "标签列表,用于搜索和分类"
},
"icon": {
"type": "string",
"description": "市场列表展示的内联 SVG 图标。**只有 Skill 卡片渲染它**——marketAgentSchema 与 marketTeamSchema 都没有 icon 字段,Agent 与团队卡片一律走 avatar,条目声明了 icon 也不会显示。Pointer 技能将其随离线元数据返回。"
},
"latestVersion": {
"type": "string",
"minLength": 3,
"maxLength": 160,
"pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?$",
"not": {
"pattern": "[\\r\\n]"
},
"description": "目录收录的上游原始数字版本,允许 1.0 与 1.0.0;canonical 原样保存。旧 runtime latestVersion 另按既有 SemVer 兼容规则投影,不改变实际安装来源或准入。"
},
"i18n": {
"type": "object",
"description": "按 locale 提供的本地化展示元数据(仅 name/shortDesc,轻量)",
"additionalProperties": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "该 locale 下的显示名称"
},
"shortDesc": {
"type": "string",
"description": "该 locale 下的简短描述"
}
},
"additionalProperties": false
}
},
"maintainer": {
"type": "object",
"required": [
"name",
"verified"
],
"properties": {
"name": {
"type": "string",
"description": "维护者名称,如 \"DesireCore Official\""
},
"verified": {
"type": "boolean",
"description": "是否官方认证维护者,认证后显示蓝色勾选标记"
},
"account": {
"type": "string",
"description": "维护方账号标识,如 GitHub 组织/用户名 \"desirecore\""
},
"url": {
"type": "string",
"description": "维护方主页或仓库 URL"
}
},
"additionalProperties": false
},
"stewardship": {
"type": "string",
"enum": [
"official",
"partner",
"community",
"pointer"
],
"description": "维护方分类:official(官方)/ partner(合作伙伴官方)/ community(社区已收录)/ pointer(仅指针,不分发内容)"
},
"license": {
"type": "string",
"minLength": 1,
"description": "许可证:SPDX id(MIT/Apache-2.0/MIT-0…)或特殊值 not-declared / source-available / packaged-distribution"
},
"redistribution": {
"type": "string",
"enum": [
"allowed",
"source-pointer-only",
"verify-package-terms"
],
"description": "再分发策略:allowed(可分发)/ source-pointer-only(仅指针,安装时拉取)/ verify-package-terms(需核验条款)"
},
"source": {
"type": "object",
"required": [
"kind",
"repoUrl"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"git",
"web",
"zip"
],
"description": "内容来源类型:git(仓库)/ web(网页或文件)/ zip(打包产物)"
},
"repoUrl": {
"type": "string",
"description": "源仓库 Git URL 或资源 URL,如 https://github.com/desirecore/skill-foo.git"
},
"repoBranch": {
"type": "string",
"description": "源仓库分支名称,默认 main(kind=git 时有效)",
"default": "main"
},
"path": {
"type": "string",
"pattern": "^(?:$|(?![A-Za-z]:[\\\\/])(?![\\\\/])(?!.*(?:^|[\\\\/])\\.\\.(?:[\\\\/]|$))[^\\u0000]+)$",
"description": "内容在源仓库中的安全相对子路径,如 \"skills/foo\";为空表示仓库根目录。禁止绝对路径、盘符与 .. 路径段。"
},
"ref": {
"type": "string",
"description": "锁定的 commit SHA / tag,用于可复现安装;为空表示取分支 HEAD"
},
"sha256": {
"type": "string",
"pattern": "^[0-9a-fA-F]{64}$",
"description": "web/zip 资源原始响应体的 SHA-256;能力自动安装要求用它绑定发现时的不可变字节。"
}
},
"additionalProperties": false
},
"requiredClientVersion": {
"type": "string",
"description": "此条目要求的最低客户端版本(semver),低于此版本时提示升级",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
},
"riskLevel": {
"type": "string",
"enum": [
"low",
"medium",
"high"
],
"description": "技能的风险等级,决定操作是否需要用户确认和权限检查"
},
"children": {
"type": "array",
"items": {
"type": "object",
"required": [
"id",
"path"
],
"properties": {
"id": {
"type": "string",
"description": "子技能 ID,同时是安装到 skills/ 下的目录名,使用小写连字符格式。长度上界不只是目录名卫生:该 id 会被拼进对外诊断的 `children.<id>.<field>`,而诊断 `field` 有 Ajv `maxLength`——不限长等于把第三方仓库的一个字符串变成详情端点 500 的开关(同步器出口另有截断兜底)。",
"pattern": "^[a-z0-9-]+$",
"maxLength": 64
},
"path": {
"type": "string",
"description": "子技能在源仓库中的子路径,如 \"skills/lark-im\"",
"minLength": 1
},
"name": {
"type": "string",
"description": "默认显示名称(源 locale),本地化变体见 i18n"
},
"i18n": {
"type": "object",
"description": "按 locale 提供的本地化展示元数据(仅 name/shortDesc,轻量)",
"additionalProperties": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "该 locale 下的显示名称"
},
"shortDesc": {
"type": "string",
"description": "该 locale 下的简短描述"
}
},
"additionalProperties": false
}
},
"version": {
"type": "string",
"description": "市场登记的子技能版本(semver),上游 SKILL.md 缺根级 version 时作为兜底",
"pattern": "^\\d+\\.\\d+\\.\\d+$"
}
},
"additionalProperties": false
},
"minItems": 1,
"description": "合集子技能清单。存在即表示本条目是合集(源仓库内有多个平级技能),安装时由用户勾选装哪几个;与 source.path 互斥。缺省时按单技能条目处理。"
}
},
"additionalProperties": false,
"$comment": "Generated from desirecore/desirecore packages/schemas/src/market.ts#marketSkillEntrySchema at commit b7d11e919882ec2cfe3087104e0bf06c10493c83 (v10.0.195), source blob 9fc439c9c662ea086ab8a8024c9e4830b084653b. Keep the complete client contract; regenerate from that export instead of editing fields manually."
}
+233 -38
View File
@@ -32,6 +32,46 @@ def unknown() -> dict[str, str]:
return {"state": "unknown"}
def known_release(version: str, scheme: str = "opaque"):
return lambda payload: payload.update(release={"state": "known", "version": version, "versionScheme": scheme})
def add_single_child_collection(payload: dict) -> None:
child_presentation = copy.deepcopy(payload["presentation"])
child_presentation["tags"] = []
child_presentation["i18n"] = {
"zh-CN": {"name": "child-one", "summary": "Same child summary"},
"en-US": {"name": "child-one", "summary": "Same child summary"},
}
payload["spec"]["collection"] = {
"role": "parent",
"childCount": 1,
"children": [
{
"identity": {
"kind": "skill",
"id": "child-one",
"parentId": "example-skill",
},
"path": "skills/child-one",
"presentation": child_presentation,
"release": unknown(),
}
]
}
def single_child_entry() -> dict[str, object]:
return {
"id": "child-one",
"path": "skills/child-one",
"i18n": {
"zh-CN": {"shortDesc": "Same child summary"},
"en-US": {"shortDesc": "Same child summary"},
},
}
def valid_entry() -> dict[str, object]:
return {
"id": "example-skill",
@@ -168,7 +208,7 @@ def valid_sidecar() -> dict[str, object]:
"upstreamMaintainer": {"name": "Example Maintainer", "verified": False},
},
"compatibility": {"platforms": unknown()},
"spec": {"kind": "skill", "riskLevel": "low"},
"spec": {"kind": "skill"},
}
@@ -178,7 +218,11 @@ class CatalogMetadataValidatorTests(unittest.TestCase):
self.root = Path(self.tempdir.name)
(self.root / "schemas").mkdir()
shutil.copyfile(SOURCE_SCHEMA, self.root / "schemas" / SOURCE_SCHEMA.name)
for client_schema in (VALIDATOR.AGENT_ENTRY_SCHEMA_NAME, VALIDATOR.TEAM_ENTRY_SCHEMA_NAME):
for client_schema in (
VALIDATOR.AGENT_ENTRY_SCHEMA_NAME,
VALIDATOR.SKILL_ENTRY_SCHEMA_NAME,
VALIDATOR.TEAM_ENTRY_SCHEMA_NAME,
):
shutil.copyfile(SOURCE_SCHEMA.with_name(client_schema), self.root / "schemas" / client_schema)
(self.root / "agents").mkdir()
(self.root / "teams").mkdir()
@@ -211,6 +255,16 @@ class CatalogMetadataValidatorTests(unittest.TestCase):
mutate(payload)
self.write_json(self.sidecar_path, payload)
def write_skill_pointer_case(self, mutate_entry=None, mutate_sidecar=None) -> None:
entry = valid_entry()
sidecar = valid_sidecar()
if mutate_entry:
mutate_entry(entry)
if mutate_sidecar:
mutate_sidecar(sidecar)
self.write_json(self.entry_path, entry)
self.write_json(self.sidecar_path, sidecar)
def write_agent_case(self, install_policy: str | None, update_policy: str | None, availability: str) -> None:
agent_dir = self.root / "agents" / "system-agent"
agent_dir.mkdir()
@@ -652,6 +706,180 @@ class CatalogMetadataValidatorTests(unittest.TestCase):
self.write_agent_pointer_case(entry_change, metadata_change)
self.assertTrue(any(issue.rule == "agent-entry-schema" for issue in self.validate().issues))
def test_rejects_skill_pointer_the_client_would_drop_even_if_sidecar_repeats_it(self) -> None:
# The client skips such an entry while indexing: the listing disappears for every
# user while manifest.stats.totalSkills keeps counting it.
cases = [
(lambda p: p.update(latestVersion="50"), known_release("50")),
(lambda p: p.update(latestVersion="1.2.3.4"), known_release("1.2.3.4")),
(lambda p: p.update(latestVersion="1.2.3-beta"), known_release("1.2.3-beta", "semver")),
(lambda p: p.update(latestVersion=123), known_release("123")),
(lambda p: p.update(latestVersion="١.٢"), known_release("١.٢")),
(lambda p: p.update(requiredClientVersion="1.0"), None),
(lambda p: p.update(version="1.2.3"), None),
(lambda p: p.update(riskLevel="extreme"), None),
(lambda p: p.update(id="Example_Skill"), None),
(lambda p: p.pop("stewardship"), None),
(lambda p: p["source"].update(kind="ftp"), None),
(lambda p: p["maintainer"].update(verified="true"), None),
]
for index, (entry_change, metadata_change) in enumerate(cases):
with self.subTest(index=index):
self.write_skill_pointer_case(entry_change, metadata_change)
self.assertTrue(any(issue.rule == "skill-entry-schema" for issue in self.validate().issues))
def test_rejects_skill_collection_shapes_the_client_rejects_outside_json_schema(self) -> None:
cases = {
"children with source.path": lambda p: (
p.update(children=[single_child_entry()]),
p["source"].update(path="skills/child-one"),
),
"duplicate child id": lambda p: p.update(children=[single_child_entry(), single_child_entry()]),
}
for name, entry_change in cases.items():
with self.subTest(name):
self.write_skill_pointer_case(entry_change, add_single_child_collection)
self.assertTrue(any(issue.rule == "skill-entry-schema" for issue in self.validate().issues))
def test_rejects_skill_pointer_entry_id_that_is_not_the_catalog_slug(self) -> None:
self.write_skill_pointer_case(lambda p: p.update(id="another-skill"))
self.assertTrue(any("entry.id" in issue.message for issue in self.validate().issues))
def test_skill_pointer_accepts_every_version_form_the_client_admits(self) -> None:
for version, scheme in (("1.3", "opaque"), ("1.2.3", "semver"), ("2026.9.19", "calver")):
with self.subTest(version=version):
self.write_skill_pointer_case(lambda p: p.update(latestVersion=version), known_release(version, scheme))
self.assertFalse(self.validate().has_errors)
def test_release_must_equal_what_the_client_derives_from_the_pointer(self) -> None:
# The client derives a release from latestVersion and rejects the whole sidecar on
# any difference, which silently turns an installable listing into listing-only.
cases = {
"pointer knows, sidecar omits": (lambda p: p.update(latestVersion="1.2.3"), None),
"different version": (lambda p: p.update(latestVersion="1.2.3"), known_release("1.2.4", "semver")),
"only the sidecar knows": (None, known_release("1.2.3", "semver")),
"opaque for a semver": (lambda p: p.update(latestVersion="1.2.3"), known_release("1.2.3")),
"semver for a calver": (
lambda p: p.update(latestVersion="2026.9.19"),
known_release("2026.9.19", "semver"),
),
}
for name, (entry_change, metadata_change) in cases.items():
with self.subTest(name):
self.write_skill_pointer_case(entry_change, metadata_change)
self.assertTrue(
any(issue.rule == "legacy-consistency" and "release" in issue.message
for issue in self.validate().issues)
)
def test_skill_pointer_sidecar_cannot_add_or_drop_facts_the_client_compares(self) -> None:
# Each case made the client reject the sidecar while this validator stayed green.
cases = {
"skillType only in sidecar": (None, lambda p: p["spec"].update(skillType="procedural")),
"riskLevel only in sidecar": (None, lambda p: p["spec"].update(riskLevel="high")),
"riskLevel only in entry": (lambda p: p.update(riskLevel="high"), None),
"riskLevel differs": (lambda p: p.update(riskLevel="low"), lambda p: p["spec"].update(riskLevel="high")),
"client floor only in sidecar": (
None,
lambda p: p["compatibility"].update(requiredClientVersion="10.0.0"),
),
"client floor only in entry": (lambda p: p.update(requiredClientVersion="10.0.0"), None),
"compatibleAgents only in sidecar": (None, lambda p: p["compatibility"].update(compatibleAgents=["x"])),
"category only in sidecar": (lambda p: p.pop("category"), None),
"tags only in sidecar": (lambda p: p.pop("tags"), None),
"path only in sidecar": (None, lambda p: p["provenance"]["content"].update(path="extra/path")),
}
for name, (entry_change, metadata_change) in cases.items():
with self.subTest(name):
self.write_skill_pointer_case(entry_change, metadata_change)
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
def test_agent_pointer_sidecar_cannot_add_facts_the_client_compares(self) -> None:
cases = {
"client floor only in sidecar": (lambda p: p.pop("requiredClientVersion"), None),
"client floor only in entry": (None, lambda p: p["compatibility"].pop("requiredClientVersion")),
"compatibleAgents only in sidecar": (None, lambda p: p["compatibility"].update(compatibleAgents=["x"])),
"category only in sidecar": (lambda p: p.pop("category"), None),
}
for name, (entry_change, metadata_change) in cases.items():
with self.subTest(name):
self.write_agent_pointer_case(entry_change, metadata_change)
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
def test_inline_agent_sidecar_must_match_the_facts_the_client_compares(self) -> None:
self.write_agent_case("market", "market", "listing-only")
agent_path = self.root / "agents" / "system-agent" / "agent.json"
sidecar_path = self.root / "agents" / "system-agent" / VALIDATOR.SIDECAR_NAME
self.write_json(self.root / "manifest.json", {
"supportedLocales": ["zh-CN", "en-US"], "stats": {"totalAgents": 1, "totalSkills": 1},
})
agent = json.loads(agent_path.read_text(encoding="utf-8"))
agent["i18n"]["en-US"]["tags"] = ["localized"]
self.write_json(agent_path, agent)
sidecar = json.loads(sidecar_path.read_text(encoding="utf-8"))
sidecar["presentation"]["tags"] = ["localized"]
self.write_json(sidecar_path, sidecar)
self.assertFalse(self.validate().has_errors, "the default locale's tags are the legacy tags")
cases = {
"tags differ": lambda p: p["presentation"].update(tags=["other"]),
"client floor only in sidecar": lambda p: p["compatibility"].update(requiredClientVersion="10.0.0"),
}
for name, mutate in cases.items():
with self.subTest(name):
changed = copy.deepcopy(sidecar)
mutate(changed)
self.write_json(sidecar_path, changed)
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
def test_builtin_skill_sidecar_must_match_the_facts_the_client_compares(self) -> None:
self.entry_path.unlink()
self.entry_path.with_name("SKILL.md").write_text(
"---\nname: example-skill\ndescription: Example builtin skill.\nversion: 1.2.3\n"
"type: meta\nrisk_level: high\ntags:\n - example\n"
"market:\n category: development\n required_client_version: 10.0.0\n"
"metadata:\n i18n:\n default_locale: en-US\n"
" zh-CN:\n name: 示例技能\n short_desc: 中文简介\n"
" en-US:\n name: Example Skill\n short_desc: English summary\n---\nBody.\n",
encoding="utf-8",
)
def matching(payload):
known_release("1.2.3", "semver")(payload)
payload["provenance"] = {}
payload["spec"] = {"kind": "skill", "riskLevel": "high"}
payload["compatibility"]["requiredClientVersion"] = "10.0.0"
self.rewrite_sidecar(matching)
self.assertFalse(
any(issue.rule == "legacy-consistency" for issue in self.validate().issues),
"an unknown frontmatter type such as meta is no skillType fact for the client",
)
cases = {
"skillType only in sidecar": lambda p: p["spec"].update(skillType="procedural"),
"riskLevel differs": lambda p: p["spec"].update(riskLevel="low"),
"client floor differs": lambda p: p["compatibility"].update(requiredClientVersion="10.0.1"),
}
for name, mutate in cases.items():
with self.subTest(name):
self.rewrite_sidecar(lambda p: (matching(p), mutate(p)))
self.assertTrue(any(issue.rule == "legacy-consistency" for issue in self.validate().issues))
def test_agent_pointer_release_cannot_exceed_what_the_entry_declares(self) -> None:
self.write_agent_pointer_case(lambda p: p.pop("latestVersion"))
self.assertTrue(
any(issue.rule == "legacy-consistency" and "release" in issue.message
for issue in self.validate().issues)
)
def test_collection_parent_version_is_ignored_like_the_client_does(self) -> None:
def entry_change(payload):
payload.update(latestVersion="1.2.3", children=[single_child_entry()])
self.write_skill_pointer_case(entry_change, add_single_child_collection)
self.assertFalse(self.validate().has_errors)
def test_agent_pointer_default_policy_cannot_be_replaced_by_sidecar(self) -> None:
def default_policy(payload):
payload.pop("installPolicy")
@@ -871,49 +1099,16 @@ Body.
def test_validates_collection_identity_and_does_not_invent_child_version(self) -> None:
entry = valid_entry()
entry["children"] = [
{
"id": "child-one",
"path": "skills/child-one",
"i18n": {
"zh-CN": {"shortDesc": "Same child summary"},
"en-US": {"shortDesc": "Same child summary"},
},
}
]
entry["children"] = [single_child_entry()]
self.write_json(self.entry_path, entry)
def mutate(payload):
child_presentation = copy.deepcopy(payload["presentation"])
child_presentation["tags"] = []
child_presentation["i18n"] = {
"zh-CN": {"name": "child-one", "summary": "Same child summary"},
"en-US": {"name": "child-one", "summary": "Same child summary"},
}
payload["spec"]["collection"] = {
"role": "parent",
"childCount": 1,
"children": [
{
"identity": {
"kind": "skill",
"id": "child-one",
"parentId": "example-skill",
},
"path": "skills/child-one",
"presentation": child_presentation,
"release": unknown(),
}
]
}
self.rewrite_sidecar(mutate)
self.rewrite_sidecar(add_single_child_collection)
report = self.validate()
self.assertFalse(report.has_errors)
self.assertTrue(any(issue.rule == "i18n-freshness" for issue in report.issues))
def invent_version(payload):
mutate(payload)
add_single_child_collection(payload)
payload["spec"]["collection"]["children"][0]["release"] = {
"state": "known",
"version": "1.0.0",
+113 -30
View File
@@ -32,6 +32,7 @@ from jsonschema import Draft7Validator, FormatChecker, ValidationError, validato
REPO_ROOT = Path(__file__).resolve().parents[2]
SCHEMA_PATH = REPO_ROOT / "schemas" / "catalog-metadata.v1.schema.json"
AGENT_ENTRY_SCHEMA_NAME = "market-agent-entry.client.schema.json"
SKILL_ENTRY_SCHEMA_NAME = "market-skill-entry.client.schema.json"
TEAM_ENTRY_SCHEMA_NAME = "market-team-entry.client.schema.json"
# Catalog roots that may hold a sidecar, in listing order.
CATALOG_ROOTS = ("agents", "teams", "skills")
@@ -50,6 +51,19 @@ EXPECTED_SCHEMA_REF = "../../schemas/catalog-metadata.v1.schema.json"
FRONTMATTER_RE = re.compile(r"^---\s*\n(.*?)\n---\s*\n", re.DOTALL)
FULL_GIT_REF_RE = re.compile(r"^[a-fA-F0-9]{40}(?:[a-fA-F0-9]{24})?$")
CONTAINER_DIGEST_RE = re.compile(r"^sha256:[a-fA-F0-9]{64}$")
CLIENT_SEMVER_RE = re.compile(
r"(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)\.(?:0|[1-9]\d*)(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?", re.ASCII
)
CLIENT_CALVER_RE = re.compile(r"\d{4}(?:[.-]\d{1,2}){1,2}(?:[.-][0-9A-Za-z]+)*", re.ASCII)
CLIENT_RISK_LEVELS = {"low", "medium", "high", "critical"}
CLIENT_SKILL_TYPES = {"procedural", "declarative", "hybrid"}
def _client_version_scheme(version: str) -> str:
"""Classify a version the way the client's normalizeRelease does: calver wins over semver."""
if CLIENT_CALVER_RE.fullmatch(version):
return "calver"
return "semver" if CLIENT_SEMVER_RE.fullmatch(version) else "opaque"
def _client_pattern(validator, pattern, instance, schema):
@@ -195,6 +209,22 @@ def _report_entry_schema_errors(
return bool(errors)
def _report_skill_collection_errors(report: Report, pointer_path: Path, root: Path, data: dict[str, Any]) -> bool:
"""Report the two collection rules the client enforces outside its JSON Schema."""
children = data.get("children")
if not children:
return False
errors = []
if data["source"].get("path"):
errors.append("children and source.path are mutually exclusive")
child_ids = [child["id"] for child in children]
if len(child_ids) != len(set(child_ids)):
errors.append("children must not repeat a child id")
for error in errors:
report.add(_rel(pointer_path, root), "skill-entry-schema", error)
return bool(errors)
def _load_team_pointer(
sidecar: Path,
parent: Path,
@@ -276,6 +306,10 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
str(data["version"]) if data.get("version") is not None else None
)
i18n, default_locale = _legacy_i18n(data.get("i18n"), short_key="shortDesc")
# Inline metadata may localize tags, and the client prefers the default locale's.
localized = data.get("i18n", {}).get(default_locale) if isinstance(data.get("i18n"), dict) else None
tags = localized.get("tags") if isinstance(localized, dict) else None
tags = tags if tags is not None and not is_pointer else data.get("tags")
return LegacyItem(
kind="agent",
item_id=parent.name,
@@ -285,7 +319,7 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
default_locale=default_locale,
version=version,
category=data.get("category") if isinstance(data.get("category"), str) else None,
tags=data.get("tags") if isinstance(data.get("tags"), list) else None,
tags=tags if isinstance(tags, list) else None,
)
if root_kind == "teams":
@@ -313,6 +347,12 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
data = _read_json(pointer_path, report, root, "legacy-read")
if data is None:
return None
if _report_entry_schema_errors(
report, pointer_path, root, entry_validators["skill"], "skill-entry-schema", data
) or _report_skill_collection_errors(report, pointer_path, root, data):
return None
if data.get("id") != parent.name:
report.add(_rel(pointer_path, root), "legacy-consistency", "entry.id must equal the catalog directory slug")
i18n, default_locale = _legacy_i18n(data.get("i18n"), short_key="shortDesc")
return LegacyItem(
kind="skill",
@@ -321,7 +361,9 @@ def load_legacy(sidecar: Path, report: Report, root: Path, entry_validators: dic
data=data,
i18n=i18n,
default_locale=default_locale,
version=str(data["version"]) if data.get("version") is not None else None,
# Client indexing reads latestVersion for pointers and ignores a collection
# parent's own version, so that parent's release stays unknown.
version=None if data.get("children") else data.get("latestVersion"),
category=data.get("category") if isinstance(data.get("category"), str) else None,
tags=data.get("tags") if isinstance(data.get("tags"), list) else None,
)
@@ -449,26 +491,59 @@ def _validate_content_consistency(
"ref": "ref",
"sha256": "sha256",
}
label = {"agent": "Agent", "team": "Team", "skill": "skill"}[legacy.kind]
for sidecar_key, legacy_key in mapping.items():
legacy_value = source.get(legacy_key)
if legacy.kind in {"agent", "team"}:
declared_value = content.get(sidecar_key)
# A sidecar must describe the exact pointer that the client installs,
# not add a different subdirectory or pin that entry.json never uses.
if sidecar_key in {"path", "ref"}:
declared_value = None if declared_value == "" else declared_value
legacy_value = None if legacy_value == "" else legacy_value
if declared_value != legacy_value:
label = "Agent" if legacy.kind == "agent" else "Team"
report.add(rel, "legacy-consistency", f"provenance.content.{sidecar_key} differs from the {label} pointer")
elif legacy_value is not None:
_compare(
report,
rel,
f"provenance.content.{sidecar_key}",
content.get(sidecar_key),
legacy_value,
)
declared_value = content.get(sidecar_key)
# A sidecar must describe the exact pointer that the client installs,
# not add a different subdirectory or pin that entry.json never uses.
if sidecar_key in {"path", "ref"}:
declared_value = None if declared_value == "" else declared_value
legacy_value = None if legacy_value == "" else legacy_value
if declared_value != legacy_value:
report.add(rel, "legacy-consistency", f"provenance.content.{sidecar_key} differs from the {label} pointer")
def _validate_client_compared_facts(
report: Report,
rel: str,
sidecar: dict[str, Any],
legacy: LegacyItem,
) -> None:
"""Compare, both ways, the facts the client compares between a sidecar and its legacy file.
Any difference makes the client reject the whole sidecar, which downgrades an
installable listing to listing-only. Clients do not hydrate Team sidecars.
"""
if legacy.kind == "team":
return
data = legacy.data
presentation = sidecar.get("presentation", {})
compatibility = sidecar.get("compatibility", {})
market = data.get("market") if legacy.source_type == "builtin" and isinstance(data.get("market"), dict) else {}
facts = [
("presentation.category", presentation.get("category"), legacy.category),
("presentation.tags", presentation.get("tags") or [], legacy.tags or []),
(
"compatibility.requiredClientVersion",
compatibility.get("requiredClientVersion"),
market.get("required_client_version", data.get("requiredClientVersion")),
),
]
if legacy.source_type == "pointer":
# A pointer has no compatibleAgents field for a sidecar to match.
facts.append(("compatibility.compatibleAgents", compatibility.get("compatibleAgents") or None, None))
if legacy.kind == "skill":
spec = sidecar.get("spec", {})
risk_level = data.get("riskLevel") or data.get("risk_level")
skill_type = data.get("type")
facts += [
("spec.riskLevel", spec.get("riskLevel"), risk_level if risk_level in CLIENT_RISK_LEVELS else None),
("spec.skillType", spec.get("skillType"), skill_type if skill_type in CLIENT_SKILL_TYPES else None),
]
for field, sidecar_value, legacy_value in facts:
if sidecar_value != legacy_value:
report.add(rel, "legacy-consistency", f"{field} differs from the legacy value")
def _validate_governance_consistency(
@@ -762,10 +837,11 @@ def validate_sidecar(
if sidecar.get("$schema") not in (None, EXPECTED_SCHEMA_REF):
report.add(rel, "fixed-sidecar-path", f"$schema must be {EXPECTED_SCHEMA_REF!r}")
presentation = sidecar.get("presentation", {})
_compare(report, rel, "presentation.category", presentation.get("category"), legacy.category)
if legacy.tags is not None:
_compare(report, rel, "presentation.tags", presentation.get("tags"), legacy.tags)
if legacy.kind == "team":
presentation = sidecar.get("presentation", {})
_compare(report, rel, "presentation.category", presentation.get("category"), legacy.category)
if legacy.tags is not None:
_compare(report, rel, "presentation.tags", presentation.get("tags"), legacy.tags)
_validate_i18n(report, rel, sidecar, legacy, supported_locales)
release = sidecar.get("release")
@@ -786,21 +862,26 @@ def validate_sidecar(
"agent-policy",
"system Agent metadata revision must not be exposed as a content release timestamp",
)
elif legacy.version is not None and isinstance(release, dict):
if release.get("state") != "known":
elif isinstance(release, dict):
# The client derives a release from the legacy version and rejects the whole
# sidecar when the two differ, in either direction and including the scheme.
if legacy.version is None:
if release.get("state") == "known":
report.add(rel, "legacy-consistency", "release declares a version the legacy file does not have")
elif release.get("state") != "known":
report.add(rel, "legacy-consistency", "release must preserve the legacy version")
else:
_compare(report, rel, "release.version", release.get("version"), legacy.version)
_compare(
report, rel, "release.versionScheme",
release.get("versionScheme"), _client_version_scheme(legacy.version),
)
if legacy.kind == "agent" and legacy.source_type == "pointer":
for field in ("installPolicy", "updatePolicy"):
# Ordinary pointers default to market/market in the client. A sidecar
# cannot turn an omitted pair into a system/repository listing.
_compare(report, rel, f"spec.{field}", spec.get(field, "market"), legacy.data.get(field, "market"))
_compare(
report, rel, "compatibility.requiredClientVersion",
sidecar["compatibility"].get("requiredClientVersion"), legacy.data.get("requiredClientVersion"),
)
if legacy.kind == "team":
# Teams are always fork-installed and git-pull-updated, so there is no
@@ -813,6 +894,7 @@ def validate_sidecar(
report.add(rel, "legacy-consistency", "compatibility.requiredClientVersion differs from the Team pointer")
_validate_content_consistency(report, rel, sidecar, legacy)
_validate_client_compared_facts(report, rel, sidecar, legacy)
_validate_governance_consistency(report, rel, sidecar, legacy)
_validate_license_evidence(report, rel, sidecar, legacy, sidecar_path.parent)
_validate_collection(report, rel, sidecar, legacy, supported_locales)
@@ -966,6 +1048,7 @@ def validate_repository(root: Path = REPO_ROOT, *, require_complete: bool = Fals
entry_validators: dict[str, Any] = {}
for kind, schema_name, rule in (
("agent", AGENT_ENTRY_SCHEMA_NAME, "agent-entry-schema"),
("skill", SKILL_ENTRY_SCHEMA_NAME, "skill-entry-schema"),
("team", TEAM_ENTRY_SCHEMA_NAME, "team-entry-schema"),
):
entry_schema = _read_json(root / "schemas" / schema_name, report, root, rule)
@@ -27,14 +27,12 @@
]
},
"release": {
"state": "known",
"version": "50",
"versionScheme": "opaque"
"state": "unknown"
},
"timestamps": {
"catalogUpdatedAt": {
"state": "known",
"value": "2026-10-27",
"value": "2026-10-31",
"precision": "day"
},
"releasePublishedAt": {
@@ -10,7 +10,6 @@
"mcp",
"cli"
],
"latestVersion": "50",
"i18n": {
"zh-CN": {
"name": "REA 逆向分析",
+2 -3
View File
@@ -34,7 +34,7 @@
"timestamps": {
"catalogUpdatedAt": {
"state": "known",
"value": "2026-10-19",
"value": "2026-10-31",
"precision": "day"
},
"releasePublishedAt": {
@@ -94,7 +94,6 @@
},
"spec": {
"kind": "skill",
"riskLevel": "medium",
"skillType": "procedural"
"riskLevel": "medium"
}
}