skilld 2.3.0 → 3.0.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (146) hide show
  1. package/README.md +106 -376
  2. package/bin/skilld.mjs +56 -0
  3. package/loader/resolve-artifact.mjs +37 -0
  4. package/package.json +23 -53
  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,1009 +0,0 @@
1
- import { detectImportedPackages, getModelLabel } from "./agent.mjs";
2
- import { computeSkillDirName, formatDuration, linkSkillToAgents, sanitizeName, timedSpinner, todayIsoDate, writeGeneratedSkillMd } from "./prompts.mjs";
3
- import { getActiveFeatures, readConfig } from "./index-identity.mjs";
4
- import { getSharedSkillsDir, skillRefsSection } from "./paths.mjs";
5
- import { getVersionKey } from "./prepare.mjs";
6
- import { createReferenceCache, ensureCacheDir } from "./cache.mjs";
7
- import { suggestPrepareHook } from "./prepare-hook2.mjs";
8
- import { fetchPkgDist, isCrateSpec, isPrerelease, parseGitHubRepoSlug, parsePackageSpec, resolveGitHubRepo, resolvePackageOrCrate, searchNpmPackages, semverDiff, toStoragePackageName } from "./semver.mjs";
9
- import { parseFrontmatter } from "./markdown.mjs";
10
- import { findSkillDirByPackage, parsePackageNames, readLock } from "./lockfile.mjs";
11
- import { ensureProjectFiles, handleShippedSkills, installSkill, linkShippedToAgents, resolveBaseDir } from "./skill-installer2.mjs";
12
- import { DEFAULT_SECTIONS, applyCachedSections, buildSkillContext, fetchAndCacheResources, findRelatedSkills, prepareSkillReferences, resolveAutoModel, runSkillEnhancement, selectLlmConfig, writeBaseSkill, writePromptFiles } from "./pipeline.mjs";
13
- import { shutdownWorker } from "./pool2.mjs";
14
- import { existsSync, mkdirSync, readFileSync } from "node:fs";
15
- import { styleText } from "node:util";
16
- import * as p from "@clack/prompts";
17
- import pLimit from "p-limit";
18
- import { join, relative, resolve } from "pathe";
19
- import logUpdate from "log-update";
20
- import { createHooks } from "hookable";
21
- const npmResolver = async (spec, opts) => {
22
- const resolution = await resolvePackageOrCrate(spec, {
23
- cwd: opts.cwd,
24
- onProgress: (msg) => opts.onProgress(`${spec}: ${msg}`)
25
- });
26
- const { isCrate, packageName, identityPackageName, storagePackageName, requestedTag, localVersion, attempts, registryVersion } = resolution;
27
- if (!resolution.resolved) {
28
- const result = {
29
- identityName: identityPackageName,
30
- attempts,
31
- registryVersion
32
- };
33
- if (!isCrate) {
34
- const shipped = handleShippedSkills(packageName, localVersion || registryVersion || "latest", opts.cwd, opts.agent, opts.global);
35
- if (shipped) result.shipped = shipped.shipped;
36
- }
37
- return result;
38
- }
39
- const resolved = resolution.resolved;
40
- return {
41
- identityName: identityPackageName,
42
- storageName: storagePackageName,
43
- version: isCrate ? resolved.version || requestedTag || "latest" : localVersion || resolved.version || "latest",
44
- resolved,
45
- kind: isCrate ? "crate" : "npm",
46
- requestedTag,
47
- localVersion
48
- };
49
- };
50
- function createGithubResolver(owner, repo) {
51
- return async (_spec, opts) => {
52
- const resolved = await resolveGitHubRepo(owner, repo, (msg) => opts.onProgress(msg));
53
- if (!resolved) return {
54
- identityName: `${owner}-${repo}`,
55
- attempts: [{
56
- source: "github-meta",
57
- status: "not-found",
58
- message: `Could not find docs for ${owner}/${repo}`
59
- }]
60
- };
61
- const repoUrl = `https://github.com/${owner}/${repo}`;
62
- const name = `${owner}-${repo}`;
63
- return {
64
- identityName: name,
65
- storageName: name,
66
- version: resolved.version || "main",
67
- resolved: {
68
- ...resolved,
69
- repoUrl
70
- },
71
- kind: "github"
72
- };
73
- };
74
- }
75
- const RATE_LIMIT_RE = /\b429\b|rate.?limit|exhausted.*capacity|quota.*reset/i;
76
- async function runBaseSync(spec, config, hooks, resolver, cwd, defaultSections) {
77
- await hooks.callHook("resolve:start", { spec });
78
- const resolverResult = await resolver(spec, {
79
- cwd,
80
- agent: config.agent,
81
- global: config.global,
82
- onProgress: (msg) => hooks.callHook("resolve:progress", {
83
- spec,
84
- message: msg
85
- })
86
- });
87
- if (!("resolved" in resolverResult)) {
88
- if (resolverResult.shipped && resolverResult.shipped.length > 0) {
89
- for (const s of resolverResult.shipped) await hooks.callHook("shipped:installed", {
90
- spec,
91
- skillName: s.skillName,
92
- skillDir: s.skillDir
93
- });
94
- return { kind: "shipped" };
95
- }
96
- await hooks.callHook("resolve:failed", {
97
- spec,
98
- identityName: resolverResult.identityName,
99
- attempts: resolverResult.attempts
100
- });
101
- return {
102
- kind: "unresolved",
103
- unresolved: resolverResult
104
- };
105
- }
106
- const { identityName, storageName, version, resolved, kind, requestedTag, localVersion } = resolverResult;
107
- const cache = createReferenceCache(storageName, version);
108
- if (config.force) cache.clearForce();
109
- const useCache = cache.has();
110
- if (kind !== "crate" && !existsSync(join(cwd, "node_modules", identityName))) {
111
- await hooks.callHook("dist:downloading", { spec });
112
- await fetchPkgDist(identityName, version);
113
- }
114
- if (kind !== "crate") {
115
- const shipped = handleShippedSkills(identityName, version, cwd, config.agent, config.global);
116
- if (shipped) {
117
- linkShippedToAgents(shipped.shipped, cwd, config.agent, config.global);
118
- for (const s of shipped.shipped) await hooks.callHook("shipped:installed", {
119
- spec,
120
- skillName: s.skillName,
121
- skillDir: s.skillDir
122
- });
123
- return { kind: "shipped" };
124
- }
125
- }
126
- await hooks.callHook("resolve:done", {
127
- spec,
128
- version,
129
- cached: useCache,
130
- force: config.force
131
- });
132
- if (kind === "npm" && !localVersion && !requestedTag && !isPrerelease(version)) {
133
- const nextTag = resolved.distTags?.next ?? resolved.distTags?.beta ?? resolved.distTags?.alpha;
134
- if (nextTag && (!resolved.releasedAt || !nextTag.releasedAt || nextTag.releasedAt > resolved.releasedAt)) await hooks.callHook("warn", {
135
- spec,
136
- message: `No local dependency found — using latest stable (${version}). Prerelease ${nextTag.version} available: skilld add ${identityName}@beta`
137
- });
138
- }
139
- cache.ensure();
140
- const isEject = !!config.eject;
141
- const baseDir = resolveBaseDir(cwd, config.agent, config.global);
142
- let skillDirName = config.name ? sanitizeName(config.name) : computeSkillDirName(storageName);
143
- if (config.mode === "update" && !config.name && !isEject) {
144
- const lock = readLock(baseDir);
145
- const found = lock ? findSkillDirByPackage(lock, identityName) : null;
146
- if (found) skillDirName = found;
147
- }
148
- const skillDir = isEject ? typeof config.eject === "string" ? join(resolve(cwd, config.eject), skillDirName) : join(cwd, "skills", skillDirName) : join(baseDir, skillDirName);
149
- mkdirSync(skillDir, { recursive: true });
150
- const existingLock = isEject ? void 0 : readLock(baseDir)?.skills[skillDirName];
151
- if (existingLock && existingLock.packageName && existingLock.packageName !== identityName) return {
152
- kind: "merge-needed",
153
- state: {
154
- identityName,
155
- storageName,
156
- version,
157
- resolved,
158
- baseDir,
159
- skillDir,
160
- skillDirName,
161
- existingLock
162
- }
163
- };
164
- const updateCtx = config.mode === "update" && existingLock ? {
165
- oldVersion: existingLock.version,
166
- newVersion: version,
167
- syncedAt: existingLock.syncedAt,
168
- wasEnhanced: (() => {
169
- const skillMdPath = join(skillDir, "SKILL.md");
170
- if (!existsSync(skillMdPath)) return false;
171
- return !!parseFrontmatter(readFileSync(skillMdPath, "utf-8")).generated_by;
172
- })()
173
- } : void 0;
174
- const features = getActiveFeatures(config.noSearch ? { search: false } : void 0);
175
- await hooks.callHook("fetch:start", { spec });
176
- const resources = await fetchAndCacheResources({
177
- packageName: storageName,
178
- resolved,
179
- version,
180
- useCache,
181
- features,
182
- from: config.from,
183
- onProgress: (msg) => hooks.callHook("fetch:progress", {
184
- spec,
185
- message: msg
186
- })
187
- });
188
- const parts = [];
189
- if (resources.docsToIndex.length > 0) {
190
- const docCount = resources.docsToIndex.filter((d) => d.metadata?.type === "doc").length;
191
- if (docCount > 0) parts.push(`${docCount} docs`);
192
- }
193
- if (resources.hasIssues) parts.push("issues");
194
- if (resources.hasDiscussions) parts.push("discussions");
195
- if (resources.hasReleases) parts.push("releases");
196
- await hooks.callHook("fetch:done", {
197
- spec,
198
- parts,
199
- cached: resources.usedCache
200
- });
201
- for (const w of resources.warnings) await hooks.callHook("warn", {
202
- spec,
203
- message: w
204
- });
205
- if (features.search) await hooks.callHook("index:start", { spec });
206
- const prepared = await prepareSkillReferences({
207
- packageName: storageName,
208
- version,
209
- cwd,
210
- skillDir,
211
- resources,
212
- features,
213
- baseDir,
214
- onIndexProgress: (msg) => hooks.callHook("index:progress", {
215
- spec,
216
- message: msg
217
- })
218
- });
219
- if (features.search) await hooks.callHook("index:done", { spec });
220
- if (!isEject) {
221
- const repoSlug = parseGitHubRepoSlug(resolved.repoUrl);
222
- cache.linkPkgNamed(skillDir, cwd);
223
- const lock = {
224
- packageName: identityName,
225
- version,
226
- repo: repoSlug,
227
- source: resources.docSource,
228
- syncedAt: todayIsoDate(),
229
- generator: "skilld"
230
- };
231
- installSkill({
232
- cwd,
233
- agent: config.agent,
234
- global: config.global,
235
- baseDir,
236
- skillDirName,
237
- lock,
238
- dedupePackageName: identityName,
239
- skipLinkAgents: true
240
- });
241
- }
242
- const updatedLock = isEject ? void 0 : readLock(baseDir)?.skills[skillDirName];
243
- const allPackages = parsePackageNames(updatedLock?.packages);
244
- const ctx = buildSkillContext({
245
- packageName: identityName,
246
- cachePackageName: storageName,
247
- version,
248
- skillDir,
249
- skillDirName,
250
- resources,
251
- prepared,
252
- resolved,
253
- packages: allPackages,
254
- features
255
- });
256
- ctx.overheadLines = writeBaseSkill(ctx, { eject: isEject }).split("\n").length;
257
- await hooks.callHook("base:done", {
258
- spec,
259
- skillDir: relative(cwd, skillDir),
260
- mode: config.mode === "update" ? "update" : "add"
261
- });
262
- const allSectionsCached = !config.force && applyCachedSections(ctx, defaultSections, { eject: isEject });
263
- if (allSectionsCached) await hooks.callHook("sections:cached", { spec });
264
- return {
265
- kind: "ready",
266
- state: {
267
- ctx,
268
- skillDir,
269
- skillDirName,
270
- baseDir,
271
- updateCtx,
272
- allSectionsCached,
273
- identityName,
274
- storageName,
275
- version,
276
- docsType: resources.docsType,
277
- repoInfo: resources.repoInfo
278
- }
279
- };
280
- }
281
- async function runEnhancePhase(state, llmConfig, config, hooks, cwd) {
282
- const isEject = !!config.eject;
283
- const spec = state.identityName;
284
- if (llmConfig?.promptOnly) writePromptFiles({
285
- ...state.ctx,
286
- packageName: state.ctx.cachePackageName ?? state.ctx.packageName,
287
- cachePackageName: void 0
288
- }, {
289
- sections: llmConfig.sections,
290
- customPrompt: llmConfig.customPrompt
291
- });
292
- else if (llmConfig) await enhanceWithHooks(state.ctx, llmConfig, {
293
- ...config,
294
- eject: isEject
295
- }, hooks, spec);
296
- if (isEject) {
297
- const cache = createReferenceCache(state.storageName, state.version);
298
- if (!config.debug) cache.clearSkillInternal(state.skillDir);
299
- cache.eject(state.skillDir, cwd, state.docsType, {
300
- features: state.ctx.features ?? getActiveFeatures(),
301
- repoInfo: state.repoInfo
302
- });
303
- return;
304
- }
305
- const shared = config.global ? false : getSharedSkillsDir(cwd) ?? false;
306
- if (shared) linkSkillToAgents(state.skillDirName, shared, cwd, config.agent);
307
- await ensureProjectFiles({
308
- cwd,
309
- agent: config.agent,
310
- global: config.global,
311
- shared
312
- });
313
- }
314
- async function enhanceWithHooks(ctx, llmConfig, config, hooks, spec) {
315
- await hooks.callHook("enhance:start", {
316
- spec,
317
- modelLabel: getModelLabel(llmConfig.model)
318
- });
319
- const result = await runSkillEnhancement(ctx, {
320
- model: llmConfig.model,
321
- force: config.force,
322
- debug: config.debug,
323
- sections: llmConfig.sections,
324
- customPrompt: llmConfig.customPrompt,
325
- eject: !!config.eject
326
- }, (progress) => hooks.callHook("enhance:progress", {
327
- spec,
328
- progress
329
- }));
330
- if (result.wasOptimized) await hooks.callHook("enhance:done", {
331
- spec,
332
- usage: result.usage ? { totalTokens: result.usage.totalTokens } : void 0,
333
- cost: result.cost,
334
- debugLogsDir: result.debugLogsDir,
335
- error: result.error,
336
- warnings: result.warnings
337
- });
338
- else await hooks.callHook("enhance:failed", {
339
- spec,
340
- error: result.error ?? "",
341
- rateLimited: !!result.error && RATE_LIMIT_RE.test(result.error)
342
- });
343
- }
344
- function createSyncRun(opts) {
345
- const hooks = createHooks();
346
- async function runBase(spec) {
347
- const result = await runBaseSync(spec, {
348
- agent: opts.agent,
349
- global: opts.global,
350
- mode: opts.mode,
351
- force: opts.force,
352
- noSearch: opts.noSearch,
353
- name: opts.name,
354
- from: opts.from,
355
- eject: opts.eject
356
- }, hooks, opts.resolver, opts.cwd, opts.defaultSections);
357
- if (result.kind === "shipped") return {
358
- kind: "shipped",
359
- spec
360
- };
361
- if (result.kind === "unresolved") return {
362
- kind: "unresolved",
363
- spec,
364
- identityName: result.unresolved.identityName,
365
- attempts: result.unresolved.attempts
366
- };
367
- if (result.kind === "merge-needed") {
368
- if (opts.onMergeNeeded) {
369
- await opts.onMergeNeeded(result.state);
370
- return {
371
- kind: "merged",
372
- spec
373
- };
374
- }
375
- return {
376
- kind: "error",
377
- spec,
378
- reason: `Skill dir already holds ${result.state.existingLock.packageName} — run sequentially to merge`
379
- };
380
- }
381
- return {
382
- kind: "ready",
383
- spec,
384
- state: result.state
385
- };
386
- }
387
- async function runEnhance(state, llmConfig) {
388
- await runEnhancePhase(state, llmConfig, {
389
- agent: opts.agent,
390
- global: opts.global,
391
- force: opts.force,
392
- debug: opts.debug,
393
- eject: opts.eject
394
- }, hooks, opts.cwd);
395
- }
396
- async function run(spec) {
397
- const base = await runBase(spec);
398
- if (base.kind !== "ready") return base;
399
- let llmConfig = null;
400
- if (!base.state.allSectionsCached && opts.resolveLlmConfig) llmConfig = await opts.resolveLlmConfig({ ready: [{
401
- spec,
402
- state: base.state
403
- }] }) ?? null;
404
- await runEnhance(base.state, llmConfig);
405
- return {
406
- kind: "enhanced",
407
- spec,
408
- state: base.state
409
- };
410
- }
411
- async function runMany(specs, runOpts) {
412
- const limit = pLimit(runOpts?.concurrency ?? 5);
413
- return (await Promise.allSettled(specs.map((spec) => limit(() => runBase(spec))))).map((r, i) => r.status === "fulfilled" ? r.value : {
414
- kind: "error",
415
- spec: specs[i],
416
- reason: r.reason instanceof Error ? r.reason.message : String(r.reason)
417
- });
418
- }
419
- return {
420
- hooks,
421
- runBase,
422
- runEnhance,
423
- run,
424
- runMany
425
- };
426
- }
427
- function bindClackUi(hooks, { cwd }) {
428
- let spinner = null;
429
- let resourceSpinner = null;
430
- let indexSpinner = null;
431
- let llmLog = null;
432
- let currentSpec = "";
433
- hooks.hook("resolve:start", ({ spec }) => {
434
- currentSpec = spec;
435
- spinner = timedSpinner();
436
- spinner.start(`Resolving ${spec}`);
437
- });
438
- hooks.hook("resolve:progress", ({ message }) => {
439
- spinner?.message(message);
440
- });
441
- hooks.hook("resolve:done", ({ version, cached, force }) => {
442
- const suffix = force ? " (force)" : cached ? " (cached)" : "";
443
- spinner?.stop(`Resolved ${currentSpec}@${version}${suffix}`);
444
- spinner = null;
445
- });
446
- hooks.hook("resolve:failed", ({ identityName }) => {
447
- spinner?.stop(`Could not find docs for: ${identityName}`);
448
- spinner = null;
449
- });
450
- hooks.hook("dist:downloading", () => {
451
- spinner?.message("Downloading dist");
452
- });
453
- hooks.hook("fetch:start", () => {
454
- resourceSpinner = timedSpinner();
455
- resourceSpinner.start("Finding resources");
456
- });
457
- hooks.hook("fetch:progress", ({ message }) => {
458
- resourceSpinner?.message(message);
459
- });
460
- hooks.hook("fetch:done", ({ parts, cached }) => {
461
- const summary = parts.length > 0 ? parts.join(", ") : "resources";
462
- resourceSpinner?.stop(cached ? `Loaded ${summary} (cached)` : `Fetched ${summary}`);
463
- resourceSpinner = null;
464
- });
465
- hooks.hook("index:start", () => {
466
- indexSpinner = timedSpinner();
467
- indexSpinner.start("Creating search index");
468
- });
469
- hooks.hook("index:progress", ({ message }) => {
470
- indexSpinner?.message(message);
471
- });
472
- hooks.hook("index:done", () => {
473
- indexSpinner?.stop("Search index ready");
474
- indexSpinner = null;
475
- });
476
- hooks.hook("warn", ({ message }) => {
477
- p.log.warn(styleText("yellow", message));
478
- });
479
- hooks.hook("base:done", ({ skillDir, mode }) => {
480
- p.log.success(mode === "update" ? `Updated skill: ${skillDir}` : `Created base skill: ${skillDir}`);
481
- });
482
- hooks.hook("sections:cached", () => {
483
- p.log.success("Applied cached SKILL.md sections");
484
- });
485
- hooks.hook("enhance:start", ({ spec, modelLabel }) => {
486
- currentSpec = spec;
487
- p.log.step(modelLabel);
488
- llmLog = p.taskLog({
489
- title: `Agent exploring ${spec}`,
490
- limit: 3
491
- });
492
- });
493
- hooks.hook("enhance:progress", ({ progress }) => {
494
- if (!llmLog) return;
495
- const line = `${progress.section ? `[${progress.section}] ` : ""}${progress.chunk}`;
496
- llmLog.message(line);
497
- });
498
- hooks.hook("enhance:done", (info) => {
499
- if (!llmLog) return;
500
- const parts = [];
501
- if (info.usage) parts.push(`${Math.round(info.usage.totalTokens / 1e3)}k tokens`);
502
- if (info.cost) parts.push(`$${info.cost.toFixed(2)}`);
503
- const suffix = parts.length > 0 ? ` (${parts.join(", ")})` : "";
504
- llmLog.success(`Generated best practices${suffix}`);
505
- llmLog = null;
506
- if (info.debugLogsDir) p.log.info(`Debug logs: ${relative(cwd, info.debugLogsDir)}`);
507
- if (info.error) p.log.warn(styleText("yellow", `Partial failure: ${info.error}`));
508
- if (info.warnings) for (const w of info.warnings) p.log.warn(styleText("yellow", w));
509
- });
510
- hooks.hook("enhance:failed", ({ error, rateLimited }) => {
511
- if (!llmLog) return;
512
- if (rateLimited) llmLog.error(`Rate limited by LLM provider. Try again shortly or use a different model via \`skilld config\``);
513
- else llmLog.error(`Enhancement failed${error ? `: ${error}` : ""}`);
514
- llmLog = null;
515
- });
516
- hooks.hook("shipped:installed", ({ skillName, skillDir }) => {
517
- p.log.success(`Using published SKILL.md: ${skillName} → ${relative(cwd, skillDir)}`);
518
- });
519
- }
520
- const STATUS_ICONS = {
521
- pending: "○",
522
- resolving: "◐",
523
- downloading: "◒",
524
- embedding: "◓",
525
- exploring: "◔",
526
- thinking: "◔",
527
- generating: "◑",
528
- done: "✓",
529
- error: "✗"
530
- };
531
- const STATUS_COLORS = {
532
- pending: "gray",
533
- resolving: "cyan",
534
- downloading: "cyan",
535
- embedding: "cyan",
536
- exploring: "blue",
537
- thinking: "magenta",
538
- generating: "yellow",
539
- done: "green",
540
- error: "red"
541
- };
542
- function renderParallel(r) {
543
- const maxNameLen = Math.max(...[...r.states.keys()].map((n) => n.length), 20);
544
- const lines = [...r.states.values()].map((s) => {
545
- const icon = styleText(STATUS_COLORS[s.status], STATUS_ICONS[s.status]);
546
- const name = s.name.padEnd(maxNameLen);
547
- const version = s.version ? `${styleText("gray", s.version)} ` : "";
548
- const elapsed = (s.status === "done" || s.status === "error") && s.startedAt && s.completedAt ? ` ${styleText("gray", `(${formatDuration(s.completedAt - s.startedAt)})`)}` : "";
549
- const preview = s.streamPreview ? ` ${styleText("gray", s.streamPreview)}` : "";
550
- return ` ${icon} ${name} ${version}${s.message}${elapsed}${preview}`;
551
- });
552
- const doneCount = [...r.states.values()].filter((s) => s.status === "done").length;
553
- const errorCount = [...r.states.values()].filter((s) => s.status === "error").length;
554
- const header = `${styleText("bold", `${r.verb} ${r.total} packages`)} (${doneCount} done${errorCount > 0 ? `, ${errorCount} failed` : ""})\n`;
555
- logUpdate(header + lines.join("\n"));
556
- }
557
- function bindParallelUi(hooks, render) {
558
- function update(spec, status, message, ver) {
559
- const state = render.states.get(spec);
560
- if (!state) return;
561
- if (!state.startedAt && status !== "pending") state.startedAt = performance.now();
562
- if ((status === "done" || status === "error") && !state.completedAt) state.completedAt = performance.now();
563
- state.status = status;
564
- state.message = message;
565
- state.streamPreview = void 0;
566
- if (ver) state.version = ver;
567
- renderParallel(render);
568
- }
569
- hooks.hook("resolve:start", ({ spec }) => update(spec, "resolving", "Resolving..."));
570
- hooks.hook("resolve:progress", ({ spec, message }) => update(spec, "resolving", message));
571
- hooks.hook("resolve:done", ({ spec, version, cached, force }) => {
572
- update(spec, "downloading", cached ? "Using cache" : force ? "Re-fetching docs..." : "Fetching docs...", version);
573
- });
574
- hooks.hook("resolve:failed", () => {});
575
- hooks.hook("dist:downloading", ({ spec }) => update(spec, "downloading", "Downloading dist..."));
576
- hooks.hook("fetch:start", () => {});
577
- hooks.hook("fetch:progress", ({ spec, message }) => update(spec, "downloading", message));
578
- hooks.hook("fetch:done", ({ spec }) => update(spec, "downloading", "Linking references..."));
579
- hooks.hook("index:start", ({ spec }) => update(spec, "embedding", "Indexing docs"));
580
- hooks.hook("index:progress", ({ spec, message }) => update(spec, "embedding", message));
581
- hooks.hook("index:done", () => {});
582
- hooks.hook("warn", () => {});
583
- hooks.hook("base:done", ({ spec, mode }) => {
584
- update(spec, "done", mode === "update" ? "Skill updated" : "Base skill created");
585
- });
586
- hooks.hook("sections:cached", () => {});
587
- hooks.hook("enhance:start", ({ spec, modelLabel }) => update(spec, "generating", modelLabel));
588
- hooks.hook("enhance:progress", ({ spec, progress }) => {
589
- update(spec, progress.type === "reasoning" ? "exploring" : "generating", `${progress.section ? `[${progress.section}] ` : ""}${progress.chunk}`);
590
- });
591
- hooks.hook("enhance:done", ({ spec }) => update(spec, "done", "Skill optimized"));
592
- hooks.hook("enhance:failed", ({ spec, error }) => update(spec, "error", error));
593
- hooks.hook("shipped:installed", ({ spec }) => update(spec, "done", "Published SKILL.md"));
594
- }
595
- const DIFF_RANK = {
596
- major: 5,
597
- premajor: 4,
598
- minor: 3,
599
- preminor: 2,
600
- patch: 1,
601
- prepatch: 1,
602
- prerelease: 0
603
- };
604
- async function syncPackagesParallel(config) {
605
- const { packages, concurrency = 5 } = config;
606
- const cwd = process.cwd();
607
- const states = /* @__PURE__ */ new Map();
608
- const specToName = /* @__PURE__ */ new Map();
609
- for (const spec of packages) {
610
- const { name } = parsePackageSpec(spec);
611
- specToName.set(spec, name);
612
- states.set(spec, {
613
- name,
614
- status: "pending",
615
- message: "Waiting..."
616
- });
617
- }
618
- const render = {
619
- states,
620
- verb: config.mode === "update" ? "Updating" : "Syncing",
621
- total: packages.length
622
- };
623
- ensureCacheDir();
624
- renderParallel(render);
625
- const run = createSyncRun({
626
- cwd,
627
- resolver: npmResolver,
628
- agent: config.agent,
629
- global: config.global,
630
- mode: config.mode,
631
- force: config.force,
632
- debug: config.debug,
633
- defaultSections: DEFAULT_SECTIONS
634
- });
635
- bindParallelUi(run.hooks, render);
636
- const limit = pLimit(concurrency);
637
- const baseResults = await Promise.allSettled(packages.map((spec) => limit(() => run.runBase(spec))));
638
- logUpdate.done();
639
- const ready = [];
640
- const shippedCount = [];
641
- const errors = [];
642
- const aggregatedWarnings = [];
643
- for (let i = 0; i < baseResults.length; i++) {
644
- const spec = packages[i];
645
- const r = baseResults[i];
646
- if (r.status === "rejected") {
647
- const err = r.reason;
648
- const reason = err instanceof Error ? err.message : String(err);
649
- const slot = states.get(spec);
650
- if (slot) slot.status = "error";
651
- errors.push({
652
- spec,
653
- reason
654
- });
655
- continue;
656
- }
657
- const result = r.value;
658
- if (result.kind === "shipped") {
659
- shippedCount.push(spec);
660
- continue;
661
- }
662
- if (result.kind === "unresolved") {
663
- const npmAttempt = result.attempts.find((a) => a.source === "npm");
664
- let reason;
665
- if (npmAttempt?.status === "not-found") {
666
- const suggestions = await searchNpmPackages(result.identityName, 3);
667
- const hint = suggestions.length > 0 ? ` (try: ${suggestions.map((s) => s.name).join(", ")})` : "";
668
- reason = (npmAttempt.message || "Not on npm") + hint;
669
- } else reason = result.attempts.filter((a) => a.status !== "success").map((a) => a.message || a.source).join("; ") || "No docs found";
670
- const slot = states.get(spec);
671
- if (slot) {
672
- slot.status = "error";
673
- slot.message = reason;
674
- }
675
- errors.push({
676
- spec,
677
- reason
678
- });
679
- continue;
680
- }
681
- if (result.kind === "error") {
682
- errors.push({
683
- spec,
684
- reason: result.reason
685
- });
686
- continue;
687
- }
688
- if (result.kind === "ready") ready.push({
689
- spec,
690
- state: result.state
691
- });
692
- }
693
- renderParallel(render);
694
- logUpdate.done();
695
- const pastVerb = config.mode === "update" ? "Updated" : "Created";
696
- p.log.success(`${pastVerb} ${ready.length} base skills${shippedCount.length > 0 ? ` (${shippedCount.length} shipped)` : ""}`);
697
- for (const w of aggregatedWarnings) p.log.warn(styleText("yellow", w));
698
- for (const { spec, reason } of errors) p.log.error(` ${spec}: ${reason}`);
699
- const cachedPkgs = [];
700
- const uncached = [];
701
- for (const r of ready) if (r.state.allSectionsCached) cachedPkgs.push(r.spec);
702
- else uncached.push(r);
703
- if (cachedPkgs.length > 0) p.log.success(`Applied cached SKILL.md sections for ${cachedPkgs.join(", ")}`);
704
- const globalConfig = readConfig();
705
- const resolvedModel = await resolveAutoModel(config.model, config.yes);
706
- if (uncached.length > 0 && !globalConfig.skipLlm && !(config.yes && !resolvedModel)) {
707
- const updateCtx = config.mode === "update" ? aggregateUpdateCtx(uncached) : void 0;
708
- const llmConfig = await selectLlmConfig(resolvedModel, void 0, updateCtx);
709
- if (llmConfig?.promptOnly) {
710
- for (const r of uncached) {
711
- const slot = states.get(r.spec);
712
- if (slot) {
713
- slot.status = "done";
714
- slot.message = "Prompts written";
715
- }
716
- }
717
- renderParallel(render);
718
- for (const r of uncached) await run.runEnhance(r.state, llmConfig);
719
- } else if (llmConfig) {
720
- p.log.step(getModelLabel(llmConfig.model));
721
- for (const r of uncached) {
722
- const displayName = specToName.get(r.spec) ?? r.spec;
723
- states.set(r.spec, {
724
- name: displayName,
725
- status: "pending",
726
- message: "Waiting...",
727
- version: getVersionKey(r.state.version)
728
- });
729
- }
730
- renderParallel(render);
731
- const llmResults = await Promise.allSettled(uncached.map((r) => limit(() => run.runEnhance(r.state, llmConfig))));
732
- logUpdate.done();
733
- const llmSucceeded = llmResults.filter((x) => x.status === "fulfilled").length;
734
- p.log.success(`Enhanced ${llmSucceeded}/${uncached.length} skills with LLM`);
735
- }
736
- } else for (const r of ready) await run.runEnhance(r.state, null);
737
- await ensureProjectFiles({
738
- cwd,
739
- agent: config.agent,
740
- global: config.global
741
- });
742
- await shutdownWorker();
743
- p.outro(`${pastVerb} ${ready.length}/${packages.length} packages`);
744
- const { suggestPrepareHook } = await import("./prepare-hook.mjs");
745
- try {
746
- await suggestPrepareHook(cwd);
747
- } catch (err) {
748
- p.log.warn(`Failed to suggest prepare hook: ${err instanceof Error ? err.message : String(err)}`);
749
- }
750
- }
751
- function aggregateUpdateCtx(ready) {
752
- let maxDiff = "";
753
- let allEnhanced = true;
754
- let anySyncedAt;
755
- for (const r of ready) {
756
- const u = r.state.updateCtx;
757
- if (!u?.wasEnhanced) allEnhanced = false;
758
- if (u?.syncedAt && (!anySyncedAt || u.syncedAt < anySyncedAt)) anySyncedAt = u.syncedAt;
759
- if (u?.oldVersion && u.newVersion) {
760
- const diff = semverDiff(u.oldVersion, u.newVersion);
761
- if (diff && (DIFF_RANK[diff] ?? 0) > (DIFF_RANK[maxDiff] ?? -1)) maxDiff = diff;
762
- }
763
- }
764
- const first = ready[0]?.state.updateCtx;
765
- return {
766
- oldVersion: ready.length === 1 ? first?.oldVersion : void 0,
767
- newVersion: ready.length === 1 ? first?.newVersion : void 0,
768
- syncedAt: anySyncedAt,
769
- wasEnhanced: allEnhanced,
770
- bumpType: maxDiff || void 0
771
- };
772
- }
773
- async function handleMerge(state, config, cwd) {
774
- const { identityName, storageName, version, resolved, baseDir, skillDir, skillDirName, existingLock } = state;
775
- p.log.step(`Merging ${identityName} into ${skillDirName}`);
776
- createReferenceCache(storageName, version).linkPkgNamed(skillDir, cwd);
777
- const repoSlug = parseGitHubRepoSlug(resolved.repoUrl);
778
- installSkill({
779
- cwd,
780
- agent: config.agent,
781
- global: config.global,
782
- baseDir,
783
- skillDirName,
784
- lock: {
785
- packageName: identityName,
786
- version,
787
- repo: repoSlug,
788
- source: existingLock.source,
789
- syncedAt: todayIsoDate(),
790
- generator: "skilld"
791
- },
792
- skipLinkAgents: true
793
- });
794
- const updatedLock = readLock(baseDir)?.skills[skillDirName];
795
- const allPackages = parsePackageNames(updatedLock?.packages);
796
- const relatedSkills = await findRelatedSkills(storageName, baseDir);
797
- const existingStorageName = toStoragePackageName(existingLock.packageName);
798
- const existingCache = createReferenceCache(existingStorageName, existingLock.version);
799
- const pkgFiles = existingCache.keyFiles(cwd);
800
- const shippedDocs = existingCache.hasShipped(cwd);
801
- const features = getActiveFeatures();
802
- writeGeneratedSkillMd(skillDir, {
803
- name: existingLock.packageName,
804
- version: existingLock.version,
805
- relatedSkills,
806
- hasIssues: features.issues && existsSync(skillRefsSection(skillDir, "issues")),
807
- hasDiscussions: features.discussions && existsSync(skillRefsSection(skillDir, "discussions")),
808
- hasReleases: features.releases && existsSync(skillRefsSection(skillDir, "releases")),
809
- docsType: existingLock.source?.includes("llms.txt") ? "llms.txt" : "docs",
810
- hasShippedDocs: shippedDocs,
811
- pkgFiles,
812
- dirName: skillDirName,
813
- packages: allPackages,
814
- features
815
- });
816
- const sharedDir = !config.global && getSharedSkillsDir(cwd);
817
- if (sharedDir) linkSkillToAgents(skillDirName, sharedDir, cwd, config.agent);
818
- p.outro(`Merged ${identityName} into ${skillDirName}`);
819
- }
820
- const RESOLVE_SOURCE_LABELS = {
821
- "npm": "npm registry",
822
- "github-docs": "GitHub versioned docs",
823
- "github-meta": "GitHub metadata",
824
- "github-search": "GitHub search",
825
- "readme": "README fallback",
826
- "llms.txt": "llms.txt convention",
827
- "crawl": "website crawl",
828
- "local": "local node_modules"
829
- };
830
- function showResolveAttempts(attempts) {
831
- if (attempts.length === 0) return;
832
- p.log.message(styleText("gray", "Doc resolution:"));
833
- for (const attempt of attempts) {
834
- const icon = attempt.status === "success" ? styleText("green", "✓") : styleText("gray", "✗");
835
- const label = RESOLVE_SOURCE_LABELS[attempt.source] ?? attempt.source;
836
- const source = styleText("gray", label);
837
- const msg = attempt.message ? ` ${styleText("gray", `— ${attempt.message}`)}` : "";
838
- p.log.message(` ${icon} ${source}${msg}`);
839
- }
840
- }
841
- async function syncCommand(state, opts) {
842
- if (opts.packages && opts.packages.length > 0) {
843
- const crateSpecs = opts.packages.filter(isCrateSpec);
844
- const npmSpecs = opts.packages.filter((p) => !isCrateSpec(p));
845
- if (npmSpecs.length > 1) await syncPackagesParallel({
846
- packages: npmSpecs,
847
- global: opts.global,
848
- agent: opts.agent,
849
- model: opts.model,
850
- yes: opts.yes,
851
- force: opts.force,
852
- debug: opts.debug,
853
- mode: opts.mode
854
- });
855
- else if (npmSpecs.length === 1) await syncSinglePackage(npmSpecs[0], opts);
856
- for (const spec of crateSpecs) await syncSinglePackage(spec, opts);
857
- return;
858
- }
859
- const packages = await interactivePicker(state);
860
- if (!packages || packages.length === 0) {
861
- p.outro("No packages selected");
862
- return;
863
- }
864
- if (packages.length > 1) return syncPackagesParallel({
865
- packages,
866
- global: opts.global,
867
- agent: opts.agent,
868
- model: opts.model,
869
- yes: opts.yes,
870
- force: opts.force,
871
- debug: opts.debug,
872
- mode: opts.mode
873
- });
874
- await syncSinglePackage(packages[0], opts);
875
- }
876
- async function interactivePicker(state) {
877
- const spin = timedSpinner();
878
- spin.start("Detecting imports...");
879
- const cwd = process.cwd();
880
- const { packages: detected, error } = await detectImportedPackages(cwd);
881
- const declaredMap = state.deps;
882
- if (error || detected.length === 0) {
883
- spin.stop(error ? `Detection failed: ${error}` : "No imports detected");
884
- if (declaredMap.size === 0) {
885
- p.log.warn("No dependencies found");
886
- return null;
887
- }
888
- return pickFromList(Array.from(declaredMap.entries(), ([name, version]) => ({
889
- name,
890
- version: maskPatch(version),
891
- count: 0,
892
- inPkgJson: true
893
- })), state);
894
- }
895
- spin.stop(`Loaded ${detected.length} project skills`);
896
- return pickFromList(detected.map((pkg) => ({
897
- name: pkg.name,
898
- version: declaredMap.get(pkg.name),
899
- count: pkg.count,
900
- inPkgJson: declaredMap.has(pkg.name)
901
- })), state);
902
- }
903
- function maskPatch(version) {
904
- if (!version) return void 0;
905
- const parts = version.split(".");
906
- if (parts.length >= 3) {
907
- parts[2] = "x";
908
- return parts.slice(0, 3).join(".");
909
- }
910
- return version;
911
- }
912
- async function pickFromList(packages, state) {
913
- const missingSet = new Set(state.missing);
914
- const outdatedSet = new Set(state.outdated.map((s) => s.name));
915
- const options = packages.map((pkg) => ({
916
- label: pkg.inPkgJson ? `${pkg.name} ★` : pkg.name,
917
- value: pkg.name,
918
- hint: [maskPatch(pkg.version), pkg.count > 0 ? `${pkg.count} imports` : null].filter(Boolean).join(" · ") || void 0
919
- }));
920
- const initialValues = packages.filter((pkg) => missingSet.has(pkg.name) || outdatedSet.has(pkg.name)).map((pkg) => pkg.name);
921
- const selected = await p.multiselect({
922
- message: "Select packages to sync",
923
- options,
924
- required: false,
925
- initialValues
926
- });
927
- if (p.isCancel(selected)) {
928
- p.cancel("Cancelled");
929
- return null;
930
- }
931
- return selected;
932
- }
933
- async function runSimpleSync(packageSpec, config) {
934
- const cwd = process.cwd();
935
- const isEject = !!config.eject;
936
- const run = createSyncRun({
937
- cwd,
938
- resolver: npmResolver,
939
- agent: config.agent,
940
- global: config.global,
941
- mode: config.mode,
942
- force: config.force,
943
- noSearch: config.noSearch,
944
- name: config.name,
945
- from: config.from,
946
- debug: config.debug,
947
- eject: config.eject,
948
- defaultSections: DEFAULT_SECTIONS,
949
- onMergeNeeded: (state) => handleMerge(state, {
950
- agent: config.agent,
951
- global: config.global
952
- }, cwd)
953
- });
954
- bindClackUi(run.hooks, { cwd });
955
- const base = await run.runBase(packageSpec);
956
- if (base.kind === "shipped") {
957
- p.outro(`Synced ${packageSpec}`);
958
- return;
959
- }
960
- if (base.kind === "unresolved") {
961
- if (!isCrateSpec(packageSpec)) {
962
- const suggestions = await searchNpmPackages(base.identityName);
963
- if (suggestions.length > 0) {
964
- showResolveAttempts(base.attempts);
965
- const selected = await p.select({
966
- message: "Did you mean one of these?",
967
- options: [...suggestions.map((s) => ({
968
- label: s.name,
969
- value: s.name,
970
- hint: s.description
971
- })), {
972
- label: "None of these",
973
- value: "_none_"
974
- }]
975
- });
976
- if (!p.isCancel(selected) && selected !== "_none_") return syncSinglePackage(selected, config);
977
- return;
978
- }
979
- }
980
- showResolveAttempts(base.attempts);
981
- return;
982
- }
983
- if (base.kind === "merged" || base.kind === "error") return;
984
- const { state } = base;
985
- const globalConfig = readConfig();
986
- const resolvedModel = await resolveAutoModel(config.model, config.yes);
987
- let llmConfig = null;
988
- if (!state.allSectionsCached && !globalConfig.skipLlm && !(config.yes && !resolvedModel)) llmConfig = await selectLlmConfig(resolvedModel, void 0, state.updateCtx);
989
- await run.runEnhance(state, llmConfig);
990
- await shutdownWorker();
991
- const ejectMsg = isEject ? " (ejected)" : "";
992
- const relDir = relative(cwd, state.skillDir);
993
- p.outro(config.mode === "update" ? `Updated ${state.identityName}${ejectMsg}` : `Synced ${state.identityName} → ${relDir}${ejectMsg}`);
994
- try {
995
- await suggestPrepareHook(cwd);
996
- } catch (err) {
997
- p.log.warn(`Failed to suggest prepare hook: ${err instanceof Error ? err.message : String(err)}`);
998
- }
999
- }
1000
- async function syncSinglePackage(packageSpec, config) {
1001
- if (isCrateSpec(packageSpec) && !packageSpec.slice(6).trim()) {
1002
- p.log.error("Invalid crate spec. Use format: crate:<name>");
1003
- return;
1004
- }
1005
- return runSimpleSync(packageSpec, config);
1006
- }
1007
- export { bindClackUi, createGithubResolver, createSyncRun, syncCommand };
1008
-
1009
- //# sourceMappingURL=sync.mjs.map