gentle-pi 4.5.1 → 4.7.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 (428) hide show
  1. package/README.md +17 -15
  2. package/assets/agents/gentle-ai-explore.md +1 -0
  3. package/assets/agents/gentle-ai-verify.md +8 -1
  4. package/assets/agents/gentle-ai-worker.md +4 -0
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +1 -0
  7. package/assets/agents/jd-judge-b.md +1 -0
  8. package/assets/design-canvas/canvas.css +13 -1
  9. package/assets/design-canvas/canvas.js +11 -2
  10. package/assets/install-wizard/wizard.js +1 -0
  11. package/assets/migrations/agent-body-history.json +162 -0
  12. package/assets/orchestrator-delegation-reference.md +7 -7
  13. package/assets/orchestrator-delegation.md +3 -3
  14. package/assets/orchestrator-full-delegation-card.md +65 -0
  15. package/assets/orchestrator-full-delegation.md +34 -0
  16. package/assets/orchestrator-memory.md +3 -3
  17. package/assets/orchestrator-prompts.md +1 -1
  18. package/assets/orchestrator-skills.md +1 -1
  19. package/assets/orchestrator-verification.md +14 -8
  20. package/assets/orchestrator.md +11 -11
  21. package/bin/gentle-shell.mjs +225 -82
  22. package/docs/agent-status.md +61 -0
  23. package/docs/bundled-install.md +7 -5
  24. package/docs/ci-performance.md +11 -0
  25. package/docs/delegated-verification.md +35 -7
  26. package/docs/fast-mode.md +15 -0
  27. package/docs/gentle-agents-activity.md +22 -0
  28. package/docs/gentle-shell.md +113 -25
  29. package/docs/install-wizard.md +2 -2
  30. package/docs/mcp-status.md +52 -0
  31. package/docs/permission-modes.md +9 -4
  32. package/docs/prompt-budget.md +28 -0
  33. package/docs/readme-reference.md +154 -50
  34. package/docs/render-cache-performance.md +11 -1
  35. package/docs/review-coordinator.md +33 -0
  36. package/docs/review-request-context.md +19 -0
  37. package/docs/review-windows-acl.md +18 -0
  38. package/docs/session-profile-format.md +20 -5
  39. package/docs/sound-notifications.md +1 -1
  40. package/docs/star-prompt.md +32 -0
  41. package/docs/voice.md +6 -3
  42. package/docs/work-continuity.md +46 -0
  43. package/docs/yolo-mode.md +5 -5
  44. package/extensions/ask-user-choice.ts +1 -0
  45. package/extensions/ask-user-question.ts +2 -0
  46. package/extensions/child-safety.ts +3 -0
  47. package/extensions/codegraph-tools.ts +38 -4
  48. package/extensions/gentle-agent-status.ts +99 -0
  49. package/extensions/gentle-agents.ts +803 -84
  50. package/extensions/gentle-ai.ts +2491 -596
  51. package/extensions/gentle-fast.ts +61 -0
  52. package/extensions/gentle-guide.ts +174 -0
  53. package/extensions/gentle-herdr-activity.ts +21 -1
  54. package/extensions/gentle-herdr-agent.ts +144 -0
  55. package/extensions/gentle-program-identity.ts +61 -0
  56. package/extensions/gentle-shell.ts +895 -120
  57. package/extensions/gentle-star-prompt.ts +334 -0
  58. package/extensions/gentle-stats.ts +5 -5
  59. package/extensions/gentle-todo.ts +59 -23
  60. package/extensions/gentle-tps.ts +48 -0
  61. package/extensions/history/store.ts +18 -12
  62. package/extensions/quiet-tools.ts +38 -8
  63. package/extensions/skill-registry.ts +210 -21
  64. package/extensions/startup-banner.ts +69 -10
  65. package/lib/agent-assets.ts +74 -17
  66. package/lib/agent-profile-pin.ts +3 -3
  67. package/lib/agent-profiles.ts +161 -3
  68. package/lib/agent-status.ts +105 -0
  69. package/lib/agents-config.ts +58 -3
  70. package/lib/agents-history.ts +24 -5
  71. package/lib/agents-keys.ts +8 -16
  72. package/lib/agents-messaging.ts +47 -5
  73. package/lib/agents-protocol.ts +80 -4
  74. package/lib/agents-runner.ts +287 -15
  75. package/lib/agents-view.ts +6 -1
  76. package/lib/agents-widget.ts +132 -9
  77. package/lib/auto-permission-runtime.ts +1 -1
  78. package/lib/bounded-writer-admission.ts +13 -1
  79. package/lib/bridge-cost.ts +28 -0
  80. package/lib/card-content-policy.ts +8 -6
  81. package/lib/codemode-renderer.ts +16 -0
  82. package/lib/command-palette-catalog.ts +1 -0
  83. package/lib/command-palette.ts +154 -25
  84. package/lib/context-backstop.ts +14 -5
  85. package/lib/destructive-command-guard.ts +48 -4
  86. package/lib/execution-surface-guard.ts +20 -0
  87. package/lib/exploration-budget.ts +64 -0
  88. package/lib/gentle-ai-binary.ts +1 -1
  89. package/lib/gentle-design.ts +3 -0
  90. package/lib/gentle-guide.ts +201 -0
  91. package/lib/gentle-shell-bundled.ts +6 -19
  92. package/lib/gentle-shell-launcher.ts +47 -8
  93. package/lib/herdr-activity.ts +23 -5
  94. package/lib/herdr-busy.ts +45 -0
  95. package/lib/herdr-task-summary-policy.ts +85 -0
  96. package/lib/image-attachments.ts +33 -0
  97. package/lib/image-disk-cache.ts +137 -0
  98. package/lib/inprocess-reviewer.ts +282 -132
  99. package/lib/jobs-sidebar-state.ts +5 -6
  100. package/lib/jobs-view.ts +198 -11
  101. package/lib/jobs-widget.ts +16 -52
  102. package/lib/keymaps-customize.ts +81 -0
  103. package/lib/keymaps.ts +291 -0
  104. package/lib/model-fallback-notice.ts +61 -0
  105. package/lib/model-fallback-policy.ts +141 -0
  106. package/lib/model-fallback-store.ts +143 -0
  107. package/lib/model-routing-authority.ts +32 -6
  108. package/lib/nan-provider.ts +3 -2
  109. package/lib/native-choice-list.ts +20 -2
  110. package/lib/native-review-cli.ts +103 -21
  111. package/lib/notification-customize.ts +48 -51
  112. package/lib/openai-fast-tier.ts +22 -0
  113. package/lib/orchestrator-discovery.ts +5 -1
  114. package/lib/orchestrator-fallback.ts +75 -0
  115. package/lib/orchestrator-mode-policy.ts +105 -0
  116. package/lib/pasted-image-paths.ts +113 -0
  117. package/lib/questionnaire/questionnaire-view.ts +225 -18
  118. package/lib/rdd-mode-control.ts +32 -0
  119. package/lib/reply-language-anchor.ts +104 -0
  120. package/lib/review-blocker.ts +92 -0
  121. package/lib/review-candidate-symlink-scan.ts +136 -0
  122. package/lib/review-candidate-view-owner.ts +85 -44
  123. package/lib/review-candidate-view.ts +10 -7
  124. package/lib/review-continuation-registry.ts +99 -0
  125. package/lib/review-coordinator.ts +163 -0
  126. package/lib/review-failure-facts.ts +49 -0
  127. package/lib/review-host-relay.ts +51 -11
  128. package/lib/review-integration-v2.ts +29 -8
  129. package/lib/review-relay-phase-timing.ts +45 -0
  130. package/lib/review-repository.ts +5 -0
  131. package/lib/review-start-context.ts +17 -0
  132. package/lib/session-profile-append-controller.ts +21 -6
  133. package/lib/session-profile-authority.ts +119 -0
  134. package/lib/session-profile-binding.ts +54 -5
  135. package/lib/session-profile-freeze.ts +107 -9
  136. package/lib/session-profile-integration.ts +313 -0
  137. package/lib/session-profile-persistence.ts +63 -9
  138. package/lib/shell-bar.ts +269 -72
  139. package/lib/shell-card.ts +26 -6
  140. package/lib/shell-changes.ts +2 -0
  141. package/lib/shell-page.ts +120 -0
  142. package/lib/shell-panel.ts +163 -0
  143. package/lib/shell-prompt.ts +53 -1
  144. package/lib/shell-sidebar-layout.ts +198 -53
  145. package/lib/shell-sidebar.ts +61 -1
  146. package/lib/shell-stats.ts +123 -0
  147. package/lib/shell-todo.ts +79 -1
  148. package/lib/shell-usage.ts +12 -2
  149. package/lib/star-prompt.ts +197 -0
  150. package/lib/verifier-admission.ts +18 -8
  151. package/lib/verifier-settle-reminder.ts +64 -0
  152. package/lib/vim-editor-adapter.ts +6 -1
  153. package/lib/visual-customization-policy.ts +67 -12
  154. package/lib/visual-customize-view.ts +373 -40
  155. package/lib/visual-layout-preview.ts +47 -0
  156. package/lib/visual-profiles.ts +2 -2
  157. package/lib/windows-session-transport.ts +53 -2
  158. package/lib/yolo-session-policy.ts +68 -16
  159. package/package.json +2 -1
  160. package/runtime/gentle-ai-binary.mjs +1 -1
  161. package/runtime/gentle-shell-bundled.mjs +6 -19
  162. package/runtime/gentle-shell-launcher.mjs +46 -7
  163. package/runtime/native-review-cli.mjs +100 -18
  164. package/runtime/review-integration-v2.mjs +29 -8
  165. package/runtime/windows-session-transport.ps1 +60 -3
  166. package/scripts/bootstrap.sh +4 -1
  167. package/scripts/build-full-delegation-card.mjs +175 -0
  168. package/scripts/bundled-install.mjs +38 -8
  169. package/scripts/download-progress.mjs +68 -0
  170. package/scripts/gentle-ai-installer.mjs +41 -18
  171. package/scripts/gentle-ai-proxy.mjs +294 -0
  172. package/scripts/install-gentle-ai.mjs +14 -1
  173. package/scripts/installer-preflight.mjs +6 -6
  174. package/scripts/installer-runner.mjs +27 -12
  175. package/scripts/installer-server.mjs +8 -7
  176. package/scripts/pi-update.mjs +113 -3
  177. package/scripts/render-cache-host.mjs +72 -0
  178. package/scripts/render-cache-performance-worker.mjs +5 -4
  179. package/scripts/render-cache-performance.mjs +6 -1
  180. package/scripts/run-test-suite.mjs +41 -13
  181. package/scripts/shell-snapshot.mjs +340 -0
  182. package/scripts/test-packed-runner.mjs +1 -1
  183. package/scripts/update-agent-body-history.mjs +41 -0
  184. package/scripts/verify-installer-tap.mjs +45 -0
  185. package/scripts/verify-package-files.mjs +14 -2
  186. package/scripts/voice-worker.cjs +32 -6
  187. package/skills/design/SKILL.md +11 -8
  188. package/skills/gentle-ai/SKILL.md +4 -4
  189. package/skills/gentle-ui-design/SKILL.md +46 -0
  190. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  191. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  192. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  193. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  194. package/skills/skill-registry/SKILL.md +4 -2
  195. package/skills/tui-design/NOTICE.md +5 -0
  196. package/skills/tui-design/SKILL.md +56 -0
  197. package/skills/tui-design/references/commands.md +75 -0
  198. package/skills/tui-design/references/critique.md +48 -0
  199. package/skills/tui-design/references/design-doc.md +44 -0
  200. package/skills/tui-design/references/terminal-craft.md +64 -0
  201. package/skills/tui-design/references/visual-loop.md +32 -0
  202. package/skills/work-unit-commits/SKILL.md +6 -7
  203. package/tests/agent-home.test.ts +28 -9
  204. package/tests/agent-profiles-workflow.test.ts +163 -0
  205. package/tests/agent-risk-escalation.test.ts +1 -1
  206. package/tests/agent-status.test.ts +143 -0
  207. package/tests/agents-config.test.ts +96 -0
  208. package/tests/agents-history.test.ts +31 -0
  209. package/tests/agents-jobs-frames.test.ts +93 -0
  210. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  211. package/tests/agents-protocol.test.ts +53 -1
  212. package/tests/agents-runner-drain.test.ts +193 -0
  213. package/tests/agents-runner.test.ts +345 -4
  214. package/tests/agents-view.test.ts +27 -0
  215. package/tests/agents-widget.test.ts +312 -10
  216. package/tests/append-system-prompt-route.test.ts +4 -1
  217. package/tests/ask-user-choice.test.ts +4 -3
  218. package/tests/ask-user-question.test.ts +97 -0
  219. package/tests/auto-permission-runtime.test.ts +1 -1
  220. package/tests/autonomous-guard.test.ts +346 -10
  221. package/tests/bounded-scan-contract.test.ts +39 -0
  222. package/tests/bounded-stop-contract.test.ts +43 -3
  223. package/tests/bridge-cost.test.ts +47 -0
  224. package/tests/bundled-install.test.ts +36 -9
  225. package/tests/card-content-policy.test.ts +3 -3
  226. package/tests/chained-pr-skill.test.ts +8 -6
  227. package/tests/child-safety.test.ts +11 -0
  228. package/tests/ci-concurrency.test.ts +11 -0
  229. package/tests/ci-merge-base-identity.test.ts +114 -0
  230. package/tests/codegraph-tools.test.ts +80 -5
  231. package/tests/codemode-rendering.test.ts +22 -2
  232. package/tests/command-palette.test.ts +300 -3
  233. package/tests/commit-slice-signal.test.ts +11 -9
  234. package/tests/delegate-for-reason-contract.test.ts +8 -7
  235. package/tests/design-canvas-assets.test.ts +185 -2
  236. package/tests/destructive-command-guard.test.ts +52 -0
  237. package/tests/download-progress.test.ts +71 -0
  238. package/tests/execution-surface-guard.test.ts +55 -0
  239. package/tests/exploration-budget.test.ts +128 -0
  240. package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
  241. package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
  242. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +26 -14
  243. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  244. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  245. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  246. package/tests/fixtures/session-profile-v1/replay.ts +172 -0
  247. package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
  248. package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
  249. package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
  250. package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
  251. package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
  252. package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
  253. package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
  254. package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
  255. package/tests/full-delegation-closure.test.ts +131 -0
  256. package/tests/full-delegation-notices.test.ts +76 -0
  257. package/tests/generic-agent-tools.test.ts +3 -3
  258. package/tests/gentle-agent-status.test.ts +74 -0
  259. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  260. package/tests/gentle-agents.test.ts +1491 -38
  261. package/tests/gentle-ai-binary.test.ts +3 -1
  262. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  263. package/tests/gentle-ai-exploration-budget.test.ts +151 -0
  264. package/tests/gentle-ai-installer.test.ts +134 -51
  265. package/tests/gentle-ai-proxy.test.ts +434 -0
  266. package/tests/gentle-ai.test.ts +1101 -52
  267. package/tests/gentle-design.test.ts +21 -0
  268. package/tests/gentle-fast.test.ts +73 -0
  269. package/tests/gentle-guide.test.ts +208 -0
  270. package/tests/gentle-herdr-activity.test.ts +80 -3
  271. package/tests/gentle-herdr-agent.test.ts +111 -0
  272. package/tests/gentle-program-identity.test.ts +197 -0
  273. package/tests/gentle-shell-bin.test.ts +172 -26
  274. package/tests/gentle-shell-bundled.test.ts +207 -31
  275. package/tests/gentle-shell-launcher.test.ts +93 -10
  276. package/tests/gentle-shell.test.ts +1937 -66
  277. package/tests/gentle-stats.test.ts +15 -2
  278. package/tests/gentle-todo.test.ts +67 -4
  279. package/tests/gentle-tps.test.ts +123 -0
  280. package/tests/gentle-ui-design-skill.test.ts +59 -0
  281. package/tests/herdr-busy.test.ts +59 -0
  282. package/tests/herdr-task-summary-policy.test.ts +132 -0
  283. package/tests/history-store-private-mode.test.ts +40 -0
  284. package/tests/image-disk-cache.test.ts +163 -0
  285. package/tests/image-paste-chips.test.ts +42 -0
  286. package/tests/independent-recovery-delivery.test.ts +83 -0
  287. package/tests/inprocess-reviewer.test.ts +298 -4
  288. package/tests/installer-posix-bootstrap.test.ts +68 -6
  289. package/tests/installer-preflight.test.ts +5 -4
  290. package/tests/installer-runner.test.ts +79 -44
  291. package/tests/installer-server.test.ts +14 -11
  292. package/tests/installer-windows-diagnostics.test.ts +4 -5
  293. package/tests/isolated-config-home.ts +28 -0
  294. package/tests/jobs-view.test.ts +260 -6
  295. package/tests/jobs-widget.test.ts +25 -37
  296. package/tests/keymaps-customize.test.ts +114 -0
  297. package/tests/keymaps.test.ts +103 -0
  298. package/tests/maintainer/mcp-status.maintest.ts +88 -0
  299. package/tests/maintainer/pi-update-source.maintest.ts +116 -0
  300. package/tests/modal-mouse-boundaries.test.ts +136 -0
  301. package/tests/model-fallback-notice.test.ts +45 -0
  302. package/tests/model-fallback-policy.test.ts +83 -0
  303. package/tests/model-fallback-store.test.ts +111 -0
  304. package/tests/model-routing-authority.test.ts +178 -2
  305. package/tests/nan-provider.test.ts +4 -4
  306. package/tests/native-choice-list.test.ts +77 -2
  307. package/tests/native-review-capability-contract.test.ts +7 -1
  308. package/tests/native-review-cli.test.ts +269 -1
  309. package/tests/no-self-pause-contract.test.ts +22 -0
  310. package/tests/notification-customize.test.ts +58 -34
  311. package/tests/odd-routing-canonical-ratchet.test.ts +6 -6
  312. package/tests/odd-routing-contract.test.ts +1 -1
  313. package/tests/orchestrator-budget.test.ts +7 -2
  314. package/tests/orchestrator-delegation-mode.test.ts +153 -0
  315. package/tests/orchestrator-fallback.test.ts +82 -0
  316. package/tests/orchestrator-mode-policy.test.ts +175 -0
  317. package/tests/orchestrator-prompt-budget.test.ts +133 -0
  318. package/tests/orchestrator-rdd-ownership.test.ts +2 -2
  319. package/tests/package-manifest.test.ts +169 -14
  320. package/tests/pasted-image-paths.test.ts +118 -0
  321. package/tests/permission-allowlist.test.ts +202 -0
  322. package/tests/persona-reply-language.test.ts +20 -1
  323. package/tests/pi-update-launcher.test.ts +40 -8
  324. package/tests/pi-update-source.test.ts +162 -0
  325. package/tests/pnpm-workspace-config.test.ts +58 -0
  326. package/tests/primary-session-prompt.test.ts +13 -0
  327. package/tests/profile-fast-tier.test.ts +311 -0
  328. package/tests/profile-pin.test.ts +29 -2
  329. package/tests/profile-tier-footer.test.ts +84 -0
  330. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  331. package/tests/questionnaire-view.test.ts +265 -0
  332. package/tests/quiet-bash-runtime.test.ts +1 -1
  333. package/tests/quiet-tool-rendering.test.ts +48 -0
  334. package/tests/rdd-aware-verification-contract.test.ts +16 -11
  335. package/tests/rdd-customize.test.ts +287 -0
  336. package/tests/rdd-mode-cache.test.ts +450 -0
  337. package/tests/rdd-mode-control.test.ts +407 -0
  338. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  339. package/tests/rdd-off-independent-regression.test.ts +69 -0
  340. package/tests/rdd-status-line.test.ts +18 -0
  341. package/tests/render-cache-performance.test.ts +171 -2
  342. package/tests/reply-language-anchor.test.ts +173 -0
  343. package/tests/review-agent-end-preflight.test.ts +1 -1
  344. package/tests/review-blocker.test.ts +193 -0
  345. package/tests/review-candidate-owner-retry.test.ts +1 -1
  346. package/tests/review-candidate-owner-sweep.test.ts +93 -0
  347. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  348. package/tests/review-candidate-view.test.ts +52 -1
  349. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  350. package/tests/review-candidate-windows-probe.test.ts +63 -0
  351. package/tests/review-committed-restart-ack.test.ts +129 -0
  352. package/tests/review-continuation-registry.test.ts +76 -0
  353. package/tests/review-controller-native-routing.test.ts +381 -11
  354. package/tests/review-controller-workspace-root.test.ts +230 -3
  355. package/tests/review-controller.test.ts +96 -11
  356. package/tests/review-coordinator-runtime.test.ts +117 -0
  357. package/tests/review-coordinator.test.ts +195 -0
  358. package/tests/review-failure-facts.test.ts +87 -0
  359. package/tests/review-gate.test.ts +24 -0
  360. package/tests/review-host-relay-routing.test.ts +258 -4
  361. package/tests/review-host-relay.test.ts +39 -0
  362. package/tests/review-inspect-preflight.test.ts +197 -0
  363. package/tests/review-integration-v2-forward.test.ts +59 -0
  364. package/tests/review-integration-v2.test.ts +46 -3
  365. package/tests/review-json-arguments.test.ts +65 -10
  366. package/tests/review-last-event-closure.test.ts +68 -0
  367. package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
  368. package/tests/review-owner-identity.test.ts +60 -24
  369. package/tests/review-relay-phase-timing.test.ts +128 -0
  370. package/tests/review-relay-transport-agent.test.ts +12 -2
  371. package/tests/review-repository.test.ts +52 -1
  372. package/tests/review-reviewer-evidence.test.ts +183 -0
  373. package/tests/review-risk-assessment.test.ts +74 -3
  374. package/tests/review-session-standing-permission-controller.test.ts +21 -1
  375. package/tests/review-sidebar-state.test.ts +5 -5
  376. package/tests/review-start-context.test.ts +19 -0
  377. package/tests/review-tool-prose-budget.test.ts +121 -0
  378. package/tests/run-test-suite.test.ts +183 -6
  379. package/tests/runtime-harness.mjs +4 -1
  380. package/tests/sensitive-path-tools.test.ts +250 -0
  381. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  382. package/tests/session-profile-append-controller.test.ts +63 -0
  383. package/tests/session-profile-authority.test.ts +259 -0
  384. package/tests/session-profile-binding.test.ts +34 -1
  385. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  386. package/tests/session-profile-extension.test.ts +615 -0
  387. package/tests/session-profile-freeze.test.ts +110 -2
  388. package/tests/session-profile-integration.test.ts +857 -0
  389. package/tests/session-profile-persistence.test.ts +57 -0
  390. package/tests/session-profile-v1-compat.test.ts +255 -0
  391. package/tests/shell-bar.test.ts +274 -72
  392. package/tests/shell-card.test.ts +13 -1
  393. package/tests/shell-page.test.ts +108 -0
  394. package/tests/shell-panel.test.ts +360 -0
  395. package/tests/shell-prompt.test.ts +54 -0
  396. package/tests/shell-render-cache.test.ts +5 -0
  397. package/tests/shell-sidebar-fullscreen.test.ts +13 -1
  398. package/tests/shell-sidebar-layout.test.ts +447 -44
  399. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  400. package/tests/shell-stats.test.ts +90 -0
  401. package/tests/shell-surface-transparent.test.ts +89 -0
  402. package/tests/shell-todo.test.ts +12 -0
  403. package/tests/shell-usage.test.ts +14 -0
  404. package/tests/skill-registry.test.ts +902 -2
  405. package/tests/star-prompt.test.ts +470 -0
  406. package/tests/startup-banner.test.ts +209 -2
  407. package/tests/startup-home-repo.test.ts +2 -0
  408. package/tests/support/review-coordinator-runtime.ts +69 -0
  409. package/tests/task-size-routing-contract.test.ts +50 -4
  410. package/tests/verifier-admission.test.ts +49 -0
  411. package/tests/verifier-settle-reminder.test.ts +281 -0
  412. package/tests/verify-first-launch-contract.test.ts +134 -8
  413. package/tests/verify-installer-tap.test.ts +57 -0
  414. package/tests/vim-editor-adapter.test.ts +2 -2
  415. package/tests/visual-customization-policy.test.ts +95 -8
  416. package/tests/visual-customize-view.test.ts +818 -9
  417. package/tests/visual-layout-preview.test.ts +42 -0
  418. package/tests/visual-profiles.test.ts +11 -0
  419. package/tests/voice-worker.test.ts +73 -2
  420. package/tests/windows-session-bootstrap.test.ts +105 -2
  421. package/tests/windows-session-transport.test.ts +126 -0
  422. package/tests/work-continuity-contract.test.ts +114 -0
  423. package/tests/writer-feature-document-admission.test.ts +92 -0
  424. package/tests/writer-surfaces.test.ts +12 -10
  425. package/tests/yolo-customize.test.ts +57 -15
  426. package/tests/yolo-mode-runtime.test.ts +4 -2
  427. package/tests/yolo-mode.test.ts +39 -20
  428. package/tests/yolo-session-policy.test.ts +270 -1
@@ -0,0 +1,163 @@
1
+ import test from "node:test";
2
+ import assert from "node:assert/strict";
3
+ import { mkdtempSync, statSync, existsSync, readFileSync, mkdirSync, writeFileSync, utimesSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import { ImageDiskCache, defaultCacheRoot } from "../lib/image-disk-cache.ts";
7
+ import { ImageAttachments } from "../lib/image-attachments.ts";
8
+
9
+ function tempRoot(): string {
10
+ return mkdtempSync(join(tmpdir(), "gentle-image-cache-"));
11
+ }
12
+
13
+ const PNG = new Uint8Array([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]);
14
+
15
+ test("the cache root honours XDG_CACHE_HOME and falls back to ~/.cache", () => {
16
+ const xdg = join(tmpdir(), "custom-cache");
17
+ assert.equal(defaultCacheRoot({ XDG_CACHE_HOME: xdg }, "/home/u"), join(xdg, "gentle-shell", "images"));
18
+ assert.equal(defaultCacheRoot({}, "/home/u"), join("/home/u", ".cache", "gentle-shell", "images"));
19
+ assert.equal(defaultCacheRoot({ XDG_CACHE_HOME: "" }, "/home/u"), join("/home/u", ".cache", "gentle-shell", "images"));
20
+ });
21
+
22
+ test("a session id cannot escape its own directory", () => {
23
+ const root = tempRoot();
24
+ const cache = new ImageDiskCache({ root, sessionId: "../../etc" });
25
+ assert.equal(cache.directory, join(root, "etc"));
26
+ assert.ok(cache.directory.startsWith(root));
27
+ });
28
+
29
+ test("writing stores the exact bytes with a private directory and file", () => {
30
+ const root = tempRoot();
31
+ const cache = new ImageDiskCache({ root, sessionId: "s1" });
32
+ const path = cache.write(1, PNG, "image/png");
33
+
34
+ assert.ok(path, "write must return the file path");
35
+ assert.deepEqual(new Uint8Array(readFileSync(path)), PNG);
36
+ if (process.platform !== "win32") {
37
+ // Windows has no POSIX owner/group/other bits; the mode is accepted but not enforced.
38
+ assert.equal(statSync(cache.directory).mode & 0o777, 0o700, "session directory is private");
39
+ assert.equal(statSync(path).mode & 0o777, 0o600, "image file is private");
40
+ }
41
+ });
42
+
43
+ test("the file extension follows the mime type", () => {
44
+ const root = tempRoot();
45
+ const cache = new ImageDiskCache({ root, sessionId: "s1" });
46
+ assert.match(cache.write(2, PNG, "image/jpeg") ?? "", /image-2\.jpg$/);
47
+ });
48
+
49
+ test("a write that cannot happen degrades instead of throwing", () => {
50
+ const blocked = join(tempRoot(), "not-a-directory");
51
+ writeFileSync(blocked, "x");
52
+ const cache = new ImageDiskCache({ root: blocked, sessionId: "s1" });
53
+ assert.equal(cache.write(1, PNG, "image/png"), undefined);
54
+ });
55
+
56
+ test("disposing removes only this session's directory", () => {
57
+ const root = tempRoot();
58
+ const mine = new ImageDiskCache({ root, sessionId: "mine" });
59
+ const other = new ImageDiskCache({ root, sessionId: "other" });
60
+ mine.write(1, PNG, "image/png");
61
+ const otherPath = other.write(1, PNG, "image/png");
62
+
63
+ mine.dispose();
64
+
65
+ assert.equal(existsSync(mine.directory), false, "own directory is gone");
66
+ assert.ok(otherPath && existsSync(otherPath), "another session is untouched");
67
+ });
68
+
69
+ test("the sweep removes stale sessions and keeps fresh ones", () => {
70
+ const root = tempRoot();
71
+ const stale = new ImageDiskCache({ root, sessionId: "stale" });
72
+ const fresh = new ImageDiskCache({ root, sessionId: "fresh" });
73
+ const staleFile = stale.write(1, PNG, "image/png")!;
74
+ fresh.write(1, PNG, "image/png");
75
+ const longAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
76
+ utimesSync(staleFile, longAgo, longAgo);
77
+
78
+ const removed = ImageDiskCache.sweepStale(root, 7 * 24 * 60 * 60 * 1000);
79
+
80
+ assert.equal(removed, 1);
81
+ assert.equal(existsSync(stale.directory), false, "old session removed");
82
+ assert.ok(existsSync(fresh.directory), "fresh session kept");
83
+ });
84
+
85
+ test("a relative XDG_CACHE_HOME is ignored, as the spec requires", () => {
86
+ assert.equal(defaultCacheRoot({ XDG_CACHE_HOME: "cache" }, "/home/u"), join("/home/u", ".cache", "gentle-shell", "images"));
87
+ });
88
+
89
+ test("runtime cache changes work: setCache reports paths, dropping it stops them", () => {
90
+ const root = tempRoot();
91
+ const attachments = new ImageAttachments();
92
+ assert.equal(attachments.cachedPaths().length, 0, "no cache, nothing to report");
93
+
94
+ attachments.setCache(new ImageDiskCache({ root, sessionId: "s1" }));
95
+ const withCache = attachments.add({ bytes: PNG, mimeType: "image/png" } as never);
96
+ assert.deepEqual(attachments.cachedPaths(), [{ token: withCache.token, path: withCache.diskPath }]);
97
+
98
+ attachments.setCache(undefined);
99
+ const withoutCache = attachments.add({ bytes: PNG, mimeType: "image/png" } as never);
100
+ assert.equal(withoutCache.diskPath, undefined, "dropping the cache stops new paths");
101
+ assert.equal(attachments.cachedPaths().length, 1, "earlier paths still registered");
102
+ });
103
+
104
+ test("cachedPaths only reports chips the draft still references", () => {
105
+ const root = tempRoot();
106
+ const attachments = new ImageAttachments(new ImageDiskCache({ root, sessionId: "s1" }));
107
+ const first = attachments.add({ bytes: PNG, mimeType: "image/png" } as never);
108
+ const second = attachments.add({ bytes: PNG, mimeType: "image/png" } as never);
109
+
110
+ assert.equal(attachments.cachedPaths(`${first.token} ${second.token}`).length, 2);
111
+ const kept = attachments.cachedPaths(`only ${second.token} survives`);
112
+ assert.deepEqual(kept, [{ token: second.token, path: second.diskPath }], "a deleted chip is not reported");
113
+ attachments.dispose();
114
+ });
115
+
116
+ test("a failed cache write leaves the chip usable without a path", () => {
117
+ const blocked = join(tempRoot(), "not-a-directory");
118
+ writeFileSync(blocked, "x");
119
+ const attachments = new ImageAttachments(new ImageDiskCache({ root: blocked, sessionId: "s1" }));
120
+ const attachment = attachments.add({ bytes: PNG, mimeType: "image/png" } as never);
121
+ assert.equal(attachment.diskPath, undefined);
122
+ assert.ok(attachment.base64.length > 0, "the payload is still intact");
123
+ assert.deepEqual(attachments.cachedPaths(), [], "nothing to report");
124
+ });
125
+
126
+ test("the sweep leaves a directory that also holds a file it did not write", () => {
127
+ const root = tempRoot();
128
+ const mixed = new ImageDiskCache({ root, sessionId: "mixed" });
129
+ const own = mixed.write(1, PNG, "image/png")!;
130
+ const foreign = join(mixed.directory, "notes.txt");
131
+ writeFileSync(foreign, "someone else");
132
+ const longAgo = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000);
133
+ utimesSync(own, longAgo, longAgo);
134
+
135
+ const removed = ImageDiskCache.sweepStale(root, 7 * 24 * 60 * 60 * 1000);
136
+
137
+ assert.equal(removed, 0, "a directory with foreign content is not removed");
138
+ assert.ok(existsSync(foreign), "the foreign file survives");
139
+ });
140
+
141
+ test("the sweep never deletes outside the cache root", () => {
142
+ const root = tempRoot();
143
+ const outside = mkdtempSync(join(tmpdir(), "gentle-outside-"));
144
+ mkdirSync(join(outside, "victim"));
145
+ assert.equal(ImageDiskCache.sweepStale(outside, 0), 0);
146
+ assert.ok(existsSync(join(outside, "victim")), "a foreign directory is left alone");
147
+ });
148
+
149
+ test("attachments keep their in-memory contract and gain a path only when a cache is given", () => {
150
+ const plain = new ImageAttachments();
151
+ const withoutCache = plain.add({ bytes: PNG, mimeType: "image/png" } as never);
152
+ assert.equal(withoutCache.diskPath, undefined, "no cache, no path, old behaviour");
153
+ assert.ok(withoutCache.base64.length > 0, "base64 stays the source of truth");
154
+
155
+ const root = tempRoot();
156
+ const withCache = new ImageAttachments(new ImageDiskCache({ root, sessionId: "s1" }));
157
+ const withPath = withCache.add({ bytes: PNG, mimeType: "image/png" } as never);
158
+ assert.ok(withPath.diskPath && existsSync(withPath.diskPath), "path exists on disk");
159
+ assert.ok(withPath.token.startsWith("[Image#"), "chip token unchanged");
160
+
161
+ withCache.dispose();
162
+ assert.equal(existsSync(join(root, "s1")), false, "dispose clears the session directory");
163
+ });
@@ -7,6 +7,9 @@ import type { ClipboardImage } from "../lib/clipboard-image.ts";
7
7
  import { ImageAttachments } from "../lib/image-attachments.ts";
8
8
  import { createVimEditorAdapter } from "../lib/vim-editor-adapter.ts";
9
9
  import { createRequire } from "node:module";
10
+ import { mkdtempSync, writeFileSync } from "node:fs";
11
+ import { tmpdir } from "node:os";
12
+ import { join } from "node:path";
10
13
 
11
14
  const INSTALLED_PI = (createRequire(import.meta.url)("@earendil-works/pi-tui/package.json") as { version: string }).version;
12
15
 
@@ -234,3 +237,42 @@ test("models without declared input capabilities are treated as image-capable",
234
237
  assert.equal(modelAcceptsImages({ input: ["text", "image"] }), true);
235
238
  assert.equal(modelAcceptsImages({ input: ["text"] }), false);
236
239
  });
240
+
241
+ // Herdr hands an image to a terminal on another machine (desktop app, --remote)
242
+ // as a temp-file path, and drops or file-manager copies arrive as quoted paths.
243
+ // A paste made only of image paths becomes chips; any other paste stays Pi's.
244
+
245
+ function imagePaste(text: string) {
246
+ return `\x1b[200~${text}\x1b[201~`;
247
+ }
248
+
249
+ function temporaryImage(name = "herdr-paste-1.png"): string {
250
+ const directory = mkdtempSync(join(tmpdir(), "gentle-paste-"));
251
+ const path = join(directory, name);
252
+ writeFileSync(path, PNG_2X1);
253
+ return path;
254
+ }
255
+
256
+ test("a pasted image path becomes a chip instead of text", () => {
257
+ const { editor, attachments } = chipEditor(async () => png());
258
+ editor.setText("look");
259
+ editor.handleInput(imagePaste(`${temporaryImage()}\n`));
260
+ assert.equal(editor.getText(), "look [Image#1]");
261
+ assert.equal(attachments.size, 1);
262
+ });
263
+
264
+ test("several quoted image paths from a drop become one chip each", () => {
265
+ const first = temporaryImage("a.png");
266
+ const second = temporaryImage("b.png");
267
+ const { editor, attachments } = chipEditor(async () => png());
268
+ editor.handleInput(imagePaste(`'${first}' '${second}' `));
269
+ assert.equal(editor.getText(), "[Image#1] [Image#2]");
270
+ assert.equal(attachments.size, 2);
271
+ });
272
+
273
+ test("a paste that is not only image paths stays Pi's normal text paste", () => {
274
+ const path = temporaryImage();
275
+ const { editor } = chipEditor(async () => png());
276
+ editor.handleInput(imagePaste(`look at ${path}`));
277
+ assert.equal(editor.getText(), `look at ${path}`);
278
+ });
@@ -0,0 +1,83 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdirSync, mkdtempSync, readFileSync, rmSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test, { after, before } from "node:test";
6
+ import { __testing } from "../extensions/gentle-ai.ts";
7
+ import { parseAgentDefinition } from "../lib/agents-config.ts";
8
+
9
+ const read = (p: string) => readFileSync(new URL(`../${p}`, import.meta.url), "utf8");
10
+ const paragraph = (p: string, prefix: string) => {
11
+ const text = p.split("\n\n").find(s => s.startsWith(prefix));
12
+ assert.ok(text, prefix);
13
+ return text;
14
+ };
15
+ let cwd: string;
16
+ let prior: string | undefined;
17
+ before(() => {
18
+ cwd = mkdtempSync(join(tmpdir(), "recovery-delivery-"));
19
+ prior = process.env.GENTLE_PI_CONFIG_HOME;
20
+ process.env.GENTLE_PI_CONFIG_HOME = join(cwd, "config");
21
+ mkdirSync(join(cwd, "project"));
22
+ });
23
+ after(() => {
24
+ if (prior === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
25
+ else process.env.GENTLE_PI_CONFIG_HOME = prior;
26
+ rmSync(cwd, { recursive: true, force: true });
27
+ });
28
+
29
+ // S2-S5: positive setup/implementation routes and negative authority boundaries
30
+ // must coexist in the delivered parent prompt, in every persona and RDD mode.
31
+ for (const persona of ["gentleman", "neutral"] as const) {
32
+ for (const mode of ["on", "off", "unknown"]) {
33
+ test(`S2-S5 delivered recovery is bounded: ${persona}/${mode}`, () => {
34
+ const p = __testing.buildGentlePrompt(persona, join(cwd, "project"), ["read"], `Receipt-driven development: ${mode}`);
35
+ assert.equal(p.split("## Authorized work continuity").length, 2);
36
+ const setup = paragraph(p, "A failed verifier setup");
37
+ assert.match(setup, /prerequisite is repaired, the human may explicitly request one new bounded verification attempt/);
38
+ assert.match(setup, /zero tests run; the checks remain unverified/);
39
+ assert.match(setup, /unavailable verifier remains unavailable; do not retry or escalate it/);
40
+ for (const guard of ["consent", "a denial", "one-run", "no-retry", "terminal native outcomes", "exhausted native budgets"]) assert.ok(setup.includes(guard), guard);
41
+ assert.match(setup, /no child is active or has an uncertain status/);
42
+ const worker = paragraph(p, "An exhausted worker-local");
43
+ assert.match(worker, /scope, executor, correction limit and checks/);
44
+ assert.match(worker, /later explicit human request is separate and remains subject to native authority/);
45
+ assert.match(worker, /new session does not reset any limit/);
46
+ assert.match(worker, /specifically authorized.*actual native authority.*in-scope compilation or implementation/);
47
+ assert.match(worker, /unavailable proof still blocks completion and delivery/);
48
+ assert.match(worker, /no child is active or has an uncertain status/);
49
+ assert.match(p, /7\. \*\*Close\.\*\*[^\n]*never more verification/);
50
+ assert.doesNotMatch(p, /Stop only for[^\n]*unavailable required proof/);
51
+ });
52
+ }
53
+ }
54
+
55
+ test("S3-S5 parsed worker and verifier contracts retain confinement and proof limits", () => {
56
+ const agent = (name: string) => {
57
+ const p = `assets/agents/gentle-ai-${name}.md`;
58
+ const parsed = parseAgentDefinition(read(p), p, "global");
59
+ assert.ok(!("error" in parsed));
60
+ return parsed;
61
+ };
62
+ const worker = agent("worker");
63
+ assert.match(worker.instructions, /handoff is not authorization to continue/);
64
+ assert.match(worker.instructions, /Do not start a fresh correction cycle/);
65
+ assert.match(worker.instructions, /missing proof still blocks completion and delivery/);
66
+ const verify = agent("verify");
67
+ assert.deepEqual(verify.tools, ["read", "grep", "find", "bash", "mcp__codegraph__codegraph_explore"]);
68
+ assert.match(verify.instructions, /Before isolated setup[^\n]*space and inodes/);
69
+ assert.match(verify.instructions, /smaller copy[^\n]*all source, test\/build files, baseline material, and dependencies/);
70
+ assert.match(verify.instructions, /first inability[^\n]*stop setup/);
71
+ assert.match(verify.instructions, /setup fails before probes[^\n]*zero tests run/);
72
+ assert.match(verify.instructions, /Do not retry setup or enter repair-helper loops/);
73
+ for (const guard of ["system temp directory", "a symlink into the workspace", "No network, no installs, no writes outside", "NODE_COMPILE_CACHE", "NO_UPDATE_NOTIFIER=1"]) assert.ok(verify.instructions.includes(guard), guard);
74
+ });
75
+
76
+ test("S2-S5 user recovery docs retain the independent-proof and native-authority boundaries", () => {
77
+ const docs = read("docs/delegated-verification.md");
78
+ assert.match(docs, /static inspection and parent tests do not replace the missing independent runtime proof/);
79
+ assert.match(docs, /no instantiated native budget[^\n]*grants no review approval/);
80
+ assert.match(docs, /Missing required proof still blocks completion and delivery/);
81
+ assert.match(docs, /active or uncertain child prevents continuation/);
82
+ assert.match(docs, /explicit one-run\/no-retry limit/);
83
+ });
@@ -1,4 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
+ import { getEventListeners } from "node:events";
3
+ import { setImmediate as nextTurn } from "node:timers/promises";
2
4
  import test from "node:test";
3
5
  import type { Api, AssistantMessage, Context, Model, SimpleStreamOptions } from "@earendil-works/pi-ai";
4
6
  import type { completeSimple } from "@earendil-works/pi-ai/compat";
@@ -221,6 +223,11 @@ test("refuses when the reviewer attempts a tool call", async () => {
221
223
  assert.equal(refused.code, INPROCESS_REVIEWER_FAILURE.TOOL_CALL_ATTEMPTED);
222
224
  });
223
225
 
226
+ function withoutRunTiming(evidence: Record<string, unknown> | undefined): Record<string, unknown> {
227
+ const { durationMs, authDurationMs, completionDurationMs, ...facts } = evidence ?? {};
228
+ return facts;
229
+ }
230
+
224
231
  test("refuses empty assistant text with safe completion evidence", async () => {
225
232
  const assistant = assistantText("", { content: [], stopReason: "stop" });
226
233
  const outcome = await runInProcessReviewer(baseRequest(), {
@@ -229,9 +236,11 @@ test("refuses empty assistant text with safe completion evidence", async () => {
229
236
  });
230
237
  const refused = expectRefused(outcome);
231
238
  assert.equal(refused.code, INPROCESS_REVIEWER_FAILURE.EMPTY_OUTPUT);
232
- assert.deepEqual(refused.evidence, {
239
+ assert.deepEqual(withoutRunTiming(refused.evidence), {
240
+ phase: "completion", provider: "openai",
233
241
  reviewerModel: "openai/gpt-5", stopReason: "stop",
234
242
  usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0 },
243
+ cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 },
235
244
  content: { blocks: 0, textBlocks: 0, thinkingBlocks: 0, textChars: 0, thinkingChars: 0 },
236
245
  });
237
246
  });
@@ -249,7 +258,8 @@ test("empty-output diagnostics allowlist facts, not provider secrets, and comple
249
258
  }));
250
259
  assert.equal(refused.code, INPROCESS_REVIEWER_FAILURE.EMPTY_OUTPUT);
251
260
  assert.equal(calls.length, 1);
252
- assert.deepEqual(refused.evidence, {
261
+ assert.deepEqual(withoutRunTiming(refused.evidence), {
262
+ phase: "completion", provider: "nan",
253
263
  reviewerModel: "nan/deepseek-v4-flash", stopReason: "length",
254
264
  usage: { input: 12, output: 64, reasoning: 64, cacheRead: 0, cacheWrite: 0, totalTokens: 76 },
255
265
  content: { blocks: 2, textBlocks: 1, thinkingBlocks: 1, textChars: 0, thinkingChars: 16 },
@@ -377,6 +387,166 @@ test("refuses with ABORTED when the provider resolves partial text after the cal
377
387
  });
378
388
 
379
389
  // ---------------------------------------------------------------------------
390
+ // Host deadlines must settle even when an auth/provider implementation ignores
391
+ // cancellation. The independent watchdog makes a broken implementation fail
392
+ // without leaving this suite waiting indefinitely.
393
+ function deferred<T>() {
394
+ let resolve!: (value: T) => void;
395
+ let reject!: (reason: unknown) => void;
396
+ const promise = new Promise<T>((yes, no) => { resolve = yes; reject = no; });
397
+ return { promise, resolve, reject };
398
+ }
399
+ // Capture real timers before per-test mocks: a broken handshake must still
400
+ // fail independently even while the reviewer deadline is driven manually.
401
+ const watchdogSetTimeout = setTimeout;
402
+ const watchdogClearTimeout = clearTimeout;
403
+ async function bounded<T>(promise: Promise<T>): Promise<T> {
404
+ let timer: ReturnType<typeof setTimeout>;
405
+ try {
406
+ return await Promise.race([promise, new Promise<never>((_, reject) => {
407
+ timer = watchdogSetTimeout(() => reject(new Error("reviewer did not settle within the independent 250ms watchdog")), 250);
408
+ })]);
409
+ } finally { watchdogClearTimeout(timer!); }
410
+ }
411
+
412
+ test("host deadline bounds authentication that never resolves", async () => {
413
+ let completions = 0;
414
+ const outcome = await bounded(runInProcessReviewer(baseRequest({ timeoutMs: 15 }), {
415
+ registry: fakeRegistry([fakeModel()], async () => await new Promise(() => {})),
416
+ complete: (async () => { completions++; return assistantText("must not run"); }) as typeof completeSimple,
417
+ }));
418
+ assert.equal(expectRefused(outcome).code, INPROCESS_REVIEWER_FAILURE.TIMED_OUT);
419
+ assert.equal(completions, 0);
420
+ });
421
+
422
+ test("host deadline skips auth and dispatch for an already cancelled caller", async () => {
423
+ const caller = new AbortController(); caller.abort();
424
+ let authentications = 0, completions = 0;
425
+ const outcome = await runInProcessReviewer(baseRequest({ signal: caller.signal }), {
426
+ registry: fakeRegistry([fakeModel()], async () => { authentications++; return { ok: true, apiKey: "fixture" }; }),
427
+ complete: (async () => { completions++; return assistantText("must not run"); }) as typeof completeSimple,
428
+ });
429
+ assert.equal(expectRefused(outcome).code, INPROCESS_REVIEWER_FAILURE.ABORTED);
430
+ assert.equal(authentications, 0); assert.equal(completions, 0);
431
+ });
432
+
433
+ for (const stop of ["caller", "deadline"] as const) {
434
+ test(`host deadline does not dispatch after late authentication following ${stop}`, async () => {
435
+ const auth = deferred<Awaited<ReturnType<InProcessReviewerRegistry["getApiKeyAndHeaders"]>>>();
436
+ const caller = new AbortController();
437
+ let completions = 0;
438
+ const pending = runInProcessReviewer(baseRequest({ signal: caller.signal, timeoutMs: stop === "deadline" ? 15 : 30_000 }), {
439
+ registry: fakeRegistry([fakeModel()], () => auth.promise),
440
+ complete: (async () => { completions++; return assistantText("must not run"); }) as typeof completeSimple,
441
+ });
442
+ if (stop === "caller") caller.abort();
443
+ try {
444
+ const outcome = await bounded(pending);
445
+ assert.equal(expectRefused(outcome).code, stop === "caller" ? INPROCESS_REVIEWER_FAILURE.ABORTED : INPROCESS_REVIEWER_FAILURE.TIMED_OUT);
446
+ } finally { auth.resolve({ ok: true, apiKey: "fixture" }); }
447
+ await nextTurn();
448
+ assert.equal(completions, 0);
449
+ });
450
+ }
451
+
452
+ for (const composed of [false, true]) {
453
+ for (const late of ["fulfill", "reject"] as const) {
454
+ test(`host deadline settles non-cooperative ${composed ? "composed" : "compat"} completion and consumes late ${late}`, { timeout: 5_000 }, async t => {
455
+ let clock = 0;
456
+ t.mock.method(performance, "now", () => clock);
457
+ t.mock.timers.enable({ apis: ["setTimeout"] });
458
+ const completion = deferred<AssistantMessage>(), entered = deferred<void>();
459
+ const registry = fakeRegistry([fakeModel()]);
460
+ let calls = 0, providerSignal: AbortSignal | undefined;
461
+ const complete = (async (_model, _context, options) => { calls++; providerSignal = options?.signal; entered.resolve(); return await completion.promise; }) as typeof completeSimple;
462
+ if (composed) registry.getProvider = () => ({ streamSimple: (model, context, options) => ({ result: () => complete(model, context, options) }) });
463
+ const pending = runInProcessReviewer(baseRequest({ timeoutMs: 15 }), { registry, complete });
464
+ try {
465
+ // This test targets a completion already dispatched. Contention
466
+ // before auth/dispatch must not expire its deadline accidentally.
467
+ await bounded(entered.promise);
468
+ assert.equal(calls, 1);
469
+ clock = 15; t.mock.timers.tick(15);
470
+ const outcome = await bounded(pending);
471
+ assert.equal(expectRefused(outcome).code, INPROCESS_REVIEWER_FAILURE.TIMED_OUT);
472
+ assert.equal(providerSignal?.aborted, true); assert.equal(calls, 1);
473
+ } finally {
474
+ if (late === "fulfill" || calls === 0) completion.resolve(assistantText("late text must never be admitted"));
475
+ else completion.reject(new Error("late provider rejection must be consumed"));
476
+ }
477
+ await nextTurn();
478
+ });
479
+ }
480
+ test(`host deadline bounds caller cancellation of a non-cooperative ${composed ? "composed" : "compat"} completion`, async () => {
481
+ const completion = deferred<AssistantMessage>(), entered = deferred<void>();
482
+ const caller = new AbortController(), registry = fakeRegistry([fakeModel()]);
483
+ let providerSignal: AbortSignal | undefined;
484
+ const complete = (async (_model, _context, options) => { providerSignal = options?.signal; entered.resolve(); return await completion.promise; }) as typeof completeSimple;
485
+ if (composed) registry.getProvider = () => ({ streamSimple: (model, context, options) => ({ result: () => complete(model, context, options) }) });
486
+ const pending = runInProcessReviewer(baseRequest({ signal: caller.signal }), { registry, complete });
487
+ try {
488
+ await bounded(entered.promise);
489
+ caller.abort();
490
+ assert.equal(expectRefused(await bounded(pending)).code, INPROCESS_REVIEWER_FAILURE.ABORTED);
491
+ assert.equal(providerSignal?.aborted, true);
492
+ assert.equal(getEventListeners(caller.signal, "abort").length, 0);
493
+ assert.equal(getEventListeners(providerSignal!, "abort").length, 0);
494
+ } finally { caller.abort(); completion.resolve(assistantText("late text")); }
495
+ await nextTurn();
496
+ });
497
+ }
498
+
499
+ test("host deadline checks monotonic elapsed time after auth before the timer can run", async t => {
500
+ let clock = 0, calls = 0;
501
+ t.mock.method(performance, "now", () => clock);
502
+ const auth = deferred<Awaited<ReturnType<InProcessReviewerRegistry["getApiKeyAndHeaders"]>>>();
503
+ const pending = runInProcessReviewer(baseRequest({ timeoutMs: 100 }), {
504
+ registry: fakeRegistry([fakeModel()], () => auth.promise),
505
+ complete: (async () => { calls++; return assistantText("must not run"); }) as typeof completeSimple,
506
+ });
507
+ clock = 101;
508
+ auth.resolve({ ok: true, apiKey: "fixture" });
509
+ assert.equal(expectRefused(await bounded(pending)).code, INPROCESS_REVIEWER_FAILURE.TIMED_OUT);
510
+ assert.equal(calls, 0);
511
+ });
512
+
513
+ test("host deadline takes precedence when caller cancellation is observed after expiry", async t => {
514
+ let clock = 0;
515
+ t.mock.method(performance, "now", () => clock);
516
+ const caller = new AbortController();
517
+ const pending = runInProcessReviewer(baseRequest({ timeoutMs: 100, signal: caller.signal }), {
518
+ registry: fakeRegistry([fakeModel()], async () => await new Promise(() => {})), complete: unreachableComplete,
519
+ });
520
+ clock = 100;
521
+ caller.abort();
522
+ assert.equal(expectRefused(await bounded(pending)).code, INPROCESS_REVIEWER_FAILURE.TIMED_OUT);
523
+ });
524
+
525
+ test("host deadline removes its caller listener when authentication throws", async () => {
526
+ const caller = new AbortController(), expected = new Error("auth fixture");
527
+ await assert.rejects(runInProcessReviewer(baseRequest({ signal: caller.signal }), {
528
+ registry: fakeRegistry([fakeModel()], async () => { throw expected; }), complete: unreachableComplete,
529
+ }), error => error === expected);
530
+ assert.equal(getEventListeners(caller.signal, "abort").length, 0);
531
+ });
532
+
533
+ test("host deadline cleans caller/provider listeners and its timer after success", async t => {
534
+ t.mock.timers.enable({ apis: ["setTimeout"] });
535
+ const caller = new AbortController();
536
+ let providerSignal: AbortSignal | undefined;
537
+ const outcome = await runInProcessReviewer(baseRequest({ signal: caller.signal }), {
538
+ registry: fakeRegistry([fakeModel()]),
539
+ complete: (async (_model, _context, options) => { providerSignal = options?.signal; return assistantText("done"); }) as typeof completeSimple,
540
+ });
541
+ assert.equal(expectText(outcome).text, "done");
542
+ assert.equal(getEventListeners(caller.signal, "abort").length, 0);
543
+ assert.equal(getEventListeners(providerSignal!, "abort").length, 0);
544
+ t.mock.timers.tick(30_000);
545
+ assert.equal(providerSignal?.aborted, false, "a completed call must not retain a deadline timer");
546
+ caller.abort();
547
+ assert.equal(providerSignal?.aborted, false, "a completed call must detach its caller signal");
548
+ });
549
+
380
550
  // Exact Context passed to complete
381
551
  // ---------------------------------------------------------------------------
382
552
 
@@ -396,6 +566,100 @@ test("passes exactly one user message with the verbatim prompt, no systemPrompt,
396
566
  assert.ok(!("tools" in calls[0]!.context));
397
567
  });
398
568
 
569
+ // ---------------------------------------------------------------------------
570
+ // Resolved auth context — synthetic OAuth-like endpoint and provider env
571
+ // ---------------------------------------------------------------------------
572
+
573
+ for (const dispatch of ["composed provider", "compatibility complete"] as const) {
574
+ function captureDispatch() {
575
+ const provider = capturingProvider(assistantText("ok"));
576
+ const compatibility = capturingComplete(assistantText("ok"));
577
+ return {
578
+ getProvider: dispatch === "composed provider" ? provider.getProvider : undefined,
579
+ complete: dispatch === "composed provider" ? unreachableComplete : compatibility.complete,
580
+ calls: dispatch === "composed provider" ? provider.calls : compatibility.calls,
581
+ };
582
+ }
583
+
584
+ test(`${dispatch} preserves the registry's exchanged key, headers, account endpoint, and env`, async () => {
585
+ const original = Object.freeze(fakeModel({ provider: "github-copilot", baseUrl: "https://api.individual.githubcopilot.com" }));
586
+ const snapshot = { ...original };
587
+ const baseUrl = "https://api.synthetic-account.githubcopilot.com";
588
+ const headers = Object.freeze({ "x-synthetic-auth": "registry-header", "x-suppress-default": null });
589
+ const env = Object.freeze({ RDD_SYNTHETIC_PROVIDER_REGION: "test-region" });
590
+ const ambientBefore = process.env.RDD_SYNTHETIC_PROVIDER_REGION;
591
+ const { getProvider, complete, calls } = captureDispatch();
592
+ const outcome = await runInProcessReviewer(baseRequest({ selection: "github-copilot/gpt-5" }), {
593
+ registry: {
594
+ ...fakeRegistry([original], async (resolvedModel) => {
595
+ assert.equal(resolvedModel, original, "auth must resolve against the registry model");
596
+ return { ok: true, apiKey: "synthetic-exchanged-access-token", headers, baseUrl, env };
597
+ }),
598
+ ...(getProvider === undefined ? {} : { getProvider }),
599
+ },
600
+ complete,
601
+ });
602
+ assert.equal(expectText(outcome).reviewerModel, "github-copilot/gpt-5");
603
+ assert.equal(calls.length, 1);
604
+ assert.deepEqual(calls[0]!.model, { ...snapshot, baseUrl });
605
+ assert.notEqual(calls[0]!.model, original, "the endpoint override needs a request-local model");
606
+ assert.equal(calls[0]!.options?.apiKey, "synthetic-exchanged-access-token");
607
+ assert.equal(calls[0]!.options?.headers, headers);
608
+ assert.equal(calls[0]!.options?.env, env);
609
+ assert.deepEqual(original, snapshot, "shared registry state must remain unchanged");
610
+ assert.equal(process.env.RDD_SYNTHETIC_PROVIDER_REGION, ambientBefore, "env must be forwarded, not installed globally");
611
+ });
612
+
613
+ test(`${dispatch} forwards env without an endpoint override`, async () => {
614
+ const original = Object.freeze(fakeModel());
615
+ const env = Object.freeze({ RDD_SYNTHETIC_PROVIDER_REGION: "env-only-region" });
616
+ const { getProvider, complete, calls } = captureDispatch();
617
+ expectText(await runInProcessReviewer(baseRequest(), {
618
+ registry: {
619
+ ...fakeRegistry([original], async () => ({ ok: true, apiKey: "synthetic-key", env })),
620
+ ...(getProvider === undefined ? {} : { getProvider }),
621
+ },
622
+ complete,
623
+ }));
624
+ assert.equal(calls[0]!.model, original);
625
+ assert.equal(calls[0]!.options?.env, env);
626
+ });
627
+
628
+ test(`${dispatch} preserves model defaults and omits unresolved env`, async () => {
629
+ const original = Object.freeze(fakeModel());
630
+ const { getProvider, complete, calls } = captureDispatch();
631
+ expectText(await runInProcessReviewer(baseRequest(), {
632
+ registry: { ...fakeRegistry([original]), ...(getProvider === undefined ? {} : { getProvider }) },
633
+ complete,
634
+ }));
635
+ assert.equal(calls[0]!.model, original);
636
+ assert.equal(calls[0]!.model.baseUrl, "https://api.openai.com");
637
+ assert.ok(!("env" in (calls[0]!.options ?? {})));
638
+ });
639
+
640
+ for (const routedToOpenCode of [true, false]) {
641
+ test(`${dispatch} uses the resolved endpoint for attribution when routed ${routedToOpenCode ? "to" : "away from"} OpenCode`, async () => {
642
+ const original = Object.freeze(fakeModel({
643
+ provider: "custom",
644
+ baseUrl: routedToOpenCode ? "https://default.invalid" : "https://opencode.ai/v1",
645
+ }));
646
+ const baseUrl = routedToOpenCode ? "https://opencode.ai/v1" : "https://account.invalid/v1";
647
+ const { getProvider, complete, calls } = captureDispatch();
648
+ expectText(await runInProcessReviewer(baseRequest({ selection: "custom/gpt-5", sessionId: "ses-synthetic" }), {
649
+ registry: {
650
+ ...fakeRegistry([original], async () => ({ ok: true, apiKey: "synthetic-key", baseUrl })),
651
+ ...(getProvider === undefined ? {} : { getProvider }),
652
+ },
653
+ complete,
654
+ }));
655
+ assert.deepEqual(calls[0]!.options?.headers, routedToOpenCode
656
+ ? { "x-opencode-session": "ses-synthetic", "x-opencode-client": "pi" }
657
+ : undefined);
658
+ assert.equal(calls[0]!.model.baseUrl, baseUrl);
659
+ });
660
+ }
661
+ }
662
+
399
663
  // ---------------------------------------------------------------------------
400
664
  // Thinking mapping
401
665
  // ---------------------------------------------------------------------------
@@ -470,6 +734,34 @@ for (const { name, model, selection } of OPENCODE_ATTRIBUTION_TESTS) {
470
734
  });
471
735
  }
472
736
 
737
+ test("each completion carries its own sessionId, never the parent session's", async () => {
738
+ const { complete, calls } = capturingComplete(assistantText("ok"));
739
+ const deps = { registry: fakeRegistry([fakeModel({ provider: "anthropic", id: "claude-sonnet-4" })]), complete };
740
+ expectText(await runInProcessReviewer(baseRequest({ selection: "anthropic/claude-sonnet-4", sessionId: "ses-live-1" }), deps));
741
+ expectText(await runInProcessReviewer(baseRequest({ selection: "anthropic/claude-sonnet-4", sessionId: "ses-live-1" }), deps));
742
+ assert.equal(calls.length, 2);
743
+ const [first, second] = calls.map((call) => call.options?.sessionId);
744
+ assert.ok(typeof first === "string" && first.length > 0);
745
+ assert.ok(typeof second === "string" && second.length > 0);
746
+ assert.notEqual(first, second);
747
+ assert.notEqual(first, "ses-live-1");
748
+ assert.notEqual(second, "ses-live-1");
749
+ });
750
+
751
+ test("an OpenCode model with a live parent keeps the parent id in the attribution header while options.sessionId stays synthetic", async () => {
752
+ const { complete, calls } = capturingComplete(assistantText("ok"));
753
+ const outcome = await runInProcessReviewer(baseRequest({ selection: "opencode/sonnet-4", sessionId: "ses-live-1" }), {
754
+ registry: fakeRegistry([fakeModel({ provider: "opencode", id: "sonnet-4", baseUrl: "https://opencode.ai" })]),
755
+ complete,
756
+ });
757
+ expectText(outcome);
758
+ assert.equal(calls.length, 1);
759
+ assert.equal(calls[0]!.options?.headers?.["x-opencode-session"], "ses-live-1");
760
+ const sessionId = calls[0]!.options?.sessionId;
761
+ assert.ok(typeof sessionId === "string" && sessionId.length > 0);
762
+ assert.notEqual(sessionId, "ses-live-1");
763
+ });
764
+
473
765
  test("a non-OpenCode model adds no attribution headers and leaves the options unchanged", async () => {
474
766
  const { complete, calls } = capturingComplete(assistantText("ok"));
475
767
  const outcome = await runInProcessReviewer(baseRequest({ selection: "anthropic/claude-sonnet-4", sessionId: "ses-live-1" }), {
@@ -591,7 +883,7 @@ test("refuses instead of falling back when getProvider returns undefined for a m
591
883
  const refused = expectRefused(outcome);
592
884
  assert.equal(refused.code, INPROCESS_REVIEWER_FAILURE.MODEL_NOT_FOUND);
593
885
  assert.match(refused.message, /review-risk/);
594
- assert.deepEqual(refused.evidence, { provider: "openai", api: "openai-responses" }, "the evidence separates this cause from a plain unresolved selection");
886
+ assert.deepEqual(withoutRunTiming(refused.evidence), { provider: "openai", api: "openai-responses", reviewerModel: "openai/gpt-5", phase: "configuration" }, "the evidence separates this cause from a plain unresolved selection");
595
887
  });
596
888
 
597
889
  // ---------------------------------------------------------------------------
@@ -711,7 +1003,9 @@ for (const transport of ["sse", "websocket", "websocket-cached", "auto", undefin
711
1003
  streamSimple: (model, context, options) => ({ result: () => captured.complete(model, context, options) }),
712
1004
  });
713
1005
  const outcome = await runInProcessReviewer(baseRequest({ transport }), { registry, complete: captured.complete });
714
- assert.deepEqual(outcome, { kind: "text", text: "review result", reviewerModel: "openai/gpt-5" });
1006
+ const { evidence, ...completion } = outcome;
1007
+ assert.deepEqual(completion, { kind: "text", text: "review result", reviewerModel: "openai/gpt-5" });
1008
+ assert.equal(evidence?.phase, "completion");
715
1009
  assert.equal(captured.calls.length, 1);
716
1010
  assert.equal(captured.calls[0]!.options?.transport, transport);
717
1011
  assert.equal(Object.hasOwn(captured.calls[0]!.options!, "transport"), transport !== undefined);