gentle-pi 4.5.0 → 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 (243) 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-music.md +6 -3
  15. package/docs/gentle-shell.md +70 -20
  16. package/docs/install-wizard.md +1 -1
  17. package/docs/mcp-status.md +52 -0
  18. package/docs/prompt-budget.md +28 -0
  19. package/docs/readme-reference.md +82 -21
  20. package/docs/session-profile-format.md +20 -5
  21. package/docs/sound-notifications.md +1 -1
  22. package/docs/star-prompt.md +32 -0
  23. package/docs/work-continuity.md +46 -0
  24. package/extensions/ask-user-question.ts +1 -0
  25. package/extensions/codegraph-tools.ts +38 -4
  26. package/extensions/gentle-agents.ts +477 -50
  27. package/extensions/gentle-ai.ts +1046 -191
  28. package/extensions/gentle-fast.ts +61 -0
  29. package/extensions/gentle-guide.ts +174 -0
  30. package/extensions/gentle-herdr-activity.ts +21 -1
  31. package/extensions/gentle-herdr-agent.ts +144 -0
  32. package/extensions/gentle-music.ts +10 -0
  33. package/extensions/gentle-program-identity.ts +61 -0
  34. package/extensions/gentle-shell.ts +642 -97
  35. package/extensions/gentle-star-prompt.ts +334 -0
  36. package/extensions/gentle-stats.ts +5 -5
  37. package/extensions/gentle-todo.ts +42 -22
  38. package/extensions/history/store.ts +18 -12
  39. package/extensions/skill-registry.ts +35 -3
  40. package/extensions/startup-banner.ts +39 -7
  41. package/lib/agent-assets.ts +74 -17
  42. package/lib/agent-profiles.ts +1 -1
  43. package/lib/agents-config.ts +12 -3
  44. package/lib/agents-keys.ts +8 -16
  45. package/lib/agents-protocol.ts +80 -4
  46. package/lib/agents-runner.ts +105 -4
  47. package/lib/agents-view.ts +6 -1
  48. package/lib/agents-widget.ts +132 -9
  49. package/lib/bridge-cost.ts +28 -0
  50. package/lib/codemode-renderer.ts +16 -0
  51. package/lib/command-palette-catalog.ts +1 -0
  52. package/lib/command-palette.ts +21 -8
  53. package/lib/exploration-budget.ts +62 -0
  54. package/lib/gentle-guide.ts +201 -0
  55. package/lib/gentle-shell-launcher.ts +4 -0
  56. package/lib/herdr-activity.ts +9 -3
  57. package/lib/herdr-task-summary-policy.ts +85 -0
  58. package/lib/inprocess-reviewer.ts +33 -13
  59. package/lib/jobs-sidebar-state.ts +5 -6
  60. package/lib/jobs-widget.ts +16 -52
  61. package/lib/keymaps-customize.ts +81 -0
  62. package/lib/keymaps.ts +291 -0
  63. package/lib/model-fallback-notice.ts +61 -0
  64. package/lib/model-fallback-policy.ts +141 -0
  65. package/lib/model-fallback-store.ts +143 -0
  66. package/lib/model-routing-authority.ts +10 -2
  67. package/lib/nan-provider.ts +3 -2
  68. package/lib/native-review-cli.ts +7 -2
  69. package/lib/notification-customize.ts +48 -51
  70. package/lib/openai-fast-tier.ts +22 -0
  71. package/lib/orchestrator-discovery.ts +5 -1
  72. package/lib/orchestrator-fallback.ts +75 -0
  73. package/lib/pasted-image-paths.ts +113 -0
  74. package/lib/questionnaire/questionnaire-view.ts +121 -7
  75. package/lib/review-candidate-view-owner.ts +4 -0
  76. package/lib/review-candidate-view.ts +10 -7
  77. package/lib/review-host-relay.ts +5 -1
  78. package/lib/review-integration-v2.ts +22 -7
  79. package/lib/review-repository.ts +5 -0
  80. package/lib/session-profile-append-controller.ts +21 -6
  81. package/lib/session-profile-authority.ts +119 -0
  82. package/lib/session-profile-binding.ts +54 -5
  83. package/lib/session-profile-freeze.ts +105 -9
  84. package/lib/session-profile-integration.ts +313 -0
  85. package/lib/session-profile-persistence.ts +63 -9
  86. package/lib/shell-bar.ts +171 -56
  87. package/lib/shell-card.ts +26 -6
  88. package/lib/shell-page.ts +120 -0
  89. package/lib/shell-panel.ts +149 -0
  90. package/lib/shell-prompt.ts +53 -1
  91. package/lib/shell-sidebar-layout.ts +98 -25
  92. package/lib/shell-sidebar.ts +54 -1
  93. package/lib/shell-stats.ts +123 -0
  94. package/lib/shell-todo.ts +71 -0
  95. package/lib/shell-usage.ts +12 -2
  96. package/lib/star-prompt.ts +197 -0
  97. package/lib/verifier-admission.ts +18 -8
  98. package/lib/verifier-settle-reminder.ts +64 -0
  99. package/lib/vim-editor-adapter.ts +6 -1
  100. package/lib/visual-customization-policy.ts +41 -6
  101. package/lib/visual-customize-view.ts +164 -26
  102. package/lib/visual-layout-preview.ts +43 -0
  103. package/lib/yolo-session-policy.ts +28 -1
  104. package/package.json +1 -1
  105. package/runtime/gentle-shell-launcher.mjs +4 -0
  106. package/runtime/native-review-cli.mjs +7 -2
  107. package/runtime/review-integration-v2.mjs +22 -7
  108. package/runtime/windows-session-transport.ps1 +60 -3
  109. package/scripts/bootstrap.sh +4 -1
  110. package/scripts/installer-preflight.mjs +1 -1
  111. package/scripts/pi-update.mjs +113 -3
  112. package/scripts/run-test-suite.mjs +17 -1
  113. package/scripts/shell-snapshot.mjs +340 -0
  114. package/scripts/test-packed-runner.mjs +1 -1
  115. package/scripts/update-agent-body-history.mjs +41 -0
  116. package/scripts/verify-installer-tap.mjs +45 -0
  117. package/scripts/verify-package-files.mjs +2 -0
  118. package/skills/gentle-ai/SKILL.md +2 -2
  119. package/skills/tui-design/NOTICE.md +5 -0
  120. package/skills/tui-design/SKILL.md +56 -0
  121. package/skills/tui-design/references/commands.md +75 -0
  122. package/skills/tui-design/references/critique.md +48 -0
  123. package/skills/tui-design/references/design-doc.md +44 -0
  124. package/skills/tui-design/references/terminal-craft.md +64 -0
  125. package/skills/tui-design/references/visual-loop.md +32 -0
  126. package/tests/agents-protocol.test.ts +53 -1
  127. package/tests/agents-runner.test.ts +168 -3
  128. package/tests/agents-view.test.ts +27 -0
  129. package/tests/agents-widget.test.ts +312 -10
  130. package/tests/bounded-scan-contract.test.ts +39 -0
  131. package/tests/bridge-cost.test.ts +32 -0
  132. package/tests/bundled-install.test.ts +6 -4
  133. package/tests/ci-concurrency.test.ts +11 -0
  134. package/tests/ci-merge-base-identity.test.ts +114 -0
  135. package/tests/codegraph-tools.test.ts +69 -0
  136. package/tests/codemode-rendering.test.ts +22 -2
  137. package/tests/command-palette.test.ts +16 -2
  138. package/tests/commit-slice-signal.test.ts +11 -9
  139. package/tests/delegate-for-reason-contract.test.ts +5 -4
  140. package/tests/design-canvas-server.test.ts +6 -2
  141. package/tests/exploration-budget.test.ts +128 -0
  142. package/tests/fixtures/agent-assets/gentle-ai-worker.strict-tdd-era.md +122 -0
  143. package/tests/fixtures/measure-orchestrator-prompt.mjs +2 -1
  144. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +18 -10
  145. package/tests/fixtures/session-profile-v1/replay.ts +125 -0
  146. package/tests/fixtures/session-profile-v1/session-profile-authority.ts +113 -0
  147. package/tests/fixtures/session-profile-v1/session-profile-binding.ts +83 -0
  148. package/tests/fixtures/session-profile-v1/session-profile-disk-reader.ts +182 -0
  149. package/tests/fixtures/session-profile-v1/session-profile-freeze.ts +290 -0
  150. package/tests/fixtures/session-profile-v1/session-profile-persistence.ts +195 -0
  151. package/tests/fixtures/session-profile-v1/v1-inputs.ts +16 -0
  152. package/tests/fixtures/windows-pipe-availability.ps1 +26 -0
  153. package/tests/fixtures/windows-session-bootstrap.ps1 +6 -2
  154. package/tests/gentle-agents.test.ts +416 -21
  155. package/tests/gentle-ai-exploration-budget.test.ts +135 -0
  156. package/tests/gentle-ai.test.ts +1011 -37
  157. package/tests/gentle-fast.test.ts +73 -0
  158. package/tests/gentle-guide.test.ts +208 -0
  159. package/tests/gentle-herdr-activity.test.ts +76 -2
  160. package/tests/gentle-herdr-agent.test.ts +111 -0
  161. package/tests/gentle-music.test.ts +36 -1
  162. package/tests/gentle-program-identity.test.ts +197 -0
  163. package/tests/gentle-shell-bin.test.ts +49 -26
  164. package/tests/gentle-shell-launcher.test.ts +18 -2
  165. package/tests/gentle-shell.test.ts +1068 -37
  166. package/tests/gentle-stats.test.ts +15 -2
  167. package/tests/gentle-todo.test.ts +50 -4
  168. package/tests/herdr-task-summary-policy.test.ts +128 -0
  169. package/tests/history-store-private-mode.test.ts +40 -0
  170. package/tests/image-paste-chips.test.ts +42 -0
  171. package/tests/inprocess-reviewer.test.ts +122 -0
  172. package/tests/installer-posix-bootstrap.test.ts +67 -5
  173. package/tests/installer-server.test.ts +2 -2
  174. package/tests/installer-windows-diagnostics.test.ts +4 -5
  175. package/tests/isolated-config-home.ts +28 -0
  176. package/tests/jobs-widget.test.ts +25 -37
  177. package/tests/keymaps-customize.test.ts +114 -0
  178. package/tests/keymaps.test.ts +103 -0
  179. package/tests/maintainer/mcp-status.maintest.ts +88 -0
  180. package/tests/maintainer/pi-update-source.maintest.ts +116 -0
  181. package/tests/model-fallback-notice.test.ts +45 -0
  182. package/tests/model-fallback-policy.test.ts +83 -0
  183. package/tests/model-fallback-store.test.ts +111 -0
  184. package/tests/nan-provider.test.ts +4 -4
  185. package/tests/no-self-pause-contract.test.ts +19 -0
  186. package/tests/notification-customize.test.ts +58 -34
  187. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  188. package/tests/odd-routing-contract.test.ts +1 -1
  189. package/tests/orchestrator-fallback.test.ts +82 -0
  190. package/tests/orchestrator-prompt-budget.test.ts +131 -0
  191. package/tests/package-manifest.test.ts +160 -7
  192. package/tests/pasted-image-paths.test.ts +118 -0
  193. package/tests/persona-reply-language.test.ts +61 -0
  194. package/tests/pi-update-launcher.test.ts +32 -8
  195. package/tests/pi-update-source.test.ts +162 -0
  196. package/tests/profile-fast-tier.test.ts +311 -0
  197. package/tests/profile-tier-footer.test.ts +79 -0
  198. package/tests/questionnaire-view.test.ts +150 -0
  199. package/tests/review-candidate-owner-sweep.test.ts +93 -0
  200. package/tests/review-candidate-view.test.ts +51 -0
  201. package/tests/review-controller-native-routing.test.ts +120 -6
  202. package/tests/review-gate.test.ts +24 -0
  203. package/tests/review-inspect-preflight.test.ts +197 -0
  204. package/tests/review-integration-v2-forward.test.ts +59 -0
  205. package/tests/review-repository.test.ts +52 -1
  206. package/tests/review-sidebar-state.test.ts +5 -5
  207. package/tests/run-test-suite.test.ts +61 -5
  208. package/tests/sensitive-path-tools.test.ts +74 -0
  209. package/tests/session-profile-append-controller.test.ts +63 -0
  210. package/tests/session-profile-authority.test.ts +259 -0
  211. package/tests/session-profile-binding.test.ts +15 -0
  212. package/tests/session-profile-extension.test.ts +615 -0
  213. package/tests/session-profile-freeze.test.ts +110 -2
  214. package/tests/session-profile-integration.test.ts +857 -0
  215. package/tests/session-profile-persistence.test.ts +57 -0
  216. package/tests/session-profile-v1-compat.test.ts +221 -0
  217. package/tests/shell-bar.test.ts +113 -55
  218. package/tests/shell-card.test.ts +13 -1
  219. package/tests/shell-page.test.ts +108 -0
  220. package/tests/shell-panel.test.ts +332 -0
  221. package/tests/shell-prompt.test.ts +54 -0
  222. package/tests/shell-render-cache.test.ts +5 -0
  223. package/tests/shell-sidebar-fullscreen.test.ts +12 -0
  224. package/tests/shell-sidebar-layout.test.ts +159 -27
  225. package/tests/shell-stats.test.ts +90 -0
  226. package/tests/shell-usage.test.ts +14 -0
  227. package/tests/skill-registry.test.ts +68 -1
  228. package/tests/star-prompt.test.ts +470 -0
  229. package/tests/startup-banner.test.ts +57 -1
  230. package/tests/task-size-routing-contract.test.ts +45 -1
  231. package/tests/verifier-settle-reminder.test.ts +281 -0
  232. package/tests/verify-first-launch-contract.test.ts +56 -5
  233. package/tests/verify-installer-tap.test.ts +57 -0
  234. package/tests/vim-editor-adapter.test.ts +2 -2
  235. package/tests/visual-customization-policy.test.ts +61 -7
  236. package/tests/visual-customize-view.test.ts +253 -8
  237. package/tests/visual-layout-preview.test.ts +28 -0
  238. package/tests/windows-session-bootstrap.test.ts +105 -2
  239. package/tests/work-continuity-contract.test.ts +86 -0
  240. package/tests/writer-surfaces.test.ts +12 -10
  241. package/tests/yolo-customize.test.ts +30 -11
  242. package/tests/yolo-mode-runtime.test.ts +4 -2
  243. package/tests/yolo-mode.test.ts +16 -2
@@ -336,6 +336,156 @@ test("height stays bounded as the question count grows", () => {
336
336
  assert.match(rendered, /❯ A/);
337
337
  });
338
338
 
339
+ test("long option preview height is bounded to terminal rows in side-by-side mode (#1340)", () => {
340
+ const longPreview = Array.from({ length: 65 }, (_, i) => `Preview line ${i + 1}`).join("\n");
341
+ const { view } = viewWithResult(single(longPreview));
342
+ const renderedLines = view.render(100);
343
+ assert.ok(
344
+ renderedLines.length <= 24,
345
+ `rendered height must be bounded to terminal rows (was ${renderedLines.length} lines, expected <= 24)`,
346
+ );
347
+ const text = renderedLines.join("\n");
348
+ assert.match(text, /Preview line 1/);
349
+ assert.match(text, /\[1–/);
350
+ });
351
+
352
+ test("scrolling with pageDown/pageUp moves the visible preview slice (#1340)", () => {
353
+ const longPreview = Array.from({ length: 65 }, (_, i) => `Preview line ${i + 1}`).join("\n");
354
+ const { view } = viewWithResult(single(longPreview));
355
+ assert.match(render(view, 100), /Preview line 1/);
356
+
357
+ // Page down scrolls the preview window
358
+ view.handleInput("\x1b[6~"); // PageDown
359
+ const pageDownText = render(view, 100);
360
+ assert.doesNotMatch(pageDownText, /Preview line 1\b/);
361
+ assert.match(pageDownText, /Preview line/);
362
+
363
+ // Page up scrolls back
364
+ view.handleInput("\x1b[5~"); // PageUp
365
+ const pageUpText = render(view, 100);
366
+ assert.match(pageUpText, /Preview line 1\b/);
367
+
368
+ // Ctrl+j and Ctrl+k also scroll
369
+ view.handleInput("\x0a"); // ctrl+j
370
+ const ctrlJText = render(view, 100);
371
+ assert.doesNotMatch(ctrlJText, /Preview line 1\b/);
372
+
373
+ view.handleInput("\x0b"); // ctrl+k
374
+ const ctrlKText = render(view, 100);
375
+ assert.match(ctrlKText, /Preview line 1\b/);
376
+
377
+ // Mouse wheel scrolls preview
378
+ view.render(100);
379
+ view.handleMouse({ type: "wheel", button: "none", wheelDelta: 1, x: 50, y: 5, screenX: 50, screenY: 5, width: 100, height: 24, shift: false, alt: false, ctrl: false });
380
+ const wheelDownText = render(view, 100);
381
+ assert.doesNotMatch(wheelDownText, /Preview line 1\b/);
382
+
383
+ // Moving cursor to next option and back resets scroll position
384
+ view.handleInput(KEY.down[0]); // to Beta
385
+ view.handleInput(KEY.up[0]); // back to Alpha
386
+ const resetText = render(view, 100);
387
+ assert.match(resetText, /Preview line 1\b/);
388
+ });
389
+
390
+ test("selecting an option without preview clears scrollability and mouse wheel handling (#1340)", () => {
391
+ const longPreview = Array.from({ length: 65 }, (_, i) => `Preview line ${i + 1}`).join("\n");
392
+ const { view } = viewWithResult(single(longPreview));
393
+
394
+ // Focused on Alpha (has preview): scrollable hint and wheel handling active
395
+ const alphaLines = view.render(100);
396
+ assert.match(alphaLines.join("\n"), /pgup\/pgdn scroll/);
397
+ const alphaWheel = view.handleMouse({
398
+ type: "wheel",
399
+ button: "none",
400
+ wheelDelta: 1,
401
+ x: 50,
402
+ y: 5,
403
+ screenX: 50,
404
+ screenY: 5,
405
+ width: 100,
406
+ height: 24,
407
+ shift: false,
408
+ alt: false,
409
+ ctrl: false,
410
+ });
411
+ assert.equal(alphaWheel?.handled, true);
412
+
413
+ // Move cursor to Beta (no preview)
414
+ view.handleInput(KEY.down[0]);
415
+ const betaLines = view.render(100);
416
+ assert.doesNotMatch(betaLines.join("\n"), /pgup\/pgdn scroll/);
417
+ const betaWheel = view.handleMouse({
418
+ type: "wheel",
419
+ button: "none",
420
+ wheelDelta: 1,
421
+ x: 50,
422
+ y: 5,
423
+ screenX: 50,
424
+ screenY: 5,
425
+ width: 100,
426
+ height: 24,
427
+ shift: false,
428
+ alt: false,
429
+ ctrl: false,
430
+ });
431
+ assert.equal(betaWheel, undefined);
432
+ });
433
+
434
+ test("long option preview height is bounded to terminal rows in inline mode (#1340)", () => {
435
+ const longPreview = Array.from({ length: 65 }, (_, i) => `Preview line ${i + 1}`).join("\n");
436
+ const { view } = viewWithResult(single(longPreview));
437
+ const renderedLines = view.render(60);
438
+ assert.ok(
439
+ renderedLines.length <= 24,
440
+ `inline rendered height must be bounded to terminal rows (was ${renderedLines.length} lines, expected <= 24)`,
441
+ );
442
+ });
443
+
444
+ test("inline preview height stays bounded within terminal rows when options wrap (#1340)", () => {
445
+ const longPreview = Array.from({ length: 65 }, (_, i) => `Preview line ${i + 1}`).join("\n");
446
+ const wrappedOptions = [
447
+ option("Option A", "This is a detailed description that wraps across multiple lines in narrow viewports", longPreview),
448
+ option("Option B", "Another long description that wraps across multiple lines when rendered inline"),
449
+ option("Option C", "Yet another detailed description for the third option taking multiple lines"),
450
+ option("Option D", "Fourth option with a description that also wraps across lines in the terminal"),
451
+ ];
452
+ const { view } = viewWithResult([question("Which configuration should be used for this environment?", wrappedOptions)]);
453
+ const renderedLines = view.render(60);
454
+ assert.ok(
455
+ renderedLines.length <= 24,
456
+ `inline rendered height must be <= 24 terminal rows (was ${renderedLines.length} lines, expected <= 24)`,
457
+ );
458
+ });
459
+
460
+ test("pageDown in inline mode advances by visible preview rows without skipping lines (#1340)", () => {
461
+ const longPreview = Array.from({ length: 65 }, (_, i) => `Preview line ${i + 1}`).join("\n");
462
+ const { view } = viewWithResult(single(longPreview));
463
+
464
+ // Initial render in inline mode (width = 60)
465
+ const initialLines = view.render(60);
466
+ const initialText = initialLines.join("\n");
467
+ assert.match(initialText, /Preview line 1\b/);
468
+
469
+ // Find the last visible preview content line in initial slice
470
+ let lastVisibleLineNum = 1;
471
+ for (let i = 1; i <= 65; i++) {
472
+ if (new RegExp(`Preview line ${i}\\b`).test(initialText)) {
473
+ lastVisibleLineNum = i;
474
+ }
475
+ }
476
+ assert.ok(lastVisibleLineNum < 65, "initial preview should be sliced");
477
+
478
+ // Page down should show the next line without skipping
479
+ view.handleInput("\x1b[6~"); // PageDown
480
+ const pageDownText = view.render(60).join("\n");
481
+ const nextExpectedLine = `Preview line ${lastVisibleLineNum + 1}\\b`;
482
+ assert.match(
483
+ pageDownText,
484
+ new RegExp(nextExpectedLine),
485
+ `PageDown must show next line (${nextExpectedLine}) without skipping lines`,
486
+ );
487
+ });
488
+
339
489
  test("Escape cancels the questionnaire with a cancelled result", () => {
340
490
  const { view, completed } = viewWithResult(single());
341
491
  view.handleInput(KEY.escape);
@@ -0,0 +1,93 @@
1
+ import assert from "node:assert/strict";
2
+ import { randomUUID } from "node:crypto";
3
+ import { mkdirSync, mkdtempSync, readFileSync, readdirSync, realpathSync, rmSync, writeFileSync } from "node:fs";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import {
8
+ assertCandidateOwnerParent,
9
+ removeCandidateOwner,
10
+ setWindowsAclAuthorityForTesting,
11
+ sweepCandidateOwners,
12
+ type CandidateViewOwner,
13
+ } from "../lib/review-candidate-view-owner.ts";
14
+ import { CandidateViewRegistry } from "../lib/review-candidate-view.ts";
15
+
16
+ function fixture(t: test.TestContext, count: number) {
17
+ const commonDir = realpathSync(mkdtempSync(join(tmpdir(), "gentle-pi-owner-sweep-")));
18
+ t.after(() => rmSync(commonDir, { recursive: true, force: true }));
19
+ const parent = join(commonDir, "gentle-ai", "candidate-views");
20
+ mkdirSync(parent, { recursive: true });
21
+ const owners: CandidateViewOwner[] = [];
22
+ for (let i = 0; i < count; i++) {
23
+ const uuid = randomUUID();
24
+ const root = join(parent, uuid);
25
+ const owner: CandidateViewOwner = { version: 1, uuid, token: randomUUID(), pid: process.pid, host: null, root, commonDir };
26
+ writeFileSync(`${root}.owner.json`, JSON.stringify(owner));
27
+ owners.push(owner);
28
+ }
29
+ const snapshot = () => readdirSync(parent).sort().map(name => [name, readFileSync(join(parent, name), "utf8")]);
30
+ return { commonDir, parent, owners, snapshot };
31
+ }
32
+
33
+ test("Windows automatic owner sweeps avoid ACL probes and preserve every marker", t => {
34
+ let aclProbes = 0;
35
+ let gitCalls = 0;
36
+ let writableCalls = 0;
37
+ setWindowsAclAuthorityForTesting(() => { aclProbes++; });
38
+ t.after(() => setWindowsAclAuthorityForTesting());
39
+ for (const count of [0, 1, 7, 30]) {
40
+ const { commonDir, snapshot } = fixture(t, count);
41
+ const before = snapshot();
42
+ for (let pass = 0; pass < 2; pass++) {
43
+ sweepCandidateOwners(commonDir, () => { gitCalls++; return ""; }, () => { writableCalls++; }, "win32");
44
+ assert.deepEqual(snapshot(), before);
45
+ }
46
+ }
47
+ assert.equal(gitCalls, 0);
48
+ assert.equal(writableCalls, 0);
49
+ assert.equal(aclProbes, 0);
50
+ });
51
+
52
+ test("registry startup sweeping on Windows preserves markers without ACL work", t => {
53
+ const { commonDir, snapshot } = fixture(t, 3);
54
+ const before = snapshot();
55
+ let aclProbes = 0;
56
+ const recorded: string[][] = [];
57
+ setWindowsAclAuthorityForTesting(() => { aclProbes++; });
58
+ t.after(() => setWindowsAclAuthorityForTesting());
59
+ const registry = new CandidateViewRegistry((_file, args) => {
60
+ recorded.push([...args]);
61
+ assert.deepEqual(args, ["rev-parse", "--git-common-dir"]);
62
+ return commonDir;
63
+ }, "win32");
64
+ registry.sweepOrphans(commonDir);
65
+ assert.deepEqual(recorded, [["rev-parse", "--git-common-dir"]]);
66
+ assert.deepEqual(snapshot(), before);
67
+ assert.equal(aclProbes, 0);
68
+ });
69
+
70
+ test("explicit Windows owner validation and cleanup still reject untrusted ACLs", t => {
71
+ const { commonDir, owners, snapshot } = fixture(t, 1);
72
+ const before = snapshot();
73
+ const denied = new Error("fixture ACL denied");
74
+ let aclProbes = 0;
75
+ let destructiveCalls = 0;
76
+ setWindowsAclAuthorityForTesting(() => { aclProbes++; throw denied; });
77
+ t.after(() => setWindowsAclAuthorityForTesting());
78
+ assert.throws(() => assertCandidateOwnerParent(commonDir, "win32"), error => error === denied);
79
+ assert.throws(() => removeCandidateOwner(owners[0]!, () => { destructiveCalls++; return ""; }, () => { destructiveCalls++; }, false, "win32"), error => error === denied);
80
+ assert.equal(aclProbes, 2);
81
+ assert.equal(destructiveCalls, 0);
82
+ assert.deepEqual(snapshot(), before);
83
+ });
84
+
85
+ test("unavailable POSIX owner stores remain a best-effort no-op", t => {
86
+ const { commonDir, snapshot } = fixture(t, 1);
87
+ const before = snapshot();
88
+ const missing = join(commonDir, "missing");
89
+ let callbacks = 0;
90
+ sweepCandidateOwners(missing, () => { callbacks++; return ""; }, () => { callbacks++; }, "linux");
91
+ assert.equal(callbacks, 0);
92
+ assert.deepEqual(snapshot(), before);
93
+ });
@@ -732,6 +732,31 @@ test("owner preparation failure names the transient cause code in the wrapper me
732
732
  );
733
733
  });
734
734
 
735
+ test("owner preparation failure surfaces a denial code and omits a code outside the bounded set", (t) => {
736
+ const cwd = repository(t);
737
+ let code = "EACCES";
738
+ t.mock.method(fs, "fsyncSync", () => {
739
+ const error = new Error("fixture denial") as NodeJS.ErrnoException;
740
+ error.code = code;
741
+ throw error;
742
+ });
743
+ syncBuiltinESMExports();
744
+ t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
745
+ const messageFor = (): string => {
746
+ try {
747
+ new CandidateViewRegistry().create({ contributorRoot: cwd });
748
+ } catch (error) {
749
+ assert.ok(error instanceof CandidateViewError);
750
+ assert.equal(error.reason, "candidate-owner-preparation-failed");
751
+ return error.message;
752
+ }
753
+ throw new Error("owner preparation was expected to fail");
754
+ };
755
+ assert.equal(messageFor(), "candidate view owner preparation failed (EACCES)");
756
+ code = "ENOSPC";
757
+ assert.equal(messageFor(), "candidate view owner preparation failed");
758
+ });
759
+
735
760
  test("ordinary cleanup preserves mismatched owner and cleanupAll continues other records", (t) => {
736
761
  const cwd = repository(t);
737
762
  const registry = new CandidateViewRegistry();
@@ -1894,15 +1919,41 @@ test("candidate view accepts internal relative symlink targets and rejects unsaf
1894
1919
  accepted.cleanup();
1895
1920
  }
1896
1921
 
1922
+ // Issue #1811: symlink targets with a single trailing slash pointing to directories are valid POSIX paths
1923
+ const trailingSlashRoot = repository(t);
1924
+ const trailingSlashTarget = "../../.agents/skills/example/";
1925
+ const trailingSlashLink = join(trailingSlashRoot, ".agent", "skills", "example");
1926
+ mkdirSync(join(trailingSlashRoot, ".agents", "skills", "example"), { recursive: true });
1927
+ mkdirSync(join(trailingSlashRoot, ".agent", "skills"), { recursive: true });
1928
+ writeFileSync(join(trailingSlashRoot, ".agents", "skills", "example", "SKILL.md"), "example\n");
1929
+ try {
1930
+ symlinkSync(trailingSlashTarget, trailingSlashLink);
1931
+ } catch {
1932
+ t.skip("platform does not support symlinks");
1933
+ return;
1934
+ }
1935
+ const trailingAccepted = createCandidateView({ contributorRoot: trailingSlashRoot });
1936
+ try {
1937
+ assert.equal(lstatSync(trailingSlashLink).isSymbolicLink(), true);
1938
+ assert.equal(readFileSync(join(trailingAccepted.root, ".agent", "skills", "example", "SKILL.md"), "utf8"), "example\n");
1939
+ trailingAccepted.verify();
1940
+ } finally {
1941
+ trailingAccepted.cleanup();
1942
+ }
1943
+
1897
1944
  for (const [name, target] of [
1898
1945
  ["escape", "../escape"],
1946
+ ["escape with trailing slash", "../escape/"],
1899
1947
  ["absolute", "/absolute-target"],
1900
1948
  ["Windows drive absolute", "C:/absolute-target"],
1901
1949
  ["lowercase Windows drive absolute", "c:/absolute-target"],
1902
1950
  ["metadata", ".git"],
1951
+ ["metadata with trailing slash", ".git/"],
1903
1952
  ["control", "unsafe\ntarget"],
1904
1953
  ["backslash", "unsafe\\target"],
1905
1954
  ["empty segment", "unsafe//target"],
1955
+ ["multiple trailing slashes", "unsafe//"],
1956
+ ["current directory with trailing slash", "./"],
1906
1957
  ] as const) {
1907
1958
  const contributorRoot = repository(t);
1908
1959
  try {
@@ -423,7 +423,7 @@ function candidateRepository(t: test.TestContext): string {
423
423
  writeFileSync(join(cwd, "tracked.txt"), "base\n");
424
424
  git("add", "tracked.txt");
425
425
  git("-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "base");
426
- return realpathSync(cwd);
426
+ return realpathSync(git("rev-parse", "--show-toplevel").trim());
427
427
  }
428
428
 
429
429
  test("approved acknowledgement burn tears down the retained candidate view and keeps its projection", async (t) => {
@@ -965,7 +965,7 @@ function repository(t: test.TestContext): string {
965
965
  execFileSync("git", ["add", "tracked.txt"], { cwd, stdio: "ignore" });
966
966
  execFileSync("git", ["-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "base"], { cwd, stdio: "ignore" });
967
967
  writeFileSync(join(cwd, "tracked.txt"), "candidate\n");
968
- return cwd;
968
+ return realpathSync(execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd, encoding: "utf8" }).trim());
969
969
  }
970
970
 
971
971
  test("candidate lifecycle sweeps startup and cleans every shutdown including reload", async (t) => {
@@ -2962,22 +2962,97 @@ test("INSPECT rejects malformed committed-range selectors before negotiated STAT
2962
2962
  },
2963
2963
  } as unknown as NativeReviewCli;
2964
2964
 
2965
- for (const input of [
2966
- { baseRef: "HEAD", committedOnly: false },
2967
- { committedOnly: true },
2968
- { baseRef: "HEAD", committedOnly: true, mode: "ordinary" },
2965
+ for (const { input, reason, field } of [
2966
+ { input: { baseRef: "HEAD", committedOnly: false }, reason: "committed-only-required" },
2967
+ { input: { baseRef: "HEAD" }, reason: "committed-only-required" },
2968
+ { input: { committedOnly: true }, reason: "committed-only-invalid" },
2969
+ { input: { baseRef: " HEAD", committedOnly: true }, reason: "base-ref-invalid" },
2970
+ { input: { baseRef: 42, committedOnly: true }, reason: "base-ref-invalid" },
2971
+ { input: { baseRef: "HEAD", committedOnly: true, mode: "ordinary" }, reason: "unknown-field", field: "mode" },
2969
2972
  ]) {
2970
2973
  const rejected = await __testing.executeReviewControllerOperation(
2971
2974
  { operation: "inspect", input: JSON.stringify(input) },
2972
2975
  cwd,
2973
2976
  native,
2974
2977
  );
2978
+ assert.equal(rejected.status, "blocked");
2979
+ assert.equal(rejected.reason, reason);
2980
+ assert.equal(rejected.field, field);
2975
2981
  assert.equal(rejected.outcome, "native-inspect-input-invalid");
2982
+ assert.equal(rejected.mutation_performed, false);
2976
2983
  assert.equal(rejected.mutation_outcome, "none");
2984
+ assert.equal(targetCalls, 0);
2977
2985
  }
2978
2986
  assert.equal(targetCalls, 0);
2979
2987
  });
2980
2988
 
2989
+ test("INSPECT accepts empty object and empty string input for ambient inspection", async (t) => {
2990
+ const cwd = repository(t);
2991
+ let targetCalls = 0;
2992
+ const requests: Array<Record<string, unknown>> = [];
2993
+ const native = {
2994
+ targetStatus: async (request: Record<string, unknown>) => {
2995
+ targetCalls += 1;
2996
+ requests.push(request);
2997
+ return startStatus(cwd);
2998
+ },
2999
+ } as unknown as NativeReviewCli;
3000
+
3001
+ for (const input of ["{}", "", " "]) {
3002
+ const result = await __testing.executeReviewControllerOperation(
3003
+ { operation: "inspect", input },
3004
+ cwd,
3005
+ native,
3006
+ );
3007
+ assert.equal(result.status, "ready", `expected ready for input ${JSON.stringify(input)}`);
3008
+ }
3009
+ assert.equal(targetCalls, 3);
3010
+ for (const request of requests) {
3011
+ assert.equal(request.baseRef, undefined);
3012
+ assert.equal(request.committedOnly, undefined);
3013
+ }
3014
+ });
3015
+
3016
+ test("INSPECT ambient input with top-level selected-empty stays read-only when selection is not required", async (t) => {
3017
+ const cwd = repository(t);
3018
+ const requests: Array<Record<string, unknown>> = [];
3019
+ let mutationCalls = 0;
3020
+ const mutationMethods = [
3021
+ "start", "answerConsent", "reclaim", "recover", "abandon",
3022
+ "quarantineLegacy", "reconcileAuthority", "repairLegacyAlias", "repair",
3023
+ "captureResult", "captureCorrectionPlan", "captureProviderRole", "captureUnachievableLens",
3024
+ "reviewMode",
3025
+ ] as const satisfies readonly (keyof NativeReviewCli)[];
3026
+ const mutationSpies = Object.fromEntries(mutationMethods.map((method) => [method, async () => {
3027
+ mutationCalls += 1;
3028
+ throw new Error(`Unexpected NativeReviewCli.${method} call during ambient INSPECT`);
3029
+ }]));
3030
+ const native = {
3031
+ ...mutationSpies,
3032
+ targetStatus: async (request: Record<string, unknown>) => {
3033
+ requests.push(request);
3034
+ return startStatus(cwd);
3035
+ },
3036
+ } as unknown as NativeReviewCli;
3037
+ for (const input of [undefined, "{}", "", " "]) {
3038
+ const parameters = { operation: "inspect", ...(input === undefined ? {} : { input }), untrackedScope: "select", intendedUntracked: [] };
3039
+ const result = await __testing.executeReviewControllerOperation(parameters, cwd, native);
3040
+ assert.equal(result.status, "ready");
3041
+ assert.equal(mutationCalls, 0, `unexpected mutation for input ${JSON.stringify(input)}`);
3042
+ assert.equal(result.untracked_selection, "not-required");
3043
+ assert.deepEqual(parameters.intendedUntracked, []);
3044
+ }
3045
+ assert.equal(requests.length, 4);
3046
+ for (const request of requests) {
3047
+ assert.equal(request.cwd, cwd);
3048
+ assert.equal("baseRef" in request, false);
3049
+ assert.equal("committedOnly" in request, false);
3050
+ // Without a provider selection stop, no selection submission is needed.
3051
+ assert.equal("untrackedScope" in request, false);
3052
+ assert.equal("intendedUntracked" in request, false);
3053
+ }
3054
+ });
3055
+
2981
3056
  test("ordinary START keeps default and explicit base selection fail-closed before native mutation", async (t) => {
2982
3057
  const cwd = repository(t);
2983
3058
  let targetCalls = 0;
@@ -3274,3 +3349,42 @@ test("collect-state public STATUS, INSPECT, and START serialize each provider co
3274
3349
  assert.ok(serialized.length < 2 * JSON.stringify(bindings).length, `${parameters.operation} answer (${serialized.length} characters) must not double the ${JSON.stringify(bindings).length}-character binding projection`);
3275
3350
  }
3276
3351
  });
3352
+
3353
+ test("a correction-plan binding bound to the frozen authority target is captured after the worktree drifts", async () => {
3354
+ // gentle-ai binds correction-plan collect inputs to authority_target_identity
3355
+ // (the frozen candidate), not to the live target_identity, once the
3356
+ // candidate has drifted; the host must accept the target the provider issued.
3357
+ const lineageId = "drifted-correction";
3358
+ const frozenTarget = `sha256:${"c".repeat(64)}`;
3359
+ const input = correctionPlanInput(lineageId);
3360
+ (input.arguments as { name: string; value: string; token?: string }[])[1] = { name: "target", value: frozenTarget, token: `--target=${frozenTarget}` };
3361
+ const drifted = (): ReviewStatusV3 => ({ ...status(lineageId, [input], "correction_required"), authorityTargetIdentity: frozenTarget });
3362
+ let captures = 0;
3363
+ const native = {
3364
+ targetStatus: async () => drifted(),
3365
+ captureCorrectionPlan: async () => {
3366
+ captures += 1;
3367
+ // The provider echoes the frozen target it was invoked with.
3368
+ return { schema: "gentle-ai.review-last-event-closure/v1", operation: "review.capture-correction-plan", lineageId, targetIdentity: frozenTarget, state: "correction_required", storeRevision: SHA };
3369
+ },
3370
+ } as unknown as NativeReviewCli;
3371
+ const { controller, capture } = reviewRuntime(native, new CandidateViewRegistry());
3372
+ const context = reviewContext(process.cwd());
3373
+ const listed = await controller.execute("", { operation: "status", lineageId }, undefined, undefined, context);
3374
+ const captured = await capture.execute("", { lineageId, collectBinding: bindingOf(listed.details as Record<string, unknown>), correctionLines: 1 }, undefined, undefined, context);
3375
+ assert.equal((captured.details as { outcome?: string }).outcome, "native-last-event-closure");
3376
+ assert.equal((captured.details as { mutation_outcome?: string }).mutation_outcome === "none", false);
3377
+ assert.equal(captures, 1);
3378
+
3379
+ // A target that is neither the frozen authority target nor the live one stays refused.
3380
+ const foreign = correctionPlanInput(lineageId);
3381
+ (foreign.arguments as { name: string; value: string; token?: string }[])[1] = { name: "target", value: `sha256:${"d".repeat(64)}`, token: `--target=sha256:${"d".repeat(64)}` };
3382
+ const foreignNative = {
3383
+ targetStatus: async () => ({ ...status(lineageId, [foreign], "correction_required"), authorityTargetIdentity: frozenTarget }),
3384
+ captureCorrectionPlan: async () => { throw new Error("must not capture"); },
3385
+ } as unknown as NativeReviewCli;
3386
+ const runtime = reviewRuntime(foreignNative, new CandidateViewRegistry());
3387
+ const foreignListed = await runtime.controller.execute("", { operation: "status", lineageId }, undefined, undefined, context);
3388
+ const refused = await runtime.capture.execute("", { lineageId, collectBinding: bindingOf(foreignListed.details as Record<string, unknown>), correctionLines: 1 }, undefined, undefined, context);
3389
+ assert.equal((refused.details as { outcome?: string }).outcome, "capture-binding-rejected");
3390
+ });
@@ -956,3 +956,27 @@ test("release fast path remote head recheck detects an advanced or unresolvable
956
956
  });
957
957
  assert.deepEqual(missing, { advanced: true, remote_head: null });
958
958
  });
959
+
960
+ // gentle-shell#2552 review: an environment-injected GIT_CONFIG_GLOBAL carrying
961
+ // url.insteadOf must not redirect the publication destination probe; the probe
962
+ // strips the key so Git reads the default config paths, never env overrides.
963
+ test("push destination probe ignores environment-injected url.insteadOf rewrites", (t) => {
964
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-probe-redirect-"));
965
+ t.after(() => rmSync(cwd, { recursive: true, force: true }));
966
+ // A hostile inherited GIT_DIR would point `git init` away from the fixture.
967
+ const fixtureEnvironment = Object.fromEntries(Object.entries(process.env).filter(([key]) => !key.toUpperCase().startsWith("GIT_")));
968
+ const git = (...args: string[]) => execFileSync("git", args, { cwd, encoding: "utf8", env: fixtureEnvironment });
969
+ git("init", "-b", "main");
970
+ git("remote", "add", "origin", "https://example.invalid/owner/repo.git");
971
+ const hostile = join(cwd, "hostile.gitconfig");
972
+ writeFileSync(hostile, '[url "https://redirect.invalid/"]\n\tinsteadOf = https://example.invalid/\n');
973
+ const prior = process.env.GIT_CONFIG_GLOBAL;
974
+ try {
975
+ process.env.GIT_CONFIG_GLOBAL = hostile;
976
+ const destination = resolveConfiguredPushDestinationV1(cwd, "origin");
977
+ assert.equal(destination.url, "https://example.invalid/owner/repo.git");
978
+ } finally {
979
+ if (prior === undefined) delete process.env.GIT_CONFIG_GLOBAL;
980
+ else process.env.GIT_CONFIG_GLOBAL = prior;
981
+ }
982
+ });