ai-extension-preview 0.1.18 → 0.1.19

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.
package/dist/index.js CHANGED
@@ -28,6 +28,8 @@ const WORK_DIR = path.join(HOME_DIR, '.ai-extension-preview', options.job || 'de
28
28
  (async () => {
29
29
  const { job: initialJobId, host, token, user: userId } = options;
30
30
  // 1. Initialize Runtime with Config
31
+ // Fix for Windows: Glob patterns in SCR DirectoryLoader require forward slashes
32
+ const pluginDir = path.join(__dirname, 'plugins').replace(/\\/g, '/');
31
33
  const runtime = new Runtime({
32
34
  config: {
33
35
  host,
@@ -37,9 +39,10 @@ const WORK_DIR = path.join(HOME_DIR, '.ai-extension-preview', options.job || 'de
37
39
  workDir: WORK_DIR
38
40
  },
39
41
  hostContext: {}, // Clear hostContext config wrapping
40
- pluginPaths: [path.join(__dirname, 'plugins')] // [NEW] Auto-discovery
42
+ pluginPaths: [pluginDir] // [NEW] Auto-discovery
41
43
  });
42
44
  // Register Plugins
45
+ runtime.logger.info(`Loading plugins from: ${pluginDir}`);
43
46
  runtime.logger.info('Initializing runtime...');
44
47
  await runtime.initialize();
45
48
  const ctx = runtime.getContext();
@@ -19,8 +19,10 @@ const BrowserManagerPlugin = {
19
19
  if (isWSL) {
20
20
  const wslPaths = getWSLTempPath();
21
21
  if (wslPaths) {
22
- STAGING_DIR = path.join(wslPaths.wsl, 'ai-ext-preview');
23
- WIN_STAGING_DIR = path.join(wslPaths.win, 'ai-ext-preview');
22
+ const folder = 'ai-ext-preview';
23
+ STAGING_DIR = path.join(wslPaths.wsl, folder);
24
+ // Force Windows Backslashes for WIN_STAGING_DIR
25
+ WIN_STAGING_DIR = `${wslPaths.win}\\${folder}`.replace(/\//g, '\\');
24
26
  }
25
27
  else {
26
28
  // Fallback
@@ -70,6 +72,15 @@ const BrowserManagerPlugin = {
70
72
  else if (extensionRoot !== STAGING_DIR) {
71
73
  await ctx.logger.info(`Detected nested extension at: ${path.basename(extensionRoot)}`);
72
74
  }
75
+ // Debug: List files in staging to verify extension presence
76
+ try {
77
+ const files = await fs.readdir(extensionRoot);
78
+ await ctx.logger.info(`[DEBUG] Files in Staging (${extensionRoot}): ${files.join(', ')}`);
79
+ await ctx.logger.info(`[DEBUG] WIN_STAGING_DIR: ${WIN_STAGING_DIR}`);
80
+ }
81
+ catch (e) {
82
+ await ctx.logger.error(`[DEBUG] Failed to list staging files: ${e.message}`);
83
+ }
73
84
  // Delegate Launch
74
85
  await ctx.actions.runAction('launcher:launch', {
75
86
  extensionPath: extensionRoot,
@@ -98,6 +109,7 @@ const BrowserManagerPlugin = {
98
109
  const hostIp = getHostIp();
99
110
  const port = 9222;
100
111
  for (let i = 0; i < maxRetries; i++) {
112
+ const errors = [];
101
113
  try {
102
114
  try {
103
115
  // Strategy 1: Host IP
@@ -112,6 +124,7 @@ const BrowserManagerPlugin = {
112
124
  }
113
125
  }
114
126
  catch (err1) {
127
+ errors.push(`Host(${hostIp}): ${err1.message}`);
115
128
  try {
116
129
  // Strategy 2: 0.0.0.0 (Requested by User)
117
130
  browserConnection = await puppeteer.connect({
@@ -120,6 +133,7 @@ const BrowserManagerPlugin = {
120
133
  });
121
134
  }
122
135
  catch (err2) {
136
+ errors.push(`0.0.0.0: ${err2.message}`);
123
137
  try {
124
138
  // Strategy 3: 127.0.0.1
125
139
  browserConnection = await puppeteer.connect({
@@ -128,6 +142,7 @@ const BrowserManagerPlugin = {
128
142
  });
129
143
  }
130
144
  catch (err3) {
145
+ errors.push(`127.0.0.1: ${err3.message}`);
131
146
  // Strategy 4: Localhost
132
147
  try {
133
148
  browserConnection = await puppeteer.connect({
@@ -136,7 +151,13 @@ const BrowserManagerPlugin = {
136
151
  });
137
152
  }
138
153
  catch (err4) {
139
- throw new Error(`Host(${hostIp}): ${err1.message}, 0.0.0.0: ${err2.message}, IP: ${err3.message}, Localhost: ${err4.message}`);
154
+ errors.push(`Localhost: ${err4.message}`);
155
+ const combinedError = errors.join(', ');
156
+ if (i === maxRetries - 1 && hostIp) {
157
+ // Final attempt hint
158
+ throw new Error(`${combinedError}. [HINT] Check Windows Firewall for port ${port}.`);
159
+ }
160
+ throw new Error(combinedError);
140
161
  }
141
162
  }
142
163
  }
@@ -31,12 +31,15 @@ const NativeLauncherPlugin = {
31
31
  // Default Profile
32
32
  let safeProfile = path.join(path.dirname(config.workDir), 'profile');
33
33
  if (process.platform === 'win32') {
34
- safeDist = normalizePathToWindows(safeDist);
34
+ // Ensure backslashes are used everywhere
35
+ safeDist = normalizePathToWindows(safeDist).replace(/\//g, '\\');
35
36
  // Use temp profile to avoid permissions issues
36
37
  // If winStagingDir was passed (from BrowserManager), we could use its sibling
37
38
  // But here we can just use os.tmpdir
38
- safeProfile = path.join(os.tmpdir(), 'ai-ext-profile');
39
+ safeProfile = path.join(os.tmpdir(), 'ai-ext-profile').replace(/\//g, '\\');
39
40
  }
41
+ await ctx.logger.info(`[DEBUG] Native Chrome Extension Path: ${safeDist}`);
42
+ await ctx.logger.info(`[DEBUG] Native Chrome Profile Path: ${safeProfile}`);
40
43
  await ctx.actions.runAction('core:log', { level: 'info', message: `Native Launch Executable: ${executable} ` });
41
44
  await ctx.actions.runAction('core:log', { level: 'info', message: `Native Launch Target: ${safeDist} ` });
42
45
  const cleanArgs = [
@@ -48,6 +51,15 @@ const NativeLauncherPlugin = {
48
51
  '--remote-debugging-port=9222', // Enable CDP
49
52
  'chrome://extensions'
50
53
  ];
54
+ // --- Developer Debug UI ---
55
+ console.log('\n' + '─'.repeat(50));
56
+ console.log(' 🛠️ DEBUG: NATIVE LAUNCH CONFIGURATION');
57
+ console.log('─'.repeat(50));
58
+ console.log(`Executable: ${executable}`);
59
+ console.log('Arguments:');
60
+ cleanArgs.forEach(arg => console.log(` ${arg}`));
61
+ console.log('─'.repeat(50) + '\n');
62
+ // ---------------------------
51
63
  try {
52
64
  // Kill existing process if any
53
65
  if (chromeProcess) {
@@ -33,19 +33,45 @@ const WSLLauncherPlugin = {
33
33
  let finalWinExtensionPath = winStagingDir;
34
34
  if (payload.extensionPath !== payload.stagingDir) {
35
35
  const relative = path.relative(payload.stagingDir, payload.extensionPath);
36
- // Join with backslashes
37
- finalWinExtensionPath = path.posix.join(winStagingDir.replace(/\\\\/g, '/'), relative).replace(/\//g, '\\\\');
36
+ // Standardize separators to backslashes for Windows
37
+ const winStagingClean = winStagingDir.replace(/\//g, '\\');
38
+ finalWinExtensionPath = `${winStagingClean}\\${relative}`.replace(/\//g, '\\');
38
39
  }
40
+ else {
41
+ finalWinExtensionPath = winStagingDir.replace(/\//g, '\\');
42
+ }
43
+ await ctx.logger.info(`[DEBUG] Chrome Extension Path: ${finalWinExtensionPath}`);
44
+ const winProfileClean = winProfile.replace(/\\+$/, '');
45
+ await ctx.logger.info(`[DEBUG] Chrome Extension Path: ${finalWinExtensionPath}`);
46
+ await ctx.logger.info(`[DEBUG] Chrome Profile Path: ${winProfileClean}`);
39
47
  const driveLetter = 'c';
40
48
  const winChromePath = chromePath
41
49
  .replace(new RegExp(`^/mnt/${driveLetter}/`), `${driveLetter.toUpperCase()}:\\\\`)
42
50
  .replace(/\//g, '\\\\');
43
51
  await ctx.logger.info(`WSL Launch Target (Win): ${finalWinExtensionPath}`);
52
+ await ctx.logger.warn('---------------------------------------------------------');
53
+ await ctx.logger.warn('⚠️ WSL DETECTED');
54
+ await ctx.logger.warn('Windows Firewall often blocks connections from WSL to Chrome.');
55
+ await ctx.logger.warn('If connection fails, run this tool from Git Bash or Command Prompt.');
56
+ await ctx.logger.warn('---------------------------------------------------------');
57
+ // --- Developer Debug UI ---
58
+ const debugInfo = [
59
+ ` Chrome Path: ${winChromePath}`,
60
+ `Extension Path: ${finalWinExtensionPath}`,
61
+ ` Profile Path: ${winProfileClean}`,
62
+ `Launch Command: powershell.exe -NoProfile -ExecutionPolicy Bypass -File "${winStagingDir}\\launch.ps1"`
63
+ ];
64
+ console.log('\n' + '─'.repeat(50));
65
+ console.log(' 🛠️ DEBUG: CHROME LAUNCH CONFIGURATION');
66
+ console.log('─'.repeat(50));
67
+ debugInfo.forEach(line => console.log(line));
68
+ console.log('─'.repeat(50) + '\n');
69
+ // ---------------------------
44
70
  // Create PowerShell Launch Script with PID capture
45
71
  const psContent = `
46
72
  $chromePath = "${winChromePath}"
47
73
  $extPath = "${finalWinExtensionPath}"
48
- $profilePath = "${winProfile}"
74
+ $profilePath = "${winProfileClean}"
49
75
 
50
76
  # Verify Paths
51
77
  if (-not (Test-Path -Path $extPath)) {
@@ -58,22 +84,17 @@ if (-not (Test-Path -Path $profilePath)) {
58
84
  New-Item -ItemType Directory -Force -Path $profilePath | Out-Null
59
85
  }
60
86
 
61
- $argsList = @(
62
- "--load-extension=\`"$extPath\`"",
63
- "--user-data-dir=\`"$profilePath\`"",
64
- "--no-first-run",
65
- "--no-default-browser-check",
66
- "--disable-gpu",
67
- "--remote-debugging-port=9222",
68
- "--remote-debugging-address=0.0.0.0",
69
- "--remote-allow-origins=*",
70
- "about:blank"
71
- )
87
+ $argsStr = "--load-extension=\`"$extPath\`" --user-data-dir=\`"$profilePath\`" --no-first-run --no-default-browser-check --disable-gpu --remote-debugging-port=9222 --remote-debugging-address=0.0.0.0 --remote-allow-origins=* about:blank"
72
88
 
73
89
  # Launch and capture PID
74
- $process = Start-Process -FilePath $chromePath -ArgumentList $argsList -PassThru
90
+ # Use single string argument to avoid array joining issues
91
+ $process = Start-Process -FilePath $chromePath -ArgumentList $argsStr -PassThru
75
92
  Write-Host "CHROME_PID:$($process.Id)"
76
93
  `;
94
+ console.log(' 📄 DEBUG: GENERATED POWERSHELL SCRIPT');
95
+ console.log('─'.repeat(50));
96
+ console.log(psContent.trim());
97
+ console.log('─'.repeat(50) + '\n');
77
98
  // Write ps1 to STAGING_DIR/launch.ps1
78
99
  const psPath = path.join(payload.stagingDir, 'launch.ps1');
79
100
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-extension-preview",
3
- "version": "0.1.18",
3
+ "version": "0.1.19",
4
4
  "description": "Local preview tool for AI Extension Builder",
5
5
  "type": "module",
6
6
  "bin": {