1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
//! Enumerate the skills a source directory offers, in either supported layout.
//!
//! Why (#4949): the deployer and the tier planner each decide "what is a skill
//! here?" and both decided it with `entry.file_type()?.is_file() &&
//! is_skill_file(name)` — a flat `<stem>.md` at the source root, and nothing
//! else. A directory-shaped skill (`<stem>/SKILL.md` plus whatever it carries)
//! failed that `is_file()` test and was dropped with no warning on every
//! deploy: `deploy_skills_filtered` reported success having never seen it.
//! Bundled skills escaped the bug only because they ship a HYBRID layout — a
//! flat `tm-capabilities.md` entry point beside a `tm-capabilities/references/`
//! companion directory — so the entry point still satisfied `is_file()` and the
//! companion directory was reached afterwards, keyed off the stem. There was no
//! working directory-skill path to route the user tier through; both tiers read
//! the same blind scan. Two real user skills sat hidden behind it for weeks:
//! a design-system skill and a knowledge-base ingest skill.
//!
//! What: [`scan_skill_sources`] returns one [`SourceSkill`] per skill in
//! `source`, accepting BOTH layouts, plus the names it had to reject so the
//! caller can report them instead of dropping them. Every non-hidden file a
//! skill's companion directory carries — `metadata.json`, `references/**`,
//! `scripts/**`, at any depth — travels with it as an [`SourceExtra`], keyed
//! `<stem>/<relative-path>`. That key scheme is byte-identical to the
//! `<stem>/references/<file>` keys the previous reference-mirroring code wrote,
//! so existing manifests keep matching and no skill re-deploys spuriously.
//! This module is the ONE place that answers the question, per this repo's
//! common-entry-point rule; [`crate::skills::deployer`] and
//! [`crate::skills::tiers`] both call it rather than re-deriving it.
//!
//! Test: `scan_finds_directory_shaped_skill`, `scan_finds_flat_skill`,
//! `scan_companion_dir_is_not_a_reject`, `scan_rejects_dir_without_skill_md`,
//! `scan_ignores_hidden_entries`, `scan_extras_are_recursive_and_sorted`.
use BTreeMap;
use ;
use crateResult;
use crate;
/// One extra file a skill carries alongside its entry point.
///
/// Why: the manifest keys every managed file individually, so each companion
/// file needs a stable relative identity independent of the absolute source
/// path it was read from.
/// What: `rel` is the `/`-joined path below the skill's own directory (e.g.
/// `references/design-tokens.md`, `scripts/ingest.sh`); `path` is where to read
/// it from.
/// Test: `scan_extras_are_recursive_and_sorted`.
/// One deployable skill discovered in a source directory.
///
/// Why: the deployer needs the entry-point content and the carried files as one
/// unit so a multi-file skill cannot half-deploy, and the tier planner needs the
/// stem from the identical scan so it never greenlights a stem the deployer
/// then rejects (the drift PR #2818's review already caught once).
/// What: the skill name, the file whose content becomes `<dest>/<stem>/SKILL.md`,
/// and every extra file it carries.
/// Test: `scan_finds_directory_shaped_skill`, `scan_finds_flat_skill`.
/// Everything one source directory offers, including what it could not offer.
///
/// Why (#4949): a name this scan cannot turn into a skill must reach the
/// caller. Returning only the successes is what made the original defect
/// invisible — there was no channel for "I saw this and could not use it".
/// What: the usable skills, sorted by stem, plus the rejected directory names,
/// sorted.
/// Test: `scan_rejects_dir_without_skill_md`.
/// Whether a directory entry name is hidden and must be ignored.
///
/// Why: `.git`, `.DS_Store`, and editor sidecars live beside real content and
/// must never be deployed or reported as a malformed skill.
/// What: true when the name starts with `.`.
/// Test: `scan_ignores_hidden_entries`.
/// Enumerate the skills in `source`, accepting both supported layouts.
///
/// Why: see the module doc — one shared answer to "what is a skill here?",
/// covering the directory shape that #4949 dropped silently.
/// What: a flat `<stem>.md` file is a skill whose entry point is that file. A
/// non-hidden subdirectory containing `SKILL.md` is a skill whose entry point
/// is that `SKILL.md`. Either way, every non-hidden file under `<source>/<stem>/`
/// (except a directory skill's own `SKILL.md`) is carried as an extra. A
/// subdirectory that merely accompanies a flat skill of the same name is the
/// hybrid bundled layout, NOT a malformed skill, and is never rejected — every
/// bundled skill would otherwise warn on every deploy. Any other non-hidden
/// subdirectory without a `SKILL.md` is returned in `rejected`. A missing
/// `source` yields an empty scan; errors reading an existing directory
/// propagate.
/// Test: `scan_finds_directory_shaped_skill`, `scan_finds_flat_skill`,
/// `scan_companion_dir_is_not_a_reject`, `scan_rejects_dir_without_skill_md`.
/// Collect every non-hidden file under `dir`, recursively.
///
/// Why: a skill's carried files are not limited to `references/*.md` — the two
/// skills #4949 hid between them ship `metadata.json`, four `references/*.md`
/// docs, and a `scripts/ingest.sh`. Filtering to `.md` here would fix the
/// `is_file()` half of the defect and leave a second silent-drop in its place.
/// What: walks `dir` depth-first, returning `/`-joined relative paths and their
/// source paths, skipping hidden entries at every level and `skip_root` (a
/// directory skill's own entry point) at the top. A missing `dir` yields an
/// empty vector. Results are sorted by `rel`.
/// Test: `scan_extras_are_recursive_and_sorted`, `scan_ignores_hidden_entries`.
/// Recursive worker for [`collect_extras`].
///
/// Why: split out so the public helper owns the sort and the caller never has
/// to thread a prefix through.
/// What: appends each non-hidden file below `dir` to `out`, prefixing its name
/// with `prefix`. Errors reading an existing directory propagate.
/// Test: via [`collect_extras`]'s tests.