JuliusBrussee/caveman · error

SKILL.md must be valid UTF-8

Error message

SKILL.md must be valid UTF-8

What it means

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.

Solutions

  1. Convert the file to UTF-8 (iconv -f WINDOWS-1252 -t UTF-8 SKILL.md) and re-import.
  2. Re-export/save the SKILL.md with 'UTF-8' encoding selected in the editor.
  3. Check validity with `iconv -f UTF-8 SKILL.md > /dev/null` before importing.

Example fix

// before (Windows-1252 file with smart quotes)
Error: SKILL.md must be valid UTF-8

// after
$ iconv -f WINDOWS-1252 -t UTF-8 SKILL.md > SKILL.md && cave skill import ./skill-dir
Defensive patterns

Strategy: validation

Validate before calling

const bytes = readFileSync('SKILL.md');
const text = bytes.toString('utf8');
if (!Buffer.from(text, 'utf8').equals(bytes)) throw new Error('not valid UTF-8: run iconv -t UTF-8');

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid ... format", "must be in format X", "does not look like a ..." — invalid argument format errors across CLI tools and libraries — this error's family across 17 libraries.

Related errors


AI-assisted analysis of JuliusBrussee/caveman@3ee70a1026 (2026-09-20). Data as JSON: /api/errors/f876415e801786fa. Report an issue: GitHub.

Appendix: source

Thrown at packages/cli/src/index.ts:1588

};

function importedSkillSource(input: string): { root: string; file: string } {
	let resolved: string;
	try { resolved = realpathSync(resolve(process.cwd(), expandTilde(input))); } catch {
		throw new Error(`source does not exist: ${input}`);
	}
	const stat = lstatSync(resolved);
	const file = stat.isDirectory() ? join(resolved, SKILL_MD) : resolved;
	if (!stat.isDirectory() && basename(resolved) !== SKILL_MD) throw new Error("source file must be named SKILL.md");
	if (!hasFile(file)) throw new Error(`SKILL.md missing under ${resolved}`);
	return { root: stat.isDirectory() ? resolved : dirname(resolved), file };
}

function cavemannifyImportedSkill(bytes: Buffer): { body: string; removedDuplicates: number; removedSeparators: number } {
	if (bytes.length === 0 || bytes.length > 256 * 1024) throw new Error("SKILL.md must be 1..262144 bytes");
	if (bytes.includes(0)) throw new Error("SKILL.md contains NUL bytes");
	const text = bytes.toString("utf8");
	if (!Buffer.from(text, "utf8").equals(bytes)) throw new Error("SKILL.md must be valid UTF-8");
	if (/-----BEGIN [A-Z ]*PRIVATE KEY-----|\b(?:sk|ghp|github_pat|xox[baprs])[-_][A-Za-z0-9_-]{16,}/i.test(text)) {
		throw new Error("SKILL.md contains credential-shaped material");
	}
	const split = splitSkillMarkdown(bytes);
	if (!split) throw new Error("SKILL.md needs closed YAML frontmatter");
	const blocks = split.bodyText.trim().split(/\r?\n(?:[ \t]*\r?\n)+/);
	const seen = new Set<string>();
	const kept: string[] = [];
	let removedDuplicates = 0;
	let removedSeparators = 0;
	for (const block of blocks) {
		const clean = block.trim();
		if (/^(?:---+|\*\*\*+|___+)$/.test(clean)) {
			removedSeparators++;
			continue;
		}
		const identity = clean.replace(/\s+/g, " ");
		if (seen.has(identity)) {

View on GitHub (pinned to 3ee70a1026)