gentle-pi 4.6.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 (536) hide show
  1. package/README.md +65 -55
  2. package/assets/agents/gentle-ai-explore.md +4 -3
  3. package/assets/agents/gentle-ai-verify.md +23 -6
  4. package/assets/agents/gentle-ai-worker.md +9 -6
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +2 -3
  7. package/assets/agents/jd-judge-b.md +2 -3
  8. package/assets/agents/review-readability.md +1 -5
  9. package/assets/agents/review-reliability.md +1 -5
  10. package/assets/agents/review-resilience.md +1 -5
  11. package/assets/agents/review-risk.md +1 -5
  12. package/assets/design-canvas/canvas-api.js +45 -0
  13. package/assets/design-canvas/canvas-boards.js +456 -0
  14. package/assets/design-canvas/canvas-boot.js +217 -0
  15. package/assets/design-canvas/canvas-checks.js +491 -0
  16. package/assets/design-canvas/canvas-comments.js +315 -0
  17. package/assets/design-canvas/canvas-compare.js +159 -0
  18. package/assets/design-canvas/canvas-events.js +75 -0
  19. package/assets/design-canvas/canvas-export.js +393 -0
  20. package/assets/design-canvas/canvas-focus.js +203 -0
  21. package/assets/design-canvas/canvas-handoffs.js +150 -0
  22. package/assets/design-canvas/canvas-i18n-es.js +392 -0
  23. package/assets/design-canvas/canvas-i18n.js +108 -0
  24. package/assets/design-canvas/canvas-layout.js +526 -0
  25. package/assets/design-canvas/canvas-menu.js +213 -0
  26. package/assets/design-canvas/canvas-messages.js +86 -0
  27. package/assets/design-canvas/canvas-minimap.js +163 -0
  28. package/assets/design-canvas/canvas-parts.js +401 -0
  29. package/assets/design-canvas/canvas-popover.js +234 -0
  30. package/assets/design-canvas/canvas-rail.js +348 -0
  31. package/assets/design-canvas/canvas-sizes.js +524 -0
  32. package/assets/design-canvas/canvas-store.js +164 -0
  33. package/assets/design-canvas/canvas-tokens.js +674 -0
  34. package/assets/design-canvas/canvas-ui.js +24 -0
  35. package/assets/design-canvas/canvas-view.js +184 -0
  36. package/assets/design-canvas/canvas.css +759 -16
  37. package/assets/design-canvas/canvas.js +2 -1497
  38. package/assets/design-canvas/index.html +117 -36
  39. package/assets/design-canvas/inspector.js +546 -16
  40. package/assets/install-wizard/wizard.js +6 -1
  41. package/assets/migrations/agent-body-history.json +40 -1
  42. package/assets/orchestrator-delegation-reference.md +10 -16
  43. package/assets/orchestrator-delegation.md +5 -5
  44. package/assets/orchestrator-full-delegation-card.md +64 -0
  45. package/assets/orchestrator-full-delegation.md +34 -0
  46. package/assets/orchestrator-memory.md +5 -5
  47. package/assets/orchestrator-prompts.md +2 -2
  48. package/assets/orchestrator-quota-recovery.md +5 -0
  49. package/assets/orchestrator-skills.md +14 -13
  50. package/assets/orchestrator-tracking.md +10 -14
  51. package/assets/orchestrator-verification.md +12 -8
  52. package/assets/orchestrator-writer.md +4 -4
  53. package/assets/orchestrator.md +21 -25
  54. package/bin/gentle-shell.mjs +292 -65
  55. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  56. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
  60. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
  61. package/docs/agent-status.md +61 -0
  62. package/docs/assets/brand/sponsor-banner.svg +60 -0
  63. package/docs/bundled-install.md +20 -10
  64. package/docs/delegated-verification.md +46 -8
  65. package/docs/desktop-rpc.md +1253 -0
  66. package/docs/gentle-agents-activity.md +40 -0
  67. package/docs/gentle-shell.md +91 -30
  68. package/docs/install-wizard.md +30 -21
  69. package/docs/odd-preparation-continuity.md +24 -0
  70. package/docs/permission-modes.md +17 -4
  71. package/docs/prompt-budget.md +12 -0
  72. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  73. package/docs/readme-reference.md +142 -45
  74. package/docs/render-cache-performance.md +11 -1
  75. package/docs/review-coordinator.md +53 -0
  76. package/docs/review-delivery-preflight.md +22 -0
  77. package/docs/review-request-context.md +19 -0
  78. package/docs/review-windows-acl.md +18 -0
  79. package/docs/voice.md +6 -3
  80. package/docs/work-continuity.md +11 -1
  81. package/docs/yolo-mode.md +5 -5
  82. package/extensions/ask-user-choice.ts +1 -0
  83. package/extensions/ask-user-question.ts +3 -2
  84. package/extensions/child-context.ts +21 -7
  85. package/extensions/child-safety.ts +3 -0
  86. package/extensions/gentle-agent-status.ts +99 -0
  87. package/extensions/gentle-agents.ts +559 -66
  88. package/extensions/gentle-ai.ts +2001 -518
  89. package/extensions/gentle-design.ts +69 -3
  90. package/extensions/gentle-desktop-rpc.ts +143 -0
  91. package/extensions/gentle-guide.ts +3 -0
  92. package/extensions/gentle-shell.ts +398 -115
  93. package/extensions/gentle-todo.ts +66 -27
  94. package/extensions/gentle-tps.ts +48 -0
  95. package/extensions/quiet-tools.ts +38 -8
  96. package/extensions/skill-registry.ts +349 -167
  97. package/extensions/startup-banner.ts +30 -3
  98. package/lib/agent-assets.ts +30 -6
  99. package/lib/agent-profile-pin.ts +3 -3
  100. package/lib/agent-profiles.ts +160 -2
  101. package/lib/agent-status.ts +105 -0
  102. package/lib/agent-tool-overlay.ts +117 -0
  103. package/lib/agents-config.ts +93 -6
  104. package/lib/agents-history.ts +24 -5
  105. package/lib/agents-message-delivery.ts +17 -0
  106. package/lib/agents-messaging.ts +55 -7
  107. package/lib/agents-protocol.ts +15 -0
  108. package/lib/agents-report-cap.ts +115 -0
  109. package/lib/agents-runner.ts +272 -16
  110. package/lib/agents-session-transport.ts +17 -1
  111. package/lib/auto-permission-runtime.ts +1 -1
  112. package/lib/background-jobs-tools.ts +9 -4
  113. package/lib/bounded-writer-admission.ts +197 -32
  114. package/lib/card-content-policy.ts +8 -6
  115. package/lib/child-context-files.ts +21 -6
  116. package/lib/codemode-renderer.ts +1 -0
  117. package/lib/command-palette.ts +133 -17
  118. package/lib/context-backstop.ts +14 -5
  119. package/lib/delivery-conflict-markers.ts +349 -0
  120. package/lib/design-canvas-assets.ts +36 -0
  121. package/lib/design-canvas-server.ts +241 -23
  122. package/lib/design-comments.ts +94 -4
  123. package/lib/design-handoffs.ts +2 -1
  124. package/lib/design-layout.ts +125 -0
  125. package/lib/design-parts.ts +281 -0
  126. package/lib/design-system-tokens.ts +111 -0
  127. package/lib/desktop-agents-service.ts +294 -0
  128. package/lib/desktop-design-service.ts +233 -0
  129. package/lib/desktop-jobs-service.ts +263 -0
  130. package/lib/desktop-rpc-agents.ts +294 -0
  131. package/lib/desktop-rpc-config.ts +731 -0
  132. package/lib/desktop-rpc-design.ts +138 -0
  133. package/lib/desktop-rpc-jobs.ts +181 -0
  134. package/lib/desktop-rpc-permissions.ts +177 -0
  135. package/lib/desktop-rpc-profiles.ts +196 -0
  136. package/lib/desktop-rpc-usage.ts +229 -0
  137. package/lib/desktop-rpc.ts +225 -0
  138. package/lib/desktop-usage-service.ts +310 -0
  139. package/lib/destructive-command-guard.ts +236 -17
  140. package/lib/execution-surface-guard.ts +20 -0
  141. package/lib/exploration-budget.ts +4 -2
  142. package/lib/gentle-ai-binary.ts +1 -1
  143. package/lib/gentle-ai-renderer.ts +13 -1
  144. package/lib/gentle-design.ts +204 -14
  145. package/lib/gentle-shell-bundled.ts +106 -28
  146. package/lib/gentle-shell-launcher.ts +43 -8
  147. package/lib/herdr-activity.ts +14 -2
  148. package/lib/herdr-busy.ts +45 -0
  149. package/lib/hidden-tools.ts +35 -0
  150. package/lib/image-attachments.ts +33 -0
  151. package/lib/image-disk-cache.ts +137 -0
  152. package/lib/inprocess-reviewer.ts +358 -144
  153. package/lib/jobs-view.ts +198 -11
  154. package/lib/model-fallback-policy.ts +9 -0
  155. package/lib/model-routing-authority.ts +31 -4
  156. package/lib/nan-provider.ts +42 -28
  157. package/lib/native-choice-list.ts +20 -2
  158. package/lib/native-review-cli.ts +172 -20
  159. package/lib/orchestrator-discovery.ts +39 -2
  160. package/lib/orchestrator-mode-policy.ts +105 -0
  161. package/lib/questionnaire/questionnaire-view.ts +105 -12
  162. package/lib/rdd-mode-control.ts +32 -0
  163. package/lib/reply-language-anchor.ts +129 -0
  164. package/lib/request-context-placement.ts +53 -0
  165. package/lib/review-blocker.ts +92 -0
  166. package/lib/review-candidate-symlink-scan.ts +136 -0
  167. package/lib/review-candidate-view-owner.ts +81 -44
  168. package/lib/review-candidate-view.ts +11 -1
  169. package/lib/review-continuation-registry.ts +116 -0
  170. package/lib/review-coordinator.ts +407 -0
  171. package/lib/review-delivery-preflight.ts +85 -0
  172. package/lib/review-failure-facts.ts +49 -0
  173. package/lib/review-host-relay.ts +51 -11
  174. package/lib/review-integration-v2.ts +63 -4
  175. package/lib/review-relay-phase-timing.ts +45 -0
  176. package/lib/review-start-context.ts +17 -0
  177. package/lib/reviewer-stream.ts +87 -0
  178. package/lib/session-profile-freeze.ts +4 -2
  179. package/lib/shell-bar.ts +140 -58
  180. package/lib/shell-changes.ts +2 -0
  181. package/lib/shell-panel.ts +17 -3
  182. package/lib/shell-prompt.ts +16 -3
  183. package/lib/shell-sidebar-layout.ts +112 -40
  184. package/lib/shell-sidebar.ts +7 -0
  185. package/lib/shell-todo.ts +10 -3
  186. package/lib/shell-usage.ts +10 -0
  187. package/lib/verifier-admission.ts +1 -1
  188. package/lib/vim-editor-adapter.ts +9 -2
  189. package/lib/visual-customization-policy.ts +36 -16
  190. package/lib/visual-customize-view.ts +216 -21
  191. package/lib/visual-layout-preview.ts +9 -5
  192. package/lib/visual-profiles.ts +2 -2
  193. package/lib/windows-session-transport.ts +53 -2
  194. package/lib/writer-batch-admission.ts +55 -0
  195. package/lib/yolo-session-policy.ts +46 -16
  196. package/package.json +3 -2
  197. package/prompts/skill-creation.md +1 -10
  198. package/runtime/design-canvas-assets.mjs +37 -0
  199. package/runtime/gentle-ai-binary.mjs +1 -1
  200. package/runtime/gentle-shell-bundled.mjs +106 -28
  201. package/runtime/gentle-shell-launcher.mjs +42 -7
  202. package/runtime/native-review-cli.mjs +169 -17
  203. package/runtime/review-integration-v2.mjs +63 -4
  204. package/scripts/bootstrap.cmd +2 -2
  205. package/scripts/bootstrap.sh +41 -4
  206. package/scripts/build-full-delegation-card.mjs +179 -0
  207. package/scripts/build-runtime-modules.mjs +1 -0
  208. package/scripts/bundled-install.mjs +38 -8
  209. package/scripts/download-progress.mjs +68 -0
  210. package/scripts/gentle-ai-installer.mjs +41 -18
  211. package/scripts/gentle-ai-proxy.mjs +294 -0
  212. package/scripts/install-gentle-ai.mjs +14 -1
  213. package/scripts/installer-downloads.mjs +34 -8
  214. package/scripts/installer-preflight.mjs +33 -22
  215. package/scripts/installer-probes.mjs +25 -5
  216. package/scripts/installer-runner.mjs +27 -12
  217. package/scripts/installer-server.mjs +46 -16
  218. package/scripts/installer-windows.mjs +2 -2
  219. package/scripts/pi-update.mjs +166 -27
  220. package/scripts/prepare-verifier.mjs +107 -0
  221. package/scripts/render-cache-host.mjs +72 -0
  222. package/scripts/render-cache-performance-worker.mjs +5 -4
  223. package/scripts/render-cache-performance.mjs +6 -1
  224. package/scripts/run-test-suite.mjs +40 -28
  225. package/scripts/update-agent-body-history.mjs +55 -8
  226. package/scripts/verify-package-files.mjs +50 -19
  227. package/scripts/voice-worker.cjs +32 -6
  228. package/skills/branch-pr/SKILL.md +16 -16
  229. package/skills/comment-writer/SKILL.md +1 -1
  230. package/skills/design/SKILL.md +16 -13
  231. package/skills/gentle-ai/SKILL.md +7 -7
  232. package/skills/gentle-ui-design/SKILL.md +46 -0
  233. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  234. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  235. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  236. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  237. package/skills/judgment-day/SKILL.md +2 -2
  238. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  239. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  240. package/skills/skill-improver/SKILL.md +2 -2
  241. package/skills/skill-registry/SKILL.md +11 -11
  242. package/skills/tui-design/SKILL.md +1 -1
  243. package/skills/work-unit-commits/SKILL.md +10 -11
  244. package/tests/agent-home.test.ts +28 -9
  245. package/tests/agent-profiles-workflow.test.ts +163 -0
  246. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  247. package/tests/agent-risk-escalation.test.ts +1 -1
  248. package/tests/agent-status.test.ts +143 -0
  249. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  250. package/tests/agent-tool-overlay.test.ts +89 -0
  251. package/tests/agents-config.test.ts +106 -1
  252. package/tests/agents-history.test.ts +31 -0
  253. package/tests/agents-jobs-frames.test.ts +93 -0
  254. package/tests/agents-message-delivery.test.ts +36 -0
  255. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  256. package/tests/agents-queries.test.ts +144 -4
  257. package/tests/agents-report-cap.test.ts +126 -0
  258. package/tests/agents-runner-drain.test.ts +193 -0
  259. package/tests/agents-runner.test.ts +215 -3
  260. package/tests/agents-session-transport.test.ts +34 -0
  261. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  262. package/tests/append-system-prompt-route.test.ts +12 -1
  263. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  264. package/tests/artifact-language.test.ts +1 -1
  265. package/tests/ask-user-choice.test.ts +4 -3
  266. package/tests/ask-user-question.test.ts +99 -1
  267. package/tests/audit-leftovers-contract.test.ts +51 -0
  268. package/tests/auto-permission-runtime.test.ts +1 -1
  269. package/tests/autonomous-guard.test.ts +346 -10
  270. package/tests/bounded-stop-contract.test.ts +51 -3
  271. package/tests/branch-pr-skill.test.ts +10 -1
  272. package/tests/bridge-cost.test.ts +19 -4
  273. package/tests/bundled-install.test.ts +31 -6
  274. package/tests/card-content-policy.test.ts +3 -3
  275. package/tests/chained-pr-skill.test.ts +8 -6
  276. package/tests/child-context-files.test.ts +64 -8
  277. package/tests/child-safety.test.ts +11 -0
  278. package/tests/child-skills-catalog.test.ts +56 -0
  279. package/tests/codegraph-tools.test.ts +11 -5
  280. package/tests/codemode-rendering.test.ts +4 -1
  281. package/tests/command-palette.test.ts +284 -1
  282. package/tests/delegate-for-reason-contract.test.ts +32 -10
  283. package/tests/delivery-conflict-markers.test.ts +348 -0
  284. package/tests/design-canvas-all-sizes.test.ts +631 -0
  285. package/tests/design-canvas-allowlist.test.ts +32 -0
  286. package/tests/design-canvas-assets.test.ts +11 -695
  287. package/tests/design-canvas-boards.test.ts +77 -0
  288. package/tests/design-canvas-checks.test.ts +655 -0
  289. package/tests/design-canvas-compare.test.ts +79 -0
  290. package/tests/design-canvas-events.test.ts +59 -0
  291. package/tests/design-canvas-export.test.ts +1168 -0
  292. package/tests/design-canvas-focus.test.ts +113 -0
  293. package/tests/design-canvas-handoffs.test.ts +59 -0
  294. package/tests/design-canvas-i18n-review.test.ts +513 -0
  295. package/tests/design-canvas-i18n-views.test.ts +259 -0
  296. package/tests/design-canvas-i18n.test.ts +526 -0
  297. package/tests/design-canvas-inspector.test.ts +937 -0
  298. package/tests/design-canvas-layout.test.ts +1222 -0
  299. package/tests/design-canvas-minimap.test.ts +413 -0
  300. package/tests/design-canvas-modules.test.ts +90 -0
  301. package/tests/design-canvas-parts.test.ts +721 -0
  302. package/tests/design-canvas-rail.test.ts +799 -0
  303. package/tests/design-canvas-server.test.ts +855 -17
  304. package/tests/design-canvas-sizes.test.ts +548 -0
  305. package/tests/design-canvas-store.test.ts +180 -0
  306. package/tests/design-canvas-tokens.test.ts +965 -0
  307. package/tests/design-canvas-view.test.ts +299 -0
  308. package/tests/design-comments.test.ts +201 -1
  309. package/tests/design-handoffs.test.ts +20 -0
  310. package/tests/design-layout.test.ts +100 -0
  311. package/tests/design-parts.test.ts +260 -0
  312. package/tests/design-system-tokens.test.ts +215 -0
  313. package/tests/desktop-rpc-agents.test.ts +893 -0
  314. package/tests/desktop-rpc-config.test.ts +1452 -0
  315. package/tests/desktop-rpc-design.test.ts +662 -0
  316. package/tests/desktop-rpc-jobs.test.ts +796 -0
  317. package/tests/desktop-rpc-permissions.test.ts +311 -0
  318. package/tests/desktop-rpc-profiles.test.ts +140 -0
  319. package/tests/desktop-rpc-safety.test.ts +119 -0
  320. package/tests/desktop-rpc-usage.test.ts +697 -0
  321. package/tests/desktop-rpc.test.ts +252 -0
  322. package/tests/destructive-command-guard.test.ts +52 -0
  323. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  324. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  325. package/tests/download-progress.test.ts +71 -0
  326. package/tests/engram-safety.test.ts +111 -0
  327. package/tests/execution-surface-guard.test.ts +55 -0
  328. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  329. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  330. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +26 -31
  331. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  332. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  333. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  334. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  335. package/tests/fixtures/session-profile-v1/replay.ts +53 -6
  336. package/tests/full-delegation-closure.test.ts +160 -0
  337. package/tests/full-delegation-notices.test.ts +76 -0
  338. package/tests/generic-agent-tools.test.ts +3 -3
  339. package/tests/gentle-agent-status.test.ts +74 -0
  340. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  341. package/tests/gentle-agents.test.ts +1403 -20
  342. package/tests/gentle-ai-binary.test.ts +3 -1
  343. package/tests/gentle-ai-child-guards.test.ts +1 -0
  344. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  345. package/tests/gentle-ai-exploration-budget.test.ts +18 -2
  346. package/tests/gentle-ai-installer.test.ts +135 -51
  347. package/tests/gentle-ai-proxy.test.ts +434 -0
  348. package/tests/gentle-ai-renderer.test.ts +36 -2
  349. package/tests/gentle-ai.test.ts +233 -43
  350. package/tests/gentle-design.test.ts +386 -1
  351. package/tests/gentle-herdr-activity.test.ts +9 -6
  352. package/tests/gentle-shell-bin.test.ts +123 -0
  353. package/tests/gentle-shell-bundled.test.ts +293 -31
  354. package/tests/gentle-shell-launcher.test.ts +78 -11
  355. package/tests/gentle-shell.test.ts +1017 -146
  356. package/tests/gentle-todo.test.ts +51 -11
  357. package/tests/gentle-tps.test.ts +123 -0
  358. package/tests/gentle-ui-design-skill.test.ts +59 -0
  359. package/tests/herdr-busy.test.ts +59 -0
  360. package/tests/herdr-task-summary-policy.test.ts +8 -4
  361. package/tests/hidden-tools.test.ts +188 -0
  362. package/tests/image-disk-cache.test.ts +163 -0
  363. package/tests/independent-recovery-delivery.test.ts +97 -0
  364. package/tests/inprocess-reviewer.test.ts +249 -4
  365. package/tests/install-wizard.test.ts +27 -1
  366. package/tests/installer-downloads.test.ts +30 -1
  367. package/tests/installer-posix-bootstrap.test.ts +115 -14
  368. package/tests/installer-preflight.test.ts +54 -5
  369. package/tests/installer-probes.test.ts +146 -0
  370. package/tests/installer-runner.test.ts +79 -44
  371. package/tests/installer-server.test.ts +215 -13
  372. package/tests/installer-windows-bootstrap.test.ts +19 -1
  373. package/tests/jobs-view.test.ts +260 -6
  374. package/tests/judgment-day-severity-admission.test.ts +46 -0
  375. package/tests/lazy-module-contradictions-contract.test.ts +158 -0
  376. package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
  377. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  378. package/tests/modal-mouse-boundaries.test.ts +136 -0
  379. package/tests/model-fallback-policy.test.ts +26 -7
  380. package/tests/model-routing-authority.test.ts +178 -2
  381. package/tests/nan-provider-runtime.test.ts +17 -3
  382. package/tests/nan-provider.test.ts +111 -56
  383. package/tests/native-choice-list.test.ts +77 -2
  384. package/tests/native-review-capability-contract.test.ts +17 -1
  385. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  386. package/tests/native-review-cli.test.ts +269 -1
  387. package/tests/native-review-parity.test.ts +24 -5
  388. package/tests/native-review-refusal-identity.test.ts +25 -0
  389. package/tests/no-self-pause-contract.test.ts +13 -2
  390. package/tests/odd-integration.test.ts +11 -3
  391. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  392. package/tests/odd-routing-contract.test.ts +80 -28
  393. package/tests/orchestrator-budget.test.ts +35 -5
  394. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  395. package/tests/orchestrator-delegation-mode.test.ts +154 -0
  396. package/tests/orchestrator-discovery.test.ts +28 -0
  397. package/tests/orchestrator-mode-policy.test.ts +175 -0
  398. package/tests/orchestrator-prompt-budget.test.ts +13 -2
  399. package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
  400. package/tests/orchestrator-rdd-ownership.test.ts +4 -3
  401. package/tests/orchestrator-work-search.test.ts +4 -2
  402. package/tests/package-files.test.ts +25 -1
  403. package/tests/package-manifest.test.ts +16 -13
  404. package/tests/parallel-reason-contract.test.ts +6 -3
  405. package/tests/permission-allowlist.test.ts +372 -0
  406. package/tests/persona-neutral-voseo.test.ts +4 -4
  407. package/tests/persona-reply-language.test.ts +1 -1
  408. package/tests/persona-single-channel.test.ts +13 -5
  409. package/tests/pi-update-launcher.test.ts +25 -7
  410. package/tests/pi-update-source.test.ts +113 -6
  411. package/tests/pi-update.test.ts +294 -19
  412. package/tests/pnpm-workspace-config.test.ts +58 -0
  413. package/tests/pnpm-workspace-policy.test.ts +47 -0
  414. package/tests/primary-context-files.test.ts +233 -0
  415. package/tests/primary-context-three-files.test.ts +174 -0
  416. package/tests/primary-session-prompt.test.ts +13 -0
  417. package/tests/profile-pin.test.ts +29 -2
  418. package/tests/profile-tier-footer.test.ts +5 -0
  419. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  420. package/tests/provider-defect-handoff.test.ts +9 -2
  421. package/tests/questionnaire-view.test.ts +115 -0
  422. package/tests/quiet-bash-runtime.test.ts +1 -1
  423. package/tests/quiet-tool-rendering.test.ts +48 -0
  424. package/tests/rdd-aware-verification-contract.test.ts +17 -12
  425. package/tests/rdd-customize.test.ts +287 -0
  426. package/tests/rdd-mode-cache.test.ts +450 -0
  427. package/tests/rdd-mode-control.test.ts +407 -0
  428. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  429. package/tests/rdd-off-independent-regression.test.ts +69 -0
  430. package/tests/rdd-status-line.test.ts +112 -1
  431. package/tests/render-cache-performance.test.ts +171 -2
  432. package/tests/reply-language-anchor-placement.test.ts +184 -0
  433. package/tests/reply-language-anchor.test.ts +189 -0
  434. package/tests/request-context-append-only.test.ts +218 -0
  435. package/tests/request-context-placement.test.ts +148 -0
  436. package/tests/review-agent-end-preflight.test.ts +80 -2
  437. package/tests/review-blocker.test.ts +193 -0
  438. package/tests/review-candidate-owner-retry.test.ts +1 -1
  439. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  440. package/tests/review-candidate-view.test.ts +66 -1
  441. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  442. package/tests/review-candidate-windows-probe.test.ts +63 -0
  443. package/tests/review-committed-restart-ack.test.ts +129 -0
  444. package/tests/review-continuation-registry.test.ts +107 -0
  445. package/tests/review-contract-prompt.test.ts +1 -1
  446. package/tests/review-controller-native-routing.test.ts +261 -5
  447. package/tests/review-controller-workspace-root.test.ts +230 -3
  448. package/tests/review-controller.test.ts +98 -12
  449. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  450. package/tests/review-coordinator-findings.test.ts +206 -0
  451. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  452. package/tests/review-coordinator-runtime.test.ts +117 -0
  453. package/tests/review-coordinator.test.ts +462 -0
  454. package/tests/review-delivery-preflight.test.ts +462 -0
  455. package/tests/review-due-compaction.test.ts +31 -0
  456. package/tests/review-due-public-boundary.test.ts +26 -0
  457. package/tests/review-failure-facts.test.ts +87 -0
  458. package/tests/review-host-relay-routing.test.ts +258 -4
  459. package/tests/review-host-relay.test.ts +39 -0
  460. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  461. package/tests/review-integration-v2.test.ts +46 -3
  462. package/tests/review-json-arguments.test.ts +105 -11
  463. package/tests/review-last-event-closure.test.ts +68 -0
  464. package/tests/review-ledger-contract.test.ts +19 -40
  465. package/tests/review-loadout-rdd-off-sdk.test.ts +95 -32
  466. package/tests/review-one-call-findings.test.ts +131 -0
  467. package/tests/review-one-call-followups.test.ts +308 -0
  468. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  469. package/tests/review-one-call.test.ts +452 -0
  470. package/tests/review-owner-identity.test.ts +60 -24
  471. package/tests/review-relay-phase-timing.test.ts +128 -0
  472. package/tests/review-relay-transport-agent.test.ts +39 -2
  473. package/tests/review-reviewer-evidence.test.ts +223 -0
  474. package/tests/review-risk-assessment.test.ts +126 -8
  475. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  476. package/tests/review-session-standing-permission-controller.test.ts +53 -3
  477. package/tests/review-start-context.test.ts +19 -0
  478. package/tests/review-tool-prose-budget.test.ts +122 -0
  479. package/tests/reviewer-stream.test.ts +149 -0
  480. package/tests/run-test-suite.test.ts +122 -1
  481. package/tests/runtime-harness.mjs +4 -1
  482. package/tests/sensitive-path-tools.test.ts +181 -5
  483. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  484. package/tests/session-profile-binding.test.ts +19 -1
  485. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  486. package/tests/session-profile-extension.test.ts +2 -2
  487. package/tests/session-profile-v1-compat.test.ts +35 -1
  488. package/tests/shell-bar.test.ts +186 -42
  489. package/tests/shell-panel.test.ts +50 -22
  490. package/tests/shell-prompt.test.ts +17 -0
  491. package/tests/shell-sidebar-fullscreen.test.ts +5 -5
  492. package/tests/shell-sidebar-layout.test.ts +294 -23
  493. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  494. package/tests/shell-surface-transparent.test.ts +89 -0
  495. package/tests/shell-todo.test.ts +12 -0
  496. package/tests/shell-usage.test.ts +59 -10
  497. package/tests/skill-contradictions-contract.test.ts +122 -0
  498. package/tests/skill-registry-watcher.test.ts +216 -2
  499. package/tests/skill-registry.test.ts +1461 -5
  500. package/tests/startup-banner.test.ts +152 -1
  501. package/tests/startup-home-repo.test.ts +2 -0
  502. package/tests/support/design-canvas-dom.ts +369 -0
  503. package/tests/support/review-coordinator-runtime.ts +264 -0
  504. package/tests/task-size-routing-contract.test.ts +45 -12
  505. package/tests/test-strength-contract.test.ts +2 -1
  506. package/tests/todo-request-append-only.test.ts +214 -0
  507. package/tests/tool-batching-contract.test.ts +3 -1
  508. package/tests/update-agent-body-history.test.ts +138 -0
  509. package/tests/verification-tiers-contract.test.ts +229 -0
  510. package/tests/verifier-admission.test.ts +49 -0
  511. package/tests/verifier-preparation.test.ts +229 -0
  512. package/tests/verify-agent-contract.test.ts +20 -2
  513. package/tests/verify-first-launch-contract.test.ts +162 -11
  514. package/tests/vim-editor-adapter.test.ts +2 -2
  515. package/tests/visual-customization-policy.test.ts +39 -6
  516. package/tests/visual-customize-view.test.ts +573 -9
  517. package/tests/visual-layout-preview.test.ts +15 -1
  518. package/tests/visual-profiles.test.ts +11 -0
  519. package/tests/voice-worker.test.ts +73 -2
  520. package/tests/windows-session-transport.test.ts +126 -0
  521. package/tests/work-continuity-contract.test.ts +77 -6
  522. package/tests/writer-admission-messages.test.ts +232 -0
  523. package/tests/writer-batch-admission.test.ts +66 -0
  524. package/tests/writer-edit-surface-scope.test.ts +52 -20
  525. package/tests/writer-feature-document-admission.test.ts +276 -0
  526. package/tests/yolo-customize.test.ts +27 -4
  527. package/tests/yolo-mode.test.ts +62 -18
  528. package/tests/yolo-session-policy.test.ts +270 -1
  529. package/skills/_shared/review-ledger-contract.md +0 -106
  530. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
  531. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
  532. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
  533. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  534. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
  535. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
  536. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -0,0 +1,260 @@
1
+ import assert from "node:assert/strict";
2
+ import { createHash } from "node:crypto";
3
+ import { existsSync, mkdirSync, mkdtempSync, readdirSync, readFileSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import type { TestContext } from "node:test";
7
+ import test from "node:test";
8
+ import { DESIGN_PARTS_MAX, DesignPartsError, createDesignPartStore, sendDesignPart } from "../lib/design-parts.ts";
9
+
10
+ // design/<slug>/parts.json (canvas-implement-part S2-S4, S6): the parts of artboards handed to the session one at a
11
+ // time ("Implement only this"). It never touches handoffs.json, so no direction is chosen or discarded.
12
+
13
+ function designRoot(t: TestContext) {
14
+ const dir = mkdtempSync(join(tmpdir(), "gentle-design-parts-"));
15
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
16
+ const root = join(dir, "design");
17
+ mkdirSync(join(root, "alpha"), { recursive: true });
18
+ return root;
19
+ }
20
+
21
+ function ticking() {
22
+ let seconds = 0;
23
+ return () => new Date(Date.UTC(2026, 9, 31, 10, 0, seconds++));
24
+ }
25
+
26
+ function ids() {
27
+ let n = 0;
28
+ return () => `part${++n}`;
29
+ }
30
+
31
+ const at = (seconds: number) => new Date(Date.UTC(2026, 9, 31, 10, 0, seconds)).toISOString();
32
+ const partsPath = (root: string) => join(root, "alpha", "parts.json");
33
+ const onDisk = (root: string) => JSON.parse(readFileSync(partsPath(root), "utf8"));
34
+ const hash = (path: string) => createHash("sha256").update(readFileSync(path)).digest("hex");
35
+ const isCode = (code: string) => (error: unknown) => error instanceof DesignPartsError && error.code === code;
36
+ const SIDEBAR = { file: "01-a.html", selector: "nav.sidebar", excerpt: "Inicio Tours Reservas", instruction: "Only the menu, not the header" };
37
+
38
+ test("S4: a missing parts.json reads as an empty document", async (t) => {
39
+ const root = designRoot(t);
40
+ assert.deepEqual(await createDesignPartStore(root).read("alpha"), { version: 1, parts: [] });
41
+ });
42
+
43
+ test("S4: add records a sent part with its artboard, element and note, appends the next one, and never touches handoffs.json", async (t) => {
44
+ const root = designRoot(t);
45
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
46
+ const first = await store.add("alpha", SIDEBAR);
47
+ assert.deepEqual(first, { id: "part1", file: "01-a.html", selector: "nav.sidebar", excerpt: "Inicio Tours Reservas", instruction: "Only the menu, not the header", status: "sent", queued: false, sentAt: at(0), startedAt: null, implementedAt: null });
48
+ assert.deepEqual(onDisk(root), { version: 1, parts: [first] });
49
+ assert.deepEqual(readdirSync(join(root, "alpha")), ["parts.json"], "no temp file and no handoffs.json");
50
+
51
+ const second = await store.add("alpha", { file: "02-b.html", selector: " footer\n .links ", excerpt: " a lot\nof space ", instruction: "" });
52
+ assert.deepEqual(second, { id: "part2", file: "02-b.html", selector: "footer .links", excerpt: "a lot of space", status: "sent", queued: false, sentAt: at(1), startedAt: null, implementedAt: null }, "collapsed selector and excerpt; an empty note is left out");
53
+ assert.deepEqual(onDisk(root).parts, [first, second], "in the order they were sent");
54
+ assert.deepEqual(await store.read("alpha"), onDisk(root));
55
+ assert.equal(existsSync(join(root, "alpha", "handoffs.json")), false);
56
+ });
57
+
58
+ test("S4: add refuses a bad artboard path, selector or note, cuts the excerpt to 300, and holds at most DESIGN_PARTS_MAX parts", async (t) => {
59
+ const root = designRoot(t);
60
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
61
+ await assert.rejects(store.add("alpha", { ...SIDEBAR, file: "../x.html" }), isCode("invalid-input"));
62
+ await assert.rejects(store.add("alpha", { ...SIDEBAR, file: "notes.txt" }), isCode("invalid-input"));
63
+ await assert.rejects(store.add("alpha", { ...SIDEBAR, selector: " " }), isCode("invalid-input"), "a selector is required");
64
+ await assert.rejects(store.add("alpha", { ...SIDEBAR, selector: "a".repeat(501) }), isCode("invalid-input"));
65
+ await assert.rejects(store.add("alpha", { ...SIDEBAR, instruction: "n".repeat(2001) }), isCode("invalid-input"));
66
+ assert.equal(existsSync(partsPath(root)), false, "a refused part writes nothing");
67
+ const long = await store.add("alpha", { ...SIDEBAR, excerpt: "x".repeat(400) });
68
+ assert.equal(long.excerpt.length, 300);
69
+ for (let i = 1; i < DESIGN_PARTS_MAX; i++) await store.add("alpha", SIDEBAR);
70
+ assert.equal(onDisk(root).parts.length, DESIGN_PARTS_MAX);
71
+ await assert.rejects(store.add("alpha", SIDEBAR), isCode("limit"));
72
+ assert.equal(onDisk(root).parts.length, DESIGN_PARTS_MAX, "the full file is unchanged");
73
+ });
74
+
75
+ test("S6: setStatus moves a part to in_progress and implemented with timestamps and the agent's note, checked against its artboard", async (t) => {
76
+ const root = designRoot(t);
77
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
78
+ await store.add("alpha", SIDEBAR);
79
+ const started = await store.setStatus("alpha", "01-a.html", "part1", "in_progress", { note: " Building the sidebar\r\n " });
80
+ assert.deepEqual(started, { ...onDisk(root).parts[0], status: "in_progress", startedAt: at(1), implementedAt: null, note: "Building the sidebar" });
81
+ const done = await store.setStatus("alpha", "01-a.html", "part1", "implemented", {});
82
+ assert.equal(done.status, "implemented");
83
+ assert.equal(done.startedAt, at(1), "the start time stays");
84
+ assert.equal(done.implementedAt, at(2));
85
+ assert.equal(done.note, undefined, "the note is exactly what the last call passed");
86
+ assert.deepEqual(onDisk(root).parts, [done]);
87
+ await assert.rejects(store.setStatus("alpha", "01-a.html", "nope", "implemented", {}), isCode("not-found"));
88
+ await assert.rejects(store.setStatus("alpha", "02-b.html", "part1", "implemented", {}), isCode("invalid-input"), "the part belongs to another artboard");
89
+ await assert.rejects(store.setStatus("alpha", "01-a.html", "part1", "sent" as never, {}), isCode("invalid-input"));
90
+ await assert.rejects(store.setStatus("alpha", "01-a.html", "part1", "implemented", { note: "n".repeat(1001) }), isCode("invalid-input"));
91
+ assert.deepEqual(onDisk(root).parts, [done], "refusals change nothing");
92
+ });
93
+
94
+ test("S4: sendDesignPart records the part before delivering it, marks it queued, and takes it back when the delivery fails", async (t) => {
95
+ const root = designRoot(t);
96
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
97
+ const sent = await sendDesignPart(store, "alpha", SIDEBAR, () => {
98
+ assert.equal(onDisk(root).parts.length, 1, "on disk before the session gets the message");
99
+ return { queued: true };
100
+ });
101
+ assert.equal(sent.queued, true);
102
+ assert.equal(sent.part.id, "part1");
103
+ assert.equal(onDisk(root).parts[0].queued, true);
104
+
105
+ await assert.rejects(sendDesignPart(store, "alpha", { ...SIDEBAR, file: "02-b.html" }, () => { throw new Error("session closed"); }), /session closed/);
106
+ assert.deepEqual(onDisk(root).parts.map((part: { id: string }) => part.id), ["part1"], "the failed part is removed, the earlier one kept");
107
+ const idle = await sendDesignPart(store, "alpha", SIDEBAR, () => undefined);
108
+ assert.equal(idle.queued, false);
109
+ assert.equal(onDisk(root).parts[1].queued, false);
110
+ });
111
+
112
+ test("S4: a parts.json the store cannot parse is reported and never overwritten", async (t) => {
113
+ const root = designRoot(t);
114
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
115
+ for (const bad of ["not json", JSON.stringify({ version: 2, parts: [] }), JSON.stringify({ version: 1, parts: {} }), JSON.stringify({ version: 1, parts: [{ id: "x", file: "../a.html" }] })]) {
116
+ writeFileSync(partsPath(root), bad);
117
+ const before = hash(partsPath(root));
118
+ await assert.rejects(store.read("alpha"), isCode("invalid-file"));
119
+ await assert.rejects(store.add("alpha", SIDEBAR), isCode("invalid-file"));
120
+ assert.equal(hash(partsPath(root)), before, "untouched");
121
+ }
122
+ await assert.rejects(store.read("../etc"), isCode("not-found"));
123
+ });
124
+
125
+ // canvas-server-data S2: "Remove" clears a part the agent never reported. It goes through the same serialized
126
+ // parts.json writer, removes only a part still `sent` (queued or not), and refuses anything else without writing.
127
+
128
+ test("S2: removeSent takes out a sent part, queued or not, keeps the others in order, and never touches handoffs.json", async (t) => {
129
+ const root = designRoot(t);
130
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
131
+ const first = await store.add("alpha", SIDEBAR);
132
+ const second = await store.add("alpha", { ...SIDEBAR, file: "02-b.html" });
133
+ const third = await store.add("alpha", SIDEBAR);
134
+ assert.equal(await store.markQueued("alpha", third.id), true);
135
+ assert.deepEqual(await store.removeSent("alpha", "part2"), second, "it answers the removed part");
136
+ assert.deepEqual(onDisk(root), { version: 1, parts: [first, { ...third, queued: true }] });
137
+ assert.deepEqual(await store.removeSent("alpha", "part3"), { ...third, queued: true }, "a queued part is still sent and can be removed");
138
+ assert.deepEqual(onDisk(root), { version: 1, parts: [first] });
139
+ assert.equal(readFileSync(partsPath(root), "utf8"), `${JSON.stringify({ version: 1, parts: [first] }, null, 2)}\n`);
140
+ assert.deepEqual(readdirSync(join(root, "alpha")), ["parts.json"], "no temp file and no handoffs.json");
141
+ });
142
+
143
+ test("S2: removeSent refuses a part in progress or implemented, an unknown or malformed id, a missing design and a broken file, leaving parts.json byte for byte", async (t) => {
144
+ const root = designRoot(t);
145
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
146
+ await store.add("alpha", SIDEBAR);
147
+ await store.add("alpha", SIDEBAR);
148
+ await store.setStatus("alpha", "01-a.html", "part1", "in_progress", {});
149
+ await store.setStatus("alpha", "01-a.html", "part2", "implemented", {});
150
+ writeFileSync(join(root, "alpha", "handoffs.json"), "{\"handoffs\":[]}");
151
+ const before = hash(partsPath(root));
152
+ const handoffs = hash(join(root, "alpha", "handoffs.json"));
153
+ await assert.rejects(store.removeSent("alpha", "part1"), (error: unknown) => error instanceof DesignPartsError && error.code === "not-sent" && error.message === 'Part "part1" is in_progress, not sent; only a sent part can be removed.');
154
+ await assert.rejects(store.removeSent("alpha", "part2"), (error: unknown) => error instanceof DesignPartsError && error.code === "not-sent" && error.message === 'Part "part2" is implemented, not sent; only a sent part can be removed.');
155
+ await assert.rejects(store.removeSent("alpha", "nope"), (error: unknown) => error instanceof DesignPartsError && error.code === "not-found" && error.message === 'No part "nope" in design/alpha/parts.json.');
156
+ for (const id of ["", "UPPER", "a".repeat(33), "../x", 7 as never, undefined as never]) {
157
+ await assert.rejects(store.removeSent("alpha", id), (error: unknown) => error instanceof DesignPartsError && error.code === "invalid-input" && error.message === "id must be 1 to 32 lowercase letters or digits", `id ${String(id)}`);
158
+ }
159
+ await assert.rejects(store.removeSent("missing", "part1"), isCode("not-found"));
160
+ assert.equal(hash(partsPath(root)), before, "every refusal leaves parts.json unchanged");
161
+ assert.equal(hash(join(root, "alpha", "handoffs.json")), handoffs, "and handoffs.json untouched");
162
+ writeFileSync(partsPath(root), "not json");
163
+ await assert.rejects(store.removeSent("alpha", "part1"), isCode("invalid-file"));
164
+ assert.equal(readFileSync(partsPath(root), "utf8"), "not json", "a broken file is never overwritten");
165
+ });
166
+
167
+ test("S2: removeSent shares the serialized writer, so a parallel add and removal both land", async (t) => {
168
+ const root = designRoot(t);
169
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
170
+ await store.add("alpha", SIDEBAR);
171
+ const [added] = await Promise.all([store.add("alpha", { ...SIDEBAR, file: "02-b.html" }), store.removeSent("alpha", "part1")]);
172
+ assert.deepEqual(onDisk(root).parts, [added], "the new part is kept and the removed one is gone");
173
+ });
174
+
175
+ test("S2 preserve: remove still takes back a part whatever its status (a failed delivery)", async (t) => {
176
+ const root = designRoot(t);
177
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
178
+ await store.add("alpha", SIDEBAR);
179
+ await store.setStatus("alpha", "01-a.html", "part1", "implemented", {});
180
+ assert.equal(await store.remove("alpha", "part1"), true);
181
+ assert.equal(await store.remove("alpha", "part1"), false);
182
+ assert.deepEqual(onDisk(root), { version: 1, parts: [] });
183
+ });
184
+
185
+ // canvas-server-data S9: parts.json holds at most 1 MiB. The serialized document is measured before the file is
186
+ // replaced, so a write that would pass the limit is refused and the previous file stays byte for byte. Control
187
+ // characters escape to six bytes each, which is how plain-looking text can reach the limit.
188
+
189
+ const MAX_PARTS_BYTES = 1024 * 1024;
190
+ const CONTROL = "\u0001";
191
+ const serialized = (parts: object[]) => `${JSON.stringify({ version: 1, parts }, null, 2)}\n`;
192
+ const bytesOf = (parts: object[]) => Buffer.byteLength(serialized(parts));
193
+
194
+ /** Filler parts so that the document of the fillers plus `extra` serializes to exactly `target` bytes. */
195
+ function fillTo(target: number, extra: object[]): object[] {
196
+ const fillers: Array<Record<string, unknown>> = [];
197
+ for (let i = 0; ; i++) {
198
+ const part: Record<string, unknown> = { id: `fill${i}`, file: "01-a.html", selector: "s", excerpt: "", instruction: "", status: "sent", queued: false, sentAt: at(0), startedAt: null, implementedAt: null };
199
+ const gap = target - bytesOf([...fillers, ...extra]);
200
+ fillers.push(part);
201
+ const overhead = bytesOf([...fillers, ...extra]) - bytesOf([...fillers.slice(0, -1), ...extra]);
202
+ // Whole six-byte escapes in the instruction, never leaving a gap too small for one more filler.
203
+ let length = Math.min(2000, Math.floor((gap - overhead) / 6));
204
+ if (length === 2000 && gap - overhead - 12000 < overhead + 12) length = 1000;
205
+ assert.ok(length >= 0 && fillers.length < 99, "the fillers fit in the parts a design can hold");
206
+ part.instruction = CONTROL.repeat(length);
207
+ const left = target - bytesOf([...fillers, ...extra]);
208
+ if (left >= 6) continue;
209
+ part.excerpt = "x".repeat(left);
210
+ assert.equal(bytesOf([...fillers, ...extra]), target);
211
+ return fillers;
212
+ }
213
+ }
214
+
215
+ test("S9: add refuses a part that would push parts.json past 1 MiB with a too-large error, leaving the file byte for byte", async (t) => {
216
+ const root = designRoot(t);
217
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
218
+ const added = { id: "part1", ...SIDEBAR, status: "sent", queued: false, sentAt: at(0), startedAt: null, implementedAt: null };
219
+ writeFileSync(partsPath(root), serialized(fillTo(MAX_PARTS_BYTES + 1, [added])));
220
+ const before = hash(partsPath(root));
221
+ await assert.rejects(store.add("alpha", SIDEBAR), (error: unknown) => error instanceof DesignPartsError && error.code === "too-large" && error.message === `design/alpha/parts.json would grow to ${MAX_PARTS_BYTES + 1} bytes, past the 1 MiB it can hold; nothing was written.`);
222
+ assert.equal(hash(partsPath(root)), before, "the previous file is intact");
223
+ assert.deepEqual(readdirSync(join(root, "alpha")), ["parts.json"], "no temp file is left");
224
+ assert.ok((await store.read("alpha")).parts.length > 0, "and it still reads");
225
+ });
226
+
227
+ test("S9: a write that lands exactly on 1 MiB is kept, and control characters in the note count as their six-byte escapes", async (t) => {
228
+ const root = designRoot(t);
229
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
230
+ const added = { id: "part1", ...SIDEBAR, status: "sent", queued: false, sentAt: at(0), startedAt: null, implementedAt: null };
231
+ writeFileSync(partsPath(root), serialized(fillTo(MAX_PARTS_BYTES, [added])));
232
+ assert.deepEqual(await store.add("alpha", SIDEBAR), added);
233
+ assert.equal(readFileSync(partsPath(root)).length, MAX_PARTS_BYTES, "exactly at the limit is allowed");
234
+ const before = hash(partsPath(root));
235
+ await assert.rejects(store.add("alpha", { ...SIDEBAR, instruction: CONTROL }), isCode("too-large"));
236
+ await assert.rejects(store.setStatus("alpha", "01-a.html", "part1", "in_progress", { note: CONTROL.repeat(10) }), isCode("too-large"), "a growing progress note is refused too");
237
+ assert.equal(hash(partsPath(root)), before, "every refusal leaves the full file unchanged");
238
+ assert.deepEqual(await store.removeSent("alpha", "part1"), added, "Remove still repairs a full file");
239
+ assert.ok(readFileSync(partsPath(root)).length < MAX_PARTS_BYTES);
240
+ });
241
+
242
+ // canvas-server-data S11: a repeated in_progress report keeps the time the part was first started.
243
+
244
+ test("S11: a repeated in_progress report keeps the first startedAt; in_progress after implemented starts again", async (t) => {
245
+ const root = designRoot(t);
246
+ const store = createDesignPartStore(root, { now: ticking(), randomId: ids() });
247
+ await store.add("alpha", SIDEBAR);
248
+ const first = await store.setStatus("alpha", "01-a.html", "part1", "in_progress", { note: "header" });
249
+ assert.equal(first.startedAt, at(1));
250
+ const again = await store.setStatus("alpha", "01-a.html", "part1", "in_progress", { note: "menu" });
251
+ assert.equal(again.startedAt, at(1), "the repeated report keeps the start time");
252
+ assert.equal(again.note, "menu", "the note is still exactly what the last call passed");
253
+ assert.equal(onDisk(root).parts[0].startedAt, at(1));
254
+ const done = await store.setStatus("alpha", "01-a.html", "part1", "implemented", {});
255
+ assert.equal(done.startedAt, at(1));
256
+ assert.equal(done.implementedAt, at(3));
257
+ const reopened = await store.setStatus("alpha", "01-a.html", "part1", "in_progress", {});
258
+ assert.equal(reopened.startedAt, at(4), "taking an implemented part up again is a new start, as before");
259
+ assert.equal(reopened.implementedAt, null);
260
+ });
@@ -0,0 +1,215 @@
1
+ import assert from "node:assert/strict";
2
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, symlinkSync, 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 { fileURLToPath } from "node:url";
8
+ import { MAX_SYSTEM_LINE, MAX_SYSTEM_TOKENS, MAX_SYSTEM_MD_BYTES, parseSystemTokens, readSystemTokens } from "../lib/design-system-tokens.ts";
9
+
10
+ // The canvas inspector compares what an artboard renders with design/system.md. The server reads that
11
+ // file read-only and gives the page its tokens: table rows with a backticked `--name` and value.
12
+
13
+ const REAL = readFileSync(fileURLToPath(new URL("../design/system.md", import.meta.url)), "utf8");
14
+
15
+ function scratch(t: TestContext): string {
16
+ const dir = mkdtempSync(join(tmpdir(), "gentle-design-tokens-"));
17
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
18
+ return dir;
19
+ }
20
+
21
+ const byName = (text: string) => new Map(parseSystemTokens(text).map((token) => [token.name, token]));
22
+
23
+ test("S1: the real design/system.md yields the wizard's colors, fonts, radius, shadows and motion tokens, grouped by section", () => {
24
+ const tokens = byName(REAL);
25
+ assert.deepEqual(tokens.get("--bg"), { name: "--bg", value: "#1a1218", section: "Colors", group: "color" });
26
+ assert.equal(tokens.get("--accent")?.value, "#f095c8");
27
+ assert.equal(tokens.get("--text-muted")?.group, "color");
28
+ assert.equal(tokens.get("--border-soft")?.value, "#ffffff17");
29
+ assert.equal(tokens.get("--info")?.value, "#a9c7ee");
30
+ assert.match(tokens.get("--font-sans")!.value, /^Inter, "SF Pro Text"/);
31
+ assert.equal(tokens.get("--font-sans")?.group, "font");
32
+ assert.match(tokens.get("--font-mono")!.value, /^"IosevkaTerm NF"/);
33
+ assert.equal(tokens.get("--radius-sm")?.value, "8px");
34
+ assert.equal(tokens.get("--radius-pill")?.value, "999px");
35
+ assert.equal(tokens.get("--radius-sm")?.group, "radius");
36
+ assert.equal(tokens.get("--glow")?.value, "0 10px 30px #f095c84d");
37
+ assert.equal(tokens.get("--glow-hover")?.value, "0 14px 36px #f095c86b");
38
+ assert.equal(tokens.get("--shadow-panel")?.group, "shadow");
39
+ assert.equal(tokens.get("--ease")?.value, "cubic-bezier(.4, 0, .2, 1)");
40
+ // Prose and non-token rows are not tokens.
41
+ for (const name of tokens.keys()) assert.match(name, /^--[A-Za-z0-9_-]+$/);
42
+ assert.equal(tokens.size, 27, [...tokens.keys()].join(" "));
43
+ });
44
+
45
+ // Every documented token row names the file it comes from in its Source cell, and that file must
46
+ // declare the token with the same value. Returns one line per problem; empty when the file is sound.
47
+ const REPO = fileURLToPath(new URL("..", import.meta.url));
48
+ const rowCells = (line: string) => line.trim().replace(/^\|/, "").replace(/\|$/, "").split(/(?<!\\)\|/).map((cell) => cell.replace(/\\\|/g, "|").trim());
49
+ const declared = (css: string) => {
50
+ const found = new Map<string, string[]>();
51
+ for (const match of css.replace(/\/\*[\s\S]*?\*\//g, "").matchAll(/(--[A-Za-z0-9_-]+)\s*:\s*([^;{}]+);/g)) {
52
+ found.set(match[1], [...(found.get(match[1]) ?? []), match[2].replace(/\s+/g, " ").trim()]);
53
+ }
54
+ return found;
55
+ };
56
+
57
+ function sourceProblems(text: string, root: string): string[] {
58
+ const problems: string[] = [];
59
+ let header: string[] | undefined;
60
+ let checked = 0;
61
+ for (const line of text.split(/\r\n?|\n/)) {
62
+ if (!line.trim().startsWith("|")) {
63
+ header = undefined;
64
+ continue;
65
+ }
66
+ const cells = rowCells(line);
67
+ if (!header) {
68
+ header = cells.map((cell) => cell.toLowerCase());
69
+ continue;
70
+ }
71
+ const tokens = parseSystemTokens(line);
72
+ if (tokens.length === 0) continue;
73
+ checked += tokens.length;
74
+ const names = tokens.map((token) => token.name).join(", ");
75
+ const column = header.indexOf("source");
76
+ const paths = column < 0 ? [] : [...(cells[column] ?? "").matchAll(/`([^`]+)`/g)].map((match) => match[1]);
77
+ if (paths.length !== 1) {
78
+ problems.push(`${names}: the row names no single source file`);
79
+ continue;
80
+ }
81
+ const path = join(root, paths[0]);
82
+ if (paths[0].split(/[\\/]/).includes("..") || !existsSync(path) || !statSync(path).isFile()) {
83
+ problems.push(`${names}: source ${paths[0]} does not exist`);
84
+ continue;
85
+ }
86
+ const css = declared(readFileSync(path, "utf8"));
87
+ for (const token of tokens) {
88
+ const values = css.get(token.name);
89
+ if (!values) problems.push(`${token.name}: not declared in ${paths[0]}`);
90
+ else if (!values.includes(token.value.replace(/\s+/g, " ").trim())) problems.push(`${token.name}: ${token.value} in system.md, ${values.join(" | ")} in ${paths[0]}`);
91
+ }
92
+ }
93
+ const total = parseSystemTokens(text).length;
94
+ if (checked !== total) problems.push(`${total - checked} documented tokens sit outside a table with a Source column`);
95
+ return problems;
96
+ }
97
+
98
+ test("S8: every token of the real design/system.md is declared, with the same value, in the source file its row names", () => {
99
+ assert.ok(parseSystemTokens(REAL).length > 0, "the real file documents tokens");
100
+ assert.deepEqual(sourceProblems(REAL, REPO), []);
101
+ });
102
+
103
+ test("S7: the real design/system.md describes the project only, never the canvas UI style", () => {
104
+ for (const canvas of ["design-canvas", "canvas.css", "--gd-", "Same brand set", "| both |"]) assert.ok(!REAL.includes(canvas), `system.md mentions ${canvas}`);
105
+ });
106
+
107
+ test("S8: the source check fails on a missing token, a different value, a row without a source and a source that does not exist", (t) => {
108
+ const root = scratch(t);
109
+ writeFileSync(join(root, "theme.css"), ":root {\n\t--a: #111111;\n\t--b: 0 1px 2px #000;\n}\n/* --c: #333333; */\n");
110
+ const table = (rows: string[]) => ["## Colors", "", "| Token | Value | Source |", "| --- | --- | --- |", ...rows].join("\n");
111
+ assert.deepEqual(sourceProblems(table(["| `--a` | `#111111` | `theme.css` |", "| `--b` | `0 1px 2px #000` | `theme.css` |"]), root), []);
112
+ assert.deepEqual(sourceProblems(table(["| `--c` | `#333333` | `theme.css` |"]), root), ["--c: not declared in theme.css"]);
113
+ assert.deepEqual(sourceProblems(table(["| `--a` | `#222222` | `theme.css` |"]), root), ["--a: #222222 in system.md, #111111 in theme.css"]);
114
+ assert.deepEqual(sourceProblems(table(["| `--a` | `#111111` | both |"]), root), ["--a: the row names no single source file"]);
115
+ assert.deepEqual(sourceProblems(table(["| `--a` | `#111111` | `gone.css` |"]), root), ["--a: source gone.css does not exist"]);
116
+ assert.deepEqual(sourceProblems(table(["| `--a` | `#111111` | `../theme.css` |"]), root), ["--a: source ../theme.css does not exist"]);
117
+ assert.deepEqual(sourceProblems("## Colors\n\n| Token | Value |\n| --- | --- |\n| `--a` | `#111111` |\n", root), ["--a: the row names no single source file"]);
118
+ assert.deepEqual(sourceProblems("## Colors\n\n| `--a` | `#111111` | `theme.css` |\n", root), ["1 documented tokens sit outside a table with a Source column"]);
119
+ });
120
+
121
+ test("S1: only table rows whose cells carry backticked names are tokens; headers, separators and prose are skipped", () => {
122
+ const text = [
123
+ "## Colors",
124
+ "",
125
+ "| Token | Value | Usage |",
126
+ "| --- | --- | --- |",
127
+ "| `--bg` | `#1a1218` | Page |",
128
+ "| --plain | `#fff` | no backticks on the name |",
129
+ "| `--novalue` | #fff | no backticks on the value |",
130
+ "| `not-a-property` | `#000` | not a custom property |",
131
+ "| `--ok-2_x` | `#abc` | |",
132
+ "A line outside a table with `--x` `#123`.",
133
+ "| |",
134
+ "|`--tight`|`#010101`|",
135
+ ].join("\n");
136
+ assert.deepEqual([...byName(text).keys()], ["--bg", "--ok-2_x", "--tight"]);
137
+ });
138
+
139
+ test("S1: a name listed in two cells is paired with its value; unequal lists are skipped", () => {
140
+ const text = "## Colors\n| `--a` / `--b` | `#111111` / `#222222` | x |\n| `--c` / `--d` | `#333333` | x |\n";
141
+ const tokens = byName(text);
142
+ assert.equal(tokens.get("--a")?.value, "#111111");
143
+ assert.equal(tokens.get("--b")?.value, "#222222");
144
+ assert.equal(tokens.has("--c"), false);
145
+ assert.equal(tokens.has("--d"), false);
146
+ });
147
+
148
+ test("S1: a duplicate name keeps its first definition, CRLF files and escaped pipes parse, and groups follow the section heading", () => {
149
+ const text = ["## Colors", "| `--a` | `#111111` |", "| `--a` | `#999999` |", "## Spacing", "| `--space-1` | `4px` |", "## Radius", "| `--r` | `a \\| b` |", "## Misc", "| `--m` | `1` |", ""].join("\r\n");
150
+ const tokens = parseSystemTokens(text);
151
+ assert.deepEqual(tokens.map((token) => [token.name, token.value, token.group]), [["--a", "#111111", "color"], ["--space-1", "4px", "spacing"], ["--r", "a | b", "radius"], ["--m", "1", "other"]]);
152
+ assert.equal(tokens[0].section, "Colors");
153
+ });
154
+
155
+ test("S1: rows before any heading have an empty section, and prose or an empty file has no tokens", () => {
156
+ assert.deepEqual(parseSystemTokens("| `--a` | `#111111` |").map((token) => [token.name, token.section]), [["--a", ""]]);
157
+ assert.deepEqual(parseSystemTokens(""), []);
158
+ assert.deepEqual(parseSystemTokens("# Title\n\nJust prose.\n"), []);
159
+ });
160
+
161
+ test("S1: tokens, names, values and sections are bounded", () => {
162
+ const rows = Array.from({ length: MAX_SYSTEM_TOKENS + 50 }, (_, index) => `| \`--t${index}\` | \`#000000\` |`).join("\n");
163
+ assert.equal(parseSystemTokens(`## Many\n${rows}`).length, MAX_SYSTEM_TOKENS);
164
+ assert.deepEqual(parseSystemTokens(`| \`--${"n".repeat(80)}\` | \`#000\` |`), [], "a name over 64 characters");
165
+ assert.deepEqual(parseSystemTokens(`| \`--v\` | \`${"x".repeat(401)}\` |`), [], "a value over 400 characters");
166
+ assert.equal(parseSystemTokens(`## ${"h".repeat(200)}\n| \`--a\` | \`#000\` |`)[0].section.length, 80);
167
+ });
168
+
169
+ test("a pathological first cell parses in linear time, and lines past the length cap are skipped", () => {
170
+ for (const filler of [" ", "1", " :", ".5"]) {
171
+ const line = `| \`--a\` ${filler.repeat(60_000)}x | y |`;
172
+ const started = performance.now();
173
+ assert.deepEqual(parseSystemTokens(`## Colors\n${line}\n`), [], JSON.stringify(filler));
174
+ assert.ok(performance.now() - started < 200, `${JSON.stringify(filler)} took ${Math.round(performance.now() - started)} ms`);
175
+ }
176
+ // Inline tokens still parse.
177
+ assert.deepEqual(parseSystemTokens("## Radius\n| `--radius-sm` 8px, `--radius-md`: `12px` | x |\n").map((token) => [token.name, token.value]), [["--radius-sm", "8px"], ["--radius-md", "12px"]]);
178
+ const long = `| \`--long\` | \`#000\` | ${"note ".repeat(MAX_SYSTEM_LINE / 5)} |`;
179
+ assert.ok(long.length > MAX_SYSTEM_LINE);
180
+ assert.deepEqual(parseSystemTokens(`## Colors\n${long}\n| \`--short\` | \`#fff\` |\n`).map((token) => token.name), ["--short"], "an over-long line is skipped, the next one still parses");
181
+ });
182
+
183
+ test("S1: readSystemTokens reads design/system.md read-only and never throws", async (t) => {
184
+ const root = scratch(t);
185
+ assert.deepEqual(await readSystemTokens(root), { exists: false, tokens: [] }, "missing file");
186
+ assert.deepEqual(await readSystemTokens(join(root, "no-such-design-root")), { exists: false, tokens: [] }, "missing design root");
187
+ writeFileSync(join(root, "system.md"), "");
188
+ assert.deepEqual(await readSystemTokens(root), { exists: true, tokens: [] }, "empty file");
189
+ writeFileSync(join(root, "system.md"), "garbage \u0000 \ud800 | | |\n| `--a` | `#112233` |\n");
190
+ assert.deepEqual((await readSystemTokens(root)).tokens.map((token) => token.name), ["--a"], "malformed content");
191
+ writeFileSync(join(root, "system.md"), REAL);
192
+ const real = await readSystemTokens(root);
193
+ assert.equal(real.exists, true);
194
+ assert.deepEqual(real.tokens, parseSystemTokens(REAL));
195
+ });
196
+
197
+ test("S1: a file past the size limit gives no tokens and says why, without reading it", async (t) => {
198
+ const root = scratch(t);
199
+ writeFileSync(join(root, "system.md"), `## Colors\n| \`--a\` | \`#000\` |\n${"x".repeat(MAX_SYSTEM_MD_BYTES)}`);
200
+ assert.deepEqual(await readSystemTokens(root), { exists: true, tokens: [], problem: "too-large" });
201
+ });
202
+
203
+ test("S1: a symlink out of the design root, a directory, or a broken link is not read", async (t) => {
204
+ const root = scratch(t);
205
+ const outside = scratch(t);
206
+ writeFileSync(join(outside, "system.md"), "| `--a` | `#112233` |");
207
+ symlinkSync(join(outside, "system.md"), join(root, "system.md"));
208
+ assert.deepEqual(await readSystemTokens(root), { exists: false, tokens: [] });
209
+ const dir = scratch(t);
210
+ mkdirSync(join(dir, "system.md"));
211
+ assert.deepEqual(await readSystemTokens(dir), { exists: false, tokens: [] });
212
+ const broken = scratch(t);
213
+ symlinkSync(join(broken, "gone.md"), join(broken, "system.md"));
214
+ assert.deepEqual(await readSystemTokens(broken), { exists: false, tokens: [] });
215
+ });