skilld 2.3.0 → 3.0.0-beta.2

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