@gaiaworks/gaia-cli 0.4.7 → 0.4.8

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaiaworks/gaia-cli",
3
- "version": "0.4.7",
3
+ "version": "0.4.8",
4
4
  "description": "JavaScript launcher for gaia-cli.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
@@ -115,45 +115,54 @@ function shellProfilePath(env = process.env) {
115
115
  return path.join(home, '.profile');
116
116
  }
117
117
 
118
- function ensureWindowsPathConfigured(binDir) {
119
- if (!binDir || process.platform !== 'win32' || pathContains(binDir)) return null;
120
- const command = [
121
- "$dir = $args[0]",
122
- "$current = [Environment]::GetEnvironmentVariable('Path', 'User')",
123
- "if (-not $current) { $current = '' }",
124
- "$parts = $current -split ';' | Where-Object { $_ }",
125
- "if ($parts -notcontains $dir) {",
126
- " $next = (@($dir) + $parts) -join ';'",
127
- " [Environment]::SetEnvironmentVariable('Path', $next, 'User')",
128
- "}",
129
- ].join("; ");
130
- const result = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command, binDir], {
131
- stdio: ["ignore", "pipe", "pipe"],
132
- encoding: "utf8",
133
- });
118
+ function ensureWindowsPathConfigured(binDir, options = {}) {
119
+ const platform = options.platform || process.platform;
120
+ const spawn = options.spawnSync || spawnSync;
121
+ if (!binDir || platform !== 'win32') return null;
122
+ const command = [
123
+ "$dir = $env:GAIA_CLI_PATH_DIR",
124
+ "$current = [Environment]::GetEnvironmentVariable('Path', 'User')",
125
+ "if (-not $current) { $current = '' }",
126
+ "$parts = $current -split ';' | Where-Object { $_ }",
127
+ "$normalize = { param($value) [Environment]::ExpandEnvironmentVariables($value.Trim().Trim([char]34).TrimEnd([char[]]'\\/')) }",
128
+ "$target = & $normalize $dir",
129
+ "$exists = @($parts | Where-Object { (& $normalize $_) -ieq $target }).Count -gt 0",
130
+ "if (-not $exists) {",
131
+ " $next = (@($dir) + $parts) -join ';'",
132
+ " [Environment]::SetEnvironmentVariable('Path', $next, 'User')",
133
+ " Write-Output '[gaia-cli:path-updated]'",
134
+ "} else {",
135
+ " Write-Output '[gaia-cli:path-unchanged]'",
136
+ "}",
137
+ ].join("; ");
138
+ const result = spawn("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command], {
139
+ stdio: ["ignore", "pipe", "pipe"],
140
+ encoding: "utf8",
141
+ env: { ...process.env, GAIA_CLI_PATH_DIR: binDir },
142
+ });
134
143
  if (result.error || result.status !== 0) {
135
- const detail = result.error ? result.error.message : `${result.stdout || ""}${result.stderr || ""}`.trim();
136
- throw new Error(`Failed to update user PATH: ${detail}`);
137
- }
138
- return "Windows user PATH";
144
+ const detail = result.error ? result.error.message : `${result.stdout || ""}${result.stderr || ""}`.trim();
145
+ throw new Error(`Failed to update user PATH: ${detail}`);
146
+ }
147
+ return (result.stdout || '').includes('[gaia-cli:path-updated]') ? 'Windows user PATH' : null;
139
148
  }
140
149
 
141
150
  function pathExportBlock(binDir) {
142
151
  return `${shellPathMarker}\nexport PATH="${binDir}:$PATH"\n`;
143
152
  }
144
153
 
145
- function ensurePathConfigured(binDir, profilePath = shellProfilePath(), platform = process.platform) {
146
- if (!binDir) return null;
147
- if (platform === 'win32') {
148
- return ensureWindowsPathConfigured(binDir);
149
- }
150
- if (!profilePath || pathContains(binDir)) return null;
151
- const existing = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
152
- if (existing.includes(binDir) || existing.includes(shellPathMarker)) return profilePath;
153
- const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
154
- fs.appendFileSync(profilePath, `${prefix}${pathExportBlock(binDir)}`);
155
- return profilePath;
156
- }
154
+ function ensurePathConfigured(binDir, profilePath = shellProfilePath(), platform = process.platform) {
155
+ if (!binDir) return null;
156
+ if (platform === 'win32') {
157
+ return ensureWindowsPathConfigured(binDir);
158
+ }
159
+ if (!profilePath) return null;
160
+ const existing = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
161
+ if (existing.includes(binDir)) return null;
162
+ const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
163
+ fs.appendFileSync(profilePath, `${prefix}${pathExportBlock(binDir)}`);
164
+ return profilePath;
165
+ }
157
166
 
158
167
  function ensureLocalBinary() {
159
168
  if (fs.existsSync(binaryPath)) return;
@@ -181,7 +190,7 @@ function installWizard(args) {
181
190
  console.error('[gaia-cli] ✓ Gaia 内置 Skill 安装完成。');
182
191
  const profilePath = ensurePathConfigured(globalBinDir);
183
192
  const suffix = explicitMode ? `当前模式: ${mode}。` : '';
184
- if (profilePath && globalBinDir && !pathContains(globalBinDir)) {
193
+ if (profilePath && globalBinDir) {
185
194
  console.error(`[gaia-cli] 安装完成,${suffix}已更新 PATH 配置: ${profilePath}`);
186
195
  console.error(`[gaia-cli] 重新打开终端后可以执行: gaia version`);
187
196
  return;