Skip to content

Commit be38808

Browse files
committed
Enhance Codex identity management and project launch diagnostics
- Update provider display names for U-M GPT identities in `create_api_identity`. - Improve error handling in `project_direnv_exec` to preserve diagnostics on launch failure. - Add detailed instructions for verifying selected identities in documentation. - Include new sections in `api-providers.md` and `subscriptions.md` for identity management and verification. - Update `build-cheatsheet.py` for clearer instructions on setting up the environment. - Enhance troubleshooting documentation with specific guidance for project launch failures. - Modify tests to ensure environment errors are visible and correctly reported. - Adjust security documentation to clarify credential management and identity separation.
1 parent be05fd5 commit be38808

16 files changed

Lines changed: 368 additions & 141 deletions

‎.github/workflows/ci.yml‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ jobs:
2525
if: runner.os == 'Linux'
2626
run: |
2727
sudo apt-get update
28-
sudo apt-get install --yes direnv expect jq
28+
sudo apt-get install --yes expect jq
29+
# Ubuntu's direnv 2.32.1 expands shell metacharacters in project paths.
30+
# Pin a release containing the upstream path-escaping fix (2.32.2+).
31+
curl --fail --location --silent --show-error \
32+
https://github.com/direnv/direnv/releases/download/v2.37.1/direnv.linux-amd64 \
33+
--output "$RUNNER_TEMP/direnv"
34+
printf '%s %s\n' \
35+
1f1b93dd6f38523fde26dfac96151ef9d31a374e3005cd3345fb93555ae0c9b5 \
36+
"$RUNNER_TEMP/direnv" | sha256sum --check
37+
sudo install -m 0755 "$RUNNER_TEMP/direnv" /usr/local/bin/direnv
2938
3039
- name: Install macOS dependencies
3140
if: runner.os == 'macOS'

‎INSTALLATION.md‎

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,11 @@ The helper runs on macOS and Linux with Bash 3.2 or newer.
5656

5757
| Use | Requirements |
5858
|---|---|
59-
| Run Codex from the terminal | Git, Codex CLI, `curl`, and `jq` |
60-
| Select an identity by project | Also install `direnv` |
59+
| Run Codex from the terminal | Git, Codex CLI, and `jq` |
60+
| Discover API models or generate a model snapshot | Also install `curl` 7.76.0 or newer |
61+
| Select an identity by project | Also install `direnv` 2.32.2 or newer |
6162
| Open labeled VS Code windows | Also install VS Code and the Codex extension |
62-
| Run the tests | Also install `direnv` and `expect` |
63+
| Run the tests | Also install `direnv` 2.32.2 or newer and `expect` |
6364
| Open projects from Finder | macOS only |
6465

6566
### macOS
@@ -70,8 +71,11 @@ With [Homebrew](https://brew.sh/):
7071
brew install git direnv jq
7172
```
7273

73-
macOS includes `curl` and normally includes `expect`. If `expect -v` fails, run
74-
`brew install expect`. Install or update the Codex CLI by following the
74+
macOS includes `curl`; check `curl --version` and use `brew install curl` if it
75+
is older than 7.76.0 and you need model discovery. Follow Homebrew's PATH
76+
instructions so `curl --version` reports the newer version. macOS normally
77+
includes `expect`; if `expect -v` fails, run `brew install expect`.
78+
Install or update the Codex CLI by following the
7579
[official Codex CLI guide](https://learn.chatgpt.com/docs/codex/cli). If you
7680
plan to use VS Code, install VS Code and follow the
7781
[official Codex IDE guide](https://learn.chatgpt.com/docs/codex/ide).
@@ -83,6 +87,13 @@ sudo apt update
8387
sudo apt install bash curl direnv expect git jq
8488
```
8589

90+
Check `curl --version` (7.76.0 or newer for model discovery) and
91+
`direnv version`. If `direnv` is older than 2.32.2, upgrade using the
92+
[official installation guide](https://direnv.net/docs/installation.html).
93+
Earlier releases incorrectly expand shell characters such as `$` in project
94+
paths; the launcher requires the upstream path-escaping fix.
95+
See the [direnv 2.32.2 release notes](https://github.com/direnv/direnv/releases/tag/v2.32.2).
96+
8697
Then install or update the Codex CLI using the
8798
[official Codex CLI guide](https://learn.chatgpt.com/docs/codex/cli). Install
8899
VS Code and the Codex extension only if you want the IDE workflow.
@@ -139,8 +150,10 @@ creates disposable identities in a temporary directory and uses mock commands;
139150
it does not need your credentials or contact a provider. If the final pass line
140151
does not appear, see [Troubleshooting](docs/troubleshooting.md).
141152

142-
The examples in this repository use `./bin/codex-home`, so adding the helper to
143-
`PATH` is optional. To run `codex-home` from any directory in future terminals,
153+
Run examples beginning with `./bin/codex-home` from the clone directory.
154+
Examples using bare `codex-home` require its `bin` directory on `PATH`, either
155+
from the shell setting below or from an approved generated project `.envrc`.
156+
To run `codex-home` from any directory in future terminals,
144157
add this line to `~/.zshrc` for zsh or `~/.bashrc` for Bash:
145158

146159
```bash
@@ -160,10 +173,10 @@ Choose the guide for the identity you need:
160173
- [Responses-compatible API providers and Azure](docs/api-providers.md)
161174
- [Optional U-M GPT setup](docs/umgpt.md)
162175

163-
From the clone directory, run `./bin/codex-home run NAME`, replacing `NAME`
164-
with the identity you created. To select an identity automatically for a
165-
project or open a labeled VS Code window,
166-
[assign the identity to a project](docs/projects-vscode.md). On macOS, you can
176+
After creating the identity, [verify its configuration and sign-in](docs/commands.md#check-the-selected-identity).
177+
Then [assign it to a project](docs/projects-vscode.md): generate the files,
178+
review them, approve `.envrc`, and launch. This selects the identity automatically
179+
for that project or opens a labeled VS Code window. On macOS, you can
167180
also install the optional [Finder Quick Action](docs/macos-open-with.md):
168181

169182
```bash

‎README.md‎

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and Linux, with optional `direnv`, VS Code, and macOS Finder integration.
1010

1111
Developed at the [Fritsche Lab](https://fritschelab.org/), University of Michigan.
1212

13+
**New here?** Follow [Installation](INSTALLATION.md) for the complete macOS or
14+
Linux setup, from prerequisites through your first identity and project.
15+
1316
## One account choice per project
1417

1518
Each project's `.envrc` selects an identity and its `CODEX_HOME`. The account,
@@ -68,13 +71,8 @@ and session history. Each VS Code window shows the identity name, with a
6871
separate VS Code user-data directory per identity. In a configured project's
6972
terminal, start the selected context with `codex-home run`.
7073

71-
On macOS, the helper opens a named editor copy: hover over its running Dock
72-
icon to read `VS Code - NAME`. Projects using the same identity reuse its
73-
instance. In Finder, use **Quick Actions > Open in Codex Project** for a
74-
configured folder. File managers with folder **Open With** menus can use the
75-
matching **VS Code - NAME** handler. You can also use `codex-home`; do not pin or directly open the
76-
generated editor copy, which needs the helper's launch environment. See
77-
[macOS Dock names](docs/projects-vscode.md#macos-dock-names).
74+
On macOS, the helper also gives each identity a [named Dock icon](docs/projects-vscode.md#macos-dock-names)
75+
and offers optional [Finder integration](docs/macos-open-with.md).
7876

7977
The CLI launcher keeps **[CODEX: NAME]** in the terminal tab/window title.
8078

@@ -85,44 +83,52 @@ sandbox. Keep credentials and identity homes private. See the
8583

8684
## Get started
8785

88-
[Install the prerequisites and clone the repository](INSTALLATION.md).
89-
The helper runs without administrator rights; installing some prerequisites
90-
may require them.
86+
If the prerequisites are installed and the clone is ready, use this quick path.
87+
Otherwise, begin with [Installation](INSTALLATION.md). The helper runs without
88+
administrator rights; installing some prerequisites may require them.
9189

9290
From the clone directory, create a ChatGPT identity and sign in:
9391

9492
```bash
9593
./bin/codex-home create-subscription personal
9694
./bin/codex-home login personal
95+
```
96+
97+
Check the intended account and workspace in the browser during sign-in. Then
98+
check the CLI authentication method and launch a session:
99+
100+
```bash
101+
./bin/codex-home run personal login status
97102
./bin/codex-home run personal
98103
```
99104

105+
In the CLI, use `/status` to inspect the active model and session configuration.
106+
The identity name is a local label; see [verification for CLI and VS Code](docs/commands.md#check-the-selected-identity).
107+
100108
For an API key, follow the [API provider](docs/api-providers.md) or
101109
[U-M GPT](docs/umgpt.md) guide. Each guide covers access, billing, and a test of
102110
Codex tool calls with your selected model.
103111

104-
U-M GPT model recommendations are kept in the visible, version-controlled
105-
file [`config/umgpt-models.toml`](config/umgpt-models.toml). Users can keep
106-
different local defaults in `~/.codex-homes/umgpt-models.toml`; run
107-
`codex-home umgpt-defaults` to compare them. Neither file is a model catalog:
108-
`codex-home models umgpt` and `codex-home models umgpt-low` query the gateway's
109-
current scoped model lists. The dated
110-
[model snapshot](docs/umgpt-models-snapshot.md) records one credential's
111-
observed catalog for review only; it is not used at runtime or an approval
112-
list.
113-
114-
To use your identity for a project in VS Code:
112+
After exiting Codex, use your identity for a project in VS Code:
115113

116114
```bash
117115
./bin/codex-home project personal "/path/to/project"
116+
```
117+
118+
Review the generated `.envrc` and `.vscode/<folder-name>.code-workspace`.
119+
The `.envrc` contains executable shell code and local paths. Then approve it
120+
and launch:
121+
122+
```bash
118123
direnv allow "/path/to/project"
119124
./bin/codex-home vscode personal "/path/to/project"
120125
```
121126

122-
Review `.envrc` before running `direnv allow`: it contains executable shell
123-
code and local paths. The helper preserves existing project files and uses
124-
local Git exclusions for the files it generates. Start a new Codex chat and
125-
check `/status` to confirm the account and provider.
127+
The helper preserves existing project files and uses local Git exclusions for
128+
the files it generates. Start a new Codex chat and [verify the extension's
129+
account and selected model](docs/commands.md#check-the-selected-identity).
130+
See [Projects and VS Code](docs/projects-vscode.md) for terminal use and
131+
existing project configuration.
126132

127133
For right-click access on macOS, run `./bin/install-macos-open-with`, then
128134
choose **Quick Actions > Open in Codex Project** on a project folder. The

‎bin/codex-home‎

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -553,8 +553,14 @@ create_api_identity() {
553553
local key_env="$4"
554554
local api_version="${5:-}"
555555
local kind="${6:-api-key}"
556+
local provider_label="Codex identity: $name"
556557
local home
557558

559+
case "$kind" in
560+
umgpt-openai) provider_label="U-M GPT Toolkit ($name)" ;;
561+
umgpt-low) provider_label="U-M GPT Toolkit ($name; LOW-SENSITIVITY DATA ONLY)" ;;
562+
esac
563+
558564
ensure_new_identity "$name"
559565
validate_provider_name "$name"
560566
validate_single_line "base URL" "$base_url"
@@ -574,7 +580,7 @@ create_api_identity() {
574580
printf 'model = %s\n' "$(toml_quote "$model")"
575581
printf 'model_provider = %s\n\n' "$(toml_quote "$name")"
576582
printf '[model_providers.%s]\n' "$name"
577-
printf 'name = %s\n' "$(toml_quote "Codex identity: $name")"
583+
printf 'name = %s\n' "$(toml_quote "$provider_label")"
578584
printf 'base_url = %s\n' "$(toml_quote "$base_url")"
579585
printf 'env_key = %s\n' "$(toml_quote "$key_env")"
580586
if [[ -n "$api_version" ]]; then
@@ -2059,15 +2065,29 @@ review_project_envrc() {
20592065
}
20602066

20612067
project_direnv_exec() {
2062-
env -u CODEX_IDENTITY -u CODEX_HOME \
2068+
local project_dir="$1" launch_status
2069+
shift
2070+
# Older direnv releases also silence log_error when this format is empty.
2071+
# Keep diagnostics visible and stream the command's output without buffering.
2072+
if env -u CODEX_IDENTITY -u CODEX_HOME \
20632073
-u DIRENV_DIFF -u DIRENV_DIR -u DIRENV_FILE -u DIRENV_WATCHES \
2064-
direnv exec "$@"
2074+
DIRENV_LOG_FORMAT="${DIRENV_LOG_FORMAT:-direnv: %s}" \
2075+
direnv exec "$project_dir" "$@"; then
2076+
return 0
2077+
else
2078+
launch_status=$?
2079+
fi
2080+
printf 'codex-home: failed to launch project: %s (exit %s)\n' "$project_dir" "$launch_status" >&2
2081+
printf '%s\n' "codex-home: verify the project's .envrc, required commands, and VS Code CLI; see the diagnostic above" >&2
2082+
return "$launch_status"
20652083
}
20662084

20672085
launch_vscode_project_env() {
20682086
local project_dir="$1" expected_name="$2"
20692087
local project_abs helper vscode_cli extensions_dir homes_root
20702088
command -v direnv >/dev/null 2>&1 || die "direnv is not installed"
2089+
direnv version 2.32.2 >/dev/null ||
2090+
die "direnv 2.32.2 or newer is required for project path escaping; upgrade direnv"
20712091
[[ -d "$project_dir" ]] || die "project directory does not exist: $project_dir"
20722092
project_abs="$(cd "$project_dir" && pwd -P)"
20732093
validate_single_line "project path" "$project_abs"

‎docs/api-providers.md‎

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ Use a separate identity for each API provider or key. The helper can configure
44
Responses-compatible APIs, direct Azure endpoints, and the U-M GPT gateway.
55
Other providers supported by Codex need manual setup.
66

7+
After [installing prerequisites and cloning the repository](../INSTALLATION.md#1-install-prerequisites)
8+
(Installation steps 1–3), run `./bin/codex-home` examples from the clone
9+
directory; bare `codex-home` assumes it is on PATH.
10+
711
## Support matrix
812

913
| Provider | Codex support | Managed by this helper | Setup |
@@ -134,6 +138,30 @@ guardrails; they do not certify that any model, Codex workflow, or data type is
134138
institutionally approved. See [U-M GPT](umgpt.md) for setup and governance
135139
details.
136140

141+
### Provider display names
142+
143+
New U-M identities use `U-M GPT Toolkit (umgpt)` or
144+
`U-M GPT Toolkit (umgpt-low; LOW-SENSITIVITY DATA ONLY)` as the provider
145+
display name. Custom identity names replace `umgpt` or `umgpt-low` in those
146+
labels, so multiple keys remain distinguishable.
147+
148+
For an existing identity, edit only the `name` value in its provider table in
149+
`$CODEX_HOME/config.toml`. For example, in
150+
`~/.codex-homes/umgpt/config.toml`:
151+
152+
```toml
153+
[model_providers.umgpt]
154+
name = "U-M GPT Toolkit (umgpt)"
155+
# Keep the existing base_url, env_key, and wire_api entries here.
156+
```
157+
158+
The [`name` field is Codex's provider display name](https://learn.chatgpt.com/docs/config-file/config-reference).
159+
Keep `model_provider = "umgpt"` and `[model_providers.umgpt]` unchanged:
160+
the helper uses the identity name as the provider ID and checks it at launch.
161+
Restart Codex to use the updated configuration. Display varies by client and
162+
version; CLI `/status` may still show the provider ID. Existing configuration
163+
files are not rewritten automatically when you update this repository.
164+
137165
## Generic bearer-token gateway
138166

139167
```bash
@@ -166,8 +194,9 @@ Create a home per key. The environment-variable names may be distinct:
166194
./bin/codex-home set-key lab-b
167195
```
168196

169-
You can also reuse one variable name: only the selected identity's `.env` is
170-
loaded. Different names can make debugging outside `direnv` easier.
197+
You can also reuse one variable name: the helper loads the selected identity's
198+
`.env`. It does not clear unrelated variables or credentials inherited from
199+
your shell. Different names can make debugging outside `direnv` easier.
171200

172201
## OpenAI Platform API key
173202

@@ -301,23 +330,28 @@ create a small marker file; replace
301330
`research-api` and the repository path as needed:
302331

303332
```bash
304-
CODEX_CONTEXTS="$HOME/Developer/codex-contexts"
305-
SMOKE_DIR="$(mktemp -d)"
306-
git -C "$SMOKE_DIR" init --quiet
307333
(
334+
set -eu
335+
CODEX_CONTEXTS="$HOME/Developer/codex-contexts"
336+
SMOKE_DIR="$(mktemp -d)"
337+
printf 'Smoke-test directory: %s\n' "$SMOKE_DIR"
338+
git -C "$SMOKE_DIR" init --quiet
308339
cd "$SMOKE_DIR"
309340
"$CODEX_CONTEXTS/bin/codex-home" run research-api exec \
310341
--ephemeral \
311342
--sandbox workspace-write \
312343
"Create codex-smoke-test.txt containing exactly OK, using a tool."
344+
test "$(cat codex-smoke-test.txt)" = "OK"
345+
printf 'Tool-call smoke test passed: %s\n' "$SMOKE_DIR"
313346
)
314-
test "$(cat "$SMOKE_DIR/codex-smoke-test.txt")" = "OK"
315-
printf 'Tool-call smoke test passed: %s\n' "$SMOKE_DIR"
316347
```
317348

318349
This request may incur provider charges. Keep research data out of the test.
319350
Inspect the temporary directory, then delete it when you are done.
320351

352+
After validation, [check the selected identity](commands.md#check-the-selected-identity)
353+
and [assign it to a project](projects-vscode.md).
354+
321355
References:
322356

323357
- [Codex custom model providers](https://learn.chatgpt.com/docs/config-file/config-advanced#custom-model-providers)

0 commit comments

Comments
 (0)