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