{"record":{"id":"f876415e801786fa","repo":"JuliusBrussee/caveman","slug":"skill-md-must-be-valid-utf-8","errorCode":null,"errorMessage":"SKILL.md must be valid UTF-8","messagePattern":"SKILL\\.md must be valid UTF-8","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/cli/src/index.ts","lineNumber":1588,"sourceCode":"};\n\nfunction importedSkillSource(input: string): { root: string; file: string } {\n\tlet resolved: string;\n\ttry { resolved = realpathSync(resolve(process.cwd(), expandTilde(input))); } catch {\n\t\tthrow new Error(`source does not exist: ${input}`);\n\t}\n\tconst stat = lstatSync(resolved);\n\tconst file = stat.isDirectory() ? join(resolved, SKILL_MD) : resolved;\n\tif (!stat.isDirectory() && basename(resolved) !== SKILL_MD) throw new Error(\"source file must be named SKILL.md\");\n\tif (!hasFile(file)) throw new Error(`SKILL.md missing under ${resolved}`);\n\treturn { root: stat.isDirectory() ? resolved : dirname(resolved), file };\n}\n\nfunction cavemannifyImportedSkill(bytes: Buffer): { body: string; removedDuplicates: number; removedSeparators: number } {\n\tif (bytes.length === 0 || bytes.length > 256 * 1024) throw new Error(\"SKILL.md must be 1..262144 bytes\");\n\tif (bytes.includes(0)) throw new Error(\"SKILL.md contains NUL bytes\");\n\tconst text = bytes.toString(\"utf8\");\n\tif (!Buffer.from(text, \"utf8\").equals(bytes)) throw new Error(\"SKILL.md must be valid UTF-8\");\n\tif (/-----BEGIN [A-Z ]*PRIVATE KEY-----|\\b(?:sk|ghp|github_pat|xox[baprs])[-_][A-Za-z0-9_-]{16,}/i.test(text)) {\n\t\tthrow new Error(\"SKILL.md contains credential-shaped material\");\n\t}\n\tconst split = splitSkillMarkdown(bytes);\n\tif (!split) throw new Error(\"SKILL.md needs closed YAML frontmatter\");\n\tconst blocks = split.bodyText.trim().split(/\\r?\\n(?:[ \\t]*\\r?\\n)+/);\n\tconst seen = new Set<string>();\n\tconst kept: string[] = [];\n\tlet removedDuplicates = 0;\n\tlet removedSeparators = 0;\n\tfor (const block of blocks) {\n\t\tconst clean = block.trim();\n\t\tif (/^(?:---+|\\*\\*\\*+|___+)$/.test(clean)) {\n\t\t\tremovedSeparators++;\n\t\t\tcontinue;\n\t\t}\n\t\tconst identity = clean.replace(/\\s+/g, \" \");\n\t\tif (seen.has(identity)) {","sourceCodeStart":1570,"sourceCodeEnd":1606,"githubUrl":"https://github.com/JuliusBrussee/caveman/blob/3ee70a102609e550bd2e68004bf5990a9341c851/packages/cli/src/index.ts#L1570-L1606","documentation":"After stripping NUL checks, cavemannifyImportedSkill decodes the bytes as UTF-8 and re-encodes them, requiring a byte-identical round trip. If re-encoding differs, the file is not valid UTF-8 (invalid sequences, lone surrogates) and the import is rejected.","triggerScenarios":"Importing a SKILL.md encoded in Latin-1/Windows-1252/Shift-JIS or containing truncated multi-byte UTF-8 sequences, so bytes.toString('utf8') lossily replaces invalid bytes and the round-trip comparison fails.","commonSituations":"Skills authored on Windows with a non-UTF-8 default encoding; files transferred through systems that mangled byte sequences; partial downloads cutting a multi-byte character in half.","solutions":["Convert the file to UTF-8 (iconv -f WINDOWS-1252 -t UTF-8 SKILL.md) and re-import.","Re-export/save the SKILL.md with 'UTF-8' encoding selected in the editor.","Check validity with `iconv -f UTF-8 SKILL.md > /dev/null` before importing."],"exampleFix":"// before (Windows-1252 file with smart quotes)\nError: SKILL.md must be valid UTF-8\n\n// after\n$ iconv -f WINDOWS-1252 -t UTF-8 SKILL.md > SKILL.md && cave skill import ./skill-dir","handlingStrategy":"validation","validationCode":"const bytes = readFileSync('SKILL.md');\nconst text = bytes.toString('utf8');\nif (!Buffer.from(text, 'utf8').equals(bytes)) throw new Error('not valid UTF-8: run iconv -t UTF-8');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Configure editors (VS Code: 'files.encoding': 'utf8') to save UTF-8 by default","Run `iconv -f UTF-8 SKILL.md > /dev/null` as a pre-import lint step","Avoid transferring skill files through channels that re-encode (some mailers/chat apps)"],"tags":["validation","encoding","utf-8"],"backgroundTag":"invalid-argument-format","analyzedSha":"3ee70a102609e550bd2e68004bf5990a9341c851","analyzedAt":"2026-09-20T15:53:39.229Z","contentChangedAt":"2026-09-20T15:53:39.229Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}