gentle-pi 2.0.0 → 2.1.1

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.
@@ -84,7 +84,7 @@ function fakeNative(overrides: Partial<NativeReviewCli> = {}): NativeReviewCli {
84
84
  sddStatus: async () => ({ ready: false }),
85
85
  reviewStatus: async () => ({ schema: "gentle-ai.review-authority-status/v1", repository: "/repo", complete: true, authoritative: true, status: "clean", entries: [], locks: [], diagnostics: [], raw: { schema: "gentle-ai.review-authority-status/v1", operation: "review/status", repository: "/repo", complete: true, authoritative: true, status: "clean", entries: [], locks: [], diagnostics: [] } }),
86
86
  targetStatus: async (request) => request.lineageId === undefined
87
- ? targetStatusFixture({ applicability: "unrelated", action: "start" })
87
+ ? candidateStartTargetStatus(request)
88
88
  : targetStatusFixture({ lineageId: request.lineageId }),
89
89
  ...overrides,
90
90
  };
@@ -102,21 +102,26 @@ function targetStatusFixture(options: {
102
102
  applicability?: "current_target" | "unrelated";
103
103
  action?: ReviewStatusV3["action"];
104
104
  lineageId?: string;
105
+ baseTree?: string;
106
+ currentCandidateTree?: string;
107
+ paths?: readonly string[];
105
108
  } = {}): ReviewStatusV3 {
106
109
  const applicability = options.applicability ?? "current_target";
107
110
  const action = options.action ?? (applicability === "current_target" ? "finalize" : "start");
108
111
  const lineageId = options.lineageId ?? "native-lineage";
109
112
  const sha = `sha256:${"a".repeat(64)}`;
110
- const tree = "b".repeat(40);
113
+ const tree = options.currentCandidateTree ?? "b".repeat(40);
114
+ const baseTree = options.baseTree ?? tree;
115
+ const paths = options.paths ?? ["app.ts"];
111
116
  const projection = {
112
117
  schema: "gentle-ai.review-integration.projection/v1" as const,
113
118
  kind: "current-changes" as const,
114
119
  projection: "workspace" as const,
115
- baseTree: tree,
120
+ baseTree,
116
121
  initialReviewTree: tree,
117
122
  currentCandidateTree: tree,
118
123
  pathsDigest: sha,
119
- paths: ["app.ts"],
124
+ paths,
120
125
  intendedUntracked: [],
121
126
  intendedUntrackedProof: sha,
122
127
  initialSnapshotIdentity: sha,
@@ -146,11 +151,11 @@ function targetStatusFixture(options: {
146
151
  schema: projection.schema,
147
152
  kind: projection.kind,
148
153
  projection: projection.projection,
149
- base_tree: tree,
154
+ base_tree: baseTree,
150
155
  initial_review_tree: tree,
151
156
  current_candidate_tree: tree,
152
157
  paths_digest: sha,
153
- paths: projection.paths,
158
+ paths,
154
159
  intended_untracked: [],
155
160
  intended_untracked_proof: sha,
156
161
  initial_snapshot_identity: sha,
@@ -178,6 +183,25 @@ function targetStatusFixture(options: {
178
183
  };
179
184
  }
180
185
 
186
+ function candidateStartTargetStatus(request: Parameters<NonNullable<NativeReviewCli["targetStatus"]>>[0]): ReviewStatusV3 {
187
+ let candidate: ReturnType<CandidateViewRegistry["create"]> | undefined;
188
+ try {
189
+ candidate = new CandidateViewRegistry().create({
190
+ contributorRoot: request.cwd,
191
+ ...(request.baseRef === undefined ? {} : { baseRef: request.baseRef, committedOnly: true }),
192
+ });
193
+ return targetStatusFixture({
194
+ applicability: "unrelated",
195
+ action: "start",
196
+ baseTree: candidate.baseTree,
197
+ currentCandidateTree: candidate.candidateTree,
198
+ paths: candidate.paths,
199
+ });
200
+ } finally {
201
+ candidate?.cleanup();
202
+ }
203
+ }
204
+
181
205
  test("INSPECT and STATUS operate on the explicit workspace root while the session cwd stays elsewhere", async (t) => {
182
206
  const sessionCwd = repository(t);
183
207
  const worktree = addWorktree(t, sessionCwd, "feat-binding");
@@ -200,10 +224,10 @@ test("START freezes the candidate from the explicit workspace root and returns t
200
224
  const worktree = addWorktree(t, sessionCwd, "feat-candidate");
201
225
  writeFileSync(join(worktree, "app.ts"), "export const value = 2; // worktree candidate\n");
202
226
  const candidateViews = new CandidateViewRegistry();
203
- const startCwds: string[] = [];
227
+ const startRequests: Parameters<NativeReviewCli["start"]>[0][] = [];
204
228
  const { controller, toolCall } = runtime(fakeNative({
205
229
  start: async (request) => {
206
- startCwds.push(request.cwd);
230
+ startRequests.push(request);
207
231
  return { lineageId: "worktree-lineage", state: "reviewing", riskLevel: "medium", selectedLenses: ["review-reliability"], changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: true };
208
232
  },
209
233
  }), candidateViews);
@@ -219,7 +243,8 @@ test("START freezes the candidate from the explicit workspace root and returns t
219
243
  const view = candidateViews.resolveForLens("worktree-lineage", "review-reliability");
220
244
  assert.equal(details.actor_binding.candidate_root, view.root);
221
245
  assert.equal(details.actor_binding.candidate_tree, view.candidateTree);
222
- assert.deepEqual(startCwds, [view.root]);
246
+ assert.deepEqual(startRequests, [{ cwd: root, targetIdentity: `sha256:${"a".repeat(64)}`, projection: "workspace" }]);
247
+ assert.notEqual(startRequests[0]?.cwd, view.root);
223
248
  assert.equal(readFileSync(join(view.root, "app.ts"), "utf8"), "export const value = 2; // worktree candidate\n");
224
249
  assert.equal(view.paths.includes("unrelated.ts"), false);
225
250
  const dispatch = { agent: "review-reliability", task: "review the change", mode: "task" };
@@ -234,8 +259,12 @@ test("absent workspaceRoot keeps the session-cwd flow and still reports the acto
234
259
  const sessionCwd = repository(t);
235
260
  writeFileSync(join(sessionCwd, "app.ts"), "export const value = 3;\n");
236
261
  const candidateViews = new CandidateViewRegistry();
262
+ const startRequests: Parameters<NativeReviewCli["start"]>[0][] = [];
237
263
  const { controller } = runtime(fakeNative({
238
- start: async () => ({ lineageId: "session-lineage", state: "reviewing", riskLevel: "medium", selectedLenses: ["review-reliability"], changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: true }),
264
+ start: async (request) => {
265
+ startRequests.push(request);
266
+ return { lineageId: "session-lineage", state: "reviewing", riskLevel: "medium", selectedLenses: ["review-reliability"], changedFiles: 1, changedLines: 1, correctionBudget: 1, action: "created", lensesRequired: true };
267
+ },
239
268
  }), candidateViews);
240
269
  const started = await controller.execute("start-session", { operation: "start", input: JSON.stringify({ mode: "ordinary" }) }, undefined, undefined, context(sessionCwd));
241
270
  const details = started.details as {
@@ -245,6 +274,7 @@ test("absent workspaceRoot keeps the session-cwd flow and still reports the acto
245
274
  assert.equal(details.workspace_root, sessionCwd);
246
275
  assert.equal(details.actor_binding.workspace_root, sessionCwd);
247
276
  assert.deepEqual(details.actor_binding.candidate_paths, ["app.ts"]);
277
+ assert.deepEqual(startRequests, [{ cwd: sessionCwd, targetIdentity: `sha256:${"a".repeat(64)}`, projection: "workspace" }]);
248
278
  const view = candidateViews.resolveForLens("session-lineage", "review-reliability");
249
279
  assert.equal(details.actor_binding.candidate_root, view.root);
250
280
  candidateViews.cleanup(view.token);
@@ -482,7 +482,7 @@ test("shipped controller and orchestrator contracts specify inspect-first compac
482
482
  assert.match(toolContract, /RESET.*reclaim.*RECOVER.*recover/s);
483
483
  assert.match(toolContract, /native-input-required.*never.*invent/is);
484
484
  assert.match(toolContract, /output.*lost|response.*lost|ambiguous.*START/is);
485
- assert.match(toolContract, /ambiguous START or FINALIZE.*target-scoped native status.*declared action/is);
485
+ assert.match(toolContract, /ambiguous START, answer-consent, or FINALIZE.*target-scoped native status.*declared action/is);
486
486
  assert.doesNotMatch(toolContract, /START throws.*lineage does not exist/is);
487
487
 
488
488
  for (const path of ["assets/orchestrator-delegation.md", "skills/gentle-ai/SKILL.md"]) {
@@ -387,15 +387,24 @@ test("failure context accepts scope_change or binding_revision but rejects both
387
387
  assert.throws(() => decodeReviewFailureV2(both), /exactly one|not allowed/);
388
388
  });
389
389
 
390
- test("consent rejects a swapped choice order and an invocation missing the exact answer suffix", () => {
390
+ test("consent rejects a swapped choice order, invalid answer domain, or invocation outside the frozen target", () => {
391
391
  const source = fixture<JsonObject>("consent.fixture.json");
392
392
  const swapped = clone(source);
393
393
  swapped.choices = [(source.choices as JsonObject[])[1], (source.choices as JsonObject[])[0]];
394
394
  assert.throws(() => decodeReviewConsentV2(swapped), /answer/);
395
395
 
396
+ const badAnswer = clone(source);
397
+ (badAnswer.choices as JsonObject[])[0].answer = "yes";
398
+ assert.throws(() => decodeReviewConsentV2(badAnswer), /answer/);
399
+
396
400
  const badInvocation = clone(source);
397
401
  (badInvocation.choices as JsonObject[])[0].invocation = "gentle-ai review start --contract gentle-ai.review-integration/v1 --consent granted";
398
402
  assert.throws(() => decodeReviewConsentV2(badInvocation), /invocation/);
403
+
404
+ const differentTarget = clone(source);
405
+ (differentTarget.choices as JsonObject[])[0].invocation = String((differentTarget.choices as JsonObject[])[0].invocation)
406
+ .replace(String(differentTarget.target_identity), `sha256:${"b".repeat(64)}`);
407
+ assert.throws(() => decodeReviewConsentV2(differentTarget), /target|invocation/);
399
408
  });
400
409
 
401
410
  test("next_transition decodes an execute variant and rejects a stop that carries a transition", () => {
@@ -364,13 +364,19 @@ async function run() {
364
364
  const toolCwd = await tempWorkspace();
365
365
  try {
366
366
  const toolHook = hooks.get("tool_call")[0];
367
+ const ghPrCwd = await tempWorkspace();
368
+ try {
369
+ execFileSync("git", ["init"], { cwd: ghPrCwd, stdio: "ignore" });
370
+ const receiptGate = await toolHook(
371
+ { toolName: "bash", input: { command: "gh pr create --draft" } },
372
+ createCtx(ghPrCwd, true, "receipt-gate-session"),
373
+ );
374
+ assert.equal(receiptGate.block, true);
375
+ assert.match(receiptGate.reason, /exactly derive.*--base/i);
376
+ } finally {
377
+ await rm(ghPrCwd, { recursive: true, force: true });
378
+ }
367
379
  assert.equal(await toolHook({ toolName: "bash", input: { command: "git status" } }, createCtx(toolCwd)), undefined);
368
- const receiptGate = await toolHook(
369
- { toolName: "bash", input: { command: "gh pr create --draft" } },
370
- createCtx(toolCwd, true, "receipt-gate-session"),
371
- );
372
- assert.equal(receiptGate.block, true);
373
- assert.match(receiptGate.reason, /exactly derive.*--base/i);
374
380
  const denied = await toolHook({ toolName: "bash", input: { command: "rm -rf /" } }, createCtx(toolCwd));
375
381
  assert.equal(denied.block, true);
376
382
  assert.match(denied.reason, /destructive/);
@@ -399,12 +405,18 @@ async function run() {
399
405
  0,
400
406
  "receipt validation must not launch or announce review actors",
401
407
  );
402
- const commitGate = await toolHook(
403
- { toolName: "bash", input: { command: "git commit -m bounded" } },
404
- createCtx(toolCwd),
405
- );
406
- assert.equal(commitGate.block, true);
407
- assert.match(commitGate.reason, /exactly derive/i);
408
+ const commitCwd = await tempWorkspace();
409
+ try {
410
+ execFileSync("git", ["init"], { cwd: commitCwd, stdio: "ignore" });
411
+ const commitGate = await toolHook(
412
+ { toolName: "bash", input: { command: "git commit -m bounded tracked.txt" } },
413
+ createCtx(commitCwd),
414
+ );
415
+ assert.equal(commitGate.block, true);
416
+ assert.match(commitGate.reason, /exactly derive/i);
417
+ } finally {
418
+ await rm(commitCwd, { recursive: true, force: true });
419
+ }
408
420
  } finally {
409
421
  await rm(toolCwd, { recursive: true, force: true });
410
422
  }