gentle-pi 3.6.0 → 4.0.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 (320) hide show
  1. package/README.md +37 -6
  2. package/assets/agents/gentle-ai-explore.md +4 -4
  3. package/assets/agents/gentle-ai-verify.md +6 -4
  4. package/assets/agents/gentle-ai-worker.md +7 -9
  5. package/assets/orchestrator-delegation.md +40 -41
  6. package/assets/orchestrator-memory.md +1 -22
  7. package/assets/orchestrator-skills.md +1 -1
  8. package/assets/orchestrator.md +12 -24
  9. package/assets/support/strict-tdd-verify.md +4 -266
  10. package/assets/support/strict-tdd.md +8 -360
  11. package/bin/gentle-shell.mjs +254 -29
  12. package/docs/delegated-verification.md +26 -1
  13. package/docs/gentle-agents-activity.md +24 -0
  14. package/docs/gentle-shell.md +95 -30
  15. package/docs/native-authority-architecture.md +2 -2
  16. package/docs/prompt-history.md +280 -0
  17. package/docs/readme-reference.md +117 -235
  18. package/docs/telemetry.md +1 -1
  19. package/docs/yolo-mode.md +86 -0
  20. package/extensions/child-context.ts +26 -0
  21. package/extensions/child-safety.ts +23 -0
  22. package/extensions/gentle-agents.ts +509 -275
  23. package/extensions/gentle-ai.ts +781 -683
  24. package/extensions/gentle-shell.ts +1375 -88
  25. package/extensions/gentle-stats.ts +101 -0
  26. package/extensions/gentle-todo.ts +18 -7
  27. package/extensions/history/atomic-write.ts +38 -0
  28. package/extensions/history/hide-prompts.ts +183 -0
  29. package/extensions/history/index.ts +1419 -0
  30. package/extensions/history/load-shared-history.ts +39 -0
  31. package/extensions/history/selector-helpers.ts +538 -0
  32. package/extensions/history/session-scan.ts +233 -0
  33. package/extensions/history/store.ts +1119 -0
  34. package/extensions/nan-provider.ts +6 -0
  35. package/extensions/quiet-tools.ts +179 -87
  36. package/extensions/resume-hint.ts +60 -0
  37. package/extensions/skill-registry.ts +16 -12
  38. package/extensions/startup-banner.ts +60 -31
  39. package/lib/agent-assets.ts +604 -0
  40. package/lib/agent-profile-pin.ts +12 -0
  41. package/lib/agents-message-delivery.ts +181 -0
  42. package/lib/agents-protocol.ts +60 -0
  43. package/lib/agents-runner.ts +105 -98
  44. package/lib/agents-view.ts +26 -3
  45. package/lib/agents-widget.ts +16 -9
  46. package/lib/append-system-prompt.ts +21 -0
  47. package/lib/bounded-writer-admission.ts +147 -0
  48. package/lib/card-style-policy.ts +60 -0
  49. package/lib/child-context-files.ts +166 -0
  50. package/lib/codemode-renderer.ts +185 -0
  51. package/lib/command-palette-catalog.ts +3 -9
  52. package/lib/command-palette.ts +25 -14
  53. package/lib/destructive-command-guard.ts +144 -0
  54. package/lib/foreign-target-grants.ts +32 -0
  55. package/lib/gentle-ai-elapsed-store.ts +87 -0
  56. package/lib/gentle-ai-renderer.ts +196 -39
  57. package/lib/gentle-shell-launcher.ts +24 -13
  58. package/lib/gentle-shell-resume-hint.ts +176 -0
  59. package/lib/history-capture-policy.ts +95 -0
  60. package/lib/model-routing-authority.ts +5 -1
  61. package/lib/nan-provider.ts +227 -0
  62. package/lib/native-review-cli.ts +53 -108
  63. package/lib/odd-phase-inference.ts +231 -0
  64. package/lib/odd-phase.ts +141 -0
  65. package/lib/overlay-repaint.ts +26 -0
  66. package/lib/pi-tui-keys.ts +53 -0
  67. package/lib/review-candidate-view-owner.ts +67 -17
  68. package/lib/review-candidate-view.ts +112 -25
  69. package/lib/review-reminder-receipt.ts +48 -8
  70. package/lib/review-risk-assessment.ts +156 -11
  71. package/lib/review-sidebar-state.ts +223 -0
  72. package/lib/selection-engine.ts +515 -0
  73. package/lib/session-change-capture.ts +10 -1
  74. package/lib/session-messaging-grants.ts +135 -0
  75. package/lib/session-worktree-registry.ts +14 -2
  76. package/lib/shell-bar.ts +179 -24
  77. package/lib/shell-card.ts +287 -18
  78. package/lib/shell-changes-view.ts +2 -1
  79. package/lib/shell-prompt.ts +102 -6
  80. package/lib/shell-sidebar-layout.ts +78 -14
  81. package/lib/shell-sidebar.ts +15 -1
  82. package/lib/shell-todo.ts +23 -13
  83. package/lib/shell-usage-view.ts +9 -4
  84. package/lib/shell-usage.ts +66 -10
  85. package/lib/stats-collector.ts +381 -0
  86. package/lib/stats-view.ts +431 -0
  87. package/lib/theme-customization.ts +52 -0
  88. package/lib/vim-editor-adapter.ts +379 -0
  89. package/lib/vim-normal-engine.ts +154 -0
  90. package/lib/vim-operator-engine.ts +416 -0
  91. package/lib/vim-policy.ts +49 -0
  92. package/lib/vim-visual-engine.ts +107 -0
  93. package/lib/visual-customization-policy.ts +108 -0
  94. package/lib/visual-customize-view.ts +330 -0
  95. package/lib/visual-profiles.ts +228 -0
  96. package/lib/yolo-session-policy.ts +240 -0
  97. package/package.json +20 -8
  98. package/runtime/gentle-shell-launcher.mjs +23 -12
  99. package/runtime/gentle-shell-resume-hint.mjs +177 -0
  100. package/runtime/native-review-cli.mjs +53 -108
  101. package/runtime/review-risk-assessment.mjs +154 -9
  102. package/scripts/build-runtime-modules.mjs +1 -0
  103. package/scripts/gentle-ai-installer.mjs +14 -13
  104. package/scripts/mirror-odd-routing.mjs +2 -2
  105. package/scripts/run-test-suite.mjs +76 -0
  106. package/scripts/test-packed-runner.mjs +31 -14
  107. package/scripts/verify-package-files.mjs +11 -22
  108. package/skills/branch-pr/SKILL.md +24 -52
  109. package/skills/chained-pr/SKILL.md +31 -15
  110. package/skills/chained-pr/references/chaining-details.md +31 -20
  111. package/skills/gentle-ai/SKILL.md +9 -15
  112. package/skills/issue-creation/SKILL.md +8 -2
  113. package/skills/issue-creation/references/delegated-workflow-actions.md +19 -0
  114. package/skills/work-unit-commits/SKILL.md +4 -3
  115. package/tests/agent-profiles.test.ts +18 -0
  116. package/tests/agents-fake-child.ts +2 -2
  117. package/tests/agents-message-delivery.test.ts +106 -0
  118. package/tests/agents-protocol.test.ts +40 -0
  119. package/tests/agents-runner.test.ts +400 -89
  120. package/tests/agents-view-thread-identity.test.ts +169 -0
  121. package/tests/agents-view.test.ts +8 -2
  122. package/tests/agents-widget.test.ts +154 -15
  123. package/tests/append-system-prompt-route.test.ts +160 -0
  124. package/tests/append-system-prompt.test.ts +46 -0
  125. package/tests/artifact-language.test.ts +19 -213
  126. package/tests/ask-user-question.test.ts +44 -1
  127. package/tests/asset-installation-runtime.test.ts +5 -16
  128. package/tests/autonomous-guard.test.ts +69 -1
  129. package/tests/bounded-writer-admission.test.ts +95 -0
  130. package/tests/branch-pr-skill.test.ts +43 -0
  131. package/tests/card-style-policy.test.ts +55 -0
  132. package/tests/chained-pr-skill.test.ts +124 -0
  133. package/tests/child-context-files.test.ts +255 -0
  134. package/tests/child-safety.test.ts +82 -0
  135. package/tests/codemode-rendering.test.ts +491 -0
  136. package/tests/command-palette.test.ts +39 -3
  137. package/tests/delegated-key-learnings-contract.test.ts +0 -76
  138. package/tests/destructive-command-guard.test.ts +84 -0
  139. package/tests/devbinary/native-review-parity.devtest.ts +170 -2
  140. package/tests/devbinary/non-git-subagent-bootstrap.devtest.ts +193 -0
  141. package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-28T10-00-00-000Z_aaa.jsonl +7 -0
  142. package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-29T23-00-00-000Z_bbb.jsonl +3 -0
  143. package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-30T08-00-00-000Z_ddd.jsonl +2 -0
  144. package/tests/fixtures/stats/sessions/--work-alpha--/2026-09-30T09-00-00-000Z_eee.jsonl +3 -0
  145. package/tests/fixtures/stats/sessions/--work-alpha--/run-1/session.jsonl +2 -0
  146. package/tests/fixtures/stats/sessions/--work-beta--/2026-09-01T12-00-00-000Z_ccc.jsonl +2 -0
  147. package/tests/fixtures/stats/user-pi/sessions/--work-alpha--/2026-09-28T10-00-00-000Z_aaa.jsonl +2 -0
  148. package/tests/fixtures/stats/user-pi/sessions/--work-alpha--/2026-09-29T23-00-00-000Z_bbb.jsonl +4 -0
  149. package/tests/fixtures/stats/user-pi/sessions/--work-gamma--/2026-09-20T09-00-00-000Z_fff.jsonl +3 -0
  150. package/tests/foreign-target-grants.test.ts +58 -0
  151. package/tests/generic-agent-tools.test.ts +54 -0
  152. package/tests/gentle-agents.test.ts +1411 -256
  153. package/tests/gentle-ai-binary.test.ts +3 -3
  154. package/tests/gentle-ai-elapsed-store.test.ts +68 -0
  155. package/tests/gentle-ai-installer.test.ts +68 -54
  156. package/tests/gentle-ai-renderer.test.ts +487 -8
  157. package/tests/gentle-ai.test.ts +288 -65
  158. package/tests/gentle-card-text.ts +2 -1
  159. package/tests/gentle-shell-bin.test.ts +651 -114
  160. package/tests/gentle-shell-launcher.test.ts +99 -52
  161. package/tests/gentle-shell-resume-hint.test.ts +270 -0
  162. package/tests/gentle-shell.test.ts +3839 -187
  163. package/tests/gentle-stats.test.ts +152 -0
  164. package/tests/gentle-theme.test.ts +4 -1
  165. package/tests/gentle-todo.test.ts +80 -8
  166. package/tests/history-atomic-write.test.ts +57 -0
  167. package/tests/history-capture-policy.test.ts +102 -0
  168. package/tests/history-command-registration.test.ts +164 -0
  169. package/tests/history-dedupe-entries.test.ts +123 -0
  170. package/tests/history-delete-backfill.test.ts +190 -0
  171. package/tests/history-delete-confirm.test.ts +460 -0
  172. package/tests/history-dispatch.test.ts +180 -0
  173. package/tests/history-drain-hidden.test.ts +110 -0
  174. package/tests/history-drain-order.test.ts +98 -0
  175. package/tests/history-expanded-globals.test.ts +62 -0
  176. package/tests/history-gc.test.ts +832 -0
  177. package/tests/history-header-layout.test.ts +265 -0
  178. package/tests/history-hide-prompts.test.ts +275 -0
  179. package/tests/history-lazy-windowing.test.ts +508 -0
  180. package/tests/history-legacy-migrate-v2.test.ts +297 -0
  181. package/tests/history-load-shared-history.test.ts +53 -0
  182. package/tests/history-max-results-cap.test.ts +76 -0
  183. package/tests/history-multi-reader.test.ts +203 -0
  184. package/tests/history-off-path.test.ts +170 -0
  185. package/tests/history-openflow-integration.test.ts +173 -0
  186. package/tests/history-overlay-margin.test.ts +326 -0
  187. package/tests/history-preview-layout.test.ts +93 -0
  188. package/tests/history-registry.test.ts +143 -0
  189. package/tests/history-scope-delete.test.ts +411 -0
  190. package/tests/history-search-caret-keys.test.ts +142 -0
  191. package/tests/history-seed-bootstrap.test.ts +170 -0
  192. package/tests/history-seed-regen.test.ts +129 -0
  193. package/tests/history-selector-windowing.test.ts +94 -0
  194. package/tests/history-session-scan-directory.test.ts +87 -0
  195. package/tests/history-session-scan-extract.test.ts +583 -0
  196. package/tests/history-session-writer.test.ts +351 -0
  197. package/tests/history-store-paths.test.ts +79 -0
  198. package/tests/history-tombstone-exact.test.ts +139 -0
  199. package/tests/history-wheel-mouse.test.ts +242 -0
  200. package/tests/inprocess-reviewer.test.ts +29 -19
  201. package/tests/issue-creation-skill.test.ts +61 -0
  202. package/tests/model-routing-authority.test.ts +16 -0
  203. package/tests/nan-provider.test.ts +471 -0
  204. package/tests/native-review-capability-contract.test.ts +13 -1
  205. package/tests/native-review-cli.test.ts +6 -120
  206. package/tests/native-review-parity-runtime.test.ts +100 -3
  207. package/tests/odd-integration.test.ts +67 -0
  208. package/tests/odd-phase-inference.test.ts +213 -0
  209. package/tests/odd-phase-loader.test.ts +253 -0
  210. package/tests/odd-phase.test.ts +307 -0
  211. package/tests/odd-routing-canonical-ratchet.test.ts +11 -6
  212. package/tests/odd-routing-contract.test.ts +86 -35
  213. package/tests/orchestrator-budget.test.ts +14 -39
  214. package/tests/orchestrator-rdd-ownership.test.ts +3 -3
  215. package/tests/overlay-repaint.test.ts +74 -0
  216. package/tests/package-manifest.test.ts +252 -115
  217. package/tests/packed-runner-owned-path.test.ts +46 -0
  218. package/tests/persona-single-channel.test.ts +6 -6
  219. package/tests/provider-defect-handoff.test.ts +3 -11
  220. package/tests/quiet-bash-runtime.test.ts +76 -0
  221. package/tests/quiet-tool-rendering.test.ts +409 -184
  222. package/tests/rdd-aware-verification-contract.test.ts +76 -1
  223. package/tests/rdd-status-line.test.ts +9 -4
  224. package/tests/resume-hint-extension.test.ts +122 -0
  225. package/tests/review-agent-end-preflight.test.ts +176 -12
  226. package/tests/review-candidate-owner-retry.test.ts +22 -1
  227. package/tests/review-candidate-view.test.ts +298 -0
  228. package/tests/review-contract-prompt.test.ts +108 -43
  229. package/tests/review-controller-lock-status.test.ts +0 -1
  230. package/tests/review-controller-native-routing.test.ts +611 -5
  231. package/tests/review-controller-workspace-root.test.ts +163 -4
  232. package/tests/review-host-relay-routing.test.ts +338 -2
  233. package/tests/review-integration-v2-forward.test.ts +200 -0
  234. package/tests/review-ledger-contract.test.ts +10 -34
  235. package/tests/review-reminder-receipt.test.ts +47 -1
  236. package/tests/review-risk-assessment.test.ts +498 -6
  237. package/tests/review-sidebar-state.test.ts +402 -0
  238. package/tests/run-test-suite.test.ts +124 -0
  239. package/tests/runtime-harness.mjs +145 -786
  240. package/tests/runtime-metrics-children.test.ts +16 -23
  241. package/tests/selection-engine.test.ts +421 -0
  242. package/tests/session-change-capture.test.ts +12 -1
  243. package/tests/session-messaging-grants.test.ts +255 -0
  244. package/tests/session-worktree-registry.test.ts +77 -0
  245. package/tests/shell-bar.test.ts +382 -1
  246. package/tests/shell-card.test.ts +353 -1
  247. package/tests/shell-changes-view.test.ts +52 -0
  248. package/tests/shell-prompt.test.ts +94 -2
  249. package/tests/shell-sidebar-layout.test.ts +325 -21
  250. package/tests/shell-sidebar-scroll-benchmark.test.ts +255 -0
  251. package/tests/shell-todo.test.ts +87 -1
  252. package/tests/shell-usage-view.test.ts +27 -0
  253. package/tests/shell-usage.test.ts +73 -0
  254. package/tests/skill-registry.test.ts +50 -1
  255. package/tests/startup-banner.test.ts +130 -2
  256. package/tests/stats-collector.test.ts +195 -0
  257. package/tests/stats-view.test.ts +202 -0
  258. package/tests/telemetry-trigger.test.ts +81 -20
  259. package/tests/theme-customization.test.ts +72 -0
  260. package/tests/vim-editor-adapter-host-resolution.test.ts +37 -0
  261. package/tests/vim-editor-adapter.test.ts +804 -0
  262. package/tests/vim-normal-engine.test.ts +101 -0
  263. package/tests/vim-operator-engine.test.ts +215 -0
  264. package/tests/vim-policy.test.ts +19 -0
  265. package/tests/vim-visual-engine.test.ts +52 -0
  266. package/tests/visual-customization-policy.test.ts +110 -0
  267. package/tests/visual-customize-view.test.ts +418 -0
  268. package/tests/visual-profiles.test.ts +87 -0
  269. package/tests/yolo-customize.test.ts +256 -0
  270. package/tests/yolo-mode-runtime.test.ts +161 -0
  271. package/tests/yolo-mode.test.ts +261 -0
  272. package/tests/yolo-session-policy.test.ts +59 -0
  273. package/themes/Gentle.json +2 -1
  274. package/themes/Gentleman-Cute.json +2 -1
  275. package/themes/Gentleman-Sexy.json +2 -1
  276. package/assets/agents/sdd-apply.md +0 -159
  277. package/assets/agents/sdd-archive.md +0 -228
  278. package/assets/agents/sdd-design.md +0 -49
  279. package/assets/agents/sdd-explore.md +0 -48
  280. package/assets/agents/sdd-init.md +0 -56
  281. package/assets/agents/sdd-onboard.md +0 -52
  282. package/assets/agents/sdd-proposal.md +0 -64
  283. package/assets/agents/sdd-remediate.md +0 -37
  284. package/assets/agents/sdd-research.md +0 -49
  285. package/assets/agents/sdd-spec.md +0 -192
  286. package/assets/agents/sdd-status.md +0 -54
  287. package/assets/agents/sdd-tasks.md +0 -108
  288. package/assets/agents/sdd-verify.md +0 -124
  289. package/assets/chains/sdd-full.chain.md +0 -83
  290. package/assets/chains/sdd-plan.chain.md +0 -56
  291. package/assets/chains/sdd-verify.chain.md +0 -43
  292. package/assets/sdd-orchestrator-workflow.md +0 -319
  293. package/assets/support/sdd-status-contract.md +0 -77
  294. package/docs/assets/diagrams/sdd-cycle.svg +0 -14
  295. package/extensions/sdd-init.ts +0 -816
  296. package/lib/openspec-deltas.ts +0 -156
  297. package/lib/sdd-preflight.ts +0 -1066
  298. package/lib/sdd-research-capabilities.ts +0 -94
  299. package/lib/sdd-status.ts +0 -26
  300. package/tests/fixtures/legacy/sdd-research-v2.5.0.md +0 -54
  301. package/tests/fixtures/native-review-cli/v2.1.3/bind-sdd.json +0 -25
  302. package/tests/fixtures/v0.10.7/assets/agents/sdd-apply.md +0 -132
  303. package/tests/openspec-deltas.test.ts +0 -209
  304. package/tests/sdd-agent-tools.test.ts +0 -156
  305. package/tests/sdd-archive-replay.test.ts +0 -82
  306. package/tests/sdd-classical-continuation.test.ts +0 -74
  307. package/tests/sdd-execution-routing-contract.test.ts +0 -44
  308. package/tests/sdd-managed-runtime-settlement.test.ts +0 -155
  309. package/tests/sdd-native-managed-uptake.test.ts +0 -243
  310. package/tests/sdd-no-attempts-contract.test.ts +0 -15
  311. package/tests/sdd-odd-integration.test.ts +0 -33
  312. package/tests/sdd-optional-research.test.ts +0 -124
  313. package/tests/sdd-planning-routing-contract.test.ts +0 -45
  314. package/tests/sdd-preflight-rpc-input.test.ts +0 -125
  315. package/tests/sdd-preflight.test.ts +0 -541
  316. package/tests/sdd-research-capabilities.test.ts +0 -114
  317. package/tests/sdd-research-live.test.ts +0 -241
  318. package/tests/sdd-selection-transport.test.ts +0 -653
  319. package/tests/sdd-status.test.ts +0 -9
  320. package/tests/sdd-task-truth.test.ts +0 -43
@@ -1,4 +1,6 @@
1
1
  import assert from "node:assert/strict";
2
+ import { execFileSync } from "node:child_process";
3
+ import { realpathSync } from "node:fs";
2
4
  import test from "node:test";
3
5
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
4
6
  import { createGentleAiExtension, __testing } from "../extensions/gentle-ai.ts";
@@ -26,6 +28,7 @@ import {
26
28
  type WriterProfile,
27
29
  type NativeReviewOutcome,
28
30
  } from "../lib/review-risk-assessment.ts";
31
+ import { consumeReviewMutation, pendingReviewMutation, recordReviewMutation } from "../lib/review-reminder-receipt.ts";
29
32
 
30
33
  // ---------------------------------------------------------------------------
31
34
  // gentle-pi#662: decoder for the native `gentle-ai review assess` envelope
@@ -80,13 +83,225 @@ test("decodeReviewAssessmentV1 rejects a malformed shape", () => {
80
83
  assert.throws(() => decodeReviewAssessmentV1(null), TypeError);
81
84
  assert.throws(() => decodeReviewAssessmentV1("gentle-ai.review-assessment/v1"), TypeError);
82
85
  assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ reasons: "none" })), TypeError);
83
- assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ reasons: [{ code: "x" }] })), TypeError);
84
86
  assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ changed_paths: -1 })), TypeError);
85
87
  assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ changed_lines: 1.5 })), TypeError);
86
88
  assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ candidate: { kind: "unknown-kind" } })), TypeError);
87
89
  assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ candidate: { kind: "current-changes", base_ref: "" } })), TypeError);
88
90
  });
89
91
 
92
+ // ---------------------------------------------------------------------------
93
+ // gentle-pi#1175: the native v2 `assess.schema.json` requires only `code` on a
94
+ // reason, and adds `candidate.consumed`, `review_due`, `review_due_reason`,
95
+ // and `next_transition`. Older binaries (for example gentle-ai v3.7.0)
96
+ // predate those fields; they must decode without invented values.
97
+ // ---------------------------------------------------------------------------
98
+
99
+ function nextTransition(overrides: Record<string, unknown> = {}): Record<string, unknown> {
100
+ return {
101
+ operation: "review.status",
102
+ command: "gentle-ai",
103
+ arguments: [
104
+ { name: "review", value: "" },
105
+ { name: "--cwd", value: "/repo" },
106
+ { name: "--next-transition", value: "start", token: "opaque-token" },
107
+ ],
108
+ ...overrides,
109
+ };
110
+ }
111
+
112
+ function newEnvelope(overrides: Record<string, unknown> = {}): Record<string, unknown> {
113
+ return validEnvelope({
114
+ risk: "high",
115
+ candidate: { kind: "current-changes", consumed: false },
116
+ review_due: true,
117
+ review_due_reason: "high_risk",
118
+ next_transition: nextTransition(),
119
+ ...overrides,
120
+ });
121
+ }
122
+
123
+ test("decodeReviewAssessmentV1 accepts a reason carrying only code and never synthesizes path or detail", () => {
124
+ const decoded = decodeReviewAssessmentV1(validEnvelope({ reasons: [{ code: "x" }, { code: "y", path: "a.ts" }, { code: "z", detail: "why" }] }));
125
+ assert.deepEqual(decoded.reasons, [{ code: "x" }, { code: "y", path: "a.ts" }, { code: "z", detail: "why" }]);
126
+ assert.equal(Object.hasOwn(decoded.reasons[0], "path"), false);
127
+ assert.equal(Object.hasOwn(decoded.reasons[0], "detail"), false);
128
+ });
129
+
130
+ test("decodeReviewAssessmentV1 rejects a reason with a missing code or an empty/non-string path or detail", () => {
131
+ for (const reason of [
132
+ {},
133
+ { code: "" },
134
+ { code: 1 },
135
+ { path: "a.ts", detail: "why" },
136
+ { code: "x", path: "" },
137
+ { code: "x", detail: "" },
138
+ { code: "x", path: 1 },
139
+ { code: "x", detail: null },
140
+ "x",
141
+ ]) {
142
+ assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ reasons: [reason] })), TypeError, `reason ${JSON.stringify(reason)} must be rejected`);
143
+ }
144
+ });
145
+
146
+ test("decodeReviewAssessmentV1 accepts an older envelope without consumed/review_due/review_due_reason and invents none of them", () => {
147
+ const decoded = decodeReviewAssessmentV1(validEnvelope());
148
+ for (const key of ["reviewDue", "reviewDueReason", "nextTransition"]) {
149
+ assert.equal(Object.hasOwn(decoded, key), false, `${key} must stay absent`);
150
+ }
151
+ assert.equal(Object.hasOwn(decoded.candidate, "consumed"), false, "consumed must stay absent, never defaulted");
152
+ });
153
+
154
+ test("decodeReviewAssessmentV1 decodes consumed, review_due, review_due_reason, and next_transition verbatim", () => {
155
+ const transition = nextTransition();
156
+ const decoded = decodeReviewAssessmentV1(newEnvelope({ next_transition: transition }));
157
+ assert.deepEqual(decoded.candidate, { kind: "current-changes", baseRef: undefined, consumed: false });
158
+ assert.equal(decoded.reviewDue, true);
159
+ assert.equal(decoded.reviewDueReason, "high_risk");
160
+ assert.deepEqual(decoded.nextTransition, nextTransition());
161
+ assert.equal(JSON.stringify(decoded.nextTransition), JSON.stringify(nextTransition()), "next_transition must keep its native key and argument order");
162
+
163
+ const consumed = decodeReviewAssessmentV1(newEnvelope({ candidate: { kind: "base-diff", base_ref: "origin/main", consumed: true }, review_due: false, review_due_reason: "already_reviewed", next_transition: undefined }));
164
+ assert.deepEqual(consumed.candidate, { kind: "base-diff", baseRef: "origin/main", consumed: true });
165
+ assert.equal(consumed.reviewDue, false);
166
+ assert.equal(consumed.reviewDueReason, "already_reviewed");
167
+ assert.equal(Object.hasOwn(consumed, "nextTransition"), false);
168
+
169
+ for (const pair of CONSISTENT_REVIEW_DUE_PAIRS) {
170
+ assert.equal(decodeReviewAssessmentV1(consistentEnvelope(pair)).reviewDueReason, pair.reason);
171
+ }
172
+
173
+ const noToken = decodeReviewAssessmentV1(newEnvelope({ next_transition: nextTransition({ arguments: [] }) }));
174
+ assert.deepEqual(noToken.nextTransition, nextTransition({ arguments: [] }));
175
+ });
176
+
177
+ test("decodeReviewAssessmentV1 rejects malformed consumed, review_due, and review_due_reason values", () => {
178
+ for (const consumed of ["true", 0, null]) {
179
+ assert.throws(() => decodeReviewAssessmentV1(newEnvelope({ candidate: { kind: "current-changes", consumed } })), TypeError, `consumed ${JSON.stringify(consumed)} must be rejected`);
180
+ }
181
+ for (const reviewDueReason of ["low_risk", "", 1, null]) {
182
+ assert.throws(() => decodeReviewAssessmentV1(newEnvelope({ review_due_reason: reviewDueReason })), TypeError, `review_due_reason ${JSON.stringify(reviewDueReason)} must be rejected`);
183
+ }
184
+ for (const reviewDue of ["true", 1, null]) {
185
+ assert.throws(() => decodeReviewAssessmentV1(newEnvelope({ review_due: reviewDue })), TypeError, `review_due ${JSON.stringify(reviewDue)} must be rejected`);
186
+ }
187
+ });
188
+
189
+ // gentle-pi#1175 (T2): the native schema fixes review_due by reason
190
+ // (true for high_risk and slice_budget_reached, false for passive,
191
+ // under_budget, and already_reviewed), and already_reviewed is reported
192
+ // exactly when the candidate is consumed. A contradictory envelope can never
193
+ // be trusted as closure evidence, so it fails decoding.
194
+ interface ReviewDuePair {
195
+ reason: string;
196
+ due: boolean;
197
+ consumed: boolean;
198
+ }
199
+
200
+ const CONSISTENT_REVIEW_DUE_PAIRS: readonly ReviewDuePair[] = [
201
+ { reason: "high_risk", due: true, consumed: false },
202
+ { reason: "slice_budget_reached", due: true, consumed: false },
203
+ { reason: "passive", due: false, consumed: false },
204
+ { reason: "under_budget", due: false, consumed: false },
205
+ { reason: "already_reviewed", due: false, consumed: true },
206
+ ];
207
+
208
+ function consistentEnvelope(pair: ReviewDuePair): Record<string, unknown> {
209
+ return newEnvelope({
210
+ candidate: { kind: "current-changes", consumed: pair.consumed },
211
+ review_due: pair.due,
212
+ review_due_reason: pair.reason,
213
+ next_transition: pair.due ? nextTransition() : undefined,
214
+ });
215
+ }
216
+
217
+ test("decodeReviewAssessmentV1 accepts every consistent review_due/review_due_reason/consumed combination", () => {
218
+ for (const pair of CONSISTENT_REVIEW_DUE_PAIRS) {
219
+ const decoded = decodeReviewAssessmentV1(consistentEnvelope(pair));
220
+ assert.equal(decoded.reviewDue, pair.due, pair.reason);
221
+ assert.equal(decoded.reviewDueReason, pair.reason);
222
+ assert.equal(decoded.candidate.consumed, pair.consumed, pair.reason);
223
+ }
224
+ // Without next_transition the due pairs stay consistent too.
225
+ assert.equal(decodeReviewAssessmentV1(newEnvelope({ next_transition: undefined })).reviewDueReason, "high_risk");
226
+ });
227
+
228
+ test("decodeReviewAssessmentV1 rejects a review_due boolean that contradicts review_due_reason", () => {
229
+ for (const pair of CONSISTENT_REVIEW_DUE_PAIRS) {
230
+ const contradictory = newEnvelope({
231
+ candidate: { kind: "current-changes", consumed: pair.consumed },
232
+ review_due: !pair.due,
233
+ review_due_reason: pair.reason,
234
+ next_transition: undefined,
235
+ });
236
+ assert.throws(() => decodeReviewAssessmentV1(contradictory), TypeError, `review_due ${!pair.due} with ${pair.reason} must be rejected`);
237
+ }
238
+ });
239
+
240
+ test("decodeReviewAssessmentV1 rejects already_reviewed unless the candidate is consumed", () => {
241
+ for (const candidate of [{ kind: "current-changes", consumed: false }, { kind: "current-changes" }]) {
242
+ assert.throws(
243
+ () => decodeReviewAssessmentV1(newEnvelope({ candidate, review_due: false, review_due_reason: "already_reviewed", next_transition: undefined })),
244
+ TypeError,
245
+ `already_reviewed with ${JSON.stringify(candidate)} must be rejected`,
246
+ );
247
+ }
248
+ });
249
+
250
+ test("decodeReviewAssessmentV1 rejects a consumed candidate reported with any reason other than already_reviewed", () => {
251
+ for (const pair of CONSISTENT_REVIEW_DUE_PAIRS.filter((entry) => entry.reason !== "already_reviewed")) {
252
+ assert.throws(
253
+ () => decodeReviewAssessmentV1(newEnvelope({
254
+ candidate: { kind: "current-changes", consumed: true },
255
+ review_due: pair.due,
256
+ review_due_reason: pair.reason,
257
+ next_transition: pair.due ? nextTransition() : undefined,
258
+ })),
259
+ TypeError,
260
+ `consumed with ${pair.reason} must be rejected`,
261
+ );
262
+ }
263
+ });
264
+
265
+ test("decodeReviewAssessmentV1 still accepts an older envelope without the review_due pair", () => {
266
+ assert.equal(decodeReviewAssessmentV1(validEnvelope()).risk, "medium");
267
+ assert.equal(Object.hasOwn(decodeReviewAssessmentV1(validEnvelope({ risk: "passive", reasons: [] })), "reviewDue"), false);
268
+ });
269
+
270
+ test("decodeReviewAssessmentV1 rejects only one of the review_due/review_due_reason pair", () => {
271
+ assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ review_due: false })), TypeError);
272
+ assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ review_due_reason: "passive" })), TypeError);
273
+ });
274
+
275
+ test("decodeReviewAssessmentV1 rejects a malformed next_transition or one not backed by review_due true", () => {
276
+ const malformed: Record<string, unknown>[] = [
277
+ nextTransition({ operation: "review.start" }),
278
+ nextTransition({ extra: true }),
279
+ nextTransition({ command: undefined }),
280
+ nextTransition({ command: "" }),
281
+ nextTransition({ arguments: undefined }),
282
+ nextTransition({ arguments: "--cwd" }),
283
+ nextTransition({ arguments: [{ name: "--cwd", value: "/repo", token: "" }] }),
284
+ nextTransition({ arguments: [{ name: "", value: "/repo" }] }),
285
+ nextTransition({ arguments: [{ name: "--cwd" }] }),
286
+ nextTransition({ arguments: [{ name: "--cwd", value: 1 }] }),
287
+ nextTransition({ arguments: [{ name: "--cwd", value: "/repo", extra: "x" }] }),
288
+ nextTransition({ arguments: [null] }),
289
+ ];
290
+ for (const transition of malformed) {
291
+ assert.throws(() => decodeReviewAssessmentV1(newEnvelope({ next_transition: transition })), TypeError, `next_transition ${JSON.stringify(transition)} must be rejected`);
292
+ }
293
+ assert.throws(() => decodeReviewAssessmentV1(newEnvelope({ next_transition: null })), TypeError);
294
+ assert.throws(() => decodeReviewAssessmentV1(newEnvelope({ review_due: false, review_due_reason: "passive" })), TypeError, "next_transition requires review_due true");
295
+ assert.throws(() => decodeReviewAssessmentV1(validEnvelope({ next_transition: nextTransition() })), TypeError, "next_transition requires review_due true");
296
+ });
297
+
298
+ test("decodeReviewAssessmentV1 ignores unknown top-level fields and never projects them", () => {
299
+ const decoded = decodeReviewAssessmentV1(newEnvelope({ future_field: { anything: true } }));
300
+ assert.equal(Object.hasOwn(decoded, "future_field"), false);
301
+ assert.equal(Object.hasOwn(decoded, "futureField"), false);
302
+ assert.equal(decoded.reviewDue, true);
303
+ });
304
+
90
305
  // ---------------------------------------------------------------------------
91
306
  // verificationPlan: every (rdd, risk, profile) combination from gentle-pi#662.
92
307
  // ---------------------------------------------------------------------------
@@ -501,7 +716,7 @@ function assessOnNativeCli(currentTargetIdentity: () => string): Partial<NativeR
501
716
  };
502
717
  }
503
718
 
504
- test("gentle_review assess: derivation is bound to the exact candidate recorded, closed can only ever be passed explicitly (gentle-pi#668 correction)", async (t) => {
719
+ test("gentle_review assess: derivation is bound to the exact candidate recorded, and a caller-declared closed is never trusted without native evidence (gentle-pi#668 correction, gentle-pi#1175)", async (t) => {
505
720
  t.after(() => __testing.clearNativeReviewOutcomeMemoForTesting());
506
721
  __testing.clearNativeReviewOutcomeMemoForTesting();
507
722
  let current = "target-a";
@@ -529,12 +744,240 @@ test("gentle_review assess: derivation is bound to the exact candidate recorded,
529
744
  assert.equal(forB.outcome_source, "unknown");
530
745
  assert.equal(forB.plan.independentVerifier, true);
531
746
 
532
- // Explicit input always wins, and is the only way to reach "closed".
747
+ // gentle-pi#1175: a caller-declared closed is only a claim. This older
748
+ // assessment carries no candidate.consumed, so it fails closed to unknown.
533
749
  const closed = (await tool.execute("call-14", { operation: "assess", input: JSON.stringify({ nativeReviewOutcome: "closed" }) }, undefined, undefined, ctx)).details as { nativeReviewOutcome: string; outcome_source: string; plan: { independentVerifier: boolean; writerSelfVerification: boolean } };
534
- assert.equal(closed.nativeReviewOutcome, "closed");
535
- assert.equal(closed.outcome_source, "explicit");
750
+ assert.equal(closed.nativeReviewOutcome, "unknown");
751
+ assert.equal(closed.outcome_source, "unknown");
536
752
  assert.equal(closed.plan.writerSelfVerification, true);
537
- assert.equal(closed.plan.independentVerifier, false, "an explicit closed outcome restores the on-path: no separate verifier");
753
+ assert.equal(closed.plan.independentVerifier, true, "an uncorroborated closed claim must keep the separate verifier");
754
+ });
755
+
756
+ // ---------------------------------------------------------------------------
757
+ // gentle-pi#1175 (T2): closure comes only from the exact native evidence of
758
+ // THIS assess call -- candidate.consumed === true, which native writes only
759
+ // inside the approved-acknowledgement burn for that exact target identity.
760
+ // ---------------------------------------------------------------------------
761
+
762
+ interface ClosureCliOptions {
763
+ rdd?: "on" | "off";
764
+ risk?: "passive" | "medium" | "high";
765
+ /** undefined models an older binary that reports no consumed/review_due. */
766
+ consumed?: boolean;
767
+ targetIdentity?: () => string;
768
+ unassessable?: boolean;
769
+ }
770
+
771
+ function closureCli(options: ClosureCliOptions): Partial<NativeReviewCli> {
772
+ const rdd = options.rdd ?? "on";
773
+ const risk = options.risk ?? "high";
774
+ const raw = options.consumed === undefined
775
+ ? validEnvelope({ risk, reasons: [] })
776
+ : validEnvelope({
777
+ risk,
778
+ reasons: [],
779
+ candidate: { kind: "current-changes", consumed: options.consumed },
780
+ review_due: options.consumed ? false : risk === "high",
781
+ review_due_reason: options.consumed ? "already_reviewed" : risk === "high" ? "high_risk" : risk === "passive" ? "passive" : "under_budget",
782
+ });
783
+ return {
784
+ reviewMode: async () => ({ operation: "status", scope: "clone", status: { global: rdd, cloneLocal: "", effective: rdd, source: NATIVE_REVIEW_MODE_SOURCE.GLOBAL } }),
785
+ assess: async () => {
786
+ if (options.unassessable) throw new Error("native process failed");
787
+ return decodeReviewAssessmentV1(raw);
788
+ },
789
+ ...(options.targetIdentity === undefined ? {} : {
790
+ targetStatus: (async () => ({ applicability: "current_target", targetIdentity: options.targetIdentity!() })) as unknown as NativeReviewCli["targetStatus"],
791
+ }),
792
+ };
793
+ }
794
+
795
+ interface AssessDetails {
796
+ risk: string;
797
+ nativeReviewOutcome: string;
798
+ outcome_source: string;
799
+ writerProfile: string;
800
+ writerProfileSource: string;
801
+ plan: { writerSelfVerification: boolean; independentVerifier: boolean; structuralReadbackOnly: boolean };
802
+ }
803
+
804
+ async function assessWith(cli: Partial<NativeReviewCli>, input?: Record<string, unknown>, context: ExtensionContext = ctx): Promise<AssessDetails> {
805
+ const params = input === undefined ? { operation: "assess" } : { operation: "assess", input: JSON.stringify(input) };
806
+ return (await reviewControllerTool(cli).execute("closure", params, undefined, undefined, context)).details as AssessDetails;
807
+ }
808
+
809
+ test("gentle_review assess: native consumed true derives closed for this candidate", async () => {
810
+ const details = await assessWith(closureCli({ consumed: true }));
811
+ assert.equal(details.nativeReviewOutcome, "closed");
812
+ assert.equal(details.outcome_source, "derived");
813
+ assert.equal(details.plan.writerSelfVerification, true);
814
+ assert.equal(details.plan.independentVerifier, false, "a natively closed candidate restores the RDD on-path");
815
+ });
816
+
817
+ test("gentle_review assess: a caller-declared closed without native consumed evidence fails closed to unknown", async () => {
818
+ for (const consumed of [false, undefined]) {
819
+ const details = await assessWith(closureCli({ consumed }), { nativeReviewOutcome: "closed" });
820
+ assert.equal(details.nativeReviewOutcome, "unknown", `consumed ${String(consumed)}`);
821
+ assert.equal(details.outcome_source, "unknown");
822
+ assert.equal(details.plan.independentVerifier, true);
823
+ }
824
+ });
825
+
826
+ test("gentle_review assess: a caller-declared closed corroborated by native consumed stays closed", async () => {
827
+ const details = await assessWith(closureCli({ consumed: true }), { nativeReviewOutcome: "closed" });
828
+ assert.equal(details.nativeReviewOutcome, "closed");
829
+ assert.equal(details.outcome_source, "derived", "closure is attributed to the native evidence, not to the caller's claim");
830
+ assert.equal(details.plan.independentVerifier, false);
831
+ });
832
+
833
+ test("gentle_review assess: explicit declined, unavailable, or unknown beats native consumed (only ever raises the bar)", async () => {
834
+ for (const outcome of ["declined", "unavailable", "unknown"]) {
835
+ const details = await assessWith(closureCli({ consumed: true }), { nativeReviewOutcome: outcome });
836
+ assert.equal(details.nativeReviewOutcome, outcome);
837
+ assert.equal(details.outcome_source, "explicit");
838
+ assert.equal(details.plan.independentVerifier, true, `${outcome} must keep the risk-gated verifier`);
839
+ }
840
+ });
841
+
842
+ test("gentle_review assess: a recorded decline for the same candidate beats native consumed and a caller-declared closed", async (t) => {
843
+ t.after(() => __testing.clearNativeReviewOutcomeMemoForTesting());
844
+ __testing.clearNativeReviewOutcomeMemoForTesting();
845
+ __testing.recordNativeReviewOutcome(ctx.cwd, "target-a", "declined");
846
+ const cli = closureCli({ consumed: true, targetIdentity: () => "target-a" });
847
+ for (const input of [undefined, { nativeReviewOutcome: "closed" }]) {
848
+ const details = await assessWith(cli, input);
849
+ assert.equal(details.nativeReviewOutcome, "declined", JSON.stringify(input));
850
+ assert.equal(details.outcome_source, "derived");
851
+ assert.equal(details.plan.independentVerifier, true);
852
+ }
853
+ });
854
+
855
+ test("gentle_review assess: a different candidate never inherits closure or a recorded decline", async (t) => {
856
+ t.after(() => __testing.clearNativeReviewOutcomeMemoForTesting());
857
+ __testing.clearNativeReviewOutcomeMemoForTesting();
858
+ __testing.recordNativeReviewOutcome(ctx.cwd, "target-a", "declined");
859
+ // Candidate B was natively closed: A's recorded decline must not leak into it.
860
+ const closedB = await assessWith(closureCli({ consumed: true, targetIdentity: () => "target-b" }));
861
+ assert.equal(closedB.nativeReviewOutcome, "closed");
862
+ // Candidate C follows B, but its own assessment is not consumed: B's closure never carries over.
863
+ const openC = await assessWith(closureCli({ consumed: false, targetIdentity: () => "target-c" }));
864
+ assert.equal(openC.nativeReviewOutcome, "unknown");
865
+ assert.equal(openC.outcome_source, "unknown");
866
+ assert.equal(openC.plan.independentVerifier, true);
867
+ });
868
+
869
+ test("gentle_review assess: an unassessable candidate is never closed", async () => {
870
+ for (const input of [undefined, { nativeReviewOutcome: "closed" }]) {
871
+ const details = await assessWith(closureCli({ unassessable: true }), input);
872
+ assert.equal(details.risk, VERIFICATION_TIER.UNASSESSABLE);
873
+ assert.equal(details.nativeReviewOutcome, "unknown");
874
+ assert.equal(details.plan.independentVerifier, true);
875
+ }
876
+ });
877
+
878
+ test("gentle_review assess: derived closure only changes the RDD on-path; RDD off plans are unchanged", async () => {
879
+ for (const risk of ["passive", "medium", "high"] as const) {
880
+ for (const consumed of [true, false]) {
881
+ const off = await assessWith(closureCli({ rdd: "off", risk, consumed }), { writerModelId: "claude-sonnet-5", writerEffort: "high" });
882
+ const expectedOff = verificationPlan({ rddLine: RDD_LINE.OFF, risk, writerProfile: WRITER_PROFILE.LARGE });
883
+ assert.deepEqual(off.plan, { ...expectedOff }, `off ${risk} consumed ${consumed}`);
884
+ const on = await assessWith(closureCli({ rdd: "on", risk, consumed }), { writerModelId: "claude-sonnet-5", writerEffort: "high" });
885
+ const expectedOn = verificationPlan({ rddLine: RDD_LINE.ON, risk, writerProfile: WRITER_PROFILE.LARGE, nativeReviewOutcome: consumed ? NATIVE_REVIEW_OUTCOME.CLOSED : NATIVE_REVIEW_OUTCOME.UNKNOWN });
886
+ assert.deepEqual(on.plan, { ...expectedOn }, `on ${risk} consumed ${consumed}`);
887
+ }
888
+ }
889
+ });
890
+
891
+ // ---------------------------------------------------------------------------
892
+ // gentle-pi#1175 (T2): the writer profile comes from the runtime-recorded
893
+ // mutation receipts for this root; caller input is used only when no pending
894
+ // runtime receipt exists.
895
+ // ---------------------------------------------------------------------------
896
+
897
+ interface RuntimeProfileFields {
898
+ writerModelId?: string;
899
+ writerEffort?: string;
900
+ }
901
+
902
+ function receiptContext(): { context: ExtensionContext; record(evidence: RuntimeProfileFields & { toolCallId: string }): void; consumeAll(): void } {
903
+ const entries: Array<{ type: string; customType: string; data: unknown }> = [];
904
+ const session = { getSessionId: () => "assess-session", getBranch: () => entries, getCwd: () => process.cwd() };
905
+ const host = { appendEntry: (customType: string, data: unknown) => { entries.push({ type: "custom", customType, data }); } };
906
+ const root = workspaceRoot();
907
+ return {
908
+ context: { cwd: process.cwd(), sessionManager: session } as unknown as ExtensionContext,
909
+ record: (evidence) => recordReviewMutation(host, session, root, { source: "direct", toolName: "write", ...evidence }),
910
+ consumeAll: () => consumeReviewMutation(host, session, root, pendingReviewMutation(session, root), "acknowledged", "target"),
911
+ };
912
+ }
913
+
914
+ function workspaceRoot(): string {
915
+ return realpathSync(execFileSync("git", ["rev-parse", "--show-toplevel"], { cwd: process.cwd(), encoding: "utf8" }).trim());
916
+ }
917
+
918
+ const mediumOffCli = (): Partial<NativeReviewCli> => closureCli({ rdd: "off", risk: "medium" });
919
+
920
+ test("gentle_review assess: the runtime writer profile wins over contradicting caller input", async () => {
921
+ const small = receiptContext();
922
+ small.record({ toolCallId: "w1", writerModelId: "openai/gpt-5-mini", writerEffort: "high" });
923
+ const claimedLarge = await assessWith(mediumOffCli(), { writerModelId: "claude-sonnet-5", writerEffort: "high" }, small.context);
924
+ assert.equal(claimedLarge.writerProfile, "small");
925
+ assert.equal(claimedLarge.writerProfileSource, "runtime");
926
+ assert.equal(claimedLarge.plan.independentVerifier, true, "a caller can never talk a runtime mini writer into a large profile");
927
+
928
+ const large = receiptContext();
929
+ large.record({ toolCallId: "w1", writerModelId: "google/gemini-2.5-pro", writerEffort: "high" });
930
+ const claimedSmall = await assessWith(mediumOffCli(), { writerEffort: "low" }, large.context);
931
+ assert.equal(claimedSmall.writerProfile, "large", "gemini must never count as mini");
932
+ assert.equal(claimedSmall.writerProfileSource, "runtime");
933
+ assert.equal(claimedSmall.plan.independentVerifier, false);
934
+ });
935
+
936
+ test("gentle_review assess: any small or unknown pending runtime writer makes the profile small", async () => {
937
+ const cases: Array<{ name: string; receipts: RuntimeProfileFields[] }> = [
938
+ { name: "missing model id", receipts: [{ writerModelId: "claude-sonnet-5", writerEffort: "high" }, { writerEffort: "high" }] },
939
+ { name: "no profile at all", receipts: [{}] },
940
+ { name: "gpt-5-mini", receipts: [{ writerModelId: "claude-sonnet-5", writerEffort: "high" }, { writerModelId: "gpt-5-mini", writerEffort: "high" }] },
941
+ { name: "low effort", receipts: [{ writerModelId: "claude-sonnet-5", writerEffort: "low" }] },
942
+ ];
943
+ for (const entry of cases) {
944
+ const fixture = receiptContext();
945
+ entry.receipts.forEach((receipt, index) => fixture.record({ toolCallId: `w${index}`, ...receipt }));
946
+ const details = await assessWith(mediumOffCli(), { writerModelId: "claude-sonnet-5", writerEffort: "high" }, fixture.context);
947
+ assert.equal(details.writerProfile, "small", entry.name);
948
+ assert.equal(details.writerProfileSource, "runtime", entry.name);
949
+ assert.equal(details.plan.independentVerifier, true, entry.name);
950
+ }
951
+
952
+ const known = receiptContext();
953
+ known.record({ toolCallId: "w1", writerModelId: "google/gemini-2.5-pro", writerEffort: "high" });
954
+ known.record({ toolCallId: "w2", writerModelId: "anthropic/claude-sonnet-5", writerEffort: "medium" });
955
+ const details = await assessWith(mediumOffCli(), undefined, known.context);
956
+ assert.equal(details.writerProfile, "large");
957
+ assert.equal(details.writerProfileSource, "runtime");
958
+ });
959
+
960
+ test("gentle_review assess: without pending runtime receipts the caller input path is unchanged", async () => {
961
+ const fixture = receiptContext();
962
+ fixture.record({ toolCallId: "w1", writerModelId: "gpt-5-mini" });
963
+ fixture.consumeAll();
964
+ const caller = await assessWith(mediumOffCli(), { writerModelId: "claude-sonnet-5", writerEffort: "high" }, fixture.context);
965
+ assert.equal(caller.writerProfile, "large", "a consumed runtime receipt is no longer evidence for the next candidate");
966
+ assert.equal(caller.writerProfileSource, "caller");
967
+
968
+ const callerSmall = await assessWith(mediumOffCli(), { writerEffort: "low" }, fixture.context);
969
+ assert.equal(callerSmall.writerProfile, "small");
970
+ assert.equal(callerSmall.writerProfileSource, "caller");
971
+
972
+ const fallback = await assessWith(mediumOffCli(), undefined, fixture.context);
973
+ assert.equal(fallback.writerProfile, "small");
974
+ assert.equal(fallback.writerProfileSource, "fallback");
975
+ assert.equal(fallback.plan.independentVerifier, true);
976
+
977
+ // No session at all behaves exactly the same way.
978
+ const noSession = await assessWith(mediumOffCli());
979
+ assert.equal(noSession.writerProfile, "small");
980
+ assert.equal(noSession.writerProfileSource, "fallback");
538
981
  });
539
982
 
540
983
  test("gentle_review assess never requires a lineageId (unlike most other operations)", async () => {
@@ -715,6 +1158,55 @@ test("native assess: a non-zero exit (an older binary reporting an unknown comma
715
1158
  );
716
1159
  });
717
1160
 
1161
+ // gentle-pi#1175: the full native path (real decoder through the native CLI
1162
+ // wrapper) must keep a code-only reason assessable and project the new
1163
+ // native facts without fabricating them for older envelopes.
1164
+
1165
+ test("gentle_review assess: a native envelope whose reasons lack path/detail is assessed, not unassessable", async () => {
1166
+ const queue = queuedAdapter([{ stdout: JSON.stringify(validEnvelope({ reasons: [{ code: "touches-auth-path" }] })) }]);
1167
+ const client = nativeClient(queue.adapter);
1168
+ const result = await reviewControllerTool({ assess: client.assess.bind(client) }).execute("code-only", { operation: "assess" }, undefined, undefined, ctx);
1169
+ const details = result.details as { risk: string; reasons: Record<string, unknown>[] };
1170
+ assert.equal(details.risk, "medium");
1171
+ assert.deepEqual(details.reasons, [{ code: "touches-auth-path" }]);
1172
+ });
1173
+
1174
+ test("gentle_review assess: consumed, reviewDue, reviewDueReason, and nextTransition are projected verbatim from native", async () => {
1175
+ const queue = queuedAdapter([{ stdout: JSON.stringify(newEnvelope({ candidate: { kind: "current-changes", consumed: false } })) }]);
1176
+ const client = nativeClient(queue.adapter);
1177
+ const result = await reviewControllerTool({ assess: client.assess.bind(client) }).execute("new-envelope", { operation: "assess" }, undefined, undefined, ctx);
1178
+ const details = result.details as Record<string, unknown> & { candidate: Record<string, unknown> };
1179
+ assert.equal(details.risk, "high");
1180
+ assert.equal(details.candidate.consumed, false);
1181
+ assert.equal(details.reviewDue, true);
1182
+ assert.equal(details.reviewDueReason, "high_risk");
1183
+ assert.deepEqual(details.nextTransition, nextTransition());
1184
+ const text = JSON.parse(result.content[0].text) as Record<string, unknown>;
1185
+ assert.deepEqual(text.nextTransition, nextTransition());
1186
+ });
1187
+
1188
+ test("gentle_review assess: an older native envelope projects no consumed/reviewDue/reviewDueReason/nextTransition", async () => {
1189
+ const queue = queuedAdapter([{ stdout: JSON.stringify(validEnvelope()) }]);
1190
+ const client = nativeClient(queue.adapter);
1191
+ const result = await reviewControllerTool({ assess: client.assess.bind(client) }).execute("old-envelope", { operation: "assess" }, undefined, undefined, ctx);
1192
+ const details = result.details as Record<string, unknown> & { candidate: Record<string, unknown> };
1193
+ assert.equal(details.risk, "medium");
1194
+ for (const key of ["reviewDue", "reviewDueReason", "nextTransition"]) {
1195
+ assert.equal(Object.hasOwn(details, key), false, `${key} must not be fabricated`);
1196
+ }
1197
+ assert.equal(Object.hasOwn(details.candidate, "consumed"), false, "consumed must not be fabricated");
1198
+ });
1199
+
1200
+ test("gentle_review assess: an unassessable projection omits reason.path instead of emitting an empty string", async () => {
1201
+ const result = await reviewControllerTool({}).execute("no-assess", { operation: "assess" }, undefined, undefined, ctx);
1202
+ const details = result.details as { risk: string; reasons: Record<string, unknown>[] };
1203
+ assert.equal(details.risk, VERIFICATION_TIER.UNASSESSABLE);
1204
+ assert.equal(details.reasons.length, 1);
1205
+ assert.equal(Object.hasOwn(details.reasons[0], "path"), false);
1206
+ assert.equal(typeof details.reasons[0].detail, "string");
1207
+ assert.ok((details.reasons[0].detail as string).length > 0);
1208
+ });
1209
+
718
1210
  test("native assess: a wrong schema or unrecognized risk value fails closed as schema-incompatible", async () => {
719
1211
  const wrongSchema = queuedAdapter([{ stdout: JSON.stringify({ schema: "gentle-ai.review-assessment/v2", risk: "medium", reasons: [], changed_paths: 0, changed_lines: 0, candidate: { kind: "current-changes" } }) }]);
720
1212
  await assert.rejects(