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,608 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, renameSync, rmdirSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { test } from "node:test";
7
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
8
+ import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
9
+ import shell, { shellGitRunner } from "../extensions/gentle-shell.ts";
10
+ import { loadFileDiff } from "../lib/change-diff.ts";
11
+ import {
12
+ CHANGE_NOT_FOUND,
13
+ CHANGES_UNAVAILABLE,
14
+ capDesktopDiff,
15
+ DESKTOP_CHANGE_DIFF_MAX_BYTES,
16
+ DESKTOP_CHANGE_ROOT_FALLBACK_LABEL,
17
+ DESKTOP_CHANGES_FILE_LIMIT,
18
+ DESKTOP_CHANGES_METHODS,
19
+ DESKTOP_CHANGES_SERVICE_CHANNEL,
20
+ DESKTOP_CHANGES_SERVICE_SCHEMA,
21
+ desktopChangeRootLabel,
22
+ INVALID_CHANGES_PARAMS,
23
+ isDesktopChangesServiceShape,
24
+ isPlausibleChangePath,
25
+ parseDesktopChangesRead,
26
+ parseGetChangeDiffParams,
27
+ parseGetChangesParams,
28
+ projectDesktopChanges,
29
+ projectDesktopDiff,
30
+ } from "../lib/desktop-rpc-changes.ts";
31
+ import { DesktopChangesBridge } from "../lib/desktop-changes-service.ts";
32
+ import { DESKTOP_RPC_SCHEMA, DESKTOP_RPC_WIDGET } from "../lib/desktop-rpc.ts";
33
+ import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
34
+ import { CHANGE_STATUS, changesModel, DIFF_MAX_BYTES, DIFF_TOO_LARGE, type GitRunner } from "../lib/shell-changes.ts";
35
+
36
+ // #3322: `get_changes` and `get_change_diff` read the `/gentle:changes`
37
+ // owner (the shell's WorktreeChangesTracker and the shared loadFileDiff
38
+ // arguments). A diff is served only for a file in the owner's current change
39
+ // set for that root; everything else is `not_found`.
40
+
41
+ // ---- Pure contract ----
42
+
43
+ test("root labels are the directory name, never an absolute path", () => {
44
+ assert.equal(desktopChangeRootLabel("/home/me/work/project"), "project");
45
+ assert.equal(desktopChangeRootLabel("C:\\Users\\me\\project\\"), "project");
46
+ assert.equal(desktopChangeRootLabel("C:/Users/me/wt-1"), "wt-1");
47
+ assert.equal(desktopChangeRootLabel("/"), DESKTOP_CHANGE_ROOT_FALLBACK_LABEL);
48
+ assert.equal(desktopChangeRootLabel("C:\\"), DESKTOP_CHANGE_ROOT_FALLBACK_LABEL);
49
+ });
50
+
51
+ test("implausible request paths are refused before the owner is asked", () => {
52
+ for (const path of ["file.ts", "lib/a b.ts", "dir/.hidden", "..foo", "a..b/c"]) assert.equal(isPlausibleChangePath(path), true, path);
53
+ for (const path of ["", "../outside", "lib/../../x", "lib\\..\\x", "/etc/passwd", "\\\\server\\share", "C:\\Windows\\win.ini", "c:/x", "a\0b", "a\nb", "x".repeat(4097)]) {
54
+ assert.equal(isPlausibleChangePath(path), false, JSON.stringify(path.slice(0, 40)));
55
+ }
56
+ });
57
+
58
+ test("params parsers accept only the documented shapes", () => {
59
+ assert.deepEqual(parseGetChangesParams({}), { ok: true });
60
+ assert.deepEqual(parseGetChangesParams({ root: "r" }), { error: INVALID_CHANGES_PARAMS });
61
+ assert.deepEqual(parseGetChangeDiffParams({ root: "root-1", path: "a.ts" }), { root: "root-1", path: "a.ts" });
62
+ for (const params of [{}, { root: "r" }, { path: "a" }, { root: 1, path: "a" }, { root: "r", path: ["a"] }, { root: "r", path: "a", extra: true }]) {
63
+ assert.deepEqual(parseGetChangeDiffParams(params as Record<string, unknown>), { error: INVALID_CHANGES_PARAMS }, JSON.stringify(params));
64
+ }
65
+ });
66
+
67
+ test("projectDesktopChanges uses opaque ids, keeps root-relative paths, and caps files at the feed limit", () => {
68
+ const files = Array.from({ length: DESKTOP_CHANGES_FILE_LIMIT + 5 }, (_, index) => ({ path: `f${String(index).padStart(4, "0")}.ts`, added: 1, deleted: 0, status: CHANGE_STATUS.MODIFIED }));
69
+ const read = projectDesktopChanges([
70
+ { root: "/abs/one", branch: "main", model: changesModel(files.slice(0, 3)) },
71
+ { root: "/abs/two", model: changesModel(files.slice(3)) },
72
+ ], (root) => (root === "/abs/one" ? "root-1" : "root-2"));
73
+ assert.deepEqual(read.roots, [{ id: "root-1", label: "one" }, { id: "root-2", label: "two" }]);
74
+ assert.equal(read.files.length, DESKTOP_CHANGES_FILE_LIMIT);
75
+ assert.equal(read.truncated, true);
76
+ assert.deepEqual(read.files[0], { root: "root-1", path: "f0000.ts", status: "modified", added: 1, deleted: 0 });
77
+ assert.equal(read.files[3]!.root, "root-2");
78
+ assert.doesNotMatch(JSON.stringify(read), /\/abs\//);
79
+ assert.equal(projectDesktopChanges([], () => "x").truncated, false);
80
+ });
81
+
82
+ test("capDesktopDiff bounds UTF-8 bytes on a line or character boundary", () => {
83
+ assert.deepEqual(capDesktopDiff("small\n"), { diff: "small\n", truncated: false });
84
+ const lines = "+line\n".repeat(DESKTOP_CHANGE_DIFF_MAX_BYTES);
85
+ const capped = capDesktopDiff(lines);
86
+ assert.equal(capped.truncated, true);
87
+ assert.ok(Buffer.byteLength(capped.diff) <= DESKTOP_CHANGE_DIFF_MAX_BYTES);
88
+ assert.ok(capped.diff.endsWith("\n") && lines.startsWith(capped.diff));
89
+ // One long line of multi-byte characters is cut between characters.
90
+ const wide = capDesktopDiff("é".repeat(10), 5);
91
+ assert.deepEqual(wide, { diff: "éé", truncated: true });
92
+ const exact = "a".repeat(DESKTOP_CHANGE_DIFF_MAX_BYTES);
93
+ assert.deepEqual(capDesktopDiff(exact), { diff: exact, truncated: false });
94
+ });
95
+
96
+ test("projectDesktopDiff answers only for a Git diff that completed or hit its bound", () => {
97
+ assert.deepEqual(projectDesktopDiff({ stdout: "d", code: 0 }), { diff: "d", truncated: false });
98
+ assert.deepEqual(projectDesktopDiff({ stdout: "d", code: 1 }), { diff: "d", truncated: false });
99
+ assert.deepEqual(projectDesktopDiff({ stdout: "partial", code: 1, truncated: true }), { diff: "partial", truncated: true });
100
+ assert.equal(projectDesktopDiff({ stdout: "fatal: bad", code: 128 }), undefined);
101
+ assert.equal(projectDesktopDiff({ stdout: "d", code: 1, timedOut: true }), undefined);
102
+ });
103
+
104
+ test("parseDesktopChangesRead rebuilds the owner answer and refuses leaky shapes", () => {
105
+ const good = { roots: [{ id: "root-1", label: "repo", extra: "/abs" }], files: [{ root: "root-1", path: "a.ts", status: "untracked", added: 2, deleted: 0, cwd: "/abs" }], truncated: false };
106
+ assert.deepEqual(parseDesktopChangesRead(good), { roots: [{ id: "root-1", label: "repo" }], files: [{ root: "root-1", path: "a.ts", status: "untracked", added: 2, deleted: 0 }], truncated: false });
107
+ assert.equal(parseDesktopChangesRead({ ...good, roots: [{ id: "root-1", label: "/home/me/repo" }] }), undefined, "an absolute label never crosses");
108
+ assert.equal(parseDesktopChangesRead({ ...good, files: [{ ...good.files[0], root: "root-9" }] }), undefined);
109
+ assert.equal(parseDesktopChangesRead({ ...good, files: [{ ...good.files[0], path: "/abs/a.ts" }] }), undefined);
110
+ assert.equal(parseDesktopChangesRead({ ...good, files: [{ ...good.files[0], status: "weird" }] }), undefined);
111
+ assert.equal(parseDesktopChangesRead({ ...good, files: [{ ...good.files[0], added: -1 }] }), undefined);
112
+ assert.equal(parseDesktopChangesRead({ ...good, truncated: "no" }), undefined);
113
+ assert.equal(parseDesktopChangesRead(undefined), undefined);
114
+ });
115
+
116
+ test("isDesktopChangesServiceShape accepts only the versioned adapter", () => {
117
+ const ok = { schema: DESKTOP_CHANGES_SERVICE_SCHEMA, read: async () => undefined, diff: async () => ({ kind: "not_found" }), dispose() {} };
118
+ assert.equal(isDesktopChangesServiceShape(ok), true);
119
+ assert.equal(isDesktopChangesServiceShape({ ...ok, schema: "other/v1" }), false);
120
+ assert.equal(isDesktopChangesServiceShape({ ...ok, diff: undefined }), false);
121
+ assert.equal(isDesktopChangesServiceShape(null), false);
122
+ });
123
+
124
+ // ---- Bridge: parse before owner work, typed errors, no raw leaks ----
125
+
126
+ function bridgeWith(service: Record<string, unknown> | undefined) {
127
+ let discoveries = 0;
128
+ const bridge = new DesktopChangesBridge({} as ExtensionAPI, { discover: async () => { discoveries += 1; return service as never; } });
129
+ bridge.attach({} as never);
130
+ return { bridge, discoveries: () => discoveries };
131
+ }
132
+
133
+ test("malformed params and implausible paths never reach the owner", async () => {
134
+ const { bridge, discoveries } = bridgeWith({ schema: DESKTOP_CHANGES_SERVICE_SCHEMA, read: async () => { throw new Error("must not read"); }, diff: async () => { throw new Error("must not diff"); }, dispose() {} });
135
+ assert.deepEqual(await bridge.handle("get_changes", { x: 1 }), { ok: false, error: INVALID_CHANGES_PARAMS });
136
+ assert.deepEqual(await bridge.handle("get_change_diff", { root: "root-1" }), { ok: false, error: INVALID_CHANGES_PARAMS });
137
+ for (const path of ["../secret", "/etc/passwd", "C:\\Windows\\win.ini", "a/../../b"]) {
138
+ assert.deepEqual(await bridge.handle("get_change_diff", { root: "root-1", path }), { ok: false, error: CHANGE_NOT_FOUND }, path);
139
+ }
140
+ assert.deepEqual(await bridge.handle("get_change_diff", { root: "", path: "a.ts" }), { ok: false, error: CHANGE_NOT_FOUND });
141
+ assert.equal(discoveries(), 0, "no owner discovery for a request that can never be served");
142
+ assert.equal(await bridge.handle("list_jobs", {}), undefined, "other methods fall through");
143
+ });
144
+
145
+ test("a missing, throwing, or malformed owner answers changes_unavailable without raw detail", async () => {
146
+ assert.deepEqual(await bridgeWith(undefined).bridge.handle("get_changes", {}), { ok: false, error: CHANGES_UNAVAILABLE });
147
+ const throwing = bridgeWith({ schema: DESKTOP_CHANGES_SERVICE_SCHEMA, read: async () => { throw new Error("git failed in /home/me/secret"); }, diff: async () => { throw new Error("/home/me/secret"); }, dispose() {} }).bridge;
148
+ assert.deepEqual(await throwing.handle("get_changes", {}), { ok: false, error: CHANGES_UNAVAILABLE });
149
+ assert.deepEqual(await throwing.handle("get_change_diff", { root: "root-1", path: "a.ts" }), { ok: false, error: CHANGES_UNAVAILABLE });
150
+ const malformed = bridgeWith({ schema: DESKTOP_CHANGES_SERVICE_SCHEMA, read: async () => ({ roots: [{ id: "r", label: "/home/me/repo" }], files: [], truncated: false }), diff: async () => ({ kind: "ok", diff: 5 }), dispose() {} }).bridge;
151
+ assert.deepEqual(await malformed.handle("get_changes", {}), { ok: false, error: CHANGES_UNAVAILABLE });
152
+ assert.deepEqual(await malformed.handle("get_change_diff", { root: "r", path: "a.ts" }), { ok: false, error: CHANGES_UNAVAILABLE });
153
+ const detached = new DesktopChangesBridge({} as ExtensionAPI, { discover: async () => { throw new Error("unreachable"); } });
154
+ assert.deepEqual(await detached.handle("get_changes", {}), { ok: false, error: CHANGES_UNAVAILABLE }, "no attached session");
155
+ });
156
+
157
+ test("the bridge re-applies the diff bound to an owner answer", async () => {
158
+ const big = "+x\n".repeat(DESKTOP_CHANGE_DIFF_MAX_BYTES);
159
+ const { bridge } = bridgeWith({ schema: DESKTOP_CHANGES_SERVICE_SCHEMA, read: async () => undefined, diff: async () => ({ kind: "ok", diff: big, truncated: false }), dispose() {} });
160
+ const outcome = await bridge.handle("get_change_diff", { root: "root-1", path: "a.ts" }) as { ok: true; data: { diff: string; truncated: boolean } };
161
+ assert.equal(outcome.data.truncated, true);
162
+ assert.ok(Buffer.byteLength(outcome.data.diff) <= DESKTOP_CHANGE_DIFF_MAX_BYTES);
163
+ });
164
+
165
+ test("a reset while the owner works drops the stale answer and disposes the adapter", async () => {
166
+ let release!: () => void;
167
+ let disposed = 0;
168
+ const service = { schema: DESKTOP_CHANGES_SERVICE_SCHEMA, read: () => new Promise((resolve) => { release = () => resolve({ roots: [], files: [], truncated: false }); }), diff: async () => ({ kind: "not_found" }), dispose() { disposed += 1; } };
169
+ const { bridge } = bridgeWith(service);
170
+ const pending = bridge.handle("get_changes", {});
171
+ await new Promise((resolve) => setTimeout(resolve, 5));
172
+ bridge.reset();
173
+ release();
174
+ assert.deepEqual(await pending, { ok: false, error: CHANGES_UNAVAILABLE });
175
+ assert.equal(disposed, 1);
176
+ });
177
+
178
+ // ---- Transport with the real owner: gentle-shell + gentle-desktop-rpc ----
179
+
180
+ function tempRepo(t: test.TestContext) {
181
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "gentle-rpc-changes-")));
182
+ t.after(() => rmSync(root, { recursive: true, force: true }));
183
+ const git = (...args: string[]) => execFileSync("git", ["-C", root, "-c", "user.name=test", "-c", "user.email=test@example.com", "-c", "commit.gpgsign=false", ...args], { encoding: "utf8" });
184
+ git("init", "-q", "--initial-branch=main");
185
+ writeFileSync(join(root, "file.ts"), "base\n");
186
+ writeFileSync(join(root, "clean.ts"), "committed and unchanged\n");
187
+ git("add", "file.ts", "clean.ts");
188
+ git("commit", "-q", "-m", "base");
189
+ return { root, git };
190
+ }
191
+
192
+ type RunnerFor = (cwd: string, maxBuffer?: number) => GitRunner;
193
+ const realGit: RunnerFor = (cwd, maxBuffer) => shellGitRunner(cwd, process.env, undefined, maxBuffer);
194
+
195
+ function app(t: test.TestContext, root: string, options: { gitRunner?: RunnerFor; withOwner?: boolean } = {}) {
196
+ const previous = process.env[INTERACTIVE_HOST_ENV];
197
+ process.env[INTERACTIVE_HOST_ENV] = "1";
198
+ t.after(() => {
199
+ if (previous === undefined) delete process.env[INTERACTIVE_HOST_ENV];
200
+ else process.env[INTERACTIVE_HOST_ENV] = previous;
201
+ });
202
+ const entries: unknown[] = [];
203
+ const handlers = new Map<string, Function[]>();
204
+ const listeners = new Map<string, Function[]>();
205
+ const commands = new Map<string, { handler: (args: string, ctx: unknown) => Promise<void> }>();
206
+ const pi: any = {
207
+ on: (key: string, fn: Function) => handlers.set(key, [...(handlers.get(key) ?? []), fn]),
208
+ events: {
209
+ on: (key: string, fn: Function) => { listeners.set(key, [...(listeners.get(key) ?? []), fn]); return () => {}; },
210
+ emit: (key: string, data: unknown) => listeners.get(key)?.forEach((fn) => fn(data)),
211
+ },
212
+ appendEntry: (customType: string, data: unknown) => entries.push({ type: "custom", customType, data }),
213
+ registerTool() {}, registerShortcut() {}, registerMessageRenderer() {},
214
+ registerCommand: (key: string, registration: any) => commands.set(key, registration),
215
+ };
216
+ let gitCalls = 0;
217
+ if (options.withOwner !== false) {
218
+ const runner = options.gitRunner ?? realGit;
219
+ shell(pi, { GENTLE_PI_SHELL_CHANGES_POLL_MS: "60000", GENTLE_PI_SHELL_CHANGES_WATCH_MS: "off" }, {
220
+ resolveWorktree: () => ({ root, commonDir: join(root, ".git") }),
221
+ devBinary: () => undefined,
222
+ gitRunner: (cwd, maxBuffer) => { const run = runner(cwd, maxBuffer); return (args) => { gitCalls += 1; return run(args); }; },
223
+ });
224
+ }
225
+ desktopRpc(pi as ExtensionAPI);
226
+ const lines: string[] = [];
227
+ const ctx: any = {
228
+ mode: "rpc", hasUI: true, cwd: root,
229
+ sessionManager: { getSessionId: () => "session", getEntries: () => entries },
230
+ ui: {
231
+ setFooter() {}, getEditorComponent: () => ({}), setWorkingVisible() {}, notify() {},
232
+ setWidget: (key: string, value: string[] | undefined) => { if (key === DESKTOP_RPC_WIDGET && value) lines.push(...value); },
233
+ },
234
+ };
235
+ const fire = async (key: string) => { for (const fn of handlers.get(key) ?? []) await fn({}, ctx); };
236
+ let sequence = 0;
237
+ return {
238
+ root, ctx, lines, fire, listeners, gitCalls: () => gitCalls,
239
+ async call(method: string, params: Record<string, unknown> = {}) {
240
+ const before = lines.length;
241
+ await commands.get("gentle:desktop")!.handler(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId: `req-${++sequence}`, method, params }), ctx);
242
+ const published = lines.slice(before).map((line) => JSON.parse(line));
243
+ assert.equal(published.length, 1, `${method} publishes exactly one line: its response, never an event`);
244
+ assert.equal(published[0].kind, "response");
245
+ return published[0] as { ok: boolean; data?: any; error?: { code: string; message: string } };
246
+ },
247
+ };
248
+ }
249
+
250
+ const pathVariants = (root: string) => [root, root.replace(/\\/g, "/"), root.replace(/\\/g, "\\\\")];
251
+
252
+ test("capabilities advertise get_changes and get_change_diff and no changes event", async (t) => {
253
+ const repo = tempRepo(t);
254
+ const a = app(t, repo.root);
255
+ await a.fire("session_start");
256
+ const response = await a.call("capabilities");
257
+ for (const method of DESKTOP_CHANGES_METHODS) assert.ok(response.data.methods.includes(method), method);
258
+ assert.deepEqual(response.data.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update", "review_mode_changed"], "reads advertise no event");
259
+ await a.fire("session_shutdown");
260
+ });
261
+
262
+ test("get_changes lists the owner's change set with opaque roots and root-relative paths", async (t) => {
263
+ const repo = tempRepo(t);
264
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
265
+ mkdirSync(join(repo.root, "lib"));
266
+ writeFileSync(join(repo.root, "lib", "new.ts"), "one\ntwo\n");
267
+ const a = app(t, repo.root);
268
+ await a.fire("session_start");
269
+ const response = await a.call("get_changes");
270
+ assert.equal(response.ok, true);
271
+ assert.equal(response.data.roots.length, 1);
272
+ const [root] = response.data.roots;
273
+ assert.equal(root.label, repo.root.split(/[\\/]/).pop());
274
+ assert.deepEqual(response.data, {
275
+ roots: [{ id: root.id, label: root.label }],
276
+ files: [
277
+ { root: root.id, path: "file.ts", status: "modified", added: 1, deleted: 1 },
278
+ { root: root.id, path: "lib/new.ts", status: "untracked", added: 2, deleted: 0 },
279
+ ],
280
+ truncated: false,
281
+ });
282
+ const wire = JSON.stringify(response);
283
+ for (const variant of pathVariants(repo.root)) assert.ok(!wire.includes(variant), "no absolute root on the wire");
284
+ assert.ok(!wire.includes(tmpdir().replace(/\\/g, "\\\\")) && !wire.includes(tmpdir().replace(/\\/g, "/")), "no temp directory on the wire");
285
+ await a.fire("session_shutdown");
286
+ });
287
+
288
+ test("get_change_diff serves exactly the panel's diff for tracked and untracked files", async (t) => {
289
+ const repo = tempRepo(t);
290
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
291
+ writeFileSync(join(repo.root, "new.ts"), "hello\n");
292
+ const a = app(t, repo.root);
293
+ await a.fire("session_start");
294
+ const listed = await a.call("get_changes");
295
+ const root = listed.data.roots[0].id as string;
296
+ const panelRun = realGit(repo.root, DIFF_MAX_BYTES);
297
+
298
+ const tracked = await a.call("get_change_diff", { root, path: "file.ts" });
299
+ assert.deepEqual(tracked, { schema: DESKTOP_RPC_SCHEMA, kind: "response", requestId: "req-2", ok: true, data: { root, path: "file.ts", diff: await loadFileDiff(panelRun, { path: "file.ts", added: 1, deleted: 1, status: CHANGE_STATUS.MODIFIED }), truncated: false } });
300
+ assert.match(tracked.data.diff, /-base\n\+changed\n/);
301
+
302
+ const untracked = await a.call("get_change_diff", { root, path: "new.ts" });
303
+ assert.equal(untracked.ok, true);
304
+ assert.equal(untracked.data.diff, await loadFileDiff(panelRun, { path: "new.ts", added: 1, deleted: 0, status: CHANGE_STATUS.UNTRACKED }));
305
+ assert.match(untracked.data.diff, /\+hello\n/);
306
+ assert.equal(untracked.data.truncated, false);
307
+ for (const variant of pathVariants(repo.root)) assert.ok(!JSON.stringify(untracked).includes(variant), "nothing beyond the diff text: no absolute path");
308
+ assert.doesNotMatch(JSON.stringify(untracked.data), /git (diff|-C)/, "no Git command on the wire");
309
+ await a.fire("session_shutdown");
310
+ });
311
+
312
+ test("get_change_diff answers not_found for anything outside the owner's change set", async (t) => {
313
+ const repo = tempRepo(t);
314
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
315
+ const outsideDir = realpathSync(mkdtempSync(join(tmpdir(), "gentle-rpc-outside-")));
316
+ t.after(() => rmSync(outsideDir, { recursive: true, force: true }));
317
+ const outside = join(outsideDir, "secret.txt");
318
+ writeFileSync(outside, "TOP-SECRET-OUTSIDE\n");
319
+ const a = app(t, repo.root);
320
+ await a.fire("session_start");
321
+ const listed = await a.call("get_changes");
322
+ const root = listed.data.roots[0].id as string;
323
+ const cases: Array<[string, Record<string, unknown>]> = [
324
+ ["unknown root", { root: "root-99", path: "file.ts" }],
325
+ ["absolute root instead of the id", { root: repo.root, path: "file.ts" }],
326
+ ["label instead of the id", { root: listed.data.roots[0].label, path: "file.ts" }],
327
+ ["exists on disk but is not in the change set", { root, path: "clean.ts" }],
328
+ ["Git metadata", { root, path: ".git/config" }],
329
+ ["does not exist", { root, path: "missing.ts" }],
330
+ ["traversal out of the root", { root, path: `../${outsideDir.split(/[\\/]/).pop()}/secret.txt` }],
331
+ ["traversal back into the set", { root, path: "lib/../file.ts" }],
332
+ ["absolute path outside", { root, path: outside }],
333
+ ["absolute path of a listed file", { root, path: join(repo.root, "file.ts") }],
334
+ ["forward-slash absolute path of a listed file", { root, path: join(repo.root, "file.ts").replace(/\\/g, "/") }],
335
+ ["dot-prefixed alias", { root, path: "./file.ts" }],
336
+ ["backslash alias", { root, path: ".\\file.ts" }],
337
+ ["case variant", { root, path: "FILE.ts" }],
338
+ ["trailing space", { root, path: "file.ts " }],
339
+ ];
340
+ for (const [name, params] of cases) {
341
+ const response = await a.call("get_change_diff", params);
342
+ assert.equal(response.ok, false, name);
343
+ assert.deepEqual(response.error, CHANGE_NOT_FOUND, name);
344
+ assert.ok(!JSON.stringify(response).includes("TOP-SECRET"), name);
345
+ }
346
+ await a.fire("session_shutdown");
347
+ });
348
+
349
+ test("a link in the worktree never serves the content outside the root it points at", async (t) => {
350
+ const repo = tempRepo(t);
351
+ const outsideDir = realpathSync(mkdtempSync(join(tmpdir(), "gentle-rpc-link-")));
352
+ t.after(() => rmSync(outsideDir, { recursive: true, force: true }));
353
+ writeFileSync(join(outsideDir, "secret.txt"), "TOP-SECRET-LINKED\n");
354
+ // A directory link is a junction on Windows (no privilege needed); a file
355
+ // symlink may be refused there without Developer Mode.
356
+ try {
357
+ symlinkSync(outsideDir, join(repo.root, "linkdir"), process.platform === "win32" ? "junction" : "dir");
358
+ } catch (error) {
359
+ t.skip(`directory links unavailable here: ${(error as NodeJS.ErrnoException).code}`);
360
+ return;
361
+ }
362
+ try { symlinkSync(join(outsideDir, "secret.txt"), join(repo.root, "link.txt"), "file"); } catch { /* file symlinks need privilege on Windows */ }
363
+ const a = app(t, repo.root);
364
+ await a.fire("session_start");
365
+ const listed = await a.call("get_changes");
366
+ const root = listed.data.roots[0].id as string;
367
+ const paths = listed.data.files.map((file: { path: string }) => file.path);
368
+ // Git for Windows lists files behind a junction as untracked files of the
369
+ // tree, so the change set itself can name them; the diff must still refuse.
370
+ if (process.platform === "win32") assert.ok(paths.includes("linkdir/secret.txt"), "the junction case is exercised here");
371
+ for (const path of ["linkdir/secret.txt", "link.txt/../linkdir/secret.txt", "linkdir/../file.ts"]) {
372
+ const response = await a.call("get_change_diff", { root, path });
373
+ assert.deepEqual(response.error, CHANGE_NOT_FOUND, path);
374
+ }
375
+ if (paths.includes("link.txt")) {
376
+ const response = await a.call("get_change_diff", { root, path: "link.txt" });
377
+ assert.ok(!JSON.stringify(response).includes("TOP-SECRET"), "a symlink diff is the link, never its target's content");
378
+ }
379
+ await a.fire("session_shutdown");
380
+ });
381
+
382
+ test("a diff past 256 KiB is cut with truncated, and one past the panel bound still answers its head", async (t) => {
383
+ const repo = tempRepo(t);
384
+ writeFileSync(join(repo.root, "medium.txt"), "+medium line of text\n".repeat(16_000));
385
+ writeFileSync(join(repo.root, "huge.txt"), "huge line of text that repeats\n".repeat(40_000));
386
+ const a = app(t, repo.root);
387
+ await a.fire("session_start");
388
+ const root = (await a.call("get_changes")).data.roots[0].id as string;
389
+ const panelRun = realGit(repo.root, DIFF_MAX_BYTES);
390
+
391
+ const medium = await a.call("get_change_diff", { root, path: "medium.txt" });
392
+ const panelMedium = await loadFileDiff(panelRun, { path: "medium.txt", added: 16_000, deleted: 0, status: CHANGE_STATUS.UNTRACKED });
393
+ assert.ok(Buffer.byteLength(panelMedium) > DESKTOP_CHANGE_DIFF_MAX_BYTES, "fixture is past the Desktop bound but within the panel's");
394
+ assert.equal(medium.data.truncated, true);
395
+ assert.ok(Buffer.byteLength(medium.data.diff) <= DESKTOP_CHANGE_DIFF_MAX_BYTES);
396
+ assert.ok(panelMedium.startsWith(medium.data.diff), "the cut diff is the head of the panel's diff");
397
+
398
+ const huge = await a.call("get_change_diff", { root, path: "huge.txt" });
399
+ assert.equal(await loadFileDiff(panelRun, { path: "huge.txt", added: 40_000, deleted: 0, status: CHANGE_STATUS.UNTRACKED }), DIFF_TOO_LARGE, "the panel shows its notice");
400
+ assert.equal(huge.data.truncated, true);
401
+ assert.ok(Buffer.byteLength(huge.data.diff) <= DESKTOP_CHANGE_DIFF_MAX_BYTES);
402
+ assert.match(huge.data.diff, /^diff --git/);
403
+ await a.fire("session_shutdown");
404
+ });
405
+
406
+ test("a clean repository is an empty success, not changes_unavailable", async (t) => {
407
+ const repo = tempRepo(t);
408
+ const a = app(t, repo.root);
409
+ await a.fire("session_start");
410
+ const response = await a.call("get_changes");
411
+ assert.equal(response.ok, true);
412
+ assert.deepEqual(response.data, { roots: [], files: [], truncated: false });
413
+ assert.deepEqual((await a.call("get_change_diff", { root: "root-1", path: "file.ts" })).error, CHANGE_NOT_FOUND);
414
+ await a.fire("session_shutdown");
415
+ });
416
+
417
+ test("get_changes caps files at the feed limit with truncated", async (t) => {
418
+ const repo = tempRepo(t);
419
+ for (let index = 0; index < DESKTOP_CHANGES_FILE_LIMIT + 3; index += 1) writeFileSync(join(repo.root, `n${String(index).padStart(3, "0")}.txt`), "x\n");
420
+ const a = app(t, repo.root);
421
+ await a.fire("session_start");
422
+ const response = await a.call("get_changes");
423
+ assert.equal(response.data.files.length, DESKTOP_CHANGES_FILE_LIMIT);
424
+ assert.equal(response.data.truncated, true);
425
+ await a.fire("session_shutdown");
426
+ });
427
+
428
+ test("changes_unavailable when there is no owner, no worktree, or Git fails", async (t) => {
429
+ const repo = tempRepo(t);
430
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
431
+
432
+ const ownerless = app(t, repo.root, { withOwner: false });
433
+ await ownerless.fire("session_start");
434
+ assert.deepEqual((await ownerless.call("get_changes")).error, CHANGES_UNAVAILABLE);
435
+ assert.deepEqual((await ownerless.call("get_change_diff", { root: "root-1", path: "file.ts" })).error, CHANGES_UNAVAILABLE);
436
+
437
+ const statusFails = app(t, repo.root, { gitRunner: (cwd, max) => { const run = realGit(cwd, max); return async (args) => args[0] === "status" ? { stdout: "fatal: /secret/path", code: 128 } : run(args); } });
438
+ await statusFails.fire("session_start");
439
+ const failed = await statusFails.call("get_changes");
440
+ assert.deepEqual(failed.error, CHANGES_UNAVAILABLE);
441
+ assert.ok(!JSON.stringify(failed).includes("/secret/path"));
442
+ await statusFails.fire("session_shutdown");
443
+
444
+ const diffFails = app(t, repo.root, { gitRunner: (cwd, max) => { const run = realGit(cwd, max); return async (args) => args.includes("diff") && !args.includes("--numstat") ? { stdout: "fatal: /secret/path", code: 128 } : run(args); } });
445
+ await diffFails.fire("session_start");
446
+ const root = (await diffFails.call("get_changes")).data.roots[0].id as string;
447
+ const diffFailed = await diffFails.call("get_change_diff", { root, path: "file.ts" });
448
+ assert.deepEqual(diffFailed.error, CHANGES_UNAVAILABLE);
449
+ assert.ok(!JSON.stringify(diffFailed).includes("/secret/path"));
450
+ await diffFails.fire("session_shutdown");
451
+
452
+ const nonRepo = realpathSync(mkdtempSync(join(tmpdir(), "gentle-rpc-norepo-")));
453
+ t.after(() => rmSync(nonRepo, { recursive: true, force: true }));
454
+ const noWorktree = app(t, nonRepo, { gitRunner: () => async () => ({ stdout: "", code: 128 }) });
455
+ await noWorktree.fire("session_start");
456
+ assert.deepEqual((await noWorktree.call("get_changes")).error, CHANGES_UNAVAILABLE);
457
+ await noWorktree.fire("session_shutdown");
458
+ });
459
+
460
+ test("invalid params are typed invalid_request through the transport, before any Git work", async (t) => {
461
+ const repo = tempRepo(t);
462
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
463
+ const a = app(t, repo.root);
464
+ await a.fire("session_start");
465
+ const before = a.gitCalls();
466
+ assert.deepEqual((await a.call("get_changes", { all: true })).error, INVALID_CHANGES_PARAMS);
467
+ assert.deepEqual((await a.call("get_change_diff", { root: "root-1" })).error, INVALID_CHANGES_PARAMS);
468
+ assert.deepEqual((await a.call("get_change_diff", { root: "root-1", path: 7 })).error, INVALID_CHANGES_PARAMS);
469
+ assert.deepEqual((await a.call("get_change_diff", { root: "root-1", path: "../x" })).error, CHANGE_NOT_FOUND);
470
+ assert.equal(a.gitCalls(), before, "a refused request runs no Git");
471
+ await a.fire("session_shutdown");
472
+ });
473
+
474
+ test("the owner answers discovery only for its own live session", async (t) => {
475
+ const repo = tempRepo(t);
476
+ const a = app(t, repo.root);
477
+ await a.fire("session_start");
478
+ assert.equal(a.listeners.get(DESKTOP_CHANGES_SERVICE_CHANNEL)?.length, 1, "one owner listens");
479
+ const answers: unknown[] = [];
480
+ const foreign = { ...a.ctx, sessionManager: { getSessionId: () => "other-session", getEntries: () => [] } };
481
+ a.listeners.get(DESKTOP_CHANGES_SERVICE_CHANNEL)![0]!({ context: foreign, respond: (service: unknown) => answers.push(service) });
482
+ assert.equal(answers.length, 0, "a different session is never answered");
483
+ await a.fire("session_shutdown");
484
+ a.listeners.get(DESKTOP_CHANGES_SERVICE_CHANNEL)![0]!({ context: a.ctx, respond: (service: unknown) => answers.push(service) });
485
+ assert.equal(answers.length, 0, "a shut-down session is never answered");
486
+ });
487
+
488
+ // ---- Hardening: repository-configured drivers, the git dir, and verifier probes ----
489
+
490
+ const linkDir = (target: string, path: string) => symlinkSync(target, path, process.platform === "win32" ? "junction" : "dir");
491
+ const unlinkDirs = (paths: string[]) => { for (const path of paths) { try { rmdirSync(path); } catch { /* already gone */ } } };
492
+
493
+ function scratchDir(t: test.TestContext, prefix: string) {
494
+ const dir = realpathSync(mkdtempSync(join(tmpdir(), prefix)));
495
+ t.after(() => rmSync(dir, { recursive: true, force: true }));
496
+ return dir;
497
+ }
498
+
499
+ test("get_change_diff never runs a repository textconv driver; the panel path is unchanged", async (t) => {
500
+ const repo = tempRepo(t);
501
+ const scratch = scratchDir(t, "gentle-rpc-driver-");
502
+ const marker = join(scratch, "marker.txt");
503
+ const script = join(scratch, "driver.sh");
504
+ const posix = (path: string) => path.split("\\").join("/");
505
+ writeFileSync(script, `#!/bin/sh\necho ran >> '${posix(marker)}'\ncat "$1"\n`);
506
+ writeFileSync(join(repo.root, ".gitattributes"), "*.txt diff=evil\n");
507
+ writeFileSync(join(repo.root, "a.txt"), "one\n");
508
+ repo.git("add", ".gitattributes", "a.txt");
509
+ repo.git("commit", "-q", "-m", "attr");
510
+ repo.git("config", "diff.evil.textconv", `sh '${posix(script)}'`);
511
+ writeFileSync(join(repo.root, "a.txt"), "two\n");
512
+ const runs = () => (existsSync(marker) ? readFileSync(marker, "utf8").split("\n").filter(Boolean).length : 0);
513
+ const a = app(t, repo.root);
514
+ await a.fire("session_start");
515
+ const root = (await a.call("get_changes")).data.roots[0].id as string;
516
+ const diff = await a.call("get_change_diff", { root, path: "a.txt" });
517
+ assert.equal(diff.ok, true);
518
+ assert.match(diff.data.diff, /-one\n\+two\n/);
519
+ assert.equal(runs(), 0, "the RPC diff never executes the repository's textconv command");
520
+ await a.fire("session_shutdown");
521
+ await loadFileDiff(realGit(repo.root, DIFF_MAX_BYTES), { path: "a.txt", added: 1, deleted: 1, status: CHANGE_STATUS.MODIFIED });
522
+ assert.ok(runs() > 0, "the panel's default call is exactly as before (it still honors the driver)");
523
+ });
524
+
525
+ test("a junction to the git dir inside the root is never served", async (t) => {
526
+ const repo = tempRepo(t);
527
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
528
+ try {
529
+ linkDir(join(repo.root, ".git"), join(repo.root, "g"));
530
+ } catch (error) {
531
+ t.skip(`directory links unavailable here: ${(error as NodeJS.ErrnoException).code}`);
532
+ return;
533
+ }
534
+ t.after(() => unlinkDirs([join(repo.root, "g")]));
535
+ const a = app(t, repo.root);
536
+ await a.fire("session_start");
537
+ const listed = await a.call("get_changes");
538
+ const root = listed.data.roots[0].id as string;
539
+ const paths = listed.data.files.map((file: { path: string }) => file.path);
540
+ if (process.platform === "win32") assert.ok(paths.includes("g/config"), "Git lists the aliased git dir: the case is exercised");
541
+ for (const path of ["g/config", "g/HEAD", "g/refs/heads/main"]) {
542
+ const response = await a.call("get_change_diff", { root, path });
543
+ assert.deepEqual(response.error, CHANGE_NOT_FOUND, path);
544
+ }
545
+ assert.equal((await a.call("get_change_diff", { root, path: "file.ts" })).ok, true, "ordinary files still answer");
546
+ await a.fire("session_shutdown");
547
+ });
548
+
549
+ test("P1: odd Windows and URL path forms are not_found and leak nothing", async (t) => {
550
+ const repo = tempRepo(t);
551
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
552
+ const a = app(t, repo.root);
553
+ await a.fire("session_start");
554
+ const root = (await a.call("get_changes")).data.roots[0].id as string;
555
+ for (const path of ["file.ts.", "file.ts::$DATA", "file.ts:x", "FILE~1.TS", "file%2Ets", "file.ts\0", "\\\\?\\" + join(repo.root, "file.ts"), "//?/C:/x", "\\\\localhost\\c$\\x", "x/".repeat(3000) + "file.ts", "file.ts/", "File.ts", "./file.ts"]) {
556
+ const response = await a.call("get_change_diff", { root, path });
557
+ assert.deepEqual(response.error, CHANGE_NOT_FOUND, JSON.stringify(path.slice(0, 30)));
558
+ for (const variant of pathVariants(repo.root)) assert.ok(!JSON.stringify(response).includes(variant));
559
+ }
560
+ await a.fire("session_shutdown");
561
+ });
562
+
563
+ test("P2: a root id from a previous session is not_found", async (t) => {
564
+ const repo = tempRepo(t);
565
+ writeFileSync(join(repo.root, "file.ts"), "changed\n");
566
+ const a = app(t, repo.root);
567
+ await a.fire("session_start");
568
+ const root = (await a.call("get_changes")).data.roots[0].id as string;
569
+ await a.fire("session_shutdown");
570
+ await a.fire("session_start");
571
+ assert.deepEqual((await a.call("get_change_diff", { root, path: "file.ts" })).error, CHANGE_NOT_FOUND);
572
+ await a.fire("session_shutdown");
573
+ });
574
+
575
+ test("P3: a directory swapped to a junction after listing is refused, nested links too", async (t) => {
576
+ const repo = tempRepo(t);
577
+ const outside = scratchDir(t, "gentle-rpc-swap-");
578
+ writeFileSync(join(outside, "secret.txt"), "TOP-SECRET-SWAP\n");
579
+ const moved = scratchDir(t, "gentle-rpc-moved-");
580
+ mkdirSync(join(repo.root, "sub"));
581
+ writeFileSync(join(repo.root, "sub", "secret.txt"), "inside\n");
582
+ mkdirSync(join(repo.root, "u"));
583
+ writeFileSync(join(repo.root, "u", "secret.txt"), "inside-untracked\n");
584
+ repo.git("add", "sub");
585
+ repo.git("commit", "-q", "-m", "sub");
586
+ writeFileSync(join(repo.root, "sub", "secret.txt"), "inside changed\n");
587
+ const a = app(t, repo.root);
588
+ await a.fire("session_start");
589
+ const root = (await a.call("get_changes")).data.roots[0].id as string;
590
+ renameSync(join(repo.root, "sub"), join(moved, "sub"));
591
+ renameSync(join(repo.root, "u"), join(moved, "u"));
592
+ try {
593
+ linkDir(outside, join(repo.root, "sub"));
594
+ linkDir(outside, join(repo.root, "u"));
595
+ } catch (error) {
596
+ t.skip(`directory links unavailable here: ${(error as NodeJS.ErrnoException).code}`);
597
+ return;
598
+ }
599
+ mkdirSync(join(repo.root, "a", "b"), { recursive: true });
600
+ linkDir(outside, join(repo.root, "a", "b", "j"));
601
+ t.after(() => unlinkDirs([join(repo.root, "sub"), join(repo.root, "u"), join(repo.root, "a", "b", "j")]));
602
+ for (const path of ["sub/secret.txt", "u/secret.txt", "a/b/j/secret.txt"]) {
603
+ const response = await a.call("get_change_diff", { root, path });
604
+ assert.ok(!JSON.stringify(response).includes("TOP-SECRET"), path);
605
+ assert.equal(response.ok, false, path);
606
+ }
607
+ await a.fire("session_shutdown");
608
+ });