MCPcopy Create free account
hub / github.com/dyoshikawa/rulesync / writeSkillAndComputeIntegrity

Function writeSkillAndComputeIntegrity

src/lib/sources.ts:341–375  ·  view source on GitHub ↗

* Write skill files to disk, compute integrity, and check against the lockfile. * Returns the computed LockedSkill entry.

(params: {
  skillName: string;
  files: Array<{ relativePath: string; content: string }>;
  curatedDir: string;
  locked: LockedSource | undefined;
  resolvedSha: string;
  sourceKey: string;
  logger: Logger;
})

Source from the content-addressed store, hash-verified

339 * Returns the computed LockedSkill entry.
340 */
341async function writeSkillAndComputeIntegrity(params: {
342 skillName: string;
343 files: Array<{ relativePath: string; content: string }>;
344 curatedDir: string;
345 locked: LockedSource | undefined;
346 resolvedSha: string;
347 sourceKey: string;
348 logger: Logger;
349}): Promise<LockedSkill> {
350 const { skillName, files, curatedDir, locked, resolvedSha, sourceKey, logger } = params;
351 const written: Array<{ path: string; content: string }> = [];
352
353 for (const file of files) {
354 checkPathTraversal({
355 relativePath: file.relativePath,
356 intendedRootDir: join(curatedDir, skillName),
357 });
358 await writeFileContent(join(curatedDir, skillName, file.relativePath), file.content);
359 written.push({ path: file.relativePath, content: file.content });
360 }
361
362 const integrity = computeSkillIntegrity(written);
363 const lockedSkillEntry = locked?.skills[skillName];
364 if (
365 lockedSkillEntry?.integrity &&
366 lockedSkillEntry.integrity !== integrity &&
367 resolvedSha === locked?.resolvedRef
368 ) {
369 logger.warn(
370 `Integrity mismatch for skill "${skillName}" from ${sourceKey}: expected "${lockedSkillEntry.integrity}", got "${integrity}". Content may have been tampered with.`,
371 );
372 }
373
374 return { integrity };
375}
376
377/**
378 * Merge newly fetched skills with existing locked skills and update the lockfile.

Callers 3

fetchGithubSkillDirFunction · 0.85
fetchSourceViaGitFunction · 0.85

Calls 4

checkPathTraversalFunction · 0.85
writeFileContentFunction · 0.85
computeSkillIntegrityFunction · 0.85
warnMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…