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
64 changes: 32 additions & 32 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"author": "",
"license": "MIT",
"dependencies": {
"@github/copilot-sdk": "^0.1.32",
"@github/copilot-sdk": "^0.2.0",
"@inquirer/prompts": "^8.2.1",
"@octokit/rest": "^22.0.1",
"chalk": "^5.6.2",
Expand Down
25 changes: 13 additions & 12 deletions tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,33 +4,34 @@ import { defineConfig } from "tsup";
import type { Plugin } from "esbuild";

/**
* Shim the SDK's getBundledCliPath() which calls import.meta.resolve().
* In ESM bundles, import.meta.resolve("@github/copilot/sdk") throws at runtime
* because the bare specifier can't be resolved from the bundle's execution
* directory (e.g. stale npx cache). In CJS bundles esbuild additionally
* replaces import.meta with {}. AgentRC always passes an explicit cliPath so
* this function is dead code, but the SDK constructor evaluates it on load.
* Shim the SDK's getBundledCliPath() which calls import.meta.resolve() and
* createRequire(__filename). In ESM bundles the bare specifier can't be
* resolved; in CJS bundles esbuild replaces import.meta with {}. AgentRC
* always passes an explicit cliPath so this function is dead code, but the
* SDK constructor evaluates it as a default value.
*
* Identical to the shim in vscode-extension/esbuild.mjs — update both together
* if the SDK changes getBundledCliPath internals.
*/
const SDK_SHIM_TARGET =
'const sdkUrl = import.meta.resolve("@github/copilot/sdk");\n const sdkPath = fileURLToPath(sdkUrl);\n return join(dirname(dirname(sdkPath)), "index.js");';
const SDK_FN_RE = /function getBundledCliPath\(\) \{[\s\S]*?\n\}/;

const shimSdkImportMeta: Plugin = {
name: "shim-sdk-import-meta",
setup(build) {
build.onLoad({ filter: /copilot-sdk[\\/]dist[\\/]client\.js$/ }, async (args) => {
let contents = await readFile(args.path, "utf8");
if (!contents.includes(SDK_SHIM_TARGET)) {
const original = await readFile(args.path, "utf8");
const contents = original.replace(
SDK_FN_RE,
'function getBundledCliPath() {\n return "bundled-cli-unavailable";\n}'
);
if (contents === original) {
throw new Error(
"[shim-sdk-import-meta] SDK internals changed — getBundledCliPath() " +
"target string not found in " +
"not found in " +
args.path +
". Update the shim in tsup.config.ts and vscode-extension/esbuild.mjs."
);
}
contents = contents.replace(SDK_SHIM_TARGET, 'return "bundled-cli-unavailable";');
return { contents, loader: "js" };
});
}
Expand Down
26 changes: 14 additions & 12 deletions vscode-extension/esbuild.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,34 @@ const watch = process.argv.includes("--watch");

/**
* esbuild plugin: neutralise the SDK's getBundledCliPath() which calls
* import.meta.resolve("@github/copilot/sdk"). In CJS bundles esbuild replaces
* import.meta with {}, making .resolve undefined and crashing at runtime.
* AgentRC always passes an explicit cliPath so this function is dead code, but
* the SDK constructor still evaluates it as a default value.
* import.meta.resolve() and createRequire(__filename). In CJS bundles esbuild
* replaces import.meta with {}, making .resolve undefined and crashing at
* runtime. AgentRC always passes an explicit cliPath so this function is dead
* code, but the SDK constructor still evaluates it as a default value.
*
* Validated against @github/copilot-sdk ^0.1.24–0.1.29.
* Validated against @github/copilot-sdk 0.1.24–0.2.0.
* If the SDK changes getBundledCliPath internals the build will fail with
* a clear error message below.
*/
const SDK_SHIM_TARGET =
'const sdkUrl = import.meta.resolve("@github/copilot/sdk");\n const sdkPath = fileURLToPath(sdkUrl);\n return join(dirname(dirname(sdkPath)), "index.js");';
const SDK_FN_RE = /function getBundledCliPath\(\) \{[\s\S]*?\n\}/;

const shimSdkImportMeta = {
name: "shim-sdk-import-meta",
setup(build) {
build.onLoad({ filter: /copilot-sdk[\\/]dist[\\/]client\.js$/ }, async (args) => {
let contents = await readFile(args.path, "utf8");
if (!contents.includes(SDK_SHIM_TARGET)) {
const original = await readFile(args.path, "utf8");
const contents = original.replace(
SDK_FN_RE,
'function getBundledCliPath() {\n return "bundled-cli-unavailable";\n}'
);
if (contents === original) {
throw new Error(
"[shim-sdk-import-meta] SDK internals changed — getBundledCliPath() " +
"target string not found in " +
"not found in " +
args.path +
". Update the shim to match the new SDK version."
". Update the shim in tsup.config.ts and vscode-extension/esbuild.mjs."
);
}
contents = contents.replace(SDK_SHIM_TARGET, 'return "bundled-cli-unavailable";');
return { contents, loader: "js" };
});
}
Expand Down
64 changes: 32 additions & 32 deletions vscode-extension/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
],
"devDependencies": {
"@eslint/js": "^10.0.1",
"@github/copilot-sdk": "^0.1.32",
"@github/copilot-sdk": "^0.2.0",
"@octokit/rest": "^22.0.1",
"@typescript-eslint/eslint-plugin": "^8.57.1",
"@typescript-eslint/parser": "^8.56.0",
Expand Down
Loading