gentle-pi 2.2.0 → 2.3.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.
- package/README.md +51 -80
- package/assets/agents/review-readability.md +0 -2
- package/assets/agents/review-reliability.md +0 -2
- package/assets/agents/review-resilience.md +0 -2
- package/assets/agents/review-risk.md +0 -2
- package/assets/agents/sdd-apply.md +5 -3
- package/assets/agents/sdd-proposal.md +2 -0
- package/assets/agents/sdd-research.md +54 -0
- package/assets/agents/sdd-status.md +4 -4
- package/assets/agents/sdd-tasks.md +2 -3
- package/assets/agents/sdd-verify.md +21 -1
- package/assets/chains/sdd-full.chain.md +1 -1
- package/assets/chains/sdd-verify.chain.md +1 -1
- package/assets/orchestrator-delegation.md +54 -248
- package/assets/orchestrator-memory.md +2 -0
- package/assets/orchestrator.md +22 -38
- package/assets/sdd-orchestrator-workflow.md +30 -37
- package/assets/support/sdd-status-contract.md +7 -7
- package/contracts/review-integration/v1/schemas/transition-execution.schema.json +42 -0
- package/contracts/review-integration/v2/schemas/last-event-closure.schema.json +66 -0
- package/contracts/review-integration/v2/schemas/opencode-provider-role.schema.json +14 -0
- package/docs/native-authority-architecture.md +9 -11
- package/docs/review-integration.md +27 -373
- package/extensions/ask-user-choice.ts +151 -0
- package/extensions/gentle-ai.ts +1778 -3673
- package/extensions/quiet-tools.ts +515 -32
- package/extensions/sdd-init.ts +4 -8
- package/lib/gentle-ai-renderer.ts +70 -0
- package/lib/model-routing-authority.ts +133 -0
- package/lib/native-review-cli.ts +372 -940
- package/lib/opaque-pi-reviewer-adapter.ts +284 -0
- package/lib/review-candidate-view.ts +341 -132
- package/lib/review-host-relay.ts +210 -68
- package/lib/review-integration-v2.ts +839 -307
- package/lib/review-last-event-controller.ts +35 -0
- package/lib/sdd-preflight.ts +177 -66
- package/lib/sdd-status.ts +66 -111
- package/lib/terminal-theme.ts +1 -1
- package/package.json +83 -82
- package/runtime/gentle-ai-binary.mjs +1 -1
- package/runtime/native-review-cli.mjs +322 -890
- package/runtime/review-integration-v2.mjs +789 -257
- package/runtime/review-relay-contract.mjs +1 -1
- package/scripts/{build-git-commit-transaction-runner.mjs → build-runtime-modules.mjs} +4 -5
- package/scripts/gentle-ai-installer.mjs +75 -22
- package/scripts/maintainer/provider-relay-matrix.mjs +195 -11
- package/scripts/test-packed-runner.mjs +4 -7
- package/scripts/verify-package-files.mjs +12 -13
- package/skills/_shared/review-ledger-contract.md +8 -14
- package/skills/chained-pr/SKILL.md +3 -0
- package/skills/cognitive-doc-design/SKILL.md +1 -1
- package/skills/comment-writer/SKILL.md +1 -1
- package/skills/gentle-ai/SKILL.md +7 -74
- package/skills/judgment-day/SKILL.md +5 -7
- package/skills/rdd-defect-workflow/SKILL.md +3 -3
- package/skills/release/SKILL.md +3 -3
- package/skills/skill-registry/SKILL.md +1 -1
- package/skills/work-unit-commits/SKILL.md +3 -1
- package/tests/artifact-language.test.ts +24 -11
- package/tests/ask-user-choice.test.ts +264 -0
- package/tests/codegraph-tools.test.ts +3 -3
- package/tests/crosslane/cross-lane.mjs +15 -1168
- package/tests/delegated-key-learnings-contract.test.ts +8 -6
- package/tests/devbinary/native-review-parity.devtest.ts +167 -250
- package/tests/devbinary/pi-host-relay.devtest.ts +867 -0
- package/tests/fixtures/devbinary/last-event-capture-correction-plan.captured.json +10 -0
- package/tests/fixtures/devbinary/last-event-capture-refuter-approved.captured.json +20 -0
- package/tests/fixtures/devbinary/last-event-capture-refuter-correction-required.captured.json +26 -0
- package/tests/fixtures/devbinary/last-event-capture-result-approved.captured.json +8 -0
- package/tests/fixtures/devbinary/last-event-capture-result-correction-required.captured.json +26 -0
- package/tests/fixtures/devbinary/last-event-capture-validation-approved.captured.json +8 -0
- package/tests/fixtures/devbinary/last-event-closure.provenance.md +13 -0
- package/tests/fixtures/devbinary/review-acknowledged-v1.captured.json +9 -0
- package/tests/fixtures/devbinary/review-acknowledged.provenance.md +31 -0
- package/tests/fixtures/devbinary/start-v3-zero-lens-closed.captured.json +21 -0
- package/tests/fixtures/native-review-cli/v2.5.0-rc.1/PROVENANCE.txt +15 -0
- package/tests/gentle-ai-binary.test.ts +83 -13
- package/tests/gentle-ai-dev-binary.test.ts +51 -228
- package/tests/gentle-ai-installer.test.ts +137 -47
- package/tests/gentle-ai.test.ts +820 -131
- package/tests/gentle-theme.test.ts +133 -0
- package/tests/maintainer/provider-relay.maintest.ts +340 -4
- package/tests/model-routing-authority.test.ts +257 -0
- package/tests/native-review-capability-contract.test.ts +28 -1
- package/tests/native-review-cli.test.ts +586 -962
- package/tests/native-review-consent.test.ts +150 -66
- package/tests/native-review-parity-runtime.test.ts +80 -359
- package/tests/native-review-parity.test.ts +674 -925
- package/tests/opaque-pi-reviewer-adapter.test.ts +266 -0
- package/tests/orchestrator-budget.test.ts +132 -88
- package/tests/orchestrator-rdd-ownership.test.ts +103 -0
- package/tests/package-manifest.test.ts +37 -35
- package/tests/provider-defect-handoff.test.ts +15 -118
- package/tests/quiet-tool-rendering.test.ts +1055 -28
- package/tests/review-authority-recovery-docs.test.ts +1 -2
- package/tests/review-candidate-view.test.ts +409 -3
- package/tests/review-compact-contract.test.ts +4 -30
- package/tests/review-controller-lock-status.test.ts +2 -2
- package/tests/review-controller-native-recovery.test.ts +363 -1450
- package/tests/review-controller-native-routing.test.ts +1251 -5642
- package/tests/review-controller-retired-ops.test.ts +1 -1
- package/tests/review-controller-workspace-root.test.ts +222 -71
- package/tests/review-controller.test.ts +26 -816
- package/tests/review-corrected-finalize-binding.test.ts +112 -153
- package/tests/review-dispatch-hydration-gap.test.ts +1 -53
- package/tests/review-gate.test.ts +0 -45
- package/tests/review-host-relay-restart-parity.test.ts +360 -0
- package/tests/review-host-relay-routing.test.ts +117 -82
- package/tests/review-host-relay.test.ts +242 -8
- package/tests/review-integration-v2-forward.test.ts +576 -553
- package/tests/review-integration-v2.test.ts +239 -165
- package/tests/review-last-event-closure.test.ts +408 -0
- package/tests/review-ledger-contract.test.ts +97 -35
- package/tests/review-recovered-lineage-routing.test.ts +0 -47
- package/tests/review-relay-transport-agent.test.ts +119 -46
- package/tests/review-snapshot.test.ts +3 -2
- package/tests/runtime-harness.mjs +361 -196
- package/tests/sdd-agent-tools.test.ts +36 -0
- package/tests/sdd-preflight.test.ts +81 -15
- package/tests/sdd-status.test.ts +109 -110
- package/tests/skill-collision-prefixes.test.ts +5 -8
- package/tests/writer-edit-surface-scope.test.ts +230 -0
- package/themes/Gentleman-Cute.json +94 -0
- package/themes/Gentleman-Sexy.json +92 -0
- package/lib/git-commit-transaction.ts +0 -861
- package/runtime/git-commit-transaction.mjs +0 -862
- package/scripts/run-git-commit-transaction.mjs +0 -35
- package/tests/fixtures/native-review-cli/v2.1.3/sdd-status-engram.json +0 -139
- package/tests/fixtures/native-review-cli/v2.1.3/sdd-status.json +0 -200
- package/tests/git-commit-transaction.test.ts +0 -530
|
@@ -1,23 +1,22 @@
|
|
|
1
|
-
// Generated by scripts/build-
|
|
1
|
+
// Generated by scripts/build-runtime-modules.mjs. Do not edit.
|
|
2
2
|
import { execFile } from "node:child_process";
|
|
3
|
-
import { createHash } from "node:crypto";
|
|
4
|
-
import { readFileSync, statSync } from "node:fs";
|
|
5
3
|
import { chmod, mkdtemp, realpath, rm, writeFile } from "node:fs/promises";
|
|
6
4
|
import { tmpdir } from "node:os";
|
|
7
5
|
import { dirname, isAbsolute, join, posix, win32 } from "node:path";
|
|
8
6
|
import { promisify } from "node:util";
|
|
9
|
-
import {
|
|
7
|
+
import { PackageLocalGentleAiBinaryMissingError, resolveGentleAiBinary } from "./gentle-ai-binary.mjs";
|
|
10
8
|
import { GENTLE_PI_REVIEW_RELAY_CONTRACT, GENTLE_PI_REVIEW_RELAY_CONTRACT_ENV } from "./review-relay-contract.mjs";
|
|
11
9
|
import {
|
|
12
10
|
REVIEW_INTEGRATION_CONTRACT,
|
|
13
|
-
|
|
11
|
+
decodeReviewAcknowledgedV1,
|
|
14
12
|
decodeReviewConsentV2,
|
|
15
13
|
decodeReviewConsentV3,
|
|
16
14
|
decodeReviewFailureV2,
|
|
17
|
-
|
|
15
|
+
decodeReviewLastEventClosureV1,
|
|
18
16
|
decodeReviewRepairV2,
|
|
19
17
|
decodeReviewResultArtifactV2,
|
|
20
18
|
decodeReviewStartV3,
|
|
19
|
+
decodeReviewStartV4,
|
|
21
20
|
decodeReviewStatusV3,
|
|
22
21
|
|
|
23
22
|
|
|
@@ -25,6 +24,11 @@ import {
|
|
|
25
24
|
|
|
26
25
|
|
|
27
26
|
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
|
|
28
32
|
} from "./review-integration-v2.mjs";
|
|
29
33
|
|
|
30
34
|
const execFileAsync = promisify(execFile);
|
|
@@ -47,12 +51,7 @@ function resolveNativeReviewMaxBufferBytes(environment = proc
|
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
export const NATIVE_REVIEW_OPERATION = {
|
|
50
|
-
VERSION: "version",
|
|
51
54
|
START: "review/start",
|
|
52
|
-
FINALIZE: "review/finalize",
|
|
53
|
-
VALIDATE: "review/validate",
|
|
54
|
-
BIND_SDD: "review/bind-sdd",
|
|
55
|
-
SDD_STATUS: "sdd-status",
|
|
56
55
|
STATUS: "review/status",
|
|
57
56
|
RECLAIM: "review/reclaim",
|
|
58
57
|
RECOVER: "review/recover",
|
|
@@ -62,9 +61,10 @@ export const NATIVE_REVIEW_OPERATION = {
|
|
|
62
61
|
REPAIR_LEGACY_ALIAS: "review/repair-legacy-alias",
|
|
63
62
|
MODE: "review/mode",
|
|
64
63
|
REPAIR: "review/repair",
|
|
65
|
-
CAPTURE_EVIDENCE: "review/capture-evidence",
|
|
66
64
|
CAPTURE_RESULT: "review/capture-result",
|
|
65
|
+
CAPTURE_CORRECTION_PLAN: "review/capture-correction-plan",
|
|
67
66
|
CAPTURE_PROVIDER_ROLE: "review/capture-provider-role",
|
|
67
|
+
ACKNOWLEDGE_APPROVED: "review/acknowledge-approved",
|
|
68
68
|
} ;
|
|
69
69
|
|
|
70
70
|
|
|
@@ -86,57 +86,6 @@ export const NATIVE_REVIEW_ERROR_CODE = {
|
|
|
86
86
|
} ;
|
|
87
87
|
|
|
88
88
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export const NATIVE_SDD_ARTIFACT_STORE = {
|
|
94
|
-
OPENSPEC: "openspec",
|
|
95
|
-
ENGRAM: "engram",
|
|
96
|
-
NONE: "none",
|
|
97
|
-
} ;
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
export const NATIVE_SDD_ARTIFACT_STATE = {
|
|
101
|
-
MISSING: "missing",
|
|
102
|
-
DONE: "done",
|
|
103
|
-
PARTIAL: "partial",
|
|
104
|
-
} ;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
89
|
|
|
141
90
|
|
|
142
91
|
|
|
@@ -184,6 +133,12 @@ export const NATIVE_REVIEW_MODE_SOURCE = {
|
|
|
184
133
|
} ;
|
|
185
134
|
|
|
186
135
|
|
|
136
|
+
export const NATIVE_REVIEW_MODE_REACH = {
|
|
137
|
+
MACHINE: "machine",
|
|
138
|
+
THIS_BUILD: "this_build",
|
|
139
|
+
} ;
|
|
140
|
+
|
|
141
|
+
|
|
187
142
|
export const NATIVE_REVIEW_MODE_SCOPE = {
|
|
188
143
|
GLOBAL: "global",
|
|
189
144
|
CLONE: "clone",
|
|
@@ -209,6 +164,7 @@ export const NATIVE_REVIEW_MODE_SCOPE = {
|
|
|
209
164
|
|
|
210
165
|
|
|
211
166
|
|
|
167
|
+
|
|
212
168
|
|
|
213
169
|
|
|
214
170
|
// Exact-match tolerated-stderr allowlist for START only, gated on the `mode`
|
|
@@ -368,26 +324,12 @@ export const NATIVE_REVIEW_LEGACY_ALIAS_REPAIR = {
|
|
|
368
324
|
|
|
369
325
|
|
|
370
326
|
|
|
371
|
-
// `review capture-evidence` argv and response shape are pinned to a real
|
|
372
|
-
// v2.2.2 review run (lineage review-b39d803b68a90767): exactly
|
|
373
|
-
// --cwd/--lineage/--target/--expected-revision/--outcome/--input, no
|
|
374
|
-
// --contract, and the `gentle-ai.review-verification-evidence/v2` record
|
|
375
|
-
// returned directly (not wrapped in an operation/v2 envelope).
|
|
376
|
-
export const NATIVE_REVIEW_CAPTURE_OUTCOME = ["passed", "verification_failed", "procedural_tooling_failed"] ;
|
|
377
|
-
|
|
378
|
-
|
|
379
327
|
// `capture-result` is an additive headless command, NOT a negotiated
|
|
380
328
|
// repository operation: it accepts no --contract, and the provider's own
|
|
381
329
|
// transition tokens already carry the repository context -- it takes that or
|
|
382
330
|
// --cwd, never both. So Pi passes the tokens through verbatim and adds only
|
|
383
331
|
// --input. Reconstructing them would mean re-deriving a lineage, revision,
|
|
384
332
|
// target, lens slot, and subject hash the provider already issued.
|
|
385
|
-
// Added for the v2 finalize transport. `capturedResults` asks the provider to
|
|
386
|
-
// discover every manifest it already admitted; `resultArtifactFiles` hands them
|
|
387
|
-
// over explicitly in lens order. Both replace the retired `--result`.
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
333
|
|
|
392
334
|
|
|
393
335
|
|
|
@@ -406,60 +348,16 @@ export const NATIVE_REVIEW_CAPTURE_OUTCOME = ["passed", "verification_failed", "
|
|
|
406
348
|
|
|
407
349
|
|
|
408
350
|
|
|
351
|
+
/** A non-final reviewer capture acknowledges an admitted artifact; final captures close natively. */
|
|
409
352
|
|
|
410
353
|
|
|
411
|
-
//
|
|
412
|
-
// provider
|
|
413
|
-
//
|
|
414
|
-
//
|
|
415
|
-
//
|
|
416
|
-
//
|
|
417
|
-
//
|
|
418
|
-
export const NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_SCHEMA = "gentle-ai.review-provider-role-capture/v1";
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
// Field defect (fambig, 2026-08-16): the evidence collect slot renders the
|
|
449
|
-
// exact submission tokens native admits — fix-diff `--target`,
|
|
450
|
-
// `--expected-revision`, and an opaque cwd-independent `--repository-context` —
|
|
451
|
-
// with `{{outcome}}`/`{{input}}` substitution slots. Satisfying the slot means
|
|
452
|
-
// executing those tokens verbatim with only the two slot substitutions, the
|
|
453
|
-
// same discipline captureResult uses; identities are never reconstructed from
|
|
454
|
-
// top-level status fields.
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
354
|
+
// The one continuation that burns approved authority. Its tokens are rendered
|
|
355
|
+
// by the provider in a closed order and are relayed verbatim: Pi never builds,
|
|
356
|
+
// reorders, or substitutes one, because a synthesized acknowledgement would be
|
|
357
|
+
// Pi deciding that a review is over. `binding` is the lineage, target, and
|
|
358
|
+
// revision the caller already holds from STATUS: when the provider answers the
|
|
359
|
+
// burn with a review-acknowledged/v1 envelope (gentle-ai #3947), that envelope
|
|
360
|
+
// must name exactly this burn.
|
|
463
361
|
|
|
464
362
|
|
|
465
363
|
|
|
@@ -467,6 +365,7 @@ export const NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_SCHEMA = "gentle-ai.review-prov
|
|
|
467
365
|
|
|
468
366
|
|
|
469
367
|
|
|
368
|
+
/** `undefined` is the pinned silent burn (every release up to v2.5.0-rc.3); an envelope is the #3947 typed burn. */
|
|
470
369
|
|
|
471
370
|
|
|
472
371
|
|
|
@@ -476,14 +375,31 @@ export const NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_SCHEMA = "gentle-ai.review-prov
|
|
|
476
375
|
|
|
477
376
|
|
|
478
377
|
|
|
378
|
+
// gentle-pi#311 P4-roles: one Go-owned non-lens provider role capture. The
|
|
379
|
+
// provider renders a SELF-CONTAINED authority-advancing vector
|
|
380
|
+
// (`review.capture-refuter` / `review.capture-validation` with binding tokens
|
|
381
|
+
// plus `--agent=pi --execute=true`, no submission descriptor); Pi executes the
|
|
382
|
+
// exact rendered invocation verbatim, in the foreground, and Go materializes
|
|
383
|
+
// the role prompt, spawns its own locked-down pi subprocess, and admits the
|
|
384
|
+
// raw verdict. Nothing here authors, parses, or transports role output.
|
|
385
|
+
export const NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_SCHEMA = "gentle-ai.review-provider-role-capture/v1";
|
|
479
386
|
|
|
387
|
+
// Capture operations and their terminal closure operations are independently
|
|
388
|
+
// named upstream. Keep this closed mapping explicit: capture-validation is the
|
|
389
|
+
// intentionally nonuniform `review/capture-validation` closure operation.
|
|
390
|
+
export const NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_CLOSURE_OPERATION = {
|
|
391
|
+
"review.capture-refuter": "review.capture-refuter",
|
|
392
|
+
"review.capture-validation": "review/capture-validation",
|
|
393
|
+
} ;
|
|
480
394
|
|
|
481
395
|
|
|
396
|
+
function isNativeReviewProviderRoleCaptureOperation(operation ) {
|
|
397
|
+
return Object.hasOwn(NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_CLOSURE_OPERATION, operation);
|
|
398
|
+
}
|
|
482
399
|
|
|
483
400
|
|
|
484
401
|
|
|
485
402
|
|
|
486
|
-
export const NATIVE_REVIEW_CONSENT_ANSWER = { GRANTED: "granted", DECLINED: "declined" } ;
|
|
487
403
|
|
|
488
404
|
|
|
489
405
|
|
|
@@ -499,8 +415,13 @@ export const NATIVE_REVIEW_CONSENT_ANSWER = { GRANTED: "granted", DECLINED: "dec
|
|
|
499
415
|
|
|
500
416
|
|
|
501
417
|
|
|
418
|
+
/** Refuter and validator captures close only when they are the native last event. */
|
|
502
419
|
|
|
503
420
|
|
|
421
|
+
export const NATIVE_UNTRACKED_SCOPE = {
|
|
422
|
+
EXCLUDE: "exclude",
|
|
423
|
+
SELECT: "select",
|
|
424
|
+
} ;
|
|
504
425
|
|
|
505
426
|
|
|
506
427
|
|
|
@@ -514,25 +435,18 @@ export const NATIVE_REVIEW_CONSENT_ANSWER = { GRANTED: "granted", DECLINED: "dec
|
|
|
514
435
|
|
|
515
436
|
|
|
516
437
|
|
|
517
|
-
// gentle-pi#311 P5: the provider-driven FINALIZE. `argumentTokens` are the
|
|
518
|
-
// exact rendered tokens of one provider-returned `review.finalize` execute
|
|
519
|
-
// transition (e.g. `--lineage=<id> --captured-results=true`), passed through
|
|
520
|
-
// verbatim and never synthesized or reordered by the host.
|
|
521
438
|
|
|
522
439
|
|
|
523
440
|
|
|
524
441
|
|
|
525
442
|
|
|
526
443
|
|
|
527
|
-
// The provider-rendered `finalize` submission descriptor forms (status/v5):
|
|
528
|
-
// the correction PLAN slot substitutes a positive line-count literal into its
|
|
529
|
-
// {{value}} token; the TARGETED VALIDATION slot substitutes a staged validator
|
|
530
|
-
// artifact path. The tokens are self-contained and execute verbatim.
|
|
531
444
|
|
|
532
445
|
|
|
533
446
|
|
|
534
447
|
|
|
535
448
|
|
|
449
|
+
export const NATIVE_REVIEW_CONSENT_ANSWER = { GRANTED: "granted", DECLINED: "declined" } ;
|
|
536
450
|
|
|
537
451
|
|
|
538
452
|
|
|
@@ -662,18 +576,12 @@ export const NATIVE_REVIEW_RECOVERY_DISPOSITION = {
|
|
|
662
576
|
|
|
663
577
|
|
|
664
578
|
|
|
665
|
-
export const NATIVE_START_ACTION = { CREATED: "created", RESUMED: "resumed",
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
579
|
+
export const NATIVE_START_ACTION = { CREATED: "created", RESUMED: "resumed", REPLAYED: "replayed", CLOSED: "closed", BLOCKED_SCOPE_ACTION: "blocked-scope-action" } ;
|
|
675
580
|
|
|
676
581
|
|
|
582
|
+
export function isCanonicalProcessString(value ) {
|
|
583
|
+
return typeof value === "string" && value.length > 0 && value.trim() === value && !/[\u0000-\u001f\u007f]/.test(value);
|
|
584
|
+
}
|
|
677
585
|
|
|
678
586
|
|
|
679
587
|
|
|
@@ -681,10 +589,47 @@ export const NATIVE_START_ACTION = { CREATED: "created", RESUMED: "resumed", REU
|
|
|
681
589
|
|
|
682
590
|
|
|
683
591
|
|
|
592
|
+
function isNativeUntrackedPath(value ) {
|
|
593
|
+
return isCanonicalProcessString(value)
|
|
594
|
+
&& !posix.isAbsolute(value)
|
|
595
|
+
&& !win32.isAbsolute(value)
|
|
596
|
+
&& !value.includes("\\")
|
|
597
|
+
&& value.split("/").every((segment) => segment.length > 0 && segment !== "." && segment !== "..");
|
|
598
|
+
}
|
|
684
599
|
|
|
600
|
+
function nativeUntrackedSelection(request ) {
|
|
601
|
+
const { untrackedScope, expectedUntrackedInventory, intendedUntracked } = request;
|
|
602
|
+
const declared = untrackedScope !== undefined || expectedUntrackedInventory !== undefined || intendedUntracked !== undefined;
|
|
603
|
+
if (!declared) return {};
|
|
604
|
+
if (
|
|
605
|
+
(untrackedScope !== NATIVE_UNTRACKED_SCOPE.EXCLUDE && untrackedScope !== NATIVE_UNTRACKED_SCOPE.SELECT) ||
|
|
606
|
+
!isCanonicalProcessString(expectedUntrackedInventory) ||
|
|
607
|
+
(intendedUntracked !== undefined && (!Array.isArray(intendedUntracked) || intendedUntracked.some((path) => !isNativeUntrackedPath(path) || intendedUntracked.indexOf(path) !== intendedUntracked.lastIndexOf(path))))
|
|
608
|
+
) {
|
|
609
|
+
throw new TypeError("Native untracked selection must declare one scope, one inventory digest, and unique repository-relative paths");
|
|
610
|
+
}
|
|
611
|
+
if (untrackedScope === NATIVE_UNTRACKED_SCOPE.EXCLUDE && (intendedUntracked?.length ?? 0) > 0) {
|
|
612
|
+
throw new TypeError("Native exclude untracked selection cannot include paths");
|
|
613
|
+
}
|
|
614
|
+
if (untrackedScope === NATIVE_UNTRACKED_SCOPE.SELECT && (intendedUntracked?.length ?? 0) === 0) {
|
|
615
|
+
throw new TypeError("Native select untracked selection requires at least one path");
|
|
616
|
+
}
|
|
617
|
+
return {
|
|
618
|
+
untrackedScope,
|
|
619
|
+
expectedUntrackedInventory,
|
|
620
|
+
intendedUntracked: intendedUntracked === undefined ? undefined : [...intendedUntracked],
|
|
621
|
+
};
|
|
622
|
+
}
|
|
685
623
|
|
|
686
|
-
|
|
687
|
-
|
|
624
|
+
function nativeUntrackedSelectionArguments(selection ) {
|
|
625
|
+
if (selection.untrackedScope === undefined) return [];
|
|
626
|
+
return [
|
|
627
|
+
`--untracked-scope=${selection.untrackedScope}`,
|
|
628
|
+
`--expected-untracked-inventory=${selection.expectedUntrackedInventory }`,
|
|
629
|
+
...(selection.untrackedScope === NATIVE_UNTRACKED_SCOPE.SELECT
|
|
630
|
+
? selection.intendedUntracked .map((path) => `--intended-untracked=${path}`)
|
|
631
|
+
: []),
|
|
632
|
+
];
|
|
688
633
|
}
|
|
689
634
|
|
|
690
635
|
const NATIVE_RISK_LEVEL = ["low", "medium", "high"] ;
|
|
@@ -765,28 +710,21 @@ export function nativeRiskEvidencePhrases(riskLevel , reasons
|
|
|
765
710
|
return riskLevel === "medium" ? [REVIEW_MEDIUM_RISK_REASON, ...phrases] : phrases;
|
|
766
711
|
}
|
|
767
712
|
const NATIVE_REVIEW_LENS = ["review-risk", "review-resilience", "review-readability", "review-reliability"] ;
|
|
768
|
-
const NATIVE_FINALIZE_STATE = ["reviewing", "correction_required", "validating", "approved", "escalated"] ;
|
|
769
713
|
const NATIVE_START_ACTION_VALUES = Object.values(NATIVE_START_ACTION);
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
const NATIVE_SDD_POST_REVIEW_ACTION = ["verify", "archive"] ;
|
|
774
|
-
|
|
775
|
-
// Organic-parity columns (mode, riskEvidence, hint, delivery) stay false on
|
|
776
|
-
// every shipped row, including "2.1.11". PI-2 adds the first capability-true
|
|
777
|
-
// row (and bumps the triple pin) in one dedicated commit — never one without
|
|
778
|
-
// the other. See Design Decision #1 (organic-rdd-parity).
|
|
714
|
+
// The pin table is intentionally preserved unchanged while #3587 is
|
|
715
|
+
// unpublished. Last-event capture support is exercised through the explicit
|
|
716
|
+
// dev-binary override; no source-level pin or contract-row mutation is allowed.
|
|
779
717
|
const ORGANIC_PARITY_DARK = { mode: false, riskEvidence: false, hint: false, delivery: false } ;
|
|
780
718
|
|
|
781
719
|
export const NATIVE_CLI_CONTRACTS = Object.freeze({
|
|
782
|
-
"2.1.4": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
783
|
-
"2.1.5": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
784
|
-
"2.1.6": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
785
|
-
"2.1.7": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
786
|
-
"2.1.8": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
787
|
-
"2.1.9": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
788
|
-
"2.1.10": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
789
|
-
"2.1.11": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
720
|
+
"2.1.4": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: false, inventory: false, reclaim: false, recover: false, abandon: false, quarantineLegacy: false, reconcileAuthority: false, repairLegacyAlias: false, ...ORGANIC_PARITY_DARK }),
|
|
721
|
+
"2.1.5": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: false, recover: false, abandon: false, quarantineLegacy: false, reconcileAuthority: false, repairLegacyAlias: false, ...ORGANIC_PARITY_DARK }),
|
|
722
|
+
"2.1.6": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: false, recover: false, abandon: false, quarantineLegacy: false, reconcileAuthority: false, repairLegacyAlias: false, ...ORGANIC_PARITY_DARK }),
|
|
723
|
+
"2.1.7": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: false, recover: false, abandon: false, quarantineLegacy: false, reconcileAuthority: false, repairLegacyAlias: false, ...ORGANIC_PARITY_DARK }),
|
|
724
|
+
"2.1.8": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: false, quarantineLegacy: false, reconcileAuthority: true, repairLegacyAlias: false, ...ORGANIC_PARITY_DARK }),
|
|
725
|
+
"2.1.9": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: false, ...ORGANIC_PARITY_DARK }),
|
|
726
|
+
"2.1.10": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, ...ORGANIC_PARITY_DARK }),
|
|
727
|
+
"2.1.11": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, ...ORGANIC_PARITY_DARK }),
|
|
790
728
|
// First capability-true row, paired with the triple pin bump in this same
|
|
791
729
|
// commit as Design Decision #1 requires.
|
|
792
730
|
//
|
|
@@ -807,7 +745,7 @@ export const NATIVE_CLI_CONTRACTS = Object.freeze({
|
|
|
807
745
|
// needs the negotiated start envelope extended upstream, which moves a
|
|
808
746
|
// byte-pinned fixture and therefore belongs to a gentle-ai release, not to
|
|
809
747
|
// a Pi capability flip.
|
|
810
|
-
"2.2.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
748
|
+
"2.2.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
811
749
|
// 2.2.1 repeats 2.2.0 because the wire did not move for the lane Pi speaks.
|
|
812
750
|
// v2.2.1 advertises capabilities/v1.5 (protocol minor 5) on
|
|
813
751
|
// review-integration/v1, but the negotiated start envelope is still the
|
|
@@ -815,16 +753,16 @@ export const NATIVE_CLI_CONTRACTS = Object.freeze({
|
|
|
815
753
|
// they are dark on 2.2.0. The release does publish a second contract,
|
|
816
754
|
// review-integration/v2, whose `start/v3` carries base/candidate trees --
|
|
817
755
|
// but Pi does not negotiate it yet, and a row must describe the lane in use.
|
|
818
|
-
"2.2.1": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
756
|
+
"2.2.1": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
819
757
|
// 2.2.2 repeats 2.2.1 for the same reason, confirmed against the released
|
|
820
758
|
// v2.2.2 binary rather than assumed: on review-integration/v1 it still
|
|
821
759
|
// advertises capabilities/v1.5 and the negotiated start envelope is still
|
|
822
760
|
// the closed `start/v2`, so riskEvidence and hint still cannot arrive.
|
|
823
|
-
"2.2.2": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
761
|
+
"2.2.2": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
824
762
|
// Ground-truthed against the released v2.2.3 binary: the v2 lane remains
|
|
825
763
|
// protocol 2.0 with the same operation set and closed START fields consumed
|
|
826
764
|
// by Pi, so the existing capability columns are unchanged.
|
|
827
|
-
"2.2.3": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
765
|
+
"2.2.3": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
828
766
|
// Ground-truthed against the released v2.4.0 binary: the v2 lane advertises
|
|
829
767
|
// capabilities/v2.2 and answers status/v5 and consent/v3, all of which the
|
|
830
768
|
// existing decoders already read, and the START envelope Pi consumes is
|
|
@@ -834,48 +772,27 @@ export const NATIVE_CLI_CONTRACTS = Object.freeze({
|
|
|
834
772
|
// envelope reports, not whether it reports it. v2.2.4 and v2.3.0 shipped
|
|
835
773
|
// while Pi stayed on 2.2.3; they were never pinned or probed, so they get
|
|
836
774
|
// no row.
|
|
837
|
-
"2.4.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true,
|
|
775
|
+
"2.4.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
776
|
+
// Ground-truthed by driving the exact v2.5.0-rc.3 tagged build through the
|
|
777
|
+
// gentle-ai-bench driven journey corpus (exit 0), which exercises the
|
|
778
|
+
// start/status/capture/validate/mode/delivery lifecycles Pi consumes. The
|
|
779
|
+
// v2 lane advertises capabilities/v2.3 and its reviewing START is the
|
|
780
|
+
// `start/v4` continuation envelope that #499 already decodes; the closed
|
|
781
|
+
// fields Pi consumes are unchanged, so the columns match the 2.4.0 row.
|
|
782
|
+
// riskEvidence and hint stay dark: still not proven to reach the
|
|
783
|
+
// negotiated path Pi reads.
|
|
784
|
+
"2.5.0-rc.3": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
785
|
+
// Ground-truthed against the published v2.5.0 binary installed from its
|
|
786
|
+
// signed archive: `review capabilities` on the v2 lane advertises
|
|
787
|
+
// capabilities/v2.4 (protocol minor 4) and answers status/v6, consent/v3,
|
|
788
|
+
// and the `start/v4` continuation, all of which the decoders already read.
|
|
789
|
+
// The closed fields Pi consumes did not change between rc.3 and stable, so
|
|
790
|
+
// the columns match the 2.5.0-rc.3 row. riskEvidence and hint stay dark:
|
|
791
|
+
// still not proven to reach the negotiated START path Pi reads.
|
|
792
|
+
"2.5.0": Object.freeze({ start: true, finalize: true, validate: true, bindSdd: true, status: true, inventory: true, reclaim: true, recover: true, abandon: true, quarantineLegacy: true, reconcileAuthority: true, repairLegacyAlias: true, mode: true, riskEvidence: false, hint: false, delivery: true }),
|
|
838
793
|
});
|
|
839
794
|
|
|
840
795
|
|
|
841
|
-
// Testing-only capability overlay: lets tests exercise mode/riskEvidence/hint/
|
|
842
|
-
// delivery decode paths under a synthetic version key without ever making a
|
|
843
|
-
// shipped row (including "2.1.11") capability-true. Production code never
|
|
844
|
-
// calls the setter, so this is inert outside test files.
|
|
845
|
-
const nativeCliContractsTestingOverlay = new Map ();
|
|
846
|
-
export function setNativeCliContractForTesting(version , contract ) {
|
|
847
|
-
if (contract === undefined) nativeCliContractsTestingOverlay.delete(version);
|
|
848
|
-
else nativeCliContractsTestingOverlay.set(version, contract);
|
|
849
|
-
}
|
|
850
|
-
function resolvedNativeCliContract(version ) {
|
|
851
|
-
return nativeCliContractsTestingOverlay.get(version) ?? (NATIVE_CLI_CONTRACTS )[version];
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
// The latest known contract row, used as the capability floor for the
|
|
855
|
-
// explicit dev-binary override (unpinned field-test mode): a maintainer
|
|
856
|
-
// dev build is at least as capable as the newest release Pi knows. The table
|
|
857
|
-
// is declared in ascending release order, so its last key is the latest.
|
|
858
|
-
const LATEST_NATIVE_CLI_CONTRACT_VERSION = Object.keys(NATIVE_CLI_CONTRACTS).at(-1) ;
|
|
859
|
-
|
|
860
|
-
// Dev-binary override version discipline: with the override configured, a
|
|
861
|
-
// version reported outside the pinned table resolves to the latest known row;
|
|
862
|
-
// with the override absent, behavior is byte-identical to the pinned gate.
|
|
863
|
-
function effectiveNativeCliContract(version ) {
|
|
864
|
-
const pinned = resolvedNativeCliContract(version);
|
|
865
|
-
if (pinned !== undefined) return pinned;
|
|
866
|
-
return gentleAiDevBinaryOverrideConfigured() ? NATIVE_CLI_CONTRACTS[LATEST_NATIVE_CLI_CONTRACT_VERSION] : undefined;
|
|
867
|
-
}
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
796
|
|
|
880
797
|
|
|
881
798
|
|
|
@@ -956,7 +873,6 @@ function decodeSelectedLenses(value , riskLevel , lensesRequired
|
|
|
956
873
|
}
|
|
957
874
|
function enumString(value , allowed ) { const parsed = stringValue(value); if (!allowed.includes(parsed)) throw new Error("unsupported enum"); return parsed; }
|
|
958
875
|
const NATIVE_DIAGNOSTIC_TEXT_LIMIT = 4_096;
|
|
959
|
-
const NATIVE_REVIEW_DENIAL_TEXT_LIMIT = 1_024;
|
|
960
876
|
|
|
961
877
|
function sanitizeNativeDiagnosticText(value , limit = NATIVE_DIAGNOSTIC_TEXT_LIMIT) {
|
|
962
878
|
const normalized = value
|
|
@@ -971,40 +887,10 @@ function sanitizeNativeDiagnosticText(value , limit = NATIVE_DIAGNOSTIC_T
|
|
|
971
887
|
return normalized.length <= limit ? normalized : `${normalized.slice(0, limit - 14)}…[truncated]`;
|
|
972
888
|
}
|
|
973
889
|
|
|
974
|
-
function parseStructuredNativeDenial(stdout ) {
|
|
975
|
-
if (Buffer.byteLength(stdout, "utf8") > NATIVE_DIAGNOSTIC_TEXT_LIMIT * 4) return undefined;
|
|
976
|
-
try {
|
|
977
|
-
const value = exactObject(JSON.parse(stdout), ["schema", "result", "allowed", "action", "reason", "context"]);
|
|
978
|
-
const result = enumString(value.result, ["scope-changed", "invalidated", "escalated"] ) ;
|
|
979
|
-
const action = sanitizeNativeDiagnosticText(requiredString(value.action), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
980
|
-
const reason = sanitizeNativeDiagnosticText(requiredString(value.reason), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
981
|
-
const expectedAction = { "scope-changed": "create-new-lineage", invalidated: "explicit-maintainer-action", escalated: "stop" }[result];
|
|
982
|
-
if (
|
|
983
|
-
value.schema !== "gentle-ai.review-gate-result/v1" ||
|
|
984
|
-
value.allowed !== false ||
|
|
985
|
-
action !== expectedAction ||
|
|
986
|
-
!isCanonicalProcessString(action) ||
|
|
987
|
-
!isCanonicalProcessString(reason)
|
|
988
|
-
) return undefined;
|
|
989
|
-
const context = decodeGateContext(value.context).raw;
|
|
990
|
-
const rawDenial = context.denial;
|
|
991
|
-
const denial = rawDenial === undefined
|
|
992
|
-
? undefined
|
|
993
|
-
: (() => {
|
|
994
|
-
const parsed = exactObject(rawDenial, ["stage", "code"]);
|
|
995
|
-
const stage = sanitizeNativeDiagnosticText(requiredString(parsed.stage), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
996
|
-
const code = sanitizeNativeDiagnosticText(requiredString(parsed.code), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
997
|
-
if (!isCanonicalProcessString(stage) || !isCanonicalProcessString(code)) throw new Error("non-canonical denial evidence");
|
|
998
|
-
return { stage, code };
|
|
999
|
-
})();
|
|
1000
|
-
return { schema: "gentle-ai.review-gate-result/v1", result, action, reason, ...(denial === undefined ? {} : { denial }) };
|
|
1001
|
-
} catch { return undefined; }
|
|
1002
|
-
}
|
|
1003
|
-
|
|
1004
890
|
// Rebuild diagnostics from a duplicated module instance before facade output.
|
|
1005
891
|
export function sanitizeForeignNativeReviewDiagnostics(value ) {
|
|
1006
892
|
try {
|
|
1007
|
-
const raw = exactObject(value, ["operation", "error_code", "timed_out", "output_limit_exceeded"], ["exit_code", "signal", "max_buffer_bytes", "configuration_hint", "stderr"
|
|
893
|
+
const raw = exactObject(value, ["operation", "error_code", "timed_out", "output_limit_exceeded"], ["exit_code", "signal", "max_buffer_bytes", "configuration_hint", "stderr"]);
|
|
1008
894
|
const operation = enumString(raw.operation, Object.values(NATIVE_REVIEW_OPERATION)) ;
|
|
1009
895
|
const errorCode = enumString(raw.error_code, Object.values(NATIVE_REVIEW_ERROR_CODE)) ;
|
|
1010
896
|
const signal = raw.signal === undefined ? undefined : requiredString(raw.signal);
|
|
@@ -1024,23 +910,10 @@ export function sanitizeForeignNativeReviewDiagnostics(value )
|
|
|
1024
910
|
output_limit_exceeded: booleanValue(raw.output_limit_exceeded),
|
|
1025
911
|
...(maxBufferBytes === undefined ? {} : { max_buffer_bytes: maxBufferBytes, configuration_hint: configurationHint }),
|
|
1026
912
|
...(raw.stderr === undefined ? {} : { stderr: sanitizeNativeDiagnosticText(stringValue(raw.stderr)) }),
|
|
1027
|
-
...(raw.denial === undefined ? {} : { denial: sanitizeForeignStructuredDenial(raw.denial) }),
|
|
1028
913
|
};
|
|
1029
914
|
} catch { return undefined; }
|
|
1030
915
|
}
|
|
1031
916
|
|
|
1032
|
-
function sanitizeForeignStructuredDenial(value ) {
|
|
1033
|
-
const parsed = exactObject(value, ["schema", "result", "action", "reason"], ["denial"]);
|
|
1034
|
-
if (parsed.schema !== "gentle-ai.review-gate-result/v1") throw new Error("invalid denial schema");
|
|
1035
|
-
const result = enumString(parsed.result, ["scope-changed", "invalidated", "escalated"] ) ;
|
|
1036
|
-
const action = sanitizeNativeDiagnosticText(requiredString(parsed.action), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
1037
|
-
const reason = sanitizeNativeDiagnosticText(requiredString(parsed.reason), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
1038
|
-
const expectedAction = { "scope-changed": "create-new-lineage", invalidated: "explicit-maintainer-action", escalated: "stop" }[result];
|
|
1039
|
-
if (action !== expectedAction || !isCanonicalProcessString(action) || !isCanonicalProcessString(reason)) throw new Error("non-canonical denial evidence");
|
|
1040
|
-
const denial = parsed.denial === undefined ? undefined : (() => { const nested = exactObject(parsed.denial, ["stage", "code"]); const stage = sanitizeNativeDiagnosticText(requiredString(nested.stage), NATIVE_REVIEW_DENIAL_TEXT_LIMIT); const code = sanitizeNativeDiagnosticText(requiredString(nested.code), NATIVE_REVIEW_DENIAL_TEXT_LIMIT); if (!isCanonicalProcessString(stage) || !isCanonicalProcessString(code)) throw new Error("non-canonical denial evidence"); return { stage, code }; })();
|
|
1041
|
-
return { schema: "gentle-ai.review-gate-result/v1", result, action, reason, ...(denial === undefined ? {} : { denial }) };
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
917
|
function nativeProcessDiagnostics(operation , code , result , maxBufferBytes ) {
|
|
1045
918
|
const outputLimitExceeded = result?.outputLimitExceeded === true;
|
|
1046
919
|
return {
|
|
@@ -1054,7 +927,6 @@ function nativeProcessDiagnostics(operation , code
|
|
|
1054
927
|
? { max_buffer_bytes: maxBufferBytes, configuration_hint: NATIVE_REVIEW_MAX_BUFFER_CONFIGURATION_HINT }
|
|
1055
928
|
: {}),
|
|
1056
929
|
...(result?.stderr.trim() ? { stderr: sanitizeNativeDiagnosticText(result.stderr) } : {}),
|
|
1057
|
-
...(result === undefined ? {} : { denial: parseStructuredNativeDenial(result.stdout) }),
|
|
1058
930
|
};
|
|
1059
931
|
}
|
|
1060
932
|
|
|
@@ -1073,39 +945,13 @@ function decodeLegacyReconcileAudit(value )
|
|
|
1073
945
|
for (const field of ["predecessor_lineage", "successor_lineage", "outcome"]) requiredString(record[field]);
|
|
1074
946
|
return { record };
|
|
1075
947
|
}
|
|
1076
|
-
function decodeNativeReviewVerificationEvidence(value ) {
|
|
1077
|
-
const body = exactObject(value, ["schema", "version", "lineage_id", "authority_revision", "target_identity", "candidate_tree", "paths_digest", "paths", "ledger_ids", "raw_payload_sha256", "raw_payload_bytes", "outcome", "record_digest"]);
|
|
1078
|
-
if (body.schema !== "gentle-ai.review-verification-evidence/v2") throw new Error("wrong verification evidence schema");
|
|
1079
|
-
return {
|
|
1080
|
-
schema: "gentle-ai.review-verification-evidence/v2",
|
|
1081
|
-
// verification-evidence.schema.json pins `version` to {"const": 2} -- the
|
|
1082
|
-
// NUMBER two, not the string. It was written as a string from a handoff
|
|
1083
|
-
// that listed the observed field NAMES without their types.
|
|
1084
|
-
version: (() => { if (body.version !== 2) throw new Error(`native verification evidence version must be the number 2, received ${JSON.stringify(body.version)}`); return 2 ; })(),
|
|
1085
|
-
lineageId: requiredString(body.lineage_id),
|
|
1086
|
-
authorityRevision: requiredString(body.authority_revision),
|
|
1087
|
-
targetIdentity: requiredString(body.target_identity),
|
|
1088
|
-
candidateTree: requiredString(body.candidate_tree),
|
|
1089
|
-
pathsDigest: requiredString(body.paths_digest),
|
|
1090
|
-
paths: stringArray(body.paths),
|
|
1091
|
-
// The schema requires ledger_ids to be an array, but v2.2.2 emits null when
|
|
1092
|
-
// there are none. Tolerated deliberately: refusing here would reject a
|
|
1093
|
-
// response the provider actually sends, and the provider violating its own
|
|
1094
|
-
// published schema is its defect to fix, not a reason to break the client.
|
|
1095
|
-
ledgerIds: body.ledger_ids === null || body.ledger_ids === undefined ? [] : stringArray(body.ledger_ids),
|
|
1096
|
-
rawPayloadSha256: requiredString(body.raw_payload_sha256),
|
|
1097
|
-
rawPayloadBytes: nonNegativeInteger(body.raw_payload_bytes),
|
|
1098
|
-
outcome: enumString(body.outcome, NATIVE_REVIEW_CAPTURE_OUTCOME) ,
|
|
1099
|
-
recordDigest: requiredString(body.record_digest),
|
|
1100
|
-
};
|
|
1101
|
-
}
|
|
1102
948
|
// Unimplemented next_transition.execute.operation values must never reach
|
|
1103
949
|
// argv synthesis. Checked against the raw pre-decode body so an operation
|
|
1104
950
|
// gentle-pi does not implement (e.g. a future `dispose-result`) fails with a
|
|
1105
951
|
// named, typed refusal instead of a generic schema-incompatible error, and
|
|
1106
952
|
// before any client ever tries to build an invocation for it (Design
|
|
1107
953
|
// Decision #6, migrate-review-integration-v2).
|
|
1108
|
-
const NATIVE_REVIEW_SUPPORTED_TRANSITION_OPERATIONS = new Set(["review.start", "review.
|
|
954
|
+
const NATIVE_REVIEW_SUPPORTED_TRANSITION_OPERATIONS = new Set(["review.start", "review.recover", "review.repair", "review.acknowledge-approved"]);
|
|
1109
955
|
function assertSupportedNextTransitionOperation(body ) {
|
|
1110
956
|
const nextTransition = body.next_transition;
|
|
1111
957
|
if (typeof nextTransition !== "object" || nextTransition === null || Array.isArray(nextTransition)) return;
|
|
@@ -1119,11 +965,23 @@ function assertSupportedNextTransitionOperation(body )
|
|
|
1119
965
|
function decode (operation , mutating , callback , diagnostics = nativeProcessDiagnostics(operation, NATIVE_REVIEW_ERROR_CODE.SCHEMA_INCOMPATIBLE)) {
|
|
1120
966
|
try { return callback(); } catch (error) { if (error instanceof NativeReviewCliError) throw error; throw new NativeReviewCliError(NATIVE_REVIEW_ERROR_CODE.SCHEMA_INCOMPATIBLE, operation, true, mutating, "native response is schema incompatible", { ...diagnostics, error_code: NATIVE_REVIEW_ERROR_CODE.SCHEMA_INCOMPATIBLE }); }
|
|
1121
967
|
}
|
|
968
|
+
function decodeReviewStartResponse(value ) {
|
|
969
|
+
const body = object(value);
|
|
970
|
+
return body.schema === "gentle-ai.review-integration.start/v4"
|
|
971
|
+
? decodeReviewStartV4(body)
|
|
972
|
+
: decodeReviewStartV3(body);
|
|
973
|
+
}
|
|
1122
974
|
function decodeReleaseEvidence(value ) {
|
|
1123
975
|
const release = exactObject(value, ["release_tree", "configuration_hash", "generated_artifact_hash", "provenance_hash", "publication_boundary_hash", "publication_state", "evidence_freshness_hash", "evidence_freshness_state"]);
|
|
1124
976
|
for (const field of ["release_tree", "configuration_hash", "generated_artifact_hash", "provenance_hash", "publication_boundary_hash", "evidence_freshness_hash"]) requiredString(release[field]);
|
|
1125
977
|
if (release.publication_state !== "sealed" || release.evidence_freshness_state !== "current") throw new Error("invalid release evidence");
|
|
1126
978
|
}
|
|
979
|
+
function decodeNonDecidingGateContext(value , expectedGate ) {
|
|
980
|
+
const context = exactObject(value, ["gate"]);
|
|
981
|
+
const gate = enumString(context.gate, NATIVE_GATE);
|
|
982
|
+
if (gate !== expectedGate) throw new Error("native non-deciding gate context does not match the requested gate");
|
|
983
|
+
return { lineageId: "", storeRevision: "", raw: context };
|
|
984
|
+
}
|
|
1127
985
|
function decodeGateContext(value ) {
|
|
1128
986
|
const context = exactObject(
|
|
1129
987
|
value,
|
|
@@ -1216,7 +1074,7 @@ function decodeNativeReviewStatusDiagnostic(value )
|
|
|
1216
1074
|
return { path: requiredString(diagnostic.path), problem: requiredString(diagnostic.problem) };
|
|
1217
1075
|
}
|
|
1218
1076
|
function decodeNativeReviewModeStatus(value ) {
|
|
1219
|
-
const status = exactObject(value, ["schema", "global", "clone_local", "effective", "source"], ["revision"]);
|
|
1077
|
+
const status = exactObject(value, ["schema", "global", "clone_local", "effective", "source"], ["revision", "reach"]);
|
|
1220
1078
|
if (status.schema !== "gentle-ai.rdd-mode-status/v1") throw new Error("wrong review mode status schema");
|
|
1221
1079
|
return {
|
|
1222
1080
|
global: enumString(status.global, Object.values(NATIVE_REVIEW_MODE_VALUE)) ,
|
|
@@ -1224,6 +1082,7 @@ function decodeNativeReviewModeStatus(value ) {
|
|
|
1224
1082
|
effective: enumString(status.effective, ["on", "off"]) ,
|
|
1225
1083
|
source: enumString(status.source, Object.values(NATIVE_REVIEW_MODE_SOURCE)) ,
|
|
1226
1084
|
...(status.revision === undefined ? {} : { revision: requiredString(status.revision) }),
|
|
1085
|
+
...(status.reach === undefined ? {} : { reach: enumString(status.reach, Object.values(NATIVE_REVIEW_MODE_REACH)) }),
|
|
1227
1086
|
};
|
|
1228
1087
|
}
|
|
1229
1088
|
|
|
@@ -1366,7 +1225,6 @@ function hasValidLensesRequired(action , state , riskLe
|
|
|
1366
1225
|
if (riskLevel === "low") return !lensesRequired;
|
|
1367
1226
|
if (action === NATIVE_START_ACTION.CREATED) return state === "reviewing" && lensesRequired;
|
|
1368
1227
|
if (action === NATIVE_START_ACTION.RESUMED) return !lensesRequired || state === "reviewing";
|
|
1369
|
-
if (action === NATIVE_START_ACTION.REUSE_RECEIPT) return state === "approved" && !lensesRequired;
|
|
1370
1228
|
return !lensesRequired;
|
|
1371
1229
|
}
|
|
1372
1230
|
|
|
@@ -1380,7 +1238,7 @@ function nativeError(code , operation
|
|
|
1380
1238
|
|
|
1381
1239
|
|
|
1382
1240
|
|
|
1383
|
-
|
|
1241
|
+
class NativeReviewPlainCli {
|
|
1384
1242
|
adapter ;
|
|
1385
1243
|
executable ;
|
|
1386
1244
|
timeoutMs ;
|
|
@@ -1426,168 +1284,14 @@ export class NativeReviewCliV214 {
|
|
|
1426
1284
|
if (result.outputLimitExceeded) throw nativeError(NATIVE_REVIEW_ERROR_CODE.OUTPUT_LIMIT, operation, mutating, "native process output exceeded limit", result, true, undefined, this.maxBufferBytes);
|
|
1427
1285
|
if (result.timedOut) throw nativeError(NATIVE_REVIEW_ERROR_CODE.TIMEOUT, operation, mutating, "native process timed out", result);
|
|
1428
1286
|
if (result.signal) throw nativeError(NATIVE_REVIEW_ERROR_CODE.SIGNAL, operation, mutating, "native process was signalled", result);
|
|
1429
|
-
const structuredValidateDenial = operation === NATIVE_REVIEW_OPERATION.VALIDATE && result.exitCode === 1;
|
|
1430
1287
|
const maintenancePartialFailure = [NATIVE_REVIEW_OPERATION.ABANDON, NATIVE_REVIEW_OPERATION.QUARANTINE_LEGACY, NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY, NATIVE_REVIEW_OPERATION.REPAIR_LEGACY_ALIAS].includes(operation) && result.exitCode !== 0;
|
|
1431
1288
|
const toleratedNotice = stderrIsTolerated(result.stderr, toleratedStderr);
|
|
1432
|
-
if (result.exitCode !== 0 && !
|
|
1433
|
-
if (result.stderr.trim().length > 0 && !
|
|
1289
|
+
if (result.exitCode !== 0 && !maintenancePartialFailure) throw nativeError(NATIVE_REVIEW_ERROR_CODE.NON_ZERO, operation, mutating, "native process failed", result);
|
|
1290
|
+
if (result.stderr.trim().length > 0 && !maintenancePartialFailure && !toleratedNotice) throw nativeError(NATIVE_REVIEW_ERROR_CODE.UNEXPECTED_STDERR, operation, mutating, "native process wrote stderr", result);
|
|
1434
1291
|
return { body: parseJson(result.stdout, operation, mutating, diagnostics), exitCode: result.exitCode, process: result };
|
|
1435
1292
|
}
|
|
1436
1293
|
|
|
1437
|
-
async verifyVersion(cwd , signal , capabilities ) {
|
|
1438
|
-
let result ;
|
|
1439
|
-
try { result = await this.adapter({ file: this.executablePath(NATIVE_REVIEW_OPERATION.VERSION, false), arguments: ["version"], cwd, timeoutMs: this.timeoutMs, maxBufferBytes: this.maxBufferBytes, signal }); }
|
|
1440
|
-
catch (error) {
|
|
1441
|
-
if (error instanceof NativeReviewCliError) throw error;
|
|
1442
|
-
if (error instanceof Error && error.name === "AbortError") throw nativeError(NATIVE_REVIEW_ERROR_CODE.CANCELLED, NATIVE_REVIEW_OPERATION.VERSION, false, "version process was cancelled");
|
|
1443
|
-
throw nativeError(NATIVE_REVIEW_ERROR_CODE.UNAVAILABLE, NATIVE_REVIEW_OPERATION.VERSION, false, "gentle-ai is unavailable");
|
|
1444
|
-
}
|
|
1445
|
-
if (result.outputLimitExceeded) throw nativeError(NATIVE_REVIEW_ERROR_CODE.OUTPUT_LIMIT, NATIVE_REVIEW_OPERATION.VERSION, false, "version process output exceeded limit", result, true, undefined, this.maxBufferBytes);
|
|
1446
|
-
if (result.timedOut) throw nativeError(NATIVE_REVIEW_ERROR_CODE.TIMEOUT, NATIVE_REVIEW_OPERATION.VERSION, false, "version process timed out", result);
|
|
1447
|
-
if (result.signal) throw nativeError(NATIVE_REVIEW_ERROR_CODE.SIGNAL, NATIVE_REVIEW_OPERATION.VERSION, false, "version process was signalled", result);
|
|
1448
|
-
if (result.exitCode !== 0) throw nativeError(NATIVE_REVIEW_ERROR_CODE.NON_ZERO, NATIVE_REVIEW_OPERATION.VERSION, false, "version process failed", result);
|
|
1449
|
-
const normalized = result.stdout.replace(/\r\n$/, "\n");
|
|
1450
|
-
const pinnedVersion = /^gentle-ai ([0-9]+\.[0-9]+\.[0-9]+)\n$/.exec(normalized)?.[1];
|
|
1451
|
-
// Dev-binary override (unpinned field-test mode): accept the binary's
|
|
1452
|
-
// reported version even when it is not a pinned three-part release
|
|
1453
|
-
// version (a main-line dev build reports e.g. "2.4.0-rc.8+fix...").
|
|
1454
|
-
// The banner shape itself stays strict. Pinned mode is byte-identical.
|
|
1455
|
-
const version = pinnedVersion ?? (gentleAiDevBinaryOverrideConfigured() ? /^gentle-ai (\S+)\n$/.exec(normalized)?.[1] : undefined);
|
|
1456
|
-
const contract = version === undefined ? undefined : effectiveNativeCliContract(version);
|
|
1457
|
-
if (result.stderr.trim().length > 0 || contract === undefined || capabilities.some((capability) => !contract[capability])) throw nativeError(NATIVE_REVIEW_ERROR_CODE.VERSION_INCOMPATIBLE, NATIVE_REVIEW_OPERATION.VERSION, false, `native gentle-ai lacks required capabilities: expected v${GENTLE_AI_VERSION}, found v${version ?? "unparseable"}`);
|
|
1458
|
-
return version ;
|
|
1459
|
-
}
|
|
1460
|
-
|
|
1461
|
-
async start(request ) {
|
|
1462
|
-
if (request.baseRef !== undefined && !isCanonicalProcessString(request.baseRef)) throw new TypeError("Native START baseRef must be a non-empty, trimmed, NUL-free string");
|
|
1463
|
-
if (request.committedOnly !== undefined && typeof request.committedOnly !== "boolean") throw new TypeError("Native START committedOnly must be a boolean when supplied");
|
|
1464
|
-
if (request.baseRef !== undefined && request.committedOnly !== true) throw new TypeError("Native START baseRef requires explicit committedOnly acknowledgement");
|
|
1465
|
-
if (request.baseRef === undefined && request.committedOnly !== undefined) throw new TypeError("Native START committedOnly requires an explicit baseRef");
|
|
1466
|
-
const version = await this.verifyVersion(request.cwd, request.signal, ["start"]);
|
|
1467
|
-
const toleratedStderr = effectiveNativeCliContract(version)?.mode === true ? REVIEW_CONSENT_NOTICES : [];
|
|
1468
|
-
const { body: result } = await this.execute(NATIVE_REVIEW_OPERATION.START, request.cwd, ["review", "start", "--cwd", request.cwd, ...(request.baseRef === undefined ? [] : ["--base-ref", request.baseRef, "--committed-only"]), ...(request.lineageId ? ["--lineage", request.lineageId] : []), ...(request.policyPath ? ["--policy", request.policyPath] : []), ...(request.focus ? ["--focus", request.focus] : [])], true, request.signal, toleratedStderr);
|
|
1469
|
-
return decode(NATIVE_REVIEW_OPERATION.START, true, () => {
|
|
1470
|
-
// `target_identity` and `lens_bindings` are real, unconditionally-present
|
|
1471
|
-
// fields on gentle-ai's plain (non-negotiated) `review start` JSON output
|
|
1472
|
-
// (confirmed against the pinned v2.1.11 Go source and live against a dev
|
|
1473
|
-
// build during Phase 6 dev-binary ground-truthing, organic-rdd-parity) —
|
|
1474
|
-
// tolerated here but not consumed: Pi's negotiated-contract client
|
|
1475
|
-
// (NativeReviewCliV216, the production default) carries lineage/target
|
|
1476
|
-
// identity through its own `review-integration/v1` decoder instead.
|
|
1477
|
-
const body = exactObject(result, ["operation", "lineage_id", "state", "risk_level", "selected_lenses", "changed_files", "changed_lines", "correction_budget", "action", "lenses_required", "projection"], ["risk_evidence", "hint", "target_identity", "lens_bindings"]);
|
|
1478
|
-
if (body.operation !== "review/start" || body.projection !== "workspace" || !(NATIVE_FINALIZE_STATE ).includes(stringValue(body.state))) throw new Error("wrong start discriminator");
|
|
1479
|
-
const lineageId = requiredString(body.lineage_id);
|
|
1480
|
-
if (request.lineageId && lineageId !== request.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, true, "native start lineage mismatch");
|
|
1481
|
-
const riskLevel = requiredString(body.risk_level);
|
|
1482
|
-
const action = enumString(body.action, NATIVE_START_ACTION_VALUES) ;
|
|
1483
|
-
const lensesRequired = booleanValue(body.lenses_required);
|
|
1484
|
-
const selectedLenses = decodeSelectedLenses(body.selected_lenses, riskLevel, lensesRequired);
|
|
1485
|
-
if (
|
|
1486
|
-
!(NATIVE_RISK_LEVEL ).includes(riskLevel) ||
|
|
1487
|
-
selectedLenses.some((lens) => !(NATIVE_REVIEW_LENS ).includes(lens)) ||
|
|
1488
|
-
!hasCanonicalSelectedLenses(riskLevel, selectedLenses) ||
|
|
1489
|
-
!hasValidLensesRequired(action, body.state , riskLevel, lensesRequired)
|
|
1490
|
-
) throw new Error("unknown or contradictory start enum");
|
|
1491
|
-
return {
|
|
1492
|
-
lineageId, state: body.state , riskLevel, selectedLenses, changedFiles: nonNegativeInteger(body.changed_files), changedLines: nonNegativeInteger(body.changed_lines), correctionBudget: nonNegativeInteger(body.correction_budget), action, lensesRequired,
|
|
1493
|
-
...(body.risk_evidence === undefined ? {} : { riskEvidence: stringArray(body.risk_evidence) }),
|
|
1494
|
-
...(body.hint === undefined ? {} : { hint: requiredString(body.hint) }),
|
|
1495
|
-
};
|
|
1496
|
-
});
|
|
1497
|
-
}
|
|
1498
|
-
|
|
1499
|
-
async stageDocument(directory , name , document ) {
|
|
1500
|
-
const path = join(directory, `${name}.json`);
|
|
1501
|
-
await writeFile(path, JSON.stringify(document), { encoding: "utf8", mode: 0o600 });
|
|
1502
|
-
await chmod(path, 0o600);
|
|
1503
|
-
return path;
|
|
1504
|
-
}
|
|
1505
|
-
async stageEvidence(directory , evidence ) {
|
|
1506
|
-
const path = join(directory, "evidence.txt");
|
|
1507
|
-
await writeFile(path, evidence, { encoding: "utf8", mode: 0o600 });
|
|
1508
|
-
await chmod(path, 0o600);
|
|
1509
|
-
return path;
|
|
1510
|
-
}
|
|
1511
|
-
|
|
1512
|
-
async finalize(request ) {
|
|
1513
|
-
if (request.evidenceDocument !== undefined && (typeof request.evidenceDocument !== "string" || request.evidenceDocument.length === 0)) throw new TypeError("Native FINALIZE evidence must contain at least one byte");
|
|
1514
|
-
await this.verifyVersion(request.cwd, request.signal, ["finalize"]);
|
|
1515
|
-
const needsStaging = request.lensResults !== undefined || request.refuterDocument !== undefined || request.validationDocument !== undefined || request.evidenceDocument !== undefined;
|
|
1516
|
-
const directory = needsStaging ? await mkdtemp(join(tmpdir(), "gentle-ai-finalize-")) : undefined;
|
|
1517
|
-
try {
|
|
1518
|
-
if (directory) await chmod(directory, 0o700);
|
|
1519
|
-
const resultFiles = directory && request.lensResults ? await Promise.all(request.lensResults.map((entry, index) => this.stageDocument(directory, `result-${index}`, entry.document))) : request.resultFiles ?? [];
|
|
1520
|
-
const refuterFile = directory && request.refuterDocument !== undefined ? await this.stageDocument(directory, "refuter", request.refuterDocument) : request.refuterFile;
|
|
1521
|
-
const validationFile = directory && request.validationDocument !== undefined ? await this.stageDocument(directory, "validation", request.validationDocument) : request.validationFile;
|
|
1522
|
-
const evidenceFile = directory && request.evidenceDocument !== undefined ? await this.stageEvidence(directory, request.evidenceDocument) : request.evidenceFile;
|
|
1523
|
-
const { body: result } = await this.execute(NATIVE_REVIEW_OPERATION.FINALIZE, request.cwd, ["review", "finalize", "--cwd", request.cwd, ...(request.lineageId ? ["--lineage", request.lineageId] : []), ...resultFiles.flatMap((path) => ["--result", path]), ...(refuterFile ? ["--refuter", refuterFile] : []), ...(request.correctionLines === undefined ? [] : ["--correction-lines", String(request.correctionLines)]), ...(validationFile ? ["--validation", validationFile] : []), ...(evidenceFile ? ["--evidence", evidenceFile] : []), ...(request.failed ? ["--failed"] : [])], true, request.signal);
|
|
1524
|
-
return decode(NATIVE_REVIEW_OPERATION.FINALIZE, true, () => {
|
|
1525
|
-
const body = exactObject(result, ["operation", "lineage_id", "state", "action", "store_revision"], ["receipt_path"]);
|
|
1526
|
-
if (body.operation !== "review/finalize") throw new Error("wrong finalize discriminator");
|
|
1527
|
-
const lineageId = requiredString(body.lineage_id);
|
|
1528
|
-
if (request.lineageId && lineageId !== request.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.FINALIZE, true, "native finalize lineage mismatch");
|
|
1529
|
-
const state = requiredString(body.state);
|
|
1530
|
-
if (!(NATIVE_FINALIZE_STATE ).includes(state)) throw new Error("unknown finalize state");
|
|
1531
|
-
return { lineageId, state, action: requiredString(body.action), storeRevision: requiredString(body.store_revision), ...(body.receipt_path === undefined ? {} : { receiptPath: requiredString(body.receipt_path) }) };
|
|
1532
|
-
});
|
|
1533
|
-
} finally { if (directory) await this.cleanupDirectory(directory).catch(() => undefined); }
|
|
1534
|
-
}
|
|
1535
|
-
|
|
1536
|
-
async validate(request ) {
|
|
1537
|
-
await this.verifyVersion(request.cwd, request.signal, ["validate"]);
|
|
1538
|
-
const execution = await this.execute(NATIVE_REVIEW_OPERATION.VALIDATE, request.cwd, ["review", "validate", "--gate", request.gate, "--cwd", request.cwd, ...(request.lineageId ? ["--lineage", request.lineageId] : []), ...(request.flags ?? [])], false, request.signal);
|
|
1539
|
-
return decode(NATIVE_REVIEW_OPERATION.VALIDATE, false, () => {
|
|
1540
|
-
const body = exactObject(execution.body, ["schema", "result", "allowed", "action", "reason", "context"], ["delivery"]);
|
|
1541
|
-
const gateResult = enumString(body.result, NATIVE_GATE_RESULT) ;
|
|
1542
|
-
const action = sanitizeNativeDiagnosticText(requiredString(body.action), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
1543
|
-
const reason = sanitizeNativeDiagnosticText(requiredString(body.reason), NATIVE_REVIEW_DENIAL_TEXT_LIMIT);
|
|
1544
|
-
// `delivery` (Design Decision #9, organic-rdd-parity) is an alternate
|
|
1545
|
-
// discriminator: when present it must be the single literal
|
|
1546
|
-
// "disabled/unmanaged" (gentle-ai's RDDDeliveryDisabledUnmanaged — the
|
|
1547
|
-
// kill switch is off and no receipt governs the candidate), paired
|
|
1548
|
-
// exactly with result:invalidated, allowed:false, action:repository-policy,
|
|
1549
|
-
// and exit 0 — never the strict continue/create-new-lineage/
|
|
1550
|
-
// explicit-maintainer-action/stop pairing used when delivery is absent.
|
|
1551
|
-
const delivery = body.delivery === undefined ? undefined : (enumString(body.delivery, ["disabled/unmanaged"]) );
|
|
1552
|
-
if (body.schema !== "gentle-ai.review-gate-result/v1" || !isCanonicalProcessString(action) || !isCanonicalProcessString(reason)) throw new Error("wrong validate discriminator");
|
|
1553
|
-
if (delivery !== undefined) {
|
|
1554
|
-
if (gateResult !== "invalidated" || body.allowed !== false || action !== "repository-policy" || execution.exitCode !== 0) throw new Error("wrong validate delivery discriminator");
|
|
1555
|
-
} else {
|
|
1556
|
-
const expectedAction = { allow: "continue", "scope-changed": "create-new-lineage", invalidated: "explicit-maintainer-action", escalated: "stop" }[gateResult];
|
|
1557
|
-
const expectedExitCode = gateResult === "allow" ? 0 : 1;
|
|
1558
|
-
if (typeof body.allowed !== "boolean" || body.allowed !== (gateResult === "allow") || action !== expectedAction || execution.exitCode !== expectedExitCode) throw new Error("wrong validate discriminator");
|
|
1559
|
-
}
|
|
1560
|
-
const gateContext = decodeGateContext(body.context);
|
|
1561
|
-
const returnedGate = gateContext.raw.gate;
|
|
1562
|
-
if (returnedGate !== request.gate && (gateResult === "allow" || returnedGate !== "")) throw new Error("native gate context does not match the requested gate");
|
|
1563
|
-
if (request.lineageId && returnedGate !== "" && gateContext.lineageId !== request.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.VALIDATE, false, "native gate lineage mismatch");
|
|
1564
|
-
return { allowed: body.allowed , result: gateResult, action, reason, gateContext, ...(delivery === undefined ? {} : { delivery }) };
|
|
1565
|
-
});
|
|
1566
|
-
}
|
|
1567
|
-
|
|
1568
|
-
async bindSdd(request ) {
|
|
1569
|
-
await this.verifyVersion(request.cwd, request.signal, ["bindSdd"]);
|
|
1570
|
-
const { body: result } = await this.execute(NATIVE_REVIEW_OPERATION.BIND_SDD, request.cwd, ["review", "bind-sdd", "--cwd", request.cwd, "--change", request.change, "--lineage", request.lineage, `--expected-binding-revision=${request.expectedBindingRevision}`], true, request.signal);
|
|
1571
|
-
return decode(NATIVE_REVIEW_OPERATION.BIND_SDD, true, () => {
|
|
1572
|
-
const body = exactObject(result, ["schema", "revision", "change", "lineage", "authority_revision", "receipt_hash", "gate_context"]);
|
|
1573
|
-
if (body.schema !== "gentle-ai.sdd-review-binding/v1" || body.change !== request.change || body.lineage !== request.lineage) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.BIND_SDD, true, "native binding identity mismatch");
|
|
1574
|
-
const receiptHash = requiredString(body.receipt_hash);
|
|
1575
|
-
const gateContext = decodeGateContext(body.gate_context);
|
|
1576
|
-
const authorityRevision = requiredString(body.authority_revision);
|
|
1577
|
-
if (gateContext.lineageId !== request.lineage || gateContext.storeRevision !== authorityRevision || gateContext.raw.gate !== "post-apply") throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.BIND_SDD, true, "native binding gate mismatch");
|
|
1578
|
-
return {
|
|
1579
|
-
revision: requiredString(body.revision),
|
|
1580
|
-
change: requiredString(body.change),
|
|
1581
|
-
lineage: requiredString(body.lineage),
|
|
1582
|
-
authorityRevision,
|
|
1583
|
-
receiptHash,
|
|
1584
|
-
gateContext,
|
|
1585
|
-
};
|
|
1586
|
-
});
|
|
1587
|
-
}
|
|
1588
|
-
|
|
1589
1294
|
async reviewStatus(request ) {
|
|
1590
|
-
await this.verifyVersion(request.cwd, request.signal, ["status", "inventory"]);
|
|
1591
1295
|
const { body: result } = await this.execute(NATIVE_REVIEW_OPERATION.STATUS, request.cwd, ["review", "status", "--cwd", request.cwd], false, request.signal);
|
|
1592
1296
|
const status = decode(NATIVE_REVIEW_OPERATION.STATUS, false, () => decodeNativeReviewStatus(result));
|
|
1593
1297
|
if (!await repositoriesMatch(request.cwd, status.repository)) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.STATUS, false, "native review status repository mismatch");
|
|
@@ -1601,7 +1305,6 @@ export class NativeReviewCliV214 {
|
|
|
1601
1305
|
// never mutates the operator's global gentle-ai state across other clones.
|
|
1602
1306
|
async reviewMode(request ) {
|
|
1603
1307
|
const cwd = await canonicalNativeReviewCwd(request.cwd);
|
|
1604
|
-
await this.verifyVersion(cwd, request.signal, ["mode"]);
|
|
1605
1308
|
const mutating = request.operation !== NATIVE_REVIEW_MODE_OPERATION.STATUS;
|
|
1606
1309
|
const { body } = await this.execute(
|
|
1607
1310
|
NATIVE_REVIEW_OPERATION.MODE,
|
|
@@ -1613,77 +1316,10 @@ export class NativeReviewCliV214 {
|
|
|
1613
1316
|
return decode(NATIVE_REVIEW_OPERATION.MODE, mutating, () => decodeNativeReviewMode(body, request.operation));
|
|
1614
1317
|
}
|
|
1615
1318
|
|
|
1616
|
-
async sddStatus(request ) {
|
|
1617
|
-
await this.verifyVersion(request.cwd, request.signal, ["sddStatus"]);
|
|
1618
|
-
const { body: result } = await this.execute(NATIVE_REVIEW_OPERATION.SDD_STATUS, request.cwd, ["sdd-status", request.change, "--cwd", request.cwd, "--json", "--instructions"], false, request.signal);
|
|
1619
|
-
return decode(NATIVE_REVIEW_OPERATION.SDD_STATUS, false, () => {
|
|
1620
|
-
const body = exactObject(result, ["schemaName", "schemaVersion", "changeName", "artifactStore", "planningHome", "changeRoot", "artifactPaths", "contextFiles", "artifacts", "taskProgress", "dependencies", "applyState", "actionContext", "relationships", "remediationState", "nextRecommended", "blockedReasons"], ["reviewGate", "reviewTransaction", "phaseInstructions"]);
|
|
1621
|
-
if (body.schemaName !== "gentle-ai.sdd-status" || body.schemaVersion !== 1 || body.changeName !== request.change || !["openspec", "engram", "none"].includes(body.artifactStore ) || !["blocked", "all_done", "ready"].includes(body.applyState )) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.SDD_STATUS, false, "native status identity mismatch");
|
|
1622
|
-
const paths = ["proposal", "specs", "design", "tasks", "applyProgress", "verifyReport", "reviewPolicy", "reviewLedger", "reviewReceipt", "reviewBundle", "reviewContext", "reviewState"];
|
|
1623
|
-
const pathMap = (value ) => { const parsed = exactObject(value, paths); for (const path of paths) stringArray(parsed[path]); };
|
|
1624
|
-
const planningHome = exactObject(body.planningHome, ["mode", "path"]);
|
|
1625
|
-
if (planningHome.mode !== "repo-local") throw new Error("invalid planning home");
|
|
1626
|
-
requiredString(planningHome.path); requiredString(body.changeRoot); pathMap(body.artifactPaths); pathMap(body.contextFiles);
|
|
1627
|
-
const artifactStates = paths.filter((path) => path !== "reviewPolicy" || body.artifactStore === NATIVE_SDD_ARTIFACT_STORE.ENGRAM);
|
|
1628
|
-
const artifacts = exactObject(body.artifacts, artifactStates);
|
|
1629
|
-
for (const path of artifactStates) if (!Object.values(NATIVE_SDD_ARTIFACT_STATE).includes(artifacts[path] )) throw new Error("invalid artifact state");
|
|
1630
|
-
const taskProgress = exactObject(body.taskProgress, ["total", "completed", "pending", "allComplete"]);
|
|
1631
|
-
const total = nonNegativeInteger(taskProgress.total), completed = nonNegativeInteger(taskProgress.completed), pending = nonNegativeInteger(taskProgress.pending);
|
|
1632
|
-
if (typeof taskProgress.allComplete !== "boolean" || completed + pending !== total || taskProgress.allComplete !== (pending === 0)) throw new Error("invalid task progress");
|
|
1633
|
-
const dependencies = exactObject(body.dependencies, ["proposal", "specs", "design", "tasks", "apply", "verify", "archive"]);
|
|
1634
|
-
for (const phase of ["proposal", "specs", "design", "tasks", "apply", "verify", "archive"]) if (!["blocked", "ready", "all_done"].includes(dependencies[phase] )) throw new Error("invalid dependency state");
|
|
1635
|
-
const actionContext = exactObject(body.actionContext, ["mode", "workspaceRoot", "allowedEditRoots"]);
|
|
1636
|
-
if (actionContext.mode !== "repo-local" || requiredString(actionContext.workspaceRoot).length === 0 || stringArray(actionContext.allowedEditRoots).length === 0) throw new Error("invalid action context");
|
|
1637
|
-
const relationships = exactObject(body.relationships, ["dependsOn", "supersedes", "amends", "conflictsWith", "sameDomainActiveChanges"]);
|
|
1638
|
-
for (const field of ["dependsOn", "supersedes", "amends", "conflictsWith", "sameDomainActiveChanges"]) stringArray(relationships[field]);
|
|
1639
|
-
const remediation = exactObject(body.remediationState, ["required", "complete", "failedEvidenceRevision", "lineageId", "generation", "fixBatch", "reason"], ["correctionBudget"]);
|
|
1640
|
-
if (typeof remediation.required !== "boolean" || typeof remediation.complete !== "boolean" || ["failedEvidenceRevision", "lineageId", "reason"].some((field) => typeof remediation[field] !== "string")) throw new Error("invalid remediation state");
|
|
1641
|
-
nonNegativeInteger(remediation.generation); nonNegativeInteger(remediation.fixBatch);
|
|
1642
|
-
if (remediation.correctionBudget !== undefined) nonNegativeInteger(remediation.correctionBudget);
|
|
1643
|
-
let reviewGateResult ;
|
|
1644
|
-
let reviewGateDelivery ;
|
|
1645
|
-
if (body.reviewGate !== undefined) {
|
|
1646
|
-
// `delivery` (present since 09e4b14c, gentle-ai v2.2.0+) is emitted
|
|
1647
|
-
// when the kill switch is off: gentle-ai's status struct carries
|
|
1648
|
-
// `Delivery` with `json:"delivery,omitempty"`, so an exact-key decode
|
|
1649
|
-
// without it rejects that payload outright. Pre-existing bug fix
|
|
1650
|
-
// (Phase 13.13, migrate-review-integration-v2).
|
|
1651
|
-
const gate = exactObject(body.reviewGate, ["result", "reason"], ["delivery"]);
|
|
1652
|
-
reviewGateResult = enumString(gate.result, NATIVE_GATE_RESULT); requiredString(gate.reason);
|
|
1653
|
-
if (gate.delivery !== undefined) reviewGateDelivery = enumString(gate.delivery, ["disabled/unmanaged"]);
|
|
1654
|
-
}
|
|
1655
|
-
if (body.reviewTransaction !== undefined) decodeReviewTransaction(body.reviewTransaction);
|
|
1656
|
-
if (body.phaseInstructions !== undefined) {
|
|
1657
|
-
const instructions = exactObject(body.phaseInstructions, ["apply", "verify", "remediate", "archive"]);
|
|
1658
|
-
for (const phase of ["apply", "verify", "remediate", "archive"]) stringArray(instructions[phase]);
|
|
1659
|
-
}
|
|
1660
|
-
const nextRecommended = requiredString(body.nextRecommended);
|
|
1661
|
-
if (!(NATIVE_SDD_NEXT_ACTION ).includes(nextRecommended)) throw new Error("unknown SDD next action");
|
|
1662
|
-
const blockedReasons = stringArray(body.blockedReasons);
|
|
1663
|
-
return {
|
|
1664
|
-
...body,
|
|
1665
|
-
artifactStore: body.artifactStore ,
|
|
1666
|
-
artifacts: artifacts ,
|
|
1667
|
-
nextRecommended,
|
|
1668
|
-
ready:
|
|
1669
|
-
(NATIVE_SDD_POST_REVIEW_ACTION ).includes(nextRecommended) &&
|
|
1670
|
-
blockedReasons.length === 0 &&
|
|
1671
|
-
// With the kill switch off, the gate result can never become
|
|
1672
|
-
// "allow" (delivery follows ordinary repository policy instead) —
|
|
1673
|
-
// gated only on `result === "allow"` this deadlocked `ready`
|
|
1674
|
-
// forever, the same deadlock gentle-ai fixed upstream in 2c18fa10.
|
|
1675
|
-
// `disabled/unmanaged` delivery is the legitimate non-blocking
|
|
1676
|
-
// terminal state and must also unblock readiness.
|
|
1677
|
-
(reviewGateResult === "allow" || reviewGateDelivery === "disabled/unmanaged"),
|
|
1678
|
-
};
|
|
1679
|
-
});
|
|
1680
|
-
}
|
|
1681
|
-
|
|
1682
1319
|
async reclaim(request ) {
|
|
1683
1320
|
for (const [name, value] of [["lineage", request.lineage], ["actor", request.actor], ["reason", request.reason]] ) {
|
|
1684
1321
|
if (!isCanonicalProcessString(value)) throw new TypeError(`Native RECLAIM ${name} must be a non-empty, trimmed, NUL-free string`);
|
|
1685
1322
|
}
|
|
1686
|
-
await this.verifyVersion(request.cwd, request.signal, ["reclaim"]);
|
|
1687
1323
|
const { body } = await this.execute(NATIVE_REVIEW_OPERATION.RECLAIM, request.cwd, ["review", "reclaim", "--cwd", request.cwd, "--lineage", request.lineage, "--actor", request.actor, "--reason", request.reason], true, request.signal);
|
|
1688
1324
|
return { record: body };
|
|
1689
1325
|
}
|
|
@@ -1704,7 +1340,6 @@ export class NativeReviewCliV214 {
|
|
|
1704
1340
|
throw new TypeError("Native RECOVER maintainerAuthorization must be a non-empty LF-only binding");
|
|
1705
1341
|
}
|
|
1706
1342
|
if (!(NATIVE_REVIEW_RECOVER_DISPOSITION ).includes(request.disposition)) throw new TypeError("Native RECOVER disposition must be scope_changed, invalidated, or escalated");
|
|
1707
|
-
await this.verifyVersion(request.cwd, request.signal, ["recover"]);
|
|
1708
1343
|
const { body } = await this.execute(NATIVE_REVIEW_OPERATION.RECOVER, request.cwd, [
|
|
1709
1344
|
"review", "recover", "--cwd", request.cwd,
|
|
1710
1345
|
"--predecessor-lineage", request.predecessorLineage,
|
|
@@ -1727,7 +1362,6 @@ export class NativeReviewCliV214 {
|
|
|
1727
1362
|
if (typeof value !== "boolean") throw new TypeError(`Native ABANDON ${name} must be a boolean`);
|
|
1728
1363
|
}
|
|
1729
1364
|
if (request.maintainerAuthorization !== nativeReviewAbandonAuthorization(request)) throw new TypeError("Native ABANDON maintainerAuthorization must match the exact lineage, revision, snapshot, reason, discarded-work, and actor binding");
|
|
1730
|
-
await this.verifyVersion(request.cwd, request.signal, ["abandon"]);
|
|
1731
1365
|
const execution = await this.execute(NATIVE_REVIEW_OPERATION.ABANDON, request.cwd, [
|
|
1732
1366
|
"review", "abandon", "--cwd", request.cwd,
|
|
1733
1367
|
"--lineage", request.lineage,
|
|
@@ -1747,7 +1381,6 @@ export class NativeReviewCliV214 {
|
|
|
1747
1381
|
}
|
|
1748
1382
|
if (request.diagnostic !== NATIVE_REVIEW_LEGACY_QUARANTINE.DIAGNOSTIC || request.disposition !== NATIVE_REVIEW_LEGACY_QUARANTINE.DISPOSITION) throw new TypeError("Native QUARANTINE_LEGACY supports only the published malformed freeze-findings diagnostic and disposition");
|
|
1749
1383
|
if (request.maintainerAuthorization !== nativeReviewLegacyQuarantineAuthorization(request)) throw new TypeError("Native QUARANTINE_LEGACY maintainerAuthorization must match the exact repository, lineage, revision, diagnostic, disposition, actor, and reason binding");
|
|
1750
|
-
await this.verifyVersion(request.cwd, request.signal, ["quarantineLegacy"]);
|
|
1751
1384
|
const execution = await this.execute(NATIVE_REVIEW_OPERATION.QUARANTINE_LEGACY, request.cwd, [
|
|
1752
1385
|
"review", "quarantine-legacy", "--cwd", request.cwd,
|
|
1753
1386
|
"--lineage", request.lineage,
|
|
@@ -1779,7 +1412,6 @@ export class NativeReviewCliV214 {
|
|
|
1779
1412
|
if (request.maintainerAuthorization !== expectedAuthorization) {
|
|
1780
1413
|
throw new TypeError("Native RECONCILE_AUTHORITY maintainerAuthorization must match the exact target and revision binding");
|
|
1781
1414
|
}
|
|
1782
|
-
const version = await this.verifyVersion(request.cwd, request.signal, ["reconcileAuthority"]);
|
|
1783
1415
|
const execution = await this.execute(NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY, request.cwd, [
|
|
1784
1416
|
"review", "reconcile-authority", "--cwd", request.cwd,
|
|
1785
1417
|
"--predecessor-lineage", request.predecessorLineage,
|
|
@@ -1790,9 +1422,7 @@ export class NativeReviewCliV214 {
|
|
|
1790
1422
|
"--reason", request.reason,
|
|
1791
1423
|
"--maintainer-authorization", request.maintainerAuthorization,
|
|
1792
1424
|
], true, request.signal);
|
|
1793
|
-
const result = decode(NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY, true, () =>
|
|
1794
|
-
? decodeLegacyReconcileAudit(execution.body)
|
|
1795
|
-
: decodeNativeMaintenanceResult(execution.body, NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY));
|
|
1425
|
+
const result = decode(NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY, true, () => decodeNativeMaintenanceResult(execution.body, NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY));
|
|
1796
1426
|
if (execution.exitCode !== 0) throw nativeError(NATIVE_REVIEW_ERROR_CODE.NON_ZERO, NATIVE_REVIEW_OPERATION.RECONCILE_AUTHORITY, true, "native authority reconciliation partially failed", execution.process, true, result.record);
|
|
1797
1427
|
return result;
|
|
1798
1428
|
}
|
|
@@ -1803,7 +1433,6 @@ export class NativeReviewCliV214 {
|
|
|
1803
1433
|
}
|
|
1804
1434
|
if (request.diagnostic !== NATIVE_REVIEW_LEGACY_ALIAS_REPAIR.DIAGNOSTIC || request.disposition !== NATIVE_REVIEW_LEGACY_ALIAS_REPAIR.DISPOSITION) throw new TypeError("Native REPAIR_LEGACY_ALIAS supports only the published historical alias diagnostic and disposition");
|
|
1805
1435
|
if (request.maintainerAuthorization !== nativeReviewLegacyAliasRepairAuthorization(request)) throw new TypeError("Native REPAIR_LEGACY_ALIAS maintainerAuthorization must match the exact repository, lineage, revision, diagnostic, disposition, actor, and reason binding");
|
|
1806
|
-
await this.verifyVersion(request.cwd, request.signal, ["repairLegacyAlias"]);
|
|
1807
1436
|
const execution = await this.execute(NATIVE_REVIEW_OPERATION.REPAIR_LEGACY_ALIAS, request.cwd, [
|
|
1808
1437
|
"review", "repair-legacy-alias", "--cwd", request.cwd,
|
|
1809
1438
|
"--lineage", request.lineage,
|
|
@@ -2006,6 +1635,19 @@ function exactConsentOption(arguments_ , name )
|
|
|
2006
1635
|
return values[0] ;
|
|
2007
1636
|
}
|
|
2008
1637
|
|
|
1638
|
+
// A Pi consent envelope is bound to Pi only when every exact provider replay
|
|
1639
|
+
// path carries exactly one `--agent pi` option. The outer envelope agent alone
|
|
1640
|
+
// cannot bind an omitted, embedded, duplicated, or conflicting invocation.
|
|
1641
|
+
function validatePiConsentChoiceAgentBindings(consent ) {
|
|
1642
|
+
if (!("agent" in consent) || consent.agent !== "pi") return;
|
|
1643
|
+
for (const choice of consent.choices) {
|
|
1644
|
+
const arguments_ = splitNativeConsentInvocation(choice.invocation).slice(1);
|
|
1645
|
+
if (exactConsentOption(arguments_, "--agent") !== "pi") {
|
|
1646
|
+
throw new NativeReviewConsentBindingError("consent-invocation-agent-changed", "Native Pi consent invocation agent binding changed");
|
|
1647
|
+
}
|
|
1648
|
+
}
|
|
1649
|
+
}
|
|
1650
|
+
|
|
2009
1651
|
function optionalConsentLineageOption(arguments_ ) {
|
|
2010
1652
|
const values = [];
|
|
2011
1653
|
for (let index = 0; index < arguments_.length; index += 1) {
|
|
@@ -2030,6 +1672,7 @@ function optionalConsentLineageOption(arguments_ )
|
|
|
2030
1672
|
|
|
2031
1673
|
|
|
2032
1674
|
function consentInvocationArguments(request ) {
|
|
1675
|
+
validatePiConsentChoiceAgentBindings(request.consent);
|
|
2033
1676
|
const choice = request.consent.choices.find((candidate) => candidate.answer === request.answer);
|
|
2034
1677
|
if (choice === undefined) throw new NativeReviewConsentBindingError("consent-answer-unknown", "Native consent answer must be granted or declined");
|
|
2035
1678
|
const words = splitNativeConsentInvocation(choice.invocation);
|
|
@@ -2065,24 +1708,7 @@ function decodeDeclinedConsentStart(value , expected
|
|
|
2065
1708
|
}
|
|
2066
1709
|
|
|
2067
1710
|
|
|
2068
|
-
const nativeCapabilitiesByDigest = new Map ();
|
|
2069
1711
|
|
|
2070
|
-
export function clearNativeReviewCapabilitiesCacheForTesting() {
|
|
2071
|
-
nativeCapabilitiesByDigest.clear();
|
|
2072
|
-
}
|
|
2073
|
-
|
|
2074
|
-
function defaultExecutableDigest(path ) {
|
|
2075
|
-
const before = statSync(path);
|
|
2076
|
-
const digest = createHash("sha256").update(readFileSync(path)).digest("hex");
|
|
2077
|
-
const after = statSync(path);
|
|
2078
|
-
if (
|
|
2079
|
-
before.dev !== after.dev ||
|
|
2080
|
-
before.ino !== after.ino ||
|
|
2081
|
-
before.size !== after.size ||
|
|
2082
|
-
before.mtimeMs !== after.mtimeMs
|
|
2083
|
-
) throw new Error("native review executable changed during capability verification");
|
|
2084
|
-
return digest;
|
|
2085
|
-
}
|
|
2086
1712
|
|
|
2087
1713
|
|
|
2088
1714
|
|
|
@@ -2134,20 +1760,18 @@ function decodeNativeProviderRoleCaptureArtifact(value )
|
|
|
2134
1760
|
}
|
|
2135
1761
|
|
|
2136
1762
|
export class NativeReviewCliV216 {
|
|
2137
|
-
|
|
1763
|
+
plain ;
|
|
2138
1764
|
adapter ;
|
|
2139
1765
|
executable ;
|
|
2140
1766
|
timeoutMs ;
|
|
2141
1767
|
maxBufferBytes ;
|
|
2142
1768
|
cleanupDirectory ;
|
|
2143
|
-
executableDigest ;
|
|
2144
1769
|
constructor(
|
|
2145
1770
|
adapter ,
|
|
2146
1771
|
executable = resolveGentleAiBinary,
|
|
2147
1772
|
timeoutMs = 30_000,
|
|
2148
1773
|
maxBufferBytes = resolveNativeReviewMaxBufferBytes(),
|
|
2149
1774
|
cleanupDirectory = (directory) => rm(directory, { recursive: true, force: true }),
|
|
2150
|
-
executableDigest = defaultExecutableDigest,
|
|
2151
1775
|
) {
|
|
2152
1776
|
if (typeof executable === "string" && (!isAbsolute(executable) || executable === "gentle-ai")) throw new TypeError("Native review requires an absolute package-local executable");
|
|
2153
1777
|
this.adapter = adapter;
|
|
@@ -2155,8 +1779,7 @@ export class NativeReviewCliV216 {
|
|
|
2155
1779
|
this.timeoutMs = timeoutMs;
|
|
2156
1780
|
this.maxBufferBytes = maxBufferBytes;
|
|
2157
1781
|
this.cleanupDirectory = cleanupDirectory;
|
|
2158
|
-
this.
|
|
2159
|
-
this.legacy = new NativeReviewCliV214(adapter, executable, timeoutMs, maxBufferBytes, cleanupDirectory);
|
|
1782
|
+
this.plain = new NativeReviewPlainCli(adapter, executable, timeoutMs, maxBufferBytes, cleanupDirectory);
|
|
2160
1783
|
}
|
|
2161
1784
|
|
|
2162
1785
|
executablePath(operation , mutating ) {
|
|
@@ -2170,15 +1793,6 @@ export class NativeReviewCliV216 {
|
|
|
2170
1793
|
}
|
|
2171
1794
|
}
|
|
2172
1795
|
|
|
2173
|
-
verifiedExecutable(operation , mutating ) {
|
|
2174
|
-
const path = this.executablePath(operation, mutating);
|
|
2175
|
-
try {
|
|
2176
|
-
return { path, digest: this.executableDigest(path) };
|
|
2177
|
-
} catch {
|
|
2178
|
-
throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, operation, mutating, "package-local native executable identity could not be verified", undefined, false);
|
|
2179
|
-
}
|
|
2180
|
-
}
|
|
2181
|
-
|
|
2182
1796
|
async invoke(
|
|
2183
1797
|
operation ,
|
|
2184
1798
|
cwd ,
|
|
@@ -2187,6 +1801,14 @@ export class NativeReviewCliV216 {
|
|
|
2187
1801
|
signal ,
|
|
2188
1802
|
path ,
|
|
2189
1803
|
toleratedStderr = [],
|
|
1804
|
+
// A successful acknowledgement burns its authority and, on every
|
|
1805
|
+
// published release up to v2.5.0-rc.3, prints nothing: there is no
|
|
1806
|
+
// receipt left to describe. Only that shape opts out of the body, and
|
|
1807
|
+
// only for a zero exit. When such an operation does print, the bytes
|
|
1808
|
+
// are handed back as a body for the caller to decode against the one
|
|
1809
|
+
// identity it accepts (gentle-ai #3947); a non-zero exit still has to
|
|
1810
|
+
// produce its typed failure envelope like every other operation.
|
|
1811
|
+
expectsBody = true,
|
|
2190
1812
|
) {
|
|
2191
1813
|
let result ;
|
|
2192
1814
|
try {
|
|
@@ -2199,6 +1821,10 @@ export class NativeReviewCliV216 {
|
|
|
2199
1821
|
if (result.timedOut) throw nativeError(NATIVE_REVIEW_ERROR_CODE.TIMEOUT, operation, mutating, "native process timed out", result);
|
|
2200
1822
|
if (result.signal) throw nativeError(NATIVE_REVIEW_ERROR_CODE.SIGNAL, operation, mutating, "native process was signalled", result);
|
|
2201
1823
|
const diagnostics = nativeProcessDiagnostics(operation, NATIVE_REVIEW_ERROR_CODE.NON_ZERO, result);
|
|
1824
|
+
if (!expectsBody && result.exitCode === 0 && result.stdout.trim().length === 0) {
|
|
1825
|
+
if (result.stderr.trim().length > 0 && !stderrIsTolerated(result.stderr, toleratedStderr)) throw nativeError(NATIVE_REVIEW_ERROR_CODE.UNEXPECTED_STDERR, operation, mutating, "native process wrote stderr", result);
|
|
1826
|
+
return { body: {}, exitCode: result.exitCode, silent: true };
|
|
1827
|
+
}
|
|
2202
1828
|
const body = parseJson(result.stdout, operation, mutating, diagnostics);
|
|
2203
1829
|
if (result.exitCode !== 0) {
|
|
2204
1830
|
try {
|
|
@@ -2208,55 +1834,11 @@ export class NativeReviewCliV216 {
|
|
|
2208
1834
|
throw nativeError(NATIVE_REVIEW_ERROR_CODE.NON_ZERO, operation, mutating, "native negotiated operation failed without a valid failure envelope", result);
|
|
2209
1835
|
}
|
|
2210
1836
|
}
|
|
2211
|
-
const forecastNarrationTolerated = operation === NATIVE_REVIEW_OPERATION.STATUS &&
|
|
1837
|
+
const forecastNarrationTolerated = operation === NATIVE_REVIEW_OPERATION.STATUS && stderrIsForecastNarration(result.stderr);
|
|
2212
1838
|
if (result.stderr.trim().length > 0 && !stderrIsTolerated(result.stderr, toleratedStderr) && !forecastNarrationTolerated) throw nativeError(NATIVE_REVIEW_ERROR_CODE.UNEXPECTED_STDERR, operation, mutating, "native process wrote stderr", result);
|
|
2213
1839
|
return { body, exitCode: result.exitCode };
|
|
2214
1840
|
}
|
|
2215
1841
|
|
|
2216
|
-
async capabilities(request = {}) {
|
|
2217
|
-
const executable = this.verifiedExecutable(NATIVE_REVIEW_OPERATION.VERSION, false);
|
|
2218
|
-
const cached = nativeCapabilitiesByDigest.get(executable.digest);
|
|
2219
|
-
if (cached !== undefined) return cached;
|
|
2220
|
-
const negotiation = (async () => {
|
|
2221
|
-
const execution = await this.invoke(
|
|
2222
|
-
NATIVE_REVIEW_OPERATION.VERSION,
|
|
2223
|
-
request.cwd ?? dirname(executable.path),
|
|
2224
|
-
["review", "capabilities", "--contract", REVIEW_INTEGRATION_CONTRACT],
|
|
2225
|
-
false,
|
|
2226
|
-
request.signal,
|
|
2227
|
-
executable.path,
|
|
2228
|
-
);
|
|
2229
|
-
// Two distinct half-upgraded-install failures (Design Decision #7,
|
|
2230
|
-
// migrate-review-integration-v2): a decode failure means the installed
|
|
2231
|
-
// runtime cannot even answer this shape (an older `.gentle-ai/` payload
|
|
2232
|
-
// that still speaks `unsupported_contract` for v2); a successful decode
|
|
2233
|
-
// whose package.version disagrees with the pin names both versions.
|
|
2234
|
-
let capabilities ;
|
|
2235
|
-
try {
|
|
2236
|
-
capabilities = decodeReviewCapabilitiesV2(execution.body, executable.digest);
|
|
2237
|
-
} catch (error) {
|
|
2238
|
-
if (error instanceof NativeReviewCliError) throw error;
|
|
2239
|
-
throw nativeError(NATIVE_REVIEW_ERROR_CODE.SCHEMA_INCOMPATIBLE, NATIVE_REVIEW_OPERATION.VERSION, false, `expected gentle-ai v${GENTLE_AI_VERSION}; the installed runtime is incompatible — reinstall gentle-pi`);
|
|
2240
|
-
}
|
|
2241
|
-
// Dev-binary override (unpinned field-test mode): the session accepts
|
|
2242
|
-
// the binary's self-reported package version instead of the exact pin.
|
|
2243
|
-
// The full capabilities decode above still applies unchanged, so an
|
|
2244
|
-
// incompatible envelope is refused either way. Pinned mode keeps the
|
|
2245
|
-
// exact equality byte-identical.
|
|
2246
|
-
if (capabilities.packageVersion !== GENTLE_AI_VERSION && !gentleAiDevBinaryOverrideConfigured()) {
|
|
2247
|
-
throw nativeError(NATIVE_REVIEW_ERROR_CODE.VERSION_INCOMPATIBLE, NATIVE_REVIEW_OPERATION.VERSION, false, `expected gentle-ai v${GENTLE_AI_VERSION}, provider reported v${capabilities.packageVersion}`);
|
|
2248
|
-
}
|
|
2249
|
-
return capabilities;
|
|
2250
|
-
})();
|
|
2251
|
-
nativeCapabilitiesByDigest.set(executable.digest, negotiation);
|
|
2252
|
-
try {
|
|
2253
|
-
return await negotiation;
|
|
2254
|
-
} catch (error) {
|
|
2255
|
-
nativeCapabilitiesByDigest.delete(executable.digest);
|
|
2256
|
-
throw error;
|
|
2257
|
-
}
|
|
2258
|
-
}
|
|
2259
|
-
|
|
2260
1842
|
async negotiated(
|
|
2261
1843
|
operation ,
|
|
2262
1844
|
cwd ,
|
|
@@ -2265,13 +1847,7 @@ export class NativeReviewCliV216 {
|
|
|
2265
1847
|
signal ,
|
|
2266
1848
|
toleratedStderr = [],
|
|
2267
1849
|
) {
|
|
2268
|
-
|
|
2269
|
-
await this.capabilities({ cwd, ...(signal === undefined ? {} : { signal }) });
|
|
2270
|
-
const afterNegotiation = this.verifiedExecutable(operation, mutating);
|
|
2271
|
-
if (afterNegotiation.path !== executable.path || afterNegotiation.digest !== executable.digest) {
|
|
2272
|
-
throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, operation, mutating, "native executable was replaced after capability negotiation", undefined, false);
|
|
2273
|
-
}
|
|
2274
|
-
return this.invoke(operation, cwd, arguments_, mutating, signal, executable.path, toleratedStderr);
|
|
1850
|
+
return this.invoke(operation, cwd, arguments_, mutating, signal, this.executablePath(operation, mutating), toleratedStderr);
|
|
2275
1851
|
}
|
|
2276
1852
|
|
|
2277
1853
|
async start(request ) {
|
|
@@ -2279,26 +1855,35 @@ export class NativeReviewCliV216 {
|
|
|
2279
1855
|
if (request.baseRef !== undefined && request.committedOnly !== true) throw new TypeError("Native START baseRef requires explicit committedOnly acknowledgement");
|
|
2280
1856
|
if (request.baseRef === undefined && request.committedOnly !== undefined) throw new TypeError("Native START committedOnly requires an explicit baseRef");
|
|
2281
1857
|
if (request.targetIdentity !== undefined && !/^sha256:[0-9a-f]{64}$/.test(request.targetIdentity)) throw new TypeError("Native START targetIdentity must be a canonical sha256 identity");
|
|
2282
|
-
//
|
|
2283
|
-
//
|
|
2284
|
-
//
|
|
1858
|
+
// STATUS owns the candidate binding and renders the only executable START
|
|
1859
|
+
// vector. Callers may supply a previously observed identity only to detect
|
|
1860
|
+
// drift; Pi never rebuilds that vector from request fields.
|
|
2285
1861
|
const projection = request.projection ?? "workspace";
|
|
2286
|
-
const
|
|
1862
|
+
const selection = nativeUntrackedSelection(request);
|
|
1863
|
+
const status = await this.targetStatus({
|
|
2287
1864
|
cwd: request.cwd,
|
|
2288
1865
|
projection,
|
|
2289
|
-
...(request.baseRef === undefined ? {} : { baseRef: request.baseRef }),
|
|
1866
|
+
...(request.baseRef === undefined ? {} : { baseRef: request.baseRef, committedOnly: true }),
|
|
2290
1867
|
...(request.lineageId === undefined ? {} : { lineageId: request.lineageId }),
|
|
1868
|
+
...selection,
|
|
1869
|
+
...(request.intendedUntrackedSelection === undefined ? {} : { intendedUntrackedSelection: request.intendedUntrackedSelection }),
|
|
1870
|
+
agent: "pi",
|
|
2291
1871
|
...(request.signal === undefined ? {} : { signal: request.signal }),
|
|
2292
|
-
})
|
|
2293
|
-
const
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
|
|
2297
|
-
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
|
|
1872
|
+
});
|
|
1873
|
+
const transition = status.nextTransition?.kind === "execute" && status.nextTransition.execute?.operation === "review.start"
|
|
1874
|
+
? status.nextTransition.execute
|
|
1875
|
+
: undefined;
|
|
1876
|
+
if (transition === undefined) throw nativeError(NATIVE_REVIEW_ERROR_CODE.SCHEMA_INCOMPATIBLE, NATIVE_REVIEW_OPERATION.START, false, "native STATUS did not offer an executable review.start transition", undefined, false);
|
|
1877
|
+
if (status.projection.projection !== projection || transition.binding.targetIdentity !== status.targetIdentity || (request.targetIdentity !== undefined && request.targetIdentity !== status.targetIdentity)) {
|
|
1878
|
+
throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, false, "native START transition target binding mismatch", undefined, false);
|
|
1879
|
+
}
|
|
1880
|
+
if (request.lineageId !== undefined && transition.binding.lineageId !== undefined && transition.binding.lineageId !== request.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, false, "native START transition lineage binding mismatch", undefined, false);
|
|
1881
|
+
const transitionTokens = transition.arguments.map((argument) => {
|
|
1882
|
+
if (argument.token === undefined) throw nativeError(NATIVE_REVIEW_ERROR_CODE.SCHEMA_INCOMPATIBLE, NATIVE_REVIEW_OPERATION.START, false, "native START transition omitted an ordered argument token", undefined, false);
|
|
1883
|
+
return argument.token;
|
|
1884
|
+
});
|
|
1885
|
+
const targetIdentity = status.targetIdentity;
|
|
1886
|
+
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.START, request.cwd, ["review", "start", ...transitionTokens], true, request.signal);
|
|
2302
1887
|
// A negotiated v2 START may answer a consent question (action:
|
|
2303
1888
|
// "consent_required") instead of `start/v3` when the provider needs an
|
|
2304
1889
|
// explicit answer it cannot infer. Discriminate before decode and surface
|
|
@@ -2308,15 +1893,16 @@ export class NativeReviewCliV216 {
|
|
|
2308
1893
|
// v2.1+) emits consent/v3, and any other identity fails closed inside
|
|
2309
1894
|
// the v3 decoder's exact identity gate.
|
|
2310
1895
|
if (execution.body.action === "consent_required") {
|
|
2311
|
-
const consent = decode(NATIVE_REVIEW_OPERATION.START, true, () =>
|
|
2312
|
-
execution.body.schema === "gentle-ai.review-integration.consent/v2"
|
|
2313
|
-
|
|
2314
|
-
|
|
2315
|
-
|
|
1896
|
+
const consent = decode(NATIVE_REVIEW_OPERATION.START, true, () => {
|
|
1897
|
+
if (execution.body.schema === "gentle-ai.review-integration.consent/v2") return decodeReviewConsentV2(execution.body);
|
|
1898
|
+
const decoded = decodeReviewConsentV3(execution.body, "pi");
|
|
1899
|
+
validatePiConsentChoiceAgentBindings(decoded);
|
|
1900
|
+
return decoded;
|
|
1901
|
+
});
|
|
2316
1902
|
if (consent.targetIdentity !== targetIdentity || consent.projection !== projection) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, true, "native consent target binding mismatch");
|
|
2317
1903
|
throw new NativeReviewConsentRequiredError(consent);
|
|
2318
1904
|
}
|
|
2319
|
-
const result = decode(NATIVE_REVIEW_OPERATION.START, true, () =>
|
|
1905
|
+
const result = decode(NATIVE_REVIEW_OPERATION.START, true, () => decodeReviewStartResponse(execution.body));
|
|
2320
1906
|
if (request.lineageId !== undefined && result.lineageId !== request.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, true, "native start lineage mismatch");
|
|
2321
1907
|
const resultTarget = result.targetIdentity ?? result.repositoryContext?.targetIdentity;
|
|
2322
1908
|
if (resultTarget !== undefined && resultTarget !== targetIdentity) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, true, "native start target mismatch");
|
|
@@ -2331,6 +1917,7 @@ export class NativeReviewCliV216 {
|
|
|
2331
1917
|
action: result.action ,
|
|
2332
1918
|
lensesRequired: result.lensesRequired,
|
|
2333
1919
|
riskReasons: result.riskReasons.map((reason) => ({ ...reason })),
|
|
1920
|
+
...("nextTransition" in result && result.nextTransition !== undefined ? { nextTransition: result.nextTransition } : {}),
|
|
2334
1921
|
// Derived, not received. `risk_reasons` is a required start/v2 field
|
|
2335
1922
|
// already recomputed against the authoritative frozen snapshot, so
|
|
2336
1923
|
// these phrases describe the same candidate the lenses will review.
|
|
@@ -2354,7 +1941,7 @@ export class NativeReviewCliV216 {
|
|
|
2354
1941
|
if (request.answer === NATIVE_REVIEW_CONSENT_ANSWER.DECLINED) {
|
|
2355
1942
|
return decode(NATIVE_REVIEW_OPERATION.START, true, () => decodeDeclinedConsentStart(execution.body, request));
|
|
2356
1943
|
}
|
|
2357
|
-
const result = decode(NATIVE_REVIEW_OPERATION.START, true, () =>
|
|
1944
|
+
const result = decode(NATIVE_REVIEW_OPERATION.START, true, () => decodeReviewStartResponse(execution.body));
|
|
2358
1945
|
const answeredTarget = result.targetIdentity ?? result.repositoryContext?.targetIdentity;
|
|
2359
1946
|
if (answeredTarget !== request.consent.targetIdentity) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, true, "native consent answer target mismatch");
|
|
2360
1947
|
if (invocation.lineageId !== undefined && result.lineageId !== invocation.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.START, true, "native consent answer lineage mismatch");
|
|
@@ -2369,6 +1956,7 @@ export class NativeReviewCliV216 {
|
|
|
2369
1956
|
action: result.action ,
|
|
2370
1957
|
lensesRequired: result.lensesRequired,
|
|
2371
1958
|
riskReasons: result.riskReasons.map((reason) => ({ ...reason })),
|
|
1959
|
+
...("nextTransition" in result && result.nextTransition !== undefined ? { nextTransition: result.nextTransition } : {}),
|
|
2372
1960
|
...(() => {
|
|
2373
1961
|
const evidence = nativeRiskEvidencePhrases(result.riskLevel, result.riskReasons);
|
|
2374
1962
|
return evidence.length === 0 ? {} : { riskEvidence: evidence };
|
|
@@ -2377,120 +1965,23 @@ export class NativeReviewCliV216 {
|
|
|
2377
1965
|
} };
|
|
2378
1966
|
}
|
|
2379
1967
|
|
|
2380
|
-
async stageDocument(directory , name , document ) {
|
|
2381
|
-
const path = join(directory, `${name}.json`);
|
|
2382
|
-
await writeFile(path, JSON.stringify(document), { encoding: "utf8", mode: 0o600 });
|
|
2383
|
-
await chmod(path, 0o600);
|
|
2384
|
-
return path;
|
|
2385
|
-
}
|
|
2386
|
-
|
|
2387
|
-
async stageEvidence(directory , evidence ) {
|
|
2388
|
-
const path = join(directory, "evidence.txt");
|
|
2389
|
-
await writeFile(path, evidence, { encoding: "utf8", mode: 0o600 });
|
|
2390
|
-
await chmod(path, 0o600);
|
|
2391
|
-
return path;
|
|
2392
|
-
}
|
|
2393
|
-
|
|
2394
|
-
async finalize(request ) {
|
|
2395
|
-
if (request.evidenceDocument !== undefined && request.evidenceDocument.length === 0) throw new TypeError("Native FINALIZE evidence must contain at least one byte");
|
|
2396
|
-
const needsStaging = request.lensResults !== undefined || request.refuterDocument !== undefined || request.validationDocument !== undefined || request.evidenceDocument !== undefined;
|
|
2397
|
-
const directory = needsStaging ? await mkdtemp(join(tmpdir(), "gentle-ai-finalize-")) : undefined;
|
|
2398
|
-
try {
|
|
2399
|
-
if (directory !== undefined) await chmod(directory, 0o700);
|
|
2400
|
-
const resultFiles = directory !== undefined && request.lensResults !== undefined ? await Promise.all(request.lensResults.map((entry, index) => this.stageDocument(directory, `result-${index}`, entry.document))) : request.resultFiles ?? [];
|
|
2401
|
-
const refuterFile = directory !== undefined && request.refuterDocument !== undefined ? await this.stageDocument(directory, "refuter", request.refuterDocument) : request.refuterFile;
|
|
2402
|
-
const validationFile = directory !== undefined && request.validationDocument !== undefined ? await this.stageDocument(directory, "validation", request.validationDocument) : request.validationFile;
|
|
2403
|
-
const evidenceFile = directory !== undefined && request.evidenceDocument !== undefined ? await this.stageEvidence(directory, request.evidenceDocument) : request.evidenceFile;
|
|
2404
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.FINALIZE, request.cwd, [
|
|
2405
|
-
"review", "finalize", "--contract", REVIEW_INTEGRATION_CONTRACT, "--cwd", request.cwd,
|
|
2406
|
-
...(request.lineageId === undefined ? [] : ["--lineage", request.lineageId]),
|
|
2407
|
-
// `--result` is RETIRED. A reviewer result supplied that way carries
|
|
2408
|
-
// no provider-owned admission, so it cannot prove the lens inspected
|
|
2409
|
-
// the frozen candidate. Results reach authority through
|
|
2410
|
-
// `review capture-result`, and FINALIZE either discovers them
|
|
2411
|
-
// (`--captured-results`) or is handed each manifest in lens order.
|
|
2412
|
-
...(request.capturedResults === true ? ["--captured-results=true"] : []),
|
|
2413
|
-
...(request.resultArtifactFiles ?? []).flatMap((path) => ["--result-artifact-file", path]),
|
|
2414
|
-
...(refuterFile === undefined ? [] : ["--refuter", refuterFile]),
|
|
2415
|
-
...(request.correctionLines === undefined ? [] : ["--correction-lines", String(request.correctionLines)]),
|
|
2416
|
-
...(validationFile === undefined ? [] : ["--validation", validationFile]),
|
|
2417
|
-
...(evidenceFile === undefined ? [] : ["--evidence", evidenceFile]),
|
|
2418
|
-
...(request.failed === true ? ["--failed"] : []),
|
|
2419
|
-
], true, request.signal);
|
|
2420
|
-
const envelope = decode(NATIVE_REVIEW_OPERATION.FINALIZE, true, () => decodeReviewOperationV2(execution.body));
|
|
2421
|
-
if (envelope.operation !== "review.finalize") throw new Error("wrong finalize operation envelope");
|
|
2422
|
-
const body = envelope.result;
|
|
2423
|
-
const lineageId = requiredString(body.lineage_id);
|
|
2424
|
-
if (request.lineageId !== undefined && lineageId !== request.lineageId) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.FINALIZE, true, "native finalize lineage mismatch");
|
|
2425
|
-
return {
|
|
2426
|
-
lineageId,
|
|
2427
|
-
state: requiredString(body.state),
|
|
2428
|
-
action: requiredString(body.action),
|
|
2429
|
-
storeRevision: requiredString(body.store_revision),
|
|
2430
|
-
// Present only when state is correction_required (validated by
|
|
2431
|
-
// decodeReviewOperationV2); carried through as the raw validated
|
|
2432
|
-
// shape rather than re-decoded, since the typed decoder for this
|
|
2433
|
-
// nested object is private to lib/review-integration-v2.ts.
|
|
2434
|
-
...(body.validation_request === undefined ? {} : { validationRequest: body.validation_request }),
|
|
2435
|
-
...(body.escalation === undefined ? {} : { escalation: requiredString(body.escalation) }),
|
|
2436
|
-
};
|
|
2437
|
-
} finally {
|
|
2438
|
-
if (directory !== undefined) await this.cleanupDirectory(directory).catch(() => undefined);
|
|
2439
|
-
}
|
|
2440
|
-
}
|
|
2441
|
-
|
|
2442
|
-
async validate(request ) {
|
|
2443
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.VALIDATE, request.cwd, [
|
|
2444
|
-
"review", "validate", "--contract", REVIEW_INTEGRATION_CONTRACT, "--gate", request.gate, "--cwd", request.cwd,
|
|
2445
|
-
...(request.lineageId === undefined ? [] : ["--lineage", request.lineageId]),
|
|
2446
|
-
...(request.flags ?? []),
|
|
2447
|
-
], false, request.signal);
|
|
2448
|
-
const envelope = decode(NATIVE_REVIEW_OPERATION.VALIDATE, false, () => decodeReviewOperationV2(execution.body));
|
|
2449
|
-
if (envelope.operation !== "review.validate") throw new Error("wrong validate operation envelope");
|
|
2450
|
-
const body = envelope.result;
|
|
2451
|
-
const gateContext = decodeGateContext(body.context);
|
|
2452
|
-
return {
|
|
2453
|
-
allowed: booleanValue(body.allowed),
|
|
2454
|
-
result: enumString(body.result, NATIVE_GATE_RESULT) ,
|
|
2455
|
-
action: requiredString(body.action),
|
|
2456
|
-
reason: requiredString(body.reason),
|
|
2457
|
-
gateContext,
|
|
2458
|
-
...(body.delivery === undefined ? {} : { delivery: enumString(body.delivery, ["disabled/unmanaged"]) }),
|
|
2459
|
-
};
|
|
2460
|
-
}
|
|
2461
|
-
|
|
2462
|
-
async bindSdd(request ) {
|
|
2463
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.BIND_SDD, request.cwd, [
|
|
2464
|
-
"review", "bind-sdd", "--contract", REVIEW_INTEGRATION_CONTRACT, "--cwd", request.cwd,
|
|
2465
|
-
"--change", request.change, "--lineage", request.lineage,
|
|
2466
|
-
`--expected-binding-revision=${request.expectedBindingRevision}`,
|
|
2467
|
-
], true, request.signal);
|
|
2468
|
-
const envelope = decode(NATIVE_REVIEW_OPERATION.BIND_SDD, true, () => decodeReviewOperationV2(execution.body));
|
|
2469
|
-
if (envelope.operation !== "review.bind_sdd") throw new Error("wrong bind-sdd operation envelope");
|
|
2470
|
-
const body = envelope.result;
|
|
2471
|
-
const gateContext = decodeGateContext(body.gate_context);
|
|
2472
|
-
const lineage = requiredString(body.lineage);
|
|
2473
|
-
const change = requiredString(body.change);
|
|
2474
|
-
if (lineage !== request.lineage || change !== request.change || gateContext.raw.gate !== "post-apply") throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.BIND_SDD, true, "native binding identity mismatch");
|
|
2475
|
-
return {
|
|
2476
|
-
revision: requiredString(body.revision),
|
|
2477
|
-
change,
|
|
2478
|
-
lineage,
|
|
2479
|
-
authorityRevision: requiredString(body.authority_revision),
|
|
2480
|
-
receiptHash: requiredString(body.receipt_hash),
|
|
2481
|
-
gateContext,
|
|
2482
|
-
};
|
|
2483
|
-
}
|
|
2484
|
-
|
|
2485
1968
|
async targetStatus(request ) {
|
|
2486
|
-
|
|
1969
|
+
if (request.baseRef !== undefined && !isCanonicalProcessString(request.baseRef)) throw new TypeError("Native STATUS baseRef must be a non-empty, trimmed, NUL-free string");
|
|
1970
|
+
if (request.baseRef !== undefined && request.committedOnly !== true) throw new TypeError("Native STATUS baseRef requires explicit committedOnly acknowledgement");
|
|
1971
|
+
if (request.baseRef === undefined && request.committedOnly !== undefined) throw new TypeError("Native STATUS committedOnly requires an explicit baseRef");
|
|
1972
|
+
const selection = nativeUntrackedSelection(request);
|
|
1973
|
+
const submitted = request.intendedUntrackedSelection;
|
|
1974
|
+
if (submitted !== undefined && submitted.argumentTokens.reduce((count, token) => count + token.split("{{value}}").length - 1, 0) !== 1) throw new TypeError("Native intended-untracked selection requires exactly one provider-issued {{value}} token");
|
|
1975
|
+
const statusArguments = submitted === undefined ? [
|
|
2487
1976
|
"review", "status", "--contract", REVIEW_INTEGRATION_CONTRACT, "--cwd", request.cwd,
|
|
2488
1977
|
"--projection", request.projection ?? "workspace",
|
|
2489
|
-
...(
|
|
1978
|
+
...nativeUntrackedSelectionArguments(selection),
|
|
1979
|
+
...(request.baseRef === undefined ? [] : ["--base-ref", request.baseRef, "--committed-only"]),
|
|
2490
1980
|
...(request.lineageId === undefined ? [] : ["--lineage", request.lineageId]),
|
|
2491
1981
|
...(request.agent === undefined ? [] : ["--agent", request.agent]),
|
|
2492
1982
|
"--next-transition",
|
|
2493
|
-
],
|
|
1983
|
+
] : ["review", "status", "--cwd", request.cwd, ...submitted.argumentTokens.map((token) => token.replaceAll("{{value}}", submitted.value))];
|
|
1984
|
+
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.STATUS, request.cwd, statusArguments, false, request.signal);
|
|
2494
1985
|
assertSupportedNextTransitionOperation(execution.body);
|
|
2495
1986
|
return decode(NATIVE_REVIEW_OPERATION.STATUS, false, () => decodeReviewStatusV3(execution.body));
|
|
2496
1987
|
}
|
|
@@ -2530,7 +2021,7 @@ export class NativeReviewCliV216 {
|
|
|
2530
2021
|
// --contract, and the verification-evidence/v2 record returned DIRECTLY —
|
|
2531
2022
|
// not wrapped in an operation/v2 envelope. Evidence is staged through the
|
|
2532
2023
|
// same 0o600 tmpfile discipline FINALIZE uses.
|
|
2533
|
-
async captureResult(request )
|
|
2024
|
+
async captureResult(request ) {
|
|
2534
2025
|
if (request.argumentTokens.length === 0) throw new TypeError("Native CAPTURE_RESULT requires the provider-issued argument tokens");
|
|
2535
2026
|
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native CAPTURE_RESULT argument tokens must all be non-empty strings");
|
|
2536
2027
|
if (request.resultDocument.length === 0) throw new TypeError("Native CAPTURE_RESULT result document must contain at least one byte");
|
|
@@ -2542,19 +2033,67 @@ export class NativeReviewCliV216 {
|
|
|
2542
2033
|
const resultFile = join(directory, "result.json");
|
|
2543
2034
|
await writeFile(resultFile, request.resultDocument, { encoding: "utf8", mode: 0o600 });
|
|
2544
2035
|
await chmod(resultFile, 0o600);
|
|
2545
|
-
const executable = this.
|
|
2036
|
+
const executable = this.executablePath(NATIVE_REVIEW_OPERATION.CAPTURE_RESULT, true);
|
|
2546
2037
|
const execution = await this.invoke(NATIVE_REVIEW_OPERATION.CAPTURE_RESULT, request.cwd ?? process.cwd(), [
|
|
2547
2038
|
"review", "capture-result",
|
|
2548
2039
|
...request.argumentTokens,
|
|
2549
2040
|
...(carriesContext || request.cwd === undefined ? [] : ["--cwd", request.cwd]),
|
|
2550
2041
|
"--input", resultFile,
|
|
2551
|
-
], true, request.signal, executable
|
|
2552
|
-
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_RESULT, true, () =>
|
|
2042
|
+
], true, request.signal, executable);
|
|
2043
|
+
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_RESULT, true, () => {
|
|
2044
|
+
const body = object(execution.body);
|
|
2045
|
+
if (body.schema === "gentle-ai.review-last-event-closure/v1") {
|
|
2046
|
+
const closure = decodeReviewLastEventClosureV1(body);
|
|
2047
|
+
if (closure.operation !== "review/capture-result") throw new TypeError("capture-result returned a closure for another operation");
|
|
2048
|
+
return closure;
|
|
2049
|
+
}
|
|
2050
|
+
return decodeNativeAdmittedResultManifest(body);
|
|
2051
|
+
});
|
|
2553
2052
|
} finally {
|
|
2554
2053
|
await this.cleanupDirectory(directory).catch(() => undefined);
|
|
2555
2054
|
}
|
|
2556
2055
|
}
|
|
2557
2056
|
|
|
2057
|
+
// Relays the provider-issued acknowledgement exactly as rendered. A success
|
|
2058
|
+
// burns the authority and its artifacts; a refusal still arrives as the
|
|
2059
|
+
// ordinary typed failure envelope. Two success shapes exist and both are
|
|
2060
|
+
// the same burn: every published release up to v2.5.0-rc.3 prints nothing
|
|
2061
|
+
// (resolved as `undefined`, byte-for-byte the pinned behaviour), and
|
|
2062
|
+
// gentle-ai #3947 prints one `gentle-ai.review-acknowledged/v1` envelope
|
|
2063
|
+
// naming the burned lineage, target, and consumed revision. Any other
|
|
2064
|
+
// output on a zero exit is schema-incompatible with the mutation outcome
|
|
2065
|
+
// unknown, exactly like a malformed terminal closure: the caller
|
|
2066
|
+
// reconciles through STATUS and never infers the burn from prose.
|
|
2067
|
+
async acknowledgeApproved(request ) {
|
|
2068
|
+
if (request.argumentTokens.length === 0) throw new TypeError("Native ACKNOWLEDGE_APPROVED requires the provider-issued argument tokens");
|
|
2069
|
+
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native ACKNOWLEDGE_APPROVED argument tokens must all be non-empty strings");
|
|
2070
|
+
if (request.argumentTokens.some((token) => token.includes("{{value}}"))) throw new TypeError("Native ACKNOWLEDGE_APPROVED argument tokens carry no caller-substituted value");
|
|
2071
|
+
const executable = this.executablePath(NATIVE_REVIEW_OPERATION.ACKNOWLEDGE_APPROVED, true);
|
|
2072
|
+
const execution = await this.invoke(NATIVE_REVIEW_OPERATION.ACKNOWLEDGE_APPROVED, request.cwd, [
|
|
2073
|
+
"review", "acknowledge-approved", ...request.argumentTokens,
|
|
2074
|
+
], true, request.signal, executable, [], false);
|
|
2075
|
+
if (execution.silent) return undefined;
|
|
2076
|
+
return decode(NATIVE_REVIEW_OPERATION.ACKNOWLEDGE_APPROVED, true, () => decodeReviewAcknowledgedV1(execution.body, request.binding ?? {}));
|
|
2077
|
+
}
|
|
2078
|
+
|
|
2079
|
+
async captureCorrectionPlan(request ) {
|
|
2080
|
+
if (request.argumentTokens.length === 0) throw new TypeError("Native CAPTURE_CORRECTION_PLAN requires the provider-issued argument tokens");
|
|
2081
|
+
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native CAPTURE_CORRECTION_PLAN argument tokens must all be non-empty strings");
|
|
2082
|
+
if (!Number.isSafeInteger(request.correctionLines) || request.correctionLines < 1 || request.correctionLines > 200) throw new TypeError("Native CAPTURE_CORRECTION_PLAN correction lines must be a positive integer up to 200");
|
|
2083
|
+
const valueIndex = request.argumentTokens.findIndex((token) => token.includes("{{value}}"));
|
|
2084
|
+
if (valueIndex < 0 || request.argumentTokens.filter((token) => token.includes("{{value}}")).length !== 1) throw new TypeError("Native CAPTURE_CORRECTION_PLAN requires exactly one provider-issued {{value}} token");
|
|
2085
|
+
const argumentTokens = request.argumentTokens.map((token, index) => index === valueIndex ? token.replaceAll("{{value}}", String(request.correctionLines)) : token);
|
|
2086
|
+
const executable = this.executablePath(NATIVE_REVIEW_OPERATION.CAPTURE_CORRECTION_PLAN, true);
|
|
2087
|
+
const execution = await this.invoke(NATIVE_REVIEW_OPERATION.CAPTURE_CORRECTION_PLAN, request.cwd, [
|
|
2088
|
+
"review", "capture-correction-plan", ...argumentTokens,
|
|
2089
|
+
], true, request.signal, executable);
|
|
2090
|
+
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_CORRECTION_PLAN, true, () => {
|
|
2091
|
+
const closure = decodeReviewLastEventClosureV1(execution.body);
|
|
2092
|
+
if (closure.operation !== "review.capture-correction-plan") throw new TypeError("capture-correction-plan returned a closure for another operation");
|
|
2093
|
+
return closure;
|
|
2094
|
+
});
|
|
2095
|
+
}
|
|
2096
|
+
|
|
2558
2097
|
// gentle-pi#311 P4-roles: executes one provider-rendered self-contained
|
|
2559
2098
|
// role capture vector exactly as rendered — one CLI invocation, verbatim
|
|
2560
2099
|
// tokens in provider order, in the foreground. Go materializes the role
|
|
@@ -2563,17 +2102,26 @@ export class NativeReviewCliV216 {
|
|
|
2563
2102
|
// --cwd: the vector's --repository-context is authoritative and mutually
|
|
2564
2103
|
// exclusive with a path). The central adapter injects the relay handshake
|
|
2565
2104
|
// environment on this spawn like on every other gentle-ai invocation.
|
|
2566
|
-
async captureProviderRole(request )
|
|
2567
|
-
|
|
2568
|
-
|
|
2105
|
+
async captureProviderRole(request ) {
|
|
2106
|
+
if (!isNativeReviewProviderRoleCaptureOperation(request.captureOperation)) throw new TypeError(`Native CAPTURE_PROVIDER_ROLE supports only review.capture-refuter and review.capture-validation, received ${JSON.stringify(request.captureOperation)}`);
|
|
2107
|
+
const verb = request.captureOperation.slice("review.".length);
|
|
2108
|
+
const expectedClosureOperation = NATIVE_REVIEW_PROVIDER_ROLE_CAPTURE_CLOSURE_OPERATION[request.captureOperation];
|
|
2569
2109
|
if (request.argumentTokens.length === 0) throw new TypeError("Native CAPTURE_PROVIDER_ROLE requires the provider-rendered argument tokens");
|
|
2570
2110
|
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native CAPTURE_PROVIDER_ROLE argument tokens must all be non-empty strings");
|
|
2571
|
-
const executable = this.
|
|
2111
|
+
const executable = this.executablePath(NATIVE_REVIEW_OPERATION.CAPTURE_PROVIDER_ROLE, true);
|
|
2572
2112
|
const execution = await this.invoke(NATIVE_REVIEW_OPERATION.CAPTURE_PROVIDER_ROLE, request.cwd, [
|
|
2573
2113
|
"review", verb,
|
|
2574
2114
|
...request.argumentTokens,
|
|
2575
|
-
], true, request.signal, executable
|
|
2576
|
-
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_PROVIDER_ROLE, true, () =>
|
|
2115
|
+
], true, request.signal, executable);
|
|
2116
|
+
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_PROVIDER_ROLE, true, () => {
|
|
2117
|
+
const body = object(execution.body);
|
|
2118
|
+
if (body.schema === "gentle-ai.review-last-event-closure/v1") {
|
|
2119
|
+
const closure = decodeReviewLastEventClosureV1(body);
|
|
2120
|
+
if (closure.operation !== expectedClosureOperation) throw new TypeError("provider role capture returned a closure for another operation");
|
|
2121
|
+
return closure;
|
|
2122
|
+
}
|
|
2123
|
+
return decodeNativeProviderRoleCaptureArtifact(body);
|
|
2124
|
+
});
|
|
2577
2125
|
}
|
|
2578
2126
|
|
|
2579
2127
|
// gentle-pi#311 P5: executes one provider-rendered `review.finalize`
|
|
@@ -2582,15 +2130,6 @@ export class NativeReviewCliV216 {
|
|
|
2582
2130
|
// --captured-results=true`); Pi assembles no reviewer, refuter, or
|
|
2583
2131
|
// validator documents for this lane — the provider discovers its own
|
|
2584
2132
|
// admitted role and lens slots.
|
|
2585
|
-
async finalizeTransition(request ) {
|
|
2586
|
-
if (request.argumentTokens.length === 0) throw new TypeError("Native FINALIZE transition requires the provider-rendered argument tokens");
|
|
2587
|
-
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native FINALIZE transition argument tokens must all be non-empty strings");
|
|
2588
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.FINALIZE, request.cwd, [
|
|
2589
|
-
"review", "finalize",
|
|
2590
|
-
...request.argumentTokens,
|
|
2591
|
-
], true, request.signal);
|
|
2592
|
-
return this.decodeFinalizeTransitionExecution(execution);
|
|
2593
|
-
}
|
|
2594
2133
|
|
|
2595
2134
|
// Same misbinding class as capture-evidence (live smoke, 2026-08-16): the
|
|
2596
2135
|
// correction PLAN and TARGETED VALIDATION collect slots render `finalize`
|
|
@@ -2601,92 +2140,8 @@ export class NativeReviewCliV216 {
|
|
|
2601
2140
|
// intent reconciliation, so the tokens pass through verbatim with only the
|
|
2602
2141
|
// {{value}} substitution: a literal for correction_lines, a staged 0o600
|
|
2603
2142
|
// artifact path for a validation document.
|
|
2604
|
-
async finalizeSubmission(request ) {
|
|
2605
|
-
if (request.argumentTokens.length === 0) throw new TypeError("Native FINALIZE submission requires the provider-rendered argument tokens");
|
|
2606
|
-
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native FINALIZE submission argument tokens must all be non-empty strings");
|
|
2607
|
-
if ((request.valueLiteral === undefined) === (request.valueDocument === undefined)) throw new TypeError("Native FINALIZE submission takes exactly one of valueLiteral or valueDocument");
|
|
2608
|
-
const valueToken = request.argumentTokens[request.valueSubstitutionLocation];
|
|
2609
|
-
if (valueToken === undefined || !valueToken.includes("{{value}}")) throw new TypeError("Native FINALIZE submission must render exactly one {{value}} slot token");
|
|
2610
|
-
if (request.valueDocument !== undefined && request.valueDocument.length === 0) throw new TypeError("Native FINALIZE submission value document must contain at least one byte");
|
|
2611
|
-
const directory = request.valueDocument === undefined ? undefined : await mkdtemp(join(tmpdir(), "gentle-ai-finalize-submission-"));
|
|
2612
|
-
try {
|
|
2613
|
-
let substituted ;
|
|
2614
|
-
if (directory !== undefined) {
|
|
2615
|
-
await chmod(directory, 0o700);
|
|
2616
|
-
const valueFile = join(directory, "value.json");
|
|
2617
|
-
await writeFile(valueFile, request.valueDocument , { encoding: "utf8", mode: 0o600 });
|
|
2618
|
-
await chmod(valueFile, 0o600);
|
|
2619
|
-
substituted = valueFile;
|
|
2620
|
-
} else {
|
|
2621
|
-
substituted = request.valueLiteral ;
|
|
2622
|
-
}
|
|
2623
|
-
const resolved = request.argumentTokens.map((token, index) => index === request.valueSubstitutionLocation ? token.replaceAll("{{value}}", substituted) : token);
|
|
2624
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.FINALIZE, request.cwd, [
|
|
2625
|
-
"review", "finalize",
|
|
2626
|
-
...resolved,
|
|
2627
|
-
], true, request.signal);
|
|
2628
|
-
return this.decodeFinalizeTransitionExecution(execution);
|
|
2629
|
-
} finally {
|
|
2630
|
-
if (directory !== undefined) await this.cleanupDirectory(directory).catch(() => undefined);
|
|
2631
|
-
}
|
|
2632
|
-
}
|
|
2633
2143
|
|
|
2634
|
-
decodeFinalizeTransitionExecution(execution ) {
|
|
2635
|
-
return decode(NATIVE_REVIEW_OPERATION.FINALIZE, true, () => {
|
|
2636
|
-
const body = object(execution.body);
|
|
2637
|
-
// A transition rendered with `--contract` answers with the negotiated
|
|
2638
|
-
// operation envelope; one rendered without (the pi runtime form)
|
|
2639
|
-
// answers with the plain `review/finalize` shape. Both are decoded
|
|
2640
|
-
// strictly; nothing else is accepted.
|
|
2641
|
-
if (typeof body.schema === "string") {
|
|
2642
|
-
const envelope = decodeReviewOperationV2(body);
|
|
2643
|
-
if (envelope.operation !== "review.finalize") throw new Error("wrong finalize operation envelope");
|
|
2644
|
-
const result = envelope.result;
|
|
2645
|
-
return {
|
|
2646
|
-
lineageId: requiredString(result.lineage_id),
|
|
2647
|
-
state: requiredString(result.state),
|
|
2648
|
-
action: requiredString(result.action),
|
|
2649
|
-
storeRevision: requiredString(result.store_revision),
|
|
2650
|
-
...(result.validation_request === undefined ? {} : { validationRequest: result.validation_request }),
|
|
2651
|
-
...(result.escalation === undefined ? {} : { escalation: requiredString(result.escalation) }),
|
|
2652
|
-
};
|
|
2653
|
-
}
|
|
2654
|
-
const plain = exactObject(body, ["operation", "lineage_id", "state", "action", "store_revision"], ["receipt_path", "validation_request", "escalation"]);
|
|
2655
|
-
if (plain.operation !== "review/finalize") throw new Error("wrong finalize discriminator");
|
|
2656
|
-
const state = requiredString(plain.state);
|
|
2657
|
-
if (!(NATIVE_FINALIZE_STATE ).includes(state)) throw new Error("unknown finalize state");
|
|
2658
|
-
return {
|
|
2659
|
-
lineageId: requiredString(plain.lineage_id),
|
|
2660
|
-
state,
|
|
2661
|
-
action: requiredString(plain.action),
|
|
2662
|
-
storeRevision: requiredString(plain.store_revision),
|
|
2663
|
-
...(plain.receipt_path === undefined ? {} : { receiptPath: requiredString(plain.receipt_path) }),
|
|
2664
|
-
...(plain.validation_request === undefined ? {} : { validationRequest: plain.validation_request }),
|
|
2665
|
-
...(plain.escalation === undefined ? {} : { escalation: requiredString(plain.escalation) }),
|
|
2666
|
-
};
|
|
2667
|
-
});
|
|
2668
|
-
}
|
|
2669
2144
|
|
|
2670
|
-
async captureEvidence(request ) {
|
|
2671
|
-
if (!(NATIVE_REVIEW_CAPTURE_OUTCOME ).includes(request.outcome)) throw new TypeError("Native CAPTURE_EVIDENCE outcome must be passed, verification_failed, or procedural_tooling_failed");
|
|
2672
|
-
if (request.evidenceDocument.length === 0) throw new TypeError("Native CAPTURE_EVIDENCE evidence must contain at least one byte");
|
|
2673
|
-
const directory = await mkdtemp(join(tmpdir(), "gentle-ai-capture-evidence-"));
|
|
2674
|
-
try {
|
|
2675
|
-
await chmod(directory, 0o700);
|
|
2676
|
-
const evidenceFile = await this.stageEvidence(directory, request.evidenceDocument);
|
|
2677
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.CAPTURE_EVIDENCE, request.cwd, [
|
|
2678
|
-
"review", "capture-evidence", "--cwd", request.cwd,
|
|
2679
|
-
"--lineage", request.lineageId,
|
|
2680
|
-
"--target", request.targetIdentity,
|
|
2681
|
-
"--expected-revision", request.expectedRevision,
|
|
2682
|
-
"--outcome", request.outcome,
|
|
2683
|
-
"--input", evidenceFile,
|
|
2684
|
-
], true, request.signal);
|
|
2685
|
-
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_EVIDENCE, true, () => decodeNativeReviewVerificationEvidence(execution.body));
|
|
2686
|
-
} finally {
|
|
2687
|
-
await this.cleanupDirectory(directory).catch(() => undefined);
|
|
2688
|
-
}
|
|
2689
|
-
}
|
|
2690
2145
|
|
|
2691
2146
|
// Field defect (fambig, 2026-08-16): at every evidence-pending sub-state
|
|
2692
2147
|
// the collect slot renders the identity native demands — for a correction
|
|
@@ -2695,85 +2150,62 @@ export class NativeReviewCliV216 {
|
|
|
2695
2150
|
// {{outcome}} and {{input}} slots substituted. Same verbatim-token
|
|
2696
2151
|
// discipline as captureResult; --repository-context is authoritative and
|
|
2697
2152
|
// mutually exclusive with a path.
|
|
2698
|
-
async captureEvidenceSubmission(request ) {
|
|
2699
|
-
if (!(NATIVE_REVIEW_CAPTURE_OUTCOME ).includes(request.outcome)) throw new TypeError("Native CAPTURE_EVIDENCE outcome must be passed, verification_failed, or procedural_tooling_failed");
|
|
2700
|
-
if (request.evidenceDocument.length === 0) throw new TypeError("Native CAPTURE_EVIDENCE evidence must contain at least one byte");
|
|
2701
|
-
if (request.argumentTokens.length === 0) throw new TypeError("Native CAPTURE_EVIDENCE submission requires the provider-rendered argument tokens");
|
|
2702
|
-
if (request.argumentTokens.some((token) => typeof token !== "string" || token.length === 0)) throw new TypeError("Native CAPTURE_EVIDENCE submission argument tokens must all be non-empty strings");
|
|
2703
|
-
const outcomeToken = request.argumentTokens[request.outcomeSubstitutionLocation];
|
|
2704
|
-
const inputToken = request.argumentTokens[request.inputSubstitutionLocation];
|
|
2705
|
-
if (request.outcomeSubstitutionLocation === request.inputSubstitutionLocation || outcomeToken === undefined || !outcomeToken.includes("{{outcome}}")) throw new TypeError("Native CAPTURE_EVIDENCE submission must render exactly one {{outcome}} slot token");
|
|
2706
|
-
if (inputToken === undefined || !inputToken.includes("{{input}}")) throw new TypeError("Native CAPTURE_EVIDENCE submission must render exactly one {{input}} slot token");
|
|
2707
|
-
const carriesContext = request.argumentTokens.some((token) => token === "--repository-context" || token.startsWith("--repository-context="));
|
|
2708
|
-
if (carriesContext && request.cwd !== undefined) throw new TypeError("Native CAPTURE_EVIDENCE submission takes a repository context or --cwd, never both");
|
|
2709
|
-
const directory = await mkdtemp(join(tmpdir(), "gentle-ai-capture-evidence-"));
|
|
2710
|
-
try {
|
|
2711
|
-
await chmod(directory, 0o700);
|
|
2712
|
-
const evidenceFile = await this.stageEvidence(directory, request.evidenceDocument);
|
|
2713
|
-
const resolved = request.argumentTokens.map((token, index) =>
|
|
2714
|
-
index === request.outcomeSubstitutionLocation
|
|
2715
|
-
? token.replaceAll("{{outcome}}", request.outcome)
|
|
2716
|
-
: index === request.inputSubstitutionLocation
|
|
2717
|
-
? token.replaceAll("{{input}}", evidenceFile)
|
|
2718
|
-
: token);
|
|
2719
|
-
const execution = await this.negotiated(NATIVE_REVIEW_OPERATION.CAPTURE_EVIDENCE, request.cwd ?? process.cwd(), [
|
|
2720
|
-
"review", "capture-evidence",
|
|
2721
|
-
...resolved,
|
|
2722
|
-
...(carriesContext || request.cwd === undefined ? [] : ["--cwd", request.cwd]),
|
|
2723
|
-
], true, request.signal);
|
|
2724
|
-
return decode(NATIVE_REVIEW_OPERATION.CAPTURE_EVIDENCE, true, () => decodeNativeReviewVerificationEvidence(execution.body));
|
|
2725
|
-
} finally {
|
|
2726
|
-
await this.cleanupDirectory(directory).catch(() => undefined);
|
|
2727
|
-
}
|
|
2728
|
-
}
|
|
2729
|
-
|
|
2730
|
-
reviewStatus(request ) {
|
|
2731
|
-
return this.legacy.reviewStatus(request);
|
|
2732
|
-
}
|
|
2733
2153
|
|
|
2734
|
-
|
|
2735
|
-
|
|
2154
|
+
async reviewStatus(request ) {
|
|
2155
|
+
const execution = await this.invoke(
|
|
2156
|
+
NATIVE_REVIEW_OPERATION.STATUS,
|
|
2157
|
+
request.cwd,
|
|
2158
|
+
["review", "status", "--cwd", request.cwd],
|
|
2159
|
+
false,
|
|
2160
|
+
request.signal,
|
|
2161
|
+
this.executablePath(NATIVE_REVIEW_OPERATION.STATUS, false),
|
|
2162
|
+
);
|
|
2163
|
+
const status = decode(NATIVE_REVIEW_OPERATION.STATUS, false, () => decodeNativeReviewStatus(execution.body));
|
|
2164
|
+
if (!await repositoriesMatch(request.cwd, status.repository)) throw nativeError(NATIVE_REVIEW_ERROR_CODE.IDENTITY_MISMATCH, NATIVE_REVIEW_OPERATION.STATUS, false, "native review status repository mismatch");
|
|
2165
|
+
return status;
|
|
2736
2166
|
}
|
|
2737
2167
|
|
|
2738
|
-
|
|
2739
|
-
|
|
2740
|
-
|
|
2741
|
-
|
|
2742
|
-
|
|
2168
|
+
async reviewMode(request ) {
|
|
2169
|
+
const cwd = await canonicalNativeReviewCwd(request.cwd);
|
|
2170
|
+
const mutating = request.operation !== NATIVE_REVIEW_MODE_OPERATION.STATUS;
|
|
2171
|
+
const execution = await this.invoke(
|
|
2172
|
+
NATIVE_REVIEW_OPERATION.MODE,
|
|
2173
|
+
cwd,
|
|
2174
|
+
["review", "mode", request.operation, "--cwd", cwd, ...(mutating ? ["--scope", "clone"] : []), "--json"],
|
|
2175
|
+
mutating,
|
|
2176
|
+
request.signal,
|
|
2177
|
+
this.executablePath(NATIVE_REVIEW_OPERATION.MODE, mutating),
|
|
2178
|
+
);
|
|
2179
|
+
return decode(NATIVE_REVIEW_OPERATION.MODE, mutating, () => decodeNativeReviewMode(execution.body, request.operation));
|
|
2743
2180
|
}
|
|
2744
2181
|
|
|
2745
2182
|
// Recovery commands are version-gated plain CLI operations outside the
|
|
2746
|
-
// negotiated integration-v1 contract, exactly like reviewStatus
|
|
2183
|
+
// negotiated integration-v1 contract, exactly like reviewStatus.
|
|
2747
2184
|
reclaim(request ) {
|
|
2748
|
-
return this.
|
|
2185
|
+
return this.plain.reclaim(request);
|
|
2749
2186
|
}
|
|
2750
2187
|
|
|
2751
2188
|
recover(request ) {
|
|
2752
|
-
return this.
|
|
2189
|
+
return this.plain.recover(request);
|
|
2753
2190
|
}
|
|
2754
2191
|
|
|
2755
2192
|
abandon(request ) {
|
|
2756
|
-
return this.
|
|
2193
|
+
return this.plain.abandon(request);
|
|
2757
2194
|
}
|
|
2758
2195
|
|
|
2759
2196
|
quarantineLegacy(request ) {
|
|
2760
|
-
return this.
|
|
2197
|
+
return this.plain.quarantineLegacy(request);
|
|
2761
2198
|
}
|
|
2762
2199
|
|
|
2763
2200
|
reconcileAuthority(request ) {
|
|
2764
|
-
return this.
|
|
2201
|
+
return this.plain.reconcileAuthority(request);
|
|
2765
2202
|
}
|
|
2766
2203
|
|
|
2767
2204
|
repairLegacyAlias(request ) {
|
|
2768
|
-
return this.
|
|
2205
|
+
return this.plain.repairLegacyAlias(request);
|
|
2769
2206
|
}
|
|
2770
2207
|
}
|
|
2771
2208
|
|
|
2772
2209
|
export function createNativeReviewCli(adapter , executable = resolveGentleAiBinary) {
|
|
2773
|
-
|
|
2774
|
-
return new NativeReviewCliV216(createNodeExecFileAdapter(), executable);
|
|
2210
|
+
return new NativeReviewCliV216(adapter ?? createNodeExecFileAdapter(), executable);
|
|
2775
2211
|
}
|
|
2776
|
-
|
|
2777
|
-
// Response-schema fixtures remain v2.1.3 historical contracts; the production
|
|
2778
|
-
// client above accepts only the v2.1.4 runtime release.
|
|
2779
|
-
export { NativeReviewCliV214 as NativeReviewCliV213 };
|