gentle-pi 4.6.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 (536) hide show
  1. package/README.md +65 -55
  2. package/assets/agents/gentle-ai-explore.md +4 -3
  3. package/assets/agents/gentle-ai-verify.md +23 -6
  4. package/assets/agents/gentle-ai-worker.md +9 -6
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +2 -3
  7. package/assets/agents/jd-judge-b.md +2 -3
  8. package/assets/agents/review-readability.md +1 -5
  9. package/assets/agents/review-reliability.md +1 -5
  10. package/assets/agents/review-resilience.md +1 -5
  11. package/assets/agents/review-risk.md +1 -5
  12. package/assets/design-canvas/canvas-api.js +45 -0
  13. package/assets/design-canvas/canvas-boards.js +456 -0
  14. package/assets/design-canvas/canvas-boot.js +217 -0
  15. package/assets/design-canvas/canvas-checks.js +491 -0
  16. package/assets/design-canvas/canvas-comments.js +315 -0
  17. package/assets/design-canvas/canvas-compare.js +159 -0
  18. package/assets/design-canvas/canvas-events.js +75 -0
  19. package/assets/design-canvas/canvas-export.js +393 -0
  20. package/assets/design-canvas/canvas-focus.js +203 -0
  21. package/assets/design-canvas/canvas-handoffs.js +150 -0
  22. package/assets/design-canvas/canvas-i18n-es.js +392 -0
  23. package/assets/design-canvas/canvas-i18n.js +108 -0
  24. package/assets/design-canvas/canvas-layout.js +526 -0
  25. package/assets/design-canvas/canvas-menu.js +213 -0
  26. package/assets/design-canvas/canvas-messages.js +86 -0
  27. package/assets/design-canvas/canvas-minimap.js +163 -0
  28. package/assets/design-canvas/canvas-parts.js +401 -0
  29. package/assets/design-canvas/canvas-popover.js +234 -0
  30. package/assets/design-canvas/canvas-rail.js +348 -0
  31. package/assets/design-canvas/canvas-sizes.js +524 -0
  32. package/assets/design-canvas/canvas-store.js +164 -0
  33. package/assets/design-canvas/canvas-tokens.js +674 -0
  34. package/assets/design-canvas/canvas-ui.js +24 -0
  35. package/assets/design-canvas/canvas-view.js +184 -0
  36. package/assets/design-canvas/canvas.css +759 -16
  37. package/assets/design-canvas/canvas.js +2 -1497
  38. package/assets/design-canvas/index.html +117 -36
  39. package/assets/design-canvas/inspector.js +546 -16
  40. package/assets/install-wizard/wizard.js +6 -1
  41. package/assets/migrations/agent-body-history.json +40 -1
  42. package/assets/orchestrator-delegation-reference.md +10 -16
  43. package/assets/orchestrator-delegation.md +5 -5
  44. package/assets/orchestrator-full-delegation-card.md +64 -0
  45. package/assets/orchestrator-full-delegation.md +34 -0
  46. package/assets/orchestrator-memory.md +5 -5
  47. package/assets/orchestrator-prompts.md +2 -2
  48. package/assets/orchestrator-quota-recovery.md +5 -0
  49. package/assets/orchestrator-skills.md +14 -13
  50. package/assets/orchestrator-tracking.md +10 -14
  51. package/assets/orchestrator-verification.md +12 -8
  52. package/assets/orchestrator-writer.md +4 -4
  53. package/assets/orchestrator.md +21 -25
  54. package/bin/gentle-shell.mjs +292 -65
  55. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  56. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/manifest.json +3 -3
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/orchestration/pi.md +1 -0
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/routing/pi.md +6 -6
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-capabilities.baseline.json +3 -3
  60. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/generated/provider-roles.baseline.json +1 -1
  61. package/docs/agent-status.md +61 -0
  62. package/docs/assets/brand/sponsor-banner.svg +60 -0
  63. package/docs/bundled-install.md +20 -10
  64. package/docs/delegated-verification.md +46 -8
  65. package/docs/desktop-rpc.md +1253 -0
  66. package/docs/gentle-agents-activity.md +40 -0
  67. package/docs/gentle-shell.md +91 -30
  68. package/docs/install-wizard.md +30 -21
  69. package/docs/odd-preparation-continuity.md +24 -0
  70. package/docs/permission-modes.md +17 -4
  71. package/docs/prompt-budget.md +12 -0
  72. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  73. package/docs/readme-reference.md +142 -45
  74. package/docs/render-cache-performance.md +11 -1
  75. package/docs/review-coordinator.md +53 -0
  76. package/docs/review-delivery-preflight.md +22 -0
  77. package/docs/review-request-context.md +19 -0
  78. package/docs/review-windows-acl.md +18 -0
  79. package/docs/voice.md +6 -3
  80. package/docs/work-continuity.md +11 -1
  81. package/docs/yolo-mode.md +5 -5
  82. package/extensions/ask-user-choice.ts +1 -0
  83. package/extensions/ask-user-question.ts +3 -2
  84. package/extensions/child-context.ts +21 -7
  85. package/extensions/child-safety.ts +3 -0
  86. package/extensions/gentle-agent-status.ts +99 -0
  87. package/extensions/gentle-agents.ts +559 -66
  88. package/extensions/gentle-ai.ts +2001 -518
  89. package/extensions/gentle-design.ts +69 -3
  90. package/extensions/gentle-desktop-rpc.ts +143 -0
  91. package/extensions/gentle-guide.ts +3 -0
  92. package/extensions/gentle-shell.ts +398 -115
  93. package/extensions/gentle-todo.ts +66 -27
  94. package/extensions/gentle-tps.ts +48 -0
  95. package/extensions/quiet-tools.ts +38 -8
  96. package/extensions/skill-registry.ts +349 -167
  97. package/extensions/startup-banner.ts +30 -3
  98. package/lib/agent-assets.ts +30 -6
  99. package/lib/agent-profile-pin.ts +3 -3
  100. package/lib/agent-profiles.ts +160 -2
  101. package/lib/agent-status.ts +105 -0
  102. package/lib/agent-tool-overlay.ts +117 -0
  103. package/lib/agents-config.ts +93 -6
  104. package/lib/agents-history.ts +24 -5
  105. package/lib/agents-message-delivery.ts +17 -0
  106. package/lib/agents-messaging.ts +55 -7
  107. package/lib/agents-protocol.ts +15 -0
  108. package/lib/agents-report-cap.ts +115 -0
  109. package/lib/agents-runner.ts +272 -16
  110. package/lib/agents-session-transport.ts +17 -1
  111. package/lib/auto-permission-runtime.ts +1 -1
  112. package/lib/background-jobs-tools.ts +9 -4
  113. package/lib/bounded-writer-admission.ts +197 -32
  114. package/lib/card-content-policy.ts +8 -6
  115. package/lib/child-context-files.ts +21 -6
  116. package/lib/codemode-renderer.ts +1 -0
  117. package/lib/command-palette.ts +133 -17
  118. package/lib/context-backstop.ts +14 -5
  119. package/lib/delivery-conflict-markers.ts +349 -0
  120. package/lib/design-canvas-assets.ts +36 -0
  121. package/lib/design-canvas-server.ts +241 -23
  122. package/lib/design-comments.ts +94 -4
  123. package/lib/design-handoffs.ts +2 -1
  124. package/lib/design-layout.ts +125 -0
  125. package/lib/design-parts.ts +281 -0
  126. package/lib/design-system-tokens.ts +111 -0
  127. package/lib/desktop-agents-service.ts +294 -0
  128. package/lib/desktop-design-service.ts +233 -0
  129. package/lib/desktop-jobs-service.ts +263 -0
  130. package/lib/desktop-rpc-agents.ts +294 -0
  131. package/lib/desktop-rpc-config.ts +731 -0
  132. package/lib/desktop-rpc-design.ts +138 -0
  133. package/lib/desktop-rpc-jobs.ts +181 -0
  134. package/lib/desktop-rpc-permissions.ts +177 -0
  135. package/lib/desktop-rpc-profiles.ts +196 -0
  136. package/lib/desktop-rpc-usage.ts +229 -0
  137. package/lib/desktop-rpc.ts +225 -0
  138. package/lib/desktop-usage-service.ts +310 -0
  139. package/lib/destructive-command-guard.ts +236 -17
  140. package/lib/execution-surface-guard.ts +20 -0
  141. package/lib/exploration-budget.ts +4 -2
  142. package/lib/gentle-ai-binary.ts +1 -1
  143. package/lib/gentle-ai-renderer.ts +13 -1
  144. package/lib/gentle-design.ts +204 -14
  145. package/lib/gentle-shell-bundled.ts +106 -28
  146. package/lib/gentle-shell-launcher.ts +43 -8
  147. package/lib/herdr-activity.ts +14 -2
  148. package/lib/herdr-busy.ts +45 -0
  149. package/lib/hidden-tools.ts +35 -0
  150. package/lib/image-attachments.ts +33 -0
  151. package/lib/image-disk-cache.ts +137 -0
  152. package/lib/inprocess-reviewer.ts +358 -144
  153. package/lib/jobs-view.ts +198 -11
  154. package/lib/model-fallback-policy.ts +9 -0
  155. package/lib/model-routing-authority.ts +31 -4
  156. package/lib/nan-provider.ts +42 -28
  157. package/lib/native-choice-list.ts +20 -2
  158. package/lib/native-review-cli.ts +172 -20
  159. package/lib/orchestrator-discovery.ts +39 -2
  160. package/lib/orchestrator-mode-policy.ts +105 -0
  161. package/lib/questionnaire/questionnaire-view.ts +105 -12
  162. package/lib/rdd-mode-control.ts +32 -0
  163. package/lib/reply-language-anchor.ts +129 -0
  164. package/lib/request-context-placement.ts +53 -0
  165. package/lib/review-blocker.ts +92 -0
  166. package/lib/review-candidate-symlink-scan.ts +136 -0
  167. package/lib/review-candidate-view-owner.ts +81 -44
  168. package/lib/review-candidate-view.ts +11 -1
  169. package/lib/review-continuation-registry.ts +116 -0
  170. package/lib/review-coordinator.ts +407 -0
  171. package/lib/review-delivery-preflight.ts +85 -0
  172. package/lib/review-failure-facts.ts +49 -0
  173. package/lib/review-host-relay.ts +51 -11
  174. package/lib/review-integration-v2.ts +63 -4
  175. package/lib/review-relay-phase-timing.ts +45 -0
  176. package/lib/review-start-context.ts +17 -0
  177. package/lib/reviewer-stream.ts +87 -0
  178. package/lib/session-profile-freeze.ts +4 -2
  179. package/lib/shell-bar.ts +140 -58
  180. package/lib/shell-changes.ts +2 -0
  181. package/lib/shell-panel.ts +17 -3
  182. package/lib/shell-prompt.ts +16 -3
  183. package/lib/shell-sidebar-layout.ts +112 -40
  184. package/lib/shell-sidebar.ts +7 -0
  185. package/lib/shell-todo.ts +10 -3
  186. package/lib/shell-usage.ts +10 -0
  187. package/lib/verifier-admission.ts +1 -1
  188. package/lib/vim-editor-adapter.ts +9 -2
  189. package/lib/visual-customization-policy.ts +36 -16
  190. package/lib/visual-customize-view.ts +216 -21
  191. package/lib/visual-layout-preview.ts +9 -5
  192. package/lib/visual-profiles.ts +2 -2
  193. package/lib/windows-session-transport.ts +53 -2
  194. package/lib/writer-batch-admission.ts +55 -0
  195. package/lib/yolo-session-policy.ts +46 -16
  196. package/package.json +3 -2
  197. package/prompts/skill-creation.md +1 -10
  198. package/runtime/design-canvas-assets.mjs +37 -0
  199. package/runtime/gentle-ai-binary.mjs +1 -1
  200. package/runtime/gentle-shell-bundled.mjs +106 -28
  201. package/runtime/gentle-shell-launcher.mjs +42 -7
  202. package/runtime/native-review-cli.mjs +169 -17
  203. package/runtime/review-integration-v2.mjs +63 -4
  204. package/scripts/bootstrap.cmd +2 -2
  205. package/scripts/bootstrap.sh +41 -4
  206. package/scripts/build-full-delegation-card.mjs +179 -0
  207. package/scripts/build-runtime-modules.mjs +1 -0
  208. package/scripts/bundled-install.mjs +38 -8
  209. package/scripts/download-progress.mjs +68 -0
  210. package/scripts/gentle-ai-installer.mjs +41 -18
  211. package/scripts/gentle-ai-proxy.mjs +294 -0
  212. package/scripts/install-gentle-ai.mjs +14 -1
  213. package/scripts/installer-downloads.mjs +34 -8
  214. package/scripts/installer-preflight.mjs +33 -22
  215. package/scripts/installer-probes.mjs +25 -5
  216. package/scripts/installer-runner.mjs +27 -12
  217. package/scripts/installer-server.mjs +46 -16
  218. package/scripts/installer-windows.mjs +2 -2
  219. package/scripts/pi-update.mjs +166 -27
  220. package/scripts/prepare-verifier.mjs +107 -0
  221. package/scripts/render-cache-host.mjs +72 -0
  222. package/scripts/render-cache-performance-worker.mjs +5 -4
  223. package/scripts/render-cache-performance.mjs +6 -1
  224. package/scripts/run-test-suite.mjs +40 -28
  225. package/scripts/update-agent-body-history.mjs +55 -8
  226. package/scripts/verify-package-files.mjs +50 -19
  227. package/scripts/voice-worker.cjs +32 -6
  228. package/skills/branch-pr/SKILL.md +16 -16
  229. package/skills/comment-writer/SKILL.md +1 -1
  230. package/skills/design/SKILL.md +16 -13
  231. package/skills/gentle-ai/SKILL.md +7 -7
  232. package/skills/gentle-ui-design/SKILL.md +46 -0
  233. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  234. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  235. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  236. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  237. package/skills/judgment-day/SKILL.md +2 -2
  238. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  239. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  240. package/skills/skill-improver/SKILL.md +2 -2
  241. package/skills/skill-registry/SKILL.md +11 -11
  242. package/skills/tui-design/SKILL.md +1 -1
  243. package/skills/work-unit-commits/SKILL.md +10 -11
  244. package/tests/agent-home.test.ts +28 -9
  245. package/tests/agent-profiles-workflow.test.ts +163 -0
  246. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  247. package/tests/agent-risk-escalation.test.ts +1 -1
  248. package/tests/agent-status.test.ts +143 -0
  249. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  250. package/tests/agent-tool-overlay.test.ts +89 -0
  251. package/tests/agents-config.test.ts +106 -1
  252. package/tests/agents-history.test.ts +31 -0
  253. package/tests/agents-jobs-frames.test.ts +93 -0
  254. package/tests/agents-message-delivery.test.ts +36 -0
  255. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  256. package/tests/agents-queries.test.ts +144 -4
  257. package/tests/agents-report-cap.test.ts +126 -0
  258. package/tests/agents-runner-drain.test.ts +193 -0
  259. package/tests/agents-runner.test.ts +215 -3
  260. package/tests/agents-session-transport.test.ts +34 -0
  261. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  262. package/tests/append-system-prompt-route.test.ts +12 -1
  263. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  264. package/tests/artifact-language.test.ts +1 -1
  265. package/tests/ask-user-choice.test.ts +4 -3
  266. package/tests/ask-user-question.test.ts +99 -1
  267. package/tests/audit-leftovers-contract.test.ts +51 -0
  268. package/tests/auto-permission-runtime.test.ts +1 -1
  269. package/tests/autonomous-guard.test.ts +346 -10
  270. package/tests/bounded-stop-contract.test.ts +51 -3
  271. package/tests/branch-pr-skill.test.ts +10 -1
  272. package/tests/bridge-cost.test.ts +19 -4
  273. package/tests/bundled-install.test.ts +31 -6
  274. package/tests/card-content-policy.test.ts +3 -3
  275. package/tests/chained-pr-skill.test.ts +8 -6
  276. package/tests/child-context-files.test.ts +64 -8
  277. package/tests/child-safety.test.ts +11 -0
  278. package/tests/child-skills-catalog.test.ts +56 -0
  279. package/tests/codegraph-tools.test.ts +11 -5
  280. package/tests/codemode-rendering.test.ts +4 -1
  281. package/tests/command-palette.test.ts +284 -1
  282. package/tests/delegate-for-reason-contract.test.ts +32 -10
  283. package/tests/delivery-conflict-markers.test.ts +348 -0
  284. package/tests/design-canvas-all-sizes.test.ts +631 -0
  285. package/tests/design-canvas-allowlist.test.ts +32 -0
  286. package/tests/design-canvas-assets.test.ts +11 -695
  287. package/tests/design-canvas-boards.test.ts +77 -0
  288. package/tests/design-canvas-checks.test.ts +655 -0
  289. package/tests/design-canvas-compare.test.ts +79 -0
  290. package/tests/design-canvas-events.test.ts +59 -0
  291. package/tests/design-canvas-export.test.ts +1168 -0
  292. package/tests/design-canvas-focus.test.ts +113 -0
  293. package/tests/design-canvas-handoffs.test.ts +59 -0
  294. package/tests/design-canvas-i18n-review.test.ts +513 -0
  295. package/tests/design-canvas-i18n-views.test.ts +259 -0
  296. package/tests/design-canvas-i18n.test.ts +526 -0
  297. package/tests/design-canvas-inspector.test.ts +937 -0
  298. package/tests/design-canvas-layout.test.ts +1222 -0
  299. package/tests/design-canvas-minimap.test.ts +413 -0
  300. package/tests/design-canvas-modules.test.ts +90 -0
  301. package/tests/design-canvas-parts.test.ts +721 -0
  302. package/tests/design-canvas-rail.test.ts +799 -0
  303. package/tests/design-canvas-server.test.ts +855 -17
  304. package/tests/design-canvas-sizes.test.ts +548 -0
  305. package/tests/design-canvas-store.test.ts +180 -0
  306. package/tests/design-canvas-tokens.test.ts +965 -0
  307. package/tests/design-canvas-view.test.ts +299 -0
  308. package/tests/design-comments.test.ts +201 -1
  309. package/tests/design-handoffs.test.ts +20 -0
  310. package/tests/design-layout.test.ts +100 -0
  311. package/tests/design-parts.test.ts +260 -0
  312. package/tests/design-system-tokens.test.ts +215 -0
  313. package/tests/desktop-rpc-agents.test.ts +893 -0
  314. package/tests/desktop-rpc-config.test.ts +1452 -0
  315. package/tests/desktop-rpc-design.test.ts +662 -0
  316. package/tests/desktop-rpc-jobs.test.ts +796 -0
  317. package/tests/desktop-rpc-permissions.test.ts +311 -0
  318. package/tests/desktop-rpc-profiles.test.ts +140 -0
  319. package/tests/desktop-rpc-safety.test.ts +119 -0
  320. package/tests/desktop-rpc-usage.test.ts +697 -0
  321. package/tests/desktop-rpc.test.ts +252 -0
  322. package/tests/destructive-command-guard.test.ts +52 -0
  323. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  324. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  325. package/tests/download-progress.test.ts +71 -0
  326. package/tests/engram-safety.test.ts +111 -0
  327. package/tests/execution-surface-guard.test.ts +55 -0
  328. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  329. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  330. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +26 -31
  331. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  332. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  333. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  334. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  335. package/tests/fixtures/session-profile-v1/replay.ts +53 -6
  336. package/tests/full-delegation-closure.test.ts +160 -0
  337. package/tests/full-delegation-notices.test.ts +76 -0
  338. package/tests/generic-agent-tools.test.ts +3 -3
  339. package/tests/gentle-agent-status.test.ts +74 -0
  340. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  341. package/tests/gentle-agents.test.ts +1403 -20
  342. package/tests/gentle-ai-binary.test.ts +3 -1
  343. package/tests/gentle-ai-child-guards.test.ts +1 -0
  344. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  345. package/tests/gentle-ai-exploration-budget.test.ts +18 -2
  346. package/tests/gentle-ai-installer.test.ts +135 -51
  347. package/tests/gentle-ai-proxy.test.ts +434 -0
  348. package/tests/gentle-ai-renderer.test.ts +36 -2
  349. package/tests/gentle-ai.test.ts +233 -43
  350. package/tests/gentle-design.test.ts +386 -1
  351. package/tests/gentle-herdr-activity.test.ts +9 -6
  352. package/tests/gentle-shell-bin.test.ts +123 -0
  353. package/tests/gentle-shell-bundled.test.ts +293 -31
  354. package/tests/gentle-shell-launcher.test.ts +78 -11
  355. package/tests/gentle-shell.test.ts +1017 -146
  356. package/tests/gentle-todo.test.ts +51 -11
  357. package/tests/gentle-tps.test.ts +123 -0
  358. package/tests/gentle-ui-design-skill.test.ts +59 -0
  359. package/tests/herdr-busy.test.ts +59 -0
  360. package/tests/herdr-task-summary-policy.test.ts +8 -4
  361. package/tests/hidden-tools.test.ts +188 -0
  362. package/tests/image-disk-cache.test.ts +163 -0
  363. package/tests/independent-recovery-delivery.test.ts +97 -0
  364. package/tests/inprocess-reviewer.test.ts +249 -4
  365. package/tests/install-wizard.test.ts +27 -1
  366. package/tests/installer-downloads.test.ts +30 -1
  367. package/tests/installer-posix-bootstrap.test.ts +115 -14
  368. package/tests/installer-preflight.test.ts +54 -5
  369. package/tests/installer-probes.test.ts +146 -0
  370. package/tests/installer-runner.test.ts +79 -44
  371. package/tests/installer-server.test.ts +215 -13
  372. package/tests/installer-windows-bootstrap.test.ts +19 -1
  373. package/tests/jobs-view.test.ts +260 -6
  374. package/tests/judgment-day-severity-admission.test.ts +46 -0
  375. package/tests/lazy-module-contradictions-contract.test.ts +158 -0
  376. package/tests/maintainer/desktop-rpc.maintest.ts +632 -0
  377. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  378. package/tests/modal-mouse-boundaries.test.ts +136 -0
  379. package/tests/model-fallback-policy.test.ts +26 -7
  380. package/tests/model-routing-authority.test.ts +178 -2
  381. package/tests/nan-provider-runtime.test.ts +17 -3
  382. package/tests/nan-provider.test.ts +111 -56
  383. package/tests/native-choice-list.test.ts +77 -2
  384. package/tests/native-review-capability-contract.test.ts +17 -1
  385. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  386. package/tests/native-review-cli.test.ts +269 -1
  387. package/tests/native-review-parity.test.ts +24 -5
  388. package/tests/native-review-refusal-identity.test.ts +25 -0
  389. package/tests/no-self-pause-contract.test.ts +13 -2
  390. package/tests/odd-integration.test.ts +11 -3
  391. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  392. package/tests/odd-routing-contract.test.ts +80 -28
  393. package/tests/orchestrator-budget.test.ts +35 -5
  394. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  395. package/tests/orchestrator-delegation-mode.test.ts +154 -0
  396. package/tests/orchestrator-discovery.test.ts +28 -0
  397. package/tests/orchestrator-mode-policy.test.ts +175 -0
  398. package/tests/orchestrator-prompt-budget.test.ts +13 -2
  399. package/tests/orchestrator-prompt-diet-contract.test.ts +221 -0
  400. package/tests/orchestrator-rdd-ownership.test.ts +4 -3
  401. package/tests/orchestrator-work-search.test.ts +4 -2
  402. package/tests/package-files.test.ts +25 -1
  403. package/tests/package-manifest.test.ts +16 -13
  404. package/tests/parallel-reason-contract.test.ts +6 -3
  405. package/tests/permission-allowlist.test.ts +372 -0
  406. package/tests/persona-neutral-voseo.test.ts +4 -4
  407. package/tests/persona-reply-language.test.ts +1 -1
  408. package/tests/persona-single-channel.test.ts +13 -5
  409. package/tests/pi-update-launcher.test.ts +25 -7
  410. package/tests/pi-update-source.test.ts +113 -6
  411. package/tests/pi-update.test.ts +294 -19
  412. package/tests/pnpm-workspace-config.test.ts +58 -0
  413. package/tests/pnpm-workspace-policy.test.ts +47 -0
  414. package/tests/primary-context-files.test.ts +233 -0
  415. package/tests/primary-context-three-files.test.ts +174 -0
  416. package/tests/primary-session-prompt.test.ts +13 -0
  417. package/tests/profile-pin.test.ts +29 -2
  418. package/tests/profile-tier-footer.test.ts +5 -0
  419. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  420. package/tests/provider-defect-handoff.test.ts +9 -2
  421. package/tests/questionnaire-view.test.ts +115 -0
  422. package/tests/quiet-bash-runtime.test.ts +1 -1
  423. package/tests/quiet-tool-rendering.test.ts +48 -0
  424. package/tests/rdd-aware-verification-contract.test.ts +17 -12
  425. package/tests/rdd-customize.test.ts +287 -0
  426. package/tests/rdd-mode-cache.test.ts +450 -0
  427. package/tests/rdd-mode-control.test.ts +407 -0
  428. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  429. package/tests/rdd-off-independent-regression.test.ts +69 -0
  430. package/tests/rdd-status-line.test.ts +112 -1
  431. package/tests/render-cache-performance.test.ts +171 -2
  432. package/tests/reply-language-anchor-placement.test.ts +184 -0
  433. package/tests/reply-language-anchor.test.ts +189 -0
  434. package/tests/request-context-append-only.test.ts +218 -0
  435. package/tests/request-context-placement.test.ts +148 -0
  436. package/tests/review-agent-end-preflight.test.ts +80 -2
  437. package/tests/review-blocker.test.ts +193 -0
  438. package/tests/review-candidate-owner-retry.test.ts +1 -1
  439. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  440. package/tests/review-candidate-view.test.ts +66 -1
  441. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  442. package/tests/review-candidate-windows-probe.test.ts +63 -0
  443. package/tests/review-committed-restart-ack.test.ts +129 -0
  444. package/tests/review-continuation-registry.test.ts +107 -0
  445. package/tests/review-contract-prompt.test.ts +1 -1
  446. package/tests/review-controller-native-routing.test.ts +261 -5
  447. package/tests/review-controller-workspace-root.test.ts +230 -3
  448. package/tests/review-controller.test.ts +98 -12
  449. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  450. package/tests/review-coordinator-findings.test.ts +206 -0
  451. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  452. package/tests/review-coordinator-runtime.test.ts +117 -0
  453. package/tests/review-coordinator.test.ts +462 -0
  454. package/tests/review-delivery-preflight.test.ts +462 -0
  455. package/tests/review-due-compaction.test.ts +31 -0
  456. package/tests/review-due-public-boundary.test.ts +26 -0
  457. package/tests/review-failure-facts.test.ts +87 -0
  458. package/tests/review-host-relay-routing.test.ts +258 -4
  459. package/tests/review-host-relay.test.ts +39 -0
  460. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  461. package/tests/review-integration-v2.test.ts +46 -3
  462. package/tests/review-json-arguments.test.ts +105 -11
  463. package/tests/review-last-event-closure.test.ts +68 -0
  464. package/tests/review-ledger-contract.test.ts +19 -40
  465. package/tests/review-loadout-rdd-off-sdk.test.ts +95 -32
  466. package/tests/review-one-call-findings.test.ts +131 -0
  467. package/tests/review-one-call-followups.test.ts +308 -0
  468. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  469. package/tests/review-one-call.test.ts +452 -0
  470. package/tests/review-owner-identity.test.ts +60 -24
  471. package/tests/review-relay-phase-timing.test.ts +128 -0
  472. package/tests/review-relay-transport-agent.test.ts +39 -2
  473. package/tests/review-reviewer-evidence.test.ts +223 -0
  474. package/tests/review-risk-assessment.test.ts +126 -8
  475. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  476. package/tests/review-session-standing-permission-controller.test.ts +53 -3
  477. package/tests/review-start-context.test.ts +19 -0
  478. package/tests/review-tool-prose-budget.test.ts +122 -0
  479. package/tests/reviewer-stream.test.ts +149 -0
  480. package/tests/run-test-suite.test.ts +122 -1
  481. package/tests/runtime-harness.mjs +4 -1
  482. package/tests/sensitive-path-tools.test.ts +181 -5
  483. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  484. package/tests/session-profile-binding.test.ts +19 -1
  485. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  486. package/tests/session-profile-extension.test.ts +2 -2
  487. package/tests/session-profile-v1-compat.test.ts +35 -1
  488. package/tests/shell-bar.test.ts +186 -42
  489. package/tests/shell-panel.test.ts +50 -22
  490. package/tests/shell-prompt.test.ts +17 -0
  491. package/tests/shell-sidebar-fullscreen.test.ts +5 -5
  492. package/tests/shell-sidebar-layout.test.ts +294 -23
  493. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  494. package/tests/shell-surface-transparent.test.ts +89 -0
  495. package/tests/shell-todo.test.ts +12 -0
  496. package/tests/shell-usage.test.ts +59 -10
  497. package/tests/skill-contradictions-contract.test.ts +122 -0
  498. package/tests/skill-registry-watcher.test.ts +216 -2
  499. package/tests/skill-registry.test.ts +1461 -5
  500. package/tests/startup-banner.test.ts +152 -1
  501. package/tests/startup-home-repo.test.ts +2 -0
  502. package/tests/support/design-canvas-dom.ts +369 -0
  503. package/tests/support/review-coordinator-runtime.ts +264 -0
  504. package/tests/task-size-routing-contract.test.ts +45 -12
  505. package/tests/test-strength-contract.test.ts +2 -1
  506. package/tests/todo-request-append-only.test.ts +214 -0
  507. package/tests/tool-batching-contract.test.ts +3 -1
  508. package/tests/update-agent-body-history.test.ts +138 -0
  509. package/tests/verification-tiers-contract.test.ts +229 -0
  510. package/tests/verifier-admission.test.ts +49 -0
  511. package/tests/verifier-preparation.test.ts +229 -0
  512. package/tests/verify-agent-contract.test.ts +20 -2
  513. package/tests/verify-first-launch-contract.test.ts +162 -11
  514. package/tests/vim-editor-adapter.test.ts +2 -2
  515. package/tests/visual-customization-policy.test.ts +39 -6
  516. package/tests/visual-customize-view.test.ts +573 -9
  517. package/tests/visual-layout-preview.test.ts +15 -1
  518. package/tests/visual-profiles.test.ts +11 -0
  519. package/tests/voice-worker.test.ts +73 -2
  520. package/tests/windows-session-transport.test.ts +126 -0
  521. package/tests/work-continuity-contract.test.ts +77 -6
  522. package/tests/writer-admission-messages.test.ts +232 -0
  523. package/tests/writer-batch-admission.test.ts +66 -0
  524. package/tests/writer-edit-surface-scope.test.ts +52 -20
  525. package/tests/writer-feature-document-admission.test.ts +276 -0
  526. package/tests/yolo-customize.test.ts +27 -4
  527. package/tests/yolo-mode.test.ts +62 -18
  528. package/tests/yolo-session-policy.test.ts +270 -1
  529. package/skills/_shared/review-ledger-contract.md +0 -106
  530. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/README.md +0 -0
  531. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/lens.schema.json +0 -0
  532. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/refuter.schema.json +0 -0
  533. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  534. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/lens.json +0 -0
  535. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/refuter.json +0 -0
  536. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.5.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -1,5 +1,6 @@
1
- import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth } from "@earendil-works/pi-tui";
1
+ import { isKeyRelease, matchesKey, truncateToWidth, visibleWidth, type TuiMouseEvent, type TuiMouseEventResult } from "@earendil-works/pi-tui";
2
2
  import { effectiveKey, type KeymapBindings } from "./keymaps.ts";
3
+ import { paintHoverable } from "./shell-hover.ts";
3
4
  import { stripAnsi } from "./terminal-theme.ts";
4
5
 
5
6
  // Command palette: a pure, curated, grouped overlay component for
@@ -137,6 +138,19 @@ const DEFAULT_ROWS = 40;
137
138
 
138
139
  type PaletteRow = { kind: "title"; text: string } | { kind: "blank" } | { kind: "item"; item: CommandPaletteItem; itemIndex: number };
139
140
 
141
+ interface PalettePointerHit {
142
+ y: number;
143
+ itemIndex: number;
144
+ }
145
+
146
+ interface PalettePointerFrame {
147
+ width: number;
148
+ height: number;
149
+ availableRows: number;
150
+ modelKey: string;
151
+ hits: PalettePointerHit[];
152
+ }
153
+
140
154
  function buildRows(groups: readonly CommandPaletteGroup[]): PaletteRow[] {
141
155
  const rows: PaletteRow[] = [];
142
156
  let itemIndex = 0;
@@ -168,7 +182,13 @@ export class CommandPalette {
168
182
  private query = "";
169
183
  private selected = 0;
170
184
  private completed = false;
185
+ private disposed = false;
171
186
  private capturing: CommandPaletteItem | undefined;
187
+ private hovered: number | undefined;
188
+ private pointerFrame: PalettePointerFrame | undefined;
189
+ private renderedWidth: number | undefined;
190
+ private renderedRows: number | undefined;
191
+ private renderedModelKey: string | undefined;
172
192
  private readonly groups: readonly CommandPaletteGroup[];
173
193
  private readonly done: (result: CommandPaletteResult) => void;
174
194
  private readonly theme: CommandPaletteTheme | undefined;
@@ -181,10 +201,55 @@ export class CommandPalette {
181
201
  this.rowsFn = rows;
182
202
  }
183
203
 
184
- invalidate(): void {}
204
+ invalidate(): void {
205
+ this.pointerFrame = undefined;
206
+ this.hovered = undefined;
207
+ this.renderedWidth = undefined;
208
+ }
209
+
210
+ dispose(): void {
211
+ this.disposed = true;
212
+ this.invalidate();
213
+ }
214
+
215
+ /** Mouse events are local to the last painted card, including its borders. */
216
+ handleMouse(event: TuiMouseEvent): TuiMouseEventResult | undefined {
217
+ if (this.completed || this.disposed || this.capturing) return undefined;
218
+ const frame = this.pointerFrame;
219
+ if (!frame || frame.width !== event.width || frame.height !== event.height ||
220
+ frame.availableRows !== this.rowsFn() || frame.modelKey !== this.modelKey()) {
221
+ this.pointerFrame = undefined;
222
+ const changed = this.setHover(undefined);
223
+ return changed && event.type === "move" && event.button === "none" ? { handled: true, render: true } : undefined;
224
+ }
225
+ const inside = event.x >= 2 && event.x < frame.width - 2 && event.y >= 0 && event.y < frame.height;
226
+ const hit = inside ? frame.hits.find((candidate) => candidate.y === event.y) : undefined;
227
+ if (event.type === "move" && event.button === "none") {
228
+ return { handled: true, render: this.setHover(hit?.itemIndex) };
229
+ }
230
+ if (event.type === "wheel" && inside && event.wheelDelta) {
231
+ const before = this.selected;
232
+ this.moveSelection(Math.sign(event.wheelDelta));
233
+ const changed = this.selected !== before;
234
+ const hoverChanged = this.setHover(undefined);
235
+ if (changed) this.pointerFrame = undefined;
236
+ return { handled: true, render: changed || hoverChanged };
237
+ }
238
+ if (event.button !== "left" || !hit) return undefined;
239
+ if (event.type === "press") return { handled: true, render: false };
240
+ if (event.type === "click") {
241
+ this.selected = hit.itemIndex;
242
+ this.pointerFrame = undefined;
243
+ this.runSelected();
244
+ return { handled: true, render: true };
245
+ }
246
+ return undefined;
247
+ }
185
248
 
186
249
  handleInput(data: string): void {
187
- if (this.completed || isKeyRelease(data)) return;
250
+ if (this.completed || this.disposed || isKeyRelease(data)) return;
251
+ this.pointerFrame = undefined;
252
+ this.hovered = undefined;
188
253
  // After Tab the next key is the one to assign, whatever it is; esc only cancels.
189
254
  if (this.capturing) {
190
255
  const item = this.capturing;
@@ -213,8 +278,7 @@ export class CommandPalette {
213
278
  return;
214
279
  }
215
280
  if (matchesKey(data, "enter") || matchesKey(data, "return")) {
216
- const item = itemAt(this.matches(), this.selected);
217
- if (item) this.finish({ type: "run", name: item.command });
281
+ this.runSelected();
218
282
  return;
219
283
  }
220
284
  if (matchesKey(data, "backspace")) {
@@ -229,9 +293,23 @@ export class CommandPalette {
229
293
  }
230
294
 
231
295
  render(width: number): string[] {
296
+ const availableRows = this.rowsFn();
297
+ const modelKey = this.modelKey();
298
+ if (this.renderedWidth !== width || this.renderedRows !== availableRows || this.renderedModelKey !== modelKey) this.hovered = undefined;
299
+ this.renderedWidth = width;
300
+ this.renderedRows = availableRows;
301
+ this.renderedModelKey = modelKey;
232
302
  const innerWidth = Math.max(1, width - CARD_PADDING);
233
- const maxTotalLines = Math.max(MIN_TOTAL_ROWS, Math.floor(this.rowsFn() * HEIGHT_RATIO));
234
- return renderPaletteCard(this.renderBody(innerWidth, maxTotalLines), width, this.theme);
303
+ const maxTotalLines = Math.max(MIN_TOTAL_ROWS, Math.floor(availableRows * HEIGHT_RATIO));
304
+ const hits: PalettePointerHit[] = [];
305
+ const frame = renderPaletteCard(this.renderBody(innerWidth, maxTotalLines, hits), width, this.theme);
306
+ // showCommandPalette caps the overlay at 85% even when the card's
307
+ // minimum height is larger. Only the actually visible prefix can act.
308
+ const visibleHeight = Math.min(frame.length, Math.max(1, Math.floor(availableRows * HEIGHT_RATIO)));
309
+ this.pointerFrame = this.disposed || this.completed || width <= CARD_PADDING ? undefined : {
310
+ width, height: visibleHeight, availableRows, modelKey, hits,
311
+ };
312
+ return frame;
235
313
  }
236
314
 
237
315
  /**
@@ -262,13 +340,30 @@ export class CommandPalette {
262
340
  return rankPaletteGroups(this.groups, this.query);
263
341
  }
264
342
 
343
+ private modelKey(): string {
344
+ return JSON.stringify(this.groups.map((group) => [group.title, group.items.map((item) => [item.command, item.label, item.description, item.shortcut])]));
345
+ }
346
+
347
+ private setHover(index: number | undefined): boolean {
348
+ if (this.hovered === index) return false;
349
+ this.hovered = index;
350
+ return true;
351
+ }
352
+
353
+ private runSelected(): void {
354
+ const item = itemAt(this.matches(), this.selected);
355
+ if (item) this.finish({ type: "run", name: item.command });
356
+ }
357
+
265
358
  private finish(result: CommandPaletteResult): void {
266
- if (this.completed) return;
359
+ if (this.completed || this.disposed) return;
267
360
  this.completed = true;
361
+ this.pointerFrame = undefined;
362
+ this.hovered = undefined;
268
363
  this.done(result);
269
364
  }
270
365
 
271
- private renderBody(width: number, maxTotalLines: number): string[] {
366
+ private renderBody(width: number, maxTotalLines: number, hits: PalettePointerHit[]): string[] {
272
367
  const lines: string[] = [];
273
368
  lines.push(this.renderHeaderRow(width));
274
369
  lines.push(this.query.length > 0 ? this.renderLine(`› ${this.query}`, width) : this.renderLine("› Search", width, "muted"));
@@ -278,7 +373,7 @@ export class CommandPalette {
278
373
  lines.push(this.renderLine(`No commands match "${this.query}"`, width, "muted"));
279
374
  } else {
280
375
  const budget = Math.max(1, maxTotalLines - CARD_BORDER_ROWS - CHROME_ROWS);
281
- lines.push(...this.renderGroups(groups, width, budget));
376
+ lines.push(...this.renderGroups(groups, width, budget, hits));
282
377
  }
283
378
  lines.push("");
284
379
  if (this.capturing) lines.push(this.renderLine(`Press the new key for ${this.capturing.label} · esc cancel`, width, "accent"));
@@ -292,37 +387,58 @@ export class CommandPalette {
292
387
  return this.justifyToWidth(left, right, width);
293
388
  }
294
389
 
295
- private renderGroups(groups: CommandPaletteGroup[], width: number, budget: number): string[] {
390
+ private renderGroups(groups: CommandPaletteGroup[], width: number, budget: number, hits: PalettePointerHit[]): string[] {
296
391
  const rows = buildRows(groups);
297
392
  const selected = Math.max(0, Math.min(countItems(groups) - 1, this.selected));
298
- if (rows.length <= budget) return rows.map((row) => this.renderRow(row, width, selected));
393
+ const result: string[] = [];
394
+ const appendRow = (row: PaletteRow) => {
395
+ if (row.kind === "item" && this.itemFits(row.item, width)) {
396
+ // Border + header, query and blank precede the grouped rows.
397
+ hits.push({ y: 4 + result.length, itemIndex: row.itemIndex });
398
+ }
399
+ result.push(this.renderRow(row, width, selected));
400
+ };
401
+ if (rows.length <= budget) {
402
+ for (const row of rows) appendRow(row);
403
+ return result;
404
+ }
299
405
  const windowSize = Math.max(1, budget - SCROLL_INDICATOR_ROWS);
300
406
  const selectedRowIndex = Math.max(0, rows.findIndex((row) => row.kind === "item" && row.itemIndex === selected));
301
407
  const start = Math.max(0, Math.min(selectedRowIndex - Math.floor(windowSize / 2), Math.max(0, rows.length - windowSize)));
302
408
  const end = Math.min(rows.length, start + windowSize);
303
- const result: string[] = [];
304
409
  if (start > 0) result.push(this.renderLine(` ↑ ${start} more`, width, "muted"));
305
410
  for (let i = start; i < end; i++) {
306
411
  const row = rows[i];
307
- if (row) result.push(this.renderRow(row, width, selected));
412
+ if (row) appendRow(row);
308
413
  }
309
414
  if (end < rows.length) result.push(this.renderLine(` ↓ ${rows.length - end} more`, width, "muted"));
310
415
  return result;
311
416
  }
312
417
 
418
+ private itemFits(item: CommandPaletteItem, width: number): boolean {
419
+ const label = sanitizeTerminalText(item.label);
420
+ const shortcut = item.shortcut ? sanitizeTerminalText(item.shortcut) : "";
421
+ return label.trim().length > 0 && 2 + visibleWidth(label) + (shortcut ? 1 + visibleWidth(shortcut) : 0) <= width;
422
+ }
423
+
313
424
  private renderRow(row: PaletteRow, width: number, selected: number): string {
314
425
  if (row.kind === "blank") return "";
315
426
  if (row.kind === "title") return this.renderLine(row.text, width, "accent");
316
- return this.renderItemRow(row.item, row.itemIndex === selected, width);
427
+ return this.renderItemRow(row.item, row.itemIndex === selected, width, this.hovered === row.itemIndex);
317
428
  }
318
429
 
319
- private renderItemRow(item: CommandPaletteItem, focused: boolean, width: number): string {
430
+ private renderItemRow(item: CommandPaletteItem, focused: boolean, width: number, hovered: boolean): string {
320
431
  const canHighlightBg = focused && this.theme?.bg !== undefined;
321
432
  const label = sanitizeTerminalText(item.label);
322
433
  const shortcut = item.shortcut ? sanitizeTerminalText(item.shortcut) : "";
323
434
  if (canHighlightBg) {
324
435
  const plainRow = this.justifyToWidth(` ${label}`, shortcut, width);
325
- return this.theme?.bg?.("selectedBg", plainRow) ?? plainRow;
436
+ const text = this.theme ? paintHoverable(this.theme, plainRow, hovered) : plainRow;
437
+ return this.theme?.bg?.("selectedBg", text) ?? text;
438
+ }
439
+ if (hovered && this.theme) {
440
+ const prefix = focused ? "▸ " : " ";
441
+ return paintHoverable(this.theme, prefix + this.justifyToWidth(label, shortcut, Math.max(0, width - 2)), true);
326
442
  }
327
443
  const prefix = focused ? this.renderText("▸ ", "accent") : " ";
328
444
  const prefixWidth = visibleWidth(stripAnsi(prefix));
@@ -1,4 +1,5 @@
1
1
  import type { ToolResultEvent, ToolResultEventResult } from "@earendil-works/pi-coding-agent";
2
+ import type { OrchestratorMode } from "./agent-profiles.ts";
2
3
 
3
4
  // Harness roadmap R1: the parent-context backstop was a fixed "~150k tokens" in
4
5
  // prompt text, so the model had to estimate its own context. The runtime now
@@ -48,18 +49,26 @@ export function contextBackstopReached(usage: MeasuredContext | undefined, env:
48
49
 
49
50
  const count = (value: number) => Math.round(value).toLocaleString("en-US");
50
51
 
51
- function contextBackstopNotice(tokens: number, contextWindow: number | null | undefined, threshold: number): string {
52
+ function contextBackstopNotice(tokens: number, contextWindow: number | null | undefined, threshold: number, fullDelegation: boolean): string {
52
53
  const share = positive(contextWindow) ? ` (${Math.round((tokens / contextWindow) * 100)}% of the ${count(contextWindow)}-token context window)` : "";
53
- return `Context backstop: the parent context measures ${count(tokens)} tokens${share}, at or past the ${count(threshold)}-token backstop: delegate the next bounded unit that needs several steps (its reads, edits, and checks) with a short handoff, while single small edits and state checks stay inline.`;
54
+ // In full delegation mode no edit stays with the parent, whatever its size, so the
55
+ // organic carve-out for small edits would contradict the session's own rules.
56
+ const tail = fullDelegation
57
+ ? "delegate the next bounded unit with a short handoff, and keep only state checks in this context."
58
+ : "delegate the next bounded unit that needs several steps (its reads, edits, and checks) with a short handoff, while single small edits and state checks stay inline.";
59
+ return `Context backstop: the parent context measures ${count(tokens)} tokens${share}, at or past the ${count(threshold)}-token backstop: ${tail}`;
54
60
  }
55
61
 
56
62
  /**
57
63
  * One notice per crossing for each session: the first measurement at or past the backstop returns it, and a
58
64
  * measurement below the backstop re-arms it (for example after compaction). Unknown tokens change nothing.
59
65
  */
60
- export function createContextBackstopSignal(env: Env = process.env): (session: unknown, usage: MeasuredContext | undefined) => string | undefined {
66
+ export function createContextBackstopSignal(
67
+ env: Env = process.env,
68
+ ): (session: unknown, usage: MeasuredContext | undefined, mode?: () => OrchestratorMode) => string | undefined {
61
69
  const notified = new Set<unknown>();
62
- return (session, usage) => {
70
+ // `mode` is a thunk: it is read only when a notice is emitted, never on every measurement.
71
+ return (session, usage, mode) => {
63
72
  if (typeof usage?.tokens !== "number") return undefined;
64
73
  const threshold = contextBackstopThreshold(usage.contextWindow, env);
65
74
  if (usage.tokens < threshold) {
@@ -68,7 +77,7 @@ export function createContextBackstopSignal(env: Env = process.env): (session: u
68
77
  }
69
78
  if (notified.has(session)) return undefined;
70
79
  notified.add(session);
71
- return contextBackstopNotice(usage.tokens, usage.contextWindow, threshold);
80
+ return contextBackstopNotice(usage.tokens, usage.contextWindow, threshold, mode?.() === "full-delegation");
72
81
  };
73
82
  }
74
83
 
@@ -0,0 +1,349 @@
1
+ import { execFile } from "node:child_process";
2
+ import { lstat, open } from "node:fs/promises";
3
+ import { join, resolve } from "node:path";
4
+ import { worktreeGitEnvironment } from "./session-worktree-registry.ts";
5
+
6
+ // cost-speed P9: a mechanical guard, not a review. It refuses a `git commit` (or
7
+ // a sequencer `--continue`) whose recorded content ADDS a full set of conflict
8
+ // markers, including what a `git add` earlier in the same command would stage.
9
+ // Pushes are not checked: the range a push publishes depends on remote refs this
10
+ // guard cannot trust offline, and blocking a legitimate push is worse than a gap
11
+ // the commit check already covers. It fails open on its own errors: unparsed
12
+ // shapes, unknown directories, git failures and the time budget let the command through.
13
+
14
+ type Denial = { block: true; reason: string };
15
+ /** What a `git add` (or `git stage`) earlier in the same command would stage. */
16
+ interface Staging { pathspecs: string[]; tracked: boolean; untracked: boolean; force: boolean }
17
+ /** The content a commit records: the index, or worktree content (tracked, and untracked when staged by `add`). */
18
+ type Source = { kind: "index" } | { kind: "worktree"; pathspecs: string[]; untracked: boolean; force: boolean };
19
+ export interface Check { directory: string; sources: Source[]; staged: Staging[] }
20
+ /** `redirect`: an unquoted redirection, complete (`2>&1`, `>out`) or needing the next word as its target (`>`). */
21
+ interface Token { value: string; operator: boolean; redirect?: "complete" | "target" }
22
+
23
+ const SHOWN = 5;
24
+ const BUDGET_MS = 5_000;
25
+ const MAX_BUFFER = 16 * 1024 * 1024;
26
+ const MAX_FILES = 200;
27
+ const MAX_UNTRACKED_BYTES = 1024 * 1024;
28
+ const EMPTY_TREE = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
29
+ const COMMIT_VALUE_OPTIONS = new Set(["-m", "-F", "-C", "-c", "-t", "--message", "--file", "--reuse-message", "--reedit-message",
30
+ "--template", "--author", "--date", "--cleanup", "--fixup", "--squash", "--trailer"]);
31
+ const SEQUENCERS = new Set(["merge", "rebase", "cherry-pick", "revert", "am"]);
32
+ // The second side of a commit that concludes a merge or applies a picked commit: a marker line counts only
33
+ // when it is added against HEAD and against this side. `revert` and `am` have no such side and stay one-sided.
34
+ const SECOND_SIDES = ["MERGE_HEAD", "CHERRY_PICK_HEAD", "REBASE_HEAD"];
35
+ const DIFF = ["--no-pager", "-c", "core.quotepath=false", "diff", "--no-ext-diff", "--no-textconv", "--no-color", "--no-relative", "--no-renames"];
36
+ const CANDIDATE = "-G^[<>][<>]";
37
+
38
+ /** Remove backslash-newline continuations outside single quotes (inside them a backslash is literal). */
39
+ function joinContinuations(command: string): string {
40
+ let out = "", single = false, double = false;
41
+ for (let at = 0; at < command.length; at++) {
42
+ const char = command[at];
43
+ if (char === "\\" && !single) {
44
+ if (command[at + 1] === "\n") { at++; continue; }
45
+ out += command.slice(at, at + 2); at++; continue;
46
+ }
47
+ if (char === "'" && !double) single = !single;
48
+ else if (char === '"' && !single) double = !double;
49
+ out += char;
50
+ }
51
+ return out;
52
+ }
53
+
54
+ function tokenize(command: string): Token[] {
55
+ const tokens: Token[] = [];
56
+ // `[<>]&`, `&>` and `>|` belong to a redirection (`2>&1`, `>&2`, `&>file`), never to a `&` separator.
57
+ for (const match of joinContinuations(command).matchAll(/(?:"(?:\\.|[^"\\])*"|'[^']*'|\\.|[<>]&|&>|>\||[^\s;&|()'"\\])+|&&|\|\||[;&|()\n]/g)) {
58
+ const raw = match[0];
59
+ const operator = /^(?:&&|\|\||[;&|()\n])$/.test(raw);
60
+ // Decided on the raw text: a quoted or escaped `<`/`>` is part of a word, never a redirection.
61
+ const redirect = operator || !/^\d*(?:&>|[<>])/.test(raw) ? undefined : /^\d*(?:&>>?|[<>]{1,2}&?|>\|)$/.test(raw) ? "target" : "complete";
62
+ tokens.push({ operator, redirect, value: operator ? raw : raw.replace(/"((?:\\.|[^"\\])*)"|'([^']*)'|\\(.)/g,
63
+ (_raw, double: string | undefined, single: string | undefined, escaped: string | undefined) => double?.replace(/\\(["\\$`])/g, "$1") ?? single ?? escaped ?? "") });
64
+ }
65
+ return tokens;
66
+ }
67
+
68
+ const literal = (value: string | undefined) => value !== undefined && value !== "" && !/[\n\r$`~*?[\]]/.test(value) && !value.startsWith("-");
69
+
70
+ /** Commit-like segments with their literal directory and the staging that precedes them; anything unclear is skipped. */
71
+ export function conflictMarkerChecks(command: string, cwd: string): Check[] {
72
+ // Heredoc bodies (a commit message, a script) are data, not segments.
73
+ const tokens = tokenize(command.replace(/(<<-?\s*(['"]?)([A-Za-z_]\w*)\2[^\n]*)\n[\s\S]*?\n\s*\3(?=\n|\)|$)/g, "$1"));
74
+ // cd persists through `;`, `&&` and `||`, but not across pipes, jobs or subshells.
75
+ const scoped = !tokens.some(token => token.operator && ["|", "&", "(", ")"].includes(token.value));
76
+ const checks: Check[] = [];
77
+ // Staging seen so far, by directory; `undefined` in the list means an add this guard cannot predict.
78
+ const staging = new Map<string, Array<Staging | undefined>>();
79
+ let directory: string | undefined = cwd;
80
+ let start = 0;
81
+ for (let end = 0; end <= tokens.length; end++) {
82
+ if (end < tokens.length && !tokens[end].operator) continue;
83
+ // Redirections are not arguments: `> out`, `2>&1`, `<<EOF`, `< message.txt`.
84
+ const words = tokens.slice(start, end).filter((token, at, all) => !token.redirect && all[at - 1]?.redirect !== "target").map(token => token.value);
85
+ start = end + 1;
86
+ let head = 0;
87
+ while (/^[A-Za-z_]\w*=/.test(words[head] ?? "")) {
88
+ if (/^GIT_/i.test(words[head])) head = words.length; // ambient git redirect: not ours to guess
89
+ head++;
90
+ }
91
+ // `builtin cd` and `command cd` are cd; with an option the shape is not ours to guess.
92
+ if ((words[head] === "builtin" || words[head] === "command") && words[head + 1] !== undefined) {
93
+ if (words[head + 1].startsWith("-")) { directory = undefined; continue; }
94
+ head++;
95
+ }
96
+ const name = (words[head] ?? "").split("/").at(-1);
97
+ const args = words.slice(head + 1);
98
+ if (name === "cd" || name === "pushd" || name === "popd") {
99
+ directory = scoped && name === "cd" && directory && args.length === 1 && literal(args[0]) ? resolve(directory, args[0]) : undefined;
100
+ continue;
101
+ }
102
+ if (name !== "git" || !directory) continue;
103
+ let target: string | undefined = directory, index = 0;
104
+ while (index < args.length && args[index].startsWith("-")) {
105
+ const option = args[index];
106
+ if (option === "-C") { target = target && literal(args[index + 1]) ? resolve(target, args[index + 1]) : undefined; index += 2; }
107
+ else if (option.startsWith("-C")) { target = target && literal(option.slice(2)) ? resolve(target, option.slice(2)) : undefined; index++; }
108
+ else if (option === "-c") index += 2;
109
+ else if (/^--(?:git-dir|work-tree|namespace)(?:=|$)/.test(option)) { target = undefined; index += option.includes("=") ? 1 : 2; }
110
+ else index++;
111
+ }
112
+ const subcommand = args[index], rest = args.slice(index + 1);
113
+ if (!target) continue;
114
+ if (subcommand === "add" || subcommand === "stage") {
115
+ staging.set(target, [...(staging.get(target) ?? []), addStaging(rest)]);
116
+ } else if (subcommand === "commit") {
117
+ const check = commitCheck(rest, target, staging.get(target) ?? []);
118
+ if (check) checks.push(check);
119
+ } else if (SEQUENCERS.has(subcommand ?? "") && rest.includes("--continue")) {
120
+ const staged = staging.get(target) ?? [];
121
+ checks.push({ directory: target, sources: [{ kind: "index" }], staged: staged.filter(item => item !== undefined) });
122
+ }
123
+ }
124
+ return checks;
125
+ }
126
+
127
+ /** What `git add <args>` would stage; `undefined` for a shape that cannot be predicted (patch, pathspec magic, shell globs). */
128
+ function addStaging(args: string[]): Staging | undefined {
129
+ let all = false, update = false, force = false, dryRun = false;
130
+ const pathspecs: string[] = [];
131
+ for (let index = 0; index < args.length; index++) {
132
+ const arg = args[index];
133
+ if (arg === "--") { pathspecs.push(...args.slice(index + 1)); break; }
134
+ if (/^(?:--patch|--interactive|--edit|--intent-to-add|--pathspec-from-file.*|--renormalize|--refresh)$/.test(arg)) return undefined;
135
+ if (arg === "--all" || arg === "--no-ignore-removal") all = true;
136
+ else if (arg === "--update") update = true;
137
+ else if (arg === "--force") force = true;
138
+ else if (arg === "--dry-run") dryRun = true;
139
+ else if (/^-[^-]/.test(arg)) {
140
+ for (const flag of arg.slice(1)) {
141
+ if ("piNe".includes(flag)) return undefined;
142
+ if (flag === "A") all = true;
143
+ else if (flag === "u") update = true;
144
+ else if (flag === "f") force = true;
145
+ else if (flag === "n") dryRun = true;
146
+ }
147
+ } else if (!arg.startsWith("-")) pathspecs.push(arg);
148
+ }
149
+ if (pathspecs.some(path => !literal(path) || path.startsWith(":"))) return undefined;
150
+ if (dryRun || (!pathspecs.length && !all && !update)) return { pathspecs: [], tracked: false, untracked: false, force: false };
151
+ return { pathspecs, tracked: true, untracked: !update, force };
152
+ }
153
+
154
+ function commitCheck(args: string[], directory: string, staged: Array<Staging | undefined>): Check | undefined {
155
+ let all = false, include = false;
156
+ const paths: string[] = [];
157
+ for (let index = 0; index < args.length; index++) {
158
+ const arg = args[index];
159
+ if (arg === "--") { paths.push(...args.slice(index + 1)); break; }
160
+ if (arg === "--dry-run" || arg.startsWith("--pathspec-from-file")) return undefined;
161
+ if (arg === "--all") all = true;
162
+ else if (arg === "--include") include = true;
163
+ else if (COMMIT_VALUE_OPTIONS.has(arg)) index++;
164
+ else if (/^-[^-]/.test(arg)) {
165
+ for (let at = 1; at < arg.length; at++) {
166
+ const flag = arg[at];
167
+ if (flag === "a") all = true;
168
+ else if (flag === "i") include = true;
169
+ else if ("mFCct".includes(flag)) { if (at === arg.length - 1) index++; break; }
170
+ else if ("Su".includes(flag)) break;
171
+ }
172
+ }
173
+ else if (!arg.startsWith("-")) paths.push(arg);
174
+ }
175
+ const known = staged.filter(item => item !== undefined);
176
+ // `commit <paths>` records only those paths' worktree content; staging does not change it unless `--include`.
177
+ if (paths.length && !include) return { directory, sources: [{ kind: "worktree", pathspecs: paths, untracked: false, force: false }], staged: [] };
178
+ const sources: Source[] = [];
179
+ if (paths.length) sources.push({ kind: "worktree", pathspecs: paths, untracked: false, force: false });
180
+ // `-a` records the worktree of every tracked file (files in the index included), which replaces the index.
181
+ if (all) sources.push({ kind: "worktree", pathspecs: [], untracked: false, force: false });
182
+ else sources.push({ kind: "index" });
183
+ return { directory, sources, staged: known };
184
+ }
185
+
186
+ type Added = Map<string, Array<{ line: number; text: string }>>;
187
+ const isCandidate = (text: string) => /^(<|=|>)\1/.test(text);
188
+
189
+ /** Added lines that could be markers from a `-U0` diff of ONE file, whose path the caller already knows. */
190
+ export function addedMarkerLines(diff: string): Array<{ line: number; text: string }> {
191
+ const lines: Array<{ line: number; text: string }> = [];
192
+ // Headers (`+++ b/...`) come before the first hunk; with `-U0` every later `+` line is added content.
193
+ let line = 0, inHunk = false;
194
+ for (const raw of diff.split("\n")) {
195
+ if (raw.startsWith("@@ ")) { line = Number(/\+(\d+)/.exec(raw)?.[1] ?? 0); inHunk = true; }
196
+ else if (inHunk && raw.startsWith("+")) {
197
+ const text = raw.slice(1).replace(/\r$/, "");
198
+ if (isCandidate(text)) lines.push({ line, text });
199
+ line++;
200
+ }
201
+ }
202
+ return lines;
203
+ }
204
+
205
+ /** `path:line` of each opening marker in files that add an opening and a closing marker of their size. */
206
+ export function conflictMarkerFindings(added: Added, sizes: Map<string, number> = new Map()): string[] {
207
+ const findings: string[] = [];
208
+ for (const [path, lines] of added) {
209
+ const size = sizes.get(path) ?? 7;
210
+ const opening = lines.filter(({ text }) => text.startsWith(`${"<".repeat(size)} `));
211
+ if (opening.length && lines.some(({ text }) => text.startsWith(`${">".repeat(size)} `)))
212
+ findings.push(...opening.map(({ line }) => `${path}:${line}`));
213
+ }
214
+ return findings;
215
+ }
216
+
217
+ class Budget {
218
+ readonly deadline = Date.now() + BUDGET_MS;
219
+ readonly signal: AbortSignal | undefined;
220
+ constructor(signal?: AbortSignal) { this.signal = signal; }
221
+ git(directory: string, args: string[]): Promise<string | undefined> {
222
+ const timeout = this.deadline - Date.now();
223
+ if (timeout <= 0 || this.signal?.aborted) return Promise.resolve(undefined);
224
+ return new Promise(done => execFile("git", args, { cwd: directory, encoding: "utf8", timeout, maxBuffer: MAX_BUFFER,
225
+ windowsHide: true, env: worktreeGitEnvironment(), ...(this.signal ? { signal: this.signal } : {}) },
226
+ (error, stdout) => done(error ? undefined : stdout)));
227
+ }
228
+ }
229
+
230
+ const nulList = (out: string) => out.split("\0").filter(Boolean);
231
+
232
+ // Git's own `conflict-marker-size` attribute is the escape for files that keep markers on purpose.
233
+ async function markerSizes(budget: Budget, top: string, paths: string[]): Promise<Map<string, number> | undefined> {
234
+ const out = await budget.git(top, ["check-attr", "-z", "conflict-marker-size", "--", ...paths]);
235
+ if (out === undefined) return undefined;
236
+ const fields = out.split("\0"), sizes = new Map<string, number>();
237
+ for (let at = 0; at + 2 < fields.length; at += 3) {
238
+ const size = Number(fields[at + 2]);
239
+ if (Number.isInteger(size) && size > 0) sizes.set(fields[at], size);
240
+ }
241
+ return sizes;
242
+ }
243
+
244
+ async function untrackedLines(top: string, path: string): Promise<Array<{ line: number; text: string }>> {
245
+ const file = join(top, path);
246
+ const stats = await lstat(file);
247
+ if (!stats.isFile() || stats.size > MAX_UNTRACKED_BYTES) return [];
248
+ const handle = await open(file, "r");
249
+ try {
250
+ const content = await handle.readFile();
251
+ if (content.subarray(0, 8000).includes(0)) return [];
252
+ return content.toString("utf8").split("\n").map((text, at) => ({ line: at + 1, text: text.replace(/\r$/, "") })).filter(({ text }) => isCandidate(text));
253
+ } finally { await handle.close(); }
254
+ }
255
+
256
+ /** Marker candidates the source adds against `base`, by root-relative path; `undefined` when git cannot say. */
257
+ async function addedBy(budget: Budget, check: Check, top: string, source: Source, base: string, exists: (path: string) => Promise<boolean>): Promise<Added | undefined> {
258
+ const added: Added = new Map();
259
+ const cached = source.kind === "index" ? ["--cached"] : [];
260
+ const pathspecs = source.kind === "worktree" ? source.pathspecs : [];
261
+ // NUL-separated names cannot be confused by spaces, quotes, tabs or non-ASCII; each file is then diffed by its exact path.
262
+ const names = await budget.git(check.directory, [...DIFF, "--name-only", "-z", CANDIDATE, ...cached, base, "--", ...pathspecs]);
263
+ if (names === undefined) return undefined;
264
+ for (const path of nulList(names).slice(0, MAX_FILES)) {
265
+ const diff = await budget.git(top, ["--literal-pathspecs", ...DIFF, "-U0", ...cached, base, "--", path]);
266
+ if (diff === undefined) return undefined;
267
+ const lines = addedMarkerLines(diff);
268
+ if (lines.length) added.set(path, lines);
269
+ }
270
+ if (source.kind === "worktree" && source.untracked) {
271
+ const others = await budget.git(check.directory, ["ls-files", "-z", "--full-name", "--others", ...(source.force ? [] : ["--exclude-standard"]), "--", ...pathspecs]);
272
+ if (others === undefined) return undefined;
273
+ for (const path of nulList(others).slice(0, MAX_FILES)) {
274
+ if (await exists(path)) continue;
275
+ const lines = await untrackedLines(top, path).catch(() => []);
276
+ if (lines.length) added.set(path, lines);
277
+ }
278
+ }
279
+ return added;
280
+ }
281
+
282
+ /** Root-relative paths a staging covers: its tracked matches and, when it adds untracked files, those too. */
283
+ async function covered(budget: Budget, check: Check, staging: Staging): Promise<Set<string> | "all" | undefined> {
284
+ if (!staging.pathspecs.length) return staging.tracked ? "all" : new Set();
285
+ const tracked = await budget.git(check.directory, ["ls-files", "-z", "--full-name", "--", ...staging.pathspecs]);
286
+ return tracked === undefined ? undefined : new Set(nulList(tracked));
287
+ }
288
+
289
+ async function verified(budget: Budget, top: string, ref: string): Promise<string | undefined> {
290
+ return (await budget.git(top, ["rev-parse", "-q", "--verify", `${ref}^{commit}`]))?.trim() || undefined;
291
+ }
292
+
293
+ async function findingsFor(budget: Budget, check: Check): Promise<string[] | undefined> {
294
+ const top = (await budget.git(check.directory, ["rev-parse", "--show-toplevel"]))?.trim();
295
+ if (!top) return undefined;
296
+ const head = await verified(budget, top, "HEAD") ?? EMPTY_TREE;
297
+ let second: string | undefined;
298
+ for (const ref of SECOND_SIDES) if ((second = await verified(budget, top, ref))) break;
299
+ const sources: Source[] = [...check.sources];
300
+ let excluded: Set<string> | "all" = new Set();
301
+ for (const staging of check.staged) {
302
+ if (!staging.tracked) continue;
303
+ sources.push({ kind: "worktree", pathspecs: staging.pathspecs, untracked: staging.untracked, force: staging.force });
304
+ const cover = await covered(budget, check, staging);
305
+ if (cover === undefined) return undefined;
306
+ if (cover === "all" || excluded === "all") excluded = "all";
307
+ else for (const path of cover) excluded.add(path);
308
+ }
309
+ const findings = new Set<string>();
310
+ for (const source of sources) {
311
+ // A staged path that `add` replaces is recorded from the worktree, not from the current index.
312
+ const replaced = source.kind === "index" ? excluded : new Set<string>();
313
+ if (replaced === "all") continue;
314
+ const exists = async (path: string) => second !== undefined && (await budget.git(top, ["cat-file", "-e", `${second}:${path}`])) !== undefined;
315
+ const added = await addedBy(budget, check, top, source, head, async () => false); // untracked: absent from HEAD
316
+ if (!added) return undefined;
317
+ for (const path of replaced) added.delete(path);
318
+ if (!added.size) continue;
319
+ const sizes = await markerSizes(budget, top, [...added.keys()]);
320
+ if (!sizes) return undefined;
321
+ let found = conflictMarkerFindings(added, sizes);
322
+ if (found.length && second !== undefined) {
323
+ // During a merge or pick, content that came whole from the other side is not this commit's addition.
324
+ const other = await addedBy(budget, check, top, source, second, exists);
325
+ if (!other) return undefined;
326
+ const keys = new Set([...other].flatMap(([path, lines]) => lines.map(({ line }) => `${path}:${line}`)));
327
+ found = found.filter(finding => keys.has(finding));
328
+ }
329
+ for (const finding of found) findings.add(finding);
330
+ }
331
+ return [...findings];
332
+ }
333
+
334
+ const printable = (finding: string) => finding.replace(/[\u0000-\u001f\u007f]/g, char => `\\x${char.charCodeAt(0).toString(16).padStart(2, "0")}`);
335
+
336
+ /** Refuse a commit that adds conflict markers; undefined means "let it run" (including every guard error). */
337
+ export async function checkDeliveryConflictMarkers(cwd: string, command: string, signal?: AbortSignal): Promise<Denial | undefined> {
338
+ try {
339
+ const budget = new Budget(signal);
340
+ for (const check of conflictMarkerChecks(command, cwd)) {
341
+ const findings = await findingsFor(budget, check);
342
+ if (findings === undefined) return undefined;
343
+ if (!findings.length) continue;
344
+ const shown = findings.slice(0, SHOWN).map(printable).join(", ") + (findings.length > SHOWN ? `, and ${findings.length - SHOWN} more` : "");
345
+ return { block: true, reason: `Conflict markers: this commit would add unresolved conflict markers (<<<<<<< ... >>>>>>>) at ${shown}. This command was not run. Resolve the markers and stage the result, then retry. A file that holds markers on purpose is exempted by a \`conflict-marker-size\` attribute in \`.gitattributes\`.` };
346
+ }
347
+ } catch { /* fail open */ }
348
+ return undefined;
349
+ }