codex-workspaces 0.1.0__tar.gz → 0.2.0__tar.gz
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.
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/CHANGELOG.md +12 -6
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/MANIFEST.in +0 -1
- {codex_workspaces-0.1.0/src/codex_workspaces.egg-info → codex_workspaces-0.2.0}/PKG-INFO +87 -17
- codex_workspaces-0.2.0/README.MD +210 -0
- codex_workspaces-0.2.0/README.zh-CN.md +210 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/docs/DESIGN.zh-CN.md +32 -12
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/docs/RELEASE.zh-CN.md +8 -8
- codex_workspaces-0.2.0/docs/TESTING.zh-CN.md +140 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/pyproject.toml +1 -1
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces/__init__.py +1 -1
- codex_workspaces-0.2.0/src/codex_workspaces/cli.py +277 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces/config.py +29 -2
- codex_workspaces-0.2.0/src/codex_workspaces/core.py +1438 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces/platforms.py +8 -3
- codex_workspaces-0.2.0/src/codex_workspaces/stats.py +170 -0
- codex_workspaces-0.2.0/src/codex_workspaces/store.py +339 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0/src/codex_workspaces.egg-info}/PKG-INFO +87 -17
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces.egg-info/SOURCES.txt +2 -1
- codex_workspaces-0.2.0/tests/test_cli.py +134 -0
- codex_workspaces-0.2.0/tests/test_core.py +567 -0
- codex_workspaces-0.1.0/README.MD +0 -140
- codex_workspaces-0.1.0/README.zh-CN.md +0 -140
- codex_workspaces-0.1.0/codex-workspaces +0 -829
- codex_workspaces-0.1.0/docs/TESTING.zh-CN.md +0 -75
- codex_workspaces-0.1.0/src/codex_workspaces/cli.py +0 -95
- codex_workspaces-0.1.0/src/codex_workspaces/core.py +0 -531
- codex_workspaces-0.1.0/tests/test_cli.py +0 -58
- codex_workspaces-0.1.0/tests/test_core.py +0 -189
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/setup.cfg +0 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces/__main__.py +0 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces/errors.py +0 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces.egg-info/dependency_links.txt +0 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces.egg-info/entry_points.txt +0 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces.egg-info/requires.txt +0 -0
- {codex_workspaces-0.1.0 → codex_workspaces-0.2.0}/src/codex_workspaces.egg-info/top_level.txt +0 -0
|
@@ -11,6 +11,13 @@ This project follows a simple changelog format while it is still pre-release.
|
|
|
11
11
|
- Added the cross-platform Python 3 package with the `codex-workspaces` console script.
|
|
12
12
|
- Added Linux/macOS symlink switching and Windows symlink/junction support.
|
|
13
13
|
- Added Python unit tests for workspace validation, creation, migration, switching, CLI dispatch, and platform safety behavior.
|
|
14
|
+
- Added `doctor` diagnostics for platform, path, link, and Codex terminal status.
|
|
15
|
+
- Added workspace size and modified-time metadata to `list`.
|
|
16
|
+
- Added workspace `rename`, guarded `delete --force`, and local `note` management.
|
|
17
|
+
- Added read-only local SQLite token usage stats with `stats`.
|
|
18
|
+
- Added the unified `~/.codex-workspaces/` root with workspace metadata, account snapshots, and default-account restore behavior.
|
|
19
|
+
- Added legacy workspace migration with `migrate`, `migrate --dry-run`, and `init <workspace> --migrate-current`.
|
|
20
|
+
- Added legacy account import with `accounts import-legacy` and workspace auth import with `accounts import-workspaces`.
|
|
14
21
|
- Added `pyproject.toml`, package metadata, editable install support, and PyPI-ready build configuration.
|
|
15
22
|
- Added GitHub Actions CI for Linux, macOS, Windows, and Python 3.9/3.11/3.13.
|
|
16
23
|
- Added GitHub Actions Trusted Publishing workflow for PyPI releases.
|
|
@@ -20,9 +27,7 @@ This project follows a simple changelog format while it is still pre-release.
|
|
|
20
27
|
- Added current workspace inspection.
|
|
21
28
|
- Added workspace switching through the active `~/.codex` symlink.
|
|
22
29
|
- Added Codex app stop, start, and restart commands.
|
|
23
|
-
- Added workspace
|
|
24
|
-
- Added first-time migration with `codex-workspaces create <workspace> --migrate-current`.
|
|
25
|
-
- Added `--migrate` as a short alias for `--migrate-current`.
|
|
30
|
+
- Added workspace initialization with `codex-workspaces init <workspace>`.
|
|
26
31
|
- Added self-install support with `codex-workspaces install [directory]`.
|
|
27
32
|
- Added English and Chinese command output, controlled by system language or `CODEX_WORKSPACES_LANG`.
|
|
28
33
|
- Renamed the command, package, module, docs, and environment variables to `codex-workspaces` / `CODEX_WORKSPACES_*`.
|
|
@@ -33,7 +38,8 @@ This project follows a simple changelog format while it is still pre-release.
|
|
|
33
38
|
- Refuses to switch workspaces when `~/.codex` exists but is not a symlink.
|
|
34
39
|
- Delegates stop, switch, and restart commands to Terminal.app when they are run from a detected Codex terminal environment.
|
|
35
40
|
- Refuses start and migration commands when they are run from a detected Codex terminal environment.
|
|
36
|
-
-
|
|
37
|
-
-
|
|
38
|
-
-
|
|
41
|
+
- Backs up legacy workspace/account sources before migration and never deletes old directories automatically.
|
|
42
|
+
- Keeps login-temp account login flows deferred instead of mixing interactive login into migration.
|
|
43
|
+
- Saves live `auth.json` before account or workspace switches when an active account is configured.
|
|
44
|
+
- Uses a lock file under `~/.codex-workspaces/lock` for account and workspace switching.
|
|
39
45
|
- Limits workspace names to letters, numbers, dots, underscores, and hyphens.
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: codex-workspaces
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Cross-platform Codex workspace switcher with a preserved macOS shell workflow.
|
|
5
5
|
Author: blockchain-project-lives
|
|
6
6
|
Project-URL: Homepage, https://github.com/blockchain-project-lives/codex-workspaces
|
|
@@ -30,21 +30,25 @@ Requires-Dist: twine>=5; extra == "dev"
|
|
|
30
30
|
|
|
31
31
|
English | [简体中文](README.zh-CN.md) | [Changelog](CHANGELOG.md)
|
|
32
32
|
|
|
33
|
-
`codex-workspaces` switches between multiple Codex workspace directories
|
|
33
|
+
`codex-workspaces` switches between multiple Codex workspace directories under `~/.codex-workspaces/workspaces/` and points the active `~/.codex` path at the selected workspace.
|
|
34
34
|
|
|
35
35
|
The project now has two entry points:
|
|
36
36
|
|
|
37
37
|
- A cross-platform Python 3 CLI for Linux, macOS, and Windows.
|
|
38
|
-
- The original macOS Bash script, still kept at [`codex-workspaces`](codex-workspaces), for users who installed the shell workflow directly.
|
|
38
|
+
- The original macOS Bash script, still kept at [`macos/codex-workspaces`](macos/codex-workspaces), for users who installed the shell workflow directly.
|
|
39
39
|
|
|
40
40
|
On macOS, the Python CLI preserves the original app workflow: stop Codex App, switch the workspace link, and start Codex App again. On Linux and Windows, app control is skipped and the CLI only switches the workspace link.
|
|
41
41
|
|
|
42
42
|
## Features
|
|
43
43
|
|
|
44
|
-
- Manage workspace directories such as `~/.codex-work
|
|
44
|
+
- Manage workspace directories such as `~/.codex-workspaces/workspaces/work`.
|
|
45
|
+
- Manage account snapshots under `~/.codex-workspaces/accounts/`.
|
|
45
46
|
- Switch the active `~/.codex` symlink or directory link.
|
|
46
|
-
-
|
|
47
|
+
- Initialize workspace directories with metadata.
|
|
48
|
+
- Temporarily switch the current workspace account with `accounts use`, then restore the workspace default account.
|
|
49
|
+
- Migrate older `~/.codex-<name>` workspaces and import legacy `~/.codex-accounts` auth snapshots.
|
|
47
50
|
- Keep macOS Codex App stop/start/restart support.
|
|
51
|
+
- Show local token usage stats from Codex `state_*.sqlite` in read-only mode.
|
|
48
52
|
- Block unsafe operations from a detected Codex built-in terminal when they cannot be delegated safely.
|
|
49
53
|
- Support English and Chinese output through `CODEX_WORKSPACES_LANG`.
|
|
50
54
|
- Package as a Python project with tests, CI, and PyPI publishing workflow.
|
|
@@ -76,10 +80,10 @@ Install from a local checkout for development:
|
|
|
76
80
|
python3 -m pip install -e ".[dev]"
|
|
77
81
|
```
|
|
78
82
|
|
|
79
|
-
The legacy macOS shell installer is still available:
|
|
83
|
+
The legacy macOS shell installer is still available from the `macos/` directory:
|
|
80
84
|
|
|
81
85
|
```bash
|
|
82
|
-
tmp="$(mktemp -t codex-workspaces.XXXXXX)" && curl -fsSL https://raw.githubusercontent.com/blockchain-project-lives/codex-workspaces/main/codex-workspaces -o "$tmp" && bash "$tmp" install && rm -f "$tmp"
|
|
86
|
+
tmp="$(mktemp -t codex-workspaces.XXXXXX)" && curl -fsSL https://raw.githubusercontent.com/blockchain-project-lives/codex-workspaces/main/macos/codex-workspaces -o "$tmp" && bash "$tmp" install && rm -f "$tmp"
|
|
83
87
|
```
|
|
84
88
|
|
|
85
89
|
## Workspace Layout
|
|
@@ -88,25 +92,67 @@ Default layout:
|
|
|
88
92
|
|
|
89
93
|
```text
|
|
90
94
|
~/.codex -> active workspace link
|
|
91
|
-
~/.codex-
|
|
92
|
-
|
|
95
|
+
~/.codex-workspaces/
|
|
96
|
+
config.json
|
|
97
|
+
state.json
|
|
98
|
+
lock
|
|
99
|
+
workspaces/
|
|
100
|
+
work/
|
|
101
|
+
auth.json
|
|
102
|
+
.codex-workspace.json
|
|
103
|
+
personal/
|
|
104
|
+
auth.json
|
|
105
|
+
.codex-workspace.json
|
|
106
|
+
accounts/
|
|
107
|
+
acct_work/
|
|
108
|
+
auth.json
|
|
109
|
+
meta.json
|
|
93
110
|
```
|
|
94
111
|
|
|
95
|
-
Customize paths with `CODEX_WORKSPACES_LINK` and `
|
|
112
|
+
Customize paths with `CODEX_WORKSPACES_LINK` and `CODEX_WORKSPACES_ROOT`.
|
|
96
113
|
|
|
97
114
|
## Usage
|
|
98
115
|
|
|
99
|
-
|
|
116
|
+
Initialize workspaces:
|
|
100
117
|
|
|
101
118
|
```bash
|
|
102
|
-
codex-workspaces
|
|
103
|
-
codex-workspaces
|
|
119
|
+
codex-workspaces init personal
|
|
120
|
+
codex-workspaces init work
|
|
104
121
|
```
|
|
105
122
|
|
|
106
|
-
|
|
123
|
+
Migrate older `~/.codex-<name>` directories without deleting the originals:
|
|
107
124
|
|
|
108
125
|
```bash
|
|
109
|
-
codex-workspaces
|
|
126
|
+
codex-workspaces migrate --dry-run
|
|
127
|
+
codex-workspaces migrate
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
If your current `~/.codex` is a real directory instead of a link, migrate it into a named workspace explicitly:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
codex-workspaces init personal --migrate-current
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
Set up account snapshots after Codex has created an `auth.json` in the active workspace:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
codex-workspaces use work --no-stop --no-start
|
|
140
|
+
codex-workspaces accounts save work
|
|
141
|
+
codex-workspaces accounts set-default work acct_work --activate
|
|
142
|
+
codex-workspaces accounts list
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
Standalone accounts can be initialized and later populated from the current workspace `auth.json`:
|
|
146
|
+
|
|
147
|
+
```bash
|
|
148
|
+
codex-workspaces accounts init research
|
|
149
|
+
codex-workspaces accounts save research
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Import legacy `codex-accounts` AUTH-mode snapshots:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
codex-workspaces accounts import-legacy ~/.codex-accounts
|
|
110
156
|
```
|
|
111
157
|
|
|
112
158
|
Switch workspaces:
|
|
@@ -128,6 +174,28 @@ Inspect workspaces:
|
|
|
128
174
|
```bash
|
|
129
175
|
codex-workspaces list
|
|
130
176
|
codex-workspaces current
|
|
177
|
+
codex-workspaces doctor
|
|
178
|
+
codex-workspaces stats
|
|
179
|
+
codex-workspaces stats work --days 14
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
Switch accounts within the current workspace:
|
|
183
|
+
|
|
184
|
+
```bash
|
|
185
|
+
codex-workspaces accounts use acct_personal
|
|
186
|
+
codex-workspaces accounts restore-default
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`accounts use` only changes the current workspace `active_account_id`; it does not change `default_account_id`. Entering a workspace with `codex-workspaces use <workspace>` restores that workspace's default account when one is configured.
|
|
190
|
+
|
|
191
|
+
`auth.json` contains credentials. Do not commit workspace directories, account snapshots, SQLite state, sessions, or shell snapshots to git; the project `.gitignore` excludes these patterns for local checkouts.
|
|
192
|
+
|
|
193
|
+
Manage workspace metadata and lifecycle:
|
|
194
|
+
|
|
195
|
+
```bash
|
|
196
|
+
codex-workspaces note work "main paid workspace"
|
|
197
|
+
codex-workspaces rename work main
|
|
198
|
+
codex-workspaces delete old-workspace --force
|
|
131
199
|
```
|
|
132
200
|
|
|
133
201
|
Control Codex App on macOS:
|
|
@@ -138,6 +206,8 @@ codex-workspaces start
|
|
|
138
206
|
codex-workspaces restart
|
|
139
207
|
```
|
|
140
208
|
|
|
209
|
+
`stats` only reads local SQLite files such as `state_*.sqlite` or `sqlite/state_*.sqlite`. It does not call quota or refresh private APIs.
|
|
210
|
+
|
|
141
211
|
## Environment Variables
|
|
142
212
|
|
|
143
213
|
| Variable | Default | Description |
|
|
@@ -145,7 +215,7 @@ codex-workspaces restart
|
|
|
145
215
|
| `CODEX_APP_NAME` | `Codex` | macOS app name to control. |
|
|
146
216
|
| `CODEX_QUIT_TIMEOUT` | `20` | Seconds to wait for app exit. |
|
|
147
217
|
| `CODEX_WORKSPACES_LINK` | `$HOME/.codex` | Active workspace link path. |
|
|
148
|
-
| `
|
|
218
|
+
| `CODEX_WORKSPACES_ROOT` | `$HOME/.codex-workspaces` | Managed root for workspaces, accounts, backups, and lock file. |
|
|
149
219
|
| `CODEX_WORKSPACES_LANG` | auto | Force output language with `en` or `zh`. |
|
|
150
220
|
|
|
151
221
|
Only the `CODEX_WORKSPACES_*` variables are used for workspace-specific configuration.
|
|
@@ -163,6 +233,6 @@ Design, test, and release notes live in [`docs/`](docs/).
|
|
|
163
233
|
|
|
164
234
|
## Publishing
|
|
165
235
|
|
|
166
|
-
CI runs tests on Linux, macOS, and Windows across Python 3.9, 3.11, and 3.13. The `Publish to
|
|
236
|
+
CI runs tests on Linux, macOS, and Windows across Python 3.9, 3.11, and 3.13. The `Publish to TestPyPI` workflow runs for `v*` tags, and the `Publish to PyPI` workflow publishes from `release/v*` branches or manual runs.
|
|
167
237
|
|
|
168
238
|
Configure TestPyPI and PyPI Trusted Publishing for this repository before using the release workflows. See [`docs/RELEASE.zh-CN.md`](docs/RELEASE.zh-CN.md).
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# codex-workspaces
|
|
2
|
+
|
|
3
|
+
English | [简体中文](README.zh-CN.md) | [Changelog](CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
`codex-workspaces` switches between multiple Codex workspace directories under `~/.codex-workspaces/workspaces/` and points the active `~/.codex` path at the selected workspace.
|
|
6
|
+
|
|
7
|
+
The project now has two entry points:
|
|
8
|
+
|
|
9
|
+
- A cross-platform Python 3 CLI for Linux, macOS, and Windows.
|
|
10
|
+
- The original macOS Bash script, still kept at [`macos/codex-workspaces`](macos/codex-workspaces), for users who installed the shell workflow directly.
|
|
11
|
+
|
|
12
|
+
On macOS, the Python CLI preserves the original app workflow: stop Codex App, switch the workspace link, and start Codex App again. On Linux and Windows, app control is skipped and the CLI only switches the workspace link.
|
|
13
|
+
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
- Manage workspace directories such as `~/.codex-workspaces/workspaces/work`.
|
|
17
|
+
- Manage account snapshots under `~/.codex-workspaces/accounts/`.
|
|
18
|
+
- Switch the active `~/.codex` symlink or directory link.
|
|
19
|
+
- Initialize workspace directories with metadata.
|
|
20
|
+
- Temporarily switch the current workspace account with `accounts use`, then restore the workspace default account.
|
|
21
|
+
- Migrate older `~/.codex-<name>` workspaces and import legacy `~/.codex-accounts` auth snapshots.
|
|
22
|
+
- Keep macOS Codex App stop/start/restart support.
|
|
23
|
+
- Show local token usage stats from Codex `state_*.sqlite` in read-only mode.
|
|
24
|
+
- Block unsafe operations from a detected Codex built-in terminal when they cannot be delegated safely.
|
|
25
|
+
- Support English and Chinese output through `CODEX_WORKSPACES_LANG`.
|
|
26
|
+
- Package as a Python project with tests, CI, and PyPI publishing workflow.
|
|
27
|
+
|
|
28
|
+
## Requirements
|
|
29
|
+
|
|
30
|
+
- Python 3.9 or newer for the Python CLI.
|
|
31
|
+
- macOS is required only for Codex App control commands: `start`, `stop`, and `restart`.
|
|
32
|
+
- Linux and macOS use directory symlinks.
|
|
33
|
+
- Windows uses directory symlinks when available and falls back to directory junctions.
|
|
34
|
+
|
|
35
|
+
## Install
|
|
36
|
+
|
|
37
|
+
Install the Python CLI from PyPI:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python3 -m pip install codex-workspaces
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
For isolated CLI installs, `pipx` is recommended:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pipx install codex-workspaces
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Install from a local checkout for development:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
python3 -m pip install -e ".[dev]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
The legacy macOS shell installer is still available from the `macos/` directory:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
tmp="$(mktemp -t codex-workspaces.XXXXXX)" && curl -fsSL https://raw.githubusercontent.com/blockchain-project-lives/codex-workspaces/main/macos/codex-workspaces -o "$tmp" && bash "$tmp" install && rm -f "$tmp"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Workspace Layout
|
|
62
|
+
|
|
63
|
+
Default layout:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
~/.codex -> active workspace link
|
|
67
|
+
~/.codex-workspaces/
|
|
68
|
+
config.json
|
|
69
|
+
state.json
|
|
70
|
+
lock
|
|
71
|
+
workspaces/
|
|
72
|
+
work/
|
|
73
|
+
auth.json
|
|
74
|
+
.codex-workspace.json
|
|
75
|
+
personal/
|
|
76
|
+
auth.json
|
|
77
|
+
.codex-workspace.json
|
|
78
|
+
accounts/
|
|
79
|
+
acct_work/
|
|
80
|
+
auth.json
|
|
81
|
+
meta.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Customize paths with `CODEX_WORKSPACES_LINK` and `CODEX_WORKSPACES_ROOT`.
|
|
85
|
+
|
|
86
|
+
## Usage
|
|
87
|
+
|
|
88
|
+
Initialize workspaces:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
codex-workspaces init personal
|
|
92
|
+
codex-workspaces init work
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Migrate older `~/.codex-<name>` directories without deleting the originals:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
codex-workspaces migrate --dry-run
|
|
99
|
+
codex-workspaces migrate
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
If your current `~/.codex` is a real directory instead of a link, migrate it into a named workspace explicitly:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
codex-workspaces init personal --migrate-current
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
Set up account snapshots after Codex has created an `auth.json` in the active workspace:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
codex-workspaces use work --no-stop --no-start
|
|
112
|
+
codex-workspaces accounts save work
|
|
113
|
+
codex-workspaces accounts set-default work acct_work --activate
|
|
114
|
+
codex-workspaces accounts list
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Standalone accounts can be initialized and later populated from the current workspace `auth.json`:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
codex-workspaces accounts init research
|
|
121
|
+
codex-workspaces accounts save research
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Import legacy `codex-accounts` AUTH-mode snapshots:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
codex-workspaces accounts import-legacy ~/.codex-accounts
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
Switch workspaces:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
codex-workspaces work
|
|
134
|
+
codex-workspaces use personal
|
|
135
|
+
codex-workspaces switch work
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
On macOS, switching stops and restarts Codex App by default. Skip those steps when needed:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
codex-workspaces work --no-stop --no-start
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Inspect workspaces:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
codex-workspaces list
|
|
148
|
+
codex-workspaces current
|
|
149
|
+
codex-workspaces doctor
|
|
150
|
+
codex-workspaces stats
|
|
151
|
+
codex-workspaces stats work --days 14
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
Switch accounts within the current workspace:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
codex-workspaces accounts use acct_personal
|
|
158
|
+
codex-workspaces accounts restore-default
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`accounts use` only changes the current workspace `active_account_id`; it does not change `default_account_id`. Entering a workspace with `codex-workspaces use <workspace>` restores that workspace's default account when one is configured.
|
|
162
|
+
|
|
163
|
+
`auth.json` contains credentials. Do not commit workspace directories, account snapshots, SQLite state, sessions, or shell snapshots to git; the project `.gitignore` excludes these patterns for local checkouts.
|
|
164
|
+
|
|
165
|
+
Manage workspace metadata and lifecycle:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
codex-workspaces note work "main paid workspace"
|
|
169
|
+
codex-workspaces rename work main
|
|
170
|
+
codex-workspaces delete old-workspace --force
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
Control Codex App on macOS:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
codex-workspaces stop
|
|
177
|
+
codex-workspaces start
|
|
178
|
+
codex-workspaces restart
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`stats` only reads local SQLite files such as `state_*.sqlite` or `sqlite/state_*.sqlite`. It does not call quota or refresh private APIs.
|
|
182
|
+
|
|
183
|
+
## Environment Variables
|
|
184
|
+
|
|
185
|
+
| Variable | Default | Description |
|
|
186
|
+
| --- | --- | --- |
|
|
187
|
+
| `CODEX_APP_NAME` | `Codex` | macOS app name to control. |
|
|
188
|
+
| `CODEX_QUIT_TIMEOUT` | `20` | Seconds to wait for app exit. |
|
|
189
|
+
| `CODEX_WORKSPACES_LINK` | `$HOME/.codex` | Active workspace link path. |
|
|
190
|
+
| `CODEX_WORKSPACES_ROOT` | `$HOME/.codex-workspaces` | Managed root for workspaces, accounts, backups, and lock file. |
|
|
191
|
+
| `CODEX_WORKSPACES_LANG` | auto | Force output language with `en` or `zh`. |
|
|
192
|
+
|
|
193
|
+
Only the `CODEX_WORKSPACES_*` variables are used for workspace-specific configuration.
|
|
194
|
+
|
|
195
|
+
## Development
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
python3 -m pip install -e ".[dev]"
|
|
199
|
+
python3 -m pytest
|
|
200
|
+
python3 -m build
|
|
201
|
+
python3 -m twine check dist/*
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Design, test, and release notes live in [`docs/`](docs/).
|
|
205
|
+
|
|
206
|
+
## Publishing
|
|
207
|
+
|
|
208
|
+
CI runs tests on Linux, macOS, and Windows across Python 3.9, 3.11, and 3.13. The `Publish to TestPyPI` workflow runs for `v*` tags, and the `Publish to PyPI` workflow publishes from `release/v*` branches or manual runs.
|
|
209
|
+
|
|
210
|
+
Configure TestPyPI and PyPI Trusted Publishing for this repository before using the release workflows. See [`docs/RELEASE.zh-CN.md`](docs/RELEASE.zh-CN.md).
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
# codex-workspaces
|
|
2
|
+
|
|
3
|
+
[English](README.MD) | 简体中文 | [更新日志](CHANGELOG.md)
|
|
4
|
+
|
|
5
|
+
`codex-workspaces` 用来切换多个 Codex 工作区目录。默认把每个工作区放在 `~/.codex-workspaces/workspaces/` 下,并让当前生效的 `~/.codex` 指向选中的工作区。
|
|
6
|
+
|
|
7
|
+
项目现在有两个入口:
|
|
8
|
+
|
|
9
|
+
- 跨平台 Python 3 CLI,支持 Linux、macOS 和 Windows。
|
|
10
|
+
- 原来的 macOS Bash 脚本,仍保留在 [`codex-workspaces`](macos/codex-workspaces),兼容已经使用 shell 安装方式的用户。
|
|
11
|
+
|
|
12
|
+
在 macOS 上,Python CLI 保留原来的 App 流程:关闭 Codex App、切换工作区链接、再启动 Codex App。在 Linux 和 Windows 上,CLI 会跳过 App 启停,只切换工作区链接。
|
|
13
|
+
|
|
14
|
+
## 功能
|
|
15
|
+
|
|
16
|
+
- 管理 `~/.codex-workspaces/workspaces/work` 这类工作区目录。
|
|
17
|
+
- 管理 `~/.codex-workspaces/accounts/` 下的账号快照。
|
|
18
|
+
- 切换当前 `~/.codex` 软链接或目录链接。
|
|
19
|
+
- 初始化带元数据的工作区目录。
|
|
20
|
+
- 通过 `accounts use` 临时切换当前工作区账号,并可恢复工作区默认账号。
|
|
21
|
+
- 迁移旧版 `~/.codex-<name>` 工作区,并导入旧 `~/.codex-accounts` 账号快照。
|
|
22
|
+
- 保留 macOS 上 Codex App 的 `stop`、`start`、`restart`。
|
|
23
|
+
- 以只读方式读取 Codex `state_*.sqlite`,展示本地 token 用量统计。
|
|
24
|
+
- 在检测到 Codex 内置 Terminal 且无法安全转交时,阻止危险操作。
|
|
25
|
+
- 支持中英文输出,可通过 `CODEX_WORKSPACES_LANG` 指定。
|
|
26
|
+
- 提供 Python 包、测试、GitHub CI 和 PyPI 发布工作流。
|
|
27
|
+
|
|
28
|
+
## 要求
|
|
29
|
+
|
|
30
|
+
- Python 3.9 或更新版本。
|
|
31
|
+
- 只有 `start`、`stop`、`restart` 这类 Codex App 控制命令要求 macOS。
|
|
32
|
+
- Linux 和 macOS 使用目录软链接。
|
|
33
|
+
- Windows 优先使用目录软链接,不可用时回退到目录 junction。
|
|
34
|
+
|
|
35
|
+
## 安装
|
|
36
|
+
|
|
37
|
+
从 PyPI 安装 Python CLI:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
python3 -m pip install codex-workspaces
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
推荐用 `pipx` 做隔离安装:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
pipx install codex-workspaces
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
本地开发安装:
|
|
50
|
+
|
|
51
|
+
```bash
|
|
52
|
+
python3 -m pip install -e ".[dev]"
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
旧版 macOS shell 安装方式仍可从 `macos/` 目录使用:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
tmp="$(mktemp -t codex-workspaces.XXXXXX)" && curl -fsSL https://raw.githubusercontent.com/blockchain-project-lives/codex-workspaces/main/macos/codex-workspaces -o "$tmp" && bash "$tmp" install && rm -f "$tmp"
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 工作区目录
|
|
62
|
+
|
|
63
|
+
默认布局:
|
|
64
|
+
|
|
65
|
+
```text
|
|
66
|
+
~/.codex -> 当前工作区链接
|
|
67
|
+
~/.codex-workspaces/
|
|
68
|
+
config.json
|
|
69
|
+
state.json
|
|
70
|
+
lock
|
|
71
|
+
workspaces/
|
|
72
|
+
work/
|
|
73
|
+
auth.json
|
|
74
|
+
.codex-workspace.json
|
|
75
|
+
personal/
|
|
76
|
+
auth.json
|
|
77
|
+
.codex-workspace.json
|
|
78
|
+
accounts/
|
|
79
|
+
acct_work/
|
|
80
|
+
auth.json
|
|
81
|
+
meta.json
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
可通过 `CODEX_WORKSPACES_LINK` 和 `CODEX_WORKSPACES_ROOT` 自定义路径。
|
|
85
|
+
|
|
86
|
+
## 使用
|
|
87
|
+
|
|
88
|
+
初始化工作区:
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
codex-workspaces init personal
|
|
92
|
+
codex-workspaces init work
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
迁移旧版 `~/.codex-<name>` 目录,不会自动删除旧目录:
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
codex-workspaces migrate --dry-run
|
|
99
|
+
codex-workspaces migrate
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
如果当前 `~/.codex` 是真实目录而不是链接,需要显式迁移成一个命名工作区:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
codex-workspaces init personal --migrate-current
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
在 Codex 已经在当前工作区写入 `auth.json` 后,设置账号快照:
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
codex-workspaces use work --no-stop --no-start
|
|
112
|
+
codex-workspaces accounts save work
|
|
113
|
+
codex-workspaces accounts set-default work acct_work --activate
|
|
114
|
+
codex-workspaces accounts list
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
单独账号可以先初始化,再从当前工作区的 `auth.json` 保存进去:
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
codex-workspaces accounts init research
|
|
121
|
+
codex-workspaces accounts save research
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
导入旧 `codex-accounts` 的 AUTH 模式账号快照:
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
codex-workspaces accounts import-legacy ~/.codex-accounts
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
切换工作区:
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
codex-workspaces work
|
|
134
|
+
codex-workspaces use personal
|
|
135
|
+
codex-workspaces switch work
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
macOS 上默认会在切换前后关闭和启动 Codex App。需要时可以跳过:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
codex-workspaces work --no-stop --no-start
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
查看工作区:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
codex-workspaces list
|
|
148
|
+
codex-workspaces current
|
|
149
|
+
codex-workspaces doctor
|
|
150
|
+
codex-workspaces stats
|
|
151
|
+
codex-workspaces stats work --days 14
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
在当前工作区临时切换账号:
|
|
155
|
+
|
|
156
|
+
```bash
|
|
157
|
+
codex-workspaces accounts use acct_personal
|
|
158
|
+
codex-workspaces accounts restore-default
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
`accounts use` 只修改当前工作区的 `active_account_id`,不会修改 `default_account_id`。执行 `codex-workspaces use <工作区>` 进入某个工作区时,如果配置了默认账号,会恢复该工作区默认账号。
|
|
162
|
+
|
|
163
|
+
`auth.json` 包含认证凭据,不要提交到 git。工作区目录、账号快照、SQLite 状态、sessions 和 shell snapshots 已在本项目 `.gitignore` 中排除。
|
|
164
|
+
|
|
165
|
+
管理工作区备注和生命周期:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
codex-workspaces note work "主力付费工作区"
|
|
169
|
+
codex-workspaces rename work main
|
|
170
|
+
codex-workspaces delete old-workspace --force
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
macOS 上控制 Codex App:
|
|
174
|
+
|
|
175
|
+
```bash
|
|
176
|
+
codex-workspaces stop
|
|
177
|
+
codex-workspaces start
|
|
178
|
+
codex-workspaces restart
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
`stats` 只读取本地 SQLite 文件,例如 `state_*.sqlite` 或 `sqlite/state_*.sqlite`。它不会调用 quota 或 refresh 私有接口。
|
|
182
|
+
|
|
183
|
+
## 环境变量
|
|
184
|
+
|
|
185
|
+
| 变量 | 默认值 | 说明 |
|
|
186
|
+
| --- | --- | --- |
|
|
187
|
+
| `CODEX_APP_NAME` | `Codex` | macOS App 名称。 |
|
|
188
|
+
| `CODEX_QUIT_TIMEOUT` | `20` | 等待 App 退出的秒数。 |
|
|
189
|
+
| `CODEX_WORKSPACES_LINK` | `$HOME/.codex` | 当前工作区链接路径。 |
|
|
190
|
+
| `CODEX_WORKSPACES_ROOT` | `$HOME/.codex-workspaces` | workspaces、accounts、backups 和 lock 所在管理根目录。 |
|
|
191
|
+
| `CODEX_WORKSPACES_LANG` | 自动 | 强制输出语言,可设为 `en` 或 `zh`。 |
|
|
192
|
+
|
|
193
|
+
工作区相关配置只使用 `CODEX_WORKSPACES_*` 变量。
|
|
194
|
+
|
|
195
|
+
## 开发
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
python3 -m pip install -e ".[dev]"
|
|
199
|
+
python3 -m pytest
|
|
200
|
+
python3 -m build
|
|
201
|
+
python3 -m twine check dist/*
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
设计、测试和发布说明见 [`docs/`](docs/)。
|
|
205
|
+
|
|
206
|
+
## 发布
|
|
207
|
+
|
|
208
|
+
CI 会在 Linux、macOS、Windows 上测试 Python 3.9、3.11、3.13。`Publish to TestPyPI` 工作流会在 `v*` tag 上运行,`Publish to PyPI` 工作流支持从 `release/v*` 分支或手动触发发布。
|
|
209
|
+
|
|
210
|
+
发布前需要在 TestPyPI 和 PyPI 分别配置 Trusted Publishing。详见 [`docs/RELEASE.zh-CN.md`](docs/RELEASE.zh-CN.md)。
|