skilld 1.7.2 → 1.7.4

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 (118) hide show
  1. package/dist/_chunks/agent.mjs +693 -599
  2. package/dist/_chunks/agent.mjs.map +1 -1
  3. package/dist/_chunks/assemble.mjs +3 -3
  4. package/dist/_chunks/assemble.mjs.map +1 -1
  5. package/dist/_chunks/author-group.mjs.map +1 -1
  6. package/dist/_chunks/author.mjs +51 -121
  7. package/dist/_chunks/author.mjs.map +1 -1
  8. package/dist/_chunks/cache.mjs +315 -9
  9. package/dist/_chunks/cache.mjs.map +1 -1
  10. package/dist/_chunks/cache2.mjs +2 -2
  11. package/dist/_chunks/cache2.mjs.map +1 -1
  12. package/dist/_chunks/cli-helpers.mjs +3 -3
  13. package/dist/_chunks/cli-helpers.mjs.map +1 -1
  14. package/dist/_chunks/core.mjs +7 -4
  15. package/dist/_chunks/detect.mjs +1 -1
  16. package/dist/_chunks/detect.mjs.map +1 -1
  17. package/dist/_chunks/embedding-cache2.mjs +2 -2
  18. package/dist/_chunks/embedding-cache2.mjs.map +1 -1
  19. package/dist/_chunks/index.d.mts +305 -112
  20. package/dist/_chunks/index.d.mts.map +1 -1
  21. package/dist/_chunks/index2.d.mts +267 -32
  22. package/dist/_chunks/index2.d.mts.map +1 -1
  23. package/dist/_chunks/index3.d.mts +32 -577
  24. package/dist/_chunks/index3.d.mts.map +1 -1
  25. package/dist/_chunks/index4.d.mts +553 -0
  26. package/dist/_chunks/index4.d.mts.map +1 -0
  27. package/dist/_chunks/install.mjs +48 -88
  28. package/dist/_chunks/install.mjs.map +1 -1
  29. package/dist/_chunks/list.mjs +1 -1
  30. package/dist/_chunks/list.mjs.map +1 -1
  31. package/dist/_chunks/lockfile.mjs +29 -6
  32. package/dist/_chunks/lockfile.mjs.map +1 -1
  33. package/dist/_chunks/markdown.mjs.map +1 -1
  34. package/dist/_chunks/monorepo.mjs +71 -0
  35. package/dist/_chunks/monorepo.mjs.map +1 -0
  36. package/dist/_chunks/package-json.mjs.map +1 -1
  37. package/dist/_chunks/{shared.mjs → package-registry.mjs} +2 -40
  38. package/dist/_chunks/package-registry.mjs.map +1 -0
  39. package/dist/_chunks/paths.mjs +49 -0
  40. package/dist/_chunks/paths.mjs.map +1 -0
  41. package/dist/_chunks/pool2.mjs +7 -2
  42. package/dist/_chunks/pool2.mjs.map +1 -1
  43. package/dist/_chunks/prepare.mjs +1 -1
  44. package/dist/_chunks/prepare.mjs.map +1 -1
  45. package/dist/_chunks/prepare2.mjs +5 -5
  46. package/dist/_chunks/prepare2.mjs.map +1 -1
  47. package/dist/_chunks/prompts.mjs +366 -18
  48. package/dist/_chunks/prompts.mjs.map +1 -1
  49. package/dist/_chunks/retriv.mjs.map +1 -1
  50. package/dist/_chunks/sanitize.mjs.map +1 -1
  51. package/dist/_chunks/search-helpers.mjs +5 -6
  52. package/dist/_chunks/search-helpers.mjs.map +1 -1
  53. package/dist/_chunks/search-interactive.mjs +1 -1
  54. package/dist/_chunks/search-interactive.mjs.map +1 -1
  55. package/dist/_chunks/search.mjs +1 -2
  56. package/dist/_chunks/search.mjs.map +1 -1
  57. package/dist/_chunks/semver.mjs +13 -0
  58. package/dist/_chunks/semver.mjs.map +1 -0
  59. package/dist/_chunks/setup.mjs.map +1 -1
  60. package/dist/_chunks/skill-installer.mjs +2 -0
  61. package/dist/_chunks/skill-installer2.mjs +155 -0
  62. package/dist/_chunks/skill-installer2.mjs.map +1 -0
  63. package/dist/_chunks/skills.mjs +10 -9
  64. package/dist/_chunks/skills.mjs.map +1 -1
  65. package/dist/_chunks/sources.mjs +575 -386
  66. package/dist/_chunks/sources.mjs.map +1 -1
  67. package/dist/_chunks/sync-pipeline.mjs +952 -0
  68. package/dist/_chunks/sync-pipeline.mjs.map +1 -0
  69. package/dist/_chunks/sync-registry.mjs +19 -13
  70. package/dist/_chunks/sync-registry.mjs.map +1 -1
  71. package/dist/_chunks/sync.mjs +797 -886
  72. package/dist/_chunks/sync.mjs.map +1 -1
  73. package/dist/_chunks/sync2.mjs +4 -2
  74. package/dist/_chunks/types.d.mts +65 -77
  75. package/dist/_chunks/types.d.mts.map +1 -1
  76. package/dist/_chunks/types2.d.mts +88 -0
  77. package/dist/_chunks/types2.d.mts.map +1 -0
  78. package/dist/_chunks/uninstall.mjs +7 -8
  79. package/dist/_chunks/uninstall.mjs.map +1 -1
  80. package/dist/_chunks/upload.mjs +2 -2
  81. package/dist/_chunks/upload.mjs.map +1 -1
  82. package/dist/_chunks/validate.mjs +1 -1
  83. package/dist/_chunks/validate.mjs.map +1 -1
  84. package/dist/_chunks/version.mjs +3 -13
  85. package/dist/_chunks/version.mjs.map +1 -1
  86. package/dist/_chunks/wizard.mjs +2 -2
  87. package/dist/_chunks/wizard.mjs.map +1 -1
  88. package/dist/_chunks/yaml.mjs.map +1 -1
  89. package/dist/agent/index.d.mts +2 -346
  90. package/dist/agent/index.mjs +2 -3
  91. package/dist/cache/index.d.mts +2 -2
  92. package/dist/cache/index.mjs +4 -3
  93. package/dist/cli.mjs +12 -13
  94. package/dist/cli.mjs.map +1 -1
  95. package/dist/index.d.mts +5 -4
  96. package/dist/index.mjs +4 -3
  97. package/dist/prepare.mjs +2 -2
  98. package/dist/prepare.mjs.map +1 -1
  99. package/dist/retriv/index.d.mts +2 -2
  100. package/dist/retriv/worker.d.mts +2 -1
  101. package/dist/retriv/worker.d.mts.map +1 -1
  102. package/dist/retriv/worker.mjs +2 -1
  103. package/dist/retriv/worker.mjs.map +1 -1
  104. package/dist/sources/index.d.mts +3 -2
  105. package/dist/sources/index.mjs +3 -3
  106. package/dist/types.d.mts +3 -3
  107. package/package.json +5 -5
  108. package/dist/_chunks/config.mjs +0 -122
  109. package/dist/_chunks/config.mjs.map +0 -1
  110. package/dist/_chunks/prefix.mjs +0 -108
  111. package/dist/_chunks/prefix.mjs.map +0 -1
  112. package/dist/_chunks/shared.mjs.map +0 -1
  113. package/dist/_chunks/skill.mjs +0 -329
  114. package/dist/_chunks/skill.mjs.map +0 -1
  115. package/dist/_chunks/sync-shared.mjs +0 -2
  116. package/dist/_chunks/sync-shared2.mjs +0 -1020
  117. package/dist/_chunks/sync-shared2.mjs.map +0 -1
  118. package/dist/agent/index.d.mts.map +0 -1
@@ -0,0 +1,952 @@
1
+ import { l as getPackageDbPath, p as skillInternalDir, u as getRepoCacheDir } from "./paths.mjs";
2
+ import { L as updateConfig, P as readConfig, b as writeToRepoCache, h as listReferenceFiles, k as defaultFeatures, t as createReferenceCache, y as writeToCache } from "./cache.mjs";
3
+ import { t as getCacheDir } from "./version.mjs";
4
+ import { r as resolvePkgDir } from "./prepare.mjs";
5
+ import { n as sanitizeMarkdown } from "./sanitize.mjs";
6
+ import { i as parseFrontmatter } from "./markdown.mjs";
7
+ import { o as listIndexIds, r as createIndex, t as SearchDepsUnavailableError } from "./retriv.mjs";
8
+ import { o as getPrereleaseChangelogRef, t as getBlogPreset } from "./package-registry.mjs";
9
+ import { $ as fetchReleaseNotes, C as resolveEntryFiles, D as generateDiscussionIndex, E as formatDiscussionAsMarkdown, F as downloadLlmsDocs, H as formatIssueAsMarkdown, J as isShallowGitDocs, K as fetchGitDocs, L as fetchLlmsTxt, N as fetchReadmeContent, O as fetchCrawledDocs, T as fetchGitHubDiscussions, U as generateIssueIndex, V as fetchGitHubIssues, W as isGhAvailable, Z as fetchBlogReleases, at as fetchGitHubRaw, et as generateReleaseIndex, k as toCrawlPattern, q as filterFrameworkDocs, s as fetchNpmPackage, tt as isPrerelease, ut as parseGitHubUrl, w as generateDocsIndex, z as normalizeLlmsLinks } from "./sources.mjs";
10
+ import { a as getModelName, i as getModelLabel, o as createToolProgress, r as getAvailableModels, t as optimizeDocs } from "./agent.mjs";
11
+ import { D as maxItems, E as SECTION_OUTPUT_FILES, O as maxLines, T as SECTION_MERGE_ORDER, n as writeGeneratedSkillMd, w as wrapSection, y as buildAllSectionPrompts } from "./prompts.mjs";
12
+ import { g as pickModel, n as NO_MODELS_MESSAGE, p as isInteractive } from "./cli-helpers.mjs";
13
+ import { c as readLock, t as buildPackageDirMap } from "./lockfile.mjs";
14
+ import { t as semverDiff } from "./semver.mjs";
15
+ import { existsSync, mkdirSync, readdirSync, writeFileSync } from "node:fs";
16
+ import { join, relative } from "pathe";
17
+ import * as p from "@clack/prompts";
18
+ const RATE_LIMIT_RE = /\b429\b|rate.?limit|exhausted.*capacity|quota.*reset/i;
19
+ async function runSkillEnhancement(ctx, run, onProgress) {
20
+ const { packageName, cachePackageName, version, skillDir, dirName, resolved, relatedSkills, references, packages, features, overheadLines } = ctx;
21
+ const { docsType, hasShippedDocs: shippedDocs, pkgFiles, hasIssues, hasDiscussions, hasReleases, hasChangelog } = references;
22
+ const { model, force, debug, sections, customPrompt, eject } = run;
23
+ const cacheKey = cachePackageName || packageName;
24
+ const docFiles = listReferenceFiles(skillDir);
25
+ const result = await optimizeDocs({
26
+ packageName: cacheKey,
27
+ skillDir,
28
+ model,
29
+ version,
30
+ hasGithub: hasIssues || hasDiscussions,
31
+ hasReleases,
32
+ hasChangelog,
33
+ docFiles,
34
+ docsType,
35
+ hasShippedDocs: shippedDocs,
36
+ noCache: force,
37
+ debug,
38
+ sections,
39
+ customPrompt,
40
+ features,
41
+ pkgFiles,
42
+ overheadLines,
43
+ onProgress
44
+ });
45
+ if (result.wasOptimized) writeGeneratedSkillMd(skillDir, {
46
+ name: packageName,
47
+ version,
48
+ releasedAt: resolved.releasedAt,
49
+ distTags: resolved.distTags,
50
+ body: result.optimized,
51
+ relatedSkills,
52
+ hasIssues,
53
+ hasDiscussions,
54
+ hasReleases,
55
+ hasChangelog,
56
+ docsType,
57
+ hasShippedDocs: shippedDocs,
58
+ pkgFiles,
59
+ generatedBy: getModelLabel(model),
60
+ dirName,
61
+ packages,
62
+ repoUrl: resolved.repoUrl,
63
+ features,
64
+ eject
65
+ });
66
+ return result;
67
+ }
68
+ async function enhanceSkillWithLLM(ctx, run) {
69
+ const llmLog = p.taskLog({
70
+ title: `Agent exploring ${ctx.packageName}`,
71
+ limit: 3
72
+ });
73
+ const { wasOptimized, usage, cost, warnings, error, debugLogsDir } = await runSkillEnhancement(ctx, run, createToolProgress(llmLog));
74
+ if (wasOptimized) {
75
+ const costParts = [];
76
+ if (usage) {
77
+ const totalK = Math.round(usage.totalTokens / 1e3);
78
+ costParts.push(`${totalK}k tokens`);
79
+ }
80
+ if (cost) costParts.push(`$${cost.toFixed(2)}`);
81
+ const costSuffix = costParts.length > 0 ? ` (${costParts.join(", ")})` : "";
82
+ llmLog.success(`Generated best practices${costSuffix}`);
83
+ if (debugLogsDir) p.log.info(`Debug logs: ${relative(process.cwd(), debugLogsDir)}`);
84
+ if (error) p.log.warn(`\x1B[33mPartial failure: ${error}\x1B[0m`);
85
+ if (warnings?.length) for (const w of warnings) p.log.warn(`\x1B[33m${w}\x1B[0m`);
86
+ } else if (error && RATE_LIMIT_RE.test(error)) llmLog.error(`Rate limited by LLM provider. Try again shortly or use a different model via \`skilld config\``);
87
+ else llmLog.error(`Enhancement failed${error ? `: ${error}` : ""}`);
88
+ }
89
+ function writeBaseSkill(ctx, opts = {}) {
90
+ const { packageName, version, skillDir, dirName, references, resolved, relatedSkills, packages, features } = ctx;
91
+ return writeGeneratedSkillMd(skillDir, {
92
+ name: packageName,
93
+ version,
94
+ releasedAt: resolved.releasedAt,
95
+ description: resolved.description,
96
+ distTags: resolved.distTags,
97
+ body: opts.body,
98
+ relatedSkills,
99
+ hasIssues: references.hasIssues,
100
+ hasDiscussions: references.hasDiscussions,
101
+ hasReleases: references.hasReleases,
102
+ hasChangelog: references.hasChangelog,
103
+ docsType: references.docsType,
104
+ hasShippedDocs: references.hasShippedDocs,
105
+ pkgFiles: references.pkgFiles,
106
+ generatedBy: opts.generatedBy,
107
+ dirName,
108
+ packages,
109
+ repoUrl: resolved.repoUrl,
110
+ features,
111
+ eject: opts.eject
112
+ });
113
+ }
114
+ function applyCachedSections(ctx, sections, opts = {}) {
115
+ const cache = createReferenceCache(ctx.cachePackageName || ctx.packageName, ctx.version);
116
+ if (!sections.every((s) => cache.readSection(SECTION_OUTPUT_FILES[s]) !== null)) return false;
117
+ const parts = [];
118
+ for (const s of SECTION_MERGE_ORDER) {
119
+ if (!sections.includes(s)) continue;
120
+ const content = cache.readSection(SECTION_OUTPUT_FILES[s]);
121
+ if (content) parts.push(wrapSection(s, content));
122
+ }
123
+ writeBaseSkill(ctx, {
124
+ body: parts.join("\n\n"),
125
+ generatedBy: "cached",
126
+ eject: opts.eject
127
+ });
128
+ return true;
129
+ }
130
+ function writePromptFiles(ctx, run) {
131
+ const { packageName, version, skillDir, references, features, overheadLines } = ctx;
132
+ const { sections, customPrompt } = run;
133
+ const docFiles = listReferenceFiles(skillDir);
134
+ const prompts = buildAllSectionPrompts({
135
+ packageName,
136
+ skillDir,
137
+ version,
138
+ hasIssues: references.hasIssues,
139
+ hasDiscussions: references.hasDiscussions,
140
+ hasReleases: references.hasReleases,
141
+ hasChangelog: references.hasChangelog,
142
+ docFiles,
143
+ docsType: references.docsType,
144
+ hasShippedDocs: references.hasShippedDocs,
145
+ pkgFiles: references.pkgFiles,
146
+ customPrompt,
147
+ features,
148
+ overheadLines,
149
+ sections
150
+ });
151
+ const skilldDir = skillInternalDir(skillDir);
152
+ mkdirSync(skilldDir, { recursive: true });
153
+ for (const [section, prompt] of prompts) writeFileSync(join(skilldDir, `PROMPT_${section}.md`), prompt);
154
+ const written = [...prompts.keys()];
155
+ if (written.length > 0) {
156
+ const relDir = relative(process.cwd(), skillDir);
157
+ const promptFiles = written.map((s) => `PROMPT_${s}.md`).join(", ");
158
+ const outputFileList = written.map((s) => SECTION_OUTPUT_FILES[s]).join(", ");
159
+ p.log.info(`Prompt files written to ${relDir}/.skilld/\n\x1B[2m\x1B[3m Read each prompt file (${promptFiles}) in ${relDir}/.skilld/, read the\n referenced files, then write your output to the matching file (${outputFileList}).\n When done, run: skilld assemble\x1B[0m`);
160
+ }
161
+ return written;
162
+ }
163
+ const DEFAULT_SECTIONS = ["best-practices", "api-changes"];
164
+ async function resolveAutoModel(override, yes) {
165
+ if (override) return override;
166
+ const config = readConfig();
167
+ if (!yes || config.skipLlm) return void 0;
168
+ if (config.model) return config.model;
169
+ const available = await getAvailableModels();
170
+ return available.find((m) => m.recommended)?.id ?? available[0]?.id;
171
+ }
172
+ async function selectSkillSections(message = "Enhance SKILL.md") {
173
+ p.log.info("Budgets adapt to package release density.");
174
+ const selected = await p.multiselect({
175
+ message,
176
+ options: [
177
+ {
178
+ label: "API changes",
179
+ value: "api-changes",
180
+ hint: "new/deprecated APIs from version history"
181
+ },
182
+ {
183
+ label: "Best practices",
184
+ value: "best-practices",
185
+ hint: "gotchas, pitfalls, patterns"
186
+ },
187
+ {
188
+ label: "Custom section",
189
+ value: "custom",
190
+ hint: "add your own section"
191
+ }
192
+ ],
193
+ initialValues: DEFAULT_SECTIONS,
194
+ required: false
195
+ });
196
+ if (p.isCancel(selected)) return {
197
+ sections: [],
198
+ cancelled: true
199
+ };
200
+ const sections = selected;
201
+ if (sections.length === 0) return {
202
+ sections: [],
203
+ cancelled: false
204
+ };
205
+ if (sections.length > 1) {
206
+ const n = sections.length;
207
+ const budgetLines = [];
208
+ for (const s of sections) switch (s) {
209
+ case "api-changes":
210
+ budgetLines.push(` API changes ${maxItems(6, 12, n)}–${maxItems(6, Math.round(12 * 1.6), n)} items (adapts to release churn)`);
211
+ break;
212
+ case "best-practices":
213
+ budgetLines.push(` Best practices ${maxItems(4, 10, n)}–${maxItems(4, Math.round(10 * 1.3), n)} items`);
214
+ break;
215
+ case "custom":
216
+ budgetLines.push(` Custom ≤${maxLines(50, 80, n)} lines`);
217
+ break;
218
+ }
219
+ p.log.info(`Budget (${n} sections):\n${budgetLines.join("\n")}`);
220
+ }
221
+ let customPrompt;
222
+ if (sections.includes("custom")) {
223
+ const heading = await p.text({
224
+ message: "Section heading",
225
+ placeholder: "e.g. \"Migration from v2\" or \"SSR Patterns\""
226
+ });
227
+ if (p.isCancel(heading)) return {
228
+ sections: [],
229
+ cancelled: true
230
+ };
231
+ const body = await p.text({
232
+ message: "Instructions for this section",
233
+ placeholder: "e.g. \"Document breaking changes and migration steps from v2 to v3\""
234
+ });
235
+ if (p.isCancel(body)) return {
236
+ sections: [],
237
+ cancelled: true
238
+ };
239
+ customPrompt = {
240
+ heading,
241
+ body
242
+ };
243
+ }
244
+ return {
245
+ sections,
246
+ customPrompt,
247
+ cancelled: false
248
+ };
249
+ }
250
+ async function selectLlmConfig(presetModel, message, updateCtx) {
251
+ if (presetModel) {
252
+ if ((await getAvailableModels()).some((m) => m.id === presetModel)) return {
253
+ model: presetModel,
254
+ sections: DEFAULT_SECTIONS
255
+ };
256
+ if (!isInteractive()) return null;
257
+ }
258
+ if (!isInteractive()) return null;
259
+ const config = readConfig();
260
+ const available = await getAvailableModels();
261
+ if (available.length === 0) {
262
+ p.log.warn(NO_MODELS_MESSAGE);
263
+ return null;
264
+ }
265
+ let defaultModel;
266
+ if (config.model && available.some((m) => m.id === config.model)) defaultModel = config.model;
267
+ else {
268
+ if (config.model) p.log.warn(`Configured model \x1B[36m${config.model}\x1B[0m is unavailable — using auto-selected fallback`);
269
+ defaultModel = available.find((m) => m.recommended)?.id ?? available[0].id;
270
+ }
271
+ const defaultModelName = getModelName(defaultModel);
272
+ const providerHint = available.find((m) => m.id === defaultModel)?.providerName ?? "";
273
+ const sourceHint = config.model === defaultModel ? "configured" : "recommended";
274
+ const defaultHint = providerHint ? `${providerHint} · ${sourceHint}` : sourceHint;
275
+ let enhanceMessage = message ? `${message}?` : "Enhance SKILL.md?";
276
+ let defaultToSkip = false;
277
+ if (updateCtx) {
278
+ const diff = updateCtx.bumpType ?? (updateCtx.oldVersion && updateCtx.newVersion ? semverDiff(updateCtx.oldVersion, updateCtx.newVersion) : null);
279
+ const isSmallBump = diff === "patch" || diff === "prerelease" || diff === "prepatch" || diff === "preminor" || diff === "premajor";
280
+ const ageParts = [];
281
+ if (diff) ageParts.push(diff);
282
+ if (updateCtx.syncedAt) {
283
+ const syncedAtMs = new Date(updateCtx.syncedAt).getTime();
284
+ if (Number.isFinite(syncedAtMs)) {
285
+ const days = Math.floor((Date.now() - syncedAtMs) / 864e5);
286
+ ageParts.push(days === 0 ? "today" : days === 1 ? "1d ago" : `${days}d ago`);
287
+ }
288
+ }
289
+ if (updateCtx.wasEnhanced) ageParts.push("LLM-enhanced");
290
+ const hint = [updateCtx.oldVersion && updateCtx.newVersion ? `${updateCtx.oldVersion} → ${updateCtx.newVersion}` : null, ...ageParts].filter(Boolean).join(" · ");
291
+ if (hint) enhanceMessage = `Enhance SKILL.md? \x1B[90m(${hint})\x1B[0m`;
292
+ if (updateCtx.wasEnhanced && isSmallBump) defaultToSkip = true;
293
+ }
294
+ const choice = await p.select({
295
+ message: enhanceMessage,
296
+ options: [
297
+ {
298
+ label: defaultModelName,
299
+ value: "default",
300
+ hint: defaultHint
301
+ },
302
+ {
303
+ label: "Different model",
304
+ value: "pick",
305
+ hint: "choose another enhancement model"
306
+ },
307
+ {
308
+ label: "Prompt only",
309
+ value: "prompt",
310
+ hint: "write prompts for manual use"
311
+ },
312
+ {
313
+ label: "Skip",
314
+ value: "skip",
315
+ hint: "base skill with docs, issues, and types"
316
+ }
317
+ ],
318
+ ...defaultToSkip ? { initialValue: "skip" } : {}
319
+ });
320
+ if (p.isCancel(choice)) return null;
321
+ if (choice === "skip") return null;
322
+ if (choice === "prompt") {
323
+ const { sections, customPrompt, cancelled } = await selectSkillSections(message ? `${message} (prompt only)` : "Select sections for prompt generation");
324
+ if (cancelled || sections.length === 0) return null;
325
+ return {
326
+ model: defaultModel,
327
+ sections,
328
+ customPrompt,
329
+ promptOnly: true
330
+ };
331
+ }
332
+ let model;
333
+ if (choice === "pick") {
334
+ const picked = await pickModel(available);
335
+ if (!picked) return null;
336
+ updateConfig({ model: picked });
337
+ model = picked;
338
+ } else model = defaultModel;
339
+ if (!model) return null;
340
+ const modelName = getModelName(model);
341
+ const { sections, customPrompt, cancelled } = await selectSkillSections(message ? `${message} (${modelName})` : `Enhance SKILL.md with ${modelName}`);
342
+ if (cancelled || sections.length === 0) return null;
343
+ return {
344
+ model,
345
+ sections,
346
+ customPrompt
347
+ };
348
+ }
349
+ function parentDocId(id) {
350
+ const idx = id.indexOf("#chunk-");
351
+ return idx === -1 ? id : id.slice(0, idx);
352
+ }
353
+ function capDocs(allDocs, max, onProgress) {
354
+ if (allDocs.length <= max) return;
355
+ const TYPE_PRIORITY = {
356
+ doc: 0,
357
+ issue: 1,
358
+ discussion: 2,
359
+ release: 3,
360
+ source: 4,
361
+ types: 5
362
+ };
363
+ allDocs.sort((a, b) => {
364
+ const ta = TYPE_PRIORITY[a.metadata?.type || "doc"] ?? 3;
365
+ const tb = TYPE_PRIORITY[b.metadata?.type || "doc"] ?? 3;
366
+ if (ta !== tb) return ta - tb;
367
+ return a.id.localeCompare(b.id);
368
+ });
369
+ onProgress(`Indexing capped at ${max}/${allDocs.length} docs (prioritized by type)`);
370
+ allDocs.length = max;
371
+ }
372
+ async function indexResources(opts) {
373
+ const { packageName, version, cwd, onProgress } = opts;
374
+ const features = opts.features ?? readConfig().features ?? defaultFeatures;
375
+ if (!features.search) return;
376
+ const dbPath = getPackageDbPath(packageName, version);
377
+ const dbExists = existsSync(dbPath);
378
+ const allDocs = [...opts.docsToIndex];
379
+ const pkgDir = resolvePkgDir(packageName, cwd, version);
380
+ if (features.search && pkgDir) {
381
+ onProgress("Scanning exports");
382
+ const entryFiles = await resolveEntryFiles(pkgDir);
383
+ for (const e of entryFiles) allDocs.push({
384
+ id: e.path,
385
+ content: e.content,
386
+ metadata: {
387
+ package: packageName,
388
+ source: `pkg/${e.path}`,
389
+ type: e.type
390
+ }
391
+ });
392
+ }
393
+ if (allDocs.length === 0) return;
394
+ capDocs(allDocs, 250, onProgress);
395
+ if (!dbExists) {
396
+ onProgress(`Building search index (${allDocs.length} docs)`);
397
+ try {
398
+ await createIndex(allDocs, {
399
+ dbPath,
400
+ onProgress: ({ phase, current, total }) => {
401
+ if (phase === "storing") {
402
+ const d = allDocs[current - 1];
403
+ onProgress(`Storing ${d?.metadata?.type === "source" || d?.metadata?.type === "types" ? "code" : d?.metadata?.type || "doc"} (${current}/${total})`);
404
+ } else if (phase === "embedding") onProgress(`Creating embeddings (${current}/${total})`);
405
+ }
406
+ });
407
+ } catch (err) {
408
+ if (err instanceof SearchDepsUnavailableError) onProgress("Search indexing skipped (native deps unavailable)");
409
+ else throw err;
410
+ }
411
+ return;
412
+ }
413
+ let existingIds;
414
+ try {
415
+ existingIds = await listIndexIds({ dbPath });
416
+ } catch (err) {
417
+ if (err instanceof SearchDepsUnavailableError) {
418
+ onProgress("Search indexing skipped (native deps unavailable)");
419
+ return;
420
+ }
421
+ throw err;
422
+ }
423
+ const existingParentIds = new Set(existingIds.map(parentDocId));
424
+ const incomingIds = new Set(allDocs.map((d) => d.id));
425
+ const newDocs = allDocs.filter((d) => !existingParentIds.has(d.id));
426
+ const removeIds = existingIds.filter((id) => !incomingIds.has(parentDocId(id)));
427
+ if (newDocs.length === 0 && removeIds.length === 0) {
428
+ onProgress("Search index up to date");
429
+ return;
430
+ }
431
+ const parts = [];
432
+ if (newDocs.length > 0) parts.push(`+${newDocs.length} new`);
433
+ if (removeIds.length > 0) parts.push(`-${removeIds.length} stale`);
434
+ onProgress(`Updating search index (${parts.join(", ")})`);
435
+ try {
436
+ await createIndex(newDocs, {
437
+ dbPath,
438
+ removeIds,
439
+ onProgress: ({ phase, current, total }) => {
440
+ if (phase === "storing") {
441
+ const d = newDocs[current - 1];
442
+ onProgress(`Storing ${d?.metadata?.type === "source" || d?.metadata?.type === "types" ? "code" : d?.metadata?.type || "doc"} (${current}/${total})`);
443
+ } else if (phase === "embedding") onProgress(`Creating embeddings (${current}/${total})`);
444
+ }
445
+ });
446
+ } catch (err) {
447
+ if (err instanceof SearchDepsUnavailableError) onProgress("Search indexing skipped (native deps unavailable)");
448
+ else throw err;
449
+ }
450
+ }
451
+ async function resolveContentDocs(opts) {
452
+ const { packageName, resolved, version, onProgress } = opts;
453
+ const docs = [];
454
+ const docsToIndex = [];
455
+ const warnings = [];
456
+ let docSource = resolved.readmeUrl || "readme";
457
+ let docsType = "readme";
458
+ const isFrameworkDoc = (path) => filterFrameworkDocs([path], packageName).length > 0;
459
+ if (resolved.gitDocsUrl && resolved.repoUrl) {
460
+ const gh = parseGitHubUrl(resolved.repoUrl);
461
+ if (gh) {
462
+ const r = await tryGitDocs({
463
+ owner: gh.owner,
464
+ repo: gh.repo,
465
+ version,
466
+ packageName,
467
+ repoUrl: resolved.repoUrl,
468
+ llmsUrl: resolved.llmsUrl,
469
+ docsUrl: resolved.docsUrl,
470
+ onProgress
471
+ });
472
+ if (r) {
473
+ docs.push(...r.docs);
474
+ docsToIndex.push(...r.docsToIndex);
475
+ if (r.warning) warnings.push(r.warning);
476
+ if (r.kind === "git") {
477
+ docSource = r.docSource;
478
+ docsType = "docs";
479
+ }
480
+ }
481
+ }
482
+ }
483
+ if (resolved.crawlUrl && docs.length === 0) {
484
+ onProgress("Crawling website");
485
+ const crawled = await fetchCrawledDocs(resolved.crawlUrl, onProgress).catch((err) => {
486
+ warnings.push(`Crawl failed for ${resolved.crawlUrl}: ${err?.message || err}`);
487
+ return [];
488
+ });
489
+ if (crawled.length === 0) warnings.push(`Crawl returned 0 docs from ${resolved.crawlUrl}`);
490
+ for (const doc of crawled) {
491
+ if (!isFrameworkDoc(doc.path)) continue;
492
+ docs.push(doc);
493
+ docsToIndex.push({
494
+ id: doc.path,
495
+ content: doc.content,
496
+ metadata: {
497
+ package: packageName,
498
+ source: doc.path,
499
+ type: "doc"
500
+ }
501
+ });
502
+ }
503
+ if (docs.length > 0) {
504
+ docSource = resolved.crawlUrl;
505
+ docsType = "docs";
506
+ }
507
+ }
508
+ if (resolved.llmsUrl && docs.length === 0) {
509
+ onProgress("Fetching llms.txt");
510
+ const llmsContent = await fetchLlmsTxt(resolved.llmsUrl);
511
+ if (llmsContent) {
512
+ docSource = resolved.llmsUrl;
513
+ docsType = "llms.txt";
514
+ const baseUrl = resolved.docsUrl || new URL(resolved.llmsUrl).origin;
515
+ docs.push({
516
+ path: "llms.txt",
517
+ content: normalizeLlmsLinks(llmsContent.raw, baseUrl)
518
+ });
519
+ if (llmsContent.links.length > 0) {
520
+ onProgress(`Downloading ${llmsContent.links.length} linked docs`);
521
+ const linked = await downloadLlmsDocs(llmsContent, baseUrl, (_url, done, total) => {
522
+ onProgress(`Downloading linked doc ${done + 1}/${total}`);
523
+ });
524
+ for (const doc of linked) {
525
+ if (!isFrameworkDoc(doc.url)) continue;
526
+ const cachePath = join("docs", ...(doc.url.startsWith("/") ? doc.url.slice(1) : doc.url).split("/"));
527
+ docs.push({
528
+ path: cachePath,
529
+ content: doc.content
530
+ });
531
+ docsToIndex.push({
532
+ id: doc.url,
533
+ content: doc.content,
534
+ metadata: {
535
+ package: packageName,
536
+ source: cachePath,
537
+ type: "doc"
538
+ }
539
+ });
540
+ }
541
+ if (linked.length > 0) docsType = "docs";
542
+ }
543
+ }
544
+ }
545
+ if (resolved.docsUrl && !docs.some((d) => d.path.startsWith("docs/"))) {
546
+ const crawlPattern = resolved.crawlUrl || toCrawlPattern(resolved.docsUrl);
547
+ onProgress("Crawling docs site");
548
+ const crawled = await fetchCrawledDocs(crawlPattern, onProgress, resolved.crawlUrl ? 200 : 400).catch((err) => {
549
+ warnings.push(`Crawl failed for ${crawlPattern}: ${err?.message || err}`);
550
+ return [];
551
+ });
552
+ let added = 0;
553
+ for (const doc of crawled) {
554
+ if (!isFrameworkDoc(doc.path)) continue;
555
+ docs.push(doc);
556
+ docsToIndex.push({
557
+ id: doc.path,
558
+ content: doc.content,
559
+ metadata: {
560
+ package: packageName,
561
+ source: doc.path,
562
+ type: "doc"
563
+ }
564
+ });
565
+ added++;
566
+ }
567
+ if (added > 0) {
568
+ docSource = crawlPattern;
569
+ docsType = "docs";
570
+ }
571
+ }
572
+ if (resolved.readmeUrl && docs.length === 0) {
573
+ onProgress("Fetching README");
574
+ const content = await fetchReadmeContent(resolved.readmeUrl);
575
+ if (content) {
576
+ docs.push({
577
+ path: "docs/README.md",
578
+ content
579
+ });
580
+ docsToIndex.push({
581
+ id: "README.md",
582
+ content,
583
+ metadata: {
584
+ package: packageName,
585
+ source: "docs/README.md",
586
+ type: "doc"
587
+ }
588
+ });
589
+ }
590
+ }
591
+ return {
592
+ docs,
593
+ docsToIndex,
594
+ docSource,
595
+ docsType,
596
+ warnings
597
+ };
598
+ }
599
+ async function tryGitDocs(opts) {
600
+ const { owner, repo, version, packageName, repoUrl, llmsUrl, docsUrl, onProgress } = opts;
601
+ onProgress("Fetching git docs");
602
+ const gitDocs = await fetchGitDocs(owner, repo, version, packageName);
603
+ if (!gitDocs || gitDocs.files.length === 0) return null;
604
+ let warning;
605
+ if (gitDocs.fallback) warning = `Docs fetched from ${gitDocs.ref} branch (no tag found for v${version})`;
606
+ const BATCH_SIZE = 20;
607
+ const results = [];
608
+ for (let i = 0; i < gitDocs.files.length; i += BATCH_SIZE) {
609
+ const batch = gitDocs.files.slice(i, i + BATCH_SIZE);
610
+ onProgress(`Downloading docs ${Math.min(i + BATCH_SIZE, gitDocs.files.length)}/${gitDocs.files.length} from ${gitDocs.ref}`);
611
+ const batchResults = await Promise.all(batch.map(async (file) => {
612
+ const content = await fetchGitHubRaw(`${gitDocs.baseUrl}/${file}`);
613
+ return content ? {
614
+ file,
615
+ content
616
+ } : null;
617
+ }));
618
+ results.push(...batchResults);
619
+ }
620
+ const docs = [];
621
+ const docsToIndex = [];
622
+ for (const r of results) {
623
+ if (!r) continue;
624
+ const stripped = gitDocs.docsPrefix ? r.file.replace(gitDocs.docsPrefix, "") : r.file;
625
+ const cachePath = stripped.startsWith("docs/") ? stripped : `docs/${stripped}`;
626
+ docs.push({
627
+ path: cachePath,
628
+ content: r.content
629
+ });
630
+ docsToIndex.push({
631
+ id: cachePath,
632
+ content: r.content,
633
+ metadata: {
634
+ package: packageName,
635
+ source: cachePath,
636
+ type: "doc"
637
+ }
638
+ });
639
+ }
640
+ if (isShallowGitDocs(docs.length) && llmsUrl) {
641
+ onProgress(`Shallow git-docs (${docs.length} files), trying llms.txt`);
642
+ return {
643
+ kind: "discarded",
644
+ docs: [],
645
+ docsToIndex: [],
646
+ docSource: "",
647
+ warning
648
+ };
649
+ }
650
+ if (llmsUrl) {
651
+ onProgress("Caching supplementary llms.txt");
652
+ const llmsContent = await fetchLlmsTxt(llmsUrl);
653
+ if (llmsContent) {
654
+ const baseUrl = docsUrl || new URL(llmsUrl).origin;
655
+ docs.push({
656
+ path: "llms.txt",
657
+ content: normalizeLlmsLinks(llmsContent.raw, baseUrl)
658
+ });
659
+ if (llmsContent.links.length > 0) {
660
+ onProgress(`Downloading ${llmsContent.links.length} supplementary docs`);
661
+ const supplementary = await downloadLlmsDocs(llmsContent, baseUrl, (_url, done, total) => {
662
+ onProgress(`Downloading supplementary doc ${done + 1}/${total}`);
663
+ });
664
+ for (const doc of supplementary) {
665
+ if (filterFrameworkDocs([doc.url], packageName).length === 0) continue;
666
+ const localPath = doc.url.startsWith("/") ? doc.url.slice(1) : doc.url;
667
+ docs.push({
668
+ path: join("llms-docs", ...localPath.split("/")),
669
+ content: doc.content
670
+ });
671
+ }
672
+ }
673
+ }
674
+ }
675
+ return {
676
+ kind: "git",
677
+ docs,
678
+ docsToIndex,
679
+ docSource: `${repoUrl}/tree/${gitDocs.ref}/docs`,
680
+ warning
681
+ };
682
+ }
683
+ async function resolveTimelineReferences(opts) {
684
+ const { packageName, resolved, version, features, from, onProgress } = opts;
685
+ const docsToIndex = [];
686
+ const gh = resolved.repoUrl ? parseGitHubUrl(resolved.repoUrl) : null;
687
+ const repoInfo = gh ? {
688
+ owner: gh.owner,
689
+ repo: gh.repo
690
+ } : void 0;
691
+ const repoCacheDir = repoInfo ? getRepoCacheDir(repoInfo.owner, repoInfo.repo) : null;
692
+ const cacheDir = getCacheDir(packageName, version);
693
+ const issuesDir = repoCacheDir ? join(repoCacheDir, "issues") : join(cacheDir, "issues");
694
+ const discussionsDir = repoCacheDir ? join(repoCacheDir, "discussions") : join(cacheDir, "discussions");
695
+ const releasesPath = repoCacheDir ? join(repoCacheDir, "releases") : join(cacheDir, "releases");
696
+ if (features.issues && gh && isGhAvailable() && !existsSync(issuesDir)) {
697
+ onProgress("Fetching issues via GitHub API");
698
+ const issues = await fetchGitHubIssues(gh.owner, gh.repo, 30, resolved.releasedAt, from).catch(() => []);
699
+ if (issues.length > 0) {
700
+ onProgress(`Caching ${issues.length} issues`);
701
+ const issueDocs = [...issues.map((issue) => ({
702
+ path: `issues/issue-${issue.number}.md`,
703
+ content: formatIssueAsMarkdown(issue)
704
+ })), {
705
+ path: "issues/_INDEX.md",
706
+ content: generateIssueIndex(issues)
707
+ }];
708
+ if (repoInfo) writeToRepoCache(repoInfo.owner, repoInfo.repo, issueDocs);
709
+ else writeToCache(packageName, version, issueDocs);
710
+ for (const issue of issues) docsToIndex.push({
711
+ id: `issue-${issue.number}`,
712
+ content: sanitizeMarkdown(`#${issue.number}: ${issue.title}\n\n${issue.body || ""}`),
713
+ metadata: {
714
+ package: packageName,
715
+ source: `issues/issue-${issue.number}.md`,
716
+ type: "issue",
717
+ number: issue.number
718
+ }
719
+ });
720
+ }
721
+ }
722
+ if (features.discussions && gh && isGhAvailable() && !existsSync(discussionsDir)) {
723
+ onProgress("Fetching discussions via GitHub API");
724
+ const discussions = await fetchGitHubDiscussions(gh.owner, gh.repo, 20, resolved.releasedAt, from).catch(() => []);
725
+ if (discussions.length > 0) {
726
+ onProgress(`Caching ${discussions.length} discussions`);
727
+ const discussionDocs = [...discussions.map((d) => ({
728
+ path: `discussions/discussion-${d.number}.md`,
729
+ content: formatDiscussionAsMarkdown(d)
730
+ })), {
731
+ path: "discussions/_INDEX.md",
732
+ content: generateDiscussionIndex(discussions)
733
+ }];
734
+ if (repoInfo) writeToRepoCache(repoInfo.owner, repoInfo.repo, discussionDocs);
735
+ else writeToCache(packageName, version, discussionDocs);
736
+ for (const d of discussions) docsToIndex.push({
737
+ id: `discussion-${d.number}`,
738
+ content: sanitizeMarkdown(`#${d.number}: ${d.title}\n\n${d.body || ""}`),
739
+ metadata: {
740
+ package: packageName,
741
+ source: `discussions/discussion-${d.number}.md`,
742
+ type: "discussion",
743
+ number: d.number
744
+ }
745
+ });
746
+ }
747
+ }
748
+ if (features.releases && gh && isGhAvailable() && !existsSync(releasesPath)) {
749
+ onProgress("Fetching releases via GitHub API");
750
+ const changelogRef = isPrerelease(version) ? getPrereleaseChangelogRef(packageName) : void 0;
751
+ const releaseDocs = await fetchReleaseNotes(gh.owner, gh.repo, version, resolved.gitRef, packageName, from, changelogRef).catch(() => []);
752
+ let blogDocs = [];
753
+ if (getBlogPreset(packageName)) {
754
+ onProgress("Fetching blog release notes");
755
+ blogDocs = await fetchBlogReleases(packageName, version).catch(() => []);
756
+ }
757
+ const allDocs = [...releaseDocs, ...blogDocs];
758
+ const blogEntries = blogDocs.filter((d) => !d.path.endsWith("_INDEX.md")).map((d) => {
759
+ const versionMatch = d.path.match(/blog-(.+)\.md$/);
760
+ const fm = parseFrontmatter(d.content);
761
+ return {
762
+ version: versionMatch?.[1] ?? "",
763
+ title: fm.title ?? `Release ${versionMatch?.[1]}`,
764
+ date: fm.date ?? ""
765
+ };
766
+ }).filter((b) => b.version);
767
+ const ghReleases = releaseDocs.filter((d) => d.path.startsWith("releases/") && !d.path.endsWith("CHANGELOG.md")).map((d) => {
768
+ const fm = parseFrontmatter(d.content);
769
+ const tag = fm.tag ?? "";
770
+ const name = fm.name ?? tag;
771
+ const published = fm.published ?? "";
772
+ return {
773
+ id: 0,
774
+ tag,
775
+ name,
776
+ prerelease: false,
777
+ createdAt: published,
778
+ publishedAt: published,
779
+ markdown: ""
780
+ };
781
+ }).filter((r) => r.tag);
782
+ const hasChangelog = allDocs.some((d) => d.path === "releases/CHANGELOG.md");
783
+ if (ghReleases.length > 0 || blogEntries.length > 0) allDocs.push({
784
+ path: "releases/_INDEX.md",
785
+ content: generateReleaseIndex({
786
+ releases: ghReleases,
787
+ packageName,
788
+ blogReleases: blogEntries,
789
+ hasChangelog
790
+ })
791
+ });
792
+ if (allDocs.length > 0) {
793
+ onProgress(`Caching ${allDocs.length} releases`);
794
+ if (repoInfo) writeToRepoCache(repoInfo.owner, repoInfo.repo, allDocs);
795
+ else writeToCache(packageName, version, allDocs);
796
+ for (const doc of allDocs) docsToIndex.push({
797
+ id: doc.path,
798
+ content: doc.content,
799
+ metadata: {
800
+ package: packageName,
801
+ source: doc.path,
802
+ type: "release"
803
+ }
804
+ });
805
+ }
806
+ }
807
+ return {
808
+ docsToIndex,
809
+ hasIssues: features.issues && existsSync(issuesDir),
810
+ hasDiscussions: features.discussions && existsSync(discussionsDir),
811
+ hasReleases: features.releases && existsSync(releasesPath),
812
+ repoInfo
813
+ };
814
+ }
815
+ async function findRelatedSkills(packageName, skillsDir) {
816
+ const related = [];
817
+ const npmInfo = await fetchNpmPackage(packageName);
818
+ if (!npmInfo?.dependencies) return related;
819
+ const deps = new Set(Object.keys(npmInfo.dependencies));
820
+ if (!existsSync(skillsDir)) return related;
821
+ const lock = readLock(skillsDir);
822
+ const pkgToDirName = lock ? buildPackageDirMap(lock) : /* @__PURE__ */ new Map();
823
+ const installedSet = new Set(readdirSync(skillsDir));
824
+ for (const dep of deps) {
825
+ const dirName = pkgToDirName.get(dep);
826
+ if (dirName && installedSet.has(dirName)) related.push(dirName);
827
+ }
828
+ return related.slice(0, 5);
829
+ }
830
+ function detectChangelog(pkgDir, cacheDir) {
831
+ if (pkgDir) {
832
+ const found = ["CHANGELOG.md", "changelog.md"].find((f) => existsSync(join(pkgDir, f)));
833
+ if (found) return `pkg/${found}`;
834
+ }
835
+ if (cacheDir && existsSync(join(cacheDir, "releases", "CHANGELOG.md"))) return "releases/CHANGELOG.md";
836
+ return false;
837
+ }
838
+ async function fetchAndCacheResources(opts) {
839
+ const { packageName, resolved, version, onProgress } = opts;
840
+ const features = opts.features ?? readConfig().features ?? defaultFeatures;
841
+ const cache = createReferenceCache(packageName, version);
842
+ const cacheInvalidated = opts.useCache && resolved.crawlUrl && cache.detectDocs(resolved.repoUrl, resolved.llmsUrl).docsType === "readme";
843
+ const useCache = opts.useCache && !cacheInvalidated;
844
+ let docSource = resolved.readmeUrl || "readme";
845
+ let docsType = "readme";
846
+ const docsToIndex = [];
847
+ const warnings = [];
848
+ if (cacheInvalidated) warnings.push(`Retrying crawl for ${resolved.crawlUrl} (previous attempt only cached README)`);
849
+ if (!useCache) {
850
+ const content = await resolveContentDocs({
851
+ packageName,
852
+ resolved,
853
+ version,
854
+ onProgress
855
+ });
856
+ docSource = content.docSource;
857
+ docsType = content.docsType;
858
+ docsToIndex.push(...content.docsToIndex);
859
+ warnings.push(...content.warnings);
860
+ if (content.docs.length > 0) {
861
+ cache.write(content.docs);
862
+ if (docsType !== "readme" && content.docs.filter((d) => d.path.startsWith("docs/") && d.path.endsWith(".md")).length > 1) {
863
+ const docsIndex = generateDocsIndex(content.docs);
864
+ if (docsIndex) cache.write([{
865
+ path: "docs/_INDEX.md",
866
+ content: docsIndex
867
+ }]);
868
+ }
869
+ }
870
+ } else {
871
+ const cached = cache.load({
872
+ repoUrl: resolved.repoUrl,
873
+ llmsUrl: resolved.llmsUrl,
874
+ readmeUrl: resolved.readmeUrl,
875
+ onProgress,
876
+ generateDocsIndex
877
+ });
878
+ docsType = cached.docsType;
879
+ docSource = cached.docSource;
880
+ docsToIndex.push(...cached.docsToIndex);
881
+ if (cached.backfillIndex) cache.write([cached.backfillIndex]);
882
+ }
883
+ const timeline = await resolveTimelineReferences({
884
+ packageName,
885
+ resolved,
886
+ version,
887
+ features,
888
+ from: opts.from,
889
+ onProgress
890
+ });
891
+ docsToIndex.push(...timeline.docsToIndex);
892
+ return {
893
+ docSource,
894
+ docsType,
895
+ docsToIndex,
896
+ hasIssues: timeline.hasIssues,
897
+ hasDiscussions: timeline.hasDiscussions,
898
+ hasReleases: timeline.hasReleases,
899
+ warnings,
900
+ repoInfo: timeline.repoInfo,
901
+ usedCache: useCache
902
+ };
903
+ }
904
+ async function prepareSkillReferences(opts) {
905
+ const { packageName, version, cwd, skillDir, resources, features, baseDir, onIndexProgress } = opts;
906
+ const cache = createReferenceCache(packageName, version);
907
+ cache.linkInto(skillDir, cwd, resources.docsType, {
908
+ features,
909
+ repoInfo: resources.repoInfo
910
+ });
911
+ if (features.search) await indexResources({
912
+ packageName,
913
+ version,
914
+ cwd,
915
+ docsToIndex: resources.docsToIndex,
916
+ features,
917
+ onProgress: onIndexProgress ?? (() => {})
918
+ });
919
+ return {
920
+ hasChangelog: detectChangelog(cache.pkgDir(cwd), cache.dir),
921
+ shippedDocs: cache.hasShipped(cwd),
922
+ pkgFiles: cache.keyFiles(cwd),
923
+ relatedSkills: baseDir ? await findRelatedSkills(packageName, baseDir) : []
924
+ };
925
+ }
926
+ function buildSkillContext(opts) {
927
+ const { packages, cachePackageName, packageName } = opts;
928
+ return {
929
+ packageName,
930
+ ...cachePackageName && cachePackageName !== packageName ? { cachePackageName } : {},
931
+ version: opts.version,
932
+ skillDir: opts.skillDir,
933
+ dirName: opts.skillDirName,
934
+ references: {
935
+ docsType: opts.resources.docsType,
936
+ hasShippedDocs: opts.prepared.shippedDocs,
937
+ pkgFiles: opts.prepared.pkgFiles,
938
+ hasIssues: opts.resources.hasIssues,
939
+ hasDiscussions: opts.resources.hasDiscussions,
940
+ hasReleases: opts.resources.hasReleases,
941
+ hasChangelog: opts.prepared.hasChangelog
942
+ },
943
+ resolved: opts.resolved,
944
+ relatedSkills: opts.prepared.relatedSkills,
945
+ packages: packages && packages.length > 1 ? packages : void 0,
946
+ features: opts.features,
947
+ overheadLines: opts.overheadLines
948
+ };
949
+ }
950
+ export { prepareSkillReferences as a, resolveAutoModel as c, applyCachedSections as d, enhanceSkillWithLLM as f, writePromptFiles as h, findRelatedSkills as i, selectLlmConfig as l, writeBaseSkill as m, detectChangelog as n, indexResources as o, runSkillEnhancement as p, fetchAndCacheResources as r, DEFAULT_SECTIONS as s, buildSkillContext as t, selectSkillSections as u };
951
+
952
+ //# sourceMappingURL=sync-pipeline.mjs.map