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,642 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtempSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import { test } from "node:test";
6
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
+ import { createDesktopFeedExtension } from "../extensions/gentle-desktop-feed.ts";
8
+ import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
9
+ import {
10
+ buildDesktopFeedSnapshot,
11
+ DESKTOP_FEED_URGENT_MS,
12
+ DESKTOP_FEED_DEBOUNCE_MS,
13
+ type DesktopFeedInput,
14
+ type DesktopFeedSnapshot,
15
+ type DesktopFeedTimers,
16
+ } from "../lib/desktop-feed.ts";
17
+ import { createDesktopFeedStore } from "../lib/desktop-feed-store.ts";
18
+ import {
19
+ DESKTOP_SESSION_EVENT,
20
+ DESKTOP_SESSION_SECTIONS,
21
+ DESKTOP_SESSION_SERVICE_CHANNEL,
22
+ desktopSessionRootLabel,
23
+ INVALID_SESSION_PARAMS,
24
+ isDesktopSessionServiceShape,
25
+ parseSessionSnapshotParams,
26
+ projectDesktopSessionSections,
27
+ SESSION_UNAVAILABLE,
28
+ } from "../lib/desktop-rpc-session.ts";
29
+ import { DesktopSessionBridge } from "../lib/desktop-session-service.ts";
30
+ import { DESKTOP_RPC_SCHEMA, DesktopRpcRouter } from "../lib/desktop-rpc.ts";
31
+ import { REVIEW_SIDEBAR_EVENT } from "../lib/review-sidebar-state.ts";
32
+ import { changesModel, type ChangedFile } from "../lib/shell-changes.ts";
33
+ import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
34
+
35
+ // Owner discovery waits up to 100 ms for a responder; let it settle.
36
+ const settle = () => new Promise((resolve) => setTimeout(resolve, 150));
37
+ const GENTLE_ENV = { PI_PROGRAM_STATUS_APP: "gentle-shell", [INTERACTIVE_HOST_ENV]: "1" };
38
+
39
+ // ---- Fixtures ----
40
+
41
+ function fixtureInput(overrides: Partial<DesktopFeedInput> = {}): DesktopFeedInput {
42
+ const files: ChangedFile[] = [
43
+ { path: "lib/a.ts", added: 3, deleted: 1, status: "modified" },
44
+ { path: "docs/new.md", added: 10, deleted: 0, status: "untracked" },
45
+ ];
46
+ const model = changesModel(files);
47
+ return {
48
+ now: Date.UTC(2026, 10, 14, 12, 0, 0),
49
+ identity: { sessionId: "sess-1", sessionFile: "/agent/sessions/--w--/s.jsonl", sessionName: "Feed", cwd: "/home/dev/work/gentle-shell", realCwd: "/private/home/dev/work/gentle-shell", pid: 100, ppid: 99, ancestors: [98, 1], mode: "rpc", agentDir: "/agent", env: {} },
50
+ branch: "feat/x",
51
+ model: { id: "claude-opus-5-5", provider: "anthropic", reasoning: true },
52
+ thinkingLevel: "high",
53
+ subscription: true,
54
+ profile: { name: "work", tier: "fast" },
55
+ context: { percent: 42, tokens: 84_000, contextWindow: 200_000 },
56
+ usage: undefined,
57
+ permission: { mode: "normal" },
58
+ todo: { tasks: [{ id: 1, title: "Write tests", status: "in_progress" }], nextId: 2, updatedTurn: 1 },
59
+ changes: { model, worktrees: [{ root: "/home/dev/work/gentle-shell", branch: "feat/x", model }] },
60
+ agents: [],
61
+ jobs: [{ id: "j1", label: "npm test", status: "running", startedAt: Date.UTC(2026, 10, 14, 11, 59, 0) }],
62
+ review: undefined,
63
+ stats: { cost: 1.25, input: 100, output: 50, cacheRead: 300, cacheWrite: 10, turns: 4, toolCalls: 7, toolErrors: 1, spanMs: 60_000, cacheHitRate: 0.75, models: [] },
64
+ activity: { working: false, blocked: 0, blockedLabel: undefined, streaming: false, phase: undefined },
65
+ pendingQuestion: undefined,
66
+ ...overrides,
67
+ };
68
+ }
69
+
70
+ function fakeTimers() {
71
+ const pending = new Map<number, { fn: () => void; ms: number }>();
72
+ let next = 0;
73
+ const timers: DesktopFeedTimers = {
74
+ set(fn, ms) { next += 1; pending.set(next, { fn, ms }); return next; },
75
+ clear(handle) { pending.delete(handle as number); },
76
+ };
77
+ return {
78
+ timers,
79
+ delays: () => [...pending.values()].map((entry) => entry.ms),
80
+ run() { const entries = [...pending.values()]; pending.clear(); for (const entry of entries) entry.fn(); },
81
+ };
82
+ }
83
+
84
+ type Handler = (event: any, ctx: any) => unknown;
85
+
86
+ function fakeBus() {
87
+ const listeners = new Map<string, Set<(data: unknown) => void>>();
88
+ return {
89
+ on(name: string, fn: (data: unknown) => void) {
90
+ const set = listeners.get(name) ?? new Set();
91
+ set.add(fn);
92
+ listeners.set(name, set);
93
+ return () => { set.delete(fn); };
94
+ },
95
+ emit(name: string, data: unknown) { for (const fn of [...(listeners.get(name) ?? [])]) fn(data); },
96
+ };
97
+ }
98
+
99
+ function fakePi() {
100
+ const handlers = new Map<string, Handler[]>();
101
+ const commands = new Map<string, { handler: (args: string, ctx: any) => Promise<void> }>();
102
+ const bus = fakeBus();
103
+ const pi = {
104
+ on(name: string, fn: Handler) { handlers.set(name, [...(handlers.get(name) ?? []), fn]); return () => {}; },
105
+ events: bus,
106
+ registerCommand(name: string, command: any) { commands.set(name, command); },
107
+ getThinkingLevel: () => "high",
108
+ } as unknown as ExtensionAPI;
109
+ const fire = (name: string, event: unknown, ctx: unknown) => { for (const fn of handlers.get(name) ?? []) fn(event, ctx); };
110
+ return { pi, bus, commands, fire };
111
+ }
112
+
113
+ function fakeCtx() {
114
+ const entries: unknown[] = [];
115
+ const widgets: Array<{ key: string; lines: string[] }> = [];
116
+ return {
117
+ cwd: "/home/dev/work/gentle-shell", mode: "rpc", hasUI: true,
118
+ isIdle: () => true,
119
+ model: { id: "claude-opus-5-5", provider: "anthropic", reasoning: true, contextWindow: 200_000 },
120
+ modelRegistry: { isUsingOAuth: () => true },
121
+ getContextUsage: () => ({ tokens: 1000, contextWindow: 200_000, percent: 0.5 }),
122
+ ui: { setWidget(key: string, lines: string[]) { widgets.push({ key, lines }); } },
123
+ widgets,
124
+ sessionManager: {
125
+ getSessionId: () => "sess-1",
126
+ getSessionFile: () => "/agent/sessions/--w--/2026_sess-1.jsonl",
127
+ getSessionName: () => undefined,
128
+ getCwd: () => "/home/dev/work/gentle-shell",
129
+ getBranch: () => entries,
130
+ getEntries: () => entries,
131
+ },
132
+ };
133
+ }
134
+
135
+ function interactiveHost(t: test.TestContext): void {
136
+ const previous = process.env[INTERACTIVE_HOST_ENV];
137
+ process.env[INTERACTIVE_HOST_ENV] = "1";
138
+ t.after(() => {
139
+ if (previous === undefined) delete process.env[INTERACTIVE_HOST_ENV];
140
+ else process.env[INTERACTIVE_HOST_ENV] = previous;
141
+ });
142
+ }
143
+
144
+ /** The real desktop RPC extension, with or without the real feed extension, on one fake pi. */
145
+ async function rpcHarness(t: test.TestContext, withFeed: boolean) {
146
+ interactiveHost(t);
147
+ const harness = fakePi();
148
+ desktopRpc(harness.pi);
149
+ const agentDir = mkdtempSync(join(tmpdir(), "desktop-rpc-session-"));
150
+ t.after(() => rmSync(agentDir, { recursive: true, force: true }));
151
+ const clock = fakeTimers();
152
+ if (withFeed) {
153
+ createDesktopFeedExtension({
154
+ env: GENTLE_ENV,
155
+ agentDir,
156
+ now: () => Date.UTC(2026, 10, 14, 12, 0, 0),
157
+ timers: clock.timers,
158
+ git: () => async () => ({ stdout: "", code: 128 }),
159
+ parentOf: async (pid) => (pid === process.ppid ? 4242 : undefined),
160
+ profile: () => ({ name: "work", tier: "fast" }),
161
+ realpath: (path) => `/private${path}`,
162
+ sweep: () => {},
163
+ actionWatch: () => () => {},
164
+ store: (dir, sessionId) => createDesktopFeedStore(dir, sessionId),
165
+ })(harness.pi);
166
+ }
167
+ const ctx = fakeCtx();
168
+ t.after(() => harness.fire("session_shutdown", { reason: "quit" }, ctx));
169
+ harness.fire("session_start", { reason: "startup" }, ctx);
170
+ await settle();
171
+ clock.run();
172
+ await settle();
173
+ clock.run();
174
+ await settle();
175
+ const lines = () => ctx.widgets.filter((widget) => widget.key === "gentle-desktop-rpc").map((widget) => widget.lines[0]!);
176
+ let requests = 0;
177
+ return {
178
+ ...harness, ctx, clock, lines,
179
+ async invoke(method: string, params: Record<string, unknown> = {}) {
180
+ requests += 1;
181
+ const before = lines().length;
182
+ await harness.commands.get("gentle:desktop")!.handler(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId: `r${requests}`, method, params }), ctx);
183
+ return lines().slice(before).map((line) => JSON.parse(line));
184
+ },
185
+ };
186
+ }
187
+
188
+ const ABSOLUTE = ["/home/dev", "/private", "/agent", "sess-1.jsonl", "4242"];
189
+
190
+ // ---- Pure contract: params ----
191
+
192
+ test("S2: get_snapshot params without sections stay the legacy read; bad sections are invalid_request", () => {
193
+ assert.deepEqual(parseSessionSnapshotParams({}), { legacy: true });
194
+ assert.deepEqual(parseSessionSnapshotParams({ other: 1 }), { legacy: true }, "unrelated params keep today's (ignored) behavior");
195
+ assert.deepEqual(parseSessionSnapshotParams({ sections: ["todo", "changes"] }), { sections: ["todo", "changes"] });
196
+ assert.deepEqual(parseSessionSnapshotParams({ sections: [...DESKTOP_SESSION_SECTIONS] }), { sections: [...DESKTOP_SESSION_SECTIONS] });
197
+ for (const params of [
198
+ { sections: ["todo", "identity"] },
199
+ { sections: ["nope"] },
200
+ { sections: "todo" },
201
+ { sections: [] },
202
+ { sections: ["todo", "todo"] },
203
+ { sections: [1] },
204
+ { sections: ["todo"], extra: true },
205
+ { sections: null },
206
+ ]) {
207
+ assert.deepEqual(parseSessionSnapshotParams(params as Record<string, unknown>), { error: INVALID_SESSION_PARAMS }, JSON.stringify(params));
208
+ }
209
+ assert.deepEqual(INVALID_SESSION_PARAMS.code, "invalid_request");
210
+ assert.deepEqual(SESSION_UNAVAILABLE.code, "session_unavailable");
211
+ assert.deepEqual([...DESKTOP_SESSION_SECTIONS], ["project", "model", "context", "cost", "usage", "profiles", "permission", "todo", "changes", "agents", "jobs", "review", "stats", "activity", "pendingQuestion", "commands"]);
212
+ });
213
+
214
+ // ---- Pure contract: field discipline ----
215
+
216
+ test("S4: the projection drops identity and every absolute path; cwd becomes a basename, roots become opaque labels", () => {
217
+ const snapshot = buildDesktopFeedSnapshot(fixtureInput());
218
+ const sections = projectDesktopSessionSections(snapshot, DESKTOP_SESSION_SECTIONS);
219
+ assert.deepEqual(Object.keys(sections), [...DESKTOP_SESSION_SECTIONS]);
220
+ assert.deepEqual(sections.project, { name: "gentle-shell", branch: "feat/x", dirty: 2 });
221
+ const label = desktopSessionRootLabel("/home/dev/work/gentle-shell");
222
+ assert.match(label, /^root-[0-9a-f]{12}$/);
223
+ assert.deepEqual(sections.changes, {
224
+ files: snapshot.changes!.files.map((file) => ({ path: file.path, root: label, status: file.status, added: file.added, deleted: file.deleted })),
225
+ summary: { files: 2, added: 13, deleted: 1 },
226
+ worktrees: [{ root: label, branch: "feat/x", files: 2 }],
227
+ truncated: false,
228
+ });
229
+ // Untouched sections are the feed's own shapes.
230
+ assert.deepEqual(sections.todo, snapshot.todo);
231
+ assert.deepEqual(sections.jobs, snapshot.jobs);
232
+ assert.deepEqual(sections.commands, snapshot.commands);
233
+ const wire = JSON.stringify(sections);
234
+ for (const needle of [...ABSOLUTE, "identity", "pid", "ancestors", "agentDir", "sessionFile", "realCwd"]) {
235
+ assert.equal(wire.includes(needle), false, needle);
236
+ }
237
+ // Only the requested sections, in the canonical order.
238
+ assert.deepEqual(Object.keys(projectDesktopSessionSections(snapshot, ["todo", "project"])), ["project", "todo"]);
239
+ });
240
+
241
+ test("S4: files of several worktrees become paths relative to their own opaque root", () => {
242
+ const one = changesModel([{ path: "a.ts", added: 1, deleted: 0, status: "modified" }]);
243
+ const two = changesModel([{ path: "b.ts", added: 2, deleted: 0, status: "modified" }]);
244
+ const combined = changesModel([
245
+ { path: "/repo/a.ts", added: 1, deleted: 0, status: "modified" },
246
+ { path: "/repo-wt/feature/b.ts", added: 2, deleted: 0, status: "modified" },
247
+ { path: "/elsewhere/c.ts", added: 0, deleted: 0, status: "deleted" },
248
+ ]);
249
+ const snapshot = buildDesktopFeedSnapshot(fixtureInput({ changes: { model: combined, worktrees: [{ root: "/repo", branch: "main", model: one }, { root: "/repo-wt/feature", branch: "feature", model: two }] } }));
250
+ const { changes } = projectDesktopSessionSections(snapshot, ["changes"]) as { changes: DesktopFeedSnapshot["changes"] };
251
+ assert.deepEqual(changes!.files.map((file) => [file.path, (file as unknown as { root: string | null }).root]).sort(), [
252
+ ["a.ts", desktopSessionRootLabel("/repo")],
253
+ ["b.ts", desktopSessionRootLabel("/repo-wt/feature")],
254
+ ["c.ts", null],
255
+ ]);
256
+ assert.deepEqual(changes!.worktrees.map((tree) => tree.root), [desktopSessionRootLabel("/repo"), desktopSessionRootLabel("/repo-wt/feature")]);
257
+ assert.equal(JSON.stringify(changes).includes("/repo"), false);
258
+ assert.equal(JSON.stringify(changes).includes("elsewhere"), false);
259
+ });
260
+
261
+ test("S5: the discovery adapter shape is checked before use", () => {
262
+ assert.equal(isDesktopSessionServiceShape(undefined), false);
263
+ assert.equal(isDesktopSessionServiceShape({ schema: "other", read() {}, observe() {}, dispose() {} }), false);
264
+ assert.equal(isDesktopSessionServiceShape({ schema: "gentle-pi.desktop-session-service/v1", read() {}, observe() {} }), false);
265
+ assert.equal(isDesktopSessionServiceShape({ schema: "gentle-pi.desktop-session-service/v1", read() {}, observe() {}, dispose() {} }), true);
266
+ assert.equal(DESKTOP_SESSION_SERVICE_CHANNEL, "gentle:desktop:session-service");
267
+ });
268
+
269
+ // ---- Through the real extensions ----
270
+
271
+ test("S2: get_snapshot without sections is byte-identical with and without the feed", async (t) => {
272
+ const without = await rpcHarness(t, false);
273
+ const withFeed = await rpcHarness(t, true);
274
+ const legacyWithout = await without.invoke("get_snapshot");
275
+ const legacyWith = await withFeed.invoke("get_snapshot");
276
+ assert.equal(legacyWith.length, 1);
277
+ // `sequence` counts delivered events: with the feed, its start-up flushes may
278
+ // already have published session_snapshot events. Everything else is identical.
279
+ const events = withFeed.lines().filter((line) => JSON.parse(line).kind === "event").length;
280
+ assert.equal(legacyWith[0].data.sequence, events);
281
+ assert.deepEqual(legacyWith, [{ ...legacyWithout[0], data: { ...legacyWithout[0].data, sequence: events } }]);
282
+ assert.equal("session" in legacyWith[0].data.state, false);
283
+ // Unrelated params keep today's behavior too.
284
+ const otherWith = await withFeed.invoke("get_snapshot", { other: true });
285
+ const otherWithout = await without.invoke("get_snapshot", { other: true });
286
+ assert.deepEqual(otherWith, [{ ...otherWithout[0], data: { ...otherWithout[0].data, sequence: events } }]);
287
+ });
288
+
289
+ test("S1/S2/S4/S5: get_snapshot with sections reads the live feed projection; reads emit no event", async (t) => {
290
+ const app = await rpcHarness(t, true);
291
+ const legacy = (await app.invoke("get_snapshot"))[0];
292
+ const out = await app.invoke("get_snapshot", { sections: ["todo", "project", "activity", "changes"] });
293
+ assert.equal(out.length, 1, "a read publishes its response and no event");
294
+ assert.equal(out[0].kind, "response");
295
+ assert.equal(out[0].ok, true);
296
+ const data = out[0].data;
297
+ assert.equal(data.schema, DESKTOP_RPC_SCHEMA);
298
+ assert.equal(data.sequence, legacy.data.sequence);
299
+ assert.deepEqual(data.state.config, legacy.data.state.config, "state.config is unchanged");
300
+ assert.deepEqual(Object.keys(data.state.session), ["project", "todo", "changes", "activity"]);
301
+ assert.deepEqual(data.state.session.project, { name: "gentle-shell", branch: null, dirty: 0 });
302
+ assert.deepEqual(data.state.session.todo, { items: [], progress: { done: 0, total: 0, open: 0 }, current: null, truncated: false });
303
+ assert.equal(data.state.session.activity.state, "idle");
304
+ const wire = JSON.stringify(data.state.session);
305
+ for (const needle of [...ABSOLUTE, "identity", "ancestors"]) assert.equal(wire.includes(needle), false, needle);
306
+
307
+ // Every section can be requested at once.
308
+ const all = await app.invoke("get_snapshot", { sections: [...DESKTOP_SESSION_SECTIONS] });
309
+ assert.deepEqual(Object.keys(all[0].data.state.session), [...DESKTOP_SESSION_SECTIONS]);
310
+ for (const needle of ABSOLUTE) assert.equal(JSON.stringify(all[0].data.state.session).includes(needle), false, needle);
311
+ });
312
+
313
+ test("S2: unknown section names are invalid_request, with or without the feed", async (t) => {
314
+ for (const withFeed of [true, false]) {
315
+ const app = await rpcHarness(t, withFeed);
316
+ const out = await app.invoke("get_snapshot", { sections: ["todo", "identity"] });
317
+ assert.equal(out.length, 1);
318
+ assert.deepEqual(out[0].error, INVALID_SESSION_PARAMS);
319
+ assert.equal(out[0].ok, false);
320
+ }
321
+ });
322
+
323
+ test("S5/S6: without the feed, sections answer session_unavailable and capabilities omit session_snapshot", async (t) => {
324
+ const app = await rpcHarness(t, false);
325
+ const out = await app.invoke("get_snapshot", { sections: ["todo"] });
326
+ assert.equal(out.length, 1);
327
+ assert.deepEqual(out[0].error, SESSION_UNAVAILABLE);
328
+ const capabilities = (await app.invoke("capabilities"))[0].data;
329
+ assert.equal(capabilities.events.includes(DESKTOP_SESSION_EVENT), false);
330
+ assert.deepEqual(capabilities.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update", "review_mode_changed"]);
331
+ assert.deepEqual((await app.invoke("get_snapshot"))[0].data.state, (await app.invoke("get_snapshot", { other: 1 }))[0].data.state);
332
+ });
333
+
334
+ test("S6: with the feed wired, capabilities advertise session_snapshot", async (t) => {
335
+ const app = await rpcHarness(t, true);
336
+ const capabilities = (await app.invoke("capabilities"))[0].data;
337
+ assert.deepEqual(capabilities.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update", "review_mode_changed", DESKTOP_SESSION_EVENT]);
338
+ assert.equal(capabilities.methods.includes("get_snapshot"), true);
339
+ });
340
+
341
+ test("S3: session_snapshot carries only changed sections, on the feed's routine and urgent tiers", async (t) => {
342
+ const app = await rpcHarness(t, true);
343
+ const before = app.lines().length;
344
+
345
+ // Routine change (review sidebar): waits for the routine debounce.
346
+ app.bus.emit(REVIEW_SIDEBAR_EVENT, { sessionId: "sess-1", snapshot: { state: "in_review", scope: "a.ts +1 file" } });
347
+ assert.equal(app.lines().length, before, "nothing is emitted before the feed's tier fires");
348
+ assert.deepEqual(app.clock.delays(), [DESKTOP_FEED_DEBOUNCE_MS]);
349
+ app.clock.run();
350
+ const routine = app.lines().slice(before).map((line) => JSON.parse(line));
351
+ assert.equal(routine.length, 1);
352
+ assert.equal(routine[0].kind, "event");
353
+ assert.equal(routine[0].event, DESKTOP_SESSION_EVENT);
354
+ assert.deepEqual(routine[0].data, { sections: { review: { state: "in_review", label: routine[0].data.sections.review.label, scope: "a.ts +1 file" } } });
355
+
356
+ // The same content again: the feed flushes nothing new, so no event.
357
+ app.bus.emit(REVIEW_SIDEBAR_EVENT, { sessionId: "sess-1", snapshot: { state: "in_review", scope: "a.ts +1 file" } });
358
+ app.clock.run();
359
+ assert.equal(app.lines().length, before + 1, "unchanged content emits no event");
360
+
361
+ // Urgent change (an extension dialog opens): the urgent tier.
362
+ app.fire("ui_prompt_start", { title: "Pick one", kind: "select" }, app.ctx);
363
+ assert.deepEqual(app.clock.delays(), [DESKTOP_FEED_URGENT_MS]);
364
+ app.clock.run();
365
+ const urgent = JSON.parse(app.lines().at(-1)!);
366
+ assert.equal(urgent.event, DESKTOP_SESSION_EVENT);
367
+ assert.deepEqual(Object.keys(urgent.data.sections), ["pendingQuestion"]);
368
+ assert.equal(urgent.data.sections.pendingQuestion.question, "Pick one");
369
+ assert.equal(urgent.seq, routine[0].seq + 1, "events share the router's sequence");
370
+ for (const needle of ABSOLUTE) assert.equal(app.lines().slice(before).join("\n").includes(needle), false, needle);
371
+ });
372
+
373
+ // ---- Bridge lifecycle ----
374
+
375
+ test("S5: the bridge drops a superseded session and answers unavailable when the owner has no live session", async () => {
376
+ let snapshot: DesktopFeedSnapshot | undefined = buildDesktopFeedSnapshot(fixtureInput());
377
+ const observers = new Set<(value: DesktopFeedSnapshot) => void>();
378
+ let disposed = 0;
379
+ const service = {
380
+ schema: "gentle-pi.desktop-session-service/v1" as const,
381
+ read: () => snapshot,
382
+ observe: (fn: (value: DesktopFeedSnapshot) => void) => { observers.add(fn); return () => observers.delete(fn); },
383
+ dispose: () => { disposed += 1; },
384
+ };
385
+ const bridge = new DesktopSessionBridge({} as ExtensionAPI, { discover: async () => service });
386
+ assert.equal(bridge.wired, false);
387
+ assert.equal(bridge.snapshot({}), undefined, "no sections: the router keeps its legacy read");
388
+ assert.deepEqual(await bridge.snapshot({ sections: ["todo"] }), { ok: false, error: SESSION_UNAVAILABLE }, "no bound session yet");
389
+ bridge.attach({ sessionManager: { getSessionId: () => "sess-1" } } as unknown as ExtensionContext);
390
+ const events: Array<Record<string, unknown>> = [];
391
+ bridge.wire((_event, data) => events.push(data));
392
+ await bridge.start();
393
+ assert.equal(bridge.wired, true);
394
+ assert.deepEqual(await bridge.snapshot({ sections: ["todo"] }), { ok: true, data: { todo: snapshot.todo } });
395
+ // An unchanged notification emits nothing; a changed one only its section.
396
+ for (const fn of observers) fn(snapshot);
397
+ assert.equal(events.length, 0);
398
+ const next = buildDesktopFeedSnapshot(fixtureInput({ permission: { mode: "yolo" } }));
399
+ for (const fn of observers) fn(next);
400
+ assert.deepEqual(events, [{ sections: { permission: next.permission } }]);
401
+ // Jobs elapsed time moves every flush and is not a change.
402
+ const later = buildDesktopFeedSnapshot(fixtureInput({ permission: { mode: "yolo" }, now: Date.UTC(2026, 10, 14, 12, 0, 5) }));
403
+ for (const fn of observers) fn(later);
404
+ assert.equal(events.length, 1);
405
+
406
+ snapshot = undefined;
407
+ assert.deepEqual(await bridge.snapshot({ sections: ["todo"] }), { ok: false, error: SESSION_UNAVAILABLE });
408
+ bridge.reset();
409
+ assert.equal(bridge.wired, false);
410
+ assert.equal(disposed, 1);
411
+ assert.equal(observers.size, 0);
412
+ for (const fn of [...observers]) fn(next);
413
+ assert.equal(events.length, 1);
414
+ });
415
+
416
+ test("S2: the router keeps get_snapshot byte-identical when no session reader is supplied", () => {
417
+ const lines: string[] = [];
418
+ const router = new DesktopRpcRouter(undefined, undefined, () => ({ config: { stores: [] } }));
419
+ router.start((line) => lines.push(line));
420
+ router.handle(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId: "a", method: "get_snapshot", params: { sections: ["todo"] } }));
421
+ assert.deepEqual(JSON.parse(lines[0]!).data, { schema: DESKTOP_RPC_SCHEMA, sequence: 0, state: { config: { stores: [] } } });
422
+ });
423
+
424
+ // ---- Path edge cases (verifier correction batch) ----
425
+
426
+ test("S4: a filesystem or drive root cwd has no project name", () => {
427
+ for (const cwd of ["/", "C:\\", "D:/", "c:"]) {
428
+ const snapshot = buildDesktopFeedSnapshot(fixtureInput({ identity: { ...fixtureInput().identity, cwd } }));
429
+ assert.equal((projectDesktopSessionSections(snapshot, ["project"]).project as { name: string | null }).name, null, cwd);
430
+ }
431
+ });
432
+
433
+ test("S4: Windows roots match case- and separator-insensitively; POSIX roots stay case-sensitive", () => {
434
+ const one = changesModel([{ path: "x", added: 1, deleted: 0, status: "modified" }]);
435
+ const combined = changesModel([
436
+ { path: "c:/repo/App/src/x.ts", added: 1, deleted: 0, status: "modified" },
437
+ { path: "C:\\REPO\\app\\lib\\y.ts", added: 1, deleted: 0, status: "modified" },
438
+ { path: "/Srv/Repo/z.ts", added: 1, deleted: 0, status: "modified" },
439
+ { path: "/srv/repo/w.ts", added: 1, deleted: 0, status: "modified" },
440
+ ]);
441
+ const snapshot = buildDesktopFeedSnapshot(fixtureInput({ changes: { model: combined, worktrees: [{ root: "C:\\Repo\\App", branch: "a", model: one }, { root: "/srv/repo", branch: "b", model: one }] } }));
442
+ const { changes } = projectDesktopSessionSections(snapshot, ["changes"]) as { changes: { files: Array<{ path: string; root: string | null }> } };
443
+ const windows = desktopSessionRootLabel("C:\\Repo\\App");
444
+ const posix = desktopSessionRootLabel("/srv/repo");
445
+ assert.deepEqual(changes.files.map((file) => [file.path, file.root]).sort(), [
446
+ ["lib/y.ts", windows],
447
+ ["src/x.ts", windows],
448
+ ["w.ts", posix],
449
+ ["z.ts", null],
450
+ ]);
451
+ });
452
+
453
+ test("S4: a worktree root of / or a bare drive never relativizes paths and has no label", () => {
454
+ for (const root of ["/", "C:\\", "d:/"]) {
455
+ const one = changesModel([{ path: "x", added: 1, deleted: 0, status: "modified" }]);
456
+ const combined = changesModel([
457
+ { path: "/etc/hosts", added: 1, deleted: 0, status: "modified" },
458
+ { path: "C:\\Windows\\win.ini", added: 1, deleted: 0, status: "modified" },
459
+ { path: "etc/relative.ts", added: 1, deleted: 0, status: "modified" },
460
+ ]);
461
+ const snapshot = buildDesktopFeedSnapshot(fixtureInput({ changes: { model: combined, worktrees: [{ root, branch: "b", model: one }] } }));
462
+ const { changes } = projectDesktopSessionSections(snapshot, ["changes"]) as { changes: { files: Array<{ path: string; root: string | null }>; worktrees: Array<{ root: string | null }> } };
463
+ assert.deepEqual(changes.files.map((file) => [file.path, file.root]).sort(), [["hosts", null], ["relative.ts", null], ["win.ini", null]], root);
464
+ assert.deepEqual(changes.worktrees.map((tree) => tree.root), [null], root);
465
+ }
466
+ });
467
+
468
+ // ---- Verifier probes (regression tests) ----
469
+
470
+ const PROBE_WIN_CWD = "C:\\Users\\devel\\My Projects\\gentle-shell";
471
+ function probeInput(overrides: Record<string, unknown> = {}): DesktopFeedInput {
472
+ const model = changesModel([{ path: "lib/a.ts", added: 3, deleted: 1, status: "modified" }]);
473
+ return {
474
+ now: Date.UTC(2026, 10, 14, 12, 0, 0),
475
+ identity: { sessionId: "sess-1", sessionFile: "C:\\Users\\devel\\.pi\\agent\\sessions\\s.jsonl", sessionName: "Feed", cwd: PROBE_WIN_CWD, realCwd: "\\\\?\\C:\\Users\\devel\\My Projects\\gentle-shell", pid: 100, ppid: 99, ancestors: [98, 1], mode: "rpc", agentDir: "C:\\Users\\devel\\.pi\\agent", env: { USERNAME: "devel", HOME: "C:\\Users\\devel" } },
476
+ branch: "feat/x",
477
+ model: { id: "m", provider: "anthropic", reasoning: true },
478
+ thinkingLevel: "high", subscription: true,
479
+ profile: { name: "work", tier: "fast" },
480
+ context: { percent: 42, tokens: 84_000, contextWindow: 200_000 },
481
+ usage: undefined,
482
+ permission: { mode: "normal" },
483
+ todo: { tasks: [{ id: 1, title: "Write tests", status: "in_progress" }], nextId: 2, updatedTurn: 1 },
484
+ changes: { model, worktrees: [{ root: PROBE_WIN_CWD, branch: "feat/x", model }] },
485
+ agents: [],
486
+ jobs: [{ id: "j1", label: "npm test", status: "running", startedAt: Date.UTC(2026, 10, 14, 11, 59, 0) }],
487
+ review: undefined,
488
+ stats: { cost: 1, input: 1, output: 1, cacheRead: 0, cacheWrite: 0, turns: 1, toolCalls: 1, toolErrors: 0, spanMs: 1, cacheHitRate: null, models: [] },
489
+ activity: { working: false, blocked: 0, blockedLabel: undefined, streaming: false, phase: undefined },
490
+ pendingQuestion: undefined,
491
+ ...overrides,
492
+ } as DesktopFeedInput;
493
+ }
494
+ const PROBE_NEEDLES = ["\\devel", "devel\\", "/devel", "Users", "C:", "D:", "\\\\", "server", "My Projects", ".pi", "s.jsonl", "/home", "/srv", "4242", "ancestors", "identity", "agentDir", "realCwd", "sessionFile"];
495
+
496
+ test("S4 probe: Windows/UNC/POSIX/spaces paths in structural fields never reach the wire", () => {
497
+ const roots = [PROBE_WIN_CWD, "D:\\wt\\feature branch", "\\\\server\\share\\repo", "/srv/home/dev/repo"];
498
+ const combined = changesModel([
499
+ { path: `${PROBE_WIN_CWD}\\lib\\a.ts`, added: 1, deleted: 0, status: "modified" },
500
+ { path: "D:/wt/feature branch/b.ts", added: 1, deleted: 0, status: "modified" },
501
+ { path: "\\\\server\\share\\repo\\c.ts", added: 1, deleted: 0, status: "modified" },
502
+ { path: "/srv/home/dev/repo/d.ts", added: 1, deleted: 0, status: "modified" },
503
+ { path: "C:\\Users\\devel\\Desktop\\outside.txt", added: 1, deleted: 0, status: "modified" },
504
+ { path: "c:\\users\\devel\\my projects\\gentle-shell\\casemismatch.ts", added: 1, deleted: 0, status: "modified" },
505
+ ]);
506
+ const one = changesModel([{ path: "x", added: 1, deleted: 0, status: "modified" }]);
507
+ const snap = buildDesktopFeedSnapshot(probeInput({ changes: { model: combined, worktrees: roots.map((root) => ({ root, branch: "b", model: one })) } }));
508
+ const sections = projectDesktopSessionSections(snap, DESKTOP_SESSION_SECTIONS);
509
+ const wire = JSON.stringify(sections);
510
+ for (const needle of PROBE_NEEDLES) assert.equal(wire.includes(needle), false, `${needle} in ${wire}`);
511
+ assert.deepEqual((sections.project as any).name, "gentle-shell");
512
+ const paths = (sections.changes as any).files.map((f: any) => [f.path, f.root]);
513
+ assert.deepEqual(paths.map((p: any) => p[0]).sort(), ["b.ts", "c.ts", "casemismatch.ts", "d.ts", "lib/a.ts", "outside.txt"]);
514
+ });
515
+
516
+ test("S4 probe: project name of a filesystem root", () => {
517
+ for (const [cwd, want] of [["/", null], ["C:\\", null], ["\\\\server\\share\\", "share"]] as const) {
518
+ const snap = buildDesktopFeedSnapshot(probeInput({ identity: { ...probeInput().identity, cwd } }));
519
+ const p = projectDesktopSessionSections(snap, ["project"]).project as any;
520
+ assert.equal(p.name, want, `cwd ${cwd} -> ${JSON.stringify(p.name)}`);
521
+ }
522
+ });
523
+
524
+ function probeService(initial: DesktopFeedSnapshot) {
525
+ let current = initial;
526
+ const observers = new Set<(s: DesktopFeedSnapshot) => void>();
527
+ return {
528
+ set(value: DesktopFeedSnapshot) { current = value; },
529
+ observers,
530
+ service: {
531
+ schema: "gentle-pi.desktop-session-service/v1" as const,
532
+ read: () => current,
533
+ observe: (fn: (s: DesktopFeedSnapshot) => void) => { observers.add(fn); return () => observers.delete(fn); },
534
+ dispose: () => {},
535
+ },
536
+ };
537
+ }
538
+
539
+ test("S3 probe: no event for updatedAt/elapsed-only changes; a late publish captured before reset is dropped", async () => {
540
+ const first = buildDesktopFeedSnapshot(probeInput());
541
+ const fake = probeService(first);
542
+ const bridge = new DesktopSessionBridge({} as ExtensionAPI, { discover: async () => fake.service });
543
+ bridge.attach({} as ExtensionContext);
544
+ const events: any[] = [];
545
+ bridge.wire((name, data) => events.push({ name, data }));
546
+ await bridge.start();
547
+ const captured = [...fake.observers];
548
+ for (const fn of captured) fn(buildDesktopFeedSnapshot(probeInput({ now: Date.UTC(2026, 10, 14, 12, 0, 30) })));
549
+ assert.equal(events.length, 0, "elapsed/updatedAt only");
550
+ const changed = buildDesktopFeedSnapshot(probeInput({ todo: { tasks: [{ id: 1, title: "Write tests", status: "completed" }], nextId: 2, updatedTurn: 2 } }));
551
+ for (const fn of captured) fn(changed);
552
+ assert.deepEqual(events.map((e) => Object.keys(e.data.sections)), [["todo"]]);
553
+ bridge.reset();
554
+ const late = buildDesktopFeedSnapshot(probeInput({ permission: { mode: "yolo" } }));
555
+ for (const fn of captured) fn(late);
556
+ assert.equal(events.length, 1, "late publish after reset dropped");
557
+ // Re-wired session with a fresh emitter: still nothing from the stale observer.
558
+ bridge.attach({} as ExtensionContext);
559
+ bridge.wire((name, data) => events.push({ name, data }));
560
+ for (const fn of captured) fn(late);
561
+ assert.equal(events.length, 1, "stale observer after re-wire dropped");
562
+ });
563
+
564
+ test("S2 probe: invalid sections answer invalid_request before any owner discovery", async () => {
565
+ let discovered = 0;
566
+ const bridge = new DesktopSessionBridge({} as ExtensionAPI, { discover: async () => { discovered += 1; return undefined; } });
567
+ bridge.attach({} as ExtensionContext);
568
+ for (const params of [{ sections: [] }, { sections: ["todo", "todo"] }, { sections: ["bogus"] }, { sections: ["todo"], x: 1 }, { sections: "todo" }, { sections: [null] }, { sections: ["Todo"] }, { sections: ["__proto__"] }, { sections: Array(17).fill("todo") }]) {
569
+ const out = await bridge.snapshot(params as Record<string, unknown>);
570
+ assert.deepEqual(out, { ok: false, error: { code: "invalid_request", message: "Invalid session snapshot sections" } }, JSON.stringify(params));
571
+ }
572
+ assert.equal(discovered, 0);
573
+ });
574
+
575
+ function probeCtx(sessionId = "sess-1") {
576
+ const widgets: any[] = [];
577
+ return {
578
+ cwd: PROBE_WIN_CWD, mode: "rpc", hasUI: true, isIdle: () => true,
579
+ model: { id: "m", provider: "anthropic", reasoning: true, contextWindow: 200_000 },
580
+ modelRegistry: { isUsingOAuth: () => true },
581
+ getContextUsage: () => ({ tokens: 1000, contextWindow: 200_000, percent: 0.5 }),
582
+ ui: { setWidget(key: string, lines: string[]) { widgets.push({ key, lines }); } }, widgets,
583
+ sessionManager: { getSessionId: () => sessionId, getSessionFile: () => "C:\\Users\\devel\\.pi\\agent\\sessions\\s.jsonl", getSessionName: () => undefined, getCwd: () => PROBE_WIN_CWD, getBranch: () => [], getEntries: () => [] },
584
+ };
585
+ }
586
+
587
+ async function probeHarness(t: test.TestContext) {
588
+ interactiveHost(t);
589
+ const h = fakePi();
590
+ desktopRpc(h.pi);
591
+ const agentDir = mkdtempSync(join(tmpdir(), "vprobe-"));
592
+ t.after(() => rmSync(agentDir, { recursive: true, force: true }));
593
+ const c = fakeTimers();
594
+ createDesktopFeedExtension({ env: GENTLE_ENV, agentDir, now: () => Date.UTC(2026, 10, 14, 12, 0, 0), timers: c.timers, git: () => async () => ({ stdout: "", code: 128 }), parentOf: async () => undefined, profile: () => ({ name: "work", tier: "fast" }), realpath: (p) => p, sweep: () => {}, actionWatch: () => () => {}, store: (d, id) => createDesktopFeedStore(d, id) })(h.pi);
595
+ const ctx = probeCtx();
596
+ t.after(() => h.fire("session_shutdown", { reason: "quit" }, ctx));
597
+ h.fire("session_start", { reason: "startup" }, ctx);
598
+ await settle(); c.run(); await settle(); c.run(); await settle();
599
+ const lines = () => ctx.widgets.filter((w: any) => w.key === "gentle-desktop-rpc").map((w: any) => w.lines[0] as string);
600
+ let i = 0;
601
+ return { ...h, ctx, c, lines, async invoke(method: string, params: Record<string, unknown> = {}) { i += 1; const before = lines().length; await h.commands.get("gentle:desktop")!.handler(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId: `r${i}`, method, params }), ctx); return lines().slice(before); } };
602
+ }
603
+
604
+ test("S3 probe: with the feed, every event's seq is contiguous and get_snapshot.sequence equals delivered events; wire has no path", async (t) => {
605
+ const app = await probeHarness(t);
606
+ app.bus.emit(REVIEW_SIDEBAR_EVENT, { sessionId: "sess-1", snapshot: { state: "in_review", scope: "a.ts" } });
607
+ app.c.run();
608
+ await app.invoke("list_jobs");
609
+ app.fire("ui_prompt_start", { title: "Pick C:\\Users\\devel\\x?", kind: "select" }, app.ctx);
610
+ app.c.run();
611
+ app.bus.emit(REVIEW_SIDEBAR_EVENT, { sessionId: "sess-1", snapshot: { state: "closed", scope: "a.ts" } });
612
+ app.c.run();
613
+ const snap = JSON.parse((await app.invoke("get_snapshot"))[0]!);
614
+ const all = app.lines().map((l) => JSON.parse(l));
615
+ const seqs = all.filter((l: any) => l.kind === "event").map((l: any) => l.seq);
616
+ assert.ok(seqs.length >= 3, `events ${seqs}`);
617
+ assert.deepEqual(seqs, seqs.map((_: unknown, i: number) => i + 1));
618
+ assert.equal(snap.data.sequence, seqs.length);
619
+ const full = JSON.parse((await app.invoke("get_snapshot", { sections: [...DESKTOP_SESSION_SECTIONS] }))[0]!);
620
+ const wire = JSON.stringify(full.data.state.session) + all.filter((l: any) => l.event === "session_snapshot").map((l: any) => JSON.stringify(l)).join("");
621
+ // Free text (the prompt title) is shown as written: strip it before checking structural fields.
622
+ const structural = wire.replaceAll("Pick C:\\\\Users\\\\devel\\\\x?", "");
623
+ for (const needle of ["\\devel", "devel\\", "Users", "My Projects", ".pi", "s.jsonl"]) assert.equal(structural.includes(needle), false, needle);
624
+ assert.equal(full.data.state.session.project.name, "gentle-shell");
625
+ });
626
+
627
+ test("S3 probe: session switch disposes the old owner; the new session's events still flow and the old one's do not", async (t) => {
628
+ const app = await probeHarness(t);
629
+ const ctx2 = probeCtx("sess-2"); (ctx2 as any).widgets = app.ctx.widgets; (ctx2 as any).ui = app.ctx.ui;
630
+ app.fire("session_shutdown", { reason: "new" }, app.ctx);
631
+ app.fire("session_start", { reason: "new" }, ctx2);
632
+ await settle(); app.c.run(); await settle(); app.c.run(); await settle();
633
+ const before = app.lines().length;
634
+ app.bus.emit(REVIEW_SIDEBAR_EVENT, { sessionId: "sess-1", snapshot: { state: "in_review", scope: "old.ts" } });
635
+ app.c.run();
636
+ assert.equal(app.lines().slice(before).some((l) => l.includes("old.ts")), false);
637
+ app.bus.emit(REVIEW_SIDEBAR_EVENT, { sessionId: "sess-2", snapshot: { state: "in_review", scope: "new.ts" } });
638
+ app.c.run();
639
+ const after = app.lines().slice(before).map((l) => JSON.parse(l));
640
+ assert.equal(after.filter((l: any) => l.event === "session_snapshot" && JSON.stringify(l).includes("new.ts")).length, 1);
641
+ app.fire("session_shutdown", { reason: "quit" }, ctx2);
642
+ });