agent-skill-sync 0.1.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_sync-0.1.0.dist-info/METADATA +182 -0
- agent_skill_sync-0.1.0.dist-info/RECORD +17 -0
- agent_skill_sync-0.1.0.dist-info/WHEEL +5 -0
- agent_skill_sync-0.1.0.dist-info/entry_points.txt +2 -0
- agent_skill_sync-0.1.0.dist-info/licenses/LICENSE +21 -0
- agent_skill_sync-0.1.0.dist-info/top_level.txt +1 -0
- skillsync/__init__.py +11 -0
- skillsync/classifier.py +161 -0
- skillsync/cli.py +218 -0
- skillsync/config.py +185 -0
- skillsync/differ.py +98 -0
- skillsync/frontmatter.py +260 -0
- skillsync/model.py +78 -0
- skillsync/report.py +134 -0
- skillsync/resolve.py +114 -0
- skillsync/scanner.py +90 -0
- skillsync/sync.py +155 -0
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-skill-sync
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Scan, classify and sync AI-agent skills (SKILL.md) across toolchains like OpenAI Codex, Claude Code and WorkBuddy.
|
|
5
|
+
License: MIT
|
|
6
|
+
Project-URL: Homepage, https://github.com/kina-cmd/agent-skill-sync
|
|
7
|
+
Project-URL: Issues, https://github.com/kina-cmd/agent-skill-sync/issues
|
|
8
|
+
Keywords: ai,agent,skills,codex,claude,workbuddy,migration,inventory
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Environment :: Console
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Topic :: Software Development :: Quality Assurance
|
|
18
|
+
Classifier: Topic :: Utilities
|
|
19
|
+
Requires-Python: >=3.11
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# agent-skill-sync
|
|
25
|
+
|
|
26
|
+
[](https://github.com/kina-cmd/agent-skill-sync/actions/workflows/ci.yml)
|
|
27
|
+
[](https://pypi.org/project/agent-skill-sync/)
|
|
28
|
+
[](https://pypi.org/project/agent-skill-sync/)
|
|
29
|
+
[](LICENSE)
|
|
30
|
+
|
|
31
|
+
**`skillsync`** — scan, classify and sync AI-agent skills (`SKILL.md` files) across toolchains.
|
|
32
|
+
|
|
33
|
+
If you use several AI coding agents (OpenAI Codex, Claude Code, WorkBuddy, …), you end up with
|
|
34
|
+
skill libraries scattered across different directories, in different layouts, some copied, some
|
|
35
|
+
stale, some requiring dependencies you never installed. `skillsync` turns that mess into one
|
|
36
|
+
honest inventory — automatically.
|
|
37
|
+
|
|
38
|
+
Zero dependencies. Pure Python ≥ 3.11 stdlib.
|
|
39
|
+
|
|
40
|
+
## What it does
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
┌──────────────┐ ┌──────────────┐ ┌────────────────┐
|
|
44
|
+
│ ~/.codex/ │ │ marketplace │ │ ~/.claude/ │ … any number of
|
|
45
|
+
│ skills/ │ │ plugin cache │ │ skills/ │ source roots
|
|
46
|
+
└──────┬───────┘ └──────┬───────┘ └───────┬────────┘
|
|
47
|
+
└──────────────┬───┴───────────────────┘
|
|
48
|
+
▼
|
|
49
|
+
┌───────────────┐ classify every skill:
|
|
50
|
+
│ scan + parse │ A portable · B missing deps
|
|
51
|
+
│ frontmatter │ C rewrite needed · D platform-private
|
|
52
|
+
└───────┬───────┘
|
|
53
|
+
▼
|
|
54
|
+
┌───────────────┐ diff against target:
|
|
55
|
+
│ INDEX.md │ identical · drifted · missing
|
|
56
|
+
│ inventory.json│
|
|
57
|
+
└───────┬───────┘
|
|
58
|
+
▼
|
|
59
|
+
┌───────────────┐ optional, safe copy:
|
|
60
|
+
│ skillsync sync│ dry-run first, backups, never deletes,
|
|
61
|
+
└───────────────┘ skips .venv/.env/node_modules
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### The A/B/C/D migration taxonomy
|
|
65
|
+
|
|
66
|
+
| Category | Meaning | Action |
|
|
67
|
+
|---|---|---|
|
|
68
|
+
| **A** | Portable — no platform-private references, every referenced command exists | copy & use |
|
|
69
|
+
| **B** | Portable but missing external deps (a CLI, an MCP server) | install deps, then copy |
|
|
70
|
+
| **C** | References another agent's conventions (`AGENTS.md`, `image_gen`, …) | rewrite for your target |
|
|
71
|
+
| **D** | Bound to the source platform's private runtime | don't migrate |
|
|
72
|
+
|
|
73
|
+
Classification is heuristic, conservative, and **every decision ships a reason** —
|
|
74
|
+
the index shows *why* a skill landed in each bucket, and *which* dependencies are missing
|
|
75
|
+
(probed live with `shutil.which` / your `[deps]` table).
|
|
76
|
+
|
|
77
|
+
## Install
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pipx install agent-skill-sync # recommended: isolated CLI install
|
|
81
|
+
pip install agent-skill-sync # or into your environment
|
|
82
|
+
|
|
83
|
+
# from source, without installing:
|
|
84
|
+
git clone https://github.com/kina-cmd/agent-skill-sync && cd agent-skill-sync
|
|
85
|
+
python -m skillsync.cli --help
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
## Usage
|
|
89
|
+
|
|
90
|
+
```bash
|
|
91
|
+
# What do I have, and in what state?
|
|
92
|
+
skillsync status
|
|
93
|
+
|
|
94
|
+
# One line per skill: category, sync state, source, missing deps
|
|
95
|
+
skillsync scan
|
|
96
|
+
skillsync scan --category B # only the ones needing deps
|
|
97
|
+
skillsync scan --json # machine-readable inventory
|
|
98
|
+
|
|
99
|
+
# Generate a full index (INDEX.md + inventory.json) you can commit
|
|
100
|
+
# or paste into a "tool reuse" skill for your agent to read
|
|
101
|
+
skillsync index --out ./output --lang zh
|
|
102
|
+
|
|
103
|
+
# Sync portable skills into the target root — plan first, always
|
|
104
|
+
skillsync sync --dry-run
|
|
105
|
+
skillsync sync --categories A
|
|
106
|
+
skillsync sync --categories A,B --force # update drifted copies (backs them up)
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Sync safety rules
|
|
110
|
+
|
|
111
|
+
* Never overwrites without `--force`; a forced update first moves the old copy to
|
|
112
|
+
`<target>/.skillsync-backup/` — nothing is ever deleted.
|
|
113
|
+
* `.venv/`, `.env`, `node_modules/`, `__pycache__/` are always excluded from copies,
|
|
114
|
+
so secrets and 500 MB virtualenvs never travel silently.
|
|
115
|
+
* `--dry-run` prints the exact plan and touches nothing.
|
|
116
|
+
|
|
117
|
+
## Configuration
|
|
118
|
+
|
|
119
|
+
By default, `skillsync` auto-discovers the well-known roots on your machine
|
|
120
|
+
(`~/.codex/skills`, `~/.codex/plugins/cache`, `~/.claude/skills` → target `~/.workbuddy/skills`).
|
|
121
|
+
|
|
122
|
+
Override or extend with `skillsync.toml` (looked up in `./` then `$XDG_CONFIG_HOME/skillsync/`):
|
|
123
|
+
|
|
124
|
+
```toml
|
|
125
|
+
[target]
|
|
126
|
+
label = "workbuddy"
|
|
127
|
+
path = "~/.workbuddy/skills"
|
|
128
|
+
|
|
129
|
+
[[sources]]
|
|
130
|
+
label = "codex"
|
|
131
|
+
path = "~/.codex/skills"
|
|
132
|
+
|
|
133
|
+
[[sources]]
|
|
134
|
+
label = "codex-marketplace"
|
|
135
|
+
path = "~/.codex/plugins/cache"
|
|
136
|
+
glob = "**/skills/*/SKILL.md"
|
|
137
|
+
|
|
138
|
+
[[sources]]
|
|
139
|
+
label = "codex-system"
|
|
140
|
+
path = "~/.codex/skills/.system"
|
|
141
|
+
system = true # platform-private → always category D
|
|
142
|
+
|
|
143
|
+
[deps]
|
|
144
|
+
# Teach the classifier that a dep is satisfied even if not on PATH:
|
|
145
|
+
voicebox = { kind = "path", value = "~/App/Voicebox/voicebox.exe" }
|
|
146
|
+
ffmpeg = "ffmpeg" # shorthand: check PATH
|
|
147
|
+
notion = { kind = "env", value = "NOTION_TOKEN" } # check env var
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
See [`skillsync.example.toml`](skillsync.example.toml) for a complete example.
|
|
151
|
+
|
|
152
|
+
## Typical workflow: keeping an index skill fresh
|
|
153
|
+
|
|
154
|
+
Many people maintain a hand-written "local tool reuse" index for their agent.
|
|
155
|
+
It rots the moment a skill is added upstream. Instead:
|
|
156
|
+
|
|
157
|
+
```bash
|
|
158
|
+
skillsync index --out ~/.workbuddy/skills/local-tool-reuse/generated --lang zh
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
…on a schedule or a git hook, and let the agent read a generated file that is
|
|
162
|
+
always true. `inventory.json` is stable, machine-readable output for further tooling.
|
|
163
|
+
|
|
164
|
+
## Development
|
|
165
|
+
|
|
166
|
+
```bash
|
|
167
|
+
python -m unittest discover tests -v
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
## Design notes
|
|
171
|
+
|
|
172
|
+
* **No PyYAML.** The frontmatter parser implements exactly the YAML subset skill
|
|
173
|
+
files use (scalars, folded/literal blocks, inline and block lists), and fails soft —
|
|
174
|
+
unparsable lines become warnings, never crashes.
|
|
175
|
+
* **No network.** Everything is local filesystem inspection.
|
|
176
|
+
* **Qualified names.** Marketplace plugin caches nest skills as
|
|
177
|
+
`<plugin>/<version>/skills/<name>/`; these are reported as `plugin:name` so
|
|
178
|
+
collisions are visible.
|
|
179
|
+
|
|
180
|
+
## License
|
|
181
|
+
|
|
182
|
+
MIT © 2026 kina-cmd
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
agent_skill_sync-0.1.0.dist-info/licenses/LICENSE,sha256=n1B3Z60LqfKo9lza_o3mpIDQVobpzJzs1Ezutf9ClZA,1065
|
|
2
|
+
skillsync/__init__.py,sha256=Zmx5Ezy0OZcDbZAQ7t_b2HksCg_BO9ahiM0xAQpCU20,409
|
|
3
|
+
skillsync/classifier.py,sha256=c-C-dNJu1-ZafXiKSfh8sUSEIonVfmf_XaCXvkZM0Ek,6895
|
|
4
|
+
skillsync/cli.py,sha256=sTpuL73JktAbNyfU8UCv2DYoWxpKnx9J4ca8dsGGr9E,8803
|
|
5
|
+
skillsync/config.py,sha256=OjRaKkEPY1tlILtfkiRAbEJE2nxCZgJHjgQaVHhOV90,5767
|
|
6
|
+
skillsync/differ.py,sha256=dfWwmu18QlSB9jWyr_-XNTpipc5nENyA2IpUc-K6HxI,3030
|
|
7
|
+
skillsync/frontmatter.py,sha256=VrYwM5XQtsFddpbH3mP838dJcVHcpmzr3OCRc55854g,8592
|
|
8
|
+
skillsync/model.py,sha256=7sljjgsq82tmGnvMhS2T_7r9sgEIisX7yCMApdQrv-0,3018
|
|
9
|
+
skillsync/report.py,sha256=cNrvGXIfNSauczNdVTkTj9IdGf3Hz7Zui97EhhJ3YkA,5458
|
|
10
|
+
skillsync/resolve.py,sha256=HwOc9jhHVe_GU5AlRQOEe7vFo4qhHDzfAHWv_6exXbk,4390
|
|
11
|
+
skillsync/scanner.py,sha256=SAjvGqmIbcXp-D0UN9ofcrXDSfqGdXQWOy8u198DNX0,3220
|
|
12
|
+
skillsync/sync.py,sha256=sMx6mtJ1FE6SLzIe80O05KtMMQGsPfL56xvKDrLx5Es,5867
|
|
13
|
+
agent_skill_sync-0.1.0.dist-info/METADATA,sha256=xbeTT6Hm6Pvelu-tCEmM_OoTnGb7YNSjVI67OxX5i4I,7578
|
|
14
|
+
agent_skill_sync-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
15
|
+
agent_skill_sync-0.1.0.dist-info/entry_points.txt,sha256=PxGra8xJCTZ0yhL3ZvUnTfdRLtWkKpmuZGpYjyoBTlE,49
|
|
16
|
+
agent_skill_sync-0.1.0.dist-info/top_level.txt,sha256=xsxa0clwU4aCjkV2dCfN83oLJ9B5Hxfh-bseAMlgl9I,10
|
|
17
|
+
agent_skill_sync-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 kina-cmd
|
|
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 @@
|
|
|
1
|
+
skillsync
|
skillsync/__init__.py
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"""skillsync — scan, classify and sync agent skills between toolchains.
|
|
2
|
+
|
|
3
|
+
A dependency-free toolkit for people who accumulate AI-agent "skills"
|
|
4
|
+
(SKILL.md files) across several CLIs — OpenAI Codex, Claude Code, WorkBuddy,
|
|
5
|
+
etc. — and want one honest inventory: what exists, where it lives, whether it
|
|
6
|
+
is runnable, and what it would take to migrate it.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
__version__ = "0.1.0"
|
|
10
|
+
|
|
11
|
+
__all__ = ["__version__"]
|
skillsync/classifier.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""Classifier: assign each skill an A/B/C/D migration category, automatically.
|
|
2
|
+
|
|
3
|
+
The taxonomy:
|
|
4
|
+
|
|
5
|
+
* **A — portable.** Nothing platform-private, every referenced external command
|
|
6
|
+
is present on this machine. Can be copied to the target and used as-is.
|
|
7
|
+
* **B — needs dependencies.** Portable in spirit, but references CLIs / MCP
|
|
8
|
+
servers / runtimes that are *missing* here. Runnable once deps are installed.
|
|
9
|
+
* **C — rewrite required.** References another agent's config conventions or
|
|
10
|
+
tool-call vocabulary (``AGENTS.md``, ``image_gen``, ``tool_search``…) that has
|
|
11
|
+
no drop-in equivalent. Methodology is reusable, the text is not.
|
|
12
|
+
* **D — platform-private.** Bound to the source runtime's internals (Codex
|
|
13
|
+
system skills, in-app browser control, codex-security, plugin management).
|
|
14
|
+
Do not migrate.
|
|
15
|
+
|
|
16
|
+
Classification is heuristic and intentionally conservative: when a skill
|
|
17
|
+
matches both a "private" marker and a missing dependency, the stronger
|
|
18
|
+
constraint wins (D > C > B > A). Every decision carries a human-readable
|
|
19
|
+
``reason`` and the concrete ``missing_deps`` so the index can show *why*.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import re
|
|
25
|
+
import shutil
|
|
26
|
+
|
|
27
|
+
from .config import Config
|
|
28
|
+
from .model import Skill
|
|
29
|
+
|
|
30
|
+
# Tokens that look like shell commands worth checking with shutil.which().
|
|
31
|
+
# We only probe a curated allowlist to avoid false positives from prose.
|
|
32
|
+
_KNOWN_COMMANDS = {
|
|
33
|
+
"ffmpeg", "ffprobe", "node", "npx", "pnpm", "yarn", "npm", "python", "python3",
|
|
34
|
+
"pip", "pipx", "uv", "git", "gh", "rg", "fd", "jq", "yt-dlp", "playwright",
|
|
35
|
+
"manim", "hf", "heygen", "codex", "docker", "magick", "convert", "sox",
|
|
36
|
+
"browser-act", "mcporter", "arkcli", "openmontage", "voicebox", "genmedia",
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
# MCP server references look like mcp__<server>__<tool> or "MCP server <name>".
|
|
40
|
+
_MCP_RE = re.compile(r"\bmcp__([a-z0-9_\-]+)__", re.IGNORECASE)
|
|
41
|
+
_MCP_PROSE_RE = re.compile(r"\b([A-Za-z0-9_\-]+)\s+MCP\b")
|
|
42
|
+
# Prose matches are noisy ("the detailed MCP", "an s MCP client"...), so a prose
|
|
43
|
+
# token only counts as a server name if it is hyphenated/underscored or in this
|
|
44
|
+
# allowlist of servers commonly referenced in skills.
|
|
45
|
+
_MCP_PROSE_ALLOWLIST = {
|
|
46
|
+
"notion", "firecrawl", "playwright", "devtools", "browser", "browserbase",
|
|
47
|
+
"scrapling", "voicebox", "linear", "gmail", "heygen", "chrome", "puppeteer",
|
|
48
|
+
"sheetagent", "github", "memory", "filesystem", "sequential-thinking",
|
|
49
|
+
"aitoearn", "hf_jobs", "codex_apps", "context7", "supabase", "sentry",
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
# Words that signal "this is just methodology, but it talks to another agent".
|
|
53
|
+
_C_MARKERS = (
|
|
54
|
+
"AGENTS.md", "CLAUDE.md", "--tools codex", "image_gen", "view_image",
|
|
55
|
+
"tool_search", "toolsearch", "present-artifact", "/plugin", "claude code",
|
|
56
|
+
"control-in-app-browser", "in-app browser",
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
# Words that signal platform-private internals — never migrate.
|
|
60
|
+
_D_MARKERS = (
|
|
61
|
+
"codex-security", "computer-use", "control-chrome", "sites:sites-hosting",
|
|
62
|
+
"sites:sites-building", "publish-artifact-to-sites", "plugin-creator",
|
|
63
|
+
"skill-installer", "plugin-management", "scan id", "scanid",
|
|
64
|
+
"documents:documents", "spreadsheets:excel-live-control",
|
|
65
|
+
"template-creator",
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _referenced_commands(text: str) -> set[str]:
|
|
70
|
+
found: set[str] = set()
|
|
71
|
+
# fenced code blocks and inline `code` are the most reliable signal
|
|
72
|
+
for chunk in re.findall(r"```.*?```", text, flags=re.DOTALL):
|
|
73
|
+
for word in re.findall(r"\b([a-z0-9_\-]+)\b", chunk):
|
|
74
|
+
if word in _KNOWN_COMMANDS:
|
|
75
|
+
found.add(word)
|
|
76
|
+
for chunk in re.findall(r"`([^`]+)`", text):
|
|
77
|
+
first = chunk.strip().split()[0] if chunk.strip() else ""
|
|
78
|
+
if first in _KNOWN_COMMANDS:
|
|
79
|
+
found.add(first)
|
|
80
|
+
return found
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def _referenced_mcp(text: str) -> set[str]:
|
|
84
|
+
found = {m.lower() for m in _MCP_RE.findall(text)}
|
|
85
|
+
for token in _MCP_PROSE_RE.findall(text):
|
|
86
|
+
t = token.lower()
|
|
87
|
+
if t in _MCP_PROSE_ALLOWLIST or "-" in t or "_" in t:
|
|
88
|
+
found.add(t)
|
|
89
|
+
# Drop generic words that the prose regex over-captures.
|
|
90
|
+
return {
|
|
91
|
+
m for m in found
|
|
92
|
+
if m not in {"the", "a", "an", "use", "call", "via", "with", "and", "or", "s", "to", "of"}
|
|
93
|
+
and len(m) > 1
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def classify(skill: Skill, config: Config) -> Skill:
|
|
98
|
+
"""Mutate and return ``skill`` with category/reason/missing_deps set."""
|
|
99
|
+
try:
|
|
100
|
+
text = skill.path.read_text(encoding="utf-8", errors="replace")
|
|
101
|
+
except OSError:
|
|
102
|
+
text = ""
|
|
103
|
+
low = text.lower()
|
|
104
|
+
|
|
105
|
+
# --- D: platform-private -------------------------------------------------
|
|
106
|
+
if skill.source.endswith("-system") or ".system" in str(skill.path):
|
|
107
|
+
skill.category = "D"
|
|
108
|
+
skill.category_reason = "lives in a platform .system root (private runtime skill)"
|
|
109
|
+
return skill
|
|
110
|
+
for marker in _D_MARKERS:
|
|
111
|
+
if marker.lower() in low:
|
|
112
|
+
skill.category = "D"
|
|
113
|
+
skill.category_reason = f"references platform-private internal '{marker}'"
|
|
114
|
+
return skill
|
|
115
|
+
for marker in config.platform_private_markers:
|
|
116
|
+
if marker.lower() in low and marker.lower() in {m.lower() for m in _D_MARKERS}:
|
|
117
|
+
skill.category = "D"
|
|
118
|
+
skill.category_reason = f"references platform-private internal '{marker}'"
|
|
119
|
+
return skill
|
|
120
|
+
|
|
121
|
+
# --- deps: missing external commands / MCP servers -----------------------
|
|
122
|
+
missing: list[str] = []
|
|
123
|
+
for cmd in sorted(_referenced_commands(text)):
|
|
124
|
+
# 'python'/'python3' are ubiquitous; only flag if truly absent.
|
|
125
|
+
if shutil.which(cmd) is None:
|
|
126
|
+
missing.append(cmd)
|
|
127
|
+
for server in sorted(_referenced_mcp(text)):
|
|
128
|
+
# A configured dep in the [deps] table can vouch for an MCP server.
|
|
129
|
+
dep = config.deps.get(server)
|
|
130
|
+
if dep is not None and dep.available():
|
|
131
|
+
continue
|
|
132
|
+
missing.append(f"MCP:{server}")
|
|
133
|
+
|
|
134
|
+
# --- C: needs rewrite for the target agent ------------------------------
|
|
135
|
+
c_hits = [m for m in _C_MARKERS if m.lower() in low]
|
|
136
|
+
if c_hits:
|
|
137
|
+
skill.category = "C"
|
|
138
|
+
skill.category_reason = (
|
|
139
|
+
"references another agent's conventions/tools (" + ", ".join(sorted(set(c_hits))[:4]) + "); "
|
|
140
|
+
"methodology reusable, text must be rewritten for the target"
|
|
141
|
+
)
|
|
142
|
+
skill.missing_deps = missing
|
|
143
|
+
return skill
|
|
144
|
+
|
|
145
|
+
# --- B: portable but missing deps ---------------------------------------
|
|
146
|
+
if missing:
|
|
147
|
+
skill.category = "B"
|
|
148
|
+
skill.category_reason = "portable, but missing external dependencies"
|
|
149
|
+
skill.missing_deps = missing
|
|
150
|
+
return skill
|
|
151
|
+
|
|
152
|
+
# --- A: portable and runnable -------------------------------------------
|
|
153
|
+
skill.category = "A"
|
|
154
|
+
skill.category_reason = "no platform-private references and all commands present"
|
|
155
|
+
skill.missing_deps = []
|
|
156
|
+
return skill
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def classify_all(skills, config: Config) -> None:
|
|
160
|
+
for skill in skills:
|
|
161
|
+
classify(skill, config)
|
skillsync/cli.py
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"""Command-line interface for skillsync."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import argparse
|
|
6
|
+
import sys
|
|
7
|
+
from collections import Counter
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
from . import __version__
|
|
11
|
+
from .classifier import classify_all
|
|
12
|
+
from .config import load_config
|
|
13
|
+
from .differ import diff_all, sync_state
|
|
14
|
+
from .model import CATEGORIES
|
|
15
|
+
from .report import to_markdown, write_outputs
|
|
16
|
+
from .resolve import resolve
|
|
17
|
+
from .scanner import scan
|
|
18
|
+
from .sync import execute_sync, plan_sync
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _prepare(cfg, *, dedupe: bool = False):
|
|
22
|
+
"""Scan → classify → diff → (optionally) resolve cross-source duplicates."""
|
|
23
|
+
result = scan(cfg)
|
|
24
|
+
classify_all(result.skills, cfg)
|
|
25
|
+
diff_all(result.skills, cfg)
|
|
26
|
+
if dedupe:
|
|
27
|
+
skills, dups, shadowed = resolve(result.skills)
|
|
28
|
+
result.skills = skills
|
|
29
|
+
result.duplicates = dups
|
|
30
|
+
result.shadowed = shadowed
|
|
31
|
+
result.resolved = True
|
|
32
|
+
return result
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
36
|
+
parser = argparse.ArgumentParser(
|
|
37
|
+
prog="skillsync",
|
|
38
|
+
description="Scan, classify and sync AI-agent skills across toolchains.",
|
|
39
|
+
)
|
|
40
|
+
parser.add_argument("--version", action="version", version=f"skillsync {__version__}")
|
|
41
|
+
parser.add_argument("--config", help="path to a skillsync.toml")
|
|
42
|
+
parser.add_argument(
|
|
43
|
+
"--dedupe",
|
|
44
|
+
action="store_true",
|
|
45
|
+
help="collapse skills that are identical across multiple source roots into one entry",
|
|
46
|
+
)
|
|
47
|
+
sub = parser.add_subparsers(dest="command", required=True)
|
|
48
|
+
|
|
49
|
+
p_scan = sub.add_parser("scan", help="scan roots and print a one-line-per-skill summary")
|
|
50
|
+
p_scan.add_argument("--source", action="append", help="extra source root label=path")
|
|
51
|
+
p_scan.add_argument("--category", choices=[*CATEGORIES, "?"], help="filter by category")
|
|
52
|
+
p_scan.add_argument("--json", action="store_true", help="emit JSON inventory")
|
|
53
|
+
|
|
54
|
+
p_status = sub.add_parser("status", help="show counts and sync state (missing/drifted/identical)")
|
|
55
|
+
|
|
56
|
+
p_index = sub.add_parser("index", help="generate INDEX.md + inventory.json")
|
|
57
|
+
p_index.add_argument("--out", default=".", help="output directory (default: cwd)")
|
|
58
|
+
p_index.add_argument("--lang", choices=["zh", "en"], default="zh")
|
|
59
|
+
|
|
60
|
+
p_sync = sub.add_parser("sync", help="copy portable skills into the target root")
|
|
61
|
+
p_sync.add_argument("--categories", default="A", help="comma list, e.g. A,B (default: A)")
|
|
62
|
+
p_sync.add_argument("--dry-run", action="store_true", help="print the plan, change nothing")
|
|
63
|
+
p_sync.add_argument("--force", action="store_true", help="update drifted copies (backs them up first)")
|
|
64
|
+
p_sync.add_argument("--prefix", default="", help="prefix added to every synced skill name")
|
|
65
|
+
p_sync.add_argument(
|
|
66
|
+
"--drifted-only",
|
|
67
|
+
action="store_true",
|
|
68
|
+
help="only refresh skills that already exist in the target but differ; never add new ones",
|
|
69
|
+
)
|
|
70
|
+
p_sync.add_argument("--source", action="append", help="restrict sync to these source labels (repeatable)")
|
|
71
|
+
|
|
72
|
+
return parser
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def _apply_extra_sources(cfg, extras: list[str] | None) -> None:
|
|
76
|
+
if not extras:
|
|
77
|
+
return
|
|
78
|
+
from .config import DEFAULT_GLOB, SourceRoot
|
|
79
|
+
|
|
80
|
+
for item in extras:
|
|
81
|
+
if "=" not in item:
|
|
82
|
+
print(f"[warn] ignoring --source without '=': {item}", file=sys.stderr)
|
|
83
|
+
continue
|
|
84
|
+
label, _, path = item.partition("=")
|
|
85
|
+
cfg.sources.append(
|
|
86
|
+
SourceRoot(label=label.strip(), path=Path(path.strip()).expanduser(), glob=DEFAULT_GLOB)
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _do_scan(cfg, args) -> int:
|
|
91
|
+
result = _prepare(cfg, dedupe=getattr(args, "dedupe", False))
|
|
92
|
+
if args.json:
|
|
93
|
+
from .report import to_json
|
|
94
|
+
|
|
95
|
+
print(to_json(result))
|
|
96
|
+
return 0
|
|
97
|
+
skills = result.skills
|
|
98
|
+
if getattr(args, "category", None):
|
|
99
|
+
skills = [s for s in skills if s.category == args.category]
|
|
100
|
+
for s in sorted(skills, key=lambda x: (x.category, x.source, x.name)):
|
|
101
|
+
state = sync_state(s)
|
|
102
|
+
deps = (" [" + ",".join(s.missing_deps) + "]") if s.missing_deps else ""
|
|
103
|
+
print(f"{s.category} {state:9} {s.source:18} {s.name}{deps}")
|
|
104
|
+
counts = Counter(s.category for s in result.skills)
|
|
105
|
+
print(
|
|
106
|
+
f"\n{len(result.skills)} skills | "
|
|
107
|
+
+ " ".join(f"{c}={counts.get(c, 0)}" for c in CATEGORIES)
|
|
108
|
+
+ (f" ?={counts.get('?', 0)}" if counts.get("?") else "")
|
|
109
|
+
)
|
|
110
|
+
if result.errors:
|
|
111
|
+
print(f"{len(result.errors)} warning(s); rerun with --json for detail", file=sys.stderr)
|
|
112
|
+
return 0
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
def _do_status(cfg, args) -> int:
|
|
116
|
+
result = _prepare(cfg, dedupe=getattr(args, "dedupe", False))
|
|
117
|
+
counts = Counter(s.category for s in result.skills)
|
|
118
|
+
sync_counts = Counter(sync_state(s) for s in result.skills)
|
|
119
|
+
print("skillsync status")
|
|
120
|
+
print("================")
|
|
121
|
+
if cfg.target:
|
|
122
|
+
print(f"target: {cfg.target.label} -> {cfg.target.path} ({'exists' if cfg.target.path.is_dir() else 'MISSING'})")
|
|
123
|
+
for label, path in result.roots_scanned:
|
|
124
|
+
n = sum(1 for s in result.skills if s.source == label)
|
|
125
|
+
print(f"source: {label:20} {n:3} skills {path}")
|
|
126
|
+
print("\nby category:")
|
|
127
|
+
for c in (*CATEGORIES, "?"):
|
|
128
|
+
if counts.get(c):
|
|
129
|
+
print(f" {c}: {counts[c]}")
|
|
130
|
+
print("\nsync state:")
|
|
131
|
+
for state in ("identical", "drifted", "missing"):
|
|
132
|
+
print(f" {state:10}: {sync_counts.get(state, 0)}")
|
|
133
|
+
drifted = [s for s in result.skills if sync_state(s) == "drifted"]
|
|
134
|
+
if drifted:
|
|
135
|
+
print("\ndrifted (source != target):")
|
|
136
|
+
for s in sorted(drifted, key=lambda x: x.name)[:40]:
|
|
137
|
+
print(f" - {s.name}")
|
|
138
|
+
if len(drifted) > 40:
|
|
139
|
+
print(f" ... and {len(drifted) - 40} more")
|
|
140
|
+
if result.resolved and result.duplicates:
|
|
141
|
+
print(f"\ndedupe: collapsed {len(result.duplicates)} name(s) identical across roots "
|
|
142
|
+
f"(e.g. {result.duplicates[0][0]}: {', '.join(result.duplicates[0][1])})")
|
|
143
|
+
if result.resolved and result.shadowed:
|
|
144
|
+
print(f"dedupe: shadowed {len(result.shadowed)} stale copy/copies superseded by a "
|
|
145
|
+
f"newer canonical version (kept the higher-priority source)")
|
|
146
|
+
return 0
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _do_index(cfg, args) -> int:
|
|
150
|
+
result = _prepare(cfg, dedupe=getattr(args, "dedupe", False))
|
|
151
|
+
out_dir = Path(args.out).expanduser()
|
|
152
|
+
paths = write_outputs(result, out_dir, lang=args.lang)
|
|
153
|
+
for p in paths:
|
|
154
|
+
print(f"wrote {p}")
|
|
155
|
+
# Also echo the markdown to stdout for quick piping.
|
|
156
|
+
print()
|
|
157
|
+
print(to_markdown(result, lang=args.lang)[:2000])
|
|
158
|
+
return 0
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
def _do_sync(cfg, args) -> int:
|
|
162
|
+
if cfg.target is None or not cfg.target.path.is_dir():
|
|
163
|
+
print("[error] target root missing; set [target] in skillsync.toml", file=sys.stderr)
|
|
164
|
+
return 2
|
|
165
|
+
result = _prepare(cfg, dedupe=getattr(args, "dedupe", False))
|
|
166
|
+
cats = tuple(c.strip().upper() for c in args.categories.split(",") if c.strip())
|
|
167
|
+
collisions = {s.name for s in result.skills if s.name.startswith(args.prefix)} if args.prefix else set()
|
|
168
|
+
report = plan_sync(
|
|
169
|
+
result.skills,
|
|
170
|
+
cfg.target.path,
|
|
171
|
+
categories=cats,
|
|
172
|
+
prefix_collisions=collisions,
|
|
173
|
+
force=args.force,
|
|
174
|
+
name_prefix=args.prefix,
|
|
175
|
+
drifted_only=args.drifted_only,
|
|
176
|
+
sources=tuple(args.source) if args.source else None,
|
|
177
|
+
)
|
|
178
|
+
mode = "DRY RUN" if args.dry_run else "SYNC"
|
|
179
|
+
print(f"{mode}: categories={'+'.join(cats)} target={cfg.target.path}")
|
|
180
|
+
for item in report.planned:
|
|
181
|
+
print(f" [{item.action}] {item.skill.name} -> {item.dest} {item.note}")
|
|
182
|
+
for item in report.skipped:
|
|
183
|
+
print(f" [skip] {item.skill.name} ({item.note})")
|
|
184
|
+
if not report.planned:
|
|
185
|
+
print(" nothing to do.")
|
|
186
|
+
return 0
|
|
187
|
+
if args.dry_run:
|
|
188
|
+
print(f"\ndry run: {len(report.planned)} action(s) would run. Re-run without --dry-run to apply.")
|
|
189
|
+
return 0
|
|
190
|
+
execute_sync(report, cfg.target.path, dry_run=False)
|
|
191
|
+
print(f"\ncopied={len(report.copied)} updated={len(report.updated)} errors={len(report.errors)}")
|
|
192
|
+
for b in report.backed_up:
|
|
193
|
+
print(f" backed up -> {b}")
|
|
194
|
+
for e in report.errors:
|
|
195
|
+
print(f" [error] {e}", file=sys.stderr)
|
|
196
|
+
return 1 if report.errors else 0
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def main(argv: list[str] | None = None) -> int:
|
|
200
|
+
parser = _build_parser()
|
|
201
|
+
args = parser.parse_args(argv)
|
|
202
|
+
cfg = load_config(args.config)
|
|
203
|
+
# --source means "add a source root" only for scan; for sync it filters by
|
|
204
|
+
# existing labels, so we must not treat sync's values as new roots.
|
|
205
|
+
if args.command == "scan":
|
|
206
|
+
_apply_extra_sources(cfg, getattr(args, "source", None))
|
|
207
|
+
|
|
208
|
+
handlers = {
|
|
209
|
+
"scan": _do_scan,
|
|
210
|
+
"status": _do_status,
|
|
211
|
+
"index": _do_index,
|
|
212
|
+
"sync": _do_sync,
|
|
213
|
+
}
|
|
214
|
+
return handlers[args.command](cfg, args)
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
if __name__ == "__main__":
|
|
218
|
+
raise SystemExit(main())
|