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
@@ -1,383 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { realpath, readFile, readdir } from 'node:fs/promises';
3
- import { join, resolve, isAbsolute, relative, sep } from 'node:path';
4
- import { parseDocument } from 'yaml';
5
- import { A as AGENT_SKILLS_SCHEMA } from '../shared/nuxt-ai-ready.Bzx0dNWj.mjs';
6
- import 'node:module';
7
- import 'node:url';
8
- import '@nuxt/kit';
9
- import 'defu';
10
- import 'nuxt-site-config/kit';
11
- import 'nuxtseo-shared/kit';
12
- import 'nuxtseo-shared/server';
13
- import 'ufo';
14
- import '../shared/nuxt-ai-ready.DCd-1s1G.mjs';
15
- import 'node:fs';
16
- import '../../dist/runtime/ai-terms.js';
17
- import '../../dist/runtime/llms-txt-files.js';
18
- import '../../dist/runtime/route-path.js';
19
- import '../../dist/runtime/server/utils/sitemap-md.js';
20
- import '../../dist/runtime/sync-secret.js';
21
- import '../../dist/runtime/cache-control.js';
22
- import '../../dist/runtime/server/utils/discovery-response.js';
23
- import 'confbox';
24
- import '../../dist/runtime/markdown-path.js';
25
- import '../../dist/runtime/server/utils/content-negotiation.js';
26
- import 'pathe';
27
- import 'nuxtseo-shared/i18n';
28
-
29
- const namePattern = /^(?!.*--)[a-z0-9](?:[a-z0-9-]{0,62}[a-z0-9])?$/;
30
- const digestPattern = /^sha256:[a-f0-9]{64}$/;
31
- const urlBase = "https://example.com/.well-known/agent-skills/index.json";
32
- function skillRoute(name) {
33
- return `/.well-known/agent-skills/${name}/SKILL.md`;
34
- }
35
- const ROOT_SKILL_ALIAS = "/SKILL.md";
36
- function aliasesOf(skill) {
37
- return skill.alias === void 0 ? [] : Array.isArray(skill.alias) ? skill.alias : [skill.alias];
38
- }
39
- function skillUrl(name) {
40
- return `${name}/SKILL.md`;
41
- }
42
- function validateAlias(alias, index, sitemapMd) {
43
- if (alias === void 0)
44
- return [];
45
- if (Array.isArray(alias))
46
- return alias.flatMap((entry) => validateAlias(entry, index, sitemapMd));
47
- if (typeof alias !== "string" || !/^\/(?:[^/?#\s]+\/)*[^/?#\s]+\.md$/.test(alias) || alias.split("/").includes(".."))
48
- return [{ index, field: "alias", message: 'must be a path-absolute route ending in .md, such as "/SKILL.md"' }];
49
- if (alias.startsWith("/.well-known/"))
50
- return [{ index, field: "alias", message: "must not use the /.well-known/ prefix reserved for discovery routes" }];
51
- if (alias === "/index.md")
52
- return [{ index, field: "alias", message: 'must not use the module-owned markdown route "/index.md"' }];
53
- if (sitemapMd && alias === "/sitemap.md")
54
- return [{ index, field: "alias", message: 'must not use the module-owned markdown route "/sitemap.md"' }];
55
- return [];
56
- }
57
- function isRecord(value) {
58
- return typeof value === "object" && value !== null && !Array.isArray(value);
59
- }
60
- function isWithinDirectory(directory, file) {
61
- const path = relative(directory, file);
62
- return path !== ".." && !path.startsWith(`..${sep}`) && !isAbsolute(path);
63
- }
64
- function validateCommonFields(skill, index) {
65
- const issues = [];
66
- if (typeof skill.name !== "string" || !namePattern.test(skill.name)) {
67
- issues.push({
68
- index,
69
- field: "name",
70
- message: "must contain 1 to 64 lowercase alphanumeric or hyphen characters, without leading, trailing, or consecutive hyphens"
71
- });
72
- }
73
- if (typeof skill.description !== "string" || skill.description.length === 0 || [...skill.description].length > 1024) {
74
- issues.push({
75
- index,
76
- field: "description",
77
- message: "must contain 1 to 1024 characters"
78
- });
79
- }
80
- return issues;
81
- }
82
- function validateSkill(skill, index, sitemapMd) {
83
- if (!isRecord(skill)) {
84
- return [{ index, field: "source", message: "must be a local or external skill entry" }];
85
- }
86
- const issues = validateCommonFields(skill, index);
87
- if (skill.source === "local") {
88
- if (typeof skill.file !== "string" || skill.file.trim().length === 0)
89
- issues.push({ index, field: "file", message: "must be a non-empty path relative to the Nuxt root directory" });
90
- issues.push(...validateAlias(skill.alias, index, sitemapMd));
91
- return issues;
92
- }
93
- if (skill.source === "external") {
94
- if (skill.type !== "skill-md" && skill.type !== "archive")
95
- issues.push({ index, field: "type", message: 'must be "skill-md" or "archive"' });
96
- 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)) {
97
- issues.push({ index, field: "url", message: "must be an HTTP(S), path-absolute, or relative URL" });
98
- }
99
- if (typeof skill.digest !== "string" || !digestPattern.test(skill.digest))
100
- issues.push({ index, field: "digest", message: "must use the format sha256: followed by 64 lowercase hexadecimal characters" });
101
- return issues;
102
- }
103
- issues.push({ index, field: "source", message: 'must be "local" or "external"' });
104
- return issues;
105
- }
106
- function resolveExternalEntry(skill) {
107
- return {
108
- name: skill.name,
109
- type: skill.type,
110
- description: skill.description,
111
- url: skill.url,
112
- digest: skill.digest
113
- };
114
- }
115
- function readSkillFrontmatter(content) {
116
- const match = content.match(/^\uFEFF?---[\t ]*\r?\n([\s\S]*?)\r?\n---[\t ]*(?:\r?\n|$)/);
117
- if (!match?.[1])
118
- return { _tag: "Err", message: "must contain YAML frontmatter with name and description fields" };
119
- const document = parseDocument(match[1], { prettyErrors: false });
120
- if (document.errors.length > 0)
121
- return { _tag: "Err", message: `contains invalid YAML frontmatter: ${document.errors[0]?.message || "unknown YAML error"}` };
122
- const metadata = document.toJS();
123
- if (!isRecord(metadata))
124
- return { _tag: "Err", message: "frontmatter must be a YAML mapping with name and description fields" };
125
- return { _tag: "Ok", metadata, hasBody: content.slice(match[0].length).trim().length > 0 };
126
- }
127
- function parseLocalSkillMetadata(content, skill, index) {
128
- const frontmatter = readSkillFrontmatter(content);
129
- if (frontmatter._tag === "Err")
130
- return [{ index, field: "file", message: frontmatter.message }];
131
- const { metadata } = frontmatter;
132
- const issues = [];
133
- if (!frontmatter.hasBody) {
134
- issues.push({
135
- index,
136
- field: "file",
137
- message: "must contain Markdown instructions after its frontmatter"
138
- });
139
- }
140
- if (metadata.name !== skill.name) {
141
- issues.push({
142
- index,
143
- field: "name",
144
- message: `must exactly match the local SKILL.md frontmatter name "${String(metadata.name)}"`
145
- });
146
- }
147
- if (metadata.description !== skill.description) {
148
- issues.push({
149
- index,
150
- field: "description",
151
- message: "must exactly match the local SKILL.md frontmatter description"
152
- });
153
- }
154
- return issues;
155
- }
156
- async function resolveLocalEntry(skill, index, rootDir, publicDirs) {
157
- const file = resolve(rootDir, skill.file);
158
- const publicDirectory = publicDirs.map((directory) => resolve(directory, "skills")).find((directory) => isWithinDirectory(directory, file));
159
- if (isAbsolute(skill.file) || !isWithinDirectory(rootDir, file) && !publicDirectory) {
160
- return {
161
- _tag: "Invalid",
162
- issues: [{
163
- index,
164
- field: "file",
165
- message: "must resolve within the Nuxt root directory"
166
- }]
167
- };
168
- }
169
- return Promise.all([realpath(rootDir), realpath(file), publicDirectory ? realpath(publicDirectory) : void 0]).then(([realRootDir, realFile, realPublicDirectory]) => {
170
- if (!isWithinDirectory(realRootDir, realFile) && !(realPublicDirectory && isWithinDirectory(realPublicDirectory, realFile))) {
171
- return {
172
- _tag: "Invalid",
173
- issues: [{
174
- index,
175
- field: "file",
176
- message: "must resolve within the Nuxt root directory"
177
- }]
178
- };
179
- }
180
- return readFile(realFile).then((content) => {
181
- const text = content.toString("utf8");
182
- if (!Buffer.from(text, "utf8").equals(content)) {
183
- return {
184
- _tag: "Invalid",
185
- issues: [{
186
- index,
187
- field: "file",
188
- message: "must contain valid UTF-8 text"
189
- }]
190
- };
191
- }
192
- const metadataIssues = parseLocalSkillMetadata(text, skill, index);
193
- if (metadataIssues.length > 0) {
194
- return {
195
- _tag: "Invalid",
196
- issues: metadataIssues
197
- };
198
- }
199
- const routes = [skillRoute(skill.name), ...aliasesOf(skill)];
200
- const digest = `sha256:${createHash("sha256").update(content).digest("hex")}`;
201
- return {
202
- _tag: "Resolved",
203
- entry: {
204
- name: skill.name,
205
- type: "skill-md",
206
- description: skill.description,
207
- url: skillUrl(skill.name),
208
- digest
209
- },
210
- routes,
211
- content: text
212
- };
213
- });
214
- }).catch((error) => ({
215
- _tag: "Invalid",
216
- issues: [{
217
- index,
218
- field: "file",
219
- message: `could not read ${file}: ${error instanceof Error ? error.message : String(error)}`
220
- }]
221
- }));
222
- }
223
- async function resolveAgentSkillsConfig(config, rootDir, options = {}) {
224
- if (config === false || config === void 0)
225
- return { _tag: "Disabled" };
226
- if (!isRecord(config) || config.skills !== void 0 && !Array.isArray(config.skills)) {
227
- return {
228
- _tag: "Invalid",
229
- issues: [{ field: "agentSkills", message: "skills must be an array when set" }]
230
- };
231
- }
232
- const configuredSkills = config.skills ?? [];
233
- if (configuredSkills.length === 0)
234
- return { _tag: "Disabled" };
235
- const sitemapMd = options.sitemapMd !== false;
236
- const issues = configuredSkills.flatMap((skill, index) => validateSkill(skill, index, sitemapMd));
237
- const seenNames = /* @__PURE__ */ new Set();
238
- const seenAliases = /* @__PURE__ */ new Set();
239
- for (const [index, skill] of configuredSkills.entries()) {
240
- if (!isRecord(skill) || typeof skill.name !== "string" || seenNames.has(skill.name)) {
241
- if (isRecord(skill) && typeof skill.name === "string" && seenNames.has(skill.name))
242
- issues.push({ index, field: "name", message: `duplicates the skill name "${skill.name}"` });
243
- continue;
244
- }
245
- seenNames.add(skill.name);
246
- for (const alias of aliasesOf(skill)) {
247
- if (seenAliases.has(alias))
248
- issues.push({ index, field: "alias", message: `duplicates the alias "${alias}"` });
249
- seenAliases.add(alias);
250
- }
251
- }
252
- if (issues.length > 0)
253
- return { _tag: "Invalid", issues };
254
- const skills = configuredSkills;
255
- const resolved = await Promise.all(skills.map((skill, index) => skill.source === "local" ? resolveLocalEntry(skill, index, rootDir, options.publicDirs ?? []) : Promise.resolve({ _tag: "Resolved", entry: resolveExternalEntry(skill) })));
256
- const fileIssues = resolved.flatMap((result) => result._tag === "Invalid" ? result.issues : []);
257
- if (fileIssues.length > 0)
258
- return { _tag: "Invalid", issues: fileIssues };
259
- const entries = [];
260
- const localArtifacts = {};
261
- const links = [];
262
- for (const result of resolved) {
263
- if (result._tag !== "Resolved")
264
- continue;
265
- entries.push(result.entry);
266
- if ("routes" in result) {
267
- for (const route of result.routes)
268
- localArtifacts[route] = result.content;
269
- const [alias] = result.routes.slice(1).sort((a, b) => a.length - b.length);
270
- links.push({ source: "local", name: result.entry.name, description: result.entry.description, href: alias ?? result.routes[0] });
271
- } else {
272
- links.push({ source: "external", name: result.entry.name, description: result.entry.description, href: result.entry.url });
273
- }
274
- }
275
- return {
276
- _tag: "Enabled",
277
- index: {
278
- $schema: AGENT_SKILLS_SCHEMA,
279
- skills: entries
280
- },
281
- localArtifacts,
282
- links
283
- };
284
- }
285
- function toPosix(path) {
286
- return path.split(sep).join("/");
287
- }
288
- async function discoverAgentSkills(options) {
289
- const dir = options.dir.replace(/^\.?\/+/, "").replace(/\/+$/, "");
290
- const skills = [];
291
- const issues = [];
292
- const seen = /* @__PURE__ */ new Set();
293
- for (const scanDir of options.scanDirs) {
294
- const base = resolve(scanDir, dir);
295
- if (!options.publicOnly && !isWithinDirectory(options.rootDir, base) && base !== options.rootDir)
296
- continue;
297
- const entries = await readdir(base, { withFileTypes: true }).catch(() => {
298
- return [];
299
- });
300
- for (const entry of entries.filter((entry2) => entry2.isDirectory()).sort((a, b) => a.name.localeCompare(b.name))) {
301
- if (seen.has(entry.name))
302
- continue;
303
- const file = join(base, entry.name, "SKILL.md");
304
- if (options.publicOnly) {
305
- const resolvedFile = await realpath(file).catch((error) => {
306
- if (error.code === "ENOENT")
307
- return null;
308
- throw error;
309
- });
310
- if (resolvedFile === null)
311
- continue;
312
- if (!isWithinDirectory(await realpath(base), resolvedFile)) {
313
- issues.push({ field: "file", message: `${toPosix(relative(options.rootDir, file))} must resolve within its public skills directory` });
314
- continue;
315
- }
316
- }
317
- const content = await readFile(file, "utf8").catch(() => {
318
- return null;
319
- });
320
- if (content === null)
321
- continue;
322
- const relativeFile = toPosix(relative(options.rootDir, file));
323
- const frontmatter = readSkillFrontmatter(content);
324
- if (frontmatter._tag === "Err") {
325
- issues.push({ field: "file", message: `${relativeFile} ${frontmatter.message}` });
326
- continue;
327
- }
328
- const { name, description } = frontmatter.metadata;
329
- if (name !== entry.name) {
330
- issues.push({ field: "name", message: `${relativeFile} frontmatter name "${String(name)}" must equal its directory name "${entry.name}"` });
331
- continue;
332
- }
333
- if (typeof description !== "string" || description.length === 0) {
334
- issues.push({ field: "description", message: `${relativeFile} frontmatter must contain a description` });
335
- continue;
336
- }
337
- seen.add(entry.name);
338
- skills.push({
339
- source: "local",
340
- name: entry.name,
341
- description,
342
- file: relativeFile,
343
- alias: `/${dir}/${entry.name}/SKILL.md`
344
- });
345
- }
346
- }
347
- return { skills, issues };
348
- }
349
- function mergeAgentSkills(discovered, configured) {
350
- const overridden = new Set(configured.map((skill) => skill.name));
351
- return [...discovered.filter((skill) => !overridden.has(skill.name)), ...configured];
352
- }
353
- function applyRootAlias(skills, root) {
354
- if (root === false)
355
- return { _tag: "Ok", skills: [...skills] };
356
- const locals = skills.filter((skill) => skill.source === "local");
357
- const target = root === void 0 ? locals.length === 1 ? locals[0] : void 0 : locals.find((skill) => skill.name === root);
358
- if (root !== void 0 && !target)
359
- return { _tag: "Invalid", issues: [{ field: "root", message: `names no local skill: "${root}"` }] };
360
- if (!target || aliasesOf(target).includes(ROOT_SKILL_ALIAS))
361
- return { _tag: "Ok", skills: [...skills] };
362
- return {
363
- _tag: "Ok",
364
- skills: skills.map((skill) => skill === target ? { ...skill, alias: [...aliasesOf(skill), ROOT_SKILL_ALIAS] } : skill)
365
- };
366
- }
367
- async function prepareAgentSkills(config, options) {
368
- if (config.dir !== void 0 && config.dir !== false && typeof config.dir !== "string")
369
- return { _tag: "Invalid", issues: [{ field: "dir", message: "must be a string or false when set" }] };
370
- if (config.skills !== void 0 && !Array.isArray(config.skills))
371
- return { _tag: "Invalid", issues: [{ field: "agentSkills", message: "skills must be an array when set" }] };
372
- const discovered = config.dir === false ? { skills: [], issues: [] } : await discoverAgentSkills({
373
- rootDir: options.rootDir,
374
- scanDirs: config.dir === void 0 ? options.publicDirs ?? options.scanDirs.map((directory) => join(directory, "public")) : options.scanDirs,
375
- dir: config.dir ?? "skills",
376
- publicOnly: config.dir === void 0
377
- });
378
- if (discovered.issues.length > 0)
379
- return { _tag: "Invalid", issues: discovered.issues };
380
- return { _tag: "Ok", skills: mergeAgentSkills(discovered.skills, config.skills ?? []) };
381
- }
382
-
383
- export { AGENT_SKILLS_SCHEMA, ROOT_SKILL_ALIAS, applyRootAlias, discoverAgentSkills, mergeAgentSkills, prepareAgentSkills, readSkillFrontmatter, resolveAgentSkillsConfig };