Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(desktop): align skill yaml validation
xd-bobo8e2b0fc14c2d
diff --git a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.pyindex c02fd38411..de23a16ceb 100644--- a/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py+++ b/apps/desktop/resources/system-skills/cindy-skill-creator/scripts/_frontmatter.py@@ -22,6 +22,47 @@ FRONTMATTER_RE = re.compile()+class FrontmatterLoader(yaml.SafeLoader):+ """SafeLoader with the scalar resolver semantics used by js-yaml 3."""+++# gray-matter 4 uses js-yaml 3's DEFAULT_SAFE_SCHEMA. Unlike PyYAML's YAML 1.1+# resolver, it leaves yes/no/on/off as strings, resolves only true/false as+# booleans, and accepts scientific notation without a decimal point.+# Copy the inherited table before editing so other vendored PyYAML consumers+# retain SafeLoader's defaults.+FrontmatterLoader.yaml_implicit_resolvers = {+ first: [+ (tag, resolver)+ for tag, resolver in resolvers+ if tag not in {"tag:yaml.org,2002:bool", "tag:yaml.org,2002:float"}+ ]+ for first, resolvers in yaml.SafeLoader.yaml_implicit_resolvers.items()+}+FrontmatterLoader.add_implicit_resolver(+ "tag:yaml.org,2002:bool",+ re.compile(r"^(?:true|True|TRUE|false|False|FALSE)$"),+ list("tTfF"),+)+FrontmatterLoader.add_implicit_resolver(+ "tag:yaml.org,2002:float",+ re.compile(+ r"""^(?:+ [-+]?(?:0|[1-9][0-9_]*)(?:+ \.[0-9_]*(?:[eE][-+]?[0-9]+)?+ |[eE][-+]?[0-9]++ )+ |\.[0-9_]+(?:[eE][-+]?[0-9]+)?+ |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*+ |[-+]?\.(?:inf|Inf|INF)+ |\.(?:nan|NaN|NAN)+ )$""",+ re.X,+ ),+ list("-+0123456789."),+)++def split_frontmatter(content):match = FRONTMATTER_RE.match(content)if not match:@@ -57,10 +98,10 @@ def _reject_duplicate_mapping_keys(node, visited=None):def parse_frontmatter(frontmatter_text):try:- root = yaml.compose(frontmatter_text, Loader=yaml.SafeLoader)+ root = yaml.compose(frontmatter_text, Loader=FrontmatterLoader)if root is not None:_reject_duplicate_mapping_keys(root)- return yaml.safe_load(frontmatter_text)+ return yaml.load(frontmatter_text, Loader=FrontmatterLoader)except FrontmatterError:raiseexcept yaml.YAMLError as exc:diff --git a/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.ts b/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.tsindex 572bf6af86..64df7527e5 100644--- a/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.ts+++ b/apps/desktop/src/main/maker-host/__tests__/built-in-skills.test.ts@@ -88,7 +88,7 @@ describe('built-in Skills', () => {const link = path.join(input.homeDir, '.agents', 'skills', 'cindy-skill-creator');expect(first.changed).toBe(true);expect(first.warnings).toEqual([]);- expect(manifest).toMatchObject({ schemaVersion: 3, bundleVersion: 7 });+ expect(manifest).toMatchObject({ schemaVersion: 3, bundleVersion: 8 });expect(descriptor.absolutePath).toBe(path.join(root, '.versions', manifest.activeBundle, 'cindy-skill-creator'),);@@ -123,7 +123,7 @@ describe('built-in Skills', () => {expect(fs.existsSync(path.join(descriptor.absolutePath, 'SKILL.md'))).toBe(true);fs.appendFileSync(path.join(input.source, 'SKILL.md'), '\nUpdated\n');- const updated = await prepareAndProjectBuiltInSkills({ ...input, bundleVersion: 8 });+ const updated = await prepareAndProjectBuiltInSkills({ ...input, bundleVersion: 9 });expect(updated.changed).toBe(true);const updatedDescriptor = updated.descriptors.find((item) => item.name === 'cindy-skill-creator',@@ -189,7 +189,7 @@ describe('built-in Skills', () => {);fs.writeFileSync(manifestPath, JSON.stringify({schemaVersion: 3,- bundleVersion: 7,+ bundleVersion: 8,fingerprints: {},activeBundle: 'damaged',}));@@ -247,9 +247,9 @@ describe('built-in Skills', () => {path.join(input.bundledRoot, 'learn', 'SKILL.md.missing'),);- const partial = await prepareBuiltInSkills({ ...input, bundleVersion: 8 });+ const partial = await prepareBuiltInSkills({ ...input, bundleVersion: 9 });const manifestPath = path.join(input.appDataDir, 'Cindy', 'shared-system-skills', '.cindy-system-skills.json');- expect(JSON.parse(fs.readFileSync(manifestPath, 'utf8')).bundleVersion).toBe(7);+ expect(JSON.parse(fs.readFileSync(manifestPath, 'utf8')).bundleVersion).toBe(8);expect(partial.warnings.join('\n')).toContain('missing SKILL.md');expect(fs.readFileSync(path.join(partial.descriptors[0]!.absolutePath, 'SKILL.md'), 'utf8'),@@ -259,9 +259,9 @@ describe('built-in Skills', () => {path.join(input.bundledRoot, 'learn', 'SKILL.md.missing'),path.join(input.bundledRoot, 'learn', 'SKILL.md'),);- const retried = await prepareBuiltInSkills({ ...input, bundleVersion: 8 });+ const retried = await prepareBuiltInSkills({ ...input, bundleVersion: 9 });expect(retried.warnings).toEqual([]);- expect(JSON.parse(fs.readFileSync(manifestPath, 'utf8')).bundleVersion).toBe(8);+ expect(JSON.parse(fs.readFileSync(manifestPath, 'utf8')).bundleVersion).toBe(9);expect(fs.readFileSync(path.join(@@ -302,7 +302,7 @@ describe('built-in Skills', () => {await originalRename(source, destination);});- const failed = await prepareBuiltInSkills({ ...input, bundleVersion: 8 });+ const failed = await prepareBuiltInSkills({ ...input, bundleVersion: 9 });expect(failed.changed).toBe(false);expect(failed.warnings.join('\n')).toContain('blocked version publish');@@ -332,7 +332,7 @@ describe('built-in Skills', () => {originalRename(source, destination);});- const failed = await prepareBuiltInSkills({ ...input, bundleVersion: 8 });+ const failed = await prepareBuiltInSkills({ ...input, bundleVersion: 9 });expect(failed.changed).toBe(false);expect(failed.warnings.join('\n')).toContain('blocked manifest switch');@@ -374,7 +374,7 @@ describe('built-in Skills', () => {expect(retried.warnings).toEqual([]);expect(JSON.parse(fs.readFileSync(manifestPath, 'utf8'))).toMatchObject({schemaVersion: 3,- bundleVersion: 7,+ bundleVersion: 8,});});diff --git a/apps/desktop/src/main/maker-host/built-in-skills.ts b/apps/desktop/src/main/maker-host/built-in-skills.tsindex 7495075642..d308d25cea 100644--- a/apps/desktop/src/main/maker-host/built-in-skills.ts+++ b/apps/desktop/src/main/maker-host/built-in-skills.ts@@ -19,7 +19,7 @@ const MANIFEST_FILE = '.cindy-system-skills.json';const VERSIONS_DIRECTORY = '.versions';const BUILT_IN_SKILL_MUTATION_WAIT_MS = 5_000;/** Increment whenever shipped built-in Skill bytes change between releases. */-export const BUILT_IN_SKILLS_BUNDLE_VERSION = 7;+export const BUILT_IN_SKILLS_BUNDLE_VERSION = 8;export interface BuiltInSkillDescriptor {name: string;diff --git a/scripts/__tests__/third-party-notices.test.mjs b/scripts/__tests__/third-party-notices.test.mjsindex dc00ee3adb..81f632cdcc 100644--- a/scripts/__tests__/third-party-notices.test.mjs+++ b/scripts/__tests__/third-party-notices.test.mjs@@ -386,6 +386,40 @@ metadata:assert.equal(result.status, 0, `${result.stdout}\n${result.stderr}`);assert.match(result.stdout, /Skill is valid!/);+ fs.writeFileSync(+ path.join(skillDir, "SKILL.md"),+ "---\nname: on\ndescription: yes\n---\n# js-yaml scalar compatibility\n",+ );+ const legacyBooleanWords = spawnSync(command, [...prefix, "-S", validator, skillDir], {+ encoding: "utf8",+ });+ assert.equal(+ legacyBooleanWords.status,+ 0,+ `${legacyBooleanWords.stdout}\n${legacyBooleanWords.stderr}`,+ );+ assert.match(legacyBooleanWords.stdout, /Skill is valid!/);++ fs.writeFileSync(+ path.join(skillDir, "SKILL.md"),+ "---\nname: yaml-regression\ndescription: true\n---\n",+ );+ const actualBoolean = spawnSync(command, [...prefix, "-S", validator, skillDir], {+ encoding: "utf8",+ });+ assert.notEqual(actualBoolean.status, 0);+ assert.match(actualBoolean.stdout, /Description must be a string, got bool/);++ fs.writeFileSync(+ path.join(skillDir, "SKILL.md"),+ "---\nname: yaml-regression\ndescription: 1e3\n---\n",+ );+ const scientificNumber = spawnSync(command, [...prefix, "-S", validator, skillDir], {+ encoding: "utf8",+ });+ assert.notEqual(scientificNumber.status, 0);+ assert.match(scientificNumber.stdout, /Description must be a string, got float/);+fs.writeFileSync(path.join(skillDir, "SKILL.md"),"---\nname: yaml-regression\ndescription: invalid\0value\n---\n",