gentle-pi 4.7.0 → 4.8.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 (365) hide show
  1. package/README.md +55 -44
  2. package/assets/agents/gentle-ai-explore.md +3 -3
  3. package/assets/agents/gentle-ai-verify.md +20 -6
  4. package/assets/agents/gentle-ai-worker.md +6 -6
  5. package/assets/agents/jd-judge-a.md +1 -3
  6. package/assets/agents/jd-judge-b.md +1 -3
  7. package/assets/agents/review-readability.md +1 -5
  8. package/assets/agents/review-reliability.md +1 -5
  9. package/assets/agents/review-resilience.md +1 -5
  10. package/assets/agents/review-risk.md +1 -5
  11. package/assets/design-canvas/canvas-api.js +45 -0
  12. package/assets/design-canvas/canvas-boards.js +456 -0
  13. package/assets/design-canvas/canvas-boot.js +217 -0
  14. package/assets/design-canvas/canvas-checks.js +491 -0
  15. package/assets/design-canvas/canvas-comments.js +315 -0
  16. package/assets/design-canvas/canvas-compare.js +159 -0
  17. package/assets/design-canvas/canvas-events.js +75 -0
  18. package/assets/design-canvas/canvas-export.js +393 -0
  19. package/assets/design-canvas/canvas-focus.js +203 -0
  20. package/assets/design-canvas/canvas-handoffs.js +150 -0
  21. package/assets/design-canvas/canvas-i18n-es.js +392 -0
  22. package/assets/design-canvas/canvas-i18n.js +108 -0
  23. package/assets/design-canvas/canvas-layout.js +526 -0
  24. package/assets/design-canvas/canvas-menu.js +213 -0
  25. package/assets/design-canvas/canvas-messages.js +86 -0
  26. package/assets/design-canvas/canvas-minimap.js +163 -0
  27. package/assets/design-canvas/canvas-parts.js +401 -0
  28. package/assets/design-canvas/canvas-popover.js +234 -0
  29. package/assets/design-canvas/canvas-rail.js +348 -0
  30. package/assets/design-canvas/canvas-sizes.js +524 -0
  31. package/assets/design-canvas/canvas-store.js +164 -0
  32. package/assets/design-canvas/canvas-tokens.js +674 -0
  33. package/assets/design-canvas/canvas-ui.js +24 -0
  34. package/assets/design-canvas/canvas-view.js +184 -0
  35. package/assets/design-canvas/canvas.css +746 -15
  36. package/assets/design-canvas/canvas.js +2 -1506
  37. package/assets/design-canvas/index.html +117 -36
  38. package/assets/design-canvas/inspector.js +546 -16
  39. package/assets/install-wizard/wizard.js +5 -1
  40. package/assets/migrations/agent-body-history.json +24 -0
  41. package/assets/orchestrator-delegation-reference.md +8 -14
  42. package/assets/orchestrator-delegation.md +4 -4
  43. package/assets/orchestrator-full-delegation-card.md +4 -5
  44. package/assets/orchestrator-full-delegation.md +8 -8
  45. package/assets/orchestrator-memory.md +2 -2
  46. package/assets/orchestrator-prompts.md +1 -1
  47. package/assets/orchestrator-quota-recovery.md +5 -0
  48. package/assets/orchestrator-skills.md +13 -12
  49. package/assets/orchestrator-tracking.md +10 -14
  50. package/assets/orchestrator-verification.md +10 -8
  51. package/assets/orchestrator-writer.md +4 -4
  52. package/assets/orchestrator.md +18 -22
  53. package/bin/gentle-shell.mjs +128 -9
  54. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  55. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
  56. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
  60. package/docs/assets/brand/sponsor-banner.svg +60 -0
  61. package/docs/bundled-install.md +14 -6
  62. package/docs/delegated-verification.md +18 -2
  63. package/docs/desktop-rpc.md +1253 -0
  64. package/docs/gentle-agents-activity.md +26 -0
  65. package/docs/gentle-shell.md +39 -16
  66. package/docs/install-wizard.md +30 -21
  67. package/docs/odd-preparation-continuity.md +24 -0
  68. package/docs/permission-modes.md +9 -1
  69. package/docs/prompt-budget.md +12 -0
  70. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  71. package/docs/readme-reference.md +76 -24
  72. package/docs/review-coordinator.md +29 -9
  73. package/docs/review-delivery-preflight.md +22 -0
  74. package/docs/work-continuity.md +11 -1
  75. package/extensions/ask-user-question.ts +2 -2
  76. package/extensions/child-context.ts +21 -7
  77. package/extensions/gentle-agents.ts +234 -33
  78. package/extensions/gentle-ai.ts +576 -135
  79. package/extensions/gentle-design.ts +69 -3
  80. package/extensions/gentle-desktop-rpc.ts +143 -0
  81. package/extensions/gentle-guide.ts +3 -0
  82. package/extensions/gentle-shell.ts +105 -52
  83. package/extensions/gentle-todo.ts +48 -25
  84. package/extensions/skill-registry.ts +248 -223
  85. package/lib/agent-assets.ts +30 -6
  86. package/lib/agent-tool-overlay.ts +117 -0
  87. package/lib/agents-config.ts +47 -6
  88. package/lib/agents-message-delivery.ts +17 -0
  89. package/lib/agents-messaging.ts +8 -2
  90. package/lib/agents-protocol.ts +15 -0
  91. package/lib/agents-report-cap.ts +115 -0
  92. package/lib/agents-runner.ts +91 -6
  93. package/lib/agents-session-transport.ts +17 -1
  94. package/lib/background-jobs-tools.ts +9 -4
  95. package/lib/bounded-writer-admission.ts +184 -31
  96. package/lib/child-context-files.ts +21 -6
  97. package/lib/codemode-renderer.ts +1 -0
  98. package/lib/delivery-conflict-markers.ts +349 -0
  99. package/lib/design-canvas-assets.ts +36 -0
  100. package/lib/design-canvas-server.ts +241 -23
  101. package/lib/design-comments.ts +94 -4
  102. package/lib/design-handoffs.ts +2 -1
  103. package/lib/design-layout.ts +125 -0
  104. package/lib/design-parts.ts +281 -0
  105. package/lib/design-system-tokens.ts +111 -0
  106. package/lib/desktop-agents-service.ts +294 -0
  107. package/lib/desktop-design-service.ts +233 -0
  108. package/lib/desktop-jobs-service.ts +263 -0
  109. package/lib/desktop-rpc-agents.ts +294 -0
  110. package/lib/desktop-rpc-config.ts +731 -0
  111. package/lib/desktop-rpc-design.ts +138 -0
  112. package/lib/desktop-rpc-jobs.ts +181 -0
  113. package/lib/desktop-rpc-permissions.ts +177 -0
  114. package/lib/desktop-rpc-profiles.ts +196 -0
  115. package/lib/desktop-rpc-usage.ts +229 -0
  116. package/lib/desktop-rpc.ts +225 -0
  117. package/lib/desktop-usage-service.ts +310 -0
  118. package/lib/destructive-command-guard.ts +188 -13
  119. package/lib/gentle-ai-renderer.ts +13 -1
  120. package/lib/gentle-design.ts +201 -14
  121. package/lib/gentle-shell-bundled.ts +100 -9
  122. package/lib/hidden-tools.ts +35 -0
  123. package/lib/inprocess-reviewer.ts +96 -12
  124. package/lib/model-fallback-policy.ts +9 -0
  125. package/lib/model-routing-authority.ts +9 -0
  126. package/lib/nan-provider.ts +42 -28
  127. package/lib/native-review-cli.ts +79 -4
  128. package/lib/orchestrator-discovery.ts +39 -2
  129. package/lib/reply-language-anchor.ts +27 -2
  130. package/lib/request-context-placement.ts +53 -0
  131. package/lib/review-candidate-view.ts +11 -1
  132. package/lib/review-continuation-registry.ts +17 -0
  133. package/lib/review-coordinator.ts +252 -8
  134. package/lib/review-delivery-preflight.ts +85 -0
  135. package/lib/review-host-relay.ts +5 -1
  136. package/lib/review-integration-v2.ts +56 -3
  137. package/lib/reviewer-stream.ts +87 -0
  138. package/lib/shell-prompt.ts +16 -3
  139. package/lib/shell-usage.ts +10 -0
  140. package/lib/vim-editor-adapter.ts +9 -2
  141. package/lib/writer-batch-admission.ts +55 -0
  142. package/lib/yolo-session-policy.ts +6 -1
  143. package/package.json +2 -2
  144. package/prompts/skill-creation.md +1 -10
  145. package/runtime/design-canvas-assets.mjs +37 -0
  146. package/runtime/gentle-shell-bundled.mjs +100 -9
  147. package/runtime/native-review-cli.mjs +79 -4
  148. package/runtime/review-integration-v2.mjs +56 -3
  149. package/scripts/bootstrap.cmd +2 -2
  150. package/scripts/bootstrap.sh +41 -4
  151. package/scripts/build-full-delegation-card.mjs +4 -0
  152. package/scripts/build-runtime-modules.mjs +1 -0
  153. package/scripts/gentle-ai-installer.mjs +10 -10
  154. package/scripts/gentle-ai-proxy.mjs +1 -1
  155. package/scripts/installer-downloads.mjs +34 -8
  156. package/scripts/installer-preflight.mjs +28 -17
  157. package/scripts/installer-probes.mjs +25 -5
  158. package/scripts/installer-server.mjs +38 -9
  159. package/scripts/installer-windows.mjs +2 -2
  160. package/scripts/pi-update.mjs +166 -27
  161. package/scripts/prepare-verifier.mjs +107 -0
  162. package/scripts/update-agent-body-history.mjs +55 -8
  163. package/scripts/verify-package-files.mjs +40 -19
  164. package/skills/branch-pr/SKILL.md +16 -16
  165. package/skills/comment-writer/SKILL.md +1 -1
  166. package/skills/design/SKILL.md +6 -6
  167. package/skills/gentle-ai/SKILL.md +5 -5
  168. package/skills/judgment-day/SKILL.md +2 -2
  169. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  170. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  171. package/skills/skill-improver/SKILL.md +2 -2
  172. package/skills/skill-registry/SKILL.md +11 -13
  173. package/skills/tui-design/SKILL.md +1 -1
  174. package/skills/work-unit-commits/SKILL.md +5 -5
  175. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  176. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  177. package/tests/agent-tool-overlay.test.ts +89 -0
  178. package/tests/agents-config.test.ts +10 -1
  179. package/tests/agents-message-delivery.test.ts +36 -0
  180. package/tests/agents-queries.test.ts +144 -4
  181. package/tests/agents-report-cap.test.ts +126 -0
  182. package/tests/agents-runner.test.ts +37 -1
  183. package/tests/agents-session-transport.test.ts +34 -0
  184. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  185. package/tests/append-system-prompt-route.test.ts +10 -2
  186. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  187. package/tests/artifact-language.test.ts +1 -1
  188. package/tests/ask-user-question.test.ts +2 -1
  189. package/tests/audit-leftovers-contract.test.ts +51 -0
  190. package/tests/bounded-stop-contract.test.ts +9 -1
  191. package/tests/branch-pr-skill.test.ts +10 -1
  192. package/tests/bundled-install.test.ts +1 -1
  193. package/tests/child-context-files.test.ts +64 -8
  194. package/tests/child-skills-catalog.test.ts +56 -0
  195. package/tests/codemode-rendering.test.ts +4 -1
  196. package/tests/delegate-for-reason-contract.test.ts +30 -8
  197. package/tests/delivery-conflict-markers.test.ts +348 -0
  198. package/tests/design-canvas-all-sizes.test.ts +631 -0
  199. package/tests/design-canvas-allowlist.test.ts +32 -0
  200. package/tests/design-canvas-assets.test.ts +11 -878
  201. package/tests/design-canvas-boards.test.ts +77 -0
  202. package/tests/design-canvas-checks.test.ts +655 -0
  203. package/tests/design-canvas-compare.test.ts +79 -0
  204. package/tests/design-canvas-events.test.ts +59 -0
  205. package/tests/design-canvas-export.test.ts +1168 -0
  206. package/tests/design-canvas-focus.test.ts +113 -0
  207. package/tests/design-canvas-handoffs.test.ts +59 -0
  208. package/tests/design-canvas-i18n-review.test.ts +513 -0
  209. package/tests/design-canvas-i18n-views.test.ts +259 -0
  210. package/tests/design-canvas-i18n.test.ts +526 -0
  211. package/tests/design-canvas-inspector.test.ts +937 -0
  212. package/tests/design-canvas-layout.test.ts +1222 -0
  213. package/tests/design-canvas-minimap.test.ts +413 -0
  214. package/tests/design-canvas-modules.test.ts +90 -0
  215. package/tests/design-canvas-parts.test.ts +721 -0
  216. package/tests/design-canvas-rail.test.ts +799 -0
  217. package/tests/design-canvas-server.test.ts +855 -17
  218. package/tests/design-canvas-sizes.test.ts +548 -0
  219. package/tests/design-canvas-store.test.ts +180 -0
  220. package/tests/design-canvas-tokens.test.ts +965 -0
  221. package/tests/design-canvas-view.test.ts +299 -0
  222. package/tests/design-comments.test.ts +201 -1
  223. package/tests/design-handoffs.test.ts +20 -0
  224. package/tests/design-layout.test.ts +100 -0
  225. package/tests/design-parts.test.ts +260 -0
  226. package/tests/design-system-tokens.test.ts +215 -0
  227. package/tests/desktop-rpc-agents.test.ts +893 -0
  228. package/tests/desktop-rpc-config.test.ts +1452 -0
  229. package/tests/desktop-rpc-design.test.ts +662 -0
  230. package/tests/desktop-rpc-jobs.test.ts +796 -0
  231. package/tests/desktop-rpc-permissions.test.ts +311 -0
  232. package/tests/desktop-rpc-profiles.test.ts +140 -0
  233. package/tests/desktop-rpc-safety.test.ts +119 -0
  234. package/tests/desktop-rpc-usage.test.ts +697 -0
  235. package/tests/desktop-rpc.test.ts +252 -0
  236. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  237. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  238. package/tests/engram-safety.test.ts +111 -0
  239. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  240. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  241. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +20 -29
  242. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  243. package/tests/full-delegation-closure.test.ts +29 -0
  244. package/tests/gentle-agents.test.ts +329 -4
  245. package/tests/gentle-ai-binary.test.ts +1 -1
  246. package/tests/gentle-ai-child-guards.test.ts +1 -0
  247. package/tests/gentle-ai-installer.test.ts +52 -51
  248. package/tests/gentle-ai-renderer.test.ts +36 -2
  249. package/tests/gentle-ai.test.ts +121 -6
  250. package/tests/gentle-design.test.ts +365 -1
  251. package/tests/gentle-shell-bundled.test.ts +91 -5
  252. package/tests/gentle-shell-launcher.test.ts +1 -1
  253. package/tests/gentle-shell.test.ts +118 -87
  254. package/tests/gentle-todo.test.ts +32 -9
  255. package/tests/hidden-tools.test.ts +188 -0
  256. package/tests/independent-recovery-delivery.test.ts +19 -5
  257. package/tests/inprocess-reviewer.test.ts +73 -0
  258. package/tests/install-wizard.test.ts +27 -1
  259. package/tests/installer-downloads.test.ts +30 -1
  260. package/tests/installer-posix-bootstrap.test.ts +114 -13
  261. package/tests/installer-preflight.test.ts +49 -1
  262. package/tests/installer-probes.test.ts +146 -0
  263. package/tests/installer-server.test.ts +203 -4
  264. package/tests/installer-windows-bootstrap.test.ts +19 -1
  265. package/tests/judgment-day-severity-admission.test.ts +46 -0
  266. package/tests/lazy-module-contradictions-contract.test.ts +158 -0
  267. package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
  268. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  269. package/tests/model-fallback-policy.test.ts +26 -7
  270. package/tests/nan-provider-runtime.test.ts +17 -3
  271. package/tests/nan-provider.test.ts +111 -56
  272. package/tests/native-review-capability-contract.test.ts +11 -1
  273. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  274. package/tests/native-review-parity.test.ts +24 -5
  275. package/tests/native-review-refusal-identity.test.ts +25 -0
  276. package/tests/no-self-pause-contract.test.ts +11 -3
  277. package/tests/odd-integration.test.ts +11 -3
  278. package/tests/odd-routing-contract.test.ts +80 -28
  279. package/tests/orchestrator-budget.test.ts +30 -5
  280. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  281. package/tests/orchestrator-delegation-mode.test.ts +2 -1
  282. package/tests/orchestrator-discovery.test.ts +28 -0
  283. package/tests/orchestrator-prompt-budget.test.ts +11 -2
  284. package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
  285. package/tests/orchestrator-rdd-ownership.test.ts +2 -1
  286. package/tests/orchestrator-work-search.test.ts +4 -2
  287. package/tests/package-files.test.ts +25 -1
  288. package/tests/package-manifest.test.ts +11 -10
  289. package/tests/parallel-reason-contract.test.ts +6 -3
  290. package/tests/permission-allowlist.test.ts +200 -30
  291. package/tests/persona-neutral-voseo.test.ts +4 -4
  292. package/tests/persona-reply-language.test.ts +1 -1
  293. package/tests/persona-single-channel.test.ts +13 -5
  294. package/tests/pi-update-launcher.test.ts +17 -7
  295. package/tests/pi-update-source.test.ts +113 -6
  296. package/tests/pi-update.test.ts +294 -19
  297. package/tests/pnpm-workspace-policy.test.ts +47 -0
  298. package/tests/primary-context-files.test.ts +233 -0
  299. package/tests/primary-context-three-files.test.ts +174 -0
  300. package/tests/provider-defect-handoff.test.ts +9 -2
  301. package/tests/rdd-aware-verification-contract.test.ts +1 -1
  302. package/tests/rdd-status-line.test.ts +94 -1
  303. package/tests/reply-language-anchor-placement.test.ts +184 -0
  304. package/tests/reply-language-anchor.test.ts +17 -1
  305. package/tests/request-context-append-only.test.ts +218 -0
  306. package/tests/request-context-placement.test.ts +148 -0
  307. package/tests/review-agent-end-preflight.test.ts +79 -1
  308. package/tests/review-candidate-view.test.ts +65 -0
  309. package/tests/review-continuation-registry.test.ts +31 -0
  310. package/tests/review-contract-prompt.test.ts +1 -1
  311. package/tests/review-controller.test.ts +2 -1
  312. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  313. package/tests/review-coordinator-findings.test.ts +206 -0
  314. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  315. package/tests/review-coordinator.test.ts +271 -4
  316. package/tests/review-delivery-preflight.test.ts +462 -0
  317. package/tests/review-due-compaction.test.ts +31 -0
  318. package/tests/review-due-public-boundary.test.ts +26 -0
  319. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  320. package/tests/review-json-arguments.test.ts +41 -2
  321. package/tests/review-ledger-contract.test.ts +19 -40
  322. package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
  323. package/tests/review-one-call-findings.test.ts +131 -0
  324. package/tests/review-one-call-followups.test.ts +308 -0
  325. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  326. package/tests/review-one-call.test.ts +452 -0
  327. package/tests/review-relay-transport-agent.test.ts +28 -1
  328. package/tests/review-reviewer-evidence.test.ts +41 -1
  329. package/tests/review-risk-assessment.test.ts +52 -5
  330. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  331. package/tests/review-session-standing-permission-controller.test.ts +32 -2
  332. package/tests/review-tool-prose-budget.test.ts +1 -0
  333. package/tests/reviewer-stream.test.ts +149 -0
  334. package/tests/session-profile-extension.test.ts +2 -2
  335. package/tests/shell-prompt.test.ts +17 -0
  336. package/tests/shell-usage.test.ts +59 -10
  337. package/tests/skill-contradictions-contract.test.ts +122 -0
  338. package/tests/skill-registry-watcher.test.ts +216 -2
  339. package/tests/skill-registry.test.ts +929 -306
  340. package/tests/support/design-canvas-dom.ts +369 -0
  341. package/tests/support/review-coordinator-runtime.ts +212 -17
  342. package/tests/task-size-routing-contract.test.ts +42 -11
  343. package/tests/test-strength-contract.test.ts +2 -1
  344. package/tests/todo-request-append-only.test.ts +214 -0
  345. package/tests/tool-batching-contract.test.ts +3 -1
  346. package/tests/update-agent-body-history.test.ts +138 -0
  347. package/tests/verification-tiers-contract.test.ts +229 -0
  348. package/tests/verifier-preparation.test.ts +229 -0
  349. package/tests/verify-agent-contract.test.ts +20 -2
  350. package/tests/verify-first-launch-contract.test.ts +87 -11
  351. package/tests/vim-editor-adapter.test.ts +2 -2
  352. package/tests/work-continuity-contract.test.ts +54 -11
  353. package/tests/writer-admission-messages.test.ts +232 -0
  354. package/tests/writer-batch-admission.test.ts +66 -0
  355. package/tests/writer-edit-surface-scope.test.ts +52 -20
  356. package/tests/writer-feature-document-admission.test.ts +184 -0
  357. package/tests/yolo-mode.test.ts +39 -0
  358. package/skills/_shared/review-ledger-contract.md +0 -106
  359. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
  360. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
  361. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
  362. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  363. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
  364. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
  365. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -1009,13 +1009,23 @@ function materializeCandidateView(request: CreateCandidateViewRequest, executor:
1009
1009
  if (unborn) git(contributorRoot, ["read-tree", "--empty"], environment, executor);
1010
1010
  else git(contributorRoot, ["read-tree", candidateCommit.commit], environment, executor);
1011
1011
  }
1012
+ if (committedOnly && intendedUntracked !== undefined && intendedUntracked.length > 0) {
1013
+ // An explicit selection may extend HEAD, never replace its tracked
1014
+ // content or expand a directory/pathspec into unrelated dirty inputs.
1015
+ const literalEnvironment = { ...process.env, GIT_LITERAL_PATHSPECS: "1" };
1016
+ const available = new Set((candidateGit(contributorRoot, ["ls-files", "--others", "--exclude-standard", "-z", "--", ...intendedUntracked], literalEnvironment, "utf8", executor) as string).split("\0"));
1017
+ const headEntries = candidateGit(contributorRoot, ["ls-tree", "-r", "--name-only", "-z", candidateCommit.commit, "--", ...intendedUntracked], literalEnvironment, "utf8", executor) as string;
1018
+ if (intendedUntracked.some(path => !available.has(path)) || headEntries.length > 0) {
1019
+ throw new CandidateViewError("committed candidate selection must name exact untracked files outside HEAD", "candidate-untracked-selection-invalid");
1020
+ }
1021
+ }
1012
1022
  if (!committedOnly) {
1013
1023
  if (intendedUntracked === undefined) git(contributorRoot, ["add", "-A"], environment, executor);
1014
1024
  else {
1015
1025
  git(contributorRoot, ["add", "-u"], environment, executor);
1016
- if (intendedUntracked.length > 0) git(contributorRoot, ["add", "--", ...intendedUntracked], { ...environment, GIT_LITERAL_PATHSPECS: "1" }, executor);
1017
1026
  }
1018
1027
  }
1028
+ if (intendedUntracked !== undefined && intendedUntracked.length > 0) git(contributorRoot, ["add", "--", ...intendedUntracked], { ...environment, GIT_LITERAL_PATHSPECS: "1" }, executor);
1019
1029
  const candidateTree = git(contributorRoot, ["write-tree"], environment, executor);
1020
1030
  const root = join(parent, randomUUID());
1021
1031
  let owner: CandidateViewOwner;
@@ -33,6 +33,7 @@ export interface RetainedNativeUntrackedStopSelector {
33
33
  }
34
34
 
35
35
  export type RetainedReviewContinuation =
36
+ | { readonly kind: "committed-range"; readonly baseRef: string; readonly mutation?: string }
36
37
  | (RetainedNativeUntrackedSelection & { readonly kind: "selection" })
37
38
  | (RetainedPreLineageNativeUntrackedSelection & { readonly kind: "pre-start" })
38
39
  | (RetainedNativeCaptureRoute & { readonly kind: "capture" })
@@ -58,6 +59,22 @@ export class ReviewContinuationRegistry {
58
59
  return value instanceof ReviewContinuationRegistry ? value : new ReviewContinuationRegistry(value);
59
60
  }
60
61
  get size(): number { return this.entries.size; }
62
+ readCommittedRange(root: string): string | undefined {
63
+ const entry = this.entries.get(`committed-range\u0000${root}`);
64
+ return entry?.kind === "committed-range" ? entry.baseRef : undefined;
65
+ }
66
+ /** A reminder may reuse a selector only for the generation explicitly assessed. */
67
+ readReminderRange(root: string, mutation: string): string | undefined {
68
+ const entry = this.entries.get(`committed-range\u0000${root}`);
69
+ return entry?.kind === "committed-range" && entry.mutation === mutation ? entry.baseRef : undefined;
70
+ }
71
+ retainCommittedRange(root: string, baseRef: string, mutation?: string): void {
72
+ this.retain(`committed-range\u0000${root}`, { kind: "committed-range", baseRef, ...(mutation === undefined ? {} : { mutation }) });
73
+ }
74
+ clearReminderRange(root: string): void {
75
+ const baseRef = this.readCommittedRange(root);
76
+ if (baseRef !== undefined) this.retainCommittedRange(root, baseRef);
77
+ }
61
78
  /** Bound retained hints by evicting the oldest key before a new insertion. */
62
79
  private retain(key: string, entry: RetainedReviewContinuation): void {
63
80
  if (!this.entries.has(key)) while (this.entries.size >= MAX_RETAINED_CONTINUATIONS) this.entries.delete(this.entries.keys().next().value!);
@@ -1,9 +1,135 @@
1
- /** Experimental host orchestration. All authority stays in the existing facade. */
1
+ /** Host orchestration of one ordinary native review. All authority stays in the existing facade. */
2
2
  export type ReviewCoordinatorTool = "gentle_review" | "gentle_review_capture" | "gentle_review_capture_group";
3
3
  type Body = Record<string, unknown>;
4
4
  const record = (value: unknown): Body => value !== null && typeof value === "object" && !Array.isArray(value) ? value as Body : {};
5
5
  const nonempty = (value: unknown): value is string => typeof value === "string" && value.trim().length > 0;
6
6
 
7
+ // odd/tasks/review-one-call.md S5: what each finding says, in the reviewer's
8
+ // own words. Each id is looked up in `findings` by exact id and its claim is
9
+ // copied unchanged, cut at the last whole character within
10
+ // REVIEW_FINDING_CLAIM_MAX_BYTES. Claims are added in `ids` order until the
11
+ // next one would pass REVIEW_FINDING_CLAIMS_MAX_BYTES in total; the rest get no
12
+ // entry. An id with no matching finding, or with more than one, is omitted.
13
+ // Beside them, `truncated` lists the ids whose kept claim is a cut prefix and
14
+ // `omitted` the ids whose one matching claim the total limit left out, so
15
+ // neither passes for a whole claim. Reviewer text is untrusted: nothing routes
16
+ // on it. Shared by the facade's approved closure (advisory findings) and the
17
+ // run's correction request (correction findings).
18
+ export const REVIEW_FINDING_CLAIM_MAX_BYTES = 1024;
19
+ export const REVIEW_FINDING_CLAIMS_MAX_BYTES = 8192;
20
+
21
+ function withinUtf8Bytes(text: string, maximum: number): string {
22
+ if (Buffer.byteLength(text) <= maximum) return text;
23
+ let kept = "", bytes = 0;
24
+ for (const character of text) {
25
+ bytes += Buffer.byteLength(character);
26
+ if (bytes > maximum) break;
27
+ kept += character;
28
+ }
29
+ return kept;
30
+ }
31
+
32
+ export function boundedFindingClaims(ids: readonly string[], findings: readonly { id: string; claim: string }[]): { claims: Record<string, string>; truncated: string[]; omitted: string[] } | undefined {
33
+ const entries: [string, string][] = [];
34
+ const truncated: string[] = [], omitted: string[] = [];
35
+ let total = 0;
36
+ for (const id of ids) {
37
+ const matches = findings.filter((finding) => finding.id === id);
38
+ if (matches.length !== 1) continue;
39
+ const claim = withinUtf8Bytes(matches[0]!.claim, REVIEW_FINDING_CLAIM_MAX_BYTES);
40
+ if (omitted.length > 0 || total + Buffer.byteLength(claim) > REVIEW_FINDING_CLAIMS_MAX_BYTES) { omitted.push(id); continue; }
41
+ total += Buffer.byteLength(claim);
42
+ entries.push([id, claim]);
43
+ if (claim !== matches[0]!.claim) truncated.push(id);
44
+ }
45
+ // fromEntries defines own data properties, so no id can reach a prototype.
46
+ return entries.length === 0 ? undefined : { claims: Object.fromEntries(entries), truncated, omitted };
47
+ }
48
+
49
+ // The provider fields of a correction-request finding relayed in
50
+ // correction_findings, unchanged. The claim travels bounded in
51
+ // correction_finding_claims; evidence and proof references stay in the relayed
52
+ // STATUS envelope.
53
+ const CORRECTION_FINDING_REQUIRED = ["id", "lens", "location", "severity"] as const;
54
+ const CORRECTION_FINDING_OPTIONAL = ["evidence_class", "causal_disposition"] as const;
55
+
56
+ /** Relay keys for a correction request's findings, or none when any entry is malformed. Never routed on. */
57
+ function correctionFindingKeys(request: unknown): Body {
58
+ const findings = record(request).findings;
59
+ if (!Array.isArray(findings) || findings.length === 0) return {};
60
+ const plain = (value: unknown): value is Body => value !== null && typeof value === "object" && !Array.isArray(value) && [Object.prototype, null].includes(Object.getPrototypeOf(value));
61
+ if (!findings.every((finding) => plain(finding) && [...CORRECTION_FINDING_REQUIRED, "claim"].every((key) => Object.hasOwn(finding, key) && nonempty(finding[key]))
62
+ && CORRECTION_FINDING_OPTIONAL.every((key) => !Object.hasOwn(finding, key) || typeof finding[key] === "string"))) return {};
63
+ const entries = findings as Body[];
64
+ const listed = entries.map((finding) => Object.fromEntries([...CORRECTION_FINDING_REQUIRED, ...CORRECTION_FINDING_OPTIONAL]
65
+ .filter((key) => Object.hasOwn(finding, key)).map((key) => [key, finding[key]])));
66
+ const bounded = boundedFindingClaims(entries.map((finding) => finding.id as string), entries as { id: string; claim: string }[]);
67
+ return { correction_findings: listed,
68
+ ...(bounded === undefined ? {} : { correction_finding_claims: bounded.claims,
69
+ ...(bounded.truncated.length === 0 ? {} : { correction_finding_claims_truncated: bounded.truncated }),
70
+ ...(bounded.omitted.length === 0 ? {} : { correction_finding_claims_omitted: bounded.omitted }) }) };
71
+ }
72
+
73
+ // The provider fields of a non-blocking finding relayed in
74
+ // non_blocking_findings, unchanged; the claim travels bounded in
75
+ // non_blocking_finding_claims.
76
+ const NON_BLOCKING_FINDING_REQUIRED = ["id", "severity", "disposition"] as const;
77
+ const NON_BLOCKING_FINDING_OPTIONAL = ["lens", "location"] as const;
78
+ const NON_BLOCKING_FINDING_FIELDS = ["id", "lens", "location", "severity", "disposition"] as const;
79
+ export const NON_BLOCKING_FINDINGS_MAX_BYTES = 16 * 1024;
80
+
81
+ /**
82
+ * The run's nested provider record without the raw `non_blocking_findings`
83
+ * (L19): the bounded top-level keys are the only copy. Nothing else changes.
84
+ */
85
+ function withoutRawNonBlockingFindings(result: Body): Body {
86
+ const nested = result.result;
87
+ if (nested === null || typeof nested !== "object" || Array.isArray(nested) || !Object.hasOwn(nested, "non_blocking_findings")) return result;
88
+ const { non_blocking_findings: _raw, ...rest } = nested as Body;
89
+ return { ...result, result: rest };
90
+ }
91
+
92
+ /**
93
+ * Relay keys for STATUS `non_blocking_findings` (gentle-ai#6088), or none when
94
+ * the provider sent no such key or any part of it is malformed. An empty
95
+ * provider list is the provider's answer ("none") and is relayed as such.
96
+ * Never routed on.
97
+ */
98
+ function nonBlockingFindingKeys(status: unknown): Body {
99
+ const native = record(status);
100
+ if (!Object.hasOwn(native, "non_blocking_findings")) return {};
101
+ const value = native.non_blocking_findings;
102
+ const plain = (entry: unknown): entry is Body => entry !== null && typeof entry === "object" && !Array.isArray(entry) && [Object.prototype, null].includes(Object.getPrototypeOf(entry));
103
+ if (!plain(value) || !nonempty(value.statement) || !Array.isArray(value.findings)) return {};
104
+ const findings = value.findings as unknown[];
105
+ if (!findings.every((finding) => plain(finding) && NON_BLOCKING_FINDING_REQUIRED.every((key) => Object.hasOwn(finding, key) && nonempty(finding[key]))
106
+ && Object.hasOwn(finding, "claim") && typeof finding.claim === "string"
107
+ && NON_BLOCKING_FINDING_OPTIONAL.every((key) => !Object.hasOwn(finding, key) || nonempty(finding[key])))) return {};
108
+ // The list is bounded too (L19): findings are listed in provider order until
109
+ // the next one would bring the list past NON_BLOCKING_FINDINGS_MAX_BYTES of
110
+ // JSON; the rest are only counted. Claims are bounded over the listed ones.
111
+ const listed: Body[] = [];
112
+ let listBytes = 2;
113
+ for (const finding of findings as Body[]) {
114
+ const entry = Object.fromEntries(NON_BLOCKING_FINDING_FIELDS.filter((key) => Object.hasOwn(finding, key)).map((key) => [key, finding[key]]));
115
+ const entryBytes = Buffer.byteLength(JSON.stringify(entry)) + (listed.length === 0 ? 0 : 1);
116
+ if (listBytes + entryBytes > NON_BLOCKING_FINDINGS_MAX_BYTES) break;
117
+ listBytes += entryBytes;
118
+ listed.push(entry);
119
+ }
120
+ const omittedCount = findings.length - listed.length;
121
+ const entries = (findings as Body[]).slice(0, listed.length);
122
+ const bounded = boundedFindingClaims(entries.map((finding) => finding.id as string), entries as { id: string; claim: string }[]);
123
+ // Statement text shares the per-claim UTF-8 cap; the host marks a cut prefix explicitly.
124
+ const statement = withinUtf8Bytes(value.statement, REVIEW_FINDING_CLAIM_MAX_BYTES);
125
+ return { non_blocking_findings: { statement, findings: listed,
126
+ ...(statement === value.statement ? {} : { statement_truncated: true }) },
127
+ ...(omittedCount === 0 ? {} : { non_blocking_findings_omitted_count: omittedCount }),
128
+ ...(bounded === undefined ? {} : { non_blocking_finding_claims: bounded.claims,
129
+ ...(bounded.truncated.length === 0 ? {} : { non_blocking_finding_claims_truncated: bounded.truncated }),
130
+ ...(bounded.omitted.length === 0 ? {} : { non_blocking_finding_claims_omitted: bounded.omitted }) }) };
131
+ }
132
+
7
133
  export interface ReviewCoordinatorInput {
8
134
  workspaceRoot?: string;
9
135
  baseRef?: string;
@@ -18,7 +144,11 @@ export interface ReviewCoordinatorInput {
18
144
 
19
145
  export interface ReviewCoordinatorDeps {
20
146
  invoke(tool: ReviewCoordinatorTool, parameters: Body): Promise<Body>;
21
- /** True only after the host has displayed the entire informational forecast. */
147
+ /**
148
+ * True to continue past an informational reviewer-run forecast: after the
149
+ * host displayed all of it, or when the host has no display and the forecast
150
+ * is only recorded in the result. Absent or false stops with "forecast".
151
+ */
22
152
  presentForecast?(details: Body): Promise<boolean>;
23
153
  signal?: AbortSignal;
24
154
  now?: () => number;
@@ -58,6 +188,27 @@ export async function runReviewCoordinator(value: unknown, deps: ReviewCoordinat
58
188
  let target: string | undefined;
59
189
  let started = false;
60
190
  const captured = new Set<string>();
191
+ // advisory_findings of the latest admitted closure. The provider emits the key
192
+ // only on an approved closure; once captured, every result this run returns
193
+ // carries it (closed or stopped), so the parent holds it before any resume:
194
+ // a resume that goes straight to the acknowledgement cannot recover it, since
195
+ // neither bound STATUS nor the ACK envelope carries it. Never routed on.
196
+ let closureFindings: { value: unknown } | undefined;
197
+ // The facade's advisory_finding_claims of that same closure (each advisory id's
198
+ // reviewer claim), relayed beside advisory_findings only; never routed on.
199
+ let closureClaims: { value: unknown } | undefined;
200
+ // The facade's marks on those claims: ids whose claim is a cut prefix, and ids
201
+ // whose claim the per-closure limit left out. Relayed with the claims only.
202
+ let closureClaimMarks: Body = {};
203
+ // The correction request's findings and their bounded claims, once STATUS
204
+ // asked for a correction plan: carried by every result after it. Never routed on.
205
+ let correctionKeys: Body = {};
206
+ // The provider's non-blocking findings of the STATUS that stopped the run on
207
+ // a correction request or a stop (escalated). Never routed on.
208
+ let nonBlockingKeys: Body = {};
209
+ // That closure's capture envelope, kept unread for cancelled only while the
210
+ // retained closure carries advisory_findings.
211
+ let pendingCapture: Body | undefined;
61
212
  const checkCancelled = () => {
62
213
  if (deps.signal?.aborted) throw Object.assign(new Error("Review coordinator cancelled"), { name: "AbortError" });
63
214
  };
@@ -83,12 +234,25 @@ export async function runReviewCoordinator(value: unknown, deps: ReviewCoordinat
83
234
  }
84
235
  steps.push({ tool, operation: parameters.operation, elapsed_ms: now() - start,
85
236
  request_bytes: Buffer.byteLength(JSON.stringify({ ...workspace, ...parameters })), response_bytes: Buffer.byteLength(JSON.stringify(result)) });
86
- if (!acknowledged(result)) checkCancelled();
237
+ // A capture closure carrying advisory_findings is checked after the outcome
238
+ // gate below, so a cancellation racing with it keeps the findings; any later
239
+ // abort ends in cancelled through runReviewCoordinator's catch.
240
+ if (!acknowledged(result) && !(tool !== "gentle_review" && Object.hasOwn(record(result.closure), "advisory_findings"))) checkCancelled();
87
241
  return result;
88
242
  };
89
- const finish = (outcome: string, result: Body) => ({ schema: "gentle-pi.review-coordinator-experiment/v1", outcome, result, forecasts, reviewer_runs: reviewerRuns,
243
+ // The run's own inputs without a selection: after selection-required the
244
+ // caller resumes the run with these plus the chosen untracked selection, so
245
+ // START keeps the requested lenses and request context.
246
+ const { untrackedScope: _scope, intendedUntracked: _paths, ...resumeInput } = structuredClone(input);
247
+ const finish = (outcome: string, result: Body) => ({ schema: "gentle-pi.review-coordinator-experiment/v1", outcome, result: withoutRawNonBlockingFindings(result), forecasts, reviewer_runs: reviewerRuns,
248
+ ...(closureFindings !== undefined ? { advisory_findings: closureFindings.value } : {}),
249
+ ...(closureFindings !== undefined && closureClaims !== undefined ? { advisory_finding_claims: closureClaims.value, ...closureClaimMarks } : {}),
250
+ ...structuredClone(correctionKeys),
251
+ ...structuredClone(nonBlockingKeys),
252
+ ...(outcome === "selection-required" ? { resume_input: resumeInput } : {}),
90
253
  ...(lineage === undefined ? {} : { lineage_id: lineage }), metrics: { elapsed_ms: now() - began, facade_calls: steps.length, steps } });
91
254
  const status = () => invoke("gentle_review", { operation: "status", lineageId: lineage, ...selectorInput });
255
+ const drive = async (): Promise<Body> => {
92
256
  let details: Body;
93
257
  if (lineage === undefined) {
94
258
  const assessment = await invoke("gentle_review", { operation: "assess", ...selectorInput });
@@ -115,7 +279,11 @@ export async function runReviewCoordinator(value: unknown, deps: ReviewCoordinat
115
279
  }
116
280
  if (details.failure !== undefined || details.native_failure !== undefined || details.reconciliation !== undefined || details.reconciliation_failure !== undefined) return finish("blocked", details);
117
281
  const transition = record(native.next_transition);
118
- if (transition.kind === "stop") return finish("stopped", details);
282
+ if (transition.kind === "stop") {
283
+ // Read for relay only, after the routing decision above.
284
+ nonBlockingKeys = nonBlockingFindingKeys(native);
285
+ return finish("stopped", details);
286
+ }
119
287
  if (transition.kind === "execute") {
120
288
  const operation = record(transition.execute).operation;
121
289
  if (operation === "review.start") {
@@ -142,7 +310,30 @@ export async function runReviewCoordinator(value: unknown, deps: ReviewCoordinat
142
310
  const entries = Array.isArray(details.collectBindings) ? details.collectBindings.map(record) : [];
143
311
  // Native explicitly supplies the authored correction request. Do not derive
144
312
  // host routing metadata from submission domains or inspect opaque bindings.
145
- if (transition.correction_request !== undefined || entries.length === 0) return finish("input-required", details);
313
+ if (transition.correction_request !== undefined) {
314
+ // Read for relay only, after the routing decision above. The correction
315
+ // fields are returned only beside the provider's answer to the
316
+ // non-blocking question (L21): without it, a parent holding only the
317
+ // findings to correct would never learn the non-blocking ones, so the
318
+ // result stays as before T11 and the parent reads the review as it did.
319
+ nonBlockingKeys = nonBlockingFindingKeys(native);
320
+ if (Object.hasOwn(nonBlockingKeys, "non_blocking_findings")) correctionKeys = correctionFindingKeys(transition.correction_request);
321
+ return finish("input-required", details);
322
+ }
323
+ // The facade's own pre-lineage intended-untracked selection (selectionBinding
324
+ // and nextStep, no collectBindings): the parent chooses, never the run. The
325
+ // facade's nextStep names the single selection operation, which would start
326
+ // without this run's intent, so only resume_input names the way on; the
327
+ // selectionBinding stays because its eligible paths are what the choice is
328
+ // made from.
329
+ if (entries.length === 0 && typeof details.selectionBinding === "string") {
330
+ const { nextStep: _singleOperation, ...selection } = details;
331
+ // Without a caller root, name the root INSPECT resolved, so a resume from a
332
+ // session in another workspace still reviews the one this selection is for.
333
+ if (input.workspaceRoot === undefined && nonempty(details.workspace_root)) resumeInput.workspaceRoot = details.workspace_root;
334
+ return finish("selection-required", selection);
335
+ }
336
+ if (entries.length === 0) return finish("input-required", details);
146
337
  if (lineage === undefined || target === undefined) return finish("blocked", details);
147
338
  const bindings = entries.map(entry => entry.collectBinding);
148
339
  if (!bindings.every(nonempty)) return finish("blocked", details);
@@ -155,9 +346,62 @@ export async function runReviewCoordinator(value: unknown, deps: ReviewCoordinat
155
346
  if (await deps.presentForecast?.(capture) !== true) return finish("forecast", capture);
156
347
  capture = await invoke(tool, { ...parameters, reviewerRunAcknowledged: true });
157
348
  }
158
- if (!["native-last-event-closure", "native-reviewer-result-captured"].includes(String(capture.outcome))
159
- || capture.failure !== undefined || capture.reconciliation !== undefined) return finish("blocked", capture);
349
+ // A group whose every reviewer result was admitted without a closing event
350
+ // reports native-reviewer-group-status-reconciled after the facade's own
351
+ // bound STATUS confirmed lineage and target and offered no further reviewer
352
+ // capture (gentle_review_capture_group). Like any accepted capture, the next
353
+ // step comes only from the bound STATUS read below. Drift, an uncertain
354
+ // submission or a failed reconciliation carries another outcome or a
355
+ // failure/reconciliation field and stays blocked.
356
+ const reconciledGroup = tool === "gentle_review_capture_group" && capture.outcome === "native-reviewer-group-status-reconciled" && capture.status === "reconciled";
357
+ // An older provider's self-contained role vector (--execute=true): Go ran the
358
+ // refuter or validator and admitted it, returning the role artifact instead
359
+ // of a closure. Like an admitted reviewer result, bound STATUS routes next.
360
+ const capturedRole = tool === "gentle_review_capture" && capture.outcome === "native-provider-role-captured" && capture.status === "captured";
361
+ if (!(["native-last-event-closure", "native-reviewer-result-captured"].includes(String(capture.outcome)) || reconciledGroup || capturedRole)
362
+ || capture.failure !== undefined || capture.reconciliation !== undefined
363
+ || capture.native_failure !== undefined || capture.reconciliation_failure !== undefined) {
364
+ checkCancelled();
365
+ return finish("blocked", capture);
366
+ }
367
+ if (Object.hasOwn(capture, "closure")) {
368
+ // Read only these keys' presence and value; closure state and variants stay unread.
369
+ const closure = record(capture.closure);
370
+ closureFindings = Object.hasOwn(closure, "advisory_findings") ? { value: structuredClone(closure.advisory_findings) } : undefined;
371
+ // Relayed only as a plain object of strings; any other shape is dropped.
372
+ const claims = closure.advisory_finding_claims;
373
+ const plainStrings = claims !== null && typeof claims === "object" && [Object.prototype, null].includes(Object.getPrototypeOf(claims))
374
+ && Object.values(claims).every(value => typeof value === "string");
375
+ closureClaims = closureFindings !== undefined && Object.hasOwn(closure, "advisory_finding_claims") && plainStrings ? { value: structuredClone(claims) } : undefined;
376
+ // Each mark is relayed only as an array of strings; any other shape is dropped.
377
+ closureClaimMarks = Object.fromEntries(["advisory_finding_claims_truncated", "advisory_finding_claims_omitted"]
378
+ .filter(key => Array.isArray(closure[key]) && (closure[key] as unknown[]).every(id => typeof id === "string"))
379
+ .map(key => [key, structuredClone(closure[key])]));
380
+ pendingCapture = closureFindings === undefined ? undefined : capture;
381
+ }
382
+ checkCancelled();
160
383
  details = await status();
161
384
  }
162
385
  return finish("transition-limit", details);
386
+ };
387
+ try {
388
+ return await drive();
389
+ } catch (error) {
390
+ // Cancelled after an admitted approved closure with findings, before the
391
+ // acknowledgement completed (which returns closed above): return its findings
392
+ // and dispatch nothing more; resuming by lineageId reaches the acknowledgement.
393
+ // Without such a closure, or for a failure other than the abort, rethrow.
394
+ // The abort itself is an AbortError-named error (checkCancelled, the facade's
395
+ // reviewCancellation, the native CLI's own abort, the signal's default
396
+ // reason) or the signal's own reason (a custom reason, such as a timeout,
397
+ // that a facade wait rejects with); any other error is a real failure.
398
+ const abort = deps.signal?.aborted === true
399
+ && ((error instanceof Error || error instanceof DOMException) && error.name === "AbortError" || error === deps.signal.reason);
400
+ if (pendingCapture === undefined || !abort) throw error;
401
+ // The capture's status ("closed") and state ("approved") describe the
402
+ // capture, not the run, which is neither closed nor acknowledged: drop them.
403
+ const { status: _status, state: _state, closure, ...envelope } = pendingCapture;
404
+ const { state: _closureState, ...pending } = record(closure);
405
+ return finish("cancelled", { ...envelope, closure: pending });
406
+ }
163
407
  }
@@ -0,0 +1,85 @@
1
+ import { execFile } from "node:child_process";
2
+ import { resolve } from "node:path";
3
+ import { NATIVE_UNTRACKED_SCOPE, type NativeReviewCli } from "./native-review-cli.ts";
4
+ import { recognizeReviewDeliveryActions } from "./destructive-command-guard.ts";
5
+ import { resolveSessionWorktree, worktreeGitEnvironment } from "./session-worktree-registry.ts";
6
+
7
+ type Denial = { block: true; reason: string };
8
+ const deny = (reason: string): Denial => ({ block: true, reason: `RDD pre-delivery: ${reason} This delivery command was not run. Review outcomes do not authorize delivery.` });
9
+
10
+ // Compare HEAD/base around this read, without retaining a verdict or snapshot.
11
+ async function identity(root: string, baseRef: string): Promise<string | undefined> {
12
+ return new Promise(done => execFile("git", ["rev-parse", "--revs-only", "--end-of-options", "HEAD^{commit}", `${baseRef}^{commit}`],
13
+ { cwd: root, encoding: "utf8", timeout: 2_000, maxBuffer: 4096, windowsHide: true, env: worktreeGitEnvironment() },
14
+ (error, stdout) => {
15
+ const ids = stdout.trim().split(/\r?\n/);
16
+ done(!error && ids.length === 2 && ids.every(id => /^(?:[a-f0-9]{40}|[a-f0-9]{64})$/.test(id)) ? ids.join("\n") : undefined);
17
+ }));
18
+ }
19
+
20
+ /**
21
+ * gentle-shell#3169: native assess refuses a committed-only range while any
22
+ * untracked file exists (a PR body written for `gh pr create --body-file`)
23
+ * unless the untracked inventory is declared. A base-diff snapshot never
24
+ * includes untracked files, so excluding them leaves the assessed range
25
+ * unchanged. The digest comes only from native status; without it nothing is
26
+ * declared and native keeps deciding.
27
+ */
28
+ export async function committedRangeUntrackedExclusion(cli: Pick<NativeReviewCli, "targetStatus"> | null | undefined, cwd: string, baseRef: string,
29
+ signal?: AbortSignal): Promise<{ untrackedScope?: typeof NATIVE_UNTRACKED_SCOPE.EXCLUDE; expectedUntrackedInventory?: string }> {
30
+ if (!cli?.targetStatus) return {};
31
+ try {
32
+ const inventory = (await cli.targetStatus({ cwd, baseRef, committedOnly: true, agent: "pi", ...(signal ? { signal } : {}) })).eligibleUntrackedInventory;
33
+ return typeof inventory === "string" && inventory ? { untrackedScope: NATIVE_UNTRACKED_SCOPE.EXCLUDE, expectedUntrackedInventory: inventory } : {};
34
+ } catch { return {}; }
35
+ }
36
+
37
+ /** One fresh check per repository/batch. The existing session registry supplies only a base-ref hint. */
38
+ export async function checkReviewDeliveryPreflight(cwd: string, toolName: string, command: string, cli: NativeReviewCli | null,
39
+ baseRefFor: (root: string) => string | undefined, declined: (root: string, target: string) => boolean,
40
+ signal?: AbortSignal, current: () => boolean = () => true): Promise<Denial | undefined> {
41
+ const actions = recognizeReviewDeliveryActions(command), deliveries = actions.filter(action => action.kind === "delivery");
42
+ if (!deliveries.length || !cli?.reviewMode) return undefined;
43
+ if (deliveries.some(delivery => delivery.unresolvedDirectory)) return deny("The delivery repository cannot be resolved from this directory or Git/environment redirect; run delivery inside its repository or use literal cd or git -C.");
44
+ if (signal?.aborted || !current()) return deny("Preflight was cancelled or its session changed.");
45
+ const bounded = AbortSignal.any([AbortSignal.timeout(10_000), ...(signal ? [signal] : [])]);
46
+ let abort!: () => void;
47
+ const expired = new Promise<Denial>(done => { abort = () => done(deny("The bounded preflight was cancelled or timed out.")); bounded.addEventListener("abort", abort, { once: true }); });
48
+ const run = async (): Promise<Denial | undefined> => {
49
+ try {
50
+ const checked: Array<{ root: string; baseRef: string; before: string }> = [];
51
+ const roots = new Set(deliveries.map(delivery => {
52
+ const target = (delivery.directories ?? []).reduce((base, directory) => resolve(base, directory), cwd);
53
+ return resolveSessionWorktree(target, cwd)?.root ?? target;
54
+ }));
55
+ for (const root of roots) {
56
+ const mode = await cli.reviewMode!({ cwd: root, operation: "status", signal: bounded });
57
+ if (bounded.aborted || !current()) return deny("Session changed during preflight; assess again.");
58
+ if (mode.status.effective === "off") continue;
59
+ if (mode.status.effective !== "on") return deny("RDD mode is unavailable; resolve it before delivery.");
60
+ if (toolName !== "bash" || deliveries.some(delivery => delivery.background) || actions.some(action => action.kind === "change")) return deny("Finish candidate-changing commands or background waits separately, then issue delivery so the resulting commits can be assessed.");
61
+ const baseRef = baseRefFor(root);
62
+ if (!baseRef) return deny('Select the actual committed range with gentle_review assess input {"baseRef":"<slice base>","committedOnly":true}.');
63
+ const before = await identity(root, baseRef);
64
+ if (!before || !cli.assess) return deny("The selected base or native assessment is unavailable; resolve it before delivery.");
65
+ if (bounded.aborted || !current()) return deny("Session changed during preflight; assess again.");
66
+ const untracked = await committedRangeUntrackedExclusion(cli, root, baseRef, bounded);
67
+ if (bounded.aborted || !current()) return deny("Session changed during preflight; assess again.");
68
+ const assessment = await cli.assess({ cwd: root, baseRef, committedOnly: true, ...untracked, signal: bounded });
69
+ if (bounded.aborted || !current()) return deny("Session changed during preflight; assess again.");
70
+ if (assessment.candidate.kind !== "base-diff" || assessment.candidate.baseRef !== baseRef || typeof assessment.reviewDue !== "boolean") return deny("Native assessment did not confirm the selected committed range.");
71
+ if (assessment.reviewDue) {
72
+ const status = await cli.targetStatus?.({ cwd: root, baseRef, committedOnly: true, agent: "pi", signal: bounded });
73
+ if (!status || status.applicability !== "current_target" || status.projection.kind !== "base-diff" || !declined(root, status.targetIdentity)) return deny("Native assessment reports a due review. Resume the bound review or inspect and follow its native transitions and human consent before delivery.");
74
+ }
75
+ checked.push({ root, baseRef, before });
76
+ }
77
+ for (const { root, baseRef, before } of checked) {
78
+ if (bounded.aborted || !current() || baseRefFor(root) !== baseRef || await identity(root, baseRef) !== before || !current()) return deny("The range or session changed during preflight; assess again.");
79
+ }
80
+ return undefined;
81
+ } catch { return deny("Native preflight is unavailable; resolve it before delivery."); }
82
+ };
83
+ try { return await Promise.race([run(), expired]); }
84
+ finally { bounded.removeEventListener("abort", abort); }
85
+ }
@@ -34,6 +34,7 @@ import { spawn } from "node:child_process";
34
34
  import { tmpdir } from "node:os";
35
35
  import { isAbsolute, join } from "node:path";
36
36
  import { completeSimple } from "@earendil-works/pi-ai/compat";
37
+ import { reviewerStreamLimits, publishReviewerProgress } from "./reviewer-stream.ts";
37
38
  import { gentleAiIsolationEnv, resolveGentleAiBinary } from "./gentle-ai-binary.ts";
38
39
  import {
39
40
  INPROCESS_REVIEWER_FAILURE,
@@ -591,7 +592,8 @@ function relayReviewerRefusalError(
591
592
  return new ReviewHostRelayError(
592
593
  REVIEW_HOST_RELAY_FAILURE.PI_TIMED_OUT,
593
594
  "pi",
594
- reviewHostRelayPiTimeoutMessage(timing.elapsedMs, timing.timeoutMs, promptByteLength),
595
+ outcome.evidence?.timeoutPhase === "first-output" || outcome.evidence?.timeoutPhase === "stream-idle"
596
+ ? outcome.message : reviewHostRelayPiTimeoutMessage(timing.elapsedMs, timing.timeoutMs, promptByteLength),
595
597
  { ...details, timedOut: true },
596
598
  );
597
599
  case INPROCESS_REVIEWER_FAILURE.PROVIDER_FAILED:
@@ -785,10 +787,12 @@ export async function prepareReviewHostRelaySlot(
785
787
  ...(preparedRequest.reviewerSessionId === undefined ? {} : { sessionId: preparedRequest.reviewerSessionId }),
786
788
  prompt: promptBytes,
787
789
  timeoutMs: piTimeoutMs,
790
+ ...reviewerStreamLimits(preparedRequest.environment!),
788
791
  ...(preparedRequest.signal === undefined ? {} : { signal: preparedRequest.signal }),
789
792
  routingKey: preparedRequest.routingKey!,
790
793
  },
791
794
  { registry: preparedRequest.reviewerRegistry!, complete: completeSimple,
795
+ onProgress: publishReviewerProgress,
792
796
  onEvidence: (evidence) => { reviewerEvidence = evidence; } },
793
797
  );
794
798
  } catch (error) {
@@ -689,9 +689,32 @@ export interface ReviewStatusV3 {
689
689
  validationRequest?: ReviewTargetedValidationRequestV1;
690
690
  /** status/v7 only: the eligible untracked-path inventory digest, absent on the `staged` projection. */
691
691
  eligibleUntrackedInventory?: string;
692
+ /**
693
+ * status/v9 opt-in (`--non-blocking-findings`, gentle-ai#6088): the admitted
694
+ * findings of a compact correction_required or escalated authority that are
695
+ * neither to correct nor unresolved, with the reviewer's claim. Display
696
+ * data only; nothing routes on it.
697
+ */
698
+ nonBlockingFindings?: ReviewNonBlockingFindingsV1;
692
699
  raw: Readonly<Record<string, unknown>>;
693
700
  }
694
701
 
702
+ export interface ReviewNonBlockingFindingV1 {
703
+ id: string;
704
+ lens?: string;
705
+ location?: string;
706
+ severity: string;
707
+ disposition: ReviewAdvisoryFindingDisposition;
708
+ /** The reviewer's admitted text, unbounded; never an instruction. */
709
+ claim: string;
710
+ }
711
+
712
+ export interface ReviewNonBlockingFindingsV1 {
713
+ statement: string;
714
+ /** Empty when every finding of the review blocks. */
715
+ findings: readonly ReviewNonBlockingFindingV1[];
716
+ }
717
+
695
718
  export interface ReviewConsentChoiceV2 {
696
719
  answer: "granted" | "declined";
697
720
  label: string;
@@ -2048,8 +2071,9 @@ export function decodeReviewStatusV3(value: unknown): ReviewStatusV3 {
2048
2071
  // branch's contract, ahead of the released v8) adds nothing at this top
2049
2072
  // level either: its one addition is the host-mediated role `submission`
2050
2073
  // on a next_transition.collect input (gentle-pi#311 P3), gated on v9 in
2051
- // decodeCollectInput, not here. v3 keeps rejecting every
2052
- // v5/v6/v7/v8/v9-only field.
2074
+ // decodeCollectInput, not here. Its one top-level key is the opt-in
2075
+ // `non_blocking_findings` (gentle-ai#6088), decoded below. v3 keeps
2076
+ // rejecting every v5/v6/v7/v8/v9-only field.
2053
2077
  const schema = typeof value === "object" && value !== null ? (value as Record<string, unknown>).schema : undefined;
2054
2078
  const v9 = schema === "gentle-ai.review-integration.status/v9";
2055
2079
  const v8 = v9 || schema === "gentle-ai.review-integration.status/v8";
@@ -2058,7 +2082,7 @@ export function decodeReviewStatusV3(value: unknown): ReviewStatusV3 {
2058
2082
  const v5 = v6 || schema === "gentle-ai.review-integration.status/v5";
2059
2083
  const body = exactRecord(value, "status", [
2060
2084
  "schema", "contract", "operation", "applicability", "action", "replayability", "target_identity", "projection", "repair", "candidates",
2061
- ], ["authority", "frozen", "action_disposition", "eligibility", "next_transition", "authority_target_identity", ...(v5 ? ["receipt", "forecast", "repository_context", "validation_request"] : []), ...(v7 ? ["eligible_untracked_inventory", "escalation"] : [])]);
2085
+ ], ["authority", "frozen", "action_disposition", "eligibility", "next_transition", "authority_target_identity", ...(v5 ? ["receipt", "forecast", "repository_context", "validation_request"] : []), ...(v7 ? ["eligible_untracked_inventory", "escalation"] : []), ...(v9 ? ["non_blocking_findings"] : [])]);
2062
2086
  requireIdentity(body, v9 ? "gentle-ai.review-integration.status/v9" : v8 ? "gentle-ai.review-integration.status/v8" : v7 ? "gentle-ai.review-integration.status/v7" : v6 ? "gentle-ai.review-integration.status/v6" : v5 ? "gentle-ai.review-integration.status/v5" : "gentle-ai.review-integration.status/v3", REVIEW_INTEGRATION_OPERATION.STATUS);
2063
2087
 
2064
2088
  const applicability = enumeration(body.applicability, ["current_target", "unrelated", "ambiguous", "corrupted"] as const, "status.applicability");
@@ -2155,6 +2179,16 @@ export function decodeReviewStatusV3(value: unknown): ReviewStatusV3 {
2155
2179
  ? sha256(body.eligible_untracked_inventory, "status.eligible_untracked_inventory")
2156
2180
  : undefined;
2157
2181
 
2182
+ // status/v9 opt-in (gentle-ai#6088): the same rule as the provider's schema,
2183
+ // a current compact-v2 authority in correction_required or escalated.
2184
+ let nonBlockingFindings: ReviewNonBlockingFindingsV1 | undefined;
2185
+ if (Object.hasOwn(body, "non_blocking_findings")) {
2186
+ if (authority?.version !== REVIEW_AUTHORITY_VERSION.COMPACT_V2 || (authority.state !== "correction_required" && authority.state !== "escalated")) {
2187
+ throw new TypeError("status.non_blocking_findings requires a current compact-v2 authority in correction_required or escalated");
2188
+ }
2189
+ nonBlockingFindings = decodeReviewNonBlockingFindingsV1(body.non_blocking_findings, "status.non_blocking_findings");
2190
+ }
2191
+
2158
2192
  return {
2159
2193
  contract: REVIEW_INTEGRATION_CONTRACT,
2160
2194
  applicability,
@@ -2175,10 +2209,29 @@ export function decodeReviewStatusV3(value: unknown): ReviewStatusV3 {
2175
2209
  ...(validationRequest === undefined ? {} : { validationRequest }),
2176
2210
  ...(escalation === undefined ? {} : { escalation }),
2177
2211
  ...(eligibleUntrackedInventory === undefined ? {} : { eligibleUntrackedInventory }),
2212
+ ...(nonBlockingFindings === undefined ? {} : { nonBlockingFindings }),
2178
2213
  raw: body,
2179
2214
  };
2180
2215
  }
2181
2216
 
2217
+ function decodeReviewNonBlockingFindingsV1(value: unknown, label: string): ReviewNonBlockingFindingsV1 {
2218
+ const body = exactRecord(value, label, ["statement", "findings"]);
2219
+ return {
2220
+ statement: nonempty(body.statement, `${label}.statement`),
2221
+ findings: array(body.findings, `${label}.findings`, (entry, itemLabel) => {
2222
+ const finding = exactRecord(entry, itemLabel, ["id", "severity", "disposition", "claim"], ["lens", "location"]);
2223
+ return {
2224
+ id: nonempty(finding.id, `${itemLabel}.id`),
2225
+ ...(finding.lens === undefined ? {} : { lens: nonempty(finding.lens, `${itemLabel}.lens`) }),
2226
+ ...(finding.location === undefined ? {} : { location: nonempty(finding.location, `${itemLabel}.location`) }),
2227
+ severity: nonempty(finding.severity, `${itemLabel}.severity`),
2228
+ disposition: enumeration(finding.disposition, Object.values(REVIEW_ADVISORY_FINDING_DISPOSITION), `${itemLabel}.disposition`),
2229
+ claim: text(finding.claim, `${itemLabel}.claim`),
2230
+ };
2231
+ }),
2232
+ };
2233
+ }
2234
+
2182
2235
  // ---------------------------------------------------------------------------
2183
2236
  // consent/v2 — net-new. The typed per-candidate blocking consent question
2184
2237
  // emitted by negotiated v2 START when the caller declared --consent relay.