@gaiaworks/gaia-cli 0.4.6 → 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/README.md CHANGED
@@ -25,7 +25,7 @@ npx @gaiaworks/gaia-cli@latest install --mode external
25
25
  npx @gaiaworks/gaia-cli@latest install --mode internal
26
26
  ```
27
27
 
28
- 未指定 `--mode` 时默认写入 `external`。安装脚本会执行 `gaia setup --mode <external|internal>`,用于初始化本地 `install_mode` Agent Skills。
28
+ 未指定 `--mode` 时默认写入 `external`。安装脚本会执行 `gaia setup --mode <external|internal>`,用于初始化本地 `install_mode`,并同步当前模式的 `gaia-shared` 与公共的 `gaia-skill-maker`。
29
29
 
30
30
  安装时会根据 npm 包版本,从 OSS 的同版本目录下载当前平台对应的 `gaia-cli` 二进制。
31
31
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gaiaworks/gaia-cli",
3
- "version": "0.4.6",
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;
@@ -171,17 +180,17 @@ function installWizard(args) {
171
180
  run(npm.command, npm.args);
172
181
  const globalBinDir = npmGlobalBinDir();
173
182
  const setupCommand = setupCommandPath(binaryPath);
174
- console.error('[gaia-cli] 正在安装 Gaia Skill: gaia-shared...');
183
+ console.error('[gaia-cli] 正在安装 Gaia 内置 Skill: gaia-shared, gaia-skill-maker...');
175
184
  try {
176
185
  run(setupCommand, ['setup', '--mode', mode], { stdio: 'ignore' });
177
186
  } catch (error) {
178
- console.error('[gaia-cli] gaia-shared 安装失败。');
187
+ console.error('[gaia-cli] Gaia 内置 Skill 安装失败。');
179
188
  throw error;
180
189
  }
181
- console.error('[gaia-cli] ✓ Gaia Skill gaia-shared 安装完成。');
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;