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
package/dist/cli.mjs CHANGED
@@ -1,612 +1,698 @@
1
1
  #!/usr/bin/env node
2
- import { existsSync } from 'node:fs';
3
- import fsp from 'node:fs/promises';
4
- import { defineCommand, runMain } from 'citty';
5
- import { consola } from 'consola';
6
- import { colors } from 'consola/utils';
7
- import { resolve, join } from 'pathe';
8
- import { joinURL } from 'ufo';
9
- import { r as readPackageMetadata } from './shared/nuxt-ai-ready.DCd-1s1G.mjs';
10
- import { APPLICATION_SECRET_ERROR, deriveRuntimeSyncSecret, LEGACY_RUNTIME_SYNC_SECRET_WARNING } from '../dist/runtime/sync-secret.js';
11
- import 'node:path';
12
- import 'node:url';
13
- import 'nuxtseo-shared/kit';
14
-
15
- const capabilities = ["llms", "api-catalog", "ai-catalog", "mcp", "skills"];
2
+ import { existsSync } from "node:fs";
3
+ import fsp from "node:fs/promises";
4
+ import { defineCommand, runMain } from "citty";
5
+ import { consola } from "consola";
6
+ import { colors } from "consola/utils";
7
+ import { join, resolve } from "pathe";
8
+ import { joinURL } from "ufo";
9
+ import { t as readPackageMetadata } from "./package-metadata-B1darl8W.mjs";
10
+ import { APPLICATION_SECRET_ERROR, LEGACY_RUNTIME_SYNC_SECRET_WARNING, deriveRuntimeSyncSecret } from "./runtime/sync-secret.js";
11
+ // src/readiness-audit.ts
12
+ const capabilities = [
13
+ "llms",
14
+ "api-catalog",
15
+ "ai-catalog",
16
+ "mcp",
17
+ "skills"
18
+ ];
16
19
  function publicUrl(input, base) {
17
- if (!URL.canParse(input, base))
18
- return { _tag: "Err", message: "Use an absolute HTTP or HTTPS URL." };
19
- const url = new URL(input, base);
20
- if (!["http:", "https:"].includes(url.protocol) || url.username || url.password)
21
- return { _tag: "Err", message: "Use an HTTP or HTTPS URL without credentials." };
22
- url.hash = "";
23
- return { _tag: "Ok", value: url };
20
+ if (!URL.canParse(input, base)) return {
21
+ _tag: "Err",
22
+ message: "Use an absolute HTTP or HTTPS URL."
23
+ };
24
+ const url = new URL(input, base);
25
+ if (!["http:", "https:"].includes(url.protocol) || url.username || url.password) return {
26
+ _tag: "Err",
27
+ message: "Use an HTTP or HTTPS URL without credentials."
28
+ };
29
+ url.hash = "";
30
+ return {
31
+ _tag: "Ok",
32
+ value: url
33
+ };
24
34
  }
25
35
  function parseAuditOptions(input) {
26
- const url = publicUrl(input.url);
27
- if (url._tag === "Err")
28
- return url;
29
- const base = input.base || "/";
30
- if (!base.startsWith("/") || base.startsWith("//") || /[?#\\]/.test(base))
31
- return { _tag: "Err", message: "Use an application base path such as /docs/." };
32
- const selected = [...new Set((input.capabilities || "").split(",").map((value) => value.trim()).filter(Boolean))];
33
- const unknown = selected.filter((value) => !capabilities.includes(value));
34
- if (unknown.length)
35
- return { _tag: "Err", message: `Unknown capabilities: ${unknown.join(", ")}. Use ${capabilities.join(", ")}.` };
36
- return { _tag: "Ok", value: { url: url.value.href, base: `${new URL(base, url.value).pathname.replace(/\/+$/, "")}/`, capabilities: selected } };
36
+ const url = publicUrl(input.url);
37
+ if (url._tag === "Err") return url;
38
+ const base = input.base || "/";
39
+ if (!base.startsWith("/") || base.startsWith("//") || /[?#\\]/.test(base)) return {
40
+ _tag: "Err",
41
+ message: "Use an application base path such as /docs/."
42
+ };
43
+ const selected = [...new Set((input.capabilities || "").split(",").map((value) => value.trim()).filter(Boolean))];
44
+ const unknown = selected.filter((value) => !capabilities.includes(value));
45
+ if (unknown.length) return {
46
+ _tag: "Err",
47
+ message: `Unknown capabilities: ${unknown.join(", ")}. Use ${capabilities.join(", ")}.`
48
+ };
49
+ return {
50
+ _tag: "Ok",
51
+ value: {
52
+ url: url.value.href,
53
+ base: `${new URL(base, url.value).pathname.replace(/\/+$/, "")}/`,
54
+ capabilities: selected
55
+ }
56
+ };
37
57
  }
38
58
  async function readDocument(url, accept, dependencies) {
39
- const maxBytes = dependencies.maxBytes ?? 2 * 1024 * 1024;
40
- const signal = AbortSignal.timeout(dependencies.timeoutMs ?? 1e4);
41
- return Promise.resolve().then(async () => {
42
- let current = url;
43
- for (let redirects = 0; redirects <= 5; redirects++) {
44
- const response = await dependencies.fetch(current, { headers: { accept }, redirect: "manual", signal });
45
- if ([301, 302, 303, 307, 308].includes(response.status)) {
46
- await response.body?.cancel();
47
- const location = response.headers.get("location");
48
- const next = location ? publicUrl(location, current) : { _tag: "Err", message: "Redirect has no Location header." };
49
- if (next._tag === "Err")
50
- return next;
51
- current = next.value.href;
52
- continue;
53
- }
54
- if (Number(response.headers.get("content-length")) > maxBytes) {
55
- await response.body?.cancel();
56
- return { _tag: "Err", message: `Response exceeds the ${maxBytes} byte limit.` };
57
- }
58
- const reader = response.body?.getReader();
59
- const decoder = new TextDecoder();
60
- let body = "";
61
- let bytes = 0;
62
- if (reader) {
63
- while (true) {
64
- const chunk = await reader.read();
65
- if (chunk.done)
66
- break;
67
- bytes += chunk.value.byteLength;
68
- if (bytes > maxBytes) {
69
- await reader.cancel();
70
- return { _tag: "Err", message: `Response exceeds the ${maxBytes} byte limit.` };
71
- }
72
- body += decoder.decode(chunk.value, { stream: true });
73
- }
74
- body += decoder.decode();
75
- }
76
- return { _tag: "Ok", value: { url: current, status: response.status, headers: response.headers, body } };
77
- }
78
- return { _tag: "Err", message: "Response exceeds the five redirect limit." };
79
- }).catch((error) => ({ _tag: "Err", message: `Request failed: ${error instanceof Error ? error.message : String(error)}` }));
59
+ const maxBytes = dependencies.maxBytes ?? 2097152;
60
+ const signal = AbortSignal.timeout(dependencies.timeoutMs ?? 1e4);
61
+ return Promise.resolve().then(async () => {
62
+ let current = url;
63
+ for (let redirects = 0; redirects <= 5; redirects++) {
64
+ const response = await dependencies.fetch(current, {
65
+ headers: { accept },
66
+ redirect: "manual",
67
+ signal
68
+ });
69
+ if ([
70
+ 301,
71
+ 302,
72
+ 303,
73
+ 307,
74
+ 308
75
+ ].includes(response.status)) {
76
+ await response.body?.cancel();
77
+ const location = response.headers.get("location");
78
+ const next = location ? publicUrl(location, current) : {
79
+ _tag: "Err",
80
+ message: "Redirect has no Location header."
81
+ };
82
+ if (next._tag === "Err") return next;
83
+ current = next.value.href;
84
+ continue;
85
+ }
86
+ if (Number(response.headers.get("content-length")) > maxBytes) {
87
+ await response.body?.cancel();
88
+ return {
89
+ _tag: "Err",
90
+ message: `Response exceeds the ${maxBytes} byte limit.`
91
+ };
92
+ }
93
+ const reader = response.body?.getReader();
94
+ const decoder = new TextDecoder();
95
+ let body = "";
96
+ let bytes = 0;
97
+ if (reader) {
98
+ while (true) {
99
+ const chunk = await reader.read();
100
+ if (chunk.done) break;
101
+ bytes += chunk.value.byteLength;
102
+ if (bytes > maxBytes) {
103
+ await reader.cancel();
104
+ return {
105
+ _tag: "Err",
106
+ message: `Response exceeds the ${maxBytes} byte limit.`
107
+ };
108
+ }
109
+ body += decoder.decode(chunk.value, { stream: true });
110
+ }
111
+ body += decoder.decode();
112
+ }
113
+ return {
114
+ _tag: "Ok",
115
+ value: {
116
+ url: current,
117
+ status: response.status,
118
+ headers: response.headers,
119
+ body
120
+ }
121
+ };
122
+ }
123
+ return {
124
+ _tag: "Err",
125
+ message: "Response exceeds the five redirect limit."
126
+ };
127
+ }).catch((error) => ({
128
+ _tag: "Err",
129
+ message: `Request failed: ${error instanceof Error ? error.message : String(error)}`
130
+ }));
80
131
  }
81
132
  function responseFailure(document) {
82
- if (document._tag === "Err")
83
- return document.message;
84
- if (document.value.headers.get("cf-mitigated") === "challenge")
85
- return "Cloudflare returned a challenge. Check crawler access rules.";
86
- if (document.value.status < 200 || document.value.status >= 300)
87
- return `HTTP ${document.value.status}. Check this public URL.`;
133
+ if (document._tag === "Err") return document.message;
134
+ if (document.value.headers.get("cf-mitigated") === "challenge") return "Cloudflare returned a challenge. Check crawler access rules.";
135
+ if (document.value.status < 200 || document.value.status >= 300) return `HTTP ${document.value.status}. Check this public URL.`;
88
136
  }
89
137
  function isHtml(body) {
90
- return /^\s*(?:<!doctype html|<html|<head|<body)/i.test(body);
138
+ return /^\s*(?:<!doctype html|<html|<head|<body)/i.test(body);
91
139
  }
92
140
  function contentCheck(id, url, document, accepts, success, failure) {
93
- const error = responseFailure(document);
94
- if (error)
95
- return { id, url, status: "fail", detail: error };
96
- return document._tag === "Ok" && accepts(document.value) ? { id, url: document.value.url, status: "pass", detail: success } : { id, url, status: "fail", detail: failure };
141
+ const error = responseFailure(document);
142
+ if (error) return {
143
+ id,
144
+ url,
145
+ status: "fail",
146
+ detail: error
147
+ };
148
+ return document._tag === "Ok" && accepts(document.value) ? {
149
+ id,
150
+ url: document.value.url,
151
+ status: "pass",
152
+ detail: success
153
+ } : {
154
+ id,
155
+ url,
156
+ status: "fail",
157
+ detail: failure
158
+ };
97
159
  }
98
160
  function markdown(document) {
99
- return /^text\/markdown(?:;|$)/i.test(document.headers.get("content-type") || "") && !!document.body.trim() && !isHtml(document.body);
161
+ return /^text\/markdown(?:;|$)/i.test(document.headers.get("content-type") || "") && !!document.body.trim() && !isHtml(document.body);
100
162
  }
101
163
  function links(header) {
102
- const source = header || "";
103
- const entries = [];
104
- let quoted = false;
105
- let target = false;
106
- let start = 0;
107
- for (let i = 0; i < source.length; i++) {
108
- const character = source[i];
109
- if (character === '"' && source[i - 1] !== "\\")
110
- quoted = !quoted;
111
- if (!quoted) {
112
- if (character === "<")
113
- target = true;
114
- if (character === ">")
115
- target = false;
116
- if (character === "," && !target) {
117
- entries.push(source.slice(start, i));
118
- start = i + 1;
119
- }
120
- }
121
- }
122
- entries.push(source.slice(start));
123
- return entries.flatMap((entry) => {
124
- const match = entry.match(/^\s*<([^>]+)>([\s\S]*)$/);
125
- if (!match)
126
- return [];
127
- const parameter = (name) => match[2]?.match(new RegExp(`;\\s*${name}\\s*=\\s*(?:"([^"]*)"|([^;\\s]+))`, "i"));
128
- const rel = parameter("rel");
129
- const type = parameter("type");
130
- return [{ href: match[1], rel: (rel?.[1] || rel?.[2] || "").split(/\s+/), type: type?.[1] || type?.[2] || "" }];
131
- });
164
+ const source = header || "";
165
+ const entries = [];
166
+ let quoted = false;
167
+ let target = false;
168
+ let start = 0;
169
+ for (let i = 0; i < source.length; i++) {
170
+ const character = source[i];
171
+ if (character === "\"" && source[i - 1] !== "\\") quoted = !quoted;
172
+ if (!quoted) {
173
+ if (character === "<") target = true;
174
+ if (character === ">") target = false;
175
+ if (character === "," && !target) {
176
+ entries.push(source.slice(start, i));
177
+ start = i + 1;
178
+ }
179
+ }
180
+ }
181
+ entries.push(source.slice(start));
182
+ return entries.flatMap((entry) => {
183
+ const match = entry.match(/^\s*<([^>]+)>([\s\S]*)$/);
184
+ if (!match) return [];
185
+ const parameter = (name) => match[2]?.match(new RegExp(`;\\s*${name}\\s*=\\s*(?:"([^"]*)"|([^;\\s]+))`, "i"));
186
+ const rel = parameter("rel");
187
+ const type = parameter("type");
188
+ return [{
189
+ href: match[1],
190
+ rel: (rel?.[1] || rel?.[2] || "").split(/\s+/),
191
+ type: type?.[1] || type?.[2] || ""
192
+ }];
193
+ });
132
194
  }
133
195
  function policy(header) {
134
- const signals = {};
135
- for (const part of header.split(",")) {
136
- const match = part.trim().match(/^(search|ai-input|ai-train)\s*=\s*(yes|no)$/);
137
- if (!match)
138
- return { _tag: "Err", message: "Content-Signal has an invalid name or value." };
139
- const name = match[1];
140
- const value = match[2];
141
- if (signals[name] && signals[name] !== value)
142
- return { _tag: "Err", message: `Content-Signal contains conflicting ${name} values.` };
143
- signals[name] = value;
144
- }
145
- return { _tag: "Ok", value: signals };
196
+ const signals = {};
197
+ for (const part of header.split(",")) {
198
+ const match = part.trim().match(/^(search|ai-input|ai-train)\s*=\s*(yes|no)$/);
199
+ if (!match) return {
200
+ _tag: "Err",
201
+ message: "Content-Signal has an invalid name or value."
202
+ };
203
+ const name = match[1];
204
+ const value = match[2];
205
+ if (signals[name] && signals[name] !== value) return {
206
+ _tag: "Err",
207
+ message: `Content-Signal contains conflicting ${name} values.`
208
+ };
209
+ signals[name] = value;
210
+ }
211
+ return {
212
+ _tag: "Ok",
213
+ value: signals
214
+ };
146
215
  }
147
216
  function policyCheck(html, md, id = "content-signal") {
148
- if (html._tag === "Err" || md._tag === "Err" || responseFailure(html) || responseFailure(md))
149
- return { id, status: "skip", detail: "Policy comparison requires both public page responses." };
150
- const source = html.value.headers.get("content-signal");
151
- const converted = md.value.headers.get("content-signal");
152
- if (!source && !converted)
153
- return { id, status: "warn", detail: "No HTTP Content-Signal. Check whether this matches your content policy." };
154
- const parsedSource = source ? policy(source) : void 0;
155
- const parsedConverted = converted ? policy(converted) : void 0;
156
- for (const parsed of [parsedSource, parsedConverted]) {
157
- if (parsed?._tag === "Err")
158
- return { id, status: "fail", detail: parsed.message };
159
- }
160
- if (parsedSource?._tag === "Ok" && (!parsedConverted || parsedConverted._tag !== "Ok" || Object.keys(parsedSource.value).length !== Object.keys(parsedConverted.value).length || Object.entries(parsedSource.value).some(([key, value]) => parsedConverted.value[key] !== value))) {
161
- return { id, status: "fail", detail: "Markdown does not preserve the HTML Content-Signal policy." };
162
- }
163
- return { id, status: "pass", detail: `HTTP policy: ${converted || source}` };
217
+ if (html._tag === "Err" || md._tag === "Err" || responseFailure(html) || responseFailure(md)) return {
218
+ id,
219
+ status: "skip",
220
+ detail: "Policy comparison requires both public page responses."
221
+ };
222
+ const source = html.value.headers.get("content-signal");
223
+ const converted = md.value.headers.get("content-signal");
224
+ if (!source && !converted) return {
225
+ id,
226
+ status: "warn",
227
+ detail: "No HTTP Content-Signal. Check whether this matches your content policy."
228
+ };
229
+ const parsedSource = source ? policy(source) : void 0;
230
+ const parsedConverted = converted ? policy(converted) : void 0;
231
+ for (const parsed of [parsedSource, parsedConverted]) if (parsed?._tag === "Err") return {
232
+ id,
233
+ status: "fail",
234
+ detail: parsed.message
235
+ };
236
+ if (parsedSource?._tag === "Ok" && (!parsedConverted || parsedConverted._tag !== "Ok" || Object.keys(parsedSource.value).length !== Object.keys(parsedConverted.value).length || Object.entries(parsedSource.value).some(([key, value]) => parsedConverted.value[key] !== value))) return {
237
+ id,
238
+ status: "fail",
239
+ detail: "Markdown does not preserve the HTML Content-Signal policy."
240
+ };
241
+ return {
242
+ id,
243
+ status: "pass",
244
+ detail: `HTTP policy: ${converted || source}`
245
+ };
164
246
  }
165
247
  function isRecord(value) {
166
- return !!value && typeof value === "object" && !Array.isArray(value);
248
+ return !!value && typeof value === "object" && !Array.isArray(value);
167
249
  }
168
250
  function parseJson(body) {
169
- try {
170
- return { _tag: "Ok", value: JSON.parse(body) };
171
- } catch {
172
- return { _tag: "Err", message: "Discovery response contains invalid JSON." };
173
- }
251
+ try {
252
+ return {
253
+ _tag: "Ok",
254
+ value: JSON.parse(body)
255
+ };
256
+ } catch {
257
+ return {
258
+ _tag: "Err",
259
+ message: "Discovery response contains invalid JSON."
260
+ };
261
+ }
174
262
  }
175
263
  function discoveryDocument(capability, document) {
176
- if (capability === "llms")
177
- return !isHtml(document.body) && /^#\s+\S/m.test(document.body);
178
- if (!/^application\/(?:[\w.+-]+\+)?json(?:;|$)/i.test(document.headers.get("content-type") || ""))
179
- return false;
180
- const parsed = parseJson(document.body);
181
- if (parsed._tag === "Err")
182
- return false;
183
- const value = parsed.value;
184
- if (!isRecord(value))
185
- return false;
186
- switch (capability) {
187
- case "api-catalog":
188
- return Array.isArray(value.linkset) && value.linkset.length > 0 && value.linkset.every((entry) => isRecord(entry) && typeof entry.anchor === "string");
189
- case "skills":
190
- return Array.isArray(value.skills);
191
- case "ai-catalog":
192
- return value.specVersion === "1.0" && Array.isArray(value.entries) && value.entries.length > 0 && value.entries.every((entry) => isRecord(entry) && typeof entry.url === "string");
193
- case "mcp":
194
- return typeof value.name === "string" && typeof value.version === "string" && Array.isArray(value.remotes) && value.remotes.some((remote) => isRecord(remote) && remote.type === "streamable-http" && typeof remote.url === "string");
195
- }
264
+ if (capability === "llms") return !isHtml(document.body) && /^#\s+\S/m.test(document.body);
265
+ if (!/^application\/(?:[\w.+-]+\+)?json(?:;|$)/i.test(document.headers.get("content-type") || "")) return false;
266
+ const parsed = parseJson(document.body);
267
+ if (parsed._tag === "Err") return false;
268
+ const value = parsed.value;
269
+ if (!isRecord(value)) return false;
270
+ switch (capability) {
271
+ case "api-catalog": return Array.isArray(value.linkset) && value.linkset.length > 0 && value.linkset.every((entry) => isRecord(entry) && typeof entry.anchor === "string");
272
+ case "skills": return Array.isArray(value.skills);
273
+ case "ai-catalog": return value.specVersion === "1.0" && Array.isArray(value.entries) && value.entries.length > 0 && value.entries.every((entry) => isRecord(entry) && typeof entry.url === "string");
274
+ case "mcp": return typeof value.name === "string" && typeof value.version === "string" && Array.isArray(value.remotes) && value.remotes.some((remote) => isRecord(remote) && remote.type === "streamable-http" && typeof remote.url === "string");
275
+ }
196
276
  }
277
+ /** Inspect one public page and its discovery documents. No sync endpoint or credential is used. */
197
278
  async function auditSite(options, dependencies) {
198
- const [html, negotiated] = await Promise.all([
199
- readDocument(options.url, "text/html", dependencies),
200
- readDocument(options.url, "text/markdown", dependencies)
201
- ]);
202
- const pageUrl = html._tag === "Ok" && !responseFailure(html) ? html.value.url : options.url;
203
- const page = new URL(pageUrl);
204
- const site = new URL(options.base, page);
205
- const advertised = html._tag === "Ok" ? links(html.value.headers.get("link")) : [];
206
- const alternate = advertised.find((link) => link.rel.includes("alternate") && link.type.toLowerCase() === "text/markdown");
207
- const linkedUrl = alternate ? publicUrl(alternate.href, pageUrl) : void 0;
208
- const direct = new URL(pageUrl);
209
- direct.pathname = `${direct.pathname.replace(/\/$/, "") || "/index"}.md`;
210
- const robotsUrl = new URL("/robots.txt", page).href;
211
- const [directMd, robots] = await Promise.all([
212
- readDocument(direct.href, "text/markdown", dependencies),
213
- readDocument(robotsUrl, "text/plain", dependencies)
214
- ]);
215
- const robotsSitemap = robots._tag === "Ok" ? robots.value.body.match(/^sitemap:\s*(\S+)/im)?.[1] : void 0;
216
- const sitemapUrl = robotsSitemap ? publicUrl(robotsSitemap, robotsUrl) : publicUrl("sitemap.xml", site.href);
217
- const sitemap = sitemapUrl._tag === "Ok" ? await readDocument(sitemapUrl.value.href, "application/xml, text/xml", dependencies) : sitemapUrl;
218
- const missingUrl = new URL(".well-known/nuxt-ai-ready-audit-missing", site).href;
219
- const missing = await readDocument(missingUrl, "text/markdown", dependencies);
220
- const checks = [
221
- contentCheck("html", options.url, html, (doc) => /^text\/html(?:;|$)/i.test(doc.headers.get("content-type") || "") && !!doc.body.trim(), "Public HTML is available.", "Expected a non-empty HTML page."),
222
- contentCheck("markdown-negotiation", options.url, negotiated, markdown, "Accept: text/markdown returns Markdown.", "Expected a non-empty text/markdown response."),
223
- contentCheck("markdown-url", direct.href, directMd, markdown, "The direct Markdown URL is available.", "Expected a non-empty text/markdown response."),
224
- { id: "markdown-link", status: linkedUrl?._tag === "Ok" && linkedUrl.value.href === direct.href ? "pass" : "warn", detail: linkedUrl?._tag === "Ok" && linkedUrl.value.href === direct.href ? "The Link header advertises the direct Markdown URL." : alternate ? "Inspect the alternate Markdown Link target." : "No alternate Markdown Link header." },
225
- contentCheck("robots", robotsUrl, robots, (doc) => !isHtml(doc.body) && /^user-agent:\s*\S/im.test(doc.body), "robots.txt is available. Inspect its crawler-specific rules.", "Expected robots.txt with a User-agent group."),
226
- contentCheck("sitemap", sitemapUrl._tag === "Ok" ? sitemapUrl.value.href : site.href, sitemap, (doc) => /<(?:urlset|sitemapindex)(?:\s|>)/i.test(doc.body) && /<loc>\s*https?:\/\/[^<]+<\/loc>/i.test(doc.body), "A sitemap document is available.", "Expected a sitemap with absolute URL entries."),
227
- policyCheck(html, negotiated),
228
- policyCheck(html, directMd, "content-signal-markdown-url"),
229
- { id: "unknown-route", url: missingUrl, status: missing._tag === "Ok" && [404, 410].includes(missing.value.status) ? "pass" : "fail", detail: missing._tag === "Err" ? missing.message : [404, 410].includes(missing.value.status) ? "Unknown routes return 404 or 410." : `Unknown route returned HTTP ${missing.value.status}. Check fallback routing.` }
230
- ];
231
- if (negotiated._tag === "Ok" && !responseFailure(negotiated)) {
232
- const vary = (negotiated.value.headers.get("vary") || "").toLowerCase().split(",").map((value) => value.trim());
233
- checks.push({ id: "vary-accept", status: vary.includes("accept") || vary.includes("*") ? "pass" : "fail", detail: vary.includes("accept") || vary.includes("*") ? "Vary separates HTML and Markdown cache entries." : "Set Vary: Accept on negotiated responses." });
234
- }
235
- const paths = { "llms": "llms.txt", "api-catalog": ".well-known/api-catalog", "ai-catalog": ".well-known/ai-catalog.json", "mcp": ".well-known/mcp/server-card.json", "skills": ".well-known/agent-skills/index.json" };
236
- const discovery = await Promise.all(capabilities.map(async (capability) => {
237
- const declaredLink = capability === "api-catalog" ? advertised.find((link) => link.rel.includes("api-catalog")) : void 0;
238
- if (!options.capabilities.includes(capability) && !declaredLink)
239
- return { id: capability, status: "skip", detail: "Not declared. Use --capabilities to check this feature." };
240
- const url = publicUrl(declaredLink?.href || paths[capability], declaredLink ? pageUrl : site.href);
241
- if (url._tag === "Err")
242
- return { id: capability, status: "fail", detail: url.message };
243
- const document = await readDocument(url.value.href, capability === "llms" ? "text/plain" : "application/json", dependencies);
244
- return contentCheck(capability, url.value.href, document, (doc) => discoveryDocument(capability, doc), "The discovery document is available.", "The discovery document has an unexpected format.");
245
- }));
246
- return { schemaVersion: 1, url: options.url, checks: [...checks, ...discovery] };
279
+ const [html, negotiated] = await Promise.all([readDocument(options.url, "text/html", dependencies), readDocument(options.url, "text/markdown", dependencies)]);
280
+ const pageUrl = html._tag === "Ok" && !responseFailure(html) ? html.value.url : options.url;
281
+ const page = new URL(pageUrl);
282
+ const site = new URL(options.base, page);
283
+ const advertised = html._tag === "Ok" ? links(html.value.headers.get("link")) : [];
284
+ const alternate = advertised.find((link) => link.rel.includes("alternate") && link.type.toLowerCase() === "text/markdown");
285
+ const linkedUrl = alternate ? publicUrl(alternate.href, pageUrl) : void 0;
286
+ const direct = new URL(pageUrl);
287
+ direct.pathname = `${direct.pathname.replace(/\/$/, "") || "/index"}.md`;
288
+ const robotsUrl = new URL("/robots.txt", page).href;
289
+ const [directMd, robots] = await Promise.all([readDocument(direct.href, "text/markdown", dependencies), readDocument(robotsUrl, "text/plain", dependencies)]);
290
+ const robotsSitemap = robots._tag === "Ok" ? robots.value.body.match(/^sitemap:\s*(\S+)/im)?.[1] : void 0;
291
+ const sitemapUrl = robotsSitemap ? publicUrl(robotsSitemap, robotsUrl) : publicUrl("sitemap.xml", site.href);
292
+ const sitemap = sitemapUrl._tag === "Ok" ? await readDocument(sitemapUrl.value.href, "application/xml, text/xml", dependencies) : sitemapUrl;
293
+ const missingUrl = new URL(".well-known/nuxt-ai-ready-audit-missing", site).href;
294
+ const missing = await readDocument(missingUrl, "text/markdown", dependencies);
295
+ const checks = [
296
+ contentCheck("html", options.url, html, (doc) => /^text\/html(?:;|$)/i.test(doc.headers.get("content-type") || "") && !!doc.body.trim(), "Public HTML is available.", "Expected a non-empty HTML page."),
297
+ contentCheck("markdown-negotiation", options.url, negotiated, markdown, "Accept: text/markdown returns Markdown.", "Expected a non-empty text/markdown response."),
298
+ contentCheck("markdown-url", direct.href, directMd, markdown, "The direct Markdown URL is available.", "Expected a non-empty text/markdown response."),
299
+ {
300
+ id: "markdown-link",
301
+ status: linkedUrl?._tag === "Ok" && linkedUrl.value.href === direct.href ? "pass" : "warn",
302
+ detail: linkedUrl?._tag === "Ok" && linkedUrl.value.href === direct.href ? "The Link header advertises the direct Markdown URL." : alternate ? "Inspect the alternate Markdown Link target." : "No alternate Markdown Link header."
303
+ },
304
+ contentCheck("robots", robotsUrl, robots, (doc) => !isHtml(doc.body) && /^user-agent:\s*\S/im.test(doc.body), "robots.txt is available. Inspect its crawler-specific rules.", "Expected robots.txt with a User-agent group."),
305
+ contentCheck("sitemap", sitemapUrl._tag === "Ok" ? sitemapUrl.value.href : site.href, sitemap, (doc) => /<(?:urlset|sitemapindex)(?:\s|>)/i.test(doc.body) && /<loc>\s*https?:\/\/[^<]+<\/loc>/i.test(doc.body), "A sitemap document is available.", "Expected a sitemap with absolute URL entries."),
306
+ policyCheck(html, negotiated),
307
+ policyCheck(html, directMd, "content-signal-markdown-url"),
308
+ {
309
+ id: "unknown-route",
310
+ url: missingUrl,
311
+ status: missing._tag === "Ok" && [404, 410].includes(missing.value.status) ? "pass" : "fail",
312
+ detail: missing._tag === "Err" ? missing.message : [404, 410].includes(missing.value.status) ? "Unknown routes return 404 or 410." : `Unknown route returned HTTP ${missing.value.status}. Check fallback routing.`
313
+ }
314
+ ];
315
+ if (negotiated._tag === "Ok" && !responseFailure(negotiated)) {
316
+ const vary = (negotiated.value.headers.get("vary") || "").toLowerCase().split(",").map((value) => value.trim());
317
+ checks.push({
318
+ id: "vary-accept",
319
+ status: vary.includes("accept") || vary.includes("*") ? "pass" : "fail",
320
+ detail: vary.includes("accept") || vary.includes("*") ? "Vary separates HTML and Markdown cache entries." : "Set Vary: Accept on negotiated responses."
321
+ });
322
+ }
323
+ const paths = {
324
+ "llms": "llms.txt",
325
+ "api-catalog": ".well-known/api-catalog",
326
+ "ai-catalog": ".well-known/ai-catalog.json",
327
+ "mcp": ".well-known/mcp/server-card.json",
328
+ "skills": ".well-known/agent-skills/index.json"
329
+ };
330
+ const discovery = await Promise.all(capabilities.map(async (capability) => {
331
+ const declaredLink = capability === "api-catalog" ? advertised.find((link) => link.rel.includes("api-catalog")) : void 0;
332
+ if (!options.capabilities.includes(capability) && !declaredLink) return {
333
+ id: capability,
334
+ status: "skip",
335
+ detail: "Not declared. Use --capabilities to check this feature."
336
+ };
337
+ const url = publicUrl(declaredLink?.href || paths[capability], declaredLink ? pageUrl : site.href);
338
+ if (url._tag === "Err") return {
339
+ id: capability,
340
+ status: "fail",
341
+ detail: url.message
342
+ };
343
+ const document = await readDocument(url.value.href, capability === "llms" ? "text/plain" : "application/json", dependencies);
344
+ return contentCheck(capability, url.value.href, document, (doc) => discoveryDocument(capability, doc), "The discovery document is available.", "The discovery document has an unexpected format.");
345
+ }));
346
+ return {
347
+ schemaVersion: 1,
348
+ url: options.url,
349
+ checks: [...checks, ...discovery]
350
+ };
247
351
  }
248
-
352
+ // src/cli.ts
249
353
  async function getSecret(cwd) {
250
- const root = process.env.NITRO_APP_SECRET ?? process.env.NUXT_APP_SECRET;
251
- if (root !== void 0 && root !== "")
252
- return deriveRuntimeSyncSecret(root);
253
- const legacy = process.env.NUXT_NUXT_AI_READY_RUNTIME_SYNC_SECRET ?? process.env.NUXT_AI_READY_RUNTIME_SYNC_SECRET;
254
- if (legacy) {
255
- console.warn(`[nuxt-ai-ready] ${LEGACY_RUNTIME_SYNC_SECRET_WARNING}`);
256
- return legacy;
257
- }
258
- const secretPath = join(cwd, "node_modules/.cache/nuxt/ai-ready/secret");
259
- if (!existsSync(secretPath)) {
260
- return null;
261
- }
262
- return fsp.readFile(secretPath, "utf-8").then((s) => s.trim()).catch(() => {
263
- return null;
264
- });
354
+ const root = process.env.NITRO_APP_SECRET ?? process.env.NUXT_APP_SECRET;
355
+ if (root !== void 0 && root !== "") return deriveRuntimeSyncSecret(root);
356
+ const legacy = process.env.NUXT_NUXT_AI_READY_RUNTIME_SYNC_SECRET ?? process.env.NUXT_AI_READY_RUNTIME_SYNC_SECRET;
357
+ if (legacy) {
358
+ console.warn(`[nuxt-ai-ready] ${LEGACY_RUNTIME_SYNC_SECRET_WARNING}`);
359
+ return legacy;
360
+ }
361
+ const secretPath = join(cwd, "node_modules/.cache/nuxt/ai-ready/secret");
362
+ if (!existsSync(secretPath)) return null;
363
+ return fsp.readFile(secretPath, "utf-8").then((s) => s.trim()).catch(() => {
364
+ return null;
365
+ });
265
366
  }
266
367
  function authHeaders(secret) {
267
- return { Authorization: `Bearer ${secret}` };
368
+ return { Authorization: `Bearer ${secret}` };
268
369
  }
269
370
  async function requireSecret(cwd) {
270
- const secret = await getSecret(cwd);
271
- if (!secret) {
272
- throw new Error(`${APPLICATION_SECRET_ERROR} For development, run nuxt dev to cache the runtime sync token.`);
273
- }
274
- return secret;
371
+ const secret = await getSecret(cwd);
372
+ if (!secret) throw new Error(`${APPLICATION_SECRET_ERROR} For development, run nuxt dev to cache the runtime sync token.`);
373
+ return secret;
275
374
  }
276
375
  function describeHttpError(status, body) {
277
- const error = body;
278
- const message = typeof error?.message === "string" && error.message ? error.message : typeof error?.statusMessage === "string" && error.statusMessage ? error.statusMessage : typeof error?.error === "string" && error.error ? error.error : null;
279
- return message ? `${status}: ${message}` : `request failed with status ${status}`;
376
+ const error = body;
377
+ const message = typeof error?.message === "string" && error.message ? error.message : typeof error?.statusMessage === "string" && error.statusMessage ? error.statusMessage : typeof error?.error === "string" && error.error ? error.error : null;
378
+ return message ? `${status}: ${message}` : `request failed with status ${status}`;
280
379
  }
281
380
  async function fetchJson(url, init, errorLabel = "Failed") {
282
- const r = await fetch(url, init).catch((err) => {
283
- throw new Error(`${errorLabel}: ${err instanceof Error ? err.message : String(err)}`);
284
- });
285
- if (!r.ok) {
286
- const body = await r.json().catch(() => {
287
- return null;
288
- });
289
- throw new Error(`${errorLabel}: ${describeHttpError(r.status, body)}`);
290
- }
291
- return r.json();
381
+ const r = await fetch(url, init).catch((err) => {
382
+ throw new Error(`${errorLabel}: ${err instanceof Error ? err.message : String(err)}`);
383
+ });
384
+ if (!r.ok) {
385
+ const body = await r.json().catch(() => {
386
+ return null;
387
+ });
388
+ throw new Error(`${errorLabel}: ${describeHttpError(r.status, body)}`);
389
+ }
390
+ return r.json();
292
391
  }
293
392
  const main = defineCommand({
294
- meta: {
295
- name: "nuxt-ai-ready",
296
- description: "Nuxt AI Ready CLI",
297
- version: await readPackageMetadata(import.meta.url).then((p) => p.version || "0.0.0")
298
- },
299
- subCommands: {
300
- token: () => defineCommand({
301
- meta: { name: "token", description: "Print the runtime sync bearer token" },
302
- args: { cwd: { type: "string", description: "Working directory", default: "." } },
303
- async run({ args }) {
304
- const secret = await requireSecret(resolve(args.cwd));
305
- process.stdout.write(`${secret}
306
- `);
307
- }
308
- }),
309
- audit: () => defineCommand({
310
- meta: { name: "audit", description: "Check a public page and its agent discovery documents" },
311
- args: {
312
- url: { type: "positional", required: true, description: "Public page URL" },
313
- base: { type: "string", default: "/", description: "Application base path, such as /docs/" },
314
- capabilities: { type: "string", description: "Check declared features: llms,api-catalog,ai-catalog,mcp,skills" },
315
- json: { type: "boolean", description: "Print structured JSON results" }
316
- },
317
- async run({ args }) {
318
- const parsed = parseAuditOptions(args);
319
- if (parsed._tag === "Err")
320
- throw new Error(parsed.message);
321
- const report = await auditSite(parsed.value, { fetch });
322
- if (args.json) {
323
- process.stdout.write(`${JSON.stringify(report, null, 2)}
324
- `);
325
- } else {
326
- consola.info(`Readiness audit: ${report.url}`);
327
- for (const check of report.checks)
328
- consola.log(`${check.status.toUpperCase()} ${check.id}: ${check.detail}`);
329
- }
330
- if (report.checks.some((check) => check.status === "fail"))
331
- process.exitCode = 1;
332
- }
333
- }),
334
- status: () => defineCommand({
335
- meta: {
336
- name: "status",
337
- description: "Show indexing status and sync progress"
338
- },
339
- args: {
340
- url: {
341
- type: "string",
342
- alias: "u",
343
- description: "Site URL (default: http://localhost:3000)",
344
- default: "http://localhost:3000"
345
- },
346
- cwd: {
347
- type: "string",
348
- description: "Working directory",
349
- default: "."
350
- }
351
- },
352
- async run({ args }) {
353
- const cwd = resolve(args.cwd || ".");
354
- const secret = await requireSecret(cwd);
355
- if (!secret)
356
- return;
357
- const url = joinURL(args.url, "/__ai-ready/status");
358
- consola.info(`Fetching status from ${args.url}...`);
359
- const res = await fetchJson(url, { headers: authHeaders(secret) }, "Failed to connect");
360
- consola.box("AI Ready Status");
361
- consola.info(`Total pages: ${colors.cyan(res.total?.toString() || "0")}`);
362
- consola.info(`Indexed: ${colors.green(res.indexed?.toString() || "0")}`);
363
- consola.info(`Pending: ${colors.yellow(res.pending?.toString() || "0")}`);
364
- if (res.activity) {
365
- consola.log("");
366
- consola.info(colors.bold("Activity:"));
367
- consola.info(` Last 1h: ${colors.cyan(res.activity.last1h?.toString() || "0")} pages indexed`);
368
- consola.info(` Last 24h: ${colors.cyan(res.activity.last24h?.toString() || "0")} pages indexed`);
369
- if (res.activity.recentPages?.length) {
370
- consola.info(` Recent:`);
371
- for (const p of res.activity.recentPages.slice(0, 5)) {
372
- const ago = Date.now() - p.indexedAt;
373
- const agoStr = ago < 6e4 ? `${Math.round(ago / 1e3)}s` : ago < 36e5 ? `${Math.round(ago / 6e4)}m` : `${Math.round(ago / 36e5)}h`;
374
- consola.info(` ${colors.dim(`${agoStr} ago`)} ${p.route} ${colors.dim(p.title || "")}`);
375
- }
376
- }
377
- }
378
- if (res.cron) {
379
- consola.log("");
380
- consola.info(colors.bold("Cron:"));
381
- if (res.cron.lock?.held) {
382
- consola.warn(` Lock: ${colors.yellow("held")} (${Math.round((res.cron.lock.elapsedMs || 0) / 1e3)}s)`);
383
- }
384
- if (res.cron.recentRuns?.length) {
385
- for (const run of res.cron.recentRuns) {
386
- const status = run.status === "success" ? colors.green(run.status) : run.status === "error" ? colors.red(run.status) : colors.yellow(run.status);
387
- consola.info(` ${colors.dim(new Date(run.startedAt).toLocaleTimeString())} ${status} ${colors.dim(`${run.durationMs || 0}ms`)} ${run.pagesIndexed ? `${run.pagesIndexed} indexed` : ""}`);
388
- }
389
- }
390
- }
391
- if (res.sitemaps?.length) {
392
- consola.log("");
393
- consola.info(colors.bold("Sitemaps:"));
394
- for (const s of res.sitemaps) {
395
- const err = s.errorCount > 0 ? colors.red(` (${s.errorCount} errors)`) : "";
396
- consola.info(` ${s.name}: ${colors.cyan(s.urlCount?.toString() || "0")} URLs${err}`);
397
- }
398
- }
399
- }
400
- }),
401
- poll: () => defineCommand({
402
- meta: {
403
- name: "poll",
404
- description: "Trigger page indexing"
405
- },
406
- args: {
407
- url: {
408
- type: "string",
409
- alias: "u",
410
- description: "Site URL (default: http://localhost:3000)",
411
- default: "http://localhost:3000"
412
- },
413
- limit: {
414
- type: "string",
415
- alias: "l",
416
- description: "Max pages to process",
417
- default: "10"
418
- },
419
- all: {
420
- type: "boolean",
421
- alias: "a",
422
- description: "Process all pending pages"
423
- },
424
- cwd: {
425
- type: "string",
426
- description: "Working directory",
427
- default: "."
428
- }
429
- },
430
- async run({ args }) {
431
- const cwd = resolve(args.cwd || ".");
432
- const secret = await requireSecret(cwd);
433
- if (!secret)
434
- return;
435
- const params = new URLSearchParams();
436
- if (args.all) {
437
- params.set("all", "true");
438
- } else {
439
- params.set("limit", args.limit || "10");
440
- }
441
- const url = joinURL(args.url, `/__ai-ready/poll?${params}`);
442
- consola.info(`Triggering poll at ${args.url}...`);
443
- const res = await fetchJson(url, { method: "POST", headers: authHeaders(secret) });
444
- consola.success(`Indexed: ${colors.green(res.indexed?.toString() || "0")} pages`);
445
- consola.info(`Remaining: ${colors.yellow(res.remaining?.toString() || "0")}`);
446
- if (res.errors?.length) {
447
- consola.warn(`Errors: ${res.errors.length}`);
448
- }
449
- if (res.duration) {
450
- consola.info(`Duration: ${colors.dim(`${res.duration}ms`)}`);
451
- }
452
- }
453
- }),
454
- restore: () => defineCommand({
455
- meta: {
456
- name: "restore",
457
- description: "Restore database from prerendered dump"
458
- },
459
- args: {
460
- url: {
461
- type: "string",
462
- alias: "u",
463
- description: "Site URL (default: http://localhost:3000)",
464
- default: "http://localhost:3000"
465
- },
466
- clear: {
467
- type: "boolean",
468
- description: "Clear existing pages first",
469
- default: true,
470
- negativeDescription: "Restore without clearing existing pages"
471
- },
472
- cwd: {
473
- type: "string",
474
- description: "Working directory",
475
- default: "."
476
- }
477
- },
478
- async run({ args }) {
479
- const cwd = resolve(args.cwd || ".");
480
- const secret = await requireSecret(cwd);
481
- if (!secret)
482
- return;
483
- const params = new URLSearchParams();
484
- if (!args.clear) {
485
- params.set("clear", "false");
486
- }
487
- const url = joinURL(args.url, `/__ai-ready/restore?${params}`);
488
- consola.info(`Restoring database at ${args.url}...`);
489
- const res = await fetchJson(url, { method: "POST", headers: authHeaders(secret) });
490
- consola.success(`Restored: ${colors.green(res.restored?.toString() || "0")} pages`);
491
- if (res.cleared) {
492
- consola.info(`Cleared: ${colors.yellow(res.cleared?.toString() || "0")} existing pages`);
493
- }
494
- }
495
- }),
496
- prune: () => defineCommand({
497
- meta: {
498
- name: "prune",
499
- description: "Remove stale routes from database"
500
- },
501
- args: {
502
- url: {
503
- type: "string",
504
- alias: "u",
505
- description: "Site URL (default: http://localhost:3000)",
506
- default: "http://localhost:3000"
507
- },
508
- dry: {
509
- type: "boolean",
510
- alias: "d",
511
- description: "Preview without deleting"
512
- },
513
- ttl: {
514
- type: "string",
515
- description: "Override pruneTtl config"
516
- },
517
- cwd: {
518
- type: "string",
519
- description: "Working directory",
520
- default: "."
521
- }
522
- },
523
- async run({ args }) {
524
- const cwd = resolve(args.cwd || ".");
525
- const secret = await getSecret(cwd);
526
- if (!secret && !args.dry) {
527
- throw new Error(`${APPLICATION_SECRET_ERROR} For development, run nuxt dev to cache the runtime sync token.`);
528
- }
529
- const params = new URLSearchParams();
530
- if (args.dry)
531
- params.set("dry", "true");
532
- if (args.ttl)
533
- params.set("ttl", args.ttl);
534
- const url = joinURL(args.url, `/__ai-ready/prune?${params}`);
535
- consola.info(`${args.dry ? "Previewing" : "Pruning"} stale routes at ${args.url}...`);
536
- const res = await fetchJson(url, {
537
- method: "POST",
538
- headers: secret ? authHeaders(secret) : void 0
539
- });
540
- if (args.dry) {
541
- consola.info(`Would prune: ${colors.yellow(res.count?.toString() || "0")} routes`);
542
- if (res.routes?.length) {
543
- for (const route of res.routes.slice(0, 20)) {
544
- consola.log(` ${colors.dim("\u2022")} ${route}`);
545
- }
546
- if (res.routes.length > 20) {
547
- consola.log(` ${colors.dim(`... and ${res.routes.length - 20} more`)}`);
548
- }
549
- }
550
- } else {
551
- consola.success(`Pruned: ${colors.green(res.pruned?.toString() || "0")} routes`);
552
- }
553
- }
554
- }),
555
- reindex: () => defineCommand({
556
- meta: {
557
- name: "reindex",
558
- description: "Reindex a single route"
559
- },
560
- args: {
561
- route: {
562
- type: "positional",
563
- description: "Route to reindex (e.g. /about)",
564
- required: true
565
- },
566
- url: {
567
- type: "string",
568
- alias: "u",
569
- description: "Site URL (default: http://localhost:3000)",
570
- default: "http://localhost:3000"
571
- },
572
- force: {
573
- type: "boolean",
574
- description: "Index even when the page is still fresh",
575
- default: true,
576
- negativeDescription: "Skip indexing when the page is still fresh"
577
- },
578
- cwd: {
579
- type: "string",
580
- description: "Working directory",
581
- default: "."
582
- }
583
- },
584
- async run({ args }) {
585
- const cwd = resolve(args.cwd || ".");
586
- const secret = await requireSecret(cwd);
587
- if (!secret)
588
- return;
589
- const params = new URLSearchParams();
590
- params.set("route", args.route);
591
- if (!args.force)
592
- params.set("force", "false");
593
- const url = joinURL(args.url, `/__ai-ready/reindex?${params}`);
594
- consola.info(`Reindexing ${args.route} at ${args.url}...`);
595
- const res = await fetchJson(url, { method: "POST", headers: authHeaders(secret) });
596
- if (res.indexed) {
597
- consola.success(`Indexed: ${colors.green(res.route)}`);
598
- if (res.contentChanged !== void 0) {
599
- consola.info(`Content changed: ${res.contentChanged ? colors.green("yes") : colors.yellow("no")}`);
600
- }
601
- } else if (res.skipped) {
602
- consola.info(`Skipped: ${colors.yellow(res.route)} (still fresh)`);
603
- } else if (res.gone) {
604
- consola.success(`Removed: ${colors.green(res.route)} (HTTP 410)`);
605
- } else {
606
- throw new Error(`Failed to reindex ${res.route ?? args.route}${res.error ? `: ${res.error}` : ""}`);
607
- }
608
- }
609
- })
610
- }
393
+ meta: {
394
+ name: "nuxt-ai-ready",
395
+ description: "Nuxt AI Ready CLI",
396
+ version: await readPackageMetadata(import.meta.url).then((p) => p.version || "0.0.0")
397
+ },
398
+ subCommands: {
399
+ token: () => defineCommand({
400
+ meta: {
401
+ name: "token",
402
+ description: "Print the runtime sync bearer token"
403
+ },
404
+ args: { cwd: {
405
+ type: "string",
406
+ description: "Working directory",
407
+ default: "."
408
+ } },
409
+ async run({ args }) {
410
+ const secret = await requireSecret(resolve(args.cwd));
411
+ process.stdout.write(`${secret}\n`);
412
+ }
413
+ }),
414
+ audit: () => defineCommand({
415
+ meta: {
416
+ name: "audit",
417
+ description: "Check a public page and its agent discovery documents"
418
+ },
419
+ args: {
420
+ url: {
421
+ type: "positional",
422
+ required: true,
423
+ description: "Public page URL"
424
+ },
425
+ base: {
426
+ type: "string",
427
+ default: "/",
428
+ description: "Application base path, such as /docs/"
429
+ },
430
+ capabilities: {
431
+ type: "string",
432
+ description: "Check declared features: llms,api-catalog,ai-catalog,mcp,skills"
433
+ },
434
+ json: {
435
+ type: "boolean",
436
+ description: "Print structured JSON results"
437
+ }
438
+ },
439
+ async run({ args }) {
440
+ const parsed = parseAuditOptions(args);
441
+ if (parsed._tag === "Err") throw new Error(parsed.message);
442
+ const report = await auditSite(parsed.value, { fetch });
443
+ if (args.json) process.stdout.write(`${JSON.stringify(report, null, 2)}\n`);
444
+ else {
445
+ consola.info(`Readiness audit: ${report.url}`);
446
+ for (const check of report.checks) consola.log(`${check.status.toUpperCase()} ${check.id}: ${check.detail}`);
447
+ }
448
+ if (report.checks.some((check) => check.status === "fail")) process.exitCode = 1;
449
+ }
450
+ }),
451
+ status: () => defineCommand({
452
+ meta: {
453
+ name: "status",
454
+ description: "Show indexing status and sync progress"
455
+ },
456
+ args: {
457
+ url: {
458
+ type: "string",
459
+ alias: "u",
460
+ description: "Site URL (default: http://localhost:3000)",
461
+ default: "http://localhost:3000"
462
+ },
463
+ cwd: {
464
+ type: "string",
465
+ description: "Working directory",
466
+ default: "."
467
+ }
468
+ },
469
+ async run({ args }) {
470
+ const secret = await requireSecret(resolve(args.cwd || "."));
471
+ if (!secret) return;
472
+ const url = joinURL(args.url, "/__ai-ready/status");
473
+ consola.info(`Fetching status from ${args.url}...`);
474
+ const res = await fetchJson(url, { headers: authHeaders(secret) }, "Failed to connect");
475
+ consola.box("AI Ready Status");
476
+ consola.info(`Total pages: ${colors.cyan(res.total?.toString() || "0")}`);
477
+ consola.info(`Indexed: ${colors.green(res.indexed?.toString() || "0")}`);
478
+ consola.info(`Pending: ${colors.yellow(res.pending?.toString() || "0")}`);
479
+ if (res.activity) {
480
+ consola.log("");
481
+ consola.info(colors.bold("Activity:"));
482
+ consola.info(` Last 1h: ${colors.cyan(res.activity.last1h?.toString() || "0")} pages indexed`);
483
+ consola.info(` Last 24h: ${colors.cyan(res.activity.last24h?.toString() || "0")} pages indexed`);
484
+ if (res.activity.recentPages?.length) {
485
+ consola.info(` Recent:`);
486
+ for (const p of res.activity.recentPages.slice(0, 5)) {
487
+ const ago = Date.now() - p.indexedAt;
488
+ const agoStr = ago < 6e4 ? `${Math.round(ago / 1e3)}s` : ago < 36e5 ? `${Math.round(ago / 6e4)}m` : `${Math.round(ago / 36e5)}h`;
489
+ consola.info(` ${colors.dim(`${agoStr} ago`)} ${p.route} ${colors.dim(p.title || "")}`);
490
+ }
491
+ }
492
+ }
493
+ if (res.cron) {
494
+ consola.log("");
495
+ consola.info(colors.bold("Cron:"));
496
+ if (res.cron.lock?.held) consola.warn(` Lock: ${colors.yellow("held")} (${Math.round((res.cron.lock.elapsedMs || 0) / 1e3)}s)`);
497
+ if (res.cron.recentRuns?.length) for (const run of res.cron.recentRuns) {
498
+ const status = run.status === "success" ? colors.green(run.status) : run.status === "error" ? colors.red(run.status) : colors.yellow(run.status);
499
+ consola.info(` ${colors.dim(new Date(run.startedAt).toLocaleTimeString())} ${status} ${colors.dim(`${run.durationMs || 0}ms`)} ${run.pagesIndexed ? `${run.pagesIndexed} indexed` : ""}`);
500
+ }
501
+ }
502
+ if (res.sitemaps?.length) {
503
+ consola.log("");
504
+ consola.info(colors.bold("Sitemaps:"));
505
+ for (const s of res.sitemaps) {
506
+ const err = s.errorCount > 0 ? colors.red(` (${s.errorCount} errors)`) : "";
507
+ consola.info(` ${s.name}: ${colors.cyan(s.urlCount?.toString() || "0")} URLs${err}`);
508
+ }
509
+ }
510
+ }
511
+ }),
512
+ poll: () => defineCommand({
513
+ meta: {
514
+ name: "poll",
515
+ description: "Trigger page indexing"
516
+ },
517
+ args: {
518
+ url: {
519
+ type: "string",
520
+ alias: "u",
521
+ description: "Site URL (default: http://localhost:3000)",
522
+ default: "http://localhost:3000"
523
+ },
524
+ limit: {
525
+ type: "string",
526
+ alias: "l",
527
+ description: "Max pages to process",
528
+ default: "10"
529
+ },
530
+ all: {
531
+ type: "boolean",
532
+ alias: "a",
533
+ description: "Process all pending pages"
534
+ },
535
+ cwd: {
536
+ type: "string",
537
+ description: "Working directory",
538
+ default: "."
539
+ }
540
+ },
541
+ async run({ args }) {
542
+ const secret = await requireSecret(resolve(args.cwd || "."));
543
+ if (!secret) return;
544
+ const params = new URLSearchParams();
545
+ if (args.all) params.set("all", "true");
546
+ else params.set("limit", args.limit || "10");
547
+ const url = joinURL(args.url, `/__ai-ready/poll?${params}`);
548
+ consola.info(`Triggering poll at ${args.url}...`);
549
+ const res = await fetchJson(url, {
550
+ method: "POST",
551
+ headers: authHeaders(secret)
552
+ });
553
+ consola.success(`Indexed: ${colors.green(res.indexed?.toString() || "0")} pages`);
554
+ consola.info(`Remaining: ${colors.yellow(res.remaining?.toString() || "0")}`);
555
+ if (res.errors?.length) consola.warn(`Errors: ${res.errors.length}`);
556
+ if (res.duration) consola.info(`Duration: ${colors.dim(`${res.duration}ms`)}`);
557
+ }
558
+ }),
559
+ restore: () => defineCommand({
560
+ meta: {
561
+ name: "restore",
562
+ description: "Restore database from prerendered dump"
563
+ },
564
+ args: {
565
+ url: {
566
+ type: "string",
567
+ alias: "u",
568
+ description: "Site URL (default: http://localhost:3000)",
569
+ default: "http://localhost:3000"
570
+ },
571
+ clear: {
572
+ type: "boolean",
573
+ description: "Clear existing pages first",
574
+ default: true,
575
+ negativeDescription: "Restore without clearing existing pages"
576
+ },
577
+ cwd: {
578
+ type: "string",
579
+ description: "Working directory",
580
+ default: "."
581
+ }
582
+ },
583
+ async run({ args }) {
584
+ const secret = await requireSecret(resolve(args.cwd || "."));
585
+ if (!secret) return;
586
+ const params = new URLSearchParams();
587
+ if (!args.clear) params.set("clear", "false");
588
+ const url = joinURL(args.url, `/__ai-ready/restore?${params}`);
589
+ consola.info(`Restoring database at ${args.url}...`);
590
+ const res = await fetchJson(url, {
591
+ method: "POST",
592
+ headers: authHeaders(secret)
593
+ });
594
+ consola.success(`Restored: ${colors.green(res.restored?.toString() || "0")} pages`);
595
+ if (res.cleared) consola.info(`Cleared: ${colors.yellow(res.cleared?.toString() || "0")} existing pages`);
596
+ }
597
+ }),
598
+ prune: () => defineCommand({
599
+ meta: {
600
+ name: "prune",
601
+ description: "Remove stale routes from database"
602
+ },
603
+ args: {
604
+ url: {
605
+ type: "string",
606
+ alias: "u",
607
+ description: "Site URL (default: http://localhost:3000)",
608
+ default: "http://localhost:3000"
609
+ },
610
+ dry: {
611
+ type: "boolean",
612
+ alias: "d",
613
+ description: "Preview without deleting"
614
+ },
615
+ ttl: {
616
+ type: "string",
617
+ description: "Override pruneTtl config"
618
+ },
619
+ cwd: {
620
+ type: "string",
621
+ description: "Working directory",
622
+ default: "."
623
+ }
624
+ },
625
+ async run({ args }) {
626
+ const secret = await getSecret(resolve(args.cwd || "."));
627
+ if (!secret && !args.dry) throw new Error(`${APPLICATION_SECRET_ERROR} For development, run nuxt dev to cache the runtime sync token.`);
628
+ const params = new URLSearchParams();
629
+ if (args.dry) params.set("dry", "true");
630
+ if (args.ttl) params.set("ttl", args.ttl);
631
+ const url = joinURL(args.url, `/__ai-ready/prune?${params}`);
632
+ consola.info(`${args.dry ? "Previewing" : "Pruning"} stale routes at ${args.url}...`);
633
+ const res = await fetchJson(url, {
634
+ method: "POST",
635
+ headers: secret ? authHeaders(secret) : void 0
636
+ });
637
+ if (args.dry) {
638
+ consola.info(`Would prune: ${colors.yellow(res.count?.toString() || "0")} routes`);
639
+ if (res.routes?.length) {
640
+ for (const route of res.routes.slice(0, 20)) consola.log(` ${colors.dim("•")} ${route}`);
641
+ if (res.routes.length > 20) consola.log(` ${colors.dim(`... and ${res.routes.length - 20} more`)}`);
642
+ }
643
+ } else consola.success(`Pruned: ${colors.green(res.pruned?.toString() || "0")} routes`);
644
+ }
645
+ }),
646
+ reindex: () => defineCommand({
647
+ meta: {
648
+ name: "reindex",
649
+ description: "Reindex a single route"
650
+ },
651
+ args: {
652
+ route: {
653
+ type: "positional",
654
+ description: "Route to reindex (e.g. /about)",
655
+ required: true
656
+ },
657
+ url: {
658
+ type: "string",
659
+ alias: "u",
660
+ description: "Site URL (default: http://localhost:3000)",
661
+ default: "http://localhost:3000"
662
+ },
663
+ force: {
664
+ type: "boolean",
665
+ description: "Index even when the page is still fresh",
666
+ default: true,
667
+ negativeDescription: "Skip indexing when the page is still fresh"
668
+ },
669
+ cwd: {
670
+ type: "string",
671
+ description: "Working directory",
672
+ default: "."
673
+ }
674
+ },
675
+ async run({ args }) {
676
+ const secret = await requireSecret(resolve(args.cwd || "."));
677
+ if (!secret) return;
678
+ const params = new URLSearchParams();
679
+ params.set("route", args.route);
680
+ if (!args.force) params.set("force", "false");
681
+ const url = joinURL(args.url, `/__ai-ready/reindex?${params}`);
682
+ consola.info(`Reindexing ${args.route} at ${args.url}...`);
683
+ const res = await fetchJson(url, {
684
+ method: "POST",
685
+ headers: authHeaders(secret)
686
+ });
687
+ if (res.indexed) {
688
+ consola.success(`Indexed: ${colors.green(res.route)}`);
689
+ if (res.contentChanged !== void 0) consola.info(`Content changed: ${res.contentChanged ? colors.green("yes") : colors.yellow("no")}`);
690
+ } else if (res.skipped) consola.info(`Skipped: ${colors.yellow(res.route)} (still fresh)`);
691
+ else if (res.gone) consola.success(`Removed: ${colors.green(res.route)} (HTTP 410)`);
692
+ else throw new Error(`Failed to reindex ${res.route ?? args.route}${res.error ? `: ${res.error}` : ""}`);
693
+ }
694
+ })
695
+ }
611
696
  });
612
697
  runMain(main);
698
+ export {};