Repository navigation
Expand file tree
/
Copy pathpackageSkillZip.js
More file actions
83 lines (69 loc) · 2.08 KB
/
Copy pathpackageSkillZip.js
File metadata and controls
83 lines (69 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const fs = require("fs");
const path = require("path");
const { execFileSync } = require("child_process");
const { validateSkillStructure } = require("./validateSkillStructure");
const SIZE_LIMIT = 15728640; // 15 MB in bytes
async function packageSkillZip(skillDir, outputDir = null) {
try {
// Validate skill structure first (skip package noise check since we exclude those in zip)
validateSkillStructure(skillDir, {
checkPlaceholders: false,
checkPackageNoise: false,
});
const resolvedDir = path.resolve(skillDir);
const resolvedOutDir = outputDir
? path.resolve(outputDir)
: path.resolve(".");
// Ensure output directory exists
if (!fs.existsSync(resolvedOutDir)) {
fs.mkdirSync(resolvedOutDir, { recursive: true });
}
const outputFile = path.join(resolvedOutDir, "skill.zip");
// Remove existing file if it exists
if (fs.existsSync(outputFile)) {
fs.unlinkSync(outputFile);
}
const parentDir = path.dirname(resolvedDir);
const folderName = path.basename(resolvedDir);
// Build zip arguments array (safe from command injection)
const zipArgs = [
"-qr",
outputFile,
folderName,
"-x",
"*/__MACOSX/*",
"-x",
"*/.DS_Store",
"-x",
"*/__pycache__/*",
"-x",
"*.pyc",
"-x",
"*/node_modules/*",
"-x",
`${folderName}/evals/*`,
"-x",
"*/Icon",
"-x",
"*/Icon?",
];
// Execute zip command from parent directory (no shell expansion)
execFileSync("zip", zipArgs, {
cwd: parentDir,
stdio: "pipe",
});
// Get file size
const stats = fs.statSync(outputFile);
const bytes = stats.size;
if (bytes > SIZE_LIMIT) {
console.warn(`WARNING: skill.zip exceeds 15 MB (${bytes} bytes)`);
}
console.log(`OK: packaged ${outputFile} (${bytes} bytes)`);
return { success: true, path: outputFile, bytes };
} catch (error) {
throw new Error(`Failed to create zip file: ${error.message}`, {
cause: error,
});
}
}
module.exports = { packageSkillZip };