Skip to content

Commit e1f4978

Browse files
committed
feat: add codex bootstrap installer and GMN endpoint selection
1 parent 5e87979 commit e1f4978

File tree

26 files changed

+3156
-106
lines changed

26 files changed

+3156
-106
lines changed
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
## Context
2+
3+
ccman already knows how to write Codex configuration safely, but a user who only downloads a single installer script cannot rely on `ccman` itself being available. Installing Codex is operationally different from switching providers because it touches system dependencies and varies by platform:
4+
5+
- Codex depends on a working Node.js + npm environment.
6+
- Users may already have Node.js installed, but the version may be incompatible with the current Codex package.
7+
- Users may already manage Node.js with `volta`, `fnm`, `nvm`, `asdf`, or `mise`; the installer should reuse that instead of introducing a second manager.
8+
- macOS, Linux, and Windows have different system package paths (`brew`, `apt`, `dnf`, `yum`, `pacman`, `zypper`, `apk`, `winget`, `choco`, `scoop`), and some users have none of them.
9+
- Global npm installs can fail because of permissions when using a system Node.js.
10+
11+
The installer therefore needs a staged bootstrap design rather than a single shell command.
12+
13+
## Goals
14+
15+
- Provide a one-click Codex bootstrap flow that can move a machine from "no Codex" to "Codex installed and configured" with minimal manual branching.
16+
- Reuse a compatible existing Node.js installation when available.
17+
- Prefer an already-installed Node.js version manager over introducing a new one.
18+
- Avoid forcing a version manager when the user's current runtime already satisfies Codex requirements.
19+
- When runtime remediation is needed, prefer per-user and reversible solutions over invasive system-wide upgrades.
20+
- Preserve the same effective Codex configuration defaults used by ccman while keeping the installer self-contained.
21+
- Ensure repository-side validation stays simulation-only and never performs real runtime installation during automated checks.
22+
23+
## Non-Goals
24+
25+
- Managing every possible shell initialization edge case for every version manager.
26+
- Supporting Codex IDE extension installation in the first version.
27+
- Replacing the user's primary package manager or shell profile wholesale.
28+
- Silently making irreversible system-level changes without confirmation.
29+
30+
## Proposed Flow
31+
32+
### 1. Bootstrap entrypoint
33+
34+
Use thin platform-native launchers:
35+
36+
- `scripts/install-codex.sh` for macOS/Linux
37+
- `scripts/install-codex.ps1` for Windows
38+
39+
These launchers only do the minimum needed to enter the shared decision flow:
40+
41+
1. Detect OS + architecture.
42+
2. Detect whether `node` is already available.
43+
3. If `node` is missing, obtain a working runtime through the runtime strategy below.
44+
4. Hand off to self-contained standalone logic for the rest of the flow.
45+
46+
This split is necessary because bootstrap logic cannot assume a compatible Node runtime exists before remediation.
47+
48+
### 2. Runtime requirement resolution
49+
50+
The installer should determine the required Node.js semver range dynamically from the current Codex package metadata when possible, then fall back to an installer-maintained floor if lookup fails.
51+
52+
Preferred resolution sequence:
53+
54+
1. If `npm` is available, query the current package metadata for `@openai/codex`.
55+
2. If metadata lookup fails, use a conservative fallback floor stored in the installer.
56+
3. After any runtime install or upgrade, re-check the resolved requirement before proceeding.
57+
58+
This avoids freezing a stale minimum Node version in the script.
59+
60+
### 3. Runtime decision order
61+
62+
The runtime decision tree should be:
63+
64+
1. **Existing compatible Node.js present**
65+
- Reuse it.
66+
- Do not install a version manager.
67+
68+
2. **Existing Node.js present but incompatible**
69+
- If an existing version manager is detected, use that manager to install or switch to a compatible Node.js.
70+
- If no manager is detected, recommend bootstrapping a per-user manager and explain why the current system Node is insufficient.
71+
72+
3. **Node.js missing**
73+
- If a version manager is already installed, use it.
74+
- Otherwise offer the safest platform-appropriate bootstrap path, with a recommended default.
75+
76+
### 4. Version manager preference
77+
78+
Detection order should prioritize already-installed tools, not a fixed global preference:
79+
80+
- `volta`
81+
- `fnm`
82+
- `nvm`
83+
- `asdf`
84+
- `mise`
85+
86+
If none are installed and runtime remediation is needed, recommend:
87+
88+
- **Default recommendation:** `volta`
89+
- per-user
90+
- cross-platform
91+
- low shell coupling
92+
- good fit for global CLI tooling like Codex
93+
- **Alternative paths:** system package manager install for users who explicitly prefer it
94+
95+
The installer should not bootstrap a manager when the current Node.js is already compatible.
96+
97+
### 5. System package fallback
98+
99+
When users decline a version manager or when a version manager path is unavailable, offer system package paths:
100+
101+
- macOS: `brew install node` if Homebrew exists; optionally bootstrap Homebrew first with explicit confirmation
102+
- Linux: distro package manager path if available, but always re-check compatibility because distro Node.js can lag behind current Codex requirements
103+
- Windows: `winget` first, then `choco` or `scoop` if available
104+
105+
System package installation must be opt-in because it is more invasive than a per-user manager.
106+
107+
### 6. Codex installation
108+
109+
Once a compatible Node.js runtime is active:
110+
111+
1. Detect existing `codex`.
112+
2. If present, record current version and decide whether to keep or upgrade.
113+
3. Install or upgrade Codex through npm.
114+
4. Verify with `codex --version`.
115+
116+
If global npm install fails because of permissions and the runtime is a system Node.js without a manager, the installer should stop and recommend the version-manager path rather than attempting unsafe privilege escalation by default.
117+
118+
### 7. Final Codex configuration
119+
120+
After Codex installation succeeds, the standalone installer should write `~/.codex/config.toml` and `~/.codex/auth.json` by itself.
121+
122+
Constraints:
123+
124+
- the script must not require `ccman` to be globally installed
125+
- the script must not require a local repo checkout or prebuilt `packages/core/dist`
126+
- the written configuration should preserve the same intended defaults as ccman's Codex setup flow wherever practical
127+
- the script should back up existing Codex config/auth files before overwriting them
128+
129+
This keeps the user experience "download and run" while preserving behavioral consistency with ccman.
130+
131+
## UX Principles
132+
133+
- Show what was detected before making changes.
134+
- Prefer "reuse what the user already has" over introducing new tools.
135+
- Make invasive actions explicit and confirmable.
136+
- Support a non-interactive mode later, but design the first version for an interactive and explainable flow.
137+
- Provide a dry-run mode for debugging decisions without changing the machine.
138+
- Keep automated verification inside the repo limited to dry-run plans, parser checks, and pure decision-logic tests.
139+
140+
## Testing Strategy
141+
142+
Because real runtime installation is machine-specific, testing should separate pure decision logic from side effects:
143+
144+
- unit-test detector parsing and decision tree selection
145+
- unit-test manager and package-manager preference rules
146+
- unit-test dry-run planning output for representative environments
147+
- repository automation MUST NOT run real installation against the host machine
148+
- keep real installation validation as a manual, opt-in activity outside automated repo checks
149+
150+
## Open Questions
151+
152+
- Whether the first version should support only GMN-based Codex configuration or also an official OpenAI login handoff.
153+
- Whether a future version should additionally expose the same flow as a `ccman` top-level command.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Change: add Codex bootstrap installer
2+
3+
## Why
4+
5+
Users who want to use Codex with ccman-managed providers still have to solve several setup steps manually: prepare a compatible Node.js runtime, choose how to install or upgrade it on their platform, install the Codex CLI itself, and only then apply provider configuration. This is especially error-prone when users already have Node installed but on an incompatible version, or when they have an existing version manager that should be reused instead of replaced.
6+
7+
## What Changes
8+
9+
- Add a one-click Codex bootstrap flow that can be downloaded and executed directly as a standalone script, without requiring a preinstalled `ccman` package or a prebuilt local repository.
10+
- Add safe runtime resolution rules so the installer reuses a compatible existing Node.js when possible, upgrades through an already-installed version manager when available, and only proposes bootstrapping a manager or system package path when necessary.
11+
- Add Codex CLI installation and verification steps that install or upgrade Codex after the runtime is ready.
12+
- Add self-contained Codex configuration writing inside the standalone script while preserving the same effective provider and model defaults as ccman's Codex setup flow.
13+
- Add a dry-run / planning mode and keep repository validation limited to simulation-only checks so automated verification never mutates the developer's real environment.
14+
- Add user-facing documentation describing runtime decision rules, supported platforms, and what happens when the environment is partially configured.
15+
16+
## Impact
17+
18+
- Affected specs: `codex-bootstrap-installer`
19+
- Affected code: standalone bootstrap scripts under `scripts/`, optional shared installer logic for simulation/testing, docs for installation and troubleshooting
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
## ADDED Requirements
2+
3+
### Requirement: Standalone cross-platform Codex bootstrap
4+
5+
The system SHALL provide a Codex bootstrap flow that can be downloaded and executed directly to guide a user from an unprepared machine to a working Codex CLI installation and Codex configuration on supported platforms.
6+
7+
#### Scenario: Existing compatible runtime
8+
9+
- **WHEN** the user runs the bootstrap flow on a machine that already has a compatible Node.js runtime
10+
- **THEN** the installer SHALL reuse the existing runtime
11+
- **AND** it SHALL proceed to install or verify the Codex CLI
12+
- **AND** it SHALL continue to the Codex configuration step
13+
14+
#### Scenario: Missing runtime
15+
16+
- **WHEN** the user runs the bootstrap flow on a machine without Node.js
17+
- **THEN** the installer SHALL detect the platform and available installation tools
18+
- **AND** it SHALL offer a supported runtime installation path before attempting Codex installation
19+
- **AND** it SHALL NOT require a preinstalled `ccman` package to continue
20+
21+
### Requirement: Runtime remediation policy
22+
23+
The installer SHALL prefer the least invasive compatible runtime path.
24+
25+
#### Scenario: Existing version manager present
26+
27+
- **WHEN** Node.js is missing or incompatible and a supported version manager is already installed
28+
- **THEN** the installer SHALL use the existing manager instead of introducing a different manager
29+
30+
#### Scenario: Compatible runtime already present
31+
32+
- **WHEN** the current Node.js installation satisfies the resolved Codex runtime requirement
33+
- **THEN** the installer SHALL NOT install or bootstrap a version manager
34+
35+
#### Scenario: Incompatible system runtime with no manager
36+
37+
- **WHEN** the current Node.js installation is incompatible and no supported version manager is detected
38+
- **THEN** the installer SHALL recommend a safe remediation path
39+
- **AND** it SHALL require confirmation before taking invasive system-level actions
40+
41+
### Requirement: Codex installation verification
42+
43+
The installer SHALL verify that Codex is installed successfully after runtime preparation.
44+
45+
#### Scenario: Fresh Codex install
46+
47+
- **WHEN** the runtime is compatible and Codex is not installed
48+
- **THEN** the installer SHALL install Codex
49+
- **AND** it SHALL verify the installation before continuing
50+
51+
#### Scenario: Existing Codex install
52+
53+
- **WHEN** Codex is already installed
54+
- **THEN** the installer SHALL detect the existing installation
55+
- **AND** it SHALL decide whether to keep or upgrade it according to the bootstrap flow
56+
57+
### Requirement: Preserve ccman-equivalent Codex defaults
58+
59+
The bootstrap flow SHALL preserve the same intended Codex provider/model defaults as ccman's Codex setup flow for the final setup step, while remaining self-contained.
60+
61+
#### Scenario: Apply provider configuration
62+
63+
- **WHEN** Codex installation succeeds and the user proceeds to configuration
64+
- **THEN** the installer SHALL write Codex configuration without requiring a local `ccman` installation
65+
- **AND** it SHALL preserve the current provider/model defaults expected from ccman's Codex setup flow
66+
- **AND** it SHALL back up existing Codex config files before overwriting them
67+
68+
### Requirement: Explainable decisions
69+
70+
The bootstrap flow SHALL explain what it detected and what action it will take before changing the machine.
71+
72+
#### Scenario: Dry-run or interactive review
73+
74+
- **WHEN** the installer evaluates the environment
75+
- **THEN** it SHALL surface the detected platform, runtime state, manager state, and chosen remediation path in a user-readable summary
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## 1. Implementation
2+
3+
- [x] 1.1 Add spec and design for Codex bootstrap installer
4+
- [x] 1.2 Add cross-platform bootstrap entrypoints for macOS/Linux and Windows
5+
- [x] 1.3 Add runtime detection for Node.js, npm, Codex, and common version managers
6+
- [x] 1.4 Add runtime remediation flow that prefers reuse, then existing manager, then safe bootstrap options
7+
- [x] 1.5 Add Codex CLI install/upgrade verification flow
8+
- [x] 1.6 Replace repo-dependent configuration handoff with self-contained Codex config writing
9+
- [x] 1.7 Update simulation-only tests for standalone download-and-run coverage
10+
- [x] 1.8 Update docs for direct script distribution and usage

packages/aicoding/README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
-**轻量依赖**:使用 inquirer 提供清晰的交互式选择
88
-**一键配置**:支持同时配置多个工具(默认 Codex + OpenCode)
99
-**两种模式**:保护模式(默认)+ 全覆盖模式
10+
-**自动测速选线**:启动时测试多条 GMN 线路,默认选中当前机器延迟最低地址
1011
-**配置保护**:保留用户现有配置,只更新认证字段
1112
-**原子性写入**:使用临时文件 + rename,确保安全
1213

@@ -32,6 +33,7 @@ curl -fsSL https://raw.githubusercontent.com/2ue/ccman/main/scripts/aicoding.sh
3233
```
3334

3435
说明:脚本会自动调用 `npx --yes @2ue/aicoding` 并保持交互式输入。
36+
未显式传入 `--openai-base-url` / `--base-url` 时,会先测速候选 GMN 域名并允许手动切换。
3537

3638
传参示例(将参数传给 aicoding):
3739

@@ -95,12 +97,14 @@ npx @2ue/aicoding sk-ant-xxx
9597
交互式流程会提示选择平台(OpenClaw 可选但默认不选中);如需自定义 Codex/OpenCode 的 OpenAI Base URL,可通过参数指定。
9698

9799
**可选:指定 Codex/OpenCode 的 OpenAI Base URL**
100+
98101
```bash
99102
# 使用指定 Base URL(仅影响 Codex/OpenCode)
100103
npx @2ue/aicoding sk-ant-xxx --openai-base-url https://gmn.chuangzuoli.com
101104
```
102105

103106
**保护的配置**
107+
104108
- **OpenCode**: 其他 provider 配置
105109
- **Codex**: `config.toml/auth.json` 会先备份为 `.bak`,再覆盖写入(不保留手动修改)
106110
- **OpenCode**: 写入前会备份 `opencode.json`
@@ -119,17 +123,18 @@ npx @2ue/aicoding sk-ant-xxx --overwrite
119123
```
120124

121125
**警告**:全覆盖模式会丢失你的自定义配置,只在以下情况使用:
126+
122127
- 配置文件损坏
123128
- 需要重置为默认配置
124129
- 确认要丢弃现有配置
125130

126131
## 配置的工具
127132

128-
| 工具 | 配置文件 | 说明 |
129-
|------|---------|------|
130-
| **Codex** | `~/.codex/config.toml`<br>`~/.codex/auth.json` | `config.toml/auth.json` 会先备份为 `.bak` 再覆盖写入;`auth.json` 仅保留 `OPENAI_API_KEY``config.toml` 仅保留一个 `model_providers` |
131-
| **OpenCode** | `~/.config/opencode/opencode.json` | 更新 `provider.gmn` 配置 |
132-
| **OpenClaw** | `~/.openclaw/openclaw.json`<br>`~/.openclaw/agents/main/agent/models.json` | 写入前会备份为 `.bak`,然后覆盖写入;端点使用 `https://gmn.chuangzuoli.com/v1` |
133+
| 工具 | 配置文件 | 说明 |
134+
| ------------ | -------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------- |
135+
| **Codex** | `~/.codex/config.toml`<br>`~/.codex/auth.json` | `config.toml/auth.json` 会先备份为 `.bak` 再覆盖写入;`auth.json` 仅保留 `OPENAI_API_KEY``config.toml` 仅保留一个 `model_providers` |
136+
| **OpenCode** | `~/.config/opencode/opencode.json` | 更新 `provider.gmn` 配置 |
137+
| **OpenClaw** | `~/.openclaw/openclaw.json`<br>`~/.openclaw/agents/main/agent/models.json` | 写入前会备份为 `.bak`,然后覆盖写入;端点使用 `https://gmn.chuangzuoli.com/v1` |
133138

134139
## 示例
135140

@@ -185,15 +190,16 @@ $ npx @2ue/aicoding --overwrite
185190

186191
## 与 ccman 的区别
187192

188-
| 特性 | aicoding | ccman |
189-
|------|----------|-------|
190-
| **用途** | 一键配置 GMN | 完整的服务商管理工具 |
191-
| **依赖** | 轻量依赖(inquirer) | 需要安装 ccman |
192-
| **功能** | 只配置 GMN | 管理多个服务商、CRUD 操作 |
193-
| **使用场景** | 快速配置、临时使用 | 日常管理、频繁切换 |
194-
| **命令** | `npx @2ue/aicoding` | `ccman gmn <apiKey>` |
193+
| 特性 | aicoding | ccman |
194+
| ------------ | -------------------- | ------------------------- |
195+
| **用途** | 一键配置 GMN | 完整的服务商管理工具 |
196+
| **依赖** | 轻量依赖(inquirer) | 需要安装 ccman |
197+
| **功能** | 只配置 GMN | 管理多个服务商、CRUD 操作 |
198+
| **使用场景** | 快速配置、临时使用 | 日常管理、频繁切换 |
199+
| **命令** | `npx @2ue/aicoding` | `ccman gmn <apiKey>` |
195200

196201
**推荐**
202+
197203
- ✅ 使用 `@2ue/aicoding`:如果你只想快速配置 GMN
198204
- ✅ 使用 `ccman`:如果你需要管理多个服务商
199205

0 commit comments

Comments
 (0)