shapewall 0.0.0-stage → 0.2.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 (304) hide show
  1. package/CHANGELOG.md +139 -0
  2. package/Dockerfile.agent +45 -0
  3. package/LICENSE +202 -0
  4. package/NOTICE +12 -0
  5. package/README.md +651 -2
  6. package/THIRD_PARTY.md +165 -0
  7. package/bin/shapewall.js +29 -0
  8. package/dist/agent/package-lock.json +8384 -0
  9. package/dist/client/assets/BoardChat-D5SFd8HE.js +28 -0
  10. package/dist/client/assets/BuzzDialog-HWXBy52W.js +1 -0
  11. package/dist/client/assets/ChecksPanel-DTdImWoD.js +1 -0
  12. package/dist/client/assets/History-CEv6b-av.js +1 -0
  13. package/dist/client/assets/LocalSettings-C4vriEVQ.js +1 -0
  14. package/dist/client/assets/Management-DCfhcEUY.js +1 -0
  15. package/dist/client/assets/QuickConnect-DQGgUsl1.js +1 -0
  16. package/dist/client/assets/ShareDialog-C_plIto0.js +2 -0
  17. package/dist/client/assets/app-update-dialog-2hPz_N9G.js +1 -0
  18. package/dist/client/assets/circle-x-BZMPi8Zf.js +1 -0
  19. package/dist/client/assets/index-ByQRKVit.css +2 -0
  20. package/dist/client/assets/index-DweQ8Qtu.js +29 -0
  21. package/dist/client/assets/refresh-cw-CRow0Nbq.js +1 -0
  22. package/dist/client/assets/runtime-Bft6x_6E.js +4 -0
  23. package/dist/client/assets/square-A8EnIYLR.js +1 -0
  24. package/dist/client/assets/tts-dist-DYlBQmwG.js +18 -0
  25. package/dist/client/assets/tts-en-g2p-BPUtBFGG.js +1 -0
  26. package/dist/client/assets/tts-ort-wasm-simd-threaded-qh98TCA_.wasm +0 -0
  27. package/dist/client/assets/tts-ort.wasm.bundle.min-rEkcs_ow.js +12 -0
  28. package/dist/client/assets/tts-rolldown-runtime-D8NudN84.js +1 -0
  29. package/dist/client/assets/tts-spacy-en-tokenizer-6SNMl--A.json +1 -0
  30. package/dist/client/assets/tts-tts.worker-Bzm6aWbv.js +1 -0
  31. package/dist/client/assets/tts-us_gold-DcjeNMH1.json +92589 -0
  32. package/dist/client/assets/tts-us_silver-C964mEB5.json +93363 -0
  33. package/dist/client/assets/ui-CLbws0rx.js +41 -0
  34. package/dist/client/build-info.json +1 -0
  35. package/dist/client/favicon.svg +7 -0
  36. package/dist/client/icons/apple-touch-icon.png +0 -0
  37. package/dist/client/icons/icon-192.png +0 -0
  38. package/dist/client/icons/icon-512.png +0 -0
  39. package/dist/client/icons/maskable-512.png +0 -0
  40. package/dist/client/index.html +25 -0
  41. package/dist/client/manifest.webmanifest +15 -0
  42. package/dist/client/sw.js +53 -0
  43. package/dist/client/theme-boot.js +27 -0
  44. package/dist/console/assets/LocalAccountsApp-BQCcmj3x.js +1 -0
  45. package/dist/console/assets/LocalConsole-Bb2FUDs7.js +1 -0
  46. package/dist/console/assets/app-update-dialog-DIeYepLZ.js +1 -0
  47. package/dist/console/assets/console-C7uJLLOn.js +51 -0
  48. package/dist/console/assets/console-R8IBY3Am.css +2 -0
  49. package/dist/console/build-info.json +1 -0
  50. package/dist/console/console.html +21 -0
  51. package/dist/console/favicon.svg +7 -0
  52. package/dist/console/icons/apple-touch-icon.png +0 -0
  53. package/dist/console/icons/icon-192.png +0 -0
  54. package/dist/console/icons/icon-512.png +0 -0
  55. package/dist/console/icons/maskable-512.png +0 -0
  56. package/dist/console/manifest.webmanifest +15 -0
  57. package/dist/console/theme-boot.js +27 -0
  58. package/docs/agent-hardening.md +342 -0
  59. package/docs/agent-recipes.md +187 -0
  60. package/docs/agent-workflow.md +320 -0
  61. package/docs/agents.md +894 -0
  62. package/docs/architecture.md +242 -0
  63. package/docs/buzz.md +140 -0
  64. package/docs/capture-warnings.md +57 -0
  65. package/docs/config.md +489 -0
  66. package/docs/deployment.md +289 -0
  67. package/docs/design-system.md +162 -0
  68. package/docs/github.md +107 -0
  69. package/docs/hosted.md +764 -0
  70. package/docs/images/board-overview.png +0 -0
  71. package/docs/images/journeys.png +0 -0
  72. package/docs/images/live-comment.png +0 -0
  73. package/docs/images/phone-comment.png +0 -0
  74. package/docs/images/phone-overview.png +0 -0
  75. package/docs/images/variant.png +0 -0
  76. package/docs/interaction-audits.md +40 -0
  77. package/docs/journeys.md +137 -0
  78. package/docs/local-accounts.md +80 -0
  79. package/docs/notifications.md +237 -0
  80. package/docs/page-checks.md +69 -0
  81. package/docs/performance.md +174 -0
  82. package/docs/starter-agent.md +325 -0
  83. package/docs/updates.md +87 -0
  84. package/examples/audits/interaction.audit.json +17 -0
  85. package/package.json +132 -4
  86. package/src/accounts/avatar.js +121 -0
  87. package/src/accounts/local.js +464 -0
  88. package/src/agent/acp/command.js +204 -0
  89. package/src/agent/acp/detect.js +75 -0
  90. package/src/agent/acp/sandbox.js +160 -0
  91. package/src/agent/agent-health.js +75 -0
  92. package/src/agent/backends/acp.js +1297 -0
  93. package/src/agent/backends/index.js +61 -0
  94. package/src/agent/backends/openai.js +308 -0
  95. package/src/agent/composer.js +221 -0
  96. package/src/agent/config.js +338 -0
  97. package/src/agent/context.js +191 -0
  98. package/src/agent/control.js +122 -0
  99. package/src/agent/errors.js +17 -0
  100. package/src/agent/feedback-loop.js +137 -0
  101. package/src/agent/manage.js +94 -0
  102. package/src/agent/next-steps.js +51 -0
  103. package/src/agent/owner-mcp.js +38 -0
  104. package/src/agent/plain-text.js +52 -0
  105. package/src/agent/ratings-core.js +213 -0
  106. package/src/agent/ratings.js +100 -0
  107. package/src/agent/reply-text.js +67 -0
  108. package/src/agent/routes.js +1065 -0
  109. package/src/agent/run.js +326 -0
  110. package/src/agent/settings-routes.js +704 -0
  111. package/src/agent/showable.js +23 -0
  112. package/src/agent/starter/approvals.js +181 -0
  113. package/src/agent/starter/build-image.js +90 -0
  114. package/src/agent/starter/cli.js +163 -0
  115. package/src/agent/starter/disk.js +53 -0
  116. package/src/agent/starter/doctor.js +180 -0
  117. package/src/agent/starter/egress-proxy.js +351 -0
  118. package/src/agent/starter/gate.js +90 -0
  119. package/src/agent/starter/loop.js +114 -0
  120. package/src/agent/starter/model-relay.js +289 -0
  121. package/src/agent/starter/pause.js +14 -0
  122. package/src/agent/starter/probe.js +272 -0
  123. package/src/agent/starter/prompt.js +41 -0
  124. package/src/agent/starter/push-guard.js +146 -0
  125. package/src/agent/starter/rpc.js +164 -0
  126. package/src/agent/starter/runtime.js +287 -0
  127. package/src/agent/starter/sandbox-main.js +121 -0
  128. package/src/agent/starter/settings.js +290 -0
  129. package/src/agent/starter/source.js +69 -0
  130. package/src/agent/starter/supervisor.js +755 -0
  131. package/src/agent/starter/sweep.js +46 -0
  132. package/src/agent/starter/tools.js +524 -0
  133. package/src/agent/starter/watch.js +84 -0
  134. package/src/agent/starter/worktree.js +409 -0
  135. package/src/agent/text-diff.js +210 -0
  136. package/src/agent/thread-history.js +223 -0
  137. package/src/agent/threads.js +399 -0
  138. package/src/agent/tools.js +200 -0
  139. package/src/agent/turn-changes.js +424 -0
  140. package/src/agent/undo-state.js +26 -0
  141. package/src/agent/user-settings.js +308 -0
  142. package/src/auth/record.js +375 -0
  143. package/src/broken-links.js +164 -0
  144. package/src/buzz/client.js +75 -0
  145. package/src/buzz/config.js +151 -0
  146. package/src/buzz/environment.js +13 -0
  147. package/src/buzz/gateway.js +192 -0
  148. package/src/buzz/routes.js +61 -0
  149. package/src/buzz/signer-child.js +205 -0
  150. package/src/buzz/store.js +89 -0
  151. package/src/buzz/transport.js +60 -0
  152. package/src/buzz/verify.js +140 -0
  153. package/src/capture/actions.js +159 -0
  154. package/src/capture/capture.js +776 -0
  155. package/src/capture/dom-names.js +189 -0
  156. package/src/capture/element-map.js +509 -0
  157. package/src/capture/live.js +827 -0
  158. package/src/capture/media-scheme.js +317 -0
  159. package/src/capture/network-summary.js +86 -0
  160. package/src/capture/pacing.js +34 -0
  161. package/src/capture/requests.js +167 -0
  162. package/src/capture/sanitize.js +752 -0
  163. package/src/checks/accessibility.js +134 -0
  164. package/src/checks/budgets.js +58 -0
  165. package/src/checks/cli.js +55 -0
  166. package/src/checks/comparison.js +113 -0
  167. package/src/checks/environments.js +32 -0
  168. package/src/checks/flow-config.js +82 -0
  169. package/src/checks/flow-origin.js +53 -0
  170. package/src/checks/flows.js +398 -0
  171. package/src/checks/lighthouse-auth.js +145 -0
  172. package/src/checks/lighthouse-findings.js +130 -0
  173. package/src/checks/lighthouse.js +395 -0
  174. package/src/checks/robots.js +85 -0
  175. package/src/checks/routes.js +52 -0
  176. package/src/checks/run-control.js +259 -0
  177. package/src/checks/runner.js +724 -0
  178. package/src/checks/schema.js +133 -0
  179. package/src/checks/seo-analysis.js +443 -0
  180. package/src/checks/seo-probe.js +190 -0
  181. package/src/checks/seo-snapshot.js +99 -0
  182. package/src/checks/store.js +214 -0
  183. package/src/checks/transport.js +47 -0
  184. package/src/cli/args.js +319 -0
  185. package/src/cli/capture.js +79 -0
  186. package/src/cli/commands.js +92 -0
  187. package/src/cli/comments.js +84 -0
  188. package/src/cli/help.js +243 -0
  189. package/src/cli/init.js +214 -0
  190. package/src/cli/misc.js +64 -0
  191. package/src/cli/notify.js +87 -0
  192. package/src/cli/open.js +22 -0
  193. package/src/cli/serve.js +274 -0
  194. package/src/cli/variant.js +82 -0
  195. package/src/cli/watch.js +70 -0
  196. package/src/cli.js +130 -0
  197. package/src/comment-fields.js +76 -0
  198. package/src/comments-cli.js +208 -0
  199. package/src/config-reload.js +100 -0
  200. package/src/config.js +1061 -0
  201. package/src/devices-cli.js +21 -0
  202. package/src/diff.js +95 -0
  203. package/src/discover.js +284 -0
  204. package/src/doctor.js +295 -0
  205. package/src/event-log.js +268 -0
  206. package/src/events-cli.js +102 -0
  207. package/src/events.js +113 -0
  208. package/src/export.js +119 -0
  209. package/src/feedback.js +246 -0
  210. package/src/github.js +551 -0
  211. package/src/hosted/LICENSE.md +105 -0
  212. package/src/hosted/access-cli.js +78 -0
  213. package/src/hosted/admin.js +682 -0
  214. package/src/hosted/agent-approvals.js +163 -0
  215. package/src/hosted/agent-policy.js +189 -0
  216. package/src/hosted/app.js +510 -0
  217. package/src/hosted/auth-routes.js +540 -0
  218. package/src/hosted/auth.js +536 -0
  219. package/src/hosted/backup.js +483 -0
  220. package/src/hosted/board-context.js +35 -0
  221. package/src/hosted/board-routes.js +486 -0
  222. package/src/hosted/board-view.js +94 -0
  223. package/src/hosted/clean-worker.js +24 -0
  224. package/src/hosted/cleaner.js +89 -0
  225. package/src/hosted/comments.js +355 -0
  226. package/src/hosted/console-routes.js +401 -0
  227. package/src/hosted/cookies.js +18 -0
  228. package/src/hosted/crypto.js +80 -0
  229. package/src/hosted/db.js +496 -0
  230. package/src/hosted/device-routes.js +175 -0
  231. package/src/hosted/device.js +233 -0
  232. package/src/hosted/events.js +63 -0
  233. package/src/hosted/guards.js +172 -0
  234. package/src/hosted/guest-view.js +65 -0
  235. package/src/hosted/http.js +39 -0
  236. package/src/hosted/import.js +300 -0
  237. package/src/hosted/mail.js +73 -0
  238. package/src/hosted/mcp-http.js +71 -0
  239. package/src/hosted/membership.js +114 -0
  240. package/src/hosted/operator.js +478 -0
  241. package/src/hosted/ops-cli.js +345 -0
  242. package/src/hosted/pages.js +146 -0
  243. package/src/hosted/permissions.js +113 -0
  244. package/src/hosted/presence.js +372 -0
  245. package/src/hosted/projects.js +124 -0
  246. package/src/hosted/public.js +109 -0
  247. package/src/hosted/push.js +622 -0
  248. package/src/hosted/quotas.js +115 -0
  249. package/src/hosted/ratelimit.js +96 -0
  250. package/src/hosted/rebind.js +316 -0
  251. package/src/hosted/retention.js +128 -0
  252. package/src/hosted/server.js +260 -0
  253. package/src/hosted/setup-link.js +64 -0
  254. package/src/hosted/setup.js +323 -0
  255. package/src/hosted/shares.js +444 -0
  256. package/src/hosted/tailscale.js +204 -0
  257. package/src/hosted/tenancy.js +301 -0
  258. package/src/hosted/token-api.js +455 -0
  259. package/src/hosted/token-events.js +60 -0
  260. package/src/hosted/tokens.js +57 -0
  261. package/src/hosted/turnstile.js +49 -0
  262. package/src/hosted/usercontent.js +154 -0
  263. package/src/hosted/zip.js +155 -0
  264. package/src/invocation.js +58 -0
  265. package/src/journey-paths.js +282 -0
  266. package/src/journeys.js +189 -0
  267. package/src/links.js +106 -0
  268. package/src/local-projects.js +182 -0
  269. package/src/lock.js +193 -0
  270. package/src/mcp.js +417 -0
  271. package/src/mentions.js +151 -0
  272. package/src/net.js +15 -0
  273. package/src/notify/config.js +275 -0
  274. package/src/notify/index.js +301 -0
  275. package/src/notify/lease.js +73 -0
  276. package/src/notify/messages.js +212 -0
  277. package/src/notify/run.js +174 -0
  278. package/src/pixeldiff.js +49 -0
  279. package/src/png.js +143 -0
  280. package/src/reactions.js +111 -0
  281. package/src/remote/cli.js +133 -0
  282. package/src/remote/credentials.js +62 -0
  283. package/src/remote/ids.js +12 -0
  284. package/src/remote/login.js +155 -0
  285. package/src/remote/remote-mcp.js +237 -0
  286. package/src/remote/remote-watch.js +291 -0
  287. package/src/remote/remote.js +313 -0
  288. package/src/remote/share-state.js +78 -0
  289. package/src/remote/share.js +369 -0
  290. package/src/remote/terminal.js +13 -0
  291. package/src/serve-state.js +64 -0
  292. package/src/server/app.js +824 -0
  293. package/src/server/devices.js +186 -0
  294. package/src/server/local-console.js +28 -0
  295. package/src/server/local-user.js +59 -0
  296. package/src/server/pairing-routes.js +159 -0
  297. package/src/server/share-routes.js +89 -0
  298. package/src/server/tailscale.js +97 -0
  299. package/src/sitemap.js +431 -0
  300. package/src/store.js +983 -0
  301. package/src/tokens.js +11 -0
  302. package/src/update/routes.js +245 -0
  303. package/src/watch.js +403 -0
  304. package/src/which.js +58 -0
@@ -0,0 +1,133 @@
1
+ import { createHash, randomUUID } from 'node:crypto'
2
+ import { z } from 'zod'
3
+ import { BUDGET_METRICS } from './budgets.js'
4
+ import { findingSeverity } from './seo-analysis.js'
5
+
6
+ export const REPORT_MAX_BYTES = 128 * 1024
7
+ export const REPORTS_MAX = 200
8
+ export const REPORT_ID_RE = /^check-[a-f0-9-]{36}$/
9
+ const id = z.string().regex(/^[a-z0-9][a-z0-9-]{0,63}$/)
10
+ const hash = z.string().regex(/^[a-f0-9]{64}$/)
11
+ // Shared diagnostics never carry original URLs, private endpoint paths,
12
+ // raw page text, selectors, headers, error stacks or arbitrary HTML.
13
+ const text = z
14
+ .string()
15
+ .max(500)
16
+ .refine((s) => !/[<>]|https?:|file:|\/[\w.~]|[?&#=]|@/i.test(s) && ![...s].some((c) => c.charCodeAt(0) < 32), 'unsafe diagnostic text')
17
+ const metric = z.number().finite().min(0).max(1e15).nullable()
18
+ export const reportSchema = z
19
+ .object({
20
+ schemaVersion: z.literal(1),
21
+ id: z.string().regex(REPORT_ID_RE),
22
+ runId: z.string().uuid(),
23
+ boardId: id,
24
+ pageId: id,
25
+ environment: id,
26
+ viewport: z
27
+ .object({
28
+ name: z.string().regex(/^[a-z][a-z0-9-]{0,31}$/),
29
+ width: z.number().int().min(240).max(3840),
30
+ height: z.number().int().min(240).max(8000),
31
+ })
32
+ .strict(),
33
+ captureVersion: z
34
+ .string()
35
+ .regex(/^\d{8}T\d{9}Z(?:-[a-f0-9]{4})?$/)
36
+ .nullable(),
37
+ sampledSeparately: z.literal(true),
38
+ state: z.enum(['complete', 'partial', 'failed', 'unsupported']),
39
+ auditedAt: z.iso.datetime(),
40
+ profile: z
41
+ .object({
42
+ runner: z.enum(['playwright', 'lighthouse', 'playwright-flow', 'axe']),
43
+ version: z.string().regex(/^[a-zA-Z0-9.+-]{1,60}$/),
44
+ mode: z.enum(['navigation', 'timespan', 'snapshot']),
45
+ cache: z.enum(['new-context', 'cold', 'warm', 'auth-preserved']),
46
+ authRole: z.enum(['anonymous', 'configured']),
47
+ sourceBuild: hash.nullable(),
48
+ stateFingerprint: hash,
49
+ seo: z.boolean(),
50
+ production: z.enum(['production', 'development', 'unknown']),
51
+ location: z.literal('local'),
52
+ sampleCount: z.number().int().min(1).max(10),
53
+ authStateHash: hash.optional(),
54
+ sourceEnvironment: id.optional(),
55
+ flowHash: hash.optional(),
56
+ flowStep: z.number().int().min(0).max(20).optional(),
57
+ accessibilityVersion: z
58
+ .string()
59
+ .regex(/^[a-zA-Z0-9.+-]{1,60}$/)
60
+ .optional(),
61
+ browser: z
62
+ .object({ version: z.string().regex(/^[a-zA-Z0-9.+-]{1,60}$/), userAgentHash: hash })
63
+ .strict()
64
+ .optional(),
65
+ throttling: z
66
+ .object({
67
+ method: z.enum(['simulate', 'devtools', 'provided']),
68
+ rttMs: metric,
69
+ throughputKbps: metric,
70
+ cpuSlowdownMultiplier: metric,
71
+ })
72
+ .strict()
73
+ .optional(),
74
+ device: z.object({ mobile: z.boolean(), deviceScaleFactor: metric, screenEmulationDisabled: z.boolean() }).strict().optional(),
75
+ })
76
+ .strict(),
77
+ completeness: z
78
+ .object({
79
+ window: z.enum(['navigation-through-configured-actions', 'explicit-flow', 'accessibility-snapshot']),
80
+ network: z.enum(['observed', 'partial', 'unavailable']),
81
+ serviceWorker: z.boolean().nullable(),
82
+ limitations: z.array(text).max(10),
83
+ })
84
+ .strict(),
85
+ metrics: z.record(z.string().regex(/^[a-zA-Z][a-zA-Z0-9]{0,59}$/), metric).refine((v) => Object.keys(v).length <= 40),
86
+ budgets: z
87
+ .object({
88
+ version: z.literal(1),
89
+ source: z.literal('config'),
90
+ thresholds: z.partialRecord(z.enum(Object.keys(BUDGET_METRICS)), z.number().finite().min(0).max(1e15)),
91
+ })
92
+ .strict()
93
+ .optional(),
94
+ findings: z
95
+ .array(
96
+ z
97
+ .object({
98
+ id,
99
+ category: z.enum(['reliability', 'semantics', 'seo', 'performance', 'accessibility']),
100
+ severity: z.enum(['warning', 'advisory']),
101
+ title: text,
102
+ observation: text,
103
+ impact: text,
104
+ nextAction: text,
105
+ })
106
+ .strict(),
107
+ )
108
+ .max(80),
109
+ })
110
+ .strict()
111
+
112
+ export function validateReport(value) {
113
+ if (Buffer.byteLength(JSON.stringify(value)) > REPORT_MAX_BYTES) throw new Error('Check report exceeds the size limit.')
114
+ return reportSchema.parse(value)
115
+ }
116
+ export const fingerprint = (value) => createHash('sha256').update(JSON.stringify(value)).digest('hex')
117
+ export const reportId = () => `check-${randomUUID()}`
118
+ export const summary = (report) => ({
119
+ actionable: report.findings.filter((f) => findingSeverity(f) === 'warning').length,
120
+ advisory: report.findings.filter((f) => findingSeverity(f) === 'advisory').length,
121
+ })
122
+
123
+ export function compareProfiles(left, right) {
124
+ const a = validateReport(left),
125
+ b = validateReport(right)
126
+ const reasons = []
127
+ if (a.boardId !== b.boardId || a.pageId !== b.pageId || a.environment !== b.environment) reasons.push('Different page or environment.')
128
+ if (fingerprint(a.viewport) !== fingerprint(b.viewport)) reasons.push('Different viewport dimensions.')
129
+ if (fingerprint(a.profile) !== fingerprint(b.profile)) reasons.push('Different runner conditions, build or configured state.')
130
+ if (!['complete', 'partial'].includes(a.state) || !['complete', 'partial'].includes(b.state))
131
+ reasons.push('A run has no usable measurements.')
132
+ return { comparable: !reasons.length, reasons }
133
+ }
@@ -0,0 +1,443 @@
1
+ // Shared with the browser: the SEO view's plain-English analysis of page
2
+ // check reports and their local search previews. Pure functions; callers
3
+ // supply validated v1 reports and validated preview snapshots.
4
+
5
+ // Google draws result titles in 20 px Arial and snippets in 14 px Arial, and
6
+ // cuts them by rendered width, not by a character count. These are Arial's
7
+ // advance widths per 1000 units, close enough to predict the cut.
8
+ const ARIAL = {
9
+ ' ': 278,
10
+ '!': 278,
11
+ '"': 355,
12
+ '#': 556,
13
+ $: 556,
14
+ '%': 889,
15
+ '&': 667,
16
+ "'": 191,
17
+ '(': 333,
18
+ ')': 333,
19
+ '*': 389,
20
+ '+': 584,
21
+ ',': 278,
22
+ '-': 333,
23
+ '.': 278,
24
+ '/': 278,
25
+ ':': 278,
26
+ ';': 278,
27
+ '<': 584,
28
+ '=': 584,
29
+ '>': 584,
30
+ '?': 556,
31
+ '@': 1015,
32
+ '[': 278,
33
+ ']': 278,
34
+ _: 556,
35
+ '|': 260,
36
+ '–': 556,
37
+ '—': 1000,
38
+ '·': 278,
39
+ '…': 1000,
40
+ '’': 222,
41
+ '‘': 222,
42
+ '“': 333,
43
+ '”': 333,
44
+ }
45
+ const UPPER = { A: 667, B: 667, C: 722, D: 722, E: 667, F: 611, G: 778, H: 722, I: 278, J: 500, K: 667, L: 556, M: 833 }
46
+ Object.assign(UPPER, { N: 722, O: 778, P: 667, Q: 778, R: 722, S: 667, T: 611, U: 722, V: 667, W: 944, X: 667, Y: 667, Z: 611 })
47
+ const LOWER = { a: 556, b: 556, c: 500, d: 556, e: 556, f: 278, g: 556, h: 556, i: 222, j: 222, k: 500, l: 222, m: 833 }
48
+ Object.assign(LOWER, { n: 556, o: 556, p: 556, q: 556, r: 333, s: 500, t: 278, u: 556, v: 500, w: 722, x: 500, y: 500, z: 500 })
49
+
50
+ function advance(char) {
51
+ if (ARIAL[char] !== undefined) return ARIAL[char]
52
+ if (UPPER[char] !== undefined) return UPPER[char]
53
+ if (LOWER[char] !== undefined) return LOWER[char]
54
+ if (/[0-9]/.test(char)) return 556
55
+ const code = char.codePointAt(0)
56
+ // CJK, kana, hangul and emoji are about one em wide.
57
+ if (code >= 0x2e80) return 1000
58
+ if (/\p{Lu}/u.test(char)) return 700
59
+ return 560
60
+ }
61
+
62
+ // Rendered width in CSS pixels of `text` in Arial at `size` px.
63
+ export function textWidth(text, size) {
64
+ let units = 0
65
+ for (const char of String(text || '')) units += advance(char)
66
+ return (units * size) / 1000
67
+ }
68
+
69
+ export const SEO_LIMITS = Object.freeze({
70
+ titleFont: 20,
71
+ titlePixels: 580,
72
+ titleMinChars: 10,
73
+ descriptionFont: 14,
74
+ descriptionPixels: 920,
75
+ descriptionMinChars: 50,
76
+ })
77
+
78
+ const clean = (value) =>
79
+ String(value || '')
80
+ .replace(/\s+/g, ' ')
81
+ .trim()
82
+
83
+ // What Google would likely show: the text cut at a word boundary to fit the
84
+ // width, with an ellipsis. `cut` says whether anything was dropped.
85
+ export function truncateForSearch(text, { size, pixels }) {
86
+ const value = clean(text)
87
+ if (textWidth(value, size) <= pixels) return { text: value, cut: false }
88
+ const room = pixels - textWidth(' ...', size)
89
+ let width = 0
90
+ let end = 0
91
+ for (const char of value) {
92
+ const next = width + (advance(char) * size) / 1000
93
+ if (next > room) break
94
+ width = next
95
+ end += char.length
96
+ }
97
+ let head = value.slice(0, end)
98
+ const space = head.lastIndexOf(' ')
99
+ if (space > end * 0.6) head = head.slice(0, space)
100
+ return { text: `${head.replace(/[\s,.;:–—-]+$/, '')} ...`, cut: true }
101
+ }
102
+
103
+ // The length observations a report records for a page's title and
104
+ // description. Returned ids are the report finding ids.
105
+ export function lengthIssues(title, description) {
106
+ const issues = []
107
+ const t = clean(title)
108
+ const d = clean(description)
109
+ if (t && [...t].length < SEO_LIMITS.titleMinChars) issues.push({ id: 'seo-title-short', length: [...t].length })
110
+ if (t && textWidth(t, SEO_LIMITS.titleFont) > SEO_LIMITS.titlePixels) issues.push({ id: 'seo-title-long', length: [...t].length })
111
+ if (d && [...d].length < SEO_LIMITS.descriptionMinChars) issues.push({ id: 'seo-description-short', length: [...d].length })
112
+ if (d && textWidth(d, SEO_LIMITS.descriptionFont) > SEO_LIMITS.descriptionPixels)
113
+ issues.push({ id: 'seo-description-long', length: [...d].length })
114
+ return issues
115
+ }
116
+
117
+ // The SEO view's wording for each finding id: a level (`error` keeps the
118
+ // page out of search or breaks sharing, `warning` hurts how it shows, `tip`
119
+ // is polish), a short label, what it means and what to do.
120
+ export const SEO_ISSUES = Object.freeze({
121
+ 'search-noindex': {
122
+ level: 'error',
123
+ group: 'indexing',
124
+ label: 'Asks search engines not to index it',
125
+ explain: 'A robots "noindex" tag or header tells Google to leave this page out of search results.',
126
+ fix: 'Remove the noindex robots meta tag or X-Robots-Tag header if this page should be found. If it is meant to stay private, mark the page private in the Shapewall config.',
127
+ },
128
+ 'robots-crawl-blocked': {
129
+ level: 'error',
130
+ group: 'indexing',
131
+ label: 'Blocked by robots.txt',
132
+ explain: 'The site’s robots.txt rules stop Googlebot from crawling this address, so Google can’t read its content.',
133
+ fix: 'Change the Disallow rule in robots.txt that matches this path, or add a more specific Allow rule for it.',
134
+ },
135
+ 'robots-unavailable': {
136
+ level: 'tip',
137
+ group: 'indexing',
138
+ label: 'Crawl rules could not be read',
139
+ explain: 'robots.txt redirected, timed out or was too large, so crawl permission is unknown.',
140
+ fix: 'Serve robots.txt directly from the site root with a 200 or 404 response.',
141
+ },
142
+ 'missing-title': {
143
+ level: 'error',
144
+ group: 'title',
145
+ label: 'No page title',
146
+ explain: 'Without a <title>, Google writes its own headline for the result, usually from text on the page.',
147
+ fix: 'Add a unique <title> that says what the page is, with the brand at the end.',
148
+ },
149
+ 'seo-title-long': {
150
+ level: 'tip',
151
+ group: 'title',
152
+ label: 'Title will be cut off',
153
+ explain: 'Google shows about 580 pixels of a title (roughly 55 to 60 characters). The rest is replaced with an ellipsis.',
154
+ fix: 'Put the important words first and shorten the title so it fits.',
155
+ },
156
+ 'seo-title-short': {
157
+ level: 'tip',
158
+ group: 'title',
159
+ label: 'Title is very short',
160
+ explain: 'A very short title gives searchers little reason to pick this result.',
161
+ fix: 'Describe the page in a few more words, for example the product or topic and the brand.',
162
+ },
163
+ 'duplicate-title': {
164
+ level: 'warning',
165
+ group: 'title',
166
+ label: 'Same title as another page',
167
+ explain: 'Several pages share this title, so searchers can’t tell them apart and Google may pick the wrong one.',
168
+ fix: 'Give each page its own title that names what is different about it.',
169
+ },
170
+ 'seo-description': {
171
+ level: 'warning',
172
+ group: 'description',
173
+ label: 'No meta description',
174
+ explain: 'Without a description, Google picks a snippet from the page text, which is often a menu or a cookie banner.',
175
+ fix: 'Add <meta name="description"> with one or two sentences (about 120 to 155 characters) that sell the page.',
176
+ },
177
+ 'seo-description-long': {
178
+ level: 'tip',
179
+ group: 'description',
180
+ label: 'Description will be cut off',
181
+ explain: 'Google shows about 920 pixels of a description (roughly 150 to 160 characters) on desktop and less on phones.',
182
+ fix: 'Keep the key message in the first 120 characters.',
183
+ },
184
+ 'seo-description-short': {
185
+ level: 'tip',
186
+ group: 'description',
187
+ label: 'Description is very short',
188
+ explain: 'A short description leaves room Google may fill with page text instead.',
189
+ fix: 'Write one or two full sentences about what the visitor gets on this page.',
190
+ },
191
+ 'duplicate-description': {
192
+ level: 'warning',
193
+ group: 'description',
194
+ label: 'Same description as another page',
195
+ explain: 'Repeated descriptions make results look identical and tell searchers nothing about this page.',
196
+ fix: 'Write a description for this page that is specific to it.',
197
+ },
198
+ 'seo-canonical': {
199
+ level: 'warning',
200
+ group: 'canonical',
201
+ label: 'No canonical URL',
202
+ explain:
203
+ 'A canonical link tells search engines which address is the real one when the page is reachable at several (with tracking parameters, trailing slashes or www).',
204
+ fix: 'Add <link rel="canonical" href="..."> with the page’s full preferred address.',
205
+ },
206
+ 'canonical-invalid': {
207
+ level: 'warning',
208
+ group: 'canonical',
209
+ label: 'Canonical URL is not a full address',
210
+ explain: 'The canonical link is relative or not http(s). Search engines may ignore it.',
211
+ fix: 'Use an absolute https:// address in the canonical link.',
212
+ },
213
+ 'canonical-elsewhere': {
214
+ level: 'error',
215
+ group: 'canonical',
216
+ label: 'Canonical points to another page',
217
+ explain: 'The canonical link names a different address, which tells Google to show that page instead of this one.',
218
+ fix: 'Point the canonical link at this page’s own address, unless this really is a copy of the other page.',
219
+ },
220
+ 'seo-ogtitle': {
221
+ level: 'warning',
222
+ group: 'social',
223
+ label: 'No social title',
224
+ explain: 'Without og:title, Slack, LinkedIn, iMessage and others guess a headline for shared links.',
225
+ fix: 'Add <meta property="og:title"> with the headline you want in link previews.',
226
+ },
227
+ 'seo-ogdescription': {
228
+ level: 'tip',
229
+ group: 'social',
230
+ label: 'No social description',
231
+ explain: 'Link previews show og:description under the headline. Without it they show nothing or random text.',
232
+ fix: 'Add <meta property="og:description"> with one short sentence.',
233
+ },
234
+ 'seo-ogimage': {
235
+ level: 'warning',
236
+ group: 'social',
237
+ label: 'No social image',
238
+ explain: 'Shared links without og:image show as a plain text line and get far fewer clicks.',
239
+ fix: 'Add <meta property="og:image"> with an absolute URL to a 1200 × 630 image.',
240
+ },
241
+ 'social-image-failed': {
242
+ level: 'error',
243
+ group: 'social',
244
+ label: 'Social image is broken',
245
+ explain: 'The og:image address returned an error or isn’t a valid image, so previews show a blank box.',
246
+ fix: 'Fix the og:image URL so it returns a PNG, JPEG or WebP image with a 200 response.',
247
+ },
248
+ 'social-image-invalid': {
249
+ level: 'warning',
250
+ group: 'social',
251
+ label: 'Social image URL is not a full address',
252
+ explain: 'og:image must be an absolute http(s) URL. Most platforms ignore relative paths.',
253
+ fix: 'Use the full https:// address of the image.',
254
+ },
255
+ 'social-image-unavailable': {
256
+ level: 'tip',
257
+ group: 'social',
258
+ label: 'Social image could not be verified',
259
+ explain: 'The image is on another domain, redirected or is in a format Shapewall can’t decode, so its preview is not shown here.',
260
+ fix: 'Nothing is necessarily wrong. Check a preview with the platform’s own debugger if in doubt.',
261
+ },
262
+ 'social-image-dimensions': {
263
+ level: 'tip',
264
+ group: 'social',
265
+ label: 'Image size differs from its tags',
266
+ explain: 'og:image:width and og:image:height don’t match the actual image, which can make previews crop or load late.',
267
+ fix: 'Update the declared width and height to the real image size, or remove them.',
268
+ },
269
+ })
270
+
271
+ const LEVEL_ORDER = { error: 0, warning: 1, tip: 2 }
272
+
273
+ // The one severity of a finding everywhere it is counted (Issues tab, summary
274
+ // tiles, page cards, sorting): an SEO finding takes its level from SEO_ISSUES
275
+ // (errors and warnings need attention, tips are notes), so the SEO view and
276
+ // the Issues tab agree; every other finding keeps the runner's severity.
277
+ export function findingSeverity(finding) {
278
+ const known = finding?.category === 'seo' ? SEO_ISSUES[finding.id] : null
279
+ return known ? (known.level === 'tip' ? 'advisory' : 'warning') : finding?.severity
280
+ }
281
+ export const SEO_FINDING_IDS = Object.freeze(Object.keys(SEO_ISSUES))
282
+
283
+ // The newest report of `runner` for a page across its devices; SEO-enabled
284
+ // reports first when `seoOnly`.
285
+ function newestReport(views, pageId, runner, test = () => true) {
286
+ let best = null
287
+ for (const view of views) {
288
+ if (view.pageId !== pageId) continue
289
+ const runs = view.runs?.length
290
+ ? view.runs
291
+ : view.report
292
+ ? [{ runner: view.report.profile.runner, state: view.state, report: view.report }]
293
+ : []
294
+ for (const run of runs) {
295
+ const report = run.report
296
+ if (!report || (run.runner || report.profile.runner) !== runner || !test(report)) continue
297
+ // Prefer desktop when two runs are from the same moment.
298
+ const better =
299
+ !best ||
300
+ report.auditedAt > best.report.auditedAt ||
301
+ (report.auditedAt === best.report.auditedAt && report.viewport.name === 'desktop')
302
+ if (better) best = { report, stale: run.state === 'stale' }
303
+ }
304
+ }
305
+ return best
306
+ }
307
+
308
+ // The report each page's SEO row is built from: its newest SEO-enabled page
309
+ // check on any device. The local API serves previews for exactly these.
310
+ export function latestSeoReports(views, pageIds) {
311
+ const out = new Map()
312
+ for (const id of pageIds) {
313
+ const found = newestReport(views, id, 'playwright', (r) => r.profile.seo)
314
+ if (found) out.set(id, found.report)
315
+ }
316
+ return out
317
+ }
318
+
319
+ const normalized = (value) => clean(value).toLowerCase()
320
+
321
+ // The board's SEO picture.
322
+ // - views: checksView(...).views
323
+ // - pages: the board's pages ({ id, title, url })
324
+ // - snapshots: { [reportId]: snapshot } of local search previews (optional)
325
+ // - privatePages: page ids configured with seo.indexable === false
326
+ export function analyzeSeo({ views = [], pages = [], snapshots = {}, privatePages = [] } = {}) {
327
+ const privateSet = new Set(privatePages)
328
+ const rows = pages.map((page) => {
329
+ const found = newestReport(views, page.id, 'playwright', (r) => r.profile.seo)
330
+ const any = found || newestReport(views, page.id, 'playwright')
331
+ const lighthouse = newestReport(views, page.id, 'lighthouse', (r) => Number.isFinite(r.metrics?.lighthouseSeoLabScore))
332
+ const report = found?.report || null
333
+ const snapshot = report ? snapshots[report.id] || null : null
334
+ const isPrivate = privateSet.has(page.id) || Boolean(report?.findings.some((f) => f.id === 'seo-private-expected'))
335
+ const row = {
336
+ pageId: page.id,
337
+ title: page.title || page.id,
338
+ url: page.url || null,
339
+ status: isPrivate ? 'private' : !any ? 'not-run' : !report ? 'no-seo' : report.state === 'failed' ? 'failed' : 'checked',
340
+ stale: Boolean(found?.stale),
341
+ report,
342
+ snapshot,
343
+ lighthouseSeo: lighthouse ? lighthouse.report.metrics.lighthouseSeoLabScore : null,
344
+ issues: [],
345
+ }
346
+ if (row.status === 'checked')
347
+ for (const finding of report.findings) {
348
+ const known = SEO_ISSUES[finding.id]
349
+ // Duplicates are recomputed below from the previews when there are any.
350
+ if (!known || (finding.id.startsWith('duplicate-') && snapshot)) continue
351
+ row.issues.push({ id: finding.id, ...known, observation: finding.observation, finding })
352
+ }
353
+ return row
354
+ })
355
+ // Duplicates across every checked public page, not just one run.
356
+ const duplicates = { title: [], description: [] }
357
+ for (const key of ['title', 'description']) {
358
+ const groups = new Map()
359
+ for (const row of rows) {
360
+ if (row.status !== 'checked' || !row.snapshot) continue
361
+ const value = normalized(row.snapshot[key])
362
+ if (!value) continue
363
+ if (!groups.has(value)) groups.set(value, [])
364
+ groups.get(value).push(row)
365
+ }
366
+ for (const [, group] of groups) {
367
+ if (group.length < 2) continue
368
+ duplicates[key].push({ value: clean(group[0].snapshot[key]), pageIds: group.map((r) => r.pageId) })
369
+ for (const row of group) {
370
+ const others = group.filter((r) => r !== row).map((r) => r.title)
371
+ const id = `duplicate-${key}`
372
+ row.issues.push({
373
+ id,
374
+ ...SEO_ISSUES[id],
375
+ observation: `Also used on ${others.slice(0, 3).join(', ')}${others.length > 3 ? ` and ${others.length - 3} more` : ''}.`,
376
+ finding: null,
377
+ others: group.filter((r) => r !== row).map((r) => r.pageId),
378
+ })
379
+ }
380
+ }
381
+ }
382
+ // Reports without previews (hosted, imported) still carry run-level duplicates.
383
+ for (const key of ['title', 'description'])
384
+ if (!duplicates[key].length) {
385
+ const ids = rows.filter((r) => r.issues.some((i) => i.id === `duplicate-${key}`)).map((r) => r.pageId)
386
+ if (ids.length > 1) duplicates[key].push({ value: null, pageIds: ids })
387
+ }
388
+ for (const row of rows) {
389
+ row.issues.sort((a, b) => LEVEL_ORDER[a.level] - LEVEL_ORDER[b.level])
390
+ row.errors = row.issues.filter((i) => i.level === 'error').length
391
+ row.warnings = row.issues.filter((i) => i.level === 'warning').length
392
+ row.tips = row.issues.filter((i) => i.level === 'tip').length
393
+ row.indexable =
394
+ row.status === 'checked'
395
+ ? !row.issues.some((i) => ['search-noindex', 'robots-crawl-blocked', 'canonical-elsewhere'].includes(i.id))
396
+ : null
397
+ }
398
+ const checked = rows.filter((r) => r.status === 'checked')
399
+ const has = (row, ...ids) => row.issues.some((i) => ids.includes(i.id))
400
+ const scores = rows.map((r) => r.lighthouseSeo).filter((n) => Number.isFinite(n))
401
+ const summary = {
402
+ pages: rows.filter((r) => r.status !== 'private').length,
403
+ checked: checked.length,
404
+ private: rows.filter((r) => r.status === 'private').length,
405
+ notChecked: rows.filter((r) => ['not-run', 'no-seo', 'failed'].includes(r.status)).length,
406
+ indexable: checked.filter((r) => r.indexable).length,
407
+ notIndexable: checked.filter((r) => r.indexable === false).length,
408
+ missingTitles: checked.filter((r) => has(r, 'missing-title')).length,
409
+ missingDescriptions: checked.filter((r) => has(r, 'seo-description')).length,
410
+ duplicateTitles: duplicates.title.reduce((n, g) => n + g.pageIds.length, 0),
411
+ duplicateDescriptions: duplicates.description.reduce((n, g) => n + g.pageIds.length, 0),
412
+ socialImageProblems: checked.filter((r) => has(r, 'seo-ogimage', 'social-image-failed', 'social-image-invalid')).length,
413
+ canonicalIssues: checked.filter((r) => has(r, 'seo-canonical', 'canonical-invalid', 'canonical-elsewhere')).length,
414
+ robotsIssues: checked.filter((r) => has(r, 'search-noindex', 'robots-crawl-blocked', 'robots-unavailable')).length,
415
+ errors: checked.reduce((n, r) => n + r.errors, 0),
416
+ warnings: checked.reduce((n, r) => n + r.warnings, 0),
417
+ tips: checked.reduce((n, r) => n + r.tips, 0),
418
+ lighthouseSeo: scores.length
419
+ ? { min: Math.min(...scores), average: Math.round(scores.reduce((a, b) => a + b, 0) / scores.length), count: scores.length }
420
+ : null,
421
+ }
422
+ return { rows, summary, duplicates }
423
+ }
424
+
425
+ // The Google result breadcrumb for a URL: "example.com › docs › setup".
426
+ export function searchBreadcrumb(url) {
427
+ try {
428
+ const u = new URL(url)
429
+ const parts = u.pathname
430
+ .split('/')
431
+ .filter(Boolean)
432
+ .map((part) => {
433
+ try {
434
+ return decodeURIComponent(part)
435
+ } catch {
436
+ return part
437
+ }
438
+ })
439
+ return { site: u.hostname.replace(/^www\./, ''), origin: `${u.protocol}//${u.host}`, path: parts }
440
+ } catch {
441
+ return { site: '', origin: '', path: [] }
442
+ }
443
+ }