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
@@ -6,10 +6,11 @@ import { test } from "node:test";
6
6
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
7
  import desktopRpc from "../extensions/gentle-desktop-rpc.ts";
8
8
  import gentleAgents, { type SessionTransportFactory } from "../extensions/gentle-agents.ts";
9
- import { isFinished, TASK_STATUS, TaskStore, type ChildResponseObservation, type ChildTokenMeasurement, type TaskRecord } from "../lib/agents-protocol.ts";
9
+ import { isFinished, TASK_EVENT, TASK_STATUS, TaskStore, type ChildResponseObservation, type ChildTokenMeasurement, type TaskRecord } from "../lib/agents-protocol.ts";
10
10
  import { historyDir, loadStoredTask, saveTask } from "../lib/agents-history.ts";
11
11
  import { AgentRunner } from "../lib/agents-runner.ts";
12
12
  import { fakeChild } from "./agents-fake-child.ts";
13
+ import { DEFAULT_MAX_BYTES, projectRpcActivity } from "../lib/agents-rpc-publisher.ts";
13
14
  import {
14
15
  AGENT_NOT_FOUND,
15
16
  AGENTS_UNAVAILABLE,
@@ -24,15 +25,21 @@ import {
24
25
  isDesktopAgentsServiceShape,
25
26
  parseCancelSubagentParams,
26
27
  parseDesktopAgentEntry,
28
+ parseDesktopAgentThread,
29
+ parseGetSubagentThreadParams,
27
30
  parseListSubagentsParams,
28
31
  projectDesktopAgent,
32
+ projectDesktopAgentThread,
29
33
  selectDesktopAgents,
30
34
  type DesktopAgentEntry,
31
35
  type DesktopAgentsCancelOutcome,
32
36
  type DesktopAgentsOwnerRead,
33
37
  type DesktopAgentsService,
38
+ type DesktopAgentsThreadOutcome,
39
+ type DesktopAgentThread,
34
40
  } from "../lib/desktop-rpc-agents.ts";
35
41
  import { DesktopAgentsBridge, discoverDesktopAgentsService } from "../lib/desktop-agents-service.ts";
42
+ import * as probeAgents from "../lib/desktop-rpc-agents.ts";
36
43
  import { DESKTOP_RPC_SCHEMA, DesktopRpcRouter, type DesktopRpcDomain } from "../lib/desktop-rpc.ts";
37
44
  import { INTERACTIVE_HOST_ENV } from "../lib/rpc-host.ts";
38
45
 
@@ -130,6 +137,12 @@ function makeAgentsOwnerService(store: TaskStore, runner: FakeRunner, sessionId
130
137
  const changed = requested && after.status !== before.status;
131
138
  return { kind: "ok", agent: projectDesktopAgent(after), requested, changed };
132
139
  },
140
+ thread: (id: string): DesktopAgentsThreadOutcome => {
141
+ if (disposed) return { kind: "not_found" };
142
+ const owned = store.get(id);
143
+ if (!owned || owned.parentSessionId !== sessionId) return { kind: "not_found" };
144
+ return { kind: "ok", thread: projectDesktopAgentThread(id, store.thread(id)) };
145
+ },
133
146
  observe: (onChange) => { observers.add(onChange); return () => observers.delete(onChange); },
134
147
  dispose: () => { disposed = true; observers.clear(); },
135
148
  };
@@ -615,6 +628,201 @@ test("the router publishes a changed cancel response before its agents_update ev
615
628
  assert.equal(JSON.parse(lines[1]!).event, DESKTOP_AGENTS_EVENT);
616
629
  });
617
630
 
631
+ // ---- get_subagent_thread ----
632
+
633
+ type ThreadData = { ok: true; data: DesktopAgentThread };
634
+
635
+ /** A store whose task t1 (session-a) has more items than the window, evicted items, and oversize fields. */
636
+ function threadStore(maxItems = 60) {
637
+ const store = new TaskStore({ maxItems });
638
+ store.add(task("t1", "session-a"));
639
+ store.add(task("theirs", "session-b"));
640
+ store.apply("theirs", { type: TASK_EVENT.NOTE, text: "foreign session note" }, 1001);
641
+ for (let index = 0; index < 70; index += 1) {
642
+ store.apply("t1", { type: TASK_EVENT.NOTE, text: `note ${index}` }, 1001);
643
+ store.apply("t1", { type: TASK_EVENT.TOOL_START, callId: `c${index}`, name: "bash", args: { command: "x".repeat(900) } }, 1001);
644
+ store.apply("t1", { type: TASK_EVENT.TOOL_END, callId: `c${index}`, output: "y".repeat(900), isError: index % 2 === 0 }, 1001);
645
+ }
646
+ store.apply("t1", { type: TASK_EVENT.TEXT, text: "z".repeat(5000) }, 1002);
647
+ return store;
648
+ }
649
+
650
+ test("parseGetSubagentThreadParams accepts only { id, sinceVersion? }", () => {
651
+ assert.deepEqual(parseGetSubagentThreadParams({ id: "t1" }), { id: "t1" });
652
+ assert.deepEqual(parseGetSubagentThreadParams({ id: "t1", sinceVersion: 0 }), { id: "t1", sinceVersion: 0 });
653
+ assert.deepEqual(parseGetSubagentThreadParams({ id: "t1", sinceVersion: 12 }), { id: "t1", sinceVersion: 12 });
654
+ for (const params of [{}, { id: "" }, { id: 1 }, { id: "t1", extra: true }, { task_id: "t1" }, { id: "t1", sinceVersion: -1 }, { id: "t1", sinceVersion: 1.5 }, { id: "t1", sinceVersion: "3" }, { id: "t1", sinceVersion: null }, { id: "t1", sinceVersion: Number.NaN }]) {
655
+ assert.deepEqual(parseGetSubagentThreadParams(params), { error: INVALID_AGENTS_PARAMS }, JSON.stringify(params));
656
+ }
657
+ });
658
+
659
+ test("projectDesktopAgentThread is the widget's exact thread projection and bounds", () => {
660
+ const store = threadStore();
661
+ const widget = projectRpcActivity(store, { parentSessionId: "session-a" }).tasks.find((entry) => entry.summary.id === "t1")!.thread;
662
+ const thread = projectDesktopAgentThread("t1", store.thread("t1"));
663
+ assert.equal(thread.id, "t1");
664
+ assert.deepEqual({ version: thread.version, dropped: thread.dropped, items: thread.items }, widget, "the method and gentle-agents.activity/v1 never disagree");
665
+ assert.equal(thread.items.length, 40, "the widget's 40-item window");
666
+ assert.equal(thread.version, store.thread("t1").version);
667
+ assert.equal(thread.dropped, store.thread("t1").dropped);
668
+ assert.ok(thread.dropped > 0, "the store evicted items beyond its own maxItems");
669
+ assert.equal(thread.truncated, true, "the store holds more items than the window");
670
+ const text = thread.items.at(-1)!;
671
+ assert.equal(text.kind, "text");
672
+ assert.equal((text as { text: string }).text.length, 2000, "text items keep the 2000-char bound");
673
+ const tool = thread.items.find((item) => item.kind === "tool") as { args: string; output: string; callId?: unknown };
674
+ assert.equal(tool.args.length, 500, "tool args keep the 500-char bound");
675
+ assert.equal(tool.output.length, 500, "tool output keeps the 500-char bound");
676
+ assert.equal(tool.callId, undefined, "the raw callId is not whitelisted");
677
+ });
678
+
679
+ test("projectDesktopAgentThread reports truncated only when the window cut items", () => {
680
+ const store = new TaskStore();
681
+ store.add(task("t1", "session-a"));
682
+ store.apply("t1", { type: TASK_EVENT.NOTE, text: "one" }, 1001);
683
+ const thread = projectDesktopAgentThread("t1", store.thread("t1"));
684
+ assert.deepEqual(thread, { id: "t1", version: 1, items: [{ kind: "note", text: "one" }], dropped: 0, truncated: false });
685
+ });
686
+
687
+ test("projectDesktopAgentThread halves items under the activity byte bound", () => {
688
+ const store = new TaskStore();
689
+ store.add(task("t1", "session-a"));
690
+ for (let index = 0; index < 40; index += 1) store.apply("t1", { type: TASK_EVENT.NOTE, text: `${"n".repeat(1990)}${index}` }, 1001);
691
+ assert.equal(projectDesktopAgentThread("t1", store.thread("t1")).items.length, 40, "under the default 256 KB bound the whole window fits");
692
+ assert.equal(DEFAULT_MAX_BYTES, 256 * 1024);
693
+ const maxBytes = 9000;
694
+ const thread = projectDesktopAgentThread("t1", store.thread("t1"), maxBytes);
695
+ assert.ok(Buffer.byteLength(JSON.stringify({ version: thread.version, dropped: thread.dropped, items: thread.items })) <= maxBytes);
696
+ assert.equal(thread.items.length, 2, "40 → 20 → 10 → 5 → 2, the activity encoder's halving");
697
+ assert.equal(thread.truncated, true);
698
+ assert.deepEqual(thread.items.map((item) => (item as { text: string }).text.slice(1990)), ["38", "39"], "the most recent items are kept");
699
+ });
700
+
701
+ test("parseDesktopAgentThread re-validates the owner thread and drops foreign fields", () => {
702
+ const valid = { id: "t1", version: 3, dropped: 0, truncated: false, items: [{ kind: "text", text: "hi" }, { kind: "tool", name: "bash", args: "{}", running: false, isError: false, output: "ok" }] };
703
+ assert.deepEqual(parseDesktopAgentThread({ ...valid, cwd: "/secret", items: [{ kind: "text", text: "hi", raw: "x" }, { kind: "tool", name: "bash", args: "{}", running: false, isError: false, output: "ok", callId: "c1" }] }), valid);
704
+ for (const bad of [
705
+ null,
706
+ { ...valid, id: "" },
707
+ { ...valid, version: -1 },
708
+ { ...valid, dropped: 1.5 },
709
+ { ...valid, truncated: "no" },
710
+ { ...valid, items: "nope" },
711
+ { ...valid, items: [{ kind: "image", text: "x" }] },
712
+ { ...valid, items: [{ kind: "text", text: "x".repeat(2001) }] },
713
+ { ...valid, items: [{ kind: "tool", name: "bash", args: "x".repeat(501), running: false, isError: false, output: "" }] },
714
+ { ...valid, items: [{ kind: "tool", name: "bash", args: "{}", running: false, isError: false, output: "x".repeat(501) }] },
715
+ { ...valid, items: [{ kind: "tool", name: "bash", args: "{}", running: "no", isError: false, output: "" }] },
716
+ ]) {
717
+ assert.equal(parseDesktopAgentThread(bad), undefined, JSON.stringify(bad).slice(0, 120));
718
+ }
719
+ });
720
+
721
+ test("get_subagent_thread answers the owned thread and emits nothing", async () => {
722
+ const store = threadStore();
723
+ const { service } = makeAgentsOwnerService(store, makeRunner(store));
724
+ const { bridge, events, scheduler } = makeBridge(service);
725
+ const outcome = await bridge.handle("get_subagent_thread", { id: "t1" });
726
+ assert.equal(outcome.ok, true);
727
+ assert.deepEqual((outcome as unknown as ThreadData).data, projectDesktopAgentThread("t1", store.thread("t1")));
728
+ assert.deepEqual(Object.keys((outcome as unknown as ThreadData).data).sort(), ["dropped", "id", "items", "truncated", "version"]);
729
+ assert.equal((outcome as { event?: unknown }).event, undefined, "a read carries no event");
730
+ assert.equal(events.length, 0, "a read emits nothing");
731
+ assert.equal(scheduler.pendingCount(), 0, "a read schedules nothing");
732
+ assert.equal(store.get("t1")!.status, TASK_STATUS.RUNNING, "a read changes nothing");
733
+ });
734
+
735
+ test("get_subagent_thread sinceVersion returns no items when unchanged and the window after a change", async () => {
736
+ const store = new TaskStore();
737
+ store.add(task("t1", "session-a"));
738
+ store.apply("t1", { type: TASK_EVENT.NOTE, text: "first" }, 1001);
739
+ const { service } = makeAgentsOwnerService(store, makeRunner(store));
740
+ const { bridge, events } = makeBridge(service);
741
+ const first = (await bridge.handle("get_subagent_thread", { id: "t1" })) as unknown as ThreadData;
742
+ assert.deepEqual(first.data, { id: "t1", version: 1, items: [{ kind: "note", text: "first" }], dropped: 0, truncated: false });
743
+
744
+ const unchanged = (await bridge.handle("get_subagent_thread", { id: "t1", sinceVersion: first.data.version })) as unknown as ThreadData;
745
+ assert.deepEqual(unchanged.data, { id: "t1", version: 1, items: [], dropped: 0, truncated: false }, "nothing newer than the client's last read");
746
+
747
+ // Streamed text merges into the last item in place, so the changed window is returned.
748
+ store.apply("t1", { type: TASK_EVENT.TEXT, text: "hel" }, 1002);
749
+ store.apply("t1", { type: TASK_EVENT.TEXT, text: "lo" }, 1003);
750
+ const changed = (await bridge.handle("get_subagent_thread", { id: "t1", sinceVersion: first.data.version })) as unknown as ThreadData;
751
+ assert.deepEqual(changed.data, { id: "t1", version: 3, items: [{ kind: "note", text: "first" }, { kind: "text", text: "hello" }], dropped: 0, truncated: false });
752
+
753
+ const ahead = (await bridge.handle("get_subagent_thread", { id: "t1", sinceVersion: 99 })) as unknown as ThreadData;
754
+ assert.equal(ahead.data.items.length, 2, "a version the store never reached is not trusted: the whole window answers");
755
+ assert.equal(events.length, 0);
756
+ });
757
+
758
+ test("get_subagent_thread unknown and foreign-session ids are typed not_found", async () => {
759
+ const store = threadStore();
760
+ const { service } = makeAgentsOwnerService(store, makeRunner(store), "session-a");
761
+ const { bridge, events } = makeBridge(service, "session-a");
762
+ for (const id of ["theirs", "t-99"]) {
763
+ const outcome = await bridge.handle("get_subagent_thread", { id });
764
+ assert.equal(outcome.ok, false, id);
765
+ assert.deepEqual(outcome.error, AGENT_NOT_FOUND, id);
766
+ assert.doesNotMatch(JSON.stringify(outcome), /foreign session note/);
767
+ }
768
+ assert.equal(events.length, 0);
769
+ });
770
+
771
+ test("get_subagent_thread rejects invalid params before any owner discovery", async () => {
772
+ const store = threadStore();
773
+ const { service } = makeAgentsOwnerService(store, makeRunner(store));
774
+ let discoveries = 0;
775
+ const bridge = new DesktopAgentsBridge({} as ExtensionAPI, { discover: async () => { discoveries += 1; return service; } });
776
+ bridge.attach({ sessionManager: { getSessionId: () => "session-a" } } as unknown as ExtensionContext);
777
+ for (const params of [{}, { id: "" }, { id: "t1", extra: true }, { id: "t1", sinceVersion: -1 }, { id: "t1", sinceVersion: "1" }]) {
778
+ const bad = await bridge.handle("get_subagent_thread", params);
779
+ assert.equal(bad.ok, false);
780
+ assert.deepEqual(bad.error, INVALID_AGENTS_PARAMS, JSON.stringify(params));
781
+ }
782
+ assert.equal(discoveries, 0, "invalid params never reach discovery");
783
+ });
784
+
785
+ test("get_subagent_thread answers agents_unavailable for an absent, older, throwing, or malformed owner without leaking", async () => {
786
+ const absent = new DesktopAgentsBridge({} as ExtensionAPI, { discover: async () => undefined });
787
+ absent.attach({ sessionManager: { getSessionId: () => "session-a" } } as unknown as ExtensionContext);
788
+ const missing = await absent.handle("get_subagent_thread", { id: "t1" });
789
+ assert.equal(missing.ok, false);
790
+ assert.deepEqual(missing.error, AGENTS_UNAVAILABLE);
791
+
792
+ const base: DesktopAgentsService = { schema: DESKTOP_AGENTS_SERVICE_SCHEMA, read: () => ({ sessionId: "session-a", agents: [] }), cancel: () => ({ kind: "not_found" as const }), observe: () => () => {}, dispose: () => {} };
793
+ const older: DesktopAgentsService = { ...base };
794
+ const throwing: DesktopAgentsService = { ...base, thread: () => { throw new Error("ENOENT /home/me/.pi/sessions/secret.jsonl sk-ant-secret"); } };
795
+ const malformed: DesktopAgentsService = { ...base, thread: () => ({ kind: "ok", thread: { id: "t1", version: 1, dropped: 0, truncated: false, items: [{ kind: "text", text: "x".repeat(5000) }] } as unknown as DesktopAgentThread }) };
796
+ const wrongId: DesktopAgentsService = { ...base, thread: () => ({ kind: "ok", thread: { id: "other", version: 1, dropped: 0, truncated: false, items: [] } }) };
797
+ for (const service of [older, throwing, malformed, wrongId]) {
798
+ const { bridge, events } = makeBridge(service);
799
+ const outcome = await bridge.handle("get_subagent_thread", { id: "t1" });
800
+ assert.equal(outcome.ok, false);
801
+ assert.deepEqual(outcome.error, AGENTS_UNAVAILABLE);
802
+ assert.doesNotMatch(JSON.stringify(outcome), /secret|ENOENT|xxxxx/);
803
+ assert.equal(events.length, 0);
804
+ }
805
+ assert.equal(isDesktopAgentsServiceShape(older), true, "an adapter without thread still serves list/cancel");
806
+ assert.equal(isDesktopAgentsServiceShape({ ...base, thread: "nope" }), false, "a non-function thread is not the adapter");
807
+ });
808
+
809
+ test("get_subagent_thread through the router publishes exactly one response line", async () => {
810
+ const store = threadStore();
811
+ const { service } = makeAgentsOwnerService(store, makeRunner(store));
812
+ const bridge = new DesktopAgentsBridge({} as ExtensionAPI, { discover: async () => service, schedule: () => () => {}, coalesceMs: 10 });
813
+ bridge.attach({ sessionManager: { getSessionId: () => "session-a" } } as unknown as ExtensionContext);
814
+ const domain: DesktopRpcDomain = (method, params) => bridge.handle(method, params as Record<string, unknown>);
815
+ const lines: string[] = [];
816
+ const router = new DesktopRpcRouter(["capabilities", "get_snapshot", ...DESKTOP_AGENTS_METHODS], [...DESKTOP_AGENTS_EVENTS], undefined, domain);
817
+ router.start((line) => lines.push(line));
818
+ await router.handle(JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId: "thread-2", method: "get_subagent_thread", params: { id: "t1" } }));
819
+ assert.equal(lines.length, 1);
820
+ const response = JSON.parse(lines[0]!);
821
+ assert.equal(response.kind, "response");
822
+ assert.equal(response.ok, true);
823
+ assert.deepEqual(response.data, projectDesktopAgentThread("t1", store.thread("t1")));
824
+ });
825
+
618
826
  // ---- Transport: capabilities and owner absence ----
619
827
 
620
828
  function desktopHarness(t: test.TestContext) {
@@ -656,11 +864,35 @@ test("the Desktop transport advertises the agents methods and event", (t) => {
656
864
  "get_design_canvas",
657
865
  "list_jobs",
658
866
  "cancel_job",
867
+ "get_job_output",
659
868
  "apply_profile",
660
869
  "list_subagents",
661
870
  "cancel_subagent",
871
+ "get_subagent_thread",
872
+ "list_sessions",
873
+ "switch_session",
874
+ "get_changes",
875
+ "get_change_diff",
876
+ "get_review_mode",
877
+ "set_review_mode",
878
+ "get_usage_stats",
879
+ "get_update_status",
662
880
  ]);
663
- assert.deepEqual(response.data.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update"]);
881
+ assert.deepEqual(response.data.events, ["config_changed", "permission_mode_changed", "rate_limit", "design_canvas", "jobs_update", "profile_applied", "agents_update", "review_mode_changed"]);
882
+ });
883
+
884
+ test("get_subagent_thread answers agents_unavailable through the transport without an owner extension", async (t) => {
885
+ const app = desktopHarness(t);
886
+ await app.commands.get("gentle:desktop")!.handler(
887
+ JSON.stringify({ schema: DESKTOP_RPC_SCHEMA, requestId: "thread-1", method: "get_subagent_thread", params: { id: "t1" } }),
888
+ app.ctx,
889
+ );
890
+ assert.equal(app.widgets.length, 1, "exactly one response line and no event");
891
+ const response = JSON.parse(app.widgets[0]!.lines[0]!);
892
+ assert.equal(response.kind, "response");
893
+ assert.equal(response.requestId, "thread-1");
894
+ assert.equal(response.ok, false);
895
+ assert.deepEqual(response.error, AGENTS_UNAVAILABLE);
664
896
  });
665
897
 
666
898
  test("list_subagents answers agents_unavailable through the transport without an owner extension", async (t) => {
@@ -882,6 +1114,40 @@ test("the real owner persists the final usage breakdown so restored finished tas
882
1114
  assert.deepEqual(stored.task.usage, { input: 100, output: 40, cacheRead: 30, cacheWrite: 10, reasoning: 5 });
883
1115
  });
884
1116
 
1117
+ test("the real owner serves an owned thread through the activity projection and not_found otherwise", async (t) => {
1118
+ const h = await realOwnerHarness(t);
1119
+ assert.deepEqual(h.service.thread!("unknown-id"), { kind: "not_found" });
1120
+ const taskId = await launchBackgroundTask(h);
1121
+ h.children[0]!.emit({ type: "message_update", assistantMessageEvent: { type: "text_delta", delta: "mapping the repo" } });
1122
+ h.children[0]!.emit({ type: "tool_execution_start", toolCallId: "call-1", toolName: "read", args: { path: "README.md" } });
1123
+ h.children[0]!.emit({ type: "tool_execution_end", toolCallId: "call-1", result: { content: [{ type: "text", text: "w".repeat(800) }] }, isError: false });
1124
+ await tick();
1125
+
1126
+ const outcome = h.service.thread!(taskId);
1127
+ assert.equal(outcome.kind, "ok");
1128
+ const thread = (outcome as { kind: "ok"; thread: DesktopAgentThread }).thread;
1129
+ assert.deepEqual(thread.items, [
1130
+ { kind: "text", text: "mapping the repo" },
1131
+ { kind: "tool", name: "read", args: JSON.stringify({ path: "README.md" }), running: false, isError: false, output: `${"w".repeat(499)}…` },
1132
+ ]);
1133
+ assert.equal(thread.dropped, 0);
1134
+ assert.equal(thread.truncated, false);
1135
+ assert.ok(thread.version > 0);
1136
+
1137
+ const bridge = new DesktopAgentsBridge(h.pi, { discover: async () => h.service, schedule: () => () => {} });
1138
+ bridge.attach(h.ctx);
1139
+ const read = (await bridge.handle("get_subagent_thread", { id: taskId })) as unknown as ThreadData;
1140
+ assert.deepEqual(read.data, thread);
1141
+ const again = (await bridge.handle("get_subagent_thread", { id: taskId, sinceVersion: thread.version })) as unknown as ThreadData;
1142
+ assert.deepEqual(again.data.items, []);
1143
+
1144
+ // The same ownership rule as cancel: a session-b context never reads session-a's thread.
1145
+ const foreignCtx = { ...h.ctx, sessionManager: { ...h.ctx.sessionManager, getSessionId: () => "session-b" } } as unknown as ExtensionContext;
1146
+ const foreign = await discoverDesktopAgentsService(h.pi, foreignCtx);
1147
+ assert.ok(foreign);
1148
+ assert.deepEqual(foreign.thread!(taskId), { kind: "not_found" });
1149
+ });
1150
+
885
1151
  test("a shut-down owner leaves the agents service channel and never answers discovery", async (t) => {
886
1152
  const harness = await realOwnerHarness(t);
887
1153
  assert.equal(harness.listeners.get(DESKTOP_AGENTS_SERVICE_CHANNEL)?.size, 1, "one owner answers while the session is live");
@@ -891,3 +1157,163 @@ test("a shut-down owner leaves the agents service channel and never answers disc
891
1157
  harness.pi.events.emit(DESKTOP_AGENTS_SERVICE_CHANNEL, { context: harness.ctx, respond: () => { answered += 1; } });
892
1158
  assert.equal(answered, 0, "a replaced runtime is never discovered through the old owner");
893
1159
  });
1160
+
1161
+ // ---- get_subagent_thread: independent verifier probes (regression) ----
1162
+ function probeTask(id: string, parentSessionId: string, o: any = {}) {
1163
+ return { id, agent: "w", mode: "task", prompt: "SECRETPROMPT", label: "p", cwd: "/r", parentSessionId, status: TASK_STATUS.RUNNING, createdAt: 1, startedAt: 1, endedAt: null, model: "m", thinking: undefined, sessionPath: "/s.jsonl", error: null, result: null, lastStep: "x", lastActivityAt: 1, turns: 0, toolCalls: 0, tokens: 0, cost: 0, ...o };
1164
+ }
1165
+ function probeOwner(store: any, sessionId = "session-a", over: any = {}) {
1166
+ let disposed = false;
1167
+ let discoveries = 0;
1168
+ const service: any = {
1169
+ schema: probeAgents.DESKTOP_AGENTS_SERVICE_SCHEMA,
1170
+ read: () => ({ sessionId, agents: probeAgents.selectDesktopAgents(store.list(sessionId)) }),
1171
+ cancel: () => ({ kind: "not_found" }),
1172
+ thread: (id: string) => {
1173
+ if (disposed) return { kind: "not_found" };
1174
+ const t = store.get(id);
1175
+ if (!t || t.parentSessionId !== sessionId) return { kind: "not_found" };
1176
+ return { kind: "ok", thread: probeAgents.projectDesktopAgentThread(id, store.thread(id)) };
1177
+ },
1178
+ observe: () => () => {},
1179
+ dispose: () => { disposed = true; },
1180
+ ...over,
1181
+ };
1182
+ return { service, count: () => discoveries, discover: async () => { discoveries++; return service; } };
1183
+ }
1184
+ function probeBridge(o: any, sessionId = "session-a") {
1185
+ const b = new DesktopAgentsBridge({} as any, { discover: o.discover, schedule: () => () => {}, coalesceMs: 1 });
1186
+ b.attach({ sessionManager: { getSessionId: () => sessionId } } as any);
1187
+ const events: any[] = [];
1188
+ b.wire((e: string) => events.push(e));
1189
+ return { b, events };
1190
+ }
1191
+ function probeSeeded() {
1192
+ const store = new TaskStore();
1193
+ store.add(probeTask("mine", "session-a"));
1194
+ store.add(probeTask("theirs", "session-b"));
1195
+ store.add(probeTask("grandchild", "child-session-of-mine"));
1196
+ store.apply("mine", { type: "text", text: "hello" }, 2);
1197
+ store.apply("theirs", { type: "tool_start", callId: "c", name: "bash", args: { cmd: "cat ~/.ssh/id_rsa" } }, 2);
1198
+ store.apply("grandchild", { type: "note", text: "nested" }, 2);
1199
+ return store;
1200
+ }
1201
+
1202
+ test("probe: invalid params are invalid_request before discovery", async () => {
1203
+ const o = probeOwner(probeSeeded());
1204
+ const { b } = probeBridge(o);
1205
+ for (const p of [{}, { id: "" }, { id: 3 }, { id: "mine", extra: 1 }, { id: "mine", sinceVersion: -1 }, { id: "mine", sinceVersion: 1.5 }, { id: "mine", sinceVersion: 2 ** 60 }, { id: "mine", sinceVersion: "1" }, { id: "mine", sinceVersion: null }, { id: "mine", sinceVersion: NaN }, { id: "mine", sinceVersion: Infinity }]) {
1206
+ const r: any = await b.handle("get_subagent_thread", p as any);
1207
+ assert.equal(r.ok, false, JSON.stringify(p));
1208
+ assert.equal(r.error.code, "invalid_request", JSON.stringify(p));
1209
+ }
1210
+ assert.equal(o.count(), 0);
1211
+ });
1212
+
1213
+ test("probe: ownership: foreign, nested, unknown are not_found with no leak; own ok", async () => {
1214
+ const o = probeOwner(probeSeeded());
1215
+ const { b, events } = probeBridge(o);
1216
+ for (const id of ["theirs", "grandchild", "nope", "__proto__", "constructor"]) {
1217
+ const r: any = await b.handle("get_subagent_thread", { id });
1218
+ assert.equal(r.ok, false, id);
1219
+ assert.equal(r.error.code, probeAgents.AGENT_NOT_FOUND.code, id);
1220
+ assert.ok(!JSON.stringify(r).includes("id_rsa"));
1221
+ }
1222
+ const r: any = await b.handle("get_subagent_thread", { id: "mine" });
1223
+ assert.equal(r.ok, true);
1224
+ assert.deepEqual(r.data.items, [{ kind: "text", text: "hello" }]);
1225
+ assert.ok(!JSON.stringify(r).includes("SECRETPROMPT"));
1226
+ assert.equal(events.length, 0);
1227
+ });
1228
+
1229
+ test("probe: session switch: a session-b owner cannot read the session-a subagent", async () => {
1230
+ const o = probeOwner(probeSeeded(), "session-b");
1231
+ const { b } = probeBridge(o, "session-b");
1232
+ const r: any = await b.handle("get_subagent_thread", { id: "mine" });
1233
+ assert.equal(r.error.code, probeAgents.AGENT_NOT_FOUND.code);
1234
+ });
1235
+
1236
+ test("probe: reset during discovery answers agents_unavailable", async () => {
1237
+ const o = probeOwner(probeSeeded());
1238
+ let release: any;
1239
+ const gate = new Promise((r) => { release = r; });
1240
+ const b = new DesktopAgentsBridge({} as any, { discover: () => gate as any, schedule: () => () => {} });
1241
+ b.attach({ sessionManager: { getSessionId: () => "session-a" } } as any);
1242
+ const pending = b.handle("get_subagent_thread", { id: "mine" });
1243
+ b.reset();
1244
+ release(o.service);
1245
+ const r: any = await pending;
1246
+ assert.equal(r.error.code, probeAgents.AGENTS_UNAVAILABLE.code);
1247
+ });
1248
+
1249
+ test("probe: older adapter, throwing, malformed, id mismatch, oversized item answer agents_unavailable", async () => {
1250
+ const store = probeSeeded();
1251
+ const cases = [
1252
+ { thread: undefined },
1253
+ { thread: () => { throw new Error("/home/x SECRETPROMPT"); } },
1254
+ { thread: () => ({ kind: "ok", thread: { id: "mine", version: 1, dropped: 0, truncated: false, items: [{ kind: "text", text: "x".repeat(2001) }] } }) },
1255
+ { thread: () => ({ kind: "ok", thread: { id: "other", version: 1, dropped: 0, truncated: false, items: [] } }) },
1256
+ { thread: () => ({ kind: "ok", thread: { id: "mine", version: -1, dropped: 0, truncated: false, items: [] } }) },
1257
+ ];
1258
+ for (const over of cases) {
1259
+ const o = probeOwner(store, "session-a", over);
1260
+ const { b } = probeBridge(o);
1261
+ const r: any = await b.handle("get_subagent_thread", { id: "mine" });
1262
+ assert.equal(r.error.code, probeAgents.AGENTS_UNAVAILABLE.code);
1263
+ assert.ok(!JSON.stringify(r).includes("SECRETPROMPT"));
1264
+ }
1265
+ });
1266
+
1267
+ test("probe: bounds: dropped vs eviction, 256KB halving with escape-heavy text", async () => {
1268
+ const store = new TaskStore({ maxItems: 400 });
1269
+ store.add(probeTask("t", "session-a"));
1270
+ // Text is sanitized and capped at 2000 chars (≤ ~6 KB/item), so a realistic text-only
1271
+ // window never exceeds 256 KB; tool names are the one unbounded field the widget forwards.
1272
+ for (let i = 0; i < 450; i++) store.apply("t", { type: "tool_start", callId: "c" + i, name: "n".repeat(8000), args: {} }, i);
1273
+ const raw = store.thread("t");
1274
+ assert.equal(raw.items.length, 400);
1275
+ assert.equal(raw.dropped, 50);
1276
+ const { b } = probeBridge(probeOwner(store));
1277
+ const r: any = await b.handle("get_subagent_thread", { id: "t" });
1278
+ assert.equal(r.ok, true);
1279
+ assert.ok(Buffer.byteLength(JSON.stringify(r.data)) <= 256 * 1024);
1280
+ assert.equal(r.data.items.length, 20, "40 items of ~12KB halved once");
1281
+ assert.equal(r.data.dropped, 50);
1282
+ assert.equal(r.data.truncated, true);
1283
+ assert.ok(r.data.items.every((it: any) => it.kind === "tool" && it.name.length === 8000));
1284
+ const w = projectRpcActivity(store, { parentSessionId: "session-a" });
1285
+ assert.equal(w.tasks[0].thread.items.length, 40);
1286
+ });
1287
+
1288
+ test("probe: tool item caps: args 500, output 500, exact key set", async () => {
1289
+ const store = new TaskStore();
1290
+ store.add(probeTask("t", "session-a"));
1291
+ store.apply("t", { type: "tool_start", callId: "c", name: "bash", args: { cmd: "y".repeat(900) } }, 1);
1292
+ store.apply("t", { type: "tool_end", callId: "c", output: "o".repeat(900), isError: true }, 2);
1293
+ const { b } = probeBridge(probeOwner(store));
1294
+ const r: any = await b.handle("get_subagent_thread", { id: "t" });
1295
+ const it = r.data.items[0];
1296
+ assert.equal(it.args.length, 500);
1297
+ assert.equal(it.output.length, 500);
1298
+ assert.equal(it.isError, true);
1299
+ assert.equal(it.running, false);
1300
+ assert.deepEqual(Object.keys(it).sort(), ["args", "isError", "kind", "name", "output", "running"]);
1301
+ assert.deepEqual(Object.keys(r.data).sort(), ["dropped", "id", "items", "truncated", "version"]);
1302
+ });
1303
+
1304
+ test("probe: sinceVersion: equal returns [], other values return the window; in-place change bumps version", async () => {
1305
+ const store = new TaskStore();
1306
+ store.add(probeTask("t", "session-a"));
1307
+ store.apply("t", { type: "text", text: "a" }, 1);
1308
+ const { b } = probeBridge(probeOwner(store));
1309
+ const first: any = await b.handle("get_subagent_thread", { id: "t" });
1310
+ const v = first.data.version;
1311
+ const same: any = await b.handle("get_subagent_thread", { id: "t", sinceVersion: v });
1312
+ assert.deepEqual(same.data, { ...first.data, items: [], truncated: false });
1313
+ store.apply("t", { type: "text", text: "b" }, 2);
1314
+ const after: any = await b.handle("get_subagent_thread", { id: "t", sinceVersion: v });
1315
+ assert.equal(after.data.version, v + 1);
1316
+ assert.deepEqual(after.data.items, [{ kind: "text", text: "ab" }]);
1317
+ const higher: any = await b.handle("get_subagent_thread", { id: "t", sinceVersion: v + 100 });
1318
+ assert.equal(higher.data.items.length, 1);
1319
+ });