agent-resource-management 2.1.2 → 2.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.js +24 -4
- package/package.json +1 -1
- package/src/cmd/skill.ts +31 -4
package/dist/main.js
CHANGED
|
@@ -956,13 +956,33 @@ async function downloadSkill(name, outputDir) {
|
|
|
956
956
|
info(`正在下载 ${name}...`);
|
|
957
957
|
}
|
|
958
958
|
const buffer = await client.downloadSkill(name);
|
|
959
|
-
const
|
|
960
|
-
|
|
959
|
+
const tempDir = mkdtempSync2("/tmp/skill-download-");
|
|
960
|
+
const zipPath = join3(tempDir, `${name}.zip`);
|
|
961
|
+
writeFileSync2(zipPath, Buffer.from(buffer));
|
|
962
|
+
execSync2(`unzip -q "${zipPath}" -d "${tempDir}"`, { stdio: "pipe" });
|
|
963
|
+
const targetDir = join3(outputDir || ".", name);
|
|
964
|
+
execSync2(`mkdir -p "${targetDir}"`, { stdio: "pipe" });
|
|
965
|
+
const entries = execSync2(`ls -1 "${tempDir}"`, { encoding: "utf-8" }).split(`
|
|
966
|
+
`).filter((e) => e.trim());
|
|
967
|
+
const nonZipEntries = entries.filter((e) => e !== `${name}.zip`);
|
|
968
|
+
if (nonZipEntries.length === 1) {
|
|
969
|
+
const onlyEntry = join3(tempDir, nonZipEntries[0]);
|
|
970
|
+
if (statSync3(onlyEntry).isDirectory()) {
|
|
971
|
+
execSync2(`cp -r "${onlyEntry}"/* "${targetDir}/"`, { stdio: "pipe" });
|
|
972
|
+
} else {
|
|
973
|
+
execSync2(`cp -r "${onlyEntry}" "${targetDir}/"`, { stdio: "pipe" });
|
|
974
|
+
}
|
|
975
|
+
} else {
|
|
976
|
+
for (const entry of nonZipEntries) {
|
|
977
|
+
execSync2(`cp -r "${join3(tempDir, entry)}" "${targetDir}/"`, { stdio: "pipe" });
|
|
978
|
+
}
|
|
979
|
+
}
|
|
980
|
+
rmSync2(tempDir, { recursive: true, force: true });
|
|
961
981
|
if (shouldOutputJson()) {
|
|
962
|
-
outputJson({ success: true, data: { path:
|
|
982
|
+
outputJson({ success: true, data: { path: targetDir } });
|
|
963
983
|
return;
|
|
964
984
|
}
|
|
965
|
-
success(`已下载到 ${
|
|
985
|
+
success(`已下载到 ${targetDir}`);
|
|
966
986
|
} catch (err) {
|
|
967
987
|
if (shouldOutputJson()) {
|
|
968
988
|
outputJson({ success: false, error: { code: "DOWNLOAD_FAILED", message: err instanceof Error ? err.message : "未知错误" } });
|
package/package.json
CHANGED
package/src/cmd/skill.ts
CHANGED
|
@@ -130,13 +130,40 @@ export async function downloadSkill(name: string, outputDir?: string): Promise<v
|
|
|
130
130
|
info(`正在下载 ${name}...`);
|
|
131
131
|
}
|
|
132
132
|
const buffer = await client.downloadSkill(name);
|
|
133
|
-
|
|
134
|
-
|
|
133
|
+
|
|
134
|
+
const tempDir = mkdtempSync('/tmp/skill-download-');
|
|
135
|
+
const zipPath = join(tempDir, `${name}.zip`);
|
|
136
|
+
writeFileSync(zipPath, Buffer.from(buffer));
|
|
137
|
+
|
|
138
|
+
execSync(`unzip -q "${zipPath}" -d "${tempDir}"`, { stdio: 'pipe' });
|
|
139
|
+
|
|
140
|
+
const targetDir = join(outputDir || '.', name);
|
|
141
|
+
execSync(`mkdir -p "${targetDir}"`, { stdio: 'pipe' });
|
|
142
|
+
|
|
143
|
+
const entries = execSync(`ls -1 "${tempDir}"`, { encoding: 'utf-8' }).split('\n').filter(e => e.trim());
|
|
144
|
+
|
|
145
|
+
const nonZipEntries = entries.filter(e => e !== `${name}.zip`);
|
|
146
|
+
|
|
147
|
+
if (nonZipEntries.length === 1) {
|
|
148
|
+
const onlyEntry = join(tempDir, nonZipEntries[0]);
|
|
149
|
+
if (statSync(onlyEntry).isDirectory()) {
|
|
150
|
+
execSync(`cp -r "${onlyEntry}"/* "${targetDir}/"`, { stdio: 'pipe' });
|
|
151
|
+
} else {
|
|
152
|
+
execSync(`cp -r "${onlyEntry}" "${targetDir}/"`, { stdio: 'pipe' });
|
|
153
|
+
}
|
|
154
|
+
} else {
|
|
155
|
+
for (const entry of nonZipEntries) {
|
|
156
|
+
execSync(`cp -r "${join(tempDir, entry)}" "${targetDir}/"`, { stdio: 'pipe' });
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
rmSync(tempDir, { recursive: true, force: true });
|
|
161
|
+
|
|
135
162
|
if (shouldOutputJson()) {
|
|
136
|
-
outputJson({ success: true, data: { path:
|
|
163
|
+
outputJson({ success: true, data: { path: targetDir } });
|
|
137
164
|
return;
|
|
138
165
|
}
|
|
139
|
-
success(`已下载到 ${
|
|
166
|
+
success(`已下载到 ${targetDir}`);
|
|
140
167
|
} catch (err) {
|
|
141
168
|
if (shouldOutputJson()) {
|
|
142
169
|
outputJson({ success: false, error: { code: 'DOWNLOAD_FAILED', message: err instanceof Error ? err.message : '未知错误' } });
|