// SPDX-License-Identifier: AGPL-3.0-only 'use strict'; const fs = require('node:fs'); const path = require('node:path'); const root = path.join(__dirname, '..', 'skills', 'sandwich-hime'); const expected = ['LICENSE', 'SKILL.md', 'agents/openai.yaml', 'references/authoring.md', 'references/workflows.md'].sort(); const actual = []; function walk(directory) { for (const entry of fs.readdirSync(directory, {withFileTypes: true})) { const target = path.join(directory, entry.name); if (entry.isSymbolicLink()) throw new Error(`skill symlink is forbidden: ${target}`); if (entry.isDirectory()) walk(target); else if (entry.isFile()) actual.push(path.relative(root, target).split(path.sep).join('/')); else throw new Error(`skill entry is not regular: ${target}`); } } walk(root); assertEqual(actual.sort(), expected, 'skill exact file allowlist'); const skill = fs.readFileSync(path.join(root, 'SKILL.md'), 'utf8'); if (!skill.startsWith('---\nname: sandwich-hime\ndescription: ') || !skill.includes('\n---\n')) throw new Error('SKILL.md frontmatter invalid'); if ((skill.match(/^---$/gm) || []).length !== 2) throw new Error('SKILL.md frontmatter delimiters invalid'); if (skill.split('\n').length > 500) throw new Error('SKILL.md exceeds 500 lines'); for (const marker of ['himesan version --json', 'himesan check --json', 'Never hand-edit generated files', 'never execute `himesan dev`', '`.san` exclusively']) { if (!skill.toLowerCase().includes(marker.toLowerCase())) throw new Error(`skill safety marker missing: ${marker}`); } const metadata = fs.readFileSync(path.join(root, 'agents', 'openai.yaml'), 'utf8'); for (const marker of ['display_name: "Sandwich Hime"', '$sandwich-hime']) if (!metadata.includes(marker)) throw new Error(`agent metadata marker missing: ${marker}`); console.log('portable skill exact-tree and safety contract verified'); function assertEqual(left, right, label) { if (JSON.stringify(left) !== JSON.stringify(right)) throw new Error(`${label}: ${JSON.stringify(left)} != ${JSON.stringify(right)}`); }