gentle-pi 4.0.0 → 4.1.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 (398) hide show
  1. package/README.md +122 -8
  2. package/assets/agents/gentle-ai-explore.md +11 -4
  3. package/assets/agents/gentle-ai-verify.md +23 -4
  4. package/assets/agents/gentle-ai-worker.md +6 -6
  5. package/assets/install-wizard/index.html +47 -0
  6. package/assets/install-wizard/wizard.css +1279 -0
  7. package/assets/install-wizard/wizard.js +951 -0
  8. package/assets/orchestrator-delegation.md +70 -163
  9. package/assets/orchestrator-memory.md +11 -4
  10. package/assets/orchestrator-prompts.md +48 -0
  11. package/assets/orchestrator-tracking.md +53 -0
  12. package/assets/orchestrator-verification.md +28 -0
  13. package/assets/orchestrator-writer.md +38 -0
  14. package/assets/orchestrator.md +29 -25
  15. package/assets/sounds/LICENSE.md +52 -0
  16. package/assets/sounds/attention.wav +0 -0
  17. package/assets/sounds/error.wav +0 -0
  18. package/assets/sounds/success.wav +0 -0
  19. package/bin/engram-guard +9 -0
  20. package/bin/gentle-shell-install.mjs +302 -0
  21. package/bin/gentle-shell.mjs +703 -22
  22. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +7 -7
  23. package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/manifest.json +2 -2
  24. package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/orchestration/pi.md +16 -4
  25. package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/generated/provider-capabilities.baseline.json +2 -2
  26. package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/generated/provider-roles.baseline.json +1 -1
  27. package/docs/bundled-install.md +397 -0
  28. package/docs/delegated-verification.md +3 -5
  29. package/docs/gentle-agents-activity.md +513 -0
  30. package/docs/gentle-shell-uninstall.md +136 -0
  31. package/docs/gentle-shell.md +81 -31
  32. package/docs/install-wizard.md +2040 -0
  33. package/docs/native-authority-architecture.md +1 -1
  34. package/docs/permission-modes.md +82 -0
  35. package/docs/prompt-history.md +1 -1
  36. package/docs/readme-reference.md +267 -40
  37. package/docs/render-cache-performance.md +28 -0
  38. package/docs/sound-notifications-proposal.md +191 -0
  39. package/docs/sound-notifications.md +114 -0
  40. package/docs/yolo-mode.md +9 -9
  41. package/extensions/child-context.ts +11 -2
  42. package/extensions/child-safety.ts +4 -2
  43. package/extensions/codegraph-tools.ts +18 -5
  44. package/extensions/gentle-agents.ts +688 -88
  45. package/extensions/gentle-ai.ts +886 -238
  46. package/extensions/gentle-herdr-activity.ts +81 -0
  47. package/extensions/gentle-notifications.ts +104 -0
  48. package/extensions/gentle-shell.ts +265 -69
  49. package/extensions/gentle-todo.ts +108 -13
  50. package/extensions/history/index.ts +11 -6
  51. package/extensions/pi-pretty.ts +39 -3
  52. package/extensions/quiet-tools.ts +91 -21
  53. package/extensions/skill-registry.ts +175 -46
  54. package/extensions/startup-banner.ts +11 -2
  55. package/lib/agent-home.ts +10 -1
  56. package/lib/agent-model-resolution.ts +80 -0
  57. package/lib/agent-profiles.ts +13 -3
  58. package/lib/agents-completion-delivery.ts +11 -3
  59. package/lib/agents-messaging.ts +1 -1
  60. package/lib/agents-protocol.ts +40 -1
  61. package/lib/agents-runner.ts +90 -15
  62. package/lib/auto-permission-classifier.ts +280 -0
  63. package/lib/auto-permission-runtime.ts +268 -0
  64. package/lib/background-jobs-tools.ts +202 -0
  65. package/lib/background-jobs.ts +253 -0
  66. package/lib/background-monitor.ts +154 -0
  67. package/lib/bounded-writer-admission.ts +83 -10
  68. package/lib/builtin-codemode-optout.ts +166 -0
  69. package/lib/card-content-policy.ts +85 -0
  70. package/lib/child-package-injection.ts +62 -0
  71. package/lib/codemode-renderer.ts +14 -4
  72. package/lib/command-palette-catalog.ts +3 -2
  73. package/lib/context-threshold.ts +26 -0
  74. package/lib/gentle-ai-binary.ts +109 -4
  75. package/lib/gentle-shell-bundled.ts +517 -0
  76. package/lib/gentle-shell-launcher.ts +74 -23
  77. package/lib/gentle-shell-startup-flow.ts +54 -0
  78. package/lib/gentle-shell-startup-update.ts +92 -0
  79. package/lib/gentle-shell-uninstall.ts +840 -0
  80. package/lib/gentle-shell-update-panel.ts +231 -0
  81. package/lib/herdr-activity.ts +183 -0
  82. package/lib/inprocess-reviewer.ts +3 -0
  83. package/lib/jobs-sidebar-state.ts +20 -0
  84. package/lib/jobs-view.ts +161 -0
  85. package/lib/model-price-ratio.ts +83 -0
  86. package/lib/nan-provider.ts +33 -11
  87. package/lib/native-review-cli.ts +194 -73
  88. package/lib/notification-audio-native.ts +162 -0
  89. package/lib/notification-audio-windows.ts +399 -0
  90. package/lib/notification-audio.ts +332 -0
  91. package/lib/notification-customize.ts +241 -0
  92. package/lib/notification-events.ts +113 -0
  93. package/lib/notification-policy.ts +148 -0
  94. package/lib/notification-pulse-client.ts +367 -0
  95. package/lib/notification-pulse-protocol.ts +305 -0
  96. package/lib/notification-pulse-stream.ts +213 -0
  97. package/lib/notification-pulse-worker.ts +66 -0
  98. package/lib/notification-scheduler.ts +173 -0
  99. package/lib/notification-service.ts +202 -0
  100. package/lib/notification-ui.ts +87 -0
  101. package/lib/odd-phase.ts +1 -1
  102. package/lib/orchestrator-alias.ts +20 -0
  103. package/lib/orchestrator-catalog.ts +79 -0
  104. package/lib/orchestrator-consultation.ts +61 -0
  105. package/lib/orchestrator-discovery.ts +49 -0
  106. package/lib/orchestrator-helper-consent.ts +122 -0
  107. package/lib/orchestrator-helper.ts +167 -0
  108. package/lib/orchestrator-message-card.ts +105 -0
  109. package/lib/orchestrator-presence.ts +115 -14
  110. package/lib/orchestrator-scope.ts +80 -0
  111. package/lib/orchestrator-state.ts +107 -0
  112. package/lib/orchestrator-tool-card.ts +280 -0
  113. package/lib/orchestrator-work-search.ts +218 -0
  114. package/lib/orchestrator-work.ts +79 -0
  115. package/lib/permission-mode-policy.ts +59 -0
  116. package/lib/review-candidate-view-owner.ts +8 -6
  117. package/lib/review-candidate-view.ts +3 -2
  118. package/lib/review-compact-contract.ts +2 -2
  119. package/lib/review-host-relay.ts +7 -2
  120. package/lib/review-integration-v2.ts +100 -22
  121. package/lib/review-publication-gate.ts +1 -1
  122. package/lib/review-risk-assessment.ts +77 -51
  123. package/lib/review-sidebar-state.ts +2 -1
  124. package/lib/review-transaction.ts +72 -3
  125. package/lib/runtime-metrics-children.ts +1 -1
  126. package/lib/runtime-metrics-native.ts +3 -2
  127. package/lib/selection-engine.ts +18 -6
  128. package/lib/session-change-capture.ts +5 -4
  129. package/lib/session-changes.ts +27 -22
  130. package/lib/session-profile-binding.ts +83 -0
  131. package/lib/session-profile-freeze.ts +266 -0
  132. package/lib/session-worktree-registry.ts +74 -8
  133. package/lib/shell-bar.ts +41 -11
  134. package/lib/shell-changes-view.ts +40 -13
  135. package/lib/shell-changes.ts +86 -71
  136. package/lib/shell-sidebar-layout.ts +5 -1
  137. package/lib/shell-todo.ts +62 -19
  138. package/lib/shell-usage.ts +4 -3
  139. package/lib/status-timing-diagnostics.ts +201 -0
  140. package/lib/telemetry-trigger.ts +3 -1
  141. package/lib/vim-editor-adapter.ts +7 -3
  142. package/lib/visual-customization-policy.ts +20 -9
  143. package/lib/visual-customize-view.ts +171 -20
  144. package/lib/writer-surfaces.ts +162 -0
  145. package/lib/yolo-session-policy.ts +198 -121
  146. package/package.json +1 -1
  147. package/runtime/child-package-injection.mjs +63 -0
  148. package/runtime/gentle-ai-binary.mjs +109 -4
  149. package/runtime/gentle-shell-bundled.mjs +518 -0
  150. package/runtime/gentle-shell-launcher.mjs +73 -22
  151. package/runtime/gentle-shell-startup-flow.mjs +55 -0
  152. package/runtime/gentle-shell-startup-update.mjs +93 -0
  153. package/runtime/gentle-shell-uninstall.mjs +841 -0
  154. package/runtime/gentle-shell-update-panel.mjs +232 -0
  155. package/runtime/native-review-cli.mjs +191 -70
  156. package/runtime/review-integration-v2.mjs +100 -22
  157. package/runtime/review-risk-assessment.mjs +77 -51
  158. package/runtime/status-timing-diagnostics.mjs +202 -0
  159. package/runtime/telemetry-trigger.mjs +3 -1
  160. package/scripts/bootstrap.cmd +255 -0
  161. package/scripts/bootstrap.sh +168 -0
  162. package/scripts/build-distribution.mjs +157 -0
  163. package/scripts/build-installer-bundles.mjs +136 -0
  164. package/scripts/build-runtime-modules.mjs +7 -0
  165. package/scripts/bundled-install.mjs +1308 -0
  166. package/scripts/bundled-wizard.mjs +399 -0
  167. package/scripts/check-types.mjs +4 -6
  168. package/scripts/gentle-ai-installer.mjs +79 -32
  169. package/scripts/install-gentle-ai.mjs +48 -1
  170. package/scripts/install-tui-mode-setting.mjs +10 -1
  171. package/scripts/install-wizard-preview.mjs +154 -0
  172. package/scripts/installer-downloads.mjs +648 -0
  173. package/scripts/installer-preflight.mjs +387 -0
  174. package/scripts/installer-probes.mjs +564 -0
  175. package/scripts/installer-runner.mjs +1102 -0
  176. package/scripts/installer-server.mjs +881 -0
  177. package/scripts/installer-windows-artifacts.json +15 -0
  178. package/scripts/installer-windows.mjs +752 -0
  179. package/scripts/main-channel.mjs +452 -0
  180. package/scripts/npm-pack-result.mjs +31 -0
  181. package/scripts/render-cache-performance-worker.mjs +205 -0
  182. package/scripts/render-cache-performance.mjs +115 -0
  183. package/scripts/run-test-suite.mjs +22 -8
  184. package/scripts/test-installer-acceptance.sh +161 -0
  185. package/scripts/test-packed-runner.mjs +23 -5
  186. package/scripts/types-baseline.json +2 -92
  187. package/scripts/verify-package-files.mjs +82 -18
  188. package/skills/gentle-ai/SKILL.md +12 -11
  189. package/tests/agent-home.test.ts +56 -3
  190. package/tests/agent-model-resolution.test.ts +113 -0
  191. package/tests/agent-profiles.test.ts +12 -0
  192. package/tests/agent-risk-escalation.test.ts +123 -0
  193. package/tests/agents-completion-delivery.test.ts +17 -0
  194. package/tests/agents-protocol.test.ts +57 -0
  195. package/tests/agents-queries.test.ts +9 -9
  196. package/tests/agents-runner-process.test.ts +31 -0
  197. package/tests/agents-runner.test.ts +89 -4
  198. package/tests/auto-mode-invariants.test.ts +258 -0
  199. package/tests/auto-mode-sdk.test.ts +57 -0
  200. package/tests/auto-mode.test.ts +49 -0
  201. package/tests/auto-permission-classifier.test.ts +283 -0
  202. package/tests/auto-permission-runtime.test.ts +196 -0
  203. package/tests/background-cache-warming.test.ts +2 -1
  204. package/tests/background-jobs.test.ts +227 -0
  205. package/tests/background-monitor.test.ts +195 -0
  206. package/tests/background-subagents-default-mode.test.ts +28 -5
  207. package/tests/bounded-stop-contract.test.ts +85 -0
  208. package/tests/bounded-writer-admission.test.ts +52 -1
  209. package/tests/bridge-wake-lifecycle.test.ts +129 -0
  210. package/tests/bridge-wake-rendering.test.ts +56 -0
  211. package/tests/build-distribution.test.ts +269 -0
  212. package/tests/builtin-codemode-optout.test.ts +242 -0
  213. package/tests/bundled-install.test.ts +1319 -0
  214. package/tests/bundled-wizard.test.ts +505 -0
  215. package/tests/card-content-policy.test.ts +68 -0
  216. package/tests/card-style-policy.test.ts +34 -2
  217. package/tests/child-codegraph-bootstrap.test.ts +74 -0
  218. package/tests/child-package-entrypoints.test.ts +65 -0
  219. package/tests/child-package-injection.test.ts +74 -0
  220. package/tests/child-safety.test.ts +12 -0
  221. package/tests/child-web-package.test.ts +224 -0
  222. package/tests/codegraph-tools.test.ts +35 -0
  223. package/tests/codemode-rendering.test.ts +107 -2
  224. package/tests/command-palette.test.ts +5 -5
  225. package/tests/context-threshold.test.ts +31 -0
  226. package/tests/delegate-for-reason-contract.test.ts +327 -0
  227. package/tests/delegated-key-learnings-contract.test.ts +3 -2
  228. package/tests/devbinary/native-review-parity.devtest.ts +1 -1
  229. package/tests/devbinary/pi-host-relay.devtest.ts +173 -3
  230. package/tests/engram-safety.test.ts +288 -0
  231. package/tests/generic-agent-tools.test.ts +16 -1
  232. package/tests/gentle-agents.test.ts +1722 -59
  233. package/tests/gentle-ai-binary-isolation.test.ts +135 -0
  234. package/tests/gentle-ai-binary.test.ts +19 -2
  235. package/tests/gentle-ai-child-guards.test.ts +202 -0
  236. package/tests/gentle-ai-dev-binary-surfacing.test.ts +125 -15
  237. package/tests/gentle-ai-installer.test.ts +548 -58
  238. package/tests/gentle-ai-prompt-model-routing.test.ts +123 -0
  239. package/tests/gentle-ai-renderer.test.ts +6 -6
  240. package/tests/gentle-ai.test.ts +999 -31
  241. package/tests/gentle-herdr-activity.test.ts +100 -0
  242. package/tests/gentle-notifications.test.ts +427 -0
  243. package/tests/gentle-shell-bin.test.ts +249 -5
  244. package/tests/gentle-shell-bundled.test.ts +1002 -0
  245. package/tests/gentle-shell-launcher.test.ts +234 -13
  246. package/tests/gentle-shell-startup-flow.test.ts +75 -0
  247. package/tests/gentle-shell-startup-update.test.ts +85 -0
  248. package/tests/gentle-shell-uninstall.test.ts +978 -0
  249. package/tests/gentle-shell-update-panel.test.ts +158 -0
  250. package/tests/gentle-shell.test.ts +541 -96
  251. package/tests/gentle-todo.test.ts +253 -2
  252. package/tests/herdr-activity.test.ts +243 -0
  253. package/tests/history-agent-home.test.ts +81 -0
  254. package/tests/history-child-guard.test.ts +70 -0
  255. package/tests/inprocess-reviewer.test.ts +20 -0
  256. package/tests/install-gentle-ai-failure.test.ts +69 -0
  257. package/tests/install-tui-mode-setting.test.ts +15 -0
  258. package/tests/install-wizard.test.ts +1223 -0
  259. package/tests/installer-bundles.test.ts +122 -0
  260. package/tests/installer-posix-bootstrap.test.ts +1201 -0
  261. package/tests/installer-preflight.test.ts +750 -0
  262. package/tests/installer-probes.test.ts +1106 -0
  263. package/tests/installer-runner.test.ts +2158 -0
  264. package/tests/installer-server.test.ts +1567 -0
  265. package/tests/installer-windows-bootstrap.test.ts +2410 -0
  266. package/tests/jobs-view.test.ts +160 -0
  267. package/tests/main-channel-upgrade.test.ts +389 -0
  268. package/tests/main-channel.test.ts +344 -0
  269. package/tests/maintainer/provider-relay.maintest.ts +13 -12
  270. package/tests/model-price-ratio.test.ts +116 -0
  271. package/tests/model-profiles-preservation.test.ts +153 -0
  272. package/tests/model-routing-package.test.ts +10 -0
  273. package/tests/nan-provider-runtime.test.ts +156 -0
  274. package/tests/nan-provider.test.ts +28 -18
  275. package/tests/native-binary-gate.test.ts +2 -0
  276. package/tests/native-review-capability-contract.test.ts +7 -1
  277. package/tests/native-review-cli.test.ts +236 -1
  278. package/tests/native-review-consent.test.ts +2 -2
  279. package/tests/native-review-parity-runtime.test.ts +1 -1
  280. package/tests/native-review-parity.test.ts +12 -48
  281. package/tests/native-risk-evidence-parity.test.ts +21 -0
  282. package/tests/no-self-pause-contract.test.ts +87 -0
  283. package/tests/notification-audio-native.test.ts +281 -0
  284. package/tests/notification-audio-windows.test.ts +581 -0
  285. package/tests/notification-audio.test.ts +548 -0
  286. package/tests/notification-customize.test.ts +655 -0
  287. package/tests/notification-events.test.ts +115 -0
  288. package/tests/notification-policy.test.ts +201 -0
  289. package/tests/notification-pulse-client.test.ts +356 -0
  290. package/tests/notification-pulse-protocol.test.ts +213 -0
  291. package/tests/notification-pulse-stream.test.ts +320 -0
  292. package/tests/notification-scheduler.test.ts +258 -0
  293. package/tests/notification-ui.test.ts +157 -0
  294. package/tests/npm-pack-result.test.ts +41 -0
  295. package/tests/odd-integration.test.ts +14 -5
  296. package/tests/odd-routing-canonical-ratchet.test.ts +53 -12
  297. package/tests/odd-routing-contract.test.ts +80 -23
  298. package/tests/orchestrator-budget.test.ts +29 -6
  299. package/tests/orchestrator-catalog.test.ts +146 -0
  300. package/tests/orchestrator-consultation-sdk.test.ts +614 -0
  301. package/tests/orchestrator-consultation.test.ts +111 -0
  302. package/tests/orchestrator-discovery.test.ts +241 -0
  303. package/tests/orchestrator-helper-consent.test.ts +171 -0
  304. package/tests/orchestrator-helper.test.ts +297 -0
  305. package/tests/orchestrator-message-card.test.ts +190 -0
  306. package/tests/orchestrator-presence.test.ts +23 -0
  307. package/tests/orchestrator-rdd-ownership.test.ts +6 -5
  308. package/tests/orchestrator-scope.test.ts +107 -0
  309. package/tests/orchestrator-state.test.ts +114 -0
  310. package/tests/orchestrator-status-publication-contract.test.ts +34 -0
  311. package/tests/orchestrator-tool-card.test.ts +398 -0
  312. package/tests/orchestrator-work-search.test.ts +318 -0
  313. package/tests/orchestrator-work.test.ts +147 -0
  314. package/tests/package-manifest.test.ts +101 -17
  315. package/tests/packed-runner-owned-path.test.ts +35 -1
  316. package/tests/parallel-reason-contract.test.ts +21 -0
  317. package/tests/parallel-writer-admission.test.ts +210 -0
  318. package/tests/permission-mode-policy.test.ts +194 -0
  319. package/tests/persona-single-channel.test.ts +4 -12
  320. package/tests/pi-pretty.test.ts +56 -0
  321. package/tests/provider-defect-handoff.test.ts +4 -3
  322. package/tests/quiet-tool-rendering.test.ts +160 -3
  323. package/tests/rdd-aware-verification-contract.test.ts +29 -41
  324. package/tests/render-cache-performance.test.ts +48 -0
  325. package/tests/review-agent-end-preflight.test.ts +62 -10
  326. package/tests/review-candidate-view.test.ts +101 -12
  327. package/tests/review-contract-prompt.test.ts +33 -4
  328. package/tests/review-controller-native-recovery.test.ts +327 -17
  329. package/tests/review-controller-native-routing.test.ts +255 -1
  330. package/tests/review-controller-workspace-root.test.ts +43 -2
  331. package/tests/review-controller.test.ts +2 -2
  332. package/tests/review-correction-lifecycle.test.ts +2 -1
  333. package/tests/review-gate.test.ts +7 -4
  334. package/tests/review-graph-schema.test.ts +2 -2
  335. package/tests/review-host-relay-routing.test.ts +5 -3
  336. package/tests/review-host-relay.test.ts +49 -2
  337. package/tests/review-integration-v2-forward.test.ts +21 -1
  338. package/tests/review-json-arguments.test.ts +167 -0
  339. package/tests/review-last-event-closure.test.ts +157 -8
  340. package/tests/review-ledger-contract.test.ts +5 -4
  341. package/tests/review-policy-judgment-day.test.ts +1 -1
  342. package/tests/review-policy-ordinary.test.ts +2 -2
  343. package/tests/review-relay-transport-agent.test.ts +66 -1
  344. package/tests/review-risk-assessment.test.ts +109 -33
  345. package/tests/review-session-standing-permission-controller.test.ts +16 -17
  346. package/tests/review-session-standing-permission-ipc.test.ts +6 -5
  347. package/tests/review-test-fixtures.ts +7 -1
  348. package/tests/review-transaction.test.ts +18 -1
  349. package/tests/run-test-suite.test.ts +83 -5
  350. package/tests/runtime-harness.mjs +42 -15
  351. package/tests/runtime-metrics-extension.test.ts +1 -1
  352. package/tests/runtime-metrics-native.test.ts +31 -1
  353. package/tests/selection-engine.test.ts +30 -0
  354. package/tests/session-change-capture.test.ts +10 -10
  355. package/tests/session-changes-shell.test.ts +242 -48
  356. package/tests/session-changes.test.ts +17 -24
  357. package/tests/session-profile-binding.test.ts +163 -0
  358. package/tests/session-profile-freeze.test.ts +381 -0
  359. package/tests/session-subject-routing-contract.test.ts +34 -0
  360. package/tests/session-worktree-registry.test.ts +57 -2
  361. package/tests/shell-bar.test.ts +40 -0
  362. package/tests/shell-changes-view.test.ts +85 -34
  363. package/tests/shell-changes.test.ts +61 -62
  364. package/tests/shell-render-cache-runtime.test.ts +69 -0
  365. package/tests/shell-render-cache.test.ts +129 -0
  366. package/tests/shell-sidebar-layout.test.ts +27 -2
  367. package/tests/shell-todo.test.ts +120 -2
  368. package/tests/shell-usage-view.test.ts +1 -1
  369. package/tests/shell-usage.test.ts +35 -0
  370. package/tests/short-check-routing-contract.test.ts +49 -0
  371. package/tests/skill-registry-watcher.test.ts +119 -0
  372. package/tests/skill-registry.test.ts +311 -5
  373. package/tests/startup-banner.test.ts +117 -3
  374. package/tests/startup-home-repo.test.ts +170 -0
  375. package/tests/status-timing-diagnostics.test.ts +283 -0
  376. package/tests/support/orchestrator-modules.ts +19 -0
  377. package/tests/task-size-routing-contract.test.ts +241 -0
  378. package/tests/telemetry-trigger.test.ts +27 -1
  379. package/tests/test-strength-contract.test.ts +124 -0
  380. package/tests/verify-agent-contract.test.ts +90 -0
  381. package/tests/verify-first-launch-contract.test.ts +139 -0
  382. package/tests/verify-package-files.test.ts +56 -0
  383. package/tests/vim-editor-adapter.test.ts +7 -7
  384. package/tests/visual-customization-policy.test.ts +32 -3
  385. package/tests/visual-customize-view.test.ts +288 -10
  386. package/tests/writer-edit-surface-scope.test.ts +59 -2
  387. package/tests/writer-surfaces.test.ts +199 -0
  388. package/tests/yolo-customize.test.ts +18 -3
  389. package/tests/yolo-mode-runtime.test.ts +37 -10
  390. package/tests/yolo-mode.test.ts +32 -4
  391. package/tests/yolo-session-policy.test.ts +1 -1
  392. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/README.md +0 -0
  393. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/schemas/lens.schema.json +0 -0
  394. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/schemas/refuter.schema.json +0 -0
  395. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  396. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/vectors/lens.json +0 -0
  397. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/vectors/refuter.json +0 -0
  398. /package/contracts/review-provider-contract-mirror/{v1.2.0 → v1.3.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -1,11 +1,16 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { execSync } from "node:child_process";
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
  import test from "node:test";
7
7
  import { pathToFileURL } from "node:url";
8
- import { __testing } from "../extensions/skill-registry.ts";
8
+ import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
9
+ import skillRegistry, { __testing } from "../extensions/skill-registry.ts";
10
+
11
+ // Registered startup reads process.env directly; a suite launched from a
12
+ // delegated child must still exercise the parent paths (gentle-shell#1690).
13
+ delete process.env.GENTLE_PI_AGENTS_CHILD;
9
14
 
10
15
  test("project skill dirs include supported workspace roots", () => {
11
16
  const cwd = "/repo";
@@ -177,6 +182,8 @@ test("startup skip honors no skill registry controls", () => {
177
182
  true,
178
183
  );
179
184
  assert.equal(__testing.shouldSkipSkillRegistryStartup(disabled, [], {}), false);
185
+ assert.equal(__testing.shouldSkipSkillRegistryStartup(disabled, [], { GENTLE_PI_AGENTS_CHILD: "1" }), true);
186
+ assert.equal(__testing.shouldSkipSkillRegistryStartup(disabled, [], { GENTLE_PI_AGENTS_CHILD: "0" }), false);
180
187
  });
181
188
 
182
189
  test("duplicate extension load is skipped only across different sources", () => {
@@ -322,10 +329,8 @@ test("ensureAtlIgnored creates .atl/.gitignore with * and leaves root .gitignore
322
329
  const cwd = mkdtempSync(join(tmpdir(), `gentle-pi-git-atl-${Date.now()}-`));
323
330
  t.after(() => rmSync(cwd, { recursive: true, force: true }));
324
331
 
325
- // Initialize real git repo with a commit
332
+ // An empty index is sufficient; fixtures never need commits.
326
333
  execSync("git init", { cwd, stdio: "ignore" });
327
- writeFileSync(join(cwd, "README.md"), "# Test\n");
328
- execSync("git add README.md && git -c user.name='Test' -c user.email='test@example.com' commit -m \"initial\"", { cwd, stdio: "ignore" });
329
334
 
330
335
  const rootGitignore = join(cwd, ".gitignore");
331
336
  const atlGitignore = join(cwd, ".atl", ".gitignore");
@@ -365,3 +370,304 @@ test("ensureAtlIgnored creates .atl/.gitignore with * and leaves root .gitignore
365
370
  .filter((l) => l !== "" && !l.startsWith("#"));
366
371
  assert.equal(updatedRules.at(-1), "*", "final active ignore rule must be *");
367
372
  });
373
+
374
+ // Keep runtime scans inside an isolated home, including the existing watcher tests.
375
+ const fixtureHome = mkdtempSync(join(tmpdir(), "gentle-pi-registry-home-"));
376
+ const originalHome = process.env.HOME;
377
+ const originalUserProfile = process.env.USERPROFILE;
378
+ const originalGitCeiling = process.env.GIT_CEILING_DIRECTORIES;
379
+ process.env.GIT_CEILING_DIRECTORIES = tmpdir();
380
+ process.env.HOME = fixtureHome;
381
+ process.env.USERPROFILE = fixtureHome;
382
+ test.after(() => {
383
+ if (originalHome === undefined) delete process.env.HOME;
384
+ else process.env.HOME = originalHome;
385
+ if (originalUserProfile === undefined) delete process.env.USERPROFILE;
386
+ else process.env.USERPROFILE = originalUserProfile;
387
+ if (originalGitCeiling === undefined) delete process.env.GIT_CEILING_DIRECTORIES;
388
+ else process.env.GIT_CEILING_DIRECTORIES = originalGitCeiling;
389
+ });
390
+
391
+ function registeredRegistry(cwd: string, suppressed = false) {
392
+ type Context = { cwd: string; hasUI: boolean; ui: { notify: (message: string, level?: string) => void } };
393
+ const events = new Map<string, (event: unknown, ctx: Context) => Promise<void>>();
394
+ const commands = new Map<string, { handler: (args: string, ctx: Context) => Promise<void> }>();
395
+ const notices: { message: string; level?: string }[] = [];
396
+ skillRegistry({
397
+ on: (name: string, handler: (event: unknown, ctx: Context) => Promise<void>) => events.set(name, handler),
398
+ registerCommand: (name: string, command: { handler: (args: string, ctx: Context) => Promise<void> }) => commands.set(name, command),
399
+ registerFlag: () => undefined,
400
+ getFlag: () => suppressed,
401
+ } as unknown as ExtensionAPI);
402
+ const ctx = { cwd, hasUI: true, ui: { notify: (message: string, level?: string) => notices.push({ message, level }) } };
403
+ return {
404
+ notices,
405
+ // Startup work runs after session_start returns; settle it for assertions.
406
+ start: async () => { await events.get("session_start")!(undefined, ctx); await __testing.startupSettled(); },
407
+ startOnly: () => events.get("session_start")!(undefined, ctx),
408
+ refresh: () => commands.get("skill-registry:refresh")!.handler("", ctx),
409
+ stop: () => events.get("session_shutdown")!(undefined, ctx),
410
+ };
411
+ }
412
+
413
+ function registryFixture(git = true, nested = false) {
414
+ const root = mkdtempSync(join(tmpdir(), "gentle-pi-protected-"));
415
+ if (git) execSync("git init", { cwd: root, stdio: "ignore" });
416
+ const cwd = nested ? join(root, "nested") : root;
417
+ mkdirSync(join(cwd, ".atl"), { recursive: true });
418
+ const skill = join(cwd, "skills", "local", "SKILL.md");
419
+ mkdirSync(dirname(skill), { recursive: true });
420
+ writeFileSync(skill, "---\nname: local\ndescription: Initial skill.\n---\n");
421
+ return { root, cwd, skill, registry: join(cwd, ".atl", "skill-registry.md"), ignore: join(cwd, ".atl", ".gitignore") };
422
+ }
423
+
424
+ for (const target of ["registry", "ignore"] as const) {
425
+ test(`registered startup preserves tracked ${target} in nested cwd and explicit refresh remains intentional`, async (t) => {
426
+ const fixture = registryFixture(true, true);
427
+ writeFileSync(fixture[target], target === "registry" ? "Reviewed registry\n" : "!*.md\n");
428
+ execSync(`git add -f nested/.atl/${target === "registry" ? "skill-registry.md" : ".gitignore"}`, { cwd: fixture.root, stdio: "ignore" });
429
+ const before = readFileSync(fixture[target], "utf8");
430
+ const runtime = registeredRegistry(fixture.cwd);
431
+ t.after(() => runtime.stop());
432
+ await runtime.start();
433
+ assert.equal(readFileSync(fixture[target], "utf8"), before);
434
+ assert.ok(runtime.notices.some(({ message, level }) => level === "warning" && message.includes(`.atl/${target === "registry" ? "skill-registry.md" : ".gitignore"}`) && message.includes("/skill-registry:refresh")));
435
+ if (target === "registry") assert.ok(!runtime.notices.some(({ message }) => message.includes("refreshed")));
436
+ await runtime.refresh();
437
+ assert.notEqual(readFileSync(fixture[target], "utf8"), before);
438
+ assert.ok(runtime.notices.some(({ message }) => message.includes("written to .atl/skill-registry.md")));
439
+ });
440
+ }
441
+
442
+ test("registered watcher protects registry tracked after a cache hit", async (t) => {
443
+ const fixture = registryFixture();
444
+ const runtime = registeredRegistry(fixture.cwd);
445
+ t.after(() => runtime.stop());
446
+ await runtime.start();
447
+ await runtime.start();
448
+ const before = readFileSync(fixture.registry, "utf8");
449
+ execSync("git add -f .atl/skill-registry.md", { cwd: fixture.root, stdio: "ignore" });
450
+ runtime.notices.length = 0;
451
+ writeFileSync(fixture.skill, "---\nname: local\ndescription: Changed skill.\n---\n");
452
+ const deadline = Date.now() + 5000;
453
+ while (runtime.notices.length === 0 && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 50));
454
+ assert.equal(readFileSync(fixture.registry, "utf8"), before);
455
+ assert.ok(runtime.notices.some(({ message, level }) => level === "warning" && message.includes("/skill-registry:refresh")));
456
+ assert.ok(!runtime.notices.some(({ message }) => message.includes("refreshed")));
457
+ });
458
+
459
+ for (const git of [true, false]) {
460
+ test(`registered startup and watcher regenerate normally in ${git ? "untracked Git" : "non-Git"} fixtures`, async (t) => {
461
+ const fixture = registryFixture(git);
462
+ const runtime = registeredRegistry(fixture.cwd);
463
+ t.after(() => runtime.stop());
464
+ await runtime.start();
465
+ assert.match(readFileSync(fixture.registry, "utf8"), /Initial skill/);
466
+ assert.equal(readFileSync(fixture.ignore, "utf8"), "*\n");
467
+ writeFileSync(fixture.skill, "---\nname: local\ndescription: Changed skill.\n---\n");
468
+ const deadline = Date.now() + 5000;
469
+ while (!readFileSync(fixture.registry, "utf8").includes("Changed skill") && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, 50));
470
+ assert.match(readFileSync(fixture.registry, "utf8"), /Changed skill/);
471
+ });
472
+ }
473
+
474
+ test("automatic forced freshness protects tracked cache without partial registry writes", async () => {
475
+ const fixture = registryFixture();
476
+ await __testing.regenerateRegistry(fixture.cwd, false);
477
+ const cache = join(fixture.cwd, ".atl", ".skill-registry.cache.json");
478
+ execSync("git add -f .atl/.skill-registry.cache.json", { cwd: fixture.root, stdio: "ignore" });
479
+ const beforeCache = readFileSync(cache, "utf8");
480
+ const beforeRegistry = readFileSync(fixture.registry, "utf8");
481
+ writeFileSync(fixture.skill, "---\nname: local\ndescription: Changed skill.\n---\n");
482
+ const result = await __testing.regenerateRegistry(fixture.cwd, true);
483
+ assert.equal(result.regenerated, false);
484
+ assert.match(result.warning ?? "", /\.atl\/\.skill-registry\.cache\.json/);
485
+ assert.equal(readFileSync(cache, "utf8"), beforeCache);
486
+ assert.equal(readFileSync(fixture.registry, "utf8"), beforeRegistry);
487
+ });
488
+
489
+ test("registered Git detection failure skips automatic writes and reports deliberate refresh", async (t) => {
490
+ const fixture = registryFixture(false);
491
+ writeFileSync(join(fixture.cwd, ".git"), "invalid gitfile\n");
492
+ const runtime = registeredRegistry(fixture.cwd);
493
+ t.after(() => runtime.stop());
494
+ await runtime.start();
495
+ assert.equal(existsSync(fixture.ignore), false);
496
+ assert.equal(existsSync(fixture.registry), false);
497
+ assert.ok(runtime.notices.some(({ message, level }) => level === "warning" && message.includes(".atl/.gitignore") && message.includes("/skill-registry:refresh")));
498
+ assert.ok(!runtime.notices.some(({ message }) => message.includes("refreshed")));
499
+ await runtime.refresh();
500
+ assert.match(readFileSync(fixture.registry, "utf8"), /Initial skill/);
501
+ });
502
+
503
+ for (const nested of [false, true]) {
504
+ test(`registered startup fails closed for broken Git redirect with nested=${nested}`, async (t) => {
505
+ const fixture = registryFixture(false, nested);
506
+ writeFileSync(join(fixture.root, ".git"), "gitdir: missing-git-directory\n");
507
+ const runtime = registeredRegistry(fixture.cwd);
508
+ t.after(() => runtime.stop());
509
+ await runtime.start();
510
+ for (const path of [fixture.ignore, fixture.registry, join(fixture.cwd, ".atl", ".skill-registry.cache.json")]) {
511
+ assert.equal(existsSync(path), false, `automatic startup must not create ${path}`);
512
+ }
513
+ assert.ok(runtime.notices.some(({ message, level }) => level === "warning" && message.includes("Resolve Git detection")));
514
+ assert.ok(!runtime.notices.some(({ message }) => message.includes("refreshed")));
515
+ });
516
+ }
517
+
518
+ test("registered startup preserves tracked generated legacy source with accurate manual remedy", async (t) => {
519
+ const fixture = registryFixture();
520
+ const legacy = join(fixture.cwd, ".pi", "extensions", "skill-registry.ts");
521
+ const source = 'Auto-generated by .pi/extensions/skill-registry.ts\nconst REGISTRY_REL_PATH = ".atl/skill-registry.md"\nfunction projectSkillDirs(cwd: string): string[]\nfunction regenerateRegistry(cwd: string, force: boolean)\n';
522
+ mkdirSync(dirname(legacy), { recursive: true });
523
+ writeFileSync(legacy, source);
524
+ execSync("git add .pi/extensions/skill-registry.ts", { cwd: fixture.root, stdio: "ignore" });
525
+ const runtime = registeredRegistry(fixture.cwd);
526
+ t.after(() => runtime.stop());
527
+ await runtime.start();
528
+ assert.equal(readFileSync(legacy, "utf8"), source);
529
+ assert.equal(existsSync(`${legacy}.disabled`), false);
530
+ assert.ok(!runtime.notices.some(({ message }) => /quarantined/i.test(message)));
531
+ const warning = runtime.notices.find(({ message, level }) => level === "warning" && message.includes(".pi/extensions/skill-registry.ts"))?.message ?? "";
532
+ assert.match(warning, /manually.*tracked legacy extension/i);
533
+ assert.doesNotMatch(warning, /\/skill-registry:refresh/);
534
+ await runtime.refresh();
535
+ assert.equal(readFileSync(legacy, "utf8"), source);
536
+ assert.equal(existsSync(`${legacy}.disabled`), false);
537
+ });
538
+
539
+ for (const control of ["environment", "--no-skills", "-ns"]) {
540
+ test(`registered ${control} suppression skips startup writes and watchers`, async (t) => {
541
+ const fixture = registryFixture();
542
+ const runtime = registeredRegistry(fixture.cwd);
543
+ const previousEnv = process.env.GENTLE_PI_NO_SKILL_REGISTRY;
544
+ const previousArgv = process.argv;
545
+ if (control === "environment") process.env.GENTLE_PI_NO_SKILL_REGISTRY = "1";
546
+ else process.argv = [...process.argv, control];
547
+ t.after(() => {
548
+ process.argv = previousArgv;
549
+ if (previousEnv === undefined) delete process.env.GENTLE_PI_NO_SKILL_REGISTRY;
550
+ else process.env.GENTLE_PI_NO_SKILL_REGISTRY = previousEnv;
551
+ return runtime.stop();
552
+ });
553
+ await runtime.start();
554
+ assert.equal(existsSync(fixture.registry), false);
555
+ assert.equal(existsSync(fixture.ignore), false);
556
+ assert.equal(__testing.activeWatcherCount(), 0);
557
+ await runtime.refresh();
558
+ assert.match(readFileSync(fixture.registry, "utf8"), /Initial skill/);
559
+ });
560
+ }
561
+
562
+ // gentle-shell#1690: delegated rpc children have hasUI=true but must not write
563
+ // .atl/, rename the legacy registry or start a watcher in the shared cwd.
564
+ test("registered startup in a delegated child avoids writes, legacy rename and watchers", async (t) => {
565
+ const fixture = registryFixture();
566
+ const legacy = join(fixture.cwd, ".pi", "extensions", "skill-registry.ts");
567
+ mkdirSync(dirname(legacy), { recursive: true });
568
+ const source = 'Auto-generated by .pi/extensions/skill-registry.ts\nconst REGISTRY_REL_PATH = ".atl/skill-registry.md"\nfunction projectSkillDirs(cwd: string): string[]\nfunction regenerateRegistry(cwd: string, force: boolean)\n';
569
+ writeFileSync(legacy, source);
570
+ const previous = process.env.GENTLE_PI_AGENTS_CHILD;
571
+ process.env.GENTLE_PI_AGENTS_CHILD = "1";
572
+ t.after(() => {
573
+ if (previous === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
574
+ else process.env.GENTLE_PI_AGENTS_CHILD = previous;
575
+ });
576
+ const runtime = registeredRegistry(fixture.cwd);
577
+ t.after(() => runtime.stop());
578
+ await runtime.start();
579
+ assert.equal(existsSync(fixture.registry), false);
580
+ assert.equal(existsSync(fixture.ignore), false);
581
+ assert.equal(readFileSync(legacy, "utf8"), source);
582
+ assert.equal(existsSync(`${legacy}.disabled`), false);
583
+ assert.equal(__testing.activeWatcherCount(), 0);
584
+ assert.deepEqual(runtime.notices, []);
585
+ });
586
+
587
+ test("registered suppression avoids writes and watchers but permits explicit refresh", async (t) => {
588
+ const fixture = registryFixture();
589
+ const runtime = registeredRegistry(fixture.cwd, true);
590
+ t.after(() => runtime.stop());
591
+ await runtime.start();
592
+ assert.equal(existsSync(fixture.registry), false);
593
+ assert.equal(existsSync(fixture.ignore), false);
594
+ assert.equal(__testing.activeWatcherCount(), 0);
595
+ await runtime.refresh();
596
+ assert.match(readFileSync(fixture.registry, "utf8"), /Initial skill/);
597
+ });
598
+
599
+ // S7 CR4: the delayed regeneration after a legacy quarantine belongs to the
600
+ // session that scheduled it; a shutdown before it fires cancels it.
601
+ test("registered startup skips the delayed quarantine regeneration after shutdown", async () => {
602
+ const fixture = registryFixture();
603
+ const legacy = join(fixture.cwd, ".pi", "extensions", "skill-registry.ts");
604
+ mkdirSync(dirname(legacy), { recursive: true });
605
+ writeFileSync(legacy, 'Auto-generated by .pi/extensions/skill-registry.ts\nconst REGISTRY_REL_PATH = ".atl/skill-registry.md"\nfunction projectSkillDirs(cwd: string): string[]\nfunction regenerateRegistry(cwd: string, force: boolean)\n');
606
+ const runtime = registeredRegistry(fixture.cwd);
607
+ await runtime.start();
608
+ assert.equal(existsSync(`${legacy}.disabled`), true, "the legacy registry was quarantined");
609
+ await runtime.stop();
610
+ rmSync(fixture.registry);
611
+ await new Promise((resolve) => setTimeout(resolve, 800));
612
+ assert.equal(existsSync(fixture.registry), false, "a shut-down session must not regenerate the registry");
613
+ });
614
+
615
+ // S4: regeneration must not hold Pi's serial session_start chain.
616
+ test("registered startup returns before regenerating and settles to the same output", async (t) => {
617
+ const fixture = registryFixture();
618
+ const runtime = registeredRegistry(fixture.cwd);
619
+ t.after(() => runtime.stop());
620
+ await runtime.startOnly();
621
+ assert.equal(existsSync(fixture.registry), false, "session_start must not await regeneration");
622
+ await __testing.startupSettled();
623
+ assert.match(readFileSync(fixture.registry, "utf8"), /Initial skill/);
624
+ assert.equal(readFileSync(fixture.ignore, "utf8"), "*\n");
625
+ assert.ok(runtime.notices.some(({ message }) => message === "Skill registry refreshed (1 skills)"));
626
+ });
627
+
628
+ // S4: a Git lookup that never answers (a repository rooted at HOME) takes the
629
+ // existing fail-closed path instead of hanging.
630
+ test("automatic Git tracking check times out into the fail-closed path", { skip: process.platform === "win32" }, async (t) => {
631
+ const fixture = registryFixture();
632
+ const bin = mkdtempSync(join(tmpdir(), "gentle-pi-slow-git-"));
633
+ writeFileSync(join(bin, "git"), "#!/bin/sh\nexec sleep 3\n", { mode: 0o755 });
634
+ const previousPath = process.env.PATH;
635
+ process.env.PATH = `${bin}:${previousPath ?? ""}`;
636
+ const previousTimeout = __testing.setGitTimeoutMs(200);
637
+ t.after(() => {
638
+ process.env.PATH = previousPath;
639
+ __testing.setGitTimeoutMs(previousTimeout);
640
+ rmSync(bin, { recursive: true, force: true });
641
+ });
642
+ const started = Date.now();
643
+ await assert.rejects(__testing.ensureAtlIgnored(fixture.cwd), /Cannot verify Git tracking/);
644
+ assert.ok(Date.now() - started < 2000, "the lookup must stop at its timeout");
645
+ assert.equal(existsSync(fixture.ignore), false);
646
+ });
647
+
648
+ // S2: a repository rooted at HOME makes every Git call scan the whole home.
649
+ // Startup skips the automatic Git work there; deliberate refresh still works.
650
+ test("registered startup skips Git work and watchers when the repository is rooted at HOME", async (t) => {
651
+ const home = realpathSync(mkdtempSync(join(tmpdir(), "gentle-pi-registry-git-home-")));
652
+ execSync("git init", { cwd: home, stdio: "ignore" });
653
+ const cwd = join(home, "project");
654
+ const skill = join(cwd, "skills", "local", "SKILL.md");
655
+ mkdirSync(dirname(skill), { recursive: true });
656
+ writeFileSync(skill, "---\nname: local\ndescription: Initial skill.\n---\n");
657
+ process.env.HOME = home;
658
+ process.env.USERPROFILE = home;
659
+ const runtime = registeredRegistry(cwd);
660
+ t.after(async () => {
661
+ await runtime.stop();
662
+ process.env.HOME = fixtureHome;
663
+ process.env.USERPROFILE = fixtureHome;
664
+ rmSync(home, { recursive: true, force: true });
665
+ });
666
+ await runtime.start();
667
+ assert.equal(existsSync(join(cwd, ".atl", ".gitignore")), false);
668
+ assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
669
+ assert.equal(__testing.activeWatcherCount(), 0);
670
+ assert.deepEqual(runtime.notices, []);
671
+ await runtime.refresh();
672
+ assert.match(readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8"), /Initial skill/);
673
+ });
@@ -2,14 +2,19 @@ import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
3
  import { syncBuiltinESMExports } from "node:module";
4
4
  import fs from "node:fs/promises";
5
- import { mkdtempSync, readFileSync, rmSync, writeFileSync } from "node:fs";
5
+ import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
6
6
  import { tmpdir } from "node:os";
7
7
  import { join } from "node:path";
8
- import startup, { isPiCliSubcommandInvocation, readGitBranch } from "../extensions/startup-banner.ts";
8
+ import startup, { isPiCliSubcommandInvocation, readBannerConfig, readGitBranch } from "../extensions/startup-banner.ts";
9
+ import { setBundledInstallForTesting } from "../lib/gentle-shell-bundled.ts";
9
10
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
10
11
  import { visibleWidth } from "@earendil-works/pi-tui";
11
12
  import { stripAnsi } from "../lib/terminal-theme.ts";
12
13
 
14
+ // The banner reads process.env directly; a suite launched from a delegated
15
+ // child must still exercise the parent paths (gentle-shell#1690).
16
+ delete process.env.GENTLE_PI_AGENTS_CHILD;
17
+
13
18
  test("startup artwork spells Gentle Shell with aligned animation spans", () => {
14
19
  const source = readFileSync(new URL("../extensions/startup-banner.ts", import.meta.url), "utf8");
15
20
  const logo = JSON.parse(source.match(/const TEXT_LOGO = (\[[\s\S]*?\]);/)![1].replace(/,\s*]/, "]")) as string[];
@@ -71,10 +76,26 @@ test("startup branch lookup uses direct git argv and hides its Windows child", a
71
76
  assert.deepEqual(calls, [{
72
77
  command: "git",
73
78
  args: ["-C", "/repo with spaces & metacharacters", "branch", "--show-current"],
74
- options: { encoding: "utf8", shell: false, windowsHide: true },
79
+ options: { encoding: "utf8", shell: false, windowsHide: true, timeout: 3000 },
75
80
  }]);
76
81
  });
77
82
 
83
+ // S4: a hung `git branch` (for example a repository rooted at HOME) must not
84
+ // keep the banner waiting; a timeout reads as the ordinary failure path.
85
+ test("startup branch lookup times out into the not-a-repo fallback", { skip: process.platform === "win32" }, async (t) => {
86
+ const bin = mkdtempSync(join(tmpdir(), "gp-banner-slow-git-"));
87
+ writeFileSync(join(bin, "git"), "#!/bin/sh\nexec sleep 3\n", { mode: 0o755 });
88
+ const previousPath = process.env.PATH;
89
+ process.env.PATH = `${bin}:${previousPath ?? ""}`;
90
+ t.after(() => {
91
+ process.env.PATH = previousPath;
92
+ rmSync(bin, { recursive: true, force: true });
93
+ });
94
+ const started = Date.now();
95
+ assert.equal(await readGitBranch(bin, undefined, 200), "Not a git repo");
96
+ assert.ok(Date.now() - started < 2000, "the lookup must stop at its timeout");
97
+ });
98
+
78
99
  test("startup banner keeps animating after invalidate and cleans up on dispose", async (t) => {
79
100
  const home = mkdtempSync(join(tmpdir(), "gp-banner-quality-"));
80
101
  writeFileSync(join(home, "animations.json"), '{"schema":"gentle-pi.animations/v1","policy":"quality"}');
@@ -396,3 +417,96 @@ test("launcher-injected extension directories do not suppress the startup banner
396
417
  assert.equal(isPiCliSubcommandInvocation(["node", "pi", sub, "npm:x"]), true, sub);
397
418
  }
398
419
  });
420
+
421
+ // gentle-shell#1690: a delegated rpc child has hasUI=true; only a piped stdout
422
+ // without rows/columns kept the banner off before the explicit child guard.
423
+ test("delegated children never paint the startup banner", async (t) => {
424
+ const previousChild = process.env.GENTLE_PI_AGENTS_CHILD;
425
+ process.env.GENTLE_PI_AGENTS_CHILD = "1";
426
+ t.after(() => {
427
+ if (previousChild === undefined) delete process.env.GENTLE_PI_AGENTS_CHILD;
428
+ else process.env.GENTLE_PI_AGENTS_CHILD = previousChild;
429
+ });
430
+ const home = mkdtempSync(join(tmpdir(), "gp-banner-child-"));
431
+ const previousHome = process.env.GENTLE_PI_CONFIG_HOME;
432
+ process.env.GENTLE_PI_CONFIG_HOME = home;
433
+ t.after(() => {
434
+ if (previousHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
435
+ else process.env.GENTLE_PI_CONFIG_HOME = previousHome;
436
+ rmSync(home, { recursive: true, force: true });
437
+ });
438
+ t.mock.timers.enable({ apis: ["setTimeout", "setInterval", "Date"] });
439
+ t.mock.method(fs, "readFile", async () => JSON.stringify({ showRose: true, showTextLogo: true, color: "pink" }));
440
+ syncBuiltinESMExports();
441
+ t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
442
+ const argv = process.argv;
443
+ process.argv = ["node"];
444
+ t.after(() => { process.argv = argv; });
445
+ for (const [key, value] of [["rows", 40], ["columns", 160]] as const) {
446
+ const descriptor = Object.getOwnPropertyDescriptor(process.stdout, key);
447
+ Object.defineProperty(process.stdout, key, { configurable: true, writable: true, value });
448
+ t.after(() => descriptor ? Object.defineProperty(process.stdout, key, descriptor) : Reflect.deleteProperty(process.stdout, key));
449
+ }
450
+ let start: Function;
451
+ let shutdown: Function;
452
+ startup({ on: (name: string, fn: Function) => {
453
+ if (name === "session_start") start = fn;
454
+ if (name === "session_shutdown") shutdown = fn;
455
+ }, registerCommand() {}, getCommands: () => [], getAllTools: () => [] } as unknown as ExtensionAPI);
456
+ t.after(() => shutdown?.());
457
+ let headers = 0;
458
+ await start!({}, { hasUI: true, cwd: "/fixture", ui: { setHeader: () => { headers++; } } });
459
+ t.mock.timers.tick(50);
460
+ assert.equal(headers, 0);
461
+ });
462
+
463
+ // S9: the config home each of these reads resolves, per case. The OS home is
464
+ // a temporary folder in every case, so no case can reach the real one.
465
+ // "unset" and "empty" are exactly as before: an empty GENTLE_PI_CONFIG_HOME
466
+ // names the current folder. "bundled" stands in for this package running from
467
+ // a bundled install (testing overlay) whose prefix the launcher passed; the
468
+ // user's own GENTLE_PI_CONFIG_HOME is then not this install's.
469
+ type ConfigHomeCase = "unset" | "empty" | "bundled";
470
+ function configHomeCase(t: { after: (fn: () => void) => void }, kind: ConfigHomeCase): { env: NodeJS.ProcessEnv; dir: string; userConfig: string } {
471
+ const base = realpathSync(mkdtempSync(join(tmpdir(), `config-home-${kind}-`)));
472
+ const saved = { HOME: process.env.HOME, USERPROFILE: process.env.USERPROFILE, GENTLE_PI_CONFIG_HOME: process.env.GENTLE_PI_CONFIG_HOME, GENTLE_SHELL_PREFIX: process.env.GENTLE_SHELL_PREFIX };
473
+ const cwd = process.cwd();
474
+ process.env.HOME = join(base, "home");
475
+ process.env.USERPROFILE = join(base, "home");
476
+ delete process.env.GENTLE_PI_CONFIG_HOME;
477
+ delete process.env.GENTLE_SHELL_PREFIX;
478
+ t.after(() => {
479
+ process.chdir(cwd);
480
+ setBundledInstallForTesting(undefined);
481
+ for (const [name, value] of Object.entries(saved)) {
482
+ if (value === undefined) delete process.env[name];
483
+ else process.env[name] = value;
484
+ }
485
+ rmSync(base, { recursive: true, force: true });
486
+ });
487
+ const userConfig = join(base, "user-config");
488
+ if (kind === "unset") return { env: {}, dir: join(base, "home", ".pi", "gentle-ai"), userConfig };
489
+ if (kind === "empty") {
490
+ mkdirSync(join(base, "cwd"));
491
+ process.chdir(join(base, "cwd"));
492
+ return { env: { GENTLE_PI_CONFIG_HOME: "" }, dir: join(base, "cwd"), userConfig };
493
+ }
494
+ const prefix = join(base, "prefix");
495
+ mkdirSync(prefix);
496
+ setBundledInstallForTesting({ root: prefix });
497
+ return { env: { GENTLE_SHELL_PREFIX: prefix, GENTLE_PI_CONFIG_HOME: userConfig }, dir: join(prefix, "config", "gentle-ai"), userConfig };
498
+ }
499
+
500
+ for (const kind of ["unset", "empty", "bundled"] as const) {
501
+ test(`the banner reads its settings from the ${kind} config home`, async (t) => {
502
+ const { env, dir, userConfig } = configHomeCase(t, kind);
503
+ Object.assign(process.env, env);
504
+ const write = (folder: string, color: string) => {
505
+ mkdirSync(folder, { recursive: true });
506
+ writeFileSync(join(folder, "banner.json"), JSON.stringify({ showRose: false, showTextLogo: true, color }));
507
+ };
508
+ write(userConfig, "yellow");
509
+ write(dir, "cyan");
510
+ assert.deepEqual(await readBannerConfig(), { showRose: false, showTextLogo: true, color: "cyan" });
511
+ });
512
+ }
@@ -0,0 +1,170 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { mkdirSync, mkdtempSync, realpathSync, rmSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
8
+ import { createGentleAiExtension, __testing } from "../extensions/gentle-ai.ts";
9
+ import type { NativeReviewCli } from "../lib/native-review-cli.ts";
10
+ import type { ReviewStatusV3 } from "../lib/review-integration-v2.ts";
11
+ import { worktreeGitEnvironment } from "../lib/session-worktree-registry.ts";
12
+
13
+ // S2/S4 (odd/tasks/startup-home-repo-and-changes.md): a repository rooted at
14
+ // HOME makes every Git call scan the user's whole tree. Startup warns once and
15
+ // skips its review negotiation there; a normal project keeps negotiating, and
16
+ // its startup RDD status read serves the first prompt without a respawn.
17
+
18
+ type AnyHandler = (event: unknown, ctx: ExtensionContext) => unknown;
19
+ type Notice = { message: string; severity: string };
20
+ const ENV_KEYS = ["HOME", "USERPROFILE", "GENTLE_PI_CONFIG_HOME", "GENTLE_PI_AGENT_HOME", "PI_CODING_AGENT_DIR", "XDG_CONFIG_HOME"] as const;
21
+
22
+ function fixture(t: test.TestContext, gitAtHome: boolean) {
23
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "gentle-pi-startup-home-")));
24
+ const home = join(root, "home");
25
+ const state = join(root, "state");
26
+ const cwd = join(home, "project");
27
+ mkdirSync(cwd, { recursive: true });
28
+ mkdirSync(state);
29
+ const git = (directory: string) => execFileSync("git", ["init", "--quiet", directory], { env: worktreeGitEnvironment(), stdio: "pipe" });
30
+ git(gitAtHome ? home : cwd);
31
+ const environment: Record<(typeof ENV_KEYS)[number], string> = {
32
+ HOME: home, USERPROFILE: home,
33
+ GENTLE_PI_CONFIG_HOME: join(state, "config"),
34
+ GENTLE_PI_AGENT_HOME: join(state, "agents"),
35
+ PI_CODING_AGENT_DIR: join(state, "pi"),
36
+ XDG_CONFIG_HOME: join(state, "xdg"),
37
+ };
38
+ const previous = new Map(ENV_KEYS.map(key => [key, process.env[key]]));
39
+ Object.assign(process.env, environment);
40
+ __testing.clearRddStatusMemoForTesting();
41
+ t.after(() => {
42
+ for (const [key, value] of previous) {
43
+ if (value === undefined) delete process.env[key];
44
+ else process.env[key] = value;
45
+ }
46
+ __testing.clearRddStatusMemoForTesting();
47
+ rmSync(root, { recursive: true, force: true });
48
+ });
49
+ return { cwd, environment };
50
+ }
51
+
52
+ function nativeCli() {
53
+ const calls = { mode: 0, target: 0 };
54
+ const cli = {
55
+ reviewMode: async () => {
56
+ calls.mode++;
57
+ return { operation: "status", scope: "clone", status: { global: "", cloneLocal: "on", effective: "on", source: "clone_local" } };
58
+ },
59
+ targetStatus: async () => {
60
+ calls.target++;
61
+ return { applicability: "unrelated", action: "start", targetIdentity: `sha256:${"5".repeat(64)}`, nextTransition: { kind: "stop" } } as unknown as ReviewStatusV3;
62
+ },
63
+ } as unknown as NativeReviewCli;
64
+ return { cli, calls };
65
+ }
66
+
67
+ function start(cli: NativeReviewCli, cwd: string, environment: NodeJS.ProcessEnv) {
68
+ const handlers = new Map<string, AnyHandler>();
69
+ const notices: Notice[] = [];
70
+ const pi = {
71
+ appendEntry() {},
72
+ on(name: string, handler: AnyHandler) { handlers.set(name, handler); },
73
+ events: { emit() {} },
74
+ registerCommand() {},
75
+ registerTool() {},
76
+ sendMessage() {},
77
+ } as unknown as ExtensionAPI;
78
+ createGentleAiExtension({
79
+ nativeReviewCli: cli,
80
+ processEnv: { ...environment, GENTLE_PI_AGENTS_CHILD: "0", GENTLE_AI_TELEMETRY: "0" },
81
+ resolveTelemetryTriggerBinary: () => join(cwd, "never-executed"),
82
+ telemetryTriggerSpawn: () => assert.fail("Startup fixtures must not spawn telemetry"),
83
+ })(pi);
84
+ const ctx = {
85
+ cwd,
86
+ hasUI: true,
87
+ ui: { notify: (message: string, severity: string) => { notices.push({ message, severity }); } },
88
+ sessionManager: { getSessionId: () => "startup-home-session", getCwd: () => cwd, getEntries: () => [], getBranch: () => [] },
89
+ } as unknown as ExtensionContext;
90
+ return { handlers, notices, ctx };
91
+ }
92
+
93
+ const homeWarning = (notices: Notice[]) => notices.filter(({ message }) => message.includes("rooted at your home folder"));
94
+
95
+ test("a repository rooted at HOME warns once and skips the startup review negotiation", async (t) => {
96
+ const { cwd, environment } = fixture(t, true);
97
+ const { cli, calls } = nativeCli();
98
+ const { handlers, notices, ctx } = start(cli, cwd, environment);
99
+ await handlers.get("session_start")!({}, ctx);
100
+ const warnings = homeWarning(notices);
101
+ assert.equal(warnings.length, 1, JSON.stringify(notices));
102
+ assert.equal(warnings[0]!.severity, "warning");
103
+ assert.match(warnings[0]!.message, /Open Gentle Shell inside a project folder/);
104
+ assert.equal(calls.target, 0, "no startup review negotiation");
105
+ assert.equal(calls.mode, 0, "no startup review mode spawn");
106
+ await handlers.get("session_start")!({ reason: "reload" }, ctx);
107
+ assert.equal(homeWarning(notices).length, 1, "the warning is shown once per process and repository");
108
+ });
109
+
110
+ test("a normal project repository keeps negotiating and its startup status serves the first prompt", async (t) => {
111
+ const { cwd, environment } = fixture(t, false);
112
+ const { cli, calls } = nativeCli();
113
+ const { handlers, notices, ctx } = start(cli, cwd, environment);
114
+ await handlers.get("session_start")!({}, ctx);
115
+ await __testing.startupNegotiationSettled();
116
+ assert.deepEqual(homeWarning(notices), []);
117
+ assert.equal(calls.target, 1, "startup still negotiates the review target");
118
+ assert.equal(calls.mode, 1);
119
+ const event = { systemPrompt: "base", systemPromptOptions: { appendSystemPrompt: "" } };
120
+ await handlers.get("before_agent_start")!(event, ctx);
121
+ assert.equal(calls.mode, 1, "the first prompt reuses the startup review mode status");
122
+ assert.match(event.systemPromptOptions.appendSystemPrompt, /Receipt-driven development: on/);
123
+ });
124
+
125
+ // S7 CR3: an unresolvable HOME is unknown, not a home-rooted repository. The
126
+ // bootstrap guard still fails closed there; the startup warning does not.
127
+ test("an unresolvable HOME neither warns nor skips the startup review negotiation", async (t) => {
128
+ const { cwd, environment } = fixture(t, false);
129
+ const missingHome = join(cwd, "..", "..", "missing-home");
130
+ process.env.HOME = missingHome;
131
+ process.env.USERPROFILE = missingHome;
132
+ const { cli, calls } = nativeCli();
133
+ const { handlers, notices, ctx } = start(cli, cwd, { ...environment, HOME: missingHome, USERPROFILE: missingHome });
134
+ await handlers.get("session_start")!({}, ctx);
135
+ await __testing.startupNegotiationSettled();
136
+ assert.deepEqual(homeWarning(notices), []);
137
+ assert.equal(calls.target, 1, "startup still negotiates the review target");
138
+ });
139
+
140
+ // S5: Pi awaits session_start handlers one after another, so the native review
141
+ // negotiation (two gentle-ai spawns) no longer holds startup. It runs after
142
+ // session_start returns, bounded by a signal, and the first prompt still reuses
143
+ // its RDD status instead of spawning the same read again.
144
+ test("startup returns before the native review negotiation finishes, and the first prompt still reuses its status", async (t) => {
145
+ const { cwd, environment } = fixture(t, false);
146
+ const { cli, calls } = nativeCli();
147
+ let release!: () => void;
148
+ const gate = new Promise<void>(resolve => { release = resolve; });
149
+ const signals: Array<AbortSignal | undefined> = [];
150
+ const slowMode = cli.reviewMode!.bind(cli);
151
+ (cli as { reviewMode: NativeReviewCli["reviewMode"] }).reviewMode = (async (request: { signal?: AbortSignal }) => {
152
+ signals.push(request.signal);
153
+ await gate;
154
+ return slowMode(request as never);
155
+ }) as NativeReviewCli["reviewMode"];
156
+ const { handlers, ctx } = start(cli, cwd, environment);
157
+ const started = handlers.get("session_start")!({}, ctx) as Promise<void>;
158
+ const outcome = await Promise.race([started.then(() => "returned"), new Promise(resolve => setTimeout(() => resolve("blocked"), 500))]);
159
+ assert.equal(outcome, "returned", "session_start must not wait for native review negotiation");
160
+ assert.equal(calls.target, 0, "negotiation is still pending");
161
+ assert.ok(signals[0] instanceof AbortSignal, "the startup review mode read is bounded by a signal");
162
+ const event = { systemPrompt: "base", systemPromptOptions: { appendSystemPrompt: "" } };
163
+ const prompt = handlers.get("before_agent_start")!(event, ctx) as Promise<void>;
164
+ release();
165
+ await prompt;
166
+ assert.equal(calls.mode, 1, "the first prompt waits for the in-flight startup read instead of spawning another");
167
+ assert.match(event.systemPromptOptions.appendSystemPrompt, /Receipt-driven development: on/);
168
+ await __testing.startupNegotiationSettled();
169
+ assert.equal(calls.target, 1, "the negotiation still completes after startup");
170
+ });