Skip to content
Merged
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
29 changes: 26 additions & 3 deletions apps/code/vite.main.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,19 @@ function fixFilenameCircularRef(): Plugin {
};
}

let claudeCliCopied = false;

function copyClaudeExecutable(): Plugin {
return {
name: "copy-claude-executable",
writeBundle() {
const destDir = join(__dirname, ".vite/build/claude-cli");

// Skip re-copying on subsequent HMR rebuilds
if (claudeCliCopied && existsSync(join(destDir, "cli.js"))) {
return;
}

if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true });
}
Expand Down Expand Up @@ -96,6 +103,7 @@ function copyClaudeExecutable(): Plugin {
if (existsSync(vendorDir)) {
cpSync(vendorDir, join(destDir, "vendor"), { recursive: true });
}
claudeCliCopied = true;
return;
}
}
Expand All @@ -121,6 +129,7 @@ function copyClaudeExecutable(): Plugin {
console.log(
"Assembled Claude CLI from workspace sources in claude-cli/ subdirectory",
);
claudeCliCopied = true;
return;
}

Expand Down Expand Up @@ -326,6 +335,8 @@ const PLUGIN_ALLOW_LIST = [
"hooks",
];

let remoteSkillsFetched = false;

function copyPosthogPlugin(isDev: boolean): Plugin {
const sourceDir = join(__dirname, "../../plugins/posthog");
const localSkillsDir = join(sourceDir, "local-skills");
Expand Down Expand Up @@ -366,10 +377,14 @@ function copyPosthogPlugin(isDev: boolean): Plugin {
}

// 2. Download and overlay remote skills (overrides same-named shipped skills)
await downloadAndExtractSkills(destSkillsDir);
// Skip re-downloading on subsequent HMR rebuilds
if (!remoteSkillsFetched) {
await downloadAndExtractSkills(destSkillsDir);

// 2b. Download and overlay context-mill omnibus skills (overrides same-named skills)
await downloadAndExtractContextMillSkills(destSkillsDir);
// 2b. Download and overlay context-mill omnibus skills (overrides same-named skills)
await downloadAndExtractContextMillSkills(destSkillsDir);
remoteSkillsFetched = true;
}

// 3. In dev mode: overlay local-skills (overrides both shipped and remote)
if (isDev && existsSync(localSkillsDir)) {
Expand Down Expand Up @@ -409,12 +424,19 @@ function copyDrizzleMigrations(): Plugin {
};
}

let codexAcpCopied = false;

function copyCodexAcpBinaries(): Plugin {
return {
name: "copy-codex-acp-binaries",
writeBundle() {
const destDir = join(__dirname, ".vite/build/codex-acp");

// Skip re-copying on subsequent HMR rebuilds
if (codexAcpCopied && existsSync(destDir)) {
return;
}

if (!existsSync(destDir)) {
mkdirSync(destDir, { recursive: true });
}
Expand Down Expand Up @@ -452,6 +474,7 @@ function copyCodexAcpBinaries(): Plugin {
);
}
}
codexAcpCopied = true;
},
};
}
Expand Down
Loading