codexopt 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.
codexopt-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Shashi
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,475 @@
1
+ Metadata-Version: 2.4
2
+ Name: codexopt
3
+ Version: 0.1.0
4
+ Summary: CodexOpt: Optimize your Agents.MD and Skills for Codex with GEPA
5
+ Author-email: Shashi <shashi@super-agentic.ai>
6
+ License-Expression: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: PyYAML>=6.0
11
+ Provides-Extra: dev
12
+ Requires-Dist: pytest>=8.0; extra == "dev"
13
+ Requires-Dist: ruff>=0.5.0; extra == "dev"
14
+ Requires-Dist: build>=1.2.0; extra == "dev"
15
+ Dynamic: license-file
16
+
17
+ # CodexOpt
18
+
19
+ CodexOpt: Optimize your Agents.MD and Skills for Codex with GEPA
20
+
21
+ CodexOpt is a lightweight Python CLI to improve Codex instruction assets with a repeatable loop:
22
+
23
+ 1. Scan instruction files.
24
+ 2. Benchmark quality.
25
+ 3. Generate optimized candidates.
26
+ 4. Apply only improvements.
27
+ 5. Produce a report.
28
+
29
+ It targets:
30
+
31
+ - `AGENTS.md`
32
+ - `.codex/skills/**/SKILL.md`
33
+
34
+ ## Why CodexOpt
35
+
36
+ Most teams edit `AGENTS.md` and `SKILL.md` manually, but struggle to answer:
37
+
38
+ - Did quality actually improve?
39
+ - Did we increase prompt bloat?
40
+ - Did we break skill frontmatter conventions?
41
+
42
+ CodexOpt turns these edits into measurable runs with artifacts you can inspect and version.
43
+
44
+ ## Features
45
+
46
+ - Project scan with issue detection for agents and skills.
47
+ - Heuristic benchmark scoring.
48
+ - Optimization engine `heuristic` (default, local and deterministic).
49
+ - Optional optimization engine `gepa` (via `gepa.optimize_anything`).
50
+ - Safe apply flow with automatic backups.
51
+ - Markdown reporting from latest runs.
52
+ - Minimal OSS CI (lint, test, build).
53
+
54
+ ## Installation
55
+
56
+ ### Requirements
57
+
58
+ - Python `>=3.10`
59
+ - `uv` (recommended) or `pip`
60
+
61
+ ### Recommended: uv (full workflow)
62
+
63
+ ```bash
64
+ uv sync --extra dev
65
+ ```
66
+
67
+ Run commands through the managed environment:
68
+
69
+ ```bash
70
+ uv run codexopt --help
71
+ ```
72
+
73
+ `uv.lock` is committed to keep dependency resolution reproducible across machines and CI.
74
+
75
+ ### Alternative: pip
76
+
77
+ ```bash
78
+ pip install -e ".[dev]"
79
+ ```
80
+
81
+ ## Quick Start (uv)
82
+
83
+ ```bash
84
+ # 1) Create config
85
+ uv run codexopt init
86
+
87
+ # 2) Inspect what will be evaluated
88
+ uv run codexopt scan
89
+
90
+ # 3) Get baseline scores
91
+ uv run codexopt benchmark
92
+
93
+ # 4) Optimize AGENTS.md
94
+ uv run codexopt optimize agents --file AGENTS.md
95
+
96
+ # 5) Optimize skills
97
+ uv run codexopt optimize skills --glob ".codex/skills/**/SKILL.md"
98
+
99
+ # 6) Review apply impact without writing
100
+ uv run codexopt apply --kind agents --dry-run
101
+
102
+ # 7) Apply selected improvements
103
+ uv run codexopt apply --kind agents
104
+
105
+ # 8) Generate markdown summary
106
+ uv run codexopt report --output codexopt-report.md
107
+ ```
108
+
109
+ Use `codexopt.example.yaml` as a starting point for committed team config.
110
+
111
+ ## Command Reference
112
+
113
+ ### Global options
114
+
115
+ ```bash
116
+ codexopt --config <path-to-codexopt.yaml> <command>
117
+ ```
118
+
119
+ ### `init`
120
+
121
+ Create a default config file.
122
+
123
+ ```bash
124
+ codexopt init [--path PATH] [--force]
125
+ ```
126
+
127
+ ### `scan`
128
+
129
+ Discover AGENTS/SKILL targets and validate shape.
130
+
131
+ ```bash
132
+ codexopt scan
133
+ ```
134
+
135
+ ### `benchmark`
136
+
137
+ Score current files using built-in heuristics.
138
+
139
+ ```bash
140
+ codexopt benchmark
141
+ ```
142
+
143
+ ### `optimize agents`
144
+
145
+ Optimize AGENTS files.
146
+
147
+ ```bash
148
+ codexopt optimize agents \
149
+ [--file PATTERN] \
150
+ [--engine heuristic|gepa] \
151
+ [--reflection-model MODEL] \
152
+ [--max-metric-calls N]
153
+ ```
154
+
155
+ ### `optimize skills`
156
+
157
+ Optimize SKILL files.
158
+
159
+ ```bash
160
+ codexopt optimize skills \
161
+ [--glob PATTERN] \
162
+ [--engine heuristic|gepa] \
163
+ [--reflection-model MODEL] \
164
+ [--max-metric-calls N]
165
+ ```
166
+
167
+ ### `apply`
168
+
169
+ Apply best candidates from the latest optimization run (or a provided run id).
170
+
171
+ ```bash
172
+ codexopt apply [--kind agents|skills] [--run-id RUN_ID] [--dry-run]
173
+ ```
174
+
175
+ ### `report`
176
+
177
+ Generate a markdown report from latest runs in state.
178
+
179
+ ```bash
180
+ codexopt report [--output FILE.md]
181
+ ```
182
+
183
+ ## Configuration
184
+
185
+ Default `codexopt.yaml`:
186
+
187
+ ```yaml
188
+ version: 1
189
+ targets:
190
+ agents_files:
191
+ - AGENTS.md
192
+ - "**/AGENTS.md"
193
+ - "**/AGENTS.override.md"
194
+ skills_globs:
195
+ - ".codex/skills/**/SKILL.md"
196
+ - "**/.codex/skills/**/SKILL.md"
197
+ exclude_globs:
198
+ - ".git/**"
199
+ - ".codexopt/**"
200
+ - ".venv/**"
201
+ - "node_modules/**"
202
+ - "reference/**"
203
+ output:
204
+ root_dir: ".codexopt"
205
+ optimization:
206
+ engine: "heuristic"
207
+ min_apply_delta: 0.01
208
+ max_metric_calls: 60
209
+ reflection_model: null
210
+ ```
211
+
212
+ Config notes:
213
+
214
+ - `targets.agents_files`: glob patterns for AGENTS targets.
215
+ - `targets.skills_globs`: glob patterns for `SKILL.md` targets.
216
+ - `targets.exclude_globs`: paths ignored during scan.
217
+ - `output.root_dir`: run artifacts and backups location.
218
+ - `optimization.engine`: default optimization engine.
219
+ - `optimization.min_apply_delta`: minimum score gain required to apply.
220
+ - `optimization.max_metric_calls`: GEPA metric budget.
221
+ - `optimization.reflection_model`: required when using GEPA engine.
222
+
223
+ ## How Scoring Works
224
+
225
+ CodexOpt computes a `0.0` to `1.0` score per file.
226
+
227
+ AGENTS scoring factors include:
228
+
229
+ - Too short or too long content penalties.
230
+ - Token-heaviness estimate penalty.
231
+ - Empty file penalty.
232
+
233
+ SKILL scoring factors include:
234
+
235
+ - Missing frontmatter penalties.
236
+ - Missing `name` / `description` penalties.
237
+ - Overly long frontmatter fields penalties.
238
+ - Too short or too long content penalties.
239
+
240
+ ## Optimization Behavior
241
+
242
+ ### Heuristic engine
243
+
244
+ Candidate transforms include:
245
+
246
+ - Whitespace normalization.
247
+ - Blank-line compaction.
248
+ - Duplicate adjacent line removal.
249
+ - Skill-specific frontmatter synthesis/trimming.
250
+
251
+ The best candidate is selected by score delta. If delta is below `min_apply_delta`, original content is kept.
252
+
253
+ ### GEPA engine (optional)
254
+
255
+ CodexOpt can call `gepa.optimize_anything` when `--engine gepa` is selected.
256
+
257
+ Requirements:
258
+
259
+ - `gepa` installed in the environment.
260
+ - A valid reflection model via `--reflection-model` or config.
261
+
262
+ Fallback behavior:
263
+
264
+ - If GEPA is unavailable or errors, CodexOpt falls back to heuristic optimization.
265
+
266
+ ## Artifacts and State
267
+
268
+ By default, everything is written under `.codexopt/`:
269
+
270
+ - `runs/<run_id>/scan.json`
271
+ - `runs/<run_id>/benchmark.json`
272
+ - `runs/<run_id>/optimize.json`
273
+ - `runs/<run_id>/apply.json`
274
+ - `backups/<timestamp>/...` (created on non-dry-run apply)
275
+ - `state.json` (tracks latest run ids per command type)
276
+
277
+ Run ids are timestamped and namespaced by command kind, for example:
278
+
279
+ - `20260308T184800123456Z-benchmark`
280
+ - `20260308T184812654321Z-optimize-skills`
281
+
282
+ ## Typical Team Workflow
283
+
284
+ 1. Commit current `AGENTS.md` and skills.
285
+ 2. Run `scan` and `benchmark` to establish baseline.
286
+ 3. Run `optimize agents` and/or `optimize skills`.
287
+ 4. Review `optimize.json` and diffs.
288
+ 5. Run `apply --dry-run` first, then `apply`.
289
+ 6. Run `report` and attach report to PR.
290
+
291
+ ## Examples
292
+
293
+ ### Example A: `AGENTS.md` cleanup
294
+
295
+ Before (`AGENTS.md`):
296
+
297
+ ```md
298
+ ## Coding Rules
299
+ Always run tests before commit.
300
+ Always run tests before commit.
301
+
302
+
303
+ Keep changes minimal.
304
+ ```
305
+
306
+ After optimization (heuristic):
307
+
308
+ ```md
309
+ ## Coding Rules
310
+ Always run tests before commit.
311
+
312
+ Keep changes minimal.
313
+ ```
314
+
315
+ What changed:
316
+
317
+ - Removed duplicate adjacent line.
318
+ - Compacted extra blank lines.
319
+
320
+ ### Example B: `SKILL.md` missing frontmatter
321
+
322
+ Before (`.codex/skills/my_skill/SKILL.md`):
323
+
324
+ ```md
325
+ Use this skill for repository release checks.
326
+ Run lint, tests, and changelog validation.
327
+ ```
328
+
329
+ After optimization (heuristic):
330
+
331
+ ```md
332
+ ---
333
+ name: my-skill
334
+ description: Repository-specific workflow skill.
335
+ ---
336
+
337
+ Use this skill for repository release checks.
338
+ Run lint, tests, and changelog validation.
339
+ ```
340
+
341
+ What changed:
342
+
343
+ - Added required frontmatter block.
344
+ - Generated normalized `name` from folder name.
345
+ - Added default `description`.
346
+
347
+ ### Example C: Reproduce end-to-end on a repo
348
+
349
+ ```bash
350
+ uv run codexopt init
351
+ uv run codexopt scan
352
+ uv run codexopt benchmark
353
+ uv run codexopt optimize agents --file AGENTS.md
354
+ uv run codexopt optimize skills --glob ".codex/skills/**/SKILL.md"
355
+ uv run codexopt apply --kind skills --dry-run
356
+ uv run codexopt apply --kind skills
357
+ uv run codexopt report --output codexopt-report.md
358
+ ```
359
+
360
+ Files to inspect after running:
361
+
362
+ - `.codexopt/runs/*/scan.json`
363
+ - `.codexopt/runs/*/benchmark.json`
364
+ - `.codexopt/runs/*/optimize.json`
365
+ - `.codexopt/runs/*/apply.json`
366
+ - `.codexopt/backups/*`
367
+
368
+ ## CI
369
+
370
+ GitHub Actions workflow is included at `.github/workflows/ci.yml` and runs:
371
+
372
+ - `uv lock --check` for lockfile consistency.
373
+ - `uv sync --extra dev` for environment setup.
374
+ - Ruff lint checks.
375
+ - Pytest tests.
376
+ - Package build (`uv build`).
377
+
378
+ It does not publish packages.
379
+
380
+ ## Development
381
+
382
+ ```bash
383
+ uv lock
384
+ uv sync --extra dev
385
+ uv run --no-sync ruff check src tests
386
+ PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 uv run --no-sync pytest -q
387
+ uv build
388
+ ```
389
+
390
+ ## FAQ / Troubleshooting
391
+
392
+ ### `codexopt apply` says "no optimization run found"
393
+
394
+ Cause:
395
+
396
+ - No prior optimization run for the selected kind.
397
+ - `state.json` does not contain the expected latest run pointer.
398
+
399
+ Fix:
400
+
401
+ ```bash
402
+ uv run codexopt optimize agents
403
+ uv run codexopt apply --kind agents
404
+ ```
405
+
406
+ Or pass an explicit run:
407
+
408
+ ```bash
409
+ uv run codexopt apply --kind agents --run-id <run_id>
410
+ ```
411
+
412
+ ### `--engine gepa` did not use GEPA
413
+
414
+ Cause:
415
+
416
+ - `gepa` is not installed, or
417
+ - `reflection_model` is missing.
418
+
419
+ Behavior:
420
+
421
+ - CodexOpt falls back to heuristic optimization when GEPA errors.
422
+
423
+ Fix:
424
+
425
+ ```bash
426
+ uv run codexopt optimize agents --engine gepa --reflection-model <model_name>
427
+ ```
428
+
429
+ ### `apply --dry-run` says files would be applied, but nothing changed
430
+
431
+ Expected behavior:
432
+
433
+ - `--dry-run` reports candidate applications without writing files.
434
+
435
+ To write changes, run again without `--dry-run`:
436
+
437
+ ```bash
438
+ uv run codexopt apply --kind agents
439
+ ```
440
+
441
+ ### Build fails with network/isolation issues
442
+
443
+ If your environment blocks dependency resolution in isolated builds, use:
444
+
445
+ ```bash
446
+ uv build
447
+ ```
448
+
449
+ ### Pytest fails due to unrelated external plugins
450
+
451
+ Some environments auto-load global pytest plugins that can break local tests.
452
+ Run with plugin autoload disabled:
453
+
454
+ ```bash
455
+ PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 uv run --no-sync pytest -q
456
+ ```
457
+
458
+ ### Optimization produced no applied changes
459
+
460
+ Cause:
461
+
462
+ - Best candidate delta is below `optimization.min_apply_delta`, or
463
+ - File content is already equivalent.
464
+
465
+ Fix:
466
+
467
+ - Lower `optimization.min_apply_delta` in `codexopt.yaml`, then re-run optimize/apply.
468
+
469
+ ## License
470
+
471
+ MIT. See `LICENSE`.
472
+
473
+ ## Author
474
+
475
+ - Shashi (`shashi@super-agentic.ai`)