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.
- skill_lens/__init__.py +3 -0
- skill_lens/cli.py +326 -0
- skill_lens/core/__init__.py +1 -0
- skill_lens/core/compare.py +172 -0
- skill_lens/core/diff.py +503 -0
- skill_lens/core/discovery.py +562 -0
- skill_lens/core/doctor.py +464 -0
- skill_lens/core/exitcodes.py +151 -0
- skill_lens/core/hasher.py +117 -0
- skill_lens/core/parser.py +311 -0
- skill_lens/core/paths.py +130 -0
- skill_lens/core/resolver.py +607 -0
- skill_lens/core/scanner.py +230 -0
- skill_lens/core/system.py +96 -0
- skill_lens/models/__init__.py +73 -0
- skill_lens/models/compare.py +104 -0
- skill_lens/models/diff.py +231 -0
- skill_lens/models/doctor.py +98 -0
- skill_lens/models/enums.py +84 -0
- skill_lens/models/installation.py +74 -0
- skill_lens/models/parsing.py +105 -0
- skill_lens/models/resolution.py +108 -0
- skill_lens/py.typed +0 -0
- skill_lens/registry/__init__.py +14 -0
- skill_lens/registry/agents/antigravity.toml +50 -0
- skill_lens/registry/agents/claude.toml +34 -0
- skill_lens/registry/agents/codex.toml +64 -0
- skill_lens/registry/agents/dsh.toml +93 -0
- skill_lens/registry/agents/grok.toml +37 -0
- skill_lens/registry/agents/omp.toml +84 -0
- skill_lens/registry/agents/opencode.toml +48 -0
- skill_lens/registry/agents/pi.toml +48 -0
- skill_lens/registry/agents/qoder.toml +38 -0
- skill_lens/registry/agents/windsurf.toml +38 -0
- skill_lens/registry/loader.py +128 -0
- skill_lens/render.py +464 -0
- skill_lens_cli-0.1.0.dist-info/METADATA +296 -0
- skill_lens_cli-0.1.0.dist-info/RECORD +41 -0
- skill_lens_cli-0.1.0.dist-info/WHEEL +4 -0
- skill_lens_cli-0.1.0.dist-info/entry_points.txt +2 -0
- skill_lens_cli-0.1.0.dist-info/licenses/LICENSE +21 -0
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
"""Inventory a discovery pass into a stable, JSON-serializable catalog.
|
|
2
|
+
|
|
3
|
+
``scan`` is the inventory view: it groups a symlink farm into one canonical
|
|
4
|
+
library with N entrypoints, separates user / project / system / plugin scopes,
|
|
5
|
+
and reports which agents can reach each skill.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from dataclasses import dataclass, field
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
from typing import Any
|
|
13
|
+
|
|
14
|
+
from skill_lens.core.discovery import (
|
|
15
|
+
SCOPE_SPECIFICITY,
|
|
16
|
+
DiscoveredEntry,
|
|
17
|
+
DiscoveryIndex,
|
|
18
|
+
discover,
|
|
19
|
+
entry_scope,
|
|
20
|
+
labels_for_entries,
|
|
21
|
+
)
|
|
22
|
+
from skill_lens.models.enums import ParseStatus, Scope, Severity
|
|
23
|
+
from skill_lens.registry.loader import AgentDefinition, load_registry
|
|
24
|
+
|
|
25
|
+
_SCOPE_ORDER = SCOPE_SPECIFICITY
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
@dataclass(frozen=True, slots=True)
|
|
29
|
+
class ScanEntry:
|
|
30
|
+
"""One row of the scan inventory."""
|
|
31
|
+
|
|
32
|
+
name: str
|
|
33
|
+
scope: Scope
|
|
34
|
+
canonical_path: str
|
|
35
|
+
parse_status: str
|
|
36
|
+
agents: tuple[str, ...]
|
|
37
|
+
entrypoint_count: int
|
|
38
|
+
is_symlink: bool
|
|
39
|
+
content_hash: str | None
|
|
40
|
+
description: str | None = None
|
|
41
|
+
variant_label: str | None = None
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> dict[str, Any]:
|
|
44
|
+
return {
|
|
45
|
+
"name": self.name,
|
|
46
|
+
"scope": self.scope.value,
|
|
47
|
+
"canonical_path": self.canonical_path,
|
|
48
|
+
"parse_status": self.parse_status,
|
|
49
|
+
"agents": list(self.agents),
|
|
50
|
+
"entrypoint_count": self.entrypoint_count,
|
|
51
|
+
"is_symlink": self.is_symlink,
|
|
52
|
+
"content_hash": self.content_hash,
|
|
53
|
+
"description": self.description,
|
|
54
|
+
"variant_label": self.variant_label,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@dataclass(frozen=True, slots=True)
|
|
59
|
+
class ScanSummary:
|
|
60
|
+
"""Aggregate counts plus the per-scope skill totals."""
|
|
61
|
+
|
|
62
|
+
detected_agents: tuple[str, ...]
|
|
63
|
+
user_skills: int
|
|
64
|
+
project_skills: int
|
|
65
|
+
system_skills: int
|
|
66
|
+
plugin_skills: int
|
|
67
|
+
#: Size of the **canonical library** -- the shared, user-scoped skills the
|
|
68
|
+
#: symlink farms point at. This is the user-scope count only: plugin and
|
|
69
|
+
#: system skills are indexed separately and must never inflate it (spec
|
|
70
|
+
#: section 4). The grand total is :attr:`total_skills`.
|
|
71
|
+
canonical_skill_count: int
|
|
72
|
+
symlink_entrypoints: int
|
|
73
|
+
|
|
74
|
+
@property
|
|
75
|
+
def total_skills(self) -> int:
|
|
76
|
+
return self.user_skills + self.project_skills + self.system_skills + self.plugin_skills
|
|
77
|
+
|
|
78
|
+
def to_dict(self) -> dict[str, Any]:
|
|
79
|
+
return {
|
|
80
|
+
"detected_agents": list(self.detected_agents),
|
|
81
|
+
"user_skills": self.user_skills,
|
|
82
|
+
"project_skills": self.project_skills,
|
|
83
|
+
"system_skills": self.system_skills,
|
|
84
|
+
"plugin_skills": self.plugin_skills,
|
|
85
|
+
"canonical_skill_count": self.canonical_skill_count,
|
|
86
|
+
"symlink_entrypoints": self.symlink_entrypoints,
|
|
87
|
+
"total_skills": self.total_skills,
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@dataclass(frozen=True, slots=True)
|
|
92
|
+
class ScanReport:
|
|
93
|
+
"""The complete result of a scan."""
|
|
94
|
+
|
|
95
|
+
home: str
|
|
96
|
+
cwd: str
|
|
97
|
+
summary: ScanSummary
|
|
98
|
+
skills: tuple[ScanEntry, ...]
|
|
99
|
+
unreadable: tuple[dict[str, str], ...] = field(default_factory=tuple)
|
|
100
|
+
|
|
101
|
+
def to_dict(self) -> dict[str, Any]:
|
|
102
|
+
return {
|
|
103
|
+
"home": self.home,
|
|
104
|
+
"cwd": self.cwd,
|
|
105
|
+
"summary": self.summary.to_dict(),
|
|
106
|
+
"skills": [skill.to_dict() for skill in self.skills],
|
|
107
|
+
"unreadable": list(self.unreadable),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
#: How a scan entry's parse status ranks as a health problem.
|
|
112
|
+
#:
|
|
113
|
+
#: These deliberately mirror the severities ``doctor`` assigns to the same
|
|
114
|
+
#: conditions (``malformed_frontmatter`` is an error, ``unreadable_root`` is a
|
|
115
|
+
#: warning). If the two ever disagree, ``--fail-on`` on ``scan`` and ``doctor``
|
|
116
|
+
#: would disagree about whether the same machine is healthy, which is worse than
|
|
117
|
+
#: either being slightly conservative.
|
|
118
|
+
_PARSE_STATUS_SEVERITY: dict[str, Severity] = {
|
|
119
|
+
ParseStatus.MALFORMED_YAML.value: Severity.ERROR,
|
|
120
|
+
ParseStatus.MISSING_DESCRIPTION.value: Severity.ERROR,
|
|
121
|
+
ParseStatus.UNREADABLE.value: Severity.WARNING,
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
def scan_severities(report: ScanReport) -> tuple[Severity, ...]:
|
|
126
|
+
"""Every health problem visible in a scan report, as severities.
|
|
127
|
+
|
|
128
|
+
Pure: takes a finished report, returns the severities. This is what lets
|
|
129
|
+
``scan --fail-on`` gate a pipeline without ``cli.py`` re-deriving the rules.
|
|
130
|
+
|
|
131
|
+
A skill that parsed cleanly contributes nothing. An unreadable *root* is a
|
|
132
|
+
warning even though no entry can be produced for it, because the absence of
|
|
133
|
+
skills in a blocked directory is itself the finding.
|
|
134
|
+
"""
|
|
135
|
+
severities: list[Severity] = [
|
|
136
|
+
_PARSE_STATUS_SEVERITY[skill.parse_status]
|
|
137
|
+
for skill in report.skills
|
|
138
|
+
if skill.parse_status in _PARSE_STATUS_SEVERITY
|
|
139
|
+
]
|
|
140
|
+
severities.extend(Severity.WARNING for _ in report.unreadable)
|
|
141
|
+
return tuple(severities)
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
def _agents_of(entry: DiscoveredEntry) -> tuple[str, ...]:
|
|
145
|
+
return tuple(sorted({hit.agent_id for hit in entry.hits}))
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _symlink_entrypoint_count(entry: DiscoveredEntry) -> int:
|
|
149
|
+
"""Count the entrypoint paths that are genuinely symlinks on disk.
|
|
150
|
+
|
|
151
|
+
Counting (agent, root) hits instead would inflate the number, because a
|
|
152
|
+
single real path is reached by several agent roots.
|
|
153
|
+
"""
|
|
154
|
+
return sum(
|
|
155
|
+
1 for path in entry.entrypoint_paths or (entry.entrypoint_path,) if Path(path).is_symlink()
|
|
156
|
+
)
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
def _variant_labels(indexed: list[tuple[DiscoveredEntry, Scope]]) -> dict[str, str]:
|
|
160
|
+
"""Label same-named copies as Variant A / B, using the shared rule.
|
|
161
|
+
|
|
162
|
+
See :func:`skill_lens.core.discovery.labels_for_entries` -- ``scan``,
|
|
163
|
+
``why`` and ``diff`` must agree, so a copy is never "Variant A" in one
|
|
164
|
+
command and "B" in another.
|
|
165
|
+
"""
|
|
166
|
+
return labels_for_entries(entry for entry, _scope in indexed)
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
def build_scan_report(
|
|
170
|
+
home: Path,
|
|
171
|
+
cwd: Path,
|
|
172
|
+
index: DiscoveryIndex | None = None,
|
|
173
|
+
registry: dict[str, AgentDefinition] | None = None,
|
|
174
|
+
) -> ScanReport:
|
|
175
|
+
"""Turn a discovery pass into a scan report."""
|
|
176
|
+
agents = registry if registry is not None else load_registry()
|
|
177
|
+
discovery = index if index is not None else discover(home, cwd, agents)
|
|
178
|
+
|
|
179
|
+
indexed = [(entry, entry_scope(entry)) for entry in discovery.entries]
|
|
180
|
+
labels = _variant_labels(indexed)
|
|
181
|
+
|
|
182
|
+
skills: list[ScanEntry] = []
|
|
183
|
+
for entry, scope in indexed:
|
|
184
|
+
canonical = entry.canonical_path or entry.entrypoint_path
|
|
185
|
+
skills.append(
|
|
186
|
+
ScanEntry(
|
|
187
|
+
name=entry.name,
|
|
188
|
+
scope=scope,
|
|
189
|
+
canonical_path=canonical,
|
|
190
|
+
parse_status=entry.parse_status,
|
|
191
|
+
agents=_agents_of(entry),
|
|
192
|
+
entrypoint_count=len(entry.entrypoint_paths) or len(entry.hits),
|
|
193
|
+
is_symlink=entry.is_symlink,
|
|
194
|
+
content_hash=entry.content_hash,
|
|
195
|
+
description=entry.parse.description if entry.parse else None,
|
|
196
|
+
variant_label=labels.get(canonical),
|
|
197
|
+
)
|
|
198
|
+
)
|
|
199
|
+
skills.sort(key=lambda s: (_SCOPE_ORDER.get(s.scope, 9), s.name))
|
|
200
|
+
|
|
201
|
+
detected = sorted({hit.agent_id for entry in discovery.entries for hit in entry.hits})
|
|
202
|
+
counts = {scope: 0 for scope in Scope}
|
|
203
|
+
for skill in skills:
|
|
204
|
+
counts[skill.scope] += 1
|
|
205
|
+
|
|
206
|
+
summary = ScanSummary(
|
|
207
|
+
detected_agents=tuple(detected),
|
|
208
|
+
user_skills=counts[Scope.USER],
|
|
209
|
+
project_skills=counts[Scope.PROJECT],
|
|
210
|
+
system_skills=counts[Scope.SYSTEM],
|
|
211
|
+
plugin_skills=counts[Scope.PLUGIN],
|
|
212
|
+
canonical_skill_count=counts[Scope.USER],
|
|
213
|
+
symlink_entrypoints=sum(_symlink_entrypoint_count(entry) for entry in discovery.entries),
|
|
214
|
+
)
|
|
215
|
+
unreadable = tuple(
|
|
216
|
+
{
|
|
217
|
+
"agent": root.agent_id,
|
|
218
|
+
"root": root.root_id,
|
|
219
|
+
"path": root.path,
|
|
220
|
+
"detail": root.detail,
|
|
221
|
+
}
|
|
222
|
+
for root in discovery.unreadable_roots
|
|
223
|
+
)
|
|
224
|
+
return ScanReport(
|
|
225
|
+
home=str(home),
|
|
226
|
+
cwd=str(cwd),
|
|
227
|
+
summary=summary,
|
|
228
|
+
skills=tuple(skills),
|
|
229
|
+
unreadable=unreadable,
|
|
230
|
+
)
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"""Live-filesystem adapter: the guarded bridge between the engine and real disk.
|
|
2
|
+
|
|
3
|
+
Everything above this module is pure -- it takes a ``home``/``cwd`` and returns
|
|
4
|
+
models. This module is the only place that asks *where the user actually is*
|
|
5
|
+
(:func:`skill_lens.core.paths` resolves ``$HOME`` at call time, never at
|
|
6
|
+
import), and the only place that touches the filesystem defensively: a real
|
|
7
|
+
home contains directories macOS TCC refuses to list and files that are
|
|
8
|
+
symlinks to nothing, and an ``OSError`` from one directory must never abort a
|
|
9
|
+
diagnostic run.
|
|
10
|
+
|
|
11
|
+
Read-only is absolute here: every call is ``iterdir`` / ``read_text`` /
|
|
12
|
+
``stat``. Skill Lens never creates, moves, or deletes anything it probes.
|
|
13
|
+
"""
|
|
14
|
+
|
|
15
|
+
from __future__ import annotations
|
|
16
|
+
|
|
17
|
+
import json
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
from typing import Any
|
|
20
|
+
|
|
21
|
+
from skill_lens.core import paths
|
|
22
|
+
from skill_lens.core.discovery import DiscoveryIndex, discover
|
|
23
|
+
from skill_lens.models.parsing import ERR_PERMISSION_DENIED
|
|
24
|
+
from skill_lens.registry.loader import AgentDefinition
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def shared_library(home: Path | None = None) -> Path:
|
|
28
|
+
"""Return ``$HOME/.agents/skills``: the library symlink farms point into.
|
|
29
|
+
|
|
30
|
+
Resolved per call from the effective home (sandbox or real), never at
|
|
31
|
+
import time (AGENTS.md rule 3).
|
|
32
|
+
"""
|
|
33
|
+
root = home if home is not None else paths.home()
|
|
34
|
+
return root / ".agents" / "skills"
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def installer_lockfile(home: Path | None = None) -> Path:
|
|
38
|
+
"""Return the installer lockfile path (``$HOME/.agents/.skill-lock.json``)."""
|
|
39
|
+
root = home if home is not None else paths.home()
|
|
40
|
+
return root / ".agents" / ".skill-lock.json"
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
#: Outcome codes returned by :func:`read_json_guarded` alongside the
|
|
44
|
+
#: ERR_* constants it can reuse from :mod:`skill_lens.models.parsing`.
|
|
45
|
+
ERR_MISSING_FILE = "missing"
|
|
46
|
+
ERR_NOT_JSON = "not_json"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
#: ``errno`` values that mean "the OS refused us", not "the file is absent".
|
|
50
|
+
_PERMISSION_ERRNOS = frozenset({1, 13}) # EPERM, EACCES
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def read_json_guarded(path: Path) -> tuple[Any | None, str | None]:
|
|
54
|
+
"""Read a JSON file without letting a refusal raise.
|
|
55
|
+
|
|
56
|
+
Returns ``(value, None)`` on success, ``(None, error)`` where ``error`` is
|
|
57
|
+
:data:`~skill_lens.models.parsing.ERR_PERMISSION_DENIED` for an OS
|
|
58
|
+
refusal, :data:`ERR_NOT_JSON` for a file that is not valid JSON, or
|
|
59
|
+
:data:`ERR_MISSING_FILE` when the path is absent. A missing lockfile is
|
|
60
|
+
not a defect -- the user may never have run an installer -- so callers
|
|
61
|
+
report it, they do not invent it.
|
|
62
|
+
"""
|
|
63
|
+
try:
|
|
64
|
+
text = path.read_text(encoding="utf-8")
|
|
65
|
+
except FileNotFoundError:
|
|
66
|
+
return None, ERR_MISSING_FILE
|
|
67
|
+
except PermissionError:
|
|
68
|
+
return None, ERR_PERMISSION_DENIED
|
|
69
|
+
except OSError as exc:
|
|
70
|
+
# A symlink to a target we cannot open surfaces as ENOENT/EACCES here;
|
|
71
|
+
# both mean "there is content we cannot read", not "there is no file".
|
|
72
|
+
if exc.errno in _PERMISSION_ERRNOS:
|
|
73
|
+
return None, ERR_PERMISSION_DENIED
|
|
74
|
+
return None, ERR_NOT_JSON
|
|
75
|
+
try:
|
|
76
|
+
return json.loads(text), None
|
|
77
|
+
except (json.JSONDecodeError, UnicodeDecodeError):
|
|
78
|
+
return None, ERR_NOT_JSON
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def live_discovery(
|
|
82
|
+
cwd: Path | None = None,
|
|
83
|
+
registry: dict[str, AgentDefinition] | None = None,
|
|
84
|
+
) -> DiscoveryIndex:
|
|
85
|
+
"""Run a full discovery pass against the live (or sandboxed) environment.
|
|
86
|
+
|
|
87
|
+
``cwd`` defaults to the terminal folder; the sandbox switch in
|
|
88
|
+
:mod:`skill_lens.core.paths` decides whether "live" means the real
|
|
89
|
+
``$HOME`` or a mock one, so this is the single entry point both ``doctor``
|
|
90
|
+
and ``compare`` use. All OSError guarding lives in the walk it delegates
|
|
91
|
+
to -- one unreadable directory produces a tagged
|
|
92
|
+
:class:`~skill_lens.core.discovery.UnreadableRoot`, not a traceback.
|
|
93
|
+
"""
|
|
94
|
+
home = paths.home()
|
|
95
|
+
working_dir = cwd if cwd is not None else paths.terminal_cwd()
|
|
96
|
+
return discover(home, working_dir, registry)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""Frozen, machine-readable data contracts for Skill Lens.
|
|
2
|
+
|
|
3
|
+
Presentation (Rich) is always a layer on top of these models -- never the
|
|
4
|
+
other way around.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from typing import Any
|
|
11
|
+
|
|
12
|
+
from skill_lens.models.compare import CompareEntry, CompareReport
|
|
13
|
+
from skill_lens.models.diff import (
|
|
14
|
+
DiffChange,
|
|
15
|
+
DiffCopy,
|
|
16
|
+
DiffFile,
|
|
17
|
+
DiffHunk,
|
|
18
|
+
DiffReport,
|
|
19
|
+
)
|
|
20
|
+
from skill_lens.models.doctor import DoctorFinding, DoctorReport
|
|
21
|
+
from skill_lens.models.enums import (
|
|
22
|
+
Collision,
|
|
23
|
+
CompareRelation,
|
|
24
|
+
Evidence,
|
|
25
|
+
HeadlineState,
|
|
26
|
+
ParseStatus,
|
|
27
|
+
Scope,
|
|
28
|
+
Severity,
|
|
29
|
+
Visibility,
|
|
30
|
+
)
|
|
31
|
+
from skill_lens.models.installation import SkillInstallation
|
|
32
|
+
from skill_lens.models.parsing import (
|
|
33
|
+
CanonicalResult,
|
|
34
|
+
CanonicalStatus,
|
|
35
|
+
ParseResult,
|
|
36
|
+
)
|
|
37
|
+
from skill_lens.models.resolution import CandidateResolution, ResolutionReport
|
|
38
|
+
|
|
39
|
+
__all__ = [
|
|
40
|
+
"CandidateResolution",
|
|
41
|
+
"CanonicalResult",
|
|
42
|
+
"CanonicalStatus",
|
|
43
|
+
"Collision",
|
|
44
|
+
"CompareEntry",
|
|
45
|
+
"CompareRelation",
|
|
46
|
+
"CompareReport",
|
|
47
|
+
"DiffChange",
|
|
48
|
+
"DiffCopy",
|
|
49
|
+
"DiffFile",
|
|
50
|
+
"DiffHunk",
|
|
51
|
+
"DiffReport",
|
|
52
|
+
"DoctorFinding",
|
|
53
|
+
"DoctorReport",
|
|
54
|
+
"Evidence",
|
|
55
|
+
"HeadlineState",
|
|
56
|
+
"ParseResult",
|
|
57
|
+
"ParseStatus",
|
|
58
|
+
"ResolutionReport",
|
|
59
|
+
"Scope",
|
|
60
|
+
"Severity",
|
|
61
|
+
"SkillInstallation",
|
|
62
|
+
"Visibility",
|
|
63
|
+
"dumps",
|
|
64
|
+
]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def dumps(value: Any) -> str:
|
|
68
|
+
"""Serialize a model (or container of models) to canonical JSON.
|
|
69
|
+
|
|
70
|
+
Uses ``sort_keys=True`` so output is byte-stable and directly comparable
|
|
71
|
+
against golden ``expected.json`` fixtures.
|
|
72
|
+
"""
|
|
73
|
+
return json.dumps(value, sort_keys=True, indent=2)
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Comparison model emitted by ``skill-lens compare --agent A --agent B``."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from skill_lens.models.enums import CompareRelation
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True)
|
|
12
|
+
class CompareEntry:
|
|
13
|
+
"""One skill name and how it sits between exactly two agents.
|
|
14
|
+
|
|
15
|
+
``path_a`` / ``path_b`` are the entrypoint paths each agent actually
|
|
16
|
+
sees -- under a symlink farm those differ even when the library is one.
|
|
17
|
+
``canonical_a`` / ``canonical_b`` are the resolved targets: equal
|
|
18
|
+
canonicals is what makes the relation ``shared`` rather than merely
|
|
19
|
+
"the same name twice". A relation that leaves one agent without the
|
|
20
|
+
name stores ``None`` on that agent's side.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
name: str
|
|
24
|
+
relation: CompareRelation
|
|
25
|
+
path_a: str | None = None
|
|
26
|
+
path_b: str | None = None
|
|
27
|
+
canonical_a: str | None = None
|
|
28
|
+
canonical_b: str | None = None
|
|
29
|
+
|
|
30
|
+
def to_dict(self) -> dict[str, Any]:
|
|
31
|
+
return {
|
|
32
|
+
"name": self.name,
|
|
33
|
+
"relation": self.relation.value,
|
|
34
|
+
"path_a": self.path_a,
|
|
35
|
+
"path_b": self.path_b,
|
|
36
|
+
"canonical_a": self.canonical_a,
|
|
37
|
+
"canonical_b": self.canonical_b,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
@classmethod
|
|
41
|
+
def from_dict(cls, data: dict[str, Any]) -> CompareEntry:
|
|
42
|
+
return cls(
|
|
43
|
+
name=data["name"],
|
|
44
|
+
relation=CompareRelation(data["relation"]),
|
|
45
|
+
path_a=data.get("path_a"),
|
|
46
|
+
path_b=data.get("path_b"),
|
|
47
|
+
canonical_a=data.get("canonical_a"),
|
|
48
|
+
canonical_b=data.get("canonical_b"),
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@dataclass(frozen=True, slots=True)
|
|
53
|
+
class CompareReport:
|
|
54
|
+
"""The complete answer for one pairwise capability comparison.
|
|
55
|
+
|
|
56
|
+
``agent_a`` / ``agent_b`` are the registry ids used on the command line
|
|
57
|
+
and decide which side of every entry the ``*_a`` fields belong to. An
|
|
58
|
+
empty ``entries`` tuple means the two agents share no skill names and
|
|
59
|
+
neither has any of its own -- a fact, not an error (exit code ``0``).
|
|
60
|
+
|
|
61
|
+
The counts are derived views of ``entries`` (same rule as
|
|
62
|
+
``DiffReport.has_differences``): never serialized, never able to drift.
|
|
63
|
+
"""
|
|
64
|
+
|
|
65
|
+
agent_a: str
|
|
66
|
+
agent_b: str
|
|
67
|
+
agent_a_name: str
|
|
68
|
+
agent_b_name: str
|
|
69
|
+
home: str
|
|
70
|
+
cwd: str
|
|
71
|
+
entries: tuple[CompareEntry, ...] = ()
|
|
72
|
+
notes: tuple[str, ...] = ()
|
|
73
|
+
|
|
74
|
+
def counts_by_relation(self) -> dict[str, int]:
|
|
75
|
+
"""Relation -> entry count (all four keys present)."""
|
|
76
|
+
counts = {relation.value: 0 for relation in CompareRelation}
|
|
77
|
+
for entry in self.entries:
|
|
78
|
+
counts[entry.relation.value] += 1
|
|
79
|
+
return counts
|
|
80
|
+
|
|
81
|
+
def to_dict(self) -> dict[str, Any]:
|
|
82
|
+
return {
|
|
83
|
+
"agent_a": self.agent_a,
|
|
84
|
+
"agent_b": self.agent_b,
|
|
85
|
+
"agent_a_name": self.agent_a_name,
|
|
86
|
+
"agent_b_name": self.agent_b_name,
|
|
87
|
+
"home": self.home,
|
|
88
|
+
"cwd": self.cwd,
|
|
89
|
+
"entries": [entry.to_dict() for entry in self.entries],
|
|
90
|
+
"notes": list(self.notes),
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@classmethod
|
|
94
|
+
def from_dict(cls, data: dict[str, Any]) -> CompareReport:
|
|
95
|
+
return cls(
|
|
96
|
+
agent_a=data["agent_a"],
|
|
97
|
+
agent_b=data["agent_b"],
|
|
98
|
+
agent_a_name=data["agent_a_name"],
|
|
99
|
+
agent_b_name=data["agent_b_name"],
|
|
100
|
+
home=data["home"],
|
|
101
|
+
cwd=data["cwd"],
|
|
102
|
+
entries=tuple(CompareEntry.from_dict(entry) for entry in data.get("entries", ())),
|
|
103
|
+
notes=tuple(data.get("notes", ())),
|
|
104
|
+
)
|