gentle-pi 4.5.1 → 4.6.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 (239) hide show
  1. package/README.md +9 -6
  2. package/assets/agents/gentle-ai-verify.md +4 -0
  3. package/assets/agents/gentle-ai-worker.md +1 -0
  4. package/assets/migrations/agent-body-history.json +147 -0
  5. package/assets/orchestrator-delegation-reference.md +3 -3
  6. package/assets/orchestrator-delegation.md +2 -2
  7. package/assets/orchestrator-verification.md +10 -6
  8. package/assets/orchestrator.md +8 -8
  9. package/bin/gentle-shell.mjs +61 -26
  10. package/docs/ci-performance.md +11 -0
  11. package/docs/delegated-verification.md +6 -0
  12. package/docs/fast-mode.md +15 -0
  13. package/docs/gentle-agents-activity.md +8 -0
  14. package/docs/gentle-shell.md +69 -19
  15. package/docs/install-wizard.md +1 -1
  16. package/docs/mcp-status.md +52 -0
  17. package/docs/prompt-budget.md +28 -0
  18. package/docs/readme-reference.md +79 -20
  19. package/docs/session-profile-format.md +20 -5
  20. package/docs/sound-notifications.md +1 -1
  21. package/docs/star-prompt.md +32 -0
  22. package/docs/work-continuity.md +46 -0
  23. package/extensions/ask-user-question.ts +1 -0
  24. package/extensions/codegraph-tools.ts +38 -4
  25. package/extensions/gentle-agents.ts +477 -50
  26. package/extensions/gentle-ai.ts +1041 -188
  27. package/extensions/gentle-fast.ts +61 -0
  28. package/extensions/gentle-guide.ts +174 -0
  29. package/extensions/gentle-herdr-activity.ts +21 -1
  30. package/extensions/gentle-herdr-agent.ts +144 -0
  31. package/extensions/gentle-program-identity.ts +61 -0
  32. package/extensions/gentle-shell.ts +642 -97
  33. package/extensions/gentle-star-prompt.ts +334 -0
  34. package/extensions/gentle-stats.ts +5 -5
  35. package/extensions/gentle-todo.ts +42 -22
  36. package/extensions/history/store.ts +18 -12
  37. package/extensions/skill-registry.ts +35 -3
  38. package/extensions/startup-banner.ts +39 -7
  39. package/lib/agent-assets.ts +74 -17
  40. package/lib/agent-profiles.ts +1 -1
  41. package/lib/agents-config.ts +12 -3
  42. package/lib/agents-keys.ts +8 -16
  43. package/lib/agents-protocol.ts +80 -4
  44. package/lib/agents-runner.ts +105 -4
  45. package/lib/agents-view.ts +6 -1
  46. package/lib/agents-widget.ts +132 -9
  47. package/lib/bridge-cost.ts +28 -0
  48. package/lib/codemode-renderer.ts +16 -0
  49. package/lib/command-palette-catalog.ts +1 -0
  50. package/lib/command-palette.ts +21 -8
  51. package/lib/exploration-budget.ts +62 -0
  52. package/lib/gentle-guide.ts +201 -0
  53. package/lib/gentle-shell-launcher.ts +4 -0
  54. package/lib/herdr-activity.ts +9 -3
  55. package/lib/herdr-task-summary-policy.ts +85 -0
  56. package/lib/inprocess-reviewer.ts +33 -13
  57. package/lib/jobs-sidebar-state.ts +5 -6
  58. package/lib/jobs-widget.ts +16 -52
  59. package/lib/keymaps-customize.ts +81 -0
  60. package/lib/keymaps.ts +291 -0
  61. package/lib/model-fallback-notice.ts +61 -0
  62. package/lib/model-fallback-policy.ts +141 -0
  63. package/lib/model-fallback-store.ts +143 -0
  64. package/lib/model-routing-authority.ts +10 -2
  65. package/lib/nan-provider.ts +3 -2
  66. package/lib/native-review-cli.ts +7 -2
  67. package/lib/notification-customize.ts +48 -51
  68. package/lib/openai-fast-tier.ts +22 -0
  69. package/lib/orchestrator-discovery.ts +5 -1
  70. package/lib/orchestrator-fallback.ts +75 -0
  71. package/lib/pasted-image-paths.ts +113 -0
  72. package/lib/questionnaire/questionnaire-view.ts +121 -7
  73. package/lib/review-candidate-view-owner.ts +4 -0
  74. package/lib/review-candidate-view.ts +10 -7
  75. package/lib/review-host-relay.ts +5 -1
  76. package/lib/review-integration-v2.ts +22 -7
  77. package/lib/review-repository.ts +5 -0
  78. package/lib/session-profile-append-controller.ts +21 -6
  79. package/lib/session-profile-authority.ts +119 -0
  80. package/lib/session-profile-binding.ts +54 -5
  81. package/lib/session-profile-freeze.ts +105 -9
  82. package/lib/session-profile-integration.ts +313 -0
  83. package/lib/session-profile-persistence.ts +63 -9
  84. package/lib/shell-bar.ts +171 -56
  85. package/lib/shell-card.ts +26 -6
  86. package/lib/shell-page.ts +120 -0
  87. package/lib/shell-panel.ts +149 -0
  88. package/lib/shell-prompt.ts +53 -1
  89. package/lib/shell-sidebar-layout.ts +98 -25
  90. package/lib/shell-sidebar.ts +54 -1
  91. package/lib/shell-stats.ts +123 -0
  92. package/lib/shell-todo.ts +71 -0
  93. package/lib/shell-usage.ts +12 -2
  94. package/lib/star-prompt.ts +197 -0
  95. package/lib/verifier-admission.ts +18 -8
  96. package/lib/verifier-settle-reminder.ts +64 -0
  97. package/lib/vim-editor-adapter.ts +6 -1
  98. package/lib/visual-customization-policy.ts +41 -6
  99. package/lib/visual-customize-view.ts +164 -26
  100. package/lib/visual-layout-preview.ts +43 -0
  101. package/lib/yolo-session-policy.ts +28 -1
  102. package/package.json +1 -1
  103. package/runtime/gentle-shell-launcher.mjs +4 -0
  104. package/runtime/native-review-cli.mjs +7 -2
  105. package/runtime/review-integration-v2.mjs +22 -7
  106. package/runtime/windows-session-transport.ps1 +60 -3
  107. package/scripts/bootstrap.sh +4 -1
  108. package/scripts/installer-preflight.mjs +1 -1
  109. package/scripts/pi-update.mjs +113 -3
  110. package/scripts/run-test-suite.mjs +17 -1
  111. package/scripts/shell-snapshot.mjs +340 -0
  112. package/scripts/test-packed-runner.mjs +1 -1
  113. package/scripts/update-agent-body-history.mjs +41 -0
  114. package/scripts/verify-installer-tap.mjs +45 -0
  115. package/scripts/verify-package-files.mjs +2 -0
  116. package/skills/gentle-ai/SKILL.md +2 -2
  117. package/skills/tui-design/NOTICE.md +5 -0
  118. package/skills/tui-design/SKILL.md +56 -0
  119. package/skills/tui-design/references/commands.md +75 -0
  120. package/skills/tui-design/references/critique.md +48 -0
  121. package/skills/tui-design/references/design-doc.md +44 -0
  122. package/skills/tui-design/references/terminal-craft.md +64 -0
  123. package/skills/tui-design/references/visual-loop.md +32 -0
  124. package/tests/agents-protocol.test.ts +53 -1
  125. package/tests/agents-runner.test.ts +168 -3
  126. package/tests/agents-view.test.ts +27 -0
  127. package/tests/agents-widget.test.ts +312 -10
  128. package/tests/bounded-scan-contract.test.ts +39 -0
  129. package/tests/bridge-cost.test.ts +32 -0
  130. package/tests/bundled-install.test.ts +6 -4
  131. package/tests/ci-concurrency.test.ts +11 -0
  132. package/tests/ci-merge-base-identity.test.ts +114 -0
  133. package/tests/codegraph-tools.test.ts +69 -0
  134. package/tests/codemode-rendering.test.ts +22 -2
  135. package/tests/command-palette.test.ts +16 -2
  136. package/tests/commit-slice-signal.test.ts +11 -9
  137. package/tests/delegate-for-reason-contract.test.ts +5 -4
  138. package/tests/exploration-budget.test.ts +128 -0
  139. package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
  140. package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
  141. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +18 -10
  142. package/tests/fixtures/session-profile-v1/replay.ts +125 -0
  143. package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
  144. package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
  145. package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
  146. package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
  147. package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
  148. package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
  149. package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
  150. package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
  151. package/tests/gentle-agents.test.ts +416 -21
  152. package/tests/gentle-ai-exploration-budget.test.ts +135 -0
  153. package/tests/gentle-ai.test.ts +1007 -33
  154. package/tests/gentle-fast.test.ts +73 -0
  155. package/tests/gentle-guide.test.ts +208 -0
  156. package/tests/gentle-herdr-activity.test.ts +76 -2
  157. package/tests/gentle-herdr-agent.test.ts +111 -0
  158. package/tests/gentle-program-identity.test.ts +197 -0
  159. package/tests/gentle-shell-bin.test.ts +49 -26
  160. package/tests/gentle-shell-launcher.test.ts +18 -2
  161. package/tests/gentle-shell.test.ts +1068 -37
  162. package/tests/gentle-stats.test.ts +15 -2
  163. package/tests/gentle-todo.test.ts +50 -4
  164. package/tests/herdr-task-summary-policy.test.ts +128 -0
  165. package/tests/history-store-private-mode.test.ts +40 -0
  166. package/tests/image-paste-chips.test.ts +42 -0
  167. package/tests/inprocess-reviewer.test.ts +122 -0
  168. package/tests/installer-posix-bootstrap.test.ts +67 -5
  169. package/tests/installer-server.test.ts +2 -2
  170. package/tests/installer-windows-diagnostics.test.ts +4 -5
  171. package/tests/isolated-config-home.ts +28 -0
  172. package/tests/jobs-widget.test.ts +25 -37
  173. package/tests/keymaps-customize.test.ts +114 -0
  174. package/tests/keymaps.test.ts +103 -0
  175. package/tests/maintainer/mcp-status.maintest.ts +88 -0
  176. package/tests/maintainer/pi-update-source.maintest.ts +116 -0
  177. package/tests/model-fallback-notice.test.ts +45 -0
  178. package/tests/model-fallback-policy.test.ts +83 -0
  179. package/tests/model-fallback-store.test.ts +111 -0
  180. package/tests/nan-provider.test.ts +4 -4
  181. package/tests/no-self-pause-contract.test.ts +19 -0
  182. package/tests/notification-customize.test.ts +58 -34
  183. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  184. package/tests/odd-routing-contract.test.ts +1 -1
  185. package/tests/orchestrator-fallback.test.ts +82 -0
  186. package/tests/orchestrator-prompt-budget.test.ts +131 -0
  187. package/tests/package-manifest.test.ts +160 -7
  188. package/tests/pasted-image-paths.test.ts +118 -0
  189. package/tests/persona-reply-language.test.ts +20 -1
  190. package/tests/pi-update-launcher.test.ts +32 -8
  191. package/tests/pi-update-source.test.ts +162 -0
  192. package/tests/profile-fast-tier.test.ts +311 -0
  193. package/tests/profile-tier-footer.test.ts +79 -0
  194. package/tests/questionnaire-view.test.ts +150 -0
  195. package/tests/review-candidate-owner-sweep.test.ts +93 -0
  196. package/tests/review-candidate-view.test.ts +51 -0
  197. package/tests/review-controller-native-routing.test.ts +120 -6
  198. package/tests/review-gate.test.ts +24 -0
  199. package/tests/review-inspect-preflight.test.ts +197 -0
  200. package/tests/review-integration-v2-forward.test.ts +59 -0
  201. package/tests/review-repository.test.ts +52 -1
  202. package/tests/review-sidebar-state.test.ts +5 -5
  203. package/tests/run-test-suite.test.ts +61 -5
  204. package/tests/sensitive-path-tools.test.ts +74 -0
  205. package/tests/session-profile-append-controller.test.ts +63 -0
  206. package/tests/session-profile-authority.test.ts +259 -0
  207. package/tests/session-profile-binding.test.ts +15 -0
  208. package/tests/session-profile-extension.test.ts +615 -0
  209. package/tests/session-profile-freeze.test.ts +110 -2
  210. package/tests/session-profile-integration.test.ts +857 -0
  211. package/tests/session-profile-persistence.test.ts +57 -0
  212. package/tests/session-profile-v1-compat.test.ts +221 -0
  213. package/tests/shell-bar.test.ts +113 -55
  214. package/tests/shell-card.test.ts +13 -1
  215. package/tests/shell-page.test.ts +108 -0
  216. package/tests/shell-panel.test.ts +332 -0
  217. package/tests/shell-prompt.test.ts +54 -0
  218. package/tests/shell-render-cache.test.ts +5 -0
  219. package/tests/shell-sidebar-fullscreen.test.ts +12 -0
  220. package/tests/shell-sidebar-layout.test.ts +159 -27
  221. package/tests/shell-stats.test.ts +90 -0
  222. package/tests/shell-usage.test.ts +14 -0
  223. package/tests/skill-registry.test.ts +68 -1
  224. package/tests/star-prompt.test.ts +470 -0
  225. package/tests/startup-banner.test.ts +57 -1
  226. package/tests/task-size-routing-contract.test.ts +45 -1
  227. package/tests/verifier-settle-reminder.test.ts +281 -0
  228. package/tests/verify-first-launch-contract.test.ts +56 -5
  229. package/tests/verify-installer-tap.test.ts +57 -0
  230. package/tests/vim-editor-adapter.test.ts +2 -2
  231. package/tests/visual-customization-policy.test.ts +61 -7
  232. package/tests/visual-customize-view.test.ts +253 -8
  233. package/tests/visual-layout-preview.test.ts +28 -0
  234. package/tests/windows-session-bootstrap.test.ts +105 -2
  235. package/tests/work-continuity-contract.test.ts +86 -0
  236. package/tests/writer-surfaces.test.ts +12 -10
  237. package/tests/yolo-customize.test.ts +30 -11
  238. package/tests/yolo-mode-runtime.test.ts +4 -2
  239. package/tests/yolo-mode.test.ts +16 -2
@@ -1,9 +1,9 @@
1
1
  import assert from "node:assert/strict";
2
2
  import test from "node:test";
3
- import { CURSOR_MARKER, ScrollView, VStack, visibleWidth, type Component, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
3
+ import { CURSOR_MARKER, Container, ScrollView, VStack, visibleWidth, type Component, type TUI, type TuiMouseEvent } from "@earendil-works/pi-tui";
4
4
  import { getScrollViewsAt, renderLayoutFrame, type LayoutBox } from "@earendil-works/pi-tui/dist/layout.js";
5
5
  import { installSidebar, invalidateSidebar, narrowStatusOwner } from "../lib/shell-sidebar-layout.ts";
6
- import { sidebarHeader, sidebarPart, sidebarState } from "../lib/shell-sidebar.ts";
6
+ import { setSidebarHover, sidebarHeader, sidebarPart, sidebarState, sidebarStatusBar } from "../lib/shell-sidebar.ts";
7
7
  import { renderShellSidebarBar } from "../lib/shell-bar.ts";
8
8
  import { renderTodoCard, type TodoState } from "../lib/shell-todo.ts";
9
9
  import { CARD_STYLE, cardStyle, setCardStyle } from "../lib/shell-card.ts";
@@ -39,10 +39,9 @@ function railWithHeader(f: ReturnType<typeof fixture>): ScrollView {
39
39
  return hstackOf(f).entries[1].component as ScrollView;
40
40
  }
41
41
 
42
- test("grouped Status preserves structured fields and opaque integration text", (t) => {
42
+ test("the rail Status keeps its section order and opaque integration text in both card styles", (t) => {
43
43
  const found = cardStyle();
44
44
  t.after(() => setCardStyle(found));
45
- // Both styles keep the group order; float panels need a theme background.
46
45
  const painted = { ...theme, bg: (_color: string, text: string) => `\x1b[48;5;22m${text}\x1b[49m` };
47
46
  for (const style of [CARD_STYLE.NEON, CARD_STYLE.FLOAT]) {
48
47
  setCardStyle(style);
@@ -52,15 +51,9 @@ test("grouped Status preserves structured fields and opaque integration text", (
52
51
  costTotal: 1, subscription: false, usage: undefined, statuses: ["opaque integration"],
53
52
  }, painted, 46);
54
53
  const text = lines.join("\n");
55
- let previous = -1;
56
- for (const heading of ["Status", "Project", "Changes", "Integrations"]) {
57
- const index = text.indexOf(heading);
58
- assert.ok(index > previous, `${style}: ${heading}`);
59
- previous = index;
60
- }
54
+ assert.ok(text.indexOf("CHANGES") >= 0 && text.indexOf("CHANGES") < text.indexOf("INTEGRATIONS"), `${style}: Changes before Integrations`);
61
55
  assert.match(text, /opaque integration/);
62
- assert.match(text, /Branch.*main/);
63
- assert.doesNotMatch(text, /Usage/);
56
+ assert.doesNotMatch(text, /Branch|Usage/);
64
57
  }
65
58
  });
66
59
 
@@ -78,6 +71,50 @@ test("installation on a missing-terminal host is a harmless no-op", () => {
78
71
  assert.doesNotThrow(dispose);
79
72
  });
80
73
 
74
+ test("root hover fallback preserves the original mouse result and restores ownership", () => {
75
+ const f = fixture("fullscreen", 80);
76
+ const root = f.root as typeof f.root & { handleMouse?: (event: TuiMouseEvent) => { handled: boolean } | undefined };
77
+ let calls = 0;
78
+ const result = { handled: true };
79
+ const original = (event: TuiMouseEvent) => { calls++; return event.type === "click" ? result : undefined; };
80
+ root.handleMouse = original;
81
+ const dispose = installSidebar(f.tui, theme);
82
+ const event: TuiMouseEvent = { type: "move", button: "none", x: 1, y: 1, screenX: 1, screenY: 1, width: 80, height: 24, shift: false, alt: false, ctrl: false };
83
+ let clears = 0;
84
+ setSidebarHover(f.tui, {}, () => { clears++; });
85
+ assert.equal(root.handleMouse!(event), undefined);
86
+ assert.equal(clears, 1);
87
+ setSidebarHover(f.tui, {}, () => { clears++; });
88
+ assert.equal(root.handleMouse!({ ...event, type: "click", button: "left" }), result);
89
+ assert.equal(clears, 1, "non-move events retain ownership");
90
+ assert.equal(calls, 2);
91
+ dispose();
92
+ assert.equal(root.handleMouse, original);
93
+ assert.equal(clears, 2, "dispose clears remaining shell hover");
94
+ });
95
+
96
+ test("root hover fallback never re-renders the transcript for wheel or move events", () => {
97
+ // pi-tui skips layout roots that keep Container.prototype.handleMouse: its
98
+ // fallback measures every child by rendering it, O(transcript) per event.
99
+ const f = fixture("fullscreen", 140);
100
+ let childRenders = 0;
101
+ const root = new Container() as Container & { [NODE]: () => unknown };
102
+ root.addChild({ render: () => { childRenders++; return ["message"]; }, invalidate() {} });
103
+ root[NODE] = f.original;
104
+ (f.host as { layoutRoot: unknown }).layoutRoot = root;
105
+ const dispose = installSidebar(f.tui, theme);
106
+ assert.notEqual(root.handleMouse, Container.prototype.handleMouse, "the hover fallback is installed");
107
+ const base: TuiMouseEvent = { type: "wheel", button: "none", wheelDelta: -1, x: 1, y: 0, screenX: 1, screenY: 0, width: 80, height: 24, shift: false, alt: false, ctrl: false };
108
+ let clears = 0;
109
+ setSidebarHover(f.tui, {}, () => { clears++; });
110
+ assert.equal(root.handleMouse(base), undefined);
111
+ assert.equal(root.handleMouse({ ...base, type: "move" }), undefined);
112
+ assert.equal(clears, 1, "move still clears shell hover");
113
+ assert.equal(childRenders, 0, "mouse events must not render transcript children");
114
+ dispose();
115
+ assert.equal(root.handleMouse, Container.prototype.handleMouse);
116
+ });
117
+
81
118
  test("only fullscreen at 140 columns activates; shrinking restores bottom paint", (t) => {
82
119
  for (const [mode, width, active] of [["regular", 140, false], ["fullscreen", 139, false], ["fullscreen", 140, true]] as const) {
83
120
  const f = fixture(mode, width);
@@ -293,13 +330,13 @@ test("TODO visibility hides both rail and bottom without mutating the registered
293
330
  assert.deepEqual(todo.render(100), ["todo"]);
294
331
  });
295
332
 
296
- test("rail orders unified Status, agents, TODO without standalone changes", (t) => {
333
+ test("rail orders live work first, then Status, without standalone changes", (t) => {
297
334
  const f = fixture();
298
335
  for (const key of ["todo", "agents", "changes"]) {
299
336
  sidebarPart(f.tui, key, { render: () => [key, ""], invalidate() {} });
300
337
  }
301
338
  t.after(installSidebar(f.tui, theme));
302
- assert.deepEqual(rail(f).render(50).map((line) => line.trim()), ["✿ Gentle Shell ✿", "", "Status", "", "agents", "", "todo"]);
339
+ assert.deepEqual(rail(f).render(50).map((line) => line.trim()), ["✿ Gentle Shell ✿", "", "todo", "", "agents", "", "Status"]);
303
340
  });
304
341
 
305
342
  test("branding belongs to scroll content before Status, never transcript or narrow bottom", (t) => {
@@ -589,7 +626,7 @@ test("a rail digest refreshes live state that no invalidation announces", (t) =>
589
626
  assert.equal(todoRenders, 2, "explicit invalidation still reaches a rail without a digest");
590
627
  });
591
628
 
592
- test("the jobs rail section paints between Status and Agents", (t) => {
629
+ test("the rail paints Todos, Jobs and Agents before Status", (t) => {
593
630
  const f = fixture();
594
631
  sidebarPart(f.tui, "jobs", { render: () => ["jobs"], invalidate() {} }, { digest: () => "jobs", render: () => ["Jobs card"], invalidate() {} });
595
632
  sidebarPart(f.tui, "agents", { render: () => ["agents"], invalidate() {} }, { digest: () => "agents", render: () => ["Agents card"], invalidate() {} });
@@ -603,7 +640,26 @@ test("the jobs rail section paints between Status and Agents", (t) => {
603
640
  for (const [name, index] of [["Status", footer], ["Jobs card", jobs], ["Agents card", agents], ["Todo card", todo]] as const) {
604
641
  assert.ok(index >= 0, `${name} paints in the rail`);
605
642
  }
606
- assert.ok(footer < jobs && jobs < agents && agents < todo, `sections paint in order, got: ${text}`);
643
+ assert.ok(todo < jobs && jobs < agents && agents < footer, `sections paint in order, got: ${text}`);
644
+ });
645
+
646
+ test("panel sections paint on the rail surface, joined by a tinted gap, while card sections stay unpainted", (t) => {
647
+ const f = fixture();
648
+ const roleCode: Record<string, number> = { customMessageBg: 236 };
649
+ const painting = { ...theme, bg: (color: string, text: string) => `\x1b[48;5;${roleCode[color] ?? 1}m${text}\x1b[49m` };
650
+ const open = "\x1b[48;5;236m";
651
+ sidebarPart(f.tui, "jobs", { render: () => ["jobs"], invalidate() {} }, { surface: "panel", digest: () => "jobs", render: (width: number) => ["JOBS".padEnd(width)], invalidate() {} });
652
+ sidebarPart(f.tui, "todo", { render: () => ["todo"], invalidate() {} }, { surface: "panel", digest: () => "todo", render: (width: number) => ["TODOS".padEnd(width)], invalidate() {} });
653
+ t.after(installSidebar(f.tui, painting));
654
+ const lines = rail(f).render(50);
655
+ const status = lines.find((line) => line.includes("Status"))!;
656
+ const jobs = lines.findIndex((line) => line.includes("JOBS"));
657
+ const todo = lines.findIndex((line) => line.includes("TODOS"));
658
+ assert.ok(!status.includes(open), "the Status card keeps its own chrome");
659
+ assert.ok(lines[jobs]!.startsWith(`${open} JOBS`), `panel row is painted including its padding: ${JSON.stringify(lines[jobs])}`);
660
+ assert.equal(jobs, todo + 2, "one gap row separates two panel sections");
661
+ assert.match(lines[todo + 1]!, /^\x1b\[48;5;236m +\x1b\[49m$/, "the gap between two panel sections is tinted too");
662
+ assert.ok(lines[todo]!.startsWith(`${open} TODOS`));
607
663
  });
608
664
 
609
665
  test("a theme switch repaints rail sections whose digest did not change", (t) => {
@@ -860,6 +916,32 @@ test("a footer digest change does not re-render Agents or TODO", (t) => {
860
916
  assert.deepEqual(counts, { footer: 2, agents: 2, todo: 2 }, "revision invalidation reaches only the sections with no digest of their own");
861
917
  });
862
918
 
919
+ test("a card style change re-renders sections whose digest is unchanged", (t) => {
920
+ const found = cardStyle();
921
+ t.after(() => setCardStyle(found));
922
+ setCardStyle(CARD_STYLE.FLOAT);
923
+ const f = fixture();
924
+ let renders = 0;
925
+ sidebarPart(f.tui, "todo", { render: () => ["todo"], invalidate() {} }, {
926
+ digest: () => "unchanged",
927
+ render: () => { renders++; return [`Todos ${cardStyle()}`]; },
928
+ invalidate() {},
929
+ });
930
+ t.after(installSidebar(f.tui, theme));
931
+
932
+ assert.match(rail(f).render(50).join("\n"), /Todos float/);
933
+ assert.equal(renders, 1);
934
+
935
+ setCardStyle(CARD_STYLE.NEON);
936
+ const output = rail(f).render(50).join("\n");
937
+ assert.match(output, /Todos neon/, "the cached float lines must not survive a switch to neon");
938
+ assert.doesNotMatch(output, /Todos float/);
939
+ assert.equal(renders, 2);
940
+
941
+ assert.match(rail(f).render(50).join("\n"), /Todos neon/);
942
+ assert.equal(renders, 2, "an unchanged style keeps the section cache");
943
+ });
944
+
863
945
  test("a throwing digest still degrades to invalidation-only under the per-section memo", (t) => {
864
946
  const f = fixture();
865
947
  let todoRenders = 0;
@@ -943,7 +1025,7 @@ test("an active header wraps the hstack in a vstack and removes the banner from
943
1025
  assert.notEqual(rail[1]?.trim(), "", "the first card starts on the second row");
944
1026
  });
945
1027
 
946
- test("float rail alignment starts Status background at the conversation body row with either header placement", (t) => {
1028
+ test("the top header has a rail-local inset without moving the conversation or losing hits", (t) => {
947
1029
  const found = cardStyle();
948
1030
  t.after(() => setCardStyle(found));
949
1031
  setCardStyle(CARD_STYLE.FLOAT);
@@ -954,9 +1036,10 @@ test("float rail alignment starts Status background at the conversation body row
954
1036
  const status = renderShellSidebarBar({
955
1037
  cwd: "/project", branch: "main", dirty: 0, sessionName: undefined,
956
1038
  modelId: "model", effort: "high", contextPercent: 45, contextWindow: 1000,
957
- costTotal: 1, subscription: false, usage: undefined, statuses: [],
1039
+ costTotal: 1, subscription: false, usage: undefined, statuses: ["one", "two", "three", "four", "five"],
958
1040
  }, painted, 48);
959
1041
  sidebarPart(f.tui, "footer", {
1042
+ surface: "panel",
960
1043
  render: () => status,
961
1044
  invalidate() {},
962
1045
  handleMouse(event) { received.push(event); return { handled: true }; },
@@ -968,19 +1051,23 @@ test("float rail alignment starts Status background at the conversation body row
968
1051
  const frame = renderLayoutFrame(f.root, 140, 8, () => {});
969
1052
  const bodyY = placement === "top" ? 2 : 0;
970
1053
  assert.match(frame.lines[bodyY], /CONVERSATION/);
971
- assert.match(frame.lines[bodyY], /\x1b\[48;5;22m/, `${placement}: the first painted padding row aligns with conversation content`);
1054
+ const inset = placement === "top" ? 1 : 0;
972
1055
  assert.doesNotMatch(frame.lines.slice(0, bodyY).join("\n"), /\x1b\[48;5;22m/);
1056
+ assert.match(frame.lines[bodyY], /\x1b\[48;5;22m/, "the panel surface reaches the header through its top padding");
1057
+ assert.match(frame.lines[bodyY + inset], /\x1b\[48;5;22m/);
1058
+ for (const line of frame.lines.slice(bodyY)) assert.equal(visibleWidth(line), 140);
973
1059
  const scroll = railWithHeader(f);
974
1060
  const content = scroll.render(50);
975
- assert.deepEqual(content, status.map((line) => ` ${line} `), "no external blank row; every internal padding byte survives");
1061
+ assert.deepEqual(content, [...(inset ? [`\x1b[48;5;22m${" ".repeat(scroll.getContentWidth(50))}\x1b[49m`] : []), ...status.map((line) => `\x1b[48;5;22m ${line} \x1b[49m`)]);
976
1062
  const height = 8 - bodyY;
977
1063
  const click = (y: number): TuiMouseEvent => ({ type: "click", button: "left", x: 2, y, screenX: 92, screenY: bodyY + y, width: 50, height, shift: false, alt: false, ctrl: false });
978
- assert.equal(scroll.handleMouse(click(0))?.handled, true);
979
- assert.equal(received.at(-1)?.y, 0, "first painted row is also the first part hit row");
980
- assert.equal(scroll.handleMouse(click(1))?.handled, true);
981
- assert.equal(received.at(-1)?.y, 1, "approved internal header offset is preserved");
1064
+ if (inset) assert.equal(scroll.handleMouse(click(0)), undefined, "inset is not a hit target");
1065
+ assert.equal(scroll.handleMouse(click(inset))?.handled, true);
1066
+ assert.equal(received.at(-1)?.y, 0, "first section row keeps its local hit offset");
1067
+ assert.equal(scroll.handleMouse(click(inset + 1))?.handled, true);
1068
+ assert.equal(received.at(-1)?.y, 1);
982
1069
  scroll.scrollBy(1000);
983
- assert.equal(scroll.scrollTop, status.length - height, "scroll bounds contain only actual card rows");
1070
+ assert.equal(scroll.scrollTop, status.length + inset - height, "scroll bounds include the inset exactly once");
984
1071
  assert.equal(scroll.handleMouse(click(height - 1))?.handled, true);
985
1072
  assert.equal(received.at(-1)?.y, status.length - 1, "last clipped viewport row hits the last card row");
986
1073
  const count = received.length;
@@ -999,10 +1086,10 @@ test("float rail alignment preserves fallback banners and neon bytes across live
999
1086
  sidebarPart(f.tui, "todo", { render: () => ["TODO"], invalidate() {} });
1000
1087
  t.after(installSidebar(f.tui, theme));
1001
1088
  const baseline = railWithHeader(f).render(50);
1002
- if (header) assert.deepEqual(baseline, ["", " Status ", "", " TODO "]);
1089
+ if (header) assert.deepEqual(baseline, ["", " TODO ", "", " Status "]);
1003
1090
  else assert.match(baseline.join("\n"), /✿ Gentle Shell ✿/);
1004
1091
  setCardStyle(CARD_STYLE.FLOAT);
1005
- assert.deepEqual(railWithHeader(f).render(50), header ? baseline.slice(1) : baseline, "only the active-header external gap changes");
1092
+ assert.deepEqual(railWithHeader(f).render(50), baseline, "the active top header keeps its gap in both styles");
1006
1093
  setCardStyle(CARD_STYLE.NEON);
1007
1094
  assert.deepEqual(railWithHeader(f).render(50), baseline, "neon is byte-identical after switching back");
1008
1095
  }
@@ -1158,3 +1245,48 @@ test("rail scrollbar stays hidden when the rail does not overflow", (t) => {
1158
1245
  scroll.scrollBy(1);
1159
1246
  assert.equal(scroll.isScrollbarVisible, false);
1160
1247
  });
1248
+
1249
+ test("a status bar part paints one full-width row below the transcript and the rail", (t) => {
1250
+ const f = fixture("fullscreen", 160);
1251
+ let widthSeen = 0;
1252
+ sidebarHeader(f.tui, { render: () => ["TITLE"], invalidate() {} });
1253
+ sidebarStatusBar(f.tui, { render: (width: number) => { widthSeen = width; return ["STATUS BAR"]; }, invalidate() {} });
1254
+ const transcript = { render: () => ["CONVERSATION"], invalidate() {} };
1255
+ f.root[NODE] = () => ({ type: "vstack", entries: [{ component: transcript }] });
1256
+ t.after(installSidebar(f.tui, theme));
1257
+ const frame = renderLayoutFrame(f.root, 160, 8, () => {});
1258
+ assert.match(frame.lines[0]!, /TITLE/);
1259
+ assert.match(frame.lines.at(-1)!, /^STATUS BAR/, "the status bar is the last row, under the rail too");
1260
+ assert.match(frame.lines[1]!, /CONVERSATION/, "the transcript starts immediately below the title");
1261
+ assert.ok(frame.lines.slice(1, -1).some((line) => /Status/.test(line)), "the rail sits above the status bar");
1262
+ assert.equal(widthSeen, 160 - 2, "rendered at the header's width");
1263
+ });
1264
+
1265
+ test("below the rail breakpoint the status bar row stays only while its part paints one (mobile)", (t) => {
1266
+ const f = fixture("fullscreen", 139);
1267
+ let paints = true;
1268
+ sidebarStatusBar(f.tui, { render: () => paints ? ["STATUS BAR"] : [], invalidate() {} });
1269
+ t.after(installSidebar(f.tui, theme));
1270
+ assert.match(renderLayoutFrame(f.root, 139, 6, () => {}).lines.at(-1)!, /^STATUS BAR/, "the mobile status bar is the last row");
1271
+ paints = false;
1272
+ assert.doesNotMatch(renderLayoutFrame(f.root, 139, 6, () => {}).lines.join("\n"), /STATUS BAR/, "a part with nothing to show leaves the native layout");
1273
+ });
1274
+
1275
+ test("the rail panel surface reaches the bottom of the viewport, not just the last section", (t) => {
1276
+ const f = fixture("fullscreen", 160);
1277
+ const painting = { ...theme, bg: (_color: string, text: string) => `\x1b[48;5;236m${text}\x1b[49m` };
1278
+ sidebarPart(f.tui, "todo", { render: () => ["todo"], invalidate() {} }, { surface: "panel", digest: () => "todo", render: (width: number) => ["TODOS".padEnd(width)], invalidate() {} });
1279
+ // The shell's Status is a panel too, so the rail ends on the panel surface.
1280
+ sidebarPart(f.tui, "footer", { render: () => ["Status"], invalidate() {} }, { surface: "panel", digest: () => "status", render: (width: number) => ["CHANGES".padEnd(width)], invalidate() {} });
1281
+ const transcript = { render: () => ["CONVERSATION"], invalidate() {} };
1282
+ f.root[NODE] = () => ({ type: "vstack", entries: [{ component: transcript }] });
1283
+ t.after(installSidebar(f.tui, painting));
1284
+ renderLayoutFrame(f.root, 160, 12, () => {});
1285
+ const frame = renderLayoutFrame(f.root, 160, 12, () => {});
1286
+ const tinted = frame.lines.filter((line) => line.includes("\x1b[48;5;236m")).length;
1287
+ assert.ok(frame.lines.at(-1)!.includes("\x1b[48;5;236m"), `the last screen row is still on the rail surface: ${JSON.stringify(frame.lines.at(-1))}`);
1288
+ assert.ok(tinted >= 10, `the surface fills the rail column (${tinted} tinted rows)`);
1289
+ assert.equal(rail(f).scrollTop, 0);
1290
+ rail(f).scrollBy(5);
1291
+ assert.equal(rail(f).scrollTop, 0, "the fill adds no scroll range");
1292
+ });
@@ -0,0 +1,90 @@
1
+ import assert from "node:assert/strict";
2
+ import test from "node:test";
3
+ import { collectSessionStats, renderStatsRows } from "../lib/shell-stats.ts";
4
+ import { renderShellStatusSections } from "../lib/shell-bar.ts";
5
+
6
+ const assistant = (model: string, at: string, usage: { input: number; output: number; cacheRead: number; cacheWrite: number; cost: number }) => ({
7
+ type: "message", timestamp: at,
8
+ message: { role: "assistant", model, provider: "anthropic", usage: { ...usage, cost: { total: usage.cost } } },
9
+ });
10
+ const tool = (at: string, isError = false) => ({ type: "message", timestamp: at, message: { role: "toolResult", toolName: "bash", isError } });
11
+ const entries = [
12
+ { type: "session", timestamp: "2026-11-03T10:00:00.000Z" },
13
+ { type: "message", timestamp: "2026-11-03T10:00:01.000Z", message: { role: "user" } },
14
+ assistant("claude-opus-5-5", "2026-11-03T10:00:10.000Z", { input: 100, output: 400, cacheRead: 8000, cacheWrite: 1500, cost: 0.5 }),
15
+ tool("2026-11-03T10:00:11.000Z"),
16
+ tool("2026-11-03T10:00:12.000Z", true),
17
+ assistant("claude-opus-5-5", "2026-11-03T10:10:00.000Z", { input: 50, output: 600, cacheRead: 9000, cacheWrite: 500, cost: 0.75 }),
18
+ assistant("gpt-5.5", "2026-11-03T11:05:00.000Z", { input: 2000, output: 300, cacheRead: 0, cacheWrite: 0, cost: 0.1 }),
19
+ { type: "custom", customType: "x", timestamp: "not a date" },
20
+ ];
21
+
22
+ test("session stats total every assistant turn and break them down per model, most expensive first", () => {
23
+ const stats = collectSessionStats(entries);
24
+ assert.equal(stats.turns, 3);
25
+ assert.equal(stats.toolCalls, 2);
26
+ assert.equal(stats.toolErrors, 1);
27
+ assert.equal(stats.input, 2150);
28
+ assert.equal(stats.output, 1300);
29
+ assert.equal(stats.cacheRead, 17000);
30
+ assert.equal(stats.cacheWrite, 2000);
31
+ assert.equal(Math.round(stats.cost * 100), 135);
32
+ assert.equal(stats.spanMs, 65 * 60 * 1000, "the span runs from the first to the last dated entry");
33
+ assert.equal(Math.round(stats.cacheHitRate! * 100), 80, "cache reads over every prompt token");
34
+ assert.deepEqual(stats.models.map((model) => [model.model, model.turns, Math.round(model.cost * 100)]), [["claude-opus-5-5", 2, 125], ["gpt-5.5", 1, 10]]);
35
+ const empty = collectSessionStats([]);
36
+ assert.equal(empty.turns, 0);
37
+ assert.equal(empty.cacheHitRate, undefined, "no prompt tokens, no hit rate");
38
+ assert.equal(empty.spanMs, 0);
39
+ });
40
+
41
+ test("the Stats rows fit the rail and name each model with its share", () => {
42
+ const theme = { fg: (_role: string, text: string) => text, bold: (text: string) => text };
43
+ const rows = renderStatsRows(collectSessionStats(entries), theme, 46);
44
+ for (const row of rows) assert.ok(row.length <= 46, `row fits: ${JSON.stringify(row)}`);
45
+ const text = rows.map((row) => row.trimEnd()).join("\n");
46
+ assert.match(text, /spent\s+\$1\.35/);
47
+ assert.match(text, /3 turns · 1h05m/);
48
+ assert.match(text, /tokens\s+in 2\.1k · out 1\.3k/);
49
+ assert.match(text, /cache\s+80% hit · 17k read/);
50
+ assert.match(text, /tools\s+2 calls · 1 failed/);
51
+ assert.match(text, /claude-opus-5-5\s+2 turns · 20k · \$1\.25/);
52
+ assert.match(text, /gpt-5\.5\s+1 turn · 2\.3k · \$0\.100/);
53
+ });
54
+
55
+ test("Status adds a foldable Stats section only when the model carries stats", () => {
56
+ const theme = { fg: (_role: string, text: string) => text, bold: (text: string) => text };
57
+ const model = { cwd: "~", modelId: "m", contextPercent: null, contextWindow: 0, costTotal: 0, subscription: false, statuses: [], changes: { files: 0, added: 0, deleted: 0 } } as never;
58
+ const without = renderShellStatusSections(model, theme as never, 46).lines.join("\n");
59
+ assert.doesNotMatch(without, /STATS/);
60
+ const stats = collectSessionStats(entries);
61
+ const view = renderShellStatusSections({ ...(model as object), stats } as never, theme as never, 46);
62
+ const header = view.lines.findIndex((line) => /^▾ STATS\s+\$1\.35/.test(line));
63
+ assert.ok(header >= 0, view.lines.join("\n"));
64
+ assert.ok(view.targets.some((target) => target.kind === "toggle" && target.section === "stats" && target.row === header));
65
+ const folded = renderShellStatusSections({ ...(model as object), stats } as never, theme as never, 46, undefined, undefined, { collapsed: new Set(["stats"]) }).lines.join("\n");
66
+ assert.match(folded, /▸ STATS/);
67
+ assert.doesNotMatch(folded, /spent/);
68
+ });
69
+
70
+ test("Stats rows keep the model name at narrow widths, strip escapes and ignore negative usage", () => {
71
+ const theme = { fg: (_role: string, text: string) => text };
72
+ const stats = collectSessionStats([
73
+ assistant("claude-bridge/claude-opus-5-5", "2026-11-03T10:00:00.000Z", { input: 100, output: 200, cacheRead: 0, cacheWrite: -5, cost: 0.2 }),
74
+ assistant("evil\x1b]0;pwned\x07model", "2026-11-03T10:01:00.000Z", { input: 10, output: 10, cacheRead: 0, cacheWrite: 0, cost: 0 }),
75
+ ]);
76
+ assert.equal(stats.cacheWrite, 0, "negative usage is not counted");
77
+ const rows = renderStatsRows(stats, theme, 30).map((row) => row.trimEnd());
78
+ for (const row of rows) assert.ok(row.length <= 30, JSON.stringify(row));
79
+ const text = rows.join("\n");
80
+ assert.match(text, /claude-opus-5-5/, "the model name survives a narrow rail (provider prefix dropped)");
81
+ assert.match(text, /1 turn · 300 · \$0\.200/, "its numbers move to their own row");
82
+ assert.doesNotMatch(text, /\x1b|\x07/, "terminal escapes in a model id never reach the screen");
83
+ });
84
+
85
+ test("Stats adds what subagents spent when the Agents section reports it", () => {
86
+ const theme = { fg: (_role: string, text: string) => text };
87
+ const rows = renderStatsRows({ ...collectSessionStats(entries), subagents: { runs: 3, tokens: 3500, cost: 0.2 } }, theme, 46).map((row) => row.trimEnd()).join("\n");
88
+ assert.match(rows, /agents\s+3 runs · 3\.5k · \$0\.200/);
89
+ assert.doesNotMatch(renderStatsRows(collectSessionStats(entries), theme, 46).join("\n"), /runs/, "no subagents, no row");
90
+ });
@@ -680,3 +680,17 @@ test("renderUsagePanel renders the failure note beside a retained snapshot, and
680
680
  assert.ok(afterFailure.some((line) => /^ {2}fetch failed · r to retry$/.test(line)), "the failure is visible beside the retained snapshot");
681
681
  assert.equal(scopePanel([codex], ["openai-codex"]).some((line) => line.includes("fetch failed")), false, "a provider whose latest refresh succeeded carries no failure note");
682
682
  });
683
+
684
+ test("UsageStore hands every recorded reading to its onRecord hook (the fallback cooldown listens there)", () => {
685
+ const seen: string[] = [];
686
+ const store = new UsageStore((usage) => seen.push(usage.provider));
687
+ store.record({ provider: "anthropic", plan: undefined, limits: [], fetchedAt: 1 });
688
+ assert.deepEqual(seen, ["anthropic"]);
689
+ assert.equal(store.get("anthropic")?.provider, "anthropic");
690
+ assert.doesNotThrow(() => new UsageStore().record({ provider: "openai", plan: undefined, limits: [], fetchedAt: 1 }));
691
+ });
692
+
693
+ test("Codex's main limit covers the whole provider; its extra limits cover one model each", () => {
694
+ const usage = parseCodexUsage(CODEX_PAYLOAD, NOW);
695
+ assert.deepEqual(usage.limits.map((limit) => [limit.name, limit.scope]), [["codex", "provider"], ["codex_spark", undefined]]);
696
+ });
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { execSync } from "node:child_process";
3
- import { existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
3
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, statSync, symlinkSync, utimesSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
  import test from "node:test";
@@ -715,3 +715,70 @@ test("registered startup skips Git work and watchers when the repository is root
715
715
  await runtime.refresh();
716
716
  assert.match(readFileSync(join(cwd, ".atl", "skill-registry.md"), "utf8"), /Initial skill/);
717
717
  });
718
+
719
+ // gentle-shell#373: permission failures must degrade truthfully. The registry
720
+ // refresh reports a typed unavailable result with the offending path and a
721
+ // safe next action, never a successful regeneration, and unexpected I/O keeps
722
+ // its own diagnostic.
723
+ test("isStorageUnavailableError classifies only storage faults", () => {
724
+ for (const code of ["EACCES", "EPERM", "EROFS", "ENOTDIR", "EISDIR", "EEXIST"]) {
725
+ assert.equal(__testing.isStorageUnavailableError({ code }), true, code);
726
+ }
727
+ for (const code of ["ENOENT", "EMFILE", "ELOOP", "ENOSPC"]) {
728
+ assert.equal(__testing.isStorageUnavailableError({ code }), false, code);
729
+ }
730
+ assert.equal(__testing.isStorageUnavailableError(new Error("no code")), false);
731
+ assert.equal(__testing.isStorageUnavailableError(null), false);
732
+ });
733
+
734
+ test("regenerateRegistry reports a typed unavailable result instead of throwing on EACCES", async (t) => {
735
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-skill-373-eacces-"));
736
+ t.after(() => {
737
+ chmodSync(join(cwd, ".atl"), 0o755);
738
+ rmSync(cwd, { recursive: true, force: true });
739
+ });
740
+ mkdirSync(join(cwd, "skills", "a"), { recursive: true });
741
+ writeFileSync(join(cwd, "skills", "a", "SKILL.md"), "---\nname: a\ndescription: A skill.\n---\nbody");
742
+ const first = await __testing.regenerateRegistry(cwd, true);
743
+ assert.equal(first.regenerated, true, "the happy path must succeed before the fault is injected");
744
+
745
+ // A write of an existing registry file succeeds regardless of the
746
+ // directory mode (the file owner owns the open), so the read-only case
747
+ // must remove the managed files first: the fresh-install scenario where
748
+ // storage is read-only and the write actually fails.
749
+ rmSync(join(cwd, ".atl", "skill-registry.md"), { force: true });
750
+ rmSync(join(cwd, ".atl", ".skill-registry.cache.json"), { force: true });
751
+ chmodSync(join(cwd, ".atl"), 0o555);
752
+ const result = await __testing.regenerateRegistry(cwd, true, true);
753
+ assert.equal(result.regenerated, false, "a permission failure must never report success");
754
+ assert.equal(result.reason, "storage-unavailable");
755
+ assert.match(result.warning ?? "", /\.atl[/\\]skill-registry\.md/);
756
+ assert.match(result.warning ?? "", /not writable/);
757
+ assert.match(result.warning ?? "", /\/skill-registry:refresh/);
758
+ assert.equal(existsSync(join(cwd, ".atl", "skill-registry.md")), false);
759
+
760
+ chmodSync(join(cwd, ".atl"), 0o755);
761
+ const recovered = await __testing.regenerateRegistry(cwd, true, true);
762
+ assert.equal(recovered.regenerated, true, "the registry must regenerate once storage is writable again");
763
+ });
764
+
765
+ test("regenerateRegistry degrades truthfully when .atl is a regular file", async (t) => {
766
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-skill-373-enotdir-"));
767
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
768
+ writeFileSync(join(cwd, ".atl"), "not a directory\n");
769
+ const result = await __testing.regenerateRegistry(cwd, true, true);
770
+ assert.equal(result.regenerated, false, "a non-directory .atl must never report success");
771
+ assert.equal(result.reason, "storage-unavailable");
772
+ assert.match(result.warning ?? "", /not writable/);
773
+ });
774
+
775
+ test("regenerateRegistry preserves the diagnostic for unexpected I/O errors", async (t) => {
776
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-skill-373-eloop-"));
777
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
778
+ symlinkSync(join(cwd, ".atl", "self"), join(cwd, ".atl"));
779
+ await assert.rejects(
780
+ __testing.regenerateRegistry(cwd, true, true),
781
+ /ELOOP/,
782
+ "unexpected I/O must keep its own diagnostic instead of a typed unavailable result",
783
+ );
784
+ });