Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions packages/core/src/extension/claude-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,15 +387,15 @@ export async function convertClaudePluginPackage(
const strict = marketplacePlugin.strict ?? false;
let mergedConfig: ClaudePluginConfig;

if (strict) {
const pluginJsonPath = path.join(
pluginSource,
'.claude-plugin',
'plugin.json',
);
if (!fs.existsSync(pluginJsonPath)) {
throw new Error(`Strict mode requires plugin.json at ${pluginJsonPath}`);
}
const pluginJsonPath = path.join(
pluginSource,
'.claude-plugin',
'plugin.json',
);
if (strict && !fs.existsSync(pluginJsonPath)) {
throw new Error(`Strict mode requires plugin.json at ${pluginJsonPath}`);
}
if (fs.existsSync(pluginJsonPath)) {
const pluginContent = fs.readFileSync(pluginJsonPath, 'utf-8');
const pluginConfig: ClaudePluginConfig = JSON.parse(pluginContent);
mergedConfig = mergeClaudeConfigs(marketplacePlugin, pluginConfig);
Expand Down Expand Up @@ -552,6 +552,18 @@ async function collectResources(
const srcFile = path.join(resolvedPath, file);
const destFile = path.join(finalDestDir, file);

// Check if the source is a regular file (skip sockets, FIFOs, directories behind symlinks, etc.)
try {
const fileStat = fs.statSync(srcFile);
if (!fileStat.isFile()) {
debugLogger.debug(`Skipping non-regular file: ${srcFile}`);
continue;
}
} catch {
debugLogger.debug(`Failed to stat file, skipping: ${srcFile}`);
continue;
}

// Ensure parent directory exists
const destFileDir = path.dirname(destFile);
if (!fs.existsSync(destFileDir)) {
Expand Down
16 changes: 15 additions & 1 deletion packages/core/src/extension/extensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1238,7 +1238,21 @@ export async function copyExtension(
source: string,
destination: string,
): Promise<void> {
await fs.promises.cp(source, destination, { recursive: true });
await fs.promises.cp(source, destination, {
recursive: true,
dereference: true,
filter: async (src: string) => {
try {
const stats = await fs.promises.stat(src);
// Only copy regular files and directories
// Skip sockets, FIFOs, block devices, and character devices
return stats.isFile() || stats.isDirectory();
} catch {
// If we can't stat the file, skip it
return false;
}
},
});
}

export function getExtensionId(
Expand Down
17 changes: 16 additions & 1 deletion packages/core/src/extension/gemini-converter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,9 +130,24 @@ export async function copyDirectory(

if (entry.isDirectory()) {
await copyDirectory(sourcePath, destPath);
} else {
} else if (entry.isSymbolicLink()) {
// Resolve symlink and copy the target content
try {
const realPath = fs.realpathSync(sourcePath);
const targetStat = fs.statSync(realPath);
if (targetStat.isDirectory()) {
await copyDirectory(realPath, destPath);
} else if (targetStat.isFile()) {
fs.copyFileSync(realPath, destPath);
}
// Skip sockets, FIFOs, etc.
} catch {
// Skip broken symlinks
}
} else if (entry.isFile()) {
fs.copyFileSync(sourcePath, destPath);
}
// Skip sockets, FIFOs, block devices, and character devices
}
}

Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/extension/github.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ describe('git extension helpers', () => {
await cloneFromGit(installMetadata, destination);

expect(mockGit.clone).toHaveBeenCalledWith('http://my-repo.com', './', [
'-c',
'core.symlinks=true',
'--depth',
'1',
]);
Expand Down
7 changes: 6 additions & 1 deletion packages/core/src/extension/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,12 @@ export async function cloneFromGit(
// We let git handle the source as is.
}
}
await git.clone(sourceUrl, './', ['--depth', '1']);
await git.clone(sourceUrl, './', [
'-c',
'core.symlinks=true',
'--depth',
'1',
]);

const remotes = await git.getRemotes(true);
if (remotes.length === 0) {
Expand Down