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
@@ -20,7 +20,7 @@ import type {
20
20
  import { __testing, applyModelConfig, applyModelConfigAsync, createGentleAiExtension } from "../extensions/gentle-ai.ts";
21
21
  import { PROFILES_KIND, PROFILES_VERSION, bootstrapProfilesFile, readProfilesFileResult, type AgentProfilesFile } from "../lib/agent-profiles.ts";
22
22
  import { bindSessionProfile, readSessionProfileBinding, resetSessionProfileBindingsForTesting } from "../lib/session-profile-binding.ts";
23
- import { freezeSessionProfileAtStartup, resetFrozenInheritedProfilesForTesting } from "../lib/session-profile-freeze.ts";
23
+ import { freezeSessionProfileAtOwnStart, freezeSessionProfileAtStartup, resetFrozenInheritedProfilesForTesting } from "../lib/session-profile-freeze.ts";
24
24
  import { createSessionProfileBind, createSessionProfileClear, createSessionProfileStartupBind, SESSION_PROFILE_CUSTOM_TYPE } from "../lib/session-profile-persistence.ts";
25
25
  import { createSessionProfileIntegration, runCurrentSessionProfileSelection } from "../lib/session-profile-integration.ts";
26
26
  import { readSessionProfileAuthority } from "../lib/session-profile-authority.ts";
@@ -1371,6 +1371,13 @@ test("models screen render does not auto-apply the Gentle theme and sanitizes ag
1371
1371
  assert.doesNotMatch(plain, /\[31m/);
1372
1372
  });
1373
1373
 
1374
+ test("unconfigured review lenses show a missing model rather than inherited routing", () => {
1375
+ const plain = __testing.routingTablePanel({}, ["openai/gpt-5.5"], ["review-risk", "review-refuter", "worker"], 100, undefined, 40).map(stripAnsi).join("\n");
1376
+ assert.match(plain, /review-risk\s+not configured\s+off/);
1377
+ assert.match(plain, /worker\s+inherit\s+inherit/);
1378
+ assert.match(plain, /review-refuter\s+Pi default/);
1379
+ });
1380
+
1374
1381
  test("models screen fills the terminal height and keeps every line inside the frame", () => {
1375
1382
  const lines = renderScreen([], [], [], { width: 72, rows: 40 });
1376
1383
  assert.equal(lines.length, 40);
@@ -1876,11 +1883,11 @@ test(`${channel} emits only a private, balanced Herdr projection`, () => {
1876
1883
  registerTool() {},
1877
1884
  } as unknown as ExtensionAPI;
1878
1885
  createGentleAiExtension({ nativeReviewCli: null })(pi);
1879
- const privateHostDiscovery = "gentle:yolo:host-ui";
1880
- assert.equal(eventHandlers.has(privateHostDiscovery), true);
1881
- assert.deepEqual([...eventHandlers.keys()].filter(name => name !== privateHostDiscovery).sort(), [
1886
+ const privateHostDiscovery = new Set(["gentle:yolo:host-ui", "gentle:rdd:host-ui"]);
1887
+ for (const channel of privateHostDiscovery) assert.equal(eventHandlers.has(channel), true);
1888
+ assert.deepEqual([...eventHandlers.keys()].filter(name => !privateHostDiscovery.has(name)).sort(), [
1882
1889
  "gentle-pi:ask-user-choice:blocked", "gentle-pi:ask-user-question:blocked", "rpiv:ask-user:blocked",
1883
- ], "only the original three blocked channels remain besides the known private host adapter");
1890
+ ], "only the original three blocked channels remain besides the known private host adapters");
1884
1891
  assert.deepEqual(published, [], "registering host discovery emits no public event or private payload");
1885
1892
  assert.equal(eventHandlers.has("gentle-pi:ask-user-choice:blocked"), true);
1886
1893
  assert.equal(eventHandlers.has("rpiv:ask-user:blocked"), true);
@@ -1894,7 +1901,9 @@ test(`${channel} emits only a private, balanced Herdr projection`, () => {
1894
1901
  command: "private questionnaire command",
1895
1902
  arbitrary: { nested: "private questionnaire field" },
1896
1903
  };
1897
- eventHandlers.get(privateHostDiscovery)!(source);
1904
+ for (const discoveryChannel of privateHostDiscovery) {
1905
+ eventHandlers.get(discoveryChannel)!(source);
1906
+ }
1898
1907
  assert.deepEqual(published, [], "private discovery ignores questionnaire data instead of relaying it");
1899
1908
  assert.deepEqual(herdrEvents, []);
1900
1909
  pi.events.emit(channel, source);
@@ -2322,6 +2331,10 @@ function profilesStoreFixture(t: test.TestContext) {
2322
2331
  for (const dir of [pinRoot, pinCommonDir]) mkdirSync(dir, { recursive: true });
2323
2332
  setProfilePinWorktreeResolverForTesting(() => ({ root: pinRoot, commonDir: pinCommonDir }));
2324
2333
  t.after(() => setProfilePinWorktreeResolverForTesting());
2334
+ // Fixture-level teardown ensures binding resets only run for profiles-panel tests,
2335
+ // rather than suite-level hooks running across 100+ unrelated tests in this file (#1768).
2336
+ resetSessionProfileBindingsForTesting();
2337
+ t.after(() => resetSessionProfileBindingsForTesting());
2325
2338
  const writePin = (path: string, profile: string) => {
2326
2339
  mkdirSync(dirname(path), { recursive: true });
2327
2340
  writeFileSync(path, `${JSON.stringify({ kind: PROFILE_PIN_KIND, version: PROFILE_PIN_VERSION, profile }, null, 2)}\n`);
@@ -2683,6 +2696,29 @@ test("applying a populated profile whose routes already match skips the confirma
2683
2696
  assert.equal(readFileSync(settingsPath, "utf8"), settingsBefore, "settings.json is untouched");
2684
2697
  });
2685
2698
 
2699
+ test("applying an already-matching active profile ignores legacy project routes in the confirmation diff", async (t) => {
2700
+ const { fixture, storePath, writeStore, writeSettings, settingsPath } = profilesStoreFixture(t);
2701
+ writeSettings();
2702
+ mkdirSync(fixture.configHome, { recursive: true });
2703
+ writeFileSync(fixture.globalPath, `${JSON.stringify({ worker: { model: "openai/gpt-5" } }, null, 2)}\n`);
2704
+ writeFileSync(fixture.projectPath, `${JSON.stringify({ "review-risk": { model: "openai/legacy" } }, null, 2)}\n`);
2705
+ const workerPath = join(fixture.root, ".pi", "agents", "worker.md");
2706
+ const reviewerPath = join(fixture.root, ".pi", "agents", "review-risk.md");
2707
+ writeMarkdown(reviewerPath, "---\nname: review-risk\ndescription: Reviewer\n---\nbody\n");
2708
+ writeStore({ team: { worker: { model: "openai/gpt-5" } } }, "team");
2709
+ const paths = [fixture.globalPath, fixture.projectPath, storePath, settingsPath, reviewerPath];
2710
+ const before = paths.map((path) => readFileSync(path, "utf8"));
2711
+
2712
+ applyOnce(fixture);
2713
+ await fixture.run("gentle:profiles");
2714
+
2715
+ assert.equal(fixture.confirmCalls.length, 0, "legacy routes outside the active profile must not produce a false clearing diff");
2716
+ assert.ok(fixture.notifications.some((entry) => entry.severity === "info" && /already matches the current global routing/.test(entry.message)));
2717
+ assert.deepEqual(paths.map((path) => readFileSync(path, "utf8")), before, "global, legacy, profile, settings, and the omitted agent stay byte-identical");
2718
+ assert.match(readFileSync(workerPath, "utf8"), /model: openai\/gpt-5/, "the apply still materializes the profile's own route");
2719
+ assert.doesNotMatch(readFileSync(reviewerPath, "utf8"), /openai\/legacy/, "the omitted legacy route is never materialized");
2720
+ });
2721
+
2686
2722
  test("applying a populated profile whose routes match and whose orchestrator is already set skips the confirmation", async (t) => {
2687
2723
  const { fixture, storePath, writeStore, writeSettings } = profilesStoreFixture(t);
2688
2724
  // writeSettings defaults to nan/deepseek-v4-flash · high; the profile's
@@ -3213,7 +3249,6 @@ function chooseAgent(panel: RoutingConsumerPanel, agent: string): void {
3213
3249
  test("models screen saves the explicit orchestrator choice into the profile", async (t) => {
3214
3250
  const { fixture, storePath, settingsPath, writeStore, writeSettings } = profilesStoreFixture(t);
3215
3251
  // Use in this session binds the fixture session in a process-wide store.
3216
- t.after(() => resetSessionProfileBindingsForTesting());
3217
3252
  writeSettings();
3218
3253
  const settingsBefore = readFileSync(settingsPath, "utf8");
3219
3254
  fixture.setLiveModel("openai", "alpha", "high");
@@ -3258,7 +3293,6 @@ test("models screen saves the explicit orchestrator choice into the profile", as
3258
3293
 
3259
3294
  test("models screen leave untouched removes a stale profile orchestrator and keeps the live model on use", async (t) => {
3260
3295
  const { fixture, storePath, settingsPath, writeStore, writeSettings } = profilesStoreFixture(t);
3261
- t.after(() => resetSessionProfileBindingsForTesting());
3262
3296
  writeSettings();
3263
3297
  const settingsBefore = readFileSync(settingsPath, "utf8");
3264
3298
  fixture.setLiveModel("openai", "alpha", "low");
@@ -4197,7 +4231,6 @@ test("Enter switches the live orchestrator, binds the profile, and writes nothin
4197
4231
  store: readFileSync(storePath, "utf8"),
4198
4232
  settings: readFileSync(settingsPath, "utf8"),
4199
4233
  };
4200
- resetSessionProfileBindingsForTesting();
4201
4234
  const notifications: Array<{ message: string; severity: string }> = [];
4202
4235
  const manager = profileActionManager(fixture.root);
4203
4236
  const ctx = {
@@ -4234,7 +4267,6 @@ test("Enter switches the live orchestrator, binds the profile, and writes nothin
4234
4267
  assert.match(applied, /Subagents and reviewers use this session's routing snapshot/);
4235
4268
  assert.match(applied, /global routing, pins, and materialized stores are untouched/);
4236
4269
  assert.doesNotMatch(applied, /launch routing is unchanged/);
4237
- resetSessionProfileBindingsForTesting();
4238
4270
  });
4239
4271
 
4240
4272
  test("Enter switches only the selecting session's orchestrator and leaves shared defaults untouched", async (t) => {
@@ -4243,8 +4275,6 @@ test("Enter switches only the selecting session's orchestrator and leaves shared
4243
4275
  writeStore({ team: { orchestrator: { model: "openai/alpha", thinking: "high" }, worker: { model: "openai/beta" } }, old: {} }, "old");
4244
4276
  const beforeStore = readFileSync(storePath, "utf8");
4245
4277
  const beforeSettings = readFileSync(settingsPath, "utf8");
4246
- resetSessionProfileBindingsForTesting();
4247
- t.after(() => resetSessionProfileBindingsForTesting());
4248
4278
  bindSessionProfile("other-session", "old", { worker: { model: "openai/old" } });
4249
4279
  const switches: string[] = [];
4250
4280
  const thinking: ThinkingLevel[] = [];
@@ -4278,7 +4308,6 @@ test("reviewer routing uses the selecting session snapshot without leaking to ot
4278
4308
  writeStore({ team: {} });
4279
4309
  mkdirSync(fixture.configHome, { recursive: true });
4280
4310
  writeFileSync(fixture.globalPath, JSON.stringify({ "review-risk": { model: "openai/global" }, "review-reliability": { model: "openai/global" } }));
4281
- resetSessionProfileBindingsForTesting();
4282
4311
  resetFrozenInheritedProfilesForTesting();
4283
4312
  t.after(() => { resetSessionProfileBindingsForTesting(); resetFrozenInheritedProfilesForTesting(); });
4284
4313
  bindSessionProfile("selecting-session", "team", { "review-risk": { model: "openai/session", thinking: "high" } });
@@ -4291,7 +4320,6 @@ test("reviewer routing uses the selecting session snapshot without leaking to ot
4291
4320
 
4292
4321
  test("reviewer routing follows the profile the session froze at startup, not later global routing", (t) => {
4293
4322
  const { fixture, writeStore } = profilesStoreFixture(t);
4294
- resetSessionProfileBindingsForTesting();
4295
4323
  resetFrozenInheritedProfilesForTesting();
4296
4324
  t.after(() => resetFrozenInheritedProfilesForTesting());
4297
4325
  writeStore({ sol: { "review-risk": { model: "openai/sol" } } }, "sol");
@@ -4305,8 +4333,6 @@ test("provider review roles fall back to the session profile orchestrator before
4305
4333
  const { writeStore, writeSettings } = profilesStoreFixture(t);
4306
4334
  writeStore({ sol: {} }, "sol");
4307
4335
  writeSettings({ defaultProvider: "nan", defaultModel: "flash" });
4308
- resetSessionProfileBindingsForTesting();
4309
- t.after(() => resetSessionProfileBindingsForTesting());
4310
4336
  bindSessionProfile("bound-session", "sol", { orchestrator: { model: "openai/sol", thinking: "high" }, "review-validator": { model: "openai/validator" } });
4311
4337
  const routing = __testing.readReviewerModelConfig(process.cwd(), "bound-session");
4312
4338
  assert.deepEqual(__testing.reviewHostRelaySelection("review-refuter", routing), { selection: "openai/sol", thinking: "high", routingKey: "review-refuter" });
@@ -4317,7 +4343,6 @@ test("provider review roles fall back to the session profile orchestrator before
4317
4343
 
4318
4344
  test("provider review roles skip the orchestrator fallback for an inherited profile", (t) => {
4319
4345
  const { fixture, writeStore, writeSettings } = profilesStoreFixture(t);
4320
- resetSessionProfileBindingsForTesting();
4321
4346
  resetFrozenInheritedProfilesForTesting();
4322
4347
  t.after(() => resetFrozenInheritedProfilesForTesting());
4323
4348
  // Inherited routing drops the orchestrator key, so only Use in this session feeds the fallback.
@@ -4329,9 +4354,22 @@ test("provider review roles skip the orchestrator fallback for an inherited prof
4329
4354
  assert.equal(__testing.reviewHostRelaySelection("review-refuter", routing).selection, "nan/flash");
4330
4355
  });
4331
4356
 
4357
+ // gentle-shell#2742, section 8: only a startup record carries the orchestrator;
4358
+ // a freeze at the session's own start knows the definition but records nothing.
4359
+ test("provider review roles skip the orchestrator fallback for a profile frozen at the session's own start", (t) => {
4360
+ const { fixture, writeStore, writeSettings } = profilesStoreFixture(t);
4361
+ resetFrozenInheritedProfilesForTesting();
4362
+ t.after(() => resetFrozenInheritedProfilesForTesting());
4363
+ writeStore({ sol: { orchestrator: { model: "openai/sol" }, "review-risk": { model: "openai/sol-risk" } } }, "sol");
4364
+ writeSettings({ defaultProvider: "nan", defaultModel: "flash" });
4365
+ freezeSessionProfileAtOwnStart({ sessionId: "own-start-session", cwd: fixture.root, configHome: fixture.configHome });
4366
+ const routing = __testing.readReviewerModelConfig(fixture.root, "own-start-session");
4367
+ assert.equal(__testing.reviewHostRelaySelection("risk", routing).selection, "openai/sol-risk");
4368
+ assert.equal(__testing.reviewHostRelaySelection("review-validator", routing).selection, "nan/flash");
4369
+ });
4370
+
4332
4371
  test("provider review roles skip the orchestrator fallback for a repository pin", (t) => {
4333
4372
  const { fixture, writeStore, writeSettings, localPinPath, writePin } = profilesStoreFixture(t);
4334
- resetSessionProfileBindingsForTesting();
4335
4373
  resetFrozenInheritedProfilesForTesting();
4336
4374
  t.after(() => resetFrozenInheritedProfilesForTesting());
4337
4375
  // Pinned routing drops the orchestrator key, so the pin's own orchestrator never feeds the fallback.
@@ -4346,7 +4384,6 @@ test("provider review roles skip the orchestrator fallback for a repository pin"
4346
4384
 
4347
4385
  test("reviewer routing keeps a frozen pin snapshot after the pin changes", (t) => {
4348
4386
  const { fixture, writeStore, writeSettings, localPinPath, writePin } = profilesStoreFixture(t);
4349
- resetSessionProfileBindingsForTesting();
4350
4387
  resetFrozenInheritedProfilesForTesting();
4351
4388
  t.after(() => resetFrozenInheritedProfilesForTesting());
4352
4389
  writeStore({
@@ -4365,7 +4402,6 @@ test("reviewer routing keeps a frozen pin snapshot after the pin changes", (t) =
4365
4402
 
4366
4403
  test("reviewer routing of a session frozen without a profile ignores a pin added later", (t) => {
4367
4404
  const { fixture, writeStore, localPinPath, writePin } = profilesStoreFixture(t);
4368
- resetSessionProfileBindingsForTesting();
4369
4405
  resetFrozenInheritedProfilesForTesting();
4370
4406
  t.after(() => resetFrozenInheritedProfilesForTesting());
4371
4407
  writeStore({ later: { "review-risk": { model: "openai/later-risk" } } });
@@ -4378,7 +4414,6 @@ test("reviewer routing of a session frozen without a profile ignores a pin added
4378
4414
 
4379
4415
  test("reviewer routing in follow mode reads the profile the target resolves now", (t) => {
4380
4416
  const { fixture, writeStore, localPinPath, writePin } = profilesStoreFixture(t);
4381
- resetSessionProfileBindingsForTesting();
4382
4417
  resetFrozenInheritedProfilesForTesting();
4383
4418
  const previous = process.env.GENTLE_PI_PROFILE_FOLLOW;
4384
4419
  process.env.GENTLE_PI_PROFILE_FOLLOW = "1";
@@ -4397,7 +4432,6 @@ test("reviewer routing in follow mode reads the profile the target resolves now"
4397
4432
 
4398
4433
  test("provider review roles ignore an orchestrator saved in global routing", (t) => {
4399
4434
  const { fixture, writeStore, writeSettings } = profilesStoreFixture(t);
4400
- resetSessionProfileBindingsForTesting();
4401
4435
  resetFrozenInheritedProfilesForTesting();
4402
4436
  writeStore({ team: {} });
4403
4437
  writeSettings({ defaultProvider: "nan", defaultModel: "flash" });
@@ -4410,7 +4444,6 @@ test("provider review roles ignore an orchestrator saved in global routing", (t)
4410
4444
 
4411
4445
  test("reviewer routing of a session frozen without a profile uses a foreign repository's own pin", (t) => {
4412
4446
  const { fixture, writeStore } = profilesStoreFixture(t);
4413
- resetSessionProfileBindingsForTesting();
4414
4447
  resetFrozenInheritedProfilesForTesting();
4415
4448
  t.after(() => resetFrozenInheritedProfilesForTesting());
4416
4449
  const foreignRoot = join(fixture.root, "foreign");
@@ -4431,7 +4464,6 @@ test("reviewer routing of a session frozen without a profile uses a foreign repo
4431
4464
 
4432
4465
  test("reviewer routing of a session started outside Git uses the target repository's pin", (t) => {
4433
4466
  const { fixture, writeStore } = profilesStoreFixture(t);
4434
- resetSessionProfileBindingsForTesting();
4435
4467
  resetFrozenInheritedProfilesForTesting();
4436
4468
  t.after(() => resetFrozenInheritedProfilesForTesting());
4437
4469
  const repoRoot = join(fixture.root, "repo");
@@ -4458,8 +4490,6 @@ test("Enter preserves session-only routing when the orchestrator is absent or ca
4458
4490
  } }, undefined);
4459
4491
  const storeBefore = readFileSync(storePath, "utf8");
4460
4492
  const settingsBefore = readFileSync(settingsPath, "utf8");
4461
- resetSessionProfileBindingsForTesting();
4462
- t.after(() => resetSessionProfileBindingsForTesting());
4463
4493
  const notifications: string[] = [];
4464
4494
  let modelCalls = 0;
4465
4495
  let thinkingCalls = 0;
@@ -4493,7 +4523,6 @@ test("u keeps the session binding when a subagent launch requires session profil
4493
4523
  const { fixture, storePath, writeStore, writeSettings } = profilesStoreFixture(t);
4494
4524
  writeSettings();
4495
4525
  writeStore({ team: { worker: { model: "openai/alpha" } } }, "team");
4496
- resetSessionProfileBindingsForTesting();
4497
4526
  const manager = profileActionManager(fixture.root);
4498
4527
  const notifications: Array<{ message: string; severity: string }> = [];
4499
4528
  const ctx = {
@@ -4520,7 +4549,6 @@ test("u keeps the session binding when a subagent launch requires session profil
4520
4549
  "the session binding was dropped by the first subagent launch",
4521
4550
  );
4522
4551
  assert.equal(authority.binding?.name, "team", "authority does not publish the bound profile");
4523
- resetSessionProfileBindingsForTesting();
4524
4552
  });
4525
4553
 
4526
4554
  test("a reload landing while a models screen step is in flight closes the loop without touching the stale ctx", async (t) => {
@@ -4566,8 +4594,6 @@ test("a reload landing while a models screen step is in flight closes the loop w
4566
4594
  test("Enter skipped by a session replacement while queued never touches the stale ctx", async (t) => {
4567
4595
  const { fixture, storePath, writeStore } = profilesStoreFixture(t);
4568
4596
  writeStore({ team: { worker: { model: "openai/alpha" } } }, undefined);
4569
- resetSessionProfileBindingsForTesting();
4570
- t.after(() => resetSessionProfileBindingsForTesting());
4571
4597
  const manager = profileActionManager(fixture.root);
4572
4598
  let stale = false;
4573
4599
  const notifications: string[] = [];
@@ -4833,6 +4859,26 @@ test("clear after a resume with no conversation writes a legacy clear, not the r
4833
4859
  assert.match(h.last().message, /^el Gentleman cleared session profile "fast" . persisted in this session\. New launches use the routing without a session profile \(pins, repository declaration, global\)\. The live orchestrator is unchanged\.$/);
4834
4860
  });
4835
4861
 
4862
+ // gentle-shell#2742, section 8: the startup record carries the orchestrator for
4863
+ // the reviewers, but an inherited profile still does not switch the live one.
4864
+ test("a resume on a startup record with an orchestrator leaves the live orchestrator alone; Use in this session switches it", async (t) => {
4865
+ const h = profilesCommandHarness(t, withFast);
4866
+ resetFrozenInheritedProfilesForTesting();
4867
+ t.after(() => resetFrozenInheritedProfilesForTesting());
4868
+ const sessions = join(h.ctx.cwd, "resumed-startup-sessions");
4869
+ const source = SessionManager.create(h.ctx.cwd, sessions);
4870
+ source.appendCustomEntry(SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileStartupBind("local", "team", TEAM_DEFINITION));
4871
+ source.appendMessage({ role: "user", content: "flush the resumed fixture", timestamp: 1 });
4872
+ const manager = SessionManager.open(source.getSessionFile()!, sessions);
4873
+ const ctx = { ...h.ctx, sessionManager: manager } as unknown as ExtensionCommandContext;
4874
+ await h.start({ type: "session_start", reason: "resume" }, ctx);
4875
+ assert.deepEqual(readSessionProfileBinding(manager.getSessionId())?.modelProfiles.orchestrator, TEAM_DEFINITION.orchestrator, "the resumed record carries the orchestrator");
4876
+ assert.deepEqual(h.liveCalls, [], "the inherited profile does not switch the live orchestrator");
4877
+ const live = { setModel: async () => { h.liveCalls.push("model"); return true; }, setThinkingLevel() { h.liveCalls.push("thinking"); }, getThinkingLevel: (): ThinkingLevel => "medium" };
4878
+ await __testing.runProfilesPanelAction(ctx, live, h.storePath, readValidProfilesStore(h.storePath), { type: "use-session", name: "team" }, {});
4879
+ assert.ok(h.liveCalls.includes("model"), "Use in this session does switch it");
4880
+ });
4881
+
4836
4882
  test("clear after a session's own start goes back to the defaults it started with", async (t) => {
4837
4883
  const h = profilesCommandHarness(t, withFast);
4838
4884
  resetFrozenInheritedProfilesForTesting();
@@ -4953,6 +4999,43 @@ for (const reason of ["startup", "new"] as const) {
4953
4999
  });
4954
5000
  }
4955
5001
 
5002
+ // gentle-shell#2742, section 3: a session still on the startup state its own
5003
+ // start froze is already where a clear would go, even with no profile record.
5004
+ for (const [subject, active, notice] of [
5005
+ ["a startup profile", "team", 'el Gentleman: this session is already on the profile it started with, "team"; nothing to clear.'],
5006
+ ["no startup profile", undefined, "el Gentleman: this session is already on no profile, as it started; nothing to clear."],
5007
+ ] as const) {
5008
+ test(`clear right after a session's own start with ${subject} says it is already there and writes nothing`, async (t) => {
5009
+ const h = profilesCommandHarness(t, withFast);
5010
+ resetFrozenInheritedProfilesForTesting();
5011
+ t.after(() => resetFrozenInheritedProfilesForTesting());
5012
+ writeFileSync(h.storePath, `${JSON.stringify({ kind: PROFILES_KIND, version: PROFILES_VERSION, profiles: withFast, ...(active ? { active } : {}) }, null, 2)}\n`);
5013
+ const manager = SessionManager.create(h.ctx.cwd, join(h.ctx.cwd, "own-start-noop-sessions"));
5014
+ const ctx = { ...h.ctx, sessionManager: manager } as unknown as ExtensionCommandContext;
5015
+ await h.start({ type: "session_start", reason: "startup" }, ctx);
5016
+ const entries = manager.getEntries().length;
5017
+ await h.run("clear", ctx);
5018
+ assert.equal(manager.getEntries().length, entries, "the transcript gains no entry");
5019
+ assert.equal(h.last().severity, "info");
5020
+ assert.equal(h.last().message, notice);
5021
+ });
5022
+ }
5023
+
5024
+ test("clear on a never-bound session whose startup state is unknown keeps the never-selected notice", async (t) => {
5025
+ const h = profilesCommandHarness(t, withFast);
5026
+ resetFrozenInheritedProfilesForTesting();
5027
+ t.after(() => resetFrozenInheritedProfilesForTesting());
5028
+ writeFileSync(h.storePath, `${JSON.stringify({ kind: PROFILES_KIND, version: PROFILES_VERSION, profiles: withFast, active: "team" }, null, 2)}\n`);
5029
+ const manager = SessionManager.create(h.ctx.cwd, join(h.ctx.cwd, "resumed-noop-sessions"));
5030
+ const ctx = { ...h.ctx, sessionManager: manager } as unknown as ExtensionCommandContext;
5031
+ await h.start({ type: "session_start", reason: "resume" }, ctx);
5032
+ const entries = manager.getEntries().length;
5033
+ await h.run("clear", ctx);
5034
+ assert.equal(manager.getEntries().length, entries, "the transcript gains no entry");
5035
+ assert.equal(h.last().severity, "info");
5036
+ assert.equal(h.last().message, "el Gentleman: no session profile was ever selected in this session; nothing to clear.");
5037
+ });
5038
+
4956
5039
  test("/gentle:profiles clear without a parent session id fails loud and writes nothing", async (t) => {
4957
5040
  const h = profilesCommandHarness(t);
4958
5041
  (h.ctx as unknown as { sessionManager: unknown }).sessionManager = { getSessionId: () => "" };
@@ -5004,7 +5087,6 @@ test("a keeps the legacy global apply semantics", async (t) => {
5004
5087
  await __testing.runProfilesPanelAction(ctx, live, storePath, file, { type: "apply-global", name: "team", config: file.profiles["team"] }, {});
5005
5088
  assert.equal(JSON.parse(readFileSync(storePath, "utf8")).active, "team", "the global store claims the profile");
5006
5089
  assert.ok(existsSync(fixture.globalPath), "the global routing is materialized");
5007
- resetSessionProfileBindingsForTesting();
5008
5090
  });
5009
5091
 
5010
5092
  test("Enter with a winning pin binds the session and never touches the pin layers", async (t) => {
@@ -5013,7 +5095,6 @@ test("Enter with a winning pin binds the session and never touches the pin layer
5013
5095
  writePin(localPinPath, "old");
5014
5096
  const pinBefore = readFileSync(localPinPath, "utf8");
5015
5097
  const storeBefore = readFileSync(storePath, "utf8");
5016
- resetSessionProfileBindingsForTesting();
5017
5098
  const manager = profileActionManager(fixture.root);
5018
5099
  const ctx = {
5019
5100
  cwd: fixture.root,
@@ -5028,13 +5109,11 @@ test("Enter with a winning pin binds the session and never touches the pin layer
5028
5109
  assert.equal(readFileSync(localPinPath, "utf8"), pinBefore, "the clone pin is untouched");
5029
5110
  assert.equal(readFileSync(storePath, "utf8"), storeBefore, "the store is untouched");
5030
5111
  assert.equal(existsSync(fixture.globalPath), false);
5031
- resetSessionProfileBindingsForTesting();
5032
5112
  });
5033
5113
 
5034
5114
  test("a session-bound profile carries ◉ and says it is used in this session", async (t) => {
5035
5115
  const { fixture, writeStore } = profilesStoreFixture(t);
5036
5116
  writeStore({ team: { worker: { model: "openai/beta" } }, other: {} }, "team");
5037
- t.after(() => resetSessionProfileBindingsForTesting());
5038
5117
  bindSessionProfile("session-panel", "team", { worker: { model: "openai/gamma" } });
5039
5118
  let rendered = "";
5040
5119
  fixture.onInput((panel) => {
@@ -5066,7 +5145,6 @@ test("Enter without a parent session id fails loud and writes nothing", async (t
5066
5145
  assert.equal(readFileSync(storePath, "utf8"), before);
5067
5146
  assert.equal(existsSync(fixture.globalPath), false);
5068
5147
  assert.equal(notifications.at(-1)?.severity, "warning");
5069
- resetSessionProfileBindingsForTesting();
5070
5148
  });
5071
5149
 
5072
5150
  // gentle-shell#1064 slice 3c: the routing screen shows the profile this session launches with.
@@ -5113,7 +5191,6 @@ test("a frozen profile is not marked as used while session profile authority is
5113
5191
  assert.doesNotMatch(rendered, /◉|Used in this session\./);
5114
5192
  assert.ok(flatScreen(rendered).includes(authorityNotice), "the whole notice fits at 40 columns");
5115
5193
 
5116
- t.after(() => resetSessionProfileBindingsForTesting());
5117
5194
  actOnProfile(fixture, "u", "team");
5118
5195
  await fixture.run("gentle:profiles");
5119
5196
  const recovered = fixture.panels.at(-1) ?? "";
@@ -5161,7 +5238,6 @@ test("a session profile edited in profiles.json after the freeze or the binding
5161
5238
  assert.equal(savedRoutingNotice(await openedScreen(fixture, 40), "team"), true, "the whole notice fits at 40 columns");
5162
5239
 
5163
5240
  resetFrozenInheritedProfilesForTesting();
5164
- t.after(() => resetSessionProfileBindingsForTesting());
5165
5241
  bindSessionProfile("session-panel", "team", { worker: { model: "openai/alpha" } });
5166
5242
  assert.equal(savedRoutingNotice(await openedScreen(fixture), "team"), true);
5167
5243
  });
@@ -5169,7 +5245,6 @@ test("a session profile edited in profiles.json after the freeze or the binding
5169
5245
  test("an Enter binding opens on its profile while another is the default (#2451)", async (t) => {
5170
5246
  const { fixture, writeStore } = profilesStoreFixture(t);
5171
5247
  writeStore({ team: { worker: { model: "openai/alpha" } }, other: { worker: { model: "openai/beta" } } }, "other");
5172
- t.after(() => resetSessionProfileBindingsForTesting());
5173
5248
  bindSessionProfile("session-panel", "team", { worker: { model: "openai/alpha" } });
5174
5249
  const rendered = await openedScreen(fixture);
5175
5250
  assert.match(screenTabLine(rendered), /team ◉(\s|$)/);
@@ -1057,6 +1057,7 @@ test("gentle_design implement fails on an unknown target and reports an invalid
1057
1057
 
1058
1058
  const DESIGN_HINT = [
1059
1059
  "Gentle Design: any request for a UI design, mockup, screen, landing page or visual directions uses the gentle-design skill by default; read the skill first when it is not loaded.",
1060
+ "Pair it with the gentle-ui-design skill for UX quality: read that skill and only the references relevant to the brief before choosing directions.",
1060
1061
  'Before designing, call the gentle_design tool (action "list"); when the project has design sources but no design/system.md, run the skill\'s design system sync first.',
1061
1062
  'After writing or changing a design, open or refresh it on the canvas with the gentle_design tool (action "open" with the slug), unless the user said not to.',
1062
1063
  "Designs stay under design/<slug>/.",
@@ -1100,6 +1101,26 @@ test("the skill triggers on natural-language design requests and opens the canva
1100
1101
  assert.match(source, /`\/gentle:design`[^\n]*optional shortcuts/);
1101
1102
  });
1102
1103
 
1104
+ test("the artboard workflow loads gentle-ui-design before choosing directions and self-checks against it", () => {
1105
+ const source = readFileSync(SKILL_PATH, "utf8");
1106
+ const steps = source.slice(source.indexOf("## Execution Steps"), source.indexOf("\n## ", source.indexOf("## Execution Steps") + 1));
1107
+ const load = steps.search(/`gentle-ui-design`/);
1108
+ assert.ok(load !== -1, "the steps load gentle-ui-design");
1109
+ assert.ok(load < steps.indexOf("Make the directions differ"), "it loads before the directions are chosen");
1110
+ assert.match(steps, /audience, primary job, (and )?success condition/);
1111
+ const check = steps.search(/UX self-check[^\n]*composition-and-feedback[^\n]*adaptive-interfaces/);
1112
+ assert.ok(check !== -1, "every artboard is self-checked against the UX guidance");
1113
+ assert.ok(check < steps.indexOf('action: "open"'), "the UX self-check runs before the canvas opens");
1114
+ });
1115
+
1116
+ test("gentle-ui-design pairs with gentle-design instead of deferring to it", () => {
1117
+ const source = readFileSync(fileURLToPath(new URL("../skills/gentle-ui-design/SKILL.md", import.meta.url)), "utf8");
1118
+ const activation = source.slice(source.indexOf("## Activation Contract"), source.indexOf("\n## ", source.indexOf("## Activation Contract") + 1));
1119
+ assert.match(activation, /Pair with `gentle-design`[^\n]*gentle-design owns delivery[^\n]*this skill owns UX quality/);
1120
+ assert.doesNotMatch(activation, /Use `gentle-design` for its HTML artboard workflow/);
1121
+ assert.match(activation, /`gentle-ai-tui-design` for terminal interfaces/);
1122
+ });
1123
+
1103
1124
  test("the skill's Before designing gate lists first, syncs automatically, and offers a re-sync when stale", () => {
1104
1125
  const source = readFileSync(SKILL_PATH, "utf8");
1105
1126
  const start = source.indexOf("## Before designing");
@@ -1,17 +1,20 @@
1
1
  import assert from "node:assert/strict";
2
- import test from "node:test";
3
- import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
4
- import { resolve, join } from "node:path";
2
+ import test, { after } from "node:test";
3
+ import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
5
6
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
6
7
  import { createHerdrActivityExtension } from "../extensions/gentle-herdr-activity.ts";
7
8
  import { oddPhaseRegistry } from "../lib/odd-phase.ts";
8
9
  import { herdrAgentLabel, metadataArgs } from "../lib/herdr-activity.ts";
9
10
 
10
11
  type Handler = (event: any, ctx: ExtensionContext) => void;
12
+ // Config homes live under the system temp directory, never inside the worktree.
13
+ const scratch = mkdtempSync(join(tmpdir(), "gentle-herdr-activity-"));
14
+ after(() => rmSync(scratch, { recursive: true, force: true }));
15
+
11
16
  function harness(overrides: NodeJS.ProcessEnv = {}, socket = true) {
12
- const home = resolve("odd/work/herdr-auto-apply-B/activity");
13
- mkdirSync(home, { recursive: true });
14
- const configHome = mkdtempSync(join(home, "session-"));
17
+ const configHome = mkdtempSync(join(scratch, "session-"));
15
18
  const subscribers = new Set<(data: unknown) => void>();
16
19
  const handlers = new Map<string, Handler>();
17
20
  const values: Array<string | null> = [];
@@ -86,6 +86,30 @@ test("a genuinely absent adjacent peer falls back to PATH", (t) => {
86
86
  assert.match(result.stdout, /pi 1\.2\.1/);
87
87
  });
88
88
 
89
+ test("a bundled runtime launch performs zero real version-probe spawns", (t) => {
90
+ const f = standaloneLauncher(t);
91
+ const peer = join(f.root, "node_modules", "@earendil-works", "pi-coding-agent");
92
+ mkdirSync(join(peer, "dist", "bundle"), { recursive: true });
93
+ writeFileSync(join(peer, "dist", "index.js"), "");
94
+ writeFileSync(join(peer, "package.json"), JSON.stringify({
95
+ name: "@earendil-works/pi-coding-agent", type: "module", version: "1.2.5",
96
+ exports: { ".": { import: "./dist/index.js" } }, bin: { pi: "dist/bundle/cli.js" },
97
+ }));
98
+ const log = join(f.root, "version-probes.log");
99
+ writeFileSync(log, "");
100
+ writeFileSync(join(peer, "dist", "bundle", "cli.js"), [
101
+ "import { appendFileSync } from 'node:fs';",
102
+ "const args = process.argv.slice(2);",
103
+ `if (args.length === 1 && args[0] === '--version') { appendFileSync(${JSON.stringify(log)}, 'x'); console.error('unexpected-version-probe'); process.exit(77); }`,
104
+ "console.log('bundled-session-ok');",
105
+ ].join("\n"));
106
+ const result = spawnSync(process.execPath, [f.launcher], { env: f.env, encoding: "utf8" });
107
+ assert.equal(result.status, 0, result.stderr);
108
+ assert.equal(result.stdout, "bundled-session-ok\n");
109
+ assert.doesNotMatch(result.stderr, /unexpected-version-probe/);
110
+ assert.equal(readFileSync(log, "utf8"), "", "only --version invocations record a probe");
111
+ });
112
+
89
113
  test("malformed adjacent metadata never silently falls back to PATH; env override still wins", (t) => {
90
114
  const f = standaloneLauncher(t);
91
115
  const peer = join(f.root, "node_modules", "@earendil-works", "pi-coding-agent");
@@ -513,6 +537,29 @@ function writeGentleAiScriptDeclaringGentlePi(path: string, extraSources: string
513
537
  chmodSync(path, 0o755);
514
538
  }
515
539
 
540
+ // Test/development-only stub for the setup subcommand's gentle-ai binary
541
+ // that replaces the provisioned home's settings.json with a directory and
542
+ // then fails, so the failure-path post-install cleanup's settings read throws
543
+ // EISDIR instead of reporting a missing file (#1647 hardening).
544
+ function writeGentleAiScriptReplacingSettingsWithDirectory(path: string, exitCode: number) {
545
+ writeFileSync(
546
+ path,
547
+ [
548
+ "#!/usr/bin/env node",
549
+ "import { mkdirSync, rmSync } from 'node:fs';",
550
+ "import { join } from 'node:path';",
551
+ "const args = process.argv.slice(2);",
552
+ "const settingsPath = join(process.env.PI_CODING_AGENT_DIR, 'settings.json');",
553
+ "rmSync(settingsPath, { force: true });",
554
+ "mkdirSync(settingsPath, { recursive: true });",
555
+ "process.stdout.write(JSON.stringify({ args }) + '\\n');",
556
+ `process.exit(${exitCode});`,
557
+ "",
558
+ ].join("\n"),
559
+ );
560
+ chmodSync(path, 0o755);
561
+ }
562
+
516
563
  // Test/development-only fake pi runtime whose `remove <source>` branch also
517
564
  // rewrites the target home's settings.json, dropping the matching `packages`
518
565
  // entry — unlike the plain `writePiScript` stub above (which only records
@@ -1369,6 +1416,39 @@ test("gentle-shell setup removes both the conflicting rpiv package and npm:gentl
1369
1416
  assert.deepEqual(JSON.parse(lines[2]).args, ["remove", "npm:gentle-pi"]);
1370
1417
  });
1371
1418
 
1419
+ test("gentle-shell setup removes npm:gentle-pi that gentle-ai declared even when gentle-ai exits non-zero", (t) => {
1420
+ const f = fixture(t);
1421
+ const gentleAiScript = join(f.root, "fake-gentle-ai.mjs");
1422
+ writeGentleAiScriptDeclaringGentlePi(gentleAiScript, [], 3);
1423
+ const env = { ...f.env, GENTLE_SHELL_GENTLE_AI_BIN: gentleAiScript };
1424
+
1425
+ const result = run(env, ["setup"]);
1426
+ assert.equal(result.status, 3);
1427
+ assert.match(
1428
+ result.stderr,
1429
+ new RegExp(
1430
+ `gentle-shell: removing npm:gentle-pi from .+: this launcher loads its own gentle-pi ${ownGentlePiVersion().replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}, so the home always matches it`,
1431
+ ),
1432
+ );
1433
+
1434
+ const lines = result.stdout.trim().split("\n").filter((line) => line.length > 0);
1435
+ assert.equal(lines.length, 2, result.stdout);
1436
+ assert.deepEqual(JSON.parse(lines[0]).args, ["install", "--agent", "pi", "--scope", "global"]);
1437
+ assert.deepEqual(JSON.parse(lines[1]).args, ["remove", "npm:gentle-pi"]);
1438
+ });
1439
+
1440
+ test("gentle-shell setup keeps the gentle-ai exit code when failure-path cleanup cannot read settings.json", (t) => {
1441
+ const f = fixture(t);
1442
+ const gentleAiScript = join(f.root, "fake-gentle-ai.mjs");
1443
+ writeGentleAiScriptReplacingSettingsWithDirectory(gentleAiScript, 3);
1444
+ const env = { ...f.env, GENTLE_SHELL_GENTLE_AI_BIN: gentleAiScript };
1445
+
1446
+ const result = run(env, ["setup"]);
1447
+ assert.equal(result.status, 3, result.stderr);
1448
+ assert.match(result.stderr, /gentle-shell: post-install cleanup failed: EISDIR/);
1449
+ assert.doesNotMatch(result.stderr, /^\s+at /m);
1450
+ });
1451
+
1372
1452
  // A --dry-run gentle-ai install writes nothing, so reading settings.json
1373
1453
  // afterwards would only ever report whatever pre-existed the run (e.g. the
1374
1454
  // isolated-home bootstrap this fixture's fake-gentle-ai script never
@@ -1868,6 +1948,23 @@ test("a failing auto-provision flow warns, still launches pi, and writes no mark
1868
1948
  }
1869
1949
  });
1870
1950
 
1951
+ // The launch that follows still reads the same unreadable settings.json, so
1952
+ // only the setup outcome is pinned here: the install's own exit code reaches
1953
+ // the ordinary "starting anyway" branch instead of the unexpected-error one.
1954
+ test("a failing auto-provision flow keeps the install exit code when failure-path cleanup cannot read settings.json", (t) => {
1955
+ const f = fixture(t);
1956
+ const gentleAiScript = join(f.root, "fake-gentle-ai.mjs");
1957
+ writeGentleAiScriptReplacingSettingsWithDirectory(gentleAiScript, 5);
1958
+ const env = enableAutoProvision({ ...f.env, GENTLE_SHELL_GENTLE_AI_BIN: gentleAiScript, GENTLE_SHELL_GENTLE_AI_PIN: "3.6.0" });
1959
+
1960
+ const result = run(env, ["--mode", "rpc"]);
1961
+ assert.match(
1962
+ result.stderr,
1963
+ /gentle-shell: automatic setup failed \(exit 5\); starting anyway and retrying next run\. Run `gentle-shell setup` to see the full output\.\ngentle-shell: post-install cleanup failed: EISDIR/,
1964
+ );
1965
+ assert.doesNotMatch(result.stderr, /automatic setup failed unexpectedly/);
1966
+ });
1967
+
1871
1968
  test("a failing auto-provision flow names the --home selector in its retry remediation", (t) => {
1872
1969
  const f = fixture(t);
1873
1970
  const target = join(f.root, "custom-home");
@@ -1883,6 +1980,32 @@ test("a failing auto-provision flow names the --home selector in its retry remed
1883
1980
  );
1884
1981
  });
1885
1982
 
1983
+ test("a failing auto-provision flow removes declared npm:gentle-pi and injects the local package on continuation", (t) => {
1984
+ const f = fixture(t);
1985
+ const gentleAiScript = join(f.root, "fake-gentle-ai.mjs");
1986
+ writeGentleAiScriptDeclaringGentlePi(gentleAiScript, [], 5);
1987
+ writePiScriptEditingSettingsOnRemove(f.piScript);
1988
+ const env = enableAutoProvision({
1989
+ ...f.env,
1990
+ GENTLE_SHELL_GENTLE_AI_BIN: gentleAiScript,
1991
+ GENTLE_SHELL_GENTLE_AI_PIN: "3.6.0",
1992
+ });
1993
+
1994
+ const result = run(env, ["--mode", "rpc"]);
1995
+ assert.equal(result.status, 0, result.stderr);
1996
+ assert.match(
1997
+ result.stderr,
1998
+ /gentle-shell: automatic setup failed \(exit 5\); starting anyway and retrying next run\. Run `gentle-shell setup` to see the full output\./,
1999
+ );
2000
+ assert.match(result.stderr, /gentle-shell: removing npm:gentle-pi/);
2001
+
2002
+ const settings = JSON.parse(readFileSync(join(f.gentleShellHome, "settings.json"), "utf8"));
2003
+ assert.deepEqual(settings.packages, []);
2004
+
2005
+ const payload = JSON.parse(result.stdout);
2006
+ assert.deepEqual(payload.args, ["-e", packageRoot, "--mode", "rpc"]);
2007
+ });
2008
+
1886
2009
  test("GENTLE_SHELL_NO_AUTO_SETUP=1 skips auto-provisioning entirely", (t) => {
1887
2010
  const f = fixture(t);
1888
2011
  const gentleAiScript = join(f.root, "fake-gentle-ai.mjs");