Skip to content
8 changes: 6 additions & 2 deletions build/darwin/create-universal-app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ async function main(buildDir?: string) {
'**/node_modules/@github/copilot-darwin-arm64/**',
'**/node_modules.asar.unpacked/@github/copilot-darwin-x64/**',
'**/node_modules.asar.unpacked/@github/copilot-darwin-arm64/**',
'**/node_modules/@github/copilot-sdk-darwin-x64/**',
'**/node_modules/@github/copilot-sdk-darwin-arm64/**',
'**/node_modules.asar.unpacked/@github/copilot-sdk-darwin-x64/**',
'**/node_modules.asar.unpacked/@github/copilot-sdk-darwin-arm64/**',
'**/node_modules/@vscode/os-proxy-resolver-darwin-x64/**',
'**/node_modules/@vscode/os-proxy-resolver-darwin-arm64/**',
'**/node_modules.asar.unpacked/@vscode/os-proxy-resolver-darwin-x64/**',
Expand Down Expand Up @@ -139,8 +143,8 @@ async function main(buildDir?: string) {
// them as arch-unique. Paths here are ASAR-internal (top level, no `node_modules`
// prefix). Over-covering is harmless: the allowlist is only consulted for files
// that are actually unique to one arch.
singleArchFiles: '{**/@github/copilot-darwin-*,**/@github/copilot-darwin-*/**,**/@github/copilot/prebuilds/darwin-*,**/@github/copilot/prebuilds/darwin-*/**,**/@github/copilot/tgrep/bin/darwin-*,**/@github/copilot/tgrep/bin/darwin-*/**,**/@github/copilot/sdk/tgrep/bin/darwin-*,**/@github/copilot/sdk/tgrep/bin/darwin-*/**,**/@github/copilot/sdk/prebuilds/darwin-*,**/@github/copilot/sdk/prebuilds/darwin-*/**,**/@github/copilot/sdk/ripgrep/bin/darwin-*,**/@github/copilot/sdk/ripgrep/bin/darwin-*/**,**/@vscode/ripgrep-universal/bin/darwin-*,**/@vscode/ripgrep-universal/bin/darwin-*/**,**/@vscode/os-proxy-resolver-darwin-*,**/@vscode/os-proxy-resolver-darwin-*/**,**/@microsoft/mxc-sdk/bin/*,**/@microsoft/mxc-sdk/bin/*/**}',
x64ArchFiles: '{*/kerberos.node,**/extensions/microsoft-authentication/dist/libmsalruntime.dylib,**/extensions/microsoft-authentication/dist/msal-node-runtime.node,**/node_modules/@github/copilot-darwin-*/**,**/node_modules/@github/copilot/prebuilds/darwin-*/*,**/node_modules/@github/copilot/tgrep/bin/darwin-*/*,**/node_modules/@github/copilot/sdk/tgrep/bin/darwin-*/*,**/node_modules.asar.unpacked/@github/copilot-darwin-*/**,**/node_modules.asar.unpacked/@github/copilot/prebuilds/darwin-*/*,**/node_modules.asar.unpacked/@github/copilot/tgrep/bin/darwin-*/*,**/node_modules.asar.unpacked/@github/copilot/sdk/tgrep/bin/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/sdk/prebuilds/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/sdk/ripgrep/bin/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/sdk/tgrep/bin/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/tgrep/bin/darwin-*/*,**/node_modules/@vscode/ripgrep-universal/bin/darwin-*/*,**/node_modules.asar.unpacked/@vscode/ripgrep-universal/bin/darwin-*/*,**/node_modules/@vscode/os-proxy-resolver-darwin-*/**,**/node_modules.asar.unpacked/@vscode/os-proxy-resolver-darwin-*/**,**/node_modules/@microsoft/mxc-sdk/bin/**,**/node_modules.asar.unpacked/@microsoft/mxc-sdk/bin/**}',
singleArchFiles: '{**/@github/copilot-darwin-*,**/@github/copilot-darwin-*/**,**/@github/copilot-sdk-darwin-*,**/@github/copilot-sdk-darwin-*/**,**/@github/copilot/prebuilds/darwin-*,**/@github/copilot/prebuilds/darwin-*/**,**/@github/copilot/tgrep/bin/darwin-*,**/@github/copilot/tgrep/bin/darwin-*/**,**/@github/copilot/sdk/tgrep/bin/darwin-*,**/@github/copilot/sdk/tgrep/bin/darwin-*/**,**/@github/copilot/sdk/prebuilds/darwin-*,**/@github/copilot/sdk/prebuilds/darwin-*/**,**/@github/copilot/sdk/ripgrep/bin/darwin-*,**/@github/copilot/sdk/ripgrep/bin/darwin-*/**,**/@vscode/ripgrep-universal/bin/darwin-*,**/@vscode/ripgrep-universal/bin/darwin-*/**,**/@vscode/os-proxy-resolver-darwin-*,**/@vscode/os-proxy-resolver-darwin-*/**,**/@microsoft/mxc-sdk/bin/*,**/@microsoft/mxc-sdk/bin/*/**}',
x64ArchFiles: '{*/kerberos.node,**/extensions/microsoft-authentication/dist/libmsalruntime.dylib,**/extensions/microsoft-authentication/dist/msal-node-runtime.node,**/node_modules/@github/copilot-darwin-*/**,**/node_modules/@github/copilot-sdk-darwin-*/**,**/node_modules/@github/copilot/prebuilds/darwin-*/*,**/node_modules/@github/copilot/tgrep/bin/darwin-*/*,**/node_modules/@github/copilot/sdk/tgrep/bin/darwin-*/*,**/node_modules.asar.unpacked/@github/copilot-darwin-*/**,**/node_modules.asar.unpacked/@github/copilot-sdk-darwin-*/**,**/node_modules.asar.unpacked/@github/copilot/prebuilds/darwin-*/*,**/node_modules.asar.unpacked/@github/copilot/tgrep/bin/darwin-*/*,**/node_modules.asar.unpacked/@github/copilot/sdk/tgrep/bin/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/sdk/prebuilds/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/sdk/ripgrep/bin/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/sdk/tgrep/bin/darwin-*/*,**/extensions/copilot/node_modules/@github/copilot/tgrep/bin/darwin-*/*,**/node_modules/@vscode/ripgrep-universal/bin/darwin-*/*,**/node_modules.asar.unpacked/@vscode/ripgrep-universal/bin/darwin-*/*,**/node_modules/@vscode/os-proxy-resolver-darwin-*/**,**/node_modules.asar.unpacked/@vscode/os-proxy-resolver-darwin-*/**,**/node_modules/@microsoft/mxc-sdk/bin/**,**/node_modules.asar.unpacked/@microsoft/mxc-sdk/bin/**}',
filesToSkipComparison: (file: string) => {
for (const expected of filesToSkip) {
if (minimatch(file, expected)) {
Expand Down
4 changes: 4 additions & 0 deletions build/darwin/verify-macho.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ const FILES_TO_SKIP = [
'**/node_modules/@github/copilot-darwin-arm64/**',
'**/node_modules.asar.unpacked/@github/copilot-darwin-x64/**',
'**/node_modules.asar.unpacked/@github/copilot-darwin-arm64/**',
'**/node_modules/@github/copilot-sdk-darwin-x64/**',
'**/node_modules/@github/copilot-sdk-darwin-arm64/**',
'**/node_modules.asar.unpacked/@github/copilot-sdk-darwin-x64/**',
'**/node_modules.asar.unpacked/@github/copilot-sdk-darwin-arm64/**',
// Copilot prebuilds: single-arch binaries in per-platform directories
'**/node_modules/@github/copilot/prebuilds/darwin-*/**',
'**/node_modules.asar.unpacked/@github/copilot/prebuilds/darwin-*/**',
Expand Down
11 changes: 4 additions & 7 deletions build/gulpfile.vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,11 @@ function packageTask(platform: string, arch: string, sourceFolderName: string, d
.pipe(createAsar(path.join(process.cwd(), 'node_modules'), [
'**/*.node',
'**/@vscode/ripgrep-universal/bin/**',
// Only the platform-specific Copilot CLI packages (`@github/copilot-<os>-<arch>`)
// need to be unpacked: the CLI is spawned as a subprocess and is a
// self-locating bundle that memory-maps files and resolves its native
// addons / sub-binaries relative to its own on-disk location, so it cannot
// run from inside the archive. `@github/copilot-sdk` is intentionally NOT
// matched here — it is pure JavaScript that the agent host loads via
// `import` (ASAR-aware), so it stays in the archive.
// The platform-specific Copilot CLI and SDK runtime packages must be
// unpacked because they contain spawned executables and native modules.
// The pure JavaScript `@github/copilot-sdk` package stays in the archive.
'**/@github/copilot-{darwin,linux,linuxmusl,win32}-*/**',
'**/@github/copilot-sdk-{darwin,linux,linuxmusl,win32}-*/**',
// The Dev Container CLI is spawned as an external Node process,
// so its bundled entrypoint must be available outside the ASAR.
'**/@devcontainers/cli/**',
Expand Down
50 changes: 22 additions & 28 deletions build/lib/copilot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,14 @@ import { ensureNpmPackage, materializeNpmPackageVersion, type EnsureNpmPackageOp
/**
* Options for {@link prepareBuiltInCopilotRipgrepShim}. Extends the npm packing
* options with an override for the extension lockfile used to verify natives
* fetched for the pinned version (defaults to the repo's copy; overridable in
* tests).
* fetched for the pinned version.
*/
export interface PrepareBuiltInCopilotOptions extends EnsureNpmPackageOptions {
extensionLockfilePath?: string;
}

/**
* The platforms that @github/copilot ships platform-specific packages for.
* These are the `@github/copilot-{platform}` optional dependency packages.
* The platforms that Copilot ships platform-specific packages for.
*/
export const copilotPlatforms = [
'darwin-arm64', 'darwin-x64',
Expand Down Expand Up @@ -170,7 +168,7 @@ export function getCopilotTgrepExcludeFilter(platform: string, arch: string): st
}

/**
* Returns a glob filter that strips @github/copilot platform packages
* Returns a glob filter that strips Copilot platform packages
* for architectures other than the build target.
*
* Alpine uses the linuxmusl-* packages. Other platform package names follow
Expand All @@ -182,55 +180,51 @@ export function getCopilotExcludeFilter(platform: string, arch: string): string[
const targetPlatformArch = toCopilotPackagePlatformArch(platform, arch);
const nonTargetPlatforms = copilotPlatforms.filter(p => p !== targetPlatformArch);

// Strip wrong-architecture @github/copilot-{platform} packages.
const excludes = nonTargetPlatforms.map(p => `!**/node_modules/@github/copilot-${p}/**`);
const excludes = nonTargetPlatforms.flatMap(p => [
`!**/node_modules/@github/copilot-${p}/**`,
`!**/node_modules/@github/copilot-sdk-${p}/**`,
]);

return [
'**',
...excludes,
'!**/node_modules/@github/copilot-*/copilot',
'!**/node_modules/@github/copilot-*/copilot.exe',
...copilotOutOfProcessRuntimeExecutables.map(executable => `!**/node_modules/@github/copilot-*/prebuilds/*/${executable}`),
];
}

/**
* Returns the public @github/copilot package files that must survive
* Returns the paired Copilot CLI and SDK platform files that must survive
* app/remote packaging for the target platform.
*
* .moduleignore strips all @github/copilot-* platform packages globally.
* Re-add the selected runtime package so Agent Host can launch its index.js
* entrypoint and load runtime prebuilds, including cli-native.node on every
* platform. Keep the standalone SEA executable and optional native payload
* trees out of the product build.
* .moduleignore strips all Copilot platform packages globally. Re-add the
* selected CLI executable and SDK package while keeping optional native
* payloads out of the product build.
*/
export function getCopilotRuntimePrebuildFiles(platform: string, arch: string, nodeModulesRoot = 'node_modules'): string[] {
const copilotPackagePlatformArch = toCopilotPackagePlatformArch(platform, arch);
const copilotPlatformPackageDir = path.posix.join(nodeModulesRoot, '@github', `copilot-${copilotPackagePlatformArch}`);
const copilotCliPackageDir = path.posix.join(nodeModulesRoot, '@github', `copilot-${copilotPackagePlatformArch}`);
const copilotSdkPackageDir = path.posix.join(nodeModulesRoot, '@github', `copilot-sdk-${copilotPackagePlatformArch}`);

return [
path.posix.join(copilotPlatformPackageDir, '**'),
`!${path.posix.join(copilotPlatformPackageDir, 'copilot')}`,
`!${path.posix.join(copilotPlatformPackageDir, 'copilot.exe')}`,
...copilotOutOfProcessRuntimeExecutables.map(executable => `!${path.posix.join(copilotPlatformPackageDir, 'prebuilds', '*', executable)}`),
...copilotOptionalNativePayloadDirs.map(dir => `!${path.posix.join(copilotPlatformPackageDir, dir, '**')}`),
...copilotOptionalNativePayloadFiles.map(file => `!${path.posix.join(copilotPlatformPackageDir, file)}`),
path.posix.join(copilotCliPackageDir, platform === 'win32' ? 'copilot.exe' : 'copilot'),
path.posix.join(copilotSdkPackageDir, '**'),
...copilotOptionalNativePayloadDirs.map(dir => `!${path.posix.join(copilotSdkPackageDir, dir, '**')}`),
...copilotOptionalNativePayloadFiles.map(file => `!${path.posix.join(copilotSdkPackageDir, file)}`),
];
}

/**
* Ensures the selected @github/copilot-{platform} package is present before
* packaging. npm only installs the host-compatible optional dependency, but
* VS Code packaging can cross-build targets such as darwin-x64 on arm64 hosts.
* Ensures the selected CLI and SDK platform packages are present before
* packaging. npm only installs host-compatible optional dependencies, but VS
* Code packaging can cross-build targets such as darwin-x64 on arm64 hosts.
*/
export function ensureCopilotPlatformPackage(platform: string, arch: string, nodeModulesRoot = 'node_modules', options: EnsureNpmPackageOptions = {}): void {
const copilotPackagePlatformArch = toCopilotPackagePlatformArch(platform, arch);
if (!copilotPlatforms.includes(copilotPackagePlatformArch)) {
return;
}

const packageName = `@github/copilot-${copilotPackagePlatformArch}`;
ensureNpmPackage(packageName, nodeModulesRoot, options);
ensureNpmPackage(`@github/copilot-${copilotPackagePlatformArch}`, nodeModulesRoot, options);
ensureNpmPackage(`@github/copilot-sdk-${copilotPackagePlatformArch}`, nodeModulesRoot, options);
}

/**
Expand Down
Loading
Loading