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,578 @@
1
+ import assert from "node:assert/strict";
2
+ import { existsSync, mkdirSync, mkdtempSync, readdirSync, rmSync, 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 type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
+ import { createTowerPublisher } from "../extensions/gentle-tower.ts";
8
+ import { readTowerSnapshots } from "../lib/tower-hub.ts";
9
+ import { TODO_PROGRESS_EVENT } from "../lib/shell-todo.ts";
10
+ import { startTowerServer } from "../lib/tower-server.ts";
11
+ import { TOWER_CHAT_TURNS } from "../lib/tower-snapshot.ts";
12
+ import { sentMessage, settleOutbox, type Outgoing } from "../web/tower/src/model.ts";
13
+
14
+ const roots: string[] = [];
15
+ after(() => roots.forEach((r) => rmSync(r, { recursive: true, force: true })));
16
+ function hub(): string {
17
+ const r = mkdtempSync(join(tmpdir(), "gentle-tower-ext-"));
18
+ roots.push(r);
19
+ return join(r, "sessions");
20
+ }
21
+
22
+ type Handler = (event: unknown, ctx: ExtensionContext) => unknown;
23
+ function fakePi() {
24
+ const handlers = new Map<string, Handler[]>();
25
+ const listeners = new Map<string, Array<(data: unknown) => void>>();
26
+ const pi = {
27
+ on(name: string, fn: Handler) { handlers.set(name, [...(handlers.get(name) ?? []), fn]); },
28
+ events: {
29
+ on(name: string, fn: (data: unknown) => void) { listeners.set(name, [...(listeners.get(name) ?? []), fn]); return () => {}; },
30
+ emit(name: string, data: unknown) { for (const fn of listeners.get(name) ?? []) fn(data); },
31
+ },
32
+ getThinkingLevel: () => "high",
33
+ registerCommand() {},
34
+ } as unknown as ExtensionAPI;
35
+ const fire = async (name: string, ctx: ExtensionContext) => { for (const fn of handlers.get(name) ?? []) await fn({}, ctx); };
36
+ return { pi, fire, emit: (name: string, data: unknown) => (pi.events as unknown as { emit(n: string, d: unknown): void }).emit(name, data) };
37
+ }
38
+
39
+ const todoEntry = (tasks: unknown[]) => ({ type: "message", message: { role: "toolResult", toolName: "todo", details: { gentleTodo: { tasks, nextId: tasks.length + 1 } } } });
40
+ const assistant = (cost: number) => ({ type: "message", message: { role: "assistant", usage: { input: 1000, output: 100, cost: { total: cost } } } });
41
+
42
+ function fakeCtx(branch: unknown[], id = "sess-1"): ExtensionContext {
43
+ return {
44
+ sessionManager: { getSessionId: () => id, getSessionName: () => "Token refresh fix", getCwd: () => "/work/gentle-ai", getBranch: () => branch },
45
+ model: { id: "claude-opus-5-5", reasoning: true },
46
+ getContextUsage: () => ({ percent: 38, contextWindow: 200000 }),
47
+ } as unknown as ExtensionContext;
48
+ }
49
+
50
+ const wait = (ms: number) => new Promise((r) => setTimeout(r, ms));
51
+
52
+ test("a finished turn publishes the session's real snapshot", async () => {
53
+ const dir = hub();
54
+ const { pi, fire } = fakePi();
55
+ const branch = [assistant(0.3), todoEntry([{ id: 1, title: "Reproduce", status: "done" }, { id: 2, title: "Fix it", status: "in_progress", note: "editing" }]), assistant(0.12)];
56
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, now: () => 42 });
57
+ const ctx = fakeCtx(branch);
58
+ await fire("session_start", ctx);
59
+ await fire("turn_end", ctx);
60
+ await wait(180);
61
+ const [s] = readTowerSnapshots(dir);
62
+ assert.equal(s.sessionId, "sess-1");
63
+ assert.equal(s.name, "Token refresh fix");
64
+ assert.deepEqual(s.project, { cwd: "/work/gentle-ai", name: "gentle-ai" });
65
+ assert.equal(s.model, "claude-opus-5-5");
66
+ assert.equal(s.effort, "high");
67
+ assert.deepEqual(s.context, { percent: 38, window: 200000 });
68
+ assert.ok(Math.abs(s.cost.total - 0.42) < 1e-9);
69
+ assert.equal(s.cost.input, 2000);
70
+ assert.deepEqual(s.todos.map((t) => [t.title, t.status]), [["Reproduce", "done"], ["Fix it", "in_progress"]]);
71
+ assert.deepEqual(s.subagents, []);
72
+ assert.equal(s.updatedAt, 42);
73
+ });
74
+
75
+ test("a subagent child session never publishes a floor", async () => {
76
+ const dir = hub();
77
+ const { pi, fire } = fakePi();
78
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir, GENTLE_PI_AGENTS_CHILD: "1" }, debounceMs: 0 });
79
+ const ctx = fakeCtx([assistant(0.1)]);
80
+ await fire("session_start", ctx);
81
+ await fire("turn_end", ctx);
82
+ await wait(180);
83
+ assert.equal(existsSync(dir) ? readdirSync(dir).length : 0, 0);
84
+ });
85
+
86
+ test("closing the session removes its floor", async () => {
87
+ const dir = hub();
88
+ const { pi, fire } = fakePi();
89
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0 });
90
+ const ctx = fakeCtx([assistant(0.1)]);
91
+ await fire("session_start", ctx);
92
+ await fire("turn_end", ctx);
93
+ await wait(180);
94
+ assert.equal(readTowerSnapshots(dir).length, 1);
95
+ await fire("session_shutdown", ctx);
96
+ assert.deepEqual(readTowerSnapshots(dir), []);
97
+ });
98
+
99
+ test("a todo change republishes the floor's tasks", async () => {
100
+ const dir = hub();
101
+ const { pi, fire, emit } = fakePi();
102
+ const branch: unknown[] = [todoEntry([{ id: 1, title: "Plan", status: "in_progress" }])];
103
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0 });
104
+ const ctx = fakeCtx(branch);
105
+ await fire("session_start", ctx);
106
+ await wait(180);
107
+ assert.deepEqual(readTowerSnapshots(dir)[0].todos.map((t) => t.status), ["in_progress"]);
108
+ branch.push(todoEntry([{ id: 1, title: "Plan", status: "done" }]));
109
+ emit(TODO_PROGRESS_EVENT, { sessionId: "sess-1", done: 1, total: 1 });
110
+ await wait(180);
111
+ assert.deepEqual(readTowerSnapshots(dir)[0].todos.map((t) => t.status), ["done"]);
112
+ });
113
+
114
+ function commandPi() {
115
+ const commands = new Map<string, { handler: (args: string, ctx: ExtensionContext) => Promise<void> | void; description?: string }>();
116
+ const base = fakePi();
117
+ (base.pi as unknown as { registerCommand: unknown }).registerCommand = (name: string, spec: { handler: (args: string, ctx: ExtensionContext) => Promise<void> | void; description?: string }) => commands.set(name, spec);
118
+ return { ...base, commands };
119
+ }
120
+ function uiCtx(messages: string[]): ExtensionContext {
121
+ return { ...fakeCtx([]), ui: { notify: (m: string) => messages.push(m) } } as unknown as ExtensionContext;
122
+ }
123
+
124
+ test("/gentle:tower opens the local tower once and reuses it", async () => {
125
+ const dir = hub();
126
+ const web = join(dir, "..", "web");
127
+ (await import("node:fs")).mkdirSync(web, { recursive: true });
128
+ (await import("node:fs")).writeFileSync(join(web, "index.html"), "<title>Gentle Tower</title>");
129
+ const { pi, commands } = commandPi();
130
+ const opened: string[] = [];
131
+ const tower = createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, webDir: web, openUrl: (u) => opened.push(u) });
132
+ const cmd = commands.get("gentle:tower");
133
+ assert.ok(cmd, "command registered");
134
+ assert.match(cmd.description ?? "", /tower/i);
135
+ const messages: string[] = [];
136
+ await cmd.handler("", uiCtx(messages));
137
+ await cmd.handler("", uiCtx(messages));
138
+ assert.equal(opened.length, 2);
139
+ assert.equal(opened[0], opened[1]);
140
+ assert.match(opened[0], /^http:\/\/127\.0\.0\.1:\d+\/[A-Za-z0-9_-]{32,}\/$/);
141
+ assert.match(messages[0], /Gentle Tower: http:\/\/127\.0\.0\.1/);
142
+ await tower?.close();
143
+ });
144
+
145
+ test("/gentle:tower explains when the web app is not built", async () => {
146
+ const dir = hub();
147
+ const { pi, commands } = commandPi();
148
+ const opened: string[] = [];
149
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, webDir: join(dir, "missing"), openUrl: (u) => opened.push(u) });
150
+ const messages: string[] = [];
151
+ await commands.get("gentle:tower")!.handler("", uiCtx(messages));
152
+ assert.deepEqual(opened, []);
153
+ assert.match(messages[0], /web app is not built/);
154
+ });
155
+
156
+ // ---------- T5: actions requested from the web view ----------
157
+ import { writeTowerAction } from "../lib/tower-actions.ts";
158
+ import { DESKTOP_AGENTS_SERVICE_SCHEMA } from "../lib/desktop-rpc-agents.ts";
159
+
160
+ interface YoloFake { readSnapshot?: (current: string) => Promise<unknown>; setMode?: (m: string, commit: () => void) => Promise<boolean> }
161
+ function actionPi(mode: string, cancel?: (id: string) => Promise<boolean>, yoloFake: YoloFake = {}) {
162
+ const base = fakePi();
163
+ const sent: Array<{ text: string; opts?: unknown }> = [];
164
+ const cancelled: string[] = [];
165
+ const modes: string[] = [];
166
+ let current = mode;
167
+ const pi = base.pi as unknown as Record<string, unknown>;
168
+ pi.sendUserMessage = (text: string, opts?: unknown) => sent.push({ text, opts });
169
+ const events = pi.events as { on(n: string, fn: (d: unknown) => void): () => void };
170
+ events.on("gentle:yolo:host-ui", (req) => (req as { respond(a: unknown): void }).respond({
171
+ read: async () => "OFF", toggle: async () => {}, observe: () => () => {}, dispose() {},
172
+ readSnapshot: async () => (yoloFake.readSnapshot ? yoloFake.readSnapshot(current) : { yolo: "OFF", mode: current, defaultMode: "normal" }),
173
+ setMode: async (m: string) => {
174
+ modes.push(m);
175
+ if (yoloFake.setMode) return yoloFake.setMode(m, () => { current = m; });
176
+ current = m;
177
+ return true;
178
+ },
179
+ }));
180
+ events.on("gentle:desktop:agents-service", (req) => (req as { respond(a: unknown): void }).respond({
181
+ read: () => ({ sessionId: "sess-1", agents: [{ id: "t1", agent: "gentle-ai-worker", status: "running", model: "m", lastStep: "editing", usage: { total: 10, cost: 0.01 } }] }),
182
+ schema: DESKTOP_AGENTS_SERVICE_SCHEMA, observe: () => () => {}, cancel: cancel ?? (async (id: string) => { cancelled.push(id); return true; }), dispose() {},
183
+ }));
184
+ return { ...base, sent, cancelled, modes, current: () => current };
185
+ }
186
+ const busyCtx = (idle: boolean) => ({ ...fakeCtx([assistant(0.1)]), isIdle: () => idle }) as unknown as ExtensionContext;
187
+
188
+ test("a web message reaches the floor: a new turn when idle, a follow-up when busy", async () => {
189
+ const dir = hub();
190
+ const { pi, fire, sent } = actionPi("normal");
191
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async () => "{}" });
192
+ let idle = true;
193
+ const ctx = { ...busyCtx(true), isIdle: () => idle } as unknown as ExtensionContext;
194
+ await fire("session_start", ctx);
195
+ await wait(150);
196
+ writeTowerAction(dir, { type: "message", sessionId: "sess-1", text: "also update the docs" });
197
+ await wait(120);
198
+ idle = false;
199
+ writeTowerAction(dir, { type: "message", sessionId: "sess-1", text: "and the changelog" });
200
+ await wait(120);
201
+ assert.deepEqual(sent, [{ text: "also update the docs", opts: undefined }, { text: "and the changelog", opts: { deliverAs: "followUp" } }]);
202
+ // The message shows up in the conversation itself; no standalone "delivered" notice.
203
+ assert.equal(readTowerSnapshots(dir)[0].notice, undefined);
204
+ await fire("session_shutdown", ctx);
205
+ });
206
+
207
+ test("a Tower follow-up survives the publisher and outbox after many tool turns", async () => {
208
+ const dir = hub(), web = join(dir, "..", "web");
209
+ mkdirSync(web, { recursive: true }); writeFileSync(join(web, "index.html"), "<title>test</title>");
210
+ const T = 1_700_000_000_000;
211
+ const branch: unknown[] = [
212
+ { type: "message", message: { role: "user", content: "terminal question", timestamp: T - 1000 } },
213
+ { type: "message", message: { role: "assistant", content: [{ type: "text", text: "previous reply" }], timestamp: T - 500 } },
214
+ ];
215
+ const action = actionPi("normal");
216
+ const send = action.pi.sendUserMessage;
217
+ (action.pi as unknown as { sendUserMessage: (text: string, opts?: unknown) => void }).sendUserMessage = (text, opts) => {
218
+ send(text, opts as never);
219
+ // Pi persists an extension-sent user message as a normal branch entry.
220
+ branch.push({ type: "message", message: { role: "user", content: [{ type: "text", text }], timestamp: T + 10 } });
221
+ };
222
+ const ctx = { ...fakeCtx(branch), isIdle: () => false } as unknown as ExtensionContext;
223
+ createTowerPublisher(action.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async () => "{}", now: () => T + 1000 });
224
+ await action.fire("session_start", ctx);
225
+ await wait(150);
226
+ const server = await startTowerServer({ hubDir: dir, webDir: web, token: "tok-123" });
227
+ const sessions = async () => (await (await fetch(`${server.url}api/sessions`)).json() as { sessions: Array<{ chat: Array<{ role: "you" | "agent"; text: string; at: number }> }> }).sessions;
228
+ try {
229
+ const before = (await sessions())[0].chat;
230
+ const outgoing: Outgoing = { ...sentMessage("tower question", T, before), state: "sent" };
231
+ const accepted = await fetch(`${server.url}api/action`, { method: "POST", headers: { Origin: `http://127.0.0.1:${server.port}`, "Content-Type": "application/json" }, body: JSON.stringify({ type: "message", sessionId: "sess-1", text: "tower question" }) });
232
+ assert.equal(accepted.status, 202);
233
+ await wait(100);
234
+ assert.deepEqual(action.sent, [{ text: "tower question", opts: { deliverAs: "followUp" } }]);
235
+ await action.fire("turn_end", ctx); await wait(80);
236
+ const echo = (await sessions())[0].chat;
237
+ assert.deepEqual(echo.map((t) => t.text), ["terminal question", "previous reply", "tower question"]);
238
+ const consumed = new Set<string>();
239
+ assert.deepEqual(settleOutbox([outgoing], echo, consumed).keep, []);
240
+ 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 } });
241
+ branch.push({ type: "message", message: { role: "assistant", content: [{ type: "text", text: "final answer" }], timestamp: T + 200 } });
242
+ await action.fire("turn_end", ctx); await wait(80);
243
+ const chat = (await sessions())[0].chat;
244
+ assert.equal(chat.length, TOWER_CHAT_TURNS);
245
+ assert.deepEqual(chat[0], { role: "you", text: "tower question", at: T + 10 });
246
+ assert.deepEqual(chat.at(-1), { role: "agent", text: "final answer", at: T + 200 });
247
+ assert.deepEqual(settleOutbox([], chat, consumed).show, []);
248
+ } finally {
249
+ await action.fire("session_shutdown", ctx);
250
+ await server.close();
251
+ }
252
+ });
253
+
254
+ test("stop helper cancels exactly that subagent", async () => {
255
+ const dir = hub();
256
+ const { pi, fire, cancelled } = actionPi("normal");
257
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async () => "{}" });
258
+ const ctx = busyCtx(false);
259
+ await fire("session_start", ctx);
260
+ await wait(150);
261
+ writeTowerAction(dir, { type: "cancel-helper", sessionId: "sess-1", helperId: "t1" });
262
+ await wait(120);
263
+ assert.deepEqual(cancelled, ["t1"]);
264
+ assert.match(readTowerSnapshots(dir)[0].notice?.text ?? "", /Stopped worker/);
265
+ await fire("session_shutdown", ctx);
266
+ });
267
+
268
+ test("a failing action is reported and the rest of the batch still runs", async () => {
269
+ const dir = hub();
270
+ const action = actionPi("normal", async () => { throw new Error("agent host gone"); });
271
+ createTowerPublisher(action.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async () => "{}" });
272
+ const ctx = busyCtx(true);
273
+ await action.fire("session_start", ctx);
274
+ await wait(150);
275
+ writeTowerAction(dir, { type: "cancel-helper", sessionId: "sess-1", helperId: "t1" });
276
+ writeTowerAction(dir, { type: "message", sessionId: "sess-1", text: "still here?" });
277
+ await wait(150);
278
+ assert.deepEqual(action.sent.map((m) => m.text), ["still here?"]);
279
+ const notice = readTowerSnapshots(dir)[0].notice;
280
+ assert.equal(notice?.ok, false);
281
+ assert.match(notice?.text ?? "", /Could not stop the helper: agent host gone/);
282
+ // The message itself shows in the conversation; only the failure is a notice.
283
+ assert.equal(notice?.text, "Could not stop the helper: agent host gone");
284
+ await action.fire("session_shutdown", ctx);
285
+ });
286
+
287
+ test("an action that never answers times out, so the inbox keeps working", async () => {
288
+ const dir = hub();
289
+ const action = actionPi("normal", () => new Promise(() => {}));
290
+ createTowerPublisher(action.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, actionTimeoutMs: 60, reviewCli: async () => "{}" });
291
+ const ctx = busyCtx(true);
292
+ await action.fire("session_start", ctx);
293
+ await wait(150);
294
+ writeTowerAction(dir, { type: "cancel-helper", sessionId: "sess-1", helperId: "t1" });
295
+ await wait(200);
296
+ writeTowerAction(dir, { type: "message", sessionId: "sess-1", text: "after the hang" });
297
+ await wait(150);
298
+ assert.deepEqual(action.sent.map((m) => m.text), ["after the hang"]);
299
+ await action.fire("session_shutdown", ctx);
300
+ });
301
+
302
+ const confirmCtx = (confirm?: (title: string, message: string) => Promise<boolean>) => ({ ...fakeCtx([assistant(0.1)]), isIdle: () => true, hasUI: confirm !== undefined, ui: confirm ? { confirm, notify() {} } : undefined }) as unknown as ExtensionContext;
303
+
304
+ async function doorCase(start: string, mode: "normal" | "auto" | "yolo" | "super-yolo", ctx: ExtensionContext) {
305
+ const dir = hub();
306
+ const action = actionPi(start);
307
+ createTowerPublisher(action.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async () => "{}" });
308
+ await action.fire("session_start", ctx);
309
+ await wait(150);
310
+ assert.equal(readTowerSnapshots(dir)[0].permission, start);
311
+ writeTowerAction(dir, { type: "permission", sessionId: "sess-1", mode });
312
+ await wait(150);
313
+ const s = readTowerSnapshots(dir)[0];
314
+ await action.fire("session_shutdown", ctx);
315
+ return { ...action, s };
316
+ }
317
+
318
+ test("the door lowers permissions from the web at once, without asking", async () => {
319
+ const asked: string[] = [];
320
+ const { modes, current, s } = await doorCase("yolo", "normal", confirmCtx(async (t) => { asked.push(t); return true; }));
321
+ assert.deepEqual(asked, []);
322
+ assert.deepEqual(modes, ["normal"]);
323
+ assert.equal(current(), "normal");
324
+ assert.equal(s.permission, "normal");
325
+ assert.equal(s.notice?.ok, true);
326
+ });
327
+
328
+ test("raising permissions from the web applies only after the terminal approves", async () => {
329
+ const asked: Array<[string, string]> = [];
330
+ const { modes, current, s } = await doorCase("normal", "yolo", confirmCtx(async (t, m) => { asked.push([t, m]); return true; }));
331
+ assert.equal(asked.length, 1);
332
+ assert.equal(asked[0][0], "Gentle Tower");
333
+ assert.match(asked[0][1], /from normal to yolo/);
334
+ assert.deepEqual(modes, ["yolo"]);
335
+ assert.equal(current(), "yolo");
336
+ assert.equal(s.permission, "yolo");
337
+ assert.deepEqual([s.notice?.ok, s.notice?.text], [true, "Permissions: yolo (approved in the terminal)"]);
338
+ });
339
+
340
+ test("a raise declined in the terminal changes nothing", async () => {
341
+ for (const answer of [async () => false, async () => undefined as unknown as boolean, async () => { throw new Error("closed"); }]) {
342
+ const { modes, current, s } = await doorCase("normal", "super-yolo", confirmCtx(answer));
343
+ assert.deepEqual(modes, []);
344
+ assert.equal(current(), "normal");
345
+ assert.equal(s.permission, "normal");
346
+ assert.deepEqual([s.notice?.ok, s.notice?.text], [false, "Raising permissions to super-yolo was declined in the terminal"]);
347
+ }
348
+ });
349
+
350
+ test("a raise is refused when the session cannot ask in its terminal", async () => {
351
+ for (const ctx of [busyCtx(true), confirmCtx(), ({ ...fakeCtx([assistant(0.1)]), hasUI: false, ui: { confirm: async () => true } }) as unknown as ExtensionContext]) {
352
+ const { modes, current, s } = await doorCase("auto", "yolo", ctx);
353
+ assert.deepEqual(modes, []);
354
+ assert.equal(current(), "auto");
355
+ assert.equal(s.permission, "auto");
356
+ assert.deepEqual([s.notice?.ok, s.notice?.text], [false, "Raising permissions to yolo needs the terminal: this session cannot ask"]);
357
+ }
358
+ });
359
+
360
+ test("permissions fail closed: when the current mode cannot be read, neither a raise nor a lower is applied", async () => {
361
+ const hang = () => new Promise<never>(() => {});
362
+ const reject = async () => { throw new Error("yolo host gone"); };
363
+ for (const broken of [reject, hang]) {
364
+ for (const mode of ["super-yolo", "normal"] as const) {
365
+ const dir = hub();
366
+ let readable = true;
367
+ const asked: string[] = [];
368
+ const action = actionPi("yolo", undefined, { readSnapshot: (current) => (readable ? Promise.resolve({ yolo: "OFF", mode: current, defaultMode: "normal" }) : broken()) });
369
+ createTowerPublisher(action.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, actionTimeoutMs: 60, reviewCli: async () => "{}" });
370
+ const ctx = confirmCtx(async (t) => { asked.push(t); return true; });
371
+ await action.fire("session_start", ctx);
372
+ await wait(150);
373
+ assert.equal(readTowerSnapshots(dir)[0].permission, "yolo");
374
+ readable = false;
375
+ writeTowerAction(dir, { type: "permission", sessionId: "sess-1", mode });
376
+ await wait(250);
377
+ const s = readTowerSnapshots(dir)[0];
378
+ assert.deepEqual(asked, [], `${mode}: never asks the terminal`);
379
+ assert.deepEqual(action.modes, [], `${mode}: never calls setMode`);
380
+ assert.equal(action.current(), "yolo");
381
+ assert.deepEqual([s.notice?.ok, s.notice?.text], [false, "Permissions unchanged: could not read the current mode"]);
382
+ assert.equal(s.permission, undefined, "an unknown mode is not shown as the old one");
383
+ await action.fire("session_shutdown", ctx);
384
+ }
385
+ }
386
+ });
387
+
388
+ test("a permission change that times out is followed until it settles and reports the real result", async () => {
389
+ const dir = hub();
390
+ const action = actionPi("yolo", undefined, { setMode: (_m, commit) => new Promise((done) => setTimeout(() => { commit(); done(true); }, 250)) });
391
+ createTowerPublisher(action.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, actionTimeoutMs: 60, reviewCli: async () => "{}" });
392
+ const ctx = confirmCtx(async () => true);
393
+ await action.fire("session_start", ctx);
394
+ await wait(150);
395
+ writeTowerAction(dir, { type: "permission", sessionId: "sess-1", mode: "normal" });
396
+ await wait(150);
397
+ let s = readTowerSnapshots(dir)[0];
398
+ assert.deepEqual([s.notice?.ok, s.notice?.text], [false, "Permissions: the change to normal is still pending; the session is in yolo"]);
399
+ assert.equal(s.permission, "yolo");
400
+ await wait(300);
401
+ s = readTowerSnapshots(dir)[0];
402
+ assert.equal(action.current(), "normal");
403
+ assert.equal(s.permission, "normal");
404
+ assert.deepEqual([s.notice?.ok, s.notice?.text], [true, "Permissions: normal"]);
405
+ await action.fire("session_shutdown", ctx);
406
+ });
407
+
408
+ test("a permission change still applies normally when it answers in time", async () => {
409
+ const { modes, s } = await doorCase("auto", "normal", confirmCtx(async () => true));
410
+ assert.deepEqual(modes, ["normal"]);
411
+ assert.deepEqual([s.permission, s.notice?.ok, s.notice?.text], ["normal", true, "Permissions: normal"]);
412
+ });
413
+
414
+ test("closing the session that opened the tower closes its server", async () => {
415
+ const dir = hub();
416
+ const web = join(dir, "..", "web");
417
+ (await import("node:fs")).mkdirSync(web, { recursive: true });
418
+ (await import("node:fs")).writeFileSync(join(web, "index.html"), "<title>Gentle Tower</title>");
419
+ const { pi, commands, fire } = commandPi();
420
+ const opened: string[] = [];
421
+ const tower = createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, webDir: web, openUrl: (u) => opened.push(u) });
422
+ const ctx = fakeCtx([assistant(0.1)]);
423
+ await fire("session_start", ctx);
424
+ await commands.get("gentle:tower")!.handler("", uiCtx([]));
425
+ assert.equal((await fetch(opened[0])).status, 200);
426
+ await fire("session_shutdown", ctx);
427
+ await wait(50);
428
+ await assert.rejects(fetch(opened[0]), "the listener is gone");
429
+ await tower?.close();
430
+ });
431
+
432
+ test("the review switch runs the review mode command and shows the new state", async () => {
433
+ const dir = hub();
434
+ const calls: string[][] = [];
435
+ let state = "on";
436
+ const { pi, fire } = actionPi("normal");
437
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async (args) => {
438
+ calls.push(args);
439
+ if (args[2] === "disable") state = "off";
440
+ if (args[2] === "enable") state = "on";
441
+ return JSON.stringify({ status: { effective: state } });
442
+ } });
443
+ const ctx = busyCtx(true);
444
+ await fire("session_start", ctx);
445
+ await wait(150);
446
+ assert.equal(readTowerSnapshots(dir)[0].review, "on");
447
+ writeTowerAction(dir, { type: "review", sessionId: "sess-1", enabled: false });
448
+ await wait(150);
449
+ assert.deepEqual(calls.map((a) => a.join(" ")), ["review mode status --json", "review mode disable", "review mode status --json"]);
450
+ assert.equal(readTowerSnapshots(dir)[0].review, "off");
451
+ await fire("session_shutdown", ctx);
452
+ });
453
+
454
+ test("a question waiting in the terminal shows on the floor", async () => {
455
+ const dir = hub();
456
+ const { pi, fire, emit } = actionPi("normal");
457
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, reviewCli: async () => "{}" });
458
+ const ctx = busyCtx(false);
459
+ await fire("session_start", ctx);
460
+ emit("gentle-pi:ask-user-question:blocked", { active: true });
461
+ await wait(150);
462
+ assert.equal(readTowerSnapshots(dir)[0].waiting, true);
463
+ emit("gentle-pi:ask-user-question:blocked", { active: false });
464
+ await wait(80);
465
+ assert.equal(readTowerSnapshots(dir)[0].waiting, undefined);
466
+ await fire("session_shutdown", ctx);
467
+ });
468
+
469
+ test("the floor carries the orchestrator's latest words, bounded", async () => {
470
+ const dir = hub();
471
+ const { pi, fire } = fakePi();
472
+ const long = "Found it. ".repeat(100);
473
+ const branch = [
474
+ { type: "message", message: { role: "assistant", content: [{ type: "text", text: "old reply" }], usage: { input: 1, output: 1, cost: { total: 0 } } } },
475
+ { type: "message", message: { role: "assistant", content: [{ type: "thinking", thinking: "hidden" }, { type: "toolCall", name: "read", arguments: {} }, { type: "text", text: long }], usage: { input: 1, output: 1, cost: { total: 0 } } } },
476
+ ];
477
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, reviewCli: async () => "{}" });
478
+ const ctx = fakeCtx(branch);
479
+ await fire("session_start", ctx);
480
+ await wait(180);
481
+ const said = readTowerSnapshots(dir)[0].said ?? "";
482
+ assert.ok(said.startsWith("Found it."));
483
+ assert.ok(said.length <= 600);
484
+ assert.doesNotMatch(said, /hidden|old reply/);
485
+ await fire("session_shutdown", ctx);
486
+ });
487
+
488
+ test("the floor carries the conversation: your messages and the agent's visible replies, in order", async () => {
489
+ const dir = hub();
490
+ const { pi, fire } = fakePi();
491
+ const branch = [
492
+ { type: "message", message: { role: "user", content: "what did you do?", timestamp: 10 } },
493
+ { type: "message", message: { role: "assistant", content: [{ type: "thinking", thinking: "hidden" }, { type: "toolCall", name: "read", arguments: {} }, { type: "text", text: "Fixed the token refresh." }], timestamp: 20, usage: { input: 1, output: 1, cost: { total: 0 } } } },
494
+ { type: "message", message: { role: "custom", customType: "gentle-todo-reminder", content: "injected", display: false, timestamp: 25 } },
495
+ ];
496
+ createTowerPublisher(pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, reviewCli: async () => "{}" });
497
+ const ctx = fakeCtx(branch);
498
+ await fire("session_start", ctx);
499
+ await wait(180);
500
+ const s = readTowerSnapshots(dir)[0];
501
+ assert.deepEqual(s.chat, [{ role: "you", text: "what did you do?", at: 10 }, { role: "agent", text: "Fixed the token refresh.", at: 20 }]);
502
+ assert.equal(s.said, "Fixed the token refresh.");
503
+ await fire("session_shutdown", ctx);
504
+ });
505
+
506
+ test("only live helpers are on the floor; finished ones leave the building", async () => {
507
+ const dir = hub();
508
+ const base = fakePi();
509
+ const events = (base.pi as unknown as { events: { on(n: string, fn: (d: unknown) => void): () => void } }).events;
510
+ const entry = (id: string, status: string) => ({ id, agent: "gentle-ai-explore", status, model: "m", lastStep: "reading", usage: { total: 1, cost: 0 } });
511
+ events.on("gentle:desktop:agents-service", (req) => (req as { respond(a: unknown): void }).respond({
512
+ schema: DESKTOP_AGENTS_SERVICE_SCHEMA,
513
+ read: () => ({ sessionId: "sess-1", agents: [entry("q", "queued"), entry("r", "running"), entry("w", "waiting"), entry("c", "completed"), entry("f", "failed"), entry("x", "cancelled"), entry("t", "timed_out")] }),
514
+ observe: () => () => {}, cancel: async () => true, dispose() {},
515
+ }));
516
+ createTowerPublisher(base.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, reviewCli: async () => "{}" });
517
+ const ctx = fakeCtx([assistant(0.1)]);
518
+ await base.fire("session_start", ctx);
519
+ await wait(180);
520
+ assert.deepEqual(readTowerSnapshots(dir)[0].subagents.map((a) => a.id), ["q", "r", "w"]);
521
+ await base.fire("session_shutdown", ctx);
522
+ });
523
+
524
+ test("a raise is decided on the action's own read, even when an earlier late write lands in between", async () => {
525
+ const dir = hub();
526
+ const base = fakePi();
527
+ const confirms: string[] = [];
528
+ const modes: string[] = [];
529
+ let current = "normal";
530
+ let releaseSlow: () => void = () => {};
531
+ let slowSettled = false;
532
+ /** While set, reads take the mode at call time and wait here; released together, they finish in call order, step by step. */
533
+ let gate: { open: () => void; wait: Promise<void>; reads: number } | undefined;
534
+ const events = (base.pi as unknown as { events: { on(n: string, fn: (d: unknown) => void): () => void } }).events;
535
+ (base.pi as unknown as { sendUserMessage: unknown }).sendUserMessage = () => {};
536
+ events.on("gentle:yolo:host-ui", (req) => (req as { respond(a: unknown): void }).respond({
537
+ read: async () => "OFF", toggle: async () => {}, observe: () => () => {}, dispose() {},
538
+ readSnapshot: async () => {
539
+ const mode = current;
540
+ if (gate) {
541
+ gate.reads++;
542
+ // The second action's own read: the earlier write now lands, and its follow-up re-reads.
543
+ if (gate.reads === 1) releaseSlow();
544
+ // That follow-up read: release both, so its result lands right after the action's own.
545
+ else setTimeout(gate.open, 0);
546
+ await gate.wait;
547
+ }
548
+ return { yolo: "OFF", mode, defaultMode: "normal" };
549
+ },
550
+ setMode: (m: string) => {
551
+ modes.push(m);
552
+ // The first write (to super-yolo) hangs past the timeout, then lands late.
553
+ if (modes.length === 1) return new Promise<boolean>((r) => { releaseSlow = () => { current = m; slowSettled = true; r(true); }; });
554
+ current = m; return Promise.resolve(true);
555
+ },
556
+ }));
557
+ createTowerPublisher(base.pi, { env: { GENTLE_TOWER_HOME: dir }, debounceMs: 0, inboxMs: 20, actionTimeoutMs: 50, reviewCli: async () => "{}" });
558
+ // The first raise is approved in the terminal; the second is declined.
559
+ const ctx = { ...fakeCtx([assistant(0.1)]), hasUI: true, isIdle: () => true, ui: { notify() {}, confirm: async (_t: string, m: string) => { confirms.push(m); return confirms.length === 1; } } } as unknown as ExtensionContext;
560
+ await base.fire("session_start", ctx);
561
+ await wait(150);
562
+ writeTowerAction(dir, { type: "permission", sessionId: "sess-1", mode: "super-yolo" });
563
+ await wait(300);
564
+ assert.deepEqual(modes, ["super-yolo"], "the approved write started");
565
+ assert.match(readTowerSnapshots(dir)[0].notice?.text ?? "", /change to super-yolo is still pending; the session is in normal/);
566
+ // The second action reads "normal". Between that read and its decision, the late write lands and
567
+ // its follow-up read publishes "super-yolo": a decision on the shared value would see a lowering.
568
+ let release = () => {};
569
+ gate = { open: () => { gate = undefined; release(); }, wait: new Promise<void>((r) => { release = r; }), reads: 0 };
570
+ writeTowerAction(dir, { type: "permission", sessionId: "sess-1", mode: "yolo" });
571
+ await wait(300);
572
+ assert.equal(slowSettled, true, "the earlier write settled");
573
+ assert.equal(confirms.length, 2, "the second action was treated as a raise and asked in the terminal");
574
+ assert.match(confirms[1], /from normal to yolo/);
575
+ assert.ok(!modes.includes("yolo"), "the declined raise never applied");
576
+ assert.equal(readTowerSnapshots(dir)[0].permission, "super-yolo", "the late write landed and was published");
577
+ await base.fire("session_shutdown", ctx);
578
+ });