gentle-pi 4.7.0 → 4.8.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 (365) hide show
  1. package/README.md +55 -44
  2. package/assets/agents/gentle-ai-explore.md +3 -3
  3. package/assets/agents/gentle-ai-verify.md +20 -6
  4. package/assets/agents/gentle-ai-worker.md +6 -6
  5. package/assets/agents/jd-judge-a.md +1 -3
  6. package/assets/agents/jd-judge-b.md +1 -3
  7. package/assets/agents/review-readability.md +1 -5
  8. package/assets/agents/review-reliability.md +1 -5
  9. package/assets/agents/review-resilience.md +1 -5
  10. package/assets/agents/review-risk.md +1 -5
  11. package/assets/design-canvas/canvas-api.js +45 -0
  12. package/assets/design-canvas/canvas-boards.js +456 -0
  13. package/assets/design-canvas/canvas-boot.js +217 -0
  14. package/assets/design-canvas/canvas-checks.js +491 -0
  15. package/assets/design-canvas/canvas-comments.js +315 -0
  16. package/assets/design-canvas/canvas-compare.js +159 -0
  17. package/assets/design-canvas/canvas-events.js +75 -0
  18. package/assets/design-canvas/canvas-export.js +393 -0
  19. package/assets/design-canvas/canvas-focus.js +203 -0
  20. package/assets/design-canvas/canvas-handoffs.js +150 -0
  21. package/assets/design-canvas/canvas-i18n-es.js +392 -0
  22. package/assets/design-canvas/canvas-i18n.js +108 -0
  23. package/assets/design-canvas/canvas-layout.js +526 -0
  24. package/assets/design-canvas/canvas-menu.js +213 -0
  25. package/assets/design-canvas/canvas-messages.js +86 -0
  26. package/assets/design-canvas/canvas-minimap.js +163 -0
  27. package/assets/design-canvas/canvas-parts.js +401 -0
  28. package/assets/design-canvas/canvas-popover.js +234 -0
  29. package/assets/design-canvas/canvas-rail.js +348 -0
  30. package/assets/design-canvas/canvas-sizes.js +524 -0
  31. package/assets/design-canvas/canvas-store.js +164 -0
  32. package/assets/design-canvas/canvas-tokens.js +674 -0
  33. package/assets/design-canvas/canvas-ui.js +24 -0
  34. package/assets/design-canvas/canvas-view.js +184 -0
  35. package/assets/design-canvas/canvas.css +746 -15
  36. package/assets/design-canvas/canvas.js +2 -1506
  37. package/assets/design-canvas/index.html +117 -36
  38. package/assets/design-canvas/inspector.js +546 -16
  39. package/assets/install-wizard/wizard.js +5 -1
  40. package/assets/migrations/agent-body-history.json +24 -0
  41. package/assets/orchestrator-delegation-reference.md +8 -14
  42. package/assets/orchestrator-delegation.md +4 -4
  43. package/assets/orchestrator-full-delegation-card.md +4 -5
  44. package/assets/orchestrator-full-delegation.md +8 -8
  45. package/assets/orchestrator-memory.md +2 -2
  46. package/assets/orchestrator-prompts.md +1 -1
  47. package/assets/orchestrator-quota-recovery.md +5 -0
  48. package/assets/orchestrator-skills.md +13 -12
  49. package/assets/orchestrator-tracking.md +10 -14
  50. package/assets/orchestrator-verification.md +10 -8
  51. package/assets/orchestrator-writer.md +4 -4
  52. package/assets/orchestrator.md +18 -22
  53. package/bin/gentle-shell.mjs +128 -9
  54. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  55. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
  56. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
  60. package/docs/assets/brand/sponsor-banner.svg +60 -0
  61. package/docs/bundled-install.md +14 -6
  62. package/docs/delegated-verification.md +18 -2
  63. package/docs/desktop-rpc.md +1253 -0
  64. package/docs/gentle-agents-activity.md +26 -0
  65. package/docs/gentle-shell.md +39 -16
  66. package/docs/install-wizard.md +30 -21
  67. package/docs/odd-preparation-continuity.md +24 -0
  68. package/docs/permission-modes.md +9 -1
  69. package/docs/prompt-budget.md +12 -0
  70. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  71. package/docs/readme-reference.md +76 -24
  72. package/docs/review-coordinator.md +29 -9
  73. package/docs/review-delivery-preflight.md +22 -0
  74. package/docs/work-continuity.md +11 -1
  75. package/extensions/ask-user-question.ts +2 -2
  76. package/extensions/child-context.ts +21 -7
  77. package/extensions/gentle-agents.ts +234 -33
  78. package/extensions/gentle-ai.ts +576 -135
  79. package/extensions/gentle-design.ts +69 -3
  80. package/extensions/gentle-desktop-rpc.ts +143 -0
  81. package/extensions/gentle-guide.ts +3 -0
  82. package/extensions/gentle-shell.ts +105 -52
  83. package/extensions/gentle-todo.ts +48 -25
  84. package/extensions/skill-registry.ts +248 -223
  85. package/lib/agent-assets.ts +30 -6
  86. package/lib/agent-tool-overlay.ts +117 -0
  87. package/lib/agents-config.ts +47 -6
  88. package/lib/agents-message-delivery.ts +17 -0
  89. package/lib/agents-messaging.ts +8 -2
  90. package/lib/agents-protocol.ts +15 -0
  91. package/lib/agents-report-cap.ts +115 -0
  92. package/lib/agents-runner.ts +91 -6
  93. package/lib/agents-session-transport.ts +17 -1
  94. package/lib/background-jobs-tools.ts +9 -4
  95. package/lib/bounded-writer-admission.ts +184 -31
  96. package/lib/child-context-files.ts +21 -6
  97. package/lib/codemode-renderer.ts +1 -0
  98. package/lib/delivery-conflict-markers.ts +349 -0
  99. package/lib/design-canvas-assets.ts +36 -0
  100. package/lib/design-canvas-server.ts +241 -23
  101. package/lib/design-comments.ts +94 -4
  102. package/lib/design-handoffs.ts +2 -1
  103. package/lib/design-layout.ts +125 -0
  104. package/lib/design-parts.ts +281 -0
  105. package/lib/design-system-tokens.ts +111 -0
  106. package/lib/desktop-agents-service.ts +294 -0
  107. package/lib/desktop-design-service.ts +233 -0
  108. package/lib/desktop-jobs-service.ts +263 -0
  109. package/lib/desktop-rpc-agents.ts +294 -0
  110. package/lib/desktop-rpc-config.ts +731 -0
  111. package/lib/desktop-rpc-design.ts +138 -0
  112. package/lib/desktop-rpc-jobs.ts +181 -0
  113. package/lib/desktop-rpc-permissions.ts +177 -0
  114. package/lib/desktop-rpc-profiles.ts +196 -0
  115. package/lib/desktop-rpc-usage.ts +229 -0
  116. package/lib/desktop-rpc.ts +225 -0
  117. package/lib/desktop-usage-service.ts +310 -0
  118. package/lib/destructive-command-guard.ts +188 -13
  119. package/lib/gentle-ai-renderer.ts +13 -1
  120. package/lib/gentle-design.ts +201 -14
  121. package/lib/gentle-shell-bundled.ts +100 -9
  122. package/lib/hidden-tools.ts +35 -0
  123. package/lib/inprocess-reviewer.ts +96 -12
  124. package/lib/model-fallback-policy.ts +9 -0
  125. package/lib/model-routing-authority.ts +9 -0
  126. package/lib/nan-provider.ts +42 -28
  127. package/lib/native-review-cli.ts +79 -4
  128. package/lib/orchestrator-discovery.ts +39 -2
  129. package/lib/reply-language-anchor.ts +27 -2
  130. package/lib/request-context-placement.ts +53 -0
  131. package/lib/review-candidate-view.ts +11 -1
  132. package/lib/review-continuation-registry.ts +17 -0
  133. package/lib/review-coordinator.ts +252 -8
  134. package/lib/review-delivery-preflight.ts +85 -0
  135. package/lib/review-host-relay.ts +5 -1
  136. package/lib/review-integration-v2.ts +56 -3
  137. package/lib/reviewer-stream.ts +87 -0
  138. package/lib/shell-prompt.ts +16 -3
  139. package/lib/shell-usage.ts +10 -0
  140. package/lib/vim-editor-adapter.ts +9 -2
  141. package/lib/writer-batch-admission.ts +55 -0
  142. package/lib/yolo-session-policy.ts +6 -1
  143. package/package.json +2 -2
  144. package/prompts/skill-creation.md +1 -10
  145. package/runtime/design-canvas-assets.mjs +37 -0
  146. package/runtime/gentle-shell-bundled.mjs +100 -9
  147. package/runtime/native-review-cli.mjs +79 -4
  148. package/runtime/review-integration-v2.mjs +56 -3
  149. package/scripts/bootstrap.cmd +2 -2
  150. package/scripts/bootstrap.sh +41 -4
  151. package/scripts/build-full-delegation-card.mjs +4 -0
  152. package/scripts/build-runtime-modules.mjs +1 -0
  153. package/scripts/gentle-ai-installer.mjs +10 -10
  154. package/scripts/gentle-ai-proxy.mjs +1 -1
  155. package/scripts/installer-downloads.mjs +34 -8
  156. package/scripts/installer-preflight.mjs +28 -17
  157. package/scripts/installer-probes.mjs +25 -5
  158. package/scripts/installer-server.mjs +38 -9
  159. package/scripts/installer-windows.mjs +2 -2
  160. package/scripts/pi-update.mjs +166 -27
  161. package/scripts/prepare-verifier.mjs +107 -0
  162. package/scripts/update-agent-body-history.mjs +55 -8
  163. package/scripts/verify-package-files.mjs +40 -19
  164. package/skills/branch-pr/SKILL.md +16 -16
  165. package/skills/comment-writer/SKILL.md +1 -1
  166. package/skills/design/SKILL.md +6 -6
  167. package/skills/gentle-ai/SKILL.md +5 -5
  168. package/skills/judgment-day/SKILL.md +2 -2
  169. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  170. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  171. package/skills/skill-improver/SKILL.md +2 -2
  172. package/skills/skill-registry/SKILL.md +11 -13
  173. package/skills/tui-design/SKILL.md +1 -1
  174. package/skills/work-unit-commits/SKILL.md +5 -5
  175. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  176. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  177. package/tests/agent-tool-overlay.test.ts +89 -0
  178. package/tests/agents-config.test.ts +10 -1
  179. package/tests/agents-message-delivery.test.ts +36 -0
  180. package/tests/agents-queries.test.ts +144 -4
  181. package/tests/agents-report-cap.test.ts +126 -0
  182. package/tests/agents-runner.test.ts +37 -1
  183. package/tests/agents-session-transport.test.ts +34 -0
  184. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  185. package/tests/append-system-prompt-route.test.ts +10 -2
  186. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  187. package/tests/artifact-language.test.ts +1 -1
  188. package/tests/ask-user-question.test.ts +2 -1
  189. package/tests/audit-leftovers-contract.test.ts +51 -0
  190. package/tests/bounded-stop-contract.test.ts +9 -1
  191. package/tests/branch-pr-skill.test.ts +10 -1
  192. package/tests/bundled-install.test.ts +1 -1
  193. package/tests/child-context-files.test.ts +64 -8
  194. package/tests/child-skills-catalog.test.ts +56 -0
  195. package/tests/codemode-rendering.test.ts +4 -1
  196. package/tests/delegate-for-reason-contract.test.ts +30 -8
  197. package/tests/delivery-conflict-markers.test.ts +348 -0
  198. package/tests/design-canvas-all-sizes.test.ts +631 -0
  199. package/tests/design-canvas-allowlist.test.ts +32 -0
  200. package/tests/design-canvas-assets.test.ts +11 -878
  201. package/tests/design-canvas-boards.test.ts +77 -0
  202. package/tests/design-canvas-checks.test.ts +655 -0
  203. package/tests/design-canvas-compare.test.ts +79 -0
  204. package/tests/design-canvas-events.test.ts +59 -0
  205. package/tests/design-canvas-export.test.ts +1168 -0
  206. package/tests/design-canvas-focus.test.ts +113 -0
  207. package/tests/design-canvas-handoffs.test.ts +59 -0
  208. package/tests/design-canvas-i18n-review.test.ts +513 -0
  209. package/tests/design-canvas-i18n-views.test.ts +259 -0
  210. package/tests/design-canvas-i18n.test.ts +526 -0
  211. package/tests/design-canvas-inspector.test.ts +937 -0
  212. package/tests/design-canvas-layout.test.ts +1222 -0
  213. package/tests/design-canvas-minimap.test.ts +413 -0
  214. package/tests/design-canvas-modules.test.ts +90 -0
  215. package/tests/design-canvas-parts.test.ts +721 -0
  216. package/tests/design-canvas-rail.test.ts +799 -0
  217. package/tests/design-canvas-server.test.ts +855 -17
  218. package/tests/design-canvas-sizes.test.ts +548 -0
  219. package/tests/design-canvas-store.test.ts +180 -0
  220. package/tests/design-canvas-tokens.test.ts +965 -0
  221. package/tests/design-canvas-view.test.ts +299 -0
  222. package/tests/design-comments.test.ts +201 -1
  223. package/tests/design-handoffs.test.ts +20 -0
  224. package/tests/design-layout.test.ts +100 -0
  225. package/tests/design-parts.test.ts +260 -0
  226. package/tests/design-system-tokens.test.ts +215 -0
  227. package/tests/desktop-rpc-agents.test.ts +893 -0
  228. package/tests/desktop-rpc-config.test.ts +1452 -0
  229. package/tests/desktop-rpc-design.test.ts +662 -0
  230. package/tests/desktop-rpc-jobs.test.ts +796 -0
  231. package/tests/desktop-rpc-permissions.test.ts +311 -0
  232. package/tests/desktop-rpc-profiles.test.ts +140 -0
  233. package/tests/desktop-rpc-safety.test.ts +119 -0
  234. package/tests/desktop-rpc-usage.test.ts +697 -0
  235. package/tests/desktop-rpc.test.ts +252 -0
  236. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  237. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  238. package/tests/engram-safety.test.ts +111 -0
  239. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  240. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  241. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
  242. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  243. package/tests/full-delegation-closure.test.ts +29 -0
  244. package/tests/gentle-agents.test.ts +329 -4
  245. package/tests/gentle-ai-binary.test.ts +1 -1
  246. package/tests/gentle-ai-child-guards.test.ts +1 -0
  247. package/tests/gentle-ai-installer.test.ts +52 -51
  248. package/tests/gentle-ai-renderer.test.ts +36 -2
  249. package/tests/gentle-ai.test.ts +121 -6
  250. package/tests/gentle-design.test.ts +365 -1
  251. package/tests/gentle-shell-bundled.test.ts +91 -5
  252. package/tests/gentle-shell-launcher.test.ts +1 -1
  253. package/tests/gentle-shell.test.ts +118 -87
  254. package/tests/gentle-todo.test.ts +32 -9
  255. package/tests/hidden-tools.test.ts +188 -0
  256. package/tests/independent-recovery-delivery.test.ts +19 -5
  257. package/tests/inprocess-reviewer.test.ts +73 -0
  258. package/tests/install-wizard.test.ts +27 -1
  259. package/tests/installer-downloads.test.ts +30 -1
  260. package/tests/installer-posix-bootstrap.test.ts +114 -13
  261. package/tests/installer-preflight.test.ts +49 -1
  262. package/tests/installer-probes.test.ts +146 -0
  263. package/tests/installer-server.test.ts +203 -4
  264. package/tests/installer-windows-bootstrap.test.ts +19 -1
  265. package/tests/judgment-day-severity-admission.test.ts +46 -0
  266. package/tests/lazy-module-contradictions-contract.test.ts +158 -0
  267. package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
  268. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  269. package/tests/model-fallback-policy.test.ts +26 -7
  270. package/tests/nan-provider-runtime.test.ts +17 -3
  271. package/tests/nan-provider.test.ts +111 -56
  272. package/tests/native-review-capability-contract.test.ts +11 -1
  273. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  274. package/tests/native-review-parity.test.ts +24 -5
  275. package/tests/native-review-refusal-identity.test.ts +25 -0
  276. package/tests/no-self-pause-contract.test.ts +11 -3
  277. package/tests/odd-integration.test.ts +11 -3
  278. package/tests/odd-routing-contract.test.ts +80 -28
  279. package/tests/orchestrator-budget.test.ts +30 -5
  280. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  281. package/tests/orchestrator-delegation-mode.test.ts +2 -1
  282. package/tests/orchestrator-discovery.test.ts +28 -0
  283. package/tests/orchestrator-prompt-budget.test.ts +11 -2
  284. package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
  285. package/tests/orchestrator-rdd-ownership.test.ts +2 -1
  286. package/tests/orchestrator-work-search.test.ts +4 -2
  287. package/tests/package-files.test.ts +25 -1
  288. package/tests/package-manifest.test.ts +11 -10
  289. package/tests/parallel-reason-contract.test.ts +6 -3
  290. package/tests/permission-allowlist.test.ts +200 -30
  291. package/tests/persona-neutral-voseo.test.ts +4 -4
  292. package/tests/persona-reply-language.test.ts +1 -1
  293. package/tests/persona-single-channel.test.ts +13 -5
  294. package/tests/pi-update-launcher.test.ts +17 -7
  295. package/tests/pi-update-source.test.ts +113 -6
  296. package/tests/pi-update.test.ts +294 -19
  297. package/tests/pnpm-workspace-policy.test.ts +47 -0
  298. package/tests/primary-context-files.test.ts +233 -0
  299. package/tests/primary-context-three-files.test.ts +174 -0
  300. package/tests/provider-defect-handoff.test.ts +9 -2
  301. package/tests/rdd-aware-verification-contract.test.ts +1 -1
  302. package/tests/rdd-status-line.test.ts +94 -1
  303. package/tests/reply-language-anchor-placement.test.ts +184 -0
  304. package/tests/reply-language-anchor.test.ts +17 -1
  305. package/tests/request-context-append-only.test.ts +218 -0
  306. package/tests/request-context-placement.test.ts +148 -0
  307. package/tests/review-agent-end-preflight.test.ts +79 -1
  308. package/tests/review-candidate-view.test.ts +65 -0
  309. package/tests/review-continuation-registry.test.ts +31 -0
  310. package/tests/review-contract-prompt.test.ts +1 -1
  311. package/tests/review-controller.test.ts +2 -1
  312. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  313. package/tests/review-coordinator-findings.test.ts +206 -0
  314. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  315. package/tests/review-coordinator.test.ts +271 -4
  316. package/tests/review-delivery-preflight.test.ts +462 -0
  317. package/tests/review-due-compaction.test.ts +31 -0
  318. package/tests/review-due-public-boundary.test.ts +26 -0
  319. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  320. package/tests/review-json-arguments.test.ts +41 -2
  321. package/tests/review-ledger-contract.test.ts +19 -40
  322. package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
  323. package/tests/review-one-call-findings.test.ts +131 -0
  324. package/tests/review-one-call-followups.test.ts +308 -0
  325. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  326. package/tests/review-one-call.test.ts +452 -0
  327. package/tests/review-relay-transport-agent.test.ts +28 -1
  328. package/tests/review-reviewer-evidence.test.ts +41 -1
  329. package/tests/review-risk-assessment.test.ts +52 -5
  330. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  331. package/tests/review-session-standing-permission-controller.test.ts +32 -2
  332. package/tests/review-tool-prose-budget.test.ts +1 -0
  333. package/tests/reviewer-stream.test.ts +149 -0
  334. package/tests/session-profile-extension.test.ts +2 -2
  335. package/tests/shell-prompt.test.ts +17 -0
  336. package/tests/shell-usage.test.ts +59 -10
  337. package/tests/skill-contradictions-contract.test.ts +122 -0
  338. package/tests/skill-registry-watcher.test.ts +216 -2
  339. package/tests/skill-registry.test.ts +929 -306
  340. package/tests/support/design-canvas-dom.ts +369 -0
  341. package/tests/support/review-coordinator-runtime.ts +212 -17
  342. package/tests/task-size-routing-contract.test.ts +42 -11
  343. package/tests/test-strength-contract.test.ts +2 -1
  344. package/tests/todo-request-append-only.test.ts +214 -0
  345. package/tests/tool-batching-contract.test.ts +3 -1
  346. package/tests/update-agent-body-history.test.ts +138 -0
  347. package/tests/verification-tiers-contract.test.ts +229 -0
  348. package/tests/verifier-preparation.test.ts +229 -0
  349. package/tests/verify-agent-contract.test.ts +20 -2
  350. package/tests/verify-first-launch-contract.test.ts +87 -11
  351. package/tests/vim-editor-adapter.test.ts +2 -2
  352. package/tests/work-continuity-contract.test.ts +54 -11
  353. package/tests/writer-admission-messages.test.ts +232 -0
  354. package/tests/writer-batch-admission.test.ts +66 -0
  355. package/tests/writer-edit-surface-scope.test.ts +52 -20
  356. package/tests/writer-feature-document-admission.test.ts +184 -0
  357. package/tests/yolo-mode.test.ts +39 -0
  358. package/skills/_shared/review-ledger-contract.md +0 -106
  359. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
  360. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
  361. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
  362. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  363. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
  364. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
  365. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -0,0 +1,491 @@
1
+ // Accessibility checks and the panel's two tabs, Comments and Quality, each with its count.
2
+ // Each design artboard's own frame checks its page when the canvas asks (gd:run-checks, sent when
3
+ // that frame loads; never to an All sizes frame or the system board) and again after each resize
4
+ // (inspector.js gd:checks). Quality lists the findings of each design artboard as the artboard
5
+ // reported them, with Show (zoom in under 100%, center the element, a ring on the canvas that follows
6
+ // it as its page scrolls: inspector.js gd:located) and Ask the agent to fix (the comment box on that
7
+ // element, prefilled). The checks describe the artboard at the size it is shown,
8
+ // and they are heuristics, not a full audit: they miss keyboard, focus-order, motion and screen-reader
9
+ // problems, and each list is capped (20 problems and 10 advice items per check, with the full count reported
10
+ // for the page's first 3000 elements; docs/gentle-shell.md).
11
+ // board.checks is changed in place only by setChecks here; the tab lives in the store (setTab); the
12
+ // ring is this module's own view state, which other modules end through clearMark.
13
+ // Each finding comes with its English title and detail, and with a key and plain vars (inspector.js): the card shows
14
+ // findings[key] over those vars, in the canvas language, or the English it came with when they are missing or do not fit.
15
+ // What Ask the agent to fix prefills (TEXT.session) is English, with the English title and detail.
16
+
17
+ const TEXT = Object.freeze({
18
+ names: { contrast: "Text contrast", target: "Target size", alt: "Images have alt text", label: "Form fields have labels", heading: "Headings in order" },
19
+ boardName: (number, title) => `${String(number).padStart(2, "0")} ${title}`,
20
+ groupLabel: (name) => `Accessibility checks of ${name}`,
21
+ notChecked: "Not checked yet",
22
+ accessible: "Accessible ✓",
23
+ failing: (count) => `${count} ${count === 1 ? "check" : "checks"}`,
24
+ passed: (names) => `Passed: ${names.join(" · ")}`,
25
+ noBoards: "No design artboards to check.",
26
+ kinds: { fail: "Problem", advice: "Advice" },
27
+ hidden: "Out of sight (hidden or off-screen), so Show centers its artboard without a ring.",
28
+ show: "Show",
29
+ showLabel: (title, label, name) => `Show ${title} on ${label} in ${name}`,
30
+ fix: "Ask the agent to fix",
31
+ fixLabel: (title, label) => `Ask the agent to fix ${title} on ${label}`,
32
+ // A finding by its key (inspector.js), over its vars: the same English the inspector sends.
33
+ findings: {
34
+ contrast: { title: "Low contrast", detail: (v) => `"${v.text}" is ${v.ratio} : 1 (${v.foreground} on ${v.background}); WCAG AA needs ${v.needed} : 1.` },
35
+ contrastLarge: { title: "Low contrast", detail: (v) => `"${v.text}" is ${v.ratio} : 1 (${v.foreground} on ${v.background}); WCAG AA needs ${v.needed} : 1 for large text.` },
36
+ targetSmall: { title: "Small touch target", detail: (v) => `${v.name ? `"${v.name}"` : v.element} is ${v.width} × ${v.height} px; WCAG 2.2 asks for ${v.min} × ${v.min} px, or enough space around it that a ${v.min} px circle on it touches no other target.` },
37
+ targetAdvised: { title: "Touch target under 44 px", detail: (v) => `${v.name ? `"${v.name}"` : v.element} is ${v.width} × ${v.height} px; ${v.advised} × ${v.advised} px is recommended for touch.` },
38
+ alt: { title: "Image without alt text", detail: (v) => `${v.source || "The image"} has no alt attribute. Describe it, or use alt="" if it is decorative.` },
39
+ label: { title: "Form field without a label", detail: (v) => `The ${v.field === "select" ? "select" : v.field === "textarea" ? "text area" : `${v.type} field`}${v.hint ? ` "${v.hint}"` : ""} has no label. Add a <label for>, aria-label or aria-labelledby; a placeholder is not a label.` },
40
+ heading: { title: "Heading level skipped", detail: (v) => `h${v.level} "${v.text}" follows h${v.previous}: ${v.missing} ${v.count === 1 ? "is" : "are"} missing.` },
41
+ },
42
+ // What Ask the agent to fix prefills: instructions for the session.
43
+ session: {
44
+ fail: (issue) => `Accessibility check on ${issue.selector}: ${issue.title}.\n${issue.detail}\nFix it so it meets WCAG 2.2 AA, keeping the design's tokens.`,
45
+ advice: (issue) => `Accessibility advice on ${issue.selector}: ${issue.title}.\n${issue.detail}\nConsider fixing it, keeping the design's tokens.`,
46
+ },
47
+ });
48
+
49
+ const TABS = ["comments", "quality"];
50
+ const CHECK_IDS = ["contrast", "target", "alt", "label", "heading"];
51
+ const SEVERITIES = ["fail", "advice"];
52
+ const LIMITS = { checks: 10, issues: 200, title: 80, detail: 400, selector: 500, label: 80, excerpt: 300, comment: 2000, variable: 120 };
53
+ // The vars of each finding key (inspector.js): exactly these, each a string or a finite number.
54
+ const FINDING_VARS = {
55
+ contrast: ["text", "ratio", "foreground", "background", "needed"],
56
+ contrastLarge: ["text", "ratio", "foreground", "background", "needed"],
57
+ targetSmall: ["name", "element", "width", "height", "min"],
58
+ targetAdvised: ["name", "element", "width", "height", "advised"],
59
+ alt: ["source"],
60
+ label: ["field", "type", "hint"],
61
+ heading: ["level", "previous", "text", "missing", "count"],
62
+ };
63
+ // Under SHOW_ZOOM, Show zooms in to it, or less when the element would not fit in SHOW_ROOM of the view at that zoom.
64
+ const SHOW_ZOOM = 1;
65
+ const SHOW_ROOM = 0.8;
66
+ // A press that moves no further than this is a click (canvas-view.js uses the same).
67
+ const CLICK_SLOP = 4;
68
+
69
+ export function init(ctx) {
70
+ const { doc, els, store, api, actions } = ctx;
71
+ const { state } = store;
72
+ const { isFiniteNumber } = api;
73
+ const T = ctx.i18n.text("checks", TEXT);
74
+ // The ring of Show: { board, issue, rect, ring, label, card, recenter } or null (rect: where the element is in its
75
+ // frame, the checks' rect until the frame locates it); the press that may be a still click on the canvas.
76
+ let mark = null;
77
+ let press = null;
78
+ let hiddenNotes = 0;
79
+
80
+ const tabButtons = () => [els.tabComments, els.tabQuality];
81
+ // The artboards of the design shown; a design switch empties it at once, before the new boards are built.
82
+ const designBoards = () => state.boards.filter((board) => board.slug === state.slug);
83
+ const failures = (board) => (board.checks ? board.checks.checks.reduce((sum, check) => sum + check.count, 0) : 0);
84
+ const isCurrent = (board, issue) => designBoards().includes(board) && Boolean(board.checks) && board.checks.issues.includes(issue);
85
+ const isMarked = (board, issue) => Boolean(mark) && mark.board === board && mark.issue === issue;
86
+
87
+ function chip(className, text) {
88
+ const span = doc.createElement("span");
89
+ span.className = className;
90
+ span.textContent = text;
91
+ return span;
92
+ }
93
+
94
+ // ---- what an artboard reports (gd:checks)
95
+
96
+ const wholeCount = (value) => Number.isInteger(value) && value >= 0;
97
+ const bounded = (value, max) => (typeof value === "string" ? value.slice(0, max) : null);
98
+
99
+ /** A report checked field by field (the page is the design's own code, not trusted); null when malformed. */
100
+ function readChecks(data) {
101
+ if (!Array.isArray(data.checks) || data.checks.length > LIMITS.checks || !Array.isArray(data.issues) || data.issues.length > LIMITS.issues) return null;
102
+ const checks = [];
103
+ for (const entry of data.checks) {
104
+ if (!entry || typeof entry !== "object" || !CHECK_IDS.includes(entry.id) || checks.some((check) => check.id === entry.id) || !wholeCount(entry.count) || !wholeCount(entry.advice)) return null;
105
+ checks.push({ id: entry.id, count: entry.count, advice: entry.advice });
106
+ }
107
+ const issues = [];
108
+ for (const raw of data.issues) {
109
+ if (!raw || typeof raw !== "object" || !CHECK_IDS.includes(raw.check) || !SEVERITIES.includes(raw.severity)) return null;
110
+ const title = bounded(raw.title, LIMITS.title);
111
+ const detail = bounded(raw.detail, LIMITS.detail);
112
+ const label = bounded(raw.label, LIMITS.label);
113
+ // The element's text, as a pick sends it (inspector.js excerptOf), for Ask the agent to fix.
114
+ const excerpt = bounded(raw.excerpt, LIMITS.excerpt);
115
+ const selector = typeof raw.selector === "string" ? raw.selector.trim() : "";
116
+ const rect = readRect(raw.rect);
117
+ if (!title || detail === null || label === null || excerpt === null || !selector || selector.length > LIMITS.selector || !rect) return null;
118
+ // Only `hidden: true` means out of sight. A key whose vars do not fit is dropped: the card shows the English.
119
+ const vars = readVars(raw.key, raw.vars);
120
+ issues.push({ check: raw.check, severity: raw.severity, title, detail, selector, label, excerpt, rect, hidden: raw.hidden === true, ...(vars ? { key: raw.key, vars } : {}) });
121
+ }
122
+ return { checks, issues };
123
+ }
124
+
125
+ /** A finding's vars, copied, when its key is known and they are exactly that key's, each a bounded string or a finite number; else null. */
126
+ function readVars(key, raw) {
127
+ if (typeof key !== "string" || !Object.hasOwn(FINDING_VARS, key) || !raw || typeof raw !== "object" || Array.isArray(raw)) return null;
128
+ const names = FINDING_VARS[key];
129
+ if (Object.keys(raw).length !== names.length) return null;
130
+ const vars = {};
131
+ for (const name of names) {
132
+ const value = raw[name];
133
+ if (!(typeof value === "string" && value.length <= LIMITS.variable) && !isFiniteNumber(value)) return null;
134
+ vars[name] = value;
135
+ }
136
+ return vars;
137
+ }
138
+
139
+ /** What a card shows for a finding: findings[key] over its vars in the canvas language, else the English it came with. */
140
+ function shown(issue) {
141
+ if (issue.vars === undefined) return { title: issue.title, detail: issue.detail };
142
+ const finding = T.findings[issue.key];
143
+ return { title: finding.title, detail: finding.detail(issue.vars) };
144
+ }
145
+
146
+ /** A box in a frame's CSS px, copied; null unless it has four finite numbers. */
147
+ function readRect(value) {
148
+ if (!value || typeof value !== "object" || !["x", "y", "width", "height"].every((key) => isFiniteNumber(value[key]))) return null;
149
+ return { x: value.x, y: value.y, width: value.width, height: value.height };
150
+ }
151
+
152
+ /**
153
+ * A gd:checks from `surface` (canvas-messages.js): only a design artboard's own frame, of the design shown, speaks for
154
+ * it, and only about the size it has now: a scan made before its page heard of the latest size (gd:size, canvas-sizes.js
155
+ * resized) is dropped. The result keeps that size (viewport, null at the artboard's own), so Ask the agent to fix files
156
+ * a finding with the size it was found at even after the frame changes size and before its next scan arrives.
157
+ */
158
+ function checksFrom(surface, data) {
159
+ const board = actions.ownerOf(surface);
160
+ if (surface !== board || board.system || !designBoards().includes(board)) return;
161
+ if (data.generation !== surface.generation) return;
162
+ const result = readChecks(data);
163
+ if (result) setChecks(board, { ...result, viewport: actions.viewportOf(surface) });
164
+ }
165
+
166
+ /** The one way board.checks changes: a new result, or null when the artboard reloads. The ring and Quality follow. */
167
+ function setChecks(board, result) {
168
+ board.checks = result;
169
+ if (mark && mark.board === board) followMark();
170
+ renderChecks();
171
+ }
172
+
173
+ /**
174
+ * A frame finished loading (canvas-sizes.js surfaceLoaded): a ring on its artboard goes with the page it was drawn on,
175
+ * and an artboard's own frame is asked to check its new page, whose old result no longer describes it.
176
+ */
177
+ function checksLoaded(surface) {
178
+ const board = actions.ownerOf(surface);
179
+ clearMark(board);
180
+ if (surface !== board || board.system) return;
181
+ board.frame.contentWindow?.postMessage({ type: "gd:run-checks" }, "*");
182
+ if (board.checks) setChecks(board, null);
183
+ }
184
+
185
+ /** The boards changed (placed again, another design, none left): a ring of a board that went goes, and Quality shows what is left. */
186
+ function refreshChecks() {
187
+ if (mark && (!actions.allBoards().includes(mark.board) || mark.board.slug !== state.slug)) clearMark();
188
+ renderChecks();
189
+ }
190
+
191
+ // ---- the tabs and Quality
192
+
193
+ function setTab(name) {
194
+ if (!TABS.includes(name)) return;
195
+ store.setTab(name);
196
+ tabButtons().forEach((tab, index) => {
197
+ const selected = TABS[index] === name;
198
+ tab.setAttribute("aria-selected", String(selected));
199
+ tab.setAttribute("tabindex", selected ? "0" : "-1");
200
+ });
201
+ els.tabpanelComments.hidden = name !== "comments";
202
+ els.quality.hidden = name !== "quality";
203
+ renderChecks();
204
+ }
205
+
206
+ /** Quality's count (problems; advice does not count) and, while it shows, one group per design artboard. */
207
+ function renderChecks() {
208
+ const boards = designBoards();
209
+ // No number until an artboard has reported: 0 would say nothing was found.
210
+ els.countQuality.textContent = boards.some((board) => board.checks) ? String(boards.reduce((sum, board) => sum + failures(board), 0)) : "";
211
+ if (state.tab !== "quality") return;
212
+ // Keyboard focus on a card's button stays on the same button of the same finding across a re-render.
213
+ const active = els.quality.contains(doc.activeElement) ? doc.activeElement : null;
214
+ const keep = active && active.dataset && active.dataset.key ? { key: active.dataset.key, control: active.dataset.control } : null;
215
+ const controls = [];
216
+ els.quality.replaceChildren(...(boards.length === 0 ? [chip("gd-check-empty", T.noBoards)] : boards.map((board) => checkGroup(board, controls))));
217
+ if (keep) (controls.find((control) => control.dataset.key === keep.key && control.dataset.control === keep.control) ?? els.tabQuality).focus();
218
+ }
219
+
220
+ function checkGroup(board, controls) {
221
+ const name = T.boardName(state.boards.indexOf(board) + 1, board.artboard.title);
222
+ const group = doc.createElement("section");
223
+ group.className = "gd-check-group";
224
+ group.setAttribute("aria-label", T.groupLabel(name));
225
+ const head = doc.createElement("div");
226
+ head.className = "gd-check-head";
227
+ const heading = doc.createElement("h3");
228
+ heading.className = "gd-check-heading";
229
+ heading.textContent = name;
230
+ const result = board.checks;
231
+ const count = failures(board);
232
+ const summary = !result ? chip("gd-check-summary", T.notChecked)
233
+ : count === 0 ? chip("gd-check-summary gd-check-summary-ok", T.accessible)
234
+ : chip("gd-check-summary gd-check-summary-fail", T.failing(count));
235
+ head.append(heading, summary);
236
+ group.append(head);
237
+ if (!result) return group;
238
+ group.append(...result.issues.map((issue) => checkCard(board, issue, name, controls)));
239
+ const passed = result.checks.filter((check) => check.count === 0).map((check) => T.names[check.id]);
240
+ if (passed.length > 0) group.append(chip("gd-check-passed", T.passed(passed)));
241
+ return group;
242
+ }
243
+
244
+ function checkCard(board, issue, name, controls) {
245
+ const fail = issue.severity === "fail";
246
+ const card = doc.createElement("article");
247
+ card.className = `gd-check ${fail ? "gd-check-fail" : "gd-check-advice"}`;
248
+ const top = doc.createElement("div");
249
+ top.className = "gd-check-top";
250
+ const words = shown(issue);
251
+ const title = doc.createElement("b");
252
+ title.className = "gd-check-title";
253
+ title.textContent = words.title;
254
+ top.append(title, chip("gd-check-kind", T.kinds[issue.severity]));
255
+ const detail = doc.createElement("small");
256
+ detail.className = "gd-check-detail";
257
+ detail.textContent = words.detail;
258
+ card.append(top, detail);
259
+ const key = [board.artboard.file, issue.check, issue.severity, issue.selector].join("\n");
260
+ const show = doc.createElement("button");
261
+ show.type = "button";
262
+ show.className = "gd-check-show gd-small";
263
+ show.setAttribute("aria-label", T.showLabel(words.title, issue.label, name));
264
+ show.append(actions.icon("i-target", "gd-i gd-i-s"), chip("", T.show));
265
+ show.addEventListener("click", () => showIssue(board, issue, card));
266
+ const fix = doc.createElement("button");
267
+ fix.type = "button";
268
+ fix.className = "gd-check-fix gd-small";
269
+ fix.textContent = T.fix;
270
+ fix.setAttribute("aria-label", T.fixLabel(words.title, issue.label));
271
+ fix.addEventListener("click", () => askAbout(board, issue));
272
+ for (const [control, kind] of [[show, "show"], [fix, "fix"]]) {
273
+ control.dataset.key = key;
274
+ control.dataset.control = kind;
275
+ controls.push(control);
276
+ }
277
+ // Show cannot point at what is out of sight: the card says why nothing is ringed.
278
+ if (issue.hidden) {
279
+ const note = chip("gd-check-hidden", T.hidden);
280
+ note.id = `gd-check-hidden-${++hiddenNotes}`;
281
+ show.setAttribute("aria-describedby", note.id);
282
+ card.append(note);
283
+ }
284
+ const buttons = doc.createElement("div");
285
+ buttons.className = "gd-check-actions";
286
+ buttons.append(show, fix);
287
+ card.append(buttons);
288
+ // A re-render keeps the card of the ring linked to it.
289
+ if (isMarked(board, issue)) {
290
+ mark.card = card;
291
+ setCardMarked(card, true);
292
+ }
293
+ return card;
294
+ }
295
+
296
+ // ---- Show and Ask the agent to fix
297
+
298
+ /**
299
+ * Brings a rect of an artboard (its CSS px) into view: another artboard's focus ends, and with none focused the canvas
300
+ * centers the rect (focus mode cannot pan). With zoomIn, a canvas under SHOW_ZOOM first zooms in about the rect; never out.
301
+ */
302
+ function reveal(board, rect, zoomIn) {
303
+ if (state.focus && state.focus !== board) actions.exitFocus();
304
+ if (state.focus) return;
305
+ const viewport = els.viewport.getBoundingClientRect();
306
+ const frame = board.frame.getBoundingClientRect();
307
+ const scale = frame.width / board.viewWidth || 1;
308
+ const x = frame.left + (rect.x + rect.width / 2) * scale;
309
+ const y = frame.top + (rect.y + rect.height / 2) * scale;
310
+ if (zoomIn && state.zoom < SHOW_ZOOM) {
311
+ const fits = Math.min(SHOW_ZOOM, (viewport.width * SHOW_ROOM) / rect.width, (viewport.height * SHOW_ROOM) / rect.height);
312
+ // Zooming about the rect's center keeps it at (x, y), so the pan below still centers it.
313
+ actions.zoomAt(Math.max(state.zoom, fits), x - viewport.left, y - viewport.top);
314
+ }
315
+ actions.panBy(viewport.left + viewport.width / 2 - x, viewport.top + viewport.height / 2 - y);
316
+ }
317
+
318
+ /** The element highlighted in every frame of its artboard; with `locate`, the ring's frame also says where it is (gd:located). */
319
+ function highlight(board, issue, locate) {
320
+ const ringed = locate ? markSurface(board) : null;
321
+ for (const surface of actions.surfacesOf(board)) surface.frame.contentWindow?.postMessage({ type: "gd:highlight", selector: issue.selector, ...(surface === ringed ? { locate: true } : {}) }, "*");
322
+ }
323
+
324
+ /** Show: the element centered and ringed; one out of sight gets no ring, and its artboard is centered instead. */
325
+ function showIssue(board, issue, card) {
326
+ // A card of a board a reload replaced, or of an older report, points at nothing.
327
+ if (!isCurrent(board, issue)) return;
328
+ if (issue.hidden) {
329
+ clearMark();
330
+ reveal(board, { x: 0, y: 0, width: board.viewWidth, height: board.viewHeight }, false);
331
+ } else {
332
+ reveal(board, issue.rect, true);
333
+ placeMark(board, issue, card);
334
+ }
335
+ highlight(board, issue, !issue.hidden);
336
+ }
337
+
338
+ /** Ask the agent to fix: the comment box on the element, prefilled and editable; in All sizes on the frame as designed. */
339
+ function askAbout(board, issue) {
340
+ if (!isCurrent(board, issue)) return;
341
+ const marked = isMarked(board, issue);
342
+ if (!marked) clearMark();
343
+ reveal(board, issue.rect, false);
344
+ // A ring it keeps goes on following the element.
345
+ highlight(board, issue, marked);
346
+ const sizes = board.sizeFrames;
347
+ const pick = { selector: issue.selector, excerpt: issue.excerpt, rect: issue.rect };
348
+ // On the artboard's own frame the comment records the size the finding was made at, not the size shown now.
349
+ if (sizes.length > 0) actions.openPopover(sizes[sizes.length - 1], pick);
350
+ else actions.openPopover(board, { ...pick, viewport: board.checks.viewport });
351
+ // The English title and detail the finding came with: the request is for the session.
352
+ els.text.value = T.session[issue.severity](issue).slice(0, LIMITS.comment);
353
+ }
354
+
355
+ // ---- the ring of Show
356
+ // Drawn by the canvas, never by the artboard's page, beside the frame the checks ran in: in the world like the pins, so it
357
+ // follows zoom and pan, or on the frame as designed in All sizes. That frame's page says where the element is once Show
358
+ // scrolled it into view and after each scroll (gd:located), so the ring stays on it, and is not drawn while the element is
359
+ // outside the frame. Esc, a still click on the canvas, another Show, a reload of its frame, another size, its frames or its
360
+ // board going, or another design clear it, and the element's highlight in its page with it (gd:clear).
361
+
362
+ /** The frame the checks ran in, which the ring is drawn on: the artboard's own, or in All sizes its frame as designed (the manifest size). */
363
+ function markSurface(board) {
364
+ const sizes = board.sizeFrames;
365
+ return sizes.length > 0 ? sizes[sizes.length - 1] : board;
366
+ }
367
+
368
+ function markHost(board) {
369
+ const surface = markSurface(board);
370
+ return surface === board ? board.frame.parentElement : surface.stage;
371
+ }
372
+
373
+ function setCardMarked(card, marked) {
374
+ if (!card) return;
375
+ card.classList.toggle("gd-check-active", marked);
376
+ if (marked) card.setAttribute("aria-current", "true");
377
+ else card.removeAttribute("aria-current");
378
+ }
379
+
380
+ function placeMark(board, issue, card) {
381
+ clearMark();
382
+ const ring = doc.createElement("div");
383
+ ring.className = `gd-check-mark ${issue.severity === "fail" ? "gd-check-mark-fail" : "gd-check-mark-advice"}`;
384
+ // The card is the accessible path (aria-current); the ring is only drawn.
385
+ ring.setAttribute("aria-hidden", "true");
386
+ const label = chip("gd-check-mark-label", "");
387
+ ring.append(label);
388
+ mark = { board, issue, rect: issue.rect, ring, label, card, recenter: true };
389
+ renderMark();
390
+ markHost(board).append(ring);
391
+ setCardMarked(card, true);
392
+ }
393
+
394
+ /** The ring centered on its element's rect (artboard CSS px), labeled with the check's title; none while outside its frame. */
395
+ function renderMark() {
396
+ const { rect } = mark;
397
+ const surface = markSurface(mark.board);
398
+ mark.ring.hidden = rect.x + rect.width < 0 || rect.y + rect.height < 0 || rect.x > surface.viewWidth || rect.y > surface.viewHeight;
399
+ mark.ring.style.left = `${rect.x + rect.width / 2}px`;
400
+ mark.ring.style.top = `${rect.y + rect.height / 2}px`;
401
+ mark.ring.style.setProperty("--gd-mark-w", `${rect.width}px`);
402
+ mark.ring.style.setProperty("--gd-mark-h", `${rect.height}px`);
403
+ mark.label.textContent = shown(mark.issue).title;
404
+ }
405
+
406
+ /**
407
+ * A new report of the ringed artboard: the ring moves to the same finding (check, kind, element), or goes. Its rect is in
408
+ * the report's frame, the artboard's own: in All sizes the ring is on the frame as designed, whose page keeps saying where
409
+ * the element is (gd:located), so the ring stays where that frame located it.
410
+ */
411
+ function followMark() {
412
+ const { board, issue } = mark;
413
+ const same = board.checks ? board.checks.issues.find((entry) => entry.check === issue.check && entry.severity === issue.severity && entry.selector === issue.selector) : null;
414
+ if (!same || same.hidden) {
415
+ clearMark();
416
+ return;
417
+ }
418
+ mark.issue = same;
419
+ if (markSurface(board) === board) mark.rect = same.rect;
420
+ renderMark();
421
+ }
422
+
423
+ /**
424
+ * A gd:located from `surface` (canvas-messages.js): where the ringed element is now, said only by the frame the ring is
425
+ * drawn on and only for its element. The ring moves there; the first report after Show also centers it, since Show
426
+ * centered where the checks saw it, before the page scrolled it into view.
427
+ */
428
+ function locatedFrom(surface, data) {
429
+ if (!mark || surface !== markSurface(mark.board) || data.selector !== mark.issue.selector) return;
430
+ const rect = readRect(data.rect);
431
+ if (!rect) return;
432
+ mark.rect = rect;
433
+ renderMark();
434
+ if (!mark.recenter) return;
435
+ mark.recenter = false;
436
+ if (!state.focus || state.focus === mark.board) reveal(mark.board, rect, false);
437
+ }
438
+
439
+ /** Removes the ring (with `board`, only a ring on that artboard); true when there was one. */
440
+ function clearMark(board) {
441
+ if (!mark || (board && mark.board !== board)) return false;
442
+ const { ring, card } = mark;
443
+ const ringed = mark.board;
444
+ mark = null;
445
+ ring.remove();
446
+ setCardMarked(card, false);
447
+ // The element's highlight in its page goes too, and the page stops saying where it is; a board that went has no page.
448
+ if (designBoards().includes(ringed)) for (const surface of actions.surfacesOf(ringed)) surface.frame.contentWindow?.postMessage({ type: "gd:clear" }, "*");
449
+ return true;
450
+ }
451
+
452
+ // A still click on the canvas (its background, an artboard's shield or header) clears the ring; a drag pans and keeps it.
453
+ els.viewport.addEventListener("pointerdown", (event) => {
454
+ const target = event.target;
455
+ const onCanvas = target === els.viewport || target === els.world || Boolean(target.closest(".gd-shield, .gd-artboard-label"));
456
+ press = mark && event.button === 0 && onCanvas && !target.closest("button") ? { id: event.pointerId, x: event.clientX, y: event.clientY } : null;
457
+ });
458
+ els.viewport.addEventListener("pointerup", (event) => {
459
+ const start = press;
460
+ press = null;
461
+ if (start && start.id === event.pointerId && Math.abs(event.clientX - start.x) <= CLICK_SLOP && Math.abs(event.clientY - start.y) <= CLICK_SLOP) clearMark();
462
+ });
463
+
464
+ // Esc clears the ring after what owns Esc already (the comment box, Compare, a menu, a dialog) and before the selected
465
+ // artboard (canvas-layout.js, registered after this) and Comment mode (canvas-popover.js).
466
+ doc.addEventListener("keydown", (event) => {
467
+ if (event.defaultPrevented || event.key !== "Escape" || event.shiftKey || !mark) return;
468
+ if (state.compare || state.menu || !els.popover.hidden || els.shortcuts.hasAttribute("open")) return;
469
+ event.preventDefault();
470
+ clearMark();
471
+ });
472
+
473
+ tabButtons().forEach((tab, index) => tab.addEventListener("click", () => setTab(TABS[index])));
474
+ // The arrows (wrapping around), Home and End move between the tabs, focus with them.
475
+ els.tabs.addEventListener("keydown", (event) => {
476
+ const current = TABS.indexOf(state.tab);
477
+ const next = { ArrowRight: (current + 1) % TABS.length, ArrowLeft: (current + TABS.length - 1) % TABS.length, Home: 0, End: TABS.length - 1 }[event.key];
478
+ if (next === undefined) return;
479
+ event.preventDefault();
480
+ setTab(TABS[next]);
481
+ tabButtons()[next].focus();
482
+ });
483
+
484
+ /** A new language: Quality's cards (focus kept, as on any re-render) and the ring's label, in place. */
485
+ function relabel() {
486
+ renderChecks();
487
+ if (mark) renderMark();
488
+ }
489
+
490
+ return { relabel, checksFrom, locatedFrom, setChecks, checksLoaded, refreshChecks, renderChecks, setTab, clearMark };
491
+ }