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,231 @@
|
|
|
1
|
+
"""Data contracts for ``skill-lens diff`` (Phase 3).
|
|
2
|
+
|
|
3
|
+
A diff is built from a :class:`~skill_lens.core.discovery.DiscoveryIndex`, whose
|
|
4
|
+
entries are already deduplicated by canonical target. A "copy" here is therefore
|
|
5
|
+
one *canonical* skill on disk: a symlink farm is one copy reached through N
|
|
6
|
+
entrypoints, and two symlinks onto the same target can never produce a diff.
|
|
7
|
+
|
|
8
|
+
These dataclasses are the contract. The Rich renderer is a layer on top of them
|
|
9
|
+
and never recomputes anything (AGENTS.md rule 4).
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
from dataclasses import dataclass
|
|
15
|
+
from enum import StrEnum
|
|
16
|
+
from typing import Any
|
|
17
|
+
|
|
18
|
+
from skill_lens.models.enums import Scope
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class DiffChange(StrEnum):
|
|
22
|
+
"""How one file differs between the baseline copy and another copy."""
|
|
23
|
+
|
|
24
|
+
ADDED = "added"
|
|
25
|
+
REMOVED = "removed"
|
|
26
|
+
MODIFIED = "modified"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@dataclass(frozen=True, slots=True)
|
|
30
|
+
class DiffHunk:
|
|
31
|
+
"""One unified-diff hunk.
|
|
32
|
+
|
|
33
|
+
``old_start`` / ``old_count`` / ``new_start`` / ``new_count`` are stored
|
|
34
|
+
exactly as a unified header spells them (``@@ -old_start,old_count
|
|
35
|
+
+new_start,new_count @@``), including the standard convention that a
|
|
36
|
+
zero-length range names the line *before* it.
|
|
37
|
+
|
|
38
|
+
``lines`` holds the body lines with their leading marker: ``" "`` for
|
|
39
|
+
context, ``"-"`` for a line only the baseline has, ``"+"`` for a line only
|
|
40
|
+
the other copy has. Storing the marker means the renderer can print the
|
|
41
|
+
hunk without recomputing the diff.
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
old_start: int
|
|
45
|
+
old_count: int
|
|
46
|
+
new_start: int
|
|
47
|
+
new_count: int
|
|
48
|
+
lines: tuple[str, ...] = ()
|
|
49
|
+
|
|
50
|
+
def to_dict(self) -> dict[str, Any]:
|
|
51
|
+
return {
|
|
52
|
+
"old_start": self.old_start,
|
|
53
|
+
"old_count": self.old_count,
|
|
54
|
+
"new_start": self.new_start,
|
|
55
|
+
"new_count": self.new_count,
|
|
56
|
+
"lines": list(self.lines),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_dict(cls, data: dict[str, Any]) -> DiffHunk:
|
|
61
|
+
return cls(
|
|
62
|
+
old_start=int(data["old_start"]),
|
|
63
|
+
old_count=int(data["old_count"]),
|
|
64
|
+
new_start=int(data["new_start"]),
|
|
65
|
+
new_count=int(data["new_count"]),
|
|
66
|
+
lines=tuple(data.get("lines", ())),
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
@dataclass(frozen=True, slots=True)
|
|
71
|
+
class DiffFile:
|
|
72
|
+
"""One file that differs between the baseline copy and another copy.
|
|
73
|
+
|
|
74
|
+
Only files that genuinely differ appear here; an unchanged file is absent
|
|
75
|
+
rather than listed with an empty hunk list. ``is_binary`` marks a file whose
|
|
76
|
+
content is never printed -- the specification reports it as differing and
|
|
77
|
+
stops there. A file that exists on one side only is ``added`` or ``removed``,
|
|
78
|
+
which is also how a rename shows up, because files are matched by relative
|
|
79
|
+
path.
|
|
80
|
+
"""
|
|
81
|
+
|
|
82
|
+
path: str
|
|
83
|
+
change: DiffChange
|
|
84
|
+
is_binary: bool = False
|
|
85
|
+
hunks: tuple[DiffHunk, ...] = ()
|
|
86
|
+
|
|
87
|
+
def to_dict(self) -> dict[str, Any]:
|
|
88
|
+
return {
|
|
89
|
+
"path": self.path,
|
|
90
|
+
"change": self.change.value,
|
|
91
|
+
"is_binary": self.is_binary,
|
|
92
|
+
"hunks": [hunk.to_dict() for hunk in self.hunks],
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@classmethod
|
|
96
|
+
def from_dict(cls, data: dict[str, Any]) -> DiffFile:
|
|
97
|
+
return cls(
|
|
98
|
+
path=data["path"],
|
|
99
|
+
change=DiffChange(data["change"]),
|
|
100
|
+
is_binary=bool(data.get("is_binary", False)),
|
|
101
|
+
hunks=tuple(DiffHunk.from_dict(hunk) for hunk in data.get("hunks", ())),
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
@dataclass(frozen=True, slots=True)
|
|
106
|
+
class DiffCopy:
|
|
107
|
+
"""One copy of a skill name, as it takes part in a diff.
|
|
108
|
+
|
|
109
|
+
``is_readable`` separates a copy that has content to compare from one that
|
|
110
|
+
cannot be read at all -- a dangling symlink, a symlink cycle, a
|
|
111
|
+
permission-denied root. An unreadable copy is still listed (it is a real
|
|
112
|
+
finding) but carries the machine-checkable ``error`` code instead of files.
|
|
113
|
+
|
|
114
|
+
``variant_label`` is ``None`` for a copy that failed frontmatter validation:
|
|
115
|
+
only the valid set receives a Variant letter, so the letters here always
|
|
116
|
+
agree with ``scan`` and ``why``. A copy whose bytes match the baseline has an
|
|
117
|
+
empty ``files`` tuple -- identical content is not a difference.
|
|
118
|
+
|
|
119
|
+
``truncated`` / ``omitted_lines`` describe this copy alone: how much of its
|
|
120
|
+
diff was dropped to stay inside the per-copy changed-line budget.
|
|
121
|
+
"""
|
|
122
|
+
|
|
123
|
+
path: str
|
|
124
|
+
scope: Scope
|
|
125
|
+
parse_status: str
|
|
126
|
+
is_valid: bool
|
|
127
|
+
is_readable: bool
|
|
128
|
+
is_baseline: bool = False
|
|
129
|
+
variant_label: str | None = None
|
|
130
|
+
content_hash: str | None = None
|
|
131
|
+
error: str | None = None
|
|
132
|
+
files: tuple[DiffFile, ...] = ()
|
|
133
|
+
truncated: bool = False
|
|
134
|
+
omitted_lines: int = 0
|
|
135
|
+
|
|
136
|
+
def to_dict(self) -> dict[str, Any]:
|
|
137
|
+
return {
|
|
138
|
+
"path": self.path,
|
|
139
|
+
"scope": self.scope.value,
|
|
140
|
+
"parse_status": self.parse_status,
|
|
141
|
+
"is_valid": self.is_valid,
|
|
142
|
+
"is_readable": self.is_readable,
|
|
143
|
+
"is_baseline": self.is_baseline,
|
|
144
|
+
"variant_label": self.variant_label,
|
|
145
|
+
"content_hash": self.content_hash,
|
|
146
|
+
"error": self.error,
|
|
147
|
+
"files": [file.to_dict() for file in self.files],
|
|
148
|
+
"truncated": self.truncated,
|
|
149
|
+
"omitted_lines": self.omitted_lines,
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@classmethod
|
|
153
|
+
def from_dict(cls, data: dict[str, Any]) -> DiffCopy:
|
|
154
|
+
return cls(
|
|
155
|
+
path=data["path"],
|
|
156
|
+
scope=Scope(data["scope"]),
|
|
157
|
+
parse_status=data["parse_status"],
|
|
158
|
+
is_valid=bool(data["is_valid"]),
|
|
159
|
+
is_readable=bool(data["is_readable"]),
|
|
160
|
+
is_baseline=bool(data.get("is_baseline", False)),
|
|
161
|
+
variant_label=data.get("variant_label"),
|
|
162
|
+
content_hash=data.get("content_hash"),
|
|
163
|
+
error=data.get("error"),
|
|
164
|
+
files=tuple(DiffFile.from_dict(file) for file in data.get("files", ())),
|
|
165
|
+
truncated=bool(data.get("truncated", False)),
|
|
166
|
+
omitted_lines=int(data.get("omitted_lines", 0)),
|
|
167
|
+
)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
@dataclass(frozen=True, slots=True)
|
|
171
|
+
class DiffReport:
|
|
172
|
+
"""The complete answer for ``skill-lens diff <name>``.
|
|
173
|
+
|
|
174
|
+
``found=False`` means the name exists nowhere on disk. That is a fact, not an
|
|
175
|
+
error: like ``why``, ``diff`` reports it and exits ``0`` (finding F-10).
|
|
176
|
+
|
|
177
|
+
``baseline_path`` is the copy every other copy is compared against -- the one
|
|
178
|
+
``discovery.variant_labels`` calls Variant A. It is ``None`` when no copy
|
|
179
|
+
passed validation, because an invalid copy is never the baseline; ``notes``
|
|
180
|
+
then says so rather than inventing a reference.
|
|
181
|
+
|
|
182
|
+
``omitted_chars`` counts the characters of diff body that were dropped to
|
|
183
|
+
stay inside the report-wide character budget, so the terminal can state how
|
|
184
|
+
much was left out.
|
|
185
|
+
"""
|
|
186
|
+
|
|
187
|
+
skill_name: str
|
|
188
|
+
home: str
|
|
189
|
+
cwd: str
|
|
190
|
+
found: bool
|
|
191
|
+
baseline_path: str | None = None
|
|
192
|
+
copies: tuple[DiffCopy, ...] = ()
|
|
193
|
+
truncated: bool = False
|
|
194
|
+
omitted_chars: int = 0
|
|
195
|
+
notes: tuple[str, ...] = ()
|
|
196
|
+
|
|
197
|
+
@property
|
|
198
|
+
def has_differences(self) -> bool:
|
|
199
|
+
"""True when any copy differs from the baseline.
|
|
200
|
+
|
|
201
|
+
Derived, never serialized: it is a view of ``copies``, not a fact the
|
|
202
|
+
computation has to keep in sync.
|
|
203
|
+
"""
|
|
204
|
+
return any(copy.files for copy in self.copies)
|
|
205
|
+
|
|
206
|
+
def to_dict(self) -> dict[str, Any]:
|
|
207
|
+
return {
|
|
208
|
+
"skill_name": self.skill_name,
|
|
209
|
+
"home": self.home,
|
|
210
|
+
"cwd": self.cwd,
|
|
211
|
+
"found": self.found,
|
|
212
|
+
"baseline_path": self.baseline_path,
|
|
213
|
+
"copies": [copy.to_dict() for copy in self.copies],
|
|
214
|
+
"truncated": self.truncated,
|
|
215
|
+
"omitted_chars": self.omitted_chars,
|
|
216
|
+
"notes": list(self.notes),
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
@classmethod
|
|
220
|
+
def from_dict(cls, data: dict[str, Any]) -> DiffReport:
|
|
221
|
+
return cls(
|
|
222
|
+
skill_name=data["skill_name"],
|
|
223
|
+
home=data["home"],
|
|
224
|
+
cwd=data["cwd"],
|
|
225
|
+
found=bool(data["found"]),
|
|
226
|
+
baseline_path=data.get("baseline_path"),
|
|
227
|
+
copies=tuple(DiffCopy.from_dict(copy) for copy in data.get("copies", ())),
|
|
228
|
+
truncated=bool(data.get("truncated", False)),
|
|
229
|
+
omitted_chars=int(data.get("omitted_chars", 0)),
|
|
230
|
+
notes=tuple(data.get("notes", ())),
|
|
231
|
+
)
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
"""Diagnostics model emitted by ``skill-lens doctor``."""
|
|
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 Evidence, Severity
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True)
|
|
12
|
+
class DoctorFinding:
|
|
13
|
+
"""A single hygiene or ecosystem-health finding.
|
|
14
|
+
|
|
15
|
+
Findings are informational only: Skill Lens never repairs anything.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
code: str
|
|
19
|
+
severity: Severity
|
|
20
|
+
message: str
|
|
21
|
+
rule_id: str
|
|
22
|
+
evidence: Evidence
|
|
23
|
+
path: str | None = None
|
|
24
|
+
detail: str | None = None
|
|
25
|
+
|
|
26
|
+
def to_dict(self) -> dict[str, Any]:
|
|
27
|
+
return {
|
|
28
|
+
"code": self.code,
|
|
29
|
+
"severity": self.severity.value,
|
|
30
|
+
"message": self.message,
|
|
31
|
+
"rule_id": self.rule_id,
|
|
32
|
+
"evidence": self.evidence.value,
|
|
33
|
+
"path": self.path,
|
|
34
|
+
"detail": self.detail,
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@classmethod
|
|
38
|
+
def from_dict(cls, data: dict[str, Any]) -> DoctorFinding:
|
|
39
|
+
return cls(
|
|
40
|
+
code=data["code"],
|
|
41
|
+
severity=Severity(data["severity"]),
|
|
42
|
+
message=data["message"],
|
|
43
|
+
rule_id=data["rule_id"],
|
|
44
|
+
evidence=Evidence(data["evidence"]),
|
|
45
|
+
path=data.get("path"),
|
|
46
|
+
detail=data.get("detail"),
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
@dataclass(frozen=True, slots=True)
|
|
51
|
+
class DoctorReport:
|
|
52
|
+
"""The complete answer for ``skill-lens doctor``.
|
|
53
|
+
|
|
54
|
+
An empty ``findings`` tuple is a clean bill of health, not an error: like
|
|
55
|
+
every other command, ``doctor`` exits ``0`` when it ran successfully.
|
|
56
|
+
``home`` and ``cwd`` record what was inspected so a report is traceable to
|
|
57
|
+
the exact filesystem state that produced it.
|
|
58
|
+
|
|
59
|
+
``healthy`` is derived from the findings -- it is a view, never a stored
|
|
60
|
+
fact the computation has to keep in sync (the same rule ``DiffReport``
|
|
61
|
+
follows for ``has_differences``).
|
|
62
|
+
"""
|
|
63
|
+
|
|
64
|
+
home: str
|
|
65
|
+
cwd: str
|
|
66
|
+
findings: tuple[DoctorFinding, ...] = ()
|
|
67
|
+
|
|
68
|
+
@property
|
|
69
|
+
def healthy(self) -> bool:
|
|
70
|
+
"""True when nothing rose above an informational note.
|
|
71
|
+
|
|
72
|
+
Derived, never serialized.
|
|
73
|
+
"""
|
|
74
|
+
return not any(finding.severity is not Severity.INFO for finding in self.findings)
|
|
75
|
+
|
|
76
|
+
def counts_by_severity(self) -> dict[str, int]:
|
|
77
|
+
"""Severity -> number of findings at that level (all three keys present)."""
|
|
78
|
+
counts = {severity.value: 0 for severity in Severity}
|
|
79
|
+
for finding in self.findings:
|
|
80
|
+
counts[finding.severity.value] += 1
|
|
81
|
+
return counts
|
|
82
|
+
|
|
83
|
+
def to_dict(self) -> dict[str, Any]:
|
|
84
|
+
return {
|
|
85
|
+
"home": self.home,
|
|
86
|
+
"cwd": self.cwd,
|
|
87
|
+
"findings": [finding.to_dict() for finding in self.findings],
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
@classmethod
|
|
91
|
+
def from_dict(cls, data: dict[str, Any]) -> DoctorReport:
|
|
92
|
+
return cls(
|
|
93
|
+
home=data["home"],
|
|
94
|
+
cwd=data["cwd"],
|
|
95
|
+
findings=tuple(
|
|
96
|
+
DoctorFinding.from_dict(finding) for finding in data.get("findings", ())
|
|
97
|
+
),
|
|
98
|
+
)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""Enumerations for the Skill Lens 3-axis resolution model.
|
|
2
|
+
|
|
3
|
+
All enums subclass ``enum.StrEnum`` (Python 3.11+), so members serialize
|
|
4
|
+
cleanly to JSON and compare equal to their plain-string values.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from enum import StrEnum
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Scope(StrEnum):
|
|
13
|
+
"""Where a skill installation lives in the capability hierarchy."""
|
|
14
|
+
|
|
15
|
+
USER = "user"
|
|
16
|
+
PROJECT = "project"
|
|
17
|
+
SYSTEM = "system"
|
|
18
|
+
PLUGIN = "plugin"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class ParseStatus(StrEnum):
|
|
22
|
+
"""Outcome of parsing a skill's frontmatter (axis 1)."""
|
|
23
|
+
|
|
24
|
+
VALID = "valid"
|
|
25
|
+
MALFORMED_YAML = "malformed_yaml"
|
|
26
|
+
MISSING_DESCRIPTION = "missing_description"
|
|
27
|
+
UNREADABLE = "unreadable"
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Visibility(StrEnum):
|
|
31
|
+
"""Whether the agent's search rules can see this installation (axis 2)."""
|
|
32
|
+
|
|
33
|
+
ACTIVE_ROOT = "active_root"
|
|
34
|
+
UNSEARCHED_ROOT = "unsearched_root"
|
|
35
|
+
OUTSIDE_WALK_BOUNDARY = "outside_walk_boundary"
|
|
36
|
+
DISABLED = "disabled"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
class Collision(StrEnum):
|
|
40
|
+
"""How this installation behaves relative to same-named copies (axis 3)."""
|
|
41
|
+
|
|
42
|
+
WINNING_ENTRY = "winning_entry"
|
|
43
|
+
SUPPRESSED_SHADOW = "suppressed_shadow"
|
|
44
|
+
COEXISTING_MERGED = "coexisting_merged"
|
|
45
|
+
QUALIFIED_NAMESPACE = "qualified_namespace"
|
|
46
|
+
AMBIGUOUS_TIE = "ambiguous_tie"
|
|
47
|
+
UNVERIFIED_POLICY = "unverified_policy"
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class HeadlineState(StrEnum):
|
|
51
|
+
"""Derived headline state surfaced by ``skill-lens why``."""
|
|
52
|
+
|
|
53
|
+
ACTIVE = "ACTIVE"
|
|
54
|
+
SHADOWED = "SHADOWED"
|
|
55
|
+
COEXISTS = "COEXISTS"
|
|
56
|
+
DISABLED = "DISABLED"
|
|
57
|
+
UNSEARCHED = "UNSEARCHED"
|
|
58
|
+
INVALID = "INVALID"
|
|
59
|
+
AMBIGUOUS = "AMBIGUOUS"
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Evidence(StrEnum):
|
|
63
|
+
"""Provenance level backing a rule. Never guess: see AGENTS.md rule 6."""
|
|
64
|
+
|
|
65
|
+
DOCUMENTED = "documented"
|
|
66
|
+
EMPIRICAL = "empirical"
|
|
67
|
+
INFERRED = "inferred"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class Severity(StrEnum):
|
|
71
|
+
"""Severity of a ``doctor`` finding."""
|
|
72
|
+
|
|
73
|
+
ERROR = "error"
|
|
74
|
+
WARNING = "warning"
|
|
75
|
+
INFO = "info"
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
class CompareRelation(StrEnum):
|
|
79
|
+
"""How one skill name sits between two agents (``skill-lens compare``)."""
|
|
80
|
+
|
|
81
|
+
SHARED = "shared"
|
|
82
|
+
DIVERGED = "diverged"
|
|
83
|
+
ONLY_A = "only_a"
|
|
84
|
+
ONLY_B = "only_b"
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""The physical side of the model: a discovered skill installation on disk."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from skill_lens.models.enums import ParseStatus, Scope
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@dataclass(frozen=True, slots=True)
|
|
12
|
+
class SkillInstallation:
|
|
13
|
+
"""A single physical installation of a skill (a directory or standalone file).
|
|
14
|
+
|
|
15
|
+
Identity is deliberately split in two, per the specification (section 4):
|
|
16
|
+
|
|
17
|
+
* ``entrypoint_path`` is the path *this agent* resolves -- a project symlink
|
|
18
|
+
wins project precedence -- and is always a real path on disk;
|
|
19
|
+
* ``canonical_path`` is the real target used for inventory deduplication.
|
|
20
|
+
|
|
21
|
+
``agent_entrypoints`` holds **entrypoint paths**, never agent ids: every path
|
|
22
|
+
on disk that reaches this canonical library, so a symlink farm reports one
|
|
23
|
+
library with N entrypoints rather than N duplicate installations.
|
|
24
|
+
|
|
25
|
+
``variant_label`` is ``"A"``/``"B"``/... for copies of one name whose bytes
|
|
26
|
+
differ, ordered so ``"A"`` is the copy the agent will actually run. It is
|
|
27
|
+
``None`` when the copies are byte-identical or there is only one.
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
name: str
|
|
31
|
+
entrypoint_path: str
|
|
32
|
+
canonical_path: str
|
|
33
|
+
scope: Scope
|
|
34
|
+
parse_status: ParseStatus
|
|
35
|
+
content_hash: str | None = None
|
|
36
|
+
description: str | None = None
|
|
37
|
+
frontmatter_name: str | None = None
|
|
38
|
+
is_symlink: bool = False
|
|
39
|
+
agent_entrypoints: tuple[str, ...] = field(default_factory=tuple)
|
|
40
|
+
variant_label: str | None = None
|
|
41
|
+
errors: tuple[str, ...] = field(default_factory=tuple)
|
|
42
|
+
|
|
43
|
+
def to_dict(self) -> dict[str, Any]:
|
|
44
|
+
return {
|
|
45
|
+
"name": self.name,
|
|
46
|
+
"entrypoint_path": self.entrypoint_path,
|
|
47
|
+
"canonical_path": self.canonical_path,
|
|
48
|
+
"scope": self.scope.value,
|
|
49
|
+
"parse_status": self.parse_status.value,
|
|
50
|
+
"content_hash": self.content_hash,
|
|
51
|
+
"description": self.description,
|
|
52
|
+
"frontmatter_name": self.frontmatter_name,
|
|
53
|
+
"is_symlink": self.is_symlink,
|
|
54
|
+
"agent_entrypoints": list(self.agent_entrypoints),
|
|
55
|
+
"variant_label": self.variant_label,
|
|
56
|
+
"errors": list(self.errors),
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@classmethod
|
|
60
|
+
def from_dict(cls, data: dict[str, Any]) -> SkillInstallation:
|
|
61
|
+
return cls(
|
|
62
|
+
name=data["name"],
|
|
63
|
+
entrypoint_path=data["entrypoint_path"],
|
|
64
|
+
canonical_path=data["canonical_path"],
|
|
65
|
+
scope=Scope(data["scope"]),
|
|
66
|
+
parse_status=ParseStatus(data["parse_status"]),
|
|
67
|
+
content_hash=data.get("content_hash"),
|
|
68
|
+
description=data.get("description"),
|
|
69
|
+
frontmatter_name=data.get("frontmatter_name"),
|
|
70
|
+
is_symlink=bool(data.get("is_symlink", False)),
|
|
71
|
+
agent_entrypoints=tuple(data.get("agent_entrypoints", ())),
|
|
72
|
+
variant_label=data.get("variant_label"),
|
|
73
|
+
errors=tuple(data.get("errors", ())),
|
|
74
|
+
)
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"""Data contracts for parsing and symlink canonicalization (Phase 1)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from enum import StrEnum
|
|
7
|
+
from typing import Any
|
|
8
|
+
|
|
9
|
+
from skill_lens.models.enums import ParseStatus
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class CanonicalStatus(StrEnum):
|
|
13
|
+
"""Outcome of resolving a possibly-symlinked entrypoint to a real path."""
|
|
14
|
+
|
|
15
|
+
OK = "ok"
|
|
16
|
+
BROKEN = "broken"
|
|
17
|
+
CYCLE = "cycle"
|
|
18
|
+
UNREADABLE = "unreadable"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# --- Error codes -----------------------------------------------------------
|
|
22
|
+
# Stable, machine-checkable identifiers. Never embed free-text messages here;
|
|
23
|
+
# the golden fixtures compare against these exact strings.
|
|
24
|
+
ERR_MISSING_FRONTMATTER = "missing_frontmatter"
|
|
25
|
+
ERR_MALFORMED_YAML = "malformed_yaml"
|
|
26
|
+
ERR_MISSING_DESCRIPTION = "missing_description"
|
|
27
|
+
ERR_UNDECODABLE_TEXT = "undecodable_text"
|
|
28
|
+
ERR_SYMLINK_CYCLE = "symlink_cycle"
|
|
29
|
+
ERR_DANGLING_SYMLINK = "dangling_symlink"
|
|
30
|
+
ERR_PERMISSION_DENIED = "permission_denied"
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _jsonable(value: Any) -> Any:
|
|
34
|
+
"""Coerce YAML values into JSON-serializable primitives."""
|
|
35
|
+
if value is None or isinstance(value, (bool, int, float, str)):
|
|
36
|
+
return value
|
|
37
|
+
if isinstance(value, (list, tuple)):
|
|
38
|
+
return [_jsonable(item) for item in value]
|
|
39
|
+
if isinstance(value, dict):
|
|
40
|
+
return {str(key): _jsonable(item) for key, item in value.items()}
|
|
41
|
+
return str(value)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
@dataclass(frozen=True, slots=True)
|
|
45
|
+
class CanonicalResult:
|
|
46
|
+
"""The result of following a symlink chain to its canonical target."""
|
|
47
|
+
|
|
48
|
+
status: CanonicalStatus
|
|
49
|
+
entrypoint_path: str
|
|
50
|
+
resolved_path: str | None
|
|
51
|
+
is_symlink: bool
|
|
52
|
+
error: str | None = None
|
|
53
|
+
|
|
54
|
+
@property
|
|
55
|
+
def is_ok(self) -> bool:
|
|
56
|
+
return self.status is CanonicalStatus.OK
|
|
57
|
+
|
|
58
|
+
def to_dict(self) -> dict[str, Any]:
|
|
59
|
+
return {
|
|
60
|
+
"status": self.status.value,
|
|
61
|
+
"entrypoint_path": self.entrypoint_path,
|
|
62
|
+
"resolved_path": self.resolved_path,
|
|
63
|
+
"is_symlink": self.is_symlink,
|
|
64
|
+
"error": self.error,
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
@dataclass(frozen=True, slots=True)
|
|
69
|
+
class ParseResult:
|
|
70
|
+
"""Everything the parser learned from one skill document.
|
|
71
|
+
|
|
72
|
+
``directory_name`` and ``frontmatter_name`` are kept separate because
|
|
73
|
+
agents disagree on identity: Claude uses the directory name while Codex
|
|
74
|
+
uses the frontmatter ``name``. The resolver picks between them.
|
|
75
|
+
"""
|
|
76
|
+
|
|
77
|
+
status: ParseStatus
|
|
78
|
+
directory_name: str
|
|
79
|
+
body: str
|
|
80
|
+
frontmatter_name: str | None = None
|
|
81
|
+
description: str | None = None
|
|
82
|
+
source_path: str | None = None
|
|
83
|
+
errors: tuple[str, ...] = ()
|
|
84
|
+
frontmatter: dict[str, Any] = field(default_factory=dict, compare=False, hash=False)
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def is_valid(self) -> bool:
|
|
88
|
+
return self.status is ParseStatus.VALID
|
|
89
|
+
|
|
90
|
+
@property
|
|
91
|
+
def identity(self) -> str:
|
|
92
|
+
"""Best-effort display identity (frontmatter name wins when present)."""
|
|
93
|
+
return self.frontmatter_name or self.directory_name
|
|
94
|
+
|
|
95
|
+
def to_dict(self) -> dict[str, Any]:
|
|
96
|
+
return {
|
|
97
|
+
"status": self.status.value,
|
|
98
|
+
"directory_name": self.directory_name,
|
|
99
|
+
"frontmatter_name": self.frontmatter_name,
|
|
100
|
+
"description": self.description,
|
|
101
|
+
"source_path": self.source_path,
|
|
102
|
+
"identity": self.identity,
|
|
103
|
+
"errors": list(self.errors),
|
|
104
|
+
"frontmatter": {key: _jsonable(value) for key, value in self.frontmatter.items()},
|
|
105
|
+
}
|