auto-optimize 1.0.0__py3-none-any.whl
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.
- auto_optimize/__init__.py +3 -0
- auto_optimize/__main__.py +5 -0
- auto_optimize/cli.py +651 -0
- auto_optimize/skills/auto-optimize-code/LICENSE +21 -0
- auto_optimize/skills/auto-optimize-code/SKILL.md +251 -0
- auto_optimize/skills/auto-optimize-code/VERSION +1 -0
- auto_optimize/skills/auto-optimize-code/references/algorithm.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/changes.md +146 -0
- auto_optimize/skills/auto-optimize-code/references/cli.md +206 -0
- auto_optimize/skills/auto-optimize-code/references/dashboard.md +203 -0
- auto_optimize/skills/auto-optimize-code/references/documents.md +55 -0
- auto_optimize/skills/auto-optimize-code/references/extending.md +87 -0
- auto_optimize/skills/auto-optimize-code/references/external-validation.md +98 -0
- auto_optimize/skills/auto-optimize-code/references/glossary.md +134 -0
- auto_optimize/skills/auto-optimize-code/references/idea-miner.md +108 -0
- auto_optimize/skills/auto-optimize-code/references/issue-bugs.md +182 -0
- auto_optimize/skills/auto-optimize-code/references/layout.md +300 -0
- auto_optimize/skills/auto-optimize-code/references/main-session.md +45 -0
- auto_optimize/skills/auto-optimize-code/references/measuring.md +208 -0
- auto_optimize/skills/auto-optimize-code/references/pr-optimization.md +127 -0
- auto_optimize/skills/auto-optimize-code/references/pr-tests.md +254 -0
- auto_optimize/skills/auto-optimize-code/references/promotion.md +133 -0
- auto_optimize/skills/auto-optimize-code/references/reading-a-search.md +65 -0
- auto_optimize/skills/auto-optimize-code/references/repo-mode.md +224 -0
- auto_optimize/skills/auto-optimize-code/references/resume.md +81 -0
- auto_optimize/skills/auto-optimize-code/references/shared-knowledge.md +114 -0
- auto_optimize/skills/auto-optimize-code/references/step0-interview.md +298 -0
- auto_optimize/skills/auto-optimize-code/references/step1-unit-tests.md +136 -0
- auto_optimize/skills/auto-optimize-code/references/step2-baseline.md +708 -0
- auto_optimize/skills/auto-optimize-code/references/step3-rounds.md +350 -0
- auto_optimize/skills/auto-optimize-code/references/step4-final.md +121 -0
- auto_optimize/skills/auto-optimize-code/references/step5-ship.md +220 -0
- auto_optimize/skills/auto-optimize-code/references/step6-finish.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/subagent.md +467 -0
- auto_optimize/skills/auto-optimize-code/references/symptoms.md +67 -0
- auto_optimize/skills/auto-optimize-code/references/writing-briefs.md +117 -0
- auto_optimize/skills/auto-optimize-code/scripts/attribution.py +156 -0
- auto_optimize/skills/auto-optimize-code/scripts/autoopt.py +12863 -0
- auto_optimize/skills/auto-optimize-code/scripts/check_seeding.py +334 -0
- auto_optimize/skills/auto-optimize-code/scripts/cold.py +90 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/README.md +165 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/autoopt_monitor.py +850 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/gpu_scan.py +954 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/monitor_writer.py +684 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/scan.py +1030 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.css +775 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/dashboard.js +3652 -0
- auto_optimize/skills/auto-optimize-code/scripts/dashboard/static/index.html +191 -0
- auto_optimize/skills/auto-optimize-code/scripts/issue_body.py +2118 -0
- auto_optimize/skills/auto-optimize-code/scripts/lint_text.py +448 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_body.py +894 -0
- auto_optimize/skills/auto-optimize-code/scripts/opt_pr_tables.py +367 -0
- auto_optimize/skills/auto-optimize-code/scripts/paired.py +188 -0
- auto_optimize/skills/auto-optimize-code/scripts/preflight.py +280 -0
- auto_optimize/skills/auto-optimize-code/scripts/probe_run.py +72 -0
- auto_optimize/skills/auto-optimize-code/scripts/publish.py +385 -0
- auto_optimize/skills/auto-optimize-code/scripts/run_iteration.py +1382 -0
- auto_optimize/skills/auto-optimize-code/scripts/ship.py +1193 -0
- auto_optimize/skills/auto-optimize-code/scripts/stages.py +651 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_body.py +1267 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_push.py +426 -0
- auto_optimize/skills/auto-optimize-code/scripts/tests_pr_tables.py +779 -0
- auto_optimize-1.0.0.dist-info/METADATA +610 -0
- auto_optimize-1.0.0.dist-info/RECORD +67 -0
- auto_optimize-1.0.0.dist-info/WHEEL +4 -0
- auto_optimize-1.0.0.dist-info/entry_points.txt +2 -0
- auto_optimize-1.0.0.dist-info/licenses/LICENSE +21 -0
auto_optimize/cli.py
ADDED
|
@@ -0,0 +1,651 @@
|
|
|
1
|
+
"""Install, list, locate and check the auto-optimize Claude Code skills.
|
|
2
|
+
|
|
3
|
+
auto-optimize install [SKILL ...] [--project [DIR] | -d DIR] [--symlink]
|
|
4
|
+
[-f]
|
|
5
|
+
auto-optimize uninstall [SKILL ...] [--project [DIR] | -d DIR] [-f]
|
|
6
|
+
auto-optimize list
|
|
7
|
+
auto-optimize path [SKILL] [--bundled]
|
|
8
|
+
auto-optimize doctor
|
|
9
|
+
|
|
10
|
+
A skill is named in full (auto-optimize-code) or by the part after
|
|
11
|
+
`auto-optimize-` (code). With no SKILL, install and uninstall act on every
|
|
12
|
+
skill this package ships.
|
|
13
|
+
|
|
14
|
+
Claude Code reads user skills from ~/.claude/skills/ ($CLAUDE_CONFIG_DIR/skills
|
|
15
|
+
when that is set) and project skills from <project>/.claude/skills/. Nothing is
|
|
16
|
+
installed on `pip install`; only `auto-optimize install` writes there.
|
|
17
|
+
|
|
18
|
+
Standard library only, Python 3.9 or later.
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
import os
|
|
22
|
+
import re
|
|
23
|
+
import sys
|
|
24
|
+
import json
|
|
25
|
+
import time
|
|
26
|
+
import shutil
|
|
27
|
+
import argparse
|
|
28
|
+
import datetime
|
|
29
|
+
import subprocess
|
|
30
|
+
|
|
31
|
+
from . import __version__
|
|
32
|
+
|
|
33
|
+
PREFIX = 'auto-optimize-'
|
|
34
|
+
# The single skill this repository held before 1.0.0, cloned by hand into a
|
|
35
|
+
# skills folder. It answers the same requests as auto-optimize-code.
|
|
36
|
+
LEGACY = 'auto-optimize'
|
|
37
|
+
MARKER = '.install.json'
|
|
38
|
+
PLUGIN_ID = 'auto-optimize@auto-optimize'
|
|
39
|
+
PYTHON_FLOOR = (3, 9)
|
|
40
|
+
|
|
41
|
+
# Never copied: caches a test run or a notebook leaves in the source, and the
|
|
42
|
+
# marker, which each install writes fresh.
|
|
43
|
+
IGNORE = shutil.ignore_patterns('__pycache__', '*.pyc', '.pytest_cache',
|
|
44
|
+
'.ipynb_checkpoints', MARKER)
|
|
45
|
+
|
|
46
|
+
# Imported by the dashboard, checked in the python3 the skill runs.
|
|
47
|
+
OPTIONAL = (
|
|
48
|
+
('plotly', 'plotly', 'the dashboard charts and its static --export'),
|
|
49
|
+
('IPython', 'ipython', 'showing the dashboard in a notebook'),
|
|
50
|
+
('jupyterlab', 'jupyterlab', 'serving the dashboard notebook'),
|
|
51
|
+
('psutil', 'psutil', 'the dashboard host and process panels'),
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
class InstallError(Exception):
|
|
56
|
+
pass
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
###
|
|
60
|
+
# The shipped skills
|
|
61
|
+
###
|
|
62
|
+
|
|
63
|
+
def bundled_root():
|
|
64
|
+
"""The folder of shipped skills: `skills/` inside the installed package,
|
|
65
|
+
or `skills/` at the top of a source checkout."""
|
|
66
|
+
|
|
67
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
68
|
+
|
|
69
|
+
for candidate in (os.path.join(here, 'skills'), os.path.normpath(
|
|
70
|
+
os.path.join(here, os.pardir, os.pardir, 'skills'))):
|
|
71
|
+
if os.path.isdir(candidate):
|
|
72
|
+
return candidate
|
|
73
|
+
|
|
74
|
+
raise InstallError('no skills folder in {} or in a source checkout above '
|
|
75
|
+
'it; the package is incomplete'.format(here))
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def bundled_skills():
|
|
79
|
+
"""{name: folder} for every shipped skill, in name order."""
|
|
80
|
+
|
|
81
|
+
root = bundled_root()
|
|
82
|
+
|
|
83
|
+
return {name: os.path.join(root, name) for name in sorted(os.listdir(root))
|
|
84
|
+
if os.path.isfile(os.path.join(root, name, 'SKILL.md'))}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def frontmatter_name(folder):
|
|
88
|
+
"""The `name:` in a folder's SKILL.md frontmatter, or None."""
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
with open(os.path.join(folder, 'SKILL.md'), encoding='utf-8') as handle:
|
|
92
|
+
text = handle.read()
|
|
93
|
+
except OSError:
|
|
94
|
+
return None
|
|
95
|
+
|
|
96
|
+
block = re.match(r'---\n(.*?)\n---\n', text, re.S)
|
|
97
|
+
found = block and re.search(r'^name:\s*(\S+)\s*$', block.group(1), re.M)
|
|
98
|
+
|
|
99
|
+
return found.group(1) if found else None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def skill_version(folder):
|
|
103
|
+
"""The skill's VERSION file, or None."""
|
|
104
|
+
|
|
105
|
+
try:
|
|
106
|
+
with open(os.path.join(folder, 'VERSION')) as handle:
|
|
107
|
+
return handle.read().strip() or None
|
|
108
|
+
except OSError:
|
|
109
|
+
return None
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def choose(names, available):
|
|
113
|
+
"""Full skill names for `names` (all of `available` when empty)."""
|
|
114
|
+
|
|
115
|
+
if not names:
|
|
116
|
+
return list(available)
|
|
117
|
+
|
|
118
|
+
chosen = []
|
|
119
|
+
|
|
120
|
+
for name in names:
|
|
121
|
+
full = name if name.startswith(PREFIX) else PREFIX + name
|
|
122
|
+
|
|
123
|
+
if full not in available:
|
|
124
|
+
raise InstallError('no skill named {!r}; this package ships {}'
|
|
125
|
+
.format(name, ', '.join(available) or 'none'))
|
|
126
|
+
|
|
127
|
+
if full not in chosen:
|
|
128
|
+
chosen.append(full)
|
|
129
|
+
|
|
130
|
+
return chosen
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
###
|
|
134
|
+
# Where skills go
|
|
135
|
+
###
|
|
136
|
+
|
|
137
|
+
def config_dir():
|
|
138
|
+
"""~/.claude, or $CLAUDE_CONFIG_DIR when set."""
|
|
139
|
+
|
|
140
|
+
return os.environ.get('CLAUDE_CONFIG_DIR') or os.path.join(
|
|
141
|
+
os.path.expanduser('~'), '.claude')
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def user_skills_dir():
|
|
145
|
+
return os.path.join(config_dir(), 'skills')
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def target_dir(args):
|
|
149
|
+
"""The skills folder an install or uninstall acts on."""
|
|
150
|
+
|
|
151
|
+
if args.directory:
|
|
152
|
+
return os.path.abspath(os.path.expanduser(args.directory))
|
|
153
|
+
|
|
154
|
+
if args.project is not None:
|
|
155
|
+
return os.path.join(os.path.abspath(os.path.expanduser(args.project)),
|
|
156
|
+
'.claude', 'skills')
|
|
157
|
+
|
|
158
|
+
return user_skills_dir()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def ownership(dest, name):
|
|
162
|
+
"""What is at `dest`: ('missing'|'copy'|'link'|'stale'|'foreign', why).
|
|
163
|
+
|
|
164
|
+
`copy` carries this installer's marker; `link` is a symlink to a folder
|
|
165
|
+
whose SKILL.md is named `name`; `stale` is a symlink to nothing. Anything
|
|
166
|
+
else is `foreign`, and replacing it needs --force.
|
|
167
|
+
"""
|
|
168
|
+
|
|
169
|
+
if not os.path.lexists(dest):
|
|
170
|
+
return 'missing', None
|
|
171
|
+
|
|
172
|
+
if os.path.islink(dest):
|
|
173
|
+
if not os.path.exists(dest):
|
|
174
|
+
return 'stale', None
|
|
175
|
+
if frontmatter_name(os.path.realpath(dest)) == name:
|
|
176
|
+
return 'link', None
|
|
177
|
+
return 'foreign', 'is a symlink to {}, which holds no {} skill'.format(
|
|
178
|
+
os.readlink(dest), name)
|
|
179
|
+
|
|
180
|
+
if os.path.isdir(dest) and os.path.isfile(os.path.join(dest, MARKER)):
|
|
181
|
+
return 'copy', None
|
|
182
|
+
|
|
183
|
+
return 'foreign', 'was not installed by auto-optimize (it has no ' \
|
|
184
|
+
'{})'.format(MARKER)
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def remove(path):
|
|
188
|
+
if os.path.islink(path) or os.path.isfile(path):
|
|
189
|
+
os.unlink(path)
|
|
190
|
+
else:
|
|
191
|
+
shutil.rmtree(path)
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
###
|
|
195
|
+
# install, uninstall
|
|
196
|
+
###
|
|
197
|
+
|
|
198
|
+
def install_one(name, source, skills_dir, symlink=False, force=False):
|
|
199
|
+
"""Put the skill `name` from `source` at `skills_dir/name`, replacing an
|
|
200
|
+
earlier install. Returns the destination.
|
|
201
|
+
|
|
202
|
+
The new copy is built beside the destination and renamed into place, so a
|
|
203
|
+
failure part-way leaves the previous install as it was.
|
|
204
|
+
"""
|
|
205
|
+
|
|
206
|
+
dest = os.path.join(skills_dir, name)
|
|
207
|
+
kind, why = ownership(dest, name)
|
|
208
|
+
|
|
209
|
+
if kind == 'foreign' and not force:
|
|
210
|
+
raise InstallError('{} {}; re-run with --force to replace it'.format(
|
|
211
|
+
dest, why))
|
|
212
|
+
|
|
213
|
+
os.makedirs(skills_dir, exist_ok=True)
|
|
214
|
+
staged = os.path.join(skills_dir, '.{}.new-{}'.format(name, os.getpid()))
|
|
215
|
+
old = os.path.join(skills_dir, '.{}.old-{}'.format(name, os.getpid()))
|
|
216
|
+
|
|
217
|
+
try:
|
|
218
|
+
if symlink:
|
|
219
|
+
os.symlink(os.path.realpath(source), staged)
|
|
220
|
+
else:
|
|
221
|
+
shutil.copytree(source, staged, ignore=IGNORE)
|
|
222
|
+
with open(os.path.join(staged, MARKER), 'w') as handle:
|
|
223
|
+
json.dump({'name': name, 'version': skill_version(source),
|
|
224
|
+
'installer': 'auto-optimize {}'.format(__version__),
|
|
225
|
+
'source': os.path.realpath(source), 'mode': 'copy',
|
|
226
|
+
'installed': datetime.datetime.now().isoformat(
|
|
227
|
+
timespec='seconds')}, handle, indent='\t')
|
|
228
|
+
handle.write('\n')
|
|
229
|
+
except BaseException:
|
|
230
|
+
if os.path.lexists(staged):
|
|
231
|
+
remove(staged)
|
|
232
|
+
raise
|
|
233
|
+
|
|
234
|
+
moved = False
|
|
235
|
+
|
|
236
|
+
try:
|
|
237
|
+
if os.path.lexists(dest):
|
|
238
|
+
os.rename(dest, old)
|
|
239
|
+
moved = True
|
|
240
|
+
os.rename(staged, dest)
|
|
241
|
+
except BaseException:
|
|
242
|
+
if moved and not os.path.lexists(dest):
|
|
243
|
+
os.rename(old, dest)
|
|
244
|
+
if os.path.lexists(staged):
|
|
245
|
+
remove(staged)
|
|
246
|
+
raise
|
|
247
|
+
|
|
248
|
+
if moved:
|
|
249
|
+
remove(old)
|
|
250
|
+
|
|
251
|
+
return dest
|
|
252
|
+
|
|
253
|
+
|
|
254
|
+
def uninstall_one(name, skills_dir, force=False):
|
|
255
|
+
"""Remove `skills_dir/name` if this installer put it there. Returns the
|
|
256
|
+
removed path, or None when nothing was there."""
|
|
257
|
+
|
|
258
|
+
dest = os.path.join(skills_dir, name)
|
|
259
|
+
kind, why = ownership(dest, name)
|
|
260
|
+
|
|
261
|
+
if kind == 'missing':
|
|
262
|
+
return None
|
|
263
|
+
|
|
264
|
+
if kind == 'foreign' and not force:
|
|
265
|
+
raise InstallError('{} {}; re-run with --force to remove it'.format(
|
|
266
|
+
dest, why))
|
|
267
|
+
|
|
268
|
+
remove(dest)
|
|
269
|
+
|
|
270
|
+
return dest
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def install(args):
|
|
274
|
+
skills = bundled_skills()
|
|
275
|
+
skills_dir = target_dir(args)
|
|
276
|
+
|
|
277
|
+
for name in choose(args.skills, skills):
|
|
278
|
+
dest = install_one(name, skills[name], skills_dir, args.symlink,
|
|
279
|
+
args.force)
|
|
280
|
+
print('installed {} {} at {}{}'.format(name, skill_version(
|
|
281
|
+
skills[name]) or '', dest, ' -> ' + os.path.realpath(dest)
|
|
282
|
+
if args.symlink else ''))
|
|
283
|
+
|
|
284
|
+
if duplicates(installations()):
|
|
285
|
+
print('note: a skill is installed more than once; `auto-optimize list` '
|
|
286
|
+
'shows where', file=sys.stderr)
|
|
287
|
+
|
|
288
|
+
return 0
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
def uninstall(args):
|
|
292
|
+
skills_dir = target_dir(args)
|
|
293
|
+
|
|
294
|
+
for name in choose(args.skills, bundled_skills()):
|
|
295
|
+
removed = uninstall_one(name, skills_dir, args.force)
|
|
296
|
+
print('removed {}'.format(removed) if removed else
|
|
297
|
+
'{} is not installed in {}'.format(name, skills_dir))
|
|
298
|
+
|
|
299
|
+
return 0
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
###
|
|
303
|
+
# Finding every copy Claude Code would load
|
|
304
|
+
###
|
|
305
|
+
|
|
306
|
+
def project_dirs(start=None):
|
|
307
|
+
"""`.claude/skills` in `start` and each parent up to the git repository's
|
|
308
|
+
top, the folders Claude Code reads project skills from."""
|
|
309
|
+
|
|
310
|
+
start = os.path.abspath(start or os.getcwd())
|
|
311
|
+
top = subprocess.run(['git', '-C', start, 'rev-parse', '--show-toplevel'],
|
|
312
|
+
capture_output=True, text=True) if shutil.which('git') else None
|
|
313
|
+
top = os.path.abspath(top.stdout.strip()) if top and top.returncode == 0 \
|
|
314
|
+
else start
|
|
315
|
+
|
|
316
|
+
out, here = [], start
|
|
317
|
+
|
|
318
|
+
while True:
|
|
319
|
+
out.append(os.path.join(here, '.claude', 'skills'))
|
|
320
|
+
parent = os.path.dirname(here)
|
|
321
|
+
if here == top or parent == here or not here.startswith(top):
|
|
322
|
+
break
|
|
323
|
+
here = parent
|
|
324
|
+
|
|
325
|
+
return out
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def plugin_installs():
|
|
329
|
+
"""[(scope, install path)] for the auto-optimize plugin, from Claude
|
|
330
|
+
Code's record of installed plugins."""
|
|
331
|
+
|
|
332
|
+
root = os.environ.get('CLAUDE_CODE_PLUGIN_CACHE_DIR') or os.path.join(
|
|
333
|
+
config_dir(), 'plugins')
|
|
334
|
+
|
|
335
|
+
try:
|
|
336
|
+
with open(os.path.join(root, 'installed_plugins.json')) as handle:
|
|
337
|
+
record = json.load(handle)
|
|
338
|
+
except (OSError, ValueError):
|
|
339
|
+
return []
|
|
340
|
+
|
|
341
|
+
entries = (record.get('plugins') or {}).get(PLUGIN_ID) if isinstance(
|
|
342
|
+
record, dict) else None
|
|
343
|
+
|
|
344
|
+
if isinstance(entries, dict):
|
|
345
|
+
entries = [entries]
|
|
346
|
+
|
|
347
|
+
return [(entry.get('scope') or 'plugin', entry['installPath'])
|
|
348
|
+
for entry in entries or [] if isinstance(entry, dict)
|
|
349
|
+
and entry.get('installPath')]
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
def installations(start=None):
|
|
353
|
+
"""Every auto-optimize-* skill Claude Code would load from here: dicts
|
|
354
|
+
of name, version, scope, mode and path."""
|
|
355
|
+
|
|
356
|
+
found, seen = [], set()
|
|
357
|
+
shipped = set(bundled_skills())
|
|
358
|
+
user = user_skills_dir()
|
|
359
|
+
places = [('user', user)] + [('project', d) for d in project_dirs(start)
|
|
360
|
+
if os.path.abspath(d) != os.path.abspath(user)]
|
|
361
|
+
|
|
362
|
+
for scope, folder in places:
|
|
363
|
+
if not os.path.isdir(folder):
|
|
364
|
+
continue
|
|
365
|
+
|
|
366
|
+
for name in sorted(os.listdir(folder)):
|
|
367
|
+
path = os.path.join(folder, name)
|
|
368
|
+
|
|
369
|
+
if path in seen or not os.path.isfile(os.path.join(path,
|
|
370
|
+
'SKILL.md')):
|
|
371
|
+
continue
|
|
372
|
+
|
|
373
|
+
if name == LEGACY and frontmatter_name(path) == LEGACY:
|
|
374
|
+
seen.add(path)
|
|
375
|
+
found.append({'name': LEGACY, 'version': None, 'scope': scope,
|
|
376
|
+
'mode': 'earlier copy (before 1.0.0)', 'path': path,
|
|
377
|
+
'legacy': True})
|
|
378
|
+
continue
|
|
379
|
+
|
|
380
|
+
# Another author's skill may share the prefix: only the shipped
|
|
381
|
+
# names, or a folder this installer wrote, are ours.
|
|
382
|
+
if not name.startswith(PREFIX) or (name not in shipped and
|
|
383
|
+
not os.path.exists(os.path.join(path, MARKER))):
|
|
384
|
+
continue
|
|
385
|
+
|
|
386
|
+
kind, _ = ownership(path, frontmatter_name(path) or name)
|
|
387
|
+
|
|
388
|
+
if kind == 'stale' or not os.path.isfile(os.path.join(path,
|
|
389
|
+
'SKILL.md')):
|
|
390
|
+
continue
|
|
391
|
+
|
|
392
|
+
seen.add(path)
|
|
393
|
+
found.append({'name': frontmatter_name(path) or name,
|
|
394
|
+
'version': skill_version(path), 'scope': scope,
|
|
395
|
+
'mode': {'copy': 'copy', 'link': 'symlink'}.get(kind,
|
|
396
|
+
'not installed by auto-optimize'), 'path': path})
|
|
397
|
+
|
|
398
|
+
for scope, root in plugin_installs():
|
|
399
|
+
folder = os.path.join(root, 'skills')
|
|
400
|
+
|
|
401
|
+
for name in sorted(os.listdir(folder)) if os.path.isdir(folder) else []:
|
|
402
|
+
path = os.path.join(folder, name)
|
|
403
|
+
|
|
404
|
+
if os.path.isfile(os.path.join(path, 'SKILL.md')):
|
|
405
|
+
found.append({'name': frontmatter_name(path) or name,
|
|
406
|
+
'version': skill_version(path), 'scope': scope,
|
|
407
|
+
'mode': 'plugin ' + PLUGIN_ID, 'path': path})
|
|
408
|
+
|
|
409
|
+
return found
|
|
410
|
+
|
|
411
|
+
|
|
412
|
+
def legacy_notes(found):
|
|
413
|
+
"""A note for each earlier copy of the skill found."""
|
|
414
|
+
|
|
415
|
+
return ['\nnote: {} holds the auto-optimize skill from before 1.0.0, '
|
|
416
|
+
'named {}. Claude Code loads it beside auto-optimize-code, and the two '
|
|
417
|
+
'answer the same requests; remove that folder.'.format(item['path'],
|
|
418
|
+
LEGACY) for item in found if item.get('legacy')]
|
|
419
|
+
|
|
420
|
+
|
|
421
|
+
def duplicates(found):
|
|
422
|
+
"""Names installed more than once."""
|
|
423
|
+
|
|
424
|
+
names = [item['name'] for item in found]
|
|
425
|
+
|
|
426
|
+
return sorted({name for name in names if names.count(name) > 1})
|
|
427
|
+
|
|
428
|
+
|
|
429
|
+
def list_command(args):
|
|
430
|
+
found = installations()
|
|
431
|
+
|
|
432
|
+
if not found:
|
|
433
|
+
print('no auto-optimize skill is installed for {}'.format(os.getcwd()))
|
|
434
|
+
return 0
|
|
435
|
+
|
|
436
|
+
rows = [(item['name'], item['version'] or '-', item['scope'],
|
|
437
|
+
item['mode'], item['path']) for item in found]
|
|
438
|
+
header = ('skill', 'version', 'scope', 'how', 'path')
|
|
439
|
+
widths = [max(len(row[i]) for row in rows + [header]) for i in range(4)]
|
|
440
|
+
|
|
441
|
+
for row in [header] + rows:
|
|
442
|
+
print(' '.join(row[i].ljust(widths[i]) for i in range(4)) + ' '
|
|
443
|
+
+ row[4])
|
|
444
|
+
|
|
445
|
+
for note in legacy_notes(found):
|
|
446
|
+
print(note)
|
|
447
|
+
|
|
448
|
+
for name in duplicates(found):
|
|
449
|
+
print('\nnote: {} is installed more than once. Claude Code loads every '
|
|
450
|
+
'copy and their descriptions compete for the same requests; keep '
|
|
451
|
+
'one (`auto-optimize uninstall`, or `claude plugin uninstall {}`)'
|
|
452
|
+
.format(name, PLUGIN_ID))
|
|
453
|
+
|
|
454
|
+
return 0
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
def path_command(args):
|
|
458
|
+
skills = bundled_skills()
|
|
459
|
+
|
|
460
|
+
if args.skill:
|
|
461
|
+
name = choose([args.skill], skills)[0]
|
|
462
|
+
elif len(skills) == 1:
|
|
463
|
+
name = next(iter(skills))
|
|
464
|
+
else:
|
|
465
|
+
raise InstallError('this package ships {}; name one'.format(
|
|
466
|
+
', '.join(skills)))
|
|
467
|
+
|
|
468
|
+
if args.bundled:
|
|
469
|
+
print(skills[name])
|
|
470
|
+
return 0
|
|
471
|
+
|
|
472
|
+
for item in installations():
|
|
473
|
+
if item['name'] == name:
|
|
474
|
+
print(item['path'])
|
|
475
|
+
return 0
|
|
476
|
+
|
|
477
|
+
print('{} is not installed; `auto-optimize install {}`'.format(name,
|
|
478
|
+
name[len(PREFIX):]), file=sys.stderr)
|
|
479
|
+
|
|
480
|
+
return 1
|
|
481
|
+
|
|
482
|
+
|
|
483
|
+
###
|
|
484
|
+
# doctor
|
|
485
|
+
###
|
|
486
|
+
|
|
487
|
+
def run(words):
|
|
488
|
+
"""(exit code, stdout) of a command, or (None, '') when it cannot start."""
|
|
489
|
+
|
|
490
|
+
try:
|
|
491
|
+
done = subprocess.run(words, capture_output=True, text=True,
|
|
492
|
+
timeout=60)
|
|
493
|
+
except (OSError, subprocess.TimeoutExpired):
|
|
494
|
+
return None, ''
|
|
495
|
+
|
|
496
|
+
return done.returncode, done.stdout.strip()
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def skill_python3():
|
|
500
|
+
"""The python3 the skill will run: the first on PATH, passing over this
|
|
501
|
+
installer's own environment when uvx, pipx or `uv run` put it first, since
|
|
502
|
+
Claude Code does not run with it."""
|
|
503
|
+
|
|
504
|
+
own = os.path.realpath(os.path.join(sys.prefix, 'bin'))
|
|
505
|
+
active = os.environ.get('VIRTUAL_ENV')
|
|
506
|
+
|
|
507
|
+
if sys.prefix == sys.base_prefix or (active and os.path.realpath(active)
|
|
508
|
+
== os.path.realpath(sys.prefix)):
|
|
509
|
+
return shutil.which('python3')
|
|
510
|
+
|
|
511
|
+
path = os.pathsep.join(entry for entry in os.environ.get('PATH',
|
|
512
|
+
'').split(os.pathsep) if entry and os.path.realpath(entry) != own)
|
|
513
|
+
|
|
514
|
+
return shutil.which('python3', path=path)
|
|
515
|
+
|
|
516
|
+
|
|
517
|
+
def doctor(args):
|
|
518
|
+
"""Check what the skill needs, in the python3 the skill runs (the one
|
|
519
|
+
on PATH, not this installer's), and every installed copy."""
|
|
520
|
+
|
|
521
|
+
problems, lines = 0, []
|
|
522
|
+
|
|
523
|
+
def report(ok, text, required=True):
|
|
524
|
+
nonlocal problems
|
|
525
|
+
problems += 0 if ok or not required else 1
|
|
526
|
+
lines.append('{:<9}{}'.format('ok' if ok else 'MISSING' if required
|
|
527
|
+
else 'optional', text))
|
|
528
|
+
|
|
529
|
+
report(sys.platform.startswith('linux'), 'Linux (this is {}); the '
|
|
530
|
+
'scripts read /proc and take file locks'.format(sys.platform))
|
|
531
|
+
|
|
532
|
+
python3 = skill_python3()
|
|
533
|
+
code, out = run([python3, '-c', 'import sys; print("%d.%d.%d" % '
|
|
534
|
+
'sys.version_info[:3])']) if python3 else (None, '')
|
|
535
|
+
version = tuple(int(part) for part in out.split('.')) if code == 0 else ()
|
|
536
|
+
report(version >= PYTHON_FLOOR, 'python3 {} or later on PATH: {}'.format(
|
|
537
|
+
'.'.join(map(str, PYTHON_FLOOR)), '{} at {}'.format(out, python3)
|
|
538
|
+
if version else 'not found'))
|
|
539
|
+
|
|
540
|
+
for tool, why in (('git', 'every iteration is a git worktree'),
|
|
541
|
+
('tar', 'the checks export an iteration\'s tree')):
|
|
542
|
+
where = shutil.which(tool)
|
|
543
|
+
report(bool(where), '{} ({}): {}'.format(tool, why, where or
|
|
544
|
+
'not found'))
|
|
545
|
+
|
|
546
|
+
missing = []
|
|
547
|
+
|
|
548
|
+
if version:
|
|
549
|
+
for module, package, why in OPTIONAL:
|
|
550
|
+
code, _ = run([python3, '-c', 'import importlib.util, sys; '
|
|
551
|
+
'sys.exit(importlib.util.find_spec({!r}) is None)'.format(
|
|
552
|
+
module)])
|
|
553
|
+
report(code == 0, '{} ({}){}'.format(module, why, '' if code == 0
|
|
554
|
+
else ': not installed'), required=False)
|
|
555
|
+
if code != 0:
|
|
556
|
+
missing.append(package)
|
|
557
|
+
|
|
558
|
+
claude = shutil.which('claude')
|
|
559
|
+
report(bool(claude), 'Claude Code (`claude`): {}'.format(claude or
|
|
560
|
+
'not on PATH'), required=False)
|
|
561
|
+
|
|
562
|
+
found = installations()
|
|
563
|
+
current = [item for item in found if not item.get('legacy')]
|
|
564
|
+
report(bool(current), 'installed skills: {}'.format(', '.join(
|
|
565
|
+
'{} ({}, {})'.format(item['name'], item['scope'], item['mode'])
|
|
566
|
+
for item in current) or 'none; `auto-optimize install`'))
|
|
567
|
+
|
|
568
|
+
print('\n'.join(lines))
|
|
569
|
+
|
|
570
|
+
if missing:
|
|
571
|
+
print('\nfor the dashboard: {} -m pip install {}'.format(python3,
|
|
572
|
+
' '.join(missing)))
|
|
573
|
+
|
|
574
|
+
for note in legacy_notes(found):
|
|
575
|
+
print(note)
|
|
576
|
+
|
|
577
|
+
for name in duplicates(current):
|
|
578
|
+
print('\nnote: {} is installed more than once; `auto-optimize list` '
|
|
579
|
+
'shows where'.format(name))
|
|
580
|
+
|
|
581
|
+
return 1 if problems else 0
|
|
582
|
+
|
|
583
|
+
|
|
584
|
+
###
|
|
585
|
+
# The command line
|
|
586
|
+
###
|
|
587
|
+
|
|
588
|
+
def parser():
|
|
589
|
+
top = argparse.ArgumentParser(prog='auto-optimize', description=__doc__,
|
|
590
|
+
formatter_class=argparse.RawDescriptionHelpFormatter)
|
|
591
|
+
top.add_argument('--version', action='version',
|
|
592
|
+
version='auto-optimize ' + __version__)
|
|
593
|
+
commands = top.add_subparsers(dest='command', metavar='COMMAND')
|
|
594
|
+
commands.required = True
|
|
595
|
+
|
|
596
|
+
def where(sub, verb):
|
|
597
|
+
group = sub.add_mutually_exclusive_group()
|
|
598
|
+
group.add_argument('--project', nargs='?', const='.', metavar='DIR',
|
|
599
|
+
help='{} the project skills folder, DIR/.claude/skills (DIR '
|
|
600
|
+
'defaults to the current directory)'.format(verb))
|
|
601
|
+
group.add_argument('-d', '--directory', metavar='DIR',
|
|
602
|
+
help='{} DIR/<skill> instead of ~/.claude/skills/<skill>'.format(
|
|
603
|
+
verb))
|
|
604
|
+
sub.add_argument('-f', '--force', action='store_true',
|
|
605
|
+
help='replace or remove a folder this installer did not create')
|
|
606
|
+
|
|
607
|
+
one = commands.add_parser('install', help='copy the skills into a '
|
|
608
|
+
'skills folder (the user folder by default)')
|
|
609
|
+
one.add_argument('skills', nargs='*', metavar='SKILL')
|
|
610
|
+
where(one, 'install into')
|
|
611
|
+
one.add_argument('--symlink', action='store_true', help='link to this '
|
|
612
|
+
'package\'s copy instead of copying it; edits there show up at once, '
|
|
613
|
+
'and the link breaks if the package moves')
|
|
614
|
+
one.set_defaults(func=install)
|
|
615
|
+
|
|
616
|
+
two = commands.add_parser('uninstall', help='remove skills this '
|
|
617
|
+
'installer put in a skills folder')
|
|
618
|
+
two.add_argument('skills', nargs='*', metavar='SKILL')
|
|
619
|
+
where(two, 'remove from')
|
|
620
|
+
two.set_defaults(func=uninstall)
|
|
621
|
+
|
|
622
|
+
three = commands.add_parser('list', help='every installed copy Claude '
|
|
623
|
+
'Code would load from here: user, project and plugin')
|
|
624
|
+
three.set_defaults(func=list_command)
|
|
625
|
+
|
|
626
|
+
four = commands.add_parser('path', help='the folder of an installed '
|
|
627
|
+
'skill, e.g. AO="$(auto-optimize path)/scripts"')
|
|
628
|
+
four.add_argument('skill', nargs='?', metavar='SKILL')
|
|
629
|
+
four.add_argument('--bundled', action='store_true', help='the copy '
|
|
630
|
+
'inside this package instead')
|
|
631
|
+
four.set_defaults(func=path_command)
|
|
632
|
+
|
|
633
|
+
five = commands.add_parser('doctor', help='check python3, git, tar, the '
|
|
634
|
+
'dashboard\'s optional modules and the installed copies')
|
|
635
|
+
five.set_defaults(func=doctor)
|
|
636
|
+
|
|
637
|
+
return top
|
|
638
|
+
|
|
639
|
+
|
|
640
|
+
def main(argv=None):
|
|
641
|
+
args = parser().parse_args(argv)
|
|
642
|
+
|
|
643
|
+
try:
|
|
644
|
+
return args.func(args)
|
|
645
|
+
except InstallError as error:
|
|
646
|
+
print('error: {}'.format(error), file=sys.stderr)
|
|
647
|
+
return 1
|
|
648
|
+
|
|
649
|
+
|
|
650
|
+
if __name__ == '__main__':
|
|
651
|
+
sys.exit(main())
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Jacob Schreiber
|
|
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.
|