@bradygaster/squad-cli 0.8.22 → 0.8.24

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.
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env node
2
+
3
+ /**
4
+ * ESM Import Patcher for @github/copilot-sdk
5
+ *
6
+ * Patches broken ESM imports in @github/copilot-sdk for Node 24+ compatibility.
7
+ *
8
+ * Root cause: @github/copilot-sdk@0.1.32 has inconsistent ESM imports:
9
+ * - session.js imports "vscode-jsonrpc/node" (BROKEN - missing .js extension)
10
+ * - client.js imports "vscode-jsonrpc/node.js" (correct)
11
+ *
12
+ * Node 24+ enforces strict ESM resolution requiring .js extensions.
13
+ * This is a temporary workaround until copilot-sdk fixes upstream.
14
+ *
15
+ * Issue: bradygaster/squad#XXX
16
+ */
17
+
18
+ import { readFileSync, writeFileSync, existsSync } from 'fs';
19
+ import { join, dirname } from 'path';
20
+ import { fileURLToPath } from 'url';
21
+
22
+ const __dirname = dirname(fileURLToPath(import.meta.url));
23
+
24
+ /**
25
+ * Patch session.js in @github/copilot-sdk
26
+ */
27
+ function patchCopilotSdk() {
28
+ // Try multiple possible locations (npm workspaces can hoist dependencies)
29
+ const possiblePaths = [
30
+ // squad-cli package node_modules
31
+ join(__dirname, '..', 'node_modules', '@github', 'copilot-sdk', 'dist', 'session.js'),
32
+ // Workspace root node_modules (common with npm workspaces)
33
+ join(__dirname, '..', '..', '..', 'node_modules', '@github', 'copilot-sdk', 'dist', 'session.js'),
34
+ // Global install location (node_modules at parent of package)
35
+ join(__dirname, '..', '..', '@github', 'copilot-sdk', 'dist', 'session.js'),
36
+ ];
37
+
38
+ let sessionJsPath = null;
39
+ for (const path of possiblePaths) {
40
+ if (existsSync(path)) {
41
+ sessionJsPath = path;
42
+ break;
43
+ }
44
+ }
45
+
46
+ if (!sessionJsPath) {
47
+ // copilot-sdk not installed (maybe optionalDependency or CI without install)
48
+ // This is fine - exit silently
49
+ return false;
50
+ }
51
+
52
+ try {
53
+ let content = readFileSync(sessionJsPath, 'utf8');
54
+
55
+ // Replace extensionless import with .js extension
56
+ const patched = content.replace(
57
+ /from\s+["']vscode-jsonrpc\/node["']/g,
58
+ 'from "vscode-jsonrpc/node.js"'
59
+ );
60
+
61
+ if (patched !== content) {
62
+ writeFileSync(sessionJsPath, patched, 'utf8');
63
+ console.log('✅ Patched @github/copilot-sdk ESM imports for Node 24+ compatibility');
64
+ return true;
65
+ } else {
66
+ // Already patched or upstream fixed
67
+ return false;
68
+ }
69
+ } catch (err) {
70
+ console.warn('⚠️ Failed to patch @github/copilot-sdk ESM imports:', err.message);
71
+ console.warn(' This may cause issues on Node 24+ if copilot-sdk loads.');
72
+ return false;
73
+ }
74
+ }
75
+
76
+ // Run patch
77
+ patchCopilotSdk();