@rbbtsn0w/adg 0.6.0 → 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 (83) hide show
  1. package/README.md +41 -9
  2. package/dist/bin/adg.js +4 -4
  3. package/dist/src/adapters/codex.js +12 -0
  4. package/dist/src/adapters/reverse.js +22 -1
  5. package/dist/src/agents/base.js +2 -1
  6. package/dist/src/agents/claude.js +52 -6
  7. package/dist/src/agents/codex.js +94 -14
  8. package/dist/src/cli/core-plugin-handlers.js +97 -0
  9. package/dist/src/cli/handlers.js +155 -210
  10. package/dist/src/cli/index.js +14 -4
  11. package/dist/src/codex-marketplace-migration.js +139 -0
  12. package/dist/src/commands/cache.js +92 -15
  13. package/dist/src/commands/inspect.js +41 -0
  14. package/dist/src/commands/install.js +140 -73
  15. package/dist/src/commands/link.js +4 -16
  16. package/dist/src/commands/marketplace.js +74 -20
  17. package/dist/src/commands/migrate.js +15 -3
  18. package/dist/src/commands/projection.js +15 -0
  19. package/dist/src/commands/select-components.js +12 -0
  20. package/dist/src/commands/state.js +4 -2
  21. package/dist/src/commands/sync.js +9 -15
  22. package/dist/src/commands/update.js +51 -10
  23. package/dist/src/commands/validate.js +9 -2
  24. package/dist/src/components.js +3 -0
  25. package/dist/src/default-dsl.js +142 -0
  26. package/dist/src/lock.js +25 -7
  27. package/dist/src/manifest.js +85 -4
  28. package/dist/src/materialize.js +5 -1
  29. package/dist/src/mcp.js +59 -0
  30. package/dist/src/paths.js +31 -4
  31. package/dist/src/render/plugins.js +7 -1
  32. package/dist/src/source-cache.js +140 -0
  33. package/dist/src/sources.js +76 -5
  34. package/dist/src/subprocess.js +53 -0
  35. package/dist/src/telemetry.js +28 -21
  36. package/dist/src/types.js +5 -1
  37. package/dist/vendor/skills/src/add.js +0 -15
  38. package/dist/vendor/skills/src/cli.js +6 -1
  39. package/dist/vendor/skills/src/git-tree.js +4 -4
  40. package/dist/vendor/skills/src/skill-lock.js +4 -3
  41. package/dist/vendor/skills/src/update.js +38 -77
  42. package/dist/vendor/skills/src/use.js +28 -4
  43. package/docs/agents-spec.md +27 -4
  44. package/docs/authoring.md +19 -2
  45. package/docs/branching-and-release.md +52 -0
  46. package/package.json +14 -3
  47. package/schemas/adg-plugin.schema.json +2 -0
  48. package/schemas/plugin-lock.schema.json +23 -1
  49. package/vendor/skills/PROVENANCE.md +2 -0
  50. package/vendor/skills/package.json +0 -144
  51. package/vendor/skills/src/add.ts +0 -2213
  52. package/vendor/skills/src/agents.ts +0 -811
  53. package/vendor/skills/src/blob.ts +0 -588
  54. package/vendor/skills/src/cli.ts +0 -391
  55. package/vendor/skills/src/constants.ts +0 -3
  56. package/vendor/skills/src/detect-agent.ts +0 -62
  57. package/vendor/skills/src/find.ts +0 -419
  58. package/vendor/skills/src/frontmatter.ts +0 -16
  59. package/vendor/skills/src/git-tree.ts +0 -36
  60. package/vendor/skills/src/git.ts +0 -277
  61. package/vendor/skills/src/install.ts +0 -91
  62. package/vendor/skills/src/installer.ts +0 -1307
  63. package/vendor/skills/src/list.ts +0 -231
  64. package/vendor/skills/src/local-lock.ts +0 -189
  65. package/vendor/skills/src/plugin-manifest.ts +0 -183
  66. package/vendor/skills/src/prompts/search-multiselect.ts +0 -387
  67. package/vendor/skills/src/providers/index.ts +0 -14
  68. package/vendor/skills/src/providers/registry.ts +0 -51
  69. package/vendor/skills/src/providers/types.ts +0 -97
  70. package/vendor/skills/src/providers/wellknown.ts +0 -812
  71. package/vendor/skills/src/remove.ts +0 -335
  72. package/vendor/skills/src/sanitize.ts +0 -65
  73. package/vendor/skills/src/self-cli.ts +0 -20
  74. package/vendor/skills/src/skill-lock.ts +0 -329
  75. package/vendor/skills/src/skills.ts +0 -316
  76. package/vendor/skills/src/source-parser.ts +0 -449
  77. package/vendor/skills/src/sync.ts +0 -478
  78. package/vendor/skills/src/telemetry.ts +0 -226
  79. package/vendor/skills/src/test-utils.ts +0 -73
  80. package/vendor/skills/src/types.ts +0 -129
  81. package/vendor/skills/src/update-source.ts +0 -90
  82. package/vendor/skills/src/update.ts +0 -821
  83. package/vendor/skills/src/use.ts +0 -682
@@ -1,821 +0,0 @@
1
- import { spawnSync } from 'child_process';
2
- import { existsSync, readdirSync } from 'fs';
3
- import { join, dirname, relative, sep } from 'path';
4
- import { fileURLToPath } from 'url';
5
- import * as p from '@clack/prompts';
6
- import pc from 'picocolors';
7
-
8
- import { readSkillLock, writeSkillLock, getGitHubToken, type SkillLockEntry } from './skill-lock.ts';
9
- import { computeSkillFolderHash, readLocalLock, type LocalSkillLockEntry } from './local-lock.ts';
10
- import {
11
- formatSourceInput,
12
- buildUpdateInstallSource,
13
- buildLocalUpdateSource,
14
- } from './update-source.ts';
15
- import { cloneRepo, cleanupTempDir } from './git.ts';
16
- import { discoverSkills } from './skills.ts';
17
- import { fetchRepoTree, findSkillMdPaths, getSkillFolderHashFromTree } from './blob.ts';
18
- import { removeCommand } from './remove.ts';
19
- import { sanitizeMetadata } from './sanitize.ts';
20
- import { track, getTracer } from './telemetry.ts';
21
- import { agents, isUniversalAgent } from './agents.ts';
22
- import { selfCliArgv } from './self-cli.ts';
23
- import type { AgentType } from './types.ts';
24
- import { SpanKind, SpanStatusCode } from '@opentelemetry/api';
25
-
26
- const __dirname = dirname(fileURLToPath(import.meta.url));
27
-
28
- /**
29
- * ADG patch: upstream re-invokes its *built* `bin/cli.mjs` to perform an update,
30
- * which a source-only vendoring (we copy `src/` only) does not ship — every
31
- * update then failed with "CLI entrypoint not found". Point self-invocation at
32
- * our actual TS entry, run via Node's type-stripping (Node >= 22.6), exactly how
33
- * `adg skills` launches the CLI. See vendor/skills/PROVENANCE.md.
34
- */
35
- const SELF_CLI_ENTRY = existsSync(join(__dirname, '../../../bin/adg.ts'))
36
- ? join(__dirname, '../../../bin/adg.ts')
37
- : join(__dirname, '../../../dist/bin/adg.js');
38
-
39
- const RESET = '\x1b[0m';
40
- const BOLD = '\x1b[1m';
41
- const DIM = '\x1b[38;5;102m';
42
- const TEXT = '\x1b[38;5;145m';
43
-
44
- // ============================================
45
- // Scope Detection and Prompt
46
- // ============================================
47
-
48
- export type UpdateScope = 'project' | 'global' | 'both';
49
-
50
- export interface UpdateCheckOptions {
51
- global?: boolean;
52
- project?: boolean;
53
- yes?: boolean;
54
- /** Optional skill name(s) to filter on (positional args) */
55
- skills?: string[];
56
- }
57
-
58
- export function parseUpdateOptions(args: string[]): UpdateCheckOptions {
59
- const options: UpdateCheckOptions = {};
60
- const positional: string[] = [];
61
- for (const arg of args) {
62
- if (arg === '-g' || arg === '--global') {
63
- options.global = true;
64
- } else if (arg === '-p' || arg === '--project') {
65
- options.project = true;
66
- } else if (arg === '-y' || arg === '--yes') {
67
- options.yes = true;
68
- } else if (!arg.startsWith('-')) {
69
- positional.push(arg);
70
- }
71
- }
72
- if (positional.length > 0) {
73
- options.skills = positional;
74
- }
75
- return options;
76
- }
77
-
78
- /**
79
- * Check whether the current working directory has project-level skills.
80
- * Returns true if either:
81
- * - skills-lock.json exists in cwd, OR
82
- * - .agents/skills/ contains at least one subdirectory with a SKILL.md
83
- */
84
- export function hasProjectSkills(cwd?: string): boolean {
85
- const dir = cwd || process.cwd();
86
-
87
- // Check 1: skills-lock.json exists
88
- const lockPath = join(dir, 'skills-lock.json');
89
- if (existsSync(lockPath)) {
90
- return true;
91
- }
92
-
93
- // Check 2: .agents/skills/ has at least one skill
94
- const skillsDir = join(dir, '.agents', 'skills');
95
- try {
96
- const entries = readdirSync(skillsDir, { withFileTypes: true });
97
- for (const entry of entries) {
98
- if (entry.isDirectory()) {
99
- const skillMd = join(skillsDir, entry.name, 'SKILL.md');
100
- if (existsSync(skillMd)) {
101
- return true;
102
- }
103
- }
104
- }
105
- } catch {
106
- // Directory doesn't exist
107
- }
108
-
109
- return false;
110
- }
111
-
112
- /**
113
- * Determine the update/check scope via interactive prompt or auto-detection.
114
- */
115
- export async function resolveUpdateScope(options: UpdateCheckOptions): Promise<UpdateScope> {
116
- if (options.skills && options.skills.length > 0) {
117
- if (options.global) return 'global';
118
- if (options.project) return 'project';
119
- return 'both';
120
- }
121
-
122
- if (options.global && options.project) {
123
- return 'both';
124
- }
125
- if (options.global) {
126
- return 'global';
127
- }
128
- if (options.project) {
129
- return 'project';
130
- }
131
-
132
- if (options.yes || !process.stdin.isTTY) {
133
- return hasProjectSkills() ? 'project' : 'global';
134
- }
135
-
136
- const scope = await p.select({
137
- message: 'Update scope',
138
- options: [
139
- {
140
- value: 'project' as UpdateScope,
141
- label: 'Project',
142
- hint: 'Update skills in current directory',
143
- },
144
- {
145
- value: 'global' as UpdateScope,
146
- label: 'Global',
147
- hint: 'Update skills in home directory',
148
- },
149
- {
150
- value: 'both' as UpdateScope,
151
- label: 'Both',
152
- hint: 'Update all skills',
153
- },
154
- ],
155
- });
156
-
157
- if (p.isCancel(scope)) {
158
- p.cancel('Cancelled');
159
- process.exit(0);
160
- }
161
-
162
- return scope as UpdateScope;
163
- }
164
-
165
- export function matchesSkillFilter(name: string, filter?: string[]): boolean {
166
- if (!filter || filter.length === 0) return true;
167
- const lower = name.toLowerCase();
168
- return filter.some((f) => f.toLowerCase() === lower);
169
- }
170
-
171
- export interface SkippedSkill {
172
- name: string;
173
- reason: string;
174
- sourceUrl: string;
175
- sourceType: string;
176
- ref?: string;
177
- }
178
-
179
- export function getSkipReason(entry: SkillLockEntry): string {
180
- if (entry.sourceType === 'local') {
181
- return 'Local path';
182
- }
183
- if (entry.sourceType === 'git') {
184
- return 'Git URL';
185
- }
186
- if (entry.sourceType === 'well-known') {
187
- return 'Well-known skill';
188
- }
189
- if (!entry.skillFolderHash) {
190
- return 'Private or deleted repo';
191
- }
192
- if (!entry.skillPath) {
193
- return 'No skill path recorded';
194
- }
195
- return 'No version tracking';
196
- }
197
-
198
- export function getInstallSource(skill: SkippedSkill): string {
199
- let url = skill.sourceUrl;
200
- if (skill.sourceType === 'well-known') {
201
- const idx = url.indexOf('/.well-known/');
202
- if (idx !== -1) {
203
- url = url.slice(0, idx);
204
- }
205
- }
206
- return formatSourceInput(url, skill.ref);
207
- }
208
-
209
- export function printSkippedSkills(skipped: SkippedSkill[]): void {
210
- if (skipped.length === 0) return;
211
- console.log();
212
- console.log(`${DIM}${skipped.length} skill(s) cannot be checked automatically:${RESET}`);
213
-
214
- const grouped = new Map<string, SkippedSkill[]>();
215
- for (const skill of skipped) {
216
- const source = getInstallSource(skill);
217
- const existing = grouped.get(source) || [];
218
- existing.push(skill);
219
- grouped.set(source, existing);
220
- }
221
-
222
- for (const [source, skills] of grouped) {
223
- if (skills.length === 1) {
224
- const skill = skills[0]!;
225
- console.log(
226
- ` ${TEXT}•${RESET} ${sanitizeMetadata(skill.name)} ${DIM}(${skill.reason})${RESET}`
227
- );
228
- } else {
229
- const reason = skills[0]!.reason;
230
- const names = skills.map((s) => sanitizeMetadata(s.name)).join(', ');
231
- console.log(` ${TEXT}•${RESET} ${names} ${DIM}(${reason})${RESET}`);
232
- }
233
- console.log(` ${DIM}To update: ${TEXT}adg skills add ${source} -g -y${RESET}`);
234
- }
235
- }
236
-
237
- export async function getProjectSkillsForUpdate(
238
- skillFilter?: string[]
239
- ): Promise<Array<{ name: string; source: string; entry: LocalSkillLockEntry }>> {
240
- const localLock = await readLocalLock();
241
- const skills: Array<{ name: string; source: string; entry: LocalSkillLockEntry }> = [];
242
-
243
- for (const [name, entry] of Object.entries(localLock.skills)) {
244
- if (!matchesSkillFilter(name, skillFilter)) continue;
245
- if (entry.sourceType === 'node_modules' || entry.sourceType === 'local') {
246
- continue;
247
- }
248
- skills.push({ name, source: entry.source, entry });
249
- }
250
-
251
- return skills;
252
- }
253
-
254
- export async function checkAndPromptForDeletions(
255
- source: string,
256
- allLockedForSource: string[],
257
- lockSkills: Record<string, { skillPath?: string }>,
258
- isGlobal: boolean,
259
- options: UpdateCheckOptions,
260
- discoveredPaths: string[]
261
- ): Promise<string[]> {
262
- const deletedSkills = allLockedForSource.filter((name) => {
263
- const entry = lockSkills[name];
264
- if (!entry?.skillPath) return false;
265
- return !discoveredPaths.includes(entry.skillPath);
266
- });
267
-
268
- if (deletedSkills.length > 0) {
269
- console.log();
270
- console.log(
271
- `${DIM}Warning:${RESET} The following skills from ${DIM}${source}${RESET} appear to have been deleted upstream:`
272
- );
273
- for (const s of deletedSkills) {
274
- console.log(` ${DIM}•${RESET} ${s}`);
275
- }
276
-
277
- const isNonInteractive = options.yes || !process.stdin.isTTY;
278
-
279
- if (isNonInteractive) {
280
- console.log(`${DIM}Skipping deletion in non-interactive mode.${RESET}`);
281
- } else {
282
- const confirmed = await p.confirm({
283
- message: `Would you like to remove the local copies of these deleted skills?`,
284
- });
285
-
286
- if (confirmed && !p.isCancel(confirmed)) {
287
- for (const s of deletedSkills) {
288
- console.log(`${DIM}Removing${RESET} ${s}...`);
289
- await removeCommand([s], { yes: true, global: isGlobal });
290
- }
291
- }
292
- }
293
- }
294
- return deletedSkills;
295
- }
296
-
297
- export async function updateGlobalSkills(
298
- options: UpdateCheckOptions = {}
299
- ): Promise<{ successCount: number; failCount: number; checkedCount: number }> {
300
- const lock = await readSkillLock();
301
- const skillNames = Object.keys(lock.skills);
302
- let successCount = 0;
303
- let failCount = 0;
304
-
305
- if (skillNames.length === 0) {
306
- if (!options.skills) {
307
- console.log(`${DIM}No global skills tracked in lock file.${RESET}`);
308
- console.log(`${DIM}Install skills with${RESET} ${TEXT}adg skills add <package> -g${RESET}`);
309
- }
310
- return { successCount, failCount, checkedCount: 0 };
311
- }
312
-
313
- const updates: Array<{ name: string; source: string; entry: SkillLockEntry }> = [];
314
- const skipped: SkippedSkill[] = [];
315
- const checkable: Array<{ name: string; entry: SkillLockEntry }> = [];
316
- // ADG patch: sources whose tree/clone could not be checked (e.g. a private
317
- // repo with no usable token). Tracked so we don't falsely report "up to date".
318
- const failedSources: string[] = [];
319
- // ADG patch: set when we normalize a legacy non-tree-SHA hash (see below).
320
- let healed = false;
321
-
322
- for (const skillName of skillNames) {
323
- if (!matchesSkillFilter(skillName, options.skills)) continue;
324
-
325
- const entry = lock.skills[skillName];
326
- if (!entry) continue;
327
-
328
- if (!entry.skillFolderHash || !entry.skillPath) {
329
- skipped.push({
330
- name: skillName,
331
- reason: getSkipReason(entry),
332
- sourceUrl: entry.sourceUrl,
333
- sourceType: entry.sourceType,
334
- ref: entry.ref,
335
- });
336
- continue;
337
- }
338
-
339
- checkable.push({ name: skillName, entry });
340
- }
341
-
342
- const bySource = new Map<string, typeof checkable>();
343
- for (const item of checkable) {
344
- const source = item.entry.source;
345
- const existing = bySource.get(source) || [];
346
- existing.push(item);
347
- bySource.set(source, existing);
348
- }
349
-
350
- for (const [source, itemsForSource] of bySource) {
351
- const firstEntry = itemsForSource[0]!.entry;
352
- const sourceUrl = firstEntry.sourceUrl || firstEntry.source;
353
- let tempDir: string | null = null;
354
-
355
- process.stdout.write(`\r${DIM}Checking skills from source: ${source}${RESET}\x1b[K\n`);
356
-
357
- try {
358
- const isGitHubSource = firstEntry.sourceType === 'github';
359
-
360
- if (isGitHubSource) {
361
- const tree = await fetchRepoTree(source, firstEntry.ref, getGitHubToken);
362
-
363
- if (!tree) {
364
- // ADG patch: a private repo returns 404 to anon and fetchRepoTree now
365
- // retries with a token; reaching here means even that failed (no token
366
- // or no access). Record it so the summary is honest.
367
- console.log(
368
- ` ${DIM}✗ Could not check ${source} — private repo or no GitHub access.${RESET}`
369
- );
370
- console.log(
371
- ` ${DIM}Set ${RESET}${TEXT}GITHUB_TOKEN${RESET}${DIM} or run ${RESET}${TEXT}gh auth login${RESET}${DIM} with access to it.${RESET}`
372
- );
373
- failedSources.push(source);
374
- continue;
375
- }
376
-
377
- const discoveredPaths = findSkillMdPaths(tree);
378
-
379
- const allLockedForSource = Object.entries(lock.skills)
380
- .filter(([_, entry]) => entry.source === source)
381
- .map(([name, _]) => name);
382
-
383
- const deletedSkills = await checkAndPromptForDeletions(
384
- source,
385
- allLockedForSource,
386
- lock.skills,
387
- true,
388
- options,
389
- discoveredPaths
390
- );
391
-
392
- const deletedSkillSet = new Set(deletedSkills);
393
-
394
- for (const { name: skillName, entry } of itemsForSource) {
395
- if (deletedSkillSet.has(skillName)) continue;
396
-
397
- const latestHash = getSkillFolderHashFromTree(tree, entry.skillPath!);
398
- if (!latestHash) continue;
399
-
400
- // ADG patch (self-heal): a github entry whose stored hash isn't a
401
- // 40-hex git tree SHA was written by an older clone-fallback that used
402
- // a sha256 content hash — it can never match `latestHash`, so it would
403
- // be re-flagged on every update. We can't tell whether the content
404
- // truly changed, so normalize the lock to the current tree SHA and do
405
- // NOT flag a spurious update. `add.ts` now always stores a tree SHA, so
406
- // this only ever fires for pre-fix entries.
407
- if (!/^[0-9a-f]{40}$/.test(entry.skillFolderHash)) {
408
- entry.skillFolderHash = latestHash;
409
- healed = true;
410
- continue;
411
- }
412
-
413
- if (latestHash !== entry.skillFolderHash) {
414
- updates.push({ name: skillName, source, entry });
415
- }
416
- }
417
-
418
- continue;
419
- }
420
-
421
- tempDir = await cloneRepo(sourceUrl, firstEntry.ref);
422
- const discoveredPaths = (await discoverSkills(tempDir)).map((skill) => {
423
- return join(relative(tempDir!, skill.path), 'SKILL.md').split(sep).join('/');
424
- });
425
-
426
- const allLockedForSource = Object.entries(lock.skills)
427
- .filter(([_, entry]) => entry.source === source)
428
- .map(([name, _]) => name);
429
-
430
- const deletedSkills = await checkAndPromptForDeletions(
431
- source,
432
- allLockedForSource,
433
- lock.skills,
434
- true,
435
- options,
436
- discoveredPaths
437
- );
438
-
439
- const deletedSkillSet = new Set(deletedSkills);
440
-
441
- for (const { name: skillName, entry } of itemsForSource) {
442
- if (deletedSkillSet.has(skillName)) continue;
443
-
444
- const skillPath = entry.skillPath!;
445
- if (!discoveredPaths.includes(skillPath)) continue;
446
-
447
- const latestHash = await computeSkillFolderHash(join(tempDir, dirname(skillPath)));
448
- if (latestHash && latestHash !== entry.skillFolderHash) {
449
- updates.push({ name: skillName, source, entry });
450
- }
451
- }
452
- } catch (error) {
453
- console.log(` ${DIM}✗ Failed to check skills from ${source}${RESET}`);
454
- failedSources.push(source); // ADG patch: surface in the summary
455
- } finally {
456
- if (tempDir) await cleanupTempDir(tempDir);
457
- }
458
- }
459
-
460
- if (checkable.length > 0) {
461
- process.stdout.write('\r\x1b[K');
462
- }
463
-
464
- // ADG patch: persist any self-healed (normalized) hashes once.
465
- if (healed) {
466
- try {
467
- await writeSkillLock(lock);
468
- } catch {
469
- // A failed heal-write is non-fatal: next run simply normalizes again.
470
- }
471
- }
472
-
473
- const checkedCount = checkable.length + skipped.length;
474
-
475
- if (checkable.length === 0 && skipped.length === 0) {
476
- if (!options.skills) {
477
- console.log(`${DIM}No global skills to check.${RESET}`);
478
- }
479
- return { successCount, failCount, checkedCount: 0 };
480
- }
481
-
482
- if (checkable.length === 0 && skipped.length > 0) {
483
- printSkippedSkills(skipped);
484
- return { successCount, failCount, checkedCount };
485
- }
486
-
487
- if (updates.length === 0) {
488
- // ADG patch: don't claim everything is current if some sources couldn't be
489
- // checked — that's how a private-repo fetch failure used to be hidden.
490
- if (failedSources.length > 0) {
491
- const n = failedSources.length;
492
- console.log(
493
- `${TEXT}✓ Checked global skills; ${n} source${n !== 1 ? 's' : ''} could not be verified (see above)${RESET}`
494
- );
495
- return { successCount, failCount: failCount + n, checkedCount };
496
- }
497
- console.log(`${TEXT}✓ All global skills are up to date${RESET}`);
498
- return { successCount, failCount, checkedCount };
499
- }
500
-
501
- console.log(`${TEXT}Found ${updates.length} global update(s)${RESET}`);
502
- console.log();
503
-
504
- for (const update of updates) {
505
- const safeName = sanitizeMetadata(update.name);
506
- console.log(`${TEXT}Updating ${safeName}...${RESET}`);
507
- const installUrl = buildUpdateInstallSource(update.entry);
508
-
509
- const cliEntry = SELF_CLI_ENTRY;
510
- if (!existsSync(cliEntry)) {
511
- failCount++;
512
- console.log(
513
- ` ${DIM}✗ Failed to update ${safeName}: CLI entrypoint not found at ${cliEntry}${RESET}`
514
- );
515
- continue;
516
- }
517
- const tracer = getTracer();
518
- const args = ['skills', 'add', installUrl, '-g', '-y'];
519
- const result = tracer.startActiveSpan("adg", { kind: SpanKind.CLIENT }, (span) => {
520
- try {
521
- span.setAttribute("process.executable.name", "adg");
522
- span.setAttribute("process.command_args", ["adg", ...args]);
523
-
524
- const r = spawnSync(
525
- process.execPath,
526
- selfCliArgv(cliEntry, args),
527
- {
528
- stdio: ['inherit', 'pipe', 'pipe'],
529
- encoding: 'utf-8',
530
- shell: process.platform === 'win32',
531
- }
532
- );
533
-
534
- if (r.pid !== undefined) span.setAttribute("process.pid", r.pid);
535
- if (r.status !== null) {
536
- span.setAttribute("process.exit.code", r.status);
537
- if (r.status !== 0) {
538
- span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
539
- span.setStatus({
540
- code: SpanStatusCode.ERROR,
541
- message: `Subprocess exited with status ${r.status}`,
542
- });
543
- }
544
- } else if (r.error) {
545
- span.setAttribute("process.exit.code", -1);
546
- span.setAttribute("error.type", (r.error as NodeJS.ErrnoException).code || r.error.name || "SpawnError");
547
- span.recordException(r.error);
548
- span.setStatus({
549
- code: SpanStatusCode.ERROR,
550
- message: r.error.message,
551
- });
552
- }
553
- return r;
554
- } finally {
555
- span.end();
556
- }
557
- });
558
-
559
- if (result.status === 0) {
560
- successCount++;
561
- console.log(` ${TEXT}✓${RESET} Updated ${safeName}`);
562
- } else {
563
- failCount++;
564
- console.log(` ${DIM}✗ Failed to update ${safeName}${RESET}`);
565
- }
566
- }
567
-
568
- printSkippedSkills(skipped);
569
- return { successCount, failCount, checkedCount };
570
- }
571
-
572
- export async function updateProjectSkills(
573
- options: UpdateCheckOptions = {}
574
- ): Promise<{ successCount: number; failCount: number; foundCount: number }> {
575
- const projectSkills = await getProjectSkillsForUpdate(options.skills);
576
- let successCount = 0;
577
- let failCount = 0;
578
-
579
- if (projectSkills.length === 0) {
580
- if (!options.skills) {
581
- console.log(`${DIM}No project skills to update.${RESET}`);
582
- console.log(
583
- `${DIM}Install project skills with${RESET} ${TEXT}adg skills add <package>${RESET}`
584
- );
585
- }
586
- return { successCount, failCount, foundCount: 0 };
587
- }
588
-
589
- const updatable = projectSkills.filter((s) => s.entry.skillPath);
590
- const legacy = projectSkills.filter((s) => !s.entry.skillPath);
591
-
592
- if (updatable.length === 0) {
593
- console.log(`${DIM}No project skills can be updated in place.${RESET}`);
594
- printLegacyProjectSkills(legacy);
595
- return { successCount, failCount, foundCount: projectSkills.length };
596
- }
597
-
598
- const cwd = process.cwd();
599
- const targetAgentNames: string[] = [];
600
- let hasUniversal = false;
601
-
602
- for (const [type, config] of Object.entries(agents)) {
603
- if (isUniversalAgent(type as AgentType)) {
604
- if (!hasUniversal && existsSync(join(cwd, '.agents'))) {
605
- hasUniversal = true;
606
- }
607
- } else {
608
- const agentRoot = config.skillsDir.split('/')[0]!;
609
- if (existsSync(join(cwd, agentRoot))) {
610
- targetAgentNames.push(config.displayName);
611
- }
612
- }
613
- }
614
-
615
- const targetParts: string[] = [];
616
- if (hasUniversal) targetParts.push('Universal');
617
- targetParts.push(...targetAgentNames);
618
-
619
- if (targetParts.length > 0) {
620
- console.log(`${TEXT}Updating for: ${targetParts.join(', ')}${RESET}`);
621
- }
622
-
623
- console.log(`${TEXT}Refreshing ${updatable.length} skill(s)...${RESET}`);
624
- console.log();
625
-
626
- const bySource = new Map<string, typeof updatable>();
627
- for (const skill of updatable) {
628
- const source = skill.entry.source;
629
- const existing = bySource.get(source) || [];
630
- existing.push(skill);
631
- bySource.set(source, existing);
632
- }
633
-
634
- const localLock = await readLocalLock();
635
- const cliEntry = SELF_CLI_ENTRY;
636
-
637
- if (!existsSync(cliEntry)) {
638
- console.log(`${DIM}✗ CLI entrypoint not found at ${cliEntry}${RESET}`);
639
- return { successCount, failCount: updatable.length, foundCount: projectSkills.length };
640
- }
641
-
642
- for (const [source, skillsForSource] of bySource) {
643
- const firstEntry = skillsForSource[0]!.entry;
644
- const sourceUrl = firstEntry.source;
645
- const ref = firstEntry.ref;
646
-
647
- const allLockedForSource = Object.entries(localLock.skills)
648
- .filter(([_, entry]) => entry.source === source)
649
- .map(([name, _]) => name);
650
-
651
- let tempDir: string | null = null;
652
- let deletedSkills: string[] = [];
653
-
654
- try {
655
- tempDir = await cloneRepo(sourceUrl, ref);
656
- const discovered = await discoverSkills(tempDir);
657
-
658
- const discoveredPaths = discovered.map((s) => {
659
- const relPath = relative(tempDir!, s.path);
660
- return join(relPath, 'SKILL.md').split(sep).join('/');
661
- });
662
-
663
- deletedSkills = await checkAndPromptForDeletions(
664
- source,
665
- allLockedForSource,
666
- localLock.skills,
667
- false,
668
- options,
669
- discoveredPaths
670
- );
671
- } catch (error) {
672
- console.log(`${DIM}✗ Failed to check for deleted skills from ${source}${RESET}`);
673
- } finally {
674
- if (tempDir) {
675
- await cleanupTempDir(tempDir);
676
- }
677
- }
678
-
679
- const remainingSkills = skillsForSource.filter((s) => !deletedSkills.includes(s.name));
680
-
681
- for (const skill of remainingSkills) {
682
- const safeName = sanitizeMetadata(skill.name);
683
- console.log(`${TEXT}Updating ${safeName}...${RESET}`);
684
- const installUrl = formatSourceInput(skill.entry.source, skill.entry.ref);
685
-
686
- const tracer = getTracer();
687
- // Preserve Eve subagent placement recorded at install time. The lock stores
688
- // '' for the root agent, which maps to the `root` keyword for `add --subagent`.
689
- const subagentArgs = skill.entry.subagents?.length
690
- ? ['--subagent', ...skill.entry.subagents.map((s) => (s === '' ? 'root' : s))]
691
- : [];
692
- const args = ['skills', 'add', installUrl, '--skill', skill.name, ...subagentArgs, '-y'];
693
- const result = tracer.startActiveSpan("adg", { kind: SpanKind.CLIENT }, (span) => {
694
- try {
695
- span.setAttribute("process.executable.name", "adg");
696
- span.setAttribute("process.command_args", ["adg", ...args]);
697
-
698
- const r = spawnSync(
699
- process.execPath,
700
- selfCliArgv(cliEntry, args),
701
- {
702
- stdio: ['inherit', 'pipe', 'pipe'],
703
- encoding: 'utf-8',
704
- shell: process.platform === 'win32',
705
- }
706
- );
707
-
708
- if (r.pid !== undefined) span.setAttribute("process.pid", r.pid);
709
- if (r.status !== null) {
710
- span.setAttribute("process.exit.code", r.status);
711
- if (r.status !== 0) {
712
- span.setAttribute("error.type", `EXIT_CODE_${r.status}`);
713
- span.setStatus({
714
- code: SpanStatusCode.ERROR,
715
- message: `Subprocess exited with status ${r.status}`,
716
- });
717
- }
718
- } else if (r.error) {
719
- span.setAttribute("process.exit.code", -1);
720
- span.setAttribute("error.type", (r.error as NodeJS.ErrnoException).code || r.error.name || "SpawnError");
721
- span.recordException(r.error);
722
- span.setStatus({
723
- code: SpanStatusCode.ERROR,
724
- message: r.error.message,
725
- });
726
- }
727
- return r;
728
- } finally {
729
- span.end();
730
- }
731
- });
732
-
733
- if (result.status === 0) {
734
- successCount++;
735
- console.log(` ${TEXT}✓${RESET} Updated ${safeName}`);
736
- } else {
737
- failCount++;
738
- console.log(` ${DIM}✗ Failed to update ${safeName}${RESET}`);
739
- }
740
- }
741
- }
742
-
743
- printLegacyProjectSkills(legacy);
744
- return { successCount, failCount, foundCount: projectSkills.length };
745
- }
746
-
747
- export function printLegacyProjectSkills(
748
- legacy: Array<{ name: string; source: string; entry: LocalSkillLockEntry }>
749
- ): void {
750
- if (legacy.length === 0) return;
751
- console.log();
752
- console.log(
753
- `${DIM}${legacy.length} project skill(s) cannot be updated automatically (installed before skillPath tracking):${RESET}`
754
- );
755
- for (const skill of legacy) {
756
- const reinstall = formatSourceInput(skill.entry.source, skill.entry.ref);
757
- console.log(` ${TEXT}•${RESET} ${sanitizeMetadata(skill.name)}`);
758
- console.log(` ${DIM}To refresh: ${TEXT}adg skills add ${reinstall} -y${RESET}`);
759
- }
760
- }
761
-
762
- export async function runUpdate(args: string[] = []): Promise<void> {
763
- const options = parseUpdateOptions(args);
764
- const scope = await resolveUpdateScope(options);
765
-
766
- if (options.skills) {
767
- console.log(`${TEXT}Updating ${options.skills.join(', ')}...${RESET}`);
768
- } else {
769
- console.log(`${TEXT}Checking for skill updates...${RESET}`);
770
- }
771
- console.log();
772
-
773
- let totalSuccess = 0;
774
- let totalFail = 0;
775
- let totalFound = 0;
776
-
777
- if (scope === 'global' || scope === 'both') {
778
- if (scope === 'both' && !options.skills) {
779
- console.log(`${BOLD}Global Skills${RESET}`);
780
- }
781
- const { successCount, failCount, checkedCount } = await updateGlobalSkills(options);
782
- totalSuccess += successCount;
783
- totalFail += failCount;
784
- totalFound += checkedCount;
785
- if (scope === 'both' && !options.skills) {
786
- console.log();
787
- }
788
- }
789
-
790
- if (scope === 'project' || scope === 'both') {
791
- if (scope === 'both' && !options.skills) {
792
- console.log(`${BOLD}Project Skills${RESET}`);
793
- }
794
- const { successCount, failCount, foundCount } = await updateProjectSkills(options);
795
- totalSuccess += successCount;
796
- totalFail += failCount;
797
- totalFound += foundCount;
798
- }
799
-
800
- if (options.skills && totalFound === 0) {
801
- console.log(`${DIM}No installed skills found matching: ${options.skills.join(', ')}${RESET}`);
802
- }
803
-
804
- console.log();
805
- if (totalSuccess > 0) {
806
- console.log(`${TEXT}✓ Updated ${totalSuccess} skill(s)${RESET}`);
807
- }
808
- if (totalFail > 0) {
809
- console.log(`${DIM}Failed to update ${totalFail} skill(s)${RESET}`);
810
- }
811
-
812
- track({
813
- event: 'update',
814
- scope,
815
- skillCount: String(totalSuccess + totalFail),
816
- successCount: String(totalSuccess),
817
- failCount: String(totalFail),
818
- });
819
-
820
- console.log();
821
- }