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,299 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { click, inspectorPick, loadCanvas, read, texts, type CanvasFixture, type FakeElement } from "./support/design-canvas-dom.ts";
4
+
5
+ // The view transform: pan, zoom, Fit and refit (canvas-view.js).
6
+
7
+ // In Move mode a drag on an artboard moves it (tests/design-canvas-layout.test.ts); in Comment mode it pans, as before.
8
+ const commentMode = (canvas: CanvasFixture) => canvas.document.getElementById("gd-comment").dispatch("click");
9
+
10
+ test("in comment mode a drag over an artboard pans the canvas and a click is routed to the inspector as a pick", async () => {
11
+ const canvas = await loadCanvas();
12
+ const [first] = canvas.boards;
13
+ first.frame.rect = { left: 100, top: 100, width: 200, height: 150 };
14
+ const before = canvas.world.style.transform;
15
+ commentMode(canvas);
16
+ first.shield!.dispatch("pointerdown", { button: 0, pointerId: 1, clientX: 150, clientY: 150 });
17
+ first.shield!.dispatch("pointermove", { pointerId: 1, clientX: 190, clientY: 170 });
18
+ first.shield!.dispatch("pointerup", { button: 0, pointerId: 1, clientX: 190, clientY: 170 });
19
+ assert.notEqual(canvas.world.style.transform, before, "the drag panned");
20
+ assert.equal(canvas.navMode.textContent, "Navigating", "a drag never enters focus mode");
21
+
22
+ click(first.shield!, 150, 130);
23
+ assert.equal(canvas.navMode.textContent, "Navigating", "comment mode picks instead of focusing");
24
+ // The frame shows a 400x300 artboard at half size: (150-100)/0.5, (130-100)/0.5.
25
+ assert.deepEqual(first.frame.contentWindow!.posted.at(-1), { type: "gd:pick-at", x: 100, y: 60 });
26
+ });
27
+
28
+ // The third field: the target is part of an artboard, so it pans in Comment mode.
29
+ const panTargets: Array<[string, (canvas: CanvasFixture) => FakeElement, boolean]> = [
30
+ ["viewport", (canvas) => canvas.viewport, false],
31
+ ["gap between artboards", (canvas) => canvas.world, false],
32
+ ["artboard gap", (canvas) => canvas.boards[0].wrapper, true],
33
+ ["frame box", (canvas) => canvas.boards[0].frame.parentElement!, true],
34
+ ["artboard title", (canvas) => canvas.boards[0].wrapper.children[0].children[0], true],
35
+ ["actions gap", (canvas) => canvas.boards[0].wrapper.children[0].children.find((child) => child.classes.has("gd-board-actions"))!, true],
36
+ ["shield", (canvas) => canvas.boards[0].shield!, true],
37
+ ];
38
+
39
+ for (const [name, targetOf, onArtboard] of panTargets) {
40
+ test(`navigation pan starts on ${name}${onArtboard ? " in comment mode" : ""} without selecting`, async () => {
41
+ const canvas = await loadCanvas();
42
+ if (onArtboard) commentMode(canvas);
43
+ const target = targetOf(canvas);
44
+ const down = target.dispatch("pointerdown", { button: 0, pointerId: 7, clientX: 10, clientY: 10 });
45
+ canvas.viewport.dispatch("pointermove", { pointerId: 7, clientX: 45, clientY: 30 });
46
+ assert.equal(canvas.world.style.transform, "translate(83px, 68px) scale(1)");
47
+ assert.equal(down.defaultPrevented, true, "only an accepted pan suppresses the pointer default");
48
+ assert.deepEqual(canvas.viewport.capturedPointers, [7]);
49
+ assert.equal(canvas.viewport.classes.has("gd-panning"), true);
50
+ canvas.viewport.dispatch("pointerup", { button: 0, pointerId: 7, clientX: 45, clientY: 30 });
51
+ assert.equal(canvas.viewport.classes.has("gd-panning"), false);
52
+ assert.equal(canvas.navMode.textContent, "Navigating", "a drag does not focus a shield");
53
+ });
54
+ }
55
+
56
+ test("navigation pan cancels a stale native drag and continues until pointerup", async () => {
57
+ const canvas = await loadCanvas();
58
+ commentMode(canvas);
59
+ const title = canvas.boards[0].wrapper.children[0].children[0];
60
+ assert.equal(title.dispatch("dragstart").defaultPrevented, true, "a native viewport drag is canceled even before a pan");
61
+ const down = title.dispatch("pointerdown", { button: 0, pointerId: 2, clientX: 10, clientY: 10 });
62
+ const dragstart = title.dispatch("dragstart");
63
+ assert.equal(dragstart.defaultPrevented, true, "an old selection cannot start a native drag");
64
+ assert.equal(down.defaultPrevented, true);
65
+ canvas.viewport.dispatch("pointermove", { pointerId: 2, clientX: 40, clientY: 25 });
66
+ assert.equal(canvas.world.style.transform, "translate(78px, 63px) scale(1)");
67
+ canvas.viewport.dispatch("pointerup", { pointerId: 2, clientX: 40, clientY: 25 });
68
+ assert.equal(canvas.viewport.classes.has("gd-panning"), false);
69
+ });
70
+
71
+ test("navigation pan leaves secondary buttons and interactive descendants to the browser", async () => {
72
+ const canvas = await loadCanvas();
73
+ commentMode(canvas);
74
+ const label = canvas.boards[0].wrapper.children[0];
75
+ const before = canvas.world.style.transform;
76
+ const secondary = label.dispatch("pointerdown", { button: 2, pointerId: 1, clientX: 10, clientY: 10 });
77
+ assert.equal(secondary.defaultPrevented, false);
78
+ canvas.viewport.dispatch("pointermove", { pointerId: 1, clientX: 40, clientY: 25 });
79
+ assert.equal(canvas.world.style.transform, before);
80
+ for (const name of ["button", "a", "input", "select", "textarea", "iframe", "editable", "plaintext-only"]) {
81
+ const control = canvas.document.createElement(name === "editable" || name === "plaintext-only" ? "div" : name);
82
+ if (name === "editable" || name === "plaintext-only") control.setAttribute("contenteditable", name === "editable" ? "true" : name);
83
+ const child = canvas.document.createElement("span");
84
+ control.append(child);
85
+ label.append(control);
86
+ const down = child.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 10, clientY: 10 });
87
+ assert.equal(down.defaultPrevented, false, `${name} pointer default`);
88
+ assert.equal(child.dispatch("dragstart").defaultPrevented, false, `${name} native drag default`);
89
+ canvas.viewport.dispatch("pointermove", { pointerId: 3, clientX: 40, clientY: 25 });
90
+ canvas.viewport.dispatch("pointerup", { pointerId: 3, clientX: 40, clientY: 25 });
91
+ assert.equal(canvas.world.style.transform, before, `${name} did not pan`);
92
+ assert.equal(canvas.viewport.classes.has("gd-panning"), false);
93
+ }
94
+ assert.deepEqual(canvas.viewport.capturedPointers, []);
95
+ const editable = canvas.document.createElement("div");
96
+ editable.setAttribute("contenteditable", "true");
97
+ const noneditable = canvas.document.createElement("div");
98
+ noneditable.setAttribute("contenteditable", "false");
99
+ editable.append(noneditable);
100
+ label.append(editable);
101
+ assert.equal(noneditable.dispatch("pointerdown", { button: 0, pointerId: 6, clientX: 10, clientY: 10 }).defaultPrevented, true);
102
+ canvas.viewport.dispatch("pointermove", { pointerId: 6, clientX: 40, clientY: 25 });
103
+ canvas.viewport.dispatch("pointerup", { pointerId: 6, clientX: 40, clientY: 25 });
104
+ assert.equal(canvas.world.style.transform, "translate(78px, 63px) scale(1)", "noneditable descendants remain pannable");
105
+ });
106
+
107
+ test("navigation pan preserves implement controls, comment pins and toolbar zoom", async () => {
108
+ const comment = { id: "abc123", file: "01-a.html", selector: "h1", excerpt: "First", comment: "Update", status: "open", sentAt: null };
109
+ const canvas = await loadCanvas(300, { "/t/api/designs/alpha/comments": { comments: [comment] } });
110
+ commentMode(canvas);
111
+ const board = canvas.boards[0];
112
+ const label = board.wrapper.children[0];
113
+ const actions = label.children.find((child) => child.classes.has("gd-board-actions"))!;
114
+ const implement = actions.children.find((child) => child.classes.has("gd-implement"))!;
115
+ const start = implement.children.find((child) => child.classes.has("gd-implement-start"))!;
116
+ const before = canvas.world.style.transform;
117
+ assert.equal(start.dispatch("pointerdown", { button: 0, pointerId: 1, clientX: 10, clientY: 10 }).defaultPrevented, false);
118
+ canvas.viewport.dispatch("pointermove", { pointerId: 1, clientX: 30, clientY: 30 });
119
+ canvas.viewport.dispatch("pointerup", { pointerId: 1, clientX: 30, clientY: 30 });
120
+ assert.equal(canvas.world.style.transform, before);
121
+ start.dispatch("click");
122
+ const confirm = implement.children.find((child) => child.classes.has("gd-implement-confirm"))!;
123
+ assert.equal(confirm.hidden, false);
124
+ assert.equal(canvas.document.activeElement, confirm.children[1]);
125
+ // The text in the confirmation is not a control and can start a pan.
126
+ const down = confirm.children[0].dispatch("pointerdown", { button: 0, pointerId: 2, clientX: 10, clientY: 10 });
127
+ canvas.viewport.dispatch("pointermove", { pointerId: 2, clientX: 20, clientY: 20 });
128
+ canvas.viewport.dispatch("pointerup", { pointerId: 2, clientX: 20, clientY: 20 });
129
+ assert.equal(canvas.world.style.transform, "translate(58px, 58px) scale(1)");
130
+ assert.equal(down.defaultPrevented, true);
131
+
132
+ canvas.message(board.frame.contentWindow, { type: "gd:pin-rects", rects: [{ id: comment.id, rect: { x: 10, y: 10, width: 30, height: 20 } }] });
133
+ const pins = board.frame.parentElement!.children.find((child) => child.classes.has("gd-pins"))!;
134
+ const pin = pins.children[0];
135
+ const beforePin = canvas.world.style.transform;
136
+ assert.equal(pin.dispatch("pointerdown", { button: 0, pointerId: 3, clientX: 10, clientY: 10 }).defaultPrevented, false);
137
+ canvas.viewport.dispatch("pointermove", { pointerId: 3, clientX: 40, clientY: 40 });
138
+ canvas.viewport.dispatch("pointerup", { pointerId: 3, clientX: 40, clientY: 40 });
139
+ assert.equal(canvas.world.style.transform, beforePin);
140
+ pin.dispatch("click");
141
+ assert.deepEqual(board.frame.contentWindow!.posted.at(-1), { type: "gd:highlight", id: comment.id });
142
+ assert.equal(canvas.document.getElementById("gd-comment-list").children[0].classes.has("gd-active"), true);
143
+ canvas.document.getElementById("gd-zoom-in").dispatch("click");
144
+ assert.equal(canvas.zoomLevel.textContent, "125%");
145
+ });
146
+
147
+ test("navigation pan does not cancel defaults or move the canvas in focus mode", async () => {
148
+ const canvas = await loadCanvas();
149
+ const board = canvas.boards[0];
150
+ click(board.shield!, 10, 10);
151
+ assert.equal(canvas.document.activeElement, board.frame);
152
+ const before = canvas.world.style.transform;
153
+ const title = board.wrapper.children[0].children[0];
154
+ const down = title.dispatch("pointerdown", { button: 0, pointerId: 5, clientX: 10, clientY: 10 });
155
+ assert.equal(down.defaultPrevented, false);
156
+ assert.equal(title.dispatch("dragstart").defaultPrevented, false);
157
+ assert.equal(board.frame.dispatch("pointerdown", { button: 0, pointerId: 8, clientX: 10, clientY: 10 }).defaultPrevented, false);
158
+ assert.equal(board.frame.dispatch("dragstart").defaultPrevented, false);
159
+ canvas.viewport.dispatch("pointermove", { pointerId: 5, clientX: 40, clientY: 25 });
160
+ canvas.viewport.dispatch("pointerup", { pointerId: 5, clientX: 40, clientY: 25 });
161
+ assert.equal(canvas.world.style.transform, before);
162
+ assert.equal(canvas.viewport.classes.has("gd-panning"), false);
163
+ assert.equal(canvas.document.activeElement, board.frame);
164
+ });
165
+
166
+ test("navigation pan preserves keyboard activation of the artboard shield", async () => {
167
+ const canvas = await loadCanvas();
168
+ const board = canvas.boards[0];
169
+ const key = board.shield!.dispatch("keydown", { key: "Enter" });
170
+ assert.equal(key.defaultPrevented, true);
171
+ assert.equal(canvas.document.activeElement, board.frame);
172
+ assert.match(canvas.navMode.textContent, /^Using: First/);
173
+ canvas.document.getElementById("gd-back").dispatch("click");
174
+ assert.equal(canvas.document.activeElement, canvas.viewport);
175
+ assert.equal(canvas.navMode.textContent, "Navigating");
176
+ });
177
+
178
+ test("navigation pan ends on pointercancel without focusing the shield", async () => {
179
+ const canvas = await loadCanvas();
180
+ const shield = canvas.boards[0].shield!;
181
+ const down = shield.dispatch("pointerdown", { button: 0, pointerId: 4, clientX: 10, clientY: 10 });
182
+ assert.equal(down.defaultPrevented, true);
183
+ canvas.viewport.dispatch("pointercancel", { pointerId: 4, clientX: 10, clientY: 10 });
184
+ canvas.viewport.dispatch("pointermove", { pointerId: 4, clientX: 40, clientY: 25 });
185
+ assert.equal(canvas.world.style.transform, "translate(48px, 48px) scale(1)");
186
+ assert.equal(canvas.viewport.classes.has("gd-panning"), false);
187
+ assert.equal(canvas.navMode.textContent, "Navigating");
188
+ });
189
+
190
+ test("navigation pan declares selection suppression without disabling editable text", () => {
191
+ const css = read("canvas.css");
192
+ const viewport = /\.gd-viewport\s*\{([^}]*)\}/.exec(css)?.[1] ?? "";
193
+ assert.match(viewport, /(?:^|;)\s*-webkit-user-select:\s*none\s*;/);
194
+ assert.match(viewport, /(?:^|;)\s*user-select:\s*none\s*;/);
195
+ const editable = /\.gd-viewport input,\s*\.gd-viewport textarea,\s*\.gd-viewport \[contenteditable\]:not\(\[contenteditable="false"\]\)\s*\{([^}]*)\}/.exec(css)?.[1] ?? "";
196
+ assert.match(editable, /(?:^|;)\s*-webkit-user-select:\s*text\s*;/);
197
+ assert.match(editable, /(?:^|;)\s*user-select:\s*text\s*;/);
198
+ const focused = /\.gd-viewport\.gd-focused\s*\{([^}]*)\}/.exec(css)?.[1] ?? "";
199
+ assert.match(focused, /(?:^|;)\s*-webkit-user-select:\s*auto\s*;/);
200
+ assert.match(focused, /(?:^|;)\s*user-select:\s*auto\s*;/);
201
+ });
202
+
203
+ test("the overview fits again when the window settles at another size, until you zoom or pan yourself", async () => {
204
+ const canvas = await loadCanvas();
205
+ Object.defineProperty(canvas.world, "offsetWidth", { get: () => 9000 });
206
+ Object.defineProperty(canvas.world, "offsetHeight", { get: () => 1000 });
207
+ // A browser window that opens small and is then given its size (a tiling window manager, a restored window).
208
+ canvas.viewport.rect = { left: 0, top: 50, width: 400, height: 300 };
209
+ canvas.document.getElementById("gd-fit").dispatch("click");
210
+ assert.equal(canvas.zoomLevel.textContent, "5%");
211
+ canvas.viewport.rect = { left: 0, top: 50, width: 1800, height: 900 };
212
+ canvas.windowEvent("resize");
213
+ const settled = canvas.zoomLevel.textContent;
214
+ canvas.document.getElementById("gd-fit").dispatch("click");
215
+ assert.deepEqual([settled, canvas.zoomLevel.textContent], ["19%", "19%"], "the same view Fit gives at the new size");
216
+ // Once you zoom, a resize leaves your view alone.
217
+ canvas.viewport.dispatch("wheel", { deltaX: 0, deltaY: -40, deltaMode: 0, ctrlKey: true, metaKey: false, shiftKey: false, clientX: 300, clientY: 300 });
218
+ const zoomed = canvas.world.style.transform;
219
+ canvas.viewport.rect = { left: 0, top: 50, width: 400, height: 300 };
220
+ canvas.windowEvent("resize");
221
+ assert.equal(canvas.world.style.transform, zoomed);
222
+ // Fit starts following the viewport again; a pan of yours ends it too.
223
+ canvas.document.getElementById("gd-fit").dispatch("click");
224
+ canvas.viewport.dispatch("wheel", { deltaX: 0, deltaY: 40, deltaMode: 0, ctrlKey: false, metaKey: false, shiftKey: false, clientX: 300, clientY: 300 });
225
+ const panned = canvas.world.style.transform;
226
+ canvas.viewport.rect = { left: 0, top: 50, width: 1800, height: 900 };
227
+ canvas.windowEvent("resize");
228
+ assert.equal(canvas.world.style.transform, panned);
229
+ assert.equal(canvas.zoomLevel.textContent, "5%");
230
+ });
231
+
232
+ test("the overview fits again when the review panel opens or closes, also where ResizeObserver is missing", async () => {
233
+ const canvas = await loadCanvas();
234
+ Object.defineProperty(canvas.world, "offsetWidth", { get: () => 9000 });
235
+ Object.defineProperty(canvas.world, "offsetHeight", { get: () => 1000 });
236
+ canvas.viewport.rect = { left: 0, top: 50, width: 400, height: 300 };
237
+ canvas.document.getElementById("gd-fit").dispatch("click");
238
+ assert.equal(canvas.zoomLevel.textContent, "5%");
239
+ // Closing the panel gives the viewport its width; no window resize event fires.
240
+ canvas.viewport.rect = { left: 0, top: 50, width: 1800, height: 900 };
241
+ canvas.document.getElementById("gd-panel-toggle").dispatch("click");
242
+ assert.equal(canvas.zoomLevel.textContent, "19%");
243
+ });
244
+
245
+ test("a comment being written keeps its element and view when the panel toggles on a fitted overview", async () => {
246
+ const canvas = await loadCanvas();
247
+ const [first] = canvas.boards;
248
+ Object.defineProperty(canvas.world, "offsetWidth", { get: () => 9000 });
249
+ Object.defineProperty(canvas.world, "offsetHeight", { get: () => 1000 });
250
+ canvas.viewport.rect = { left: 0, top: 50, width: 400, height: 300 };
251
+ canvas.document.getElementById("gd-fit").dispatch("click");
252
+ canvas.document.getElementById("gd-comment").dispatch("click");
253
+ canvas.message(first.frame.contentWindow, inspectorPick(first.frame, { type: "gd:pick", selector: "#cta", excerpt: "Buy now", rect: { x: 4, y: 8, width: 60, height: 20 } }));
254
+ const popover = canvas.document.getElementById("gd-popover");
255
+ assert.equal(popover.hidden, false);
256
+ const view = canvas.world.style.transform;
257
+ canvas.viewport.rect = { left: 0, top: 50, width: 1800, height: 900 };
258
+ canvas.document.getElementById("gd-panel-toggle").dispatch("click");
259
+ assert.equal(popover.hidden, false, "the comment box stays open");
260
+ assert.equal(canvas.document.getElementById("gd-popover-target").textContent, "01-a.html · #cta");
261
+ assert.equal(canvas.world.style.transform, view, "the view waits until the comment box closes");
262
+ // Once it closes, the next size change fits again.
263
+ canvas.document.getElementById("gd-popover-cancel").dispatch("click");
264
+ canvas.windowEvent("resize");
265
+ assert.equal(canvas.zoomLevel.textContent, "19%");
266
+ });
267
+
268
+ test("a pick on another artboard clears the previous artboard's pick; a new pick on the same artboard does not", async () => {
269
+ const canvas = await loadCanvas();
270
+ const [first, second] = canvas.boards;
271
+ commentMode(canvas);
272
+ const pick = { type: "gd:pick", selector: "#cta", excerpt: "Buy now", rect: { x: 4, y: 8, width: 60, height: 20 } };
273
+ const clears = (board: typeof first) => board.frame.contentWindow!.posted.filter((message) => message.type === "gd:clear").length;
274
+ canvas.message(first.frame.contentWindow, inspectorPick(first.frame, pick));
275
+ canvas.message(first.frame.contentWindow, inspectorPick(first.frame, { ...pick, selector: "#title" }));
276
+ assert.equal(clears(first), 0, "the same artboard replaces its own pick");
277
+ canvas.message(second.frame.contentWindow, inspectorPick(second.frame, pick));
278
+ assert.equal(clears(first), 1, "the first artboard's highlight is cleared");
279
+ assert.equal(clears(second), 0);
280
+ assert.equal(canvas.document.getElementById("gd-popover-target").textContent, "02-b.html · #cta");
281
+ });
282
+
283
+ test("a comment whose element reports a 0x0 rect (hidden or not rendered) gets no pin", async () => {
284
+ const comments = [
285
+ { id: "hidden1", file: "01-a.html", selector: "#gone", excerpt: "", comment: "Hidden", status: "open", sentAt: null },
286
+ { id: "shown01", file: "01-a.html", selector: "h1", excerpt: "First", comment: "Shown", status: "open", sentAt: null },
287
+ ];
288
+ const canvas = await loadCanvas(300, { "/t/api/designs/alpha/comments": { comments } });
289
+ const board = canvas.boards[0];
290
+ canvas.message(board.frame.contentWindow, { type: "gd:pin-rects", rects: [
291
+ { id: "hidden1", rect: { x: 0, y: 0, width: 0, height: 0 } },
292
+ { id: "shown01", rect: { x: 10, y: 10, width: 30, height: 20 } },
293
+ ] });
294
+ const pins = board.frame.parentElement!.children.find((child) => child.classes.has("gd-pins"))!;
295
+ assert.deepEqual(pins.children.map((pin) => pin.dataset.id), ["shown01"], "no pin at the artboard's corner for the hidden element");
296
+ const items = canvas.document.getElementById("gd-comment-list").children;
297
+ assert.equal(items.length, 2, "the hidden element's comment stays in the list");
298
+ assert.ok(items.every((item) => texts(item, "gd-badge-detached").length === 0), "a hidden element is not a detached comment");
299
+ });
@@ -4,7 +4,7 @@ import { tmpdir } from "node:os";
4
4
  import { join } from "node:path";
5
5
  import type { TestContext } from "node:test";
6
6
  import test from "node:test";
7
- import { DesignCommentsError, MAX_DESIGN_COMMENTS, MAX_DESIGN_SCREENSHOT_BYTES, createDesignCommentStore } from "../lib/design-comments.ts";
7
+ import { DesignCommentsError, MAX_DESIGN_COMMENTS, MAX_DESIGN_SCREENSHOT_BYTES, createDesignCommentStore, describeViewport, normalizeNote } from "../lib/design-comments.ts";
8
8
 
9
9
  // design/<slug>/comments.json has one owner: every read and write goes through
10
10
  // lib/design-comments.ts, so the canvas server and the agent tool serialize.
@@ -199,3 +199,203 @@ test("a stored screenshot path outside .screenshots makes comments.json invalid,
199
199
  await assert.rejects(store.add("alpha", { ...INPUT, screenshot: { mimeType: "image/png", data: PNG } }), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-file");
200
200
  assert.deepEqual(readdirSync(outside), []);
201
201
  });
202
+
203
+ // S7: the optional viewport a comment was made at.
204
+
205
+ const VIEWPORT = { width: 390, height: 844 };
206
+ const stored = (extra: Record<string, unknown> = {}) => ({ id: "a1", ...INPUT, createdAt: FIXED.toISOString(), status: "open", sentAt: null, resolvedAt: null, ...extra });
207
+
208
+ test("S7: a comment added with a viewport stores it; without one the key is absent", async (t) => {
209
+ const root = designRoot(t);
210
+ const store = fixedStore(root);
211
+ const withViewport = await store.add("alpha", { ...INPUT, viewport: VIEWPORT });
212
+ assert.deepEqual(withViewport, { id: "id0000", ...INPUT, viewport: VIEWPORT, createdAt: FIXED.toISOString(), status: "open", sentAt: null, resolvedAt: null });
213
+ const plain = await store.add("alpha", INPUT);
214
+ assert.equal("viewport" in plain, false, "never written when absent");
215
+ const onDisk = JSON.parse(readFileSync(join(root, "alpha", "comments.json"), "utf8"));
216
+ assert.deepEqual(onDisk.comments[0].viewport, VIEWPORT);
217
+ assert.equal("viewport" in onDisk.comments[1], false);
218
+ assert.deepEqual(await store.read("alpha"), onDisk);
219
+ // The bounds are inclusive.
220
+ for (const edge of [{ width: 240, height: 1 }, { width: 4096, height: 20000 }]) assert.deepEqual((await store.add("alpha", { ...INPUT, viewport: edge })).viewport, edge);
221
+ });
222
+
223
+ test("S7: an invalid viewport is refused before anything is written", async (t) => {
224
+ const root = designRoot(t);
225
+ const store = fixedStore(root);
226
+ const invalid: unknown[] = [
227
+ { width: 239, height: 844 }, { width: 4097, height: 844 }, { width: 390, height: 0 }, { width: 390, height: 20001 },
228
+ { width: 390.5, height: 844 }, { width: "390", height: 844 }, { width: 390 }, { height: 844 }, {}, null, [], "390x844", 390,
229
+ { width: Number.NaN, height: 844 }, { width: Infinity, height: 844 },
230
+ ];
231
+ for (const viewport of invalid) {
232
+ await assert.rejects(store.add("alpha", { ...INPUT, viewport } as never), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-input" && /viewport/.test(error.message), JSON.stringify(viewport));
233
+ }
234
+ assert.deepEqual(readdirSync(join(root, "alpha")), [], "comments.json was not created");
235
+ });
236
+
237
+ test("S7: a comments.json with a valid viewport reads; one without it stays valid; an invalid one makes the file invalid and is never overwritten", async (t) => {
238
+ const root = designRoot(t);
239
+ const store = createDesignCommentStore(root);
240
+ const path = join(root, "alpha", "comments.json");
241
+ writeFileSync(path, JSON.stringify({ version: 1, comments: [stored({ viewport: VIEWPORT }), stored({ id: "a2" })] }));
242
+ const { comments } = await store.read("alpha");
243
+ assert.deepEqual(comments[0].viewport, VIEWPORT);
244
+ assert.equal("viewport" in comments[1], false);
245
+ // Other writes keep the viewport.
246
+ await store.setStatus("alpha", ["a1"], "resolved");
247
+ assert.deepEqual(JSON.parse(readFileSync(path, "utf8")).comments[0].viewport, VIEWPORT);
248
+
249
+ for (const viewport of [{ width: 100, height: 844 }, { width: 390, height: 99999 }, { width: 390 }, "wide", null, [], { width: 390.5, height: 1 }]) {
250
+ const bytes = JSON.stringify({ version: 1, comments: [stored({ viewport })] });
251
+ writeFileSync(path, bytes);
252
+ await assert.rejects(store.read("alpha"), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-file" && /comments\[0\]: viewport/.test(error.message), bytes);
253
+ await assert.rejects(store.add("alpha", INPUT), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-file");
254
+ assert.equal(readFileSync(path, "utf8"), bytes, "bytes unchanged");
255
+ }
256
+ });
257
+
258
+ test("S7: describeViewport names the Phone and Tablet presets and otherwise reads width × height", () => {
259
+ assert.equal(describeViewport({ width: 390, height: 844 }), "Phone 390 × 844");
260
+ assert.equal(describeViewport({ width: 820, height: 1180 }), "Tablet 820 × 1180");
261
+ assert.equal(describeViewport({ width: 720, height: 820 }), "720 × 820");
262
+ assert.equal(describeViewport({ width: 390, height: 900 }), "390 × 900", "the preset name needs the preset height too");
263
+ });
264
+
265
+ // S5: the agent's one-line reply on a resolved comment.
266
+
267
+ test("S5: setStatus resolved with a note stores it, trimmed, as the comment's resolution", async (t) => {
268
+ const root = designRoot(t);
269
+ const store = fixedStore(root);
270
+ const a = await store.add("alpha", INPUT);
271
+ const b = await store.add("alpha", INPUT);
272
+ const result = await store.setStatus("alpha", [a.id], "resolved", { note: " Made the title 32px.\r\n " });
273
+ assert.equal(result.updated[0].resolution, "Made the title 32px.");
274
+ const onDisk = JSON.parse(readFileSync(join(root, "alpha", "comments.json"), "utf8")).comments;
275
+ assert.equal(onDisk[0].resolution, "Made the title 32px.");
276
+ assert.equal("resolution" in onDisk[1], false, "comments resolved or open without a note never get the key");
277
+ assert.equal((await store.read("alpha")).comments.find((comment) => comment.id === b.id)!.resolution, undefined);
278
+ });
279
+
280
+ test("S11: the resolution note is one line: line breaks and the whitespace around them become one space", async (t) => {
281
+ const root = designRoot(t);
282
+ const store = fixedStore(root);
283
+ const a = await store.add("alpha", INPUT);
284
+ const result = await store.setStatus("alpha", [a.id], "resolved", { note: " Made the title 32px. \r\n\n Kept the spacing.\rDone\n " });
285
+ assert.equal(result.updated[0].resolution, "Made the title 32px. Kept the spacing. Done", "spaces inside a line are kept");
286
+ assert.equal(JSON.parse(readFileSync(join(root, "alpha", "comments.json"), "utf8")).comments[0].resolution, "Made the title 32px. Kept the spacing. Done");
287
+ assert.equal(normalizeNote("a\u2028b\u2029 c"), "a b c", "Unicode line and paragraph separators are line breaks too");
288
+ assert.equal(normalizeNote(" \n\r\n "), undefined, "nothing left is no note");
289
+ assert.equal(normalizeNote("one line"), "one line");
290
+ });
291
+
292
+ test("S5: setStatus resolved without a note, or with a blank one, stores no resolution", async (t) => {
293
+ const root = designRoot(t);
294
+ const store = fixedStore(root);
295
+ const a = await store.add("alpha", INPUT);
296
+ const b = await store.add("alpha", INPUT);
297
+ await store.setStatus("alpha", [a.id], "resolved");
298
+ await store.setStatus("alpha", [b.id], "resolved", { note: " \n " });
299
+ const onDisk = JSON.parse(readFileSync(join(root, "alpha", "comments.json"), "utf8")).comments;
300
+ assert.deepEqual(onDisk.map((comment: { status: string }) => comment.status), ["resolved", "resolved"]);
301
+ assert.deepEqual(onDisk.map((comment: object) => "resolution" in comment), [false, false]);
302
+ });
303
+
304
+ test("S5: a note of 500 characters is kept; 501 is refused as invalid-input and comments.json is unchanged", async (t) => {
305
+ const root = designRoot(t);
306
+ const store = fixedStore(root);
307
+ const a = await store.add("alpha", INPUT);
308
+ const path = join(root, "alpha", "comments.json");
309
+ const before = readFileSync(path, "utf8");
310
+ await assert.rejects(store.setStatus("alpha", [a.id], "resolved", { note: "x".repeat(501) }), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-input" && /at most 500 characters/.test(error.message));
311
+ await assert.rejects(store.setStatus("alpha", [a.id], "resolved", { note: 7 as never }), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-input" && /note must be a string/.test(error.message));
312
+ assert.equal(readFileSync(path, "utf8"), before);
313
+ const kept = await store.setStatus("alpha", [a.id], "resolved", { note: "x".repeat(500) });
314
+ assert.equal(kept.updated[0].resolution!.length, 500);
315
+ });
316
+
317
+ test("S5: reopening a comment clears its resolution; resolving again with a note replaces it", async (t) => {
318
+ const root = designRoot(t);
319
+ const store = fixedStore(root);
320
+ const a = await store.add("alpha", INPUT);
321
+ await store.setStatus("alpha", [a.id], "resolved", { note: "First try." });
322
+ const reopened = await store.setStatus("alpha", [a.id], "open");
323
+ assert.equal(reopened.updated[0].status, "open");
324
+ assert.equal("resolution" in reopened.updated[0], false);
325
+ assert.equal("resolution" in JSON.parse(readFileSync(join(root, "alpha", "comments.json"), "utf8")).comments[0], false);
326
+ await store.setStatus("alpha", [a.id], "resolved", { note: "Second try." });
327
+ const again = await store.setStatus("alpha", [a.id], "resolved", { note: "Final." });
328
+ assert.equal(again.updated[0].resolution, "Final.");
329
+ assert.equal((await store.read("alpha")).comments[0].resolution, "Final.");
330
+ });
331
+
332
+ test("S5: a note on an open-status change is refused rather than stored", async (t) => {
333
+ const root = designRoot(t);
334
+ const store = fixedStore(root);
335
+ const a = await store.add("alpha", INPUT);
336
+ const before = readFileSync(join(root, "alpha", "comments.json"), "utf8");
337
+ await assert.rejects(store.setStatus("alpha", [a.id], "open", { note: "nope" }), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-input");
338
+ assert.equal(readFileSync(join(root, "alpha", "comments.json"), "utf8"), before);
339
+ });
340
+
341
+ test("S5: a malformed resolution in an existing comments.json is an invalid-file error and the file is never overwritten", async (t) => {
342
+ const root = designRoot(t);
343
+ const store = fixedStore(root);
344
+ const a = await store.add("alpha", INPUT);
345
+ const path = join(root, "alpha", "comments.json");
346
+ const good = JSON.parse(readFileSync(path, "utf8"));
347
+ for (const resolution of [7, null, ["x"], "x".repeat(501)]) {
348
+ const bytes = JSON.stringify({ version: 1, comments: [{ ...good.comments[0], status: "resolved", resolution }] });
349
+ writeFileSync(path, bytes);
350
+ await assert.rejects(store.read("alpha"), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-file" && /resolution/.test(error.message), JSON.stringify(resolution));
351
+ await assert.rejects(store.setStatus("alpha", [a.id], "open"), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-file");
352
+ assert.equal(readFileSync(path, "utf8"), bytes);
353
+ }
354
+ // A valid resolution and a comment without one both read back.
355
+ writeFileSync(path, JSON.stringify({ version: 1, comments: [{ ...good.comments[0], status: "resolved", resolution: "Done." }, { ...good.comments[0], id: "other1" }] }));
356
+ assert.deepEqual((await store.read("alpha")).comments.map((comment) => comment.resolution), ["Done.", undefined]);
357
+ });
358
+
359
+ test("setText normalizes like a new comment: line endings become \\n, the text is trimmed, and blank text is refused without writing", async (t) => {
360
+ const root = designRoot(t);
361
+ const store = fixedStore(root);
362
+ const a = await store.add("alpha", INPUT);
363
+ const edited = await store.setText("alpha", a.id, " Line one\r\nLine two\rLine three \n");
364
+ assert.equal(edited.comment.comment, "Line one\nLine two\nLine three");
365
+ assert.equal((await store.read("alpha")).comments[0].comment, "Line one\nLine two\nLine three", "the stored text is the normalized one");
366
+ const path = join(root, "alpha", "comments.json");
367
+ const before = readFileSync(path, "utf8");
368
+ for (const blank of [" ", "\r\n\t"]) {
369
+ await assert.rejects(store.setText("alpha", a.id, blank), (error: unknown) => error instanceof DesignCommentsError && error.code === "invalid-input", JSON.stringify(blank));
370
+ }
371
+ assert.equal(readFileSync(path, "utf8"), before, "a refused text leaves comments.json unchanged");
372
+ const same = await store.setText("alpha", a.id, "Line one\r\nLine two\nLine three ");
373
+ assert.equal(same.previous, "Line one\nLine two\nLine three");
374
+ assert.equal(readFileSync(path, "utf8"), before, "a text equal after normalizing writes nothing");
375
+ });
376
+
377
+ test("canvas-layout S17: setText changes the text of an open comment, sent or not, returns the previous text and refuses resolved, unknown and invalid ones without writing", async (t) => {
378
+ const root = designRoot(t);
379
+ const store = fixedStore(root);
380
+ const a = await store.add("alpha", INPUT);
381
+ const sent = await store.add("alpha", INPUT);
382
+ const resolved = await store.add("alpha", INPUT);
383
+ await store.markSent("alpha", [sent.id]);
384
+ await store.setStatus("alpha", [resolved.id], "resolved");
385
+ const edited = await store.setText("alpha", a.id, "Make it much bigger");
386
+ assert.equal(edited.comment.comment, "Make it much bigger");
387
+ assert.equal(edited.previous, "Make it bigger");
388
+ assert.equal(edited.comment.sentAt, null);
389
+ assert.equal(edited.comment.createdAt, FIXED.toISOString(), "the creation time stays");
390
+ const resent = await store.setText("alpha", sent.id, "Smaller");
391
+ assert.deepEqual([resent.comment.comment, resent.previous, resent.comment.sentAt], ["Smaller", "Make it bigger", FIXED.toISOString()], "a sent comment can change and keeps its sentAt");
392
+ const path = join(root, "alpha", "comments.json");
393
+ const before = readFileSync(path, "utf8");
394
+ assert.equal(JSON.parse(before).comments[0].comment, "Make it much bigger");
395
+ const refused = (code: string) => (error: unknown) => error instanceof DesignCommentsError && error.code === code;
396
+ await assert.rejects(store.setText("alpha", resolved.id, "New"), refused("locked"));
397
+ await assert.rejects(store.setText("alpha", "nope00", "New"), refused("not-found"));
398
+ await assert.rejects(store.setText("alpha", a.id, ""), refused("invalid-input"));
399
+ await assert.rejects(store.setText("alpha", a.id, "x".repeat(2001)), refused("invalid-input"));
400
+ assert.equal(readFileSync(path, "utf8"), before, "a refused edit writes nothing");
401
+ });
@@ -280,3 +280,23 @@ test("a delivery answer never overwrites a state the agent already changed", asy
280
280
  }), /boom/);
281
281
  assert.equal(onDisk(root).handoffs["02-b.html"].status, "in_progress", "a failure after the agent took it over keeps the agent's state");
282
282
  });
283
+
284
+ // canvas-server-data S11: a repeated in_progress report keeps the time the handoff was first started.
285
+ test("S11: a repeated in_progress report keeps the first startedAt; in_progress after implemented starts again", async (t) => {
286
+ const root = designRoot(t);
287
+ const store = createDesignHandoffStore(root, { now: ticking() });
288
+ await store.markSent("alpha", "01-a.html", { queued: false });
289
+ const first = await store.setStatus("alpha", "01-a.html", "in_progress", { note: "header" });
290
+ assert.equal(first.startedAt, at(1));
291
+ const again = await store.setStatus("alpha", "01-a.html", "in_progress", { note: "menu" });
292
+ assert.deepEqual(again, { status: "in_progress", queued: false, sentAt: at(0), startedAt: at(1), implementedAt: null, note: "menu" }, "the start time stays; the note is the last one");
293
+ assert.deepEqual(onDisk(root).handoffs["01-a.html"], again);
294
+ const done = await store.setStatus("alpha", "01-a.html", "implemented", {});
295
+ assert.equal(done.startedAt, at(1));
296
+ const reopened = await store.setStatus("alpha", "01-a.html", "in_progress", {});
297
+ assert.equal(reopened.startedAt, at(4), "taking an implemented handoff up again is a new start, as before");
298
+ assert.equal(reopened.implementedAt, null);
299
+ const fresh = await store.setStatus("alpha", "02-b.html", "in_progress", {});
300
+ assert.equal(fresh.startedAt, at(5), "a first report on an artboard never handed off still starts it");
301
+ assert.equal((await store.setStatus("alpha", "02-b.html", "in_progress", {})).startedAt, at(5));
302
+ });
@@ -0,0 +1,100 @@
1
+ import assert from "node:assert/strict";
2
+ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import type { TestContext } from "node:test";
6
+ import test from "node:test";
7
+ import { DESIGN_LAYOUT_COORDINATE_MAX, DESIGN_LAYOUT_MAX_POSITIONS, DesignLayoutError, createDesignLayoutStore } from "../lib/design-layout.ts";
8
+
9
+ // design/<slug>/layout.json (canvas-layout S3): where each artboard sits on the canvas and the arrangement last
10
+ // chosen. Validated whole before it is written; a file that cannot be read is no layout, never an error.
11
+
12
+ function designRoot(t: TestContext) {
13
+ const dir = mkdtempSync(join(tmpdir(), "gentle-design-layout-"));
14
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
15
+ const root = join(dir, "design");
16
+ mkdirSync(join(root, "alpha"), { recursive: true });
17
+ return root;
18
+ }
19
+
20
+ const layoutPath = (root: string) => join(root, "alpha", "layout.json");
21
+ const isCode = (code: string) => (error: unknown) => error instanceof DesignLayoutError && error.code === code;
22
+ const LAYOUT = { arrangement: "free", positions: { system: { x: 0, y: 0 }, "01-a.html": { x: 880, y: -40 }, "sub/02-b.html": { x: 1360, y: 400 } } };
23
+
24
+ test("S3: a design without layout.json has no layout, and an unknown design is not found", async (t) => {
25
+ const root = designRoot(t);
26
+ const store = createDesignLayoutStore(root);
27
+ assert.equal(await store.read("alpha"), null);
28
+ await assert.rejects(store.read("missing"), isCode("not-found"));
29
+ await assert.rejects(store.read("../alpha"), isCode("not-found"));
30
+ await assert.rejects(store.write("missing", LAYOUT), isCode("not-found"));
31
+ assert.equal(existsSync(join(root, "missing")), false);
32
+ });
33
+
34
+ test("S3: write saves the whole layout as formatted JSON, leaves no temp file, and read gives it back", async (t) => {
35
+ const root = designRoot(t);
36
+ const store = createDesignLayoutStore(root);
37
+ assert.deepEqual(await store.write("alpha", LAYOUT), LAYOUT);
38
+ assert.equal(readFileSync(layoutPath(root), "utf8"), `${JSON.stringify(LAYOUT, null, 2)}\n`);
39
+ assert.deepEqual(readdirSync(join(root, "alpha")), ["layout.json"]);
40
+ assert.deepEqual(await store.read("alpha"), LAYOUT);
41
+ // Each write replaces the whole file: a board left out is dropped.
42
+ const row = { arrangement: "row", positions: { "01-a.html": { x: 0, y: 0 } } };
43
+ await store.write("alpha", row);
44
+ assert.deepEqual(JSON.parse(readFileSync(layoutPath(root), "utf8")), row);
45
+ for (const arrangement of ["column", "grid"]) assert.equal((await store.write("alpha", { arrangement, positions: {} })).arrangement, arrangement);
46
+ });
47
+
48
+ test("S3: write refuses anything but a known arrangement and integer positions of artboards, and writes nothing", async (t) => {
49
+ const root = designRoot(t);
50
+ const store = createDesignLayoutStore(root);
51
+ const many = Object.fromEntries(Array.from({ length: DESIGN_LAYOUT_MAX_POSITIONS + 1 }, (_, index) => [`${index}.html`, { x: 0, y: 0 }]));
52
+ const refused: Array<[unknown, RegExp]> = [
53
+ [null, /must be a JSON object/],
54
+ [[], /must be a JSON object/],
55
+ ["row", /must be a JSON object/],
56
+ [{ ...LAYOUT, version: 1 }, /unknown keys: version/],
57
+ [{ positions: {} }, /arrangement must be/],
58
+ [{ arrangement: "diagonal", positions: {} }, /arrangement must be/],
59
+ [{ arrangement: "row" }, /positions must be an object/],
60
+ [{ arrangement: "row", positions: [] }, /positions must be an object/],
61
+ [{ arrangement: "row", positions: { "../x.html": { x: 0, y: 0 } } }, /keys must be relative \.html artboard paths or "system"/],
62
+ [{ arrangement: "row", positions: { "notes.txt": { x: 0, y: 0 } } }, /keys must be/],
63
+ [{ arrangement: "row", positions: { "": { x: 0, y: 0 } } }, /keys must be/],
64
+ [{ arrangement: "row", positions: { "01-a.html": [0, 0] } }, /must be an object with x and y/],
65
+ [{ arrangement: "row", positions: { "01-a.html": { x: 0, y: 0, z: 1 } } }, /may hold only x and y/],
66
+ [{ arrangement: "row", positions: { "01-a.html": { x: 1.5, y: 0 } } }, /x and y must be integers between -2000000 and 2000000/],
67
+ [{ arrangement: "row", positions: { "01-a.html": { x: "1", y: 0 } } }, /x and y must be integers/],
68
+ [{ arrangement: "row", positions: { "01-a.html": { x: 0 } } }, /x and y must be integers/],
69
+ [{ arrangement: "row", positions: { "01-a.html": { x: Number.NaN, y: 0 } } }, /x and y must be integers/],
70
+ [{ arrangement: "row", positions: { "01-a.html": { x: Number.POSITIVE_INFINITY, y: 0 } } }, /x and y must be integers/],
71
+ [{ arrangement: "row", positions: { "01-a.html": { x: 0, y: -DESIGN_LAYOUT_COORDINATE_MAX - 1 } } }, /x and y must be integers/],
72
+ [{ arrangement: "row", positions: { "01-a.html": { x: 1e300, y: 0 } } }, /x and y must be integers between -2000000 and 2000000/],
73
+ [{ arrangement: "row", positions: many }, /at most 100 boards/],
74
+ ];
75
+ for (const [value, message] of refused) {
76
+ await assert.rejects(store.write("alpha", value), (error: unknown) => isCode("invalid-input")(error) && message.test((error as Error).message), JSON.stringify(value)?.slice(0, 80));
77
+ }
78
+ assert.equal(existsSync(layoutPath(root)), false, "a refused layout writes nothing");
79
+ await store.write("alpha", LAYOUT);
80
+ const before = readFileSync(layoutPath(root), "utf8");
81
+ await assert.rejects(store.write("alpha", { arrangement: "row", positions: { "01-a.html": { x: 0.5, y: 0 } } }), isCode("invalid-input"));
82
+ assert.equal(readFileSync(layoutPath(root), "utf8"), before, "and leaves the saved one as it was");
83
+ // The bounds themselves are accepted.
84
+ const edge = { arrangement: "free", positions: { "01-a.html": { x: -DESIGN_LAYOUT_COORDINATE_MAX, y: DESIGN_LAYOUT_COORDINATE_MAX } } };
85
+ assert.deepEqual(await store.write("alpha", edge), edge);
86
+ });
87
+
88
+ test("S3: an unreadable or invalid layout.json reads as no layout, and the next write replaces it", async (t) => {
89
+ const root = designRoot(t);
90
+ const store = createDesignLayoutStore(root);
91
+ for (const content of ["{ not json", "[]", JSON.stringify({ arrangement: "row" }), JSON.stringify({ arrangement: "row", positions: { "01-a.html": { x: 1.5, y: 0 } } }), "x".repeat(300 * 1024)]) {
92
+ writeFileSync(layoutPath(root), content);
93
+ assert.equal(await store.read("alpha"), null, content.slice(0, 40));
94
+ }
95
+ await store.write("alpha", LAYOUT);
96
+ assert.deepEqual(await store.read("alpha"), LAYOUT);
97
+ rmSync(layoutPath(root));
98
+ mkdirSync(layoutPath(root));
99
+ assert.equal(await store.read("alpha"), null, "a directory named layout.json is no layout");
100
+ });