@eloxiv/cli 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (294) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +12 -2
  3. package/dist/AgentSkills.d.ts +51 -0
  4. package/dist/AgentSkills.d.ts.map +1 -0
  5. package/dist/AgentSkills.js +264 -0
  6. package/dist/AgentSkills.js.map +1 -0
  7. package/dist/AgentWeb.d.ts +83 -0
  8. package/dist/AgentWeb.d.ts.map +1 -0
  9. package/dist/AgentWeb.js +436 -0
  10. package/dist/AgentWeb.js.map +1 -0
  11. package/dist/App.d.ts +213 -0
  12. package/dist/App.d.ts.map +1 -0
  13. package/dist/App.js +357 -0
  14. package/dist/App.js.map +1 -0
  15. package/dist/Blueprint.d.ts +47 -0
  16. package/dist/Blueprint.d.ts.map +1 -0
  17. package/dist/Blueprint.js +241 -0
  18. package/dist/Blueprint.js.map +1 -0
  19. package/dist/Brand.d.ts +42 -0
  20. package/dist/Brand.d.ts.map +1 -0
  21. package/dist/Brand.js +370 -0
  22. package/dist/Brand.js.map +1 -0
  23. package/dist/Changelog.d.ts +22 -0
  24. package/dist/Changelog.d.ts.map +1 -0
  25. package/dist/Changelog.js +117 -0
  26. package/dist/Changelog.js.map +1 -0
  27. package/dist/Cli.d.ts +17 -0
  28. package/dist/Cli.d.ts.map +1 -0
  29. package/dist/Cli.js +810 -0
  30. package/dist/Cli.js.map +1 -0
  31. package/dist/DbAdmin.d.ts +18 -0
  32. package/dist/DbAdmin.d.ts.map +1 -0
  33. package/dist/DbAdmin.js +91 -0
  34. package/dist/DbAdmin.js.map +1 -0
  35. package/dist/Dependencies.d.ts +53 -0
  36. package/dist/Dependencies.d.ts.map +1 -0
  37. package/dist/Dependencies.js +132 -0
  38. package/dist/Dependencies.js.map +1 -0
  39. package/dist/Deploy.d.ts +39 -0
  40. package/dist/Deploy.d.ts.map +1 -0
  41. package/dist/Deploy.js +458 -0
  42. package/dist/Deploy.js.map +1 -0
  43. package/dist/Docs.d.ts +71 -0
  44. package/dist/Docs.d.ts.map +1 -0
  45. package/dist/Docs.js +240 -0
  46. package/dist/Docs.js.map +1 -0
  47. package/dist/Doctor.d.ts +56 -0
  48. package/dist/Doctor.d.ts.map +1 -0
  49. package/dist/Doctor.js +368 -0
  50. package/dist/Doctor.js.map +1 -0
  51. package/dist/Dossier.d.ts +23 -0
  52. package/dist/Dossier.d.ts.map +1 -0
  53. package/dist/Dossier.js +92 -0
  54. package/dist/Dossier.js.map +1 -0
  55. package/dist/Emit.d.ts +26 -0
  56. package/dist/Emit.d.ts.map +1 -0
  57. package/dist/Emit.js +51 -0
  58. package/dist/Emit.js.map +1 -0
  59. package/dist/Errors.d.ts +26 -0
  60. package/dist/Errors.d.ts.map +1 -0
  61. package/dist/Errors.js +17 -0
  62. package/dist/Errors.js.map +1 -0
  63. package/dist/Evals.d.ts +52 -0
  64. package/dist/Evals.d.ts.map +1 -0
  65. package/dist/Evals.js +126 -0
  66. package/dist/Evals.js.map +1 -0
  67. package/dist/Files.d.ts +47 -0
  68. package/dist/Files.d.ts.map +1 -0
  69. package/dist/Files.js +145 -0
  70. package/dist/Files.js.map +1 -0
  71. package/dist/Generate.d.ts +80 -0
  72. package/dist/Generate.d.ts.map +1 -0
  73. package/dist/Generate.js +310 -0
  74. package/dist/Generate.js.map +1 -0
  75. package/dist/Guards.d.ts +45 -0
  76. package/dist/Guards.d.ts.map +1 -0
  77. package/dist/Guards.js +530 -0
  78. package/dist/Guards.js.map +1 -0
  79. package/dist/Inspect.d.ts +125 -0
  80. package/dist/Inspect.d.ts.map +1 -0
  81. package/dist/Inspect.js +270 -0
  82. package/dist/Inspect.js.map +1 -0
  83. package/dist/Keychain.d.ts +57 -0
  84. package/dist/Keychain.d.ts.map +1 -0
  85. package/dist/Keychain.js +73 -0
  86. package/dist/Keychain.js.map +1 -0
  87. package/dist/Lock.d.ts +13 -0
  88. package/dist/Lock.d.ts.map +1 -0
  89. package/dist/Lock.js +145 -0
  90. package/dist/Lock.js.map +1 -0
  91. package/dist/Mcp.d.ts +91 -0
  92. package/dist/Mcp.d.ts.map +1 -0
  93. package/dist/Mcp.js +128 -0
  94. package/dist/Mcp.js.map +1 -0
  95. package/dist/Merge.d.ts +18 -0
  96. package/dist/Merge.d.ts.map +1 -0
  97. package/dist/Merge.js +43 -0
  98. package/dist/Merge.js.map +1 -0
  99. package/dist/Migrate.d.ts +78 -0
  100. package/dist/Migrate.d.ts.map +1 -0
  101. package/dist/Migrate.js +288 -0
  102. package/dist/Migrate.js.map +1 -0
  103. package/dist/Plugins.d.ts +36 -0
  104. package/dist/Plugins.d.ts.map +1 -0
  105. package/dist/Plugins.js +304 -0
  106. package/dist/Plugins.js.map +1 -0
  107. package/dist/Postgres.d.ts +73 -0
  108. package/dist/Postgres.d.ts.map +1 -0
  109. package/dist/Postgres.js +294 -0
  110. package/dist/Postgres.js.map +1 -0
  111. package/dist/Publish.d.ts +23 -0
  112. package/dist/Publish.d.ts.map +1 -0
  113. package/dist/Publish.js +59 -0
  114. package/dist/Publish.js.map +1 -0
  115. package/dist/Registry.d.ts +539 -0
  116. package/dist/Registry.d.ts.map +1 -0
  117. package/dist/Registry.js +340 -0
  118. package/dist/Registry.js.map +1 -0
  119. package/dist/Remote.d.ts +90 -0
  120. package/dist/Remote.d.ts.map +1 -0
  121. package/dist/Remote.js +1006 -0
  122. package/dist/Remote.js.map +1 -0
  123. package/dist/Run.d.ts +120 -0
  124. package/dist/Run.d.ts.map +1 -0
  125. package/dist/Run.js +477 -0
  126. package/dist/Run.js.map +1 -0
  127. package/dist/SyncGen.d.ts +118 -0
  128. package/dist/SyncGen.d.ts.map +1 -0
  129. package/dist/SyncGen.js +392 -0
  130. package/dist/SyncGen.js.map +1 -0
  131. package/dist/Update.d.ts +301 -0
  132. package/dist/Update.d.ts.map +1 -0
  133. package/dist/Update.js +627 -0
  134. package/dist/Update.js.map +1 -0
  135. package/dist/bin.d.ts +3 -0
  136. package/dist/bin.d.ts.map +1 -0
  137. package/dist/bin.js +42 -0
  138. package/dist/bin.js.map +1 -0
  139. package/dist/docs/backlog.md +56 -0
  140. package/dist/docs/ci.md +277 -0
  141. package/dist/docs/cli.md +696 -0
  142. package/dist/docs/connectors/google.md +115 -0
  143. package/dist/docs/connectors/http-openapi.md +7 -0
  144. package/dist/docs/connectors/mcp.md +8 -0
  145. package/dist/docs/connectors/microsoft-graph.md +75 -0
  146. package/dist/docs/connectors/openai.md +25 -0
  147. package/dist/docs/connectors/slack.md +162 -0
  148. package/dist/docs/connectors/workos.md +39 -0
  149. package/dist/docs/contracts/README.md +173 -0
  150. package/dist/docs/contracts/action-consent.md +92 -0
  151. package/dist/docs/contracts/action-registry.md +85 -0
  152. package/dist/docs/contracts/actor.md +100 -0
  153. package/dist/docs/contracts/agent-resources.md +90 -0
  154. package/dist/docs/contracts/agent-runtime.md +257 -0
  155. package/dist/docs/contracts/approvals.md +126 -0
  156. package/dist/docs/contracts/audit.md +75 -0
  157. package/dist/docs/contracts/auth-provider.md +74 -0
  158. package/dist/docs/contracts/calendar-provider.md +46 -0
  159. package/dist/docs/contracts/client-sdk.md +245 -0
  160. package/dist/docs/contracts/collab-document.md +151 -0
  161. package/dist/docs/contracts/command.md +44 -0
  162. package/dist/docs/contracts/connections.md +235 -0
  163. package/dist/docs/contracts/context-accounting.md +50 -0
  164. package/dist/docs/contracts/daemon.md +243 -0
  165. package/dist/docs/contracts/db-tx.md +53 -0
  166. package/dist/docs/contracts/delegation.md +68 -0
  167. package/dist/docs/contracts/device-control.md +103 -0
  168. package/dist/docs/contracts/directory-provider.md +36 -0
  169. package/dist/docs/contracts/directory.md +161 -0
  170. package/dist/docs/contracts/document-source.md +33 -0
  171. package/dist/docs/contracts/files.md +115 -0
  172. package/dist/docs/contracts/flags.md +83 -0
  173. package/dist/docs/contracts/host.md +68 -0
  174. package/dist/docs/contracts/http-api.md +43 -0
  175. package/dist/docs/contracts/ingestion.md +130 -0
  176. package/dist/docs/contracts/ingress.md +141 -0
  177. package/dist/docs/contracts/invocation.md +260 -0
  178. package/dist/docs/contracts/local-client.md +108 -0
  179. package/dist/docs/contracts/locale.md +56 -0
  180. package/dist/docs/contracts/machine-identity.md +117 -0
  181. package/dist/docs/contracts/mail-provider.md +49 -0
  182. package/dist/docs/contracts/memory.md +53 -0
  183. package/dist/docs/contracts/messaging.md +40 -0
  184. package/dist/docs/contracts/metering.md +139 -0
  185. package/dist/docs/contracts/model-provider.md +84 -0
  186. package/dist/docs/contracts/module-manifest.md +213 -0
  187. package/dist/docs/contracts/notification-channel.md +90 -0
  188. package/dist/docs/contracts/notifications.md +123 -0
  189. package/dist/docs/contracts/outbox.md +80 -0
  190. package/dist/docs/contracts/privacy.md +110 -0
  191. package/dist/docs/contracts/progress.md +52 -0
  192. package/dist/docs/contracts/query-surface.md +108 -0
  193. package/dist/docs/contracts/readiness.md +63 -0
  194. package/dist/docs/contracts/release.md +142 -0
  195. package/dist/docs/contracts/result-rendering.md +61 -0
  196. package/dist/docs/contracts/sandbox.md +186 -0
  197. package/dist/docs/contracts/scheduler.md +148 -0
  198. package/dist/docs/contracts/screen-context.md +81 -0
  199. package/dist/docs/contracts/search.md +120 -0
  200. package/dist/docs/contracts/secrets.md +74 -0
  201. package/dist/docs/contracts/settings.md +109 -0
  202. package/dist/docs/contracts/sharing.md +77 -0
  203. package/dist/docs/contracts/slot.md +48 -0
  204. package/dist/docs/contracts/space.md +67 -0
  205. package/dist/docs/contracts/storage-adapter.md +45 -0
  206. package/dist/docs/contracts/storage-backend.md +56 -0
  207. package/dist/docs/contracts/sync.md +213 -0
  208. package/dist/docs/contracts/telemetry.md +80 -0
  209. package/dist/docs/contracts/theme-tokens.md +50 -0
  210. package/dist/docs/contracts/tool-source.md +58 -0
  211. package/dist/docs/contracts/versioning.md +99 -0
  212. package/dist/docs/contracts/view.md +65 -0
  213. package/dist/docs/contracts/work-items.md +99 -0
  214. package/dist/docs/contracts/workflow.md +82 -0
  215. package/dist/docs/decisions.md +163 -0
  216. package/dist/docs/example-app.md +192 -0
  217. package/dist/docs/getting-started.md +927 -0
  218. package/dist/docs/goal.md +54 -0
  219. package/dist/docs/parity.md +29 -0
  220. package/dist/docs/performance.md +129 -0
  221. package/dist/docs/registry/README.md +74 -0
  222. package/dist/docs/registry/app.md +38 -0
  223. package/dist/docs/registry/approvals-ui-foldkit.md +28 -0
  224. package/dist/docs/registry/calendar-ui-foldkit.md +27 -0
  225. package/dist/docs/registry/calendar.md +35 -0
  226. package/dist/docs/registry/chat-ui-foldkit.md +30 -0
  227. package/dist/docs/registry/desktop-rune.md +49 -0
  228. package/dist/docs/registry/desktop.md +32 -0
  229. package/dist/docs/registry/eloxiv-action.md +25 -0
  230. package/dist/docs/registry/eloxiv-connector.md +25 -0
  231. package/dist/docs/registry/eloxiv-module.md +25 -0
  232. package/dist/docs/registry/eloxiv-policy.md +25 -0
  233. package/dist/docs/registry/eloxiv-view.md +25 -0
  234. package/dist/docs/registry/hello-ui-foldkit.md +29 -0
  235. package/dist/docs/registry/hello.md +39 -0
  236. package/dist/docs/registry/home-ui-foldkit.md +27 -0
  237. package/dist/docs/registry/home.md +29 -0
  238. package/dist/docs/registry/inbox-ui-foldkit.md +27 -0
  239. package/dist/docs/registry/mail-ui-foldkit.md +27 -0
  240. package/dist/docs/registry/mail.md +34 -0
  241. package/dist/docs/registry/meeting-prep.md +26 -0
  242. package/dist/docs/registry/members-ui-foldkit.md +28 -0
  243. package/dist/docs/registry/mobile.md +37 -0
  244. package/dist/docs/registry/notes-ui-foldkit.md +27 -0
  245. package/dist/docs/registry/notes.md +26 -0
  246. package/dist/docs/registry/people-ui-foldkit.md +28 -0
  247. package/dist/docs/registry/people.md +38 -0
  248. package/dist/docs/registry/shell-foldkit.md +34 -0
  249. package/dist/docs/registry/theme.md +25 -0
  250. package/dist/docs/registry/ui-conformance.md +30 -0
  251. package/dist/docs/release.md +100 -0
  252. package/dist/docs/scaffold.md +826 -0
  253. package/dist/docs/security/threat-model.md +299 -0
  254. package/dist/docs/upstream/zero-cache-socket-handoff.md +105 -0
  255. package/dist/index.d.ts +8 -0
  256. package/dist/index.d.ts.map +1 -0
  257. package/dist/index.js +8 -0
  258. package/dist/index.js.map +1 -0
  259. package/package.json +48 -3
  260. package/src/AgentSkills.ts +329 -0
  261. package/src/AgentWeb.ts +507 -0
  262. package/src/App.ts +435 -0
  263. package/src/Blueprint.ts +276 -0
  264. package/src/Brand.ts +415 -0
  265. package/src/Changelog.ts +136 -0
  266. package/src/Cli.ts +1458 -0
  267. package/src/DbAdmin.ts +115 -0
  268. package/src/Dependencies.ts +170 -0
  269. package/src/Deploy.ts +563 -0
  270. package/src/Docs.ts +309 -0
  271. package/src/Doctor.ts +424 -0
  272. package/src/Dossier.ts +148 -0
  273. package/src/Emit.ts +68 -0
  274. package/src/Errors.ts +18 -0
  275. package/src/Evals.ts +153 -0
  276. package/src/Files.ts +152 -0
  277. package/src/Generate.ts +402 -0
  278. package/src/Guards.ts +541 -0
  279. package/src/Inspect.ts +358 -0
  280. package/src/Keychain.ts +107 -0
  281. package/src/Lock.ts +174 -0
  282. package/src/Mcp.ts +159 -0
  283. package/src/Merge.ts +70 -0
  284. package/src/Migrate.ts +331 -0
  285. package/src/Plugins.ts +347 -0
  286. package/src/Postgres.ts +353 -0
  287. package/src/Publish.ts +64 -0
  288. package/src/Registry.ts +405 -0
  289. package/src/Remote.ts +1158 -0
  290. package/src/Run.ts +541 -0
  291. package/src/SyncGen.ts +570 -0
  292. package/src/Update.ts +873 -0
  293. package/src/bin.ts +46 -0
  294. package/src/index.ts +7 -0
@@ -0,0 +1,507 @@
1
+ /**
2
+ * Public agent-readable web surfaces (docs/cli.md, "agent-web"):
3
+ *
4
+ * eloxiv agent-web generate [--config agent-web.json] [--out <dir>] [--dry-run]
5
+ * robots.txt (crawler rules), sitemap.xml with a sitemap per page group, llms.txt, a Markdown mirror per page
6
+ * and each page's JSON-LD, from the app's own config, written into the shell's public directory
7
+ * eloxiv agent-web audit <url> [--config agent-web.json]
8
+ * a deployed site checked: the files above served and consistent, pages answering, JSON-LD parseable, and the
9
+ * kernel's MCP endpoint refusing a tool listing without credentials unless tools are declared public
10
+ *
11
+ * A public page never implies public tool access. The kernel serves MCP only to signed-in clients (MachineIdentity's
12
+ * OAuth); llms.txt says so, and lists a tool as public only when the config names it in `publicTools`, which the
13
+ * audit then holds the deployment to (an anonymous listing must offer exactly those, and a deployment that offers
14
+ * tools nobody declared fails). Areas that are the app, not its public pages (`/api/`, `/mcp`, `/auth/`, `/oauth/`,
15
+ * `/rpc`, `/zero/`, `/connections/`, `/ingress/`), are always disallowed to crawlers.
16
+ */
17
+ import { Schema } from "effect"
18
+ import { existsSync, readFileSync } from "node:fs"
19
+ import { join } from "node:path"
20
+ import { CliError } from "./Errors.ts"
21
+
22
+ export const AgentWebPage = Schema.Struct({
23
+ /** The page's path on the site (`/`, `/pricing`). */
24
+ path: Schema.String,
25
+ title: Schema.String,
26
+ description: Schema.String,
27
+ /** The page's content as Markdown: a file of the app (relative to it) mirrored at `<path>.md`. */
28
+ markdown: Schema.optional(Schema.String),
29
+ /** The sitemap it is listed in (default `pages`). */
30
+ group: Schema.optional(Schema.String),
31
+ /** schema.org type for its JSON-LD (default `WebPage`). */
32
+ type: Schema.optional(Schema.String),
33
+ lastModified: Schema.optional(Schema.String),
34
+ })
35
+
36
+ export const AgentWebConfig = Schema.Struct({
37
+ /** The public site's origin, `https://...`. */
38
+ site: Schema.String,
39
+ name: Schema.String,
40
+ description: Schema.String,
41
+ /** The kernel's public URL, where `/mcp` is (default: the site). */
42
+ kernel: Schema.optional(Schema.String),
43
+ pages: Schema.Array(AgentWebPage),
44
+ crawlers: Schema.optional(
45
+ Schema.Struct({
46
+ /** Extra paths crawlers must not visit (the app's own areas are always disallowed). */
47
+ disallow: Schema.optional(Schema.Array(Schema.String)),
48
+ /** Whether AI training crawlers (GPTBot, Google-Extended, CCBot, ...) may read the pages (default false). */
49
+ aiTraining: Schema.optional(Schema.Boolean),
50
+ }),
51
+ ),
52
+ /** MCP tools the kernel serves without credentials, by tool name. Empty: none (the default). */
53
+ publicTools: Schema.optional(Schema.Array(Schema.String)),
54
+ })
55
+ export type AgentWebConfig = typeof AgentWebConfig.Type
56
+
57
+ /** The app's own areas: never for crawlers. */
58
+ export const APP_AREAS = ["/api/", "/mcp", "/auth/", "/oauth/", "/rpc", "/zero/", "/connections/", "/ingress/"]
59
+ /** Crawlers that gather training data, refused unless `crawlers.aiTraining`. */
60
+ export const TRAINING_CRAWLERS = [
61
+ "GPTBot",
62
+ "Google-Extended",
63
+ "CCBot",
64
+ "anthropic-ai",
65
+ "ClaudeBot",
66
+ "Applebot-Extended",
67
+ "Bytespider",
68
+ "meta-externalagent",
69
+ ]
70
+
71
+ export const readAgentWebConfig = (dir: string, file = "agent-web.json"): AgentWebConfig => {
72
+ const path = join(dir, file)
73
+ if (!existsSync(path))
74
+ throw new CliError({ message: `${path} does not exist: write the site's pages there (docs/cli.md, "agent-web")` })
75
+ let config: AgentWebConfig
76
+ try {
77
+ config = Schema.decodeUnknownSync(AgentWebConfig)(JSON.parse(readFileSync(path, "utf8")))
78
+ } catch (e) {
79
+ throw new CliError({
80
+ message: `${file} is not a valid agent-web config: ${e instanceof Error ? e.message : String(e)}`,
81
+ })
82
+ }
83
+ const site = new URL(config.site)
84
+ if (site.protocol !== "https:" && site.hostname !== "localhost" && site.hostname !== "127.0.0.1") {
85
+ throw new CliError({ message: `site must be https (got ${config.site})` })
86
+ }
87
+ for (const page of config.pages) {
88
+ if (!page.path.startsWith("/") || page.path.includes("..") || /[?#\s]/.test(page.path)) {
89
+ throw new CliError({ message: `A page path is an absolute path without query or fragment (got ${page.path})` })
90
+ }
91
+ if (APP_AREAS.some((area) => page.path.startsWith(area))) {
92
+ throw new CliError({
93
+ message: `${page.path} is in the app's own area (${APP_AREAS.join(", ")}), not a public page`,
94
+ })
95
+ }
96
+ }
97
+ return config
98
+ }
99
+
100
+ const xml = (text: string) =>
101
+ text.replace(/[<>&'"]/g, (c) => ({ "<": "&lt;", ">": "&gt;", "&": "&amp;", "'": "&apos;", '"': "&quot;" })[c]!)
102
+ const origin = (config: AgentWebConfig) => new URL(config.site).origin
103
+ const urlOf = (config: AgentWebConfig, path: string) => `${origin(config)}${path}`
104
+ /** Where a page's Markdown mirror is served: `/index.md` for `/`, `/pricing.md` for `/pricing`. */
105
+ export const mirrorPath = (path: string) => (path === "/" ? "/index.md" : `${path.replace(/\/$/, "")}.md`)
106
+ const slug = (path: string) => (path === "/" ? "index" : path.replace(/^\/|\/$/g, "").replace(/[^a-zA-Z0-9-]+/g, "-"))
107
+ const groups = (config: AgentWebConfig) => [...new Set(config.pages.map((p) => p.group ?? "pages"))]
108
+
109
+ /** The files `generate` writes (relative to the output directory), from `config` and the app's Markdown files. */
110
+ export const agentWebFiles = (
111
+ dir: string,
112
+ config: AgentWebConfig,
113
+ ): ReadonlyArray<{ readonly path: string; readonly content: string }> => {
114
+ const files: Array<{ path: string; content: string }> = []
115
+ const aiTraining = config.crawlers?.aiTraining === true
116
+ const disallow = [...APP_AREAS, ...(config.crawlers?.disallow ?? [])]
117
+ files.push({
118
+ path: "robots.txt",
119
+ content: [
120
+ "# Generated by eloxiv agent-web generate. Public pages only: the app's own areas are never crawled.",
121
+ ...(aiTraining ? [] : TRAINING_CRAWLERS.flatMap((agent) => [`User-agent: ${agent}`, "Disallow: /", ""])),
122
+ "User-agent: *",
123
+ ...disallow.map((path) => `Disallow: ${path}`),
124
+ "Allow: /",
125
+ "",
126
+ `Sitemap: ${urlOf(config, "/sitemap.xml")}`,
127
+ "",
128
+ ].join("\n"),
129
+ })
130
+ files.push({
131
+ path: "sitemap.xml",
132
+ content: [
133
+ `<?xml version="1.0" encoding="UTF-8"?>`,
134
+ `<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`,
135
+ ...groups(config).map(
136
+ (g) => ` <sitemap><loc>${xml(urlOf(config, `/sitemap-${slug(`/${g}`)}.xml`))}</loc></sitemap>`,
137
+ ),
138
+ `</sitemapindex>`,
139
+ "",
140
+ ].join("\n"),
141
+ })
142
+ for (const group of groups(config)) {
143
+ files.push({
144
+ path: `sitemap-${slug(`/${group}`)}.xml`,
145
+ content: [
146
+ `<?xml version="1.0" encoding="UTF-8"?>`,
147
+ `<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">`,
148
+ ...config.pages
149
+ .filter((p) => (p.group ?? "pages") === group)
150
+ .map(
151
+ (p) =>
152
+ ` <url><loc>${xml(urlOf(config, p.path))}</loc>${p.lastModified === undefined ? "" : `<lastmod>${xml(p.lastModified)}</lastmod>`}</url>`,
153
+ ),
154
+ `</urlset>`,
155
+ "",
156
+ ].join("\n"),
157
+ })
158
+ }
159
+ const publicTools = config.publicTools ?? []
160
+ const kernel = config.kernel ?? config.site
161
+ files.push({
162
+ path: "llms.txt",
163
+ content: [
164
+ `# ${config.name}`,
165
+ "",
166
+ `> ${config.description}`,
167
+ "",
168
+ "## Pages",
169
+ "",
170
+ ...config.pages.map(
171
+ (p) =>
172
+ `- [${p.title}](${urlOf(config, p.markdown === undefined ? p.path : mirrorPath(p.path))}): ${p.description}`,
173
+ ),
174
+ "",
175
+ "## Tools",
176
+ "",
177
+ `The app's actions are MCP tools at ${new URL("/mcp", kernel).href}, for signed-in clients only (OAuth 2.1 with the authorisation server its protected-resource metadata names). Reading these pages grants no access to them.`,
178
+ ...(publicTools.length === 0
179
+ ? ["", "No tool is public."]
180
+ : ["", "Public tools (no sign-in):", "", ...publicTools.map((tool) => `- ${tool}`)]),
181
+ "",
182
+ ].join("\n"),
183
+ })
184
+ for (const page of config.pages) {
185
+ if (page.markdown !== undefined) {
186
+ const source = join(dir, page.markdown)
187
+ if (!existsSync(source))
188
+ throw new CliError({ message: `${page.path}'s Markdown ${page.markdown} does not exist` })
189
+ files.push({ path: mirrorPath(page.path).slice(1), content: readFileSync(source, "utf8") })
190
+ }
191
+ files.push({
192
+ path: `jsonld/${slug(page.path)}.json`,
193
+ content: `${JSON.stringify(
194
+ {
195
+ "@context": "https://schema.org",
196
+ "@type": page.type ?? "WebPage",
197
+ name: page.title,
198
+ description: page.description,
199
+ url: urlOf(config, page.path),
200
+ isPartOf: { "@type": "WebSite", name: config.name, url: origin(config) },
201
+ ...(page.lastModified === undefined ? {} : { dateModified: page.lastModified }),
202
+ },
203
+ null,
204
+ 2,
205
+ )}\n`,
206
+ })
207
+ }
208
+ return files
209
+ }
210
+
211
+ export interface AuditCheck {
212
+ readonly id: string
213
+ readonly status: "pass" | "warn" | "fail"
214
+ readonly detail: string
215
+ }
216
+
217
+ const MAX_BYTES = 1024 * 1024
218
+ const MAX_PAGES = 50
219
+
220
+ /** GET `url` with a timeout and a size bound; never follows a redirect off the site's origin. */
221
+ const get = async (url: string, allowedOrigins: ReadonlyArray<string>, init: RequestInit = {}) => {
222
+ let current = url
223
+ for (let hop = 0; hop < 5; hop++) {
224
+ if (!allowedOrigins.includes(new URL(current).origin))
225
+ throw new Error(`refused to leave the site for ${new URL(current).origin}`)
226
+ const response = await fetch(current, { ...init, redirect: "manual", signal: AbortSignal.timeout(10_000) })
227
+ const location = response.headers.get("location")
228
+ if (response.status >= 300 && response.status < 400 && location !== null) {
229
+ await response.body?.cancel()
230
+ current = new URL(location, current).href
231
+ continue
232
+ }
233
+ const reader = response.body?.getReader()
234
+ const chunks: Array<Uint8Array> = []
235
+ let size = 0
236
+ if (reader !== undefined) {
237
+ for (;;) {
238
+ const { done, value } = await reader.read()
239
+ if (done) break
240
+ size += value.length
241
+ if (size > MAX_BYTES) {
242
+ await reader.cancel()
243
+ throw new Error(`${current} is larger than ${MAX_BYTES} bytes`)
244
+ }
245
+ chunks.push(value)
246
+ }
247
+ }
248
+ return { status: response.status, headers: response.headers, text: new TextDecoder().decode(Buffer.concat(chunks)) }
249
+ }
250
+ throw new Error(`${url} redirects too often`)
251
+ }
252
+
253
+ type ToolListing =
254
+ | { readonly kind: "refused" | "absent" | "error"; readonly detail: string }
255
+ | { readonly kind: "listed"; readonly names: ReadonlyArray<string> }
256
+
257
+ /** The JSON-RPC messages of an MCP answer: a JSON body (one message or a batch) or a server-sent event stream. */
258
+ const messagesOf = (answer: {
259
+ readonly headers: Headers
260
+ readonly text: string
261
+ }): ReadonlyArray<Record<string, unknown>> => {
262
+ const bodies = (answer.headers.get("content-type") ?? "").includes("text/event-stream")
263
+ ? answer.text
264
+ .split(/\r?\n\r?\n/u)
265
+ .map((block) =>
266
+ block
267
+ .split(/\r?\n/u)
268
+ .filter((l) => l.startsWith("data:"))
269
+ .map((l) => l.slice(5).trimStart())
270
+ .join("\n"),
271
+ )
272
+ .filter((data) => data !== "")
273
+ : [answer.text]
274
+ return bodies.flatMap((body) => {
275
+ try {
276
+ const value = JSON.parse(body) as unknown
277
+ return (Array.isArray(value) ? value : [value]).filter(
278
+ (m): m is Record<string, unknown> => m !== null && typeof m === "object",
279
+ )
280
+ } catch {
281
+ return []
282
+ }
283
+ })
284
+ }
285
+
286
+ /**
287
+ * What the MCP endpoint at `endpoint` lists to a client with no credential, as an MCP client must ask: `initialize`,
288
+ * `notifications/initialized`, then `tools/list` in the session it opened. A refusal (401, 403) is `refused`; no
289
+ * endpoint (404, unreachable) `absent`; anything that is not a successful listing (another status, a JSON-RPC error
290
+ * such as a missing session, no `result.tools`) is an `error`, never an empty list.
291
+ */
292
+ const anonymousTools = async (endpoint: string, origins: ReadonlyArray<string>): Promise<ToolListing> => {
293
+ let session: string | undefined
294
+ const post = (message: Record<string, unknown>) =>
295
+ get(endpoint, origins, {
296
+ method: "POST",
297
+ headers: {
298
+ "content-type": "application/json",
299
+ accept: "application/json, text/event-stream",
300
+ "mcp-protocol-version": "2025-06-18",
301
+ ...(session === undefined ? {} : { "mcp-session-id": session }),
302
+ },
303
+ body: JSON.stringify({ jsonrpc: "2.0", ...message }),
304
+ }).catch((e: Error) => ({ status: 0, headers: new Headers(), text: e.message }))
305
+ const refusal = (answer: {
306
+ readonly status: number
307
+ readonly headers: Headers
308
+ readonly text: string
309
+ }): ToolListing | undefined =>
310
+ answer.status === 401 || answer.status === 403
311
+ ? {
312
+ kind: "refused",
313
+ detail: `${answer.status}${answer.headers.get("www-authenticate") === null ? "" : ", with WWW-Authenticate"}`,
314
+ }
315
+ : answer.status === 0 || answer.status === 404
316
+ ? { kind: "absent", detail: String(answer.status || answer.text) }
317
+ : undefined
318
+ const result = (
319
+ answer: { readonly status: number; readonly headers: Headers; readonly text: string },
320
+ id: number,
321
+ what: string,
322
+ ) => {
323
+ if (answer.status < 200 || answer.status >= 300)
324
+ return { error: `${what} answered ${answer.status}: ${answer.text.slice(0, 200)}` }
325
+ const reply = messagesOf(answer).find((m) => m["id"] === id)
326
+ if (reply === undefined) return { error: `${what} gave no answer to its request` }
327
+ if (reply["error"] !== undefined)
328
+ return { error: `${what} failed: ${JSON.stringify(reply["error"]).slice(0, 200)}` }
329
+ return { value: reply["result"] }
330
+ }
331
+ const initialized = await post({
332
+ id: 1,
333
+ method: "initialize",
334
+ params: {
335
+ protocolVersion: "2025-06-18",
336
+ capabilities: {},
337
+ clientInfo: { name: "eloxiv-agent-web-audit", version: "1" },
338
+ },
339
+ })
340
+ const early = refusal(initialized)
341
+ if (early !== undefined) return early
342
+ const started = result(initialized, 1, "initialize")
343
+ if ("error" in started) return { kind: "error", detail: started.error }
344
+ session = initialized.headers.get("mcp-session-id") ?? undefined
345
+ const notified = await post({ method: "notifications/initialized" })
346
+ const notRefused = refusal(notified)
347
+ if (notRefused !== undefined) return notRefused
348
+ const listed = await post({ id: 2, method: "tools/list", params: {} })
349
+ const late = refusal(listed)
350
+ if (late !== undefined) return late
351
+ const list = result(listed, 2, "tools/list")
352
+ if ("error" in list) return { kind: "error", detail: list.error }
353
+ const toolsValue = (list.value as { tools?: unknown } | undefined)?.tools
354
+ if (!Array.isArray(toolsValue)) return { kind: "error", detail: "tools/list's result has no tools" }
355
+ return {
356
+ kind: "listed",
357
+ names: toolsValue.flatMap((t) =>
358
+ t !== null && typeof t === "object" && typeof (t as { name?: unknown }).name === "string"
359
+ ? [(t as { name: string }).name]
360
+ : [],
361
+ ),
362
+ }
363
+ }
364
+
365
+ /**
366
+ * Audit the deployed site at `url` (its origin), and the kernel's MCP endpoint (`config.kernel`, else the site).
367
+ * Fetches only the site's and the kernel's origins, at most MAX_PAGES pages, each bounded in time and size.
368
+ */
369
+ export const auditAgentWeb = async (url: string, config?: AgentWebConfig): Promise<ReadonlyArray<AuditCheck>> => {
370
+ const site = new URL(url).origin
371
+ const kernel = new URL(config?.kernel ?? site).origin
372
+ const origins = [...new Set([site, kernel])]
373
+ const checks: Array<AuditCheck> = []
374
+ const add = (id: string, status: AuditCheck["status"], detail: string) => checks.push({ id, status, detail })
375
+ const fetchText = (path: string) =>
376
+ get(new URL(path, site).href, origins).catch((e: Error) => ({ status: 0, headers: new Headers(), text: e.message }))
377
+
378
+ const robots = await fetchText("/robots.txt")
379
+ if (robots.status !== 200) add("robots.txt", "fail", `answered ${robots.status || robots.text}`)
380
+ else {
381
+ const disallowed = new Set(
382
+ robots.text
383
+ .split("\n")
384
+ .filter((l) => /^disallow:/i.test(l.trim()))
385
+ .map((l) => l.split(":").slice(1).join(":").trim()),
386
+ )
387
+ const open = APP_AREAS.filter((area) => !disallowed.has(area))
388
+ add(
389
+ "robots.txt",
390
+ open.length === 0 ? "pass" : "fail",
391
+ open.length === 0 ? "the app's areas are disallowed" : `does not disallow ${open.join(", ")}`,
392
+ )
393
+ add(
394
+ "sitemap reference",
395
+ /^sitemap:/im.test(robots.text) ? "pass" : "warn",
396
+ /^sitemap:/im.test(robots.text) ? "robots.txt names the sitemap" : "robots.txt names no sitemap",
397
+ )
398
+ }
399
+
400
+ const index = await fetchText("/sitemap.xml")
401
+ const pageUrls: Array<string> = []
402
+ if (index.status !== 200) add("sitemap.xml", "fail", `answered ${index.status || index.text}`)
403
+ else {
404
+ const locs = [...index.text.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1]!.replace(/&amp;/g, "&"))
405
+ const isIndex = /<sitemapindex/.test(index.text)
406
+ const offsite = locs.filter((l) => new URL(l).origin !== site)
407
+ if (offsite.length > 0) add("sitemap.xml", "fail", `lists other origins: ${offsite.slice(0, 3).join(", ")}`)
408
+ for (const loc of isIndex ? locs.filter((l) => new URL(l).origin === site) : []) {
409
+ const child = await fetchText(loc)
410
+ if (child.status !== 200)
411
+ add(`sitemap ${new URL(loc).pathname}`, "fail", `answered ${child.status || child.text}`)
412
+ else pageUrls.push(...[...child.text.matchAll(/<loc>([^<]+)<\/loc>/g)].map((m) => m[1]!.replace(/&amp;/g, "&")))
413
+ }
414
+ if (!isIndex) pageUrls.push(...locs)
415
+ if (offsite.length === 0)
416
+ add("sitemap.xml", "pass", `${pageUrls.length} pages${isIndex ? ` in ${locs.length} sitemaps` : ""}`)
417
+ }
418
+
419
+ const llms = await fetchText("/llms.txt")
420
+ const declared: Array<string> = []
421
+ if (llms.status !== 200) add("llms.txt", "fail", `answered ${llms.status || llms.text}`)
422
+ else {
423
+ const toolsSection = llms.text.split(/^## Tools\s*$/m)[1] ?? ""
424
+ declared.push(
425
+ ...[...(toolsSection.split(/^Public tools[^\n]*$/m)[1] ?? "").matchAll(/^- (\S+)/gm)].map((m) => m[1]!),
426
+ )
427
+ add(
428
+ "llms.txt",
429
+ /^# /m.test(llms.text) ? "pass" : "warn",
430
+ /^# /m.test(llms.text) ? "served, with a title" : "has no # title",
431
+ )
432
+ for (const link of [...llms.text.matchAll(/\]\((https?:[^)]+\.md)\)/g)]
433
+ .map((m) => m[1]!)
434
+ .filter((l) => new URL(l).origin === site)
435
+ .slice(0, MAX_PAGES)) {
436
+ const mirror = await fetchText(link)
437
+ const type = mirror.headers.get("content-type") ?? ""
438
+ if (mirror.status !== 200)
439
+ add(`mirror ${new URL(link).pathname}`, "fail", `answered ${mirror.status || mirror.text}`)
440
+ else if (/text\/html/.test(type) || /^\s*<!doctype html/i.test(mirror.text))
441
+ add(`mirror ${new URL(link).pathname}`, "fail", "served as HTML (the shell's fallback?), not Markdown")
442
+ else add(`mirror ${new URL(link).pathname}`, "pass", type || "served")
443
+ }
444
+ }
445
+
446
+ for (const page of [...new Set(pageUrls)].slice(0, MAX_PAGES)) {
447
+ const response = await get(page, origins).catch((e: Error) => ({
448
+ status: 0,
449
+ headers: new Headers(),
450
+ text: e.message,
451
+ }))
452
+ if (response.status !== 200) {
453
+ add(`page ${new URL(page).pathname}`, "fail", `answered ${response.status || response.text}`)
454
+ continue
455
+ }
456
+ const blocks = [
457
+ ...response.text.matchAll(/<script[^>]+type=["']application\/ld\+json["'][^>]*>([\s\S]*?)<\/script>/gi),
458
+ ]
459
+ const broken = blocks.filter((b) => {
460
+ try {
461
+ JSON.parse(b[1]!)
462
+ return false
463
+ } catch {
464
+ return true
465
+ }
466
+ })
467
+ add(
468
+ `page ${new URL(page).pathname}`,
469
+ broken.length > 0 ? "fail" : blocks.length === 0 ? "warn" : "pass",
470
+ broken.length > 0
471
+ ? "has JSON-LD that does not parse"
472
+ : blocks.length === 0
473
+ ? "answers, with no JSON-LD"
474
+ : `answers, ${blocks.length} JSON-LD block${blocks.length === 1 ? "" : "s"}`,
475
+ )
476
+ }
477
+
478
+ // Tools: an anonymous MCP listing must offer exactly what llms.txt (and the config) declare public: by default none.
479
+ const publicTools = [...new Set([...(config?.publicTools ?? []), ...declared])].sort()
480
+ const tools = await anonymousTools(new URL("/mcp", kernel).href, origins)
481
+ if (tools.kind === "refused") {
482
+ add(
483
+ "public tools",
484
+ publicTools.length === 0 ? "pass" : "fail",
485
+ publicTools.length === 0
486
+ ? `the MCP endpoint refuses an anonymous client (${tools.detail})`
487
+ : `declared public (${publicTools.join(", ")}) but the endpoint refuses anonymous clients`,
488
+ )
489
+ } else if (tools.kind === "absent") {
490
+ add("public tools", "warn", `no MCP endpoint answered at ${kernel}/mcp (${tools.detail})`)
491
+ } else if (tools.kind === "error") {
492
+ add("public tools", "fail", `the MCP endpoint did not list its tools to an anonymous client: ${tools.detail}`)
493
+ } else if (tools.kind === "listed") {
494
+ const undeclared = tools.names.filter((t) => !publicTools.includes(t))
495
+ const missing = publicTools.filter((t) => !tools.names.includes(t))
496
+ add(
497
+ "public tools",
498
+ undeclared.length === 0 && missing.length === 0 ? "pass" : "fail",
499
+ undeclared.length > 0
500
+ ? `the endpoint offers tools to anonymous clients that nobody declared public: ${undeclared.join(", ")}`
501
+ : missing.length > 0
502
+ ? `declared public but not offered: ${missing.join(", ")}`
503
+ : `exactly the declared public tools: ${publicTools.join(", ") || "none"}`,
504
+ )
505
+ }
506
+ return checks
507
+ }