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,191 @@
|
|
|
1
|
+
"""Skill scaffolding for ``askill new`` (v0.15.0, docs/v0.15.0-plan.md R1).
|
|
2
|
+
|
|
3
|
+
Creates a spec-compliant skill skeleton in the central repository. The
|
|
4
|
+
SKILL.md frontmatter is generated from the declarative product registry
|
|
5
|
+
(``products.py`` → ``required_frontmatter``), so scaffolding automatically
|
|
6
|
+
tracks per-product requirements: declare a new field on a product and the
|
|
7
|
+
scaffold picks it up without any change here.
|
|
8
|
+
"""
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
from ..config.products import CENTRAL_DIR, PRODUCTS
|
|
14
|
+
from .spec import _NAME_RE, NAME_MAX, check_spec, product_frontmatter_issues
|
|
15
|
+
|
|
16
|
+
_DESC_PLACEHOLDER = "(TODO) One line: what does {name} do and when should the agent use it?"
|
|
17
|
+
_DESC_ZH_PLACEHOLDER = "(TODO)一句话说明 {name} 的用途与适用场景。"
|
|
18
|
+
|
|
19
|
+
_BODY_TEMPLATE = """\
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# {name}
|
|
23
|
+
|
|
24
|
+
{description}
|
|
25
|
+
|
|
26
|
+
## What it does
|
|
27
|
+
|
|
28
|
+
(TODO) Describe when the agent should load this skill and what problem it solves.
|
|
29
|
+
|
|
30
|
+
## How to use
|
|
31
|
+
|
|
32
|
+
(TODO) Step-by-step instructions the agent should follow.
|
|
33
|
+
|
|
34
|
+
## Files
|
|
35
|
+
|
|
36
|
+
- `references/` - detailed documentation, loaded on demand (keeps SKILL.md
|
|
37
|
+
under the ~500-line progressive-disclosure recommendation)
|
|
38
|
+
- `scripts/` - optional helper scripts. The security audit scans every file
|
|
39
|
+
here: avoid `curl | sh`, hardcoded secrets and prompt-injection phrasing.
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
_REFERENCES_README = """\
|
|
43
|
+
# references/
|
|
44
|
+
|
|
45
|
+
(TODO) Move detailed documentation here - reference files the agent reads
|
|
46
|
+
on demand. Keeping SKILL.md lean (~500 lines max) follows the progressive
|
|
47
|
+
disclosure recommendation of the Agent Skills spec.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def validate_skill_name(name: str) -> str | None:
|
|
52
|
+
"""Return an error message for an invalid skill name, else None.
|
|
53
|
+
|
|
54
|
+
Mirrors the agentskills.io rules that ``askill verify`` enforces, so a
|
|
55
|
+
name accepted here is never rejected there.
|
|
56
|
+
"""
|
|
57
|
+
if not name:
|
|
58
|
+
return "Skill name must not be empty."
|
|
59
|
+
if len(name) > NAME_MAX:
|
|
60
|
+
return f"Skill name is {len(name)} chars (max {NAME_MAX})."
|
|
61
|
+
if not _NAME_RE.match(name):
|
|
62
|
+
return (
|
|
63
|
+
f"Skill name {name!r} must be lowercase letters/digits with "
|
|
64
|
+
"single hyphens between segments (no leading/trailing/double hyphens)."
|
|
65
|
+
)
|
|
66
|
+
return None
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def collect_required_frontmatter(
|
|
70
|
+
targets: list[str] | None,
|
|
71
|
+
) -> tuple[list[str], str | None]:
|
|
72
|
+
"""Union of extra frontmatter fields declared by the given targets.
|
|
73
|
+
|
|
74
|
+
``targets=None`` means every declaring product (superset - the default
|
|
75
|
+
so a scaffold loads in any product without edits). ``targets=[]`` means
|
|
76
|
+
explicitly no product requirements (base spec fields only). The raw
|
|
77
|
+
declaration order is preserved; note a product may declare ``name`` or
|
|
78
|
+
``description`` (e.g. QwenWork documents all four fields) -
|
|
79
|
+
:func:`create_skill` skips those because the base frontmatter always
|
|
80
|
+
provides them.
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
(fields, error) - error names an unknown target short, if any.
|
|
84
|
+
"""
|
|
85
|
+
if targets is not None:
|
|
86
|
+
known = sorted(p["short"] for p in PRODUCTS)
|
|
87
|
+
unknown = [t for t in targets if t not in known]
|
|
88
|
+
if unknown:
|
|
89
|
+
return [], (
|
|
90
|
+
f"Unknown product short(s): {', '.join(unknown)} "
|
|
91
|
+
f"(available: {', '.join(known)})"
|
|
92
|
+
)
|
|
93
|
+
fields: list[str] = []
|
|
94
|
+
for p in PRODUCTS:
|
|
95
|
+
if targets is not None and p["short"] not in targets:
|
|
96
|
+
continue
|
|
97
|
+
for f in p.get("required_frontmatter", []):
|
|
98
|
+
if f not in fields:
|
|
99
|
+
fields.append(f)
|
|
100
|
+
return fields, None
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
def create_skill(
|
|
104
|
+
name: str,
|
|
105
|
+
*,
|
|
106
|
+
targets: list[str] | None = None,
|
|
107
|
+
description: str | None = None,
|
|
108
|
+
description_zh: str | None = None,
|
|
109
|
+
version: str = "0.1.0",
|
|
110
|
+
minimal: bool = False,
|
|
111
|
+
central_dir: Path | None = None,
|
|
112
|
+
) -> dict:
|
|
113
|
+
"""Create a new skill skeleton in the central repository.
|
|
114
|
+
|
|
115
|
+
Args:
|
|
116
|
+
name: Skill name; must satisfy the agentskills.io name rules and
|
|
117
|
+
match the directory name (verify enforces both).
|
|
118
|
+
targets: Product shorts whose ``required_frontmatter`` to prefill.
|
|
119
|
+
None = superset of all declaring products; [] = base fields only.
|
|
120
|
+
description: Frontmatter description (TODO placeholder if omitted).
|
|
121
|
+
description_zh: Chinese description (only written when some target
|
|
122
|
+
requires it; TODO placeholder if omitted).
|
|
123
|
+
version: Value for a required ``version`` field (default 0.1.0).
|
|
124
|
+
minimal: Only SKILL.md, no references/ or scripts/ subdirs.
|
|
125
|
+
central_dir: Override the central repository (tests); defaults to
|
|
126
|
+
the module-level ``CENTRAL_DIR``.
|
|
127
|
+
|
|
128
|
+
Returns:
|
|
129
|
+
Report dict ``{"name", "path", "created", "error", "frontmatter",
|
|
130
|
+
"spec", "product_issues"}``. On validation failure ``created`` is
|
|
131
|
+
False and ``error`` explains why; nothing touches the filesystem.
|
|
132
|
+
"""
|
|
133
|
+
report: dict = {
|
|
134
|
+
"name": name, "path": None, "created": False, "error": None,
|
|
135
|
+
"frontmatter": {}, "spec": None, "product_issues": [],
|
|
136
|
+
}
|
|
137
|
+
if err := validate_skill_name(name):
|
|
138
|
+
report["error"] = err
|
|
139
|
+
return report
|
|
140
|
+
fields, err = collect_required_frontmatter(targets)
|
|
141
|
+
if err:
|
|
142
|
+
report["error"] = err
|
|
143
|
+
return report
|
|
144
|
+
|
|
145
|
+
central = Path(central_dir) if central_dir is not None else CENTRAL_DIR
|
|
146
|
+
skill_dir = central / name
|
|
147
|
+
report["path"] = str(skill_dir)
|
|
148
|
+
if skill_dir.exists():
|
|
149
|
+
report["error"] = (
|
|
150
|
+
f"Skill already exists: {skill_dir} "
|
|
151
|
+
f"(remove first with 'askill remove {name}', or pick another name)"
|
|
152
|
+
)
|
|
153
|
+
return report
|
|
154
|
+
|
|
155
|
+
desc = description or _DESC_PLACEHOLDER.format(name=name)
|
|
156
|
+
values: dict[str, str] = {
|
|
157
|
+
"version": version,
|
|
158
|
+
"description_zh": description_zh or _DESC_ZH_PLACEHOLDER.format(name=name),
|
|
159
|
+
}
|
|
160
|
+
fm: dict[str, str] = {"name": name, "description": desc}
|
|
161
|
+
lines = ["---", f"name: {name}", f"description: {desc}"]
|
|
162
|
+
for f in fields:
|
|
163
|
+
if f in fm:
|
|
164
|
+
# base frontmatter already covers it (e.g. QwenWork declares
|
|
165
|
+
# name/description on top of the universal spec) - a duplicate
|
|
166
|
+
# key would shadow the real value when the flat parser reads it
|
|
167
|
+
continue
|
|
168
|
+
value = values.get(f, "TODO")
|
|
169
|
+
lines.append(f"{f}: {value}")
|
|
170
|
+
fm[f] = value
|
|
171
|
+
lines.append("---")
|
|
172
|
+
if not minimal:
|
|
173
|
+
lines.append(_BODY_TEMPLATE.format(name=name, description=desc))
|
|
174
|
+
|
|
175
|
+
skill_dir.mkdir(parents=True)
|
|
176
|
+
(skill_dir / "SKILL.md").write_text("\n".join(lines) + "\n", encoding="utf-8")
|
|
177
|
+
if not minimal:
|
|
178
|
+
refs = skill_dir / "references"
|
|
179
|
+
refs.mkdir()
|
|
180
|
+
(refs / "README.md").write_text(_REFERENCES_README, encoding="utf-8")
|
|
181
|
+
scripts = skill_dir / "scripts"
|
|
182
|
+
scripts.mkdir()
|
|
183
|
+
# keep the empty dir visible to git
|
|
184
|
+
(scripts / ".gitkeep").write_text("", encoding="utf-8")
|
|
185
|
+
|
|
186
|
+
report["created"] = True
|
|
187
|
+
report["frontmatter"] = fm
|
|
188
|
+
# prove compliance on the spot: the scaffold must pass verify untouched
|
|
189
|
+
report["spec"] = check_spec(skill_dir)
|
|
190
|
+
report["product_issues"] = product_frontmatter_issues(skill_dir)
|
|
191
|
+
return report
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
"""Source tracking: record where each skill came from, check for updates.
|
|
2
|
+
|
|
3
|
+
``askill install <github-url>`` writes an entry into
|
|
4
|
+
``~/.agents/skills/.askill-sources.json``; ``askill update [skill]`` then
|
|
5
|
+
compares the recorded repo's latest commit against the recorded one and
|
|
6
|
+
reports / applies upgrades.
|
|
7
|
+
"""
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
import json
|
|
11
|
+
import subprocess
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
|
|
14
|
+
from ..config.products import CENTRAL_DIR
|
|
15
|
+
|
|
16
|
+
SOURCES_FILE = CENTRAL_DIR / ".askill-sources.json"
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# ---------------------------------------------------------------- io
|
|
20
|
+
|
|
21
|
+
def load_sources() -> dict:
|
|
22
|
+
"""Load the sources registry; {} when missing or corrupt."""
|
|
23
|
+
try:
|
|
24
|
+
if SOURCES_FILE.exists():
|
|
25
|
+
return json.loads(SOURCES_FILE.read_text(encoding="utf-8"))
|
|
26
|
+
except (OSError, ValueError):
|
|
27
|
+
pass
|
|
28
|
+
return {}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def save_sources(data: dict) -> None:
|
|
32
|
+
"""Persist the sources registry (utf-8, stable formatting)."""
|
|
33
|
+
SOURCES_FILE.parent.mkdir(parents=True, exist_ok=True)
|
|
34
|
+
SOURCES_FILE.write_text(
|
|
35
|
+
json.dumps(data, ensure_ascii=False, indent=2),
|
|
36
|
+
encoding="utf-8",
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def record_source(
|
|
41
|
+
skill_name: str,
|
|
42
|
+
repo_url: str,
|
|
43
|
+
sub_path: str = "",
|
|
44
|
+
branch: str | None = None,
|
|
45
|
+
commit: str | None = None,
|
|
46
|
+
) -> None:
|
|
47
|
+
"""Record (or overwrite) the origin of one skill."""
|
|
48
|
+
data = load_sources()
|
|
49
|
+
data[skill_name] = {
|
|
50
|
+
"repo_url": repo_url.rstrip("/"),
|
|
51
|
+
"sub_path": sub_path,
|
|
52
|
+
"branch": branch,
|
|
53
|
+
"commit": commit,
|
|
54
|
+
"installed_at": __import__("time").strftime("%Y-%m-%dT%H:%M:%S"),
|
|
55
|
+
}
|
|
56
|
+
save_sources(data)
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def remove_source(skill_name: str) -> None:
|
|
60
|
+
"""Drop the tracking entry for a removed skill."""
|
|
61
|
+
data = load_sources()
|
|
62
|
+
if skill_name in data:
|
|
63
|
+
del data[skill_name]
|
|
64
|
+
save_sources(data)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
# ---------------------------------------------------------------- update
|
|
68
|
+
|
|
69
|
+
def _latest_commit(repo_url: str, branch: str | None) -> tuple[str | None, str | None]:
|
|
70
|
+
"""Fetch the remote HEAD commit sha (and resolved branch) via ls-remote.
|
|
71
|
+
|
|
72
|
+
Returns (sha, branch) - (None, None) on network/git failure.
|
|
73
|
+
"""
|
|
74
|
+
cmd = ["git", "ls-remote", repo_url]
|
|
75
|
+
if branch:
|
|
76
|
+
cmd += [branch]
|
|
77
|
+
try:
|
|
78
|
+
r = subprocess.run(
|
|
79
|
+
cmd, capture_output=True, text=True,
|
|
80
|
+
encoding="utf-8", errors="replace", timeout=60,
|
|
81
|
+
)
|
|
82
|
+
if r.returncode != 0:
|
|
83
|
+
return None, None
|
|
84
|
+
for line in r.stdout.splitlines():
|
|
85
|
+
sha, ref = line.split("\t", 1)
|
|
86
|
+
ref = ref.strip()
|
|
87
|
+
if ref.startswith("refs/heads/") or ref == "HEAD":
|
|
88
|
+
resolved = ref.removeprefix("refs/heads/")
|
|
89
|
+
return sha, resolved
|
|
90
|
+
return None, None
|
|
91
|
+
except (subprocess.TimeoutExpired, OSError):
|
|
92
|
+
return None, None
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def check_update(skill_name: str) -> dict:
|
|
96
|
+
"""Check one skill for a remote update.
|
|
97
|
+
|
|
98
|
+
Returns dict: {skill, status, remote_commit?, local_commit?, branch?}
|
|
99
|
+
status: tracked | untracked | missing | up-to-date | update-available | error
|
|
100
|
+
"""
|
|
101
|
+
sources = load_sources()
|
|
102
|
+
info = sources.get(skill_name)
|
|
103
|
+
if not info:
|
|
104
|
+
return {"skill": skill_name, "status": "untracked"}
|
|
105
|
+
skill_dir = CENTRAL_DIR / skill_name
|
|
106
|
+
if not skill_dir.exists():
|
|
107
|
+
return {"skill": skill_name, "status": "missing"}
|
|
108
|
+
|
|
109
|
+
sha, branch = _latest_commit(info["repo_url"], info.get("branch"))
|
|
110
|
+
if not sha:
|
|
111
|
+
return {"skill": skill_name, "status": "error"}
|
|
112
|
+
|
|
113
|
+
local = info.get("commit")
|
|
114
|
+
# The previous ``if local and sha.startswith(local) or local == sha``
|
|
115
|
+
# relied on Python's ``A and B or C`` short-circuit; it happened to be
|
|
116
|
+
# correct in practice (``sha`` is always a non-empty hex hash from
|
|
117
|
+
# ``_latest_commit``) but the mixed-priority chain is easy to break in
|
|
118
|
+
# future edits. Spell the predicate out so the intent is unambiguous
|
|
119
|
+
# and the unrecorded (``local is None``) boundary is explicit.
|
|
120
|
+
is_up_to_date = sha.startswith(local) or local == sha if local else False
|
|
121
|
+
if is_up_to_date:
|
|
122
|
+
return {
|
|
123
|
+
"skill": skill_name, "status": "up-to-date",
|
|
124
|
+
"remote_commit": sha[:8], "branch": branch or info.get("branch"),
|
|
125
|
+
}
|
|
126
|
+
return {
|
|
127
|
+
"skill": skill_name, "status": "update-available",
|
|
128
|
+
"remote_commit": sha[:8], "local_commit": (local or "?")[:8],
|
|
129
|
+
"branch": branch or info.get("branch"),
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
def check_all_updates() -> list[dict]:
|
|
134
|
+
"""Check every tracked skill; untracked skills are listed once at the end."""
|
|
135
|
+
sources = load_sources()
|
|
136
|
+
results = [check_update(name) for name in sorted(sources)]
|
|
137
|
+
return results
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
# ---------------------------------------------------------------- rollback
|
|
141
|
+
|
|
142
|
+
def _versions_root() -> Path:
|
|
143
|
+
"""Snapshot root OUTSIDE the central repo (inventory/status never see it)."""
|
|
144
|
+
return CENTRAL_DIR.parent / ".askill-versions"
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
def snapshot_skill(skill_name: str) -> Path | None:
|
|
148
|
+
"""Copy the current version of a skill as the rollback point (v0.24.0).
|
|
149
|
+
|
|
150
|
+
One snapshot per skill - the next update overwrites it. Returns the
|
|
151
|
+
snapshot dir, or None when the skill does not exist.
|
|
152
|
+
"""
|
|
153
|
+
import shutil
|
|
154
|
+
|
|
155
|
+
skill_dir = CENTRAL_DIR / skill_name
|
|
156
|
+
if not skill_dir.exists():
|
|
157
|
+
return None
|
|
158
|
+
root = _versions_root() / skill_name
|
|
159
|
+
if root.exists():
|
|
160
|
+
shutil.rmtree(root)
|
|
161
|
+
root.mkdir(parents=True)
|
|
162
|
+
shutil.copytree(skill_dir, root / "last")
|
|
163
|
+
return root / "last"
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def list_rollbackable() -> list[tuple[str, str]]:
|
|
167
|
+
"""Skills with a rollback snapshot, with the snapshot's mtime label."""
|
|
168
|
+
import time
|
|
169
|
+
|
|
170
|
+
root = _versions_root()
|
|
171
|
+
if not root.exists():
|
|
172
|
+
return []
|
|
173
|
+
out = []
|
|
174
|
+
for d in sorted(root.iterdir()):
|
|
175
|
+
last = d / "last"
|
|
176
|
+
if last.exists():
|
|
177
|
+
when = time.strftime("%Y-%m-%d %H:%M", time.localtime(last.stat().st_mtime))
|
|
178
|
+
out.append((d.name, when))
|
|
179
|
+
return out
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def rollback_skill(skill_name: str, verbose: bool = True) -> bool:
|
|
183
|
+
"""Restore the pre-update snapshot of a skill and re-sync (v0.24.0).
|
|
184
|
+
|
|
185
|
+
The snapshot is consumed on success (one-step undo, not a version
|
|
186
|
+
history - for that, keep the skill in a git repo).
|
|
187
|
+
"""
|
|
188
|
+
import shutil
|
|
189
|
+
import tempfile
|
|
190
|
+
|
|
191
|
+
snap = _versions_root() / skill_name / "last"
|
|
192
|
+
if not snap.exists():
|
|
193
|
+
if verbose:
|
|
194
|
+
print(f"No rollback snapshot for '{skill_name}'.")
|
|
195
|
+
print("Snapshots are taken automatically each time 'askill update' replaces a skill.")
|
|
196
|
+
return False
|
|
197
|
+
|
|
198
|
+
skill_dir = CENTRAL_DIR / skill_name
|
|
199
|
+
if skill_dir.exists():
|
|
200
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
201
|
+
shutil.move(str(skill_dir), str(Path(tmp) / "current"))
|
|
202
|
+
shutil.copytree(snap, skill_dir)
|
|
203
|
+
shutil.rmtree(_versions_root() / skill_name)
|
|
204
|
+
if verbose:
|
|
205
|
+
print(f"Rolled back '{skill_name}' to the pre-update snapshot.")
|
|
206
|
+
|
|
207
|
+
from .sync import sync_skill
|
|
208
|
+
sync_skill(skill_name, verbose=verbose)
|
|
209
|
+
return True
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
def update_skill(skill_name: str, verbose: bool = True) -> bool:
|
|
213
|
+
"""Re-install one skill from its recorded origin and re-sync everywhere.
|
|
214
|
+
|
|
215
|
+
The old directory is replaced atomically-ish (moved aside first).
|
|
216
|
+
"""
|
|
217
|
+
import shutil
|
|
218
|
+
import tempfile
|
|
219
|
+
|
|
220
|
+
sources = load_sources()
|
|
221
|
+
info = sources.get(skill_name)
|
|
222
|
+
if not info:
|
|
223
|
+
if verbose:
|
|
224
|
+
print(f"No source recorded for '{skill_name}' (installed locally?)")
|
|
225
|
+
return False
|
|
226
|
+
|
|
227
|
+
url = info["repo_url"]
|
|
228
|
+
if info.get("sub_path"):
|
|
229
|
+
url = f"{url}/tree/{info.get('branch') or 'HEAD'}/{info['sub_path']}"
|
|
230
|
+
elif info.get("branch"):
|
|
231
|
+
url = f"{url}/tree/{info['branch']}"
|
|
232
|
+
|
|
233
|
+
skill_dir = CENTRAL_DIR / skill_name
|
|
234
|
+
if skill_dir.exists():
|
|
235
|
+
# v0.24.0: keep the outgoing version as a one-step undo (the update
|
|
236
|
+
# below moves the old dir into a temp dir that dies on exit - without
|
|
237
|
+
# the snapshot a failed update would lose the skill entirely)
|
|
238
|
+
snapshot_skill(skill_name)
|
|
239
|
+
with tempfile.TemporaryDirectory() as tmp:
|
|
240
|
+
shutil.move(str(skill_dir), str(Path(tmp) / "old"))
|
|
241
|
+
if verbose:
|
|
242
|
+
print(f"Removed old version of '{skill_name}'")
|
|
243
|
+
|
|
244
|
+
# reuse the URL installer so behaviour (incl. source recording) matches
|
|
245
|
+
from .sync import _install_from_url, sync_skill
|
|
246
|
+
name, ok = _install_from_url(url, verbose=verbose)
|
|
247
|
+
if not ok or name != skill_name:
|
|
248
|
+
if verbose:
|
|
249
|
+
print(f"Update failed for '{skill_name}'")
|
|
250
|
+
return False
|
|
251
|
+
|
|
252
|
+
# stamp the new commit
|
|
253
|
+
sha, _ = _latest_commit(info["repo_url"], info.get("branch"))
|
|
254
|
+
record_source(
|
|
255
|
+
skill_name, info["repo_url"], info.get("sub_path", ""),
|
|
256
|
+
info.get("branch"), sha,
|
|
257
|
+
)
|
|
258
|
+
sync_skill(skill_name, verbose=verbose)
|
|
259
|
+
if verbose:
|
|
260
|
+
print(f"Updated '{skill_name}' and synced to all products.")
|
|
261
|
+
return True
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
"""Agent Skills specification (agentskills.io) compliance checks (v0.11.0).
|
|
2
|
+
|
|
3
|
+
``askill verify [skill]`` validates skills in the central repository
|
|
4
|
+
against the published Agent Skills specification so they can be indexed by
|
|
5
|
+
skills.sh and read by every spec-compliant agent.
|
|
6
|
+
|
|
7
|
+
Stdlib only: a tiny frontmatter parser covering the flat ``key: value``
|
|
8
|
+
layout the spec uses (nested ``metadata:`` maps and lists are skipped
|
|
9
|
+
without error).
|
|
10
|
+
"""
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import re
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
|
|
16
|
+
from .inventory import list_skills
|
|
17
|
+
|
|
18
|
+
# Spec constraints (https://agentskills.io/specification)
|
|
19
|
+
NAME_MAX = 64
|
|
20
|
+
DESC_MAX = 1024
|
|
21
|
+
COMPAT_MAX = 500
|
|
22
|
+
BODY_LINES_SOFT = 500 # recommendation, not a hard rule -> warning
|
|
23
|
+
|
|
24
|
+
# lowercase letters/digits, single hyphens between segments; the regex
|
|
25
|
+
# rejects uppercase, leading/trailing hyphens and consecutive hyphens.
|
|
26
|
+
_NAME_RE = re.compile(r"^[a-z0-9]+(?:-[a-z0-9]+)*$")
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def parse_frontmatter(text: str) -> tuple[dict, list[str]]:
|
|
30
|
+
"""Extract flat ``key: value`` pairs from the YAML frontmatter block.
|
|
31
|
+
|
|
32
|
+
Returns (fields, warnings). Nested maps (``metadata:`` children) and
|
|
33
|
+
list items are ignored - they are legal in the spec but irrelevant to
|
|
34
|
+
the checks below.
|
|
35
|
+
"""
|
|
36
|
+
lines = text.split("\n")
|
|
37
|
+
if not lines or lines[0].strip() != "---":
|
|
38
|
+
return {}, ["SKILL.md does not start with a '---' frontmatter block"]
|
|
39
|
+
|
|
40
|
+
fields: dict[str, str] = {}
|
|
41
|
+
warnings: list[str] = []
|
|
42
|
+
terminated = False
|
|
43
|
+
for lineno, line in enumerate(lines[1:], start=2):
|
|
44
|
+
stripped = line.strip()
|
|
45
|
+
if stripped == "---":
|
|
46
|
+
terminated = True
|
|
47
|
+
break
|
|
48
|
+
if not stripped or line[:1] in (" ", "\t") or stripped.startswith("- "):
|
|
49
|
+
continue # blank, nested map/list entry - skip quietly
|
|
50
|
+
if ":" not in line:
|
|
51
|
+
warnings.append(f"frontmatter line {lineno} has no ':' and was ignored")
|
|
52
|
+
continue
|
|
53
|
+
key, _, value = line.partition(":")
|
|
54
|
+
fields[key.strip()] = value.strip().strip('"').strip("'")
|
|
55
|
+
|
|
56
|
+
if not terminated:
|
|
57
|
+
warnings.append("frontmatter block is never closed with '---'")
|
|
58
|
+
return fields, warnings
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def check_spec(skill_dir: Path) -> dict:
|
|
62
|
+
"""Validate one skill directory against the Agent Skills spec.
|
|
63
|
+
|
|
64
|
+
Returns ``{"skill", "ok", "errors", "warnings"}`` where ``ok`` is False
|
|
65
|
+
only for spec violations (errors), never for advisory warnings.
|
|
66
|
+
"""
|
|
67
|
+
errors: list[str] = []
|
|
68
|
+
warnings: list[str] = []
|
|
69
|
+
skill_dir = Path(skill_dir)
|
|
70
|
+
|
|
71
|
+
skill_md = skill_dir / "SKILL.md"
|
|
72
|
+
if not skill_md.is_file():
|
|
73
|
+
return {
|
|
74
|
+
"skill": skill_dir.name, "ok": False,
|
|
75
|
+
"errors": ["SKILL.md missing"], "warnings": [],
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
text = skill_md.read_text(encoding="utf-8", errors="replace")
|
|
79
|
+
fields, fm_warnings = parse_frontmatter(text)
|
|
80
|
+
warnings.extend(fm_warnings)
|
|
81
|
+
|
|
82
|
+
name = fields.get("name")
|
|
83
|
+
if not name:
|
|
84
|
+
errors.append("frontmatter missing required 'name'")
|
|
85
|
+
else:
|
|
86
|
+
if len(name) > NAME_MAX:
|
|
87
|
+
errors.append(f"'name' is {len(name)} chars (max {NAME_MAX})")
|
|
88
|
+
if not _NAME_RE.match(name):
|
|
89
|
+
errors.append(
|
|
90
|
+
f"'name' {name!r} must be lowercase letters/digits with single "
|
|
91
|
+
"hyphens between segments (no leading/trailing/double hyphens)"
|
|
92
|
+
)
|
|
93
|
+
if name != skill_dir.name:
|
|
94
|
+
errors.append(
|
|
95
|
+
f"'name' {name!r} does not match directory name {skill_dir.name!r}"
|
|
96
|
+
)
|
|
97
|
+
|
|
98
|
+
description = fields.get("description")
|
|
99
|
+
if not description:
|
|
100
|
+
errors.append("frontmatter missing required 'description'")
|
|
101
|
+
elif len(description) > DESC_MAX:
|
|
102
|
+
errors.append(f"'description' is {len(description)} chars (max {DESC_MAX})")
|
|
103
|
+
|
|
104
|
+
compatibility = fields.get("compatibility")
|
|
105
|
+
if compatibility and len(compatibility) > COMPAT_MAX:
|
|
106
|
+
errors.append(f"'compatibility' is {len(compatibility)} chars (max {COMPAT_MAX})")
|
|
107
|
+
|
|
108
|
+
# body size is a recommendation (progressive disclosure), advisory only
|
|
109
|
+
terminated = text.split("\n")
|
|
110
|
+
body_start = None
|
|
111
|
+
for i, line in enumerate(terminated[1:], start=2):
|
|
112
|
+
if line.strip() == "---":
|
|
113
|
+
body_start = i
|
|
114
|
+
break
|
|
115
|
+
if body_start is not None:
|
|
116
|
+
body_lines = len([line for line in terminated[body_start:] if line.strip()])
|
|
117
|
+
if body_lines > BODY_LINES_SOFT:
|
|
118
|
+
warnings.append(
|
|
119
|
+
f"SKILL.md body has {body_lines} lines "
|
|
120
|
+
f"({BODY_LINES_SOFT} recommended); consider moving detail "
|
|
121
|
+
"into references/ files"
|
|
122
|
+
)
|
|
123
|
+
|
|
124
|
+
return {
|
|
125
|
+
"skill": skill_dir.name,
|
|
126
|
+
"ok": not errors,
|
|
127
|
+
"errors": errors,
|
|
128
|
+
"warnings": warnings,
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def check_all_specs(central: Path | None = None) -> list[dict]:
|
|
133
|
+
"""Validate every skill in the central repository.
|
|
134
|
+
|
|
135
|
+
Args:
|
|
136
|
+
central: override the central repository. Defaults to the
|
|
137
|
+
configured ``CENTRAL_DIR``; the CLI passes its own (seam-aware)
|
|
138
|
+
enumeration so tests patching ``sync.CENTRAL_DIR`` keep
|
|
139
|
+
working while spec itself stays decoupled from sync.
|
|
140
|
+
"""
|
|
141
|
+
return [check_spec(d) for d in list_skills(central)]
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def product_frontmatter_issues(
|
|
145
|
+
skill_dir: Path, targets: list[str] | None = None
|
|
146
|
+
) -> list[str]:
|
|
147
|
+
"""Check a skill against products that mandate extra frontmatter fields.
|
|
148
|
+
|
|
149
|
+
v0.13.0: per-product requirements are declared in products.py
|
|
150
|
+
(``required_frontmatter``), e.g. QwenWork requires ``name``, ``version``,
|
|
151
|
+
``description`` and ``description_zh``. Without this check users only
|
|
152
|
+
find out when the product silently fails to load the skill.
|
|
153
|
+
|
|
154
|
+
v0.18.0: ``targets`` (a list of product shorts) narrows the check to the
|
|
155
|
+
products the skill is actually meant for. A skill published only to
|
|
156
|
+
WorkBuddy should not be blocked by QwenWork's ``description_zh``
|
|
157
|
+
requirement. ``targets=None`` (default) checks every declaring product,
|
|
158
|
+
preserving the behaviour ``askill verify`` relies on.
|
|
159
|
+
|
|
160
|
+
Returns:
|
|
161
|
+
List of human-readable issues, e.g.
|
|
162
|
+
``"qwenwork: missing frontmatter field(s): version, description_zh"``.
|
|
163
|
+
Empty list when every (selected) declaring product is satisfied.
|
|
164
|
+
"""
|
|
165
|
+
from ..config.products import PRODUCTS
|
|
166
|
+
|
|
167
|
+
skill_md = Path(skill_dir) / "SKILL.md"
|
|
168
|
+
if not skill_md.is_file():
|
|
169
|
+
return []
|
|
170
|
+
text = skill_md.read_text(encoding="utf-8", errors="replace")
|
|
171
|
+
fields, _ = parse_frontmatter(text)
|
|
172
|
+
|
|
173
|
+
selected = {t.lower() for t in targets} if targets else None
|
|
174
|
+
|
|
175
|
+
issues: list[str] = []
|
|
176
|
+
for p in PRODUCTS:
|
|
177
|
+
if selected is not None and p["short"] not in selected:
|
|
178
|
+
continue
|
|
179
|
+
required = p.get("required_frontmatter")
|
|
180
|
+
if not required:
|
|
181
|
+
continue
|
|
182
|
+
missing = [f for f in required if not fields.get(f)]
|
|
183
|
+
if missing:
|
|
184
|
+
issues.append(
|
|
185
|
+
f"{p['short']}: missing frontmatter field(s) "
|
|
186
|
+
f"{', '.join(missing)} in SKILL.md"
|
|
187
|
+
)
|
|
188
|
+
return issues
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""Skill synchronization engine (package since the 2026-11-02 split).
|
|
2
|
+
|
|
3
|
+
The package owns the historical test seam: ``CENTRAL_DIR`` and
|
|
4
|
+
``PRODUCTS`` live as package attributes, and the five names tests patch
|
|
5
|
+
on this namespace (``CENTRAL_DIR``, ``PRODUCTS``, ``get_product_path``,
|
|
6
|
+
``is_symlink_or_junction``, ``_install_from_url``) are read by the
|
|
7
|
+
submodules through ``_pkg`` at call time - so
|
|
8
|
+
``patch("...services.sync.<name>")`` keeps intercepting after the split
|
|
9
|
+
(architecture health check 2026-10-31, §4).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from ...config.products import CENTRAL_DIR, PRODUCTS, get_product_path
|
|
13
|
+
from ...utils.filesystem import is_symlink_or_junction
|
|
14
|
+
from .adopt import _patch_products, adopt_from_platform
|
|
15
|
+
from .audit_report import audit_all, audit_skill, residency_report
|
|
16
|
+
from .engine import (
|
|
17
|
+
FOOTER,
|
|
18
|
+
_pack_status,
|
|
19
|
+
_platform_key,
|
|
20
|
+
_sync_one_product,
|
|
21
|
+
gc_dead_links,
|
|
22
|
+
get_status,
|
|
23
|
+
list_skills,
|
|
24
|
+
print_onboarding,
|
|
25
|
+
remove_skill,
|
|
26
|
+
sync_skill,
|
|
27
|
+
)
|
|
28
|
+
from .install import (
|
|
29
|
+
_install_from_local,
|
|
30
|
+
_install_from_url,
|
|
31
|
+
_post_install_checks,
|
|
32
|
+
install_skill,
|
|
33
|
+
)
|
|
34
|
+
from .pack import pack_skill
|
|
35
|
+
from .settings_io import _disable_in_settings, _enable_in_settings, _write_json_atomic
|