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
@@ -1,10 +1,10 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { mkdtempSync, writeFileSync } from "node:fs";
3
- import { tmpdir } from "node:os";
4
- import { join } from "node:path";
3
+ import { homedir, tmpdir } from "node:os";
4
+ import { join, relative } from "node:path";
5
5
  import test from "node:test";
6
6
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
- import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
7
+ import { createGentleAiExtension, isDesktopActionPathOn } from "../extensions/gentle-ai.ts";
8
8
 
9
9
  // gentle-shell#2349: the sensitive-path deny list must not depend on which
10
10
  // path-taking tool the model picks. grep, find, and ls take the same `path`
@@ -17,6 +17,8 @@ type Handler = (event: { toolName: string; input: unknown; toolCallId: string },
17
17
  interface HarnessOptions {
18
18
  child?: boolean;
19
19
  mode?: "normal" | "yolo" | "super-yolo";
20
+ /** The resolved Gentle Pi agent home (GENTLE_PI_AGENT_HOME) of this process. */
21
+ agentHome?: string;
20
22
  /** Counts the approval dialog, so a test can prove the mode fixture is live. */
21
23
  onApprovalPrompt?: () => void;
22
24
  }
@@ -35,7 +37,7 @@ function toolCall(options: HarnessOptions = {}) {
35
37
  if (options.mode !== undefined) {
36
38
  writeFileSync(join(home, "permission-mode.json"), `${JSON.stringify({ schema: "gentle-pi.permission-mode/v1", mode: options.mode })}\n`);
37
39
  }
38
- createGentleAiExtension({ processEnv: { GENTLE_PI_AGENTS_CHILD: options.child === true ? "1" : "0", GENTLE_PI_CONFIG_HOME: home }, nativeReviewCli: null })(pi);
40
+ createGentleAiExtension({ processEnv: { GENTLE_PI_AGENTS_CHILD: options.child === true ? "1" : "0", GENTLE_PI_CONFIG_HOME: home, ...(options.agentHome === undefined ? {} : { GENTLE_PI_AGENT_HOME: options.agentHome }) }, nativeReviewCli: null })(pi);
39
41
  const sessionManager = { getSessionId: () => "session-2349", getBranch: () => [], getEntries: () => [] };
40
42
  const ctx = { cwd: process.cwd(), hasUI: false, sessionManager, ui: { confirm: async () => false, select: async () => { options.onApprovalPrompt?.(); return undefined; } } } as unknown as ExtensionContext;
41
43
  return async (toolName: string, input: unknown) => {
@@ -134,6 +136,138 @@ for (const mode of ["yolo", "super-yolo"] as const) {
134
136
  });
135
137
  }
136
138
 
139
+ // T7 (odd/tasks/herdr-desktop.md, B1): the desktop inbox, outbox and snapshots
140
+ // under `<agentDir>/desktop/` are the human's channel into a live session, so
141
+ // the agent's own file tools and shell commands cannot write an action there.
142
+ // Only the real folders are guarded: `<agent home>/desktop` for the resolved
143
+ // Gentle Pi agent home and the two standard homes, on the normalized absolute
144
+ // path. A project folder that happens to be named `agent/desktop` is not one.
145
+ const CUSTOM_AGENT_HOME = "/tmp/customhome";
146
+ // Bash drops unquoted backslashes, so a Windows home spelled with `\` would no
147
+ // longer name the desktop folder inside a shell command. Forward slashes keep
148
+ // these tests about the guard, not about shell quoting, on every platform.
149
+ const HOME = homedir().replace(/\\/g, "/");
150
+ const desktopPaths = [
151
+ "~/.gentle-shell/agent/desktop/inbox/x.json",
152
+ "$HOME/.pi/agent/desktop/outbox",
153
+ "${HOME}/.pi/agent/desktop/sessions/s.json",
154
+ `${HOME}/.gentle-shell/agent/desktop/outbox/sess-1/a1.json`,
155
+ `${HOME}/.pi/agent/desktop/sessions/sess-1.json`,
156
+ "~/.gentle-shell/agent/desktop",
157
+ "~/.gentle-shell/agent/x/../desktop/inbox/a.json",
158
+ "~/.Gentle-Shell/Agent/Desktop/Inbox/a.json",
159
+ `${CUSTOM_AGENT_HOME}/desktop/sessions/a.json`,
160
+ `${CUSTOM_AGENT_HOME}/./desktop/inbox/s/a.json`,
161
+ ] as const;
162
+
163
+ for (const mode of [undefined, "super-yolo"] as const) {
164
+ test(`the desktop action folders are sensitive paths for file tools and bash${mode ? ` in ${mode}` : ""} (T7)`, async () => {
165
+ const call = toolCall({ ...(mode ? { mode } : {}), agentHome: CUSTOM_AGENT_HOME });
166
+ for (const path of desktopPaths) {
167
+ assert.deepEqual(await call("read", { path }), { block: true, reason: reason(path) }, `read ${path}`);
168
+ assert.deepEqual(await call("write", { path, content: "{}" }), { block: true, reason: reason(path) }, `write ${path}`);
169
+ assert.deepEqual(await call("edit", { path, edits: [] }), { block: true, reason: reason(path) }, `edit ${path}`);
170
+ assert.deepEqual(await call("ls", { path }), { block: true, reason: reason(path) }, `ls ${path}`);
171
+ assert.deepEqual(await call("bash", { command: `printf '{}' > ${path}` }), { block: true, reason: reason(path) }, `bash ${path}`);
172
+ }
173
+ assert.deepEqual(await call("bash", { command: "mv /tmp/a.json ~/.gentle-shell/agent/desktop/inbox/s/a.json" }), { block: true, reason: reason("~/.gentle-shell/agent/desktop/inbox/s/a.json") });
174
+ assert.deepEqual(await call("bash", { command: 'mkdir -p "$HOME/.pi/agent/desktop/outbox"' }), { block: true, reason: reason("$HOME/.pi/agent/desktop/outbox") });
175
+ });
176
+ }
177
+
178
+ test("a custom agent home's desktop folder is guarded only while that home is the resolved one (T7)", async () => {
179
+ const call = toolCall();
180
+ const path = `${CUSTOM_AGENT_HOME}/desktop/sessions/a.json`;
181
+ assert.equal(await call("write", { path, content: "x" }), undefined, path);
182
+ assert.equal(await call("bash", { command: `mkdir -p ${CUSTOM_AGENT_HOME}/desktop/inbox` }), undefined);
183
+ // A `..` that leaves the desktop folder leaves the guard too.
184
+ assert.equal(await call("read", { path: "~/.gentle-shell/agent/desktop/../notes.md" }), undefined);
185
+ });
186
+
187
+ test("ordinary project folders named agent/desktop/... stay readable and writable (T7 FP)", async () => {
188
+ const call = toolCall();
189
+ for (const path of ["src/agent/desktop/inbox/index.ts", "packages/agent/desktop/sessions/list.ts", "agent/desktop/outbox", ".pi/agent/desktop/notes.md"]) {
190
+ assert.equal(await call("read", { path }), undefined, path);
191
+ assert.equal(await call("write", { path, content: "x" }), undefined, path);
192
+ }
193
+ assert.equal(await call("bash", { command: "mkdir -p src/agent/desktop/sessions" }), undefined);
194
+ });
195
+
196
+ test("relative and option-embedded paths into the real desktop folder stay blocked (T7)", async () => {
197
+ const call = toolCall();
198
+ // The harness hands the tool call `process.cwd()`, so the relative path is computed against it.
199
+ const rel = relative(process.cwd(), join(homedir(), ".gentle-shell", "agent", "desktop", "inbox", "s", "a.json")).replace(/\\/g, "/");
200
+ assert.equal((await call("write", { path: rel, content: "{}" }))?.block, true, rel);
201
+ assert.equal((await call("read", { path: rel }))?.block, true, rel);
202
+ assert.equal((await call("bash", { command: `printf '{}' > ${rel}` }))?.block, true, rel);
203
+ for (const command of [
204
+ "cp a.json --target-directory=$HOME/.gentle-shell/agent/desktop/inbox/s",
205
+ "VAR=$HOME/.gentle-shell/agent/desktop/inbox; cp a.json $VAR",
206
+ 'cp a.json "--target-directory=$HOME/.gentle-shell/agent/desktop/inbox/s"',
207
+ "cp a.json '--target-directory=~/.pi/agent/desktop/outbox'",
208
+ 'cp a.json --target-directory="${HOME}/.gentle-shell/agent/desktop/inbox/s"',
209
+ `cp a.json --target-directory=${rel}`,
210
+ ]) {
211
+ assert.equal((await call("bash", { command }))?.block, true, command);
212
+ }
213
+ });
214
+
215
+ test("relative project paths named agent/desktop stay allowed when the cwd is a project dir (T7 FP)", async () => {
216
+ const call = toolCall();
217
+ for (const path of ["src/agent/desktop/inbox/index.ts", "agent/desktop/outbox", ".pi/agent/desktop/notes.md", "./agent/desktop/inbox/a.json"]) {
218
+ assert.equal(await call("write", { path, content: "x" }), undefined, path);
219
+ assert.equal(await call("bash", { command: `mkdir -p ${path}` }), undefined, path);
220
+ assert.equal(await call("bash", { command: `cp a.json --target-directory=${path}` }), undefined, path);
221
+ assert.equal(await call("bash", { command: `OUT=${path} make` }), undefined, path);
222
+ }
223
+ assert.equal(await call("bash", { command: "git log --format=%H --since=yesterday" }), undefined);
224
+ });
225
+
226
+ // On Windows the bash tool runs Git for Windows bash, where `/c/Users/<user>`
227
+ // and `/cygdrive/c/Users/<user>` name the same folder as `C:\Users\<user>`.
228
+ // The guard reads those drive spellings on win32 only, case-insensitively, so
229
+ // this runs on every platform through the injected platform and home.
230
+ // `$USERPROFILE` and other variables are not expanded (documented fail-open).
231
+ test("MSYS and Cygwin drive spellings of the Windows home stay inside the desktop guard (T7)", () => {
232
+ const win = { platform: "win32" as const, home: "C:\\Users\\someone", homes: ["C:\\Users\\someone\\.gentle-shell\\agent", "C:\\Users\\someone\\.pi\\agent"] };
233
+ for (const path of [
234
+ "/c/Users/someone/.gentle-shell/agent/desktop/inbox/s/a.json",
235
+ "/C/users/SOMEONE/.gentle-shell/agent/desktop",
236
+ "/cygdrive/c/Users/someone/.pi/agent/desktop/outbox/x.json",
237
+ "//?/C:/Users/someone/.gentle-shell/agent/desktop/inbox/a.json",
238
+ "C:\\Users\\someone\\.gentle-shell\\agent\\desktop\\inbox\\a.json",
239
+ "c:/users/someone/.pi/agent/desktop/sessions/s.json",
240
+ "~/.gentle-shell/agent/desktop/inbox/a.json",
241
+ ]) assert.equal(isDesktopActionPathOn(path, win), true, path);
242
+ for (const path of [
243
+ "/c/Users/someone/project/agent/desktop/inbox/x.ts",
244
+ "/cd/foo",
245
+ "/c",
246
+ "/d/Users/someone/.gentle-shell/agent/desktop/inbox/a.json",
247
+ "$USERPROFILE/.gentle-shell/agent/desktop/inbox/a.json",
248
+ ]) assert.equal(isDesktopActionPathOn(path, win), false, path);
249
+ // The same drive spellings mean ordinary folders off Windows.
250
+ const posixHost = { platform: "linux" as const, home: "/home/someone", homes: ["/home/someone/.gentle-shell/agent"] };
251
+ assert.equal(isDesktopActionPathOn("/home/someone/.gentle-shell/agent/desktop/inbox/a.json", posixHost), true);
252
+ assert.equal(isDesktopActionPathOn("/c/home/someone/.gentle-shell/agent/desktop/inbox/a.json", posixHost), false);
253
+ assert.equal(isDesktopActionPathOn("/cygdrive/c/home/someone/.gentle-shell/agent/desktop", posixHost), false);
254
+ });
255
+
256
+ test("adding the desktop folders keeps every earlier deny and the ordinary allow (T7)", async () => {
257
+ for (const mode of [undefined, "super-yolo"] as const) {
258
+ const call = toolCall({ ...(mode ? { mode } : {}), agentHome: CUSTOM_AGENT_HOME });
259
+ for (const path of [".env", "~/.ssh/id_rsa", "secrets/x", "cert.pem", "~/.aws/credentials"]) {
260
+ assert.deepEqual(await call("read", { path }), { block: true, reason: reason(path) }, `${mode ?? "normal"} read ${path}`);
261
+ }
262
+ assert.deepEqual(await call("bash", { command: "cat ~/.aws/credentials" }), { block: true, reason: reason("~/.aws/credentials") });
263
+ for (const path of ["src/desktop/inbox.ts", "docs/desktop-feed.md", "lib/desktop-feed-actions.ts", "desktop/inbox/readme.md", "/opt/custom/agent/desktop/inbox/a.json"]) {
264
+ assert.equal(await call("read", { path }), undefined, path);
265
+ assert.equal(await call("write", { path, content: "x" }), undefined, path);
266
+ }
267
+ assert.equal(await call("bash", { command: "cat src/index.ts" }), undefined);
268
+ }
269
+ });
270
+
137
271
  // The mode fixture above is only meaningful if it is live, so pin the modal it
138
272
  // changes: YOLO waives the push approval, and the same push without the fixture
139
273
  // still needs one.
@@ -1,5 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
+ import { execFileSync } from "node:child_process";
3
4
  import {
4
5
  existsSync,
5
6
  mkdirSync,
@@ -27,25 +28,60 @@ import {
27
28
  import { loadExtensionFromFactory } from "../node_modules/@earendil-works/pi-coding-agent/dist/core/extensions/loader.js";
28
29
  import { getThemeByName } from "../node_modules/@earendil-works/pi-coding-agent/dist/modes/interactive/theme/theme.js";
29
30
  import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
31
+ import fast from "../extensions/gentle-fast.ts";
32
+ import gentleAgents from "../extensions/gentle-agents.ts";
33
+ import { resolveSessionWorktree } from "../lib/session-worktree-registry.ts";
34
+ import { fakeChild } from "./agents-fake-child.ts";
35
+ import { PROFILE_TIER_EVENT } from "../lib/openai-fast-tier.ts";
30
36
  import { readSessionProfileBinding } from "../lib/session-profile-binding.ts";
31
37
  import { SESSION_PROFILE_CUSTOM_TYPE } from "../lib/session-profile-persistence.ts";
38
+ import { localProfilePinPath, repoProfileDeclarationPath, setProfilePinWorktreeResolverForTesting, writeProfilePinSync } from "../lib/agent-profile-pin.ts";
39
+ import { readFrozenDefaultOrchestrator, readFrozenInheritedProfile, resolveSessionProfile, sessionProfileRoutingAt } from "../lib/session-profile-freeze.ts";
40
+ import type { AgentRoutingEntry } from "../lib/model-routing-authority.ts";
32
41
  import { replay, type Transcript } from "./fixtures/session-profile-v1/replay.ts";
33
42
 
34
43
  // Actual SDK factory loader, AgentSession and replacement runtime. Only resource,
35
44
  // auth and UI boundaries are fixture-owned. No prompts, provider streams or Git.
36
- async function fixture(t: test.TestContext, memory = false, flushed = true, active?: string) {
45
+ async function fixture(t: test.TestContext, memory = false, flushed = true, active?: string, startup?: {
46
+ env?: NodeJS.ProcessEnv;
47
+ layer?: "local" | "repo";
48
+ orchestrator?: AgentRoutingEntry;
49
+ noAuth?: boolean;
50
+ reason?: "startup" | "new" | "resume" | "fork";
51
+ fastOrder?: "ai-first" | "fast-first";
52
+ agents?: boolean;
53
+ routing?: Record<string, AgentRoutingEntry>;
54
+ headless?: boolean;
55
+ }) {
37
56
  const root = mkdtempSync(join(tmpdir(), "u3-public-"));
38
57
  const config = join(root, "config"),
39
58
  agentDir = join(root, "agent");
40
59
  mkdirSync(config);
41
60
  mkdirSync(agentDir);
42
- const originalConfig = process.env.GENTLE_PI_CONFIG_HOME;
43
- process.env.GENTLE_PI_CONFIG_HOME = config;
61
+ const environment = {
62
+ GENTLE_PI_CONFIG_HOME: config,
63
+ GENTLE_PI_AGENT_HOME: agentDir,
64
+ PI_CODING_AGENT_DIR: agentDir,
65
+ GENTLE_PI_AGENTS_CHILD: startup?.env?.GENTLE_PI_AGENTS_CHILD,
66
+ GENTLE_PI_PROFILE_FOLLOW: startup?.env?.GENTLE_PI_PROFILE_FOLLOW,
67
+ };
68
+ const originals = Object.fromEntries(Object.keys(environment).map((key) => [key, process.env[key]]));
69
+ for (const [key, value] of Object.entries(environment)) {
70
+ if (value === undefined) delete process.env[key];
71
+ else process.env[key] = value;
72
+ }
73
+ t.after(() => {
74
+ for (const [key, value] of Object.entries(originals)) {
75
+ if (value === undefined) delete process.env[key];
76
+ else process.env[key] = value;
77
+ }
78
+ setProfilePinWorktreeResolverForTesting();
79
+ });
44
80
  const profilesPath = join(config, "profiles.json");
45
81
  const profiles = {
46
82
  team: { worker: { model: "openai/gpt-4o" } },
47
83
  empty: {},
48
- live: { orchestrator: { model: "openai/gpt-5.2", thinking: "high" } },
84
+ live: { ...startup?.routing, orchestrator: startup?.orchestrator ?? { model: "openai/gpt-5.2", thinking: "high" } },
49
85
  };
50
86
  const saveProfiles = () =>
51
87
  writeFileSync(
@@ -58,6 +94,23 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
58
94
  }),
59
95
  );
60
96
  saveProfiles();
97
+ const spawned: Array<{ args: string[]; cwd: string }> = [];
98
+ if (startup?.agents) {
99
+ const template = join(root, "git-template");
100
+ mkdirSync(template);
101
+ execFileSync("git", ["init", "--quiet", `--template=${template}`, root]);
102
+ mkdirSync(join(agentDir, "agents"));
103
+ writeFileSync(join(agentDir, "agents", "explore.md"), "---\ndescription: Offline launch probe\n---\nMap the target.");
104
+ }
105
+ const identity = { root, commonDir: join(root, "git-common") };
106
+ setProfilePinWorktreeResolverForTesting(() => identity);
107
+ if (startup?.layer) {
108
+ writeProfilePinSync(repoProfileDeclarationPath(root), startup.layer === "local" ? "team" : "live");
109
+ if (startup.layer === "local") writeProfilePinSync(localProfilePinPath(identity.commonDir), "live");
110
+ }
111
+ const settingsPath = join(agentDir, "settings.json");
112
+ const settings = '{"defaultProvider":"openai","defaultModel":"gpt-4o","defaultThinkingLevel":"off"}\n';
113
+ if (startup) writeFileSync(settingsPath, settings);
61
114
  const modelRuntime = await ModelRuntime.create({
62
115
  authPath: join(agentDir, "auth.json"),
63
116
  modelsPath: null,
@@ -73,7 +126,7 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
73
126
  let authCalls = 0,
74
127
  providerCalls = 0;
75
128
  let auth: () => Promise<unknown> = async () => ({ type: "api-key" });
76
- modelRuntime.hasConfiguredAuth = () => true;
129
+ modelRuntime.hasConfiguredAuth = () => !startup?.noAuth;
77
130
  modelRuntime.checkAuth = (async () => {
78
131
  authCalls++;
79
132
  return auth();
@@ -84,7 +137,16 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
84
137
  };
85
138
  const notices: Array<{ text: string; severity?: string }> = [],
86
139
  errors: string[] = [],
87
- events: string[] = [];
140
+ events: string[] = [],
141
+ tierEvents: unknown[] = [];
142
+ // A headless session has no notify surface; the extension reports through
143
+ // stderr, so the fixture captures console.error for assertions.
144
+ const headlessNotes: string[] = [];
145
+ const boundConsoleError = console.error;
146
+ if (startup?.headless) console.error = (...args: unknown[]) => void headlessNotes.push(args.map(String).join(" "));
147
+ t.after(() => {
148
+ if (startup?.headless) console.error = boundConsoleError;
149
+ });
88
150
  let selection: keyof typeof profiles | undefined;
89
151
  let currentApi: ExtensionAPI | undefined;
90
152
  let cancel = false;
@@ -92,6 +154,7 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
92
154
  theme: getThemeByName("dark")!,
93
155
  getAllThemes: () => [{ name: "dark" }],
94
156
  notify: (text: string, severity?: string) => notices.push({ text, severity }),
157
+ confirm: async () => true,
95
158
  setStatus() {},
96
159
  setWidget() {},
97
160
  custom(factory: Parameters<ExtensionUIContext["custom"]>[0]) {
@@ -143,6 +206,9 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
143
206
  const reload = async () => {
144
207
  extensionRuntime = createExtensionRuntime();
145
208
  const bus = createEventBus();
209
+ bus.on(PROFILE_TIER_EVENT, (event) => tierEvents.push(event));
210
+ const fastFirst = startup?.fastOrder === "fast-first"
211
+ ? await loadExtensionFromFactory(fast, root, bus, extensionRuntime) : undefined;
146
212
  loaded = [
147
213
  await loadExtensionFromFactory(
148
214
  (pi) => {
@@ -150,7 +216,7 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
150
216
  createGentleAiExtension({
151
217
  nativeReviewCli: null,
152
218
  candidateViews: null,
153
- processEnv: { GENTLE_PI_AGENTS_CHILD: "1" },
219
+ processEnv: startup?.env ?? { GENTLE_PI_AGENTS_CHILD: "1" },
154
220
  resolveTelemetryTriggerBinary: () => {
155
221
  throw Error("disabled fixture telemetry");
156
222
  },
@@ -186,6 +252,27 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
186
252
  extensionRuntime,
187
253
  ),
188
254
  ];
255
+ if (startup?.agents) loaded.push(await loadExtensionFromFactory(
256
+ (pi) => gentleAgents(pi, environment, {
257
+ home: root,
258
+ agentHome: agentDir,
259
+ env: environment,
260
+ resolveWorktree: resolveSessionWorktree,
261
+ pi: { command: "pi", args: [] },
262
+ spawn: (_command, args, options) => {
263
+ spawned.push({ args: [...args], cwd: options.cwd });
264
+ return fakeChild().child;
265
+ },
266
+ schedule: () => () => {},
267
+ sessionTransport: {
268
+ createRegistry: async () => ({ list: async () => [], listActivations: async () => [] }),
269
+ createListener: (registry) => ({ registry, start: async () => {}, close: async () => {} }),
270
+ createClient: () => ({ close() {}, sendNotification: async () => assert.fail("no peer messages") }),
271
+ },
272
+ }), root, bus, extensionRuntime,
273
+ ));
274
+ if (fastFirst) loaded.unshift(fastFirst);
275
+ else if (startup?.fastOrder === "ai-first") loaded.push(await loadExtensionFromFactory(fast, root, bus, extensionRuntime));
189
276
  };
190
277
  const loader: ResourceLoader = {
191
278
  getExtensions: () => ({
@@ -206,7 +293,7 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
206
293
  };
207
294
  await reload();
208
295
  const created = await createAgentSession({
209
- cwd: root,
296
+ cwd: manager.getCwd(),
210
297
  agentDir,
211
298
  modelRuntime,
212
299
  model: baseModel,
@@ -230,14 +317,14 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
230
317
  manager.appendMessage({ role: "user", content: "fixture", timestamp: 1 });
231
318
  const first = await make(manager, {
232
319
  type: "session_start",
233
- reason: "startup",
320
+ reason: startup?.reason ?? "startup",
234
321
  });
235
322
  const bind = (session: AgentSession) =>
236
- session.bindExtensions({
237
- uiContext: ui,
238
- mode: "tui",
239
- onError: (e) => errors.push(JSON.stringify(e)),
240
- });
323
+ session.bindExtensions(
324
+ startup?.headless
325
+ ? { mode: "print", onError: (e) => errors.push(JSON.stringify(e)) }
326
+ : { uiContext: ui, mode: "tui", onError: (e) => errors.push(JSON.stringify(e)) },
327
+ );
241
328
  await bind(first.session);
242
329
  const runtime = new AgentSessionRuntime(
243
330
  first.session,
@@ -257,8 +344,6 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
257
344
  runtime.setRebindSession(bind);
258
345
  t.after(async () => {
259
346
  await runtime.dispose();
260
- if (originalConfig === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
261
- else process.env.GENTLE_PI_CONFIG_HOME = originalConfig;
262
347
  rmSync(root, { recursive: true, force: true });
263
348
  assert.equal(providerCalls, 0);
264
349
  assert.deepEqual(errors, []);
@@ -292,10 +377,21 @@ async function fixture(t: test.TestContext, memory = false, flushed = true, acti
292
377
  ];
293
378
  return {
294
379
  root,
380
+ config,
381
+ spawned,
295
382
  runtime,
296
383
  manager,
384
+ settingsUnchanged: () => assert.equal(readFileSync(settingsPath, "utf8"), settings),
385
+ async startAt(cwd: string) {
386
+ const next = await make(SessionManager.inMemory(cwd), { type: "session_start", reason: "startup" });
387
+ await bind(next.session);
388
+ t.after(() => next.session.dispose());
389
+ return next.session;
390
+ },
297
391
  notices,
392
+ headlessNotes,
298
393
  events,
394
+ tierEvents,
299
395
  errors,
300
396
  profiles,
301
397
  saveProfiles,
@@ -576,6 +672,204 @@ for (const transition of ["fork", "tree", "reload", "new"] as const)
576
672
  assert.equal(f.authCalls(), 1);
577
673
  });
578
674
 
675
+ // A3: startup model selection through the real SDK, never the panel action.
676
+ for (const fastOrder of ["ai-first", "fast-first"] as const) {
677
+ test(`A3 startup notifies Fast and keeps its tier (${fastOrder})`, async (t) => {
678
+ const orchestrator = { model: "openai/gpt-6.1-sol", tier: "fast" as const };
679
+ const f = await fixture(t, false, false, "live", { env: {}, orchestrator, fastOrder });
680
+ assert.equal(f.runtime.session.model?.id, "gpt-6.1-sol");
681
+ assert.equal(f.authCalls(), 1);
682
+ assert.deepEqual(f.tierEvents, [{ sessionId: f.manager.getSessionId(), ...orchestrator }]);
683
+ const payload = { input: "fixture", service_tier: "flex" };
684
+ assert.deepEqual(await f.runtime.session.extensionRunner.emitBeforeProviderRequest(payload), { ...payload, service_tier: "priority" });
685
+ assert.deepEqual(payload, { input: "fixture", service_tier: "flex" });
686
+ assert.equal(f.family().length, 0, "notification does not publish a profile record");
687
+ f.settingsUnchanged();
688
+ });
689
+
690
+ test(`A3 Fast startup notification leaves settings.json byte-for-byte unchanged (${fastOrder})`, async (t) => {
691
+ const f = await fixture(t, false, false, "live", {
692
+ env: {}, orchestrator: { model: "openai/gpt-6.1-sol", tier: "fast" }, fastOrder,
693
+ });
694
+ assert.equal(f.tierEvents.length, 1, "startup sends the live-only notification");
695
+ f.settingsUnchanged();
696
+ await f.runtime.session.extensionRunner.emitBeforeProviderRequest({ input: "fixture" });
697
+ f.settingsUnchanged();
698
+ });
699
+
700
+ test(`A3 Use in this session preserves Fast notification after startup (${fastOrder})`, async (t) => {
701
+ const f = await fixture(t, false, false, undefined, {
702
+ env: {}, orchestrator: { model: "openai/gpt-6.1-sol", tier: "fast" }, fastOrder,
703
+ });
704
+ assert.deepEqual(await f.runtime.session.extensionRunner.emitBeforeProviderRequest({}), {});
705
+ await f.enter("live");
706
+ assert.equal(f.runtime.session.model?.id, "gpt-6.1-sol");
707
+ assert.deepEqual(f.tierEvents, [{ sessionId: f.manager.getSessionId(), ...f.profiles.live.orchestrator }]);
708
+ assert.deepEqual(await f.runtime.session.extensionRunner.emitBeforeProviderRequest({}), { service_tier: "priority" });
709
+ f.settingsUnchanged();
710
+ });
711
+ }
712
+
713
+ for (const layer of ["local", "repo", "global"] as const)
714
+ test(`A3 own start switches the ${layer} profile's orchestrator without settings writes`, async (t) => {
715
+ const f = await fixture(t, false, false, layer === "global" ? "live" : "team", { env: {}, ...(layer === "global" ? {} : { layer }) });
716
+ assert.equal(f.runtime.session.model?.id, "gpt-5.2");
717
+ assert.equal(f.runtime.session.thinkingLevel, "high");
718
+ assert.equal(f.authCalls(), 1);
719
+ assert.deepEqual(readFrozenDefaultOrchestrator(f.manager.getSessionId()), f.profiles.live.orchestrator);
720
+ assert.equal(f.family().length, 0, "startup does not publish an explicit selection");
721
+ assert.equal(f.binding(), undefined);
722
+ assert.ok(f.notices.some((n) => n.text.includes('profile "live"') && n.text.includes("This session now runs on openai/gpt-5.2 · high.")));
723
+ f.settingsUnchanged();
724
+ const before = f.protectedBytes();
725
+ await f.runtime.session.reload();
726
+ assert.equal(f.authCalls(), 1, "reload must not reapply the startup orchestrator");
727
+ assert.deepEqual(f.protectedBytes(), before);
728
+ });
729
+
730
+ for (const active of [undefined, "team"] as const)
731
+ test(`A3 own start keeps the model with ${active ?? "no profile"}`, async (t) => {
732
+ const f = await fixture(t, false, false, active, { env: {} });
733
+ assert.equal(f.runtime.session.model?.id, "gpt-4o");
734
+ assert.equal(f.runtime.session.thinkingLevel, "off");
735
+ assert.equal(f.authCalls(), 0);
736
+ assert.equal(f.family().length, 0);
737
+ if (active) assert.ok(f.notices.some((n) => n.text.includes('profile "team" has no orchestrator model; this session keeps its current model.')));
738
+ else assert.equal(f.notices.some((n) => /orchestrator|current model|now runs/.test(n.text)), false);
739
+ f.settingsUnchanged();
740
+ });
741
+
742
+ for (const failure of ["model", "credentials"] as const)
743
+ test(`A3 missing ${failure} keeps the current model and notifies`, async (t) => {
744
+ const f = await fixture(t, false, false, "live", {
745
+ env: {},
746
+ ...(failure === "model" ? { orchestrator: { model: "openai/not-in-catalog", thinking: "high" as const } } : { noAuth: true }),
747
+ });
748
+ assert.equal(f.runtime.session.model?.id, "gpt-4o");
749
+ assert.equal(f.runtime.session.thinkingLevel, "off");
750
+ assert.equal(f.authCalls(), 0);
751
+ assert.equal(f.family().length, 0);
752
+ assert.equal(f.binding(), undefined);
753
+ const text = failure === "model"
754
+ ? "openai/not-in-catalog is not in the model catalog; this session keeps its current model."
755
+ : "no authentication is configured for openai; this session keeps its current model.";
756
+ assert.ok(f.notices.some((n) => n.text.includes(text)), JSON.stringify(f.notices));
757
+ f.settingsUnchanged();
758
+ });
759
+
760
+ test(`A3 headless own start reports the switch outcome on stderr`, async (t) => {
761
+ const f = await fixture(t, false, false, "live", {
762
+ env: {},
763
+ orchestrator: { model: "openai/not-in-catalog", thinking: "high" as const },
764
+ headless: true,
765
+ });
766
+ assert.equal(f.runtime.session.model?.id, "gpt-4o");
767
+ assert.equal(f.authCalls(), 0);
768
+ assert.equal(f.family().length, 0);
769
+ assert.ok(
770
+ f.headlessNotes.some((line) =>
771
+ line.includes('profile "live"') &&
772
+ line.includes("openai/not-in-catalog is not in the model catalog; this session keeps its current model")),
773
+ JSON.stringify(f.headlessNotes),
774
+ );
775
+ assert.equal(f.notices.length, 0, "a headless session has no UI notifications");
776
+ f.settingsUnchanged();
777
+ });
778
+
779
+ for (const env of [{ GENTLE_PI_PROFILE_FOLLOW: "1" }, { GENTLE_PI_AGENTS_CHILD: "1" }])
780
+ test(`A3 ${Object.keys(env)[0]} skips startup switching and freezing`, async (t) => {
781
+ const f = await fixture(t, false, false, "live", { env });
782
+ assert.equal(f.runtime.session.model?.id, "gpt-4o");
783
+ assert.equal(f.runtime.session.thinkingLevel, "off");
784
+ assert.equal(f.authCalls(), 0);
785
+ assert.equal(readFrozenInheritedProfile(f.manager.getSessionId()), undefined);
786
+ assert.equal(f.notices.some((n) => /orchestrator|current model|now runs/.test(n.text)), false);
787
+ f.settingsUnchanged();
788
+ });
789
+
790
+ for (const reason of ["new", "resume", "fork"] as const)
791
+ test(`A3 ${reason} respects the own-start reason guard`, async (t) => {
792
+ const f = await fixture(t, false, false, "live", { env: {}, reason });
793
+ assert.equal(f.runtime.session.model?.id, reason === "new" ? "gpt-5.2" : "gpt-4o");
794
+ assert.equal(f.authCalls(), reason === "new" ? 1 : 0);
795
+ f.settingsUnchanged();
796
+ });
797
+
798
+ test("A3 an existing conversation does not switch at process startup", async (t) => {
799
+ const f = await fixture(t, false, true, "live", { env: {} });
800
+ assert.equal(f.runtime.session.model?.id, "gpt-4o");
801
+ assert.equal(f.authCalls(), 0);
802
+ f.settingsUnchanged();
803
+ });
804
+
805
+ test("A3 a foreign repository session resolves its own profile, not the parent's frozen orchestrator", async (t) => {
806
+ const f = await fixture(t, false, false, "live", { env: {} });
807
+ assert.equal(f.runtime.session.model?.id, "gpt-5.2");
808
+ const foreign = join(f.root, "foreign");
809
+ mkdirSync(foreign);
810
+ const identity = { root: foreign, commonDir: join(foreign, "git-common") };
811
+ setProfilePinWorktreeResolverForTesting(() => identity);
812
+ writeProfilePinSync(localProfilePinPath(identity.commonDir), "team");
813
+ const child = await f.startAt(foreign);
814
+ assert.equal(child.model?.id, "gpt-4o", "the foreign profile has no orchestrator");
815
+ assert.equal(f.authCalls(), 1, "the parent switch is not repeated for the foreign session");
816
+ assert.equal(f.runtime.session.model?.id, "gpt-5.2", "the parent's model stays independent");
817
+ // Existing inherited ROLE routing still belongs to its session across targets.
818
+ const resolution = resolveSessionProfile({ sessionId: f.manager.getSessionId(), cwd: f.root, configHome: f.config });
819
+ assert.deepEqual(sessionProfileRoutingAt(resolution, { cwd: foreign, configHome: f.config, foreignRepository: true }), {});
820
+ assert.equal(readFrozenDefaultOrchestrator(child.sessionManager.getSessionId()), undefined);
821
+ f.settingsUnchanged();
822
+ });
823
+
824
+ for (const active of ["live", undefined] as const)
825
+ test(`A3 foreign launch from the started session preserves its model and frozen routing (${active ?? "no profile"})`, async (t) => {
826
+ const routing = { explore: { model: "openai/gpt-5.2", thinking: "low" as const } };
827
+ const f = await fixture(t, false, false, active, { env: {}, agents: true, routing });
828
+ const session = f.runtime.session;
829
+ assert.equal(session.model?.id, active ? "gpt-5.2" : "gpt-4o");
830
+ assert.equal(session.thinkingLevel, active ? "high" : "off");
831
+ assert.equal(f.authCalls(), active ? 1 : 0, "only the profiled own start switches");
832
+ const frozen = readFrozenInheritedProfile(f.manager.getSessionId());
833
+ assert.ok(frozen, "own start froze the session's inherited routing");
834
+ assert.equal(frozen.profile?.name, active);
835
+ f.settingsUnchanged();
836
+ const foreign = join(f.root, "foreign");
837
+ execFileSync("git", ["init", "--quiet", `--template=${join(f.root, "git-template")}`, foreign]);
838
+ const foreignIdentity = resolveSessionWorktree(foreign, f.root)!;
839
+ assert.ok(foreignIdentity);
840
+ // A competing orchestrator makes any accidental target-start switch observable.
841
+ Object.assign(f.profiles.team, {
842
+ orchestrator: { model: "openai/gpt-4o", thinking: "minimal" },
843
+ explore: { model: "openai/gpt-4o", thinking: "minimal" },
844
+ });
845
+ f.saveProfiles();
846
+ writeProfilePinSync(localProfilePinPath(foreignIdentity.commonDir), "team");
847
+ const runner = session.extensionRunner;
848
+ const launch = runner.getToolDefinition("subagent_run");
849
+ assert.ok(launch);
850
+ const ctx = runner.createContext() as unknown as Parameters<typeof launch.execute>[4];
851
+ const setModel = t.mock.method(session, "setModel");
852
+ const before = { model: session.model, thinking: session.thinkingLevel, auth: f.authCalls(), events: [...f.events] };
853
+ const result = await launch.execute("a3-foreign", {
854
+ agent: "explore", task: "Map the foreign target without provider requests.", repository_root: foreign, mode: "background",
855
+ }, undefined, undefined, ctx);
856
+ await new Promise((resolve) => setImmediate(resolve));
857
+ assert.equal(result.isError, undefined);
858
+ assert.equal(f.spawned.length, 1, "the launch reaches the offline child spawn");
859
+ assert.equal(f.spawned[0].cwd, foreign);
860
+ const args = f.spawned[0].args;
861
+ assert.ok(args.includes("--model"));
862
+ assert.equal(args[args.indexOf("--model") + 1], active ? "openai/gpt-5.2:low" : "openai/gpt-4o:minimal",
863
+ active ? "the frozen profile wins over the foreign pin" : "a session frozen without a profile uses the foreign pin");
864
+ assert.equal(f.runtime.session, session, "launch uses the already-started parent");
865
+ assert.equal(session.model, before.model);
866
+ assert.equal(session.thinkingLevel, before.thinking);
867
+ assert.equal(f.authCalls(), before.auth, "foreign launch does not authenticate another own-start switch");
868
+ assert.equal(setModel.mock.callCount(), 0, "foreign launch never switches the live parent model");
869
+ assert.deepEqual(f.events, before.events, "launch does not emit another session start");
870
+ f.settingsUnchanged();
871
+ });
872
+
579
873
  // gentle-shell#2742, section 3: a new session knows the startup state it froze.
580
874
  const data = (entry: unknown) => (entry as { data?: unknown } | undefined)?.data;
581
875
  for (const active of ["live", undefined] as const)
@@ -15,6 +15,8 @@ import {
15
15
  profileFollowEnabled,
16
16
  sessionProfileRoutingAt,
17
17
  readFrozenInheritedProfile,
18
+ readFrozenDefaultOrchestrator,
19
+ setFrozenDefaultOrchestrator,
18
20
  resetFrozenInheritedProfilesForTesting,
19
21
  readSessionProfileOwnStartup,
20
22
  resolveInheritedProfile,
@@ -483,6 +485,30 @@ test("own start captures the startup profile with its full definition, orchestra
483
485
  assert.deepEqual(JSON.parse(JSON.stringify(readSessionProfileOwnStartup("session-a"))), { origin: "global", name: "team", modelProfiles: TEAM });
484
486
  });
485
487
 
488
+ test("own start freezes the full orchestrator without requiring a tier, independently of role routing", () => {
489
+ const f = fixture({ team: { ...TEAM, orchestrator: { model: "openai/gpt-5", thinking: "high" } } });
490
+ f.setActive("team");
491
+ const opts = options(f, "session-a");
492
+ freezeSessionProfileAtOwnStart(opts);
493
+ const entry = readFrozenDefaultOrchestrator("session-a");
494
+ assert.deepEqual(entry, { model: "openai/gpt-5", thinking: "high" });
495
+ entry!.model = "mutated";
496
+ f.editProfile("team", LOCAL);
497
+ freezeSessionProfileAtOwnStart(opts);
498
+ assert.deepEqual(readFrozenDefaultOrchestrator("session-a"), { model: "openai/gpt-5", thinking: "high" }, "first startup wins and readers cannot mutate it");
499
+ assert.deepEqual(JSON.parse(JSON.stringify(sessionProfileModelProfiles(resolveSessionProfile(opts)))), { worker: TEAM.worker });
500
+ });
501
+
502
+ test("Make default still updates only its applying session's frozen orchestrator", () => {
503
+ const entry = { model: "openai/gpt-5", tier: "fast" as const };
504
+ setFrozenDefaultOrchestrator("session-a", entry);
505
+ entry.model = "mutated";
506
+ assert.deepEqual(readFrozenDefaultOrchestrator("session-a"), { model: "openai/gpt-5", tier: "fast" });
507
+ assert.equal(readFrozenDefaultOrchestrator("session-b"), undefined);
508
+ setFrozenDefaultOrchestrator("session-a", undefined);
509
+ assert.equal(readFrozenDefaultOrchestrator("session-a"), undefined);
510
+ });
511
+
486
512
  test("a session frozen by a plain resume has no known startup state", () => {
487
513
  const f = fixture();
488
514
  f.setActive("team");