@gaiaworks/gaia-cli 0.0.3 → 0.0.5

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
@@ -14,17 +14,17 @@ npx @gaiaworks/gaia-cli version
14
14
 
15
15
  ```bash
16
16
  npx @gaiaworks/gaia-cli@latest install
17
- gaia-cli version
17
+ gaia version
18
18
  ```
19
19
 
20
20
  安装模式:
21
21
 
22
22
  ```bash
23
23
  npx @gaiaworks/gaia-cli@latest install
24
- npx @gaiaworks/gaia-cli@latest install --mode saas
25
- npx @gaiaworks/gaia-cli@latest install --mode work
24
+ npx @gaiaworks/gaia-cli@latest install --mode external
25
+ npx @gaiaworks/gaia-cli@latest install --mode internal
26
26
  ```
27
27
 
28
- 未指定 `--mode` 时默认写入 `saas`。安装脚本会在全局安装完成后执行 `gaia-cli config set mode <saas|work>`,用于后续区分内部/外部登录流程和 shared skill 规则。
28
+ 未指定 `--mode` 时默认写入 `external`。安装脚本会执行 `gaia setup --mode <external|internal>`,用于初始化本地 `install_mode` Agent Skills。
29
29
 
30
30
  安装时会根据 npm 包版本,从 OSS 的同版本目录下载当前平台对应的 `gaia-cli` 二进制。
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@gaiaworks/gaia-cli",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "description": "JavaScript launcher for gaia-cli.",
5
5
  "license": "UNLICENSED",
6
6
  "private": false,
7
7
  "bin": {
8
- "gaia-cli": "scripts/run.js"
8
+ "gaia": "scripts/run.js"
9
9
  },
10
10
  "os": [
11
11
  "darwin",
@@ -9,9 +9,10 @@ const { binaryName, install } = require('./install');
9
9
  const packageJson = JSON.parse(fs.readFileSync(path.join(__dirname, '..', 'package.json'), 'utf8'));
10
10
  const packageSpec = `${packageJson.name}@${packageJson.version}`;
11
11
  const binaryPath = path.join(__dirname, '..', 'bin', binaryName());
12
+ const shellPathMarker = '# Added by gaia-cli installer';
12
13
 
13
14
  function parseInstallArgs(args) {
14
- let mode = 'saas';
15
+ let mode = 'external';
15
16
  let explicitMode = false;
16
17
  const npmArgs = [];
17
18
 
@@ -20,7 +21,7 @@ function parseInstallArgs(args) {
20
21
  if (arg === '--mode') {
21
22
  const value = args[i + 1];
22
23
  if (!value) {
23
- throw new Error('--mode requires a value: work or saas');
24
+ throw new Error('--mode requires a value: external or internal');
24
25
  }
25
26
  mode = value;
26
27
  explicitMode = true;
@@ -35,8 +36,8 @@ function parseInstallArgs(args) {
35
36
  npmArgs.push(arg);
36
37
  }
37
38
 
38
- if (mode !== 'work' && mode !== 'saas') {
39
- throw new Error(`Unsupported mode: ${mode}. Expected work or saas.`);
39
+ if (mode !== 'external' && mode !== 'internal') {
40
+ throw new Error(`Unsupported mode: ${mode}. Expected external or internal.`);
40
41
  }
41
42
 
42
43
  return { explicitMode, mode, npmArgs };
@@ -45,6 +46,7 @@ function parseInstallArgs(args) {
45
46
  function run(command, args, options = {}) {
46
47
  const result = spawnSync(command, args, {
47
48
  stdio: options.stdio || 'inherit',
49
+ encoding: 'utf8',
48
50
  });
49
51
 
50
52
  if (result.error) {
@@ -57,6 +59,83 @@ function run(command, args, options = {}) {
57
59
  }
58
60
  }
59
61
 
62
+ function runCapture(command, args) {
63
+ return spawnSync(command, args, {
64
+ stdio: ['ignore', 'pipe', 'pipe'],
65
+ encoding: 'utf8',
66
+ });
67
+ }
68
+
69
+ function npmGlobalBinDir() {
70
+ const result = runCapture('npm', ['prefix', '-g']);
71
+ if (result.error || result.status !== 0) return null;
72
+ const prefix = result.stdout.trim();
73
+ if (!prefix) return null;
74
+ return process.platform === 'win32' ? prefix : path.join(prefix, 'bin');
75
+ }
76
+
77
+ function npmGlobalCommandPath(binDir, platform = process.platform) {
78
+ if (!binDir) return null;
79
+ if (platform === 'win32') return path.win32.join(binDir, 'gaia.cmd');
80
+ return path.posix.join(binDir, 'gaia');
81
+ }
82
+
83
+ function pathContains(dir) {
84
+ if (!dir) return false;
85
+ const entries = (process.env.PATH || '').split(path.delimiter).filter(Boolean);
86
+ return entries.some((entry) => path.resolve(entry) === path.resolve(dir));
87
+ }
88
+
89
+ function shellProfilePath(env = process.env) {
90
+ if (process.platform === 'win32') return null;
91
+ const home = env.HOME;
92
+ if (!home) return null;
93
+ const shell = path.basename(env.SHELL || '');
94
+ if (shell === 'zsh') return path.join(home, '.zshrc');
95
+ if (shell === 'bash') return path.join(home, '.bashrc');
96
+ return path.join(home, '.profile');
97
+ }
98
+
99
+ function ensureWindowsPathConfigured(binDir) {
100
+ if (!binDir || process.platform !== 'win32' || pathContains(binDir)) return null;
101
+ const command = [
102
+ "$dir = $args[0]",
103
+ "$current = [Environment]::GetEnvironmentVariable('Path', 'User')",
104
+ "if (-not $current) { $current = '' }",
105
+ "$parts = $current -split ';' | Where-Object { $_ }",
106
+ "if ($parts -notcontains $dir) {",
107
+ " $next = (@($dir) + $parts) -join ';'",
108
+ " [Environment]::SetEnvironmentVariable('Path', $next, 'User')",
109
+ "}",
110
+ ].join("; ");
111
+ const result = spawnSync("powershell.exe", ["-NoProfile", "-NonInteractive", "-Command", command, binDir], {
112
+ stdio: ["ignore", "pipe", "pipe"],
113
+ encoding: "utf8",
114
+ });
115
+ if (result.error || result.status !== 0) {
116
+ const detail = result.error ? result.error.message : `${result.stdout || ""}${result.stderr || ""}`.trim();
117
+ throw new Error(`Failed to update user PATH: ${detail}`);
118
+ }
119
+ return "Windows user PATH";
120
+ }
121
+
122
+ function pathExportBlock(binDir) {
123
+ return `${shellPathMarker}\nexport PATH="${binDir}:$PATH"\n`;
124
+ }
125
+
126
+ function ensurePathConfigured(binDir, profilePath = shellProfilePath()) {
127
+ if (!binDir) return null;
128
+ if (process.platform === 'win32') {
129
+ return ensureWindowsPathConfigured(binDir);
130
+ }
131
+ if (!profilePath || pathContains(binDir)) return null;
132
+ const existing = fs.existsSync(profilePath) ? fs.readFileSync(profilePath, 'utf8') : '';
133
+ if (existing.includes(binDir) || existing.includes(shellPathMarker)) return profilePath;
134
+ const prefix = existing && !existing.endsWith('\n') ? '\n' : '';
135
+ fs.appendFileSync(profilePath, `${prefix}${pathExportBlock(binDir)}`);
136
+ return profilePath;
137
+ }
138
+
60
139
  function ensureLocalBinary() {
61
140
  if (fs.existsSync(binaryPath)) return;
62
141
  install();
@@ -70,11 +149,21 @@ function installWizard(args) {
70
149
 
71
150
  ensureLocalBinary();
72
151
  run('npm', ['install', '-g', packageSpec]);
73
- run(binaryPath, ['config', 'set', 'mode', mode], { stdio: 'ignore' });
152
+ const globalBinDir = npmGlobalBinDir();
153
+ const globalCommand = npmGlobalCommandPath(globalBinDir);
154
+ const setupCommand = globalCommand && fs.existsSync(globalCommand) ? globalCommand : binaryPath;
155
+ run(setupCommand, ['setup', '--mode', mode], { stdio: 'ignore' });
156
+ const profilePath = ensurePathConfigured(globalBinDir);
157
+ const suffix = explicitMode ? `当前模式: ${mode}。` : '';
158
+ if (profilePath && globalBinDir && !pathContains(globalBinDir)) {
159
+ console.error(`[gaia-cli] 安装完成,${suffix}已更新 PATH 配置: ${profilePath}`);
160
+ console.error(`[gaia-cli] 重新打开终端后可以执行: gaia version`);
161
+ return;
162
+ }
74
163
  if (explicitMode) {
75
- console.error(`[gaia-cli] 安装完成,当前模式: ${mode}。可以执行: gaia-cli version`);
164
+ console.error(`[gaia-cli] 安装完成,当前模式: ${mode}。可以执行: gaia version`);
76
165
  } else {
77
- console.error('[gaia-cli] 安装完成。可以执行: gaia-cli version');
166
+ console.error('[gaia-cli] 安装完成。可以执行: gaia version');
78
167
  }
79
168
  }
80
169
 
@@ -88,6 +177,13 @@ if (require.main === module) {
88
177
  }
89
178
 
90
179
  module.exports = {
180
+ ensurePathConfigured,
181
+ ensureWindowsPathConfigured,
182
+ npmGlobalBinDir,
183
+ npmGlobalCommandPath,
184
+ pathContains,
185
+ pathExportBlock,
186
+ shellProfilePath,
91
187
  installWizard,
92
188
  parseInstallArgs,
93
189
  };
File without changes
package/scripts/run.js CHANGED
File without changes