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
@@ -9,7 +9,7 @@ import { dirname, join, resolve, sep } from "node:path";
9
9
  import test from "node:test";
10
10
  import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
11
11
  import { __testing, createGentleAiExtension, PendingReviewConsentRegistry } from "../extensions/gentle-ai.ts";
12
- import { CandidateViewRegistry } from "../lib/review-candidate-view.ts";
12
+ import { CandidateViewError, CandidateViewRegistry } from "../lib/review-candidate-view.ts";
13
13
  import { NATIVE_REVIEW_ERROR_CODE, NativeReviewCliError, NativeReviewConsentRequiredError, type NativeReviewCli } from "../lib/native-review-cli.ts";
14
14
  import { decodeReviewConsentV3, decodeReviewStatusV3, type ReviewCollectInputV3, type ReviewStatusV3 } from "../lib/review-integration-v2.ts";
15
15
 
@@ -463,7 +463,10 @@ test("interleaved sessions sharing a CLI retain only their own capture routes",
463
463
  const index = requests.length - 1;
464
464
  if (index < 2) { [readyA, readyB][index]!(); await waits[index]!; }
465
465
  const lineageId = String(request.lineageId);
466
- return status(lineageId, [inputs.get(lineageId)!]);
466
+ // Cache absence alone is not foreign-session evidence. The provider
467
+ // rejects selectorless requests for these committed-range candidates.
468
+ return request.baseRef === (lineageId === a ? "base-a" : "base-b")
469
+ ? status(lineageId, [inputs.get(lineageId)!]) : status(lineageId, []);
467
470
  },
468
471
  captureCorrectionPlan: async ({ argumentTokens }: { argumentTokens: readonly string[] }) => {
469
472
  captures += 1;
@@ -487,7 +490,25 @@ test("interleaved sessions sharing a CLI retain only their own capture routes",
487
490
  outcomes: [ownA, ownB, foreign, cleaned].map(({ details }) => (details as { outcome?: string }).outcome),
488
491
  revalidationCalls: requests.length - 2,
489
492
  captures,
490
- }, { outcomes: ["native-last-event-closure", "native-last-event-closure", "capture-binding-rejected", "capture-binding-rejected"], revalidationCalls: 2, captures: 2 });
493
+ }, { outcomes: ["native-last-event-closure", "native-last-event-closure", "capture-binding-rejected", "capture-binding-rejected"], revalidationCalls: 4, captures: 2 });
494
+ });
495
+
496
+ test("capture route recovery uses a trusted committed projection through unknown-outcome reconciliation", async (t) => {
497
+ const candidateViews = new CandidateViewRegistry();
498
+ t.after(() => candidateViews.cleanupAll());
499
+ const cwd = repository(t), lineageId = "recovered-committed", input = correctionPlanInput(lineageId);
500
+ const view = candidateViews.create({ contributorRoot: cwd, baseRef: execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim(), committedOnly: true });
501
+ candidateViews.retain(view.token, lineageId);
502
+ const target = candidateViews.resolveProjection(lineageId, cwd), requests: Array<Record<string, unknown>> = [];
503
+ const native = {
504
+ targetStatus: async (request: Record<string, unknown>) => { requests.push(request); return status(lineageId, [input]); },
505
+ captureCorrectionPlan: async () => { throw Object.assign(new Error("lost response"), { mutationOutcome: "unknown", nextAction: "review.status" }); },
506
+ } as unknown as NativeReviewCli;
507
+ const result = await __testing.executeReviewCaptureOperation({ lineageId, collectBinding: JSON.stringify(input), correctionLines: 1 }, cwd, native, undefined, candidateViews, new Map(), true);
508
+ assert.equal(result.outcome, "native-capture-outcome-unknown");
509
+ assert.equal(requests.length, 2, "one admission STATUS and one reconciliation, never capture replay");
510
+ assert.ok(requests.every((request) => request.cwd === cwd && request.lineageId === lineageId && request.baseRef === target.baseCommit && request.committedOnly === true));
511
+ assert.equal(requests[0]!.agent, "pi");
491
512
  });
492
513
 
493
514
  test("REPAIR retains frozen committed collect selectors and leaves workspace routes unselected", async (t) => {
@@ -649,7 +670,8 @@ test("STATUS preserves retained intended-untracked selection through selectorles
649
670
  selections,
650
671
  true,
651
672
  );
652
- assert.deepEqual({ outcome: stale.outcome, requests: requests.length, captures }, { outcome: "capture-binding-rejected", requests: 3, captures: 0 });
673
+ assert.deepEqual({ outcome: stale.outcome, requests: requests.length, captures }, { outcome: "capture-binding-rejected", requests: 4, captures: 0 });
674
+ assert.deepEqual(requests[3], { cwd, lineageId, agent: "pi", ...selectedUntracked });
653
675
 
654
676
  const captured = await __testing.executeReviewCaptureOperation(
655
677
  { lineageId, collectBinding: bindingB, correctionLines: 1 },
@@ -666,6 +688,7 @@ test("STATUS preserves retained intended-untracked selection through selectorles
666
688
  { cwd, lineageId, agent: "pi", baseRef: "main", committedOnly: true },
667
689
  { cwd, lineageId, agent: "pi", ...selectedUntracked },
668
690
  { cwd, lineageId, agent: "pi", ...selectedUntracked },
691
+ { cwd, lineageId, agent: "pi", ...selectedUntracked },
669
692
  ]);
670
693
  assert.equal(captures, 1);
671
694
 
@@ -676,10 +699,14 @@ test("STATUS preserves retained intended-untracked selection through selectorles
676
699
  });
677
700
 
678
701
  test("route retention caps, rejects collisions and invalid selectors, and clears every terminal state", async () => {
679
- const native = { targetStatus: async (request: Record<string, unknown>) => status(String(request.lineageId)) } as unknown as NativeReviewCli;
702
+ const requests: Array<Record<string, unknown>> = [];
703
+ const native = { targetStatus: async (request: Record<string, unknown>) => { requests.push(request); return status(String(request.lineageId), request.baseRef === undefined ? [] : [collectInput(String(request.lineageId))]); } } as unknown as NativeReviewCli;
680
704
  const selections = new Map();
681
705
  for (let index = 0; index <= 64; index += 1) await __testing.executeReviewControllerOperation({ operation: "status", lineageId: `bounded-${index}`, input: JSON.stringify({ baseRef: `base-${index}`, committedOnly: true }) }, process.cwd(), native, undefined, undefined, undefined, selections);
706
+ assert.equal(selections.size, 64, "route retention remains bounded before native refresh");
682
707
  const evicted = await __testing.executeReviewCaptureOperation({ lineageId: "bounded-0", collectBinding: JSON.stringify(collectInput("bounded-0")) }, process.cwd(), native, undefined, undefined, selections, true);
708
+ assert.equal(requests.length, 66, "eviction must negotiate fresh native STATUS before rejection");
709
+ assert.deepEqual(requests.at(-1), { cwd: process.cwd(), lineageId: "bounded-0", agent: "pi" });
683
710
  const collision = new Map(), lineageId = "route-collision", input = correctionPlanInput(lineageId);
684
711
  await __testing.executeReviewControllerOperation({ operation: "status", lineageId, input: JSON.stringify({ baseRef: "base-a", committedOnly: true }) }, process.cwd(), { targetStatus: async () => status(lineageId, [input]) } as unknown as NativeReviewCli, undefined, undefined, undefined, collision);
685
712
  const rejected = await __testing.executeReviewControllerOperation({ operation: "status", lineageId, input: JSON.stringify({ baseRef: "base-b", committedOnly: true }) }, process.cwd(), { targetStatus: async () => status(lineageId, [input]) } as unknown as NativeReviewCli, undefined, undefined, undefined, collision);
@@ -936,6 +963,72 @@ function startStatus(cwd: string, baseRef?: string, intendedUntracked: readonly
936
963
  }
937
964
  }
938
965
 
966
+ test("START reports POSIX candidate parent privacy refusal without native START or permission repair", { skip: process.platform === "win32" }, async (t) => {
967
+ const cwd = repository(t);
968
+ const target = startStatus(cwd);
969
+ const parent = join(cwd, ".git", "gentle-ai", "candidate-views");
970
+ chmodSync(parent, 0o777);
971
+ let starts = 0;
972
+ const native = {
973
+ targetStatus: async () => target,
974
+ start: async () => { starts++; throw new Error("native START must not run"); },
975
+ } as unknown as NativeReviewCli;
976
+ let result: Record<string, unknown>;
977
+ try {
978
+ result = await __testing.executeReviewControllerOperation({ operation: "start", input: JSON.stringify({ mode: "ordinary" }) }, cwd, native);
979
+ } finally {
980
+ assert.equal(fs.lstatSync(parent).mode & 0o777, 0o777);
981
+ chmodSync(parent, 0o700);
982
+ }
983
+ assert.equal(result.status, "blocked");
984
+ assert.equal(result.outcome, "native-operation-failed");
985
+ assert.equal(result.lineage_created, false);
986
+ assert.equal(result.mutation_outcome, "none");
987
+ assert.deepEqual(result.diagnostics, {
988
+ code: "candidate-owner-parent-privacy",
989
+ message: "candidate-views parent must be owned by the current user and inaccessible to group and others; inspect its ownership and permissions, then correct them out of band before retrying START",
990
+ });
991
+ assert.equal(starts, 0);
992
+ });
993
+
994
+ test("START reports ineffective POSIX private-mode mounts without native START or permission repair", { skip: process.platform === "win32" }, async (t) => {
995
+ const cwd = repository(t);
996
+ const target = startStatus(cwd);
997
+ const parent = join(cwd, ".git", "gentle-ai", "candidate-views");
998
+ mkdirSync(parent, { recursive: true, mode: 0o700 });
999
+ chmodSync(parent, 0o777);
1000
+ const originalLstat = fs.lstatSync;
1001
+ t.mock.method(fs, "lstatSync", (path: Parameters<typeof fs.lstatSync>[0], ...args: unknown[]) => {
1002
+ const stat = (originalLstat as (...arguments_: unknown[]) => ReturnType<typeof fs.lstatSync>)(path, ...args);
1003
+ return typeof path === "string" && path.includes(".gentle-ai-chmod-probe-")
1004
+ ? Object.assign(Object.create(Object.getPrototypeOf(stat)), stat, { mode: (Number(stat.mode) & ~0o777) | 0o777, uid: process.getuid?.() })
1005
+ : stat;
1006
+ });
1007
+ syncBuiltinESMExports();
1008
+ t.after(() => { t.mock.restoreAll(); syncBuiltinESMExports(); });
1009
+ let starts = 0;
1010
+ const native = {
1011
+ targetStatus: async () => target,
1012
+ start: async () => { starts++; throw new Error("native START must not run"); },
1013
+ } as unknown as NativeReviewCli;
1014
+ let result: Record<string, unknown>;
1015
+ try {
1016
+ result = await __testing.executeReviewControllerOperation({ operation: "start", input: JSON.stringify({ mode: "ordinary" }) }, cwd, native);
1017
+ } finally {
1018
+ assert.equal(fs.lstatSync(parent).mode & 0o777, 0o777);
1019
+ chmodSync(parent, 0o700);
1020
+ }
1021
+ assert.equal(result.status, "blocked");
1022
+ assert.equal(result.outcome, "native-operation-failed");
1023
+ assert.equal(result.lineage_created, false);
1024
+ assert.equal(result.mutation_outcome, "none");
1025
+ assert.deepEqual(result.diagnostics, {
1026
+ code: "candidate-owner-parent-chmod-ineffective",
1027
+ message: "candidate-views parent filesystem does not honor POSIX permission changes; move this repository's Git common directory to a POSIX-metadata filesystem or enable metadata support before retrying START",
1028
+ });
1029
+ assert.equal(starts, 0);
1030
+ });
1031
+
939
1032
  test("ordinary START binds the native workspace candidate and returns the native result", async (t) => {
940
1033
  const cwd = repository(t);
941
1034
  const target = startStatus(cwd);
@@ -1045,6 +1138,171 @@ test("ordinary START adopts the offered committed-range base while an untracked
1045
1138
  assert.equal(startCalls, 1, "native START is reached exactly once without drift");
1046
1139
  });
1047
1140
 
1141
+ test("ordinary START adopts a provider-offered base tree without treating it as caller input", async (t) => {
1142
+ const cwd = repository(t);
1143
+ execFileSync("git", ["add", "tracked.txt"], { cwd });
1144
+ execFileSync("git", ["-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "candidate"], { cwd });
1145
+ const baseCommit = execFileSync("git", ["rev-parse", "HEAD~1"], { cwd, encoding: "utf8" }).trim();
1146
+ const baseTree = execFileSync("git", ["rev-parse", `${baseCommit}^{tree}`], { cwd, encoding: "utf8" }).trim();
1147
+ const offered = startStatus(cwd);
1148
+ offered.nextTransition = {
1149
+ kind: "execute", reasonCode: "start_required",
1150
+ execute: { operation: "review.start", arguments: [
1151
+ { name: "target", value: offered.targetIdentity, token: `--target=${offered.targetIdentity}` },
1152
+ { name: "projection", value: "workspace", token: "--projection=workspace" },
1153
+ { name: "base-ref", value: baseTree, token: `--base-ref=${baseTree}` },
1154
+ { name: "committed-only", value: "true", token: "--committed-only=true" },
1155
+ { name: "agent", value: "pi", token: "--agent=pi" },
1156
+ ], preconditions: [], binding: {} },
1157
+ } as unknown as ReviewStatusV3["nextTransition"];
1158
+ const adopted = startStatus(cwd, baseCommit);
1159
+ const requests: Array<Record<string, unknown>> = [];
1160
+ const starts: Array<Record<string, unknown>> = [];
1161
+ const native = {
1162
+ targetStatus: async (request: Record<string, unknown>) => {
1163
+ requests.push(request);
1164
+ return requests.length === 1 ? offered : adopted;
1165
+ },
1166
+ start: async (request: Record<string, unknown>) => {
1167
+ starts.push(request);
1168
+ return { lineageId: "tree-offer-started", state: "reviewing", riskLevel: "low", selectedLenses: [], changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false, riskReasons: [], raw: {} };
1169
+ },
1170
+ } as unknown as NativeReviewCli;
1171
+ const views = new CandidateViewRegistry();
1172
+ t.after(() => views.cleanupAll());
1173
+ const result = await __testing.executeReviewControllerOperation({ operation: "start", input: JSON.stringify({ mode: "ordinary" }) }, cwd, native, undefined, views);
1174
+ assert.equal(result.operation, "start");
1175
+ assert.equal(requests.length, 2, "provider-offered tree requires a second bound STATUS");
1176
+ assert.equal(requests[1]!.baseRef, baseTree, "transport preserves the offered tree selector");
1177
+ assert.equal(starts.length, 1);
1178
+ assert.equal(starts[0]!.baseRef, baseTree, "native START receives the provider's original tree selector");
1179
+ assert.equal(starts[0]!.targetIdentity, adopted.targetIdentity);
1180
+ for (const input of [undefined, { baseRef: baseCommit, committedOnly: true }, undefined]) {
1181
+ const before = requests.length;
1182
+ const next = await __testing.executeReviewControllerOperation({ operation: "status", lineageId: "tree-offer-started", ...(input === undefined ? {} : { input: JSON.stringify(input) }) }, cwd, native, undefined, views);
1183
+ assert.equal(next.operation, "status");
1184
+ assert.equal(requests.length, before + 1);
1185
+ assert.equal(requests.at(-1)!.baseRef, input?.baseRef ?? baseTree, "selectorless STATUS must replay the provider tree; explicit caller commit wins only for its call");
1186
+ assert.equal(requests.at(-1)!.lineageId, "tree-offer-started");
1187
+ }
1188
+ });
1189
+
1190
+ test("facade STATUS hydrates an ordinary staged-index reviewer candidate without treating its base tree as an offered range", async (t) => {
1191
+ const cwd = repository(t);
1192
+ const baseTree = execFileSync("git", ["rev-parse", "HEAD^{tree}"], { cwd, encoding: "utf8" }).trim();
1193
+ writeFileSync(join(cwd, "tracked.txt"), "staged index candidate\n");
1194
+ execFileSync("git", ["add", "tracked.txt"], { cwd });
1195
+ const stagedTree = execFileSync("git", ["write-tree"], { cwd, encoding: "utf8" }).trim();
1196
+ const lineageId = "staged-index-hydration";
1197
+ const target = status(lineageId);
1198
+ target.projection = { ...target.projection, projection: "staged", baseTree, initialReviewTree: stagedTree, currentCandidateTree: stagedTree, paths: ["tracked.txt"] };
1199
+ const views = new CandidateViewRegistry();
1200
+ t.after(() => views.cleanupAll());
1201
+ const native = { targetStatus: async () => target } as unknown as NativeReviewCli;
1202
+ await __testing.executeReviewControllerOperation({ operation: "status", lineageId }, cwd, native, undefined, views);
1203
+ const restored = views.resolveCurrentForLens("review-risk", cwd);
1204
+ assert.equal(restored.baseTree, baseTree);
1205
+ assert.equal(restored.candidateTree, stagedTree);
1206
+ assert.equal(restored.committedOnly, false);
1207
+ assert.equal(views.resolveProjection(lineageId, cwd).providerBaseTree, undefined);
1208
+ });
1209
+
1210
+ test("fresh facade STATUS hydrates a historical commit-backed range without granting provider-tree provenance", async (t) => {
1211
+ const cwd = repository(t);
1212
+ const baseCommit = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
1213
+ const baseTree = execFileSync("git", ["rev-parse", "HEAD^{tree}"], { cwd, encoding: "utf8" }).trim();
1214
+ writeFileSync(join(cwd, "tracked.txt"), "committed candidate\n");
1215
+ execFileSync("git", ["add", "tracked.txt"], { cwd });
1216
+ execFileSync("git", ["-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "candidate"], { cwd });
1217
+ const currentTree = execFileSync("git", ["rev-parse", "HEAD^{tree}"], { cwd, encoding: "utf8" }).trim();
1218
+ const historical = status("historical-commit-range");
1219
+ historical.projection = { ...historical.projection, projection: "staged", baseTree, initialReviewTree: currentTree, currentCandidateTree: currentTree, paths: ["tracked.txt"] };
1220
+ const views = new CandidateViewRegistry();
1221
+ t.after(() => views.cleanupAll());
1222
+ await __testing.executeReviewControllerOperation({ operation: "status", lineageId: "historical-commit-range" }, cwd, { targetStatus: async () => historical } as unknown as NativeReviewCli, undefined, views);
1223
+ const restored = views.resolveCurrentForLens("review-risk", cwd);
1224
+ assert.equal(restored.baseCommit, baseCommit);
1225
+ assert.equal(restored.baseTree, baseTree);
1226
+ assert.equal(restored.candidateTree, currentTree);
1227
+ assert.equal(restored.committedOnly, true);
1228
+ assert.equal(views.resolveProjection("historical-commit-range", cwd).providerBaseTree, undefined);
1229
+ });
1230
+
1231
+ test("facade STATUS refuses an unreachable base tree and a false staged-index kind", async (t) => {
1232
+ const cwd = repository(t);
1233
+ const currentTree = execFileSync("git", ["rev-parse", "HEAD^{tree}"], { cwd, encoding: "utf8" }).trim();
1234
+ const unreachableTree = execFileSync("git", ["mktree"], { cwd, input: "", encoding: "utf8" }).trim();
1235
+ assert.notEqual(unreachableTree, currentTree);
1236
+ const unknown = status("unprovable-tree");
1237
+ unknown.projection = { ...unknown.projection, projection: "staged", baseTree: unreachableTree, initialReviewTree: currentTree, currentCandidateTree: currentTree, paths: ["tracked.txt"] };
1238
+ const views = new CandidateViewRegistry();
1239
+ t.after(() => views.cleanupAll());
1240
+ await __testing.executeReviewControllerOperation({ operation: "status", lineageId: "unprovable-tree" }, cwd, { targetStatus: async () => unknown } as unknown as NativeReviewCli, undefined, views);
1241
+ assert.equal(views.hasProjection("unprovable-tree", cwd), false);
1242
+ assert.throws(() => views.resolveCurrentForLens("review-risk", cwd), (error: unknown) => error instanceof CandidateViewError && error.reason === "current-binding-hydration-failed");
1243
+
1244
+ writeFileSync(join(cwd, "tracked.txt"), "staged index candidate\n");
1245
+ execFileSync("git", ["add", "tracked.txt"], { cwd });
1246
+ const stagedTree = execFileSync("git", ["write-tree"], { cwd, encoding: "utf8" }).trim();
1247
+ writeFileSync(join(cwd, "tracked.txt"), "uncommitted workspace content\n");
1248
+ const falseKind = status("false-staged-index");
1249
+ falseKind.projection = { ...falseKind.projection, projection: "staged", baseTree: currentTree, initialReviewTree: stagedTree, currentCandidateTree: stagedTree, paths: ["tracked.txt"] };
1250
+ const otherViews = new CandidateViewRegistry();
1251
+ t.after(() => otherViews.cleanupAll());
1252
+ await __testing.executeReviewControllerOperation({ operation: "status", lineageId: "false-staged-index" }, cwd, { targetStatus: async () => falseKind } as unknown as NativeReviewCli, undefined, otherViews);
1253
+ assert.equal(otherViews.hasProjection("false-staged-index", cwd), false);
1254
+ assert.throws(() => otherViews.resolveCurrentForLens("review-risk", cwd), (error: unknown) => error instanceof CandidateViewError && error.reason === "current-binding-hydration-failed" && error.message.includes("candidate-view-invalid"));
1255
+ });
1256
+
1257
+ test("provider tree adoption refuses drifted targets, malformed offers and explicit caller trees", async (t) => {
1258
+ const cwd = repository(t);
1259
+ execFileSync("git", ["add", "tracked.txt"], { cwd });
1260
+ execFileSync("git", ["-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "candidate"], { cwd });
1261
+ const baseCommit = execFileSync("git", ["rev-parse", "HEAD~1"], { cwd, encoding: "utf8" }).trim();
1262
+ const baseTree = execFileSync("git", ["rev-parse", `${baseCommit}^{tree}`], { cwd, encoding: "utf8" }).trim();
1263
+ const adopted = startStatus(cwd, baseCommit);
1264
+ const offered = startStatus(cwd);
1265
+ offered.nextTransition = { kind: "execute", reasonCode: "start_required", execute: { operation: "review.start", arguments: [{ name: "base-ref", value: baseTree }, { name: "committed-only", value: "true" }], preconditions: [], binding: {} } } as unknown as ReviewStatusV3["nextTransition"];
1266
+ const drifted = startStatus(cwd);
1267
+ const malformed = startStatus(cwd);
1268
+ malformed.nextTransition = { kind: "execute", reasonCode: "start_required", execute: { operation: "review.start", arguments: [{ name: "base-ref", value: baseTree }, { name: "base-ref", value: baseTree }, { name: "committed-only", value: "true" }], preconditions: [], binding: {} } } as unknown as ReviewStatusV3["nextTransition"];
1269
+ const malformedExtra = startStatus(cwd);
1270
+ malformedExtra.nextTransition = { kind: "execute", reasonCode: "start_required", execute: { operation: "review.start", arguments: [
1271
+ { name: "agent", value: "pi" }, { name: "base-ref", value: baseTree, token: `--base-ref=${baseTree}` },
1272
+ { name: "committed-only", value: "true", token: "--committed-only=true" }, { name: "committed-only", value: "false" },
1273
+ ], preconditions: [], binding: {} } } as unknown as ReviewStatusV3["nextTransition"];
1274
+ const malformedToken = startStatus(cwd);
1275
+ malformedToken.nextTransition = { kind: "execute", reasonCode: "start_required", execute: { operation: "review.start", arguments: [
1276
+ { name: "agent", value: "pi" }, { name: "base-ref", value: baseTree, token: "--base-ref=HEAD" },
1277
+ { name: "committed-only", value: "true", token: "--committed-only=true" },
1278
+ ], preconditions: [], binding: {} } } as unknown as ReviewStatusV3["nextTransition"];
1279
+ const blob = execFileSync("git", ["rev-parse", "HEAD:tracked.txt"], { cwd, encoding: "utf8" }).trim();
1280
+ const wrongType = startStatus(cwd);
1281
+ wrongType.nextTransition = { kind: "execute", reasonCode: "start_required", execute: { operation: "review.start", arguments: [{ name: "base-ref", value: blob }, { name: "committed-only", value: "true" }], preconditions: [], binding: {} } } as unknown as ReviewStatusV3["nextTransition"];
1282
+ for (const scenario of [
1283
+ { name: "changed tree target", first: offered, second: drifted, expectedReads: 2 },
1284
+ { name: "malformed duplicate offer", first: malformed, second: adopted, expectedReads: 1 },
1285
+ { name: "conflicting selector among unrelated arguments", first: malformedExtra, second: adopted, expectedReads: 1 },
1286
+ { name: "selector token disagrees with value", first: malformedToken, second: adopted, expectedReads: 1 },
1287
+ { name: "wrong object type", first: wrongType, second: adopted, expectedReads: 2 },
1288
+ ]) {
1289
+ let reads = 0, starts = 0;
1290
+ const views = new CandidateViewRegistry();
1291
+ t.after(() => views.cleanupAll());
1292
+ const native = { targetStatus: async () => (++reads === 1 ? scenario.first : scenario.second), start: async () => { starts++; throw new Error("native START must not run"); } } as unknown as NativeReviewCli;
1293
+ const result = await __testing.executeReviewControllerOperation({ operation: "start", input: JSON.stringify({ mode: "ordinary" }) }, cwd, native, undefined, views);
1294
+ assert.equal(reads, scenario.expectedReads, scenario.name);
1295
+ assert.equal(starts, 0, scenario.name);
1296
+ assert.equal(result.status, "blocked", scenario.name);
1297
+ }
1298
+ let reads = 0, starts = 0;
1299
+ const native = { targetStatus: async () => { reads++; return offered; }, start: async () => { starts++; throw new Error("native START must not run"); } } as unknown as NativeReviewCli;
1300
+ const rejected = await __testing.executeReviewControllerOperation({ operation: "start", input: JSON.stringify({ mode: "ordinary", baseRef: baseTree, committedOnly: true }) }, cwd, native);
1301
+ assert.equal(rejected.outcome, "native-start-base-ref-unresolvable");
1302
+ assert.equal(reads, 0);
1303
+ assert.equal(starts, 0);
1304
+ });
1305
+
1048
1306
  test("ordinary START preserves sanitized foreign diagnostics through one ambiguous reconciliation", async (t) => {
1049
1307
  const cwd = repository(t);
1050
1308
  const target = startStatus(cwd);
@@ -1160,6 +1418,60 @@ for (const statusSchema of ["gentle-ai.review-integration.status/v6", "gentle-ai
1160
1418
  assert.equal(requests.every((request) => !("lineageId" in request)), true);
1161
1419
  });
1162
1420
 
1421
+ test("committed-range inspect stop carries its binding selector into selection STATUS and START, rejecting a mismatched binding", async (t) => {
1422
+ const { cwd, eligible, selection } = untrackedStopFixture(t);
1423
+ const baseRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
1424
+ const initialTarget = startStatus(cwd, baseRef), target = startStatus(cwd, baseRef, [eligible]);
1425
+ const boundSelection = { ...selection, arguments: selection.arguments.map((arg) => arg.name === "base_tree" ? { ...arg, value: initialTarget.projection.baseTree } : arg.name === "candidate_tree" ? { ...arg, value: initialTarget.projection.currentCandidateTree } : arg) };
1426
+ const initial = { ...initialTarget, nextTransition: { kind: "collect", reasonCode: "intended_untracked_selection_required", collect: { inputs: [boundSelection] } }, raw: { schema: "gentle-ai.review-integration.status/v7" } } as ReviewStatusV3;
1427
+ const requests: Array<Record<string, unknown>> = [], starts: Array<Record<string, unknown>> = [], retained = new Map();
1428
+ const native = {
1429
+ targetStatus: async (request: Record<string, unknown>) => { requests.push(request); return "intendedUntrackedSelection" in request ? target : initial; },
1430
+ start: async (request: Record<string, unknown>) => { starts.push(request); return { lineageId: "review-selected", state: "reviewing", riskLevel: "low", selectedLenses: [], changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false, riskReasons: [], raw: {} }; },
1431
+ } as unknown as NativeReviewCli;
1432
+ const inspected = await __testing.executeReviewControllerOperation({ operation: "inspect", input: JSON.stringify({ baseRef: "HEAD", committedOnly: true }) }, cwd, native, undefined, undefined, undefined, retained);
1433
+ assert.equal(typeof inspected.selectionBinding, "string");
1434
+ assert.equal(retained.has(`${cwd}\u0000`), true, "plain inspect stop retains its selector");
1435
+ const mismatch = await __testing.executeReviewControllerOperation({ operation: "select-intended-untracked", selectionBinding: (inspected.selectionBinding as string).replace(eligible, "other.md"), intendedUntracked: [eligible] }, cwd, native, undefined, undefined, undefined, retained);
1436
+ assert.equal(mismatch.outcome, "intended-untracked-selection-binding-rejected");
1437
+ assert.equal(requests.length, 1, "mismatched binding must not request another STATUS");
1438
+ assert.equal(starts.length, 0);
1439
+ const selected = await __testing.executeReviewControllerOperation({ operation: "select-intended-untracked", selectionBinding: inspected.selectionBinding, intendedUntracked: [eligible] }, cwd, native, undefined, undefined, undefined, retained);
1440
+ assert.equal(selected.operation, "select-intended-untracked");
1441
+ assert.equal(starts.length, 1, JSON.stringify(selected));
1442
+ assert.equal(requests.length, 3);
1443
+ for (const request of requests) { assert.equal(request.baseRef, baseRef); assert.equal(request.committedOnly, true); }
1444
+ assert.equal(starts[0]!.baseRef, baseRef);
1445
+ assert.equal(starts[0]!.committedOnly, true);
1446
+ });
1447
+
1448
+ test("committed-range selection rejects target-identity drift before START", async (t) => {
1449
+ const { cwd, eligible, selection } = untrackedStopFixture(t);
1450
+ const baseRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
1451
+ const initialTarget = startStatus(cwd, baseRef);
1452
+ const boundSelection = { ...selection, arguments: selection.arguments.map((arg) => arg.name === "base_tree" ? { ...arg, value: initialTarget.projection.baseTree } : arg.name === "candidate_tree" ? { ...arg, value: initialTarget.projection.currentCandidateTree } : arg) };
1453
+ const initial = { ...initialTarget, nextTransition: { kind: "collect", reasonCode: "intended_untracked_selection_required", collect: { inputs: [boundSelection] } }, raw: { schema: "gentle-ai.review-integration.status/v7" } } as ReviewStatusV3;
1454
+ const changed = { ...initial, targetIdentity: `sha256:${"d".repeat(64)}` } as ReviewStatusV3;
1455
+ const requests: Array<Record<string, unknown>> = [];
1456
+ let starts = 0;
1457
+ const retained = new Map();
1458
+ const native = {
1459
+ targetStatus: async (request: Record<string, unknown>) => { requests.push(request); return requests.length === 1 ? initial : changed; },
1460
+ start: async () => { starts++; throw new Error("START must not run for a changed target"); },
1461
+ } as unknown as NativeReviewCli;
1462
+ const inspected = await __testing.executeReviewControllerOperation({ operation: "inspect", input: JSON.stringify({ baseRef: "HEAD", committedOnly: true }) }, cwd, native, undefined, undefined, undefined, retained);
1463
+ assert.equal(typeof inspected.selectionBinding, "string");
1464
+ const rejected = await __testing.executeReviewControllerOperation({ operation: "select-intended-untracked", selectionBinding: inspected.selectionBinding, intendedUntracked: [eligible] }, cwd, native, undefined, undefined, undefined, retained);
1465
+ assert.equal(rejected.status, "blocked");
1466
+ assert.equal(rejected.outcome, "intended-untracked-selection-binding-rejected");
1467
+ assert.equal(rejected.mutation_performed, false);
1468
+ assert.equal(rejected.mutation_outcome, "none");
1469
+ assert.equal(requests.length, 2);
1470
+ assert.equal(requests[1]!.baseRef, baseRef);
1471
+ assert.equal(requests[1]!.committedOnly, true);
1472
+ assert.equal(starts, 0);
1473
+ });
1474
+
1163
1475
  // gentle-pi#706: inspect names the exact continuation for the intended-untracked
1164
1476
  // stop and can resolve it in one call through top-level untrackedScope.
1165
1477
  function untrackedStopFixture(
@@ -1562,6 +1874,300 @@ test("a fresh unsuccessful inspect invalidates its prior pre-lineage selection",
1562
1874
  assert.equal(retained.has(`${cwd}\u0000`), false);
1563
1875
  });
1564
1876
 
1877
+ // gentle-pi#1192: a committed-range inspect's retained pre-lineage selection
1878
+ // must remember its own baseRef/committedOnly too, so a later plain START
1879
+ // replays the same committed range instead of falling back to the
1880
+ // workspace-diff one.
1881
+ test("inspect with a committed-range selector retains baseRef/committedOnly, and a plain START adopts it", async (t) => {
1882
+ const cwd = repository(t), eligible = "selected.md";
1883
+ writeFileSync(join(cwd, eligible), "selected\n");
1884
+ const baseRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
1885
+ // The inspect handler carries its committed-range selector through both the
1886
+ // pre-resolution and resolution STATUS calls, so a faithful fixture for
1887
+ // this scenario must project the committed range on both, not the
1888
+ // workspace-diff range untrackedStopFixture builds.
1889
+ const initialTarget = startStatus(cwd, baseRef),
1890
+ target = startStatus(cwd, baseRef, [eligible]);
1891
+ const selection: ReviewCollectInputV3 = {
1892
+ name: "intended_untracked_selection",
1893
+ schema: "gentle-ai.review-intended-untracked-selection/v1",
1894
+ captureOperation: "external.select_intended_untracked",
1895
+ arguments: [
1896
+ { name: "target_identity", value: SHA },
1897
+ { name: "projection", value: "workspace" },
1898
+ { name: "base_tree", value: initialTarget.projection.baseTree },
1899
+ { name: "candidate_tree", value: initialTarget.projection.currentCandidateTree },
1900
+ { name: "eligible_paths_json", value: JSON.stringify([eligible]) },
1901
+ { name: "expected_untracked_inventory", value: SHA },
1902
+ ],
1903
+ submission: {
1904
+ operationToken: "status",
1905
+ argumentTokens: [
1906
+ "--contract=gentle-ai.review-integration/v2",
1907
+ "--next-transition=true",
1908
+ "--agent=pi",
1909
+ "--projection=workspace",
1910
+ "--intended-untracked-selection={{value}}",
1911
+ ],
1912
+ values: [
1913
+ {
1914
+ slot: "intended_untracked_selection",
1915
+ domain: "schema_bound_json",
1916
+ schema: "gentle-ai.review-intended-untracked-selection/v1",
1917
+ substitutionLocation: 4,
1918
+ },
1919
+ ],
1920
+ },
1921
+ };
1922
+ const initial = {
1923
+ ...initialTarget,
1924
+ nextTransition: {
1925
+ kind: "collect",
1926
+ reasonCode: "intended_untracked_selection_required",
1927
+ collect: { inputs: [selection] },
1928
+ },
1929
+ raw: { schema: "gentle-ai.review-integration.status/v7" },
1930
+ } as ReviewStatusV3;
1931
+ const requests: Array<Record<string, unknown>> = [],
1932
+ starts: Array<Record<string, unknown>> = [],
1933
+ retained = new Map();
1934
+ const native = {
1935
+ targetStatus: async (request: Record<string, unknown>) => {
1936
+ requests.push(request);
1937
+ return "intendedUntrackedSelection" in request ? target : initial;
1938
+ },
1939
+ start: async (request: Record<string, unknown>) => {
1940
+ starts.push(request);
1941
+ return {
1942
+ lineageId: "review-started", state: "reviewing", riskLevel: "low", selectedLenses: [],
1943
+ changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false,
1944
+ riskReasons: [], raw: {},
1945
+ };
1946
+ },
1947
+ } as unknown as NativeReviewCli;
1948
+ const resolved = await __testing.executeReviewControllerOperation(
1949
+ {
1950
+ operation: "inspect",
1951
+ input: JSON.stringify({ baseRef: "HEAD", committedOnly: true }),
1952
+ untrackedScope: "select",
1953
+ intendedUntracked: [eligible],
1954
+ },
1955
+ cwd, native, undefined, undefined, undefined, retained,
1956
+ );
1957
+ assert.equal(resolved.status, "ready");
1958
+ const retainedEntry = retained.get(`${cwd}\u0000`) as { baseRef?: string; committedOnly?: true } | undefined;
1959
+ assert.notEqual(retainedEntry, undefined);
1960
+ assert.equal(retainedEntry!.baseRef, baseRef);
1961
+ assert.equal(retainedEntry!.committedOnly, true);
1962
+
1963
+ const started = await __testing.executeReviewControllerOperation(
1964
+ { operation: "start", input: JSON.stringify({ mode: "ordinary" }) },
1965
+ cwd, native, undefined, undefined, undefined, retained,
1966
+ );
1967
+ assert.equal(started.operation, "start");
1968
+ assert.equal((started.result as { lineage_id?: string }).lineage_id, "review-started");
1969
+ assert.equal(requests.length, 3);
1970
+ const startStatusRequest = requests[2]!;
1971
+ assert.equal(startStatusRequest.baseRef, baseRef);
1972
+ assert.equal(startStatusRequest.committedOnly, true);
1973
+ assert.equal(startStatusRequest.untrackedScope, "select");
1974
+ assert.deepEqual(startStatusRequest.intendedUntrackedSelection, {
1975
+ argumentTokens: selection.submission!.argumentTokens,
1976
+ value: JSON.stringify({
1977
+ schema: "gentle-ai.review-intended-untracked-selection/v1",
1978
+ untracked_scope: "select",
1979
+ expected_untracked_inventory: SHA,
1980
+ intended_untracked: [eligible],
1981
+ }),
1982
+ });
1983
+ assert.equal(starts.length, 1);
1984
+ assert.equal(starts[0]!.baseRef, baseRef);
1985
+ assert.equal(starts[0]!.committedOnly, true);
1986
+ assert.equal(starts[0]!.untrackedScope, "select");
1987
+ assert.equal(retained.has(`${cwd}\u0000`), false);
1988
+ const lineageEntry = retained.get(`${cwd}\u0000review-started`) as { untrackedScope: string; baseRef?: string } | undefined;
1989
+ assert.notEqual(lineageEntry, undefined);
1990
+ assert.equal(lineageEntry!.untrackedScope, "select");
1991
+ // The lineage-scoped entry must stay a plain untracked selection: a
1992
+ // leftover baseRef field would make readRetainedNativeUntrackedSelection
1993
+ // mistake it for a RetainedNativeCaptureRoute.
1994
+ assert.equal("baseRef" in lineageEntry!, false);
1995
+ });
1996
+
1997
+ // gentle-pi#review-ready-inspect-selector: a plain inspect that resolves ready
1998
+ // without ever needing an untrackedScope decision must still retain its own
1999
+ // committed-range selector, so the following plain START replays the exact
2000
+ // inspected range instead of adopting the native default base-ref (#874).
2001
+ test("a plain ready inspect retains its committed selector, and a plain START adopts it", async (t) => {
2002
+ const cwd = repository(t);
2003
+ const baseRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
2004
+ const target = startStatus(cwd, baseRef);
2005
+ const requests: Array<Record<string, unknown>> = [],
2006
+ starts: Array<Record<string, unknown>> = [],
2007
+ retained = new Map();
2008
+ const native = {
2009
+ targetStatus: async (request: Record<string, unknown>) => { requests.push(request); return target; },
2010
+ start: async (request: Record<string, unknown>) => {
2011
+ starts.push(request);
2012
+ return {
2013
+ lineageId: "ready-started", state: "reviewing", riskLevel: "low", selectedLenses: [],
2014
+ changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false,
2015
+ riskReasons: [], raw: {},
2016
+ };
2017
+ },
2018
+ } as unknown as NativeReviewCli;
2019
+ const inspected = await __testing.executeReviewControllerOperation(
2020
+ { operation: "inspect", input: JSON.stringify({ baseRef: "HEAD", committedOnly: true }) },
2021
+ cwd, native, undefined, undefined, undefined, retained,
2022
+ );
2023
+ assert.equal(inspected.status, "ready");
2024
+ const retainedEntry = retained.get(`${cwd}\u0000`) as { baseRef?: string; committedOnly?: true } | undefined;
2025
+ assert.notEqual(retainedEntry, undefined);
2026
+ assert.equal(retainedEntry!.baseRef, baseRef);
2027
+ assert.equal(retainedEntry!.committedOnly, true);
2028
+
2029
+ const started = await __testing.executeReviewControllerOperation(
2030
+ { operation: "start", input: JSON.stringify({ mode: "ordinary" }) },
2031
+ cwd, native, undefined, undefined, undefined, retained,
2032
+ );
2033
+ assert.equal(started.operation, "start");
2034
+ assert.equal((started.result as { lineage_id?: string }).lineage_id, "ready-started");
2035
+ assert.equal(requests.length, 2);
2036
+ const startStatusRequest = requests[1]!;
2037
+ assert.equal(startStatusRequest.baseRef, baseRef);
2038
+ assert.equal(startStatusRequest.committedOnly, true);
2039
+ assert.equal(starts.length, 1);
2040
+ assert.equal(starts[0]!.baseRef, baseRef);
2041
+ assert.equal(starts[0]!.committedOnly, true);
2042
+ assert.equal(retained.has(`${cwd}\u0000`), false);
2043
+ });
2044
+
2045
+ test("a later ready inspect with a different baseRef replaces the earlier retained selector", async (t) => {
2046
+ const cwd = repository(t);
2047
+ const baseRef1 = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
2048
+ const target1 = startStatus(cwd, baseRef1);
2049
+ execFileSync("git", ["add", "tracked.txt"], { cwd, stdio: "ignore" });
2050
+ execFileSync("git", ["-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "second"], { cwd, stdio: "ignore" });
2051
+ const baseRef2 = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
2052
+ const target2 = startStatus(cwd, baseRef2);
2053
+ const starts: Array<Record<string, unknown>> = [],
2054
+ retained = new Map();
2055
+ const native = {
2056
+ targetStatus: async (request: Record<string, unknown>) => (request.baseRef === baseRef2 ? target2 : target1),
2057
+ start: async (request: Record<string, unknown>) => {
2058
+ starts.push(request);
2059
+ return {
2060
+ lineageId: "second-started", state: "reviewing", riskLevel: "low", selectedLenses: [],
2061
+ changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false,
2062
+ riskReasons: [], raw: {},
2063
+ };
2064
+ },
2065
+ } as unknown as NativeReviewCli;
2066
+ await __testing.executeReviewControllerOperation(
2067
+ { operation: "inspect", input: JSON.stringify({ baseRef: baseRef1, committedOnly: true }) },
2068
+ cwd, native, undefined, undefined, undefined, retained,
2069
+ );
2070
+ await __testing.executeReviewControllerOperation(
2071
+ { operation: "inspect", input: JSON.stringify({ baseRef: baseRef2, committedOnly: true }) },
2072
+ cwd, native, undefined, undefined, undefined, retained,
2073
+ );
2074
+ const retainedEntry = retained.get(`${cwd}\u0000`) as { baseRef?: string } | undefined;
2075
+ assert.equal(retainedEntry?.baseRef, baseRef2);
2076
+
2077
+ const started = await __testing.executeReviewControllerOperation(
2078
+ { operation: "start", input: JSON.stringify({ mode: "ordinary" }) },
2079
+ cwd, native, undefined, undefined, undefined, retained,
2080
+ );
2081
+ assert.equal((started.result as { lineage_id?: string }).lineage_id, "second-started");
2082
+ assert.equal(starts.length, 1);
2083
+ assert.equal(starts[0]!.baseRef, baseRef2);
2084
+ });
2085
+
2086
+ test("START rejects a ready-inspect retained selector when fresh STATUS identifies a changed candidate", async (t) => {
2087
+ const cwd = repository(t);
2088
+ const baseRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
2089
+ const candidateA = startStatus(cwd, baseRef);
2090
+ const candidateB = {
2091
+ ...candidateA,
2092
+ targetIdentity: "target-b",
2093
+ projection: { ...candidateA.projection, currentCandidateTree: "candidate-b" },
2094
+ } as ReviewStatusV3;
2095
+ const retained = new Map();
2096
+ let statusCalls = 0;
2097
+ let starts = 0;
2098
+ const native = {
2099
+ targetStatus: async () => { statusCalls += 1; return statusCalls === 1 ? candidateA : candidateB; },
2100
+ start: async () => {
2101
+ starts += 1;
2102
+ return {
2103
+ lineageId: "unexpected", state: "reviewing", riskLevel: "low", selectedLenses: [],
2104
+ changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false,
2105
+ riskReasons: [], raw: {},
2106
+ };
2107
+ },
2108
+ } as unknown as NativeReviewCli;
2109
+ await __testing.executeReviewControllerOperation(
2110
+ { operation: "inspect", input: JSON.stringify({ baseRef: "HEAD", committedOnly: true }) },
2111
+ cwd, native, undefined, null, undefined, retained,
2112
+ );
2113
+ const rejected = await __testing.executeReviewControllerOperation(
2114
+ { operation: "start", input: JSON.stringify({ mode: "ordinary" }) },
2115
+ cwd, native, undefined, null, undefined, retained,
2116
+ );
2117
+ assert.equal(rejected.outcome, "native-start-retained-selection-candidate-mismatch");
2118
+ assert.equal(starts, 0);
2119
+ assert.equal(retained.has(`${cwd}\u0000`), false);
2120
+ });
2121
+
2122
+ test("an explicit baseRef that conflicts with a retained committed-range selector is not adopted", async (t) => {
2123
+ const { cwd, eligible, initial, target } = untrackedStopFixture(t);
2124
+ const headRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
2125
+ writeFileSync(join(cwd, "tracked.txt"), "second\n");
2126
+ execFileSync("git", ["add", "tracked.txt"], { cwd, stdio: "ignore" });
2127
+ execFileSync("git", ["-c", "user.name=Routing Test", "-c", "user.email=routing@example.invalid", "commit", "-m", "second"], { cwd, stdio: "ignore" });
2128
+ const otherRef = execFileSync("git", ["rev-parse", "HEAD"], { cwd, encoding: "utf8" }).trim();
2129
+ const readyTarget = startStatus(cwd, otherRef);
2130
+ const starts: Array<Record<string, unknown>> = [],
2131
+ retained = new Map();
2132
+ const native = {
2133
+ targetStatus: async (request: Record<string, unknown>) =>
2134
+ request.baseRef === otherRef ? readyTarget : ("intendedUntrackedSelection" in request ? target : initial),
2135
+ start: async (request: Record<string, unknown>) => {
2136
+ starts.push(request);
2137
+ return {
2138
+ lineageId: "review-started", state: "reviewing", riskLevel: "low", selectedLenses: [],
2139
+ changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: false,
2140
+ riskReasons: [], raw: {},
2141
+ };
2142
+ },
2143
+ } as unknown as NativeReviewCli;
2144
+ await __testing.executeReviewControllerOperation(
2145
+ {
2146
+ operation: "inspect",
2147
+ input: JSON.stringify({ baseRef: headRef, committedOnly: true }),
2148
+ untrackedScope: "select",
2149
+ intendedUntracked: [eligible],
2150
+ },
2151
+ cwd, native, undefined, undefined, undefined, retained,
2152
+ );
2153
+ const retainedEntry = retained.get(`${cwd}\u0000`) as { baseRef?: string } | undefined;
2154
+ assert.equal(retainedEntry?.baseRef, headRef);
2155
+
2156
+ const started = await __testing.executeReviewControllerOperation(
2157
+ { operation: "start", input: JSON.stringify({ mode: "ordinary", baseRef: otherRef, committedOnly: true }) },
2158
+ cwd, native, undefined, undefined, undefined, retained,
2159
+ );
2160
+ assert.equal(started.operation, "start");
2161
+ assert.equal(starts.length, 1);
2162
+ assert.equal(starts[0]!.baseRef, otherRef);
2163
+ // The conflicting explicit START never adopts the retained scope/inventory.
2164
+ assert.equal("untrackedScope" in starts[0]!, false);
2165
+ // A successful START always clears the pre-lineage "" entry (gentle-pi#706),
2166
+ // whether or not it consumed it: a new lineage invalidates any stale
2167
+ // pre-lineage selection regardless of this START's own adoption choice.
2168
+ assert.equal(retained.has(`${cwd}\u0000`), false);
2169
+ });
2170
+
1565
2171
  test("START rejects a retained pre-lineage selection when fresh STATUS identifies a changed candidate", async (t) => {
1566
2172
  const { cwd, eligible, initial, target } = untrackedStopFixture(t);
1567
2173
  const retained = new Map();