nuxt-ai-ready 3.6.0 → 3.6.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (161) hide show
  1. package/dist/agent-skills-config-CmZq9uWW.mjs +18 -0
  2. package/dist/agent-skills-zGLgFB6H.mjs +468 -0
  3. package/dist/cli.d.mts +1 -0
  4. package/dist/cli.mjs +656 -570
  5. package/dist/devtools/pages/ai-ready/debug.vue +9 -3
  6. package/dist/devtools/pages/ai-ready/index.vue +3 -1
  7. package/dist/devtools/pages/ai-ready/llms-txt.vue +15 -4
  8. package/dist/devtools/pages/ai-ready.vue +28 -4
  9. package/dist/module.d.mts +106 -112
  10. package/dist/module.json +3 -3
  11. package/dist/module.mjs +2732 -26
  12. package/dist/package-metadata-B1darl8W.mjs +28 -0
  13. package/dist/prerender-QMv07W4h.mjs +650 -0
  14. package/dist/runtime/app/composables/webmcp.js +90 -97
  15. package/dist/runtime/app/plugins/md-alternate.server.js +29 -26
  16. package/dist/runtime/app/plugins/md-hints.prerender.js +13 -15
  17. package/dist/runtime/app/plugins/webmcp.client.js +49 -53
  18. package/dist/runtime/app/webmcp-config.js +2 -2
  19. package/dist/runtime/cache-control.js +16 -10
  20. package/dist/runtime/i18n-url.js +6 -6
  21. package/dist/runtime/index.js +4 -12
  22. package/dist/runtime/llms-txt-directive.js +20 -13
  23. package/dist/runtime/llms-txt-files.js +188 -187
  24. package/dist/runtime/llms-txt-format.js +54 -55
  25. package/dist/runtime/llms-txt-i18n.js +22 -19
  26. package/dist/runtime/llms-txt-utils.js +140 -95
  27. package/dist/runtime/markdown-links.js +45 -39
  28. package/dist/runtime/markdown-path.js +29 -9
  29. package/dist/runtime/markdown-text.js +2 -1
  30. package/dist/runtime/mcp.js +5 -1
  31. package/dist/runtime/route-path.js +14 -8
  32. package/dist/runtime/server/db/drizzle/client.js +71 -75
  33. package/dist/runtime/server/db/drizzle/index.js +16 -28
  34. package/dist/runtime/server/db/drizzle/providers/bun.d.ts +2 -1
  35. package/dist/runtime/server/db/drizzle/providers/bun.js +10 -7
  36. package/dist/runtime/server/db/drizzle/providers/d1.js +16 -13
  37. package/dist/runtime/server/db/drizzle/providers/dbPath.js +60 -37
  38. package/dist/runtime/server/db/drizzle/providers/libsql.js +23 -11
  39. package/dist/runtime/server/db/drizzle/providers/neon.js +13 -10
  40. package/dist/runtime/server/db/drizzle/providers/node-sqlite.js +10 -7
  41. package/dist/runtime/server/db/drizzle/providers/postgres.js +13 -10
  42. package/dist/runtime/server/db/drizzle/queries.js +633 -532
  43. package/dist/runtime/server/db/drizzle/raw.js +200 -176
  44. package/dist/runtime/server/db/index.js +3 -0
  45. package/dist/runtime/server/db/queries.js +816 -607
  46. package/dist/runtime/server/db/schema/postgres.js +56 -50
  47. package/dist/runtime/server/db/schema/sqlite.js +56 -50
  48. package/dist/runtime/server/db/schema-sql.js +35 -38
  49. package/dist/runtime/server/db/seed.js +60 -45
  50. package/dist/runtime/server/db/shared.js +300 -213
  51. package/dist/runtime/server/index.js +1 -17
  52. package/dist/runtime/server/mcp/cache-key.js +5 -1
  53. package/dist/runtime/server/mcp/resources/pages.js +32 -33
  54. package/dist/runtime/server/mcp/tools/get-page-markdown.js +41 -27
  55. package/dist/runtime/server/mcp/tools/list-pages.js +40 -34
  56. package/dist/runtime/server/mcp/tools/search-pages.js +24 -16
  57. package/dist/runtime/server/middleware/markdown.d.ts +1 -1
  58. package/dist/runtime/server/middleware/markdown.js +15 -13
  59. package/dist/runtime/server/middleware/markdown.prerender.d.ts +1 -1
  60. package/dist/runtime/server/middleware/markdown.prerender.js +135 -119
  61. package/dist/runtime/server/middleware/render-markdown.d.ts +1 -1
  62. package/dist/runtime/server/middleware/render-markdown.js +164 -144
  63. package/dist/runtime/server/plugins/ai-terms.d.ts +1 -1
  64. package/dist/runtime/server/plugins/ai-terms.js +4 -8
  65. package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.d.ts +1 -1
  66. package/dist/runtime/server/plugins/content-signal-capture-nitro3.prerender.js +7 -8
  67. package/dist/runtime/server/plugins/content-signal-capture.prerender.d.ts +1 -1
  68. package/dist/runtime/server/plugins/content-signal-capture.prerender.js +7 -7
  69. package/dist/runtime/server/plugins/db-lifecycle-nitro3.d.ts +1 -1
  70. package/dist/runtime/server/plugins/db-lifecycle-nitro3.js +13 -14
  71. package/dist/runtime/server/plugins/db-lifecycle.js +13 -11
  72. package/dist/runtime/server/plugins/html-capture.prerender.js +6 -6
  73. package/dist/runtime/server/plugins/link-header-nitro3.d.ts +1 -1
  74. package/dist/runtime/server/plugins/link-header-nitro3.js +23 -13
  75. package/dist/runtime/server/plugins/link-header.d.ts +1 -1
  76. package/dist/runtime/server/plugins/link-header.js +30 -30
  77. package/dist/runtime/server/plugins/llms-txt-directive-html.d.ts +1 -1
  78. package/dist/runtime/server/plugins/llms-txt-directive-html.js +4 -3
  79. package/dist/runtime/server/plugins/markdown-negotiation.d.ts +1 -1
  80. package/dist/runtime/server/plugins/markdown-negotiation.js +64 -45
  81. package/dist/runtime/server/plugins/sitemap-seeder.js +144 -112
  82. package/dist/runtime/server/routes/__ai-ready/cron.get.d.ts +1 -1
  83. package/dist/runtime/server/routes/__ai-ready/cron.get.js +17 -11
  84. package/dist/runtime/server/routes/__ai-ready/devtools.get.d.ts +1 -1
  85. package/dist/runtime/server/routes/__ai-ready/devtools.get.js +60 -45
  86. package/dist/runtime/server/routes/__ai-ready/pages.get.d.ts +36 -1
  87. package/dist/runtime/server/routes/__ai-ready/pages.get.js +44 -40
  88. package/dist/runtime/server/routes/__ai-ready/poll.post.d.ts +15 -1
  89. package/dist/runtime/server/routes/__ai-ready/poll.post.js +30 -30
  90. package/dist/runtime/server/routes/__ai-ready/prune.post.d.ts +13 -1
  91. package/dist/runtime/server/routes/__ai-ready/prune.post.js +29 -15
  92. package/dist/runtime/server/routes/__ai-ready/reindex.post.d.ts +22 -1
  93. package/dist/runtime/server/routes/__ai-ready/reindex.post.js +31 -21
  94. package/dist/runtime/server/routes/__ai-ready/restore.post.d.ts +4 -1
  95. package/dist/runtime/server/routes/__ai-ready/restore.post.js +28 -22
  96. package/dist/runtime/server/routes/__ai-ready/status.get.d.ts +1 -1
  97. package/dist/runtime/server/routes/__ai-ready/status.get.js +52 -53
  98. package/dist/runtime/server/routes/__ai-ready-debug.get.d.ts +83 -1
  99. package/dist/runtime/server/routes/__ai-ready-debug.get.js +209 -189
  100. package/dist/runtime/server/routes/agent-skills-artifact.d.ts +1 -1
  101. package/dist/runtime/server/routes/agent-skills-artifact.js +16 -14
  102. package/dist/runtime/server/routes/agent-skills-index.d.ts +1 -1
  103. package/dist/runtime/server/routes/agent-skills-index.js +8 -6
  104. package/dist/runtime/server/routes/ai-catalog.js +19 -19
  105. package/dist/runtime/server/routes/ai-terms.js +23 -19
  106. package/dist/runtime/server/routes/api-catalog.js +23 -23
  107. package/dist/runtime/server/routes/llms-full.txt.get.d.ts +1 -1
  108. package/dist/runtime/server/routes/llms-full.txt.get.js +42 -41
  109. package/dist/runtime/server/routes/llms.txt.get.d.ts +1 -1
  110. package/dist/runtime/server/routes/llms.txt.get.js +38 -33
  111. package/dist/runtime/server/routes/mcp-server-card.js +19 -19
  112. package/dist/runtime/server/routes/sitemap.md.get.d.ts +1 -1
  113. package/dist/runtime/server/routes/sitemap.md.get.js +38 -39
  114. package/dist/runtime/server/tasks/ai-ready-cron.d.ts +1 -1
  115. package/dist/runtime/server/tasks/ai-ready-cron.js +17 -14
  116. package/dist/runtime/server/utils/auth.js +76 -53
  117. package/dist/runtime/server/utils/batchIndex.js +72 -60
  118. package/dist/runtime/server/utils/checkStale.js +181 -134
  119. package/dist/runtime/server/utils/cloudflare-prerendered.js +23 -20
  120. package/dist/runtime/server/utils/cloudflare.js +69 -51
  121. package/dist/runtime/server/utils/content-negotiation.js +30 -18
  122. package/dist/runtime/server/utils/content.js +4 -1
  123. package/dist/runtime/server/utils/context.js +30 -19
  124. package/dist/runtime/server/utils/cron-plan.js +6 -6
  125. package/dist/runtime/server/utils/discovery-response.js +5 -6
  126. package/dist/runtime/server/utils/fetch.js +2 -1
  127. package/dist/runtime/server/utils/frontmatter.js +44 -57
  128. package/dist/runtime/server/utils/i18n.js +3 -8
  129. package/dist/runtime/server/utils/indexPage.js +152 -113
  130. package/dist/runtime/server/utils/keywords.js +278 -277
  131. package/dist/runtime/server/utils/link-header.js +67 -56
  132. package/dist/runtime/server/utils/llms-full.js +39 -49
  133. package/dist/runtime/server/utils/markdown-redirect.js +26 -14
  134. package/dist/runtime/server/utils/markdown-request.js +62 -47
  135. package/dist/runtime/server/utils/negotiation-decision.d.ts +8 -0
  136. package/dist/runtime/server/utils/negotiation-decision.js +106 -34
  137. package/dist/runtime/server/utils/negotiation-response.d.ts +1 -1
  138. package/dist/runtime/server/utils/negotiation-response.js +195 -144
  139. package/dist/runtime/server/utils/page-updated-at.js +23 -15
  140. package/dist/runtime/server/utils/prerender-html.js +31 -17
  141. package/dist/runtime/server/utils/runCron.js +263 -192
  142. package/dist/runtime/server/utils/sitemap-crawl-state.js +57 -39
  143. package/dist/runtime/server/utils/sitemap-lastmod.js +16 -14
  144. package/dist/runtime/server/utils/sitemap-md.js +39 -50
  145. package/dist/runtime/server/utils/sitemap-routes.js +7 -7
  146. package/dist/runtime/server/utils/sitemap.js +459 -414
  147. package/dist/runtime/server/utils.js +141 -122
  148. package/dist/runtime/site-tool-catalog.js +39 -43
  149. package/dist/runtime/site-tool-config.js +1 -0
  150. package/dist/runtime/sync-secret.js +11 -11
  151. package/dist/runtime/types.js +1 -0
  152. package/dist/runtime/webmcp-site-tools.js +278 -250
  153. package/dist/runtime/webmcp.js +53 -42
  154. package/dist/static-headers-G7hFL3wE.mjs +328 -0
  155. package/dist/types.d.mts +1 -9
  156. package/package.json +20 -24
  157. package/skills/nuxt-ai-ready/SKILL.md +8 -2
  158. package/dist/chunks/agent-skills.mjs +0 -383
  159. package/dist/chunks/prerender.mjs +0 -683
  160. package/dist/shared/nuxt-ai-ready.Bzx0dNWj.mjs +0 -3034
  161. package/dist/shared/nuxt-ai-ready.DCd-1s1G.mjs +0 -29
@@ -0,0 +1,18 @@
1
+ import { publicCacheControl } from "./runtime/cache-control.js";
2
+ // src/utils/agent-skills-config.ts
3
+ const AGENT_SKILLS_SCHEMA = "https://schemas.agentskills.io/discovery/0.2.0/schema.json";
4
+ const AGENT_SKILLS_INDEX_ROUTE = "/.well-known/agent-skills/index.json";
5
+ const AGENT_SKILLS_CACHE_CONTROL = publicCacheControl(3600, 86400);
6
+ /** Resolve an external artifact against its discovery index, including when no site URL exists. */
7
+ function resolveExternalSkillUrl(href, indexUrl) {
8
+ const normalized = href.replaceAll(/[\t\n\r]/g, "");
9
+ if (URL.canParse(normalized)) return new URL(normalized).href;
10
+ if (normalized.startsWith("//")) {
11
+ const resolved = new URL(normalized, "https://nuxt-ai-ready.invalid");
12
+ return `//${resolved.username || resolved.password ? `${resolved.username}${resolved.password ? `:${resolved.password}` : ""}@` : ""}${resolved.host}${resolved.pathname}${resolved.search}${resolved.hash}`;
13
+ }
14
+ if (URL.canParse(indexUrl)) return new URL(normalized, indexUrl).href;
15
+ const resolved = new URL(normalized, new URL(indexUrl, "https://nuxt-ai-ready.invalid"));
16
+ return `${resolved.pathname}${resolved.search}${resolved.hash}`;
17
+ }
18
+ export { resolveExternalSkillUrl as i, AGENT_SKILLS_INDEX_ROUTE as n, AGENT_SKILLS_SCHEMA as r, AGENT_SKILLS_CACHE_CONTROL as t };
@@ -0,0 +1,468 @@
1
+ import { createHash } from "node:crypto";
2
+ import { readFile, readdir, realpath } from "node:fs/promises";
3
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import { parseDocument } from "yaml";
5
+ import { r as AGENT_SKILLS_SCHEMA } from "./agent-skills-config-CmZq9uWW.mjs";
6
+ // src/utils/agent-skills.ts
7
+ const namePattern = /^(?!.*--)[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
8
+ const digestPattern = /^sha256:[a-f0-9]{64}$/;
9
+ const urlBase = "https://example.com/.well-known/agent-skills/index.json";
10
+ function skillRoute(name) {
11
+ return `/.well-known/agent-skills/${name}/SKILL.md`;
12
+ }
13
+ const ROOT_SKILL_ALIAS = "/SKILL.md";
14
+ function aliasesOf(skill) {
15
+ return skill.alias === void 0 ? [] : Array.isArray(skill.alias) ? skill.alias : [skill.alias];
16
+ }
17
+ function skillUrl(name) {
18
+ return `${name}/SKILL.md`;
19
+ }
20
+ /**
21
+ * An alias is a second address for the same artifact bytes. It must be a
22
+ * path-absolute `.md` route outside `/.well-known/` and outside the
23
+ * module-owned markdown routes, so the discovery routes, the sitemap
24
+ * markdown endpoint and the home page markdown twin stay unambiguous.
25
+ */
26
+ function validateAlias(alias, index, sitemapMd) {
27
+ if (alias === void 0) return [];
28
+ if (Array.isArray(alias)) return alias.flatMap((entry) => validateAlias(entry, index, sitemapMd));
29
+ if (typeof alias !== "string" || !/^\/(?:[^/?#\s]+\/)*[^/?#\s]+\.md$/.test(alias) || alias.split("/").includes("..")) return [{
30
+ index,
31
+ field: "alias",
32
+ message: "must be a path-absolute route ending in .md, such as \"/SKILL.md\""
33
+ }];
34
+ if (alias.startsWith("/.well-known/")) return [{
35
+ index,
36
+ field: "alias",
37
+ message: "must not use the /.well-known/ prefix reserved for discovery routes"
38
+ }];
39
+ if (alias === "/index.md") return [{
40
+ index,
41
+ field: "alias",
42
+ message: "must not use the module-owned markdown route \"/index.md\""
43
+ }];
44
+ if (sitemapMd && alias === "/sitemap.md") return [{
45
+ index,
46
+ field: "alias",
47
+ message: "must not use the module-owned markdown route \"/sitemap.md\""
48
+ }];
49
+ return [];
50
+ }
51
+ function isRecord(value) {
52
+ return typeof value === "object" && value !== null && !Array.isArray(value);
53
+ }
54
+ function isWithinDirectory(directory, file) {
55
+ const path = relative(directory, file);
56
+ return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
57
+ }
58
+ function validateCommonFields(skill, index) {
59
+ const issues = [];
60
+ if (typeof skill.name !== "string" || !namePattern.test(skill.name)) issues.push({
61
+ index,
62
+ field: "name",
63
+ message: "must contain 1 to 64 lowercase alphanumeric or hyphen characters, without leading, trailing, or consecutive hyphens"
64
+ });
65
+ if (typeof skill.description !== "string" || skill.description.length === 0 || [...skill.description].length > 1024) issues.push({
66
+ index,
67
+ field: "description",
68
+ message: "must contain 1 to 1024 characters"
69
+ });
70
+ return issues;
71
+ }
72
+ function validateSkill(skill, index, sitemapMd) {
73
+ if (!isRecord(skill)) return [{
74
+ index,
75
+ field: "source",
76
+ message: "must be a local or external skill entry"
77
+ }];
78
+ const issues = validateCommonFields(skill, index);
79
+ if (skill.source === "local") {
80
+ if (typeof skill.file !== "string" || skill.file.trim().length === 0) issues.push({
81
+ index,
82
+ field: "file",
83
+ message: "must be a non-empty path relative to the Nuxt root directory"
84
+ });
85
+ issues.push(...validateAlias(skill.alias, index, sitemapMd));
86
+ return issues;
87
+ }
88
+ if (skill.source === "external") {
89
+ if (skill.type !== "skill-md" && skill.type !== "archive") issues.push({
90
+ index,
91
+ field: "type",
92
+ message: "must be \"skill-md\" or \"archive\""
93
+ });
94
+ if (typeof skill.url !== "string" || skill.url.trim().length === 0 || skill.url !== skill.url.trim() || !URL.canParse(skill.url, urlBase) || !["http:", "https:"].includes(new URL(skill.url, urlBase).protocol)) issues.push({
95
+ index,
96
+ field: "url",
97
+ message: "must be an HTTP(S), path-absolute, or relative URL"
98
+ });
99
+ if (typeof skill.digest !== "string" || !digestPattern.test(skill.digest)) issues.push({
100
+ index,
101
+ field: "digest",
102
+ message: "must use the format sha256: followed by 64 lowercase hexadecimal characters"
103
+ });
104
+ return issues;
105
+ }
106
+ issues.push({
107
+ index,
108
+ field: "source",
109
+ message: "must be \"local\" or \"external\""
110
+ });
111
+ return issues;
112
+ }
113
+ function resolveExternalEntry(skill) {
114
+ return {
115
+ name: skill.name,
116
+ type: skill.type,
117
+ description: skill.description,
118
+ url: skill.url,
119
+ digest: skill.digest
120
+ };
121
+ }
122
+ /** The frontmatter block of a SKILL.md, parsed but not yet validated. */
123
+ function readSkillFrontmatter(content) {
124
+ const match = content.match(/^\uFEFF?---[\t ]*\r?\n([\s\S]*?)\r?\n---[\t ]*(?:\r?\n|$)/);
125
+ if (!match?.[1]) return {
126
+ _tag: "Err",
127
+ message: "must contain YAML frontmatter with name and description fields"
128
+ };
129
+ const document = parseDocument(match[1], { prettyErrors: false });
130
+ if (document.errors.length > 0) return {
131
+ _tag: "Err",
132
+ message: `contains invalid YAML frontmatter: ${document.errors[0]?.message || "unknown YAML error"}`
133
+ };
134
+ const metadata = document.toJS();
135
+ if (!isRecord(metadata)) return {
136
+ _tag: "Err",
137
+ message: "frontmatter must be a YAML mapping with name and description fields"
138
+ };
139
+ return {
140
+ _tag: "Ok",
141
+ metadata,
142
+ hasBody: content.slice(match[0].length).trim().length > 0
143
+ };
144
+ }
145
+ function parseLocalSkillMetadata(content, skill, index) {
146
+ const frontmatter = readSkillFrontmatter(content);
147
+ if (frontmatter._tag === "Err") return [{
148
+ index,
149
+ field: "file",
150
+ message: frontmatter.message
151
+ }];
152
+ const { metadata } = frontmatter;
153
+ const issues = [];
154
+ if (!frontmatter.hasBody) issues.push({
155
+ index,
156
+ field: "file",
157
+ message: "must contain Markdown instructions after its frontmatter"
158
+ });
159
+ if (metadata.name !== skill.name) issues.push({
160
+ index,
161
+ field: "name",
162
+ message: `must exactly match the local SKILL.md frontmatter name "${String(metadata.name)}"`
163
+ });
164
+ if (metadata.description !== skill.description) issues.push({
165
+ index,
166
+ field: "description",
167
+ message: "must exactly match the local SKILL.md frontmatter description"
168
+ });
169
+ return issues;
170
+ }
171
+ async function resolveLocalEntry(skill, index, rootDir, publicDirs) {
172
+ const file = resolve(rootDir, skill.file);
173
+ const publicDirectory = publicDirs.map((directory) => resolve(directory, "skills")).find((directory) => isWithinDirectory(directory, file));
174
+ if (isAbsolute(skill.file) || !isWithinDirectory(rootDir, file) && !publicDirectory) return {
175
+ _tag: "Invalid",
176
+ issues: [{
177
+ index,
178
+ field: "file",
179
+ message: "must resolve within the Nuxt root directory"
180
+ }]
181
+ };
182
+ return Promise.all([
183
+ realpath(rootDir),
184
+ realpath(file),
185
+ publicDirectory ? realpath(publicDirectory) : void 0
186
+ ]).then(([realRootDir, realFile, realPublicDirectory]) => {
187
+ if (!isWithinDirectory(realRootDir, realFile) && !(realPublicDirectory && isWithinDirectory(realPublicDirectory, realFile))) return {
188
+ _tag: "Invalid",
189
+ issues: [{
190
+ index,
191
+ field: "file",
192
+ message: "must resolve within the Nuxt root directory"
193
+ }]
194
+ };
195
+ return readFile(realFile).then((content) => {
196
+ const text = content.toString("utf8");
197
+ if (!Buffer.from(text, "utf8").equals(content)) return {
198
+ _tag: "Invalid",
199
+ issues: [{
200
+ index,
201
+ field: "file",
202
+ message: "must contain valid UTF-8 text"
203
+ }]
204
+ };
205
+ const metadataIssues = parseLocalSkillMetadata(text, skill, index);
206
+ if (metadataIssues.length > 0) return {
207
+ _tag: "Invalid",
208
+ issues: metadataIssues
209
+ };
210
+ const routes = [skillRoute(skill.name), ...aliasesOf(skill)];
211
+ const digest = `sha256:${createHash("sha256").update(content).digest("hex")}`;
212
+ return {
213
+ _tag: "Resolved",
214
+ entry: {
215
+ name: skill.name,
216
+ type: "skill-md",
217
+ description: skill.description,
218
+ url: skillUrl(skill.name),
219
+ digest
220
+ },
221
+ routes,
222
+ content: text
223
+ };
224
+ });
225
+ }).catch((error) => ({
226
+ _tag: "Invalid",
227
+ issues: [{
228
+ index,
229
+ field: "file",
230
+ message: `could not read ${file}: ${error instanceof Error ? error.message : String(error)}`
231
+ }]
232
+ }));
233
+ }
234
+ async function resolveAgentSkillsConfig(config, rootDir, options = {}) {
235
+ if (config === false || config === void 0) return { _tag: "Disabled" };
236
+ if (!isRecord(config) || config.skills !== void 0 && !Array.isArray(config.skills)) return {
237
+ _tag: "Invalid",
238
+ issues: [{
239
+ field: "agentSkills",
240
+ message: "skills must be an array when set"
241
+ }]
242
+ };
243
+ const configuredSkills = config.skills ?? [];
244
+ if (configuredSkills.length === 0) return { _tag: "Disabled" };
245
+ const sitemapMd = options.sitemapMd !== false;
246
+ const issues = configuredSkills.flatMap((skill, index) => validateSkill(skill, index, sitemapMd));
247
+ const seenNames = /* @__PURE__ */ new Set();
248
+ const seenAliases = /* @__PURE__ */ new Set();
249
+ for (const [index, skill] of configuredSkills.entries()) {
250
+ if (!isRecord(skill) || typeof skill.name !== "string" || seenNames.has(skill.name)) {
251
+ if (isRecord(skill) && typeof skill.name === "string" && seenNames.has(skill.name)) issues.push({
252
+ index,
253
+ field: "name",
254
+ message: `duplicates the skill name "${skill.name}"`
255
+ });
256
+ continue;
257
+ }
258
+ seenNames.add(skill.name);
259
+ for (const alias of aliasesOf(skill)) {
260
+ if (seenAliases.has(alias)) issues.push({
261
+ index,
262
+ field: "alias",
263
+ message: `duplicates the alias "${alias}"`
264
+ });
265
+ seenAliases.add(alias);
266
+ }
267
+ }
268
+ if (issues.length > 0) return {
269
+ _tag: "Invalid",
270
+ issues
271
+ };
272
+ const skills = configuredSkills;
273
+ const resolved = await Promise.all(skills.map((skill, index) => skill.source === "local" ? resolveLocalEntry(skill, index, rootDir, options.publicDirs ?? []) : Promise.resolve({
274
+ _tag: "Resolved",
275
+ entry: resolveExternalEntry(skill)
276
+ })));
277
+ const fileIssues = resolved.flatMap((result) => result._tag === "Invalid" ? result.issues : []);
278
+ if (fileIssues.length > 0) return {
279
+ _tag: "Invalid",
280
+ issues: fileIssues
281
+ };
282
+ const entries = [];
283
+ const localArtifacts = {};
284
+ const links = [];
285
+ for (const result of resolved) {
286
+ if (result._tag !== "Resolved") continue;
287
+ entries.push(result.entry);
288
+ if ("routes" in result) {
289
+ for (const route of result.routes) localArtifacts[route] = result.content;
290
+ const [alias] = result.routes.slice(1).sort((a, b) => a.length - b.length);
291
+ links.push({
292
+ source: "local",
293
+ name: result.entry.name,
294
+ description: result.entry.description,
295
+ href: alias ?? result.routes[0]
296
+ });
297
+ } else links.push({
298
+ source: "external",
299
+ name: result.entry.name,
300
+ description: result.entry.description,
301
+ href: result.entry.url
302
+ });
303
+ }
304
+ return {
305
+ _tag: "Enabled",
306
+ index: {
307
+ $schema: AGENT_SKILLS_SCHEMA,
308
+ skills: entries
309
+ },
310
+ localArtifacts,
311
+ links
312
+ };
313
+ }
314
+ function toPosix(path) {
315
+ return path.split(sep).join("/");
316
+ }
317
+ /**
318
+ * The convention: `<dir>/<name>/SKILL.md`. Frontmatter supplies `name` and
319
+ * `description`, so a skill needs no config entry, and `name` must equal the
320
+ * directory name as the Agent Skills specification requires. Each skill is
321
+ * also served at `/<dir>/<name>/SKILL.md`, so the URL mirrors the repository.
322
+ * The first scan directory wins a name clash, which puts the project ahead of
323
+ * its layers.
324
+ */
325
+ async function discoverAgentSkills(options) {
326
+ const dir = options.dir.replace(/^\.?\/+/, "").replace(/\/+$/, "");
327
+ const skills = [];
328
+ const issues = [];
329
+ const seen = /* @__PURE__ */ new Set();
330
+ for (const scanDir of options.scanDirs) {
331
+ const base = resolve(scanDir, dir);
332
+ if (!options.publicOnly && !isWithinDirectory(options.rootDir, base) && base !== options.rootDir) continue;
333
+ const entries = await readdir(base, { withFileTypes: true }).catch(() => {
334
+ return [];
335
+ });
336
+ for (const entry of entries.filter((entry) => entry.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
337
+ if (seen.has(entry.name)) continue;
338
+ const file = join(base, entry.name, "SKILL.md");
339
+ if (options.publicOnly) {
340
+ const resolvedFile = await realpath(file).catch((error) => {
341
+ if (error.code === "ENOENT") return null;
342
+ throw error;
343
+ });
344
+ if (resolvedFile === null) continue;
345
+ if (!isWithinDirectory(await realpath(base), resolvedFile)) {
346
+ issues.push({
347
+ field: "file",
348
+ message: `${toPosix(relative(options.rootDir, file))} must resolve within its public skills directory`
349
+ });
350
+ continue;
351
+ }
352
+ }
353
+ const content = await readFile(file, "utf8").catch(() => {
354
+ return null;
355
+ });
356
+ if (content === null) continue;
357
+ const relativeFile = toPosix(relative(options.rootDir, file));
358
+ const frontmatter = readSkillFrontmatter(content);
359
+ if (frontmatter._tag === "Err") {
360
+ issues.push({
361
+ field: "file",
362
+ message: `${relativeFile} ${frontmatter.message}`
363
+ });
364
+ continue;
365
+ }
366
+ const { name, description } = frontmatter.metadata;
367
+ if (name !== entry.name) {
368
+ issues.push({
369
+ field: "name",
370
+ message: `${relativeFile} frontmatter name "${String(name)}" must equal its directory name "${entry.name}"`
371
+ });
372
+ continue;
373
+ }
374
+ if (typeof description !== "string" || description.length === 0) {
375
+ issues.push({
376
+ field: "description",
377
+ message: `${relativeFile} frontmatter must contain a description`
378
+ });
379
+ continue;
380
+ }
381
+ seen.add(entry.name);
382
+ skills.push({
383
+ source: "local",
384
+ name: entry.name,
385
+ description,
386
+ file: relativeFile,
387
+ alias: `/${dir}/${entry.name}/SKILL.md`
388
+ });
389
+ }
390
+ }
391
+ return {
392
+ skills,
393
+ issues
394
+ };
395
+ }
396
+ /** Explicit entries replace discovered ones with the same name; order is discovered first, then explicit. */
397
+ function mergeAgentSkills(discovered, configured) {
398
+ const overridden = new Set(configured.map((skill) => skill.name));
399
+ return [...discovered.filter((skill) => !overridden.has(skill.name)), ...configured];
400
+ }
401
+ /**
402
+ * `/SKILL.md` is where installers and people look first. Serve it for the
403
+ * named local skill, or for the only local skill when nothing is named.
404
+ */
405
+ function applyRootAlias(skills, root) {
406
+ if (root === false) return {
407
+ _tag: "Ok",
408
+ skills: [...skills]
409
+ };
410
+ const locals = skills.filter((skill) => skill.source === "local");
411
+ const target = root === void 0 ? locals.length === 1 ? locals[0] : void 0 : locals.find((skill) => skill.name === root);
412
+ if (root !== void 0 && !target) return {
413
+ _tag: "Invalid",
414
+ issues: [{
415
+ field: "root",
416
+ message: `names no local skill: "${root}"`
417
+ }]
418
+ };
419
+ if (!target || aliasesOf(target).includes("/SKILL.md")) return {
420
+ _tag: "Ok",
421
+ skills: [...skills]
422
+ };
423
+ return {
424
+ _tag: "Ok",
425
+ skills: skills.map((skill) => skill === target ? {
426
+ ...skill,
427
+ alias: [...aliasesOf(skill), ROOT_SKILL_ALIAS]
428
+ } : skill)
429
+ };
430
+ }
431
+ /**
432
+ * Discovery plus explicit config, before the `ai-ready:agent-skills` hook runs.
433
+ * The root alias is applied after the hook, so a skill the hook adds counts.
434
+ */
435
+ async function prepareAgentSkills(config, options) {
436
+ if (config.dir !== void 0 && config.dir !== false && typeof config.dir !== "string") return {
437
+ _tag: "Invalid",
438
+ issues: [{
439
+ field: "dir",
440
+ message: "must be a string or false when set"
441
+ }]
442
+ };
443
+ if (config.skills !== void 0 && !Array.isArray(config.skills)) return {
444
+ _tag: "Invalid",
445
+ issues: [{
446
+ field: "agentSkills",
447
+ message: "skills must be an array when set"
448
+ }]
449
+ };
450
+ const discovered = config.dir === false ? {
451
+ skills: [],
452
+ issues: []
453
+ } : await discoverAgentSkills({
454
+ rootDir: options.rootDir,
455
+ scanDirs: config.dir === void 0 ? options.publicDirs ?? options.scanDirs.map((directory) => join(directory, "public")) : options.scanDirs,
456
+ dir: config.dir ?? "skills",
457
+ publicOnly: config.dir === void 0
458
+ });
459
+ if (discovered.issues.length > 0) return {
460
+ _tag: "Invalid",
461
+ issues: discovered.issues
462
+ };
463
+ return {
464
+ _tag: "Ok",
465
+ skills: mergeAgentSkills(discovered.skills, config.skills ?? [])
466
+ };
467
+ }
468
+ export { applyRootAlias, prepareAgentSkills, resolveAgentSkillsConfig };
package/dist/cli.d.mts ADDED
@@ -0,0 +1 @@
1
+ export {}