gentle-pi 4.8.0 → 4.9.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 (370) hide show
  1. package/README.md +60 -0
  2. package/assets/agents/gentle-ai-explore.md +1 -1
  3. package/assets/agents/gentle-ai-verify.md +1 -1
  4. package/assets/agents/gentle-ai-worker.md +10 -9
  5. package/assets/design-canvas/canvas-boards.js +22 -2
  6. package/assets/design-canvas/canvas-boot.js +3 -1
  7. package/assets/design-canvas/canvas-i18n-es.js +5 -0
  8. package/assets/design-canvas/canvas-menu.js +13 -7
  9. package/assets/design-canvas/canvas-messages.js +1 -1
  10. package/assets/design-canvas/canvas-rail.js +5 -2
  11. package/assets/design-canvas/canvas-store.js +3 -0
  12. package/assets/design-canvas/canvas-theme.js +69 -0
  13. package/assets/design-canvas/canvas.css +27 -2
  14. package/assets/design-canvas/index.html +3 -0
  15. package/assets/design-canvas/inspector.js +28 -5
  16. package/assets/design-canvas/theme-early.js +10 -0
  17. package/assets/migrations/agent-body-history.json +6 -0
  18. package/assets/orchestrator-delegation.md +1 -5
  19. package/assets/orchestrator-full-delegation-card.md +9 -13
  20. package/assets/orchestrator-full-delegation.md +2 -2
  21. package/assets/orchestrator-memory.md +2 -2
  22. package/assets/orchestrator-prompts.md +3 -31
  23. package/assets/orchestrator-tracking.md +6 -6
  24. package/assets/orchestrator-verification.md +4 -4
  25. package/assets/orchestrator-writer.md +12 -12
  26. package/assets/orchestrator.md +2 -2
  27. package/bin/gentle-shell.mjs +77 -1
  28. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +7 -7
  29. package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/manifest.json +3 -3
  30. package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/orchestration/pi.md +1 -1
  31. package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/routing/pi.md +10 -10
  32. package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
  33. package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
  34. package/docs/assets/features/gentle-tower.png +0 -0
  35. package/docs/auto-permission-answers.md +1 -1
  36. package/docs/bundled-install.md +1 -1
  37. package/docs/delegated-verification.md +6 -4
  38. package/docs/desktop-feed.md +303 -0
  39. package/docs/desktop-rpc.md +703 -25
  40. package/docs/fast-mode.md +2 -2
  41. package/docs/gentle-shell-desktop.md +465 -0
  42. package/docs/gentle-shell.md +65 -3
  43. package/docs/images/desktop/chat.png +0 -0
  44. package/docs/images/desktop/palette.png +0 -0
  45. package/docs/images/desktop/todo.png +0 -0
  46. package/docs/install-wizard.md +1 -1
  47. package/docs/odd-preparation-continuity.md +1 -1
  48. package/docs/readme-reference.md +44 -15
  49. package/docs/work-continuity.md +10 -7
  50. package/extensions/ask-user-choice.ts +36 -18
  51. package/extensions/ask-user-question.ts +47 -8
  52. package/extensions/gentle-agents.ts +206 -37
  53. package/extensions/gentle-ai.ts +234 -24
  54. package/extensions/gentle-desktop-feed.ts +778 -0
  55. package/extensions/gentle-desktop-rpc.ts +145 -12
  56. package/extensions/gentle-herdr-desktop-status.ts +275 -0
  57. package/extensions/gentle-shell.ts +69 -7
  58. package/extensions/gentle-stats.ts +30 -1
  59. package/extensions/gentle-tower.ts +305 -0
  60. package/extensions/skill-registry.ts +13 -3
  61. package/herdr/RECIPE.md +157 -0
  62. package/herdr/keys.json +14 -0
  63. package/herdr/layouts/gentle-shell.json +202 -0
  64. package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
  65. package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
  66. package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
  67. package/herdr/mods/gentle-agents/main.js +190 -0
  68. package/herdr/mods/gentle-agents/mod.json +1 -0
  69. package/herdr/mods/gentle-agents/snapshot.js +469 -0
  70. package/herdr/mods/gentle-agents/tokens.js +273 -0
  71. package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
  72. package/herdr/mods/gentle-chat/actions.js +180 -0
  73. package/herdr/mods/gentle-chat/feed.js +321 -0
  74. package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
  75. package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
  76. package/herdr/mods/gentle-chat/icons/check.svg +1 -0
  77. package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
  78. package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
  79. package/herdr/mods/gentle-chat/icons/down.svg +1 -0
  80. package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
  81. package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
  82. package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
  83. package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
  84. package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
  85. package/herdr/mods/gentle-chat/icons/send.svg +1 -0
  86. package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
  87. package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
  88. package/herdr/mods/gentle-chat/icons/term.svg +1 -0
  89. package/herdr/mods/gentle-chat/icons/user.svg +1 -0
  90. package/herdr/mods/gentle-chat/icons/x.svg +1 -0
  91. package/herdr/mods/gentle-chat/main.js +968 -0
  92. package/herdr/mods/gentle-chat/mod.json +1 -0
  93. package/herdr/mods/gentle-chat/session.js +212 -0
  94. package/herdr/mods/gentle-chat/snapshot.js +469 -0
  95. package/herdr/mods/gentle-chat/tokens.js +137 -0
  96. package/herdr/mods/gentle-chat/ui.js +883 -0
  97. package/herdr/mods/gentle-confirm/main.js +60 -0
  98. package/herdr/mods/gentle-confirm/mod.json +1 -0
  99. package/herdr/mods/gentle-inspector/actions.js +180 -0
  100. package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
  101. package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
  102. package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
  103. package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
  104. package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
  105. package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
  106. package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
  107. package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
  108. package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
  109. package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
  110. package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
  111. package/herdr/mods/gentle-inspector/main.js +500 -0
  112. package/herdr/mods/gentle-inspector/mod.json +1 -0
  113. package/herdr/mods/gentle-inspector/snapshot.js +469 -0
  114. package/herdr/mods/gentle-inspector/tokens.js +273 -0
  115. package/herdr/mods/gentle-palette/actions.js +180 -0
  116. package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
  117. package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
  118. package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
  119. package/herdr/mods/gentle-palette/icons/check.svg +1 -0
  120. package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
  121. package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
  122. package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
  123. package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
  124. package/herdr/mods/gentle-palette/icons/review.svg +1 -0
  125. package/herdr/mods/gentle-palette/icons/search.svg +1 -0
  126. package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
  127. package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
  128. package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
  129. package/herdr/mods/gentle-palette/icons/term.svg +1 -0
  130. package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
  131. package/herdr/mods/gentle-palette/main.js +333 -0
  132. package/herdr/mods/gentle-palette/mod.json +1 -0
  133. package/herdr/mods/gentle-palette/snapshot.js +469 -0
  134. package/herdr/mods/gentle-palette/tokens.js +273 -0
  135. package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
  136. package/herdr/mods/gentle-pane/icons/close.svg +1 -0
  137. package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
  138. package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
  139. package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
  140. package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
  141. package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
  142. package/herdr/mods/gentle-pane/icons/term.svg +1 -0
  143. package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
  144. package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
  145. package/herdr/mods/gentle-pane/main.js +91 -0
  146. package/herdr/mods/gentle-pane/mod.json +1 -0
  147. package/herdr/mods/gentle-pane/snapshot.js +469 -0
  148. package/herdr/mods/gentle-pane/tokens.js +273 -0
  149. package/herdr/mods/gentle-sidebar/actions.js +180 -0
  150. package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
  151. package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
  152. package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
  153. package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
  154. package/herdr/mods/gentle-sidebar/main.js +171 -0
  155. package/herdr/mods/gentle-sidebar/mod.json +1 -0
  156. package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
  157. package/herdr/mods/gentle-sidebar/tokens.js +273 -0
  158. package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
  159. package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
  160. package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
  161. package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
  162. package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
  163. package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
  164. package/herdr/mods/gentle-spaces/machines.js +31 -0
  165. package/herdr/mods/gentle-spaces/main.js +299 -0
  166. package/herdr/mods/gentle-spaces/mod.json +1 -0
  167. package/herdr/mods/gentle-spaces/snapshot.js +469 -0
  168. package/herdr/mods/gentle-spaces/tokens.js +273 -0
  169. package/herdr/mods/gentle-status/actions.js +180 -0
  170. package/herdr/mods/gentle-status/main.js +192 -0
  171. package/herdr/mods/gentle-status/mod.json +1 -0
  172. package/herdr/mods/gentle-status/snapshot.js +469 -0
  173. package/herdr/mods/gentle-status/tokens.js +273 -0
  174. package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
  175. package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
  176. package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
  177. package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
  178. package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
  179. package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
  180. package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
  181. package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
  182. package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
  183. package/herdr/mods/gentle-tabs/main.js +171 -0
  184. package/herdr/mods/gentle-tabs/mod.json +1 -0
  185. package/herdr/mods/gentle-tabs/snapshot.js +469 -0
  186. package/herdr/mods/gentle-tabs/tokens.js +273 -0
  187. package/herdr/mods/gentle-tokens/main.js +20 -0
  188. package/herdr/mods/gentle-tokens/mod.json +1 -0
  189. package/herdr/mods/gentle-tokens/snapshot.js +469 -0
  190. package/herdr/mods/gentle-tokens/tokens.js +273 -0
  191. package/herdr/preview.png +0 -0
  192. package/herdr/themes/gentle-shell-dark.json +33 -0
  193. package/herdr/themes/gentle-shell-light.json +34 -0
  194. package/lib/agents-protocol.ts +2 -0
  195. package/lib/agents-rpc-publisher.ts +39 -12
  196. package/lib/agents-runner.ts +1 -0
  197. package/lib/auto-permission-answers.ts +2 -1
  198. package/lib/background-jobs.ts +22 -2
  199. package/lib/bounded-writer-admission.ts +1 -1
  200. package/lib/change-diff.ts +104 -0
  201. package/lib/commit-slice-signal.ts +1 -1
  202. package/lib/design-canvas-assets.ts +2 -0
  203. package/lib/desktop-agents-service.ts +31 -10
  204. package/lib/desktop-changes-service.ts +171 -0
  205. package/lib/desktop-feed-actions.ts +804 -0
  206. package/lib/desktop-feed-answers.ts +129 -0
  207. package/lib/desktop-feed-sources.ts +184 -0
  208. package/lib/desktop-feed-stats.ts +98 -0
  209. package/lib/desktop-feed-store.ts +124 -0
  210. package/lib/desktop-feed.ts +788 -0
  211. package/lib/desktop-jobs-service.ts +34 -7
  212. package/lib/desktop-review-service.ts +187 -0
  213. package/lib/desktop-rpc-agents.ts +112 -3
  214. package/lib/desktop-rpc-changes.ts +223 -0
  215. package/lib/desktop-rpc-config-watch.ts +285 -0
  216. package/lib/desktop-rpc-config.ts +162 -8
  217. package/lib/desktop-rpc-jobs.ts +118 -9
  218. package/lib/desktop-rpc-permissions.ts +154 -3
  219. package/lib/desktop-rpc-review.ts +180 -0
  220. package/lib/desktop-rpc-session.ts +203 -0
  221. package/lib/desktop-rpc-sessions.ts +250 -0
  222. package/lib/desktop-rpc-stats.ts +187 -0
  223. package/lib/desktop-rpc-updates.ts +143 -0
  224. package/lib/desktop-rpc.ts +116 -5
  225. package/lib/desktop-session-service.ts +223 -0
  226. package/lib/desktop-sessions-service.ts +249 -0
  227. package/lib/desktop-stats-service.ts +142 -0
  228. package/lib/desktop-updates-service.ts +268 -0
  229. package/lib/gentle-shell-desktop.ts +1370 -0
  230. package/lib/gentle-shell-launcher.ts +45 -3
  231. package/lib/herdr-desktop-events.ts +40 -0
  232. package/lib/herdr-desktop-status.ts +229 -0
  233. package/lib/jobs-sidebar-state.ts +5 -0
  234. package/lib/native-review-cli.ts +7 -0
  235. package/lib/openai-fast-tier.ts +1 -0
  236. package/lib/session-profile-freeze.ts +13 -5
  237. package/lib/stats-collector.ts +56 -27
  238. package/lib/tower-actions.ts +100 -0
  239. package/lib/tower-hub.ts +73 -0
  240. package/lib/tower-launch.ts +111 -0
  241. package/lib/tower-open.ts +99 -0
  242. package/lib/tower-presence.ts +70 -0
  243. package/lib/tower-server.ts +234 -0
  244. package/lib/tower-snapshot.ts +298 -0
  245. package/lib/update-status.ts +238 -0
  246. package/lib/verifier-settle-reminder.ts +1 -1
  247. package/package.json +13 -4
  248. package/runtime/design-canvas-assets.mjs +2 -0
  249. package/runtime/gentle-shell-desktop.mjs +1371 -0
  250. package/runtime/gentle-shell-launcher.mjs +44 -2
  251. package/runtime/native-review-cli.mjs +7 -0
  252. package/runtime/tower-actions.mjs +101 -0
  253. package/runtime/tower-hub.mjs +74 -0
  254. package/runtime/tower-launch.mjs +112 -0
  255. package/runtime/tower-open.mjs +100 -0
  256. package/runtime/tower-presence.mjs +71 -0
  257. package/runtime/tower-server.mjs +234 -0
  258. package/runtime/tower-snapshot.mjs +299 -0
  259. package/scripts/build-full-delegation-card.mjs +1 -21
  260. package/scripts/build-runtime-modules.mjs +9 -0
  261. package/scripts/gentle-ai-installer.mjs +10 -10
  262. package/scripts/verify-package-files.mjs +35 -15
  263. package/skills/provider-defect-report/SKILL.md +61 -0
  264. package/skills/rdd-defect-workflow/SKILL.md +3 -3
  265. package/tests/agent-prompt-diet-contract.test.ts +2 -2
  266. package/tests/append-system-prompt-route.test.ts +16 -5
  267. package/tests/ask-user-choice.test.ts +78 -21
  268. package/tests/ask-user-question.test.ts +59 -5
  269. package/tests/auto-permission-answers.test.ts +12 -1
  270. package/tests/background-jobs.test.ts +12 -0
  271. package/tests/bounded-stop-contract.test.ts +139 -26
  272. package/tests/change-diff.test.ts +75 -0
  273. package/tests/commit-slice-signal.test.ts +3 -2
  274. package/tests/decision-routing-contract.test.ts +390 -0
  275. package/tests/delegated-key-learnings-contract.test.ts +21 -28
  276. package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
  277. package/tests/design-canvas-i18n.test.ts +24 -22
  278. package/tests/design-canvas-inspector.test.ts +67 -0
  279. package/tests/design-canvas-modules.test.ts +3 -2
  280. package/tests/design-canvas-rail.test.ts +10 -10
  281. package/tests/design-canvas-store.test.ts +9 -0
  282. package/tests/design-canvas-theme.test.ts +198 -0
  283. package/tests/design-canvas-tokens.test.ts +1 -1
  284. package/tests/desktop-feed-actions-guards.test.ts +595 -0
  285. package/tests/desktop-feed-actions.test.ts +761 -0
  286. package/tests/desktop-feed-live-work.test.ts +209 -0
  287. package/tests/desktop-feed-performance.test.ts +369 -0
  288. package/tests/desktop-feed-plan-profiles.test.ts +509 -0
  289. package/tests/desktop-feed-send-prompt.test.ts +303 -0
  290. package/tests/desktop-feed-tool-summaries.test.ts +69 -0
  291. package/tests/desktop-feed.test.ts +615 -0
  292. package/tests/desktop-rpc-agents.test.ts +428 -2
  293. package/tests/desktop-rpc-changes.test.ts +608 -0
  294. package/tests/desktop-rpc-config-watch.test.ts +1159 -0
  295. package/tests/desktop-rpc-config.test.ts +11 -1
  296. package/tests/desktop-rpc-design.test.ts +11 -1
  297. package/tests/desktop-rpc-jobs.test.ts +402 -5
  298. package/tests/desktop-rpc-permissions.test.ts +11 -1
  299. package/tests/desktop-rpc-review.test.ts +678 -0
  300. package/tests/desktop-rpc-session.test.ts +642 -0
  301. package/tests/desktop-rpc-sessions.test.ts +647 -0
  302. package/tests/desktop-rpc-stats.test.ts +431 -0
  303. package/tests/desktop-rpc-updates.test.ts +525 -0
  304. package/tests/desktop-rpc-usage.test.ts +11 -1
  305. package/tests/desktop-rpc.test.ts +43 -2
  306. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +11 -13
  307. package/tests/fixtures/session-profile-v1/replay.ts +4 -1
  308. package/tests/full-delegation-closure.test.ts +20 -1
  309. package/tests/gentle-agents.test.ts +519 -4
  310. package/tests/gentle-ai-binary.test.ts +1 -1
  311. package/tests/gentle-ai-installer.test.ts +52 -52
  312. package/tests/gentle-ai.test.ts +75 -16
  313. package/tests/gentle-fast.test.ts +15 -0
  314. package/tests/gentle-herdr-desktop-status.test.ts +595 -0
  315. package/tests/gentle-shell-desktop-bin.test.ts +125 -0
  316. package/tests/gentle-shell-desktop.test.ts +927 -0
  317. package/tests/gentle-shell-launcher-tower.test.ts +104 -0
  318. package/tests/gentle-shell.test.ts +3 -0
  319. package/tests/gentle-tower.test.ts +578 -0
  320. package/tests/herdr-desktop-status.test.ts +285 -0
  321. package/tests/independent-recovery-delivery.test.ts +16 -4
  322. package/tests/installer-server.test.ts +2 -2
  323. package/tests/lazy-module-contradictions-contract.test.ts +27 -4
  324. package/tests/maintainer/desktop-rpc.maintest.ts +279 -4
  325. package/tests/native-review-capability-contract.test.ts +9 -1
  326. package/tests/no-self-pause-contract.test.ts +23 -13
  327. package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
  328. package/tests/odd-routing-contract.test.ts +19 -3
  329. package/tests/orchestrator-budget.test.ts +3 -1
  330. package/tests/orchestrator-prompt-budget.test.ts +2 -1
  331. package/tests/orchestrator-prompt-diet-contract.test.ts +31 -3
  332. package/tests/package-manifest.test.ts +10 -10
  333. package/tests/pi-routing-measured-values.test.ts +24 -0
  334. package/tests/primary-session-prompt.test.ts +25 -0
  335. package/tests/profile-fast-tier.test.ts +66 -1
  336. package/tests/provider-defect-handoff.test.ts +118 -100
  337. package/tests/review-contract-prompt.test.ts +2 -1
  338. package/tests/review-due-public-boundary.test.ts +2 -1
  339. package/tests/sensitive-path-tools.test.ts +138 -4
  340. package/tests/session-profile-extension.test.ts +310 -16
  341. package/tests/session-profile-freeze.test.ts +26 -0
  342. package/tests/session-profile-v1-compat.test.ts +20 -0
  343. package/tests/skill-collision-prefixes.test.ts +1 -0
  344. package/tests/skill-contradictions-contract.test.ts +5 -3
  345. package/tests/skill-registry.test.ts +54 -0
  346. package/tests/stats-collector.test.ts +109 -2
  347. package/tests/support/design-canvas-dom.ts +17 -0
  348. package/tests/task-size-routing-contract.test.ts +7 -3
  349. package/tests/tower-actions.test.ts +247 -0
  350. package/tests/tower-artifacts.test.ts +114 -0
  351. package/tests/tower-open.test.ts +97 -0
  352. package/tests/tower-presence.test.ts +175 -0
  353. package/tests/tower-server.test.ts +122 -0
  354. package/tests/tower-snapshot.test.ts +236 -0
  355. package/tests/tower-web-echo.test.ts +125 -0
  356. package/tests/tower-web-hover.test.ts +251 -0
  357. package/tests/verification-scoped-stop-contract.test.ts +32 -0
  358. package/tests/verification-tiers-contract.test.ts +5 -5
  359. package/tests/verifier-settle-reminder.test.ts +2 -2
  360. package/tests/verify-first-launch-contract.test.ts +2 -2
  361. package/tests/work-continuity-contract.test.ts +83 -17
  362. package/tests/writer-rejection-next-step.test.ts +55 -0
  363. package/tests/writer-surface-authority-contract.test.ts +158 -0
  364. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/README.md +0 -0
  365. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
  366. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
  367. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  368. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
  369. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
  370. /package/contracts/review-provider-contract-mirror/{v1.5.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -0,0 +1,236 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtempSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test, { after } from "node:test";
6
+ import { buildTowerSnapshot, chatFromBranch, nameSubagents, TOWER_CHAT_TEXT_MAX, TOWER_CHAT_TURNS, TOWER_SNAPSHOT_VERSION } from "../lib/tower-snapshot.ts";
7
+ import { readTowerSnapshots, removeTowerSnapshot, TOWER_SNAPSHOT_MAX_BYTES, writeTowerSnapshot } from "../lib/tower-hub.ts";
8
+
9
+ const roots: string[] = [];
10
+ after(() => roots.forEach((r) => rmSync(r, { recursive: true, force: true })));
11
+ function scratch(): string {
12
+ const r = mkdtempSync(join(tmpdir(), "gentle-tower-"));
13
+ roots.push(r);
14
+ return join(r, "hub");
15
+ }
16
+
17
+ const base = {
18
+ sessionId: "s-1",
19
+ sessionName: "Token refresh fix",
20
+ cwd: "/Users/me/work/gentle-ai",
21
+ modelId: "claude-opus-5-5",
22
+ effort: "high",
23
+ context: { percent: 38, contextWindow: 200000 },
24
+ stats: { cost: 0.42, input: 121000, output: 9800 },
25
+ todos: [
26
+ { id: 1, title: "Reproduce with a failing test", status: "done" as const },
27
+ { id: 2, title: "Retry once when the refresh fails", status: "blocked" as const, note: "waiting for your answer" },
28
+ ],
29
+ agents: [
30
+ { id: "t1", agent: "gentle-ai-worker", status: "running", lastStep: "editing", usage: { total: 1200, cost: 0.03 } },
31
+ { id: "t2", agent: "gentle-ai-explore", status: "completed", lastStep: "done", usage: { total: 800, cost: 0.01 } },
32
+ ],
33
+ phase: "implementing",
34
+ now: 1700000000000,
35
+ };
36
+
37
+ test("snapshot maps the live session data the tower shows", () => {
38
+ const s = buildTowerSnapshot(base);
39
+ assert.equal(s.version, TOWER_SNAPSHOT_VERSION);
40
+ assert.equal(s.sessionId, "s-1");
41
+ assert.equal(s.name, "Token refresh fix");
42
+ assert.deepEqual(s.project, { cwd: "/Users/me/work/gentle-ai", name: "gentle-ai" });
43
+ assert.equal(s.model, "claude-opus-5-5");
44
+ assert.equal(s.effort, "high");
45
+ assert.deepEqual(s.context, { percent: 38, window: 200000 });
46
+ assert.deepEqual(s.cost, { total: 0.42, input: 121000, output: 9800 });
47
+ assert.deepEqual(s.todos, [
48
+ { id: 1, title: "Reproduce with a failing test", status: "done" },
49
+ { id: 2, title: "Retry once when the refresh fails", status: "blocked", note: "waiting for your answer" },
50
+ ]);
51
+ assert.deepEqual(s.subagents.map((a) => [a.name, a.role, a.status, a.lastStep, a.cost]), [
52
+ ["worker", "worker", "running", "editing", 0.03],
53
+ ["explore", "explore", "completed", "done", 0.01],
54
+ ]);
55
+ assert.equal(s.phase, "implementing");
56
+ assert.equal(s.updatedAt, 1700000000000);
57
+ });
58
+
59
+ test("snapshot falls back when the session has no name, model or context yet", () => {
60
+ const s = buildTowerSnapshot({ ...base, sessionName: undefined, modelId: undefined, effort: undefined, context: undefined, todos: [], agents: [], phase: undefined });
61
+ assert.equal(s.name, "gentle-ai");
62
+ assert.equal(s.model, "no-model");
63
+ assert.equal(s.effort, undefined);
64
+ assert.deepEqual(s.context, { percent: null, window: 0 });
65
+ assert.deepEqual(s.todos, []);
66
+ assert.deepEqual(s.subagents, []);
67
+ assert.equal(s.phase, undefined);
68
+ });
69
+
70
+ test("subagents are named by role, with a task word only when a role repeats", () => {
71
+ const named = nameSubagents([
72
+ { id: "a", agent: "gentle-ai-worker", label: "write the session tests" },
73
+ { id: "b", agent: "gentle-ai-worker", label: "Change session.go" },
74
+ { id: "c", agent: "gentle-ai-explore" },
75
+ { id: "d", agent: "gentle-ai-verify" },
76
+ { id: "e", agent: "gentle-ai-verify" },
77
+ ]);
78
+ assert.deepEqual(named.map((n) => n.name), ["worker-session", "worker-change", "explore", "verify-d", "verify-e"]);
79
+ assert.deepEqual(named.map((n) => n.role), ["worker", "worker", "explore", "verify", "verify"]);
80
+ });
81
+
82
+ test("the hub writes atomically with private permissions and reads every session back", () => {
83
+ const dir = scratch();
84
+ const s = buildTowerSnapshot(base);
85
+ writeTowerSnapshot(dir, s);
86
+ writeTowerSnapshot(dir, { ...s, name: "renamed" });
87
+ // Windows has no POSIX file modes (stat reports 0o666), so only POSIX checks them.
88
+ const posix = process.platform !== "win32";
89
+ if (posix) assert.equal(statSync(dir).mode & 0o777, 0o700);
90
+ const files = readdirSync(dir);
91
+ assert.deepEqual(files, ["s-1.json"]);
92
+ if (posix) assert.equal(statSync(join(dir, "s-1.json")).mode & 0o777, 0o600);
93
+ assert.deepEqual(readTowerSnapshots(dir).map((x) => x.name), ["renamed"]);
94
+ removeTowerSnapshot(dir, "s-1");
95
+ assert.deepEqual(readdirSync(dir), []);
96
+ assert.deepEqual(readTowerSnapshots(dir), []);
97
+ });
98
+
99
+ test("an oversized snapshot is refused and the stored one stays unchanged", () => {
100
+ const dir = scratch();
101
+ const s = buildTowerSnapshot(base);
102
+ writeTowerSnapshot(dir, s);
103
+ const before = readFileSync(join(dir, "s-1.json"), "utf8");
104
+ const huge = { ...s, name: "x".repeat(TOWER_SNAPSHOT_MAX_BYTES) };
105
+ assert.throws(() => writeTowerSnapshot(dir, huge), /too large/);
106
+ assert.equal(readFileSync(join(dir, "s-1.json"), "utf8"), before);
107
+ assert.deepEqual(readdirSync(dir), ["s-1.json"]);
108
+ });
109
+
110
+ test("unsafe session ids never become file names", () => {
111
+ const dir = scratch();
112
+ assert.throws(() => writeTowerSnapshot(dir, { ...buildTowerSnapshot(base), sessionId: "../escape" }), /session id/);
113
+ assert.throws(() => removeTowerSnapshot(dir, "../escape"), /session id/);
114
+ });
115
+
116
+ test("reading skips files that are not valid snapshots", () => {
117
+ const dir = scratch();
118
+ writeTowerSnapshot(dir, buildTowerSnapshot(base));
119
+ writeFileSync(join(dir, "junk.json"), "{not json", { mode: 0o600 });
120
+ writeFileSync(join(dir, "old.json"), JSON.stringify({ version: 0 }), { mode: 0o600 });
121
+ assert.deepEqual(readTowerSnapshots(dir).map((x) => x.sessionId), ["s-1"]);
122
+ });
123
+
124
+ test("a session with huge history still publishes a snapshot within the hub limit, marking what it left out", () => {
125
+ const dir = scratch();
126
+ const long = (c: string, n: number) => c.repeat(n);
127
+ const huge = buildTowerSnapshot({
128
+ ...base,
129
+ sessionName: long("n", 5000),
130
+ cwd: `/w/${long("d", 5000)}`,
131
+ todos: Array.from({ length: 600 }, (_, i) => ({ id: i + 1, title: long("t", 2000), status: (i % 2 ? "pending" : "done") as "pending" | "done", note: long("漢", 1500) })),
132
+ agents: Array.from({ length: 200 }, (_, i) => ({ id: `a${i}`, agent: "gentle-ai-worker", label: long("l", 500), status: "running", lastStep: long("s", 3000), usage: { total: 1, cost: 0 } })),
133
+ said: long("w", 10000),
134
+ models: Array.from({ length: 300 }, (_, i) => ({ model: `${long("m", 2000)}${i}`, cost: 1, tokens: 1 })),
135
+ artifacts: Array.from({ length: 50 }, (_, i) => ({ path: `/${long("p", 3000)}${i}.md`, kind: "doc" as const })),
136
+ });
137
+ assert.ok(Buffer.byteLength(JSON.stringify(huge)) <= TOWER_SNAPSHOT_MAX_BYTES, `snapshot is ${Buffer.byteLength(JSON.stringify(huge))} bytes`);
138
+ writeTowerSnapshot(dir, huge);
139
+ const [back] = readTowerSnapshots(dir);
140
+ assert.equal(back.sessionId, "s-1");
141
+ assert.ok(back.name.length <= 200 && back.name.endsWith("…"));
142
+ assert.ok(back.todos.length > 0 && back.todos.length < 600);
143
+ assert.ok(back.subagents.length > 0);
144
+ assert.ok(back.said!.length <= 600);
145
+ assert.ok((back.omitted?.todos ?? 0) > 0, "the snapshot says tasks were left out");
146
+ // The next update of the same session still publishes.
147
+ writeTowerSnapshot(dir, { ...huge, name: "renamed" });
148
+ assert.equal(readTowerSnapshots(dir)[0].name, "renamed");
149
+ });
150
+
151
+ test("a long project folder is kept whole, so New floor launches in the real folder", () => {
152
+ const cwd = `/w/${"d".repeat(3000)}/project`;
153
+ const s = buildTowerSnapshot({ ...base, cwd, sessionName: undefined });
154
+ assert.equal(s.project.cwd, cwd);
155
+ assert.equal(s.project.name, "project");
156
+ // Even when everything else must shrink to fit, the folder stays whole.
157
+ const huge = buildTowerSnapshot({
158
+ ...base,
159
+ cwd,
160
+ todos: Array.from({ length: 600 }, (_, i) => ({ id: i + 1, title: "t".repeat(2000), status: "pending" as const })),
161
+ artifacts: Array.from({ length: 12 }, (_, i) => ({ path: `/a/${"p".repeat(3000)}${i}.md`, kind: "doc" as const })),
162
+ });
163
+ assert.equal(huge.project.cwd, cwd);
164
+ assert.ok(Buffer.byteLength(JSON.stringify(huge)) <= TOWER_SNAPSHOT_MAX_BYTES);
165
+ assert.ok((huge.omitted?.todos ?? 0) > 0);
166
+ });
167
+
168
+ test("artifact paths are never cut: a path too long to carry leaves the artifact out and counts it", () => {
169
+ const kept = `/a/${"p".repeat(2000)}/notes.md`;
170
+ const tooLong = `/a/${"q".repeat(5000)}/plan.md`;
171
+ const s = buildTowerSnapshot({ ...base, artifacts: [{ path: tooLong, kind: "doc" }, { path: kept, kind: "doc" }, { path: "/a/short.md", kind: "doc" }] });
172
+ assert.deepEqual(s.artifacts, [{ path: kept, kind: "doc" }, { path: "/a/short.md", kind: "doc" }]);
173
+ assert.deepEqual(s.omitted, { artifacts: 1 });
174
+ assert.ok(s.artifacts!.every((a) => !a.path.endsWith("…")));
175
+ });
176
+
177
+ test("a normal snapshot carries no omission marker", () => {
178
+ assert.equal(buildTowerSnapshot(base).omitted, undefined);
179
+ });
180
+
181
+ // ---------- the intercom conversation ----------
182
+ const msg = (role: string, content: unknown, timestamp: number, extra: Record<string, unknown> = {}) => ({ type: "message", message: { role, content, timestamp, ...extra } });
183
+
184
+ test("the conversation keeps the visible turns in order: your words and the agent's visible text", () => {
185
+ const chat = chatFromBranch([
186
+ msg("user", "what did you do?", 1),
187
+ msg("assistant", [{ type: "thinking", thinking: "secret plan" }, { type: "toolCall", id: "c1", name: "read", arguments: { path: "a.ts" } }], 2),
188
+ msg("toolResult", [{ type: "text", text: "file body" }], 3, { toolCallId: "c1", toolName: "read" }),
189
+ msg("assistant", [{ type: "text", text: "I fixed the refresh." }, { type: "toolCall", id: "c2", name: "bash", arguments: {} }], 4),
190
+ msg("custom", "injected reminder", 5, { customType: "gentle-todo-reminder", display: false }),
191
+ { type: "custom_message", customType: "note", content: "hidden note", display: false, timestamp: "1970-01-01T00:00:00.006Z" },
192
+ msg("user", "[System-generated wake] a helper finished", 7),
193
+ msg("user", [{ type: "text", text: "and the docs?" }, { type: "image", data: "x", mimeType: "image/png" }], 8),
194
+ msg("assistant", [{ type: "text", text: " " }], 9),
195
+ msg("assistant", [{ type: "text", text: "Updated them too." }], 10),
196
+ ]);
197
+ assert.deepEqual(chat, [
198
+ { role: "you", text: "what did you do?", at: 1 },
199
+ { role: "agent", text: "I fixed the refresh.", at: 4 },
200
+ { role: "you", text: "and the docs?", at: 8 },
201
+ { role: "agent", text: "Updated them too.", at: 10 },
202
+ ]);
203
+ });
204
+
205
+ test("the conversation keeps only the latest turns, each bounded", () => {
206
+ const entries = Array.from({ length: 30 }, (_, i) => msg(i % 2 ? "assistant" : "user", i % 2 ? [{ type: "text", text: `reply ${i} ${"r".repeat(5000)}` }] : `ask ${i}`, 100 + i));
207
+ const chat = chatFromBranch(entries);
208
+ assert.equal(chat.length, TOWER_CHAT_TURNS);
209
+ assert.equal(chat[0].at, 100 + 30 - TOWER_CHAT_TURNS);
210
+ assert.equal(chat.at(-1)!.at, 129);
211
+ for (const t of chat) assert.ok(t.text.length <= TOWER_CHAT_TEXT_MAX, `turn of ${t.text.length} chars`);
212
+ assert.ok(chat.at(-1)!.text.endsWith("…"));
213
+ // The snapshot applies the same bounds to whatever it is given.
214
+ const s = buildTowerSnapshot({ ...base, chat: Array.from({ length: 20 }, (_, i) => ({ role: "agent" as const, text: "z".repeat(3000), at: i })) });
215
+ assert.equal(s.chat!.length, TOWER_CHAT_TURNS);
216
+ assert.equal(s.chat![0].at, 20 - TOWER_CHAT_TURNS);
217
+ assert.ok(s.chat!.every((t) => t.text.length <= TOWER_CHAT_TEXT_MAX));
218
+ });
219
+
220
+ test("a session with no conversation carries no chat, and the latest words stay for older views", () => {
221
+ const s = buildTowerSnapshot({ ...base, said: "hello" });
222
+ assert.equal(s.chat, undefined);
223
+ assert.equal(s.said, "hello");
224
+ });
225
+
226
+ test("when the snapshot is too large the oldest chat turns go first, before any task", () => {
227
+ const chat = Array.from({ length: TOWER_CHAT_TURNS }, (_, i) => ({ role: (i % 2 ? "agent" : "you") as "agent" | "you", text: `${i}:${"漢".repeat(TOWER_CHAT_TEXT_MAX)}`, at: i }));
228
+ const todos = Array.from({ length: 200 }, (_, i) => ({ id: i + 1, title: "t".repeat(60), status: "done" as const, note: "n".repeat(60) }));
229
+ const s = buildTowerSnapshot({ ...base, todos, chat });
230
+ assert.ok(Buffer.byteLength(JSON.stringify(s)) <= TOWER_SNAPSHOT_MAX_BYTES);
231
+ assert.ok(s.chat!.length > 0 && s.chat!.length < TOWER_CHAT_TURNS, `kept ${s.chat!.length} turns`);
232
+ assert.deepEqual(s.chat!.map((t) => t.at), chat.slice(-s.chat!.length).map((t) => t.at), "the newest turns stay");
233
+ assert.equal(s.omitted?.chat, TOWER_CHAT_TURNS - s.chat!.length);
234
+ assert.equal(s.todos.length, 200, "no task was dropped");
235
+ assert.ok(s.todos.every((t) => t.note), "no task note was dropped");
236
+ });
@@ -0,0 +1,125 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { echoTurn, sentMessage, settleOutbox, turnKey, type Outgoing } from "../web/tower/src/model.ts";
4
+ import type { TowerChatTurn } from "../web/tower/src/types.ts";
5
+ import { buildTowerSnapshot, chatFromBranch, TOWER_CHAT_TURNS } from "../lib/tower-snapshot.ts";
6
+
7
+ const you = (text: string, at: number): TowerChatTurn => ({ role: "you", text, at });
8
+ const T = 1_700_000_000_000;
9
+
10
+ test("a sent message is acknowledged only by its own turn, recorded at or after it was sent", () => {
11
+ const before = [you("yes", T - 1000)];
12
+ const pending = sentMessage("yes, run tests", T, before);
13
+ // An older, shorter turn already in the chat never acknowledges the new message.
14
+ assert.equal(echoTurn(pending, before, new Set()), undefined);
15
+ const own = you("yes, run tests", T + 300);
16
+ assert.equal(echoTurn(pending, [...before, own], new Set()), own);
17
+ });
18
+
19
+ test("an identical turn that was already in the chat when sending is not the echo", () => {
20
+ const before = [you("ok", T - 500)];
21
+ const pending = sentMessage("ok", T, before);
22
+ assert.equal(echoTurn(pending, before, new Set()), undefined);
23
+ const own = you("ok", T + 100);
24
+ assert.equal(echoTurn(pending, [...before, own], new Set()), own);
25
+ });
26
+
27
+ test("the text must match exactly, unless the session cut the turn at its length limit", () => {
28
+ const pending = sentMessage("deploy", T, []);
29
+ assert.equal(echoTurn(pending, [you("deploy now", T + 10)], new Set()), undefined);
30
+ assert.equal(echoTurn(pending, [you("dep…", T + 10)], new Set()), undefined, "a short turn ending in … is not a cut one");
31
+ const long = "x".repeat(1500);
32
+ const cut = you(`${"x".repeat(1199)}…`, T + 10);
33
+ assert.equal(echoTurn(sentMessage(long, T, []), [cut], new Set()), cut);
34
+ });
35
+
36
+ test("a turn from well before sending, or one already used by an earlier message, is not the echo", () => {
37
+ const pending = sentMessage("again", T, []);
38
+ assert.equal(echoTurn(pending, [you("again", T - 2500)], new Set()), undefined);
39
+ const first = you("again", T + 10);
40
+ const used = new Set([turnKey(first)]);
41
+ assert.equal(echoTurn(pending, [first], used), undefined);
42
+ const second = you("again", T + 20);
43
+ assert.equal(echoTurn(pending, [first, second], used), second);
44
+ // Agent turns never acknowledge a message.
45
+ assert.equal(echoTurn(sentMessage("hi", T, []), [{ role: "agent", text: "hi", at: T + 5 }], new Set()), undefined);
46
+ });
47
+
48
+ const out = (text: string, at: number, chat: TowerChatTurn[], state: Outgoing["state"] = "sending"): Outgoing => ({ ...sentMessage(text, at, chat), state });
49
+ const texts = (items: readonly Outgoing[]) => items.map((o) => `${o.text}:${o.state}`);
50
+
51
+ test("a failed resend of an identical message shows as not sent, even after the earlier one's turn arrived", () => {
52
+ const consumed = new Set<string>();
53
+ // The first "ok" went through; the second was sent before the first one's turn reached the view.
54
+ const first = out("ok", T, [], "sent");
55
+ const second = out("ok", T + 500, []);
56
+ const echo = you("ok", T + 100);
57
+ // Every snapshot carries fresh turn objects: the same turn, rendered twice.
58
+ let r = settleOutbox([first, second], [{ ...echo }], consumed);
59
+ assert.deepEqual(texts(r.keep), ["ok:sending"], "the first message is acknowledged by its turn");
60
+ assert.deepEqual(texts(r.show), ["ok:sending"]);
61
+ r = settleOutbox(r.keep, [{ ...echo }], consumed);
62
+ assert.deepEqual(texts(r.keep), ["ok:sending"], "a turn that acknowledged one message never acknowledges another");
63
+ assert.deepEqual(texts(r.show), ["ok:sending"]);
64
+ second.state = "failed";
65
+ r = settleOutbox(r.keep, [{ ...echo }], consumed);
66
+ assert.deepEqual(texts(r.show), ["ok:failed"], "the failed resend is shown as not sent");
67
+ assert.deepEqual(texts(r.keep), ["ok:failed"]);
68
+ });
69
+
70
+ test("an identical turn matched while sending never marks a failed send as delivered", () => {
71
+ const consumed = new Set<string>();
72
+ const pending = out("ok", T, [{ role: "you", text: "ok", at: T - 5000 }]);
73
+ // An identical turn appears (typed in the terminal) while the request is still pending: it is not shown twice.
74
+ const typed = you("ok", T + 50);
75
+ let r = settleOutbox([pending], [typed], consumed);
76
+ assert.deepEqual(texts(r.keep), ["ok:sending"], "kept until the request answers");
77
+ assert.deepEqual(texts(r.show), []);
78
+ pending.state = "failed";
79
+ r = settleOutbox(r.keep, [{ ...typed }], consumed);
80
+ assert.deepEqual(texts(r.show), ["ok:failed"], "the failure is reported, not hidden behind the identical turn");
81
+ assert.equal(consumed.size, 0, "a failed send never consumes a turn");
82
+ });
83
+
84
+ test("a delivered message whose turn arrived leaves the outbox", () => {
85
+ const consumed = new Set<string>();
86
+ const sent = out("hi", T, [], "sent");
87
+ const turn = you("hi", T + 10);
88
+ const r = settleOutbox([sent], [turn], consumed);
89
+ assert.deepEqual([r.keep, r.show], [[], []]);
90
+ assert.deepEqual([...consumed], [turnKey(turn)]);
91
+ // Turns no longer in the chat are forgotten.
92
+ settleOutbox([], [], consumed);
93
+ assert.equal(consumed.size, 0);
94
+ });
95
+
96
+ test("a delivered Tower question remains with its answer after many visible assistant tool turns", () => {
97
+ const terminal = { type: "message", message: { role: "user", content: "terminal question", timestamp: T - 1000 } };
98
+ const previous = { type: "message", message: { role: "assistant", content: [{ type: "text", text: "previous reply" }], timestamp: T - 500 } };
99
+ const question = { type: "message", message: { role: "user", content: [{ type: "text", text: "tower question" }], timestamp: T + 10 } };
100
+ const branch: unknown[] = [terminal, previous];
101
+ const sent = out("tower question", T, chatFromBranch(branch), "sent");
102
+ branch.push(question);
103
+ const snapshot = (entries: unknown[]) => buildTowerSnapshot({ sessionId: "s", cwd: "/w/app", stats: { cost: 0, input: 0, output: 0 }, todos: [], agents: [], chat: chatFromBranch(entries), now: T + 1000 });
104
+ const acknowledged = snapshot(branch).chat!;
105
+ assert.deepEqual(acknowledged.map((t) => [t.role, t.text]), [["you", "terminal question"], ["agent", "previous reply"], ["you", "tower question"]]);
106
+ const consumed = new Set<string>();
107
+ assert.deepEqual(settleOutbox([sent], acknowledged, consumed).keep, [], "the publisher's user turn consumes the local outgoing copy");
108
+ for (let i = 0; i < TOWER_CHAT_TURNS; i++) branch.push({ type: "message", message: { role: "assistant", content: [{ type: "text", text: `working ${i}` }, { type: "toolCall", id: `t${i}`, name: "read", arguments: {} }], timestamp: T + 20 + i } });
109
+ branch.push({ type: "message", message: { role: "assistant", content: [{ type: "text", text: "final answer" }], timestamp: T + 200 } });
110
+ const chat = snapshot(branch).chat!;
111
+ assert.equal(chat.length, TOWER_CHAT_TURNS);
112
+ assert.deepEqual(chat[0], you("tower question", T + 10), "the latest human question must survive the assistant's many intermediate messages");
113
+ assert.deepEqual(chat.at(-1), { role: "agent", text: "final answer", at: T + 200 });
114
+ assert.deepEqual(settleOutbox([], chat, consumed).show, [], "the acknowledged question is shown by the publisher, not duplicated from the outbox");
115
+ });
116
+
117
+ test("without a human question the conversation still keeps the latest bounded assistant turns", () => {
118
+ const branch = Array.from({ length: TOWER_CHAT_TURNS + 3 }, (_, i) => ({ type: "message", message: { role: "assistant", content: [{ type: "text", text: `reply ${i}` }], timestamp: T + i } }));
119
+ branch.splice(2, 0, { type: "message", message: { role: "user", content: [{ type: "text", text: "[System-generated wake] internal" }], timestamp: T + 2 } });
120
+ const chat = chatFromBranch(branch);
121
+ assert.equal(chat.length, TOWER_CHAT_TURNS);
122
+ assert.equal(chat[0].text, "reply 3");
123
+ assert.equal(chat.at(-1)?.text, `reply ${TOWER_CHAT_TURNS + 2}`);
124
+ assert.ok(chat.every((t) => t.role === "agent"));
125
+ });
@@ -0,0 +1,251 @@
1
+ import assert from "node:assert/strict";
2
+ import { spawnSync } from "node:child_process";
3
+ import { copyFileSync, existsSync, mkdtempSync, mkdirSync, rmSync, symlinkSync } from "node:fs";
4
+ import { registerHooks } from "node:module";
5
+ import { tmpdir } from "node:os";
6
+ import { join } from "node:path";
7
+ import test from "node:test";
8
+ import { fileURLToPath } from "node:url";
9
+ import ts from "typescript";
10
+ import type { Project, TowerSnapshot } from "../web/tower/src/types.ts";
11
+
12
+ test("hover test typechecks and skips cleanly with only root dependencies", (t) => {
13
+ const root = mkdtempSync(join(tmpdir(), "gentle-tower-hover-ci-"));
14
+ t.after(() => rmSync(root, { recursive: true, force: true }));
15
+ mkdirSync(join(root, "tests"), { recursive: true });
16
+ mkdirSync(join(root, "web", "tower", "src"), { recursive: true });
17
+ for (const file of ["package.json", "tsconfig.json", "tests/tower-web-hover.test.ts", ...["types.ts", "model.ts", "art.ts", "scene.ts"].map((name) => `web/tower/src/${name}`)]) {
18
+ copyFileSync(new URL(`../${file}`, import.meta.url), join(root, file));
19
+ }
20
+ // Link only the root installation. No nested web dependency directory exists.
21
+ symlinkSync(fileURLToPath(new URL("../node_modules", import.meta.url)), join(root, "node_modules"), "junction");
22
+ assert.equal(existsSync(join(root, "web", "tower", "node_modules")), false);
23
+ const configFile = join(root, "tsconfig.json");
24
+ const config = ts.readConfigFile(configFile, ts.sys.readFile);
25
+ assert.equal(config.error, undefined);
26
+ const parsed = ts.parseJsonConfigFileContent(config.config, ts.sys, root, undefined, configFile);
27
+ assert.deepEqual(parsed.errors, []);
28
+ assert.deepEqual(parsed.fileNames, [join(root, "tests", "tower-web-hover.test.ts")]);
29
+ const diagnostics = ts.getPreEmitDiagnostics(ts.createProgram(parsed.fileNames, parsed.options));
30
+ const formatted = ts.formatDiagnostics(diagnostics, { getCurrentDirectory: () => root, getCanonicalFileName: (file) => file, getNewLine: () => "\n" });
31
+ assert.equal(diagnostics.length, 0, formatted);
32
+ // A nested test runner must not inherit the outer runner's child-test protocol.
33
+ const env = { ...process.env };
34
+ delete env.NODE_TEST_CONTEXT;
35
+ const args = ["--experimental-strip-types", "--test", "--test-reporter=tap", "--test-name-pattern=^Tower Pixi hover$", join(root, "tests", "tower-web-hover.test.ts")];
36
+ const run = () => spawnSync(process.execPath, args, { encoding: "utf8", timeout: 10_000, env });
37
+ const skipped = run();
38
+ assert.equal(skipped.status, 0, `${skipped.stdout}\n${skipped.stderr}`);
39
+ assert.match(skipped.stdout, /Tower Pixi hover/);
40
+ assert.match(skipped.stdout, /install web\/tower dependencies to exercise Pixi hover/);
41
+ // A present but broken install is an error, not a misleading dependency skip.
42
+ mkdirSync(join(root, "web", "tower", "node_modules", "pixi.js"), { recursive: true });
43
+ const broken = run();
44
+ assert.notEqual(broken.status, 0);
45
+ assert.match(`${broken.stdout}\n${broken.stderr}`, /ERR_MODULE_NOT_FOUND/);
46
+ });
47
+
48
+ // Load the same extensionless local imports Vite resolves, without starting a
49
+ // browser or replacing Pixi's event boundary with a synthetic hit test.
50
+ registerHooks({ resolve(specifier, context, next) {
51
+ if (context.parentURL?.includes("/web/tower/src/") && /^\.\/[^.]+$/.test(specifier)) return next(`${specifier}.ts`, context);
52
+ return next(specifier, context);
53
+ } });
54
+
55
+ type Listener = (event: { clientX: number; clientY: number }) => void;
56
+ class Canvas {
57
+ width = 720;
58
+ height = 450;
59
+ style: { cursor?: string } = {};
60
+ isConnected = true;
61
+ listeners = new Map<string, Listener[]>();
62
+ addEventListener(name: string, fn: Listener) { this.listeners.set(name, [...(this.listeners.get(name) ?? []), fn]); }
63
+ dispatch(name: string, x: number, y: number) { for (const fn of this.listeners.get(name) ?? []) fn({ clientX: x, clientY: y }); }
64
+ getBoundingClientRect() { return { left: 0, top: 0, width: this.width, height: this.height }; }
65
+ getContext() {
66
+ const canvas = this;
67
+ const gradient = { addColorStop() {} };
68
+ return new Proxy({
69
+ canvas,
70
+ createLinearGradient: () => gradient,
71
+ createRadialGradient: () => gradient,
72
+ createPattern: () => ({}),
73
+ createImageData: (w: number, h: number) => ({ data: new Uint8ClampedArray(w * h * 4) }),
74
+ getImageData: (_x: number, _y: number, w: number, h: number) => ({ data: new Uint8ClampedArray(w * h * 4) }),
75
+ measureText: (text: string) => ({ width: text.length * 6, actualBoundingBoxAscent: 8, actualBoundingBoxDescent: 2 }),
76
+ } as Record<PropertyKey, unknown>, { get: (target, key) => target[key] ?? (() => {}) });
77
+ }
78
+ }
79
+ class Tooltip {
80
+ className = "";
81
+ hidden = false;
82
+ textContent = "";
83
+ offsetWidth = 100;
84
+ style = { transform: "" };
85
+ setAttribute() {}
86
+ }
87
+ const tips: Tooltip[] = [];
88
+ Object.defineProperty(globalThis, "HTMLCanvasElement", { value: Canvas, configurable: true });
89
+ Object.defineProperty(globalThis, "CanvasRenderingContext2D", { value: class {}, configurable: true });
90
+ Object.defineProperty(globalThis, "Path2D", { value: class { constructor(_path?: string) {} }, configurable: true });
91
+ Object.defineProperty(globalThis, "matchMedia", { value: () => ({ matches: true }), configurable: true });
92
+ Object.defineProperty(globalThis, "innerWidth", { value: 720, configurable: true });
93
+ Object.defineProperty(globalThis, "document", { value: {
94
+ createElement: (tag: string) => tag === "canvas" ? new Canvas() : new Tooltip(),
95
+ body: { appendChild: (tip: Tooltip) => tips.push(tip) },
96
+ }, configurable: true });
97
+
98
+ // Root-only installs need not have the separately installed web project's dependencies.
99
+ // URL imports follow the runtime-only test convention: root tsc must not pull the
100
+ // Pixi scene into its graph, while the web project's own tsc still checks it.
101
+ const pixi = new URL("../web/tower/node_modules/pixi.js/", import.meta.url);
102
+ if (!existsSync(pixi)) {
103
+ test("Tower Pixi hover", { skip: "install web/tower dependencies to exercise Pixi hover" }, () => {});
104
+ } else {
105
+ const { EventBoundary, FederatedPointerEvent } = await import(new URL("lib/events/index.mjs", pixi).href);
106
+ const { updateRenderGroupTransforms } = await import(new URL("lib/scene/container/utils/updateRenderGroupTransforms.mjs", pixi).href);
107
+ // The real renderer installs this mixin during initialization, which the canvas stub skips.
108
+ await import(new URL("lib/events/init.mjs", pixi).href);
109
+ const { TowerScene } = await import(new URL("../web/tower/src/scene.ts", import.meta.url).href);
110
+ const { room, floorLine, BX, BW } = await import(new URL("../web/tower/src/art.ts", import.meta.url).href);
111
+
112
+ async function setup() {
113
+ const scene = new TowerScene();
114
+ const canvas = new Canvas();
115
+ const boundary = new EventBoundary(scene.app.stage);
116
+ const frames: Array<{ fn: (ticker: { deltaMS: number }) => void; priority: number }> = [];
117
+ const events = {
118
+ rootBoundary: boundary,
119
+ mapPositionToPoint: (point: { x: number; y: number }, x: number, y: number) => { point.x = x; point.y = y; },
120
+ setCursor: (cursor: string) => { canvas.style.cursor = cursor === "default" ? "inherit" : cursor; },
121
+ };
122
+ scene.app.init = async () => {
123
+ Object.defineProperty(scene.app, "renderer", { value: { canvas, events, resize(w: number, h: number) { canvas.width = w; canvas.height = h; } } });
124
+ Object.defineProperty(scene.app, "ticker", { value: { add: (fn: (ticker: { deltaMS: number }) => void, _ctx?: unknown, priority = 0) => { frames.push({ fn, priority }); } } });
125
+ };
126
+ await scene.mount({ appendChild() {} } as unknown as HTMLElement);
127
+ const session: TowerSnapshot = {
128
+ version: 1, sessionId: "floor-1", name: "Alpha", project: { cwd: "/w/app", name: "app" }, model: "model",
129
+ context: { percent: null, window: 0 }, cost: { total: 1, input: 0, output: 0 },
130
+ todos: [{ id: 1, title: "Investigate", status: "in_progress" }], subagents: [{ id: "helper-1", role: "explore", name: "explore", status: "running", cost: 0, tokens: 0 }],
131
+ phase: "implementing", permission: "normal", artifacts: [{ path: "/w/app/flow.mmd", kind: "diagram" }, { path: "/w/app/notes.md", kind: "doc" }, { path: "/w/app/shot.png", kind: "image" }], updatedAt: 1,
132
+ };
133
+ const project: Project = { id: "app", cwd: "/w/app", sessions: [session] };
134
+ scene.show(project, ["#f095c8"]);
135
+ // Renderer-free setup must still apply Pixi's actual world transforms before hit testing.
136
+ scene.app.stage.enableRenderGroup();
137
+ const render = () => updateRenderGroupTransforms(scene.app.stage.renderGroup!, true);
138
+ render();
139
+ const tip = tips.at(-1)!;
140
+ const pixi = (name: string, x: number, y: number) => {
141
+ render();
142
+ const e = new FederatedPointerEvent(null);
143
+ e.type = name; e.pointerType = "mouse"; e.pointerId = 1; e.button = 0; e.global.set(x, y);
144
+ boundary.mapEvent(e);
145
+ canvas.style.cursor = boundary.cursor ?? "inherit";
146
+ };
147
+ // Pixi renders at LOW priority (-25), between scene movement and hover.
148
+ const nextFrame = () => {
149
+ for (const f of frames.filter((f) => f.priority > -25)) f.fn({ deltaMS: 16 });
150
+ render();
151
+ for (const f of frames.filter((f) => f.priority < -25)) f.fn({ deltaMS: 16 });
152
+ };
153
+ const move = (x: number, y: number) => { pixi("pointermove", x, y); canvas.dispatch("pointermove", x, y); nextFrame(); };
154
+ const click = (x: number, y: number) => { pixi("pointerdown", x, y); pixi("pointerup", x, y); };
155
+ return { scene, session, project, tip, canvas, move, click, frame: nextFrame };
156
+ }
157
+
158
+ const roomCases = [
159
+ ["map", "Tasks · floor 1"], ["workshop", "Floor 1 · Talk, Tasks, Artifacts"],
160
+ ["lab", "Floor 1 · Talk, Tasks, Artifacts"], ["review", "Floor 1 · Talk, Tasks, Artifacts"],
161
+ ["engram", "Engram library"], ["engine", "Your tab"], ["lounge", "Your tab"],
162
+ ] as const;
163
+
164
+ test("hovering every room keeps its own label and cursor through stationary frames and clicks", async () => {
165
+ const { scene, tip, canvas, move, click } = await setup();
166
+ const selected: string[] = [];
167
+ scene.onRoom = (id, floor) => selected.push(`${id}:${floor}`);
168
+ const y = scene.layout!.roof + 14;
169
+ // Start on LOUNGE, then visit MAP and the other rooms, with a held pointer.
170
+ for (const [id, label] of [roomCases[6], ...roomCases]) {
171
+ const x = room(id).x + 3;
172
+ for (let i = 0; i < 30; i++) {
173
+ move(x, y);
174
+ assert.equal(tip.hidden, false, `${id} frame ${i}`);
175
+ assert.equal(tip.textContent, label, `${id} frame ${i}`);
176
+ assert.equal(canvas.style.cursor, "pointer", `${id} frame ${i}`);
177
+ }
178
+ const before = selected.length;
179
+ click(x, y);
180
+ assert.equal(selected.length, before + 1);
181
+ assert.equal(selected.at(-1), `${id}:0`);
182
+ }
183
+ // Decoration is not a separate target: notes and the elephant still click the room.
184
+ for (const [id, x, y] of [["map", room("map").x + 12, scene.layout!.roof + 35], ["engram", room("engram").x + 65, floorLine(scene.layout!, 0) - 12]] as const) {
185
+ move(x, y); click(x, y);
186
+ assert.equal(tip.textContent, id === "map" ? "Tasks · floor 1" : "Engram library");
187
+ assert.equal(selected.at(-1), `${id}:0`);
188
+ }
189
+ });
190
+
191
+ test("people, artifact and door own hover and clicks over rooms, including after a redraw", async () => {
192
+ const { scene, session, project, tip, canvas, move, click, frame } = await setup();
193
+ const picks: string[] = [], doors: number[] = [], artifacts: string[] = [];
194
+ scene.onPick = (p) => { if (p) picks.push(p.kind === "helper" ? p.helper!.id : p.session.name); };
195
+ scene.onDoor = (floor) => doors.push(floor);
196
+ scene.onArtifact = (_floor, artifact) => artifacts.push(artifact.path);
197
+ const L = scene.layout!;
198
+ const cases = [
199
+ { x: room("workshop").x + 14, y: floorLine(L, 0) - 20, label: "Talk to Alpha", action: () => assert.equal(picks.at(-1), "Alpha") },
200
+ { x: room("map").x + 14, y: floorLine(L, 0) - 20, label: "explore · running · details", action: () => assert.equal(picks.at(-1), "helper-1") },
201
+ { x: room("map").x + 50, y: L.roof + 33, label: "Open diagram: flow.mmd", action: () => assert.equal(artifacts.at(-1), "/w/app/flow.mmd") },
202
+ { x: room("workshop").x + 50, y: L.roof + 33, label: "Open image: shot.png", action: () => assert.equal(artifacts.at(-1), "/w/app/shot.png") },
203
+ { x: room("workshop").x + 70, y: L.roof + 66, label: "Open doc: notes.md", action: () => assert.equal(artifacts.at(-1), "/w/app/notes.md") },
204
+ { x: BX + BW + 19, y: L.lobby + 42, label: "Permissions: normal · floor 1", action: () => assert.equal(doors.at(-1), 0) },
205
+ { x: BX + BW - 10, y: L.lobby + 20, label: "Permissions: normal · floor 1", action: () => assert.equal(doors.at(-1), 0) },
206
+ ];
207
+ for (const c of cases) {
208
+ for (let i = 0; i < 30; i++) {
209
+ move(c.x, c.y);
210
+ assert.equal(tip.hidden, false, `${c.label} frame ${i}`);
211
+ assert.equal(tip.textContent, c.label, `${c.label} frame ${i}`);
212
+ assert.equal(canvas.style.cursor, "pointer", `${c.label} frame ${i}`);
213
+ }
214
+ const before = picks.length + doors.length + artifacts.length;
215
+ click(c.x, c.y); c.action();
216
+ assert.equal(picks.length + doors.length + artifacts.length, before + 1, c.label);
217
+ }
218
+ // Live snapshots reconstruct the door while the pointer has not moved.
219
+ session.permission = "auto";
220
+ scene.show(project, ["#f095c8"]);
221
+ frame();
222
+ assert.equal(tip.hidden, false);
223
+ assert.equal(tip.textContent, "Permissions: auto · floor 1");
224
+ const door = cases.at(-1)!;
225
+ const before = doors.length;
226
+ click(door.x, door.y);
227
+ assert.equal(doors.length, before + 1);
228
+ assert.equal(doors.at(-1), 0);
229
+ // Moving a person on a new snapshot also resolves the old position to the room.
230
+ move(cases[0].x, cases[0].y);
231
+ session.phase = "checking";
232
+ scene.show(project, ["#f095c8"]);
233
+ frame();
234
+ assert.equal(tip.textContent, "Floor 1 · Talk, Tasks, Artifacts");
235
+ move(room("lab").x + 14, floorLine(L, 0) - 20);
236
+ assert.equal(tip.textContent, "Talk to Alpha");
237
+ });
238
+
239
+ test("leaving the building clears the previous label and canvas cursor", async () => {
240
+ const { scene, tip, canvas, move } = await setup();
241
+ move(room("lounge").x + 3, scene.layout!.roof + 14);
242
+ assert.equal(tip.textContent, "Your tab");
243
+ move(20, 20);
244
+ assert.equal(tip.hidden, true);
245
+ assert.notEqual(canvas.style.cursor, "pointer");
246
+ move(room("lounge").x + 3, scene.layout!.roof + 14);
247
+ canvas.dispatch("pointerleave", 0, 0);
248
+ assert.equal(tip.hidden, true);
249
+ assert.notEqual(canvas.style.cursor, "pointer");
250
+ });
251
+ }
@@ -0,0 +1,32 @@
1
+ import assert from "node:assert/strict";
2
+ import { readFileSync } from "node:fs";
3
+ import test from "node:test";
4
+ import { verifierSettleReminderText } from "../lib/verifier-settle-reminder.ts";
5
+
6
+ // harness-continuity T6 (S3/S6): a verification stop is scoped to the unit it verifies. It reports the
7
+ // open blockers or missing proof as partial, keeps every budget separate and unreset, and never revives the
8
+ // retired generic terminal phrase. Instruction-delivery contract only, not proof of model adherence.
9
+ const verification = readFileSync(new URL("../assets/orchestrator-verification.md", import.meta.url), "utf8");
10
+ const lineStarting = (start: string) => verification.split("\n").find((line) => line.startsWith(start)) ?? "";
11
+
12
+ test("S3/S6: verification stops are scoped partial reports, never the generic terminal phrase", () => {
13
+ assert.ok(!verification.includes("Needs your decision"), "the verification module must not keep the retired terminal phrase");
14
+ const setup = lineStarting("A failed verifier setup");
15
+ assert.match(setup, /If setup still fails or lacks prerequisites, stop verifying/);
16
+ assert.match(setup, /exact unrun checks as unverified/);
17
+ assert.match(setup, /never repair helpers more or auto-relaunch for it/);
18
+ const correction = lineStarting("5. **One correction**");
19
+ assert.match(correction, /Blockers still open after that leave the unit `status: partial`, naming any genuine human decision/);
20
+ assert.match(correction, /independent authorized work continues/);
21
+ assert.match(correction, /A second correction runs automatically only when the recheck shows the same blocker still failing; a new finding never earns one/);
22
+ });
23
+
24
+ test("S6: worker, setup, recheck, native, and user budgets stay separate and changed state never resets them", () => {
25
+ assert.match(verification, /Worker, setup, recheck, native and user budgets stay separate; changed state earns a fresh check, not a reset\./);
26
+ });
27
+
28
+ test("S3/S6: the settle reminder asks for the verifier or an honest missing-proof report", () => {
29
+ const text = verifierSettleReminderText(3);
30
+ assert.ok(!text.includes("Needs your decision"), "the reminder must not revive the retired terminal phrase");
31
+ assert.match(text, /If verification is unavailable, report the missing proof and do not claim the change complete\./);
32
+ });