skill-lens-cli 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.
Files changed (41) hide show
  1. skill_lens/__init__.py +3 -0
  2. skill_lens/cli.py +326 -0
  3. skill_lens/core/__init__.py +1 -0
  4. skill_lens/core/compare.py +172 -0
  5. skill_lens/core/diff.py +503 -0
  6. skill_lens/core/discovery.py +562 -0
  7. skill_lens/core/doctor.py +464 -0
  8. skill_lens/core/exitcodes.py +151 -0
  9. skill_lens/core/hasher.py +117 -0
  10. skill_lens/core/parser.py +311 -0
  11. skill_lens/core/paths.py +130 -0
  12. skill_lens/core/resolver.py +607 -0
  13. skill_lens/core/scanner.py +230 -0
  14. skill_lens/core/system.py +96 -0
  15. skill_lens/models/__init__.py +73 -0
  16. skill_lens/models/compare.py +104 -0
  17. skill_lens/models/diff.py +231 -0
  18. skill_lens/models/doctor.py +98 -0
  19. skill_lens/models/enums.py +84 -0
  20. skill_lens/models/installation.py +74 -0
  21. skill_lens/models/parsing.py +105 -0
  22. skill_lens/models/resolution.py +108 -0
  23. skill_lens/py.typed +0 -0
  24. skill_lens/registry/__init__.py +14 -0
  25. skill_lens/registry/agents/antigravity.toml +50 -0
  26. skill_lens/registry/agents/claude.toml +34 -0
  27. skill_lens/registry/agents/codex.toml +64 -0
  28. skill_lens/registry/agents/dsh.toml +93 -0
  29. skill_lens/registry/agents/grok.toml +37 -0
  30. skill_lens/registry/agents/omp.toml +84 -0
  31. skill_lens/registry/agents/opencode.toml +48 -0
  32. skill_lens/registry/agents/pi.toml +48 -0
  33. skill_lens/registry/agents/qoder.toml +38 -0
  34. skill_lens/registry/agents/windsurf.toml +38 -0
  35. skill_lens/registry/loader.py +128 -0
  36. skill_lens/render.py +464 -0
  37. skill_lens_cli-0.1.0.dist-info/METADATA +296 -0
  38. skill_lens_cli-0.1.0.dist-info/RECORD +41 -0
  39. skill_lens_cli-0.1.0.dist-info/WHEEL +4 -0
  40. skill_lens_cli-0.1.0.dist-info/entry_points.txt +2 -0
  41. skill_lens_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
skill_lens/__init__.py ADDED
@@ -0,0 +1,3 @@
1
+ """Skill Lens: A local diagnostics and resolution CLI tool for AI agent capabilities."""
2
+
3
+ __version__ = "0.1.0"
skill_lens/cli.py ADDED
@@ -0,0 +1,326 @@
1
+ """Skill Lens command-line interface.
2
+
3
+ Line-oriented Typer commands (scan, why, agents, diff, doctor, compare).
4
+ Every command supports ``--json`` and returns machine-readable output; the
5
+ Rich layer is presentation only.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from pathlib import Path
11
+ from typing import Annotated
12
+
13
+ import typer
14
+ from rich.console import Console
15
+
16
+ from skill_lens import __version__
17
+ from skill_lens.core import paths
18
+ from skill_lens.core.compare import run_compare
19
+ from skill_lens.core.diff import build_diff_report
20
+ from skill_lens.core.discovery import normalize_cwd
21
+ from skill_lens.core.doctor import run_doctor
22
+ from skill_lens.core.exitcodes import ExitCode, FailOn, exit_code_for, fail_on_help
23
+ from skill_lens.core.resolver import resolve_skill
24
+ from skill_lens.core.scanner import build_scan_report, scan_severities
25
+ from skill_lens.models import dumps
26
+ from skill_lens.models.enums import Severity
27
+ from skill_lens.registry.loader import list_agents
28
+ from skill_lens.render import (
29
+ render_agents,
30
+ render_compare,
31
+ render_diff,
32
+ render_doctor,
33
+ render_scan,
34
+ render_why,
35
+ )
36
+
37
+ app = typer.Typer(
38
+ name="skill-lens",
39
+ help="Local, read-only diagnostics and resolution for AI agent skills.",
40
+ no_args_is_help=True,
41
+ add_completion=False,
42
+ )
43
+
44
+ console = Console()
45
+ error_console = Console(stderr=True)
46
+
47
+
48
+ def _emit_json(payload: object) -> None:
49
+ """Print canonical JSON without wrapping, markup or highlighting.
50
+
51
+ Rich's default word-wrap would insert newlines inside JSON strings and
52
+ corrupt the output, so wrapping and markup are disabled explicitly.
53
+ """
54
+ console.print(dumps(payload), soft_wrap=True, markup=False, highlight=False)
55
+
56
+
57
+ def _version_callback(value: bool) -> None:
58
+ if value:
59
+ console.print(f"skill-lens {__version__}")
60
+ raise typer.Exit()
61
+
62
+
63
+ @app.callback()
64
+ def main(
65
+ version: Annotated[
66
+ bool,
67
+ typer.Option("--version", callback=_version_callback, is_eager=True, help="Show version."),
68
+ ] = False,
69
+ ) -> None:
70
+ """Skill Lens: know what skills you have, and why each one wins."""
71
+
72
+
73
+ def _apply_sandbox(sandbox: Path | None) -> None:
74
+ if sandbox is not None:
75
+ paths.set_sandbox(sandbox)
76
+
77
+
78
+ def _effective_home() -> Path:
79
+ return paths.home()
80
+
81
+
82
+ def _effective_cwd(cwd: Path | None, sandbox: Path | None) -> Path:
83
+ """Resolve the working directory, clamped to the sandbox when there is one.
84
+
85
+ ``$HOME`` is usually not inside a repository, so defaulting there silently
86
+ skipped every project root -- hence the terminal folder. A *relative*
87
+ ``--cwd`` keeps its documented meaning under ``--sandbox``: home-relative,
88
+ never process-relative, so a sandboxed run can never be walked from the
89
+ folder the user happens to be standing in.
90
+ """
91
+ if cwd is None:
92
+ return paths.terminal_cwd()
93
+ if sandbox is None:
94
+ return cwd
95
+ return normalize_cwd(cwd, sandbox)
96
+
97
+
98
+ def _assert_inside_sandbox(cwd: Path, sandbox: Path) -> None:
99
+ """Refuse a ``--cwd`` that points out of the sandbox.
100
+
101
+ Relative values are clamped first (see :func:`_effective_cwd`), but an
102
+ *absolute* one was accepted verbatim and let a sandboxed run read any
103
+ directory on the machine. Resolving both sides means the check still holds
104
+ when the sandbox itself sits behind a symlink (macOS ``/tmp``).
105
+ """
106
+ if paths.same_location(cwd, sandbox):
107
+ return
108
+ try:
109
+ cwd.resolve().relative_to(sandbox.resolve())
110
+ except ValueError:
111
+ raise typer.BadParameter(f"--cwd must stay inside --sandbox {sandbox}; got {cwd}") from None
112
+
113
+
114
+ _CWD_HELP = "Working directory (defaults to the current terminal folder)."
115
+
116
+
117
+ def _finish(severities: tuple[Severity, ...], fail_on: FailOn) -> None:
118
+ """Exit with the status the threshold implies, once output is already sent.
119
+
120
+ Called only *after* the report has been printed, so a failing run still
121
+ shows the user everything that caused the failure. An exit raised before the
122
+ report would make ``--fail-on`` a way to hide the evidence.
123
+ """
124
+ code = exit_code_for(severities, fail_on)
125
+ if code is not ExitCode.OK:
126
+ raise typer.Exit(code=int(code))
127
+
128
+
129
+ @app.command()
130
+ def scan(
131
+ sandbox: Annotated[
132
+ Path | None,
133
+ typer.Option("--sandbox", help="Treat this directory as a mock $HOME."),
134
+ ] = None,
135
+ cwd: Annotated[
136
+ Path | None,
137
+ typer.Option("--cwd", help=_CWD_HELP),
138
+ ] = None,
139
+ as_json: Annotated[
140
+ bool,
141
+ typer.Option("--json", help="Emit machine-readable JSON."),
142
+ ] = False,
143
+ fail_on: Annotated[
144
+ FailOn,
145
+ typer.Option("--fail-on", help=fail_on_help()),
146
+ ] = FailOn.NEVER,
147
+ ) -> None:
148
+ """Inventory skills across every detected agent."""
149
+ _apply_sandbox(sandbox)
150
+ home = _effective_home()
151
+ working_dir = _effective_cwd(cwd, sandbox)
152
+ if sandbox is not None:
153
+ _assert_inside_sandbox(working_dir, home)
154
+ report = build_scan_report(home, working_dir)
155
+ if as_json:
156
+ _emit_json(report.to_dict())
157
+ else:
158
+ render_scan(report, console)
159
+ _finish(scan_severities(report), fail_on)
160
+
161
+
162
+ @app.command()
163
+ def why(
164
+ skill_name: Annotated[str, typer.Argument(help="Skill name to resolve.")],
165
+ agent: Annotated[str, typer.Option("--agent", help="Target agent id (e.g. claude).")],
166
+ cwd: Annotated[
167
+ Path | None,
168
+ typer.Option("--cwd", help=_CWD_HELP),
169
+ ] = None,
170
+ sandbox: Annotated[
171
+ Path | None,
172
+ typer.Option("--sandbox", help="Treat this directory as a mock $HOME."),
173
+ ] = None,
174
+ as_json: Annotated[
175
+ bool,
176
+ typer.Option("--json", help="Emit machine-readable JSON."),
177
+ ] = False,
178
+ ) -> None:
179
+ """Explain how a skill resolves for one agent, and why."""
180
+ _apply_sandbox(sandbox)
181
+ home = _effective_home()
182
+ working_dir = _effective_cwd(cwd, sandbox)
183
+ if sandbox is not None:
184
+ _assert_inside_sandbox(working_dir, home)
185
+ try:
186
+ report = resolve_skill(skill_name, agent, working_dir, home)
187
+ except KeyError as exc:
188
+ error_console.print(f"[red]Error:[/red] {exc.args[0]}")
189
+ raise typer.Exit(code=2) from None
190
+ if as_json:
191
+ _emit_json(report.to_dict())
192
+ return
193
+ render_why(report, console)
194
+
195
+
196
+ @app.command()
197
+ def agents(
198
+ as_json: Annotated[
199
+ bool,
200
+ typer.Option("--json", help="Emit machine-readable JSON."),
201
+ ] = False,
202
+ ) -> None:
203
+ """List the known agent definitions and their precedence policy."""
204
+ definitions = list_agents()
205
+ if as_json:
206
+ payload = [
207
+ {
208
+ "id": agent.id,
209
+ "name": agent.name,
210
+ "collision_policy": agent.collision_policy,
211
+ "policy_evidence": agent.policy_evidence.value,
212
+ "roots": len(agent.roots),
213
+ }
214
+ for agent in definitions
215
+ ]
216
+ _emit_json(payload)
217
+ return
218
+ render_agents(definitions, console)
219
+
220
+
221
+ @app.command()
222
+ def diff(
223
+ skill_name: Annotated[str, typer.Argument(help="Skill name whose variants to diff.")],
224
+ sandbox: Annotated[
225
+ Path | None,
226
+ typer.Option("--sandbox", help="Treat this directory as a mock $HOME."),
227
+ ] = None,
228
+ cwd: Annotated[
229
+ Path | None,
230
+ typer.Option("--cwd", help=_CWD_HELP),
231
+ ] = None,
232
+ as_json: Annotated[
233
+ bool,
234
+ typer.Option("--json", help="Emit machine-readable JSON."),
235
+ ] = False,
236
+ ) -> None:
237
+ """Unified diff between the differing variants that share one name."""
238
+ _apply_sandbox(sandbox)
239
+ home = _effective_home()
240
+ working_dir = _effective_cwd(cwd, sandbox)
241
+ if sandbox is not None:
242
+ _assert_inside_sandbox(working_dir, home)
243
+ report = build_diff_report(skill_name, working_dir, home)
244
+ if as_json:
245
+ _emit_json(report.to_dict())
246
+ return
247
+ render_diff(report, console)
248
+
249
+
250
+ @app.command()
251
+ def doctor(
252
+ sandbox: Annotated[
253
+ Path | None,
254
+ typer.Option("--sandbox", help="Treat this directory as a mock $HOME."),
255
+ ] = None,
256
+ cwd: Annotated[
257
+ Path | None,
258
+ typer.Option("--cwd", help=_CWD_HELP),
259
+ ] = None,
260
+ as_json: Annotated[
261
+ bool,
262
+ typer.Option("--json", help="Emit machine-readable JSON."),
263
+ ] = False,
264
+ fail_on: Annotated[
265
+ FailOn,
266
+ typer.Option("--fail-on", help=fail_on_help()),
267
+ ] = FailOn.NEVER,
268
+ ) -> None:
269
+ """Check skill hygiene: broken links, bad frontmatter, budget risks."""
270
+ _apply_sandbox(sandbox)
271
+ home = _effective_home()
272
+ working_dir = _effective_cwd(cwd, sandbox)
273
+ if sandbox is not None:
274
+ _assert_inside_sandbox(working_dir, home)
275
+ # The CLI goes through the live adapter (system.py) so the OSError-
276
+ # guarded bridge is the production path, not a test-only helper.
277
+ report = run_doctor(cwd=working_dir)
278
+ if as_json:
279
+ _emit_json(report.to_dict())
280
+ else:
281
+ render_doctor(report, console)
282
+ _finish(tuple(finding.severity for finding in report.findings), fail_on)
283
+
284
+
285
+ @app.command()
286
+ def compare(
287
+ agents: Annotated[
288
+ list[str],
289
+ typer.Option("--agent", help="Agent id to compare. Pass exactly two."),
290
+ ],
291
+ sandbox: Annotated[
292
+ Path | None,
293
+ typer.Option("--sandbox", help="Treat this directory as a mock $HOME."),
294
+ ] = None,
295
+ cwd: Annotated[
296
+ Path | None,
297
+ typer.Option("--cwd", help=_CWD_HELP),
298
+ ] = None,
299
+ as_json: Annotated[
300
+ bool,
301
+ typer.Option("--json", help="Emit machine-readable JSON."),
302
+ ] = False,
303
+ ) -> None:
304
+ """Compare which skills two agents can reach: shared, diverged, one-sided."""
305
+ if len(agents) != 2:
306
+ raise typer.BadParameter(
307
+ f"pass --agent exactly twice (two agents to compare); got {len(agents)}."
308
+ )
309
+ _apply_sandbox(sandbox)
310
+ home = _effective_home()
311
+ working_dir = _effective_cwd(cwd, sandbox)
312
+ if sandbox is not None:
313
+ _assert_inside_sandbox(working_dir, home)
314
+ try:
315
+ report = run_compare(agents[0], agents[1], cwd=working_dir)
316
+ except KeyError as exc:
317
+ error_console.print(f"[red]Error:[/red] {exc.args[0]}")
318
+ raise typer.Exit(code=2) from None
319
+ if as_json:
320
+ _emit_json(report.to_dict())
321
+ return
322
+ render_compare(report, console)
323
+
324
+
325
+ if __name__ == "__main__": # pragma: no cover
326
+ app()
@@ -0,0 +1 @@
1
+ """Core engine package: paths, parsing, resolution and diagnostics."""
@@ -0,0 +1,172 @@
1
+ """``skill-lens compare --agent A --agent B``: pairwise capability surface.
2
+
3
+ Pure function over one discovery pass. Both agents are read from the *same*
4
+ :class:`~skill_lens.core.discovery.DiscoveryIndex` so the comparison is
5
+ consistent: a skill counts as shared when the two entrypoints resolve to one
6
+ canonical target, or -- when they are separate files -- to identical bytes.
7
+ Names that exist in both agents with genuinely different content are called
8
+ out as divergences, exactly the state where ``skill-lens diff`` is the
9
+ follow-up command.
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from pathlib import Path
15
+
16
+ from skill_lens.core.discovery import DiscoveredEntry, DiscoveryIndex, discover
17
+ from skill_lens.core.system import live_discovery
18
+ from skill_lens.models.compare import CompareEntry, CompareReport
19
+ from skill_lens.models.enums import CompareRelation
20
+ from skill_lens.registry.loader import AgentDefinition, load_registry
21
+
22
+
23
+ def build_compare_report(
24
+ agent_a: str,
25
+ agent_b: str,
26
+ home: Path,
27
+ cwd: Path,
28
+ index: DiscoveryIndex | None = None,
29
+ registry: dict[str, AgentDefinition] | None = None,
30
+ ) -> CompareReport:
31
+ """Compare the skills two agents can reach, name by name.
32
+
33
+ Raises ``KeyError`` for an unknown agent id -- the CLI turns that into
34
+ exit code ``2``. ``agent_a`` decides which side of every entry the ``*_a``
35
+ fields describe, so ``claude vs codex`` and ``codex vs claude`` are honest
36
+ mirrors of one another, not re-judged.
37
+ """
38
+ agents = registry if registry is not None else load_registry()
39
+ definition_a = _require(agent_a, agents)
40
+ definition_b = _require(agent_b, agents)
41
+
42
+ discovery = index if index is not None else discover(home, cwd, agents)
43
+
44
+ by_agent: dict[str, dict[str, list[DiscoveredEntry]]] = {agent_a: {}, agent_b: {}}
45
+ for entry in discovery.entries:
46
+ for agent_id in (agent_a, agent_b):
47
+ if any(hit.agent_id == agent_id for hit in entry.hits):
48
+ by_agent[agent_id].setdefault(entry.name, []).append(entry)
49
+
50
+ entries = [
51
+ _classify(
52
+ name,
53
+ by_agent[agent_a].get(name, []),
54
+ by_agent[agent_b].get(name, []),
55
+ agent_a,
56
+ agent_b,
57
+ )
58
+ for name in sorted(set(by_agent[agent_a]) | set(by_agent[agent_b]))
59
+ ]
60
+ notes: list[str] = []
61
+ diverged = [entry.name for entry in entries if entry.relation is CompareRelation.DIVERGED]
62
+ if diverged:
63
+ joined = ", ".join(f"'{name}'" for name in diverged)
64
+ notes.append(
65
+ f"names where {agent_a} and {agent_b} read different copies: {joined}. "
66
+ "Run 'skill-lens diff <name>' to see the text differences."
67
+ )
68
+
69
+ return CompareReport(
70
+ agent_a=agent_a,
71
+ agent_b=agent_b,
72
+ agent_a_name=definition_a.name,
73
+ agent_b_name=definition_b.name,
74
+ home=str(home),
75
+ cwd=str(cwd),
76
+ entries=tuple(entries),
77
+ notes=tuple(notes),
78
+ )
79
+
80
+
81
+ def _require(agent_id: str, agents: dict[str, AgentDefinition]) -> AgentDefinition:
82
+ """Fetch one definition or raise the CLI-friendly ``KeyError``."""
83
+ definition = agents.get(agent_id)
84
+ if definition is None:
85
+ known = ", ".join(sorted(agents))
86
+ raise KeyError(f"unknown agent '{agent_id}'. Known agents: {known}")
87
+ return definition
88
+
89
+
90
+ def _entrypoint_for(agent_id: str, entry: DiscoveredEntry) -> str | None:
91
+ """The path *this* agent sees for this entry (its own hit, not the first)."""
92
+ for hit in entry.hits:
93
+ if hit.agent_id == agent_id:
94
+ return hit.entrypoint_path
95
+ return None
96
+
97
+
98
+ def _classify(
99
+ name: str,
100
+ entries_a: list[DiscoveredEntry],
101
+ entries_b: list[DiscoveredEntry],
102
+ agent_a: str,
103
+ agent_b: str,
104
+ ) -> CompareEntry:
105
+ """One name, two agents: shared copy, divergent copies, or only one side.
106
+
107
+ An agent that reaches a name through *several* canonical copies (its own
108
+ ambiguous duplicates) is compared on the first entry discovery produced;
109
+ ``why`` and ``diff`` are the tools for that mess, ``compare`` only needs
110
+ to be honest that both sides exist.
111
+ """
112
+ if entries_a and entries_b:
113
+ canonicals_b = {entry.canonical_path for entry in entries_b if entry.canonical_path}
114
+ shared = next((entry for entry in entries_a if entry.canonical_path in canonicals_b), None)
115
+ if shared is not None:
116
+ mirror = next(e for e in entries_b if e.canonical_path == shared.canonical_path)
117
+ return CompareEntry(
118
+ name=name,
119
+ relation=CompareRelation.SHARED,
120
+ path_a=_entrypoint_for(agent_a, shared),
121
+ path_b=_entrypoint_for(agent_b, mirror),
122
+ canonical_a=shared.canonical_path,
123
+ canonical_b=mirror.canonical_path,
124
+ )
125
+ # Separate canonical files. They still describe the same capability
126
+ # when the bytes match -- hashing a copy is what discovery already
127
+ # does for `diff`, so reuse it here instead of sending the user to
128
+ # `diff` for copies that would then report "no differences".
129
+ hash_a = entries_a[0].content_hash
130
+ hash_b = entries_b[0].content_hash
131
+ if hash_a is not None and hash_a == hash_b:
132
+ return CompareEntry(
133
+ name=name,
134
+ relation=CompareRelation.SHARED,
135
+ path_a=_entrypoint_for(agent_a, entries_a[0]),
136
+ path_b=_entrypoint_for(agent_b, entries_b[0]),
137
+ canonical_a=entries_a[0].canonical_path,
138
+ canonical_b=entries_b[0].canonical_path,
139
+ )
140
+ return CompareEntry(
141
+ name=name,
142
+ relation=CompareRelation.DIVERGED,
143
+ path_a=_entrypoint_for(agent_a, entries_a[0]),
144
+ path_b=_entrypoint_for(agent_b, entries_b[0]),
145
+ canonical_a=entries_a[0].canonical_path,
146
+ canonical_b=entries_b[0].canonical_path,
147
+ )
148
+ only_a = bool(entries_a)
149
+ side = entries_a if only_a else entries_b
150
+ return CompareEntry(
151
+ name=name,
152
+ relation=CompareRelation.ONLY_A if only_a else CompareRelation.ONLY_B,
153
+ path_a=_entrypoint_for(agent_a, side[0]) if only_a else None,
154
+ path_b=_entrypoint_for(agent_b, side[0]) if not only_a else None,
155
+ canonical_a=side[0].canonical_path if only_a else None,
156
+ canonical_b=side[0].canonical_path if not only_a else None,
157
+ )
158
+
159
+
160
+ def run_compare(agent_a: str, agent_b: str, cwd: Path | None = None) -> CompareReport:
161
+ """Compare two agents against the live machine (used by the CLI).
162
+
163
+ Agent ids are validated *before* the filesystem walk, so a typo costs an
164
+ error message, not a crawl. The loaded registry is handed down, too.
165
+ """
166
+ agents = load_registry()
167
+ _require(agent_a, agents)
168
+ _require(agent_b, agents)
169
+ index = live_discovery(cwd, agents)
170
+ return build_compare_report(
171
+ agent_a, agent_b, Path(index.home), Path(index.cwd), index=index, registry=agents
172
+ )