xsync-cli 0.1.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.
Files changed (49) hide show
  1. xsync_cli-0.1.0/.gitignore +24 -0
  2. xsync_cli-0.1.0/LICENSE +21 -0
  3. xsync_cli-0.1.0/PKG-INFO +184 -0
  4. xsync_cli-0.1.0/README.md +172 -0
  5. xsync_cli-0.1.0/docs/superpowers/plans/2026-09-13-xsync-cli.md +3144 -0
  6. xsync_cli-0.1.0/docs/superpowers/specs/2026-09-13-xsync-design.md +427 -0
  7. xsync_cli-0.1.0/docs/verification-2026-09-13.md +93 -0
  8. xsync_cli-0.1.0/pyproject.toml +24 -0
  9. xsync_cli-0.1.0/src/xsync_cli/__init__.py +0 -0
  10. xsync_cli-0.1.0/src/xsync_cli/adapters/__init__.py +0 -0
  11. xsync_cli-0.1.0/src/xsync_cli/adapters/codex.py +148 -0
  12. xsync_cli-0.1.0/src/xsync_cli/adapters/codex_config.py +123 -0
  13. xsync_cli-0.1.0/src/xsync_cli/adapters/codex_wiring.py +137 -0
  14. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/__init__.py +0 -0
  15. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/generic-codex.md +116 -0
  16. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/generic-codex.messages.json +1 -0
  17. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/gpt-5.4.md +123 -0
  18. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/gpt-5.4.messages.json +1 -0
  19. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/gpt-5.5.md +148 -0
  20. xsync_cli-0.1.0/src/xsync_cli/adapters/prompts/gpt-5.5.messages.json +1 -0
  21. xsync_cli-0.1.0/src/xsync_cli/adapters/rules/__init__.py +0 -0
  22. xsync_cli-0.1.0/src/xsync_cli/adapters/rules/codex.toml +64 -0
  23. xsync_cli-0.1.0/src/xsync_cli/cli.py +321 -0
  24. xsync_cli-0.1.0/src/xsync_cli/core/__init__.py +0 -0
  25. xsync_cli-0.1.0/src/xsync_cli/core/atomic.py +28 -0
  26. xsync_cli-0.1.0/src/xsync_cli/core/diff.py +81 -0
  27. xsync_cli-0.1.0/src/xsync_cli/core/filters.py +33 -0
  28. xsync_cli-0.1.0/src/xsync_cli/core/model.py +35 -0
  29. xsync_cli-0.1.0/src/xsync_cli/core/profiles.py +166 -0
  30. xsync_cli-0.1.0/src/xsync_cli/sources/__init__.py +0 -0
  31. xsync_cli-0.1.0/src/xsync_cli/sources/openai_compat.py +117 -0
  32. xsync_cli-0.1.0/tests/__init__.py +0 -0
  33. xsync_cli-0.1.0/tests/fixtures/__init__.py +0 -0
  34. xsync_cli-0.1.0/tests/fixtures/ninerouter_models.json +35 -0
  35. xsync_cli-0.1.0/tests/fixtures/plain_openai_models.json +6 -0
  36. xsync_cli-0.1.0/tests/test_atomic.py +41 -0
  37. xsync_cli-0.1.0/tests/test_cli_codex.py +141 -0
  38. xsync_cli-0.1.0/tests/test_cli_profiles.py +102 -0
  39. xsync_cli-0.1.0/tests/test_codex_config.py +104 -0
  40. xsync_cli-0.1.0/tests/test_codex_render.py +182 -0
  41. xsync_cli-0.1.0/tests/test_codex_wiring.py +143 -0
  42. xsync_cli-0.1.0/tests/test_diff.py +50 -0
  43. xsync_cli-0.1.0/tests/test_filters.py +55 -0
  44. xsync_cli-0.1.0/tests/test_model.py +41 -0
  45. xsync_cli-0.1.0/tests/test_openai_compat.py +116 -0
  46. xsync_cli-0.1.0/tests/test_package_data.py +18 -0
  47. xsync_cli-0.1.0/tests/test_profiles.py +114 -0
  48. xsync_cli-0.1.0/tools/extract_prompts.py +82 -0
  49. xsync_cli-0.1.0/uv.lock +93 -0
@@ -0,0 +1,24 @@
1
+ # Secrets
2
+ .env
3
+ .env.*
4
+ *.pypirc
5
+
6
+ # Python
7
+ __pycache__/
8
+ *.py[cod]
9
+ *.egg-info/
10
+ .eggs/
11
+ build/
12
+ dist/
13
+ .venv/
14
+ venv/
15
+
16
+ # Tooling
17
+ .pytest_cache/
18
+ .ruff_cache/
19
+ .mypy_cache/
20
+ .coverage
21
+ htmlcov/
22
+
23
+ # macOS
24
+ .DS_Store
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Alienstro
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,184 @@
1
+ Metadata-Version: 2.5
2
+ Name: xsync-cli
3
+ Version: 0.1.0
4
+ Summary: Sync the model list of an OpenAI-compatible endpoint into the Codex model catalog.
5
+ License-Expression: MIT
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.11
8
+ Requires-Dist: tomlkit>=0.13
9
+ Provides-Extra: dev
10
+ Requires-Dist: pytest>=8.0; extra == 'dev'
11
+ Description-Content-Type: text/markdown
12
+
13
+ # xsync-cli
14
+
15
+ Sync the model list of an OpenAI-compatible endpoint into the Codex model
16
+ catalog.
17
+
18
+ Codex reads its model list from a large JSON catalog file. A person must
19
+ write that file by hand. The file becomes wrong when the endpoint adds a
20
+ model or drops a model. `xsync` writes the file for you.
21
+
22
+ xsync codex
23
+ wrote 35 models to /Users/you/.codex/9router-models.json
24
+
25
+ ## Install
26
+
27
+ uv tool install xsync-cli
28
+
29
+ Or:
30
+
31
+ pipx install xsync-cli
32
+
33
+ The package needs Python 3.11 or later. The command is `xsync`.
34
+
35
+ ## Start
36
+
37
+ ### 1. Make a profile
38
+
39
+ xsync setup
40
+
41
+ The command asks for the profile name, the base URL, and the API key. Leave
42
+ the key empty when the endpoint needs none. The command then reads the
43
+ endpoint and shows every model that it serves.
44
+
45
+ The last question asks for the wire API:
46
+
47
+ - `chat` — most OpenAI-compatible servers.
48
+ - `responses` — the OpenAI Responses API.
49
+
50
+ A wrong value breaks every request. Ask the operator of the endpoint when
51
+ you do not know.
52
+
53
+ ### 2. Connect Codex to the endpoint
54
+
55
+ xsync codex --init
56
+
57
+ The command adds `[model_providers.<profile>]` to `~/.codex/config.toml` and
58
+ points `model_catalog_json` at the catalog of the profile. Run this one time
59
+ for each endpoint.
60
+
61
+ ### 3. Sync
62
+
63
+ xsync codex
64
+
65
+ Run this command again when the endpoint changes.
66
+
67
+ ## Commands
68
+
69
+ | Command | Action |
70
+ |---|---|
71
+ | `xsync setup` | Make a profile. |
72
+ | `xsync list` | Show the profiles. The active profile has a star. |
73
+ | `xsync use <name>` | Set the active profile. |
74
+ | `xsync remove <name>` | Delete a profile. |
75
+ | `xsync codex` | Sync the active profile into the Codex catalog. |
76
+ | `xsync codex --dry-run` | Show the difference. Write nothing. |
77
+ | `xsync codex --profile <name>` | Use another profile for one run. |
78
+ | `xsync codex --init` | Connect Codex to the endpoint of the profile. |
79
+ | `xsync codex --reset` | Remove everything that xSync wrote. |
80
+ | `xsync codex --reset --force` | Reset when no state file exists. |
81
+
82
+ Exit codes: `0` for success, `1` for an error, `2` when the endpoint does not
83
+ answer.
84
+
85
+ ## Switch between endpoints
86
+
87
+ Codex holds one model provider. Therefore one profile is active at a time.
88
+
89
+ xsync codex --profile openrouter --init
90
+
91
+ This command points Codex at the other endpoint and fills the catalog in one
92
+ step.
93
+
94
+ `xsync codex --profile X` without `--init` fills the catalog from X while
95
+ Codex still routes somewhere else. Every model then fails at request time.
96
+ xSync finds this mismatch before it writes, and it stops:
97
+
98
+ catalog would come from "openrouter" (https://openrouter.ai/api/v1)
99
+ but Codex routes to "9router" (http://127.0.0.1:20128/v1)
100
+ run: xsync codex --profile openrouter --init
101
+
102
+ ## The profile file
103
+
104
+ Path: `~/.config/xsync/profiles.toml`. Mode: `0600`.
105
+
106
+ active = "9router"
107
+
108
+ [profiles.9router]
109
+ base_url = "http://127.0.0.1:20128/v1"
110
+ api_key = "sk-..."
111
+ wire_api = "responses"
112
+
113
+ [profiles.openrouter]
114
+ base_url = "https://openrouter.ai/api/v1"
115
+ api_key_env = "OPENROUTER_API_KEY"
116
+ wire_api = "chat"
117
+ exclude = ["*-embedding-*"]
118
+
119
+ A profile uses `api_key` or `api_key_env`, but not both. Use `api_key_env`
120
+ when you share the file. A profile with neither key sends no `Authorization`
121
+ header.
122
+
123
+ The `include` and `exclude` lists hold glob patterns. An empty `include`
124
+ list keeps every model. The `exclude` list always wins.
125
+
126
+ ## Safety
127
+
128
+ - The catalog write is atomic. xSync writes a temporary file, confirms the
129
+ JSON, and then replaces the target. It keeps one backup with the suffix
130
+ `.bak`.
131
+ - The everyday `xsync codex` command never opens `config.toml` for writing.
132
+ Only `--init` and `--reset` do.
133
+ - Codex writes `config.toml` while it runs. Therefore `--init` and `--reset`
134
+ hash the file before the edit and again before the replace. On a
135
+ difference they stop and write nothing.
136
+ - `--reset` removes only what the state file `~/.codex/.xsync-state.json`
137
+ records. It never restores an old copy of `config.toml`, because Codex
138
+ adds project entries to that file over time.
139
+ - With no state file, `--reset` prints the keys that it would remove and
140
+ then stops. Add `--force` to continue.
141
+ - xSync never prints an API key.
142
+
143
+ ## What xSync reads and what it writes
144
+
145
+ | File | Read | Write |
146
+ |---|---|---|
147
+ | `{base_url}/models` | yes | no |
148
+ | `~/.config/xsync/profiles.toml` | yes | yes |
149
+ | `~/.codex/<profile>-models.json` | yes | yes |
150
+ | `~/.codex/config.toml` | yes | only with `--init` or `--reset` |
151
+ | `~/.codex/.xsync-state.json` | yes | only with `--init` or `--reset` |
152
+
153
+ ## The catalog fields
154
+
155
+ The Codex catalog needs 33 fields for each model. The endpoint supplies
156
+ approximately 8 of them:
157
+
158
+ | Codex field | Source |
159
+ |---|---|
160
+ | `slug` | the model id |
161
+ | `context_window`, `max_context_window` | the context window |
162
+ | `input_modalities` | the vision flag |
163
+ | `supported_reasoning_levels` | the reasoning flag |
164
+ | `supports_parallel_tool_calls` | the tool flag |
165
+ | `supports_search_tool` | the search flag |
166
+
167
+ The other fields come from `adapters/rules/codex.toml`. The rules apply in
168
+ three layers. A later layer wins:
169
+
170
+ 1. `[defaults]`
171
+ 2. `[prefix.<first slug segment>]`
172
+ 3. `[slug."<exact slug>"]`
173
+
174
+ Every default value comes from a catalog that works with codex-cli 0.153.4.
175
+
176
+ ## Develop
177
+
178
+ uv run --extra dev pytest
179
+
180
+ No test opens a network connection.
181
+
182
+ ## License
183
+
184
+ MIT.
@@ -0,0 +1,172 @@
1
+ # xsync-cli
2
+
3
+ Sync the model list of an OpenAI-compatible endpoint into the Codex model
4
+ catalog.
5
+
6
+ Codex reads its model list from a large JSON catalog file. A person must
7
+ write that file by hand. The file becomes wrong when the endpoint adds a
8
+ model or drops a model. `xsync` writes the file for you.
9
+
10
+ xsync codex
11
+ wrote 35 models to /Users/you/.codex/9router-models.json
12
+
13
+ ## Install
14
+
15
+ uv tool install xsync-cli
16
+
17
+ Or:
18
+
19
+ pipx install xsync-cli
20
+
21
+ The package needs Python 3.11 or later. The command is `xsync`.
22
+
23
+ ## Start
24
+
25
+ ### 1. Make a profile
26
+
27
+ xsync setup
28
+
29
+ The command asks for the profile name, the base URL, and the API key. Leave
30
+ the key empty when the endpoint needs none. The command then reads the
31
+ endpoint and shows every model that it serves.
32
+
33
+ The last question asks for the wire API:
34
+
35
+ - `chat` — most OpenAI-compatible servers.
36
+ - `responses` — the OpenAI Responses API.
37
+
38
+ A wrong value breaks every request. Ask the operator of the endpoint when
39
+ you do not know.
40
+
41
+ ### 2. Connect Codex to the endpoint
42
+
43
+ xsync codex --init
44
+
45
+ The command adds `[model_providers.<profile>]` to `~/.codex/config.toml` and
46
+ points `model_catalog_json` at the catalog of the profile. Run this one time
47
+ for each endpoint.
48
+
49
+ ### 3. Sync
50
+
51
+ xsync codex
52
+
53
+ Run this command again when the endpoint changes.
54
+
55
+ ## Commands
56
+
57
+ | Command | Action |
58
+ |---|---|
59
+ | `xsync setup` | Make a profile. |
60
+ | `xsync list` | Show the profiles. The active profile has a star. |
61
+ | `xsync use <name>` | Set the active profile. |
62
+ | `xsync remove <name>` | Delete a profile. |
63
+ | `xsync codex` | Sync the active profile into the Codex catalog. |
64
+ | `xsync codex --dry-run` | Show the difference. Write nothing. |
65
+ | `xsync codex --profile <name>` | Use another profile for one run. |
66
+ | `xsync codex --init` | Connect Codex to the endpoint of the profile. |
67
+ | `xsync codex --reset` | Remove everything that xSync wrote. |
68
+ | `xsync codex --reset --force` | Reset when no state file exists. |
69
+
70
+ Exit codes: `0` for success, `1` for an error, `2` when the endpoint does not
71
+ answer.
72
+
73
+ ## Switch between endpoints
74
+
75
+ Codex holds one model provider. Therefore one profile is active at a time.
76
+
77
+ xsync codex --profile openrouter --init
78
+
79
+ This command points Codex at the other endpoint and fills the catalog in one
80
+ step.
81
+
82
+ `xsync codex --profile X` without `--init` fills the catalog from X while
83
+ Codex still routes somewhere else. Every model then fails at request time.
84
+ xSync finds this mismatch before it writes, and it stops:
85
+
86
+ catalog would come from "openrouter" (https://openrouter.ai/api/v1)
87
+ but Codex routes to "9router" (http://127.0.0.1:20128/v1)
88
+ run: xsync codex --profile openrouter --init
89
+
90
+ ## The profile file
91
+
92
+ Path: `~/.config/xsync/profiles.toml`. Mode: `0600`.
93
+
94
+ active = "9router"
95
+
96
+ [profiles.9router]
97
+ base_url = "http://127.0.0.1:20128/v1"
98
+ api_key = "sk-..."
99
+ wire_api = "responses"
100
+
101
+ [profiles.openrouter]
102
+ base_url = "https://openrouter.ai/api/v1"
103
+ api_key_env = "OPENROUTER_API_KEY"
104
+ wire_api = "chat"
105
+ exclude = ["*-embedding-*"]
106
+
107
+ A profile uses `api_key` or `api_key_env`, but not both. Use `api_key_env`
108
+ when you share the file. A profile with neither key sends no `Authorization`
109
+ header.
110
+
111
+ The `include` and `exclude` lists hold glob patterns. An empty `include`
112
+ list keeps every model. The `exclude` list always wins.
113
+
114
+ ## Safety
115
+
116
+ - The catalog write is atomic. xSync writes a temporary file, confirms the
117
+ JSON, and then replaces the target. It keeps one backup with the suffix
118
+ `.bak`.
119
+ - The everyday `xsync codex` command never opens `config.toml` for writing.
120
+ Only `--init` and `--reset` do.
121
+ - Codex writes `config.toml` while it runs. Therefore `--init` and `--reset`
122
+ hash the file before the edit and again before the replace. On a
123
+ difference they stop and write nothing.
124
+ - `--reset` removes only what the state file `~/.codex/.xsync-state.json`
125
+ records. It never restores an old copy of `config.toml`, because Codex
126
+ adds project entries to that file over time.
127
+ - With no state file, `--reset` prints the keys that it would remove and
128
+ then stops. Add `--force` to continue.
129
+ - xSync never prints an API key.
130
+
131
+ ## What xSync reads and what it writes
132
+
133
+ | File | Read | Write |
134
+ |---|---|---|
135
+ | `{base_url}/models` | yes | no |
136
+ | `~/.config/xsync/profiles.toml` | yes | yes |
137
+ | `~/.codex/<profile>-models.json` | yes | yes |
138
+ | `~/.codex/config.toml` | yes | only with `--init` or `--reset` |
139
+ | `~/.codex/.xsync-state.json` | yes | only with `--init` or `--reset` |
140
+
141
+ ## The catalog fields
142
+
143
+ The Codex catalog needs 33 fields for each model. The endpoint supplies
144
+ approximately 8 of them:
145
+
146
+ | Codex field | Source |
147
+ |---|---|
148
+ | `slug` | the model id |
149
+ | `context_window`, `max_context_window` | the context window |
150
+ | `input_modalities` | the vision flag |
151
+ | `supported_reasoning_levels` | the reasoning flag |
152
+ | `supports_parallel_tool_calls` | the tool flag |
153
+ | `supports_search_tool` | the search flag |
154
+
155
+ The other fields come from `adapters/rules/codex.toml`. The rules apply in
156
+ three layers. A later layer wins:
157
+
158
+ 1. `[defaults]`
159
+ 2. `[prefix.<first slug segment>]`
160
+ 3. `[slug."<exact slug>"]`
161
+
162
+ Every default value comes from a catalog that works with codex-cli 0.153.4.
163
+
164
+ ## Develop
165
+
166
+ uv run --extra dev pytest
167
+
168
+ No test opens a network connection.
169
+
170
+ ## License
171
+
172
+ MIT.