@rbbtsn0w/adg 0.10.1-dev.pr151.b79dccc → 0.10.1-dev.pr152.b8c43a6

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.
@@ -0,0 +1,50 @@
1
+ import { parseSource } from './source-parser.js';
2
+ const NPM_PREFIX = 'npm:';
3
+ // the SPEC allows git-hosted sources only, not local paths or plain URLs
4
+ const REMOTE_SOURCE_TYPES = new Set(['github', 'gitlab', 'git']);
5
+ function isSkillsFieldEntry(value) {
6
+ if (typeof value === 'string')
7
+ return true;
8
+ if (!value || typeof value !== 'object' || !('source' in value))
9
+ return false;
10
+ if (typeof value.source !== 'string')
11
+ return false;
12
+ const skills = 'skills' in value ? value.skills : undefined;
13
+ const ref = 'ref' in value ? value.ref : undefined;
14
+ return ((skills === undefined ||
15
+ (Array.isArray(skills) && skills.every((s) => typeof s === 'string'))) &&
16
+ (ref === undefined || typeof ref === 'string'));
17
+ }
18
+ /** Parse the entries of `declarer`'s `skills` field. Problems are returned, not thrown. */
19
+ export function parseSkillsField(entries, declarer) {
20
+ const parsed = { npm: [], remote: [], errors: [] };
21
+ for (const raw of entries) {
22
+ if (!isSkillsFieldEntry(raw)) {
23
+ parsed.errors.push(`${declarer}: invalid "skills" entry ${JSON.stringify(raw)}`);
24
+ continue;
25
+ }
26
+ const { source, skills = [], ref } = typeof raw === 'string' ? { source: raw } : raw;
27
+ if (!source.startsWith(NPM_PREFIX)) {
28
+ const remote = parseSource(source);
29
+ if (!REMOTE_SOURCE_TYPES.has(remote.type)) {
30
+ parsed.errors.push(`${declarer}: "${source}" is not a git source`);
31
+ }
32
+ else if (ref !== undefined && remote.ref !== undefined) {
33
+ parsed.errors.push(`${declarer}: "${source}" already has a ref; remove "ref"`);
34
+ }
35
+ else {
36
+ parsed.remote.push({
37
+ parsed: { ...remote, ref: ref ?? remote.ref },
38
+ skills: remote.skillFilter ? [...skills, remote.skillFilter] : skills,
39
+ });
40
+ }
41
+ }
42
+ else if (ref !== undefined) {
43
+ parsed.errors.push(`${declarer}: "ref" cannot be used with "${source}"`);
44
+ }
45
+ else {
46
+ parsed.npm.push({ package: source.slice(NPM_PREFIX.length), skills });
47
+ }
48
+ }
49
+ return parsed;
50
+ }
@@ -14,16 +14,18 @@ const AGENT_PROJECT_SKILL_DIRS = [
14
14
  '.codex/skills',
15
15
  '.commandcode/skills',
16
16
  '.continue/skills',
17
+ '.factory/skills',
17
18
  '.github/skills',
18
19
  '.goose/skills',
19
20
  '.grok/skills',
20
21
  '.iflow/skills',
21
22
  '.junie/skills',
23
+ '.kilo/skills',
22
24
  '.kilocode/skills',
23
25
  '.kimchi/skills',
24
26
  '.kiro/skills',
25
- '.mux/skills',
26
27
  '.minimax/skills',
28
+ '.mux/skills',
27
29
  '.neovate/skills',
28
30
  '.opencode/skills',
29
31
  '.openhands/skills',
@@ -39,12 +41,12 @@ const AGENT_PROJECT_SKILL_DIRS = [
39
41
  function normalizeSkillName(name) {
40
42
  return name.toLowerCase().replace(/[\s_]+/g, '-');
41
43
  }
42
- function warnSkippedSkill(skillMdPath, reason) {
43
- console.warn(`⚠ Skipped ${sanitizeMetadata(skillMdPath)} — ${stripTerminalEscapes(reason)}`);
44
- }
45
44
  function normalizeRelativePath(path) {
46
45
  return path.split(sep).join('/').replace(/\/+/g, '/');
47
46
  }
47
+ function isRecord(value) {
48
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
49
+ }
48
50
  /**
49
51
  * Check if internal skills should be installed.
50
52
  * Internal skills are hidden by default unless INSTALL_INTERNAL_SKILLS=1 is set.
@@ -53,7 +55,7 @@ export function shouldInstallInternalSkills() {
53
55
  const envValue = process.env.INSTALL_INTERNAL_SKILLS;
54
56
  return envValue === '1' || envValue === 'true';
55
57
  }
56
- async function hasSkillMd(dir) {
58
+ export async function hasSkillMd(dir) {
57
59
  try {
58
60
  const skillPath = join(dir, 'SKILL.md');
59
61
  const stats = await stat(skillPath);
@@ -63,44 +65,55 @@ async function hasSkillMd(dir) {
63
65
  return false;
64
66
  }
65
67
  }
68
+ function warnSkippedSkill(skillMdPath, reason) {
69
+ console.warn(`⚠ Skipped ${sanitizeMetadata(skillMdPath)} — ${stripTerminalEscapes(reason)}`);
70
+ }
66
71
  export async function parseSkillMd(skillMdPath, options) {
72
+ let content;
67
73
  try {
68
- const content = await readFile(skillMdPath, 'utf-8');
69
- const { data } = parseFrontmatter(content);
70
- if (!data.name || !data.description) {
71
- warnSkippedSkill(skillMdPath, 'missing name or description');
72
- return null;
73
- }
74
- // Ensure name and description are strings (YAML can parse numbers, booleans, etc.)
75
- if (typeof data.name !== 'string' || typeof data.description !== 'string') {
76
- warnSkippedSkill(skillMdPath, 'name and description must be strings');
77
- return null;
78
- }
79
- // ADG patch: narrow `metadata` from the loosely-typed frontmatter (`unknown`)
80
- // before reading it, so the file typechecks under the root tsconfig without
81
- // changing behavior. See vendor/skills/PROVENANCE.md.
82
- const metadata = data.metadata && typeof data.metadata === 'object'
83
- ? data.metadata
84
- : undefined;
85
- // Skip internal skills unless:
86
- // 1. INSTALL_INTERNAL_SKILLS=1 is set, OR
87
- // 2. includeInternal option is true (e.g., when user explicitly requests a skill)
88
- const isInternal = metadata?.internal === true;
89
- if (isInternal && !shouldInstallInternalSkills() && !options?.includeInternal) {
90
- return null;
91
- }
92
- return {
93
- name: sanitizeMetadata(data.name),
94
- description: sanitizeMetadata(data.description),
95
- path: dirname(skillMdPath),
96
- rawContent: content,
97
- metadata,
98
- };
74
+ content = await readFile(skillMdPath, 'utf-8');
99
75
  }
100
- catch (error) {
101
- warnSkippedSkill(skillMdPath, `failed to parse skill: ${error.message}`);
76
+ catch (err) {
77
+ warnSkippedSkill(skillMdPath, `failed to read file: ${err.message}`);
102
78
  return null;
103
79
  }
80
+ let data;
81
+ try {
82
+ ({ data } = parseFrontmatter(content));
83
+ }
84
+ catch (err) {
85
+ warnSkippedSkill(skillMdPath, `YAML parse error: ${err.message}`);
86
+ return null;
87
+ }
88
+ if (!data.name || !data.description) {
89
+ const missing = [];
90
+ if (!data.name)
91
+ missing.push('name');
92
+ if (!data.description)
93
+ missing.push('description');
94
+ warnSkippedSkill(skillMdPath, `missing required frontmatter field(s): ${missing.join(', ')}`);
95
+ return null;
96
+ }
97
+ // Ensure name and description are strings (YAML can parse numbers, booleans, etc.)
98
+ if (typeof data.name !== 'string' || typeof data.description !== 'string') {
99
+ warnSkippedSkill(skillMdPath, `frontmatter "name" and "description" must be strings (got ${typeof data.name} and ${typeof data.description})`);
100
+ return null;
101
+ }
102
+ // Skip internal skills unless:
103
+ // 1. INSTALL_INTERNAL_SKILLS=1 is set, OR
104
+ // 2. includeInternal option is true (e.g., when user explicitly requests a skill)
105
+ const metadata = isRecord(data.metadata) ? data.metadata : undefined;
106
+ const isInternal = metadata?.internal === true;
107
+ if (isInternal && !shouldInstallInternalSkills() && !options?.includeInternal) {
108
+ return null;
109
+ }
110
+ return {
111
+ name: sanitizeMetadata(data.name),
112
+ description: sanitizeMetadata(data.description),
113
+ path: dirname(skillMdPath),
114
+ rawContent: content,
115
+ metadata,
116
+ };
104
117
  }
105
118
  async function findSkillDirs(dir, depth = 0, maxDepth = 5) {
106
119
  if (depth > maxDepth)
@@ -134,6 +147,7 @@ export function isSubpathSafe(basePath, subpath) {
134
147
  export async function discoverSkills(basePath, subpath, options) {
135
148
  const skills = [];
136
149
  const seenNames = new Set();
150
+ const parsedSkillPaths = new Set();
137
151
  const localLock = await readLocalLock(basePath);
138
152
  const lockedSkillNames = new Set(Object.keys(localLock.skills).map(normalizeSkillName));
139
153
  // Validate subpath doesn't escape basePath (prevent path traversal)
@@ -163,11 +177,18 @@ export async function discoverSkills(basePath, subpath, options) {
163
177
  const directoryName = normalizeSkillName(basename(skill.path));
164
178
  return lockedSkillNames.has(skillName) || lockedSkillNames.has(directoryName);
165
179
  };
180
+ const parseSkillAt = async (skillDir) => {
181
+ const skillMdPath = resolve(skillDir, 'SKILL.md');
182
+ if (parsedSkillPaths.has(skillMdPath))
183
+ return null;
184
+ parsedSkillPaths.add(skillMdPath);
185
+ return parseSkillMd(skillMdPath, options);
186
+ };
166
187
  // If pointing directly at a skill, add it (and return early unless fullDepth is set).
167
188
  // If the root SKILL.md is an installed project skill tracked by skills-lock.json,
168
189
  // ignore it and continue scanning in case the repo also contains source skills.
169
190
  if (await hasSkillMd(searchPath)) {
170
- let skill = await parseSkillMd(join(searchPath, 'SKILL.md'), options);
191
+ let skill = await parseSkillAt(searchPath);
171
192
  if (skill) {
172
193
  if (!isInstalledProjectSkill(skill)) {
173
194
  skill = enhanceSkill(skill);
@@ -189,7 +210,7 @@ export async function discoverSkills(basePath, subpath, options) {
189
210
  join(searchPath, 'skills/.system'),
190
211
  ...AGENT_PROJECT_SKILL_DIRS.map((dir) => join(searchPath, dir)),
191
212
  ];
192
- // Known skill container dirs are walked up to the configured depth so layouts
213
+ // Known skill container dirs are walked up to three levels deep so layouts
193
214
  // like `skills/<category>/<category>/<skill>/SKILL.md` are discovered without
194
215
  // requiring `--full-depth`. The repo root (first entry) keeps its
195
216
  // existing depth-1 behavior to avoid surfacing unrelated `SKILL.md`
@@ -201,8 +222,8 @@ export async function discoverSkills(basePath, subpath, options) {
201
222
  const tryAddSkillAt = async (skillDir) => {
202
223
  if (!(await hasSkillMd(skillDir)))
203
224
  return false;
204
- let skill = await parseSkillMd(join(skillDir, 'SKILL.md'), options);
205
- if (!skill || seenNames.has(skill.name))
225
+ let skill = await parseSkillAt(skillDir);
226
+ if (!skill || (!options?.includeDuplicateNames && seenNames.has(skill.name)))
206
227
  return true;
207
228
  if (isInstalledProjectSkill(skill))
208
229
  return true;
@@ -212,7 +233,6 @@ export async function discoverSkills(basePath, subpath, options) {
212
233
  return true;
213
234
  };
214
235
  const walkSkillDirs = async (dir, maxDepth, depth = 1) => {
215
- const walkDeep = deepContainerDirs.has(dir);
216
236
  try {
217
237
  const entries = await readdir(dir, { withFileTypes: true });
218
238
  for (const entry of entries) {
@@ -220,29 +240,29 @@ export async function discoverSkills(basePath, subpath, options) {
220
240
  continue;
221
241
  const childDir = join(dir, entry.name);
222
242
  const foundAtChild = await tryAddSkillAt(childDir);
223
- // Don't descend past a discovered SKILL.md (matches the existing
224
- // flat-layout semantics) and don't go deeper inside non-container
225
- // priority dirs.
226
- if (foundAtChild || !walkDeep || depth >= maxDepth)
227
- continue;
228
- if (SKIP_DIRS.includes(entry.name))
243
+ // Preserve flat-layout semantics by stopping below a discovered
244
+ // skill, and never descend through ignored directories.
245
+ if (foundAtChild || depth >= maxDepth || SKIP_DIRS.includes(entry.name))
229
246
  continue;
230
247
  await walkSkillDirs(childDir, maxDepth, depth + 1);
231
248
  }
232
249
  }
233
250
  catch {
234
- // Directory doesn't exist or is unreadable.
251
+ // Directory doesn't exist or is unreadable; skip silently.
235
252
  }
236
253
  };
237
254
  for (const dir of prioritySearchDirs) {
238
- await walkSkillDirs(dir, deepContainerDirs.has(dir) ? DEFAULT_SKILL_CONTAINER_DEPTH : 1);
255
+ const walkDeep = deepContainerDirs.has(dir);
256
+ await walkSkillDirs(dir, walkDeep ? DEFAULT_SKILL_CONTAINER_DEPTH : 1);
239
257
  }
240
258
  // Fall back to recursive search if nothing found, or if fullDepth is set
241
259
  if (skills.length === 0 || options?.fullDepth) {
242
260
  const allSkillDirs = await findSkillDirs(searchPath);
243
261
  for (const skillDir of allSkillDirs) {
244
- let skill = await parseSkillMd(join(skillDir, 'SKILL.md'), options);
245
- if (skill && !seenNames.has(skill.name) && !isInstalledProjectSkill(skill)) {
262
+ let skill = await parseSkillAt(skillDir);
263
+ if (skill &&
264
+ (options?.includeDuplicateNames || !seenNames.has(skill.name)) &&
265
+ !isInstalledProjectSkill(skill)) {
246
266
  skill = enhanceSkill(skill);
247
267
  skills.push(skill);
248
268
  seenNames.add(skill.name);
@@ -115,6 +115,67 @@ export function sanitizeSubpath(subpath) {
115
115
  }
116
116
  return subpath;
117
117
  }
118
+ /**
119
+ * Azure Repos version query values: GBbranch, GTtag, GCcommit.
120
+ * Bare values are treated as refs as-is.
121
+ */
122
+ function azureReposVersionToRef(version) {
123
+ if (!version) {
124
+ return undefined;
125
+ }
126
+ // GB = branch, GT = tag. GC (commit) is omitted because `git clone --branch`
127
+ // cannot check out a SHA.
128
+ const prefixed = /^(?:GB|GT)(.+)$/i.exec(version)?.[1];
129
+ return prefixed || undefined;
130
+ }
131
+ /**
132
+ * Parse Azure Repos HTTPS URLs (cloud and Server).
133
+ * Marker is `/_git/{repo}` — the same path Azure DevOps uses for git clone,
134
+ * on any host. Query `path` and `version` come from the web UI.
135
+ */
136
+ function parseAzureReposSource(input, fragmentRef, fragmentSkillFilter) {
137
+ if (!input.startsWith('http://') && !input.startsWith('https://')) {
138
+ return null;
139
+ }
140
+ let parsed;
141
+ try {
142
+ parsed = new URL(input);
143
+ }
144
+ catch {
145
+ return null;
146
+ }
147
+ const segments = parsed.pathname.split('/').filter(Boolean);
148
+ const gitIndex = segments.indexOf('_git');
149
+ if (gitIndex < 0 || gitIndex === segments.length - 1) {
150
+ return null;
151
+ }
152
+ const repo = segments[gitIndex + 1].replace(/\.git$/, '');
153
+ if (!repo) {
154
+ return null;
155
+ }
156
+ const clonePath = '/' +
157
+ [...segments.slice(0, gitIndex), '_git', repo]
158
+ .map((segment) => {
159
+ try {
160
+ return encodeURIComponent(decodeURIComponent(segment));
161
+ }
162
+ catch {
163
+ return encodeURIComponent(segment);
164
+ }
165
+ })
166
+ .join('/');
167
+ const cloneUrl = `${parsed.protocol}//${parsed.host}${clonePath}`;
168
+ const ref = azureReposVersionToRef(parsed.searchParams.get('version')) || fragmentRef;
169
+ const pathParam = parsed.searchParams.get('path');
170
+ const subpath = pathParam ? sanitizeSubpath(pathParam.replace(/^\/+/, '')) : undefined;
171
+ return {
172
+ type: 'git',
173
+ url: cloneUrl,
174
+ ...(ref ? { ref } : {}),
175
+ ...(subpath ? { subpath } : {}),
176
+ ...(fragmentSkillFilter ? { skillFilter: fragmentSkillFilter } : {}),
177
+ };
178
+ }
118
179
  /**
119
180
  * Check if a string represents a local file system path
120
181
  */
@@ -129,7 +190,7 @@ function isLocalPath(input) {
129
190
  }
130
191
  /**
131
192
  * Parse a source string into a structured format
132
- * Supports: local paths, GitHub URLs, GitLab URLs, GitHub shorthand, well-known URLs,
193
+ * Supports: local paths, GitHub URLs, GitLab URLs, Azure Repos URLs, GitHub shorthand, well-known URLs,
133
194
  * hosted download URLs, and direct git URLs
134
195
  */
135
196
  // Source aliases: map common shorthand to canonical source
@@ -164,6 +225,13 @@ function looksLikeGitSource(input) {
164
225
  if (parsed.hostname === 'gitlab.com') {
165
226
  return /^\/.+?\/[^/]+(?:\.git)?(?:\/-\/tree\/[^/]+(?:\/.*)?)?\/?$/.test(pathname);
166
227
  }
228
+ // Azure Repos clone and web URLs use /_git/{repo} on any host
229
+ // (dev.azure.com, *.visualstudio.com, Azure DevOps Server).
230
+ const azureSegments = pathname.split('/').filter(Boolean);
231
+ const azureGitIndex = azureSegments.indexOf('_git');
232
+ if (azureGitIndex >= 0 && azureGitIndex < azureSegments.length - 1) {
233
+ return true;
234
+ }
167
235
  }
168
236
  catch {
169
237
  // Fall through to generic checks below.
@@ -368,6 +436,12 @@ export function parseSource(input) {
368
436
  };
369
437
  }
370
438
  }
439
+ // Azure Repos (any host): https://dev.azure.com/org/project/_git/repo
440
+ // Also Azure DevOps Server: https://server[/tfs]/{collection}/{project}/_git/{repo}
441
+ const azureRepos = parseAzureReposSource(input, fragmentRef, fragmentSkillFilter);
442
+ if (azureRepos) {
443
+ return azureRepos;
444
+ }
371
445
  // GitHub shorthand: owner/repo, owner/repo/path/to/skill, or owner/repo@skill-name
372
446
  // Exclude paths that start with . or / to avoid matching local paths
373
447
  // GH_HOST selects a GitHub Enterprise host for shorthand inputs. Enterprise