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
@@ -1,10 +1,10 @@
1
1
  import assert from "node:assert/strict";
2
2
  import { execFileSync } from "node:child_process";
3
- import { mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
3
+ import { mkdirSync, mkdtempSync, readFileSync, realpathSync, rmSync, writeFileSync } from "node:fs";
4
4
  import { tmpdir } from "node:os";
5
5
  import { join } from "node:path";
6
6
  import test from "node:test";
7
- import { __testing } from "../extensions/gentle-ai.ts";
7
+ import { __testing, createGentleAiExtension } from "../extensions/gentle-ai.ts";
8
8
  import { CandidateViewRegistry } from "../lib/review-candidate-view.ts";
9
9
  import { localProfilePinPath, repoProfileDeclarationPath, writeProfilePinSync } from "../lib/agent-profile-pin.ts";
10
10
  import { createProfile, emptyProfilesFile, profilesFilePath, writeProfilesFileSync } from "../lib/agent-profiles.ts";
@@ -14,6 +14,11 @@ import { NativeReviewIntegrationError, type NativeReviewCli, type NativeReviewUn
14
14
  import { REVIEW_HOST_RELAY_FAILURE, REVIEW_HOST_RELAY_PI_TIMEOUT_ENV, REVIEW_HOST_RELAY_PI_TIMEOUT_MAX_MS, REVIEW_HOST_RELAY_SUBMISSION_MISSING_MESSAGE, REVIEW_HOST_RELAY_UNAVAILABLE_MESSAGE, ReviewHostRelayError, type ReviewHostRelayRequest } from "../lib/review-host-relay.ts";
15
15
  import { decodeReviewFailureV2, decodeReviewNextTransitionV3, decodeReviewStatusV3, type ReviewArtifactSubjectV2, type ReviewCaptureSubmissionV1, type ReviewCollectInputV3, type ReviewStatusV3 } from "../lib/review-integration-v2.ts";
16
16
  import type { InProcessReviewerRegistry } from "../lib/inprocess-reviewer.ts";
17
+ import { SessionManager, type ExtensionAPI, type ExtensionContext } from "@earendil-works/pi-coding-agent";
18
+ import { createSessionProfileBind, createSessionProfileClear, createSessionProfileStartupBind, SESSION_PROFILE_CUSTOM_TYPE } from "../lib/session-profile-persistence.ts";
19
+ import { readSessionProfileAuthority } from "../lib/session-profile-authority.ts";
20
+ import { resetSessionProfileBindingsForTesting } from "../lib/session-profile-binding.ts";
21
+ import { resetFrozenInheritedProfilesForTesting, resolveSessionProfile, sessionProfileRoutingAt } from "../lib/session-profile-freeze.ts";
17
22
 
18
23
  // One-slot capture routing: the host relay runs only when the selected
19
24
  // provider-returned collect input carries the --materialize token. Every
@@ -1212,7 +1217,7 @@ const PINNED_COMPLETE: AgentModelConfig = {
1212
1217
  // three reviewer roles that models.json still configures.
1213
1218
  const PINNED_PARTIAL: AgentModelConfig = { "review-risk": { model: "pinned/risk-model" } };
1214
1219
 
1215
- function pinFixture(t: test.TestContext): string {
1220
+ function pinFixture(t: test.TestContext, globalModels: AgentModelConfig | "absent" = GLOBAL_MODELS): string {
1216
1221
  const configHome = mkdtempSync(join(tmpdir(), "gentle-pi-relay-pin-config-"));
1217
1222
  const previous = process.env.GENTLE_PI_CONFIG_HOME;
1218
1223
  const previousDevBinary = process.env[GENTLE_AI_DEV_BINARY_ENV];
@@ -1235,7 +1240,7 @@ function pinFixture(t: test.TestContext): string {
1235
1240
  store = createProfile(store, "pinned-complete", PINNED_COMPLETE);
1236
1241
  store = createProfile(store, "pinned-partial", PINNED_PARTIAL);
1237
1242
  writeProfilesFileSync(profilesFilePath(configHome), store);
1238
- writeFileSync(join(configHome, "models.json"), `${JSON.stringify(GLOBAL_MODELS, null, 2)}\n`);
1243
+ if (globalModels !== "absent") writeFileSync(join(configHome, "models.json"), `${JSON.stringify(globalModels, null, 2)}\n`);
1239
1244
  return repository(t);
1240
1245
  }
1241
1246
 
@@ -1398,6 +1403,7 @@ test("a pinned profile missing a required group role is refused typed before any
1398
1403
  const failure = result.failure as { kind?: string } | undefined;
1399
1404
  assert.equal(failure?.kind, "reviewer-config-invalid");
1400
1405
  assert.match(String(result.reason), /no model is configured for review-resilience/, "whole-profile precedence: models.json must not fill the pinned profile's gaps");
1406
+ assert.match(String(result.reason), /\(routing source: repository profile pin; the review-resilience entry is missing\)/, "the refusal names where the routing came from");
1401
1407
  assert.equal(modelLookups, 0, "the typed refusal fires before any model resolution");
1402
1408
  assert.equal(authAttempts, 0, "the typed refusal fires before any provider auth");
1403
1409
  });
@@ -1487,3 +1493,251 @@ test("a lens slot with no routing entry never borrows Pi's persisted default mod
1487
1493
  assert.equal(relayed.length, 1);
1488
1494
  assert.equal(relayed[0]!.selection, undefined);
1489
1495
  });
1496
+
1497
+ // gentle-shell#2742, section 7: reviewers check session profile authority as
1498
+ // launches do. A saved Pi session whose newest record is the given one.
1499
+ function profileSession(t: test.TestContext, customType: string, data: unknown): SessionManager {
1500
+ const dir = mkdtempSync(join(tmpdir(), "gentle-pi-relay-session-"));
1501
+ t.after(() => { rmSync(dir, { recursive: true, force: true }); resetSessionProfileBindingsForTesting(); resetFrozenInheritedProfilesForTesting(); });
1502
+ const manager = SessionManager.create(dir, join(dir, "sessions"));
1503
+ manager.appendMessage({ role: "user", content: "fixture", timestamp: 1 });
1504
+ manager.appendCustomEntry(customType, data);
1505
+ return manager;
1506
+ }
1507
+
1508
+ const transcript = (manager: SessionManager) => readFileSync(manager.getSessionFile()!, "utf8");
1509
+
1510
+ // The v9 host-mediated validator: the refuter slot under the validation operation.
1511
+ const hostMediatedValidatorCollectInput = (lineageId: string): ReviewCollectInputV3 => ({ ...hostMediatedRefuterCollectInput(lineageId), name: "provider_validation", schema: "https://gentle-ai.dev/schema/review/validator/v1", captureOperation: "review.capture-validation" });
1512
+
1513
+ for (const role of ["lens", "refuter", "validator"] as const)
1514
+ test(`unavailable session profile authority blocks a ${role} capture before any reviewer run, then the same binding resumes`, async (t) => {
1515
+ t.after(() => __testing.setReviewHostRelayRunnerForTesting());
1516
+ const cwd = pinFixture(t);
1517
+ isolatedAgentHome(t, PI_DEFAULT_SETTINGS);
1518
+ const manager = profileSession(t, "gentle-pi.session-profile/v99", { kind: "future" });
1519
+ const lineageId = `relay-authority-${role}`;
1520
+ const input = role === "lens" ? relayCollectInput(lineageId, "review-risk", 0) : role === "refuter" ? hostMediatedRefuterCollectInput(lineageId) : hostMediatedValidatorCollectInput(lineageId);
1521
+ const harness = nativeHarness([finalizeStatus(lineageId, [input]), finalizeStatus(lineageId, [input])]);
1522
+ const relays: string[] = [];
1523
+ __testing.setReviewHostRelayRunnerForTesting(async (request) => { relays.push(request.routingKey); return { promptByteLength: 64, resultByteLength: 32, submission: '{"admission_decision":"completed"}' }; });
1524
+ const before = transcript(manager);
1525
+ const capture = () => __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(input), reviewerRunAcknowledged: true }, cwd, harness.native, undefined, undefined, undefined, false, undefined, manager.getSessionId(), undefined, manager);
1526
+
1527
+ const blocked = await capture();
1528
+
1529
+ assert.deepEqual([blocked.status, blocked.outcome, blocked.mutation_performed, blocked.mutation_outcome], ["blocked", "session-profile-authority-unavailable", false, "none"]);
1530
+ assert.match(String(blocked.reason), /^Session profile authority unavailable; affected launches are blocked/);
1531
+ assert.deepEqual(relays, [], "no reviewer run starts");
1532
+ assert.equal(transcript(manager), before, "the transcript gains no entry");
1533
+ manager.appendCustomEntry(SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileClear());
1534
+ assert.equal((await capture()).status, "captured", "the untouched review resumes once authority is available");
1535
+ assert.deepEqual(relays, [role === "lens" ? "review-risk" : `review-${role}`]);
1536
+ });
1537
+
1538
+ // An older provider's self-contained --execute=true role vector: Go spawns its
1539
+ // own pi for the refuter or validator, so it is a reviewer run too.
1540
+ function providerRoleVectorInput(lineageId: string, captureOperation: string): ReviewCollectInputV3 {
1541
+ return { name: "provider_role", schema: `https://gentle-ai.dev/schema/review/${captureOperation === "review.capture-refuter" ? "refuter" : "validator"}/v1`, captureOperation, arguments: [...roleBindingArguments(lineageId), { name: "agent", value: "pi", token: "--agent=pi" }, { name: "execute", value: "true", token: "--execute=true" }] };
1542
+ }
1543
+
1544
+ for (const captureOperation of ["review.capture-refuter", "review.capture-validation"])
1545
+ test(`unavailable session profile authority blocks a self-contained ${captureOperation} vector before Go spawns its reviewer, then the same binding resumes`, async (t) => {
1546
+ const cwd = pinFixture(t);
1547
+ const manager = profileSession(t, "gentle-pi.session-profile/v99", { kind: "future" });
1548
+ const lineageId = `relay-authority-${captureOperation}`, input = providerRoleVectorInput(lineageId, captureOperation);
1549
+ const harness = nativeHarness([finalizeStatus(lineageId, [input]), finalizeStatus(lineageId, [input])]);
1550
+ let spawned = 0;
1551
+ const native: NativeReviewCli = { ...harness.native, captureProviderRole: async () => { spawned += 1; return { schema: "gentle-ai.review-provider-role-capture/v1", lineageId, targetIdentity: SHA, role: "refuter", captured: true } as never; } };
1552
+ const before = transcript(manager);
1553
+ const capture = () => __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(input) }, cwd, native, undefined, undefined, undefined, false, undefined, manager.getSessionId(), undefined, manager);
1554
+
1555
+ const blocked = await capture();
1556
+
1557
+ assert.deepEqual([blocked.status, blocked.outcome, blocked.mutation_performed, blocked.mutation_outcome], ["blocked", "session-profile-authority-unavailable", false, "none"]);
1558
+ assert.equal(spawned, 0, "no reviewer run starts");
1559
+ assert.equal(transcript(manager), before, "the transcript gains no entry");
1560
+ manager.appendCustomEntry(SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileClear());
1561
+ assert.equal((await capture()).outcome, "native-provider-role-captured", "the untouched review resumes once authority is available");
1562
+ assert.equal(spawned, 1);
1563
+ });
1564
+
1565
+ test("unavailable session profile authority blocks a grouped capture before any reviewer run, then the same group resumes", async (t) => {
1566
+ t.after(() => __testing.setReviewHostRelayGroupRunnersForTesting());
1567
+ const cwd = pinFixture(t);
1568
+ const manager = profileSession(t, "gentle-pi.session-profile/v99", { kind: "future" });
1569
+ const lineageId = "relay-authority-group", inputs = groupInputs(lineageId);
1570
+ const harness = nativeHarness([finalizeStatus(lineageId, inputs), finalizeStatus(lineageId, inputs), ...inputs.map((_input, index) => finalizeStatus(lineageId, inputs.slice(index))), finalizeStatus(lineageId)]);
1571
+ let relays = 0;
1572
+ __testing.setReviewHostRelayGroupRunnersForTesting(async (requests) => { relays += requests.length; return requests.map(prepared); }, async () => ({ promptByteLength: 64, resultByteLength: 32, submission: "{}" }));
1573
+ const before = transcript(manager);
1574
+ const capture = () => __testing.executeReviewCaptureGroupOperation({ lineageId, collectBindings: inputs.map((input) => JSON.stringify(input)), reviewerRunAcknowledged: true }, cwd, harness.native, undefined, undefined, undefined, false, undefined, manager.getSessionId(), undefined, manager);
1575
+
1576
+ const blocked = await capture();
1577
+
1578
+ assert.deepEqual([blocked.status, blocked.outcome, blocked.mutation_performed, blocked.mutation_outcome], ["blocked", "session-profile-authority-unavailable", false, "none"]);
1579
+ assert.equal(relays, 0, "no reviewer run starts");
1580
+ assert.equal(harness.statusCalls.length, 1, "only the selecting STATUS ran");
1581
+ assert.equal(transcript(manager), before, "the transcript gains no entry");
1582
+ manager.appendCustomEntry(SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileClear());
1583
+ assert.equal((await capture()).outcome, "native-reviewer-group-status-reconciled", "the untouched group resumes once authority is available");
1584
+ assert.equal(relays, 4);
1585
+ });
1586
+
1587
+ // The registered tools read the session manager from Pi's ctx, as a real turn does.
1588
+ for (const name of ["gentle_review_capture", "gentle_review_capture_group"])
1589
+ test(`the registered ${name} tool blocks on the unavailable authority of ctx.sessionManager`, async (t) => {
1590
+ t.after(() => { __testing.setReviewHostRelayRunnerForTesting(); __testing.setReviewHostRelayGroupRunnersForTesting(); });
1591
+ const cwd = pinFixture(t);
1592
+ const manager = profileSession(t, "gentle-pi.session-profile/v99", { kind: "future" });
1593
+ const lineageId = `relay-authority-tool-${name}`, inputs = name === "gentle_review_capture" ? [relayCollectInput(lineageId, "review-risk", 0)] : groupInputs(lineageId);
1594
+ const harness = nativeHarness([finalizeStatus(lineageId, inputs)]);
1595
+ let relays = 0;
1596
+ __testing.setReviewHostRelayRunnerForTesting(async () => { relays += 1; return { promptByteLength: 64, resultByteLength: 32, submission: "{}" }; });
1597
+ __testing.setReviewHostRelayGroupRunnersForTesting(async (requests) => { relays += requests.length; return requests.map(prepared); }, async () => ({ promptByteLength: 64, resultByteLength: 32, submission: "{}" }));
1598
+ const tools = new Map<string, { execute: (id: string, params: unknown, signal: undefined, onUpdate: undefined, ctx: ExtensionContext) => Promise<{ details: Record<string, unknown> }> }>();
1599
+ createGentleAiExtension({ nativeReviewCli: harness.native })({ on() {}, registerTool(definition: { name: string }) { tools.set(definition.name, definition as never); }, registerCommand() {} } as unknown as ExtensionAPI);
1600
+ const params = name === "gentle_review_capture" ? { lineageId, collectBinding: JSON.stringify(inputs[0]), reviewerRunAcknowledged: true } : { lineageId, collectBindings: inputs.map((input) => JSON.stringify(input)), reviewerRunAcknowledged: true };
1601
+
1602
+ const { details } = await tools.get(name)!.execute("call-1", params, undefined, undefined, { cwd, hasUI: false, sessionManager: manager } as unknown as ExtensionContext);
1603
+
1604
+ assert.deepEqual([details.tool, details.status, details.outcome], [name, "blocked", "session-profile-authority-unavailable"]);
1605
+ assert.equal(relays, 0, "no reviewer run starts");
1606
+ });
1607
+
1608
+ test("a review without a session id runs as today, with no record to distrust", async (t) => {
1609
+ t.after(() => __testing.setReviewHostRelayRunnerForTesting());
1610
+ const cwd = pinFixture(t);
1611
+ const lineageId = "relay-authority-no-session", input = relayCollectInput(lineageId, "review-risk", 0);
1612
+ const harness = nativeHarness([finalizeStatus(lineageId, [input])]);
1613
+ const relayed: ReviewHostRelayRequest[] = [];
1614
+ __testing.setReviewHostRelayRunnerForTesting(async (request) => { relayed.push(request); return { promptByteLength: 64, resultByteLength: 32, submission: '{"admission_decision":"completed"}' }; });
1615
+ const unsaved = { getSessionId: () => "", getBranch: () => [{ type: "custom", customType: "gentle-pi.session-profile/v99", data: { kind: "future" } }], getSessionFile: () => undefined };
1616
+
1617
+ const result = await __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(input), reviewerRunAcknowledged: true }, cwd, harness.native, undefined, undefined, undefined, false, undefined, undefined, undefined, unsaved as never);
1618
+
1619
+ assert.equal(result.status, "captured");
1620
+ assert.equal(relayed[0]!.selection, "global/risk-model");
1621
+ });
1622
+
1623
+ // gentle-shell#2742, section 8: a startup record carries the profile's
1624
+ // orchestrator, so the provider review roles fall back to it as they do for
1625
+ // Use in this session; launch routing still ignores the key.
1626
+ test("a startup record's orchestrator feeds the provider review roles while launches ignore it", async (t) => {
1627
+ const cwd = pinFixture(t);
1628
+ isolatedAgentHome(t, PI_DEFAULT_SETTINGS);
1629
+ const team: AgentModelConfig = { orchestrator: { model: "team/orchestrator", thinking: "high" }, "review-risk": { model: "team/risk-model" } };
1630
+ const manager = profileSession(t, SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileStartupBind("global", "team", team));
1631
+ assert.equal(readSessionProfileAuthority(manager).available, true);
1632
+ const sessionId = manager.getSessionId(), lineageId = "relay-startup-orchestrator";
1633
+ const harness = nativeHarness([finalizeStatus(lineageId, [hostMediatedRefuterCollectInput(lineageId)])]);
1634
+ const relayed: ReviewHostRelayRequest[] = [];
1635
+ t.after(() => __testing.setReviewHostRelayRunnerForTesting());
1636
+ __testing.setReviewHostRelayRunnerForTesting(async (request) => { relayed.push(request); return { promptByteLength: 64, resultByteLength: 32, submission: '{"admission_decision":"completed"}' }; });
1637
+
1638
+ await __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(hostMediatedRefuterCollectInput(lineageId)), reviewerRunAcknowledged: true }, cwd, harness.native, undefined, undefined, undefined, false, undefined, sessionId, undefined, manager);
1639
+
1640
+ assert.deepEqual([relayed[0]!.routingKey, relayed[0]!.selection, relayed[0]!.thinking], ["review-refuter", "team/orchestrator", "high"]);
1641
+ const routing = __testing.readReviewerModelConfig(cwd, sessionId);
1642
+ assert.equal(__testing.reviewHostRelaySelection("review-validator", routing).selection, "team/orchestrator");
1643
+ assert.equal(__testing.reviewHostRelaySelection("risk", routing).selection, "team/risk-model");
1644
+ const resolution = resolveSessionProfile({ sessionId, cwd, configHome: process.env.GENTLE_PI_CONFIG_HOME! });
1645
+ assert.deepEqual([resolution.kind, sessionProfileRoutingAt(resolution, { cwd, configHome: process.env.GENTLE_PI_CONFIG_HOME! })], ["inherited", { "review-risk": { model: "team/risk-model" } }], "launch routing stays role-only");
1646
+ });
1647
+
1648
+ // gentle-shell#2163: with no binding, pin or frozen profile the reviewer reads
1649
+ // the same global effective routing the models panel shows and launches use
1650
+ // (#1731), so a lens routed only through subagents.json is not refused. An
1651
+ // explicit snapshot stays whole and fail-closed (#1544/#2477).
1652
+ function agentHomeRouting(t: test.TestContext, modelProfiles: Record<string, unknown>): void {
1653
+ isolatedAgentHome(t);
1654
+ const agentHome = process.env.GENTLE_PI_AGENT_HOME!;
1655
+ mkdirSync(join(agentHome, "agents"), { recursive: true });
1656
+ for (const name of Object.keys(modelProfiles)) writeFileSync(join(agentHome, "agents", `${name}.md`), `---\nname: ${name}\ndescription: fixture lens\n---\nReview.\n`);
1657
+ writeFileSync(join(agentHome, "subagents.json"), `${JSON.stringify({ model_profiles: modelProfiles }, null, 2)}\n`);
1658
+ }
1659
+
1660
+ test("without a binding or pin the reviewer reads the global effective routing the panel shows", async (t) => {
1661
+ t.after(() => __testing.setReviewHostRelayRunnerForTesting());
1662
+ const cwd = pinFixture(t, "absent");
1663
+ agentHomeRouting(t, { "review-risk": { model: "agenthome/risk-model", effort: "high" } });
1664
+ const lineageId = "relay-effective-routing";
1665
+ const harness = nativeHarness([finalizeStatus(lineageId, [relayCollectInput(lineageId, "review-risk", 0)])]);
1666
+ const relayed: ReviewHostRelayRequest[] = [];
1667
+ __testing.setReviewHostRelayRunnerForTesting(async (request) => {
1668
+ relayed.push(request);
1669
+ return { promptByteLength: 64, resultByteLength: 32, submission: '{"admission_decision":"completed"}' };
1670
+ });
1671
+
1672
+ const reviewer = __testing.readReviewerModelConfig(cwd, undefined);
1673
+ const result = await runCapture(cwd, harness, lineageId);
1674
+
1675
+ assert.deepEqual(reviewer, __testing.readEffectiveModelConfig(cwd), "what the panel shows is what the reviewer reads");
1676
+ assert.deepEqual(reviewer["review-risk"], { model: "agenthome/risk-model", thinking: "high" });
1677
+ assert.equal(result.status, "captured");
1678
+ assert.deepEqual([relayed[0]!.routingKey, relayed[0]!.selection, relayed[0]!.thinking], ["review-risk", "agenthome/risk-model", "high"]);
1679
+ });
1680
+
1681
+ test("an explicit session binding that omits a lens still refuses, naming the binding as its source", async (t) => {
1682
+ const cwd = pinFixture(t);
1683
+ agentHomeRouting(t, { "review-resilience": { model: "agenthome/resilience-model" } });
1684
+ const manager = profileSession(t, SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileBind("partial", { "review-risk": { model: "bound/risk-model" } }));
1685
+ const sessionId = manager.getSessionId(), lineageId = "relay-binding-missing-lens";
1686
+ const input = relayCollectInput(lineageId, "review-resilience", 0);
1687
+ const harness = nativeHarness([finalizeStatus(lineageId, [input])]);
1688
+ let modelLookups = 0;
1689
+ const registry: InProcessReviewerRegistry = { find: () => { modelLookups += 1; return undefined; }, getApiKeyAndHeaders: async () => ({ ok: true }) };
1690
+
1691
+ const result = await __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(input), reviewerRunAcknowledged: true }, cwd, harness.native, undefined, undefined, undefined, false, registry, sessionId, undefined, manager) as Record<string, unknown>;
1692
+
1693
+ assert.equal(resolveSessionProfile({ sessionId, cwd, configHome: process.env.GENTLE_PI_CONFIG_HOME! }).kind, "explicit");
1694
+ assert.equal(__testing.readReviewerModelConfig(cwd, sessionId)["review-resilience"], undefined, "neither models.json nor subagents.json fills the binding's gap");
1695
+ assert.equal(result.status, "blocked");
1696
+ assert.equal((result.failure as { kind?: string } | undefined)?.kind, "reviewer-config-invalid");
1697
+ assert.match(String(result.reason), /no model is configured for review-resilience \(routing source: session profile binding; the review-resilience entry is missing\)/);
1698
+ assert.equal(modelLookups, 0, "the typed refusal fires before any model resolution");
1699
+ });
1700
+
1701
+ test("a frozen startup profile that omits a lens keeps its whole snapshot over the effective routing", async (t) => {
1702
+ const cwd = pinFixture(t);
1703
+ agentHomeRouting(t, { "review-resilience": { model: "agenthome/resilience-model" } });
1704
+ const manager = profileSession(t, SESSION_PROFILE_CUSTOM_TYPE, createSessionProfileStartupBind("global", "team", { "review-risk": { model: "team/risk-model" } }));
1705
+ assert.equal(readSessionProfileAuthority(manager).available, true);
1706
+ const sessionId = manager.getSessionId();
1707
+
1708
+ const routing = __testing.readReviewerModelConfig(cwd, sessionId);
1709
+
1710
+ assert.deepEqual(routing, { "review-risk": { model: "team/risk-model" } });
1711
+ assert.deepEqual(__testing.reviewHostRelaySelection("resilience", routing), { routingKey: "review-resilience" }, "lens roles stay fail-closed");
1712
+ });
1713
+
1714
+ // The reviewed candidate never selects its own reviewer: the unpinned reviewer
1715
+ // reads the global effective routing from the session's directory, as the
1716
+ // launcher does, never from the target's project agents or subagents.json.
1717
+ function plantCandidateReviewer(target: string): void {
1718
+ mkdirSync(join(target, ".pi", "agents"), { recursive: true });
1719
+ writeFileSync(join(target, ".pi", "agents", "review-risk.md"), "---\nname: review-risk\ndescription: x\nmodel: candidate/chosen-model\n---\nx\n");
1720
+ }
1721
+
1722
+ test("an unpinned reviewer never reads routing from the reviewed target's own project agents", (t) => {
1723
+ const session = pinFixture(t, "absent");
1724
+ agentHomeRouting(t, { "review-risk": {} });
1725
+ const target = repository(t);
1726
+ plantCandidateReviewer(target);
1727
+ const routing = __testing.readReviewerModelConfig(target, "sid-target-agents", session);
1728
+ assert.deepEqual(routing["review-risk"], __testing.readEffectiveModelConfig(session)["review-risk"], "the reviewer reads the session's routing, not the candidate's");
1729
+ assert.equal(__testing.reviewHostRelaySelection("risk", routing).selection, undefined, "the lens stays fail-closed");
1730
+ });
1731
+
1732
+ test("an unpinned reviewer never reads routing from a same-clone worktree target's project agents", (t) => {
1733
+ const session = pinFixture(t, "absent");
1734
+ agentHomeRouting(t, { "review-risk": {} });
1735
+ const parent = mkdtempSync(join(tmpdir(), "gentle-pi-relay-worktree-"));
1736
+ t.after(() => rmSync(parent, { recursive: true, force: true }));
1737
+ const target = join(parent, "writer");
1738
+ execFileSync("git", ["worktree", "add", "-q", "-b", "writer", target], { cwd: session });
1739
+ plantCandidateReviewer(target);
1740
+ const routing = __testing.readReviewerModelConfig(target, "sid-worktree-agents", session);
1741
+ assert.deepEqual(routing["review-risk"], __testing.readEffectiveModelConfig(session)["review-risk"], "the reviewer reads the session's routing, not the writer worktree's");
1742
+ assert.equal(__testing.reviewHostRelaySelection("risk", routing).selection, undefined, "the lens stays fail-closed");
1743
+ });
@@ -621,6 +621,45 @@ test("a routing entry with no configured model is refused typed, naming the rout
621
621
  assert.match(error.message, /review-risk/);
622
622
  });
623
623
 
624
+ test("invalid or unavailable reviewer models refuse before materialization or completion", async (t) => {
625
+ const cases = [
626
+ { name: "invalid selection", override: { selection: "not-a-provider-model" }, kind: REVIEW_HOST_RELAY_FAILURE.REVIEWER_CONFIG_INVALID, expectedEvidence: undefined },
627
+ { name: "missing model", override: { reviewerRegistry: { find: () => undefined, getApiKeyAndHeaders: async () => { throw new Error("must not authenticate"); } } }, kind: REVIEW_HOST_RELAY_FAILURE.REVIEWER_MODEL_NOT_FOUND, expectedEvidence: undefined },
628
+ { name: "missing provider", override: { reviewerRegistry: { find: () => ({ provider: "extension", id: "model", api: "custom" }) as never, getProvider: () => undefined, getApiKeyAndHeaders: async () => { throw new Error("must not authenticate"); } } }, kind: REVIEW_HOST_RELAY_FAILURE.REVIEWER_MODEL_NOT_FOUND, expectedEvidence: { provider: "extension", api: "custom", reviewerModel: "extension/model" } },
629
+ ];
630
+ for (const item of cases) await t.test(item.name, async (t) => {
631
+ const fixture = harness(t), reviewer = textReviewer(REVIEWER_TEXT);
632
+ const error = await rejectsWithRelayError(runRelay(fixture, item.override, reviewer.runReviewer), item.kind, "pi");
633
+ assert.deepEqual(error.reviewerEvidence, item.expectedEvidence);
634
+ assert.equal(error.mutationOutcome, "none");
635
+ assert.equal(readLog(fixture.logPath).length, 0, "no native materialize or submit may run");
636
+ assert.equal(reviewer.calls.length, 0, "no completion may run");
637
+ assert.equal(existsSync(fixture.submitCapturePath), false);
638
+ });
639
+ });
640
+
641
+ test("a group checks every model before preparing any sibling reviewer", async (t) => {
642
+ for (const invalid of ["missing selection", "missing registry", "invalid selection", "missing model", "missing provider"]) await t.test(invalid, async (t) => {
643
+ const fixture = harness(t), requests = reviewerGroupRequests(fixture), reviewer = textReviewer(REVIEWER_TEXT);
644
+ requests[2] = { ...requests[2], ...(invalid === "missing selection" ? { selection: undefined }
645
+ : invalid === "missing registry" ? { reviewerRegistry: undefined }
646
+ : invalid === "invalid selection" ? { selection: "invalid" }
647
+ : invalid === "missing provider" ? { reviewerRegistry: { find: () => ({ provider: "extension", id: "model", api: "custom" }) as never, getProvider: () => undefined, getApiKeyAndHeaders: async () => { throw new Error("must not authenticate"); } } }
648
+ : { reviewerRegistry: { find: () => undefined, getApiKeyAndHeaders: async () => { throw new Error("must not authenticate"); } } }) };
649
+ let preparations = 0;
650
+ const kind = ["missing model", "missing provider"].includes(invalid) ? REVIEW_HOST_RELAY_FAILURE.REVIEWER_MODEL_NOT_FOUND : REVIEW_HOST_RELAY_FAILURE.REVIEWER_CONFIG_INVALID;
651
+ const error = await rejectsWithRelayError(runReviewHostRelayReviewerGroup(requests, async (request) => {
652
+ preparations++;
653
+ return prepareReviewHostRelaySlot(request, reviewer.runReviewer);
654
+ }), kind, "pi");
655
+ assert.deepEqual(error.reviewerEvidence, invalid === "missing provider" ? { provider: "extension", api: "custom", reviewerModel: "extension/model" } : undefined);
656
+ assert.equal(preparations, 0, "no sibling preparation may begin");
657
+ assert.equal(readLog(fixture.logPath).length, 0, "no native materialize or submit may run");
658
+ assert.equal(reviewer.calls.length, 0, "no completion may run");
659
+ assert.equal(existsSync(fixture.submitCapturePath), false);
660
+ });
661
+ });
662
+
624
663
  test("a tool call's cancelled signal maps to REVIEWER_ABORTED and forwards the caller's own signal to the completion", async (t) => {
625
664
  const fixture = harness(t);
626
665
  const controller = new AbortController();
@@ -16,6 +16,7 @@ import {
16
16
  decodeReviewStartV3,
17
17
  decodeReviewStartV4,
18
18
  decodeReviewStatusV3,
19
+ decodeReviewTargetedValidationRequestV1,
19
20
  } from "../lib/review-integration-v2.ts";
20
21
 
21
22
  const fixtureRoot = join(process.cwd(), "contracts", "review-integration", "v2", "fixtures");
@@ -951,6 +952,37 @@ test("next_transition decodes the v9 host-mediated provider role submission form
951
952
  );
952
953
  });
953
954
 
955
+ test("targeted validation preserves an explicitly frozen empty policy without accepting absent or non-string policy", () => {
956
+ // Gentle AI v4.3.1 CompactState explicitly distinguishes a non-nil empty
957
+ // policy from missing historical policy; both the constructor and request
958
+ // serializer retain the empty string. It is evidence, not a required label.
959
+ const sha = `sha256:${"a".repeat(64)}`;
960
+ const request = {
961
+ schema: "gentle-ai.review-targeted-validation-request/v1", request_hash: sha,
962
+ lineage_id: "review-fixture", expected_revision: sha, target_identity: sha,
963
+ fix_finding_ids: ["R1-001"], policy_content: "",
964
+ fix_findings: [{ id: "R1-001", lens: "risk", location: "selected.txt:1", severity: "CRITICAL",
965
+ claim: "restore the requested behavior", proof_refs: ["selected.txt:1"], evidence_class: "deterministic", causal_disposition: "introduced" }],
966
+ fix_classifications: [{ finding_id: "R1-001", class: "deterministic", causal_disposition: "introduced", proof: "selected.txt:1" }],
967
+ projection: "workspace", correction_candidate_tree: "b".repeat(40), correction_target_identity: sha,
968
+ correction_paths: ["selected.txt"], correction_paths_digest: sha,
969
+ };
970
+ for (const policy_content of ["", "\n \t", "Frozen policy\n"]) {
971
+ const input = { ...request, policy_content };
972
+ const before = structuredClone(input);
973
+ assert.equal(decodeReviewTargetedValidationRequestV1(input).policyContent, policy_content);
974
+ assert.deepEqual(input, before, "frozen policy bytes and request bindings must remain unchanged");
975
+ }
976
+ for (const policy_content of [undefined, null, false, 0, [], {}]) {
977
+ assert.throws(() => decodeReviewTargetedValidationRequestV1({ ...request, policy_content }), /policy_content/);
978
+ }
979
+ const absent: Record<string, unknown> = { ...request };
980
+ delete absent.policy_content;
981
+ assert.throws(() => decodeReviewTargetedValidationRequestV1(absent), /policy_content is required/);
982
+ assert.throws(() => decodeReviewTargetedValidationRequestV1({ ...request, request_hash: "invalid" }), /request_hash/);
983
+ assert.throws(() => decodeReviewTargetedValidationRequestV1({ ...request, base_tree: "c".repeat(40) }), /base_tree is not allowed/);
984
+ });
985
+
954
986
  test("v5 targeted-validator collect inputs carry the exact provider-owned validation request", () => {
955
987
  const requestHash = `sha256:${"a".repeat(64)}`;
956
988
  const expectedRevision = `sha256:${"b".repeat(64)}`;
@@ -1077,9 +1109,12 @@ test("v5 targeted-validator collect inputs carry the exact provider-owned valida
1077
1109
  ((malformedRequest.collect.inputs[0] as JsonObject).validation_request as JsonObject).unadvertised = true;
1078
1110
  assert.throws(() => decodeReviewNextTransitionV3(malformedRequest, { v5: true }), /not allowed/);
1079
1111
 
1080
- const weakenedRequest = clone(transition);
1081
- ((weakenedRequest.collect.inputs[0] as JsonObject).validation_request as JsonObject).policy_content = "";
1082
- assert.throws(() => decodeReviewNextTransitionV3(weakenedRequest, { v5: true }), /policy_content/);
1112
+ const emptyPolicyRequest = clone(transition);
1113
+ ((emptyPolicyRequest.collect.inputs[0] as JsonObject).validation_request as JsonObject).policy_content = "";
1114
+ assert.equal(decodeReviewNextTransitionV3(emptyPolicyRequest, { v5: true }).collect?.inputs[0]?.validationRequest?.policyContent, "");
1115
+ const malformedPolicyRequest = clone(transition);
1116
+ ((malformedPolicyRequest.collect.inputs[0] as JsonObject).validation_request as JsonObject).policy_content = null;
1117
+ assert.throws(() => decodeReviewNextTransitionV3(malformedPolicyRequest, { v5: true }), /policy_content/);
1083
1118
  });
1084
1119
 
1085
1120
  test("status.frozen carries the optional frozen manifest digest", () => {
@@ -1155,3 +1190,11 @@ test("next_transition.execute.binding stays open, as its schema declares no prop
1155
1190
  };
1156
1191
  assert.doesNotThrow(() => decodeReviewNextTransitionV3(withContext));
1157
1192
  });
1193
+
1194
+ test("capabilities retain request-context and START preflight features only when supported", () => {
1195
+ const source = fixture<any>("capabilities.fixture.json");
1196
+ source.features.optional.push({ name: "start_request_context", supported: true, requires: [] }, { name: "start_options_preflight", supported: false, requires: [] });
1197
+ const result = decodeReviewCapabilitiesV2(source, executableDigest);
1198
+ assert.equal(result.optionalFeatures.has("start_request_context"), true);
1199
+ assert.equal(result.optionalFeatures.has("start_options_preflight"), false);
1200
+ });
@@ -1,11 +1,21 @@
1
1
  import assert from "node:assert/strict";
2
+ import { readFileSync } from "node:fs";
3
+ import { dirname, join } from "node:path";
2
4
  import test from "node:test";
5
+ import { fileURLToPath } from "node:url";
3
6
  import { stream as streamAnthropic } from "@earendil-works/pi-ai/api/anthropic-messages";
4
7
  import { normalizeContext, validateToolArguments, type Model, type ToolCall } from "@earendil-works/pi-ai";
5
8
  import type { ExtensionAPI } from "@earendil-works/pi-coding-agent";
6
9
  import type { NativeReviewCli } from "../lib/native-review-cli.ts";
7
10
  import { __testing, createGentleAiExtension } from "../extensions/gentle-ai.ts";
8
11
 
12
+ const metadata = join(dirname(fileURLToPath(import.meta.resolve("@earendil-works/pi-ai"))), "..", "package.json");
13
+ const version: string = JSON.parse(readFileSync(metadata, "utf8")).version;
14
+ assert.match(version, /^\d+\.\d+\.\d+$/);
15
+ const [major, minor] = version.split(".").map(Number);
16
+ assert.ok(major >= 1, `Pi AI >=1.0.0 required, installed ${version}`);
17
+ const coercesStringNull = major > 1 || (major === 1 && minor >= 5);
18
+
9
19
  function registeredTools(): Map<string, any> {
10
20
  const tools = new Map<string, any>();
11
21
  createGentleAiExtension({ nativeReviewCli: null })({
@@ -53,7 +63,7 @@ test("public Anthropic non-strict adapter preserves the complete review tool dec
53
63
  assert.deepEqual(controller.required, ["operation"]);
54
64
  assert.deepEqual(Object.keys(controller.properties).sort(), ["operation", "lineageId", "selectionBinding", "intendedUntracked", "untrackedScope", "changeName", "idempotencyKey", "transition", "input", "outputPath", "inputPath", "operationId", "lineageIds", "workspaceRoot"].sort());
55
65
  assert.ok(controller.properties.input.anyOf.some((schema: any) => schema.type === "object"));
56
- assert.match(controller.properties.input.description, /START\/ASSESS\/answer-consent/);
66
+ assert.match(controller.properties.input.description, /START\/ASSESS\/answer-consent\/abandon/);
57
67
  assert.deepEqual(controller.properties.operation.enum, tools.get("gentle_review").parameters.properties.operation.enum);
58
68
  for (const name of ["gentle_review_capture", "gentle_review_capture_group"]) {
59
69
  const schema = emitted.get(name);
@@ -77,6 +87,19 @@ test("public Anthropic non-strict adapter preserves the complete review tool dec
77
87
  });
78
88
 
79
89
  const binding = { name: "reviewer_result", arguments: [] };
90
+
91
+ test("STATUS accepts object selectors and rejects malformed input before native access", async () => {
92
+ const input = { baseRef: "HEAD", committedOnly: true };
93
+ assert.equal(__testing.parseReviewControllerParameters(validate("gentle_review", { operation: "status", input })).input, JSON.stringify(input));
94
+ let calls = 0;
95
+ const native = new Proxy({}, { get: () => async () => { calls++; throw new Error("invalid input reached native"); } }) as NativeReviewCli;
96
+ for (const malformed of [null, [], 42]) await assert.rejects(__testing.executeReviewControllerOperation({ operation: "status", input: malformed }, process.cwd(), native), /input|JSON|object/i);
97
+ for (const malformed of [{ baseRef: "HEAD" }, { baseRef: "HEAD", committedOnly: false }, { unexpected: true }]) {
98
+ const result = await __testing.executeReviewControllerOperation({ operation: "status", input: malformed }, process.cwd(), native);
99
+ assert.equal(result.outcome, "native-status-input-invalid");
100
+ }
101
+ assert.equal(calls, 0);
102
+ });
80
103
  test("registered review schemas admit START/ASSESS objects and ordered capture objects", () => {
81
104
  for (const operation of ["start", "assess"]) {
82
105
  const input = operation === "start" ? { mode: "ordinary" } : { committedOnly: true, baseRef: "HEAD" };
@@ -106,6 +129,29 @@ test("answer-consent admits JSON object input and coerces it cleanly (#2375)", a
106
129
  assert.match(String(outcome.outcome), /consent-binding-stale/);
107
130
  });
108
131
 
132
+ test("abandon admits JSON object input and coerces it to a serialized string", () => {
133
+ const input = { actor: "loonbac", reason: "operator_disposition" };
134
+ const args = validate("gentle_review", { operation: "abandon", lineageId: "review-1", input });
135
+ assert.deepEqual(args.input, input);
136
+ assert.equal(__testing.parseReviewControllerParameters(args).input, JSON.stringify(input));
137
+ });
138
+
139
+ test("validated abandon objects reach the mocked native facade and still fail closed", async () => {
140
+ let statusCalls = 0;
141
+ let abandonCalls = 0;
142
+ const native = {
143
+ reviewStatus: async () => { statusCalls++; return { entries: [] }; },
144
+ abandon: async () => { abandonCalls++; },
145
+ } as unknown as NativeReviewCli;
146
+ const bad = await __testing.executeReviewControllerOperation(validate("gentle_review", { operation: "abandon", lineageId: "review-1", input: { actor: "loonbac", reason: "not-a-reason" } }), process.cwd(), native);
147
+ assert.equal(bad.outcome, "native-input-invalid");
148
+ assert.equal(statusCalls, 0);
149
+ const ineligible = await __testing.executeReviewControllerOperation(validate("gentle_review", { operation: "abandon", lineageId: "review-1", input: { actor: "loonbac", reason: "operator_disposition" } }), process.cwd(), native);
150
+ assert.equal(ineligible.outcome, "native-abandon-ineligible");
151
+ assert.equal(statusCalls, 1);
152
+ assert.equal(abandonCalls, 0);
153
+ });
154
+
109
155
  test("validated ASSESS objects reach the mocked native facade with parsed fields", async () => {
110
156
  const requests: unknown[] = [];
111
157
  const native = { assess: async (request: unknown) => { requests.push(request); throw new Error("mock assessment unavailable"); } } as unknown as NativeReviewCli;
@@ -126,9 +172,10 @@ test("serialized inputs remain byte-for-byte unchanged at validation and facade
126
172
  assert.equal(__testing.parseReviewCaptureParameters(validate("gentle_review_capture", { lineageId: "l", collectBinding })).collectBinding, collectBinding);
127
173
  });
128
174
 
129
- test("actual validation rejects arrays, null and coerced primitives rather than admitting native calls", async () => {
130
- for (const value of [[], 123, true, "123", "null", "[]"]) {
131
- for (const operation of ["start", "assess", "answer-consent", "inspect", "reset", "recover"]) {
175
+ test("validation and facade keep arrays, primitives and null fail-closed", async () => {
176
+ const operations = ["start", "assess", "answer-consent", "inspect", "reset", "recover"];
177
+ for (const value of [[], 123, true, "123", "[]"]) {
178
+ for (const operation of operations) {
132
179
  assert.throws(() => validate("gentle_review", { operation, input: value }), /Validation failed/);
133
180
  }
134
181
  assert.throws(() => validate("gentle_review_capture", { lineageId: "l", collectBinding: value }), /Validation failed/);
@@ -136,20 +183,28 @@ test("actual validation rejects arrays, null and coerced primitives rather than
136
183
  }
137
184
  let calls = 0;
138
185
  const native = new Proxy({}, { get() { return async () => { calls++; throw new Error("unexpected native execution"); }; } }) as NativeReviewCli;
139
- for (const value of [null, false]) {
140
- for (const operation of ["start", "assess", "answer-consent", "inspect", "reset", "recover"]) {
141
- const validated = validate("gentle_review", { operation, input: value });
142
- assert.equal(validated.input, null, "nullable shell preserves null instead of stripping it to omitted");
143
- await assert.rejects(__testing.executeReviewControllerOperation(validated, process.cwd(), native));
186
+ // SDK coercion admits the nullable shell, not native operation input.
187
+ for (const value of [null, false, "null"]) {
188
+ for (const operation of operations) {
189
+ if (value === "null" && !coercesStringNull) {
190
+ assert.throws(() => validate("gentle_review", { operation, input: value }), /Validation failed/);
191
+ } else {
192
+ const validated = validate("gentle_review", { operation, input: value });
193
+ assert.equal(validated.input, null, "nullable shell preserves null instead of stripping it to omitted");
194
+ await assert.rejects(__testing.executeReviewControllerOperation(validated, process.cwd(), native));
195
+ }
144
196
  }
145
197
  assert.throws(() => validate("gentle_review_capture", { lineageId: "l", collectBinding: value }), /Validation failed/);
146
198
  assert.throws(() => validate("gentle_review_capture_group", { lineageId: "l", collectBindings: [binding, value] }), /Validation failed/);
147
199
  }
200
+ for (const operation of operations) {
201
+ await assert.rejects(__testing.executeReviewControllerOperation({ operation, input: "null" }, process.cwd(), native), /input must be a JSON object/);
202
+ }
148
203
  assert.equal(calls, 0);
149
204
  });
150
205
 
151
206
  test("all other controller operations keep object input fail-closed at the facade boundary (#1698)", async () => {
152
- const operations = (tools.get("gentle_review").parameters.properties.operation.enum as string[]).filter((operation) => operation !== "start" && operation !== "assess" && operation !== "answer-consent" && operation !== "select-intended-untracked");
207
+ const operations = (tools.get("gentle_review").parameters.properties.operation.enum as string[]).filter((operation) => operation !== "start" && operation !== "assess" && operation !== "answer-consent" && operation !== "abandon" && operation !== "status" && operation !== "select-intended-untracked");
153
208
  let calls = 0;
154
209
  const native = new Proxy({}, { get() { return async () => { calls++; throw new Error("unexpected native execution"); }; } }) as NativeReviewCli;
155
210
  for (const operation of operations) {