skilld 1.7.3 → 2.0.0

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 (161) hide show
  1. package/dist/_chunks/add.mjs +66 -0
  2. package/dist/_chunks/add.mjs.map +1 -0
  3. package/dist/_chunks/agent-prompt.mjs +88 -0
  4. package/dist/_chunks/agent-prompt.mjs.map +1 -0
  5. package/dist/_chunks/agent.mjs +737 -619
  6. package/dist/_chunks/agent.mjs.map +1 -1
  7. package/dist/_chunks/args.mjs +42 -0
  8. package/dist/_chunks/args.mjs.map +1 -0
  9. package/dist/_chunks/assemble.mjs +11 -8
  10. package/dist/_chunks/assemble.mjs.map +1 -1
  11. package/dist/_chunks/author.mjs +77 -131
  12. package/dist/_chunks/author.mjs.map +1 -1
  13. package/dist/_chunks/cache.mjs +320 -54
  14. package/dist/_chunks/cache.mjs.map +1 -1
  15. package/dist/_chunks/cache2.mjs +7 -6
  16. package/dist/_chunks/cache2.mjs.map +1 -1
  17. package/dist/_chunks/client.mjs +117 -0
  18. package/dist/_chunks/client.mjs.map +1 -0
  19. package/dist/_chunks/core.mjs +7 -4
  20. package/dist/_chunks/detect.mjs +54 -44
  21. package/dist/_chunks/detect.mjs.map +1 -1
  22. package/dist/_chunks/eject.mjs +69 -0
  23. package/dist/_chunks/eject.mjs.map +1 -0
  24. package/dist/_chunks/embedding-cache2.mjs +2 -2
  25. package/dist/_chunks/env.mjs +19 -0
  26. package/dist/_chunks/env.mjs.map +1 -0
  27. package/dist/_chunks/install-many.mjs +376 -0
  28. package/dist/_chunks/install-many.mjs.map +1 -0
  29. package/dist/_chunks/install.mjs +86 -371
  30. package/dist/_chunks/install.mjs.map +1 -1
  31. package/dist/_chunks/intro.mjs +63 -0
  32. package/dist/_chunks/intro.mjs.map +1 -0
  33. package/dist/_chunks/list.mjs +2 -2
  34. package/dist/_chunks/list.mjs.map +1 -1
  35. package/dist/_chunks/lockfile.mjs +31 -7
  36. package/dist/_chunks/lockfile.mjs.map +1 -1
  37. package/dist/_chunks/login.mjs +233 -0
  38. package/dist/_chunks/login.mjs.map +1 -0
  39. package/dist/_chunks/logout.mjs +27 -0
  40. package/dist/_chunks/logout.mjs.map +1 -0
  41. package/dist/_chunks/map.mjs +11 -0
  42. package/dist/_chunks/map.mjs.map +1 -0
  43. package/dist/_chunks/markdown.mjs +79 -54
  44. package/dist/_chunks/markdown.mjs.map +1 -1
  45. package/dist/_chunks/menu.mjs +33 -0
  46. package/dist/_chunks/menu.mjs.map +1 -0
  47. package/dist/_chunks/model-picker.mjs +61 -0
  48. package/dist/_chunks/model-picker.mjs.map +1 -0
  49. package/dist/_chunks/monorepo.mjs +73 -0
  50. package/dist/_chunks/monorepo.mjs.map +1 -0
  51. package/dist/_chunks/package-json.mjs.map +1 -1
  52. package/dist/_chunks/paths.mjs +47 -0
  53. package/dist/_chunks/paths.mjs.map +1 -0
  54. package/dist/_chunks/pipeline.mjs +985 -0
  55. package/dist/_chunks/pipeline.mjs.map +1 -0
  56. package/dist/_chunks/pool2.mjs +2 -2
  57. package/dist/_chunks/portable.mjs +151 -0
  58. package/dist/_chunks/portable.mjs.map +1 -0
  59. package/dist/_chunks/prepare-hook.mjs +2 -0
  60. package/dist/_chunks/prepare-hook2.mjs +61 -0
  61. package/dist/_chunks/prepare-hook2.mjs.map +1 -0
  62. package/dist/_chunks/prepare.mjs +47 -3
  63. package/dist/_chunks/prepare.mjs.map +1 -1
  64. package/dist/_chunks/prepare2.mjs +9 -8
  65. package/dist/_chunks/prepare2.mjs.map +1 -1
  66. package/dist/_chunks/prompts.mjs +784 -26
  67. package/dist/_chunks/prompts.mjs.map +1 -1
  68. package/dist/_chunks/pull.mjs +219 -0
  69. package/dist/_chunks/pull.mjs.map +1 -0
  70. package/dist/_chunks/regex.mjs +19 -0
  71. package/dist/_chunks/regex.mjs.map +1 -0
  72. package/dist/_chunks/retriv.mjs +2 -171
  73. package/dist/_chunks/retriv2.mjs +159 -0
  74. package/dist/_chunks/retriv2.mjs.map +1 -0
  75. package/dist/_chunks/sanitize.mjs +12 -9
  76. package/dist/_chunks/sanitize.mjs.map +1 -1
  77. package/dist/_chunks/search-helpers.mjs +9 -8
  78. package/dist/_chunks/search-helpers.mjs.map +1 -1
  79. package/dist/_chunks/search-interactive.mjs +23 -20
  80. package/dist/_chunks/search-interactive.mjs.map +1 -1
  81. package/dist/_chunks/search.mjs +3 -4
  82. package/dist/_chunks/search.mjs.map +1 -1
  83. package/dist/_chunks/{sources.mjs → semver.mjs} +1128 -838
  84. package/dist/_chunks/semver.mjs.map +1 -0
  85. package/dist/_chunks/skill-installer.mjs +2 -0
  86. package/dist/_chunks/skill-installer2.mjs +154 -0
  87. package/dist/_chunks/skill-installer2.mjs.map +1 -0
  88. package/dist/_chunks/skills.mjs +12 -12
  89. package/dist/_chunks/skills.mjs.map +1 -1
  90. package/dist/_chunks/store.mjs +107 -0
  91. package/dist/_chunks/store.mjs.map +1 -0
  92. package/dist/_chunks/sync.mjs +761 -1349
  93. package/dist/_chunks/sync.mjs.map +1 -1
  94. package/dist/_chunks/sync2.mjs +2 -3
  95. package/dist/_chunks/telemetry.mjs +26 -0
  96. package/dist/_chunks/telemetry.mjs.map +1 -0
  97. package/dist/_chunks/uninstall.mjs +15 -13
  98. package/dist/_chunks/uninstall.mjs.map +1 -1
  99. package/dist/_chunks/update.mjs +171 -0
  100. package/dist/_chunks/update.mjs.map +1 -0
  101. package/dist/_chunks/upload.mjs +4 -4
  102. package/dist/_chunks/validate.mjs +1 -1
  103. package/dist/_chunks/version.mjs +16 -27
  104. package/dist/_chunks/version.mjs.map +1 -1
  105. package/dist/_chunks/whoami.mjs +21 -0
  106. package/dist/_chunks/whoami.mjs.map +1 -0
  107. package/dist/_chunks/wizard.mjs +2 -190
  108. package/dist/_chunks/wizard2.mjs +200 -0
  109. package/dist/_chunks/wizard2.mjs.map +1 -0
  110. package/dist/cli.mjs +77 -59
  111. package/dist/cli.mjs.map +1 -1
  112. package/dist/prepare.mjs +5 -4
  113. package/dist/prepare.mjs.map +1 -1
  114. package/dist/retriv/worker.d.mts +5 -1
  115. package/dist/retriv/worker.d.mts.map +1 -1
  116. package/dist/retriv/worker.mjs +1 -1
  117. package/package.json +20 -29
  118. package/dist/_chunks/author-group.mjs +0 -17
  119. package/dist/_chunks/author-group.mjs.map +0 -1
  120. package/dist/_chunks/cli-helpers.mjs +0 -335
  121. package/dist/_chunks/cli-helpers.mjs.map +0 -1
  122. package/dist/_chunks/cli-helpers2.mjs +0 -2
  123. package/dist/_chunks/config.mjs +0 -122
  124. package/dist/_chunks/config.mjs.map +0 -1
  125. package/dist/_chunks/index.d.mts +0 -151
  126. package/dist/_chunks/index.d.mts.map +0 -1
  127. package/dist/_chunks/index2.d.mts +0 -44
  128. package/dist/_chunks/index2.d.mts.map +0 -1
  129. package/dist/_chunks/index3.d.mts +0 -589
  130. package/dist/_chunks/index3.d.mts.map +0 -1
  131. package/dist/_chunks/prefix.mjs +0 -108
  132. package/dist/_chunks/prefix.mjs.map +0 -1
  133. package/dist/_chunks/retriv.mjs.map +0 -1
  134. package/dist/_chunks/setup.mjs +0 -17
  135. package/dist/_chunks/setup.mjs.map +0 -1
  136. package/dist/_chunks/shared.mjs +0 -503
  137. package/dist/_chunks/shared.mjs.map +0 -1
  138. package/dist/_chunks/skill.mjs +0 -329
  139. package/dist/_chunks/skill.mjs.map +0 -1
  140. package/dist/_chunks/sources.mjs.map +0 -1
  141. package/dist/_chunks/sync-registry.mjs +0 -59
  142. package/dist/_chunks/sync-registry.mjs.map +0 -1
  143. package/dist/_chunks/sync-shared.mjs +0 -2
  144. package/dist/_chunks/sync-shared2.mjs +0 -1020
  145. package/dist/_chunks/sync-shared2.mjs.map +0 -1
  146. package/dist/_chunks/types.d.mts +0 -88
  147. package/dist/_chunks/types.d.mts.map +0 -1
  148. package/dist/_chunks/wizard.mjs.map +0 -1
  149. package/dist/agent/index.d.mts +0 -346
  150. package/dist/agent/index.d.mts.map +0 -1
  151. package/dist/agent/index.mjs +0 -5
  152. package/dist/cache/index.d.mts +0 -2
  153. package/dist/cache/index.mjs +0 -4
  154. package/dist/index.d.mts +0 -5
  155. package/dist/index.mjs +0 -5
  156. package/dist/retriv/index.d.mts +0 -3
  157. package/dist/retriv/index.mjs +0 -2
  158. package/dist/sources/index.d.mts +0 -2
  159. package/dist/sources/index.mjs +0 -3
  160. package/dist/types.d.mts +0 -4
  161. package/dist/types.mjs +0 -1
@@ -1,26 +1,24 @@
1
- import { a as getModelLabel, r as createToolProgress, s as optimizeDocs } from "./agent.mjs";
2
- import { c as getRepoCacheDir, s as getPackageDbPath, t as getCacheDir } from "./version.mjs";
3
- import { i as readPackageJsonSafe } from "./package-json.mjs";
4
- import { n as linkShippedSkill, r as resolvePkgDir, t as getShippedSkills } from "./prepare.mjs";
5
- import { n as sanitizeMarkdown } from "./sanitize.mjs";
6
- import { a as hasShippedDocs, c as isReadmeOnlyCache, d as linkPkgNamed, h as readCachedDocs, i as getPkgKeyFiles, m as listReferenceFiles, o as inferDocsTypeFromCache, r as ensureCacheDir, s as isCached, v as writeToCache } from "./cache.mjs";
7
- import { r as createIndex, t as SearchDepsUnavailableError } from "./retriv.mjs";
8
- import { n as getSharedSkillsDir } from "./shared.mjs";
9
- import { A as filterFrameworkDocs, E as fetchGitDocs, I as fetchLlmsTxt, P as downloadLlmsDocs, Q as fetchGitHubRaw, R as normalizeLlmsLinks, _ as resolveEntryFiles, d as resolvePackageDocs, j as isShallowGitDocs, k as fetchReadmeContent, m as fetchGitSkills, rt as parseGitHubUrl } from "./sources.mjs";
10
1
  import { a as targets } from "./detect.mjs";
11
- import { _ as timedSpinner, n as writeGeneratedSkillMd, o as linkSkillToAgents, r as writeSkillMd } from "./skill.mjs";
12
- import { a as readConfig, t as defaultFeatures } from "./config.mjs";
13
- import { _ as promptForAgent, b as resolveAgent, x as sharedArgs } from "./cli-helpers.mjs";
14
- import { a as readLock, c as writeLock, n as parsePackageNames, r as parsePackages, s as syncLockfilesToDirs, t as mergeLocks } from "./lockfile.mjs";
15
- import { r as toStoragePackageName } from "./prefix.mjs";
16
- import { S as writePromptFiles, a as classifyCachedDoc, b as selectLlmConfig, g as indexResources } from "./sync-shared2.mjs";
2
+ import { i as getModelLabel } from "./agent.mjs";
3
+ import { h as timedSpinner, i as linkSkillToAgents, n as writeSkillMd } from "./prompts.mjs";
4
+ import { f as getSharedSkillsDir, m as skillInternalDir } from "./paths.mjs";
5
+ import { n as sanitizeMarkdown } from "./sanitize.mjs";
6
+ import { a as resolvePkgDir, i as linkShippedSkill, n as getShippedSkills, s as getCacheDir } from "./prepare.mjs";
7
+ import { i as readPackageJsonSafe } from "./package-json.mjs";
8
+ import { d as readConfig, o as defaultFeatures, r as ensureCacheDir, t as createReferenceCache } from "./cache.mjs";
9
+ import { n as promptForAgent, r as resolveAgent } from "./agent-prompt.mjs";
10
+ import { t as sharedArgs } from "./args.mjs";
11
+ import { _ as fetchGitSkills, a as resolvePackageDocs, l as toStoragePackageName } from "./semver.mjs";
12
+ import { a as parsePackageNames, c as readLock, d as writeLock, i as mergeLocks, o as parsePackages, u as syncLockfilesToDirs } from "./lockfile.mjs";
13
+ import { a as prepareSkillReferences, c as selectLlmConfig, f as writeBaseSkill, p as writePromptFiles, r as fetchAndCacheResources, t as buildSkillContext, u as enhanceSkillWithLLM } from "./pipeline.mjs";
17
14
  import { n as shutdownWorker } from "./pool2.mjs";
18
- import "./sync.mjs";
19
- import { homedir } from "node:os";
20
- import { dirname, join } from "pathe";
21
- import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
15
+ import { copyFileSync, existsSync, lstatSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
16
+ import { styleText } from "node:util";
22
17
  import * as p from "@clack/prompts";
23
18
  import { defineCommand } from "citty";
19
+ import { dirname, join } from "pathe";
20
+ import { homedir } from "node:os";
21
+ const STATIC_REGEX_1 = /ungh:\/\/([^/]+)\/(.+)/;
24
22
  async function installCommand(opts) {
25
23
  const cwd = process.cwd();
26
24
  const agent = targets[opts.agent];
@@ -46,7 +44,7 @@ async function installCommand(opts) {
46
44
  continue;
47
45
  }
48
46
  const skillDir = join(skillsDir, name);
49
- const referencesPath = join(skillDir, ".skilld");
47
+ const referencesPath = skillInternalDir(skillDir);
50
48
  const skillMdPath = join(skillDir, "SKILL.md");
51
49
  if (!existsSync(skillDir) || !existsSync(skillMdPath) || !existsSync(referencesPath) || hasStaleReferences(referencesPath, toStoragePackageName(info.packageName || name), info.version, features)) toRestore.push({
52
50
  name,
@@ -59,11 +57,11 @@ async function installCommand(opts) {
59
57
  }
60
58
  p.log.info(`Restoring ${toRestore.length} references`);
61
59
  ensureCacheDir();
62
- const allSkillNames = skills.map(([, info]) => info.packageName || "").filter(Boolean);
63
60
  const regenerated = [];
64
61
  for (const { name, info } of toRestore) {
65
62
  const version = info.version;
66
- const pkgName = toStoragePackageName(info.packageName || unsanitizeName(name, info.source));
63
+ const identityName = info.packageName || unsanitizeName(name, info.source);
64
+ const pkgName = toStoragePackageName(identityName);
67
65
  if (info.source === "shipped") {
68
66
  const match = getShippedSkills(pkgName, cwd, version).find((s) => s.skillName === name);
69
67
  if (match) {
@@ -97,260 +95,75 @@ async function installCommand(opts) {
97
95
  continue;
98
96
  }
99
97
  const skillDir = join(skillsDir, name);
100
- const referencesPath = join(skillDir, ".skilld");
101
- const globalCachePath = getCacheDir(pkgName, version);
98
+ const cache = createReferenceCache(pkgName, version);
102
99
  const spin = timedSpinner();
103
- if (isCached(pkgName, version)) {
104
- spin.start(`Linking ${name}`);
105
- mkdirSync(skillDir, { recursive: true });
106
- mkdirSync(referencesPath, { recursive: true });
107
- linkPkgSymlink(referencesPath, pkgName, cwd, version);
108
- for (const pkg of parsePackages(info.packages)) linkPkgNamed(skillDir, pkg.name, cwd, pkg.version);
109
- if (!pkgHasShippedDocs(pkgName, cwd, version) && !isReadmeOnlyCache(globalCachePath)) {
110
- const docsLink = join(referencesPath, "docs");
111
- const cachedDocs = join(globalCachePath, "docs");
112
- if (existsSync(docsLink)) unlinkSync(docsLink);
113
- if (existsSync(cachedDocs)) symlinkSync(cachedDocs, docsLink, "junction");
114
- }
115
- const repoGh = info.repo ? parseGitHubUrl(`https://github.com/${info.repo}`) : null;
116
- const repoCachePath = repoGh ? getRepoCacheDir(repoGh.owner, repoGh.repo) : null;
117
- if (features.issues) {
118
- const issuesLink = join(referencesPath, "issues");
119
- const repoIssues = repoCachePath ? join(repoCachePath, "issues") : null;
120
- const cachedIssues = repoIssues && existsSync(repoIssues) ? repoIssues : join(globalCachePath, "issues");
121
- if (existsSync(issuesLink)) unlinkSync(issuesLink);
122
- if (existsSync(cachedIssues)) symlinkSync(cachedIssues, issuesLink, "junction");
123
- }
124
- if (features.discussions) {
125
- const discussionsLink = join(referencesPath, "discussions");
126
- const repoDiscussions = repoCachePath ? join(repoCachePath, "discussions") : null;
127
- const cachedDiscussions = repoDiscussions && existsSync(repoDiscussions) ? repoDiscussions : join(globalCachePath, "discussions");
128
- if (existsSync(discussionsLink)) unlinkSync(discussionsLink);
129
- if (existsSync(cachedDiscussions)) symlinkSync(cachedDiscussions, discussionsLink, "junction");
130
- }
131
- if (features.releases) {
132
- const releasesLink = join(referencesPath, "releases");
133
- const repoReleases = repoCachePath ? join(repoCachePath, "releases") : null;
134
- const cachedReleases = repoReleases && existsSync(repoReleases) ? repoReleases : join(globalCachePath, "releases");
135
- if (existsSync(releasesLink)) unlinkSync(releasesLink);
136
- if (existsSync(cachedReleases)) symlinkSync(cachedReleases, releasesLink, "junction");
137
- }
138
- const sectionsLink = join(referencesPath, "sections");
139
- const cachedSections = join(globalCachePath, "sections");
140
- if (existsSync(sectionsLink)) unlinkSync(sectionsLink);
141
- if (existsSync(cachedSections)) symlinkSync(cachedSections, sectionsLink, "junction");
142
- if (features.search && !existsSync(getPackageDbPath(pkgName, version))) {
143
- spin.message(`Indexing ${name}`);
144
- await indexResources({
145
- packageName: pkgName,
146
- version,
147
- cwd,
148
- docsToIndex: readCachedDocs(pkgName, version).map((d) => ({
149
- id: d.path,
150
- content: d.content,
151
- metadata: {
152
- package: pkgName,
153
- source: d.path,
154
- type: classifyCachedDoc(d.path).type
155
- }
156
- })),
157
- features,
158
- onProgress: (msg) => spin.message(msg)
159
- });
160
- }
161
- if (!copyFromExistingAgent(skillDir, name, allSkillsDirs)) {
162
- if (regenerateBaseSkillMd(skillDir, pkgName, version, cwd, allSkillNames, info.source, info.packages)) regenerated.push({
163
- name,
164
- pkgName,
165
- version,
166
- skillDir,
167
- packages: info.packages
168
- });
169
- }
170
- spin.stop(`Linked ${name}`);
171
- continue;
172
- }
173
- spin.start(`Downloading ${name}@${version}`);
174
- const resolved = await resolvePackageDocs(pkgName, { version });
100
+ const wasCacheHit = cache.has();
101
+ spin.start(wasCacheHit ? `Linking ${name}` : `Downloading ${name}@${version}`);
102
+ mkdirSync(skillDir, { recursive: true });
103
+ const resolved = wasCacheHit ? synthesizeResolved(identityName, version, info, cwd) : await resolvePackageDocs(pkgName, { version });
175
104
  if (!resolved) {
176
105
  spin.stop(`Could not resolve: ${name}`);
177
106
  continue;
178
107
  }
179
- const cachedDocs = [];
180
- const docsToIndex = [];
181
- const isFrameworkDoc = (path) => filterFrameworkDocs([path], pkgName).length > 0;
182
- if (resolved.gitDocsUrl && resolved.repoUrl) {
183
- const gh = parseGitHubUrl(resolved.repoUrl);
184
- if (gh) {
185
- const gitDocs = await fetchGitDocs(gh.owner, gh.repo, version, pkgName);
186
- if (gitDocs?.files.length) {
187
- const BATCH_SIZE = 20;
188
- for (let i = 0; i < gitDocs.files.length; i += BATCH_SIZE) {
189
- const batch = gitDocs.files.slice(i, i + BATCH_SIZE);
190
- const results = await Promise.all(batch.map(async (file) => {
191
- const content = await fetchGitHubRaw(`${gitDocs.baseUrl}/${file}`);
192
- if (!content) return null;
193
- return {
194
- file,
195
- content
196
- };
197
- }));
198
- for (const r of results) if (r) {
199
- const stripped = gitDocs.docsPrefix ? r.file.replace(gitDocs.docsPrefix, "") : r.file;
200
- const cachePath = stripped.startsWith("docs/") ? stripped : `docs/${stripped}`;
201
- cachedDocs.push({
202
- path: cachePath,
203
- content: r.content
204
- });
205
- docsToIndex.push({
206
- id: cachePath,
207
- content: r.content,
208
- metadata: {
209
- package: pkgName,
210
- source: cachePath,
211
- type: "doc"
212
- }
213
- });
214
- }
215
- }
216
- if (isShallowGitDocs(cachedDocs.length) && resolved.llmsUrl) {
217
- cachedDocs.length = 0;
218
- docsToIndex.length = 0;
219
- } else if (cachedDocs.length > 0 && resolved.llmsUrl) {
220
- const llmsContent = await fetchLlmsTxt(resolved.llmsUrl);
221
- if (llmsContent) {
222
- const baseUrl = resolved.docsUrl || new URL(resolved.llmsUrl).origin;
223
- cachedDocs.push({
224
- path: "llms.txt",
225
- content: normalizeLlmsLinks(llmsContent.raw)
226
- });
227
- if (llmsContent.links.length > 0) {
228
- const docs = await downloadLlmsDocs(llmsContent, baseUrl);
229
- for (const doc of docs) {
230
- if (!isFrameworkDoc(doc.url)) continue;
231
- const localPath = doc.url.startsWith("/") ? doc.url.slice(1) : doc.url;
232
- cachedDocs.push({
233
- path: join("llms-docs", ...localPath.split("/")),
234
- content: doc.content
235
- });
236
- }
237
- }
238
- }
239
- }
240
- }
241
- }
242
- }
243
- if (resolved.llmsUrl && cachedDocs.length === 0) {
244
- const llmsContent = await fetchLlmsTxt(resolved.llmsUrl);
245
- if (llmsContent) {
246
- cachedDocs.push({
247
- path: "llms.txt",
248
- content: normalizeLlmsLinks(llmsContent.raw)
249
- });
250
- if (llmsContent.links.length > 0) {
251
- const docs = await downloadLlmsDocs(llmsContent, resolved.docsUrl || new URL(resolved.llmsUrl).origin);
252
- for (const doc of docs) {
253
- if (!isFrameworkDoc(doc.url)) continue;
254
- const cachePath = join("docs", ...(doc.url.startsWith("/") ? doc.url.slice(1) : doc.url).split("/"));
255
- cachedDocs.push({
256
- path: cachePath,
257
- content: doc.content
258
- });
259
- docsToIndex.push({
260
- id: doc.url,
261
- content: doc.content,
262
- metadata: {
263
- package: pkgName,
264
- source: cachePath,
265
- type: "doc"
266
- }
267
- });
268
- }
269
- }
270
- }
271
- }
272
- if (resolved.readmeUrl && cachedDocs.length === 0) {
273
- const content = await fetchReadmeContent(resolved.readmeUrl);
274
- if (content) {
275
- cachedDocs.push({
276
- path: "docs/README.md",
277
- content
278
- });
279
- docsToIndex.push({
280
- id: "README.md",
281
- content,
282
- metadata: {
283
- package: pkgName,
284
- source: "docs/README.md",
285
- type: "doc"
286
- }
287
- });
288
- }
108
+ const resources = await fetchAndCacheResources({
109
+ packageName: pkgName,
110
+ resolved,
111
+ version,
112
+ useCache: wasCacheHit,
113
+ features,
114
+ onProgress: (msg) => spin.message(msg)
115
+ });
116
+ for (const w of resources.warnings) p.log.warn(`${name}: ${w}`);
117
+ if (!cache.has()) {
118
+ spin.stop(`No docs found for ${name}`);
119
+ continue;
289
120
  }
290
- if (cachedDocs.length > 0) {
291
- writeToCache(pkgName, version, cachedDocs);
292
- mkdirSync(referencesPath, { recursive: true });
293
- linkPkgSymlink(referencesPath, pkgName, cwd, version);
294
- for (const pkg of parsePackages(info.packages)) linkPkgNamed(skillDir, pkg.name, cwd, pkg.version);
295
- if (!isReadmeOnlyCache(globalCachePath)) {
296
- const docsLink = join(referencesPath, "docs");
297
- const cachedDocsDir = join(globalCachePath, "docs");
298
- if (existsSync(docsLink)) unlinkSync(docsLink);
299
- if (existsSync(cachedDocsDir)) symlinkSync(cachedDocsDir, docsLink, "junction");
300
- }
301
- if (features.search) try {
302
- if (docsToIndex.length > 0) await createIndex(docsToIndex, { dbPath: getPackageDbPath(pkgName, version) });
303
- const pkgDir = resolvePkgDir(pkgName, cwd, version);
304
- const entryFiles = pkgDir ? await resolveEntryFiles(pkgDir) : [];
305
- if (entryFiles.length > 0) await createIndex(entryFiles.map((e) => ({
306
- id: e.path,
307
- content: e.content,
308
- metadata: {
309
- package: pkgName,
310
- source: `pkg/${e.path}`,
311
- type: e.type
312
- }
313
- })), { dbPath: getPackageDbPath(pkgName, version) });
314
- } catch (err) {
315
- if (!(err instanceof SearchDepsUnavailableError)) throw err;
316
- }
317
- if (!copyFromExistingAgent(skillDir, name, allSkillsDirs)) {
318
- if (regenerateBaseSkillMd(skillDir, pkgName, version, cwd, allSkillNames, info.source, info.packages)) regenerated.push({
121
+ const ctx = buildSkillContext({
122
+ packageName: identityName,
123
+ cachePackageName: pkgName,
124
+ version,
125
+ skillDir,
126
+ skillDirName: name,
127
+ resources,
128
+ prepared: await prepareSkillReferences({
129
+ packageName: pkgName,
130
+ version,
131
+ cwd,
132
+ skillDir,
133
+ resources,
134
+ features,
135
+ baseDir: skillsDir,
136
+ extraPackages: parsePackages(info.packages),
137
+ onIndexProgress: (msg) => spin.message(msg)
138
+ }),
139
+ resolved,
140
+ packages: parsePackageNames(info.packages),
141
+ features
142
+ });
143
+ if (!copyFromExistingAgent(skillDir, name, allSkillsDirs)) {
144
+ if (!existsSync(join(skillDir, "SKILL.md"))) {
145
+ writeBaseSkill(ctx);
146
+ regenerated.push({
319
147
  name,
320
- pkgName,
321
- version,
322
- skillDir,
323
- packages: info.packages
148
+ ctx
324
149
  });
325
150
  }
326
- spin.stop(`Downloaded and linked ${name}`);
327
- } else spin.stop(`No docs found for ${name}`);
151
+ }
152
+ spin.stop(wasCacheHit ? `Linked ${name}` : `Downloaded and linked ${name}`);
328
153
  }
329
154
  if (regenerated.length > 0 && !readConfig().skipLlm) {
330
155
  const llmConfig = await selectLlmConfig(void 0, `Enhance SKILL.md for ${regenerated.map((r) => r.name).join(", ")}`);
331
- if (llmConfig?.promptOnly) {
332
- const features = readConfig().features ?? defaultFeatures;
333
- for (const { pkgName, version, skillDir } of regenerated) {
334
- const globalCachePath = getCacheDir(pkgName, version);
335
- writePromptFiles({
336
- packageName: pkgName,
337
- skillDir,
338
- version,
339
- hasIssues: existsSync(join(globalCachePath, "issues")),
340
- hasDiscussions: existsSync(join(globalCachePath, "discussions")),
341
- hasReleases: existsSync(join(globalCachePath, "releases")),
342
- hasChangelog: false,
343
- docsType: "docs",
344
- hasShippedDocs: false,
345
- pkgFiles: getPkgKeyFiles(pkgName, process.cwd(), version),
346
- sections: llmConfig.sections,
347
- customPrompt: llmConfig.customPrompt,
348
- features
349
- });
350
- }
351
- } else if (llmConfig) {
156
+ if (llmConfig?.promptOnly) for (const { ctx } of regenerated) writePromptFiles(ctx, {
157
+ sections: llmConfig.sections,
158
+ customPrompt: llmConfig.customPrompt
159
+ });
160
+ else if (llmConfig) {
352
161
  p.log.step(getModelLabel(llmConfig.model));
353
- for (const { pkgName, version, skillDir, packages: pkgPackages } of regenerated) await enhanceRegenerated(pkgName, version, skillDir, llmConfig.model, llmConfig.sections, llmConfig.customPrompt, pkgPackages);
162
+ for (const { ctx } of regenerated) await enhanceSkillWithLLM(ctx, {
163
+ model: llmConfig.model,
164
+ sections: llmConfig.sections,
165
+ customPrompt: llmConfig.customPrompt
166
+ });
354
167
  }
355
168
  }
356
169
  for (const [name, info] of Object.entries(lock.skills)) writeLock(skillsDir, name, info);
@@ -375,7 +188,7 @@ function copyFromExistingAgent(skillDir, name, allSkillsDirs) {
375
188
  }
376
189
  function unsanitizeName(sanitized, source) {
377
190
  if (source?.includes("ungh://")) {
378
- const match = source.match(/ungh:\/\/([^/]+)\/(.+)/);
191
+ const match = source.match(STATIC_REGEX_1);
379
192
  if (match) return `@${match[1]}/${match[2]}`;
380
193
  }
381
194
  if (sanitized.startsWith("antfu-")) return `@antfu/${sanitized.slice(6)}`;
@@ -385,78 +198,15 @@ function unsanitizeName(sanitized, source) {
385
198
  if (sanitized.startsWith("vueuse-")) return `@vueuse/${sanitized.slice(7)}`;
386
199
  return sanitized;
387
200
  }
388
- function linkPkgSymlink(referencesDir, name, cwd, version) {
389
- const pkgPath = resolvePkgDir(name, cwd, version);
390
- if (!pkgPath) return;
391
- const pkgLink = join(referencesDir, "pkg");
392
- if (existsSync(pkgLink)) unlinkSync(pkgLink);
393
- symlinkSync(pkgPath, pkgLink, "junction");
394
- }
395
- function pkgHasShippedDocs(name, cwd, version) {
396
- const pkgPath = resolvePkgDir(name, cwd, version);
397
- if (!pkgPath) return false;
398
- for (const candidate of [
399
- "docs",
400
- "documentation",
401
- "doc"
402
- ]) if (existsSync(join(pkgPath, candidate))) return true;
403
- return false;
404
- }
405
- async function enhanceRegenerated(pkgName, version, skillDir, model, sections, customPrompt, packages) {
406
- const llmLog = p.taskLog({
407
- title: `Agent exploring ${pkgName}`,
408
- limit: 3
409
- });
410
- const docFiles = listReferenceFiles(skillDir);
411
- const globalCachePath = getCacheDir(pkgName, version);
412
- const hasIssues = existsSync(join(globalCachePath, "issues"));
413
- const hasDiscussions = existsSync(join(globalCachePath, "discussions"));
414
- const hasGithub = hasIssues || hasDiscussions;
415
- const hasReleases = existsSync(join(globalCachePath, "releases"));
416
- const features = readConfig().features ?? defaultFeatures;
417
- const { optimized, wasOptimized } = await optimizeDocs({
418
- packageName: pkgName,
419
- skillDir,
420
- model,
201
+ function synthesizeResolved(identityName, version, info, cwd) {
202
+ const repoUrl = info.repo?.includes("/") ? `https://github.com/${info.repo}` : void 0;
203
+ const pkgPath = resolvePkgDir(toStoragePackageName(identityName), cwd, version);
204
+ return {
205
+ name: identityName,
421
206
  version,
422
- hasGithub,
423
- hasReleases,
424
- docFiles,
425
- sections,
426
- customPrompt,
427
- features,
428
- pkgFiles: getPkgKeyFiles(pkgName, process.cwd(), version),
429
- onProgress: createToolProgress(llmLog)
430
- });
431
- if (wasOptimized) {
432
- llmLog.success("Generated best practices");
433
- const cwd = process.cwd();
434
- const pkgPath = resolvePkgDir(pkgName, cwd, version);
435
- let description;
436
- if (pkgPath) {
437
- const pkgJsonResult = readPackageJsonSafe(join(pkgPath, "package.json"));
438
- if (pkgJsonResult) description = pkgJsonResult.parsed.description;
439
- }
440
- const docsType = inferDocsTypeFromCache(globalCachePath);
441
- const dirName = skillDir.split("/").pop();
442
- const allPackages = parsePackageNames(packages);
443
- writeGeneratedSkillMd(skillDir, {
444
- name: pkgName,
445
- version,
446
- description,
447
- body: optimized,
448
- relatedSkills: [],
449
- hasIssues,
450
- hasDiscussions,
451
- hasReleases,
452
- docsType,
453
- hasShippedDocs: hasShippedDocs(pkgName, cwd, version),
454
- pkgFiles: getPkgKeyFiles(pkgName, cwd, version),
455
- dirName,
456
- packages: allPackages.length > 1 ? allPackages : void 0,
457
- features
458
- });
459
- } else llmLog.message("Enhancement skipped");
207
+ repoUrl,
208
+ description: pkgPath ? readPackageJsonSafe(join(pkgPath, "package.json"))?.parsed.description : void 0
209
+ };
460
210
  }
461
211
  const installCommandDef = defineCommand({
462
212
  meta: {
@@ -475,48 +225,13 @@ const installCommandDef = defineCommand({
475
225
  if (!picked || picked === "none") return;
476
226
  agent = picked;
477
227
  }
478
- p.intro(`\x1B[1m\x1B[35mskilld\x1B[0m install`);
228
+ p.intro(`${styleText(["bold", "magenta"], "skilld")} install`);
479
229
  return installCommand({
480
230
  global: args.global,
481
231
  agent
482
232
  });
483
233
  }
484
234
  });
485
- function regenerateBaseSkillMd(skillDir, pkgName, version, cwd, allSkillNames, source, packages) {
486
- if (existsSync(join(skillDir, "SKILL.md"))) return false;
487
- const pkgPath = resolvePkgDir(pkgName, cwd, version);
488
- let description;
489
- if (pkgPath) {
490
- const pkgResult = readPackageJsonSafe(join(pkgPath, "package.json"));
491
- if (pkgResult) description = pkgResult.parsed.description;
492
- }
493
- const globalCachePath = getCacheDir(pkgName, version);
494
- const docsType = inferDocsTypeFromCache(globalCachePath, source);
495
- const feat = readConfig().features ?? defaultFeatures;
496
- const hasIssues = feat.issues && existsSync(join(globalCachePath, "issues"));
497
- const hasDiscussions = feat.discussions && existsSync(join(globalCachePath, "discussions"));
498
- const hasReleases = feat.releases && existsSync(join(globalCachePath, "releases"));
499
- const relatedSkills = allSkillNames.filter((n) => n !== pkgName);
500
- const dirName = skillDir.split("/").pop();
501
- const allPackages = parsePackageNames(packages);
502
- mkdirSync(skillDir, { recursive: true });
503
- writeGeneratedSkillMd(skillDir, {
504
- name: pkgName,
505
- version,
506
- description,
507
- relatedSkills,
508
- hasIssues,
509
- hasDiscussions,
510
- hasReleases,
511
- docsType,
512
- hasShippedDocs: hasShippedDocs(pkgName, cwd, version),
513
- pkgFiles: getPkgKeyFiles(pkgName, cwd, version),
514
- dirName,
515
- packages: allPackages.length > 1 ? allPackages : void 0,
516
- features: readConfig().features ?? defaultFeatures
517
- });
518
- return true;
519
- }
520
235
  function hasStaleReferences(referencesPath, pkgName, version, features) {
521
236
  for (const entry of readdirSync(referencesPath)) {
522
237
  const entryPath = join(referencesPath, entry);