@rbbtsn0w/adg 0.6.0-beta.9 → 0.7.0-beta.1

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 (50) hide show
  1. package/README.md +10 -7
  2. package/dist/bin/adg.js +4 -3
  3. package/dist/src/agents/base.js +2 -1
  4. package/dist/src/cli/core-plugin-handlers.js +97 -0
  5. package/dist/src/cli/handlers.js +4 -82
  6. package/dist/src/manifest.js +56 -3
  7. package/dist/src/subprocess.js +53 -0
  8. package/dist/vendor/skills/src/add.js +0 -15
  9. package/dist/vendor/skills/src/git-tree.js +4 -4
  10. package/dist/vendor/skills/src/skill-lock.js +4 -3
  11. package/dist/vendor/skills/src/update.js +9 -73
  12. package/dist/vendor/skills/src/use.js +28 -4
  13. package/docs/branching-and-release.md +52 -0
  14. package/package.json +11 -2
  15. package/schemas/adg-plugin.schema.json +1 -0
  16. package/vendor/skills/PROVENANCE.md +2 -0
  17. package/vendor/skills/package.json +0 -144
  18. package/vendor/skills/src/add.ts +0 -2213
  19. package/vendor/skills/src/agents.ts +0 -811
  20. package/vendor/skills/src/blob.ts +0 -588
  21. package/vendor/skills/src/cli.ts +0 -396
  22. package/vendor/skills/src/constants.ts +0 -3
  23. package/vendor/skills/src/detect-agent.ts +0 -62
  24. package/vendor/skills/src/find.ts +0 -419
  25. package/vendor/skills/src/frontmatter.ts +0 -16
  26. package/vendor/skills/src/git-tree.ts +0 -36
  27. package/vendor/skills/src/git.ts +0 -277
  28. package/vendor/skills/src/install.ts +0 -91
  29. package/vendor/skills/src/installer.ts +0 -1307
  30. package/vendor/skills/src/list.ts +0 -231
  31. package/vendor/skills/src/local-lock.ts +0 -189
  32. package/vendor/skills/src/plugin-manifest.ts +0 -183
  33. package/vendor/skills/src/prompts/search-multiselect.ts +0 -387
  34. package/vendor/skills/src/providers/index.ts +0 -14
  35. package/vendor/skills/src/providers/registry.ts +0 -51
  36. package/vendor/skills/src/providers/types.ts +0 -97
  37. package/vendor/skills/src/providers/wellknown.ts +0 -812
  38. package/vendor/skills/src/remove.ts +0 -335
  39. package/vendor/skills/src/sanitize.ts +0 -65
  40. package/vendor/skills/src/self-cli.ts +0 -20
  41. package/vendor/skills/src/skill-lock.ts +0 -329
  42. package/vendor/skills/src/skills.ts +0 -316
  43. package/vendor/skills/src/source-parser.ts +0 -449
  44. package/vendor/skills/src/sync.ts +0 -478
  45. package/vendor/skills/src/telemetry.ts +0 -226
  46. package/vendor/skills/src/test-utils.ts +0 -73
  47. package/vendor/skills/src/types.ts +0 -129
  48. package/vendor/skills/src/update-source.ts +0 -90
  49. package/vendor/skills/src/update.ts +0 -849
  50. package/vendor/skills/src/use.ts +0 -682
@@ -1,419 +0,0 @@
1
- import * as readline from 'readline';
2
- import { runAdd, parseAddOptions } from './add.ts';
3
- import { sanitizeMetadata } from './sanitize.ts';
4
- import { track } from './telemetry.ts';
5
- import { isRepoPrivate } from './source-parser.ts';
6
- import { isRunningInAgent } from './detect-agent.ts';
7
-
8
- const RESET = '\x1b[0m';
9
- const BOLD = '\x1b[1m';
10
- const DIM = '\x1b[38;5;102m';
11
- const TEXT = '\x1b[38;5;145m';
12
- const CYAN = '\x1b[36m';
13
- const MAGENTA = '\x1b[35m';
14
- const YELLOW = '\x1b[33m';
15
-
16
- // API endpoint for skills search
17
- const SEARCH_API_BASE = process.env.SKILLS_API_URL || 'https://skills.sh';
18
-
19
- function formatInstalls(count: number): string {
20
- if (!count || count <= 0) return '';
21
- if (count >= 1_000_000) return `${(count / 1_000_000).toFixed(1).replace(/\.0$/, '')}M installs`;
22
- if (count >= 1_000) return `${(count / 1_000).toFixed(1).replace(/\.0$/, '')}K installs`;
23
- return `${count} install${count === 1 ? '' : 's'}`;
24
- }
25
-
26
- export interface SearchSkill {
27
- name: string;
28
- slug: string;
29
- source: string;
30
- installs: number;
31
- }
32
-
33
- export interface FindOptions {
34
- owner?: string;
35
- }
36
-
37
- export interface ParseFindOptionsResult {
38
- query: string;
39
- options: FindOptions;
40
- errors: string[];
41
- }
42
-
43
- const GITHUB_OWNER_PATTERN = /^[a-z0-9](?:[a-z0-9-]{0,38})$/i;
44
-
45
- export function parseFindOptions(args: string[]): ParseFindOptionsResult {
46
- const queryParts: string[] = [];
47
- const options: FindOptions = {};
48
- const errors: string[] = [];
49
-
50
- for (let i = 0; i < args.length; i++) {
51
- const arg = args[i];
52
- if (!arg) continue;
53
-
54
- let ownerValue: string | undefined;
55
- if (arg === '--owner') {
56
- const value = args[i + 1];
57
- if (!value || value.startsWith('-')) {
58
- errors.push('--owner requires a GitHub owner');
59
- continue;
60
- }
61
- ownerValue = value;
62
- i++;
63
- } else if (arg.startsWith('--owner=')) {
64
- ownerValue = arg.slice('--owner='.length);
65
- if (!ownerValue) {
66
- errors.push('--owner requires a GitHub owner');
67
- continue;
68
- }
69
- } else {
70
- queryParts.push(arg);
71
- continue;
72
- }
73
-
74
- const owner = ownerValue.trim().toLowerCase();
75
- if (!GITHUB_OWNER_PATTERN.test(owner)) {
76
- errors.push('--owner must be a valid GitHub owner');
77
- continue;
78
- }
79
- options.owner = owner;
80
- }
81
-
82
- return { query: queryParts.join(' '), options, errors };
83
- }
84
-
85
- // Search via API
86
- export async function searchSkillsAPI(query: string, owner?: string): Promise<SearchSkill[]> {
87
- try {
88
- const params = new URLSearchParams({ q: query, limit: '10' });
89
- if (owner) params.set('owner', owner);
90
- const url = `${SEARCH_API_BASE}/api/search?${params.toString()}`;
91
- const res = await fetch(url);
92
-
93
- if (!res.ok) return [];
94
-
95
- const data = (await res.json()) as {
96
- skills: Array<{
97
- id: string;
98
- name: string;
99
- installs: number;
100
- source: string;
101
- }>;
102
- };
103
-
104
- return data.skills
105
- .map((skill) => ({
106
- name: sanitizeMetadata(skill.name),
107
- slug: sanitizeMetadata(skill.id),
108
- source: sanitizeMetadata(skill.source || ''),
109
- installs: skill.installs,
110
- }))
111
- .sort((a, b) => (b.installs || 0) - (a.installs || 0));
112
- } catch {
113
- return [];
114
- }
115
- }
116
-
117
- // ANSI escape codes for terminal control
118
- const HIDE_CURSOR = '\x1b[?25l';
119
- const SHOW_CURSOR = '\x1b[?25h';
120
- const CLEAR_DOWN = '\x1b[J';
121
- const MOVE_UP = (n: number) => `\x1b[${n}A`;
122
- const MOVE_TO_COL = (n: number) => `\x1b[${n}G`;
123
-
124
- // Custom fzf-style search prompt using raw readline
125
- async function runSearchPrompt(initialQuery = '', owner?: string): Promise<SearchSkill | null> {
126
- let results: SearchSkill[] = [];
127
- let selectedIndex = 0;
128
- let query = initialQuery;
129
- let loading = false;
130
- let debounceTimer: ReturnType<typeof setTimeout> | null = null;
131
- let lastRenderedLines = 0;
132
-
133
- // Enable raw mode for keypress events
134
- if (process.stdin.isTTY) {
135
- process.stdin.setRawMode(true);
136
- }
137
-
138
- // Setup readline for keypress events but don't let it echo
139
- readline.emitKeypressEvents(process.stdin);
140
-
141
- // Resume stdin to start receiving events
142
- process.stdin.resume();
143
-
144
- // Hide cursor during selection
145
- process.stdout.write(HIDE_CURSOR);
146
-
147
- function render(): void {
148
- // Move cursor up to overwrite previous render
149
- if (lastRenderedLines > 0) {
150
- process.stdout.write(MOVE_UP(lastRenderedLines) + MOVE_TO_COL(1));
151
- }
152
-
153
- // Clear from cursor to end of screen (removes ghost trails)
154
- process.stdout.write(CLEAR_DOWN);
155
-
156
- const lines: string[] = [];
157
-
158
- // Search input line with cursor
159
- const cursor = `${BOLD}_${RESET}`;
160
- lines.push(`${TEXT}Search skills:${RESET} ${query}${cursor}`);
161
- lines.push('');
162
-
163
- // Results - keep showing existing results while loading new ones
164
- if (!query || query.length < 2) {
165
- lines.push(`${DIM}Start typing to search (min 2 chars)${RESET}`);
166
- } else if (results.length === 0 && loading) {
167
- lines.push(`${DIM}Searching...${RESET}`);
168
- } else if (results.length === 0) {
169
- lines.push(`${DIM}No skills found${RESET}`);
170
- } else {
171
- const maxVisible = 8;
172
- const visible = results.slice(0, maxVisible);
173
-
174
- for (let i = 0; i < visible.length; i++) {
175
- const skill = visible[i]!;
176
- const isSelected = i === selectedIndex;
177
- const arrow = isSelected ? `${BOLD}>${RESET}` : ' ';
178
- const name = isSelected ? `${BOLD}${skill.name}${RESET}` : `${TEXT}${skill.name}${RESET}`;
179
- const source = skill.source ? ` ${DIM}${skill.source}${RESET}` : '';
180
- const installs = formatInstalls(skill.installs);
181
- const installsBadge = installs ? ` ${CYAN}${installs}${RESET}` : '';
182
- const loadingIndicator = loading && i === 0 ? ` ${DIM}...${RESET}` : '';
183
-
184
- lines.push(` ${arrow} ${name}${source}${installsBadge}${loadingIndicator}`);
185
- }
186
- }
187
-
188
- lines.push('');
189
- lines.push(`${DIM}up/down navigate | enter select | esc cancel${RESET}`);
190
-
191
- // Write each line
192
- for (const line of lines) {
193
- process.stdout.write(line + '\n');
194
- }
195
-
196
- lastRenderedLines = lines.length;
197
- }
198
-
199
- function triggerSearch(q: string): void {
200
- // Always clear any pending debounce timer
201
- if (debounceTimer) {
202
- clearTimeout(debounceTimer);
203
- debounceTimer = null;
204
- }
205
-
206
- // Always reset loading state when starting a new search
207
- loading = false;
208
-
209
- if (!q || q.length < 2) {
210
- results = [];
211
- selectedIndex = 0;
212
- render();
213
- return;
214
- }
215
-
216
- // Use API search for all queries (debounced)
217
- loading = true;
218
- render();
219
-
220
- // Adaptive debounce: shorter queries = longer wait (user still typing)
221
- // 2 chars: 250ms, 3 chars: 200ms, 4 chars: 150ms, 5+ chars: 150ms
222
- const debounceMs = Math.max(150, 350 - q.length * 50);
223
-
224
- debounceTimer = setTimeout(async () => {
225
- try {
226
- results = await searchSkillsAPI(q, owner);
227
- selectedIndex = 0;
228
- } catch {
229
- results = [];
230
- } finally {
231
- loading = false;
232
- debounceTimer = null;
233
- render();
234
- }
235
- }, debounceMs);
236
- }
237
-
238
- // Trigger initial search if there's a query, then render
239
- if (initialQuery) {
240
- triggerSearch(initialQuery);
241
- }
242
- render();
243
-
244
- return new Promise((resolve) => {
245
- function cleanup(): void {
246
- process.stdin.removeListener('keypress', handleKeypress);
247
- if (process.stdin.isTTY) {
248
- process.stdin.setRawMode(false);
249
- }
250
- process.stdout.write(SHOW_CURSOR);
251
- // Pause stdin to fully release it for child processes
252
- process.stdin.pause();
253
- }
254
-
255
- function handleKeypress(_ch: string | undefined, key: readline.Key): void {
256
- if (!key) return;
257
-
258
- if (key.name === 'escape' || (key.ctrl && key.name === 'c')) {
259
- // Cancel
260
- cleanup();
261
- resolve(null);
262
- return;
263
- }
264
-
265
- if (key.name === 'return') {
266
- // Submit
267
- cleanup();
268
- resolve(results[selectedIndex] || null);
269
- return;
270
- }
271
-
272
- if (key.name === 'up') {
273
- selectedIndex = Math.max(0, selectedIndex - 1);
274
- render();
275
- return;
276
- }
277
-
278
- if (key.name === 'down') {
279
- selectedIndex = Math.min(Math.max(0, results.length - 1), selectedIndex + 1);
280
- render();
281
- return;
282
- }
283
-
284
- if (key.name === 'backspace') {
285
- if (query.length > 0) {
286
- query = query.slice(0, -1);
287
- triggerSearch(query);
288
- }
289
- return;
290
- }
291
-
292
- // Regular character input
293
- if (key.sequence && !key.ctrl && !key.meta && key.sequence.length === 1) {
294
- const char = key.sequence;
295
- if (char >= ' ' && char <= '~') {
296
- query += char;
297
- triggerSearch(query);
298
- }
299
- }
300
- }
301
-
302
- process.stdin.on('keypress', handleKeypress);
303
- });
304
- }
305
-
306
- // Parse owner/repo from a package string (for the find command)
307
- function getOwnerRepoFromString(pkg: string): { owner: string; repo: string } | null {
308
- // Handle owner/repo or owner/repo@skill
309
- const atIndex = pkg.lastIndexOf('@');
310
- const repoPath = atIndex > 0 ? pkg.slice(0, atIndex) : pkg;
311
- const match = repoPath.match(/^([^/]+)\/([^/]+)$/);
312
- if (match) {
313
- return { owner: match[1]!, repo: match[2]! };
314
- }
315
- return null;
316
- }
317
-
318
- async function isRepoPublic(owner: string, repo: string): Promise<boolean> {
319
- const isPrivate = await isRepoPrivate(owner, repo);
320
- // Return true only if we know it's public (isPrivate === false)
321
- // Return false if private or unable to determine
322
- return isPrivate === false;
323
- }
324
-
325
- export async function runFind(args: string[]): Promise<void> {
326
- const { query, options: findOptions, errors } = parseFindOptions(args);
327
- const owner = findOptions.owner;
328
- const isNonInteractive = !process.stdin.isTTY;
329
- const agentTip = `${DIM}Tip: if running in a coding agent, follow these steps:${RESET}
330
- ${DIM} 1) npx skills find [query] [--owner <owner>]${RESET}
331
- ${DIM} 2) npx skills add <owner/repo@skill>${RESET}`;
332
-
333
- if (errors.length > 0) {
334
- for (const error of errors) console.error(error);
335
- console.error('Usage: npx skills find <query> [--owner <owner>]');
336
- return;
337
- }
338
-
339
- // Non-interactive mode: just print results and exit
340
- if (query) {
341
- const results = await searchSkillsAPI(query, owner);
342
-
343
- // Track telemetry for non-interactive search
344
- track({
345
- event: 'find',
346
- query,
347
- resultCount: String(results.length),
348
- });
349
-
350
- if (results.length === 0) {
351
- const ownerSuffix = owner ? ` from owner "${owner}"` : '';
352
- console.log(`${DIM}No skills found for "${query}"${ownerSuffix}${RESET}`);
353
- return;
354
- }
355
-
356
- console.log(`${DIM}Install with${RESET} npx skills add <owner/repo@skill>`);
357
- console.log();
358
-
359
- for (const skill of results.slice(0, 6)) {
360
- const pkg = skill.source || skill.slug;
361
- const installs = formatInstalls(skill.installs);
362
- console.log(
363
- `${TEXT}${pkg}@${skill.name}${RESET}${installs ? ` ${CYAN}${installs}${RESET}` : ''}`
364
- );
365
- console.log(`${DIM}└ https://skills.sh/${skill.slug}${RESET}`);
366
- console.log();
367
- }
368
- return;
369
- }
370
-
371
- // Skip interactive search when running inside an AI agent or non-TTY
372
- if (isNonInteractive || (await isRunningInAgent())) {
373
- console.log(agentTip);
374
- console.log();
375
- console.log(`${DIM}Usage: npx skills find <query> [--owner <owner>]${RESET}`);
376
- return;
377
- }
378
-
379
- const selected = await runSearchPrompt('', owner);
380
-
381
- // Track telemetry for interactive search
382
- track({
383
- event: 'find',
384
- query: '',
385
- resultCount: selected ? '1' : '0',
386
- interactive: '1',
387
- });
388
-
389
- if (!selected) {
390
- console.log(`${DIM}Search cancelled${RESET}`);
391
- console.log();
392
- return;
393
- }
394
-
395
- // Use source (owner/repo) and skill name for installation
396
- const pkg = selected.source || selected.slug;
397
- const skillName = selected.name;
398
-
399
- console.log();
400
- console.log(`${TEXT}Installing ${BOLD}${skillName}${RESET} from ${DIM}${pkg}${RESET}...`);
401
- console.log();
402
-
403
- // Run add directly since we're in the same CLI
404
- const { source, options: addOptions } = parseAddOptions([pkg, '--skill', skillName]);
405
- await runAdd(source, addOptions);
406
-
407
- console.log();
408
-
409
- const info = getOwnerRepoFromString(pkg);
410
- if (info && (await isRepoPublic(info.owner, info.repo))) {
411
- console.log(
412
- `${DIM}View the skill at${RESET} ${TEXT}https://skills.sh/${selected.slug}${RESET}`
413
- );
414
- } else {
415
- console.log(`${DIM}Discover more skills at${RESET} ${TEXT}https://skills.sh${RESET}`);
416
- }
417
-
418
- console.log();
419
- }
@@ -1,16 +0,0 @@
1
- import { parse as parseYaml } from 'yaml';
2
-
3
- /**
4
- * Minimal frontmatter parser. Only supports YAML (the `---` delimiter).
5
- * Does NOT support `---js` / `---javascript` to avoid eval()-based RCE
6
- * that exists in gray-matter's built-in JS engine.
7
- */
8
- export function parseFrontmatter(raw: string): {
9
- data: Record<string, unknown>;
10
- content: string;
11
- } {
12
- const match = raw.match(/^---\r?\n([\s\S]*?)\r?\n---\r?\n?([\s\S]*)$/);
13
- if (!match) return { data: {}, content: raw };
14
- const data = (parseYaml(match[1]!) as Record<string, unknown>) ?? {};
15
- return { data, content: match[2] ?? '' };
16
- }
@@ -1,36 +0,0 @@
1
- import { execFile } from 'node:child_process';
2
- import { promisify } from 'node:util';
3
-
4
- const execFileAsync = promisify(execFile);
5
-
6
- /**
7
- * ADG-added file (see vendor/skills/PROVENANCE.md → Local patches).
8
- *
9
- * Return the git *tree object SHA* for a folder inside a freshly cloned repo —
10
- * the SAME 40-hex value GitHub's Trees API returns and that
11
- * `getSkillFolderHashFromTree` (blob.ts) compares against at update time.
12
- *
13
- * Used by `add.ts` so a github source that fell back to a `git clone` at install
14
- * still records a tree SHA, not a sha256 content hash. Otherwise the install and
15
- * update hashing schemes diverge and every update perpetually re-flags the skill
16
- * (the bug that made a collection repo "fully update" on every run).
17
- *
18
- * `folder === ''` means the repo root. Returns null if git can't resolve it.
19
- *
20
- * Deliberately uses `child_process` rather than simple-git: this keeps the file
21
- * free of simple-git's typings, which don't satisfy ADG's strict tsconfig when a
22
- * test pulls the module into the typecheck graph.
23
- */
24
- export async function gitTreeShaForFolder(
25
- repoDir: string,
26
- folder: string
27
- ): Promise<string | null> {
28
- const spec = folder ? `HEAD:${folder}` : 'HEAD^{tree}';
29
- try {
30
- const { stdout } = await execFileAsync('git', ['-C', repoDir, 'rev-parse', spec]);
31
- const sha = stdout.trim();
32
- return /^[0-9a-f]{40}$/.test(sha) ? sha : null;
33
- } catch {
34
- return null;
35
- }
36
- }