gentle-pi 4.6.0 → 4.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (290) hide show
  1. package/README.md +10 -11
  2. package/assets/agents/gentle-ai-explore.md +1 -0
  3. package/assets/agents/gentle-ai-verify.md +5 -2
  4. package/assets/agents/gentle-ai-worker.md +3 -0
  5. package/assets/agents/jd-fix-agent.md +1 -0
  6. package/assets/agents/jd-judge-a.md +1 -0
  7. package/assets/agents/jd-judge-b.md +1 -0
  8. package/assets/design-canvas/canvas.css +13 -1
  9. package/assets/design-canvas/canvas.js +11 -2
  10. package/assets/install-wizard/wizard.js +1 -0
  11. package/assets/migrations/agent-body-history.json +16 -1
  12. package/assets/orchestrator-delegation-reference.md +4 -4
  13. package/assets/orchestrator-delegation.md +1 -1
  14. package/assets/orchestrator-full-delegation-card.md +65 -0
  15. package/assets/orchestrator-full-delegation.md +34 -0
  16. package/assets/orchestrator-memory.md +3 -3
  17. package/assets/orchestrator-prompts.md +1 -1
  18. package/assets/orchestrator-skills.md +1 -1
  19. package/assets/orchestrator-verification.md +7 -5
  20. package/assets/orchestrator.md +3 -3
  21. package/bin/gentle-shell.mjs +164 -56
  22. package/docs/agent-status.md +61 -0
  23. package/docs/bundled-install.md +7 -5
  24. package/docs/delegated-verification.md +29 -7
  25. package/docs/gentle-agents-activity.md +14 -0
  26. package/docs/gentle-shell.md +54 -16
  27. package/docs/install-wizard.md +1 -1
  28. package/docs/permission-modes.md +9 -4
  29. package/docs/readme-reference.md +75 -30
  30. package/docs/render-cache-performance.md +11 -1
  31. package/docs/review-coordinator.md +33 -0
  32. package/docs/review-request-context.md +19 -0
  33. package/docs/review-windows-acl.md +18 -0
  34. package/docs/voice.md +6 -3
  35. package/docs/yolo-mode.md +5 -5
  36. package/extensions/ask-user-choice.ts +1 -0
  37. package/extensions/ask-user-question.ts +1 -0
  38. package/extensions/child-safety.ts +3 -0
  39. package/extensions/gentle-agent-status.ts +99 -0
  40. package/extensions/gentle-agents.ts +326 -34
  41. package/extensions/gentle-ai.ts +1496 -454
  42. package/extensions/gentle-shell.ts +293 -63
  43. package/extensions/gentle-todo.ts +18 -2
  44. package/extensions/gentle-tps.ts +48 -0
  45. package/extensions/quiet-tools.ts +38 -8
  46. package/extensions/skill-registry.ts +175 -18
  47. package/extensions/startup-banner.ts +30 -3
  48. package/lib/agent-profile-pin.ts +3 -3
  49. package/lib/agent-profiles.ts +160 -2
  50. package/lib/agent-status.ts +105 -0
  51. package/lib/agents-config.ts +46 -0
  52. package/lib/agents-history.ts +24 -5
  53. package/lib/agents-messaging.ts +47 -5
  54. package/lib/agents-runner.ts +183 -12
  55. package/lib/auto-permission-runtime.ts +1 -1
  56. package/lib/bounded-writer-admission.ts +13 -1
  57. package/lib/card-content-policy.ts +8 -6
  58. package/lib/command-palette.ts +133 -17
  59. package/lib/context-backstop.ts +14 -5
  60. package/lib/destructive-command-guard.ts +48 -4
  61. package/lib/execution-surface-guard.ts +20 -0
  62. package/lib/exploration-budget.ts +4 -2
  63. package/lib/gentle-ai-binary.ts +1 -1
  64. package/lib/gentle-design.ts +3 -0
  65. package/lib/gentle-shell-bundled.ts +6 -19
  66. package/lib/gentle-shell-launcher.ts +43 -8
  67. package/lib/herdr-activity.ts +14 -2
  68. package/lib/herdr-busy.ts +45 -0
  69. package/lib/image-attachments.ts +33 -0
  70. package/lib/image-disk-cache.ts +137 -0
  71. package/lib/inprocess-reviewer.ts +270 -140
  72. package/lib/jobs-view.ts +198 -11
  73. package/lib/model-routing-authority.ts +22 -4
  74. package/lib/native-choice-list.ts +20 -2
  75. package/lib/native-review-cli.ts +96 -19
  76. package/lib/orchestrator-mode-policy.ts +105 -0
  77. package/lib/questionnaire/questionnaire-view.ts +105 -12
  78. package/lib/rdd-mode-control.ts +32 -0
  79. package/lib/reply-language-anchor.ts +104 -0
  80. package/lib/review-blocker.ts +92 -0
  81. package/lib/review-candidate-symlink-scan.ts +136 -0
  82. package/lib/review-candidate-view-owner.ts +81 -44
  83. package/lib/review-continuation-registry.ts +99 -0
  84. package/lib/review-coordinator.ts +163 -0
  85. package/lib/review-failure-facts.ts +49 -0
  86. package/lib/review-host-relay.ts +46 -10
  87. package/lib/review-integration-v2.ts +7 -1
  88. package/lib/review-relay-phase-timing.ts +45 -0
  89. package/lib/review-start-context.ts +17 -0
  90. package/lib/session-profile-freeze.ts +4 -2
  91. package/lib/shell-bar.ts +140 -58
  92. package/lib/shell-changes.ts +2 -0
  93. package/lib/shell-panel.ts +17 -3
  94. package/lib/shell-sidebar-layout.ts +112 -40
  95. package/lib/shell-sidebar.ts +7 -0
  96. package/lib/shell-todo.ts +10 -3
  97. package/lib/verifier-admission.ts +1 -1
  98. package/lib/visual-customization-policy.ts +36 -16
  99. package/lib/visual-customize-view.ts +216 -21
  100. package/lib/visual-layout-preview.ts +9 -5
  101. package/lib/visual-profiles.ts +2 -2
  102. package/lib/windows-session-transport.ts +53 -2
  103. package/lib/yolo-session-policy.ts +40 -15
  104. package/package.json +2 -1
  105. package/runtime/gentle-ai-binary.mjs +1 -1
  106. package/runtime/gentle-shell-bundled.mjs +6 -19
  107. package/runtime/gentle-shell-launcher.mjs +42 -7
  108. package/runtime/native-review-cli.mjs +93 -16
  109. package/runtime/review-integration-v2.mjs +7 -1
  110. package/scripts/build-full-delegation-card.mjs +175 -0
  111. package/scripts/bundled-install.mjs +38 -8
  112. package/scripts/download-progress.mjs +68 -0
  113. package/scripts/gentle-ai-installer.mjs +41 -18
  114. package/scripts/gentle-ai-proxy.mjs +294 -0
  115. package/scripts/install-gentle-ai.mjs +14 -1
  116. package/scripts/installer-preflight.mjs +5 -5
  117. package/scripts/installer-runner.mjs +27 -12
  118. package/scripts/installer-server.mjs +8 -7
  119. package/scripts/render-cache-host.mjs +72 -0
  120. package/scripts/render-cache-performance-worker.mjs +5 -4
  121. package/scripts/render-cache-performance.mjs +6 -1
  122. package/scripts/run-test-suite.mjs +40 -28
  123. package/scripts/verify-package-files.mjs +12 -2
  124. package/scripts/voice-worker.cjs +32 -6
  125. package/skills/design/SKILL.md +11 -8
  126. package/skills/gentle-ai/SKILL.md +2 -2
  127. package/skills/gentle-ui-design/SKILL.md +46 -0
  128. package/skills/gentle-ui-design/references/adaptive-interfaces.md +46 -0
  129. package/skills/gentle-ui-design/references/browse-and-compare.md +62 -0
  130. package/skills/gentle-ui-design/references/composition-and-feedback.md +56 -0
  131. package/skills/gentle-ui-design/references/task-and-content.md +60 -0
  132. package/skills/skill-registry/SKILL.md +4 -2
  133. package/skills/work-unit-commits/SKILL.md +6 -7
  134. package/tests/agent-home.test.ts +28 -9
  135. package/tests/agent-profiles-workflow.test.ts +163 -0
  136. package/tests/agent-risk-escalation.test.ts +1 -1
  137. package/tests/agent-status.test.ts +143 -0
  138. package/tests/agents-config.test.ts +96 -0
  139. package/tests/agents-history.test.ts +31 -0
  140. package/tests/agents-jobs-frames.test.ts +93 -0
  141. package/tests/agents-prompt-lifecycle-runtime.test.ts +376 -0
  142. package/tests/agents-runner-drain.test.ts +193 -0
  143. package/tests/agents-runner.test.ts +178 -2
  144. package/tests/append-system-prompt-route.test.ts +4 -1
  145. package/tests/ask-user-choice.test.ts +4 -3
  146. package/tests/ask-user-question.test.ts +97 -0
  147. package/tests/auto-permission-runtime.test.ts +1 -1
  148. package/tests/autonomous-guard.test.ts +346 -10
  149. package/tests/bounded-stop-contract.test.ts +43 -3
  150. package/tests/bridge-cost.test.ts +19 -4
  151. package/tests/bundled-install.test.ts +30 -5
  152. package/tests/card-content-policy.test.ts +3 -3
  153. package/tests/chained-pr-skill.test.ts +8 -6
  154. package/tests/child-safety.test.ts +11 -0
  155. package/tests/codegraph-tools.test.ts +11 -5
  156. package/tests/command-palette.test.ts +284 -1
  157. package/tests/delegate-for-reason-contract.test.ts +3 -3
  158. package/tests/design-canvas-assets.test.ts +185 -2
  159. package/tests/destructive-command-guard.test.ts +52 -0
  160. package/tests/download-progress.test.ts +71 -0
  161. package/tests/execution-surface-guard.test.ts +55 -0
  162. package/tests/fixtures/primary-session-prompt/gentleman.golden.md +9 -5
  163. package/tests/fixtures/proxy-tls/proxy.crt +19 -0
  164. package/tests/fixtures/proxy-tls/proxy.key +28 -0
  165. package/tests/fixtures/session-profile-v1/gentle-ai-reviewer.ts +89 -0
  166. package/tests/fixtures/session-profile-v1/replay.ts +53 -6
  167. package/tests/full-delegation-closure.test.ts +131 -0
  168. package/tests/full-delegation-notices.test.ts +76 -0
  169. package/tests/generic-agent-tools.test.ts +3 -3
  170. package/tests/gentle-agent-status.test.ts +74 -0
  171. package/tests/gentle-agents-child-jobs.test.ts +237 -0
  172. package/tests/gentle-agents.test.ts +1070 -12
  173. package/tests/gentle-ai-binary.test.ts +3 -1
  174. package/tests/gentle-ai-elapsed-store.test.ts +19 -0
  175. package/tests/gentle-ai-exploration-budget.test.ts +18 -2
  176. package/tests/gentle-ai-installer.test.ts +134 -51
  177. package/tests/gentle-ai-proxy.test.ts +434 -0
  178. package/tests/gentle-ai.test.ts +113 -38
  179. package/tests/gentle-design.test.ts +21 -0
  180. package/tests/gentle-herdr-activity.test.ts +9 -6
  181. package/tests/gentle-shell-bin.test.ts +123 -0
  182. package/tests/gentle-shell-bundled.test.ts +207 -31
  183. package/tests/gentle-shell-launcher.test.ts +77 -10
  184. package/tests/gentle-shell.test.ts +899 -59
  185. package/tests/gentle-todo.test.ts +19 -2
  186. package/tests/gentle-tps.test.ts +123 -0
  187. package/tests/gentle-ui-design-skill.test.ts +59 -0
  188. package/tests/herdr-busy.test.ts +59 -0
  189. package/tests/herdr-task-summary-policy.test.ts +8 -4
  190. package/tests/image-disk-cache.test.ts +163 -0
  191. package/tests/independent-recovery-delivery.test.ts +83 -0
  192. package/tests/inprocess-reviewer.test.ts +176 -4
  193. package/tests/installer-posix-bootstrap.test.ts +1 -1
  194. package/tests/installer-preflight.test.ts +5 -4
  195. package/tests/installer-runner.test.ts +79 -44
  196. package/tests/installer-server.test.ts +14 -11
  197. package/tests/jobs-view.test.ts +260 -6
  198. package/tests/modal-mouse-boundaries.test.ts +136 -0
  199. package/tests/model-routing-authority.test.ts +178 -2
  200. package/tests/native-choice-list.test.ts +77 -2
  201. package/tests/native-review-capability-contract.test.ts +7 -1
  202. package/tests/native-review-cli.test.ts +269 -1
  203. package/tests/no-self-pause-contract.test.ts +4 -1
  204. package/tests/odd-routing-canonical-ratchet.test.ts +3 -3
  205. package/tests/orchestrator-budget.test.ts +7 -2
  206. package/tests/orchestrator-delegation-mode.test.ts +153 -0
  207. package/tests/orchestrator-mode-policy.test.ts +175 -0
  208. package/tests/orchestrator-prompt-budget.test.ts +3 -1
  209. package/tests/orchestrator-rdd-ownership.test.ts +2 -2
  210. package/tests/package-manifest.test.ts +11 -9
  211. package/tests/permission-allowlist.test.ts +202 -0
  212. package/tests/pi-update-launcher.test.ts +8 -0
  213. package/tests/pnpm-workspace-config.test.ts +58 -0
  214. package/tests/primary-session-prompt.test.ts +13 -0
  215. package/tests/profile-pin.test.ts +29 -2
  216. package/tests/profile-tier-footer.test.ts +5 -0
  217. package/tests/profiles-panel-delegation-mode.test.ts +422 -0
  218. package/tests/questionnaire-view.test.ts +115 -0
  219. package/tests/quiet-bash-runtime.test.ts +1 -1
  220. package/tests/quiet-tool-rendering.test.ts +48 -0
  221. package/tests/rdd-aware-verification-contract.test.ts +16 -11
  222. package/tests/rdd-customize.test.ts +287 -0
  223. package/tests/rdd-mode-cache.test.ts +450 -0
  224. package/tests/rdd-mode-control.test.ts +407 -0
  225. package/tests/rdd-mode-scope-regression.test.ts +137 -0
  226. package/tests/rdd-off-independent-regression.test.ts +69 -0
  227. package/tests/rdd-status-line.test.ts +18 -0
  228. package/tests/render-cache-performance.test.ts +171 -2
  229. package/tests/reply-language-anchor.test.ts +173 -0
  230. package/tests/review-agent-end-preflight.test.ts +1 -1
  231. package/tests/review-blocker.test.ts +193 -0
  232. package/tests/review-candidate-owner-retry.test.ts +1 -1
  233. package/tests/review-candidate-symlink-scan.test.ts +157 -0
  234. package/tests/review-candidate-view.test.ts +1 -1
  235. package/tests/review-candidate-windows-boundary.test.ts +131 -0
  236. package/tests/review-candidate-windows-probe.test.ts +63 -0
  237. package/tests/review-committed-restart-ack.test.ts +129 -0
  238. package/tests/review-continuation-registry.test.ts +76 -0
  239. package/tests/review-controller-native-routing.test.ts +261 -5
  240. package/tests/review-controller-workspace-root.test.ts +230 -3
  241. package/tests/review-controller.test.ts +96 -11
  242. package/tests/review-coordinator-runtime.test.ts +117 -0
  243. package/tests/review-coordinator.test.ts +195 -0
  244. package/tests/review-failure-facts.test.ts +87 -0
  245. package/tests/review-host-relay-routing.test.ts +258 -4
  246. package/tests/review-host-relay.test.ts +39 -0
  247. package/tests/review-integration-v2.test.ts +46 -3
  248. package/tests/review-json-arguments.test.ts +65 -10
  249. package/tests/review-last-event-closure.test.ts +68 -0
  250. package/tests/review-loadout-rdd-off-sdk.test.ts +65 -31
  251. package/tests/review-owner-identity.test.ts +60 -24
  252. package/tests/review-relay-phase-timing.test.ts +128 -0
  253. package/tests/review-relay-transport-agent.test.ts +12 -2
  254. package/tests/review-reviewer-evidence.test.ts +183 -0
  255. package/tests/review-risk-assessment.test.ts +74 -3
  256. package/tests/review-session-standing-permission-controller.test.ts +21 -1
  257. package/tests/review-start-context.test.ts +19 -0
  258. package/tests/review-tool-prose-budget.test.ts +121 -0
  259. package/tests/run-test-suite.test.ts +122 -1
  260. package/tests/runtime-harness.mjs +4 -1
  261. package/tests/sensitive-path-tools.test.ts +181 -5
  262. package/tests/session-profile-append-controller-pi.test.ts +60 -31
  263. package/tests/session-profile-binding.test.ts +19 -1
  264. package/tests/session-profile-disk-reader-pi.test.ts +58 -16
  265. package/tests/session-profile-v1-compat.test.ts +35 -1
  266. package/tests/shell-bar.test.ts +186 -42
  267. package/tests/shell-panel.test.ts +50 -22
  268. package/tests/shell-sidebar-fullscreen.test.ts +5 -5
  269. package/tests/shell-sidebar-layout.test.ts +294 -23
  270. package/tests/shell-sidebar-scroll-benchmark.test.ts +1 -1
  271. package/tests/shell-surface-transparent.test.ts +89 -0
  272. package/tests/shell-todo.test.ts +12 -0
  273. package/tests/skill-registry.test.ts +838 -5
  274. package/tests/startup-banner.test.ts +152 -1
  275. package/tests/startup-home-repo.test.ts +2 -0
  276. package/tests/support/review-coordinator-runtime.ts +69 -0
  277. package/tests/task-size-routing-contract.test.ts +5 -3
  278. package/tests/verifier-admission.test.ts +49 -0
  279. package/tests/verify-first-launch-contract.test.ts +78 -3
  280. package/tests/visual-customization-policy.test.ts +39 -6
  281. package/tests/visual-customize-view.test.ts +573 -9
  282. package/tests/visual-layout-preview.test.ts +15 -1
  283. package/tests/visual-profiles.test.ts +11 -0
  284. package/tests/voice-worker.test.ts +73 -2
  285. package/tests/windows-session-transport.test.ts +126 -0
  286. package/tests/work-continuity-contract.test.ts +28 -0
  287. package/tests/writer-feature-document-admission.test.ts +92 -0
  288. package/tests/yolo-customize.test.ts +27 -4
  289. package/tests/yolo-mode.test.ts +23 -18
  290. package/tests/yolo-session-policy.test.ts +270 -1
@@ -0,0 +1,450 @@
1
+ import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { mkdirSync, mkdtempSync, 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 type { AssistantMessage } from "@earendil-works/pi-ai";
8
+ import type { ExtensionAPI, ExtensionContext, ExtensionUIContext } from "@earendil-works/pi-coding-agent";
9
+ import type { NativeReviewCli, NativeReviewModeRequest, NativeReviewModeResult } from "../lib/native-review-cli.ts";
10
+
11
+ const HIDDEN = ["gentle_review_capture", "gentle_review_capture_group", "gentle_review_scope"];
12
+ const line = (mode: string, source: string) => `Receipt-driven development: ${mode} (decided by ${source})`;
13
+
14
+ function deferred<T>() {
15
+ let resolve!: (value: T) => void;
16
+ const promise = new Promise<T>((done) => { resolve = done; });
17
+ return { promise, resolve };
18
+ }
19
+
20
+ type Mode = "on" | "off";
21
+ type State = { global: Mode | ""; cloneLocal: "" | "off" };
22
+
23
+ // This is the fixture's actual native state and mutation ledger: no native
24
+ // process, settings file, consent provider, or real repository is touched.
25
+ function nativeFixture(initial: State) {
26
+ const states = new Map<string, State>();
27
+ const calls: Array<{ cwd: string; operation: string; scope?: unknown }> = [];
28
+ const writes: Array<{ cwd: string; operation: string; state: State }> = [];
29
+ const targets: string[] = [];
30
+ const assessments: string[] = [];
31
+ let failMutation = false;
32
+ let failRead = false;
33
+ let invalidRead = false;
34
+ let hold: ReturnType<typeof deferred<NativeReviewModeResult>> | undefined;
35
+ let started: ReturnType<typeof deferred<void>> | undefined;
36
+ const state = (cwd: string) => {
37
+ if (!states.has(cwd)) states.set(cwd, { ...initial });
38
+ return states.get(cwd)!;
39
+ };
40
+ const result = (cwd: string, operation: NativeReviewModeRequest["operation"]): NativeReviewModeResult => {
41
+ const value = state(cwd);
42
+ const source = value.cloneLocal === "off" ? "clone_local" : value.global ? "global" : "default";
43
+ const effective = value.cloneLocal === "off" ? "off" : value.global || "on";
44
+ return { operation, scope: "clone", status: { ...value, effective, source } };
45
+ };
46
+ const cli = {
47
+ async reviewMode(request: NativeReviewModeRequest) {
48
+ const { cwd, operation } = request;
49
+ calls.push({ cwd, operation, ...("scope" in request ? { scope: request.scope } : {}) });
50
+ if (operation === "status") {
51
+ const snapshot = result(cwd, operation);
52
+ if (hold) { const waiting = hold; hold = undefined; started!.resolve(); return waiting.promise; }
53
+ if (failRead) throw new Error("fixture status unavailable");
54
+ if (invalidRead) return { ...snapshot, status: { ...snapshot.status, source: "invalid" } } as unknown as NativeReviewModeResult;
55
+ return snapshot;
56
+ }
57
+ if (failMutation) throw new Error("fixture mutation refused");
58
+ const current = state(cwd);
59
+ current.cloneLocal = operation === "disable" ? "off" : "";
60
+ writes.push({ cwd, operation, state: { ...current } });
61
+ return result(cwd, operation);
62
+ },
63
+ async assess({ cwd }: { cwd: string }) {
64
+ assessments.push(cwd);
65
+ return { schema: "gentle-ai.review-assessment/v1", risk: "medium", reasons: [], changedPaths: 1, changedLines: 1, candidate: { kind: "current-changes" } };
66
+ },
67
+ async targetStatus({ cwd }: { cwd: string }) { targets.push(cwd); throw new Error("fixture target unavailable"); },
68
+ } as unknown as NativeReviewCli;
69
+ return {
70
+ cli, calls, writes, targets, assessments, state, result,
71
+ failMutation(value: boolean) { failMutation = value; },
72
+ failRead(value: boolean) { failRead = value; },
73
+ invalidRead(value: boolean) { invalidRead = value; },
74
+ holdNext() { hold = deferred<NativeReviewModeResult>(); started = deferred<void>(); return { read: hold, started: started.promise }; },
75
+ };
76
+ }
77
+
78
+ type FixtureNative = ReturnType<typeof nativeFixture>;
79
+
80
+ async function fixture(t: { after(fn: () => Promise<void>): void }, initial: State) {
81
+ const root = realpathSync(mkdtempSync(join(tmpdir(), "gentle-rdd-mode-cache-")));
82
+ const profile = join(root, "profile");
83
+ mkdirSync(profile);
84
+ const bindings = { PI_CODING_AGENT_DIR: profile, PI_CODING_AGENT_SESSION_DIR: join(root, "sessions"), GENTLE_PI_AGENT_HOME: profile, GENTLE_PI_CONFIG_HOME: join(root, "config") };
85
+ const previous = Object.fromEntries(Object.keys(bindings).map((key) => [key, process.env[key]]));
86
+ Object.assign(process.env, bindings);
87
+ const live: Array<() => Promise<void>> = [];
88
+ let clearMemo: (() => void) | undefined;
89
+ t.after(async () => {
90
+ try {
91
+ for (const close of live) await close();
92
+ } finally {
93
+ clearMemo?.();
94
+ for (const [key, value] of Object.entries(previous)) {
95
+ if (value === undefined) delete process.env[key]; else process.env[key] = value;
96
+ }
97
+ rmSync(root, { recursive: true, force: true });
98
+ }
99
+ });
100
+ const sdk = await import("@earendil-works/pi-coding-agent");
101
+ const ai = await import("@earendil-works/pi-ai");
102
+ const { createGentleAiExtension, __testing } = await import("../extensions/gentle-ai.ts");
103
+ clearMemo = __testing.clearRddStatusMemoForTesting;
104
+ clearMemo();
105
+ const native = nativeFixture(initial);
106
+ const repo = (name: string) => {
107
+ const cwd = join(root, name);
108
+ mkdirSync(cwd);
109
+ const config = join(root, "gitconfig");
110
+ writeFileSync(config, "");
111
+ execFileSync("git", ["init", "--initial-branch=fixture"], { cwd, env: { PATH: process.env.PATH, HOME: root, GIT_CONFIG_NOSYSTEM: "1", GIT_CONFIG_GLOBAL: config }, stdio: "ignore" });
112
+ return cwd;
113
+ };
114
+ let number = 0;
115
+ async function host(cwd: string, nativeCli: NativeReviewCli | null = native.cli) {
116
+ const id = ++number;
117
+ const notices: Array<{ message: string; type?: string }> = [];
118
+ const errors: string[] = [];
119
+ const requests: Array<{ system: string; tools: string[] }> = [];
120
+ const shutdown: Array<() => Promise<void>> = [];
121
+ const tools = new Map<string, { execute(...args: any[]): Promise<any> }>();
122
+ let ctx: ExtensionContext | undefined;
123
+ const ui = new Proxy({ notify: (message: string, type?: string) => notices.push({ message, type }) }, {
124
+ get(target, key) { return key in target ? Reflect.get(target, key) : () => undefined; },
125
+ }) as unknown as ExtensionUIContext;
126
+ const settings = sdk.SettingsManager.inMemory({ compaction: { enabled: false }, retry: { enabled: false }, cacheWarming: "off", packages: [] });
127
+ const runtime = await sdk.ModelRuntime.create({ credentials: new ai.InMemoryCredentialStore(), modelsPath: null, modelsStorePath: join(root, `models-${id}.json`), refreshOnCreate: false, allowModelNetwork: false });
128
+ const provider = `rdd-fixture-${id}`;
129
+ const model = { id: "driver", name: "Fixture driver", provider, api: provider, baseUrl: "http://invalid.local", reasoning: false, input: ["text"], contextWindow: 1_000_000, maxTokens: 1024, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0 } } as const;
130
+ const loader = new sdk.DefaultResourceLoader({ cwd, agentDir: profile, settingsManager: settings, noExtensions: true, noSkills: true, noPromptTemplates: true, noThemes: true, noContextFiles: true,
131
+ extensionFactories: [(pi) => {
132
+ pi.on("session_start", (_event, context) => { ctx = context; });
133
+ const capture = new Proxy(pi, { get(target, key) {
134
+ if (key === "registerTool") return (tool: Parameters<ExtensionAPI["registerTool"]>[0]) => {
135
+ tools.set(tool.name, tool);
136
+ return target.registerTool(tool);
137
+ };
138
+ if (key !== "on") return Reflect.get(target, key);
139
+ const on: ExtensionAPI["on"] = (event, handler) => {
140
+ if (event === "session_shutdown") shutdown.push(async () => { assert.ok(ctx); await handler({ type: "session_shutdown" }, ctx); });
141
+ return target.on(event, handler);
142
+ };
143
+ return on;
144
+ } });
145
+ createGentleAiExtension({ nativeReviewCli: nativeCli, candidateViews: null, processEnv: { ...bindings, GENTLE_AI_TELEMETRY: "0" }, resolveTelemetryTriggerBinary: () => { throw new Error("fixture"); } })(capture);
146
+ pi.registerProvider(provider, { api: provider, apiKey: "fixture-only", baseUrl: "http://invalid.local", models: [{ id: model.id, name: model.name, reasoning: false, input: ["text"], cost: model.cost, contextWindow: model.contextWindow, maxTokens: model.maxTokens }],
147
+ streamSimple(_model, context) {
148
+ requests.push({ system: ai.getCurrentSystemPrompt(context.messages), tools: ai.getCurrentTools(context.messages).map((tool) => tool.name) });
149
+ const stream = ai.createAssistantMessageEventStream();
150
+ const message: AssistantMessage = { role: "assistant", api: model.api, provider, model: model.id, content: [], stopReason: "stop", timestamp: Date.now(), usage: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, totalTokens: 0, cost: { input: 0, output: 0, cacheRead: 0, cacheWrite: 0, total: 0 } } };
151
+ queueMicrotask(() => { stream.push({ type: "start", partial: message }); stream.push({ type: "done", reason: "stop", message }); stream.end(); });
152
+ return stream;
153
+ },
154
+ });
155
+ }],
156
+ });
157
+ await loader.reload();
158
+ assert.deepEqual(loader.getExtensions().errors, []);
159
+ const { session } = await sdk.createAgentSession({ cwd, agentDir: profile, modelRuntime: runtime, model: model as never, thinkingLevel: "off", resourceLoader: loader, tools: ["read", "gentle_review", ...HIDDEN], sessionManager: sdk.SessionManager.inMemory(cwd), settingsManager: settings });
160
+ let closed = false;
161
+ const close = async () => {
162
+ if (closed) return;
163
+ closed = true;
164
+ await session.abort();
165
+ // SDK dispose does not emit session_shutdown; dispatch the actual
166
+ // registered production handlers with their SDK-provided context.
167
+ for (const handler of shutdown) await handler();
168
+ session.dispose();
169
+ };
170
+ live.push(close);
171
+ await session.bindExtensions({ mode: "rpc", uiContext: ui, onError: (error) => errors.push(error.error) });
172
+ return {
173
+ session, notices, requests, errors, close,
174
+ prompt: (text: string) => session.prompt(text, { source: "interactive" }),
175
+ assess: () => {
176
+ assert.ok(ctx);
177
+ return tools.get("gentle_review")!.execute("mode-race", { operation: "assess" }, undefined, undefined, ctx);
178
+ },
179
+ };
180
+ }
181
+ return { root, repo, host, native };
182
+ }
183
+
184
+ function assertPrompt(host: { requests: Array<{ system: string; tools: string[] }> }, expected: "on" | "off" | "unknown", source?: string) {
185
+ const request = host.requests.at(-1)!;
186
+ assert.ok(request);
187
+ const expectedLine = expected === "unknown" ? "Receipt-driven development: unknown (native status unavailable)" : line(expected, source!);
188
+ assert.ok(request.system.includes(expectedLine), `expected ${expectedLine}; got ${request.system.match(/Receipt-driven development: [^\n]+/)?.[0]}`);
189
+ assert.equal(request.system.includes("RDD off does not require an assessment"), expected === "off");
190
+ assert.equal(request.system.includes("named Task Size high-risk item still requires one independent verifier"), expected === "off");
191
+ for (const name of HIDDEN) assert.equal(request.tools.includes(name), expected !== "off", name);
192
+ }
193
+
194
+ test("registered mode command refreshes pinned on/off/source and preserves clone-default reporting", { timeout: 30_000 }, async (t) => {
195
+ const f = await fixture(t, { global: "on", cloneLocal: "" });
196
+ const cwd = f.repo("repo");
197
+ const host = await f.host(cwd);
198
+ await host.prompt("Initial request");
199
+ assertPrompt(host, "on", "global");
200
+ await host.prompt("/gentle:review-mode disable");
201
+ assert.deepEqual(host.notices.at(-1), { message: "receipt-driven development: off (decided by clone_local)", type: "info" });
202
+ await host.prompt("After disable");
203
+ assertPrompt(host, "off", "clone_local");
204
+ await host.prompt("/gentle:review-mode enable");
205
+ assert.deepEqual(host.notices.at(-1), { message: "receipt-driven development: on (decided by global)", type: "info" });
206
+ await host.prompt("After enable");
207
+ assertPrompt(host, "on", "global");
208
+ f.native.state(cwd).global = "";
209
+ await host.prompt("/gentle:review-mode enable");
210
+ assert.deepEqual(host.notices.at(-1), { message: "receipt-driven development: on (decided by default)", type: "info" });
211
+ await host.prompt("After source change");
212
+ assertPrompt(host, "on", "default");
213
+ await host.prompt("/gentle:review-mode status");
214
+ assert.deepEqual(host.notices.at(-1), { message: "receipt-driven development: on (decided by default)", type: "info" });
215
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["disable", "enable", "enable"]);
216
+ for (const call of f.native.calls) assert.equal(call.scope, undefined, "legacy command does not request a global scope");
217
+ assert.deepEqual(host.errors, []);
218
+ });
219
+
220
+ test("invalid, refused and malformed reads do not grant authority or fabricate off", { timeout: 30_000 }, async (t) => {
221
+ const f = await fixture(t, { global: "off", cloneLocal: "off" });
222
+ const cwd = f.repo("repo");
223
+ const host = await f.host(cwd);
224
+ await host.prompt("Initial request");
225
+ assertPrompt(host, "off", "clone_local");
226
+ const calls = f.native.calls.length;
227
+ const state = { ...f.native.state(cwd) };
228
+ const writes = structuredClone(f.native.writes);
229
+ await host.prompt("/gentle:review-mode invalid action");
230
+ assert.deepEqual(host.notices.at(-1), { message: 'Unknown /gentle:review-mode sub-action "invalid action". Use status, disable, or enable.', type: "warning" });
231
+ assert.equal(f.native.calls.length, calls);
232
+ assert.deepEqual(f.native.state(cwd), state);
233
+ assert.deepEqual(f.native.writes, writes);
234
+ f.native.failMutation(true);
235
+ await host.prompt("/gentle:review-mode enable");
236
+ assert.deepEqual(host.notices.at(-1), { message: "fixture mutation refused", type: "error" });
237
+ assert.deepEqual(f.native.state(cwd), state);
238
+ assert.deepEqual(f.native.writes, writes);
239
+ f.native.invalidRead(true);
240
+ await host.prompt("Read after failure");
241
+ assertPrompt(host, "unknown");
242
+ f.native.invalidRead(false);
243
+ await host.prompt("Freshly confirmed off");
244
+ assertPrompt(host, "off", "clone_local");
245
+ const beforeFreshRead = f.native.calls.filter((call) => call.operation === "status").length;
246
+ await host.prompt("Confirm off again");
247
+ assertPrompt(host, "off", "clone_local");
248
+ assert.equal(f.native.calls.filter((call) => call.operation === "status").length, beforeFreshRead + 1);
249
+ f.native.failRead(true);
250
+ await host.prompt("Failed fresh off read");
251
+ assertPrompt(host, "unknown");
252
+ f.native.failRead(false);
253
+ f.native.failMutation(false);
254
+ await host.prompt("/gentle:review-mode enable");
255
+ assert.deepEqual(host.notices.at(-1), { message: "receipt-driven development: off (decided by global)\nThat did not turn reviews back on: /gentle:review-mode enable only clears a clone-local override, which cannot override a global off. Run `gentle-ai review mode enable --scope=global` to turn them back on.", type: "warning" });
256
+ assert.deepEqual(f.native.state(cwd), { global: "off", cloneLocal: "" });
257
+ await host.prompt("Read global off");
258
+ assertPrompt(host, "off", "global");
259
+ assert.deepEqual(host.errors, []);
260
+ });
261
+
262
+ test("late startup status cannot resurrect on after a successful disable", { timeout: 30_000 }, async (t) => {
263
+ const f = await fixture(t, { global: "on", cloneLocal: "" });
264
+ const cwd = f.repo("repo");
265
+ const pending = f.native.holdNext();
266
+ const host = await f.host(cwd);
267
+ await pending.started;
268
+ await host.prompt("/gentle:review-mode disable");
269
+ assert.deepEqual(f.native.state(cwd), { global: "on", cloneLocal: "off" });
270
+ pending.read.resolve({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "", effective: "on", source: "global" } });
271
+ await pending.read.promise;
272
+ await new Promise<void>((resolve) => setImmediate(resolve));
273
+ await host.prompt("After stale startup result");
274
+ assertPrompt(host, "off", "clone_local");
275
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["disable"]);
276
+ assert.deepEqual(f.native.targets, [], "stale on must not launch target status");
277
+ assert.deepEqual(host.errors, []);
278
+ });
279
+
280
+ test("an unavailable mode provider cannot change native state or validate off", { timeout: 30_000 }, async (t) => {
281
+ const f = await fixture(t, { global: "off", cloneLocal: "off" });
282
+ const cwd = f.repo("repo");
283
+ const state = { ...f.native.state(cwd) };
284
+ const host = await f.host(cwd, null);
285
+ await host.prompt("/gentle:review-mode disable");
286
+ assert.deepEqual(host.notices.at(-1), { message: "Gentle AI review mode is not available with the currently negotiated native version.", type: "info" });
287
+ await host.prompt("Unavailable status");
288
+ assertPrompt(host, "unknown");
289
+ assert.deepEqual(f.native.calls, []);
290
+ assert.deepEqual(f.native.writes, []);
291
+ assert.deepEqual(f.native.state(cwd), state);
292
+ assert.deepEqual(host.errors, []);
293
+ });
294
+
295
+ test("a stale in-flight off prompt cannot undo another session's enable", { timeout: 30_000 }, async (t) => {
296
+ const f = await fixture(t, { global: "on", cloneLocal: "off" });
297
+ const cwd = f.repo("repo");
298
+ const first = await f.host(cwd);
299
+ const second = await f.host(cwd);
300
+ await first.prompt("First session ready");
301
+ await second.prompt("Second session ready");
302
+ assertPrompt(first, "off", "clone_local");
303
+ assertPrompt(second, "off", "clone_local");
304
+ const pending = f.native.holdNext();
305
+ const inFlight = first.prompt("Prompt awaiting the old status");
306
+ await pending.started;
307
+ await second.prompt("/gentle:review-mode enable");
308
+ assert.deepEqual(second.notices.at(-1), { message: "receipt-driven development: on (decided by global)", type: "info" });
309
+ assert.deepEqual(f.native.state(cwd), { global: "on", cloneLocal: "" });
310
+ pending.read.resolve({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "off", effective: "off", source: "clone_local" } });
311
+ await inFlight;
312
+ assertPrompt(first, "unknown");
313
+ await first.prompt("Prompt after the stale read");
314
+ await second.prompt("Other session after enable");
315
+ assertPrompt(first, "on", "global");
316
+ assertPrompt(second, "on", "global");
317
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["enable"]);
318
+ assert.deepEqual([...first.errors, ...second.errors], []);
319
+ });
320
+
321
+ test("existing review-mode command protocol retains exact notifications and native requests", { timeout: 30_000 }, async (t) => {
322
+ const f = await fixture(t, { global: "on", cloneLocal: "" });
323
+ const cwd = f.repo("repo");
324
+ const host = await f.host(cwd);
325
+ await host.prompt("Warm status");
326
+ host.notices.length = 0;
327
+ f.native.calls.length = 0;
328
+ for (const action of ["", " status", " disable", " status", " enable", " invalid action"]) await host.prompt(`/gentle:review-mode${action}`);
329
+ f.native.failMutation(true);
330
+ await host.prompt("/gentle:review-mode disable");
331
+ f.native.failMutation(false);
332
+ f.native.state(cwd).global = "off";
333
+ f.native.state(cwd).cloneLocal = "off";
334
+ await host.prompt("/gentle:review-mode enable");
335
+ const expected = [
336
+ { message: "receipt-driven development: on (decided by global)", type: "info" },
337
+ { message: "receipt-driven development: on (decided by global)", type: "info" },
338
+ { message: "receipt-driven development: off (decided by clone_local)", type: "info" },
339
+ { message: "receipt-driven development: off (decided by clone_local)", type: "info" },
340
+ { message: "receipt-driven development: on (decided by global)", type: "info" },
341
+ { message: 'Unknown /gentle:review-mode sub-action "invalid action". Use status, disable, or enable.', type: "warning" },
342
+ { message: "fixture mutation refused", type: "error" },
343
+ { message: "receipt-driven development: off (decided by global)\nThat did not turn reviews back on: /gentle:review-mode enable only clears a clone-local override, which cannot override a global off. Run `gentle-ai review mode enable --scope=global` to turn them back on.", type: "warning" },
344
+ ];
345
+ const calls = f.native.calls.map((call) => ({ ...call, cwd: "<fixture-cwd>" }));
346
+ assert.deepEqual(host.notices, expected);
347
+ assert.deepEqual(calls, ["status", "status", "disable", "status", "enable", "disable", "enable"].map((operation) => ({ cwd: "<fixture-cwd>", operation })));
348
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["disable", "enable", "enable"]);
349
+ assert.deepEqual(f.native.state(cwd), { global: "off", cloneLocal: "" });
350
+ assert.deepEqual(host.errors, []);
351
+ t.diagnostic(`COMMAND_DIFFERENTIAL ${JSON.stringify({ notices: host.notices, calls, writes: f.native.writes.map(({ operation, state }) => ({ operation, state })), state: f.native.state(cwd), errors: host.errors })}`);
352
+ });
353
+
354
+ test("session and workspace replacement cannot reuse an older in-flight startup result", { timeout: 30_000 }, async (t) => {
355
+ const f = await fixture(t, { global: "on", cloneLocal: "" });
356
+ const a = f.repo("repo-a");
357
+ const b = f.repo("repo-b");
358
+ const pending = f.native.holdNext();
359
+ const old = await f.host(a);
360
+ await pending.started;
361
+ await old.close();
362
+ f.native.state(a).cloneLocal = "off";
363
+ f.native.state(b).cloneLocal = "off";
364
+ const other = await f.host(b);
365
+ await other.prompt("Workspace B");
366
+ assertPrompt(other, "off", "clone_local");
367
+ const current = await f.host(a);
368
+ await current.prompt("New session A");
369
+ assertPrompt(current, "off", "clone_local");
370
+ pending.read.resolve({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "", effective: "on", source: "global" } });
371
+ await pending.read.promise;
372
+ await new Promise<void>((resolve) => setImmediate(resolve));
373
+ await current.prompt("A after old startup completes");
374
+ assertPrompt(current, "off", "clone_local");
375
+ assert.deepEqual(f.native.targets, []);
376
+ assert.deepEqual(f.native.writes, []);
377
+ assert.deepEqual([...old.errors, ...other.errors, ...current.errors], []);
378
+ });
379
+
380
+ test("held startup OFF cannot suppress guidance after registered enable", { timeout: 30_000 }, async (t) => {
381
+ const f = await fixture(t, { global: "on", cloneLocal: "off" });
382
+ const cwd = f.repo("repo");
383
+ const pending = f.native.holdNext();
384
+ const host = await f.host(cwd);
385
+ await pending.started;
386
+ await host.prompt("/gentle:review-mode enable");
387
+ assert.deepEqual(host.notices.at(-1), { message: "receipt-driven development: on (decided by global)", type: "info" });
388
+ pending.read.resolve({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "off", effective: "off", source: "clone_local" } });
389
+ await pending.read.promise;
390
+ await new Promise<void>((resolve) => setImmediate(resolve));
391
+ await host.prompt("Require current guidance");
392
+ assertPrompt(host, "on", "global");
393
+ const result = await host.assess();
394
+ assert.equal(result.details.rddLine, "on");
395
+ assert.equal(result.details.nativeRisk, "medium");
396
+ assert.deepEqual(f.native.assessments, [cwd]);
397
+ assert.deepEqual(f.native.targets, [cwd]);
398
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["enable"]);
399
+ assert.deepEqual(host.errors, []);
400
+ });
401
+
402
+ test("shutdown and reopen invalidate a held OFF direct assessment", { timeout: 30_000 }, async (t) => {
403
+ const f = await fixture(t, { global: "on", cloneLocal: "off" });
404
+ const cwd = f.repo("repo");
405
+ const old = await f.host(cwd);
406
+ await old.prompt("Initial OFF");
407
+ assertPrompt(old, "off", "clone_local");
408
+ const pending = f.native.holdNext();
409
+ const assessment = old.assess();
410
+ await pending.started;
411
+ await old.close();
412
+ const fresh = await f.host(cwd);
413
+ await fresh.prompt("/gentle:review-mode enable");
414
+ assert.deepEqual(fresh.notices.at(-1), { message: "receipt-driven development: on (decided by global)", type: "info" });
415
+ pending.read.resolve({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "off", effective: "off", source: "clone_local" } });
416
+ const result = await assessment;
417
+ assert.equal(result.details.rddLine, "unknown");
418
+ assert.equal(result.details.nativeRisk, "medium");
419
+ await fresh.prompt("Reopened guidance");
420
+ assertPrompt(fresh, "on", "global");
421
+ assert.deepEqual(f.native.assessments, [cwd]);
422
+ assert.deepEqual(f.native.targets, [cwd]);
423
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["enable"]);
424
+ assert.deepEqual([...old.errors, ...fresh.errors], []);
425
+ });
426
+
427
+ test("a held OFF assessment cannot skip native assessment after another session enables RDD", { timeout: 30_000 }, async (t) => {
428
+ const f = await fixture(t, { global: "on", cloneLocal: "off" });
429
+ const cwd = f.repo("repo");
430
+ const first = await f.host(cwd);
431
+ const second = await f.host(cwd);
432
+ await first.prompt("First session ready");
433
+ await second.prompt("Second session ready");
434
+ const pending = f.native.holdNext();
435
+ const inFlight = first.assess();
436
+ await pending.started;
437
+ await second.prompt("/gentle:review-mode enable");
438
+ assert.deepEqual(second.notices.at(-1), { message: "receipt-driven development: on (decided by global)", type: "info" });
439
+ assert.deepEqual(f.native.state(cwd), { global: "on", cloneLocal: "" });
440
+ pending.read.resolve({ operation: "status", scope: "clone", status: { global: "on", cloneLocal: "off", effective: "off", source: "clone_local" } });
441
+ const result = await inFlight;
442
+ assert.equal(result.isError === true, false);
443
+ assert.equal(result.details.rddLine, "unknown", "a stale OFF response is not fresh evidence");
444
+ assert.equal(result.details.nativeRisk, "medium");
445
+ assert.equal(result.details.plan.writerSelfVerification, true);
446
+ assert.deepEqual(f.native.assessments, [cwd]);
447
+ assert.deepEqual(f.native.targets, [cwd]);
448
+ assert.deepEqual(f.native.writes.map(({ operation }) => operation), ["enable"]);
449
+ assert.deepEqual([...first.errors, ...second.errors], []);
450
+ });