gentle-pi 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +10 -11
  2. package/assets/agents/gentle-ai-explore.md +1 -0
  3. package/assets/agents/gentle-ai-verify.md +5 -2
  4. package/assets/agents/gentle-ai-worker.md +3 -0
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +1 -0
  7. package/assets/agents/jd-judge-b.md +1 -0
  8. package/assets/design-canvas/canvas.css +13 -1
  9. package/assets/design-canvas/canvas.js +11 -2
  10. package/assets/install-wizard/wizard.js +1 -0
  11. package/assets/migrations/agent-body-history.json +16 -1
  12. package/assets/orchestrator-delegation-reference.md +4 -4
  13. package/assets/orchestrator-delegation.md +1 -1
  14. package/assets/orchestrator-full-delegation-card.md +65 -0
  15. package/assets/orchestrator-full-delegation.md +34 -0
  16. package/assets/orchestrator-memory.md +3 -3
  17. package/assets/orchestrator-prompts.md +1 -1
  18. package/assets/orchestrator-skills.md +1 -1
  19. package/assets/orchestrator-verification.md +7 -5
  20. package/assets/orchestrator.md +3 -3
  21. package/bin/gentle-shell.mjs +164 -56
  22. package/docs/agent-status.md +61 -0
  23. package/docs/bundled-install.md +7 -5
  24. package/docs/delegated-verification.md +29 -7
  25. package/docs/gentle-agents-activity.md +14 -0
  26. package/docs/gentle-shell.md +54 -16
  27. package/docs/install-wizard.md +1 -1
  28. package/docs/permission-modes.md +9 -4
  29. package/docs/readme-reference.md +75 -30
  30. package/docs/render-cache-performance.md +11 -1
  31. package/docs/review-coordinator.md +33 -0
  32. package/docs/review-request-context.md +19 -0
  33. package/docs/review-windows-acl.md +18 -0
  34. package/docs/voice.md +6 -3
  35. package/docs/yolo-mode.md +5 -5
  36. package/extensions/ask-user-choice.ts +1 -0
  37. package/extensions/ask-user-question.ts +1 -0
  38. package/extensions/child-safety.ts +3 -0
  39. package/extensions/gentle-agent-status.ts +99 -0
  40. package/extensions/gentle-agents.ts +326 -34
  41. package/extensions/gentle-ai.ts +1496 -454
  42. package/extensions/gentle-shell.ts +293 -63
  43. package/extensions/gentle-todo.ts +18 -2
  44. package/extensions/gentle-tps.ts +48 -0
  45. package/extensions/quiet-tools.ts +38 -8
  46. package/extensions/skill-registry.ts +175 -18
  47. package/extensions/startup-banner.ts +30 -3
  48. package/lib/agent-profile-pin.ts +3 -3
  49. package/lib/agent-profiles.ts +160 -2
  50. package/lib/agent-status.ts +105 -0
  51. package/lib/agents-config.ts +46 -0
  52. package/lib/agents-history.ts +24 -5
  53. package/lib/agents-messaging.ts +47 -5
  54. package/lib/agents-runner.ts +183 -12
  55. package/lib/auto-permission-runtime.ts +1 -1
  56. package/lib/bounded-writer-admission.ts +13 -1
  57. package/lib/card-content-policy.ts +8 -6
  58. package/lib/command-palette.ts +133 -17
  59. package/lib/context-backstop.ts +14 -5
  60. package/lib/destructive-command-guard.ts +48 -4
  61. package/lib/execution-surface-guard.ts +20 -0
  62. package/lib/exploration-budget.ts +4 -2
  63. package/lib/gentle-ai-binary.ts +1 -1
  64. package/lib/gentle-design.ts +3 -0
  65. package/lib/gentle-shell-bundled.ts +6 -19
  66. package/lib/gentle-shell-launcher.ts +43 -8
  67. package/lib/herdr-activity.ts +14 -2
  68. package/lib/herdr-busy.ts +45 -0
  69. package/lib/image-attachments.ts +33 -0
  70. package/lib/image-disk-cache.ts +137 -0
  71. package/lib/inprocess-reviewer.ts +270 -140
  72. package/lib/jobs-view.ts +198 -11
  73. package/lib/model-routing-authority.ts +22 -4
  74. package/lib/native-choice-list.ts +20 -2
  75. package/lib/native-review-cli.ts +96 -19
  76. package/lib/orchestrator-mode-policy.ts +105 -0
  77. package/lib/questionnaire/questionnaire-view.ts +105 -12
  78. package/lib/rdd-mode-control.ts +32 -0
  79. package/lib/reply-language-anchor.ts +104 -0
  80. package/lib/review-blocker.ts +92 -0
  81. package/lib/review-candidate-symlink-scan.ts +136 -0
  82. package/lib/review-candidate-view-owner.ts +81 -44
  83. package/lib/review-continuation-registry.ts +99 -0
  84. package/lib/review-coordinator.ts +163 -0
  85. package/lib/review-failure-facts.ts +49 -0
  86. package/lib/review-host-relay.ts +46 -10
  87. package/lib/review-integration-v2.ts +7 -1
  88. package/lib/review-relay-phase-timing.ts +45 -0
  89. package/lib/review-start-context.ts +17 -0
  90. package/lib/session-profile-freeze.ts +4 -2
  91. package/lib/shell-bar.ts +140 -58
  92. package/lib/shell-changes.ts +2 -0
  93. package/lib/shell-panel.ts +17 -3
  94. package/lib/shell-sidebar-layout.ts +112 -40
  95. package/lib/shell-sidebar.ts +7 -0
  96. package/lib/shell-todo.ts +10 -3
  97. package/lib/verifier-admission.ts +1 -1
  98. package/lib/visual-customization-policy.ts +36 -16
  99. package/lib/visual-customize-view.ts +216 -21
  100. package/lib/visual-layout-preview.ts +9 -5
  101. package/lib/visual-profiles.ts +2 -2
  102. package/lib/windows-session-transport.ts +53 -2
  103. package/lib/yolo-session-policy.ts +40 -15
  104. package/package.json +2 -1
  105. package/runtime/gentle-ai-binary.mjs +1 -1
  106. package/runtime/gentle-shell-bundled.mjs +6 -19
  107. package/runtime/gentle-shell-launcher.mjs +42 -7
  108. package/runtime/native-review-cli.mjs +93 -16
  109. package/runtime/review-integration-v2.mjs +7 -1
  110. package/scripts/build-full-delegation-card.mjs +175 -0
  111. package/scripts/bundled-install.mjs +38 -8
  112. package/scripts/download-progress.mjs +68 -0
  113. package/scripts/gentle-ai-installer.mjs +41 -18
  114. package/scripts/gentle-ai-proxy.mjs +294 -0
  115. package/scripts/install-gentle-ai.mjs +14 -1
  116. package/scripts/installer-preflight.mjs +5 -5
  117. package/scripts/installer-runner.mjs +27 -12
  118. package/scripts/installer-server.mjs +8 -7
  119. package/scripts/render-cache-host.mjs +72 -0
  120. package/scripts/render-cache-performance-worker.mjs +5 -4
  121. package/scripts/render-cache-performance.mjs +6 -1
  122. package/scripts/run-test-suite.mjs +40 -28
  123. package/scripts/verify-package-files.mjs +12 -2
  124. package/scripts/voice-worker.cjs +32 -6
  125. package/skills/design/SKILL.md +11 -8
  126. package/skills/gentle-ai/SKILL.md +2 -2
  127. package/skills/gentle-ui-design/SKILL.md +46 -0
  128. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  129. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  130. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  131. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  132. package/skills/skill-registry/SKILL.md +4 -2
  133. package/skills/work-unit-commits/SKILL.md +6 -7
  134. package/tests/agent-home.test.ts +28 -9
  135. package/tests/agent-profiles-workflow.test.ts +163 -0
  136. package/tests/agent-risk-escalation.test.ts +1 -1
  137. package/tests/agent-status.test.ts +143 -0
  138. package/tests/agents-config.test.ts +96 -0
  139. package/tests/agents-history.test.ts +31 -0
  140. package/tests/agents-jobs-frames.test.ts +93 -0
  141. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  142. package/tests/agents-runner-drain.test.ts +193 -0
  143. package/tests/agents-runner.test.ts +178 -2
  144. package/tests/append-system-prompt-route.test.ts +4 -1
  145. package/tests/ask-user-choice.test.ts +4 -3
  146. package/tests/ask-user-question.test.ts +97 -0
  147. package/tests/auto-permission-runtime.test.ts +1 -1
  148. package/tests/autonomous-guard.test.ts +346 -10
  149. package/tests/bounded-stop-contract.test.ts +43 -3
  150. package/tests/bridge-cost.test.ts +19 -4
  151. package/tests/bundled-install.test.ts +30 -5
  152. package/tests/card-content-policy.test.ts +3 -3
  153. package/tests/chained-pr-skill.test.ts +8 -6
  154. package/tests/child-safety.test.ts +11 -0
  155. package/tests/codegraph-tools.test.ts +11 -5
  156. package/tests/command-palette.test.ts +284 -1
  157. package/tests/delegate-for-reason-contract.test.ts +3 -3
  158. package/tests/design-canvas-assets.test.ts +185 -2
  159. package/tests/destructive-command-guard.test.ts +52 -0
  160. package/tests/download-progress.test.ts +71 -0
  161. package/tests/execution-surface-guard.test.ts +55 -0
  162. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
  163. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  164. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  165. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  166. package/tests/fixtures/session-profile-v1/replay.ts +53 -6
  167. package/tests/full-delegation-closure.test.ts +131 -0
  168. package/tests/full-delegation-notices.test.ts +76 -0
  169. package/tests/generic-agent-tools.test.ts +3 -3
  170. package/tests/gentle-agent-status.test.ts +74 -0
  171. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  172. package/tests/gentle-agents.test.ts +1070 -12
  173. package/tests/gentle-ai-binary.test.ts +3 -1
  174. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  175. package/tests/gentle-ai-exploration-budget.test.ts +18 -2
  176. package/tests/gentle-ai-installer.test.ts +134 -51
  177. package/tests/gentle-ai-proxy.test.ts +434 -0
  178. package/tests/gentle-ai.test.ts +113 -38
  179. package/tests/gentle-design.test.ts +21 -0
  180. package/tests/gentle-herdr-activity.test.ts +9 -6
  181. package/tests/gentle-shell-bin.test.ts +123 -0
  182. package/tests/gentle-shell-bundled.test.ts +207 -31
  183. package/tests/gentle-shell-launcher.test.ts +77 -10
  184. package/tests/gentle-shell.test.ts +899 -59
  185. package/tests/gentle-todo.test.ts +19 -2
  186. package/tests/gentle-tps.test.ts +123 -0
  187. package/tests/gentle-ui-design-skill.test.ts +59 -0
  188. package/tests/herdr-busy.test.ts +59 -0
  189. package/tests/herdr-task-summary-policy.test.ts +8 -4
  190. package/tests/image-disk-cache.test.ts +163 -0
  191. package/tests/independent-recovery-delivery.test.ts +83 -0
  192. package/tests/inprocess-reviewer.test.ts +176 -4
  193. package/tests/installer-posix-bootstrap.test.ts +1 -1
  194. package/tests/installer-preflight.test.ts +5 -4
  195. package/tests/installer-runner.test.ts +79 -44
  196. package/tests/installer-server.test.ts +14 -11
  197. package/tests/jobs-view.test.ts +260 -6
  198. package/tests/modal-mouse-boundaries.test.ts +136 -0
  199. package/tests/model-routing-authority.test.ts +178 -2
  200. package/tests/native-choice-list.test.ts +77 -2
  201. package/tests/native-review-capability-contract.test.ts +7 -1
  202. package/tests/native-review-cli.test.ts +269 -1
  203. package/tests/no-self-pause-contract.test.ts +4 -1
  204. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  205. package/tests/orchestrator-budget.test.ts +7 -2
  206. package/tests/orchestrator-delegation-mode.test.ts +153 -0
  207. package/tests/orchestrator-mode-policy.test.ts +175 -0
  208. package/tests/orchestrator-prompt-budget.test.ts +3 -1
  209. package/tests/orchestrator-rdd-ownership.test.ts +2 -2
  210. package/tests/package-manifest.test.ts +11 -9
  211. package/tests/permission-allowlist.test.ts +202 -0
  212. package/tests/pi-update-launcher.test.ts +8 -0
  213. package/tests/pnpm-workspace-config.test.ts +58 -0
  214. package/tests/primary-session-prompt.test.ts +13 -0
  215. package/tests/profile-pin.test.ts +29 -2
  216. package/tests/profile-tier-footer.test.ts +5 -0
  217. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  218. package/tests/questionnaire-view.test.ts +115 -0
  219. package/tests/quiet-bash-runtime.test.ts +1 -1
  220. package/tests/quiet-tool-rendering.test.ts +48 -0
  221. package/tests/rdd-aware-verification-contract.test.ts +16 -11
  222. package/tests/rdd-customize.test.ts +287 -0
  223. package/tests/rdd-mode-cache.test.ts +450 -0
  224. package/tests/rdd-mode-control.test.ts +407 -0
  225. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  226. package/tests/rdd-off-independent-regression.test.ts +69 -0
  227. package/tests/rdd-status-line.test.ts +18 -0
  228. package/tests/render-cache-performance.test.ts +171 -2
  229. package/tests/reply-language-anchor.test.ts +173 -0
  230. package/tests/review-agent-end-preflight.test.ts +1 -1
  231. package/tests/review-blocker.test.ts +193 -0
  232. package/tests/review-candidate-owner-retry.test.ts +1 -1
  233. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  234. package/tests/review-candidate-view.test.ts +1 -1
  235. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  236. package/tests/review-candidate-windows-probe.test.ts +63 -0
  237. package/tests/review-committed-restart-ack.test.ts +129 -0
  238. package/tests/review-continuation-registry.test.ts +76 -0
  239. package/tests/review-controller-native-routing.test.ts +261 -5
  240. package/tests/review-controller-workspace-root.test.ts +230 -3
  241. package/tests/review-controller.test.ts +96 -11
  242. package/tests/review-coordinator-runtime.test.ts +117 -0
  243. package/tests/review-coordinator.test.ts +195 -0
  244. package/tests/review-failure-facts.test.ts +87 -0
  245. package/tests/review-host-relay-routing.test.ts +258 -4
  246. package/tests/review-host-relay.test.ts +39 -0
  247. package/tests/review-integration-v2.test.ts +46 -3
  248. package/tests/review-json-arguments.test.ts +65 -10
  249. package/tests/review-last-event-closure.test.ts +68 -0
  250. package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
  251. package/tests/review-owner-identity.test.ts +60 -24
  252. package/tests/review-relay-phase-timing.test.ts +128 -0
  253. package/tests/review-relay-transport-agent.test.ts +12 -2
  254. package/tests/review-reviewer-evidence.test.ts +183 -0
  255. package/tests/review-risk-assessment.test.ts +74 -3
  256. package/tests/review-session-standing-permission-controller.test.ts +21 -1
  257. package/tests/review-start-context.test.ts +19 -0
  258. package/tests/review-tool-prose-budget.test.ts +121 -0
  259. package/tests/run-test-suite.test.ts +122 -1
  260. package/tests/runtime-harness.mjs +4 -1
  261. package/tests/sensitive-path-tools.test.ts +181 -5
  262. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  263. package/tests/session-profile-binding.test.ts +19 -1
  264. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  265. package/tests/session-profile-v1-compat.test.ts +35 -1
  266. package/tests/shell-bar.test.ts +186 -42
  267. package/tests/shell-panel.test.ts +50 -22
  268. package/tests/shell-sidebar-fullscreen.test.ts +5 -5
  269. package/tests/shell-sidebar-layout.test.ts +294 -23
  270. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  271. package/tests/shell-surface-transparent.test.ts +89 -0
  272. package/tests/shell-todo.test.ts +12 -0
  273. package/tests/skill-registry.test.ts +838 -5
  274. package/tests/startup-banner.test.ts +152 -1
  275. package/tests/startup-home-repo.test.ts +2 -0
  276. package/tests/support/review-coordinator-runtime.ts +69 -0
  277. package/tests/task-size-routing-contract.test.ts +5 -3
  278. package/tests/verifier-admission.test.ts +49 -0
  279. package/tests/verify-first-launch-contract.test.ts +78 -3
  280. package/tests/visual-customization-policy.test.ts +39 -6
  281. package/tests/visual-customize-view.test.ts +573 -9
  282. package/tests/visual-layout-preview.test.ts +15 -1
  283. package/tests/visual-profiles.test.ts +11 -0
  284. package/tests/voice-worker.test.ts +73 -2
  285. package/tests/windows-session-transport.test.ts +126 -0
  286. package/tests/work-continuity-contract.test.ts +28 -0
  287. package/tests/writer-feature-document-admission.test.ts +92 -0
  288. package/tests/yolo-customize.test.ts +27 -4
  289. package/tests/yolo-mode.test.ts +23 -18
  290. package/tests/yolo-session-policy.test.ts +270 -1
@@ -6,7 +6,8 @@ import { dirname, join } 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";
9
- import skillRegistry, { __testing } from "../extensions/skill-registry.ts";
9
+ import skillRegistryExtension, { __testing, type ResolvedSkill } from "../extensions/skill-registry.ts";
10
+ const skillRegistry = skillRegistryExtension;
10
11
 
11
12
  // Registered startup reads process.env directly; a suite launched from a
12
13
  // delegated child must still exercise the parent paths (gentle-shell#1690).
@@ -364,6 +365,838 @@ test("non-forced regeneration invalidates cache when skill bytes change but path
364
365
  assert.doesNotMatch(secondRegistry, /Variant one\. Body A\./);
365
366
  });
366
367
 
368
+ function escapeRegExp(value: string): string {
369
+ return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
370
+ }
371
+
372
+ test("toResolvedEntry maps exact file path and scope from sourceInfo", () => {
373
+ const cwd = join(tmpdir(), `gentle-pi-resolved-${Date.now()}`);
374
+ const projectPath = join(cwd, "skills", "go-testing", "SKILL.md");
375
+ const projectEntry = __testing.toResolvedEntry(
376
+ {
377
+ name: "go-testing",
378
+ description: "Trigger: Go tests.\nApply focused patterns.",
379
+ filePath: projectPath,
380
+ sourceInfo: { scope: "project" },
381
+ } satisfies ResolvedSkill,
382
+ cwd,
383
+ );
384
+ assert.ok(projectEntry);
385
+ assert.equal(projectEntry.name, "go-testing");
386
+ assert.equal(projectEntry.path, projectPath, "resolved path must be preserved exactly");
387
+ assert.equal(projectEntry.description, "Trigger: Go tests. Apply focused patterns.");
388
+ assert.equal(projectEntry.scope, "project");
389
+
390
+ const userEntry = __testing.toResolvedEntry(
391
+ {
392
+ name: "docs",
393
+ description: "Docs.",
394
+ filePath: "/home/u/.pi/agent/skills/docs/SKILL.md",
395
+ sourceInfo: { scope: "user" },
396
+ } satisfies ResolvedSkill,
397
+ cwd,
398
+ );
399
+ assert.ok(userEntry);
400
+ assert.equal(userEntry.scope, "user");
401
+
402
+ const temporaryEntry = __testing.toResolvedEntry(
403
+ {
404
+ name: "temp",
405
+ description: "Temp.",
406
+ filePath: "/run/pi/temp-skills/temp/SKILL.md",
407
+ sourceInfo: { scope: "temporary" },
408
+ } satisfies ResolvedSkill,
409
+ cwd,
410
+ );
411
+ assert.ok(temporaryEntry);
412
+ assert.equal(temporaryEntry.scope, "user", "temporary scope maps to the user label");
413
+
414
+ const absentEntry = __testing.toResolvedEntry(
415
+ { name: "plain", description: "Plain.", filePath: "/anywhere/plain/SKILL.md" } satisfies ResolvedSkill,
416
+ cwd,
417
+ );
418
+ assert.ok(absentEntry);
419
+ assert.equal(absentEntry.scope, "user", "absent sourceInfo falls back to the user label");
420
+ });
421
+
422
+ test("toResolvedEntry appends package origin to the scope label", () => {
423
+ const cwd = join(tmpdir(), `gentle-pi-resolved-package-${Date.now()}`);
424
+ const packaged = __testing.toResolvedEntry(
425
+ {
426
+ name: "packaged",
427
+ description: "Packaged.",
428
+ filePath: "/pkg/skills/packaged/SKILL.md",
429
+ sourceInfo: { scope: "user", origin: "package" },
430
+ } satisfies ResolvedSkill,
431
+ cwd,
432
+ );
433
+ assert.ok(packaged);
434
+ assert.equal(packaged.scope, "user · package");
435
+
436
+ const projectPackaged = __testing.toResolvedEntry(
437
+ {
438
+ name: "project-packaged",
439
+ description: "Packaged.",
440
+ filePath: "/pkg/skills/project-packaged/SKILL.md",
441
+ sourceInfo: { scope: "project", origin: "package" },
442
+ } satisfies ResolvedSkill,
443
+ cwd,
444
+ );
445
+ assert.ok(projectPackaged);
446
+ assert.equal(projectPackaged.scope, "project · package");
447
+
448
+ const topLevel = __testing.toResolvedEntry(
449
+ {
450
+ name: "top",
451
+ description: "Top.",
452
+ filePath: "/pkg/skills/top/SKILL.md",
453
+ sourceInfo: { scope: "user", origin: "top-level" },
454
+ } satisfies ResolvedSkill,
455
+ cwd,
456
+ );
457
+ assert.ok(topLevel);
458
+ assert.equal(topLevel.scope, "user", "top-level origin must not append the package label");
459
+ });
460
+
461
+ test("toResolvedEntry returns undefined when model invocation is disabled", () => {
462
+ assert.equal(
463
+ __testing.toResolvedEntry(
464
+ {
465
+ name: "internal",
466
+ description: "Internal.",
467
+ filePath: "/skills/internal/SKILL.md",
468
+ disableModelInvocation: true,
469
+ } satisfies ResolvedSkill,
470
+ "/repo",
471
+ ),
472
+ undefined,
473
+ );
474
+ });
475
+
476
+ test("toResolvedEntry returns undefined for excluded skill names", () => {
477
+ assert.equal(
478
+ __testing.toResolvedEntry(
479
+ {
480
+ name: "sdd-research",
481
+ description: "Research.",
482
+ filePath: "/skills/sdd-research/SKILL.md",
483
+ } satisfies ResolvedSkill,
484
+ "/repo",
485
+ ),
486
+ undefined,
487
+ );
488
+ assert.equal(
489
+ __testing.toResolvedEntry(
490
+ {
491
+ name: "_shared",
492
+ description: "Shared.",
493
+ filePath: "/skills/_shared/SKILL.md",
494
+ } satisfies ResolvedSkill,
495
+ "/repo",
496
+ ),
497
+ undefined,
498
+ );
499
+ });
500
+
501
+ test("mergeResolvedWithLoose gives resolved paths per-path authority", () => {
502
+ const cwd = join(tmpdir(), `gentle-pi-merge-${Date.now()}`);
503
+ const resolvedPath = join(tmpdir(), `gentle-pi-merge-pkg-${Date.now()}`, "skills", "dup", "SKILL.md");
504
+ const otherPath = join(cwd, ".opencode", "skills", "other", "SKILL.md");
505
+ const merged = __testing.mergeResolvedWithLoose(
506
+ [{ name: "dup", path: resolvedPath, description: "resolved", scope: "user · package" }],
507
+ [
508
+ { name: "dup", path: resolvedPath, description: "loose" },
509
+ { name: "other", path: otherPath, description: "loose-other" },
510
+ ],
511
+ cwd,
512
+ );
513
+
514
+ assert.equal(merged.length, 2, "only the path-colliding loose entry is dropped");
515
+ const dup = merged.find((entry) => entry.name === "dup");
516
+ assert.ok(dup);
517
+ assert.equal(dup.path, resolvedPath, "the exact resolved path must survive");
518
+ assert.equal(dup.description, "resolved");
519
+ assert.ok(merged.some((entry) => entry.name === "other"), "unrelated loose entries survive");
520
+ });
521
+
522
+ test("mergeResolvedWithLoose keeps project-over-user name precedence", () => {
523
+ const cwd = join(tmpdir(), `gentle-pi-merge-precedence-${Date.now()}`);
524
+ const packagePath = join(tmpdir(), `gentle-pi-merge-pkg2-${Date.now()}`, "skills", "dup", "SKILL.md");
525
+ const projectPath = join(cwd, "skills", "dup", "SKILL.md");
526
+
527
+ const looseProjectWins = __testing.mergeResolvedWithLoose(
528
+ [{ name: "dup", path: packagePath, description: "resolved", scope: "user · package" }],
529
+ [{ name: "dup", path: projectPath, description: "loose" }],
530
+ cwd,
531
+ );
532
+ assert.equal(looseProjectWins.length, 1);
533
+ assert.equal(looseProjectWins[0].path, projectPath, "loose project path beats resolved user/package path");
534
+
535
+ const resolvedProjectPath = join(cwd, ".claude", "skills", "dup", "SKILL.md");
536
+ const userPath = join(tmpdir(), `gentle-pi-merge-home-${Date.now()}`, ".pi", "agent", "skills", "dup", "SKILL.md");
537
+ const resolvedWins = __testing.mergeResolvedWithLoose(
538
+ [{ name: "dup", path: resolvedProjectPath, description: "resolved", scope: "project" }],
539
+ [{ name: "dup", path: userPath, description: "loose" }],
540
+ cwd,
541
+ );
542
+ assert.equal(resolvedWins.length, 1);
543
+ assert.equal(resolvedWins[0].path, resolvedProjectPath, "resolved project path beats loose user path");
544
+ });
545
+
546
+ test("mergeResolvedWithLoose does not promote resolved user scope inside cwd", () => {
547
+ const cwd = join(tmpdir(), `gentle-pi-resolved-user-cwd-${Date.now()}`);
548
+ const resolvedPath = join(cwd, ".pi", "agent", "skills", "dup", "SKILL.md");
549
+ const loosePath = join(cwd, "skills", "dup", "SKILL.md");
550
+ const resolved = __testing.toResolvedEntry({
551
+ name: "dup", description: "Pi user skill", filePath: resolvedPath,
552
+ sourceInfo: { scope: "user" },
553
+ }, cwd);
554
+ assert.ok(resolved);
555
+ assert.equal(resolved.scope, "user");
556
+ const merged = __testing.mergeResolvedWithLoose(
557
+ [resolved], [{ name: "dup", path: loosePath, description: "Loose project skill" }], cwd,
558
+ );
559
+ assert.equal(merged.length, 1);
560
+ assert.equal(merged[0].path, loosePath, "loose project beats Pi-resolved user even inside cwd");
561
+ });
562
+
563
+ test("mergeResolvedWithLoose honors resolved project scope outside cwd", () => {
564
+ const cwd = join(tmpdir(), `gentle-pi-linked-workspace-${Date.now()}`);
565
+ const linkedPath = join(tmpdir(), `gentle-pi-linked-source-${Date.now()}`, "skills", "dup", "SKILL.md");
566
+ const loosePath = join(cwd, "skills", "dup", "SKILL.md");
567
+ const resolved = __testing.toResolvedEntry({
568
+ name: "dup", description: "Pi project skill", filePath: linkedPath,
569
+ sourceInfo: { scope: "project" },
570
+ }, cwd);
571
+ assert.ok(resolved);
572
+ const merged = __testing.mergeResolvedWithLoose(
573
+ [resolved], [{ name: "dup", path: loosePath, description: "Loose cwd skill" }], cwd,
574
+ );
575
+ assert.equal(merged.length, 1);
576
+ assert.deepEqual(merged[0], resolved);
577
+ });
578
+
579
+ test("mergeResolvedWithLoose with empty resolved matches the loose-only result", () => {
580
+ const cwd = join(tmpdir(), `gentle-pi-merge-empty-${Date.now()}`);
581
+ const loose = [
582
+ { name: "zeta", path: join(cwd, "skills", "zeta", "SKILL.md"), description: "z" },
583
+ {
584
+ name: "alpha",
585
+ path: join(tmpdir(), `gentle-pi-merge-empty-home-${Date.now()}`, "skills", "alpha", "SKILL.md"),
586
+ description: "a-user",
587
+ },
588
+ { name: "alpha", path: join(cwd, ".opencode", "skills", "alpha", "SKILL.md"), description: "a-project" },
589
+ ];
590
+
591
+ assert.deepEqual(
592
+ __testing.mergeResolvedWithLoose([], loose, cwd),
593
+ __testing.dedupeBySkillName(loose, cwd),
594
+ );
595
+ });
596
+
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
+ );
654
+ });
655
+
656
+ test("regenerateRegistry carries a skill resolved from a non-default PI_CODING_AGENT_DIR", async () => {
657
+ // Acceptance case from gentle-shell#369 (2026-09-27): with
658
+ // PI_CODING_AGENT_DIR set to a non-default directory, Pi resolves user
659
+ // skills from <agent-dir>/skills, which no loose scan root reaches. The
660
+ // runtime mirror must be the only route into the registry.
661
+ const cwd = join(tmpdir(), `gentle-pi-agentdir-cwd-${Date.now()}`);
662
+ const isolatedHome = join(tmpdir(), `gentle-pi-agentdir-home-${Date.now()}`);
663
+ const agentDir = join(tmpdir(), `gentle-pi-agentdir-root-${Date.now()}`);
664
+ const skillPath = join(agentDir, "skills", "codegraph", "SKILL.md");
665
+ mkdirSync(dirname(skillPath), { recursive: true });
666
+ writeFileSync(skillPath, "---\nname: codegraph\ndescription: Trigger: agent-dir skill.\n---\n");
667
+
668
+ const resolved: ResolvedSkill[] = [
669
+ {
670
+ name: "codegraph",
671
+ description: "Trigger: agent-dir skill.",
672
+ filePath: skillPath,
673
+ sourceInfo: { scope: "user" },
674
+ },
675
+ ];
676
+
677
+ const previousHome = process.env.HOME;
678
+ const previousAgentDir = process.env.PI_CODING_AGENT_DIR;
679
+ process.env.HOME = isolatedHome;
680
+ process.env.PI_CODING_AGENT_DIR = agentDir;
681
+ try {
682
+ const result = await __testing.regenerateRegistry(cwd, false, resolved);
683
+ assert.equal(result.regenerated, true, "agent-dir resolved skill must trigger regeneration");
684
+ 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
+ );
694
+
695
+ // Counter-proof: with no resolved set, the isolated agent dir is
696
+ // unreachable — no loose root scans it. If the skill still appeared, a
697
+ // hardcoded agent-dir loose root would have been reintroduced.
698
+ const bareCwd = join(tmpdir(), `gentle-pi-agentdir-bare-${Date.now()}`);
699
+ const decoyPath = join(bareCwd, "skills", "decoy", "SKILL.md");
700
+ mkdirSync(dirname(decoyPath), { recursive: true });
701
+ writeFileSync(decoyPath, "---\nname: decoy\ndescription: Trigger: decoy.\n---\n");
702
+ await __testing.regenerateRegistry(bareCwd, false, []);
703
+ const bareRegistry = readFileSync(join(bareCwd, ".atl", "skill-registry.md"), "utf8");
704
+ assert.match(
705
+ bareRegistry,
706
+ new RegExp(escapeRegExp(decoyPath)),
707
+ "decoy loose skill proves the registry was written",
708
+ );
709
+ assert.doesNotMatch(
710
+ bareRegistry,
711
+ new RegExp(escapeRegExp(skillPath)),
712
+ "no loose scan root may reach a non-default agent dir",
713
+ );
714
+ } finally {
715
+ if (previousHome === undefined) {
716
+ delete process.env.HOME;
717
+ } else {
718
+ process.env.HOME = previousHome;
719
+ }
720
+ if (previousAgentDir === undefined) {
721
+ delete process.env.PI_CODING_AGENT_DIR;
722
+ } else {
723
+ process.env.PI_CODING_AGENT_DIR = previousAgentDir;
724
+ }
725
+ }
726
+ });
727
+
728
+ test("regenerateRegistry never re-indexes a filtered Pi skill from a loose root", async (t) => {
729
+ // A Pi-managed loose root (.pi/skills) still holds the SKILL.md of a skill
730
+ // Pi filtered out at runtime; the loose scan must not resurrect it as an
731
+ // active registry row.
732
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-suppressed-"));
733
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
734
+ const disabledPath = join(cwd, ".pi", "skills", "runtime-hidden", "SKILL.md");
735
+ const livePath = join(cwd, ".pi", "skills", "loose-live", "SKILL.md");
736
+ for (const [path, name, description] of [
737
+ [disabledPath, "runtime-hidden", "Hidden by runtime disablement."],
738
+ [livePath, "loose-live", "Loose live skill."],
739
+ ] as const) {
740
+ mkdirSync(dirname(path), { recursive: true });
741
+ writeFileSync(path, `---\nname: ${name}\ndescription: ${description}\n---\n`);
742
+ }
743
+
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);
754
+ 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/);
762
+ });
763
+
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()}`);
766
+ 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/);
780
+ });
781
+
782
+ function fakeSkillRegistryPi(getFlag: (name: string) => boolean = () => false) {
783
+ const handlers = new Map<string, Array<(event: unknown, ctx: unknown) => unknown>>();
784
+ const commands = new Map<string, { handler: (args: string, ctx: unknown) => Promise<void> }>();
785
+ const pi = {
786
+ on(event: string, handler: (event: unknown, ctx: unknown) => unknown) {
787
+ handlers.set(event, [...(handlers.get(event) ?? []), handler]);
788
+ },
789
+ registerFlag(_name: string, _registration: unknown) {},
790
+ registerCommand(name: string, registration: { handler: (args: string, ctx: unknown) => Promise<void> }) {
791
+ commands.set(name, registration);
792
+ },
793
+ getFlag,
794
+ } as unknown as ExtensionAPI;
795
+ return { pi, handlers, commands };
796
+ }
797
+
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
+ );
819
+ });
820
+
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
+ );
864
+ });
865
+
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
+ );
890
+ });
891
+
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)));
909
+ });
910
+
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";
915
+ const first: ResolvedSkill[] = [
916
+ { name: "duplicate", description: "Trigger: first entry.", filePath: alphaPath },
917
+ { name: "duplicate", description: "Trigger: second entry.", filePath: betaPath },
918
+ ];
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)));
957
+ });
958
+
959
+ test("before_agent_start rejects malformed batches and preserves prior resolved skills", async () => {
960
+ const cwd = join(tmpdir(), `gentle-pi-wire-malformed-batch-${Date.now()}`);
961
+ const skillPath = "/pkg/skills/valid-before-malformed/SKILL.md";
962
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
963
+ skillRegistryExtension(pi);
964
+ const handler = handlers.get("before_agent_start")?.[0];
965
+ const refresh = commands.get("skill-registry:refresh");
966
+ assert.ok(handler);
967
+ assert.ok(refresh);
968
+
969
+ await handler(
970
+ { systemPromptOptions: { skills: [{ name: "valid", description: "Valid runtime skill.", filePath: skillPath }] } },
971
+ { cwd, hasUI: false },
972
+ );
973
+ for (const skills of [
974
+ [
975
+ { name: "replacement-scope", description: "Must not partially apply.", filePath: "/pkg/skills/replacement-scope/SKILL.md" },
976
+ {
977
+ name: "invalid-scope",
978
+ description: "Invalid nested metadata.",
979
+ filePath: "/pkg/skills/invalid-scope/SKILL.md",
980
+ sourceInfo: { scope: 42 },
981
+ },
982
+ ],
983
+ [
984
+ { name: "replacement-origin", description: "Must not partially apply.", filePath: "/pkg/skills/replacement-origin/SKILL.md" },
985
+ {
986
+ name: "invalid-origin",
987
+ description: "Invalid nested metadata.",
988
+ filePath: "/pkg/skills/invalid-origin/SKILL.md",
989
+ sourceInfo: { origin: "invalid" },
990
+ },
991
+ ],
992
+ ]) {
993
+ writeFileSync(join(cwd, ".atl", "skill-registry.md"), "sentinel\n");
994
+ await handler({ systemPromptOptions: { skills } }, { cwd, hasUI: false });
995
+ await refresh.handler("", { cwd, hasUI: false, ui: { notify() {} } });
996
+
997
+ 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/);
1001
+ }
1002
+ });
1003
+
1004
+ test("watcher refresh retains captured runtime-resolved skills", { timeout: 5_000 }, async () => {
1005
+ const cwd = join(tmpdir(), `gentle-pi-watch-resolved-${Date.now()}`);
1006
+ const looseSkillPath = join(cwd, "skills", "loose", "SKILL.md");
1007
+ const resolvedPath = "/pkg/skills/watcher-retained/SKILL.md";
1008
+ mkdirSync(dirname(looseSkillPath), { recursive: true });
1009
+ writeFileSync(looseSkillPath, "---\nname: loose\ndescription: Before watcher refresh.\n---\n");
1010
+ await __testing.applyResolvedSkillsUpdate(cwd, [
1011
+ { name: "retained", description: "Runtime authority.", filePath: resolvedPath },
1012
+ ]);
1013
+
1014
+ let resolveRefresh: (() => void) | undefined;
1015
+ let timeout: ReturnType<typeof setTimeout> | undefined;
1016
+ const refreshed = new Promise<void>((resolve) => {
1017
+ resolveRefresh = resolve;
1018
+ });
1019
+ try {
1020
+ await __testing.startSkillRegistryWatcher(cwd, () => resolveRefresh?.());
1021
+ writeFileSync(looseSkillPath, "---\nname: loose\ndescription: After watcher refresh.\n---\n");
1022
+ await Promise.race([
1023
+ refreshed,
1024
+ new Promise<void>((_resolve, reject) => {
1025
+ timeout = setTimeout(() => reject(new Error("watcher did not refresh the registry")), 3_000);
1026
+ }),
1027
+ ]);
1028
+ } finally {
1029
+ if (timeout) clearTimeout(timeout);
1030
+ __testing.closeSkillRegistryWatchers();
1031
+ }
1032
+
1033
+ const registry = readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8");
1034
+ assert.match(registry, new RegExp(escapeRegExp(resolvedPath)));
1035
+ });
1036
+
1037
+ test("before_agent_start handler wires pi-resolved skills into the registry", async () => {
1038
+ // Happy path: the handler captures runtime-resolved skills for the session cwd.
1039
+ {
1040
+ const cwd = join(tmpdir(), `gentle-pi-wire-${Date.now()}`);
1041
+ const { pi, handlers } = fakeSkillRegistryPi();
1042
+ skillRegistryExtension(pi);
1043
+ const handler = handlers.get("before_agent_start")?.[0];
1044
+ assert.ok(handler, "default export must register a before_agent_start handler");
1045
+
1046
+ const skillPath = join(
1047
+ tmpdir(),
1048
+ `gentle-pi-wire-pkg-${Date.now()}`,
1049
+ "skills",
1050
+ "wired-skill",
1051
+ "SKILL.md",
1052
+ );
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)));
1071
+ }
1072
+
1073
+ // The no-skill-registry opt-out must leave the registry untouched.
1074
+ {
1075
+ const cwd = join(tmpdir(), `gentle-pi-wire-skip-${Date.now()}`);
1076
+ const { pi, handlers } = fakeSkillRegistryPi((name) => name === "no-skill-registry");
1077
+ skillRegistryExtension(pi);
1078
+ const handler = handlers.get("before_agent_start")?.[0];
1079
+ assert.ok(handler);
1080
+
1081
+ await handler(
1082
+ { systemPromptOptions: { skills: [{ name: "skipped", description: "S.", filePath: "/pkg/skills/skipped/SKILL.md" }] } },
1083
+ { cwd, hasUI: false },
1084
+ );
1085
+ assert.equal(
1086
+ existsSync(join(cwd, ".atl", "skill-registry.md")),
1087
+ false,
1088
+ "flagged opt-out must not write a registry",
1089
+ );
1090
+ }
1091
+
1092
+ // A non-array skills payload must be ignored entirely.
1093
+ {
1094
+ const cwd = join(tmpdir(), `gentle-pi-wire-malformed-${Date.now()}`);
1095
+ const { pi, handlers } = fakeSkillRegistryPi();
1096
+ skillRegistryExtension(pi);
1097
+ const handler = handlers.get("before_agent_start")?.[0];
1098
+ assert.ok(handler);
1099
+
1100
+ await handler(
1101
+ { systemPromptOptions: { skills: "not-an-array" } },
1102
+ { cwd, hasUI: false },
1103
+ );
1104
+ assert.equal(
1105
+ existsSync(join(cwd, ".atl", "skill-registry.md")),
1106
+ false,
1107
+ "non-array skills payload must not write a registry",
1108
+ );
1109
+ }
1110
+ });
1111
+
1112
+ test("startup regeneration keeps the resolved set captured before it settles", async (t) => {
1113
+ // Startup regeneration is scheduled by session_start and lands later; a
1114
+ // capture that already arrived is newer authority and must survive it.
1115
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-startup-authority-"));
1116
+ const packageRoot = mkdtempSync(join(tmpdir(), "gentle-pi-startup-authority-pkg-"));
1117
+ t.after(() => {
1118
+ rmSync(cwd, { recursive: true, force: true });
1119
+ rmSync(packageRoot, { recursive: true, force: true });
1120
+ });
1121
+ const loosePath = join(cwd, "skills", "loose", "SKILL.md");
1122
+ mkdirSync(dirname(loosePath), { recursive: true });
1123
+ writeFileSync(loosePath, "---\nname: loose\ndescription: Loose project skill.\n---\n");
1124
+ const resolvedPath = join(packageRoot, "skills", "runtime-authority", "SKILL.md");
1125
+
1126
+ const { pi, handlers } = fakeSkillRegistryPi();
1127
+ skillRegistryExtension(pi);
1128
+ const capture = handlers.get("before_agent_start")?.[0];
1129
+ const start = handlers.get("session_start")?.[0];
1130
+ assert.ok(capture, "default export must register a before_agent_start handler");
1131
+ assert.ok(start, "default export must register a session_start handler");
1132
+ const ctx = { cwd, hasUI: false };
1133
+
1134
+ await capture(
1135
+ {
1136
+ systemPromptOptions: {
1137
+ skills: [
1138
+ {
1139
+ name: "runtime-authority",
1140
+ description: "Trigger: runtime authority. Captured before startup settles.",
1141
+ filePath: resolvedPath,
1142
+ sourceInfo: { scope: "project", origin: "package" },
1143
+ },
1144
+ ],
1145
+ },
1146
+ },
1147
+ ctx,
1148
+ );
1149
+ await start(undefined, ctx);
1150
+ await __testing.startupSettled();
1151
+
1152
+ 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");
1154
+ 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
+ );
1159
+ });
1160
+
1161
+ test("manual /skill-registry:refresh keeps the captured resolved set", async () => {
1162
+ const cwd = join(tmpdir(), `gentle-pi-refresh-${Date.now()}`);
1163
+ const skillPath = join(tmpdir(), `gentle-pi-refresh-pkg-${Date.now()}`, "skills", "refreshed", "SKILL.md");
1164
+ const { pi, handlers, commands } = fakeSkillRegistryPi();
1165
+ skillRegistryExtension(pi);
1166
+ const handler = handlers.get("before_agent_start")?.[0];
1167
+ assert.ok(handler);
1168
+ const refresh = commands.get("skill-registry:refresh");
1169
+ assert.ok(refresh, "default export must register skill-registry:refresh");
1170
+
1171
+ await handler(
1172
+ {
1173
+ systemPromptOptions: {
1174
+ skills: [
1175
+ {
1176
+ name: "refreshed",
1177
+ description: "Trigger: refresh retention. Authority must survive a manual refresh.",
1178
+ filePath: skillPath,
1179
+ sourceInfo: { scope: "project", origin: "package" },
1180
+ },
1181
+ ],
1182
+ },
1183
+ },
1184
+ { cwd, hasUI: false },
1185
+ );
1186
+ assert.ok(existsSync(join(cwd, ".atl", "skill-registry.md")));
1187
+
1188
+ // A forced manual refresh must not drop the runtime-resolved authority.
1189
+ const notices: string[] = [];
1190
+ await refresh.handler("", { cwd, hasUI: true, ui: { notify: (text: string) => notices.push(text) } });
1191
+ 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
+ );
1197
+ assert.ok(notices.length > 0);
1198
+ });
1199
+
367
1200
  test("ensureAtlIgnored creates .atl/.gitignore with * and leaves root .gitignore untouched (#1387)", async (t) => {
368
1201
  const cwd = mkdtempSync(join(tmpdir(), `gentle-pi-git-atl-${Date.now()}-`));
369
1202
  t.after(() => rmSync(cwd, { recursive: true, force: true }));
@@ -749,7 +1582,7 @@ test("regenerateRegistry reports a typed unavailable result instead of throwing
749
1582
  rmSync(join(cwd, ".atl", "skill-registry.md"), { force: true });
750
1583
  rmSync(join(cwd, ".atl", ".skill-registry.cache.json"), { force: true });
751
1584
  chmodSync(join(cwd, ".atl"), 0o555);
752
- const result = await __testing.regenerateRegistry(cwd, true, true);
1585
+ const result = await __testing.regenerateRegistry(cwd, true, [], true);
753
1586
  assert.equal(result.regenerated, false, "a permission failure must never report success");
754
1587
  assert.equal(result.reason, "storage-unavailable");
755
1588
  assert.match(result.warning ?? "", /\.atl[/\\]skill-registry\.md/);
@@ -758,7 +1591,7 @@ test("regenerateRegistry reports a typed unavailable result instead of throwing
758
1591
  assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
759
1592
 
760
1593
  chmodSync(join(cwd, ".atl"), 0o755);
761
- const recovered = await __testing.regenerateRegistry(cwd, true, true);
1594
+ const recovered = await __testing.regenerateRegistry(cwd, true, [], true);
762
1595
  assert.equal(recovered.regenerated, true, "the registry must regenerate once storage is writable again");
763
1596
  });
764
1597
 
@@ -766,7 +1599,7 @@ test("regenerateRegistry degrades truthfully when .atl is a regular file", async
766
1599
  const cwd = mkdtempSync(join(tmpdir(), "gentle-skill-373-enotdir-"));
767
1600
  t.after(() => rmSync(cwd, { recursive: true, force: true }));
768
1601
  writeFileSync(join(cwd, ".atl"), "not a directory\n");
769
- const result = await __testing.regenerateRegistry(cwd, true, true);
1602
+ const result = await __testing.regenerateRegistry(cwd, true, [], true);
770
1603
  assert.equal(result.regenerated, false, "a non-directory .atl must never report success");
771
1604
  assert.equal(result.reason, "storage-unavailable");
772
1605
  assert.match(result.warning ?? "", /not writable/);
@@ -777,7 +1610,7 @@ test("regenerateRegistry preserves the diagnostic for unexpected I/O errors", as
777
1610
  t.after(() => rmSync(cwd, { recursive: true, force: true }));
778
1611
  symlinkSync(join(cwd, ".atl", "self"), join(cwd, ".atl"));
779
1612
  await assert.rejects(
780
- __testing.regenerateRegistry(cwd, true, true),
1613
+ __testing.regenerateRegistry(cwd, true, [], true),
781
1614
  /ELOOP/,
782
1615
  "unexpected I/O must keep its own diagnostic instead of a typed unavailable result",
783
1616
  );