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
@@ -0,0 +1,197 @@
1
+ import assert from "node:assert/strict";
2
+ import { chmodSync, existsSync, mkdirSync, mkdtempSync, realpathSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
3
+ import { execFileSync } from "node:child_process";
4
+ import { tmpdir } from "node:os";
5
+ import { join } from "node:path";
6
+ import test from "node:test";
7
+ import { __testing } from "../extensions/gentle-ai.ts";
8
+ import type { NativeReviewCli } from "../lib/native-review-cli.ts";
9
+
10
+ // gentle-ai#2196: inspect must not advertise a review.start whose candidate-view
11
+ // materialization is already known to fail. START verifies cheap non-mutating
12
+ // invariants (candidate owner parent privacy, symlink capability for trees that
13
+ // track symlinks); inspect runs the same non-persistent checks before a ready
14
+ // advertisement leaves the controller, with the typed codes START would emit.
15
+
16
+ function git(cwd: string, ...arguments_: string[]): string {
17
+ return execFileSync("git", [...arguments_], { cwd, encoding: "utf8" }).trim();
18
+ }
19
+
20
+ function fixtureRepository(tracksSymlink: boolean): { root: string; candidateTree: string } {
21
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "inspect-preflight-")));
22
+ git(root, "init", "--quiet", "-b", "main");
23
+ writeFileSync(join(root, "tracked.txt"), "base\n");
24
+ if (tracksSymlink) symlinkSync("tracked.txt", join(root, "link"));
25
+ git(root, "add", "-A");
26
+ execFileSync("git", ["-c", "user.email=t@example.com", "-c", "user.name=T", "commit", "--quiet", "-m", "base"], { cwd: root, encoding: "utf8" });
27
+ return { root, candidateTree: git(root, "rev-parse", "HEAD^{tree}") };
28
+ }
29
+
30
+ const START_TRANSITION = { kind: "execute", execute: { operation: "review.start", arguments: [] } } as const;
31
+
32
+ function readyNative(candidateTree: string): NativeReviewCli {
33
+ return {
34
+ reviewMode: async () => ({ operation: "status", status: { effective: "on", source: "global", global: "on", cloneLocal: "" } }),
35
+ targetStatus: async () => ({
36
+ action: "start",
37
+ applicability: "unrelated",
38
+ targetIdentity: `sha256:${"a".repeat(64)}`,
39
+ projection: { projection: "workspace", baseTree: candidateTree, initialReviewTree: candidateTree, currentCandidateTree: candidateTree, paths: [] },
40
+ // raw is the full native STATUS body, which carries the executable transition.
41
+ raw: { schema: "gentle-ai.review-integration.status/v7", action: "start", reason_code: "fresh_target_ready", next_transition: START_TRANSITION },
42
+ nextTransition: { kind: "execute", execute: { operation: "review.start", arguments: [] } },
43
+ }),
44
+ } as unknown as NativeReviewCli;
45
+ }
46
+
47
+ const inspect = (root: string, native: NativeReviewCli) =>
48
+ __testing.executeReviewControllerOperation({ operation: "inspect" }, root, native, undefined, null) as Promise<Record<string, unknown>>;
49
+
50
+ const posix = process.platform !== "win32";
51
+
52
+ for (const quota of [{ name: "plain", untrackedScope: undefined }] as const) {
53
+ test(`inspect withholds a ready START advertisement when the candidate owner parent is not private (${quota.name}, gentle-ai#2196)`, { skip: posix ? false : "POSIX privacy modes are unavailable on Windows" }, async t => {
54
+ const { root } = fixtureRepository(false);
55
+ t.after(() => rmSync(root, { recursive: true, force: true }));
56
+ const views = join(root, ".git", "gentle-ai", "candidate-views");
57
+ mkdirSync(views, { recursive: true, mode: 0o700 });
58
+ chmodSync(views, 0o777);
59
+ const result = await inspect(root, readyNative(git(root, "rev-parse", "HEAD^{tree}")));
60
+ assert.equal(result.status, "blocked");
61
+ assert.equal(result.outcome, "candidate-view-preflight-blocked");
62
+ assert.equal((result.diagnostics as { code?: string }).code, "candidate-owner-parent-privacy");
63
+ assert.equal(result.mutation_performed, false);
64
+ assert.equal(result.lineage_created, false);
65
+ });
66
+ }
67
+
68
+ test("inspect withholds a ready START advertisement for any other candidate owner failure START would repeat (gentle-ai#2196)", { skip: posix ? false : "POSIX symlinked owner parent fixture" }, async t => {
69
+ const { root, candidateTree } = fixtureRepository(false);
70
+ t.after(() => rmSync(root, { recursive: true, force: true }));
71
+ const elsewhere = join(root, ".git", "elsewhere");
72
+ mkdirSync(elsewhere, { mode: 0o700 });
73
+ mkdirSync(join(root, ".git", "gentle-ai"), { mode: 0o700 });
74
+ symlinkSync(elsewhere, join(root, ".git", "gentle-ai", "candidate-views"));
75
+ const result = await inspect(root, readyNative(candidateTree));
76
+ assert.equal(result.status, "blocked");
77
+ assert.equal(result.outcome, "candidate-view-preflight-blocked");
78
+ assert.equal((result.diagnostics as { code?: string }).code, "candidate-owner-preparation-failed");
79
+ assert.equal(result.mutation_performed, false);
80
+ assert.equal(result.lineage_created, false);
81
+ });
82
+
83
+ const unprivileged = posix && process.getuid?.() !== 0;
84
+
85
+ test("inspect withholds a ready START advertisement when the missing owner parent cannot be created under its nearest existing ancestor (gentle-ai#2196)", { skip: unprivileged ? false : "needs POSIX permission bits enforced for this process" }, async t => {
86
+ const { root, candidateTree } = fixtureRepository(false);
87
+ const commonDir = join(root, ".git");
88
+ t.after(() => {
89
+ chmodSync(commonDir, 0o755);
90
+ rmSync(root, { recursive: true, force: true });
91
+ });
92
+ // The owner parent is missing, so START would try to create it under .git;
93
+ // without write access there that creation fails, and START with it.
94
+ chmodSync(commonDir, 0o555);
95
+ const result = await inspect(root, readyNative(candidateTree));
96
+ assert.equal(result.status, "blocked");
97
+ assert.equal(result.outcome, "candidate-view-preflight-blocked");
98
+ assert.deepEqual(result.diagnostics, { code: "candidate-owner-preparation-failed", message: "candidate view owner preparation failed (EACCES)" });
99
+ assert.equal(result.mutation_performed, false);
100
+ assert.equal(result.lineage_created, false);
101
+ assert.equal(existsSync(join(commonDir, "gentle-ai")), false, "the preflight creates nothing");
102
+ });
103
+
104
+ test("inspect withholds a ready START advertisement when the frozen tree tracks symlinks this process cannot create (gentle-ai#2196)", { skip: posix ? false : "fixture needs a tracked symlink" }, async t => {
105
+ const { root, candidateTree } = fixtureRepository(true);
106
+ t.after(() => rmSync(root, { recursive: true, force: true }));
107
+ __testing.setCandidateViewSymlinkProbeForTesting(() => { throw new Error("EPERM (probe)"); });
108
+ t.after(() => __testing.setCandidateViewSymlinkProbeForTesting(undefined));
109
+ const result = await inspect(root, readyNative(candidateTree));
110
+ assert.equal(result.status, "blocked");
111
+ assert.equal(result.outcome, "candidate-view-preflight-blocked");
112
+ assert.equal((result.diagnostics as { code?: string }).code, "symlink-materialization-failed");
113
+ assert.match(String((result.diagnostics as { message?: string }).message), /enable symlink capability out of band before retrying START/);
114
+ });
115
+
116
+ test("a blocked inspect result carries no executable START transition but keeps the native status data (gentle-ai#2196)", { skip: posix ? false : "fixture needs a tracked symlink" }, async t => {
117
+ const { root, candidateTree } = fixtureRepository(true);
118
+ t.after(() => rmSync(root, { recursive: true, force: true }));
119
+ __testing.setCandidateViewSymlinkProbeForTesting(() => { throw new Error("EPERM (probe)"); });
120
+ t.after(() => __testing.setCandidateViewSymlinkProbeForTesting(undefined));
121
+ const result = await inspect(root, readyNative(candidateTree));
122
+ assert.equal(result.status, "blocked");
123
+ assert.equal(result.next_transition, undefined);
124
+ assert.deepEqual(result.result, { schema: "gentle-ai.review-integration.status/v7", action: "start", reason_code: "fresh_target_ready" });
125
+ assert.equal(JSON.stringify(result).includes("review.start"), false, "no nested field may still advertise review.start");
126
+ });
127
+
128
+ test("a frozen tree without symlinks never consults the symlink capability probe (gentle-ai#2196)", async t => {
129
+ const { root, candidateTree } = fixtureRepository(false);
130
+ t.after(() => rmSync(root, { recursive: true, force: true }));
131
+ let probed = 0;
132
+ __testing.setCandidateViewSymlinkProbeForTesting(() => { probed++; throw new Error("EPERM (probe)"); });
133
+ t.after(() => __testing.setCandidateViewSymlinkProbeForTesting(undefined));
134
+ const result = await inspect(root, readyNative(candidateTree));
135
+ assert.equal(probed, 0, "no symlink entries in the frozen tree means no capability probe");
136
+ assert.equal(result.status, "ready", "a healthy candidate keeps its advertisement");
137
+ });
138
+
139
+ test("a healthy worktree keeps the ready START advertisement (gentle-ai#2196)", { skip: posix ? false : "real symlink probe depends on runner capability" }, async t => {
140
+ const { root, candidateTree } = fixtureRepository(true);
141
+ t.after(() => rmSync(root, { recursive: true, force: true }));
142
+ const result = await inspect(root, readyNative(candidateTree));
143
+ assert.equal(result.status, "ready");
144
+ assert.equal(result.outcome, undefined);
145
+ });
146
+
147
+ test("the symlink capability probe samples the filesystem that will hold the candidate view, never tmpdir (gentle-ai#2196)", { skip: posix ? false : "fixture needs a tracked symlink" }, async t => {
148
+ const { root, candidateTree } = fixtureRepository(true);
149
+ t.after(() => rmSync(root, { recursive: true, force: true }));
150
+ let probeRoot: string | undefined;
151
+ __testing.setCandidateViewSymlinkProbeForTesting((directory: string) => {
152
+ probeRoot = directory;
153
+ });
154
+ t.after(() => __testing.setCandidateViewSymlinkProbeForTesting(undefined));
155
+ const result = await inspect(root, readyNative(candidateTree));
156
+ assert.equal(result.status, "ready");
157
+ assert.ok(probeRoot !== undefined, "a symlink-tracking frozen tree consults the capability probe");
158
+ assert.ok(probeRoot!.startsWith(join(root, ".git")), `probe must run inside the candidate-view filesystem, saw: ${probeRoot}`);
159
+ });
160
+
161
+ test("inspect withholds the ready START advertisement when the symlink capability stays unconfirmed (gentle-ai#2196)", { skip: posix ? false : "fixture needs a tracked symlink" }, async t => {
162
+ const { root, candidateTree } = fixtureRepository(true);
163
+ t.after(() => rmSync(root, { recursive: true, force: true }));
164
+ __testing.setCandidateViewSymlinkProbeForTesting(() => {
165
+ throw new __testing.CandidateViewSymlinkProbeUnavailableError("no existing ancestor could host the probe");
166
+ });
167
+ t.after(() => __testing.setCandidateViewSymlinkProbeForTesting(undefined));
168
+ const result = await inspect(root, readyNative(candidateTree));
169
+ assert.equal(result.status, "blocked");
170
+ assert.equal(result.outcome, "candidate-view-preflight-blocked");
171
+ assert.equal((result.diagnostics as { code?: string }).code, "symlink-capability-unconfirmed");
172
+ assert.equal(result.mutation_performed, false);
173
+ assert.equal(result.lineage_created, false);
174
+ });
175
+
176
+ test("an incomplete symlink scan never claims a symlink-free tree and keeps the advertisement; START owns unreadable trees (gentle-ai#2196)", async t => {
177
+ const { root } = fixtureRepository(false);
178
+ t.after(() => rmSync(root, { recursive: true, force: true }));
179
+ let probed = 0;
180
+ __testing.setCandidateViewSymlinkProbeForTesting(() => {
181
+ probed++;
182
+ });
183
+ t.after(() => __testing.setCandidateViewSymlinkProbeForTesting(undefined));
184
+ const result = await inspect(root, readyNative("f".repeat(40)));
185
+ assert.equal(result.status, "ready", "an unconfirmed scan withholds no advertisement");
186
+ assert.equal(probed, 0, "an unconfirmed scan never consults the capability probe");
187
+ });
188
+
189
+ test("the scan classification itself is a tri-state: unreadable trees are unconfirmed, never symlink-free (gentle-ai#2196)", async t => {
190
+ const { root } = fixtureRepository(true);
191
+ t.after(() => rmSync(root, { recursive: true, force: true }));
192
+ assert.equal(__testing.scanCandidateTreeForSymlinks(root, git(root, "rev-parse", "HEAD^{tree}")), "tracks-symlinks");
193
+ const bare = fixtureRepository(false);
194
+ t.after(() => rmSync(bare.root, { recursive: true, force: true }));
195
+ assert.equal(__testing.scanCandidateTreeForSymlinks(bare.root, git(bare.root, "rev-parse", "HEAD^{tree}")), "no-symlinks");
196
+ assert.equal(__testing.scanCandidateTreeForSymlinks(bare.root, "f".repeat(40)), "unconfirmed", "an unreadable tree is never classified symlink-free");
197
+ });
@@ -1024,3 +1024,62 @@ test("START/v4 accepts every risk reason code and signal the published start sch
1024
1024
  unknown.risk_reasons = [{ code: "code_from_a_newer_cli" }];
1025
1025
  assert.throws(() => decodeReviewStartV4(unknown), /risk_reasons\[0\]\.code is unsupported/);
1026
1026
  });
1027
+
1028
+ // A base-diff target keeps its selector in the intended-untracked submission
1029
+ // (provider-issued, exact forms only), so re-entering STATUS resolves the same
1030
+ // target instead of the workspace candidate.
1031
+ const PROVIDER_PREFIX = ["--contract=gentle-ai.review-integration/v2", "--next-transition=true", "--agent=pi"];
1032
+ const SELECTION_TOKEN = "--intended-untracked-selection={{value}}";
1033
+ const TREE = "a".repeat(40);
1034
+
1035
+ function intendedUntrackedSubmissionStatus(selector: readonly string[], location?: number): JsonObject {
1036
+ const body = initialIntendedUntrackedStatusV6();
1037
+ const input = ((body.next_transition as JsonObject).collect as JsonObject).inputs as JsonObject[];
1038
+ const submission = input[0]!.submission as JsonObject;
1039
+ const tokens = [...PROVIDER_PREFIX, ...selector, SELECTION_TOKEN];
1040
+ submission.argument_tokens = tokens;
1041
+ (submission.value as JsonObject).substitution_location = location ?? tokens.length - 1;
1042
+ return body;
1043
+ }
1044
+
1045
+ function decodedSubmissionTokens(body: JsonObject): readonly string[] {
1046
+ const decoded = decodeReviewStatusV3(body);
1047
+ const input = decoded.nextTransition?.kind === "collect" ? decoded.nextTransition.collect?.inputs[0] : undefined;
1048
+ return input?.submission?.argumentTokens ?? [];
1049
+ }
1050
+
1051
+ test("status/v6 intended-untracked submission accepts the workspace and provider-issued base-diff selectors", () => {
1052
+ assert.deepEqual(decodedSubmissionTokens(intendedUntrackedSubmissionStatus(["--projection=workspace"])), [...PROVIDER_PREFIX, "--projection=workspace", SELECTION_TOKEN]);
1053
+ for (const scope of ["--committed-only=true", "--workspace-overlay=true"]) {
1054
+ const selector = [`--base-ref=${TREE}`, scope];
1055
+ assert.deepEqual(decodedSubmissionTokens(intendedUntrackedSubmissionStatus(selector)), [...PROVIDER_PREFIX, ...selector, SELECTION_TOKEN]);
1056
+ }
1057
+ assert.deepEqual(decodedSubmissionTokens(intendedUntrackedSubmissionStatus([`--base-ref=${"b".repeat(64)}`, "--committed-only=true"])).length, 6);
1058
+ });
1059
+
1060
+ test("status/v6 intended-untracked submission rejects any other selector or substitution location", () => {
1061
+ for (const selector of [
1062
+ ["--projection=staged"],
1063
+ ["--base-ref=HEAD", "--committed-only=true"],
1064
+ [`--base-ref=${TREE}`],
1065
+ ["--committed-only=true"],
1066
+ [],
1067
+ [`--base-ref=${TREE}`, "--committed-only=true", "--projection=workspace"],
1068
+ ]) {
1069
+ assert.throws(() => decodeReviewStatusV3(intendedUntrackedSubmissionStatus(selector)), /argument_tokens|substitution/, selector.join(" "));
1070
+ }
1071
+ assert.throws(() => decodeReviewStatusV3(intendedUntrackedSubmissionStatus([`--base-ref=${TREE}`, "--committed-only=true"], 4)), /substitution_location/);
1072
+ });
1073
+
1074
+ test("targetStatus runs a provider-issued base-diff submission as issued instead of re-forwarding the request base-ref", async () => {
1075
+ const queue = queuedTargetStatusAdapter();
1076
+ const tokens = [...PROVIDER_PREFIX, `--base-ref=${TREE}`, "--committed-only=true", SELECTION_TOKEN];
1077
+ await targetStatusClient(queue.adapter).targetStatus({
1078
+ cwd: "/repo", baseRef: "deadbeef", committedOnly: true,
1079
+ intendedUntrackedSelection: { argumentTokens: tokens, value: '{"selection":true}' },
1080
+ });
1081
+ assert.deepEqual(queue.calls[0], [
1082
+ "review", "status", "--cwd", "/repo",
1083
+ ...PROVIDER_PREFIX, `--base-ref=${TREE}`, "--committed-only=true", '--intended-untracked-selection={"selection":true}',
1084
+ ]);
1085
+ });
@@ -4,7 +4,7 @@ import { cpSync, mkdtempSync, mkdirSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { dirname, join, resolve } from "node:path";
6
6
  import test from "node:test";
7
- import { resolveRepositoryAuthorityV1, reviewGitEnvironment, setReviewRepositoryIdentityRetryHookForTesting } from "../lib/review-repository.ts";
7
+ import { publicationProbeGitEnvironment, resolveRepositoryAuthorityV1, reviewGitEnvironment, setReviewRepositoryIdentityRetryHookForTesting } from "../lib/review-repository.ts";
8
8
  import { REVIEW_MODE, ReviewTransactionStore, createReviewState, setReviewMutationLockPlatformForTesting } from "../lib/review-transaction.ts";
9
9
  import { REVIEW_LENS, REVIEW_ROUTE } from "../lib/review-triggers.ts";
10
10
  import { qualifiedReviewLockPlatform, testSnapshot } from "./review-test-fixtures.ts";
@@ -76,6 +76,57 @@ test("review Git environment rejects inherited unsafe Git overrides", () => {
76
76
  }
77
77
  });
78
78
 
79
+ // gentle-shell#2552: the unit-test runner pins the config-file keys for
80
+ // hermeticity, and reviewGitEnvironment overrides them itself, so inherited
81
+ // values must be tolerated instead of failing closed; routing overrides do not.
82
+ test("review Git environment tolerates inherited config-file keys and still pins them", () => {
83
+ const prior = { GIT_CONFIG_GLOBAL: process.env.GIT_CONFIG_GLOBAL, GIT_CONFIG_NOSYSTEM: process.env.GIT_CONFIG_NOSYSTEM, GIT_CONFIG_COUNT: process.env.GIT_CONFIG_COUNT };
84
+ try {
85
+ process.env.GIT_CONFIG_GLOBAL = "/hostile/global.gitconfig";
86
+ process.env.GIT_CONFIG_NOSYSTEM = "1";
87
+ const environment = reviewGitEnvironment();
88
+ assert.equal(environment.GIT_CONFIG_GLOBAL, "/dev/null");
89
+ assert.equal(environment.GIT_CONFIG_SYSTEM, "/dev/null");
90
+ assert.equal(environment.GIT_CONFIG_NOSYSTEM, "1");
91
+ process.env.GIT_CONFIG_COUNT = "1";
92
+ assert.throws(() => reviewGitEnvironment(), /REVIEW_GIT_ENV_UNSAFE/);
93
+ } finally {
94
+ for (const [key, value] of Object.entries(prior)) {
95
+ if (value === undefined) delete process.env[key];
96
+ else process.env[key] = value;
97
+ }
98
+ }
99
+ });
100
+
101
+ // gentle-shell#2552: deleting the config-file keys makes the probe fall back to
102
+ // the host's default config paths, which are not environment-injectable; the
103
+ // unit-stage runner redirects HOME instead of relying on preserved pins.
104
+ test("publication probe drops inherited config-file keys and routing overrides", () => {
105
+ const prior = { GIT_CONFIG_GLOBAL: process.env.GIT_CONFIG_GLOBAL, GIT_CONFIG_SYSTEM: process.env.GIT_CONFIG_SYSTEM, GIT_CONFIG_NOSYSTEM: process.env.GIT_CONFIG_NOSYSTEM, GIT_DIR: process.env.GIT_DIR, GIT_CONFIG_COUNT: process.env.GIT_CONFIG_COUNT, GIT_CONFIG_KEY_0: process.env.GIT_CONFIG_KEY_0, GIT_CONFIG_VALUE_0: process.env.GIT_CONFIG_VALUE_0 };
106
+ try {
107
+ process.env.GIT_CONFIG_GLOBAL = "/pinned/global.gitconfig";
108
+ process.env.GIT_CONFIG_SYSTEM = "/pinned/system.gitconfig";
109
+ process.env.GIT_CONFIG_NOSYSTEM = "1";
110
+ process.env.GIT_DIR = "/unsafe";
111
+ process.env.GIT_CONFIG_COUNT = "1";
112
+ process.env.GIT_CONFIG_KEY_0 = "user.name";
113
+ process.env.GIT_CONFIG_VALUE_0 = "injected";
114
+ const environment = publicationProbeGitEnvironment();
115
+ assert.equal(environment.GIT_CONFIG_GLOBAL, undefined);
116
+ assert.equal(environment.GIT_CONFIG_SYSTEM, undefined);
117
+ assert.equal(environment.GIT_CONFIG_NOSYSTEM, undefined);
118
+ assert.equal(environment.GIT_DIR, undefined);
119
+ assert.equal(environment.GIT_CONFIG_COUNT, undefined);
120
+ assert.equal(environment.GIT_CONFIG_KEY_0, undefined);
121
+ assert.equal(environment.GIT_CONFIG_VALUE_0, undefined);
122
+ } finally {
123
+ for (const [key, value] of Object.entries(prior)) {
124
+ if (value === undefined) delete process.env[key];
125
+ else process.env[key] = value;
126
+ }
127
+ }
128
+ });
129
+
79
130
  test("a Windows drive-letter Git common directory resolves repository authority", { skip: process.platform !== "win32" }, (t) => {
80
131
  const root = repository(t);
81
132
  const commonDirectory = git(root, "rev-parse", "--path-format=absolute", "--git-common-dir");
@@ -377,12 +377,12 @@ test("RDD labels say what is happening and who acts", () => {
377
377
  });
378
378
  });
379
379
 
380
- test("RDD stays hidden without current-session evidence and occupies one group between Changes and Integrations", () => {
381
- assert.doesNotMatch(renderShellSidebarBar(model(), theme, 46).join("\n"), /RDD/);
380
+ test("the Review section stays hidden without current-session evidence and sits between Changes and Integrations", () => {
381
+ assert.doesNotMatch(renderShellSidebarBar(model(), theme, 46).join("\n"), /REVIEW/);
382
382
  const text = renderShellSidebarBar(model({ state: "reviewing", scope: "app.ts +2 files" }), theme, 46).join("\n");
383
- assert.equal((text.match(/RDD/g) ?? []).length, 1);
384
- assert.ok(text.indexOf("Changes") < text.indexOf("RDD"));
385
- assert.ok(text.indexOf("RDD") < text.indexOf("Integrations"));
383
+ assert.equal((text.match(/REVIEW/g) ?? []).length, 1);
384
+ assert.ok(text.indexOf("CHANGES") < text.indexOf("REVIEW"));
385
+ assert.ok(text.indexOf("REVIEW") < text.indexOf("INTEGRATIONS"));
386
386
  assert.match(text, /Reviewers running…/);
387
387
  assert.match(text, /app\.ts \+2 files/);
388
388
  });
@@ -1,6 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { spawnSync } from "node:child_process";
3
- import { existsSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
3
+ import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, symlinkSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { dirname, join } from "node:path";
6
6
  import { fileURLToPath } from "node:url";
@@ -115,10 +115,14 @@ function probeStageEnvironment(t: test.TestContext, env: NodeJS.ProcessEnv) {
115
115
  const stagesPath = writeStagesFile(t, []);
116
116
  const probePath = join(dirname(stagesPath), "probe.mjs");
117
117
  writeFileSync(probePath, `
118
- import { existsSync, readdirSync } from "node:fs";
118
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
119
119
  const home = process.env.GENTLE_PI_CONFIG_HOME;
120
+ const gitGlobalPath = process.env.GIT_CONFIG_GLOBAL;
121
+ const xdgPath = process.env.XDG_CONFIG_HOME;
120
122
  console.log("ENV_PROBE=" + JSON.stringify({
121
123
  git: Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toUpperCase().startsWith("GIT_"))),
124
+ gitGlobal: gitGlobalPath ? { exists: existsSync(gitGlobalPath), content: existsSync(gitGlobalPath) ? readFileSync(gitGlobalPath, "utf8") : null } : null,
125
+ xdg: xdgPath ?? null,
122
126
  agents: Object.fromEntries(Object.entries(process.env).filter(([key]) => key.toUpperCase().startsWith("GENTLE_PI_AGENTS_"))),
123
127
  home,
124
128
  files: home && existsSync(home) ? readdirSync(home) : null,
@@ -153,10 +157,62 @@ test("unit stage strips inherited Git configuration without changing later stage
153
157
  GIT_DIR: "inherited-repository", GIT_AUTHOR_NAME: "inherited-author",
154
158
  };
155
159
  const [unit, provider] = probeStageEnvironment(t, env);
156
- assert.deepEqual(unit.git, {});
160
+ assert.equal(unit.git.GIT_DIR, undefined);
161
+ assert.equal(unit.git.GIT_AUTHOR_NAME, undefined);
162
+ assert.equal(unit.git.GIT_CONFIG_COUNT, undefined);
157
163
  for (const [key, value] of Object.entries(env)) assert.equal(provider.git[key], value);
158
164
  });
159
165
 
166
+ // gentle-shell#2552: Git reads its global/system config files by path, so
167
+ // stripping inherited GIT_* environment was not enough — a host global ignore
168
+ // (e.g. ".agents/") leaked into fixtures and dropped untracked symlink targets
169
+ // from `git add -A`. The stage must pin every remaining config source.
170
+ test("unit stage pins Git config files to empty defaults; later stages keep inherited ones", (t) => {
171
+ const [unit, provider] = probeStageEnvironment(t, { GIT_CONFIG_GLOBAL: "inherited-global", GIT_CONFIG_NOSYSTEM: "0" });
172
+ assert.match(unit.git.GIT_CONFIG_GLOBAL ?? "", /empty\.gitconfig$/);
173
+ assert.deepEqual(unit.gitGlobal, { exists: true, content: "" }, "the pinned global config exists and is empty while the stage runs");
174
+ assert.equal(unit.git.GIT_CONFIG_NOSYSTEM, "1");
175
+ assert.equal(provider.git.GIT_CONFIG_GLOBAL, "inherited-global");
176
+ assert.deepEqual(provider.gitGlobal, { exists: false, content: null }, "later stages keep their inherited Git config sources");
177
+ assert.equal(provider.xdg, process.env.XDG_CONFIG_HOME ?? null, "later stages keep the inherited XDG configuration");
178
+ });
179
+
180
+ // gentle-shell#2552: Git reads $XDG_CONFIG_HOME/git/ignore even with an empty
181
+ // GIT_CONFIG_GLOBAL, so a host ignore file (e.g. ".agents/") must not drop
182
+ // fixture files from `git add -A` inside the unit stage.
183
+ test("unit stage isolates the XDG ignore file; a hostile host ignore cannot hide fixture files", (t) => {
184
+ const hostileHome = mkdtempSync(join(tmpdir(), "gentle-pi-hostile-home-"));
185
+ t.after(() => rmSync(hostileHome, { recursive: true, force: true }));
186
+ mkdirSync(join(hostileHome, ".config", "git"), { recursive: true });
187
+ writeFileSync(join(hostileHome, ".config", "git", "ignore"), ".agents/\n");
188
+ const stagesDir = mkdtempSync(join(tmpdir(), "gentle-pi-xdg-fixture-"));
189
+ t.after(() => rmSync(stagesDir, { recursive: true, force: true }));
190
+ const fixturePath = join(stagesDir, "fixture.mjs");
191
+ writeFileSync(fixturePath, `
192
+ import { execFileSync } from "node:child_process";
193
+ import { mkdirSync, mkdtempSync, writeFileSync } from "node:fs";
194
+ import { join } from "node:path";
195
+ import { tmpdir } from "node:os";
196
+ const cwd = mkdtempSync(join(tmpdir(), "gentle-pi-xdg-repo-"));
197
+ const run = (...args) => execFileSync("git", args, { cwd, encoding: "utf8" });
198
+ run("init", "-b", "main");
199
+ mkdirSync(join(cwd, ".agents", "skills", "example"), { recursive: true });
200
+ writeFileSync(join(cwd, ".agents", "skills", "example", "SKILL.md"), "example\\n");
201
+ run("add", "-A");
202
+ console.log("XDG_FIXTURE=" + JSON.stringify({ staged: run("ls-files").includes(".agents/skills/example/SKILL.md") }));
203
+ `);
204
+ writeFileSync(join(stagesDir, "stages.json"), JSON.stringify([
205
+ { name: "unit-tests", command: `node "${fixturePath}"` },
206
+ ]));
207
+ const result = spawnSync(process.execPath, [runnerPath, join(stagesDir, "stages.json")], {
208
+ encoding: "utf8", env: { ...process.env, HOME: hostileHome, XDG_CONFIG_HOME: "" },
209
+ });
210
+ assert.equal(result.status, 0, result.stderr);
211
+ const fixture = result.stdout.split(/\r?\n/).find((line) => line.startsWith("XDG_FIXTURE="));
212
+ assert.ok(fixture, "the fixture probe ran");
213
+ assert.deepEqual(JSON.parse(fixture.slice("XDG_FIXTURE=".length)), { staged: true }, "the hostile XDG ignore did not hide the fixture file");
214
+ });
215
+
160
216
  test("unit stage strips inherited subagent context without changing later stages", (t) => {
161
217
  const env = { GENTLE_PI_AGENTS_CHILD: "1", GENTLE_PI_AGENTS_OWNED_IPC: "1" };
162
218
  const [unit, provider] = probeStageEnvironment(t, env);
@@ -171,7 +227,7 @@ test("unit stage accepts an uncreated inherited config home without creating it"
171
227
  assert.equal(existsSync(home), false);
172
228
  const [unit, provider] = probeStageEnvironment(t, { GENTLE_PI_CONFIG_HOME: home });
173
229
  assert.notEqual(unit.home, home);
174
- assert.deepEqual(unit.files, []);
230
+ assert.deepEqual(unit.files, ["empty.gitconfig"]);
175
231
  assert.equal(existsSync(unit.home), false);
176
232
  assert.equal(provider.home, home);
177
233
  assert.equal(provider.files, null);
@@ -186,7 +242,7 @@ test("unit stage uses an empty temporary config home and removes it after exit",
186
242
  writeFileSync(configPath, config);
187
243
  const [unit, provider] = probeStageEnvironment(t, { GENTLE_PI_CONFIG_HOME: home });
188
244
  assert.notEqual(unit.home, home);
189
- assert.deepEqual(unit.files, []);
245
+ assert.deepEqual(unit.files, ["empty.gitconfig"]);
190
246
  assert.equal(existsSync(unit.home), false);
191
247
  assert.equal(provider.home, home);
192
248
  assert.deepEqual(provider.files, ["runtime-guardrails.json"]);
@@ -0,0 +1,74 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtempSync } from "node:fs";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
+ import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
8
+
9
+ // gentle-shell#2349: the sensitive-path deny list must not depend on which
10
+ // path-taking tool the model picks. grep, find, and ls take the same `path`
11
+ // input as read, so a sensitive `path` is denied for them too.
12
+
13
+ type Handler = (event: { toolName: string; input: unknown; toolCallId: string }, ctx: ExtensionContext) => unknown;
14
+
15
+ function toolCall() {
16
+ const handlers: Handler[] = [];
17
+ const pi = {
18
+ on: (name: string, handler: Handler) => { if (name === "tool_call") handlers.push(handler); },
19
+ events: { on() {}, emit() {} },
20
+ registerTool() {}, registerCommand() {}, registerShortcut() {}, registerMessageRenderer() {},
21
+ } as unknown as ExtensionAPI;
22
+ // An isolated config home keeps the permission mode at its default, so every
23
+ // later tool_call check admits an ordinary path and the whole chain returns
24
+ // undefined. A block from any check is then observable, not just this guard's.
25
+ const home = mkdtempSync(join(tmpdir(), "gentle-shell-2349-"));
26
+ createGentleAiExtension({ processEnv: { GENTLE_PI_AGENTS_CHILD: "0", GENTLE_PI_CONFIG_HOME: home }, nativeReviewCli: null })(pi);
27
+ const sessionManager = { getSessionId: () => "session-2349", getBranch: () => [], getEntries: () => [] };
28
+ const ctx = { cwd: process.cwd(), hasUI: false, sessionManager, ui: { confirm: async () => false } } as unknown as ExtensionContext;
29
+ return async (toolName: string, input: unknown) => {
30
+ for (const handler of handlers) {
31
+ const result = await handler({ toolName, input, toolCallId: "probe" }, ctx);
32
+ if (result !== undefined) return result as { block?: boolean; reason?: string };
33
+ }
34
+ return undefined;
35
+ };
36
+ }
37
+
38
+ const reason = (path: string) => `Gentle AI safety policy blocked access to sensitive path: ${path}. Ask the user for an explicit safer plan.`;
39
+
40
+ test("grep, find, and ls deny a sensitive path exactly like read (gentle-shell#2349)", async () => {
41
+ const call = toolCall();
42
+ for (const [toolName, input, path] of [
43
+ ["grep", { pattern: "API_KEY", path: ".env" }, ".env"],
44
+ ["grep", { pattern: "x", path: "/app/.env.production" }, "/app/.env.production"],
45
+ ["find", { pattern: "*", path: "~/.ssh" }, "~/.ssh"],
46
+ ["ls", { path: "secrets" }, "secrets"],
47
+ ["ls", { path: "/home/u/.aws/credentials" }, "/home/u/.aws/credentials"],
48
+ ["grep", { pattern: "x", paths: ["src", ".env"] }, ".env"],
49
+ ] as const) {
50
+ assert.deepEqual(await call(toolName, input), { block: true, reason: reason(path) }, `${toolName} ${path}`);
51
+ }
52
+ });
53
+
54
+ test("grep, find, and ls admit ordinary paths and their default scope (gentle-shell#2349)", async () => {
55
+ const call = toolCall();
56
+ for (const [toolName, input] of [
57
+ ["grep", { pattern: "TODO", path: "src" }],
58
+ ["grep", { pattern: "TODO" }],
59
+ ["find", { pattern: "*.ts", path: "lib" }],
60
+ ["find", { pattern: "*.ts" }],
61
+ ["ls", { path: "docs" }],
62
+ ["ls", {}],
63
+ ["grep", { pattern: "TODO", paths: ["src", "lib"] }],
64
+ ] as const) {
65
+ assert.equal(await call(toolName, input), undefined, `${toolName} ${JSON.stringify(input)}`);
66
+ }
67
+ });
68
+
69
+ test("read, write, and edit keep denying sensitive paths (gentle-shell#2349)", async () => {
70
+ const call = toolCall();
71
+ assert.deepEqual(await call("read", { path: ".env.local" }), { block: true, reason: reason(".env.local") });
72
+ assert.deepEqual(await call("write", { path: "secrets/token.txt", content: "x" }), { block: true, reason: reason("secrets/token.txt") });
73
+ assert.deepEqual(await call("edit", { path: "id_rsa.pem", edits: [] }), { block: true, reason: reason("id_rsa.pem") });
74
+ });
@@ -729,3 +729,66 @@ for (const changed of ["data", "timestamp", "parentId", "extra"] as const) {
729
729
  assert.equal(current.refresh().status, "indeterminate");
730
730
  });
731
731
  }
732
+
733
+ test("the attachment appends the A2 startup bind, explicit startup state and startup-none clear", () => {
734
+ const f = fixture();
735
+ f.mode = "disk";
736
+ const team = { worker: { model: "provider/team" }, orchestrator: { model: "provider/main" } };
737
+ const startup = { origin: "repo" as const, name: "team", modelProfiles: team };
738
+ const outcomes = [
739
+ f.controller.bindStartup("repo", "team", team),
740
+ f.controller.bind("chosen", {}, startup),
741
+ f.controller.clear("none"),
742
+ ];
743
+ assert.deepEqual(outcomes, [
744
+ { status: "persisted", state: { status: "bound", binding: { kind: "bind", ...startup }, entryIndex: 0, lineNumber: 2 } },
745
+ { status: "persisted", state: { status: "bound", binding: { kind: "bind", origin: "user", name: "chosen", modelProfiles: {}, startup }, entryIndex: 1, lineNumber: 3 } },
746
+ { status: "persisted", state: { status: "cleared", startup: "none", entryIndex: 2, lineNumber: 4 } },
747
+ ]);
748
+ assert.deepEqual(f.rows.map((row) => row.data), [
749
+ { kind: "bind", ...startup },
750
+ { kind: "bind", origin: "user", name: "chosen", modelProfiles: {}, startup },
751
+ { kind: "clear", startup: "none" },
752
+ ]);
753
+ });
754
+ test("detached and reloaded attachments reject bindStartup, bind and clear without appending", () => {
755
+ const f = fixture();
756
+ f.mode = "disk";
757
+ let calls = 0;
758
+ const counted = (t: string, d: unknown) => {
759
+ calls++;
760
+ f.append(t, d);
761
+ };
762
+ const owner = createSessionProfileAppendController(f.source, counted, {
763
+ readFile: f.readFile,
764
+ }) as ReturnType<typeof createSessionProfileAppendController> & {
765
+ detach(): void;
766
+ attach(
767
+ source: typeof f.source,
768
+ appendEntry: (type: string, data: unknown) => void,
769
+ context: { reason: string },
770
+ options?: { readFile: typeof f.readFile },
771
+ ): typeof f.controller;
772
+ };
773
+ const team = { worker: { model: "provider/team" } };
774
+ const startup = { origin: "repo" as const, name: "team", modelProfiles: team };
775
+ assert.equal(owner.bindStartup("repo", "team", team).status, "persisted");
776
+ const rejected = {
777
+ status: "indeterminate",
778
+ state: { status: "indeterminate", reason: "detached-source" },
779
+ };
780
+ const attempt = () => [
781
+ owner.bindStartup("repo", "stale", team),
782
+ owner.bind("stale", {}, startup),
783
+ owner.clear("none"),
784
+ ];
785
+ const entries = structuredClone(f.rows);
786
+ owner.detach();
787
+ assert.deepEqual(attempt(), [rejected, rejected, rejected]);
788
+ assert.deepEqual(f.rows, entries);
789
+ assert.equal(calls, 1);
790
+ owner.attach(f.source, counted, { reason: "reload" }, { readFile: f.readFile });
791
+ assert.deepEqual(attempt(), [rejected, rejected, rejected]);
792
+ assert.deepEqual(f.rows, entries);
793
+ assert.equal(calls, 1);
794
+ });