gentle-pi 4.7.0 → 4.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (617) hide show
  1. package/README.md +115 -44
  2. package/assets/agents/gentle-ai-explore.md +3 -3
  3. package/assets/agents/gentle-ai-verify.md +20 -6
  4. package/assets/agents/gentle-ai-worker.md +14 -13
  5. package/assets/agents/jd-judge-a.md +1 -3
  6. package/assets/agents/jd-judge-b.md +1 -3
  7. package/assets/agents/review-readability.md +1 -5
  8. package/assets/agents/review-reliability.md +1 -5
  9. package/assets/agents/review-resilience.md +1 -5
  10. package/assets/agents/review-risk.md +1 -5
  11. package/assets/design-canvas/canvas-api.js +45 -0
  12. package/assets/design-canvas/canvas-boards.js +476 -0
  13. package/assets/design-canvas/canvas-boot.js +219 -0
  14. package/assets/design-canvas/canvas-checks.js +491 -0
  15. package/assets/design-canvas/canvas-comments.js +315 -0
  16. package/assets/design-canvas/canvas-compare.js +159 -0
  17. package/assets/design-canvas/canvas-events.js +75 -0
  18. package/assets/design-canvas/canvas-export.js +393 -0
  19. package/assets/design-canvas/canvas-focus.js +203 -0
  20. package/assets/design-canvas/canvas-handoffs.js +150 -0
  21. package/assets/design-canvas/canvas-i18n-es.js +397 -0
  22. package/assets/design-canvas/canvas-i18n.js +108 -0
  23. package/assets/design-canvas/canvas-layout.js +526 -0
  24. package/assets/design-canvas/canvas-menu.js +219 -0
  25. package/assets/design-canvas/canvas-messages.js +86 -0
  26. package/assets/design-canvas/canvas-minimap.js +163 -0
  27. package/assets/design-canvas/canvas-parts.js +401 -0
  28. package/assets/design-canvas/canvas-popover.js +234 -0
  29. package/assets/design-canvas/canvas-rail.js +351 -0
  30. package/assets/design-canvas/canvas-sizes.js +524 -0
  31. package/assets/design-canvas/canvas-store.js +167 -0
  32. package/assets/design-canvas/canvas-theme.js +69 -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 +773 -17
  37. package/assets/design-canvas/canvas.js +2 -1506
  38. package/assets/design-canvas/index.html +120 -36
  39. package/assets/design-canvas/inspector.js +574 -21
  40. package/assets/design-canvas/theme-early.js +10 -0
  41. package/assets/install-wizard/wizard.js +5 -1
  42. package/assets/migrations/agent-body-history.json +30 -0
  43. package/assets/orchestrator-delegation-reference.md +8 -14
  44. package/assets/orchestrator-delegation.md +5 -9
  45. package/assets/orchestrator-full-delegation-card.md +11 -16
  46. package/assets/orchestrator-full-delegation.md +9 -9
  47. package/assets/orchestrator-memory.md +4 -4
  48. package/assets/orchestrator-prompts.md +3 -31
  49. package/assets/orchestrator-quota-recovery.md +5 -0
  50. package/assets/orchestrator-skills.md +13 -12
  51. package/assets/orchestrator-tracking.md +13 -17
  52. package/assets/orchestrator-verification.md +12 -10
  53. package/assets/orchestrator-writer.md +13 -13
  54. package/assets/orchestrator.md +20 -24
  55. package/bin/gentle-shell.mjs +205 -10
  56. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -9
  57. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/manifest.json +3 -3
  58. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/orchestration/pi.md +2 -1
  59. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/routing/pi.md +16 -16
  60. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-capabilities.baseline.json +3 -3
  61. package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/generated/provider-roles.baseline.json +1 -1
  62. package/docs/assets/brand/sponsor-banner.svg +60 -0
  63. package/docs/assets/features/gentle-tower.png +0 -0
  64. package/docs/auto-permission-answers.md +1 -1
  65. package/docs/bundled-install.md +14 -6
  66. package/docs/delegated-verification.md +23 -5
  67. package/docs/desktop-feed.md +303 -0
  68. package/docs/desktop-rpc.md +1931 -0
  69. package/docs/fast-mode.md +2 -2
  70. package/docs/gentle-agents-activity.md +26 -0
  71. package/docs/gentle-shell-desktop.md +465 -0
  72. package/docs/gentle-shell.md +102 -17
  73. package/docs/images/desktop/chat.png +0 -0
  74. package/docs/images/desktop/palette.png +0 -0
  75. package/docs/images/desktop/todo.png +0 -0
  76. package/docs/install-wizard.md +30 -21
  77. package/docs/odd-preparation-continuity.md +24 -0
  78. package/docs/permission-modes.md +9 -1
  79. package/docs/prompt-budget.md +12 -0
  80. package/docs/rdd-odd-friction-triage-2026-11-07.md +57 -0
  81. package/docs/readme-reference.md +113 -32
  82. package/docs/review-coordinator.md +29 -9
  83. package/docs/review-delivery-preflight.md +22 -0
  84. package/docs/work-continuity.md +19 -6
  85. package/extensions/ask-user-choice.ts +36 -18
  86. package/extensions/ask-user-question.ts +48 -9
  87. package/extensions/child-context.ts +21 -7
  88. package/extensions/gentle-agents.ts +436 -66
  89. package/extensions/gentle-ai.ts +809 -158
  90. package/extensions/gentle-design.ts +69 -3
  91. package/extensions/gentle-desktop-feed.ts +778 -0
  92. package/extensions/gentle-desktop-rpc.ts +276 -0
  93. package/extensions/gentle-guide.ts +3 -0
  94. package/extensions/gentle-herdr-desktop-status.ts +275 -0
  95. package/extensions/gentle-shell.ts +174 -59
  96. package/extensions/gentle-stats.ts +30 -1
  97. package/extensions/gentle-todo.ts +48 -25
  98. package/extensions/gentle-tower.ts +305 -0
  99. package/extensions/skill-registry.ts +260 -225
  100. package/herdr/RECIPE.md +157 -0
  101. package/herdr/keys.json +14 -0
  102. package/herdr/layouts/gentle-shell.json +202 -0
  103. package/herdr/mods/gentle-agents/icons/kind-herdr.svg +1 -0
  104. package/herdr/mods/gentle-agents/icons/kind-remote.svg +1 -0
  105. package/herdr/mods/gentle-agents/icons/kind-tui.svg +1 -0
  106. package/herdr/mods/gentle-agents/main.js +190 -0
  107. package/herdr/mods/gentle-agents/mod.json +1 -0
  108. package/herdr/mods/gentle-agents/snapshot.js +469 -0
  109. package/herdr/mods/gentle-agents/tokens.js +273 -0
  110. package/herdr/mods/gentle-chat/MINIMAL.md +69 -0
  111. package/herdr/mods/gentle-chat/actions.js +180 -0
  112. package/herdr/mods/gentle-chat/feed.js +321 -0
  113. package/herdr/mods/gentle-chat/icons/branch.svg +1 -0
  114. package/herdr/mods/gentle-chat/icons/chat.svg +1 -0
  115. package/herdr/mods/gentle-chat/icons/check.svg +1 -0
  116. package/herdr/mods/gentle-chat/icons/chev.svg +1 -0
  117. package/herdr/mods/gentle-chat/icons/clip.svg +1 -0
  118. package/herdr/mods/gentle-chat/icons/down.svg +1 -0
  119. package/herdr/mods/gentle-chat/icons/folder.svg +1 -0
  120. package/herdr/mods/gentle-chat/icons/kind-herdr.svg +1 -0
  121. package/herdr/mods/gentle-chat/icons/kind-remote.svg +1 -0
  122. package/herdr/mods/gentle-chat/icons/kind-tui.svg +1 -0
  123. package/herdr/mods/gentle-chat/icons/mark.svg +1 -0
  124. package/herdr/mods/gentle-chat/icons/send.svg +1 -0
  125. package/herdr/mods/gentle-chat/icons/shield.svg +1 -0
  126. package/herdr/mods/gentle-chat/icons/stop.svg +1 -0
  127. package/herdr/mods/gentle-chat/icons/term.svg +1 -0
  128. package/herdr/mods/gentle-chat/icons/user.svg +1 -0
  129. package/herdr/mods/gentle-chat/icons/x.svg +1 -0
  130. package/herdr/mods/gentle-chat/main.js +968 -0
  131. package/herdr/mods/gentle-chat/mod.json +1 -0
  132. package/herdr/mods/gentle-chat/session.js +212 -0
  133. package/herdr/mods/gentle-chat/snapshot.js +469 -0
  134. package/herdr/mods/gentle-chat/tokens.js +137 -0
  135. package/herdr/mods/gentle-chat/ui.js +883 -0
  136. package/herdr/mods/gentle-confirm/main.js +60 -0
  137. package/herdr/mods/gentle-confirm/mod.json +1 -0
  138. package/herdr/mods/gentle-inspector/actions.js +180 -0
  139. package/herdr/mods/gentle-inspector/icons/bolt.svg +1 -0
  140. package/herdr/mods/gentle-inspector/icons/bot.svg +1 -0
  141. package/herdr/mods/gentle-inspector/icons/check.svg +1 -0
  142. package/herdr/mods/gentle-inspector/icons/db.svg +1 -0
  143. package/herdr/mods/gentle-inspector/icons/diff.svg +1 -0
  144. package/herdr/mods/gentle-inspector/icons/jobs.svg +1 -0
  145. package/herdr/mods/gentle-inspector/icons/plug.svg +1 -0
  146. package/herdr/mods/gentle-inspector/icons/review.svg +1 -0
  147. package/herdr/mods/gentle-inspector/icons/stats.svg +1 -0
  148. package/herdr/mods/gentle-inspector/icons/stop.svg +1 -0
  149. package/herdr/mods/gentle-inspector/icons/todo.svg +1 -0
  150. package/herdr/mods/gentle-inspector/main.js +500 -0
  151. package/herdr/mods/gentle-inspector/mod.json +1 -0
  152. package/herdr/mods/gentle-inspector/snapshot.js +469 -0
  153. package/herdr/mods/gentle-inspector/tokens.js +273 -0
  154. package/herdr/mods/gentle-palette/actions.js +180 -0
  155. package/herdr/mods/gentle-palette/icons/bolt.svg +1 -0
  156. package/herdr/mods/gentle-palette/icons/bot.svg +1 -0
  157. package/herdr/mods/gentle-palette/icons/chat.svg +1 -0
  158. package/herdr/mods/gentle-palette/icons/check.svg +1 -0
  159. package/herdr/mods/gentle-palette/icons/cmd.svg +1 -0
  160. package/herdr/mods/gentle-palette/icons/diff.svg +1 -0
  161. package/herdr/mods/gentle-palette/icons/jobs.svg +1 -0
  162. package/herdr/mods/gentle-palette/icons/plus.svg +1 -0
  163. package/herdr/mods/gentle-palette/icons/review.svg +1 -0
  164. package/herdr/mods/gentle-palette/icons/search.svg +1 -0
  165. package/herdr/mods/gentle-palette/icons/shield.svg +1 -0
  166. package/herdr/mods/gentle-palette/icons/stats.svg +1 -0
  167. package/herdr/mods/gentle-palette/icons/stop.svg +1 -0
  168. package/herdr/mods/gentle-palette/icons/term.svg +1 -0
  169. package/herdr/mods/gentle-palette/icons/todo.svg +1 -0
  170. package/herdr/mods/gentle-palette/main.js +333 -0
  171. package/herdr/mods/gentle-palette/mod.json +1 -0
  172. package/herdr/mods/gentle-palette/snapshot.js +469 -0
  173. package/herdr/mods/gentle-palette/tokens.js +273 -0
  174. package/herdr/mods/gentle-pane/icons/chat.svg +1 -0
  175. package/herdr/mods/gentle-pane/icons/close.svg +1 -0
  176. package/herdr/mods/gentle-pane/icons/kind-herdr.svg +1 -0
  177. package/herdr/mods/gentle-pane/icons/kind-remote.svg +1 -0
  178. package/herdr/mods/gentle-pane/icons/kind-tui.svg +1 -0
  179. package/herdr/mods/gentle-pane/icons/split-down.svg +1 -0
  180. package/herdr/mods/gentle-pane/icons/split-right.svg +1 -0
  181. package/herdr/mods/gentle-pane/icons/term.svg +1 -0
  182. package/herdr/mods/gentle-pane/icons/unzoom.svg +1 -0
  183. package/herdr/mods/gentle-pane/icons/zoom.svg +1 -0
  184. package/herdr/mods/gentle-pane/main.js +91 -0
  185. package/herdr/mods/gentle-pane/mod.json +1 -0
  186. package/herdr/mods/gentle-pane/snapshot.js +469 -0
  187. package/herdr/mods/gentle-pane/tokens.js +273 -0
  188. package/herdr/mods/gentle-sidebar/actions.js +180 -0
  189. package/herdr/mods/gentle-sidebar/icons/gear.svg +1 -0
  190. package/herdr/mods/gentle-sidebar/icons/mark.svg +1 -0
  191. package/herdr/mods/gentle-sidebar/icons/refresh.svg +1 -0
  192. package/herdr/mods/gentle-sidebar/icons/server-plus.svg +1 -0
  193. package/herdr/mods/gentle-sidebar/main.js +171 -0
  194. package/herdr/mods/gentle-sidebar/mod.json +1 -0
  195. package/herdr/mods/gentle-sidebar/snapshot.js +469 -0
  196. package/herdr/mods/gentle-sidebar/tokens.js +273 -0
  197. package/herdr/mods/gentle-spaces/icons/kind-herdr.svg +1 -0
  198. package/herdr/mods/gentle-spaces/icons/kind-remote.svg +1 -0
  199. package/herdr/mods/gentle-spaces/icons/kind-tui.svg +1 -0
  200. package/herdr/mods/gentle-spaces/icons/monitor.svg +1 -0
  201. package/herdr/mods/gentle-spaces/icons/plus.svg +1 -0
  202. package/herdr/mods/gentle-spaces/icons/server.svg +1 -0
  203. package/herdr/mods/gentle-spaces/machines.js +31 -0
  204. package/herdr/mods/gentle-spaces/main.js +299 -0
  205. package/herdr/mods/gentle-spaces/mod.json +1 -0
  206. package/herdr/mods/gentle-spaces/snapshot.js +469 -0
  207. package/herdr/mods/gentle-spaces/tokens.js +273 -0
  208. package/herdr/mods/gentle-status/actions.js +180 -0
  209. package/herdr/mods/gentle-status/main.js +192 -0
  210. package/herdr/mods/gentle-status/mod.json +1 -0
  211. package/herdr/mods/gentle-status/snapshot.js +469 -0
  212. package/herdr/mods/gentle-status/tokens.js +273 -0
  213. package/herdr/mods/gentle-tabs/icons/close.svg +1 -0
  214. package/herdr/mods/gentle-tabs/icons/kind-herdr.svg +1 -0
  215. package/herdr/mods/gentle-tabs/icons/kind-remote.svg +1 -0
  216. package/herdr/mods/gentle-tabs/icons/kind-tui.svg +1 -0
  217. package/herdr/mods/gentle-tabs/icons/plus.svg +1 -0
  218. package/herdr/mods/gentle-tabs/icons/win-close.svg +1 -0
  219. package/herdr/mods/gentle-tabs/icons/win-max.svg +1 -0
  220. package/herdr/mods/gentle-tabs/icons/win-min.svg +1 -0
  221. package/herdr/mods/gentle-tabs/icons/win-restore.svg +1 -0
  222. package/herdr/mods/gentle-tabs/main.js +171 -0
  223. package/herdr/mods/gentle-tabs/mod.json +1 -0
  224. package/herdr/mods/gentle-tabs/snapshot.js +469 -0
  225. package/herdr/mods/gentle-tabs/tokens.js +273 -0
  226. package/herdr/mods/gentle-tokens/main.js +20 -0
  227. package/herdr/mods/gentle-tokens/mod.json +1 -0
  228. package/herdr/mods/gentle-tokens/snapshot.js +469 -0
  229. package/herdr/mods/gentle-tokens/tokens.js +273 -0
  230. package/herdr/preview.png +0 -0
  231. package/herdr/themes/gentle-shell-dark.json +33 -0
  232. package/herdr/themes/gentle-shell-light.json +34 -0
  233. package/lib/agent-assets.ts +30 -6
  234. package/lib/agent-tool-overlay.ts +117 -0
  235. package/lib/agents-config.ts +47 -6
  236. package/lib/agents-message-delivery.ts +17 -0
  237. package/lib/agents-messaging.ts +8 -2
  238. package/lib/agents-protocol.ts +17 -0
  239. package/lib/agents-report-cap.ts +115 -0
  240. package/lib/agents-rpc-publisher.ts +39 -12
  241. package/lib/agents-runner.ts +92 -6
  242. package/lib/agents-session-transport.ts +17 -1
  243. package/lib/auto-permission-answers.ts +2 -1
  244. package/lib/background-jobs-tools.ts +9 -4
  245. package/lib/background-jobs.ts +22 -2
  246. package/lib/bounded-writer-admission.ts +184 -31
  247. package/lib/change-diff.ts +104 -0
  248. package/lib/child-context-files.ts +21 -6
  249. package/lib/codemode-renderer.ts +1 -0
  250. package/lib/commit-slice-signal.ts +1 -1
  251. package/lib/delivery-conflict-markers.ts +349 -0
  252. package/lib/design-canvas-assets.ts +38 -0
  253. package/lib/design-canvas-server.ts +241 -23
  254. package/lib/design-comments.ts +94 -4
  255. package/lib/design-handoffs.ts +2 -1
  256. package/lib/design-layout.ts +125 -0
  257. package/lib/design-parts.ts +281 -0
  258. package/lib/design-system-tokens.ts +111 -0
  259. package/lib/desktop-agents-service.ts +315 -0
  260. package/lib/desktop-changes-service.ts +171 -0
  261. package/lib/desktop-design-service.ts +233 -0
  262. package/lib/desktop-feed-actions.ts +804 -0
  263. package/lib/desktop-feed-answers.ts +129 -0
  264. package/lib/desktop-feed-sources.ts +184 -0
  265. package/lib/desktop-feed-stats.ts +98 -0
  266. package/lib/desktop-feed-store.ts +124 -0
  267. package/lib/desktop-feed.ts +788 -0
  268. package/lib/desktop-jobs-service.ts +290 -0
  269. package/lib/desktop-review-service.ts +187 -0
  270. package/lib/desktop-rpc-agents.ts +403 -0
  271. package/lib/desktop-rpc-changes.ts +223 -0
  272. package/lib/desktop-rpc-config-watch.ts +285 -0
  273. package/lib/desktop-rpc-config.ts +885 -0
  274. package/lib/desktop-rpc-design.ts +138 -0
  275. package/lib/desktop-rpc-jobs.ts +290 -0
  276. package/lib/desktop-rpc-permissions.ts +328 -0
  277. package/lib/desktop-rpc-profiles.ts +196 -0
  278. package/lib/desktop-rpc-review.ts +180 -0
  279. package/lib/desktop-rpc-session.ts +203 -0
  280. package/lib/desktop-rpc-sessions.ts +250 -0
  281. package/lib/desktop-rpc-stats.ts +187 -0
  282. package/lib/desktop-rpc-updates.ts +143 -0
  283. package/lib/desktop-rpc-usage.ts +229 -0
  284. package/lib/desktop-rpc.ts +336 -0
  285. package/lib/desktop-session-service.ts +223 -0
  286. package/lib/desktop-sessions-service.ts +249 -0
  287. package/lib/desktop-stats-service.ts +142 -0
  288. package/lib/desktop-updates-service.ts +268 -0
  289. package/lib/desktop-usage-service.ts +310 -0
  290. package/lib/destructive-command-guard.ts +188 -13
  291. package/lib/gentle-ai-renderer.ts +13 -1
  292. package/lib/gentle-design.ts +201 -14
  293. package/lib/gentle-shell-bundled.ts +100 -9
  294. package/lib/gentle-shell-desktop.ts +1370 -0
  295. package/lib/gentle-shell-launcher.ts +45 -3
  296. package/lib/herdr-desktop-events.ts +40 -0
  297. package/lib/herdr-desktop-status.ts +229 -0
  298. package/lib/hidden-tools.ts +35 -0
  299. package/lib/inprocess-reviewer.ts +96 -12
  300. package/lib/jobs-sidebar-state.ts +5 -0
  301. package/lib/model-fallback-policy.ts +9 -0
  302. package/lib/model-routing-authority.ts +9 -0
  303. package/lib/nan-provider.ts +42 -28
  304. package/lib/native-review-cli.ts +86 -4
  305. package/lib/openai-fast-tier.ts +1 -0
  306. package/lib/orchestrator-discovery.ts +39 -2
  307. package/lib/reply-language-anchor.ts +27 -2
  308. package/lib/request-context-placement.ts +53 -0
  309. package/lib/review-candidate-view.ts +11 -1
  310. package/lib/review-continuation-registry.ts +17 -0
  311. package/lib/review-coordinator.ts +252 -8
  312. package/lib/review-delivery-preflight.ts +85 -0
  313. package/lib/review-host-relay.ts +5 -1
  314. package/lib/review-integration-v2.ts +56 -3
  315. package/lib/reviewer-stream.ts +87 -0
  316. package/lib/session-profile-freeze.ts +13 -5
  317. package/lib/shell-prompt.ts +16 -3
  318. package/lib/shell-usage.ts +10 -0
  319. package/lib/stats-collector.ts +56 -27
  320. package/lib/tower-actions.ts +100 -0
  321. package/lib/tower-hub.ts +73 -0
  322. package/lib/tower-launch.ts +111 -0
  323. package/lib/tower-open.ts +99 -0
  324. package/lib/tower-presence.ts +70 -0
  325. package/lib/tower-server.ts +234 -0
  326. package/lib/tower-snapshot.ts +298 -0
  327. package/lib/update-status.ts +238 -0
  328. package/lib/verifier-settle-reminder.ts +1 -1
  329. package/lib/vim-editor-adapter.ts +9 -2
  330. package/lib/writer-batch-admission.ts +55 -0
  331. package/lib/yolo-session-policy.ts +6 -1
  332. package/package.json +14 -5
  333. package/prompts/skill-creation.md +1 -10
  334. package/runtime/design-canvas-assets.mjs +39 -0
  335. package/runtime/gentle-shell-bundled.mjs +100 -9
  336. package/runtime/gentle-shell-desktop.mjs +1371 -0
  337. package/runtime/gentle-shell-launcher.mjs +44 -2
  338. package/runtime/native-review-cli.mjs +86 -4
  339. package/runtime/review-integration-v2.mjs +56 -3
  340. package/runtime/tower-actions.mjs +101 -0
  341. package/runtime/tower-hub.mjs +74 -0
  342. package/runtime/tower-launch.mjs +112 -0
  343. package/runtime/tower-open.mjs +100 -0
  344. package/runtime/tower-presence.mjs +71 -0
  345. package/runtime/tower-server.mjs +234 -0
  346. package/runtime/tower-snapshot.mjs +299 -0
  347. package/scripts/bootstrap.cmd +2 -2
  348. package/scripts/bootstrap.sh +41 -4
  349. package/scripts/build-full-delegation-card.mjs +5 -21
  350. package/scripts/build-runtime-modules.mjs +10 -0
  351. package/scripts/gentle-ai-installer.mjs +10 -10
  352. package/scripts/gentle-ai-proxy.mjs +1 -1
  353. package/scripts/installer-downloads.mjs +34 -8
  354. package/scripts/installer-preflight.mjs +28 -17
  355. package/scripts/installer-probes.mjs +25 -5
  356. package/scripts/installer-server.mjs +38 -9
  357. package/scripts/installer-windows.mjs +2 -2
  358. package/scripts/pi-update.mjs +166 -27
  359. package/scripts/prepare-verifier.mjs +107 -0
  360. package/scripts/update-agent-body-history.mjs +55 -8
  361. package/scripts/verify-package-files.mjs +61 -20
  362. package/skills/branch-pr/SKILL.md +16 -16
  363. package/skills/comment-writer/SKILL.md +1 -1
  364. package/skills/design/SKILL.md +6 -6
  365. package/skills/gentle-ai/SKILL.md +5 -5
  366. package/skills/judgment-day/SKILL.md +2 -2
  367. package/skills/judgment-day/references/prompts-and-formats.md +1 -1
  368. package/skills/provider-defect-report/SKILL.md +61 -0
  369. package/skills/rdd-defect-workflow/SKILL.md +6 -6
  370. package/skills/skill-improver/SKILL.md +2 -2
  371. package/skills/skill-registry/SKILL.md +11 -13
  372. package/skills/tui-design/SKILL.md +1 -1
  373. package/skills/work-unit-commits/SKILL.md +5 -5
  374. package/tests/agent-prompt-diet-contract.test.ts +101 -0
  375. package/tests/agent-tool-overlay-acceptance.test.ts +158 -0
  376. package/tests/agent-tool-overlay.test.ts +89 -0
  377. package/tests/agents-config.test.ts +10 -1
  378. package/tests/agents-message-delivery.test.ts +36 -0
  379. package/tests/agents-queries.test.ts +144 -4
  380. package/tests/agents-report-cap.test.ts +126 -0
  381. package/tests/agents-runner.test.ts +37 -1
  382. package/tests/agents-session-transport.test.ts +34 -0
  383. package/tests/always-on-prompt-verdicts-contract.test.ts +188 -0
  384. package/tests/append-system-prompt-route.test.ts +26 -7
  385. package/tests/approved-text-leftovers-contract.test.ts +136 -0
  386. package/tests/artifact-language.test.ts +1 -1
  387. package/tests/ask-user-choice.test.ts +78 -21
  388. package/tests/ask-user-question.test.ts +61 -6
  389. package/tests/audit-leftovers-contract.test.ts +51 -0
  390. package/tests/auto-permission-answers.test.ts +12 -1
  391. package/tests/background-jobs.test.ts +12 -0
  392. package/tests/bounded-stop-contract.test.ts +148 -27
  393. package/tests/branch-pr-skill.test.ts +10 -1
  394. package/tests/bundled-install.test.ts +1 -1
  395. package/tests/change-diff.test.ts +75 -0
  396. package/tests/child-context-files.test.ts +64 -8
  397. package/tests/child-skills-catalog.test.ts +56 -0
  398. package/tests/codemode-rendering.test.ts +4 -1
  399. package/tests/commit-slice-signal.test.ts +3 -2
  400. package/tests/decision-routing-contract.test.ts +390 -0
  401. package/tests/delegate-for-reason-contract.test.ts +30 -8
  402. package/tests/delegated-key-learnings-contract.test.ts +21 -28
  403. package/tests/delivery-b-rendered-surfaces.test.ts +32 -0
  404. package/tests/delivery-conflict-markers.test.ts +348 -0
  405. package/tests/design-canvas-all-sizes.test.ts +631 -0
  406. package/tests/design-canvas-allowlist.test.ts +32 -0
  407. package/tests/design-canvas-assets.test.ts +11 -878
  408. package/tests/design-canvas-boards.test.ts +77 -0
  409. package/tests/design-canvas-checks.test.ts +655 -0
  410. package/tests/design-canvas-compare.test.ts +79 -0
  411. package/tests/design-canvas-events.test.ts +59 -0
  412. package/tests/design-canvas-export.test.ts +1168 -0
  413. package/tests/design-canvas-focus.test.ts +113 -0
  414. package/tests/design-canvas-handoffs.test.ts +59 -0
  415. package/tests/design-canvas-i18n-review.test.ts +513 -0
  416. package/tests/design-canvas-i18n-views.test.ts +259 -0
  417. package/tests/design-canvas-i18n.test.ts +528 -0
  418. package/tests/design-canvas-inspector.test.ts +1004 -0
  419. package/tests/design-canvas-layout.test.ts +1222 -0
  420. package/tests/design-canvas-minimap.test.ts +413 -0
  421. package/tests/design-canvas-modules.test.ts +91 -0
  422. package/tests/design-canvas-parts.test.ts +721 -0
  423. package/tests/design-canvas-rail.test.ts +799 -0
  424. package/tests/design-canvas-server.test.ts +855 -17
  425. package/tests/design-canvas-sizes.test.ts +548 -0
  426. package/tests/design-canvas-store.test.ts +189 -0
  427. package/tests/design-canvas-theme.test.ts +198 -0
  428. package/tests/design-canvas-tokens.test.ts +965 -0
  429. package/tests/design-canvas-view.test.ts +299 -0
  430. package/tests/design-comments.test.ts +201 -1
  431. package/tests/design-handoffs.test.ts +20 -0
  432. package/tests/design-layout.test.ts +100 -0
  433. package/tests/design-parts.test.ts +260 -0
  434. package/tests/design-system-tokens.test.ts +215 -0
  435. package/tests/desktop-feed-actions-guards.test.ts +595 -0
  436. package/tests/desktop-feed-actions.test.ts +761 -0
  437. package/tests/desktop-feed-live-work.test.ts +209 -0
  438. package/tests/desktop-feed-performance.test.ts +369 -0
  439. package/tests/desktop-feed-plan-profiles.test.ts +509 -0
  440. package/tests/desktop-feed-send-prompt.test.ts +303 -0
  441. package/tests/desktop-feed-tool-summaries.test.ts +69 -0
  442. package/tests/desktop-feed.test.ts +615 -0
  443. package/tests/desktop-rpc-agents.test.ts +1319 -0
  444. package/tests/desktop-rpc-changes.test.ts +608 -0
  445. package/tests/desktop-rpc-config-watch.test.ts +1159 -0
  446. package/tests/desktop-rpc-config.test.ts +1462 -0
  447. package/tests/desktop-rpc-design.test.ts +672 -0
  448. package/tests/desktop-rpc-jobs.test.ts +1193 -0
  449. package/tests/desktop-rpc-permissions.test.ts +321 -0
  450. package/tests/desktop-rpc-profiles.test.ts +140 -0
  451. package/tests/desktop-rpc-review.test.ts +678 -0
  452. package/tests/desktop-rpc-safety.test.ts +119 -0
  453. package/tests/desktop-rpc-session.test.ts +642 -0
  454. package/tests/desktop-rpc-sessions.test.ts +647 -0
  455. package/tests/desktop-rpc-stats.test.ts +431 -0
  456. package/tests/desktop-rpc-updates.test.ts +525 -0
  457. package/tests/desktop-rpc-usage.test.ts +707 -0
  458. package/tests/desktop-rpc.test.ts +293 -0
  459. package/tests/devbinary/pi-host-relay.devtest.ts +149 -80
  460. package/tests/devbinary/review-session-consent.devtest.ts +84 -0
  461. package/tests/engram-safety.test.ts +111 -0
  462. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.captured.json +92 -0
  463. package/tests/fixtures/devbinary/status-v9-escalated-non-blocking.provenance.md +3 -0
  464. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +30 -41
  465. package/tests/fixtures/refusal-identity.probe.mjs +139 -0
  466. package/tests/fixtures/session-profile-v1/replay.ts +4 -1
  467. package/tests/full-delegation-closure.test.ts +48 -0
  468. package/tests/gentle-agents.test.ts +848 -8
  469. package/tests/gentle-ai-binary.test.ts +1 -1
  470. package/tests/gentle-ai-child-guards.test.ts +1 -0
  471. package/tests/gentle-ai-installer.test.ts +52 -51
  472. package/tests/gentle-ai-renderer.test.ts +36 -2
  473. package/tests/gentle-ai.test.ts +195 -21
  474. package/tests/gentle-design.test.ts +365 -1
  475. package/tests/gentle-fast.test.ts +15 -0
  476. package/tests/gentle-herdr-desktop-status.test.ts +595 -0
  477. package/tests/gentle-shell-bundled.test.ts +91 -5
  478. package/tests/gentle-shell-desktop-bin.test.ts +125 -0
  479. package/tests/gentle-shell-desktop.test.ts +927 -0
  480. package/tests/gentle-shell-launcher-tower.test.ts +104 -0
  481. package/tests/gentle-shell-launcher.test.ts +1 -1
  482. package/tests/gentle-shell.test.ts +121 -87
  483. package/tests/gentle-todo.test.ts +32 -9
  484. package/tests/gentle-tower.test.ts +578 -0
  485. package/tests/herdr-desktop-status.test.ts +285 -0
  486. package/tests/hidden-tools.test.ts +188 -0
  487. package/tests/independent-recovery-delivery.test.ts +35 -9
  488. package/tests/inprocess-reviewer.test.ts +73 -0
  489. package/tests/install-wizard.test.ts +27 -1
  490. package/tests/installer-downloads.test.ts +30 -1
  491. package/tests/installer-posix-bootstrap.test.ts +114 -13
  492. package/tests/installer-preflight.test.ts +49 -1
  493. package/tests/installer-probes.test.ts +146 -0
  494. package/tests/installer-server.test.ts +203 -4
  495. package/tests/installer-windows-bootstrap.test.ts +19 -1
  496. package/tests/judgment-day-severity-admission.test.ts +46 -0
  497. package/tests/lazy-module-contradictions-contract.test.ts +181 -0
  498. package/tests/maintainer/desktop-rpc.maintest.ts +907 -0
  499. package/tests/maintainer/pi-update-source.maintest.ts +48 -18
  500. package/tests/model-fallback-policy.test.ts +26 -7
  501. package/tests/nan-provider-runtime.test.ts +17 -3
  502. package/tests/nan-provider.test.ts +111 -56
  503. package/tests/native-review-capability-contract.test.ts +19 -1
  504. package/tests/native-review-cli-nonblocking-findings.test.ts +165 -0
  505. package/tests/native-review-parity.test.ts +24 -5
  506. package/tests/native-review-refusal-identity.test.ts +25 -0
  507. package/tests/no-self-pause-contract.test.ts +33 -15
  508. package/tests/odd-integration.test.ts +11 -3
  509. package/tests/odd-routing-canonical-ratchet.test.ts +10 -0
  510. package/tests/odd-routing-contract.test.ts +99 -31
  511. package/tests/orchestrator-budget.test.ts +32 -5
  512. package/tests/orchestrator-consultation-sdk.test.ts +32 -6
  513. package/tests/orchestrator-delegation-mode.test.ts +2 -1
  514. package/tests/orchestrator-discovery.test.ts +28 -0
  515. package/tests/orchestrator-prompt-budget.test.ts +12 -2
  516. package/tests/orchestrator-prompt-diet-contract.test.ts +249 -0
  517. package/tests/orchestrator-rdd-ownership.test.ts +2 -1
  518. package/tests/orchestrator-work-search.test.ts +4 -2
  519. package/tests/package-files.test.ts +25 -1
  520. package/tests/package-manifest.test.ts +15 -14
  521. package/tests/parallel-reason-contract.test.ts +6 -3
  522. package/tests/permission-allowlist.test.ts +200 -30
  523. package/tests/persona-neutral-voseo.test.ts +4 -4
  524. package/tests/persona-reply-language.test.ts +1 -1
  525. package/tests/persona-single-channel.test.ts +13 -5
  526. package/tests/pi-routing-measured-values.test.ts +24 -0
  527. package/tests/pi-update-launcher.test.ts +17 -7
  528. package/tests/pi-update-source.test.ts +113 -6
  529. package/tests/pi-update.test.ts +294 -19
  530. package/tests/pnpm-workspace-policy.test.ts +47 -0
  531. package/tests/primary-context-files.test.ts +233 -0
  532. package/tests/primary-context-three-files.test.ts +174 -0
  533. package/tests/primary-session-prompt.test.ts +25 -0
  534. package/tests/profile-fast-tier.test.ts +66 -1
  535. package/tests/provider-defect-handoff.test.ts +124 -99
  536. package/tests/rdd-aware-verification-contract.test.ts +1 -1
  537. package/tests/rdd-status-line.test.ts +94 -1
  538. package/tests/reply-language-anchor-placement.test.ts +184 -0
  539. package/tests/reply-language-anchor.test.ts +17 -1
  540. package/tests/request-context-append-only.test.ts +218 -0
  541. package/tests/request-context-placement.test.ts +148 -0
  542. package/tests/review-agent-end-preflight.test.ts +79 -1
  543. package/tests/review-candidate-view.test.ts +65 -0
  544. package/tests/review-continuation-registry.test.ts +31 -0
  545. package/tests/review-contract-prompt.test.ts +2 -1
  546. package/tests/review-controller.test.ts +2 -1
  547. package/tests/review-coordinator-correction-gate.test.ts +105 -0
  548. package/tests/review-coordinator-findings.test.ts +206 -0
  549. package/tests/review-coordinator-nonblocking-scope.test.ts +169 -0
  550. package/tests/review-coordinator.test.ts +271 -4
  551. package/tests/review-delivery-preflight.test.ts +462 -0
  552. package/tests/review-due-compaction.test.ts +31 -0
  553. package/tests/review-due-public-boundary.test.ts +27 -0
  554. package/tests/review-integration-nonblocking-findings.test.ts +108 -0
  555. package/tests/review-json-arguments.test.ts +41 -2
  556. package/tests/review-ledger-contract.test.ts +19 -40
  557. package/tests/review-loadout-rdd-off-sdk.test.ts +30 -1
  558. package/tests/review-one-call-findings.test.ts +131 -0
  559. package/tests/review-one-call-followups.test.ts +308 -0
  560. package/tests/review-one-call-reviewer-requests.test.ts +207 -0
  561. package/tests/review-one-call.test.ts +452 -0
  562. package/tests/review-relay-transport-agent.test.ts +28 -1
  563. package/tests/review-reviewer-evidence.test.ts +41 -1
  564. package/tests/review-risk-assessment.test.ts +52 -5
  565. package/tests/review-run-statement-guidance-independent.test.ts +54 -0
  566. package/tests/review-session-standing-permission-controller.test.ts +32 -2
  567. package/tests/review-tool-prose-budget.test.ts +1 -0
  568. package/tests/reviewer-stream.test.ts +149 -0
  569. package/tests/sensitive-path-tools.test.ts +138 -4
  570. package/tests/session-profile-extension.test.ts +312 -18
  571. package/tests/session-profile-freeze.test.ts +26 -0
  572. package/tests/session-profile-v1-compat.test.ts +20 -0
  573. package/tests/shell-prompt.test.ts +17 -0
  574. package/tests/shell-usage.test.ts +59 -10
  575. package/tests/skill-collision-prefixes.test.ts +1 -0
  576. package/tests/skill-contradictions-contract.test.ts +124 -0
  577. package/tests/skill-registry-watcher.test.ts +216 -2
  578. package/tests/skill-registry.test.ts +983 -306
  579. package/tests/stats-collector.test.ts +109 -2
  580. package/tests/support/design-canvas-dom.ts +386 -0
  581. package/tests/support/review-coordinator-runtime.ts +212 -17
  582. package/tests/task-size-routing-contract.test.ts +49 -14
  583. package/tests/test-strength-contract.test.ts +2 -1
  584. package/tests/todo-request-append-only.test.ts +214 -0
  585. package/tests/tool-batching-contract.test.ts +3 -1
  586. package/tests/tower-actions.test.ts +247 -0
  587. package/tests/tower-artifacts.test.ts +114 -0
  588. package/tests/tower-open.test.ts +97 -0
  589. package/tests/tower-presence.test.ts +175 -0
  590. package/tests/tower-server.test.ts +122 -0
  591. package/tests/tower-snapshot.test.ts +236 -0
  592. package/tests/tower-web-echo.test.ts +125 -0
  593. package/tests/tower-web-hover.test.ts +251 -0
  594. package/tests/update-agent-body-history.test.ts +138 -0
  595. package/tests/verification-scoped-stop-contract.test.ts +32 -0
  596. package/tests/verification-tiers-contract.test.ts +229 -0
  597. package/tests/verifier-preparation.test.ts +229 -0
  598. package/tests/verifier-settle-reminder.test.ts +2 -2
  599. package/tests/verify-agent-contract.test.ts +20 -2
  600. package/tests/verify-first-launch-contract.test.ts +88 -12
  601. package/tests/vim-editor-adapter.test.ts +2 -2
  602. package/tests/work-continuity-contract.test.ts +136 -27
  603. package/tests/writer-admission-messages.test.ts +232 -0
  604. package/tests/writer-batch-admission.test.ts +66 -0
  605. package/tests/writer-edit-surface-scope.test.ts +52 -20
  606. package/tests/writer-feature-document-admission.test.ts +184 -0
  607. package/tests/writer-rejection-next-step.test.ts +55 -0
  608. package/tests/writer-surface-authority-contract.test.ts +158 -0
  609. package/tests/yolo-mode.test.ts +39 -0
  610. package/skills/_shared/review-ledger-contract.md +0 -106
  611. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/README.md +0 -0
  612. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/lens.schema.json +0 -0
  613. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/refuter.schema.json +0 -0
  614. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/schemas/targeted-validator.schema.json +0 -0
  615. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/lens.json +0 -0
  616. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/refuter.json +0 -0
  617. /package/contracts/review-provider-contract-mirror/{v1.4.0 → v1.6.0}/bundle/vectors/targeted-validator.json +0 -0
@@ -1,8 +1,8 @@
1
1
  import assert from "node:assert/strict";
2
- import { execSync } from "node:child_process";
2
+ import { execSync, spawn, spawnSync } from "node:child_process";
3
3
  import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
- import { dirname, join } from "node:path";
5
+ import { dirname, join, relative } from "node:path";
6
6
  import test from "node:test";
7
7
  import { pathToFileURL } from "node:url";
8
8
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
@@ -184,6 +184,60 @@ test("findSkillFiles follows direct symlinked skills but not symlinked categorie
184
184
  assert.deepEqual(await __testing.findSkillFiles(root), [skillPath]);
185
185
  });
186
186
 
187
+ function writeSkill(root: string, dir: string, name: string): string {
188
+ const file = join(root, dir, "SKILL.md");
189
+ mkdirSync(dirname(file), { recursive: true });
190
+ writeFileSync(file, `---\nname: ${name}\ndescription: ${dir}.\n---\n`);
191
+ return file;
192
+ }
193
+
194
+ test("same-name duplicate in one scope resolves to the directory named after the skill", (t) => {
195
+ const root = mkdtempSync(join(tmpdir(), "gentle-pi-backup-dedupe-"));
196
+ t.after(() => rmSync(root, { recursive: true, force: true }));
197
+ const skills = join(root, "home", ".claude", "skills");
198
+ const hiddenBackup = writeSkill(skills, ".backup-live-to-youtube-20261114", "live-to-youtube");
199
+ const live = writeSkill(skills, "live-to-youtube", "live-to-youtube");
200
+ const suffixBackup = writeSkill(skills, "gentle-stack-main.backup-20260927T204711", "gentle-stack-main");
201
+ const stack = writeSkill(skills, "gentle-stack-main", "gentle-stack-main");
202
+ const cwd = join(root, "project");
203
+ const entry = (path: string, name: string) => ({ name, path, description: "d" });
204
+
205
+ for (const entries of [
206
+ [entry(hiddenBackup, "live-to-youtube"), entry(live, "live-to-youtube"), entry(suffixBackup, "gentle-stack-main"), entry(stack, "gentle-stack-main")],
207
+ [entry(live, "live-to-youtube"), entry(hiddenBackup, "live-to-youtube"), entry(stack, "gentle-stack-main"), entry(suffixBackup, "gentle-stack-main")],
208
+ ]) {
209
+ assert.deepEqual(__testing.dedupeBySkillName(entries, cwd).map((e) => e.path), [stack, live]);
210
+ }
211
+ });
212
+
213
+ test("findSkillFiles skips dot-prefixed skill directories inside a hidden root", async (t) => {
214
+ const root = mkdtempSync(join(tmpdir(), "gentle-pi-hidden-skill-"));
215
+ t.after(() => rmSync(root, { recursive: true, force: true }));
216
+ const skills = join(root, ".claude", "skills");
217
+ writeSkill(skills, ".backup-live-to-youtube-20261114", "live-to-youtube");
218
+ writeSkill(skills, join(".backup-category", "nested"), "nested");
219
+ const live = writeSkill(skills, "live-to-youtube", "live-to-youtube");
220
+
221
+ assert.deepEqual(await __testing.findSkillFiles(skills), [live]);
222
+ });
223
+
224
+ test("a root without duplicates keeps every skill and the first-candidate tie-break", async (t) => {
225
+ const root = mkdtempSync(join(tmpdir(), "gentle-pi-no-dup-"));
226
+ t.after(() => rmSync(root, { recursive: true, force: true }));
227
+ const skills = join(root, "skills");
228
+ const alpha = writeSkill(skills, "alpha", "alpha");
229
+ const beta = writeSkill(skills, "beta-dir", "beta");
230
+ const files = await __testing.findSkillFiles(skills);
231
+ assert.deepEqual(files, [alpha, beta]);
232
+ const cwd = join(root, "elsewhere");
233
+ const entries = files.map((path) => ({ name: __testing.parseFrontmatter(readFileSync(path, "utf8")).name ?? "", path, description: "d" }));
234
+ assert.deepEqual(__testing.dedupeBySkillName(entries, cwd).map((e) => e.path), [alpha, beta]);
235
+
236
+ const otherBeta = join(skills, "beta-old", "SKILL.md");
237
+ const [chosen] = __testing.dedupeBySkillName([entries[1], { name: "beta", path: otherBeta, description: "d" }], cwd);
238
+ assert.equal(chosen.path, beta);
239
+ });
240
+
187
241
  test("only missing skill-file errors allow category scanning", () => {
188
242
  assert.equal(__testing.isMissingSkillFileError({ code: "ENOENT" }), true);
189
243
  assert.equal(__testing.isMissingSkillFileError({ code: "ENOTDIR" }), true);
@@ -369,6 +423,49 @@ function escapeRegExp(value: string): string {
369
423
  return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
370
424
  }
371
425
 
426
+ // Pi lists its loaded skills itself, so the effective block proves a retained
427
+ // capture through a same-name user-root copy the captured record outranks.
428
+ function isolatedHome(t: { after(fn: () => void): void }): string {
429
+ const home = mkdtempSync(join(tmpdir(), "gentle-p2-home-"));
430
+ const oldHome = process.env.HOME, oldProfile = process.env.USERPROFILE;
431
+ process.env.HOME = home;
432
+ process.env.USERPROFILE = home;
433
+ t.after(() => {
434
+ if (oldHome === undefined) delete process.env.HOME; else process.env.HOME = oldHome;
435
+ if (oldProfile === undefined) delete process.env.USERPROFILE; else process.env.USERPROFILE = oldProfile;
436
+ rmSync(home, { recursive: true, force: true });
437
+ });
438
+ return home;
439
+ }
440
+
441
+ // os.homedir() reads USERPROFILE on Windows, so the helper must isolate both variables.
442
+ test("isolatedHome points HOME and USERPROFILE at the temporary home and restores both", async (t) => {
443
+ const before = { home: process.env.HOME, profile: process.env.USERPROFILE };
444
+ let home = "";
445
+ await t.test("inside the fixture", (st) => {
446
+ home = isolatedHome(st);
447
+ assert.equal(process.env.HOME, home);
448
+ assert.equal(process.env.USERPROFILE, home);
449
+ });
450
+ assert.equal(process.env.HOME, before.home);
451
+ assert.equal(process.env.USERPROFILE, before.profile);
452
+ assert.ok(!existsSync(home), "the temporary home is removed after the fixture");
453
+ });
454
+
455
+ // Positive control: without `read` or `bash` Pi lists nothing, so the retained capture becomes rows.
456
+ async function promptWithoutReaders(event: (event: unknown, ctx: unknown) => unknown, cwd: string): Promise<string> {
457
+ const options = { selectedTools: ["grep"], appendSystemPrompt: "" };
458
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
459
+ return options.appendSystemPrompt;
460
+ }
461
+
462
+ function userShadow(home: string, name: string): string {
463
+ const file = join(home, ".agents", "skills", `${name}-copy`, "SKILL.md");
464
+ mkdirSync(dirname(file), { recursive: true });
465
+ writeFileSync(file, `---\nname: ${name}\ndescription: User-root copy.\n---\n`);
466
+ return file;
467
+ }
468
+
372
469
  test("toResolvedEntry maps exact file path and scope from sourceInfo", () => {
373
470
  const cwd = join(tmpdir(), `gentle-pi-resolved-${Date.now()}`);
374
471
  const projectPath = join(cwd, "skills", "go-testing", "SKILL.md");
@@ -594,63 +691,20 @@ test("mergeResolvedWithLoose with empty resolved matches the loose-only result",
594
691
  );
595
692
  });
596
693
 
597
- test("regenerateRegistry merges pi-resolved skills with the loose scan", async () => {
598
- const cwd = join(tmpdir(), `gentle-pi-regen-resolved-${Date.now()}`);
599
- const looseSkillPath = join(cwd, "skills", "loose-one", "SKILL.md");
600
- mkdirSync(dirname(looseSkillPath), { recursive: true });
601
- writeFileSync(looseSkillPath, "---\nname: loose-one\ndescription: Loose skill.\n---\n");
602
-
603
- const pkgRoot = join(tmpdir(), `gentle-pi-regen-pkg-${Date.now()}`);
604
- const resolvedSkillPath = join(pkgRoot, "skills", "resolved-one", "SKILL.md");
605
- const resolved: ResolvedSkill[] = [
606
- {
607
- name: "resolved-one",
608
- description: "Trigger: resolved skill. Runtime authority.",
609
- filePath: resolvedSkillPath,
610
- sourceInfo: { scope: "project", origin: "package" },
611
- },
612
- ];
613
-
614
- const first = await __testing.regenerateRegistry(cwd, false, resolved);
615
- assert.equal(first.regenerated, true, "first regeneration writes the registry");
616
- assert.equal(first.reason, "fingerprint-changed");
617
- assert.ok(
618
- first.skillCount >= 2,
619
- "merged count must include the resolved skill and the loose skill (host user skills may add more)",
620
- );
621
-
622
- const registryPath = join(cwd, ".atl", "skill-registry.md");
623
- const registry = readFileSync(registryPath, "utf8");
624
- assert.match(registry, new RegExp(escapeRegExp(resolvedSkillPath)));
625
- assert.match(registry, new RegExp(escapeRegExp(looseSkillPath)));
626
- assert.match(registry, /project · package/);
627
- assert.match(
628
- registry,
629
- /Pi-resolved runtime authority \(before_agent_start\.systemPromptOptions\.skills\): 1 skill\(s\)/,
630
- );
631
-
632
- const second = await __testing.regenerateRegistry(cwd, false, resolved);
633
- assert.equal(second.regenerated, false, "identical resolved set must be a cache hit");
634
- assert.equal(second.reason, "cache-hit");
635
-
636
- const changed: ResolvedSkill[] = [
637
- ...resolved,
638
- {
639
- name: "resolved-two",
640
- description: "Second resolved skill.",
641
- filePath: join(pkgRoot, "skills", "resolved-two", "SKILL.md"),
642
- sourceInfo: { scope: "user" },
643
- },
644
- ];
645
- const third = await __testing.regenerateRegistry(cwd, false, changed);
646
- assert.equal(third.regenerated, true, "changed resolved set must regenerate");
647
- assert.equal(third.reason, "fingerprint-changed");
648
- const updated = readFileSync(registryPath, "utf8");
649
- assert.match(updated, /resolved-two/);
650
- assert.match(
651
- updated,
652
- /Pi-resolved runtime authority \(before_agent_start\.systemPromptOptions\.skills\): 2 skill\(s\)/,
653
- );
694
+ test("disk regeneration retains loose skill paths and byte-identical refreshes", async (t) => {
695
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-regen-disk-"));
696
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
697
+ const skill = join(cwd, "skills", "loose-one", "SKILL.md");
698
+ mkdirSync(dirname(skill), { recursive: true });
699
+ writeFileSync(skill, "---\nname: loose-one\ndescription: Loose skill.\n---\n");
700
+ const first = await __testing.regenerateRegistry(cwd, false);
701
+ assert.equal(first.regenerated, true);
702
+ assert.equal(first.skillCount, 1);
703
+ const path = join(cwd, ".atl", "skill-registry.md");
704
+ assert.ok(readFileSync(path, "utf8").includes(skill));
705
+ const before = statSync(path).mtimeMs;
706
+ assert.equal((await __testing.regenerateRegistry(cwd, false)).reason, "cache-hit");
707
+ assert.equal(statSync(path).mtimeMs, before);
654
708
  });
655
709
 
656
710
  test("regenerateRegistry carries a skill resolved from a non-default PI_CODING_AGENT_DIR", async () => {
@@ -675,22 +729,20 @@ test("regenerateRegistry carries a skill resolved from a non-default PI_CODING_A
675
729
  ];
676
730
 
677
731
  const previousHome = process.env.HOME;
732
+ const previousProfile = process.env.USERPROFILE;
678
733
  const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
679
734
  process.env.HOME = isolatedHome;
735
+ process.env.USERPROFILE = isolatedHome;
680
736
  process.env.PI_CODING_AGENT_DIR = agentDir;
681
737
  try {
682
- const result = await __testing.regenerateRegistry(cwd, false, resolved);
683
- assert.equal(result.regenerated, true, "agent-dir resolved skill must trigger regeneration");
738
+ const { pi, handlers } = fakeSkillRegistryPi();
739
+ skillRegistry(pi);
740
+ const options = { skills: resolved, appendSystemPrompt: "" };
741
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, { cwd, hasUI: false });
742
+ assert.ok(!options.appendSystemPrompt.includes(skillPath), "Pi lists the custom agent-dir skill itself");
743
+ await __testing.regenerateRegistry(cwd, false);
684
744
  const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
685
- assert.match(
686
- registry,
687
- new RegExp(escapeRegExp(skillPath)),
688
- "the agent-dir skill reaches the registry through the runtime mirror",
689
- );
690
- assert.match(
691
- registry,
692
- /Pi-resolved runtime authority \(before_agent_start\.systemPromptOptions\.skills\): 1 skill\(s\)/,
693
- );
745
+ assert.ok(!registry.includes(skillPath), "runtime-only paths are not stored on disk");
694
746
 
695
747
  // Counter-proof: with no resolved set, the isolated agent dir is
696
748
  // unreachable — no loose root scans it. If the skill still appeared, a
@@ -699,7 +751,7 @@ test("regenerateRegistry carries a skill resolved from a non-default PI_CODING_A
699
751
  const decoyPath = join(bareCwd, "skills", "decoy", "SKILL.md");
700
752
  mkdirSync(dirname(decoyPath), { recursive: true });
701
753
  writeFileSync(decoyPath, "---\nname: decoy\ndescription: Trigger: decoy.\n---\n");
702
- await __testing.regenerateRegistry(bareCwd, false, []);
754
+ await __testing.regenerateRegistry(bareCwd, false);
703
755
  const bareRegistry = readFileSync(join(bareCwd, ".atl", "skill-registry.md"), "utf8");
704
756
  assert.match(
705
757
  bareRegistry,
@@ -717,6 +769,7 @@ test("regenerateRegistry carries a skill resolved from a non-default PI_CODING_A
717
769
  } else {
718
770
  process.env.HOME = previousHome;
719
771
  }
772
+ if (previousProfile === undefined) delete process.env.USERPROFILE; else process.env.USERPROFILE = previousProfile;
720
773
  if (previousAgentDir === undefined) {
721
774
  delete process.env.PI_CODING_AGENT_DIR;
722
775
  } else {
@@ -741,42 +794,23 @@ test("regenerateRegistry never re-indexes a filtered Pi skill from a loose root"
741
794
  writeFileSync(path, `---\nname: ${name}\ndescription: ${description}\n---\n`);
742
795
  }
743
796
 
744
- const result = await __testing.regenerateRegistry(cwd, true, [
745
- {
746
- name: "runtime-hidden",
747
- description: "Hidden by runtime disablement.",
748
- filePath: disabledPath,
749
- disableModelInvocation: true,
750
- },
751
- ] satisfies ResolvedSkill[], true);
752
-
753
- assert.equal(result.regenerated, true);
797
+ const { pi, handlers } = fakeSkillRegistryPi();
798
+ skillRegistry(pi);
799
+ const options = { skills: [{ name: "runtime-hidden", description: "Hidden by runtime disablement.", filePath: disabledPath, disableModelInvocation: true }], appendSystemPrompt: "" };
800
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, { cwd, hasUI: false });
801
+ assert.ok(options.appendSystemPrompt.includes(livePath));
802
+ assert.ok(!options.appendSystemPrompt.includes(disabledPath), "disabled paths are suppressed from the session view");
803
+ assert.equal((await __testing.regenerateRegistry(cwd, true, true)).regenerated, true);
754
804
  const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
755
- assert.match(registry, new RegExp(escapeRegExp(livePath)), "the loose scan still indexes live skills");
756
- assert.doesNotMatch(
757
- registry,
758
- new RegExp(escapeRegExp(disabledPath)),
759
- "a skill Pi resolved and filtered must never come back through the loose scan",
760
- );
761
- assert.doesNotMatch(registry, /Hidden by runtime disablement/);
805
+ assert.ok(registry.includes(livePath) && registry.includes(disabledPath), "disk indexing is independent of session disablement");
762
806
  });
763
807
 
764
- test("renderRegistry emits the pi-resolved authority bullet only when resolved entries exist", () => {
765
- const cwd = join(tmpdir(), `gentle-pi-render-resolved-${Date.now()}`);
808
+ test("renderRegistry describes disk-only authority rather than runtime counts", () => {
809
+ const cwd = join(tmpdir(), "gentle-pi-render-disk");
766
810
  const entry = { name: "docs", path: join(cwd, "skills", "docs", "SKILL.md"), description: "Docs." };
767
-
768
- const withResolved = __testing.renderRegistry(cwd, ["skills"], [entry], 1);
769
- const sourcesIndex = withResolved.indexOf("## Sources scanned");
770
- const bulletText = "- Pi-resolved runtime authority (before_agent_start.systemPromptOptions.skills): 1 skill(s)";
771
- const bulletIndex = withResolved.indexOf(bulletText);
772
- assert.ok(bulletIndex > sourcesIndex, "authority bullet must live in the sources section");
773
- assert.ok(
774
- withResolved.indexOf("- skills") > bulletIndex,
775
- "authority bullet must be the first source bullet",
776
- );
777
-
778
- const withoutResolved = __testing.renderRegistry(cwd, ["skills"], [entry], 0);
779
- assert.doesNotMatch(withoutResolved, /Pi-resolved runtime authority/);
811
+ const rendered = __testing.renderRegistry(cwd, ["skills"], [entry]);
812
+ assert.match(rendered, /excludes session-only runtime skills/);
813
+ assert.doesNotMatch(rendered, /Pi-resolved runtime authority/);
780
814
  });
781
815
 
782
816
  function fakeSkillRegistryPi(getFlag: (name: string) => boolean = () => false) {
@@ -795,170 +829,94 @@ function fakeSkillRegistryPi(getFlag: (name: string) => boolean = () => false) {
795
829
  return { pi, handlers, commands };
796
830
  }
797
831
 
798
- test("applyResolvedSkillsUpdate writes the registry from pi-resolved skills", async () => {
799
- const cwd = join(tmpdir(), `gentle-pi-apply-${Date.now()}`);
800
- const skillPath = join(tmpdir(), `gentle-pi-apply-pkg-${Date.now()}`, "skills", "applied", "SKILL.md");
801
-
802
- const result = await __testing.applyResolvedSkillsUpdate(cwd, [
803
- {
804
- name: "applied",
805
- description: "Trigger: applied skill. Runtime capture.",
806
- filePath: skillPath,
807
- sourceInfo: { scope: "project", origin: "package" },
808
- },
809
- ] satisfies ResolvedSkill[]);
810
-
811
- assert.equal(result.regenerated, true, "first applied update must write the registry");
812
- const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
813
- assert.match(registry, new RegExp(escapeRegExp(skillPath)));
814
- assert.match(registry, /project · package/);
815
- assert.match(
816
- registry,
817
- /Pi-resolved runtime authority \(before_agent_start\.systemPromptOptions\.skills\): 1 skill\(s\)/,
818
- );
832
+ test("registered event leaves Pi-listed project package skills out without publishing runtime rows", async (t) => {
833
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-apply-"));
834
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
835
+ isolatedHome(t);
836
+ const skillPath = join(cwd, "custom", "applied", "SKILL.md");
837
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
838
+ const options = { skills: [{ name: "applied", description: "Trigger: applied skill.", filePath: skillPath, sourceInfo: { scope: "project", origin: "package" } }], appendSystemPrompt: "" };
839
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, { cwd, hasUI: false });
840
+ assert.equal(options.appendSystemPrompt, "");
841
+ assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
819
842
  });
820
843
 
821
- test("resolved set spans global packages, project-local packages, and custom paths", async () => {
822
- // Issue #369 acceptance: global and project-local npm packages plus custom
823
- // package-declared paths must all be represented by their exact SKILL.md path.
824
- const cwd = join(tmpdir(), `gentle-pi-apply-matrix-${Date.now()}`);
825
- const globalPkgPath = join("/", "usr", "lib", "node_modules", "@scope", "pkg-a", "skills", "global-pkg-skill", "SKILL.md");
826
- const projectPkgPath = join(cwd, "node_modules", "pkg-b", "skills", "project-pkg-skill", "SKILL.md");
827
- const customPath = join(cwd, "custom-declared", "skills", "custom-path-skill", "SKILL.md");
828
-
829
- const result = await __testing.applyResolvedSkillsUpdate(cwd, [
830
- {
831
- name: "global-pkg-skill",
832
- description: "Trigger: global npm package skill.",
833
- filePath: globalPkgPath,
834
- sourceInfo: { scope: "user", origin: "package" },
835
- },
836
- {
837
- name: "project-pkg-skill",
838
- description: "Trigger: project-local npm package skill.",
839
- filePath: projectPkgPath,
840
- sourceInfo: { scope: "project", origin: "package" },
841
- },
842
- {
843
- name: "custom-path-skill",
844
- description: "Trigger: custom package-declared path skill.",
845
- filePath: customPath,
846
- sourceInfo: { scope: "project", origin: "top-level" },
847
- },
848
- ] satisfies ResolvedSkill[]);
849
-
850
- assert.equal(result.regenerated, true);
851
- // The loose scan merges this host's real user skill dirs, so the count is a
852
- // lower bound; the exact-path assertions below carry the acceptance weight.
853
- assert.ok(result.skillCount >= 3, `expected >= 3 skills, got ${result.skillCount}`);
854
- const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
855
- for (const path of [globalPkgPath, projectPkgPath, customPath]) {
856
- assert.match(registry, new RegExp(escapeRegExp(path)));
857
- }
858
- assert.match(registry, /user · package/);
859
- assert.match(registry, /project · package/);
860
- assert.match(
861
- registry,
862
- /Pi-resolved runtime authority \(before_agent_start\.systemPromptOptions\.skills\): 3 skill\(s\)/,
863
- );
844
+ test("Pi-listed global packages, project-local packages, and custom paths emit no rows", async (t) => {
845
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-apply-matrix-"));
846
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
847
+ isolatedHome(t);
848
+ const globalPkgPath = join(cwd, "global", "node_modules", "pkg-a", "SKILL.md");
849
+ const projectPkgPath = join(cwd, "node_modules", "pkg-b", "SKILL.md");
850
+ const customPath = join(cwd, "custom-declared", "SKILL.md");
851
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
852
+ const options = { skills: [
853
+ { name: "global-pkg", description: "Global", filePath: globalPkgPath, sourceInfo: { scope: "user", origin: "package" } },
854
+ { name: "project-pkg", description: "Project", filePath: projectPkgPath, sourceInfo: { scope: "project", origin: "package" } },
855
+ { name: "custom", description: "Custom", filePath: customPath, sourceInfo: { scope: "project", origin: "top-level" } },
856
+ ], appendSystemPrompt: "" };
857
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, { cwd, hasUI: false });
858
+ assert.equal(options.appendSystemPrompt, "");
864
859
  });
865
860
 
866
- test("applyResolvedSkillsUpdate is idempotent for an unchanged resolved set", async () => {
867
- const cwd = join(tmpdir(), `gentle-pi-apply-idempotent-${Date.now()}`);
868
- const resolved: ResolvedSkill[] = [
869
- {
870
- name: "idempotent",
871
- description: "Trigger: idempotent skill.",
872
- filePath: "/pkg/skills/idempotent/SKILL.md",
873
- sourceInfo: { scope: "user", origin: "package" },
874
- },
875
- ];
876
-
877
- await __testing.applyResolvedSkillsUpdate(cwd, resolved);
878
- const registryPath = join(cwd, ".atl", "skill-registry.md");
879
- const before = statSync(registryPath);
880
- await new Promise((resolve) => setTimeout(resolve, 25));
881
-
882
- const second = await __testing.applyResolvedSkillsUpdate(cwd, resolved);
883
- assert.equal(second.regenerated, false, "identical resolved set must be a cache hit");
884
- assert.equal(second.reason, "cache-hit");
885
- assert.equal(
886
- statSync(registryPath).mtimeMs,
887
- before.mtimeMs,
888
- "cache hit must not rewrite the registry file",
889
- );
861
+ test("repeated registered runtime captures do not duplicate the effective prompt", async (t) => {
862
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-apply-idempotent-"));
863
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
864
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
865
+ const options = { skills: [{ name: "idempotent", description: "Trigger: idempotent skill.", filePath: "/pkg/skills/idempotent/SKILL.md" }], appendSystemPrompt: "existing" };
866
+ const event = handlers.get("before_agent_start")![0];
867
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
868
+ const before = options.appendSystemPrompt;
869
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
870
+ assert.equal(options.appendSystemPrompt, before);
890
871
  });
891
872
 
892
- test("applyResolvedSkillsUpdate regenerates when the resolved set changes", async () => {
893
- const cwd = join(tmpdir(), `gentle-pi-apply-change-${Date.now()}`);
894
- const firstPath = "/pkg/skills/change-one/SKILL.md";
895
- await __testing.applyResolvedSkillsUpdate(cwd, [
896
- { name: "change-one", description: "First.", filePath: firstPath } satisfies ResolvedSkill,
897
- ]);
898
-
899
- const secondPath = "/pkg/skills/change-two/SKILL.md";
900
- const changed = await __testing.applyResolvedSkillsUpdate(cwd, [
901
- { name: "change-one", description: "First.", filePath: firstPath } satisfies ResolvedSkill,
902
- { name: "change-two", description: "Second.", filePath: secondPath } satisfies ResolvedSkill,
903
- ]);
904
-
905
- assert.equal(changed.regenerated, true, "changed resolved set must regenerate");
906
- assert.equal(changed.reason, "fingerprint-changed");
907
- const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
908
- assert.match(registry, new RegExp(escapeRegExp(secondPath)));
873
+ test("registered event replaces the effective view when runtime skills change", async (t) => {
874
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-apply-change-"));
875
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
876
+ isolatedHome(t);
877
+ const disk = (name: string) => {
878
+ const file = join(cwd, "skills", name, "SKILL.md");
879
+ mkdirSync(dirname(file), { recursive: true });
880
+ writeFileSync(file, `---\nname: ${name}\ndescription: ${name}.\n---\n`);
881
+ return file;
882
+ };
883
+ const first = disk("first"), second = disk("second");
884
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
885
+ const options = { skills: [{ name: "first", description: "First", filePath: first }], appendSystemPrompt: "" };
886
+ const event = handlers.get("before_agent_start")![0];
887
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
888
+ assert.ok(!options.appendSystemPrompt.includes(first) && options.appendSystemPrompt.includes(second));
889
+ options.skills = [{ name: "second", description: "Second", filePath: second }];
890
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
891
+ assert.ok(options.appendSystemPrompt.includes(first) && !options.appendSystemPrompt.includes(second));
909
892
  });
910
893
 
911
- test("resolved fingerprint tracks normalized descriptions, effective disabled state, and runtime order", async () => {
912
- const cwd = join(tmpdir(), `gentle-pi-resolved-fingerprint-${Date.now()}`);
913
- const alphaPath = "/pkg/skills/fingerprint-alpha/SKILL.md";
914
- const betaPath = "/pkg/skills/fingerprint-beta/SKILL.md";
894
+ test("Pi-listed runtime duplicates emit no rows whatever their disabled state or order", async (t) => {
895
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-resolved-order-"));
896
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
897
+ const shadow = userShadow(isolatedHome(t), "duplicate");
898
+ const alpha = "/pkg/alpha/SKILL.md", beta = "/pkg/beta/SKILL.md";
915
899
  const first: ResolvedSkill[] = [
916
- { name: "duplicate", description: "Trigger: first entry.", filePath: alphaPath },
917
- { name: "duplicate", description: "Trigger: second entry.", filePath: betaPath },
900
+ { name: "duplicate", description: " Trigger: first entry. ", filePath: alpha },
901
+ { name: "duplicate", description: "Trigger: second entry.", filePath: beta },
918
902
  ];
919
-
920
- assert.equal((await __testing.regenerateRegistry(cwd, false, first)).regenerated, true);
921
- assert.equal(
922
- (await __testing.regenerateRegistry(cwd, false, [
923
- { ...first[0], description: " Trigger: first entry. " },
924
- first[1],
925
- ])).regenerated,
926
- false,
927
- "whitespace-only description changes must remain cache-equivalent",
928
- );
929
- assert.equal(
930
- (await __testing.regenerateRegistry(cwd, false, [
931
- { ...first[0], description: "Trigger: updated first entry." },
932
- first[1],
933
- ])).regenerated,
934
- true,
935
- "normalized description changes must invalidate the cache",
936
- );
937
- assert.equal(
938
- (await __testing.regenerateRegistry(cwd, false, [
939
- { ...first[0], description: "Trigger: updated first entry.", disableModelInvocation: true },
940
- first[1],
941
- ])).regenerated,
942
- true,
943
- "effective disabled-state changes must invalidate the cache",
944
- );
945
-
946
- const orderCwd = join(tmpdir(), `gentle-pi-resolved-order-${Date.now()}`);
947
- assert.equal((await __testing.regenerateRegistry(orderCwd, false, first)).regenerated, true);
948
- const reordered = [first[1], first[0]];
949
- assert.equal(
950
- (await __testing.regenerateRegistry(orderCwd, false, reordered)).regenerated,
951
- true,
952
- "runtime order changes must invalidate the cache",
953
- );
954
- const registry = readFileSync(join(orderCwd, ".atl", "skill-registry.md"), "utf8");
955
- assert.match(registry, new RegExp(escapeRegExp(betaPath)));
956
- assert.doesNotMatch(registry, new RegExp(escapeRegExp(alphaPath)));
903
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
904
+ const options = { skills: first, appendSystemPrompt: "" };
905
+ const event = handlers.get("before_agent_start")![0];
906
+ for (const skills of [first, [{ ...first[0], disableModelInvocation: true }, first[1]], [first[1], first[0]]]) {
907
+ options.skills = skills;
908
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
909
+ assert.equal(options.appendSystemPrompt, "", "the Pi-listed winner outranks the user-root copy");
910
+ }
911
+ options.skills = first.map((skill) => ({ ...skill, disableModelInvocation: true }));
912
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
913
+ assert.ok(options.appendSystemPrompt.includes(shadow), "with every Pi record disabled the disk copy is the winner");
957
914
  });
958
915
 
959
- test("before_agent_start rejects malformed batches and preserves prior resolved skills", async () => {
916
+ test("before_agent_start rejects malformed batches and preserves prior resolved skills", async (t) => {
960
917
  const cwd = join(tmpdir(), `gentle-pi-wire-malformed-batch-${Date.now()}`);
961
918
  const skillPath = "/pkg/skills/valid-before-malformed/SKILL.md";
919
+ const shadow = userShadow(isolatedHome(t), "valid");
962
920
  const { pi, handlers, commands } = fakeSkillRegistryPi();
963
921
  skillRegistryExtension(pi);
964
922
  const handler = handlers.get("before_agent_start")?.[0];
@@ -966,10 +924,9 @@ test("before_agent_start rejects malformed batches and preserves prior resolved
966
924
  assert.ok(handler);
967
925
  assert.ok(refresh);
968
926
 
969
- await handler(
970
- { systemPromptOptions: { skills: [{ name: "valid", description: "Valid runtime skill.", filePath: skillPath }] } },
971
- { cwd, hasUI: false },
972
- );
927
+ const options: { skills: unknown; appendSystemPrompt: string } = { skills: [{ name: "valid", description: "Valid runtime skill.", filePath: skillPath }], appendSystemPrompt: "" };
928
+ await handler({ systemPromptOptions: options }, { cwd, hasUI: false });
929
+ await refresh.handler("", { cwd, hasUI: false, ui: { notify() {} } });
973
930
  for (const skills of [
974
931
  [
975
932
  { name: "replacement-scope", description: "Must not partially apply.", filePath: "/pkg/skills/replacement-scope/SKILL.md" },
@@ -990,26 +947,30 @@ test("before_agent_start rejects malformed batches and preserves prior resolved
990
947
  },
991
948
  ],
992
949
  ]) {
993
- writeFileSync(join(cwd, ".atl", "skill-registry.md"), "sentinel\n");
994
- await handler({ systemPromptOptions: { skills } }, { cwd, hasUI: false });
950
+ options.skills = skills;
951
+ await handler({ systemPromptOptions: options }, { cwd, hasUI: false });
952
+ assert.ok(!options.appendSystemPrompt.includes(shadow), "the retained capture still outranks its user-root copy");
953
+ assert.ok(!options.appendSystemPrompt.includes(skillPath));
954
+ assert.ok(!options.appendSystemPrompt.includes(skills[0].filePath));
955
+ assert.ok((await promptWithoutReaders(handler, cwd)).includes(skillPath), "the capture is retained");
995
956
  await refresh.handler("", { cwd, hasUI: false, ui: { notify() {} } });
996
-
997
957
  const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
998
- assert.match(registry, new RegExp(escapeRegExp(skillPath)));
999
- assert.doesNotMatch(registry, new RegExp(escapeRegExp(skills[0].filePath)));
1000
- assert.doesNotMatch(registry, /sentinel/);
958
+ assert.ok(!registry.includes(skillPath));
959
+ assert.ok(!registry.includes(skills[0].filePath));
1001
960
  }
1002
961
  });
1003
962
 
1004
- test("watcher refresh retains captured runtime-resolved skills", { timeout: 5_000 }, async () => {
963
+ test("watcher refresh retains captured runtime-resolved skills", { timeout: 5_000 }, async (t) => {
1005
964
  const cwd = join(tmpdir(), `gentle-pi-watch-resolved-${Date.now()}`);
965
+ const shadow = userShadow(isolatedHome(t), "retained");
1006
966
  const looseSkillPath = join(cwd, "skills", "loose", "SKILL.md");
1007
967
  const resolvedPath = "/pkg/skills/watcher-retained/SKILL.md";
1008
968
  mkdirSync(dirname(looseSkillPath), { recursive: true });
1009
969
  writeFileSync(looseSkillPath, "---\nname: loose\ndescription: Before watcher refresh.\n---\n");
1010
- await __testing.applyResolvedSkillsUpdate(cwd, [
1011
- { name: "retained", description: "Runtime authority.", filePath: resolvedPath },
1012
- ]);
970
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
971
+ const options: { skills?: unknown; appendSystemPrompt: string } = { skills: [{ name: "retained", description: "Runtime authority.", filePath: resolvedPath }], appendSystemPrompt: "" };
972
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, { cwd, hasUI: false });
973
+ await __testing.regenerateRegistry(cwd, false);
1013
974
 
1014
975
  let resolveRefresh: (() => void) | undefined;
1015
976
  let timeout: ReturnType<typeof setTimeout> | undefined;
@@ -1031,13 +992,19 @@ test("watcher refresh retains captured runtime-resolved skills", { timeout: 5_00
1031
992
  }
1032
993
 
1033
994
  const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1034
- assert.match(registry, new RegExp(escapeRegExp(resolvedPath)));
995
+ assert.doesNotMatch(registry, new RegExp(escapeRegExp(resolvedPath)));
996
+ options.skills = undefined;
997
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, { cwd, hasUI: false });
998
+ assert.ok(!options.appendSystemPrompt.includes(resolvedPath) && !options.appendSystemPrompt.includes(shadow), "the retained capture still outranks its user-root copy");
999
+ assert.match(options.appendSystemPrompt, /After watcher refresh/);
1000
+ assert.ok((await promptWithoutReaders(handlers.get("before_agent_start")![0], cwd)).includes(resolvedPath), "the capture is retained");
1035
1001
  });
1036
1002
 
1037
- test("before_agent_start handler wires pi-resolved skills into the registry", async () => {
1003
+ test("before_agent_start handler wires pi-resolved skills into the registry", async (t) => {
1038
1004
  // Happy path: the handler captures runtime-resolved skills for the session cwd.
1039
1005
  {
1040
1006
  const cwd = join(tmpdir(), `gentle-pi-wire-${Date.now()}`);
1007
+ const shadow = userShadow(isolatedHome(t), "wired-skill");
1041
1008
  const { pi, handlers } = fakeSkillRegistryPi();
1042
1009
  skillRegistryExtension(pi);
1043
1010
  const handler = handlers.get("before_agent_start")?.[0];
@@ -1050,24 +1017,11 @@ test("before_agent_start handler wires pi-resolved skills into the registry", as
1050
1017
  "wired-skill",
1051
1018
  "SKILL.md",
1052
1019
  );
1053
- await handler(
1054
- {
1055
- systemPromptOptions: {
1056
- skills: [
1057
- {
1058
- name: "wired-skill",
1059
- description: "Trigger: wired skill. Runtime capture.",
1060
- filePath: skillPath,
1061
- sourceInfo: { scope: "project", origin: "package" },
1062
- },
1063
- ],
1064
- },
1065
- },
1066
- { cwd, hasUI: false },
1067
- );
1068
-
1069
- const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1070
- assert.match(registry, new RegExp(escapeRegExp(skillPath)));
1020
+ const options = { skills: [{ name: "wired-skill", description: "Trigger: wired skill. Runtime capture.", filePath: skillPath, sourceInfo: { scope: "project", origin: "package" } }], appendSystemPrompt: "" };
1021
+ await handler({ systemPromptOptions: options }, { cwd, hasUI: false });
1022
+ assert.equal(options.appendSystemPrompt, "", `the capture outranks ${shadow} and Pi lists ${skillPath}`);
1023
+ assert.ok((await promptWithoutReaders(handler, cwd)).includes(skillPath), "the capture is wired");
1024
+ assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
1071
1025
  }
1072
1026
 
1073
1027
  // The no-skill-registry opt-out must leave the registry untouched.
@@ -1122,6 +1076,7 @@ test("startup regeneration keeps the resolved set captured before it settles", a
1122
1076
  mkdirSync(dirname(loosePath), { recursive: true });
1123
1077
  writeFileSync(loosePath, "---\nname: loose\ndescription: Loose project skill.\n---\n");
1124
1078
  const resolvedPath = join(packageRoot, "skills", "runtime-authority", "SKILL.md");
1079
+ const shadow = userShadow(isolatedHome(t), "runtime-authority");
1125
1080
 
1126
1081
  const { pi, handlers } = fakeSkillRegistryPi();
1127
1082
  skillRegistryExtension(pi);
@@ -1150,16 +1105,19 @@ test("startup regeneration keeps the resolved set captured before it settles", a
1150
1105
  await __testing.startupSettled();
1151
1106
 
1152
1107
  const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1153
- assert.match(registry, new RegExp(escapeRegExp(resolvedPath)), "startup regeneration must not drop captured runtime authority");
1108
+ assert.doesNotMatch(registry, new RegExp(escapeRegExp(resolvedPath)));
1154
1109
  assert.match(registry, new RegExp(escapeRegExp(loosePath)));
1155
- assert.match(
1156
- registry,
1157
- /Pi-resolved runtime authority \(before_agent_start\.systemPromptOptions\.skills\): 1 skill\(s\)/,
1158
- );
1110
+ const options = { appendSystemPrompt: "" };
1111
+ await capture({ systemPromptOptions: options }, ctx);
1112
+ assert.ok(!options.appendSystemPrompt.includes(shadow), "startup must not drop the session capture");
1113
+ assert.ok((await promptWithoutReaders(capture, cwd)).includes(resolvedPath), "the capture is retained");
1114
+ assert.ok(!options.appendSystemPrompt.includes(resolvedPath));
1115
+ assert.ok(options.appendSystemPrompt.includes(loosePath));
1159
1116
  });
1160
1117
 
1161
- test("manual /skill-registry:refresh keeps the captured resolved set", async () => {
1118
+ test("manual /skill-registry:refresh keeps the captured resolved set", async (t) => {
1162
1119
  const cwd = join(tmpdir(), `gentle-pi-refresh-${Date.now()}`);
1120
+ const shadow = userShadow(isolatedHome(t), "refreshed");
1163
1121
  const skillPath = join(tmpdir(), `gentle-pi-refresh-pkg-${Date.now()}`, "skills", "refreshed", "SKILL.md");
1164
1122
  const { pi, handlers, commands } = fakeSkillRegistryPi();
1165
1123
  skillRegistryExtension(pi);
@@ -1183,17 +1141,17 @@ test("manual /skill-registry:refresh keeps the captured resolved set", async ()
1183
1141
  },
1184
1142
  { cwd, hasUI: false },
1185
1143
  );
1186
- assert.ok(existsSync(join(cwd, ".atl", "skill-registry.md")));
1144
+ assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
1187
1145
 
1188
- // A forced manual refresh must not drop the runtime-resolved authority.
1146
+ // A forced manual refresh writes disk only without dropping the session capture.
1189
1147
  const notices: string[] = [];
1190
1148
  await refresh.handler("", { cwd, hasUI: true, ui: { notify: (text: string) => notices.push(text) } });
1191
1149
  const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1192
- assert.match(
1193
- registry,
1194
- new RegExp(escapeRegExp(skillPath)),
1195
- "forced refresh must retain pi-resolved skills",
1196
- );
1150
+ assert.doesNotMatch(registry, new RegExp(escapeRegExp(skillPath)));
1151
+ const options = { appendSystemPrompt: "" };
1152
+ await handler({ systemPromptOptions: options }, { cwd, hasUI: false });
1153
+ assert.equal(options.appendSystemPrompt, "", `the capture outranks ${shadow} and Pi lists ${skillPath}`);
1154
+ assert.ok((await promptWithoutReaders(handler, cwd)).includes(skillPath), "the capture is retained");
1197
1155
  assert.ok(notices.length > 0);
1198
1156
  });
1199
1157
 
@@ -1248,6 +1206,8 @@ const fixtureHome = mkdtempSync(join(tmpdir(), "gentle-pi-registry-home-"));
1248
1206
  const originalHome = process.env.HOME;
1249
1207
  const originalUserProfile = process.env.USERPROFILE;
1250
1208
  const originalGitCeiling = process.env.GIT_CEILING_DIRECTORIES;
1209
+ const originalCodexHome = process.env.CODEX_HOME;
1210
+ delete process.env.CODEX_HOME;
1251
1211
  process.env.GIT_CEILING_DIRECTORIES = tmpdir();
1252
1212
  process.env.HOME = fixtureHome;
1253
1213
  process.env.USERPROFILE = fixtureHome;
@@ -1258,6 +1218,9 @@ test.after(() => {
1258
1218
  else process.env.USERPROFILE = originalUserProfile;
1259
1219
  if (originalGitCeiling === undefined) delete process.env.GIT_CEILING_DIRECTORIES;
1260
1220
  else process.env.GIT_CEILING_DIRECTORIES = originalGitCeiling;
1221
+ if (originalCodexHome === undefined) delete process.env.CODEX_HOME;
1222
+ else process.env.CODEX_HOME = originalCodexHome;
1223
+ rmSync(fixtureHome, { recursive: true, force: true });
1261
1224
  });
1262
1225
 
1263
1226
  function registeredRegistry(cwd: string, suppressed = false) {
@@ -1307,7 +1270,7 @@ for (const target of ["registry", "ignore"] as const) {
1307
1270
  if (target === "registry") assert.ok(!runtime.notices.some(({ message }) => message.includes("refreshed")));
1308
1271
  await runtime.refresh();
1309
1272
  assert.notEqual(readFileSync(fixture[target], "utf8"), before);
1310
- assert.ok(runtime.notices.some(({ message }) => message.includes("written to .atl/skill-registry.md")));
1273
+ assert.ok(runtime.notices.some(({ message }) => message.includes(target === "registry" ? "written to .atl/skill-registry.md" : "unchanged in .atl/skill-registry.md")));
1311
1274
  });
1312
1275
  }
1313
1276
 
@@ -1348,8 +1311,10 @@ for (const git of [true, false]) {
1348
1311
  });
1349
1312
  }
1350
1313
 
1351
- test("automatic forced freshness protects tracked cache without partial registry writes", async () => {
1314
+ test("automatic forced freshness and registered startup protect tracked cache without partial writes", async (t) => {
1352
1315
  const fixture = registryFixture();
1316
+ const runtime = registeredRegistry(fixture.cwd);
1317
+ t.after(async () => { await runtime.stop(); rmSync(fixture.root, { recursive: true, force: true }); });
1353
1318
  await __testing.regenerateRegistry(fixture.cwd, false);
1354
1319
  const cache = join(fixture.cwd, ".atl", ".skill-registry.cache.json");
1355
1320
  execSync("git add -f .atl/.skill-registry.cache.json", { cwd: fixture.root, stdio: "ignore" });
@@ -1361,6 +1326,13 @@ test("automatic forced freshness protects tracked cache without partial registry
1361
1326
  assert.match(result.warning ?? "", /\.atl\/\.skill-registry\.cache\.json/);
1362
1327
  assert.equal(readFileSync(cache, "utf8"), beforeCache);
1363
1328
  assert.equal(readFileSync(fixture.registry, "utf8"), beforeRegistry);
1329
+ await runtime.start();
1330
+ assert.equal(readFileSync(cache, "utf8"), beforeCache);
1331
+ assert.equal(readFileSync(fixture.registry, "utf8"), beforeRegistry);
1332
+ assert.ok(runtime.notices.some(({ message, level }) => level === "warning" && message.includes(".atl/.skill-registry.cache.json") && message.includes("/skill-registry:refresh")));
1333
+ await runtime.refresh();
1334
+ assert.match(readFileSync(fixture.registry, "utf8"), /Changed skill/);
1335
+ assert.notEqual(readFileSync(cache, "utf8"), beforeCache);
1364
1336
  });
1365
1337
 
1366
1338
  test("registered Git detection failure skips automatic writes and reports deliberate refresh", async (t) => {
@@ -1582,7 +1554,7 @@ test("regenerateRegistry reports a typed unavailable result instead of throwing
1582
1554
  rmSync(join(cwd, ".atl", "skill-registry.md"), { force: true });
1583
1555
  rmSync(join(cwd, ".atl", ".skill-registry.cache.json"), { force: true });
1584
1556
  chmodSync(join(cwd, ".atl"), 0o555);
1585
- const result = await __testing.regenerateRegistry(cwd, true, [], true);
1557
+ const result = await __testing.regenerateRegistry(cwd, true, true);
1586
1558
  assert.equal(result.regenerated, false, "a permission failure must never report success");
1587
1559
  assert.equal(result.reason, "storage-unavailable");
1588
1560
  assert.match(result.warning ?? "", /\.atl[/\\]skill-registry\.md/);
@@ -1591,7 +1563,7 @@ test("regenerateRegistry reports a typed unavailable result instead of throwing
1591
1563
  assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
1592
1564
 
1593
1565
  chmodSync(join(cwd, ".atl"), 0o755);
1594
- const recovered = await __testing.regenerateRegistry(cwd, true, [], true);
1566
+ const recovered = await __testing.regenerateRegistry(cwd, true, true);
1595
1567
  assert.equal(recovered.regenerated, true, "the registry must regenerate once storage is writable again");
1596
1568
  });
1597
1569
 
@@ -1599,19 +1571,724 @@ test("regenerateRegistry degrades truthfully when .atl is a regular file", async
1599
1571
  const cwd = mkdtempSync(join(tmpdir(), "gentle-skill-373-enotdir-"));
1600
1572
  t.after(() => rmSync(cwd, { recursive: true, force: true }));
1601
1573
  writeFileSync(join(cwd, ".atl"), "not a directory\n");
1602
- const result = await __testing.regenerateRegistry(cwd, true, [], true);
1574
+ const result = await __testing.regenerateRegistry(cwd, true, true);
1603
1575
  assert.equal(result.regenerated, false, "a non-directory .atl must never report success");
1604
1576
  assert.equal(result.reason, "storage-unavailable");
1605
1577
  assert.match(result.warning ?? "", /not writable/);
1606
1578
  });
1607
1579
 
1580
+ test("S5 roots, Codex override, UTF-8 order and Unicode whitespace follow the shared discovery contract", async (t) => {
1581
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-shared-roots-"));
1582
+ const home = mkdtempSync(join(tmpdir(), "gentle-shared-home-"));
1583
+ const oldHome = process.env.HOME, oldProfile = process.env.USERPROFILE, oldCodex = process.env.CODEX_HOME;
1584
+ t.after(() => {
1585
+ if (oldHome === undefined) delete process.env.HOME; else process.env.HOME = oldHome;
1586
+ if (oldProfile === undefined) delete process.env.USERPROFILE; else process.env.USERPROFILE = oldProfile;
1587
+ if (oldCodex === undefined) delete process.env.CODEX_HOME; else process.env.CODEX_HOME = oldCodex;
1588
+ rmSync(cwd, { recursive: true, force: true }); rmSync(home, { recursive: true, force: true });
1589
+ });
1590
+ process.env.HOME = home; process.env.USERPROFILE = home;
1591
+ const codex = join(home, "codex-real"); mkdirSync(join(codex, "skills"), { recursive: true });
1592
+ process.env.CODEX_HOME = relative(process.cwd(), codex);
1593
+ const projectRoots = ["skills", ".opencode/skills", ".claude/skills", ".gemini/skills", ".trae/skills", ".cursor/skills", ".github/skills", ".codex/skills", ".qwen/skills", ".kiro/skills", ".openclaw/skills", ".pi/skills", ".agent/skills", ".agents/skills", ".atl/skills", ".hermes/skills"];
1594
+ assert.deepEqual(__testing.projectSkillDirs(cwd), projectRoots.map((root) => join(cwd, root)));
1595
+ const userRoots = [".pi/agent/skills", ".config/agents/skills", ".agents/skills", ".kimi-code/skills", ".kimi/skills", ".config/opencode/skills", ".config/kilo/skills", ".claude/skills", ".gemini/skills", ".gemini/config/skills", ".gemini/antigravity/skills", ".gemini/antigravity-desktop/skills", ".gemini/antigravity-cli/skills", ".cursor/skills", ".copilot/skills", "CODEX", ".codeium/windsurf/skills", ".qwen/skills", ".kiro/skills", ".openclaw/skills", ".hermes/skills", ".trae/skills"];
1596
+ assert.deepEqual(await __testing.userSkillDirs(), userRoots.map((root) => root === "CODEX" ? join(realpathSync(codex), "skills") : join(home, root)));
1597
+ const low = join(cwd, "skills", "one", "SKILL.md"), high = join(cwd, "skills", "two", "SKILL.md");
1598
+ mkdirSync(dirname(low), { recursive: true }); mkdirSync(dirname(high), { recursive: true });
1599
+ writeFileSync(low, "---\nname: \uE000\ndescription: alpha\u0085beta\n---\n");
1600
+ writeFileSync(high, "---\nname: \u{10000}\ndescription: gamma\uFEFFdelta\n---\n");
1601
+ const { pi, commands } = fakeSkillRegistryPi(); skillRegistry(pi);
1602
+ await commands.get("skill-registry:refresh")!.handler("", { cwd, hasUI: false, ui: { notify() {} } });
1603
+ const disk = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1604
+ assert.ok(disk.indexOf("`\uE000`") < disk.indexOf("`\u{10000}`"), "names sort by UTF-8 bytes");
1605
+ assert.ok(disk.includes("alpha beta"), "NEL is Unicode White_Space");
1606
+ assert.ok(disk.includes("gamma\uFEFFdelta"), "BOM is not Unicode White_Space");
1607
+ });
1608
+
1609
+ test("S5–S6 registered refresh publishes exact disk-only bytes and repairs the cache without rewriting equal bytes", async (t) => {
1610
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-shared-registry-"));
1611
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1612
+ const skill = join(cwd, "skills", "local", "SKILL.md");
1613
+ mkdirSync(dirname(skill), { recursive: true });
1614
+ writeFileSync(skill, '---\nname: local\ndescription: "Trigger: local | docs"\n---\n');
1615
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
1616
+ skillRegistry(pi);
1617
+ const refresh = commands.get("skill-registry:refresh")!;
1618
+ const notices: string[] = [];
1619
+ const ctx = { cwd, hasUI: true, ui: { notify: (message: string) => notices.push(message) } };
1620
+ await refresh.handler("", ctx); // A cold command has no runtime capture.
1621
+ const registryPath = join(cwd, ".atl", "skill-registry.md");
1622
+ const cachePath = join(cwd, ".atl", ".skill-registry.cache.json");
1623
+ const expected = [
1624
+ `# Skill Registry — ${cwd.split(/[\\/]/).at(-1)}`, "",
1625
+ "<!-- Shared disk skill registry; generated by Gentle Shell or Gentle AI. -->", "",
1626
+ "## Sources scanned", "", "- skills", "", "## Contract", "",
1627
+ "**Delegator use only.** This disk index is not a summary and excludes session-only runtime skills. Pi delegators use their effective session view; other delegators use these rows. Pass exact `SKILL.md` paths to subagents.", "",
1628
+ "`SKILL.md` remains the source of truth. Do not inject generated summaries or compact rules by default; pass paths so subagents load the full runtime contract and preserve author intent.", "",
1629
+ "## Skills", "", "| Skill | Trigger / description | Scope | Path |", "| --- | --- | --- | --- |",
1630
+ `| \`local\` | Trigger: local \\| docs | project | \`${skill}\` |`, "", "## Loading protocol", "",
1631
+ "1. Match task context and target files against the effective view's `Trigger / description` column.",
1632
+ "2. Pass only the matching `Path` values to the subagent under `## Skills to load before work`.",
1633
+ "3. Instruct the subagent to read those exact `SKILL.md` files before reading, writing, reviewing, testing, or creating artifacts.",
1634
+ "4. If no matching skill exists, proceed without project skill injection and report `skill_resolution: none`.", "",
1635
+ ].join("\n");
1636
+ assert.equal(readFileSync(registryPath, "utf8"), expected);
1637
+ const { createHash } = await import("node:crypto");
1638
+ const hash = createHash("sha256").update(expected).digest("hex");
1639
+ assert.equal(readFileSync(cachePath, "utf8"), `{"schema":1,"registry_sha256":"${hash}"}\n`);
1640
+ const before = statSync(registryPath).mtimeMs;
1641
+ writeFileSync(cachePath, '{"fingerprint":"legacy"}');
1642
+ await refresh.handler("", ctx);
1643
+ assert.equal(readFileSync(cachePath, "utf8"), `{"schema":1,"registry_sha256":"${hash}"}\n`);
1644
+ assert.equal(statSync(registryPath).mtimeMs, before, "forced equality must not rewrite registry");
1645
+ const options = { skills: [{ name: "runtime", description: "Runtime only", filePath: join(cwd, "custom", "SKILL.md") }], appendSystemPrompt: "existing" };
1646
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, ctx);
1647
+ assert.ok(options.appendSystemPrompt.includes(skill) && !options.appendSystemPrompt.includes("Runtime only"));
1648
+ assert.equal(readFileSync(registryPath, "utf8"), expected);
1649
+ assert.equal(statSync(registryPath).mtimeMs, before);
1650
+ assert.ok(notices.some((message) => message.includes(".atl/skill-registry.md")));
1651
+ await handlers.get("session_shutdown")![0](undefined, ctx);
1652
+ });
1653
+
1654
+ test("S7 registered prompt replaces runtime batches, suppresses disabled winners, and retains raw same-name alternatives", async (t) => {
1655
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-effective-registry-"));
1656
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1657
+ const winner = join(cwd, "skills", "winner", "SKILL.md");
1658
+ const alternate = join(cwd, ".claude", "skills", "alternate", "SKILL.md");
1659
+ for (const [path, description] of [[winner, "First disk candidate"], [alternate, "Alternate disk candidate"]]) {
1660
+ mkdirSync(dirname(path), { recursive: true });
1661
+ writeFileSync(path, `---\nname: duplicate\ndescription: ${description}\n---\n`);
1662
+ }
1663
+ // A disk copy of the runtime skill shows whether the runtime capture is current.
1664
+ const runtimeCopy = join(cwd, ".agents", "skills", "runtime-copy", "SKILL.md");
1665
+ mkdirSync(dirname(runtimeCopy), { recursive: true });
1666
+ writeFileSync(runtimeCopy, "---\nname: runtime\ndescription: Runtime disk copy\n---\n");
1667
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
1668
+ skillRegistry(pi);
1669
+ const event = handlers.get("before_agent_start")![0];
1670
+ const ctx = { cwd, hasUI: false, ui: { notify() {} } };
1671
+ await commands.get("skill-registry:refresh")!.handler("", ctx);
1672
+ const registry = join(cwd, ".atl", "skill-registry.md");
1673
+ const original = readFileSync(registry, "utf8");
1674
+ const runtime = join(cwd, "custom", "runtime", "SKILL.md");
1675
+ const options: { skills?: unknown; appendSystemPrompt: string } = { skills: [{ name: "runtime", description: "Package runtime", filePath: runtime, sourceInfo: { scope: "project", origin: "package" } }], appendSystemPrompt: "other extension" };
1676
+ await event({ systemPromptOptions: options }, ctx);
1677
+ assert.ok(!options.appendSystemPrompt.includes(runtime) && !options.appendSystemPrompt.includes(runtimeCopy), "Pi lists the runtime winner");
1678
+ assert.ok(options.appendSystemPrompt.includes(winner));
1679
+ assert.equal(readFileSync(registry, "utf8"), original);
1680
+ options.skills = [{ name: "broken", description: "invalid", filePath: 2 }];
1681
+ await event({ systemPromptOptions: options }, ctx);
1682
+ assert.ok(!options.appendSystemPrompt.includes(runtimeCopy), "malformed capture preserves the last valid batch");
1683
+ assert.ok(!options.appendSystemPrompt.includes("broken"));
1684
+ options.skills = [{ name: "duplicate", description: "Disabled", filePath: winner, disableModelInvocation: true }];
1685
+ await event({ systemPromptOptions: options }, ctx);
1686
+ assert.ok(!options.appendSystemPrompt.includes(runtime) && options.appendSystemPrompt.includes(runtimeCopy), "replacement removes the old runtime capture");
1687
+ assert.ok(!options.appendSystemPrompt.includes(winner), "disabled resolved path is suppressed");
1688
+ assert.ok(options.appendSystemPrompt.includes(alternate), "same-name alternate survives suppression");
1689
+ options.skills = [];
1690
+ await event({ systemPromptOptions: options }, ctx);
1691
+ assert.ok(options.appendSystemPrompt.includes(winner), "empty valid capture restores independently eligible disk paths");
1692
+ assert.ok(!options.appendSystemPrompt.includes(alternate));
1693
+ assert.ok(options.appendSystemPrompt.startsWith("other extension"));
1694
+ await handlers.get("session_shutdown")![0](undefined, ctx);
1695
+ });
1696
+
1697
+ test("S4–S7 disk edits update the next effective view while runtime remains session-local", async (t) => {
1698
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-effective-disk-"));
1699
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1700
+ isolatedHome(t);
1701
+ const skill = join(cwd, "skills", "disk", "SKILL.md");
1702
+ mkdirSync(dirname(skill), { recursive: true });
1703
+ const one = "---\nname: disk\ndescription: first\n---\n";
1704
+ const two = "---\nname: disk\ndescription: other\n---\n";
1705
+ writeFileSync(skill, one);
1706
+ utimesSync(skill, 1_000_000_000, 1_000_000_000);
1707
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
1708
+ skillRegistry(pi);
1709
+ const event = handlers.get("before_agent_start")![0];
1710
+ const ctx = { cwd, hasUI: false, ui: { notify() {} } };
1711
+ const runtime = join(cwd, "outside", "SKILL.md");
1712
+ const options: { skills?: unknown; appendSystemPrompt: string } = { skills: [{ name: "runtime", description: "Runtime retained", filePath: runtime }], appendSystemPrompt: "" };
1713
+ await commands.get("skill-registry:refresh")!.handler("", ctx);
1714
+ await event({ systemPromptOptions: options }, ctx);
1715
+ assert.match(options.appendSystemPrompt, /first/);
1716
+ writeFileSync(skill, two);
1717
+ utimesSync(skill, 1_000_000_000, 1_000_000_000);
1718
+ await commands.get("skill-registry:refresh")!.handler("", ctx);
1719
+ options.skills = undefined;
1720
+ await event({ systemPromptOptions: options }, ctx);
1721
+ assert.match(options.appendSystemPrompt, /other/);
1722
+ assert.doesNotMatch(options.appendSystemPrompt, /first/);
1723
+ assert.ok(!options.appendSystemPrompt.includes(runtime), "Pi lists the runtime skill");
1724
+ rmSync(skill);
1725
+ await commands.get("skill-registry:refresh")!.handler("", ctx);
1726
+ await event({ systemPromptOptions: options }, ctx);
1727
+ assert.ok(!options.appendSystemPrompt.includes(skill));
1728
+ assert.equal(options.appendSystemPrompt, "", "no on-disk-only rows remain");
1729
+ assert.ok(!readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8").includes(runtime));
1730
+ await handlers.get("session_shutdown")![0](undefined, ctx);
1731
+ });
1732
+
1733
+ for (const [label, excluded] of [
1734
+ ["direct sdd prefix", "sdd-hidden"],
1735
+ ["nested sdd prefix", "category/sdd-hidden"],
1736
+ ["direct shared name", "_shared"],
1737
+ ["nested shared name", "category/_shared"],
1738
+ ["direct registry name", "skill-registry"],
1739
+ ["nested registry name", "category/skill-registry"],
1740
+ ["excluded category", "sdd-category/child"],
1741
+ ] as const) {
1742
+ test(`S5 correction B1 excludes ${label} before reading its alias`, async (t) => {
1743
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-s5-excluded-"));
1744
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1745
+ const create = (path: string, name: string, description: string) => {
1746
+ const file = join(cwd, "skills", path, "SKILL.md");
1747
+ mkdirSync(dirname(file), { recursive: true });
1748
+ writeFileSync(file, `---\nname: ${name}\ndescription: ${description}\n---\n`);
1749
+ return file;
1750
+ };
1751
+ const hidden = create(excluded, "safe-alias", "Must stay excluded");
1752
+ const winner = create("disabled", "duplicate", "Disk winner");
1753
+ const alternate = create("z-alternate", "duplicate", "Eligible alternate");
1754
+ const visible = create("visible", "visible", "Visible skill");
1755
+ const runtime = join(cwd, "custom", "runtime", "SKILL.md");
1756
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
1757
+ skillRegistry(pi);
1758
+ const notices: string[] = [];
1759
+ const ctx = { cwd, hasUI: true, ui: { notify: (message: string) => notices.push(message) } };
1760
+ await commands.get("skill-registry:refresh")!.handler("", ctx);
1761
+ const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1762
+ assert.deepEqual(registry.split("\n").filter((line) => line.startsWith("| `")), [
1763
+ `| \`duplicate\` | Disk winner | project | \`${winner}\` |`,
1764
+ `| \`visible\` | Visible skill | project | \`${visible}\` |`,
1765
+ ]);
1766
+ assert.ok(!registry.includes(hidden));
1767
+ assert.deepEqual(notices, ["Skill registry: 2 skill(s) written to .atl/skill-registry.md"]);
1768
+ const options = { skills: [
1769
+ { name: "duplicate", description: "Disabled", filePath: winner, disableModelInvocation: true },
1770
+ { name: "runtime", description: "Runtime skill", filePath: runtime, sourceInfo: { scope: "project", origin: "package" } },
1771
+ ], appendSystemPrompt: "" };
1772
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, ctx);
1773
+ assert.deepEqual(options.appendSystemPrompt.split("\n").filter((line) => line.startsWith("| `")), [
1774
+ `| \`duplicate\` | Eligible alternate | \`${alternate}\` |`,
1775
+ `| \`visible\` | Visible skill | \`${visible}\` |`,
1776
+ ]);
1777
+ assert.ok(!options.appendSystemPrompt.includes(hidden));
1778
+ assert.equal(readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8"), registry);
1779
+ await handlers.get("session_shutdown")![0](undefined, ctx);
1780
+ });
1781
+ }
1782
+
1783
+ test("S5 correction B1 preserves eligible direct symlinks and rejects excluded symlinks and categories", async (t) => {
1784
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-s5-links-"));
1785
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1786
+ const roots = join(cwd, "skills"), targets = join(cwd, "targets");
1787
+ for (const [path, name] of [["allowed", "linked"], ["excluded", "excluded-alias"], ["category/child", "category-alias"]]) {
1788
+ mkdirSync(join(targets, path), { recursive: true });
1789
+ writeFileSync(join(targets, path, "SKILL.md"), `---\nname: ${name}\ndescription: ${name}\n---\n`);
1790
+ }
1791
+ mkdirSync(roots, { recursive: true });
1792
+ symlinkSync(join(targets, "allowed"), join(roots, "linked"), "dir");
1793
+ symlinkSync(join(targets, "excluded"), join(roots, "sdd-linked"), "dir");
1794
+ symlinkSync(join(targets, "category"), join(roots, "linked-category"), "dir");
1795
+ const { pi, commands } = fakeSkillRegistryPi();
1796
+ skillRegistry(pi);
1797
+ const notices: string[] = [];
1798
+ await commands.get("skill-registry:refresh")!.handler("", { cwd, hasUI: true, ui: { notify: (message: string) => notices.push(message) } });
1799
+ const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1800
+ assert.deepEqual(registry.split("\n").filter((line) => line.startsWith("| `")), [
1801
+ `| \`linked\` | linked | project | \`${join(roots, "linked", "SKILL.md")}\` |`,
1802
+ ]);
1803
+ assert.deepEqual(notices, ["Skill registry: 1 skill(s) written to .atl/skill-registry.md"]);
1804
+ });
1805
+
1806
+ for (const [label, quote] of [["apostrophe", "'"], ["double quote", '"']] as const) {
1807
+ test(`S5 correction B3 preserves a single unmatched ${label} in the public view`, async (t) => {
1808
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-s5-quote-"));
1809
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1810
+ const create = (dir: string, name: string, description: string) => {
1811
+ const file = join(cwd, "skills", dir, "SKILL.md");
1812
+ mkdirSync(dirname(file), { recursive: true });
1813
+ writeFileSync(file, `---\nname: ${name}\ndescription: ${description}\n---\n`);
1814
+ return file;
1815
+ };
1816
+ const literal = create("literal", quote, quote);
1817
+ const empty = create("empty", "''", "''");
1818
+ const paired = create("paired-dir", "'paired'", '"Paired description"');
1819
+ const expected = [
1820
+ `| \`${quote}\` | ${quote} | project | \`${literal}\` |`,
1821
+ `| \`empty\` | — | project | \`${empty}\` |`,
1822
+ `| \`paired\` | Paired description | project | \`${paired}\` |`,
1823
+ ];
1824
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
1825
+ skillRegistry(pi);
1826
+ const notices: string[] = [];
1827
+ const ctx = { cwd, hasUI: true, ui: { notify: (message: string) => notices.push(message) } };
1828
+ await commands.get("skill-registry:refresh")!.handler("", ctx);
1829
+ const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1830
+ assert.deepEqual(registry.split("\n").filter((line) => line.startsWith("| `")), expected);
1831
+ assert.deepEqual(notices, ["Skill registry: 3 skill(s) written to .atl/skill-registry.md"]);
1832
+ const options = { skills: [], appendSystemPrompt: "" };
1833
+ await handlers.get("before_agent_start")![0]({ systemPromptOptions: options }, ctx);
1834
+ assert.deepEqual(options.appendSystemPrompt.split("\n").filter((line) => line.startsWith("| `")), expected.map((row) => row.replace(" | project | ", " | ")));
1835
+ assert.equal(readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8"), registry);
1836
+ await handlers.get("session_shutdown")![0](undefined, ctx);
1837
+ });
1838
+ }
1839
+
1608
1840
  test("regenerateRegistry preserves the diagnostic for unexpected I/O errors", async (t) => {
1609
1841
  const cwd = mkdtempSync(join(tmpdir(), "gentle-skill-373-eloop-"));
1610
1842
  t.after(() => rmSync(cwd, { recursive: true, force: true }));
1611
1843
  symlinkSync(join(cwd, ".atl", "self"), join(cwd, ".atl"));
1612
1844
  await assert.rejects(
1613
- __testing.regenerateRegistry(cwd, true, [], true),
1845
+ __testing.regenerateRegistry(cwd, true, true),
1614
1846
  /ELOOP/,
1615
1847
  "unexpected I/O must keep its own diagnostic instead of a typed unavailable result",
1616
1848
  );
1617
1849
  });
1850
+
1851
+ // cost-speed-painpoints S15 P2: Pi already lists its loaded skills in
1852
+ // `<available_skills>`; the effective block carries only on-disk skills Pi did
1853
+ // not load, so the parent's view is `<available_skills>` plus these rows.
1854
+ const UNLISTED_HEADING = "## Effective session skills: on disk, not loaded by Pi; `<available_skills>` lists the rest";
1855
+
1856
+ async function unlistedFixture(t: { after(fn: () => void): void }) {
1857
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-p2-cwd-"));
1858
+ const home = isolatedHome(t);
1859
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
1860
+ const create = (root: string, dir: string, name: string, description: string) => {
1861
+ const file = join(root, dir, "SKILL.md");
1862
+ mkdirSync(dirname(file), { recursive: true });
1863
+ writeFileSync(file, `---\nname: ${name}\ndescription: ${description}\n---\n`);
1864
+ return file;
1865
+ };
1866
+ const { pi, handlers } = fakeSkillRegistryPi(); skillRegistry(pi);
1867
+ return { cwd, home, create, event: handlers.get("before_agent_start")![0], shutdown: handlers.get("session_shutdown")![0] };
1868
+ }
1869
+
1870
+ test("P2 a skill Pi loaded is not repeated in the effective block", async (t) => {
1871
+ const { cwd, create, event, shutdown } = await unlistedFixture(t);
1872
+ const loaded = create(join(cwd, "skills"), "loaded", "loaded", "Loaded by Pi.");
1873
+ const diskOnly = create(join(cwd, ".claude", "skills"), "disk-only", "disk-only", "Only on disk.");
1874
+ const packaged = "/pkg/skills/packaged/SKILL.md";
1875
+ const options = { skills: [
1876
+ { name: "loaded", description: "Loaded by Pi.", filePath: loaded, sourceInfo: { scope: "project" as const } },
1877
+ { name: "packaged", description: "Package skill.", filePath: packaged, sourceInfo: { scope: "user" as const, origin: "package" as const } },
1878
+ ], appendSystemPrompt: "" };
1879
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1880
+ assert.ok(!options.appendSystemPrompt.includes(loaded), "a Pi-loaded disk skill is not repeated");
1881
+ assert.ok(!options.appendSystemPrompt.includes(packaged), "a Pi-loaded package skill is not repeated");
1882
+ assert.ok(options.appendSystemPrompt.includes(diskOnly));
1883
+ await shutdown(undefined, { cwd, hasUI: false });
1884
+ });
1885
+
1886
+ test("P2 a skill only on disk is listed with name, description and path and no scope column", async (t) => {
1887
+ const { cwd, home, create, event, shutdown } = await unlistedFixture(t);
1888
+ const loaded = create(join(cwd, "skills"), "loaded", "loaded", "Loaded by Pi.");
1889
+ const diskOnly = create(join(home, ".claude", "skills"), "other-agent", "other-agent", "Trigger: other agent | shared.");
1890
+ const options = { skills: [{ name: "loaded", description: "Loaded by Pi.", filePath: loaded }], appendSystemPrompt: "existing" };
1891
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1892
+ assert.equal(options.appendSystemPrompt, [
1893
+ "existing", "",
1894
+ "<!-- gentle-pi effective skills begin -->",
1895
+ UNLISTED_HEADING,
1896
+ "| Skill | Trigger / description | Path |",
1897
+ "| --- | --- | --- |",
1898
+ `| \`other-agent\` | Trigger: other agent \\| shared. | \`${diskOnly}\` |`,
1899
+ "<!-- gentle-pi effective skills end -->",
1900
+ ].join("\n"));
1901
+ await shutdown(undefined, { cwd, hasUI: false });
1902
+ });
1903
+
1904
+ test("P2 no on-disk-only skills emits no effective block", async (t) => {
1905
+ const { cwd, create, event, shutdown } = await unlistedFixture(t);
1906
+ const loaded = create(join(cwd, "skills"), "loaded", "loaded", "Loaded by Pi.");
1907
+ const options = { skills: [{ name: "loaded", description: "Loaded by Pi.", filePath: loaded }, { name: "runtime", description: "Runtime.", filePath: "/pkg/runtime/SKILL.md" }], appendSystemPrompt: "existing" };
1908
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1909
+ assert.equal(options.appendSystemPrompt, "existing");
1910
+ // A block emitted on an earlier turn is removed once every row is loaded by Pi.
1911
+ const later = create(join(cwd, ".agents", "skills"), "later", "later", "Later disk skill.");
1912
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1913
+ assert.ok(options.appendSystemPrompt.includes(later));
1914
+ options.skills = [...options.skills, { name: "later", description: "Later disk skill.", filePath: later }];
1915
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1916
+ assert.equal(options.appendSystemPrompt, "existing");
1917
+ await shutdown(undefined, { cwd, hasUI: false });
1918
+ });
1919
+
1920
+ test("P2 effective rows are ordered by name and identical on the next turn", async (t) => {
1921
+ const { cwd, home, create, event, shutdown } = await unlistedFixture(t);
1922
+ const zeta = create(join(cwd, ".claude", "skills"), "zeta", "zeta", "Zeta.");
1923
+ const alpha = create(join(home, ".agents", "skills"), "alpha", "alpha", "Alpha.");
1924
+ const mid = create(join(cwd, "skills"), "mid", "mid", "Mid.");
1925
+ const loaded = create(join(cwd, "skills"), "beta", "beta", "Loaded.");
1926
+ const options = { skills: [{ name: "beta", description: "Loaded.", filePath: loaded }], appendSystemPrompt: "" };
1927
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1928
+ const first = options.appendSystemPrompt;
1929
+ assert.deepEqual(first.split("\n").filter((line) => line.startsWith("| `")), [
1930
+ `| \`alpha\` | Alpha. | \`${alpha}\` |`,
1931
+ `| \`mid\` | Mid. | \`${mid}\` |`,
1932
+ `| \`zeta\` | Zeta. | \`${zeta}\` |`,
1933
+ ]);
1934
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1935
+ assert.equal(options.appendSystemPrompt, first);
1936
+ options.skills = [...options.skills];
1937
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1938
+ assert.equal(options.appendSystemPrompt, first);
1939
+ await shutdown(undefined, { cwd, hasUI: false });
1940
+ });
1941
+
1942
+ test("P2 the renamed registry skill stays out of the effective block while the disk index keeps CLI parity", async (t) => {
1943
+ const { cwd, home, create, event, shutdown } = await unlistedFixture(t);
1944
+ const renamed = create(join(home, ".claude", "skills"), "registry-copy", "gentle-ai-skill-registry", "Index skills.");
1945
+ const diskOnly = create(join(home, ".claude", "skills"), "other", "other", "Other agent skill.");
1946
+ const options = { skills: [], appendSystemPrompt: "" };
1947
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1948
+ assert.ok(options.appendSystemPrompt.includes(diskOnly));
1949
+ assert.ok(!options.appendSystemPrompt.includes(renamed), "the registry skill is never a selectable row");
1950
+ await __testing.regenerateRegistry(cwd, true, true);
1951
+ // The Gentle AI CLI writer excludes only `_shared` and `skill-registry`; equal inputs must give equal bytes.
1952
+ assert.ok(readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8").includes(renamed));
1953
+ await shutdown(undefined, { cwd, hasUI: false });
1954
+ });
1955
+
1956
+ test("P2 the skill-registry skill names only existing references and no runtime internals", () => {
1957
+ const root = join(import.meta.dirname, "..");
1958
+ const skill = readFileSync(join(root, "skills", "skill-registry", "SKILL.md"), "utf8");
1959
+ const references = skill.slice(skill.indexOf("## References"));
1960
+ for (const [, path] of references.matchAll(/`([^`]+\.md)`/g)) assert.ok(existsSync(join(root, path)), `missing reference: ${path}`);
1961
+ assert.doesNotMatch(skill, /systemPromptOptions|pi\.skills|node_modules/);
1962
+ assert.match(skill, /`<available_skills>`/);
1963
+ });
1964
+
1965
+ test("P2 Pi-loaded skills stay in the effective block when Pi renders no <available_skills>", async (t) => {
1966
+ const { cwd, event, shutdown } = await unlistedFixture(t);
1967
+ const packaged = "/pkg/skills/packaged/SKILL.md";
1968
+ const skills = [{ name: "packaged", description: "Package skill.", filePath: packaged, sourceInfo: { scope: "user" as const, origin: "package" as const } }];
1969
+ const without = { skills, selectedTools: ["grep", "find", "ls", "subagent_run"], appendSystemPrompt: "" };
1970
+ await event({ systemPromptOptions: without }, { cwd, hasUI: false });
1971
+ assert.ok(without.appendSystemPrompt.includes(packaged), "without read or bash Pi lists nothing, so the block carries the skill");
1972
+ assert.doesNotMatch(without.appendSystemPrompt, /lists the rest/);
1973
+ const withRead = { skills, selectedTools: ["read"], appendSystemPrompt: "" };
1974
+ await event({ systemPromptOptions: withRead }, { cwd, hasUI: false });
1975
+ assert.equal(withRead.appendSystemPrompt, "");
1976
+ const absent = { skills, appendSystemPrompt: "" };
1977
+ await event({ systemPromptOptions: absent }, { cwd, hasUI: false });
1978
+ assert.equal(absent.appendSystemPrompt, "", "an absent tool list is Pi's default, which includes read");
1979
+ await shutdown(undefined, { cwd, hasUI: false });
1980
+ });
1981
+
1982
+ test("P2 a Pi-loaded symlinked skill and a disabled-only record emit no row", async (t) => {
1983
+ const { cwd, home, create, event, shutdown } = await unlistedFixture(t);
1984
+ const real = create(join(home, ".claude", "skills"), "linked", "linked", "Linked skill.");
1985
+ mkdirSync(join(home, ".agents", "skills"), { recursive: true });
1986
+ symlinkSync(dirname(real), join(home, ".agents", "skills", "linked"), "dir");
1987
+ const viaLink = join(home, ".agents", "skills", "linked", "SKILL.md");
1988
+ const options = { skills: [
1989
+ { name: "linked", description: "Linked skill.", filePath: viaLink },
1990
+ { name: "hidden", description: "Disabled.", filePath: "/pkg/skills/hidden/SKILL.md", disableModelInvocation: true },
1991
+ ], appendSystemPrompt: "" };
1992
+ await event({ systemPromptOptions: options }, { cwd, hasUI: false });
1993
+ assert.equal(options.appendSystemPrompt, "");
1994
+ await shutdown(undefined, { cwd, hasUI: false });
1995
+ });
1996
+
1997
+ // gentle-shell#3020 regression coverage, ported from @Cobies' gentle-shell#3070
1998
+ // onto the merged #3089 contract: the shared registry is disk-only and written
1999
+ // only when its rendered bytes change, while each session's Pi-resolved skills
2000
+ // stay session-local in its prompt. One shared `.atl/` is read by every Pi
2001
+ // session in the cwd, so the decisive evidence has to come from genuinely
2002
+ // separate processes. Each child imports the real extension and drives its
2003
+ // public `before_agent_start` handler (a prompt) and the watcher-poll seam.
2004
+ const registryExtensionUrl = pathToFileURL(
2005
+ join(import.meta.dirname, "..", "extensions", "skill-registry.ts"),
2006
+ ).href;
2007
+
2008
+ interface SharedCacheResult {
2009
+ regenerated: boolean;
2010
+ skillCount: number;
2011
+ reason: string;
2012
+ warning?: string;
2013
+ }
2014
+
2015
+ interface SharedCacheOutcome {
2016
+ result: SharedCacheResult;
2017
+ // The effective block this process appended to its own prompt, if it prompted.
2018
+ prompt?: string;
2019
+ }
2020
+
2021
+ interface ManagedFileSnapshot {
2022
+ bytes: string;
2023
+ ino: number;
2024
+ mtimeMs: number;
2025
+ size: number;
2026
+ }
2027
+
2028
+ function managedFileSnapshot(path: string): ManagedFileSnapshot {
2029
+ const info = statSync(path);
2030
+ return { bytes: readFileSync(path, "utf8"), ino: info.ino, mtimeMs: info.mtimeMs, size: info.size };
2031
+ }
2032
+
2033
+ function snapshotKey(snapshot: ManagedFileSnapshot | { bytes: string; ino: number; mtimeMs: number }): string {
2034
+ return JSON.stringify([snapshot.bytes, snapshot.ino, snapshot.mtimeMs]);
2035
+ }
2036
+
2037
+ function sharedCacheFixture() {
2038
+ const root = mkdtempSync(join(tmpdir(), "gentle-pi-shared-cache-"));
2039
+ const cwd = join(root, "workspace");
2040
+ const skill = join(cwd, "skills", "loose", "SKILL.md");
2041
+ mkdirSync(dirname(skill), { recursive: true });
2042
+ writeFileSync(skill, "---\nname: loose\ndescription: Shared cache loose skill.\n---\n");
2043
+ return {
2044
+ root,
2045
+ cwd,
2046
+ skill,
2047
+ home: join(root, "home"),
2048
+ cache: join(cwd, ".atl", ".skill-registry.cache.json"),
2049
+ registry: join(cwd, ".atl", "skill-registry.md"),
2050
+ };
2051
+ }
2052
+
2053
+ // Child-side prelude shared by both process helpers: an isolated HOME, a fake
2054
+ // Pi that records handlers, and a `prompt(resolved)` that fires the real
2055
+ // `before_agent_start` with Pi listing nothing (`selectedTools: ["grep"]`), so
2056
+ // the session's resolved rows must surface in its own effective block.
2057
+ const sharedCacheChildPrelude = `
2058
+ import { join } from "node:path";
2059
+ delete process.env.GENTLE_PI_AGENTS_CHILD;
2060
+ process.env.HOME = join(process.env.GS_ROOT, "home");
2061
+ process.env.USERPROFILE = process.env.HOME;
2062
+ const { default: skillRegistry, __testing } = await import(process.env.GS_EXTENSION);
2063
+ const handlers = new Map();
2064
+ skillRegistry({
2065
+ on(event, handler) { handlers.set(event, [...(handlers.get(event) ?? []), handler]); },
2066
+ registerFlag() {},
2067
+ registerCommand() {},
2068
+ getFlag() { return false; },
2069
+ });
2070
+ const prompt = async (cwd, resolved) => {
2071
+ const options = { skills: resolved, selectedTools: ["grep"], appendSystemPrompt: "" };
2072
+ await handlers.get("before_agent_start")[0]({ systemPromptOptions: options }, { cwd, hasUI: false });
2073
+ return options.appendSystemPrompt;
2074
+ };
2075
+ `;
2076
+
2077
+ function runSharedCacheProcess(root: string, cwd: string, resolved: ResolvedSkill[]): SharedCacheOutcome {
2078
+ // A session holding a resolved set prompts first (the real before_agent_start
2079
+ // path); every session then runs what a watcher poll does.
2080
+ const child = spawnSync(process.execPath, ["--experimental-strip-types", "--input-type=module", "-e", `
2081
+ ${sharedCacheChildPrelude}
2082
+ const cwd = ${JSON.stringify(cwd)};
2083
+ const resolved = ${JSON.stringify(resolved)};
2084
+ const promptText = resolved.length > 0 ? await prompt(cwd, resolved) : undefined;
2085
+ const result = await __testing.regenerateRegistry(cwd, false);
2086
+ console.log("RESULT " + JSON.stringify({ result, prompt: promptText }));
2087
+ `], {
2088
+ encoding: "utf8",
2089
+ timeout: 20_000,
2090
+ env: { ...process.env, GIT_CEILING_DIRECTORIES: root, GS_ROOT: root, GS_EXTENSION: registryExtensionUrl },
2091
+ });
2092
+ assert.equal(child.error, undefined, `${child.error?.message}\n${child.stderr}`);
2093
+ assert.equal(child.status, 0, child.stderr);
2094
+ const line = child.stdout.split("\n").find((candidate) => candidate.startsWith("RESULT "));
2095
+ assert.ok(line, `child printed no result:\n${child.stdout}\n${child.stderr}`);
2096
+ return JSON.parse(line.slice("RESULT ".length)) as SharedCacheOutcome;
2097
+ }
2098
+
2099
+ test("a process with no resolved skills cache-hits and preserves the published registry (#3020)", async (t) => {
2100
+ const fixture = sharedCacheFixture();
2101
+ t.after(() => rmSync(fixture.root, { recursive: true, force: true }));
2102
+ const resolvedPath = join(fixture.root, "pkg", "skills", "prompted", "SKILL.md");
2103
+ const resolved: ResolvedSkill[] = [
2104
+ {
2105
+ name: "prompted",
2106
+ description: "Trigger: prompted session authority.",
2107
+ filePath: resolvedPath,
2108
+ sourceInfo: { scope: "project", origin: "package" },
2109
+ },
2110
+ ];
2111
+
2112
+ const published = runSharedCacheProcess(fixture.root, fixture.cwd, resolved);
2113
+ assert.equal(published.result.regenerated, true, "the first process must publish the shared registry");
2114
+ assert.equal(published.result.reason, "fingerprint-changed");
2115
+ assert.doesNotMatch(
2116
+ readFileSync(fixture.registry, "utf8"),
2117
+ new RegExp(escapeRegExp(resolvedPath)),
2118
+ "Pi-resolved rows are session-local and must never reach the shared registry",
2119
+ );
2120
+ assert.ok(published.prompt?.includes(resolvedPath), "the publishing session keeps its Pi-resolved rows in its own prompt");
2121
+
2122
+ const registryBefore = managedFileSnapshot(fixture.registry);
2123
+ const cacheBefore = managedFileSnapshot(fixture.cache);
2124
+ await new Promise((resolve) => setTimeout(resolve, 25));
2125
+
2126
+ const idle = runSharedCacheProcess(fixture.root, fixture.cwd, []);
2127
+ assert.equal(idle.result.regenerated, false, "a session with no resolved skills must not rewrite the shared registry");
2128
+ assert.equal(idle.result.reason, "cache-hit");
2129
+ assert.equal(idle.result.skillCount, 1, "the idle session still indexes the shared disk skill");
2130
+ assert.deepEqual(managedFileSnapshot(fixture.registry), registryBefore, "an idle poll must not rewrite the registry");
2131
+ assert.deepEqual(managedFileSnapshot(fixture.cache), cacheBefore, "an idle poll must not rewrite the cache");
2132
+
2133
+ // The resolved session prompting again must not fight the idle one for the file.
2134
+ const peerPoll = runSharedCacheProcess(fixture.root, fixture.cwd, resolved);
2135
+ assert.equal(peerPoll.result.regenerated, false, "a prompted session must not republish the shared registry");
2136
+ assert.equal(peerPoll.result.reason, "cache-hit");
2137
+ assert.ok(peerPoll.prompt?.includes(resolvedPath));
2138
+ assert.deepEqual(managedFileSnapshot(fixture.registry), registryBefore, "a prompt plus poll must not rewrite the registry");
2139
+ assert.deepEqual(managedFileSnapshot(fixture.cache), cacheBefore, "a prompt plus poll must not rewrite the cache");
2140
+
2141
+ // A real skill change still writes, exactly once, and stays disk-only.
2142
+ writeFileSync(fixture.skill, "---\nname: loose\ndescription: Changed loose skill.\n---\n");
2143
+ const filesChanged = runSharedCacheProcess(fixture.root, fixture.cwd, []);
2144
+ assert.equal(filesChanged.result.regenerated, true, "a skill byte change must still regenerate");
2145
+ const changedRegistry = readFileSync(fixture.registry, "utf8");
2146
+ assert.match(changedRegistry, /Changed loose skill/);
2147
+ assert.doesNotMatch(changedRegistry, new RegExp(escapeRegExp(resolvedPath)));
2148
+ const changedSnapshot = managedFileSnapshot(fixture.registry);
2149
+
2150
+ const settled = runSharedCacheProcess(fixture.root, fixture.cwd, resolved);
2151
+ assert.equal(settled.result.regenerated, false, "the change must be bounded to one publish");
2152
+ assert.equal(settled.result.reason, "cache-hit");
2153
+ assert.deepEqual(managedFileSnapshot(fixture.registry), changedSnapshot);
2154
+ });
2155
+
2156
+ const sharedCacheRoundsScript = `
2157
+ ${sharedCacheChildPrelude}
2158
+ import fs from "node:fs";
2159
+ const root = process.env.GS_ROOT;
2160
+ const role = process.env.GS_ROLE;
2161
+ const peer = role === "a" ? "b" : "a";
2162
+ const cwd = join(root, "workspace");
2163
+ const cachePath = join(cwd, ".atl", ".skill-registry.cache.json");
2164
+ const registryPath = join(cwd, ".atl", "skill-registry.md");
2165
+ const logPath = join(root, "rounds-" + role + ".jsonl");
2166
+ const snapshot = (path) => {
2167
+ const info = fs.statSync(path);
2168
+ return { bytes: fs.readFileSync(path, "utf8"), ino: info.ino, mtimeMs: info.mtimeMs };
2169
+ };
2170
+ const waitFor = async (name) => {
2171
+ const deadline = Date.now() + 10000;
2172
+ while (!fs.existsSync(join(root, name))) {
2173
+ if (Date.now() > deadline) throw new Error("timed out waiting for " + name);
2174
+ await new Promise((resolve) => setTimeout(resolve, 20));
2175
+ }
2176
+ };
2177
+ const resolved = JSON.parse(process.env.GS_RESOLVED);
2178
+ for (const round of [1, 2, 3]) {
2179
+ const promptText = await prompt(cwd, resolved);
2180
+ const result = await __testing.regenerateRegistry(cwd, false);
2181
+ fs.appendFileSync(logPath, JSON.stringify({
2182
+ role,
2183
+ round,
2184
+ result,
2185
+ prompt: promptText,
2186
+ cache: snapshot(cachePath),
2187
+ registry: snapshot(registryPath),
2188
+ }) + "\\n");
2189
+ fs.writeFileSync(join(root, "done-" + role + "-" + round), "");
2190
+ await waitFor("done-" + peer + "-" + round);
2191
+ }
2192
+ console.log("ROUNDS_DONE " + role);
2193
+ `;
2194
+
2195
+ function runSharedCacheRounds(
2196
+ root: string,
2197
+ role: "a" | "b",
2198
+ resolved: ResolvedSkill[],
2199
+ ): Promise<{ status: number | null; stdout: string; stderr: string }> {
2200
+ return new Promise((resolve) => {
2201
+ const child = spawn(
2202
+ process.execPath,
2203
+ ["--experimental-strip-types", "--input-type=module", "-e", sharedCacheRoundsScript],
2204
+ {
2205
+ env: {
2206
+ ...process.env,
2207
+ GIT_CEILING_DIRECTORIES: root,
2208
+ GS_ROOT: root,
2209
+ GS_ROLE: role,
2210
+ GS_RESOLVED: JSON.stringify(resolved),
2211
+ GS_EXTENSION: registryExtensionUrl,
2212
+ },
2213
+ },
2214
+ );
2215
+ let stdout = "";
2216
+ let stderr = "";
2217
+ child.stdout.on("data", (chunk: Buffer) => { stdout += chunk.toString(); });
2218
+ child.stderr.on("data", (chunk: Buffer) => { stderr += chunk.toString(); });
2219
+ child.on("error", (error) => resolve({ status: null, stdout, stderr: `${stderr}${error.message}` }));
2220
+ child.on("close", (status) => resolve({ status, stdout, stderr }));
2221
+ });
2222
+ }
2223
+
2224
+ test("two processes with different resolved sets each publish once and then cache-hit (#3020)", { timeout: 30_000 }, async (t) => {
2225
+ const fixture = sharedCacheFixture();
2226
+ t.after(() => rmSync(fixture.root, { recursive: true, force: true }));
2227
+ const resolvedPathFor = (role: "a" | "b") => join(fixture.root, "pkg", "skills", `session-${role}`, "SKILL.md");
2228
+ const resolvedFor = (role: "a" | "b"): ResolvedSkill[] => [
2229
+ {
2230
+ name: `session-${role}`,
2231
+ description: `Trigger: session ${role}.`,
2232
+ filePath: resolvedPathFor(role),
2233
+ },
2234
+ ];
2235
+
2236
+ const outcomes = await Promise.all([
2237
+ runSharedCacheRounds(fixture.root, "a", resolvedFor("a")),
2238
+ runSharedCacheRounds(fixture.root, "b", resolvedFor("b")),
2239
+ ]);
2240
+ for (const outcome of outcomes) {
2241
+ assert.equal(outcome.status, 0, outcome.stderr);
2242
+ assert.match(outcome.stdout, /ROUNDS_DONE/);
2243
+ }
2244
+
2245
+ type Snapshot = { bytes: string; ino: number; mtimeMs: number };
2246
+ type Round = { role: "a" | "b"; round: number; result: SharedCacheResult; prompt: string; cache: Snapshot; registry: Snapshot };
2247
+ const readRounds = (role: "a" | "b"): Round[] =>
2248
+ readFileSync(join(fixture.root, `rounds-${role}.jsonl`), "utf8")
2249
+ .split("\n")
2250
+ .filter(Boolean)
2251
+ .map((line) => JSON.parse(line) as Round);
2252
+ const rounds = [...readRounds("a"), ...readRounds("b")];
2253
+ assert.equal(rounds.length, 6, "both processes must complete all three rounds");
2254
+ const firstRound = rounds.filter((entry) => entry.round === 1);
2255
+ const laterRounds = rounds.filter((entry) => entry.round > 1);
2256
+ assert.equal(firstRound.length, 2);
2257
+ assert.equal(laterRounds.length, 4);
2258
+
2259
+ // Both sessions render the same disk-only bytes, so the first publication
2260
+ // is shared. Which process lands it (or whether both race identical bytes
2261
+ // in) is timing-dependent, so round 1 only bounds the count.
2262
+ const firstPublishes = firstRound.filter((entry) => entry.result.regenerated).length;
2263
+ assert.ok(firstPublishes >= 1 && firstPublishes <= 2, `round 1 must publish at most once per session, saw ${firstPublishes}`);
2264
+ for (const entry of firstRound.filter((candidate) => candidate.result.regenerated)) {
2265
+ assert.equal(entry.result.reason, "fingerprint-changed");
2266
+ }
2267
+ for (const entry of laterRounds) {
2268
+ assert.equal(entry.result.regenerated, false, `session ${entry.role} round ${entry.round} must be quiet`);
2269
+ assert.equal(entry.result.reason, "cache-hit");
2270
+ }
2271
+ assert.equal(
2272
+ rounds.filter((entry) => entry.result.regenerated).length,
2273
+ firstPublishes,
2274
+ "no session may publish again after the first round",
2275
+ );
2276
+
2277
+ const steadyCaches = new Set(laterRounds.map((entry) => snapshotKey(entry.cache)));
2278
+ const steadyRegistries = new Set(laterRounds.map((entry) => snapshotKey(entry.registry)));
2279
+ assert.equal(steadyCaches.size, 1, "the shared cache must stop changing after the first publication");
2280
+ assert.equal(steadyRegistries.size, 1, "the shared registry must stop changing after the first publication");
2281
+
2282
+ // Each session keeps its own resolved set in its own prompt, and the shared
2283
+ // file never carries either session's runtime-only rows.
2284
+ for (const entry of rounds) {
2285
+ const peer = entry.role === "a" ? "b" : "a";
2286
+ assert.ok(entry.prompt.includes(resolvedPathFor(entry.role)), `session ${entry.role} round ${entry.round} must see its own resolved row`);
2287
+ assert.ok(!entry.prompt.includes(resolvedPathFor(peer)), `session ${entry.role} must never see session ${peer}'s resolved row`);
2288
+ }
2289
+ const shared = readFileSync(fixture.registry, "utf8");
2290
+ for (const role of ["a", "b"] as const) {
2291
+ assert.doesNotMatch(shared, new RegExp(escapeRegExp(resolvedPathFor(role))), `session ${role}'s runtime row must stay out of the shared registry`);
2292
+ }
2293
+ assert.match(shared, new RegExp(escapeRegExp(fixture.skill)), "the shared registry still indexes the disk skill");
2294
+ });