skillshuttle 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.
- agent_skill_manager/__init__.py +12 -0
- agent_skill_manager/__main__.py +5 -0
- agent_skill_manager/completion/__init__.py +25 -0
- agent_skill_manager/completion/_askill +112 -0
- agent_skill_manager/completion/askill.bash +105 -0
- agent_skill_manager/completion/askill.fish +94 -0
- agent_skill_manager/config/__init__.py +4 -0
- agent_skill_manager/config/products.py +238 -0
- agent_skill_manager/controllers/__init__.py +4 -0
- agent_skill_manager/controllers/cli.py +1344 -0
- agent_skill_manager/controllers/parsers/__init__.py +77 -0
- agent_skill_manager/controllers/parsers/authoring.py +109 -0
- agent_skill_manager/controllers/parsers/distribution.py +168 -0
- agent_skill_manager/controllers/parsers/operations.py +108 -0
- agent_skill_manager/models/__init__.py +11 -0
- agent_skill_manager/models/product.py +30 -0
- agent_skill_manager/models/report.py +62 -0
- agent_skill_manager/services/__init__.py +4 -0
- agent_skill_manager/services/audit.py +441 -0
- agent_skill_manager/services/auto_adopt.py +238 -0
- agent_skill_manager/services/ci_format.py +100 -0
- agent_skill_manager/services/doctor.py +305 -0
- agent_skill_manager/services/drift.py +88 -0
- agent_skill_manager/services/get.py +160 -0
- agent_skill_manager/services/inventory.py +37 -0
- agent_skill_manager/services/manifest.py +167 -0
- agent_skill_manager/services/overlap.py +112 -0
- agent_skill_manager/services/paths_export.py +204 -0
- agent_skill_manager/services/publish.py +298 -0
- agent_skill_manager/services/registry.py +124 -0
- agent_skill_manager/services/remediation.py +145 -0
- agent_skill_manager/services/scaffold.py +191 -0
- agent_skill_manager/services/sources.py +261 -0
- agent_skill_manager/services/spec.py +188 -0
- agent_skill_manager/services/sync/__init__.py +35 -0
- agent_skill_manager/services/sync/adopt.py +174 -0
- agent_skill_manager/services/sync/audit_report.py +128 -0
- agent_skill_manager/services/sync/engine.py +510 -0
- agent_skill_manager/services/sync/install.py +411 -0
- agent_skill_manager/services/sync/pack.py +43 -0
- agent_skill_manager/services/sync/settings_io.py +110 -0
- agent_skill_manager/services/upgrade.py +205 -0
- agent_skill_manager/services/watch.py +473 -0
- agent_skill_manager/services/welcome.py +49 -0
- agent_skill_manager/utils/__init__.py +4 -0
- agent_skill_manager/utils/filesystem.py +219 -0
- agent_skill_manager/utils/watcher.py +607 -0
- skillshuttle-1.0.0.dist-info/METADATA +552 -0
- skillshuttle-1.0.0.dist-info/RECORD +53 -0
- skillshuttle-1.0.0.dist-info/WHEEL +5 -0
- skillshuttle-1.0.0.dist-info/entry_points.txt +3 -0
- skillshuttle-1.0.0.dist-info/licenses/LICENSE +21 -0
- skillshuttle-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,298 @@
|
|
|
1
|
+
"""Skill publishing for ``askill publish`` (v0.15.0, docs/v0.15.0-plan.md R2).
|
|
2
|
+
|
|
3
|
+
Takes one skill from the central repository to a GitHub repository so
|
|
4
|
+
others can ``askill install owner/repo@skill`` (or ``npx skills add``).
|
|
5
|
+
|
|
6
|
+
Design notes:
|
|
7
|
+
|
|
8
|
+
- Three gates run before anything touches git: spec check, per-product
|
|
9
|
+
frontmatter, and a security audit floor (dangerous verdicts block).
|
|
10
|
+
- ``push=False`` (the CLI default) is a dry run: gates and the exact git
|
|
11
|
+
plan print, nothing is pushed and no bookkeeping is written.
|
|
12
|
+
- The remote URL defaults to SSH (``git@github.com:owner/repo.git``) to
|
|
13
|
+
match the maintainer workflow; ``https=True`` switches to the credential
|
|
14
|
+
helper route.
|
|
15
|
+
- Two layouts: **subdir** (default, additive and non-destructive - the
|
|
16
|
+
skill lands in ``<name>/`` next to whatever the repo already holds) and
|
|
17
|
+
**root** (``root=True``, replaces the repo root contents; refuses when
|
|
18
|
+
the remote has files unless ``force=True``).
|
|
19
|
+
- Tests drive the whole flow against local ``file://`` bare remotes - no
|
|
20
|
+
network, no credentials.
|
|
21
|
+
"""
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import json
|
|
25
|
+
import re
|
|
26
|
+
import shutil
|
|
27
|
+
import subprocess
|
|
28
|
+
import tempfile
|
|
29
|
+
import time
|
|
30
|
+
from pathlib import Path
|
|
31
|
+
|
|
32
|
+
from ..config.products import CENTRAL_DIR
|
|
33
|
+
from .audit import analyze_skill_dir
|
|
34
|
+
from .spec import check_spec, product_frontmatter_issues
|
|
35
|
+
|
|
36
|
+
PUBLISHED_FILE = ".askill-published.json"
|
|
37
|
+
|
|
38
|
+
_GIT_TIMEOUT_S = 120
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def _git(*args: str, cwd: Path | None = None, check: bool = True) -> subprocess.CompletedProcess:
|
|
42
|
+
"""Run a git command; capture output, never inherit the terminal."""
|
|
43
|
+
return subprocess.run(
|
|
44
|
+
["git", *args],
|
|
45
|
+
cwd=str(cwd) if cwd else None,
|
|
46
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace",
|
|
47
|
+
check=check, timeout=_GIT_TIMEOUT_S,
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _remote_url(repo: str, https: bool) -> str:
|
|
52
|
+
"""``owner/name`` -> a cloneable URL (SSH default, HTTPS opt-in).
|
|
53
|
+
|
|
54
|
+
Anything that is not a strict ``owner/name`` shorthand (explicit URLs,
|
|
55
|
+
local paths - the latter is how tests inject file remotes) passes
|
|
56
|
+
through unchanged. Only trailing slashes are stripped: stripping the
|
|
57
|
+
leading one would corrupt absolute Unix paths (``/tmp/...`` became
|
|
58
|
+
``tmp/...`` and stopped resolving - caught by CI on Linux).
|
|
59
|
+
"""
|
|
60
|
+
repo = repo.rstrip("/")
|
|
61
|
+
if re.fullmatch(r"[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+", repo):
|
|
62
|
+
return f"https://github.com/{repo}.git" if https else f"git@github.com:{repo}.git"
|
|
63
|
+
return repo
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def _run_gates(
|
|
67
|
+
skill_dir: Path, targets: list[str] | None = None
|
|
68
|
+
) -> tuple[list[str], bool]:
|
|
69
|
+
"""Pre-publish gates. Returns (problems, risky_but_allowed).
|
|
70
|
+
|
|
71
|
+
``targets`` (product shorts) scopes the per-product frontmatter gate to
|
|
72
|
+
the products the skill is actually published to; ``None`` checks all
|
|
73
|
+
declaring products (see product_frontmatter_issues).
|
|
74
|
+
"""
|
|
75
|
+
problems: list[str] = []
|
|
76
|
+
|
|
77
|
+
spec = check_spec(skill_dir)
|
|
78
|
+
if not spec["ok"]:
|
|
79
|
+
problems.extend(f"spec: {e}" for e in spec["errors"])
|
|
80
|
+
|
|
81
|
+
product_issues = product_frontmatter_issues(skill_dir, targets=targets)
|
|
82
|
+
if product_issues:
|
|
83
|
+
scope = (
|
|
84
|
+
f"for targets {', '.join(sorted(targets))}" if targets else "for all products"
|
|
85
|
+
)
|
|
86
|
+
problems.extend(f"frontmatter ({scope}): {i}" for i in product_issues)
|
|
87
|
+
|
|
88
|
+
risky = False
|
|
89
|
+
report = analyze_skill_dir(skill_dir)
|
|
90
|
+
verdict = report.get("verdict", "safe")
|
|
91
|
+
if verdict == "dangerous":
|
|
92
|
+
problems.append(
|
|
93
|
+
f"audit: verdict is dangerous ({report.get('score')}/100) - "
|
|
94
|
+
"fix the findings before publishing"
|
|
95
|
+
)
|
|
96
|
+
elif verdict in ("risky", "caution"):
|
|
97
|
+
risky = True
|
|
98
|
+
|
|
99
|
+
return problems, risky
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _remote_exists(url: str) -> bool:
|
|
103
|
+
try:
|
|
104
|
+
result = _git("ls-remote", url, check=False)
|
|
105
|
+
return result.returncode == 0
|
|
106
|
+
except (subprocess.TimeoutExpired, OSError):
|
|
107
|
+
return False
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
def _load_published(central: Path) -> dict:
|
|
111
|
+
path = central / PUBLISHED_FILE
|
|
112
|
+
if not path.exists():
|
|
113
|
+
return {}
|
|
114
|
+
try:
|
|
115
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
116
|
+
except (OSError, ValueError):
|
|
117
|
+
return {}
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _record_published(central: Path, entry: dict) -> None:
|
|
121
|
+
data = _load_published(central)
|
|
122
|
+
data[entry["skill"]] = entry
|
|
123
|
+
(central / PUBLISHED_FILE).write_text(
|
|
124
|
+
json.dumps(data, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
def publish_skill(
|
|
129
|
+
name: str,
|
|
130
|
+
repo: str,
|
|
131
|
+
*,
|
|
132
|
+
root: bool = False,
|
|
133
|
+
force: bool = False,
|
|
134
|
+
https: bool = False,
|
|
135
|
+
push: bool = False,
|
|
136
|
+
create: bool = False,
|
|
137
|
+
targets: list[str] | None = None,
|
|
138
|
+
central_dir: Path | None = None,
|
|
139
|
+
verbose: bool = True,
|
|
140
|
+
) -> dict:
|
|
141
|
+
"""Publish one skill from the central repo to a git repository.
|
|
142
|
+
|
|
143
|
+
Args:
|
|
144
|
+
name: Skill directory in the central repository.
|
|
145
|
+
repo: ``owner/name`` shorthand or an explicit URL (tests use
|
|
146
|
+
``file://`` remotes).
|
|
147
|
+
root: Replace the repository ROOT contents with the skill
|
|
148
|
+
(single-skill repo, install as ``owner/repo``). Default is the
|
|
149
|
+
additive ``<skill>/`` subdir layout (install as
|
|
150
|
+
``owner/repo@skill``).
|
|
151
|
+
force: Allow root mode on a non-empty remote (still requires push).
|
|
152
|
+
https: Clone/push over the HTTPS credential-helper route instead
|
|
153
|
+
of the default SSH URL.
|
|
154
|
+
push: Actually push. Without it the run is a dry run: gates run,
|
|
155
|
+
the git plan prints, nothing is written.
|
|
156
|
+
create: Create the GitHub repository first via ``gh repo create``
|
|
157
|
+
(needs the gh CLI; other hosts must pre-create the repo).
|
|
158
|
+
targets: Limit the per-product frontmatter gate to these product
|
|
159
|
+
shorts (repeatable). Default: check every declaring product.
|
|
160
|
+
Use this when publishing a skill to a subset of products so an
|
|
161
|
+
unrelated product's requirement can't block the publish.
|
|
162
|
+
central_dir: Override the central repository (tests).
|
|
163
|
+
verbose: Print progress.
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
``{"ok", "error", "problems", "risky", "plan", "published", "url"}``
|
|
167
|
+
where ``plan`` lists the git actions (dry run fills this instead
|
|
168
|
+
of pushing) and ``published`` is the bookkeeping entry on success.
|
|
169
|
+
"""
|
|
170
|
+
report: dict = {
|
|
171
|
+
"skill": name, "ok": False, "error": None, "problems": [],
|
|
172
|
+
"risky": False, "plan": [], "published": None, "url": None,
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
central = Path(central_dir) if central_dir is not None else CENTRAL_DIR
|
|
176
|
+
skill_dir = central / name
|
|
177
|
+
if not skill_dir.is_dir() or not (skill_dir / "SKILL.md").exists():
|
|
178
|
+
report["error"] = f"Skill not found in central repo: {name}"
|
|
179
|
+
return report
|
|
180
|
+
|
|
181
|
+
# ------------------------------------------------------------- gates
|
|
182
|
+
problems, risky = _run_gates(skill_dir, targets=targets)
|
|
183
|
+
report["problems"] = problems
|
|
184
|
+
report["risky"] = risky
|
|
185
|
+
if problems:
|
|
186
|
+
report["error"] = "pre-publish gates failed (see problems)"
|
|
187
|
+
return report
|
|
188
|
+
|
|
189
|
+
url = _remote_url(repo, https)
|
|
190
|
+
report["url"] = url
|
|
191
|
+
|
|
192
|
+
# ------------------------------------------------------------ remote
|
|
193
|
+
workdir = Path(tempfile.mkdtemp(prefix="askill-publish-"))
|
|
194
|
+
try:
|
|
195
|
+
if _remote_exists(url):
|
|
196
|
+
_git("clone", "--depth", "1", url, str(workdir))
|
|
197
|
+
elif create:
|
|
198
|
+
gh = shutil.which("gh")
|
|
199
|
+
if not gh:
|
|
200
|
+
report["error"] = (
|
|
201
|
+
"repo does not exist and gh CLI is unavailable - create it "
|
|
202
|
+
f"manually (github.com/new) and rerun with --repo {repo}"
|
|
203
|
+
)
|
|
204
|
+
return report
|
|
205
|
+
if verbose:
|
|
206
|
+
print(f" creating GitHub repo {repo} via gh...")
|
|
207
|
+
result = subprocess.run(
|
|
208
|
+
[gh, "repo", "create", repo, "--public"],
|
|
209
|
+
capture_output=True, text=True, encoding="utf-8", errors="replace",
|
|
210
|
+
timeout=_GIT_TIMEOUT_S,
|
|
211
|
+
)
|
|
212
|
+
if result.returncode != 0:
|
|
213
|
+
report["error"] = f"gh repo create failed: {result.stderr.strip()}"
|
|
214
|
+
return report
|
|
215
|
+
_git("clone", "--depth", "1", url, str(workdir))
|
|
216
|
+
else:
|
|
217
|
+
report["error"] = (
|
|
218
|
+
f"repo not reachable: {url} - pass --create to create it "
|
|
219
|
+
"on GitHub, or check the name"
|
|
220
|
+
)
|
|
221
|
+
return report
|
|
222
|
+
|
|
223
|
+
# -------------------------------------------------- copy the skill
|
|
224
|
+
dest = workdir if root else workdir / name
|
|
225
|
+
if root:
|
|
226
|
+
leftovers = [
|
|
227
|
+
p.name for p in workdir.iterdir()
|
|
228
|
+
if p.name != ".git" and not (p.is_dir() and not any(p.iterdir()))
|
|
229
|
+
]
|
|
230
|
+
if leftovers and not force:
|
|
231
|
+
# gate in dry runs too: the plan must not promise an action
|
|
232
|
+
# a real push would refuse
|
|
233
|
+
report["error"] = (
|
|
234
|
+
"root mode would replace existing repo content "
|
|
235
|
+
f"({', '.join(leftovers[:3])}...) - pass --force to allow"
|
|
236
|
+
)
|
|
237
|
+
return report
|
|
238
|
+
for p in list(workdir.iterdir()):
|
|
239
|
+
if p.name == ".git":
|
|
240
|
+
continue
|
|
241
|
+
shutil.rmtree(p) if p.is_dir() else p.unlink()
|
|
242
|
+
dest.mkdir(parents=True, exist_ok=True)
|
|
243
|
+
for item in skill_dir.iterdir():
|
|
244
|
+
target = dest / item.name
|
|
245
|
+
if item.is_dir():
|
|
246
|
+
shutil.copytree(item, target, dirs_exist_ok=True)
|
|
247
|
+
else:
|
|
248
|
+
shutil.copy2(item, target)
|
|
249
|
+
|
|
250
|
+
# ------------------------------------------------------- git plan
|
|
251
|
+
if not _git("status", "--porcelain", cwd=workdir).stdout.strip():
|
|
252
|
+
report["error"] = "nothing to publish - remote already matches the skill"
|
|
253
|
+
return report
|
|
254
|
+
commit_msg = f"publish {name} from askill"
|
|
255
|
+
plan = [
|
|
256
|
+
f"git add -A ({'repo root' if root else name + '/'} layout)",
|
|
257
|
+
f'git commit -m "{commit_msg}"',
|
|
258
|
+
"git push origin HEAD",
|
|
259
|
+
]
|
|
260
|
+
report["plan"] = plan
|
|
261
|
+
if verbose:
|
|
262
|
+
for line in plan:
|
|
263
|
+
print(f" plan: {line}")
|
|
264
|
+
|
|
265
|
+
if not push:
|
|
266
|
+
report["ok"] = True # dry run completed cleanly
|
|
267
|
+
return report
|
|
268
|
+
|
|
269
|
+
_git("add", "-A", cwd=workdir)
|
|
270
|
+
_git("-c", "user.name=askill-publish", "-c",
|
|
271
|
+
"user.email=askill@local", "commit", "-m", commit_msg, cwd=workdir)
|
|
272
|
+
_git("push", "origin", "HEAD", cwd=workdir)
|
|
273
|
+
commit = _git("rev-parse", "--short", "HEAD", cwd=workdir).stdout.strip()
|
|
274
|
+
|
|
275
|
+
entry = {
|
|
276
|
+
"skill": name, "repo": repo, "url": url,
|
|
277
|
+
"layout": "root" if root else "subdir",
|
|
278
|
+
"branch": _git("rev-parse", "--abbrev-ref", "HEAD", cwd=workdir).stdout.strip(),
|
|
279
|
+
"commit": commit, "pushed_at": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
|
280
|
+
}
|
|
281
|
+
_record_published(central, entry)
|
|
282
|
+
report["published"] = entry
|
|
283
|
+
report["ok"] = True
|
|
284
|
+
return report
|
|
285
|
+
except subprocess.CalledProcessError as e:
|
|
286
|
+
report["error"] = f"git failed: {(e.stderr or e.stdout or '').strip()[:300]}"
|
|
287
|
+
return report
|
|
288
|
+
except (subprocess.TimeoutExpired, OSError) as e:
|
|
289
|
+
report["error"] = f"git failed: {e}"
|
|
290
|
+
return report
|
|
291
|
+
finally:
|
|
292
|
+
shutil.rmtree(workdir, ignore_errors=True)
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def published_skills(central_dir: Path | None = None) -> dict:
|
|
296
|
+
"""Load the publish bookkeeping (``.askill-published.json``)."""
|
|
297
|
+
central = Path(central_dir) if central_dir is not None else CENTRAL_DIR
|
|
298
|
+
return _load_published(central)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"""skills.sh ecosystem integration (v0.11.0).
|
|
2
|
+
|
|
3
|
+
skills.sh (by Vercel Labs) is the de-facto registry of the open Agent
|
|
4
|
+
Skills ecosystem (agentskills.io). This module gives askill first-class,
|
|
5
|
+
stdlib-only access to it:
|
|
6
|
+
|
|
7
|
+
- :func:`search_skills` - query the public skills.sh search API
|
|
8
|
+
- :func:`resolve_source` - normalize ecosystem shorthand sources to GitHub
|
|
9
|
+
- :func:`find_skill_dir` - locate one skill's directory inside a cloned repo
|
|
10
|
+
|
|
11
|
+
Shorthand source formats accepted by ``askill install`` (mirroring the
|
|
12
|
+
``npx skills`` CLI so every command documented on skills.sh works verbatim):
|
|
13
|
+
|
|
14
|
+
owner/repo -> https://github.com/owner/repo
|
|
15
|
+
owner/repo@skill -> same, then pick the ``skill`` dir
|
|
16
|
+
https://skills.sh/owner/repo/skill -> same as owner/repo@skill
|
|
17
|
+
|
|
18
|
+
Plain GitHub URLs and local paths keep working exactly as before.
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
|
|
22
|
+
import json
|
|
23
|
+
import re
|
|
24
|
+
import urllib.error
|
|
25
|
+
import urllib.parse
|
|
26
|
+
import urllib.request
|
|
27
|
+
from pathlib import Path
|
|
28
|
+
|
|
29
|
+
SKILLS_SH_API = "https://skills.sh/api/search"
|
|
30
|
+
USER_AGENT = "askill (+https://github.com/yxdwind/skillshuttle)"
|
|
31
|
+
REQUEST_TIMEOUT_S = 15
|
|
32
|
+
|
|
33
|
+
# owner/repo or owner/repo@skill - the drive-letter colon of Windows paths
|
|
34
|
+
# (C:/...) never matches, so local paths stay local.
|
|
35
|
+
_SHORTHAND_RE = re.compile(
|
|
36
|
+
r"^([A-Za-z0-9_.-]+)/([A-Za-z0-9_.-]+)(?:@([A-Za-z0-9_.-]+))?$"
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class RegistryError(RuntimeError):
|
|
41
|
+
"""skills.sh registry unreachable or returned an unusable response."""
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
# ---------------------------------------------------------------- search
|
|
45
|
+
|
|
46
|
+
def search_skills(query: str, limit: int = 10, timeout: float = REQUEST_TIMEOUT_S) -> list[dict]:
|
|
47
|
+
"""Search the skills.sh registry.
|
|
48
|
+
|
|
49
|
+
Returns a list of ``{"source", "skill_id", "name", "installs"}`` dicts,
|
|
50
|
+
best match first. Raises :class:`RegistryError` on network/API failure
|
|
51
|
+
so callers can fall back or report cleanly.
|
|
52
|
+
"""
|
|
53
|
+
url = f"{SKILLS_SH_API}?q={urllib.parse.quote(query.strip())}"
|
|
54
|
+
req = urllib.request.Request(
|
|
55
|
+
url, headers={"User-Agent": USER_AGENT, "Accept": "application/json"},
|
|
56
|
+
)
|
|
57
|
+
try:
|
|
58
|
+
with urllib.request.urlopen(req, timeout=timeout) as resp:
|
|
59
|
+
data = json.loads(resp.read().decode("utf-8", "replace"))
|
|
60
|
+
except (urllib.error.URLError, OSError, ValueError) as exc:
|
|
61
|
+
raise RegistryError(f"skills.sh unreachable: {exc}") from exc
|
|
62
|
+
|
|
63
|
+
results = []
|
|
64
|
+
for item in data.get("skills", []):
|
|
65
|
+
if not isinstance(item, dict):
|
|
66
|
+
continue
|
|
67
|
+
results.append({
|
|
68
|
+
"source": item.get("source", ""),
|
|
69
|
+
"skill_id": item.get("skillId", ""),
|
|
70
|
+
"name": item.get("name") or item.get("skillId", ""),
|
|
71
|
+
"installs": int(item.get("installs", 0) or 0),
|
|
72
|
+
})
|
|
73
|
+
if len(results) >= limit:
|
|
74
|
+
break
|
|
75
|
+
return results
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
# ---------------------------------------------------------------- resolve
|
|
79
|
+
|
|
80
|
+
def resolve_source(source: str) -> dict | None:
|
|
81
|
+
"""Normalize a skills.sh-ecosystem source into GitHub install parameters.
|
|
82
|
+
|
|
83
|
+
Returns ``{"repo_url", "skill", "original"}`` for shorthand sources, or
|
|
84
|
+
``None`` when *source* is not ecosystem shorthand (caller then treats it
|
|
85
|
+
as a local path or plain URL, unchanged).
|
|
86
|
+
"""
|
|
87
|
+
src = source.strip()
|
|
88
|
+
if "://" in src or src.startswith("git@"):
|
|
89
|
+
# skills.sh page URLs: https://skills.sh/owner/repo[/skill]
|
|
90
|
+
if "skills.sh/" in src:
|
|
91
|
+
path = src.split("skills.sh/", 1)[1].strip("/")
|
|
92
|
+
parts = [p for p in path.split("/") if p]
|
|
93
|
+
if len(parts) >= 2:
|
|
94
|
+
return {
|
|
95
|
+
"repo_url": f"https://github.com/{parts[0]}/{parts[1]}",
|
|
96
|
+
"skill": parts[2] if len(parts) > 2 else None,
|
|
97
|
+
"original": source,
|
|
98
|
+
}
|
|
99
|
+
return None
|
|
100
|
+
|
|
101
|
+
match = _SHORTHAND_RE.match(src.strip("/"))
|
|
102
|
+
if not match:
|
|
103
|
+
return None
|
|
104
|
+
return {
|
|
105
|
+
"repo_url": f"https://github.com/{match.group(1)}/{match.group(2)}",
|
|
106
|
+
"skill": match.group(3),
|
|
107
|
+
"original": source,
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def find_skill_dir(repo_root: Path, skill_id: str) -> Path | None:
|
|
112
|
+
"""Locate the directory of one skill inside a cloned repo.
|
|
113
|
+
|
|
114
|
+
Checked in order: ``<root>/<skill_id>``, ``<root>/skills/<skill_id>``,
|
|
115
|
+
then a full scan for a directory named *skill_id* containing SKILL.md
|
|
116
|
+
(the registry id carries no path information, so the layout varies).
|
|
117
|
+
"""
|
|
118
|
+
for candidate in (repo_root / skill_id, repo_root / "skills" / skill_id):
|
|
119
|
+
if (candidate / "SKILL.md").is_file():
|
|
120
|
+
return candidate
|
|
121
|
+
for skill_md in sorted(repo_root.rglob("SKILL.md")):
|
|
122
|
+
if skill_md.parent.name == skill_id:
|
|
123
|
+
return skill_md.parent
|
|
124
|
+
return None
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
"""Derive a repair plan from a ``doctor`` report (P1-7).
|
|
2
|
+
|
|
3
|
+
This module is **pure**: it never touches the filesystem, never invokes sync,
|
|
4
|
+
and never imports the sync package. It only classifies what ``doctor`` already
|
|
5
|
+
found into (a) actions ``--apply`` may execute and (b) actions that need a
|
|
6
|
+
human. Execution lives in the CLI so the read-only guarantee of
|
|
7
|
+
``services/doctor.py`` stays intact.
|
|
8
|
+
|
|
9
|
+
Classification of a dead link is the same rule ``gc_dead_links`` uses:
|
|
10
|
+
a dead link whose name still exists in the central repo is re-linkable by a
|
|
11
|
+
normal ``askill sync``; one whose name is gone is stale and belongs to
|
|
12
|
+
``askill sync --gc``. Real directories are never repairable automatically -
|
|
13
|
+
they are drift/adopt territory.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
from __future__ import annotations
|
|
17
|
+
|
|
18
|
+
from typing import Any
|
|
19
|
+
|
|
20
|
+
__all__ = ["build_fix_plan", "render_plan"]
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def build_fix_plan(
|
|
24
|
+
report: dict[str, Any],
|
|
25
|
+
central_names: set[str] | None = None,
|
|
26
|
+
) -> dict[str, Any]:
|
|
27
|
+
"""Return a machine-readable repair plan derived from a doctor report."""
|
|
28
|
+
names = central_names or set()
|
|
29
|
+
actions: list[dict[str, Any]] = []
|
|
30
|
+
manual: list[dict[str, str]] = []
|
|
31
|
+
|
|
32
|
+
relink: list[str] = []
|
|
33
|
+
stale: list[str] = []
|
|
34
|
+
for row in report.get("products", []):
|
|
35
|
+
short = row.get("short", "?")
|
|
36
|
+
for name in row.get("broken_names") or []:
|
|
37
|
+
target = f"{short}/{name}"
|
|
38
|
+
(relink if name in names else stale).append(target)
|
|
39
|
+
|
|
40
|
+
if relink:
|
|
41
|
+
actions.append({
|
|
42
|
+
"id": "relink",
|
|
43
|
+
"command": "askill sync",
|
|
44
|
+
"auto": True,
|
|
45
|
+
"reason": "dead link(s) still named after a central skill - a normal sync reconnects them",
|
|
46
|
+
"items": sorted(relink),
|
|
47
|
+
})
|
|
48
|
+
if stale:
|
|
49
|
+
actions.append({
|
|
50
|
+
"id": "gc",
|
|
51
|
+
"command": "askill sync --gc",
|
|
52
|
+
"auto": True,
|
|
53
|
+
"reason": "dead link(s) with no matching central skill - safe to remove",
|
|
54
|
+
"items": sorted(stale),
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
locked = [
|
|
58
|
+
row.get("short", "?") for row in report.get("products", [])
|
|
59
|
+
if row.get("settings_writable") is False
|
|
60
|
+
]
|
|
61
|
+
if locked:
|
|
62
|
+
manual.append({
|
|
63
|
+
"id": "settings-locked",
|
|
64
|
+
"command": "close the running IDE, then re-run: askill sync",
|
|
65
|
+
"reason": "settings.json is locked; sync can create links but cannot enable the skill",
|
|
66
|
+
"items": ", ".join(sorted(locked)),
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
orphans = report.get("central", {}).get("orphan_sources") or []
|
|
70
|
+
if orphans:
|
|
71
|
+
manual.append({
|
|
72
|
+
"id": "orphan-sources",
|
|
73
|
+
"command": "edit .askill-sources.json in the central repo",
|
|
74
|
+
"reason": "source-tracking entries without a matching skill",
|
|
75
|
+
"items": ", ".join(orphans),
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
drift = [
|
|
79
|
+
row.get("short", "?") for row in report.get("products", [])
|
|
80
|
+
if (row.get("fork_dirs") or 0) > 0
|
|
81
|
+
]
|
|
82
|
+
if drift:
|
|
83
|
+
manual.append({
|
|
84
|
+
"id": "drift-candidates",
|
|
85
|
+
"command": "askill drift (then askill adopt or askill sync --force)",
|
|
86
|
+
"reason": "real directories shadow central skills - never overwritten automatically",
|
|
87
|
+
"items": ", ".join(sorted(drift)),
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
if not report.get("central", {}).get("exists", True):
|
|
91
|
+
manual.append({
|
|
92
|
+
"id": "missing-central",
|
|
93
|
+
"command": "askill install <source>",
|
|
94
|
+
"reason": "central repository does not exist yet",
|
|
95
|
+
"items": "",
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
for check in report.get("checks", []):
|
|
99
|
+
if check.get("severity") == "fail":
|
|
100
|
+
manual.append({
|
|
101
|
+
"id": f"env:{check.get('id', '?')}",
|
|
102
|
+
"command": "fix the environment, then re-run: askill doctor",
|
|
103
|
+
"reason": check.get("detail", ""),
|
|
104
|
+
"items": "",
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
manual.append({
|
|
108
|
+
"id": "rollbacks",
|
|
109
|
+
"command": "askill rollback --list",
|
|
110
|
+
"reason": "snapshots taken before each update are available if a new version misbehaves",
|
|
111
|
+
"items": "",
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
return {
|
|
115
|
+
"actions": actions,
|
|
116
|
+
"manual": manual,
|
|
117
|
+
"auto_count": len(actions),
|
|
118
|
+
"manual_count": len(manual),
|
|
119
|
+
"noop": not actions,
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def render_plan(plan: dict[str, Any], *, applying: bool = False) -> str:
|
|
124
|
+
"""Human-readable plan. ``applying`` only changes the header wording."""
|
|
125
|
+
mode = "applying repair plan" if applying else "repair plan (dry-run, no changes made)"
|
|
126
|
+
lines = [f"askill doctor --fix - {mode}", ""]
|
|
127
|
+
if plan["noop"]:
|
|
128
|
+
lines.append(" No automatic repairs needed: no stale or re-linkable dead links found.")
|
|
129
|
+
for action in plan["actions"]:
|
|
130
|
+
lines.append(f" [auto] {action['command']}")
|
|
131
|
+
lines.append(f" {action['reason']}")
|
|
132
|
+
items = action["items"]
|
|
133
|
+
if items:
|
|
134
|
+
lines.append(f" affected: {', '.join(items[:6])}"
|
|
135
|
+
+ (" ..." if len(items) > 6 else ""))
|
|
136
|
+
if plan["manual"]:
|
|
137
|
+
lines += ["", " Manual steps (never executed automatically):"]
|
|
138
|
+
for item in plan["manual"]:
|
|
139
|
+
lines.append(f" - {item['id']}: {item['command']}")
|
|
140
|
+
if item["items"]:
|
|
141
|
+
lines.append(f" affected: {item['items']}")
|
|
142
|
+
if item["reason"]:
|
|
143
|
+
lines.append(f" why: {item['reason']}")
|
|
144
|
+
lines += ["", " Real directories are never overwritten; use drift/adopt/--force explicitly."]
|
|
145
|
+
return "\n".join(lines)
|