gentle-pi 2.2.0 → 2.4.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 (160) hide show
  1. package/README.md +76 -79
  2. package/assets/agents/review-readability.md +0 -2
  3. package/assets/agents/review-reliability.md +0 -2
  4. package/assets/agents/review-resilience.md +0 -2
  5. package/assets/agents/review-risk.md +0 -2
  6. package/assets/agents/sdd-apply.md +5 -3
  7. package/assets/agents/sdd-explore.md +1 -0
  8. package/assets/agents/sdd-proposal.md +2 -0
  9. package/assets/agents/sdd-research.md +54 -0
  10. package/assets/agents/sdd-status.md +4 -4
  11. package/assets/agents/sdd-tasks.md +2 -3
  12. package/assets/agents/sdd-verify.md +21 -1
  13. package/assets/chains/sdd-full.chain.md +1 -1
  14. package/assets/chains/sdd-verify.chain.md +1 -1
  15. package/assets/orchestrator-delegation.md +56 -249
  16. package/assets/orchestrator-memory.md +2 -0
  17. package/assets/orchestrator.md +20 -40
  18. package/assets/sdd-orchestrator-workflow.md +30 -37
  19. package/assets/support/sdd-status-contract.md +7 -7
  20. package/contracts/review-integration/v1/schemas/transition-execution.schema.json +42 -0
  21. package/contracts/review-integration/v2/schemas/last-event-closure.schema.json +66 -0
  22. package/contracts/review-integration/v2/schemas/opencode-provider-role.schema.json +14 -0
  23. package/contracts/review-provider-contract-mirror/provider-contract.lock.json +8 -7
  24. package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/bundle/README.md +10 -0
  25. package/contracts/review-provider-contract-mirror/v1.2.0/bundle/manifest.json +74 -0
  26. package/contracts/review-provider-contract-mirror/v1.2.0/bundle/orchestration/pi.md +53 -0
  27. package/contracts/review-provider-contract-mirror/v1.2.0/bundle/schemas/targeted-validator.schema.json +1 -0
  28. package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/generated/provider-capabilities.baseline.json +9 -2
  29. package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/generated/provider-roles.baseline.json +2 -2
  30. package/docs/native-authority-architecture.md +9 -11
  31. package/docs/review-integration.md +27 -373
  32. package/extensions/ask-user-choice.ts +151 -0
  33. package/extensions/gentle-ai.ts +2349 -3785
  34. package/extensions/quiet-tools.ts +515 -32
  35. package/extensions/sdd-init.ts +4 -8
  36. package/lib/agent-home.ts +8 -0
  37. package/lib/gentle-ai-renderer.ts +70 -0
  38. package/lib/model-routing-authority.ts +133 -0
  39. package/lib/native-review-cli.ts +387 -940
  40. package/lib/opaque-pi-reviewer-adapter.ts +284 -0
  41. package/lib/provider-contract-bundle.ts +88 -6
  42. package/lib/review-candidate-view.ts +341 -132
  43. package/lib/review-host-relay.ts +324 -96
  44. package/lib/review-integration-v2.ts +868 -307
  45. package/lib/review-last-event-controller.ts +35 -0
  46. package/lib/sdd-preflight.ts +179 -68
  47. package/lib/sdd-status.ts +66 -111
  48. package/lib/terminal-theme.ts +1 -1
  49. package/package.json +83 -82
  50. package/runtime/gentle-ai-binary.mjs +1 -1
  51. package/runtime/native-review-cli.mjs +337 -890
  52. package/runtime/review-integration-v2.mjs +816 -255
  53. package/runtime/review-relay-contract.mjs +1 -1
  54. package/scripts/{build-git-commit-transaction-runner.mjs → build-runtime-modules.mjs} +4 -5
  55. package/scripts/gentle-ai-installer.mjs +75 -22
  56. package/scripts/maintainer/provider-relay-matrix.mjs +195 -11
  57. package/scripts/test-packed-runner.mjs +4 -7
  58. package/scripts/verify-package-files.mjs +23 -23
  59. package/skills/_shared/review-ledger-contract.md +14 -14
  60. package/skills/chained-pr/SKILL.md +3 -0
  61. package/skills/cognitive-doc-design/SKILL.md +1 -1
  62. package/skills/comment-writer/SKILL.md +1 -1
  63. package/skills/gentle-ai/SKILL.md +7 -74
  64. package/skills/issue-creation/SKILL.md +53 -93
  65. package/skills/judgment-day/SKILL.md +5 -7
  66. package/skills/rdd-defect-workflow/SKILL.md +3 -3
  67. package/skills/release/SKILL.md +3 -3
  68. package/skills/skill-registry/SKILL.md +1 -1
  69. package/skills/work-unit-commits/SKILL.md +3 -1
  70. package/tests/artifact-language.test.ts +24 -11
  71. package/tests/ask-user-choice.test.ts +264 -0
  72. package/tests/codegraph-tools.test.ts +3 -3
  73. package/tests/crosslane/cross-lane.mjs +15 -1168
  74. package/tests/delegated-key-learnings-contract.test.ts +8 -6
  75. package/tests/devbinary/native-review-parity.devtest.ts +167 -250
  76. package/tests/devbinary/pi-host-relay.devtest.ts +867 -0
  77. package/tests/fixtures/devbinary/last-event-capture-correction-plan.captured.json +10 -0
  78. package/tests/fixtures/devbinary/last-event-capture-refuter-approved.captured.json +20 -0
  79. package/tests/fixtures/devbinary/last-event-capture-refuter-correction-required.captured.json +26 -0
  80. package/tests/fixtures/devbinary/last-event-capture-result-approved.captured.json +8 -0
  81. package/tests/fixtures/devbinary/last-event-capture-result-correction-required.captured.json +26 -0
  82. package/tests/fixtures/devbinary/last-event-capture-validation-approved.captured.json +8 -0
  83. package/tests/fixtures/devbinary/last-event-closure.provenance.md +13 -0
  84. package/tests/fixtures/devbinary/review-acknowledged-v1.captured.json +9 -0
  85. package/tests/fixtures/devbinary/review-acknowledged.provenance.md +31 -0
  86. package/tests/fixtures/devbinary/start-v3-zero-lens-closed.captured.json +21 -0
  87. package/tests/fixtures/native-review-cli/v2.5.0-rc.1/PROVENANCE.txt +15 -0
  88. package/tests/fixtures/provider-contract-bundle/v1.2.0/README.md +22 -0
  89. package/{contracts/review-provider-contract-mirror/v1.1.0/bundle → tests/fixtures/provider-contract-bundle/v1.2.0}/manifest.json +11 -2
  90. package/tests/fixtures/provider-contract-bundle/v1.2.0/orchestration/pi.md +97 -0
  91. package/tests/fixtures/provider-contract-bundle/v1.2.0/schemas/lens.schema.json +16 -0
  92. package/tests/fixtures/provider-contract-bundle/v1.2.0/schemas/refuter.schema.json +1 -0
  93. package/tests/fixtures/provider-contract-bundle/v1.2.0/vectors/lens.json +1 -0
  94. package/tests/fixtures/provider-contract-bundle/v1.2.0/vectors/refuter.json +1 -0
  95. package/tests/fixtures/provider-contract-bundle/v1.2.0/vectors/targeted-validator.json +1 -0
  96. package/tests/gentle-ai-binary.test.ts +83 -13
  97. package/tests/gentle-ai-dev-binary.test.ts +51 -228
  98. package/tests/gentle-ai-installer.test.ts +137 -47
  99. package/tests/gentle-ai.test.ts +821 -131
  100. package/tests/gentle-theme.test.ts +133 -0
  101. package/tests/issue-creation-skill.test.ts +103 -0
  102. package/tests/maintainer/provider-relay.maintest.ts +340 -4
  103. package/tests/model-routing-authority.test.ts +257 -0
  104. package/tests/native-review-capability-contract.test.ts +45 -1
  105. package/tests/native-review-cli.test.ts +586 -962
  106. package/tests/native-review-consent.test.ts +150 -66
  107. package/tests/native-review-parity-runtime.test.ts +80 -359
  108. package/tests/native-review-parity.test.ts +674 -925
  109. package/tests/opaque-pi-reviewer-adapter.test.ts +266 -0
  110. package/tests/orchestrator-budget.test.ts +132 -88
  111. package/tests/orchestrator-rdd-ownership.test.ts +103 -0
  112. package/tests/package-manifest.test.ts +152 -36
  113. package/tests/provider-contract-bundle.test.ts +76 -0
  114. package/tests/provider-contract-mirror.test.ts +19 -0
  115. package/tests/provider-defect-handoff.test.ts +15 -118
  116. package/tests/quiet-tool-rendering.test.ts +1055 -28
  117. package/tests/review-agent-end-preflight.test.ts +408 -0
  118. package/tests/review-authority-recovery-docs.test.ts +1 -2
  119. package/tests/review-candidate-view.test.ts +409 -3
  120. package/tests/review-compact-contract.test.ts +4 -30
  121. package/tests/review-contract-prompt.test.ts +139 -0
  122. package/tests/review-controller-lock-status.test.ts +2 -2
  123. package/tests/review-controller-native-recovery.test.ts +363 -1450
  124. package/tests/review-controller-native-routing.test.ts +1251 -5642
  125. package/tests/review-controller-retired-ops.test.ts +1 -1
  126. package/tests/review-controller-workspace-root.test.ts +222 -71
  127. package/tests/review-controller.test.ts +26 -816
  128. package/tests/review-corrected-finalize-binding.test.ts +112 -153
  129. package/tests/review-dispatch-hydration-gap.test.ts +1 -53
  130. package/tests/review-gate.test.ts +0 -45
  131. package/tests/review-host-relay-restart-parity.test.ts +360 -0
  132. package/tests/review-host-relay-routing.test.ts +328 -91
  133. package/tests/review-host-relay.test.ts +436 -14
  134. package/tests/review-integration-v2-forward.test.ts +623 -553
  135. package/tests/review-integration-v2.test.ts +239 -165
  136. package/tests/review-last-event-closure.test.ts +408 -0
  137. package/tests/review-ledger-contract.test.ts +97 -35
  138. package/tests/review-recovered-lineage-routing.test.ts +0 -47
  139. package/tests/review-relay-transport-agent.test.ts +119 -46
  140. package/tests/review-snapshot.test.ts +3 -2
  141. package/tests/runtime-harness.mjs +362 -196
  142. package/tests/sdd-agent-tools.test.ts +36 -0
  143. package/tests/sdd-preflight.test.ts +81 -15
  144. package/tests/sdd-status.test.ts +109 -110
  145. package/tests/skill-collision-prefixes.test.ts +5 -8
  146. package/tests/writer-edit-surface-scope.test.ts +366 -0
  147. package/themes/Gentleman-Cute.json +94 -0
  148. package/themes/Gentleman-Sexy.json +92 -0
  149. package/lib/git-commit-transaction.ts +0 -861
  150. package/runtime/git-commit-transaction.mjs +0 -862
  151. package/scripts/run-git-commit-transaction.mjs +0 -35
  152. package/tests/fixtures/native-review-cli/v2.1.3/sdd-status-engram.json +0 -139
  153. package/tests/fixtures/native-review-cli/v2.1.3/sdd-status.json +0 -200
  154. package/tests/git-commit-transaction.test.ts +0 -530
  155. /package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/bundle/schemas/lens.schema.json +0 -0
  156. /package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/bundle/schemas/refuter.schema.json +0 -0
  157. /package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/bundle/vectors/lens.json +0 -0
  158. /package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/bundle/vectors/refuter.json +0 -0
  159. /package/contracts/review-provider-contract-mirror/{v1.1.0 → v1.2.0}/bundle/vectors/targeted-validator.json +0 -0
  160. /package/{contracts/review-provider-contract-mirror/v1.1.0/bundle → tests/fixtures/provider-contract-bundle/v1.2.0}/schemas/targeted-validator.schema.json +0 -0
@@ -0,0 +1,408 @@
1
+ import assert from "node:assert/strict";
2
+ import { mkdtemp } from "node:fs/promises";
3
+ import { tmpdir } from "node:os";
4
+ import { join } from "node:path";
5
+ import test from "node:test";
6
+ import type { ExtensionAPI, ExtensionContext } from "@earendil-works/pi-coding-agent";
7
+ import { createGentleAiExtension } from "../extensions/gentle-ai.ts";
8
+ import type { NativeReviewCli } from "../lib/native-review-cli.ts";
9
+ import type { ReviewStatusV3 } from "../lib/review-integration-v2.ts";
10
+
11
+ // gentle-pi#556 / gentle-ai#4051: with RDD enabled, the agent finished an
12
+ // implementation and reported completion without ever entering the review
13
+ // preflight. These tests cover the read-only, idempotent `agent_end` nudge
14
+ // that reminds the agent to call gentle_review before reporting completion,
15
+ // without ever starting a review or answering consent itself.
16
+ //
17
+ // gentle-pi#568: `session_start` records the target identity STATUS reports
18
+ // at session start as a baseline, so `agent_end` skips a candidate that
19
+ // already existed before this session touched the worktree (the user's own
20
+ // pre-session work, not this session's output). These tests point
21
+ // `GENTLE_PI_AGENT_HOME` and the session `cwd` at fresh temp directories so
22
+ // `session_start`'s real SDD asset install and model config sweep never
23
+ // touch this machine's actual home directory.
24
+
25
+ type AnyHandler = (event: unknown, ctx: ExtensionContext) => unknown;
26
+ type SentMessage = { message: Record<string, unknown>; options: Record<string, unknown> };
27
+
28
+ function harness(nativeReviewCli: NativeReviewCli | null): {
29
+ handlers: Map<string, AnyHandler>;
30
+ sent: SentMessage[];
31
+ } {
32
+ const handlers = new Map<string, AnyHandler>();
33
+ const sent: SentMessage[] = [];
34
+ const pi = {
35
+ on(name: string, handler: AnyHandler) {
36
+ handlers.set(name, handler);
37
+ },
38
+ events: { emit() {} },
39
+ registerCommand() {},
40
+ registerTool() {},
41
+ sendMessage(message: Record<string, unknown>, options: Record<string, unknown> = {}) {
42
+ sent.push({ message, options });
43
+ },
44
+ } as unknown as ExtensionAPI;
45
+ createGentleAiExtension({ nativeReviewCli })(pi);
46
+ return { handlers, sent };
47
+ }
48
+
49
+ function ctx(sessionId: string, hasUI = true, cwd = process.cwd()): ExtensionContext {
50
+ return {
51
+ cwd,
52
+ hasUI,
53
+ ui: { notify() {} },
54
+ sessionManager: { getSessionId: () => sessionId },
55
+ } as unknown as ExtensionContext;
56
+ }
57
+
58
+ async function withSessionStartEnv<T>(callback: (cwd: string) => Promise<T>): Promise<T> {
59
+ const previousAgentHome = process.env.GENTLE_PI_AGENT_HOME;
60
+ const previousConfigHome = process.env.GENTLE_PI_CONFIG_HOME;
61
+ process.env.GENTLE_PI_AGENT_HOME = await mkdtemp(join(tmpdir(), "gentle-pi-session-baseline-agent-home-"));
62
+ // Isolates both the model-config sweep and the dev-binary registration
63
+ // lookup from this machine's real ~/.pi/gentle-ai, so `session_start`'s
64
+ // unrelated notifications never leak into these assertions.
65
+ process.env.GENTLE_PI_CONFIG_HOME = await mkdtemp(join(tmpdir(), "gentle-pi-session-baseline-config-home-"));
66
+ try {
67
+ const cwd = await mkdtemp(join(tmpdir(), "gentle-pi-session-baseline-cwd-"));
68
+ return await callback(cwd);
69
+ } finally {
70
+ if (previousAgentHome === undefined) delete process.env.GENTLE_PI_AGENT_HOME;
71
+ else process.env.GENTLE_PI_AGENT_HOME = previousAgentHome;
72
+ if (previousConfigHome === undefined) delete process.env.GENTLE_PI_CONFIG_HOME;
73
+ else process.env.GENTLE_PI_CONFIG_HOME = previousConfigHome;
74
+ }
75
+ }
76
+
77
+ function onMode(effective: "on" | "off"): NativeReviewCli["reviewMode"] {
78
+ return async () => ({
79
+ operation: "status",
80
+ scope: "clone",
81
+ status: { global: "", cloneLocal: effective === "on" ? "on" : "", effective, source: "clone_local" },
82
+ });
83
+ }
84
+
85
+ function executeStartStatus(targetIdentity: string): ReviewStatusV3 {
86
+ return {
87
+ applicability: "unrelated",
88
+ action: "start",
89
+ targetIdentity,
90
+ nextTransition: { kind: "execute", execute: { operation: "review.start", arguments: [] } },
91
+ } as unknown as ReviewStatusV3;
92
+ }
93
+
94
+ function collectStatus(targetIdentity: string): ReviewStatusV3 {
95
+ return {
96
+ applicability: "unrelated",
97
+ action: "start",
98
+ targetIdentity,
99
+ nextTransition: { kind: "collect", collect: { inputs: [] } },
100
+ } as unknown as ReviewStatusV3;
101
+ }
102
+
103
+ function stopStatus(targetIdentity: string): ReviewStatusV3 {
104
+ return {
105
+ applicability: "unrelated",
106
+ action: "start",
107
+ targetIdentity,
108
+ nextTransition: { kind: "stop" },
109
+ } as unknown as ReviewStatusV3;
110
+ }
111
+
112
+ const agentEndEvent = { type: "agent_end", messages: [] };
113
+
114
+ test("agent_end performs no STATUS call and sends nothing when RDD is off", async () => {
115
+ const statusRequests: unknown[] = [];
116
+ const native = {
117
+ reviewMode: onMode("off"),
118
+ targetStatus: async (request: unknown) => {
119
+ statusRequests.push(request);
120
+ throw new Error("targetStatus must not be called when RDD is off");
121
+ },
122
+ } as unknown as NativeReviewCli;
123
+ const { handlers, sent } = harness(native);
124
+ const agentEnd = handlers.get("agent_end");
125
+ assert.equal(typeof agentEnd, "function");
126
+ await agentEnd!(agentEndEvent, ctx("agent-end-rdd-off"));
127
+ assert.deepEqual(statusRequests, []);
128
+ assert.deepEqual(sent, []);
129
+ });
130
+
131
+ test("agent_end nudges exactly once when RDD is on and STATUS offers review.start", async () => {
132
+ const targetIdentity = `sha256:${"a".repeat(64)}`;
133
+ const statusRequests: Array<{ agent?: string }> = [];
134
+ const native = {
135
+ reviewMode: onMode("on"),
136
+ targetStatus: async (request: { agent?: string }) => {
137
+ statusRequests.push(request);
138
+ return executeStartStatus(targetIdentity);
139
+ },
140
+ } as unknown as NativeReviewCli;
141
+ const { handlers, sent } = harness(native);
142
+ const agentEnd = handlers.get("agent_end");
143
+ await agentEnd!(agentEndEvent, ctx("agent-end-execute"));
144
+
145
+ assert.equal(sent.length, 1);
146
+ const [entry] = sent;
147
+ assert.equal(entry?.message.customType, "gentle-pi.review-preflight");
148
+ const content = String(entry?.message.content);
149
+ assert.match(content, /gentle_review/);
150
+ assert.ok(content.includes(targetIdentity), "message must name the target identity");
151
+ assert.equal(entry?.options.triggerTurn, true);
152
+ assert.equal(statusRequests[0]?.agent, "pi");
153
+ });
154
+
155
+ test("agent_end nudges once per target identity and again for a fresh identity", async () => {
156
+ let targetIdentity = `sha256:${"b".repeat(64)}`;
157
+ const native = {
158
+ reviewMode: onMode("on"),
159
+ targetStatus: async () => executeStartStatus(targetIdentity),
160
+ } as unknown as NativeReviewCli;
161
+ const { handlers, sent } = harness(native);
162
+ const agentEnd = handlers.get("agent_end");
163
+ const session = ctx("agent-end-repeat");
164
+
165
+ await agentEnd!(agentEndEvent, session);
166
+ await agentEnd!(agentEndEvent, session);
167
+ assert.equal(sent.length, 1, "the same target identity nudges only once");
168
+
169
+ targetIdentity = `sha256:${"e".repeat(64)}`;
170
+ await agentEnd!(agentEndEvent, session);
171
+ assert.equal(sent.length, 2, "a different target identity nudges again");
172
+ });
173
+
174
+ test("agent_end sends nothing when STATUS offers collect or stop", async () => {
175
+ for (const [label, status] of [
176
+ ["collect", collectStatus(`sha256:${"c".repeat(64)}`)],
177
+ ["stop", stopStatus(`sha256:${"d".repeat(64)}`)],
178
+ ] as const) {
179
+ const native = {
180
+ reviewMode: onMode("on"),
181
+ targetStatus: async () => status,
182
+ } as unknown as NativeReviewCli;
183
+ const { handlers, sent } = harness(native);
184
+ const agentEnd = handlers.get("agent_end");
185
+ await agentEnd!(agentEndEvent, ctx(`agent-end-${label}`));
186
+ assert.deepEqual(sent, [], label);
187
+ }
188
+ });
189
+
190
+ test("agent_end skips headless sessions before any native call", async () => {
191
+ const native = {
192
+ reviewMode: async () => {
193
+ throw new Error("reviewMode must not be called when hasUI is false");
194
+ },
195
+ targetStatus: async () => {
196
+ throw new Error("targetStatus must not be called when hasUI is false");
197
+ },
198
+ } as unknown as NativeReviewCli;
199
+ const { handlers, sent } = harness(native);
200
+ const agentEnd = handlers.get("agent_end");
201
+ await agentEnd!(agentEndEvent, ctx("agent-end-no-ui", false));
202
+ assert.deepEqual(sent, []);
203
+ });
204
+
205
+ test("agent_end pairs a named agent's start with its own end, then still nudges for the primary loop's end", async () => {
206
+ const targetIdentity = `sha256:${"f".repeat(64)}`;
207
+ const native = {
208
+ reviewMode: onMode("on"),
209
+ targetStatus: async () => executeStartStatus(targetIdentity),
210
+ } as unknown as NativeReviewCli;
211
+ const { handlers, sent } = harness(native);
212
+ const beforeAgentStart = handlers.get("before_agent_start");
213
+ const agentEnd = handlers.get("agent_end");
214
+ assert.equal(typeof beforeAgentStart, "function");
215
+ const session = ctx("agent-end-subagent");
216
+
217
+ await beforeAgentStart!({ agentName: "review-readability", systemPrompt: "" }, session);
218
+ await agentEnd!(agentEndEvent, session);
219
+ assert.deepEqual(sent, [], "the subagent's own loop end is suppressed");
220
+
221
+ await agentEnd!(agentEndEvent, session);
222
+ assert.equal(sent.length, 1, "the primary loop's end still nudges once the subagent's end is paired off");
223
+ });
224
+
225
+ test("agent_end resets the subagent depth when a fresh primary loop starts", async () => {
226
+ const targetIdentity = `sha256:${"1".repeat(64)}`;
227
+ const native = {
228
+ reviewMode: onMode("on"),
229
+ targetStatus: async () => executeStartStatus(targetIdentity),
230
+ } as unknown as NativeReviewCli;
231
+ const { handlers, sent } = harness(native);
232
+ const beforeAgentStart = handlers.get("before_agent_start");
233
+ const agentEnd = handlers.get("agent_end");
234
+ const session = ctx("agent-end-subagent-reset");
235
+
236
+ await beforeAgentStart!({ agentName: "review-readability", systemPrompt: "" }, session);
237
+ await beforeAgentStart!({ systemPrompt: "" }, session);
238
+ await agentEnd!(agentEndEvent, session);
239
+
240
+ assert.equal(sent.length, 1, "a fresh primary-loop start resets the depth so its own end nudges");
241
+ });
242
+
243
+ test("agent_end handler exists but sends nothing when nativeReviewCli is null", async () => {
244
+ const { handlers, sent } = harness(null);
245
+ const agentEnd = handlers.get("agent_end");
246
+ assert.equal(typeof agentEnd, "function");
247
+ await agentEnd!(agentEndEvent, ctx("agent-end-null-cli"));
248
+ assert.deepEqual(sent, []);
249
+ });
250
+
251
+ test("agent_end sends nothing and does not throw when target STATUS rejects", async () => {
252
+ const native = {
253
+ reviewMode: onMode("on"),
254
+ targetStatus: async () => {
255
+ throw new Error("native status unavailable");
256
+ },
257
+ } as unknown as NativeReviewCli;
258
+ const { handlers, sent } = harness(native);
259
+ const agentEnd = handlers.get("agent_end");
260
+ await assert.doesNotReject(async () => agentEnd!(agentEndEvent, ctx("agent-end-status-throws")));
261
+ assert.deepEqual(sent, []);
262
+ });
263
+
264
+ test("session_shutdown clears the nudged-target set for its session key", async () => {
265
+ const targetIdentity = `sha256:${"9".repeat(64)}`;
266
+ const native = {
267
+ reviewMode: onMode("on"),
268
+ targetStatus: async () => executeStartStatus(targetIdentity),
269
+ } as unknown as NativeReviewCli;
270
+ const { handlers, sent } = harness(native);
271
+ const agentEnd = handlers.get("agent_end");
272
+ const shutdown = handlers.get("session_shutdown");
273
+ assert.equal(typeof shutdown, "function");
274
+ const session = ctx("agent-end-shutdown");
275
+
276
+ await agentEnd!(agentEndEvent, session);
277
+ assert.equal(sent.length, 1);
278
+
279
+ await shutdown!({}, session);
280
+ await agentEnd!(agentEndEvent, session);
281
+ assert.equal(sent.length, 2, "shutdown clears the nudged set so the same identity nudges again");
282
+ });
283
+
284
+ test("session_start records the baseline target identity when RDD is on", async () => {
285
+ const targetIdentity = `sha256:${"2".repeat(64)}`;
286
+ const statusRequests: Array<{ agent?: string }> = [];
287
+ const native = {
288
+ reviewMode: onMode("on"),
289
+ targetStatus: async (request: { agent?: string }) => {
290
+ statusRequests.push(request);
291
+ return executeStartStatus(targetIdentity);
292
+ },
293
+ } as unknown as NativeReviewCli;
294
+ await withSessionStartEnv(async (cwd) => {
295
+ const { handlers, sent } = harness(native);
296
+ const sessionStart = handlers.get("session_start");
297
+ assert.equal(typeof sessionStart, "function");
298
+ const notifications: Array<{ message: string; severity: string }> = [];
299
+ const session = {
300
+ ...ctx("session-baseline-record", true, cwd),
301
+ ui: { notify: (message: string, severity: string) => notifications.push({ message, severity }) },
302
+ };
303
+ await sessionStart!({}, session);
304
+ assert.equal(statusRequests[0]?.agent, "pi");
305
+ assert.deepEqual(sent, []);
306
+ assert.deepEqual(notifications, []);
307
+ });
308
+ });
309
+
310
+ test("agent_end skips the candidate that matches the session's recorded baseline, then nudges for a new one", async () => {
311
+ let targetIdentity = `sha256:${"3".repeat(64)}`;
312
+ const native = {
313
+ reviewMode: onMode("on"),
314
+ targetStatus: async () => executeStartStatus(targetIdentity),
315
+ } as unknown as NativeReviewCli;
316
+ await withSessionStartEnv(async (cwd) => {
317
+ const { handlers, sent } = harness(native);
318
+ const sessionStart = handlers.get("session_start");
319
+ const agentEnd = handlers.get("agent_end");
320
+ const session = ctx("session-baseline-skip", true, cwd);
321
+
322
+ await sessionStart!({}, session);
323
+ await agentEnd!(agentEndEvent, session);
324
+ assert.deepEqual(sent, [], "the baseline candidate predates the session and is not nudged");
325
+
326
+ targetIdentity = `sha256:${"4".repeat(64)}`;
327
+ await agentEnd!(agentEndEvent, session);
328
+ assert.equal(sent.length, 1, "a candidate identity different from the baseline still nudges");
329
+ });
330
+ });
331
+
332
+ test("session_start with RDD off records no baseline, so agent_end still reminds once", async () => {
333
+ const targetIdentity = `sha256:${"5".repeat(64)}`;
334
+ let mode: "on" | "off" = "off";
335
+ const statusRequests: unknown[] = [];
336
+ const native = {
337
+ reviewMode: async () => ({
338
+ operation: "status",
339
+ scope: "clone",
340
+ status: { global: "", cloneLocal: mode === "on" ? "on" : "", effective: mode, source: "clone_local" },
341
+ }),
342
+ targetStatus: async (request: unknown) => {
343
+ statusRequests.push(request);
344
+ if (mode === "off") throw new Error("targetStatus must not be called when RDD is off");
345
+ return executeStartStatus(targetIdentity);
346
+ },
347
+ } as unknown as NativeReviewCli;
348
+ await withSessionStartEnv(async (cwd) => {
349
+ const { handlers, sent } = harness(native);
350
+ const sessionStart = handlers.get("session_start");
351
+ const agentEnd = handlers.get("agent_end");
352
+ const session = ctx("session-baseline-rdd-off", true, cwd);
353
+
354
+ await sessionStart!({}, session);
355
+ assert.deepEqual(statusRequests, []);
356
+
357
+ mode = "on";
358
+ await agentEnd!(agentEndEvent, session);
359
+ assert.equal(sent.length, 1, "no baseline was recorded while RDD was off, so the first dirty candidate still reminds");
360
+ });
361
+ });
362
+
363
+ test("session_start whose targetStatus rejects records no baseline, so agent_end still reminds once", async () => {
364
+ const targetIdentity = `sha256:${"6".repeat(64)}`;
365
+ let shouldThrow = true;
366
+ const native = {
367
+ reviewMode: onMode("on"),
368
+ targetStatus: async () => {
369
+ if (shouldThrow) throw new Error("native status unavailable at session start");
370
+ return executeStartStatus(targetIdentity);
371
+ },
372
+ } as unknown as NativeReviewCli;
373
+ await withSessionStartEnv(async (cwd) => {
374
+ const { handlers, sent } = harness(native);
375
+ const sessionStart = handlers.get("session_start");
376
+ const agentEnd = handlers.get("agent_end");
377
+ const session = ctx("session-baseline-throws", true, cwd);
378
+
379
+ await assert.doesNotReject(async () => sessionStart!({}, session));
380
+
381
+ shouldThrow = false;
382
+ await agentEnd!(agentEndEvent, session);
383
+ assert.equal(sent.length, 1, "STATUS threw at session_start, so no baseline was recorded and the candidate still reminds");
384
+ });
385
+ });
386
+
387
+ test("session_shutdown clears the recorded baseline so the same identity reminds again", async () => {
388
+ const targetIdentity = `sha256:${"7".repeat(64)}`;
389
+ const native = {
390
+ reviewMode: onMode("on"),
391
+ targetStatus: async () => executeStartStatus(targetIdentity),
392
+ } as unknown as NativeReviewCli;
393
+ await withSessionStartEnv(async (cwd) => {
394
+ const { handlers, sent } = harness(native);
395
+ const sessionStart = handlers.get("session_start");
396
+ const agentEnd = handlers.get("agent_end");
397
+ const shutdown = handlers.get("session_shutdown");
398
+ const session = ctx("session-baseline-shutdown", true, cwd);
399
+
400
+ await sessionStart!({}, session);
401
+ await agentEnd!(agentEndEvent, session);
402
+ assert.deepEqual(sent, [], "the baseline candidate is skipped");
403
+
404
+ await shutdown!({}, session);
405
+ await agentEnd!(agentEndEvent, session);
406
+ assert.equal(sent.length, 1, "shutdown cleared the baseline, so the same identity reminds again in the next session");
407
+ });
408
+ });
@@ -17,11 +17,10 @@ test("recovery guidance documents the narrow published native maintenance contra
17
17
  assert.match(README, /review dispose-result.*unsupported.*pending.*design/i);
18
18
  assert.match(README, /RESET.*RECOVER.*destructive/i);
19
19
  assert.match(README, /typed envelopes/i);
20
- assert.match(README, /pre-commit.*pre-push.*pre-PR.*release/is);
21
20
  });
22
21
 
23
22
  test("controller help keeps authorization, blocked outcomes, and recovery boundaries explicit", () => {
24
- assert.match(CONTROLLER, /v2\.1\.11 repair-legacy-alias.*fresh native inventory.*fresh UI approval/is);
23
+ assert.match(CONTROLLER, /REPAIR_LEGACY_ALIAS.*freshly reads native inventory.*interactive approval/is);
25
24
  assert.match(CONTROLLER, /unchanged_target,malformed_recovery_authorization/);
26
25
  assert.match(CONTROLLER, /provider-selected recovery disposition/);
27
26
  assert.match(CONTROLLER, /headlessly|headless/i);