skilld 2.0.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +94 -0
- package/dist/_chunks/add.mjs +10 -9
- package/dist/_chunks/add.mjs.map +1 -1
- package/dist/_chunks/agent-prompt.mjs +4 -4
- package/dist/_chunks/agent-prompt.mjs.map +1 -1
- package/dist/_chunks/agent.mjs +282 -109
- package/dist/_chunks/agent.mjs.map +1 -1
- package/dist/_chunks/args.mjs +2 -2
- package/dist/_chunks/args.mjs.map +1 -1
- package/dist/_chunks/assemble.mjs +4 -4
- package/dist/_chunks/assemble.mjs.map +1 -1
- package/dist/_chunks/author.mjs +12 -11
- package/dist/_chunks/author.mjs.map +1 -1
- package/dist/_chunks/cache.mjs +21 -138
- package/dist/_chunks/cache.mjs.map +1 -1
- package/dist/_chunks/cache2.mjs +3 -3
- package/dist/_chunks/cache2.mjs.map +1 -1
- package/dist/_chunks/client.mjs +4 -3
- package/dist/_chunks/client.mjs.map +1 -1
- package/dist/_chunks/core.mjs +1 -1
- package/dist/_chunks/detect.mjs +1 -1
- package/dist/_chunks/detect.mjs.map +1 -1
- package/dist/_chunks/detect2.mjs +1 -1
- package/dist/_chunks/eject.mjs +7 -7
- package/dist/_chunks/eject.mjs.map +1 -1
- package/dist/_chunks/embedding-cache.mjs +1 -1
- package/dist/_chunks/embedding-cache2.mjs +14 -13
- package/dist/_chunks/embedding-cache2.mjs.map +1 -1
- package/dist/_chunks/env.mjs +1 -1
- package/dist/_chunks/env.mjs.map +1 -1
- package/dist/_chunks/index-identity.mjs +365 -0
- package/dist/_chunks/index-identity.mjs.map +1 -0
- package/dist/_chunks/index-identity2.mjs +2 -0
- package/dist/_chunks/install-many.mjs +20 -18
- package/dist/_chunks/install-many.mjs.map +1 -1
- package/dist/_chunks/install.mjs +34 -29
- package/dist/_chunks/install.mjs.map +1 -1
- package/dist/_chunks/intro.mjs +6 -6
- package/dist/_chunks/intro.mjs.map +1 -1
- package/dist/_chunks/list.mjs +5 -4
- package/dist/_chunks/list.mjs.map +1 -1
- package/dist/_chunks/lockfile.mjs +8 -6
- package/dist/_chunks/lockfile.mjs.map +1 -1
- package/dist/_chunks/login.mjs +7 -6
- package/dist/_chunks/login.mjs.map +1 -1
- package/dist/_chunks/logout.mjs +2 -2
- package/dist/_chunks/logout.mjs.map +1 -1
- package/dist/_chunks/map.mjs +1 -1
- package/dist/_chunks/map.mjs.map +1 -1
- package/dist/_chunks/markdown.mjs +2 -2
- package/dist/_chunks/markdown.mjs.map +1 -1
- package/dist/_chunks/menu.mjs +1 -1
- package/dist/_chunks/menu.mjs.map +1 -1
- package/dist/_chunks/model-picker.mjs +1 -1
- package/dist/_chunks/model-picker.mjs.map +1 -1
- package/dist/_chunks/monorepo.mjs +5 -4
- package/dist/_chunks/monorepo.mjs.map +1 -1
- package/dist/_chunks/package-json.mjs +7 -5
- package/dist/_chunks/package-json.mjs.map +1 -1
- package/dist/_chunks/paths.mjs +1 -1
- package/dist/_chunks/paths.mjs.map +1 -1
- package/dist/_chunks/pipeline.mjs +34 -26
- package/dist/_chunks/pipeline.mjs.map +1 -1
- package/dist/_chunks/pool.mjs +1 -1
- package/dist/_chunks/pool2.mjs +2 -2
- package/dist/_chunks/pool2.mjs.map +1 -1
- package/dist/_chunks/portable.mjs +8 -7
- package/dist/_chunks/portable.mjs.map +1 -1
- package/dist/_chunks/prepare-hook.mjs +1 -1
- package/dist/_chunks/prepare-hook2.mjs +3 -3
- package/dist/_chunks/prepare-hook2.mjs.map +1 -1
- package/dist/_chunks/prepare.mjs +17 -11
- package/dist/_chunks/prepare.mjs.map +1 -1
- package/dist/_chunks/prepare2.mjs +12 -10
- package/dist/_chunks/prepare2.mjs.map +1 -1
- package/dist/_chunks/prompts.mjs +8 -6
- package/dist/_chunks/prompts.mjs.map +1 -1
- package/dist/_chunks/pull.mjs +9 -8
- package/dist/_chunks/pull.mjs.map +1 -1
- package/dist/_chunks/regex.mjs +1 -1
- package/dist/_chunks/retriv.mjs +2 -2
- package/dist/_chunks/retriv2.mjs +22 -4
- package/dist/_chunks/retriv2.mjs.map +1 -1
- package/dist/_chunks/sanitize.mjs +1 -1
- package/dist/_chunks/sanitize.mjs.map +1 -1
- package/dist/_chunks/search-helpers.mjs +5 -5
- package/dist/_chunks/search-helpers.mjs.map +1 -1
- package/dist/_chunks/search-interactive.mjs +4 -4
- package/dist/_chunks/search-interactive.mjs.map +1 -1
- package/dist/_chunks/search.mjs +6 -6
- package/dist/_chunks/search.mjs.map +1 -1
- package/dist/_chunks/semver.mjs +111 -77
- package/dist/_chunks/semver.mjs.map +1 -1
- package/dist/_chunks/skill-installer.mjs +1 -1
- package/dist/_chunks/skill-installer2.mjs +26 -17
- package/dist/_chunks/skill-installer2.mjs.map +1 -1
- package/dist/_chunks/skills.mjs +7 -7
- package/dist/_chunks/skills.mjs.map +1 -1
- package/dist/_chunks/store.mjs +2 -2
- package/dist/_chunks/store.mjs.map +1 -1
- package/dist/_chunks/sync.mjs +26 -19
- package/dist/_chunks/sync.mjs.map +1 -1
- package/dist/_chunks/sync2.mjs +1 -1
- package/dist/_chunks/telemetry.mjs +3 -3
- package/dist/_chunks/telemetry.mjs.map +1 -1
- package/dist/_chunks/uninstall.mjs +32 -28
- package/dist/_chunks/uninstall.mjs.map +1 -1
- package/dist/_chunks/update.mjs +14 -13
- package/dist/_chunks/update.mjs.map +1 -1
- package/dist/_chunks/upload.mjs +13 -10
- package/dist/_chunks/upload.mjs.map +1 -1
- package/dist/_chunks/validate.mjs +1 -1
- package/dist/_chunks/validate.mjs.map +1 -1
- package/dist/_chunks/version.mjs +1 -1
- package/dist/_chunks/version.mjs.map +1 -1
- package/dist/_chunks/whoami.mjs +1 -1
- package/dist/_chunks/whoami.mjs.map +1 -1
- package/dist/_chunks/wizard.mjs +1 -1
- package/dist/_chunks/wizard2.mjs +8 -8
- package/dist/_chunks/wizard2.mjs.map +1 -1
- package/dist/_chunks/yaml.mjs +1 -1
- package/dist/_chunks/yaml.mjs.map +1 -1
- package/dist/cli-entry.d.mts +1 -1
- package/dist/cli.d.mts +1 -1
- package/dist/cli.mjs +111 -35
- package/dist/cli.mjs.map +1 -1
- package/dist/prepare.d.mts +1 -1
- package/dist/prepare.mjs +6 -4
- package/dist/prepare.mjs.map +1 -1
- package/dist/retriv/worker.d.mts.map +1 -1
- package/dist/retriv/worker.mjs +11 -5
- package/dist/retriv/worker.mjs.map +1 -1
- package/package.json +24 -24
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import "./agent.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
2
|
+
import { SECTION_OUTPUT_FILES, buildAllSectionPrompts, computeSkillDirName, portabilizePrompt, timedSpinner, todayIsoDate, writeGeneratedSkillMd } from "./prompts.mjs";
|
|
3
|
+
import { getActiveFeatures } from "./index-identity.mjs";
|
|
4
|
+
import { createReferenceCache, listReferenceFiles } from "./cache.mjs";
|
|
5
|
+
import { fetchPkgDist, parseGitHubRepoSlug, resolvePackageOrCrate } from "./semver.mjs";
|
|
6
|
+
import { writeLock } from "./lockfile.mjs";
|
|
7
|
+
import { ensureGitignore, ensureProjectFiles, installSkill, resolveBaseDir } from "./skill-installer2.mjs";
|
|
8
|
+
import { DEFAULT_SECTIONS, fetchAndCacheResources, prepareSkillReferences } from "./pipeline.mjs";
|
|
8
9
|
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
|
9
10
|
import { styleText } from "node:util";
|
|
10
11
|
import * as p from "@clack/prompts";
|
|
@@ -146,6 +147,6 @@ async function exportPortablePrompts(packageSpec, opts) {
|
|
|
146
147
|
const outputFileList = sectionList.map((s) => SECTION_OUTPUT_FILES[s]).join(", ");
|
|
147
148
|
p.log.info(`Have your agent enhance the skill. Give it this prompt:\n${styleText(["dim", "italic"], ` Read each prompt file (${promptFiles}) in ${relDir}/, read the\n referenced files, then write your output to the matching file (${outputFileList}).\n When done, run: skilld assemble`)}`);
|
|
148
149
|
}
|
|
149
|
-
export { exportPortablePrompts
|
|
150
|
+
export { exportPortablePrompts };
|
|
150
151
|
|
|
151
152
|
//# sourceMappingURL=portable.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"portable.mjs","names":[],"sources":["../../src/commands/sync/portable.ts"],"sourcesContent":["import type { AgentType, SkillSection } from '../../agent/index.ts'\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs'\nimport { styleText } from 'node:util'\nimport * as p from '@clack/prompts'\nimport { join, relative, resolve } from 'pathe'\nimport {\n buildAllSectionPrompts,\n computeSkillDirName,\n portabilizePrompt,\n SECTION_OUTPUT_FILES,\n writeGeneratedSkillMd,\n} from '../../agent/index.ts'\nimport { ensureGitignore, ensureProjectFiles, installSkill, resolveBaseDir } from '../../agent/skill-installer.ts'\nimport { createReferenceCache, listReferenceFiles } from '../../cache/index.ts'\nimport { getActiveFeatures } from '../../core/config.ts'\nimport { timedSpinner, todayIsoDate } from '../../core/formatting.ts'\nimport { writeLock } from '../../core/lockfile.ts'\nimport { parseGitHubRepoSlug } from '../../core/url.ts'\nimport {\n fetchPkgDist,\n resolvePackageOrCrate,\n} from '../../sources/index.ts'\nimport { DEFAULT_SECTIONS } from '../llm-prompts.ts'\nimport {\n fetchAndCacheResources,\n prepareSkillReferences,\n} from './pipeline.ts'\n\nexport async function exportPortablePrompts(packageSpec: string, opts: {\n out?: string\n sections?: SkillSection[]\n force?: boolean\n agent?: AgentType | 'none'\n}): Promise<void> {\n const sections = opts.sections ?? DEFAULT_SECTIONS\n\n const spin = timedSpinner()\n spin.start(`Resolving ${packageSpec}`)\n const cwd = process.cwd()\n\n const { packageName, localVersion, resolved } = await resolvePackageOrCrate(packageSpec, {\n cwd,\n onProgress: label => spin.message(`${packageSpec}: ${label}`),\n })\n\n if (!resolved) {\n spin.stop(`Could not find docs for: ${packageSpec}`)\n return\n }\n\n const version = localVersion || resolved.version || 'latest'\n const cache = createReferenceCache(packageName, version)\n const useCache = !opts.force && cache.has()\n\n if (!existsSync(join(cwd, 'node_modules', packageName))) {\n spin.message(`Downloading ${packageName}@${version} dist`)\n await fetchPkgDist(packageName, version)\n }\n\n spin.stop(`Resolved ${packageName}@${useCache ? cache.versionKey : version}`)\n cache.ensure()\n\n const skillDirName = computeSkillDirName(packageName)\n const features = getActiveFeatures()\n\n const agent: AgentType | null = opts.agent === 'none'\n ? null\n : opts.agent ?? (await import('../../agent/detect.ts').then(m => m.detectTargetAgent()))\n const baseDir = agent\n ? resolveBaseDir(cwd, agent, false)\n : join(cwd, '.claude', 'skills')\n const skillDir = opts.out ? resolve(cwd, opts.out) : join(baseDir, skillDirName)\n\n if (existsSync(skillDir) && !opts.force) {\n const existing = Object.values(SECTION_OUTPUT_FILES).filter(f => existsSync(join(skillDir, f)))\n if (existing.length > 0)\n p.log.warn(`Overwriting existing output files in ${relative(cwd, skillDir)}: ${existing.join(', ')}`)\n }\n mkdirSync(skillDir, { recursive: true })\n\n const resSpin = timedSpinner()\n resSpin.start('Fetching resources')\n const resources = await fetchAndCacheResources({\n packageName,\n resolved,\n version,\n useCache,\n features,\n onProgress: msg => resSpin.message(msg),\n })\n resSpin.stop('Resources ready')\n for (const w of resources.warnings)\n p.log.warn(styleText('yellow', w))\n\n const prepared = await prepareSkillReferences({\n packageName,\n version,\n cwd,\n skillDir,\n resources,\n features,\n baseDir: join(skillDir, '..'),\n })\n const { hasChangelog, shippedDocs, pkgFiles, relatedSkills } = prepared\n const docFiles = listReferenceFiles(skillDir)\n\n const prompts = buildAllSectionPrompts({\n packageName,\n skillDir,\n version,\n hasIssues: resources.hasIssues,\n hasDiscussions: resources.hasDiscussions,\n hasReleases: resources.hasReleases,\n hasChangelog,\n docFiles,\n docsType: resources.docsType,\n hasShippedDocs: shippedDocs,\n pkgFiles,\n features,\n sections,\n })\n\n cache.eject(skillDir, cwd, resources.docsType, { features, repoInfo: resources.repoInfo })\n cache.clearSkillInternal(skillDir)\n\n for (const [section, prompt] of prompts) {\n const portable = portabilizePrompt(prompt, section)\n writeFileSync(join(skillDir, `PROMPT_${section}.md`), portable)\n }\n\n writeGeneratedSkillMd(skillDir, {\n name: packageName,\n version,\n releasedAt: resolved.releasedAt,\n description: resolved.description,\n distTags: resolved.distTags,\n relatedSkills,\n hasIssues: resources.hasIssues,\n hasDiscussions: resources.hasDiscussions,\n hasReleases: resources.hasReleases,\n hasChangelog,\n docsType: resources.docsType,\n hasShippedDocs: shippedDocs,\n pkgFiles,\n repoUrl: resolved.repoUrl,\n features,\n eject: true,\n })\n\n const repoSlug = parseGitHubRepoSlug(resolved.repoUrl)\n if (agent) {\n const { shared } = installSkill({\n cwd,\n agent,\n global: false,\n baseDir,\n skillDirName,\n lock: {\n packageName,\n version,\n repo: repoSlug,\n source: resources.docSource,\n syncedAt: todayIsoDate(),\n generator: 'skilld',\n },\n })\n await ensureProjectFiles({ cwd, agent, global: false, shared })\n }\n else {\n writeLock(baseDir, skillDirName, {\n packageName,\n version,\n repo: repoSlug,\n source: resources.docSource,\n syncedAt: todayIsoDate(),\n generator: 'skilld',\n })\n await ensureGitignore('.claude/skills', cwd, false)\n }\n\n const relDir = relative(cwd, skillDir)\n const sectionList = [...prompts.keys()]\n p.log.success(`Skill installed to ${relDir}`)\n\n const promptFiles = sectionList.map(s => `PROMPT_${s}.md`).join(', ')\n const outputFileList = sectionList.map(s => SECTION_OUTPUT_FILES[s]).join(', ')\n p.log.info(`Have your agent enhance the skill. Give it this prompt:\\n${styleText(['dim', 'italic'], ` Read each prompt file (${promptFiles}) in ${relDir}/, read the\\n referenced files, then write your output to the matching file (${outputFileList}).\\n When done, run: skilld assemble`)}`)\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"portable.mjs","names":[],"sources":["../../src/commands/sync/portable.ts"],"sourcesContent":["import type { AgentType, SkillSection } from '../../agent/index.ts'\nimport { existsSync, mkdirSync, writeFileSync } from 'node:fs'\nimport { styleText } from 'node:util'\nimport * as p from '@clack/prompts'\nimport { join, relative, resolve } from 'pathe'\nimport {\n buildAllSectionPrompts,\n computeSkillDirName,\n portabilizePrompt,\n SECTION_OUTPUT_FILES,\n writeGeneratedSkillMd,\n} from '../../agent/index.ts'\nimport { ensureGitignore, ensureProjectFiles, installSkill, resolveBaseDir } from '../../agent/skill-installer.ts'\nimport { createReferenceCache, listReferenceFiles } from '../../cache/index.ts'\nimport { getActiveFeatures } from '../../core/config.ts'\nimport { timedSpinner, todayIsoDate } from '../../core/formatting.ts'\nimport { writeLock } from '../../core/lockfile.ts'\nimport { parseGitHubRepoSlug } from '../../core/url.ts'\nimport {\n fetchPkgDist,\n resolvePackageOrCrate,\n} from '../../sources/index.ts'\nimport { DEFAULT_SECTIONS } from '../llm-prompts.ts'\nimport {\n fetchAndCacheResources,\n prepareSkillReferences,\n} from './pipeline.ts'\n\nexport async function exportPortablePrompts(packageSpec: string, opts: {\n out?: string\n sections?: SkillSection[]\n force?: boolean\n agent?: AgentType | 'none'\n}): Promise<void> {\n const sections = opts.sections ?? DEFAULT_SECTIONS\n\n const spin = timedSpinner()\n spin.start(`Resolving ${packageSpec}`)\n const cwd = process.cwd()\n\n const { packageName, localVersion, resolved } = await resolvePackageOrCrate(packageSpec, {\n cwd,\n onProgress: label => spin.message(`${packageSpec}: ${label}`),\n })\n\n if (!resolved) {\n spin.stop(`Could not find docs for: ${packageSpec}`)\n return\n }\n\n const version = localVersion || resolved.version || 'latest'\n const cache = createReferenceCache(packageName, version)\n const useCache = !opts.force && cache.has()\n\n if (!existsSync(join(cwd, 'node_modules', packageName))) {\n spin.message(`Downloading ${packageName}@${version} dist`)\n await fetchPkgDist(packageName, version)\n }\n\n spin.stop(`Resolved ${packageName}@${useCache ? cache.versionKey : version}`)\n cache.ensure()\n\n const skillDirName = computeSkillDirName(packageName)\n const features = getActiveFeatures()\n\n const agent: AgentType | null = opts.agent === 'none'\n ? null\n : opts.agent ?? (await import('../../agent/detect.ts').then(m => m.detectTargetAgent()))\n const baseDir = agent\n ? resolveBaseDir(cwd, agent, false)\n : join(cwd, '.claude', 'skills')\n const skillDir = opts.out ? resolve(cwd, opts.out) : join(baseDir, skillDirName)\n\n if (existsSync(skillDir) && !opts.force) {\n const existing = Object.values(SECTION_OUTPUT_FILES).filter(f => existsSync(join(skillDir, f)))\n if (existing.length > 0)\n p.log.warn(`Overwriting existing output files in ${relative(cwd, skillDir)}: ${existing.join(', ')}`)\n }\n mkdirSync(skillDir, { recursive: true })\n\n const resSpin = timedSpinner()\n resSpin.start('Fetching resources')\n const resources = await fetchAndCacheResources({\n packageName,\n resolved,\n version,\n useCache,\n features,\n onProgress: msg => resSpin.message(msg),\n })\n resSpin.stop('Resources ready')\n for (const w of resources.warnings)\n p.log.warn(styleText('yellow', w))\n\n const prepared = await prepareSkillReferences({\n packageName,\n version,\n cwd,\n skillDir,\n resources,\n features,\n baseDir: join(skillDir, '..'),\n })\n const { hasChangelog, shippedDocs, pkgFiles, relatedSkills } = prepared\n const docFiles = listReferenceFiles(skillDir)\n\n const prompts = buildAllSectionPrompts({\n packageName,\n skillDir,\n version,\n hasIssues: resources.hasIssues,\n hasDiscussions: resources.hasDiscussions,\n hasReleases: resources.hasReleases,\n hasChangelog,\n docFiles,\n docsType: resources.docsType,\n hasShippedDocs: shippedDocs,\n pkgFiles,\n features,\n sections,\n })\n\n cache.eject(skillDir, cwd, resources.docsType, { features, repoInfo: resources.repoInfo })\n cache.clearSkillInternal(skillDir)\n\n for (const [section, prompt] of prompts) {\n const portable = portabilizePrompt(prompt, section)\n writeFileSync(join(skillDir, `PROMPT_${section}.md`), portable)\n }\n\n writeGeneratedSkillMd(skillDir, {\n name: packageName,\n version,\n releasedAt: resolved.releasedAt,\n description: resolved.description,\n distTags: resolved.distTags,\n relatedSkills,\n hasIssues: resources.hasIssues,\n hasDiscussions: resources.hasDiscussions,\n hasReleases: resources.hasReleases,\n hasChangelog,\n docsType: resources.docsType,\n hasShippedDocs: shippedDocs,\n pkgFiles,\n repoUrl: resolved.repoUrl,\n features,\n eject: true,\n })\n\n const repoSlug = parseGitHubRepoSlug(resolved.repoUrl)\n if (agent) {\n const { shared } = installSkill({\n cwd,\n agent,\n global: false,\n baseDir,\n skillDirName,\n lock: {\n packageName,\n version,\n repo: repoSlug,\n source: resources.docSource,\n syncedAt: todayIsoDate(),\n generator: 'skilld',\n },\n })\n await ensureProjectFiles({ cwd, agent, global: false, shared })\n }\n else {\n writeLock(baseDir, skillDirName, {\n packageName,\n version,\n repo: repoSlug,\n source: resources.docSource,\n syncedAt: todayIsoDate(),\n generator: 'skilld',\n })\n await ensureGitignore('.claude/skills', cwd, false)\n }\n\n const relDir = relative(cwd, skillDir)\n const sectionList = [...prompts.keys()]\n p.log.success(`Skill installed to ${relDir}`)\n\n const promptFiles = sectionList.map(s => `PROMPT_${s}.md`).join(', ')\n const outputFileList = sectionList.map(s => SECTION_OUTPUT_FILES[s]).join(', ')\n p.log.info(`Have your agent enhance the skill. Give it this prompt:\\n${styleText(['dim', 'italic'], ` Read each prompt file (${promptFiles}) in ${relDir}/, read the\\n referenced files, then write your output to the matching file (${outputFileList}).\\n When done, run: skilld assemble`)}`)\n}\n"],"mappings":";;;;;;;;;;;;AA4BA,eAAsB,sBAAsB,aAAqB,MAK/C;CAChB,MAAM,WAAW,KAAK,YAAY;CAElC,MAAM,OAAO,aAAa;CAC1B,KAAK,MAAM,aAAa,aAAa;CACrC,MAAM,MAAM,QAAQ,IAAI;CAExB,MAAM,EAAE,aAAa,cAAc,aAAa,MAAM,sBAAsB,aAAa;EACvF;EACA,aAAY,UAAS,KAAK,QAAQ,GAAG,YAAY,IAAI,OAAO;CAC9D,CAAC;CAED,IAAI,CAAC,UAAU;EACb,KAAK,KAAK,4BAA4B,aAAa;EACnD;CACF;CAEA,MAAM,UAAU,gBAAgB,SAAS,WAAW;CACpD,MAAM,QAAQ,qBAAqB,aAAa,OAAO;CACvD,MAAM,WAAW,CAAC,KAAK,SAAS,MAAM,IAAI;CAE1C,IA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AAQ,KAAK,CAAC;CACtC,EAAE,IAAI,QAAQ,sBAAsB,QAAQ;CAE5C,MAAM,cAAc,YAAY,KAAI,MAAK,UAAU,EAAE,IAAI,CAAC,CAAC,KAAK,IAAI;CACpE,MAAM,iBAAiB,YAAY,KAAI,MAAK,qBAAqB,EAAE,CAAC,CAAC,KAAK,IAAI;CAC9E,EAAE,IAAI,KAAK,4DAA4D,UAAU,CAAC,OAAO,QAAQ,GAAG,4BAA4B,YAAY,OAAO,OAAO,gFAAgF,eAAe,sCAAsC,GAAG;AACpS"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { suggestPrepareHook } from "./prepare-hook2.mjs";
|
|
2
2
|
export { suggestPrepareHook };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { editJsonProperty, patchPackageJson, readPackageJsonSafe } from "./package-json.mjs";
|
|
2
|
+
import { isInteractive } from "./env.mjs";
|
|
3
3
|
import { styleText } from "node:util";
|
|
4
4
|
import * as p from "@clack/prompts";
|
|
5
5
|
import { join } from "pathe";
|
|
@@ -56,6 +56,6 @@ function isSkilldDep(cwd) {
|
|
|
56
56
|
const deps = pkg.parsed;
|
|
57
57
|
return !!(deps.dependencies?.skilld || deps.devDependencies?.skilld);
|
|
58
58
|
}
|
|
59
|
-
export { hasPrepareHook
|
|
59
|
+
export { buildPrepareScript, hasPrepareHook, suggestPrepareHook };
|
|
60
60
|
|
|
61
61
|
//# sourceMappingURL=prepare-hook2.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare-hook2.mjs","names":[],"sources":["../../src/cli/prepare-hook.ts"],"sourcesContent":["import { styleText } from 'node:util'\nimport * as p from '@clack/prompts'\nimport { parseTree } from 'jsonc-parser'\nimport { join } from 'pathe'\nimport { editJsonProperty, patchPackageJson, readPackageJsonSafe } from '../core/package-json.ts'\nimport { isInteractive } from './env.ts'\n\nconst STATIC_REGEX_1 = /[&|;]+\\s*$/\nconst STATIC_REGEX_2 = /npx|\\.store|dlx/\n\nexport function hasPrepareHook(cwd: string = process.cwd()): boolean {\n const pkg = readPackageJsonSafe(join(cwd, 'package.json'))\n if (!pkg)\n return true\n const existing = (pkg.parsed.scripts as Record<string, unknown> | undefined)?.prepare\n return typeof existing === 'string' && existing.includes('skilld')\n}\n\nexport async function suggestPrepareHook(cwd: string = process.cwd()): Promise<boolean> {\n const pkgJsonPath = join(cwd, 'package.json')\n const pkg = readPackageJsonSafe(pkgJsonPath)\n if (!pkg)\n return false\n\n const rawExisting = (pkg.parsed.scripts as Record<string, unknown> | undefined)?.prepare\n const existing: string | undefined = typeof rawExisting === 'string' ? rawExisting : undefined\n\n if (existing?.includes('skilld'))\n return true\n\n const prepareCmd = buildPrepareScript(existing, cwd)\n\n if (!isInteractive()) {\n p.log.info(\n `${styleText('gray', 'Add to package.json scripts:')}\\n`\n + ` ${styleText('cyan', `\"prepare\": \"${prepareCmd}\"`)}\\n`\n + ` ${styleText('gray', 'Restores references and shipped skills on install.')}`,\n )\n return false\n }\n\n const confirmed = await p.confirm({\n message: `Add ${styleText('cyan', `\"prepare\": \"${prepareCmd}\"`)} to package.json?`,\n initialValue: true,\n })\n if (p.isCancel(confirmed) || !confirmed)\n return false\n\n patchPackageJson(pkgJsonPath, (content) => {\n const tree = parseTree(content)\n const hasScripts = tree?.children?.some(c =>\n c.type === 'property' && c.children?.[0]?.value === 'scripts',\n )\n\n let patched = content\n if (!hasScripts)\n patched = editJsonProperty(patched, ['scripts'], {})\n\n return editJsonProperty(patched, ['scripts', 'prepare'], prepareCmd)\n })\n p.log.success(`Added ${styleText('cyan', 'skilld prepare')} to package.json`)\n return true\n}\n\nexport function buildPrepareScript(existing: string | undefined, cwd: string = process.cwd()): string {\n const bin = isNpxExecution() && !isSkilldDep(cwd) ? 'npx skilld' : 'skilld'\n const cmd = `${bin} prepare || true`\n if (!existing || !existing.trim())\n return cmd\n\n const trimmed = existing.trim()\n const cleaned = trimmed.replace(STATIC_REGEX_1, '').trim()\n if (!cleaned)\n return cmd\n\n return `${cleaned} && (${cmd})`\n}\n\nfunction isNpxExecution(): boolean {\n if (process.env.npm_command === 'exec')\n return true\n const execPath = process.env._ || ''\n return STATIC_REGEX_2.test(execPath)\n}\n\nfunction isSkilldDep(cwd: string): boolean {\n const pkg = readPackageJsonSafe(join(cwd, 'package.json'))\n if (!pkg)\n return false\n const deps = pkg.parsed as Record<string, any>\n return !!(deps.dependencies?.skilld || deps.devDependencies?.skilld)\n}\n"],"mappings":";;;;;;AAOA,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,SAAgB,eAAe,MAAc,QAAQ,
|
|
1
|
+
{"version":3,"file":"prepare-hook2.mjs","names":[],"sources":["../../src/cli/prepare-hook.ts"],"sourcesContent":["import { styleText } from 'node:util'\nimport * as p from '@clack/prompts'\nimport { parseTree } from 'jsonc-parser'\nimport { join } from 'pathe'\nimport { editJsonProperty, patchPackageJson, readPackageJsonSafe } from '../core/package-json.ts'\nimport { isInteractive } from './env.ts'\n\nconst STATIC_REGEX_1 = /[&|;]+\\s*$/\nconst STATIC_REGEX_2 = /npx|\\.store|dlx/\n\nexport function hasPrepareHook(cwd: string = process.cwd()): boolean {\n const pkg = readPackageJsonSafe(join(cwd, 'package.json'))\n if (!pkg)\n return true\n const existing = (pkg.parsed.scripts as Record<string, unknown> | undefined)?.prepare\n return typeof existing === 'string' && existing.includes('skilld')\n}\n\nexport async function suggestPrepareHook(cwd: string = process.cwd()): Promise<boolean> {\n const pkgJsonPath = join(cwd, 'package.json')\n const pkg = readPackageJsonSafe(pkgJsonPath)\n if (!pkg)\n return false\n\n const rawExisting = (pkg.parsed.scripts as Record<string, unknown> | undefined)?.prepare\n const existing: string | undefined = typeof rawExisting === 'string' ? rawExisting : undefined\n\n if (existing?.includes('skilld'))\n return true\n\n const prepareCmd = buildPrepareScript(existing, cwd)\n\n if (!isInteractive()) {\n p.log.info(\n `${styleText('gray', 'Add to package.json scripts:')}\\n`\n + ` ${styleText('cyan', `\"prepare\": \"${prepareCmd}\"`)}\\n`\n + ` ${styleText('gray', 'Restores references and shipped skills on install.')}`,\n )\n return false\n }\n\n const confirmed = await p.confirm({\n message: `Add ${styleText('cyan', `\"prepare\": \"${prepareCmd}\"`)} to package.json?`,\n initialValue: true,\n })\n if (p.isCancel(confirmed) || !confirmed)\n return false\n\n patchPackageJson(pkgJsonPath, (content) => {\n const tree = parseTree(content)\n const hasScripts = tree?.children?.some(c =>\n c.type === 'property' && c.children?.[0]?.value === 'scripts',\n )\n\n let patched = content\n if (!hasScripts)\n patched = editJsonProperty(patched, ['scripts'], {})\n\n return editJsonProperty(patched, ['scripts', 'prepare'], prepareCmd)\n })\n p.log.success(`Added ${styleText('cyan', 'skilld prepare')} to package.json`)\n return true\n}\n\nexport function buildPrepareScript(existing: string | undefined, cwd: string = process.cwd()): string {\n const bin = isNpxExecution() && !isSkilldDep(cwd) ? 'npx skilld' : 'skilld'\n const cmd = `${bin} prepare || true`\n if (!existing || !existing.trim())\n return cmd\n\n const trimmed = existing.trim()\n const cleaned = trimmed.replace(STATIC_REGEX_1, '').trim()\n if (!cleaned)\n return cmd\n\n return `${cleaned} && (${cmd})`\n}\n\nfunction isNpxExecution(): boolean {\n if (process.env.npm_command === 'exec')\n return true\n const execPath = process.env._ || ''\n return STATIC_REGEX_2.test(execPath)\n}\n\nfunction isSkilldDep(cwd: string): boolean {\n const pkg = readPackageJsonSafe(join(cwd, 'package.json'))\n if (!pkg)\n return false\n const deps = pkg.parsed as Record<string, any>\n return !!(deps.dependencies?.skilld || deps.devDependencies?.skilld)\n}\n"],"mappings":";;;;;;AAOA,MAAM,iBAAiB;AACvB,MAAM,iBAAiB;AAEvB,SAAgB,eAAe,MAAc,QAAQ,IAAI,GAAY;CACnE,MAAM,MAAM,oBAAoB,KAAK,KAAK,cAAc,CAAC;CACzD,IAAI,CAAC,KACH,OAAO;CACT,MAAM,WAAY,IAAI,OAAO,SA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Ae,SAChD;CACnB,IAAI,CAAC,YAAY,CAAC,SAAS,KAAK,GAC9B,OAAO;CAGT,MAAM,UADU,SAAS,KACH,CAAC,CAAC,QAAQ,gBAAgB,EAAE,CAAC,CAAC,KAAK;CACzD,IAAI,CAAC,SACH,OAAO;CAET,OAAO,GAAG,QAAQ,OAAO,IAAI;AAC/B;AAEA,SAAS,iBAA0B;CACjC,IAAI,QAAQ,IAAI,gBAAgB,QAC9B,OAAO;CACT,MAAM,WAAW,QAAQ,IAAI,KAAK;CAClC,OAAO,eAAe,KAAK,QAAQ;AACrC;AAEA,SAAS,YAAY,KAAsB;CACzC,MAAM,MAAM,oBAAoB,KAAK,KAAK,cAAc,CAAC;CACzD,IAAI,CAAC,KACH,OAAO;CACT,MAAM,OAAO,IAAI;CACjB,OAAO,CAAC,EAAE,KAAK,cAAc,UAAU,KAAK,iBAAiB;AAC/D"}
|
package/dist/_chunks/prepare.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { REFERENCES_DIR } from "./paths.mjs";
|
|
2
|
+
import { README_FILENAME_RE } from "./regex.mjs";
|
|
3
|
+
import { readPackageJsonSafe } from "./package-json.mjs";
|
|
4
4
|
import { existsSync, lstatSync, mkdirSync, readdirSync, rmSync, symlinkSync, unlinkSync } from "node:fs";
|
|
5
5
|
import { basename, join, resolve } from "pathe";
|
|
6
6
|
const VALID_PKG_NAME = /^(?:@[a-z0-9][-a-z0-9._]*\/)?[a-z0-9][-a-z0-9._]*$/;
|
|
@@ -61,11 +61,13 @@ function getShippedSkills(name, cwd, version) {
|
|
|
61
61
|
}
|
|
62
62
|
function linkShippedSkill(baseDir, skillName, targetDir) {
|
|
63
63
|
const linkPath = join(baseDir, skillName);
|
|
64
|
-
if (existsSync(linkPath))
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
64
|
+
if (existsSync(linkPath)) {
|
|
65
|
+
if (lstatSync(linkPath).isSymbolicLink()) unlinkSync(linkPath);
|
|
66
|
+
else rmSync(linkPath, {
|
|
67
|
+
recursive: true,
|
|
68
|
+
force: true
|
|
69
|
+
});
|
|
70
|
+
}
|
|
69
71
|
symlinkSync(targetDir, linkPath);
|
|
70
72
|
}
|
|
71
73
|
function hasShippedDocs(name, cwd, version) {
|
|
@@ -75,14 +77,18 @@ function hasShippedDocs(name, cwd, version) {
|
|
|
75
77
|
"docs",
|
|
76
78
|
"documentation",
|
|
77
79
|
"doc"
|
|
78
|
-
])
|
|
80
|
+
]) {
|
|
81
|
+
const docsPath = join(pkgPath, candidate);
|
|
82
|
+
if (existsSync(docsPath)) return true;
|
|
83
|
+
}
|
|
79
84
|
return false;
|
|
80
85
|
}
|
|
81
86
|
function getPkgKeyFiles(name, cwd, version) {
|
|
82
87
|
const pkgPath = resolvePkgDir(name, cwd, version);
|
|
83
88
|
if (!pkgPath) return [];
|
|
84
89
|
const files = [];
|
|
85
|
-
const
|
|
90
|
+
const pkgJsonPath = join(pkgPath, "package.json");
|
|
91
|
+
const pkgJsonResult = readPackageJsonSafe(pkgJsonPath);
|
|
86
92
|
if (pkgJsonResult) {
|
|
87
93
|
const pkg = pkgJsonResult.parsed;
|
|
88
94
|
if (pkg.main) files.push(basename(pkg.main));
|
|
@@ -94,6 +100,6 @@ function getPkgKeyFiles(name, cwd, version) {
|
|
|
94
100
|
files.push(...entries);
|
|
95
101
|
return [...new Set(files)];
|
|
96
102
|
}
|
|
97
|
-
export {
|
|
103
|
+
export { getCacheDir, getPkgKeyFiles, getShippedSkills, getVersionKey, hasShippedDocs, linkShippedSkill, resolvePkgDir, restorePkgSymlink };
|
|
98
104
|
|
|
99
105
|
//# sourceMappingURL=prepare.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare.mjs","names":[],"sources":["../../src/cache/internal/version.ts","../../src/core/prepare.ts"],"sourcesContent":["/**\n * Version utilities\n */\n\nimport { resolve } from 'pathe'\nimport { REFERENCES_DIR } from '../../core/paths.ts'\n\n/** Validate npm package name (scoped or unscoped) */\nconst VALID_PKG_NAME = /^(?:@[a-z0-9][-a-z0-9._]*\\/)?[a-z0-9][-a-z0-9._]*$/\n\n/** Validate version string (semver-ish, no path separators) */\nconst VALID_VERSION = /^[a-z0-9][-\\w.+]*$/i\n\n/**\n * Get exact version key for cache keying\n */\nexport function getVersionKey(version: string): string {\n return version\n}\n\n/**\n * Get cache key for a package: name@version\n */\nexport function getCacheKey(name: string, version: string): string {\n return `${name}@${getVersionKey(version)}`\n}\n\n/**\n * Get path to cached package references.\n * Validates name/version to prevent path traversal.\n */\nexport function getCacheDir(name: string, version: string): string {\n if (!VALID_PKG_NAME.test(name))\n throw new Error(`Invalid package name: ${name}`)\n if (!VALID_VERSION.test(version))\n throw new Error(`Invalid version: ${version}`)\n\n const dir = resolve(REFERENCES_DIR, getCacheKey(name, version))\n if (!dir.startsWith(REFERENCES_DIR))\n throw new Error(`Path traversal detected: ${dir}`)\n return dir\n}\n","/**\n * Shared prepare utilities used by both the fast entry (src/prepare.ts)\n * and the full CLI command (src/commands/prepare.ts).\n *\n * Keep this module lightweight: no imports from agent/, cache/storage.ts,\n * or any module that pulls in sanitize/clack/citty.\n */\n\nimport type { SkillInfo } from './lockfile.ts'\nimport { existsSync, lstatSync, mkdirSync, readdirSync, rmSync, symlinkSync, unlinkSync } from 'node:fs'\nimport { basename, join } from 'pathe'\nimport { getCacheDir } from '../cache/internal/version.ts'\nimport { readPackageJsonSafe } from './package-json.ts'\nimport { README_FILENAME_RE } from './regex.ts'\n\nconst STATIC_REGEX_2 = /^changelog\\.md$/i\n\n/** Map lockfile identity name to storage-safe cache key (crate:X → @skilld-crate/X) */\nfunction toStorageName(name: string): string {\n if (name.startsWith('crate:'))\n return `@skilld-crate/${name.slice('crate:'.length)}`\n return name\n}\n\n/** Resolve package directory: node_modules first, then global cache */\nexport function resolvePkgDir(name: string, cwd: string, version?: string): string | null {\n const nodeModulesPath = join(cwd, 'node_modules', name)\n if (existsSync(nodeModulesPath))\n return nodeModulesPath\n\n if (version) {\n const cachedPkgDir = join(getCacheDir(name, version), 'pkg')\n if (existsSync(join(cachedPkgDir, 'package.json')))\n return cachedPkgDir\n }\n\n return null\n}\n\n/** Restore .skilld/pkg symlink to node_modules if broken */\nexport function restorePkgSymlink(skillsDir: string, name: string, info: SkillInfo, cwd: string): void {\n const refsDir = join(skillsDir, name, '.skilld')\n const pkgLink = join(refsDir, 'pkg')\n\n if (!existsSync(join(skillsDir, name)))\n return\n\n // Use lstatSync to detect dangling symlinks — existsSync follows symlinks\n // and returns false for dangling ones, causing symlinkSync to throw EEXIST\n try {\n const stat = lstatSync(pkgLink)\n if (stat.isSymbolicLink()) {\n if (existsSync(pkgLink))\n return // symlink exists and target is valid\n unlinkSync(pkgLink) // dangling symlink — remove before re-creating\n }\n else {\n return // real file/dir exists at this path\n }\n }\n catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT')\n return // permission/IO error — bail instead of masking\n }\n\n const pkgName = toStorageName(info.packageName || name)\n const pkgDir = resolvePkgDir(pkgName, cwd, info.version)\n if (!pkgDir)\n return\n\n mkdirSync(refsDir, { recursive: true })\n symlinkSync(pkgDir, pkgLink)\n}\n\nexport interface ShippedSkill {\n skillName: string\n skillDir: string\n}\n\n/** Check if package ships a skills/ directory with SKILL.md or _SKILL.md subdirs */\nexport function getShippedSkills(name: string, cwd: string, version?: string): ShippedSkill[] {\n const pkgPath = resolvePkgDir(name, cwd, version)\n if (!pkgPath)\n return []\n\n const skillsPath = join(pkgPath, 'skills')\n if (!existsSync(skillsPath))\n return []\n\n return readdirSync(skillsPath, { withFileTypes: true })\n .filter(d => d.isDirectory() && (existsSync(join(skillsPath, d.name, 'SKILL.md')) || existsSync(join(skillsPath, d.name, '_SKILL.md'))))\n .map(d => ({ skillName: d.name, skillDir: join(skillsPath, d.name) }))\n}\n\n/** Create symlink from skills dir to shipped skill dir */\nexport function linkShippedSkill(baseDir: string, skillName: string, targetDir: string): void {\n const linkPath = join(baseDir, skillName)\n if (existsSync(linkPath)) {\n const stat = lstatSync(linkPath)\n if (stat.isSymbolicLink())\n unlinkSync(linkPath)\n else rmSync(linkPath, { recursive: true, force: true })\n }\n symlinkSync(targetDir, linkPath)\n}\n\n/** Check if a package ships a docs/, documentation/, or doc/ directory */\nexport function hasShippedDocs(name: string, cwd: string, version?: string): boolean {\n const pkgPath = resolvePkgDir(name, cwd, version)\n if (!pkgPath)\n return false\n\n const docsCandidates = ['docs', 'documentation', 'doc']\n for (const candidate of docsCandidates) {\n const docsPath = join(pkgPath, candidate)\n if (existsSync(docsPath))\n return true\n }\n return false\n}\n\n/**\n * Get key files from a package directory for display.\n * Returns entry points + docs files.\n */\nexport function getPkgKeyFiles(name: string, cwd: string, version?: string): string[] {\n const pkgPath = resolvePkgDir(name, cwd, version)\n if (!pkgPath)\n return []\n\n const files: string[] = []\n const pkgJsonPath = join(pkgPath, 'package.json')\n\n const pkgJsonResult = readPackageJsonSafe(pkgJsonPath)\n if (pkgJsonResult) {\n const pkg = pkgJsonResult.parsed as Record<string, any>\n\n if (pkg.main)\n files.push(basename(pkg.main))\n if (pkg.module && pkg.module !== pkg.main)\n files.push(basename(pkg.module))\n\n const typesPath = pkg.types || pkg.typings\n if (typesPath && existsSync(join(pkgPath, typesPath)))\n files.push(typesPath)\n }\n\n const entries = readdirSync(pkgPath).filter(f =>\n README_FILENAME_RE.test(f) || STATIC_REGEX_2.test(f),\n )\n files.push(...entries)\n\n return [...new Set(files)]\n}\n"],"mappings":";;;;;;AAQA,MAAM,gBAAA;AAGN,SAAM,cAAgB,SAAA;;;AAKtB,SAAgB,YAAA,MAAc,SAAyB;CACrD,OAAO,GAAA,KAAA,GAAA,cAAA,
|
|
1
|
+
{"version":3,"file":"prepare.mjs","names":[],"sources":["../../src/cache/internal/version.ts","../../src/core/prepare.ts"],"sourcesContent":["/**\n * Version utilities\n */\n\nimport { resolve } from 'pathe'\nimport { REFERENCES_DIR } from '../../core/paths.ts'\n\n/** Validate npm package name (scoped or unscoped) */\nconst VALID_PKG_NAME = /^(?:@[a-z0-9][-a-z0-9._]*\\/)?[a-z0-9][-a-z0-9._]*$/\n\n/** Validate version string (semver-ish, no path separators) */\nconst VALID_VERSION = /^[a-z0-9][-\\w.+]*$/i\n\n/**\n * Get exact version key for cache keying\n */\nexport function getVersionKey(version: string): string {\n return version\n}\n\n/**\n * Get cache key for a package: name@version\n */\nexport function getCacheKey(name: string, version: string): string {\n return `${name}@${getVersionKey(version)}`\n}\n\n/**\n * Get path to cached package references.\n * Validates name/version to prevent path traversal.\n */\nexport function getCacheDir(name: string, version: string): string {\n if (!VALID_PKG_NAME.test(name))\n throw new Error(`Invalid package name: ${name}`)\n if (!VALID_VERSION.test(version))\n throw new Error(`Invalid version: ${version}`)\n\n const dir = resolve(REFERENCES_DIR, getCacheKey(name, version))\n if (!dir.startsWith(REFERENCES_DIR))\n throw new Error(`Path traversal detected: ${dir}`)\n return dir\n}\n","/**\n * Shared prepare utilities used by both the fast entry (src/prepare.ts)\n * and the full CLI command (src/commands/prepare.ts).\n *\n * Keep this module lightweight: no imports from agent/, cache/storage.ts,\n * or any module that pulls in sanitize/clack/citty.\n */\n\nimport type { SkillInfo } from './lockfile.ts'\nimport { existsSync, lstatSync, mkdirSync, readdirSync, rmSync, symlinkSync, unlinkSync } from 'node:fs'\nimport { basename, join } from 'pathe'\nimport { getCacheDir } from '../cache/internal/version.ts'\nimport { readPackageJsonSafe } from './package-json.ts'\nimport { README_FILENAME_RE } from './regex.ts'\n\nconst STATIC_REGEX_2 = /^changelog\\.md$/i\n\n/** Map lockfile identity name to storage-safe cache key (crate:X → @skilld-crate/X) */\nfunction toStorageName(name: string): string {\n if (name.startsWith('crate:'))\n return `@skilld-crate/${name.slice('crate:'.length)}`\n return name\n}\n\n/** Resolve package directory: node_modules first, then global cache */\nexport function resolvePkgDir(name: string, cwd: string, version?: string): string | null {\n const nodeModulesPath = join(cwd, 'node_modules', name)\n if (existsSync(nodeModulesPath))\n return nodeModulesPath\n\n if (version) {\n const cachedPkgDir = join(getCacheDir(name, version), 'pkg')\n if (existsSync(join(cachedPkgDir, 'package.json')))\n return cachedPkgDir\n }\n\n return null\n}\n\n/** Restore .skilld/pkg symlink to node_modules if broken */\nexport function restorePkgSymlink(skillsDir: string, name: string, info: SkillInfo, cwd: string): void {\n const refsDir = join(skillsDir, name, '.skilld')\n const pkgLink = join(refsDir, 'pkg')\n\n if (!existsSync(join(skillsDir, name)))\n return\n\n // Use lstatSync to detect dangling symlinks — existsSync follows symlinks\n // and returns false for dangling ones, causing symlinkSync to throw EEXIST\n try {\n const stat = lstatSync(pkgLink)\n if (stat.isSymbolicLink()) {\n if (existsSync(pkgLink))\n return // symlink exists and target is valid\n unlinkSync(pkgLink) // dangling symlink — remove before re-creating\n }\n else {\n return // real file/dir exists at this path\n }\n }\n catch (err) {\n if ((err as NodeJS.ErrnoException).code !== 'ENOENT')\n return // permission/IO error — bail instead of masking\n }\n\n const pkgName = toStorageName(info.packageName || name)\n const pkgDir = resolvePkgDir(pkgName, cwd, info.version)\n if (!pkgDir)\n return\n\n mkdirSync(refsDir, { recursive: true })\n symlinkSync(pkgDir, pkgLink)\n}\n\nexport interface ShippedSkill {\n skillName: string\n skillDir: string\n}\n\n/** Check if package ships a skills/ directory with SKILL.md or _SKILL.md subdirs */\nexport function getShippedSkills(name: string, cwd: string, version?: string): ShippedSkill[] {\n const pkgPath = resolvePkgDir(name, cwd, version)\n if (!pkgPath)\n return []\n\n const skillsPath = join(pkgPath, 'skills')\n if (!existsSync(skillsPath))\n return []\n\n return readdirSync(skillsPath, { withFileTypes: true })\n .filter(d => d.isDirectory() && (existsSync(join(skillsPath, d.name, 'SKILL.md')) || existsSync(join(skillsPath, d.name, '_SKILL.md'))))\n .map(d => ({ skillName: d.name, skillDir: join(skillsPath, d.name) }))\n}\n\n/** Create symlink from skills dir to shipped skill dir */\nexport function linkShippedSkill(baseDir: string, skillName: string, targetDir: string): void {\n const linkPath = join(baseDir, skillName)\n if (existsSync(linkPath)) {\n const stat = lstatSync(linkPath)\n if (stat.isSymbolicLink())\n unlinkSync(linkPath)\n else rmSync(linkPath, { recursive: true, force: true })\n }\n symlinkSync(targetDir, linkPath)\n}\n\n/** Check if a package ships a docs/, documentation/, or doc/ directory */\nexport function hasShippedDocs(name: string, cwd: string, version?: string): boolean {\n const pkgPath = resolvePkgDir(name, cwd, version)\n if (!pkgPath)\n return false\n\n const docsCandidates = ['docs', 'documentation', 'doc']\n for (const candidate of docsCandidates) {\n const docsPath = join(pkgPath, candidate)\n if (existsSync(docsPath))\n return true\n }\n return false\n}\n\n/**\n * Get key files from a package directory for display.\n * Returns entry points + docs files.\n */\nexport function getPkgKeyFiles(name: string, cwd: string, version?: string): string[] {\n const pkgPath = resolvePkgDir(name, cwd, version)\n if (!pkgPath)\n return []\n\n const files: string[] = []\n const pkgJsonPath = join(pkgPath, 'package.json')\n\n const pkgJsonResult = readPackageJsonSafe(pkgJsonPath)\n if (pkgJsonResult) {\n const pkg = pkgJsonResult.parsed as Record<string, any>\n\n if (pkg.main)\n files.push(basename(pkg.main))\n if (pkg.module && pkg.module !== pkg.main)\n files.push(basename(pkg.module))\n\n const typesPath = pkg.types || pkg.typings\n if (typesPath && existsSync(join(pkgPath, typesPath)))\n files.push(typesPath)\n }\n\n const entries = readdirSync(pkgPath).filter(f =>\n README_FILENAME_RE.test(f) || STATIC_REGEX_2.test(f),\n )\n files.push(...entries)\n\n return [...new Set(files)]\n}\n"],"mappings":";;;;;;AAQA,MAAM,gBAAA;AAGN,SAAM,cAAgB,SAAA;;;AAKtB,SAAgB,YAAA,MAAc,SAAyB;CACrD,OAAO,GAAA,KAAA,GAAA,cAAA,OAAA;AACT;;;CAKA,IAAA,CAAA,cAAgB,KAAY,OAAc,GAAA,MAAyB,IAAA,MAAA,oBAAA,SAAA;CACjE,MAAA,MAAU,QAAQ,gBAAc,YAAO,MAAA,OAAA,CAAA;CACzC,IAAA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import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
3
|
+
import { linkSkillToAgents, todayIsoDate } from "./prompts.mjs";
|
|
4
|
+
import { getSharedSkillsDir } from "./paths.mjs";
|
|
5
|
+
import { VERSION_RANGE_PREFIX_RE } from "./regex.mjs";
|
|
6
|
+
import { getShippedSkills, linkShippedSkill, restorePkgSymlink } from "./prepare.mjs";
|
|
7
|
+
import { resolveAgent } from "./agent-prompt.mjs";
|
|
8
|
+
import { readLock, writeLock } from "./lockfile.mjs";
|
|
9
|
+
import { getProjectState } from "./skills.mjs";
|
|
10
10
|
import { existsSync, mkdirSync } from "node:fs";
|
|
11
11
|
import * as p from "@clack/prompts";
|
|
12
12
|
import { defineCommand } from "citty";
|
|
@@ -34,13 +34,15 @@ const prepareCommandDef = defineCommand({
|
|
|
34
34
|
let allIntact = true;
|
|
35
35
|
for (const [name, info] of Object.entries(lock.skills)) {
|
|
36
36
|
if (!info.version) continue;
|
|
37
|
-
|
|
37
|
+
const skillDir = join(skillsDir, name);
|
|
38
|
+
if (existsSync(skillDir)) {
|
|
38
39
|
if (info.source !== "shipped") restorePkgSymlink(skillsDir, name, info, cwd);
|
|
39
40
|
continue;
|
|
40
41
|
}
|
|
41
42
|
allIntact = false;
|
|
42
43
|
if (info.source === "shipped") {
|
|
43
|
-
const
|
|
44
|
+
const pkgName = info.packageName || name;
|
|
45
|
+
const match = getShippedSkills(pkgName, cwd, info.version).find((s) => s.skillName === name);
|
|
44
46
|
if (match) linkShippedSkill(skillsDir, name, match.skillDir);
|
|
45
47
|
}
|
|
46
48
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepare2.mjs","names":["agents"],"sources":["../../src/commands/prepare.ts"],"sourcesContent":["/**\n * Prepare command — lightweight hook for package.json \"prepare\" script.\n *\n * Designed to run on every `pnpm install` / `npm install`. Blocking, fast, no LLM calls.\n * 1. Restore broken symlinks from lockfile (like `install` but skips doc fetching)\n * 2. Auto-install shipped skills from deps (just symlinks + lockfile writes)\n * 3. Report outdated skills count and suggest `skilld update`\n */\n\nimport { existsSync, mkdirSync } from 'node:fs'\nimport * as p from '@clack/prompts'\nimport { defineCommand } from 'citty'\nimport { join } from 'pathe'\nimport { agents, linkSkillToAgents } from '../agent/index.ts'\nimport { resolveAgent } from '../cli/agent-prompt.ts'\nimport { todayIsoDate } from '../core/formatting.ts'\nimport { readLock, writeLock } from '../core/lockfile.ts'\nimport { getSharedSkillsDir } from '../core/paths.ts'\nimport { getShippedSkills, linkShippedSkill, restorePkgSymlink } from '../core/prepare.ts'\nimport { VERSION_RANGE_PREFIX_RE } from '../core/regex.ts'\nimport { getProjectState } from '../core/skills.ts'\n\nexport const prepareCommandDef = defineCommand({\n meta: { name: 'prepare', description: 'Restore references and sync shipped skills (for package.json hooks)' },\n args: {\n agent: {\n type: 'enum' as const,\n options: Object.keys(agents),\n alias: 'a',\n description: 'Target agent',\n },\n },\n async run({ args }) {\n const cwd = process.cwd()\n\n const agent = resolveAgent(args.agent)\n if (!agent || agent === 'none')\n return\n\n const agentConfig = agents[agent]\n const shared = getSharedSkillsDir(cwd)\n const skillsDir = shared || join(cwd, agentConfig.skillsDir)\n\n // ── Fast path: read primary lockfile, check all skills intact ──\n\n const lock = readLock(skillsDir)\n if (lock && Object.keys(lock.skills).length > 0) {\n let allIntact = true\n\n for (const [name, info] of Object.entries(lock.skills)) {\n if (!info.version)\n continue\n\n const skillDir = join(skillsDir, name)\n if (existsSync(skillDir)) {\n // Skill dir exists; for non-shipped, also check .skilld/pkg symlink\n if (info.source !== 'shipped')\n restorePkgSymlink(skillsDir, name, info, cwd)\n continue\n }\n\n // Skill dir missing, needs restore\n allIntact = false\n\n if (info.source === 'shipped') {\n const pkgName = info.packageName || name\n const shipped = getShippedSkills(pkgName, cwd, info.version)\n const match = shipped.find(s => s.skillName === name)\n if (match)\n linkShippedSkill(skillsDir, name, match.skillDir)\n }\n }\n\n // If all skills intact, skip expensive getProjectState entirely\n if (allIntact)\n return\n }\n\n // ── Slow path: discover new shipped skills + report outdated ──\n\n const state = await getProjectState(cwd)\n let shippedCount = 0\n\n if (state.shipped.length > 0) {\n mkdirSync(skillsDir, { recursive: true })\n\n for (const entry of state.shipped) {\n const version = state.deps.get(entry.packageName)?.replace(VERSION_RANGE_PREFIX_RE, '') || '0.0.0'\n\n for (const skill of entry.skills) {\n linkShippedSkill(skillsDir, skill.skillName, skill.skillDir)\n writeLock(skillsDir, skill.skillName, {\n packageName: entry.packageName,\n version,\n source: 'shipped',\n syncedAt: todayIsoDate(),\n generator: 'skilld',\n })\n\n if (shared)\n linkSkillToAgents(skill.skillName, shared, cwd, agent)\n\n shippedCount++\n }\n }\n\n if (shippedCount > 0)\n p.log.success(`Installed ${shippedCount} shipped skill${shippedCount > 1 ? 's' : ''}`)\n }\n\n if (state.outdated.length > 0) {\n const n = state.outdated.length\n p.log.info(`${n} package${n > 1 ? 's' : ''} ha${n > 1 ? 've' : 's'} new features and/or breaking changes. Run \\`skilld update\\` to sync.`)\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAsBA,SAAa,OAAA,KAAA,
|
|
1
|
+
{"version":3,"file":"prepare2.mjs","names":["agents"],"sources":["../../src/commands/prepare.ts"],"sourcesContent":["/**\n * Prepare command — lightweight hook for package.json \"prepare\" script.\n *\n * Designed to run on every `pnpm install` / `npm install`. Blocking, fast, no LLM calls.\n * 1. Restore broken symlinks from lockfile (like `install` but skips doc fetching)\n * 2. Auto-install shipped skills from deps (just symlinks + lockfile writes)\n * 3. Report outdated skills count and suggest `skilld update`\n */\n\nimport { existsSync, mkdirSync } from 'node:fs'\nimport * as p from '@clack/prompts'\nimport { defineCommand } from 'citty'\nimport { join } from 'pathe'\nimport { agents, linkSkillToAgents } from '../agent/index.ts'\nimport { resolveAgent } from '../cli/agent-prompt.ts'\nimport { todayIsoDate } from '../core/formatting.ts'\nimport { readLock, writeLock } from '../core/lockfile.ts'\nimport { getSharedSkillsDir } from '../core/paths.ts'\nimport { getShippedSkills, linkShippedSkill, restorePkgSymlink } from '../core/prepare.ts'\nimport { VERSION_RANGE_PREFIX_RE } from '../core/regex.ts'\nimport { getProjectState } from '../core/skills.ts'\n\nexport const prepareCommandDef = defineCommand({\n meta: { name: 'prepare', description: 'Restore references and sync shipped skills (for package.json hooks)' },\n args: {\n agent: {\n type: 'enum' as const,\n options: Object.keys(agents),\n alias: 'a',\n description: 'Target agent',\n },\n },\n async run({ args }) {\n const cwd = process.cwd()\n\n const agent = resolveAgent(args.agent)\n if (!agent || agent === 'none')\n return\n\n const agentConfig = agents[agent]\n const shared = getSharedSkillsDir(cwd)\n const skillsDir = shared || join(cwd, agentConfig.skillsDir)\n\n // ── Fast path: read primary lockfile, check all skills intact ──\n\n const lock = readLock(skillsDir)\n if (lock && Object.keys(lock.skills).length > 0) {\n let allIntact = true\n\n for (const [name, info] of Object.entries(lock.skills)) {\n if (!info.version)\n continue\n\n const skillDir = join(skillsDir, name)\n if (existsSync(skillDir)) {\n // Skill dir exists; for non-shipped, also check .skilld/pkg symlink\n if (info.source !== 'shipped')\n restorePkgSymlink(skillsDir, name, info, cwd)\n continue\n }\n\n // Skill dir missing, needs restore\n allIntact = false\n\n if (info.source === 'shipped') {\n const pkgName = info.packageName || name\n const shipped = getShippedSkills(pkgName, cwd, info.version)\n const match = shipped.find(s => s.skillName === name)\n if (match)\n linkShippedSkill(skillsDir, name, match.skillDir)\n }\n }\n\n // If all skills intact, skip expensive getProjectState entirely\n if (allIntact)\n return\n }\n\n // ── Slow path: discover new shipped skills + report outdated ──\n\n const state = await getProjectState(cwd)\n let shippedCount = 0\n\n if (state.shipped.length > 0) {\n mkdirSync(skillsDir, { recursive: true })\n\n for (const entry of state.shipped) {\n const version = state.deps.get(entry.packageName)?.replace(VERSION_RANGE_PREFIX_RE, '') || '0.0.0'\n\n for (const skill of entry.skills) {\n linkShippedSkill(skillsDir, skill.skillName, skill.skillDir)\n writeLock(skillsDir, skill.skillName, {\n packageName: entry.packageName,\n version,\n source: 'shipped',\n syncedAt: todayIsoDate(),\n generator: 'skilld',\n })\n\n if (shared)\n linkSkillToAgents(skill.skillName, shared, cwd, agent)\n\n shippedCount++\n }\n }\n\n if (shippedCount > 0)\n p.log.success(`Installed ${shippedCount} shipped skill${shippedCount > 1 ? 's' : ''}`)\n }\n\n if (state.outdated.length > 0) {\n const n = state.outdated.length\n p.log.info(`${n} package${n > 1 ? 's' : ''} ha${n > 1 ? 've' : 's'} new features and/or breaking changes. Run \\`skilld update\\` to sync.`)\n }\n },\n})\n"],"mappings":";;;;;;;;;;;;;;;;;;;;EAsBA,SAAa,OAAA,KAAA,OAAoB;EAC/B,OAAM;EAAE,aAAM;CAAW,EAAA;CAAmF,MAAA,IAAA,EAAA,QAAA;EAC5G,MAAM,MACJ,QAAO,IAAA;EACL,MAAM,QAAA,aAAA,KAAA,KAAA;EACN,IAAA,CAAA,SAAS,UAAYA,QAAM;EAC3B,MAAA,cAAO,QAAA;EACP,MAAA,SAAa,mBAAA,GAAA;EACf,MACF,YAAA,UAAA,KAAA,KAAA,YAAA,SAAA;EACA,MAAM,OAAM,SAAQ,SAAA;EAClB,IAAA,QAAY,OAAA,KAAY,KAAA,MAAA,CAAA,CAAA,SAAA,GAAA;GAExB,IAAA,YAAc;GACd,KAAK,MAAA,CAAA,MAAS,SAAU,OACtB,QAAA,KAAA,MAAA,GAAA;IAEF,IAAM,CAAA,KAAA,SAAcA;IACpB,MAAM,WAAS,KAAA,WAAmB,IAAG;IACrC,IAAM,WAAA,QAAY,GAAU;KAI5B,IAAM,KAAA,WAAgB,WAAS,kBAAA,WAAA,MAAA,MAAA,GAAA;KAC/B;IACE;IAEA,YAAY;IACV,IAAI,KAAC,WACH,WAAA;KAEF,MAAM,UAAW,KAAK,eAAe;KACrC,MAAI,QAAW,iBAAW,SAAA,KAAA,KAAA,OAAA,CAAA,CAAA,MAAA,MAAA,EAAA,cAAA,IAAA;KAExB,IAAI,OAAK,iBAAW,WAClB,MAAA,MAAkB,QAAA;IACpB;GACF;GAGA,IAAA,WAAY;EAEZ;EACE,MAAA,QAAM,MAAU,gBAAK,GAAe;EAEpC,IAAA,eADgB;EAEhB,IAAA,MAAI,QACF,SAAA,GAAA;GACJ,UAAA,WAAA,EAAA,WAAA,KAAA,CAAA;GACF,KAAA,MAAA,SAAA,MAAA,SAAA;IAGA,MAAI,UACF,MAAA,KAAA,IAAA,MAAA,WAAA,CAAA,EAAA,QAAA,yBAAA,EAAA,KAAA;IACJ,KAAA,MAAA,SAAA,MAAA,QAAA;KAIA,iBAAoB,WAAA,MAAgB,WAAG,MAAA,QAAA;KACvC,UAAI,WAAe,MAAA,WAAA;MAEf,aAAM,MAAQ;MAChB;MAEA,QAAW;MACT,UAAM,aAAgB;MAEtB,WAAW;KACT,CAAA;KACA,IAAA,QAAU,kBAAiB,MAAA,WAAW,QAAA,KAAA,KAAA;KACpC;IACA;GACA;GACA,IAAA,eAAU,GAAA,EAAA,IAAa,QAAA,aAAA,aAAA,gBAAA,eAAA,IAAA,MAAA,IAAA;EACvB;EACF,IAAC,MAAA,SAAA,SAAA,GAAA;GAED,MAAI,IAAA,MACF,SAAA;GAEF,EAAA,IAAA,KAAA,GAAA,EAAA,UAAA,IAAA,IAAA,MAAA,GAAA,KAAA,IAAA,IAAA,OAAA,IAAA,sEAAA;EACF;CACF;AAEA,CAAA;AAIF,SAAI"}
|
package/dist/_chunks/prompts.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { targets } from "./detect.mjs";
|
|
2
2
|
import "./paths.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
3
|
+
import { NPM_SCOPE_PREFIX_RE, SEMVER_MAJOR_MINOR_RE } from "./regex.mjs";
|
|
4
|
+
import { repairMarkdown, sanitizeMarkdown } from "./sanitize.mjs";
|
|
5
|
+
import { yamlEscape } from "./yaml.mjs";
|
|
6
6
|
import { existsSync, lstatSync, mkdirSync, symlinkSync, unlinkSync, writeFileSync } from "node:fs";
|
|
7
7
|
import { styleText } from "node:util";
|
|
8
8
|
import * as p from "@clack/prompts";
|
|
@@ -1087,7 +1087,9 @@ function linkSkillToAgents(skillName, sharedDir, cwd, agentType) {
|
|
|
1087
1087
|
} catch {}
|
|
1088
1088
|
if (targetExists && !isSymlink) continue;
|
|
1089
1089
|
if (isSymlink) unlinkSync(target);
|
|
1090
|
-
|
|
1090
|
+
const source = join(sharedDir, skillName);
|
|
1091
|
+
const rel = relative(agentSkillsDir, source);
|
|
1092
|
+
symlinkSync(rel, target);
|
|
1091
1093
|
linkedDirs.add(agentSkillsDir);
|
|
1092
1094
|
}
|
|
1093
1095
|
}
|
|
@@ -1245,6 +1247,6 @@ function generateFooter(relatedSkills) {
|
|
|
1245
1247
|
if (relatedSkills.length === 0) return "";
|
|
1246
1248
|
return `\nRelated: ${relatedSkills.join(", ")}\n`;
|
|
1247
1249
|
}
|
|
1248
|
-
export {
|
|
1250
|
+
export { SECTION_MERGE_ORDER, SECTION_OUTPUT_FILES, buildAllSectionPrompts, computeSkillDirName, extractMarkedSections, formatCompactSnippet, formatDuration, formatSnippet, formatSource, getBlogPreset, getCrawlUrl, getDocOverride, getPrereleaseChangelogRef, getSectionValidator, highlightTerms, linkSkillToAgents, maxItems, maxLines, normalizeScores, portabilizePrompt, resolveSkilldCommand, sanitizeName, scoreLabel, timeAgo, timedSpinner, todayIsoDate, unlinkSkillFromAgents, wrapSection, writeGeneratedSkillMd, writeSkillMd };
|
|
1249
1251
|
|
|
1250
1252
|
//# sourceMappingURL=prompts.mjs.map
|