Skip to content

Commit 994acb0

Browse files
committed
Add a golden closed intent gate
1 parent 02d84b1 commit 994acb0

9 files changed

Lines changed: 401 additions & 12 deletions

‎package.json‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,14 +160,15 @@
160160
"test:core": "npm run build:core && node packages/core/test/run-context-planner-tests.js && node packages/core/test/run-adapter-registry-tests.js && node packages/core/test/run-git-error-tests.js",
161161
"build:cli": "npm run build:core && npm run build --workspace @getripple/cli",
162162
"build:mcp": "npm run build:core && npm run build --workspace @getripple/mcp",
163-
"test:cli": "npm run build:cli && node packages/cli/test/run-cli-tests.js && node packages/cli/test/run-policy-tests.js && node packages/cli/test/run-golden-init-proof.js && node packages/cli/test/run-golden-doctor-contract-proof.js && node packages/cli/test/run-golden-gitignore-hygiene-proof.js && node packages/cli/test/run-golden-drift-control-proof.js && node packages/cli/test/run-golden-approval-control-proof.js && node packages/cli/test/run-golden-handoff-proof.js && node packages/cli/test/run-golden-ci-gate-proof.js",
163+
"test:cli": "npm run build:cli && node packages/cli/test/run-cli-tests.js && node packages/cli/test/run-policy-tests.js && node packages/cli/test/run-golden-init-proof.js && node packages/cli/test/run-golden-doctor-contract-proof.js && node packages/cli/test/run-golden-gitignore-hygiene-proof.js && node packages/cli/test/run-golden-drift-control-proof.js && node packages/cli/test/run-golden-approval-control-proof.js && node packages/cli/test/run-golden-closed-intent-gate-proof.js && node packages/cli/test/run-golden-handoff-proof.js && node packages/cli/test/run-golden-ci-gate-proof.js",
164164
"test:agent-workflow": "npm run build:cli && node packages/cli/test/run-agent-workflow-tests.js",
165165
"test:init": "npm run build:cli && node packages/cli/test/run-golden-init-proof.js",
166166
"test:doctor-contract": "npm run build:cli && node packages/cli/test/run-golden-doctor-contract-proof.js",
167167
"test:gitignore-hygiene": "npm run build:cli && node packages/cli/test/run-golden-gitignore-hygiene-proof.js",
168168
"test:package-install": "npm run build:cli && node packages/cli/test/run-golden-package-install-proof.js",
169169
"test:drift-control": "npm run build:cli && node packages/cli/test/run-golden-drift-control-proof.js",
170170
"test:approval-control": "npm run build:cli && node packages/cli/test/run-golden-approval-control-proof.js",
171+
"test:closed-intent-gate": "npm run build:cli && node packages/cli/test/run-golden-closed-intent-gate-proof.js",
171172
"test:agent-handoff": "npm run build:cli && node packages/cli/test/run-golden-handoff-proof.js",
172173
"test:ci-gate": "npm run build:cli && node packages/cli/test/run-golden-ci-gate-proof.js",
173174
"test:gate-output": "npm run build:cli && node packages/cli/test/run-golden-gate-output-proof.js",
@@ -178,13 +179,15 @@
178179
"proof:package-install": "npm run test:package-install",
179180
"proof:drift-control": "npm run test:drift-control",
180181
"proof:approval-control": "npm run test:approval-control",
182+
"proof:closed-intent-gate": "npm run test:closed-intent-gate",
181183
"proof:agent-handoff": "npm run test:agent-handoff",
182184
"proof:ci-gate": "npm run test:ci-gate",
183185
"proof:gate-output": "npm run test:gate-output",
184186
"proof:large-gate-performance": "npm run test:large-gate-performance",
185-
"test:mcp": "npm run build:mcp && node packages/mcp/test/run-mcp-tests.js && node packages/mcp/test/run-golden-mcp-doctor-contract-proof.js && node packages/mcp/test/run-golden-mcp-gate-proof.js && node packages/mcp/test/run-golden-mcp-gitignore-hygiene-proof.js && node packages/mcp/test/run-golden-mcp-fast-gate-proof.js && node packages/mcp/test/run-golden-mcp-large-gate-performance-proof.js && node packages/mcp/test/run-golden-mcp-stdio-gate-proof.js",
187+
"test:mcp": "npm run build:mcp && node packages/mcp/test/run-mcp-tests.js && node packages/mcp/test/run-golden-mcp-doctor-contract-proof.js && node packages/mcp/test/run-golden-mcp-gate-proof.js && node packages/mcp/test/run-golden-mcp-closed-intent-gate-proof.js && node packages/mcp/test/run-golden-mcp-gitignore-hygiene-proof.js && node packages/mcp/test/run-golden-mcp-fast-gate-proof.js && node packages/mcp/test/run-golden-mcp-large-gate-performance-proof.js && node packages/mcp/test/run-golden-mcp-stdio-gate-proof.js",
186188
"test:mcp-doctor-contract": "npm run build:mcp && node packages/mcp/test/run-golden-mcp-doctor-contract-proof.js",
187189
"test:mcp-gate": "npm run build:mcp && node packages/mcp/test/run-golden-mcp-gate-proof.js",
190+
"test:mcp-closed-intent-gate": "npm run build:mcp && node packages/mcp/test/run-golden-mcp-closed-intent-gate-proof.js",
188191
"test:mcp-gitignore-hygiene": "npm run build:mcp && node packages/mcp/test/run-golden-mcp-gitignore-hygiene-proof.js",
189192
"test:mcp-fast-gate": "npm run build:mcp && node packages/mcp/test/run-golden-mcp-fast-gate-proof.js",
190193
"test:mcp-large-gate-performance": "npm run build:mcp && node packages/mcp/test/run-golden-mcp-large-gate-performance-proof.js",
@@ -194,13 +197,14 @@
194197
"smoke:mcp": "npm run build:mcp && node packages/mcp/test/smoke-mcp.js",
195198
"proof:mcp-doctor-contract": "npm run test:mcp-doctor-contract",
196199
"proof:mcp-gate": "npm run test:mcp-gate",
200+
"proof:mcp-closed-intent-gate": "npm run test:mcp-closed-intent-gate",
197201
"proof:mcp-gitignore-hygiene": "npm run test:mcp-gitignore-hygiene",
198202
"proof:mcp-fast-gate": "npm run test:mcp-fast-gate",
199203
"proof:mcp-large-gate-performance": "npm run test:mcp-large-gate-performance",
200204
"proof:mcp-stdio-gate": "npm run test:mcp-stdio-gate",
201205
"proof:mcp-package-install": "npm run test:mcp-package-install",
202206
"proof:publish-readiness": "npm run test:publish-readiness",
203-
"test:agent-control": "npm run build:cli && node packages/cli/test/run-golden-init-proof.js && node packages/cli/test/run-golden-doctor-contract-proof.js && node packages/cli/test/run-golden-gitignore-hygiene-proof.js && node packages/cli/test/run-golden-package-install-proof.js && node packages/cli/test/run-golden-drift-control-proof.js && node packages/cli/test/run-golden-approval-control-proof.js && node packages/cli/test/run-golden-handoff-proof.js && node packages/cli/test/run-golden-ci-gate-proof.js && node packages/cli/test/run-golden-gate-output-proof.js && npm run build:mcp && node packages/mcp/test/run-golden-mcp-doctor-contract-proof.js && node packages/mcp/test/run-golden-mcp-gate-proof.js && node packages/mcp/test/run-golden-mcp-gitignore-hygiene-proof.js && node packages/mcp/test/run-golden-mcp-fast-gate-proof.js && node packages/mcp/test/run-golden-mcp-large-gate-performance-proof.js && node packages/mcp/test/run-golden-mcp-stdio-gate-proof.js && node packages/mcp/test/run-golden-mcp-package-install-proof.js && node test/run-package-readiness-proof.js",
207+
"test:agent-control": "npm run build:cli && node packages/cli/test/run-golden-init-proof.js && node packages/cli/test/run-golden-doctor-contract-proof.js && node packages/cli/test/run-golden-gitignore-hygiene-proof.js && node packages/cli/test/run-golden-package-install-proof.js && node packages/cli/test/run-golden-drift-control-proof.js && node packages/cli/test/run-golden-approval-control-proof.js && node packages/cli/test/run-golden-closed-intent-gate-proof.js && node packages/cli/test/run-golden-handoff-proof.js && node packages/cli/test/run-golden-ci-gate-proof.js && node packages/cli/test/run-golden-gate-output-proof.js && npm run build:mcp && node packages/mcp/test/run-golden-mcp-doctor-contract-proof.js && node packages/mcp/test/run-golden-mcp-gate-proof.js && node packages/mcp/test/run-golden-mcp-closed-intent-gate-proof.js && node packages/mcp/test/run-golden-mcp-gitignore-hygiene-proof.js && node packages/mcp/test/run-golden-mcp-fast-gate-proof.js && node packages/mcp/test/run-golden-mcp-large-gate-performance-proof.js && node packages/mcp/test/run-golden-mcp-stdio-gate-proof.js && node packages/mcp/test/run-golden-mcp-package-install-proof.js && node test/run-package-readiness-proof.js",
204208
"proof:agent-control": "npm run test:agent-control",
205209
"test:release-check": "node test/run-release-check-proof.js",
206210
"test:persona": "node test/run-product-persona-proof.js",

‎packages/cli/src/index.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3997,6 +3997,16 @@ async function checkCommand(options: CliOptions): Promise<void> {
39973997
const workspaceRoot = resolveWorkspaceRoot(".");
39983998
const baseRef = options.base ?? "HEAD";
39993999
const mode = selectedChangeMode(options);
4000+
let loadedIntent: ChangeIntent | undefined;
4001+
if (options.intent) {
4002+
try {
4003+
loadedIntent = loadChangeIntent(workspaceRoot, options.intent);
4004+
} catch (err) {
4005+
if (!options.strict && !options.githubAnnotations) {
4006+
throw err;
4007+
}
4008+
}
4009+
}
40004010
const checkFiles = listFilesForChangeMode(workspaceRoot, mode, baseRef);
40014011
const engine = createFastCheckEngine(workspaceRoot);
40024012

@@ -4012,7 +4022,7 @@ async function checkCommand(options: CliOptions): Promise<void> {
40124022
let summary: StagedCheckWithIntentSummary = stagedSummary;
40134023
if (options.intent) {
40144024
try {
4015-
const intent = loadChangeIntent(workspaceRoot, options.intent);
4025+
const intent = loadedIntent ?? loadChangeIntent(workspaceRoot, options.intent);
40164026
summary = validateStagedCheckAgainstIntent(
40174027
stagedSummary,
40184028
intent,
@@ -4089,9 +4099,9 @@ async function buildAuditFromCliOptions(options: CliOptions): Promise<RippleAudi
40894099
const intentRef = options.intent ?? "latest";
40904100
const mode = selectedChangeMode(options);
40914101
const baseRef = options.base ?? "HEAD";
4092-
const files = listFilesForChangeMode(workspaceRoot, mode, baseRef);
40934102
const intent = loadChangeIntent(workspaceRoot, intentRef);
40944103
const currentPolicyExplanation = currentPolicyExplanationForIntent(workspaceRoot, intent);
4104+
const files = listFilesForChangeMode(workspaceRoot, mode, baseRef);
40954105

40964106
return buildAuditForFiles({
40974107
workspaceRoot,
@@ -5462,8 +5472,8 @@ function printAgentPolicyExplanation(
54625472

54635473
async function repairCommand(options: CliOptions): Promise<void> {
54645474
const workspaceRoot = resolveWorkspaceRoot(".");
5465-
const stagedFiles = listGitStagedFiles(workspaceRoot);
54665475
const intent = loadChangeIntent(workspaceRoot, options.intent ?? "latest");
5476+
const stagedFiles = listGitStagedFiles(workspaceRoot);
54675477
const engine = createFastCheckEngine(workspaceRoot);
54685478

54695479
try {

‎packages/cli/test/run-cli-tests.js‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,20 @@ function main() {
19191919
inactiveIntentStatus.nextSteps.some((step) => step.includes("ripple plan")),
19201920
"inactive intent status should tell humans how to start a new boundary"
19211921
);
1922+
const closedIntentGate = runCliResult(["gate", "--intent", "latest", "--json"]);
1923+
assert.notStrictEqual(
1924+
closedIntentGate.status,
1925+
0,
1926+
"gate should fail closed instead of treating a closed marker as active intent"
1927+
);
1928+
assert(
1929+
closedIntentGate.stderr.includes("saved boundary is closed"),
1930+
"gate should explain that the saved boundary is closed"
1931+
);
1932+
assert(
1933+
closedIntentGate.stderr.includes("Agents must not continue from a closed boundary"),
1934+
"gate should tell agents not to continue from a closed boundary"
1935+
);
19221936

19231937
// Keep a CLI-level proof that function mode saves a symbol boundary.
19241938
const functionBoundaryPlan = runCliJson([
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
const assert = require("assert");
2+
const fs = require("fs");
3+
const path = require("path");
4+
const { spawnSync } = require("child_process");
5+
6+
const repoRoot = path.resolve(__dirname, "..", "..", "..");
7+
const cliPath = path.join(repoRoot, "packages", "cli", "dist", "index.js");
8+
const workspaceRoot = path.join(
9+
repoRoot,
10+
"test",
11+
".tmp",
12+
`golden-closed-intent-gate-proof-${Date.now()}`,
13+
);
14+
15+
function writeFile(relativePath, contents) {
16+
const filePath = path.join(workspaceRoot, relativePath);
17+
fs.mkdirSync(path.dirname(filePath), { recursive: true });
18+
fs.writeFileSync(filePath, contents);
19+
}
20+
21+
function runCliResult(args) {
22+
return spawnSync(process.execPath, [cliPath, ...args], {
23+
cwd: workspaceRoot,
24+
encoding: "utf8",
25+
stdio: ["ignore", "pipe", "pipe"],
26+
});
27+
}
28+
29+
function assertIncludes(output, expected, label) {
30+
assert(
31+
output.includes(expected),
32+
`${label} should include ${expected}\n\nOutput:\n${output}`,
33+
);
34+
}
35+
36+
function assertNotIncludes(output, unexpected, label) {
37+
assert(
38+
!output.includes(unexpected),
39+
`${label} should not include ${unexpected}\n\nOutput:\n${output}`,
40+
);
41+
}
42+
43+
function setupClosedIntentFixture() {
44+
if (!fs.existsSync(cliPath)) {
45+
throw new Error("CLI build output is missing. Run npm run build:cli first.");
46+
}
47+
48+
writeFile(
49+
"package.json",
50+
JSON.stringify({ name: "ripple-closed-intent-gate-proof" }, null, 2),
51+
);
52+
writeFile(
53+
".ripple/intents/latest.json",
54+
`${JSON.stringify(
55+
{
56+
protocol: "ripple-closed-intent",
57+
version: 1,
58+
closedAt: "2026-06-12T00:00:00.000Z",
59+
closedBy: "Ripple Golden Proof",
60+
reason: "previous boundary is complete",
61+
originalIntentPath: ".ripple/intents/latest.json",
62+
intent: {
63+
protocol: "ripple-change-intent",
64+
version: 1,
65+
id: "intent-golden-closed",
66+
createdAt: "2026-06-12T00:00:00.000Z",
67+
task: "change auth behavior",
68+
targetFile: "src/auth.ts",
69+
controlMode: "file",
70+
humanGate: "required-before-edit",
71+
boundaryRisk: "critical",
72+
},
73+
},
74+
null,
75+
2,
76+
)}\n`,
77+
);
78+
}
79+
80+
function main() {
81+
setupClosedIntentFixture();
82+
83+
const result = runCliResult(["gate", "--intent", "latest"]);
84+
if (result.error) {
85+
throw result.error;
86+
}
87+
const stdout = result.stdout ?? "";
88+
const stderr = result.stderr ?? "";
89+
const output = `${stdout}\n${stderr}`;
90+
91+
assert.notStrictEqual(
92+
result.status,
93+
0,
94+
"closed intent gate should stop instead of continuing",
95+
);
96+
assert.strictEqual(
97+
stdout,
98+
"",
99+
"closed intent gate should not print a successful gate report",
100+
);
101+
102+
[
103+
"Ripple CLI error:",
104+
"No active Ripple change intent found",
105+
"the saved boundary is closed",
106+
"Closed by: Ripple Golden Proof.",
107+
"Reason: previous boundary is complete",
108+
"Agents must not continue from a closed boundary.",
109+
"Run ripple intent status",
110+
"create a new saved plan",
111+
"ripple plan --file <file> --task \"<task>\" --agent --save",
112+
].forEach((expected) =>
113+
assertIncludes(output, expected, "golden closed intent gate proof"),
114+
);
115+
116+
[
117+
"git diff",
118+
"Git could not be started",
119+
"Could not read staged files",
120+
"Ripple gate: CONTINUE",
121+
].forEach((unexpected) =>
122+
assertNotIncludes(output, unexpected, "golden closed intent gate proof"),
123+
);
124+
125+
console.log("Ripple golden closed intent gate proof passed");
126+
console.log(`Workspace: ${workspaceRoot}`);
127+
console.log("Gate: closed intent fails closed before git");
128+
}
129+
130+
main();

‎packages/core/src/change-intent.ts‎

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,26 @@ export function loadChangeIntent(
11261126
intentPath: string = "latest"
11271127
): ChangeIntent {
11281128
const targetPath = resolveIntentPath(workspaceRoot, intentPath);
1129-
const parsed = JSON.parse(fs.readFileSync(targetPath, "utf8")) as unknown;
1129+
let raw: string;
1130+
try {
1131+
raw = fs.readFileSync(targetPath, "utf8");
1132+
} catch (err) {
1133+
if (isNodeError(err) && err.code === "ENOENT") {
1134+
throw new Error(
1135+
`No active Ripple change intent found at ${targetPath}. Run ripple plan --file <file> --task "<task>" --agent --save before an agent edits.`
1136+
);
1137+
}
1138+
throw err;
1139+
}
1140+
1141+
let parsed: unknown;
1142+
try {
1143+
parsed = JSON.parse(raw) as unknown;
1144+
} catch (err) {
1145+
throw new Error(
1146+
`Invalid Ripple change intent JSON at ${targetPath}. Ask the human to inspect or recreate the saved boundary before continuing. ${errorMessage(err)}`
1147+
);
1148+
}
11301149
return assertChangeIntent(parsed, targetPath);
11311150
}
11321151

@@ -2564,10 +2583,17 @@ function resolveIntentPath(workspaceRoot: string, intentPath: string): string {
25642583

25652584
function assertChangeIntent(value: unknown, sourcePath: string): ChangeIntent {
25662585
if (!isRecord(value)) {
2567-
throw new Error(`Invalid Ripple change intent: ${sourcePath}`);
2586+
throw new Error(
2587+
`Invalid Ripple change intent at ${sourcePath}. Ask the human to inspect or recreate the saved boundary before continuing.`
2588+
);
2589+
}
2590+
if (value.protocol === "ripple-closed-intent") {
2591+
throw new Error(closedIntentErrorMessage(value, sourcePath));
25682592
}
25692593
if (value.protocol !== INTENT_PROTOCOL || value.version !== INTENT_VERSION) {
2570-
throw new Error(`Unsupported Ripple change intent: ${sourcePath}`);
2594+
throw new Error(
2595+
`No active Ripple change intent found at ${sourcePath}. Found protocol ${String(value.protocol)} instead of ${INTENT_PROTOCOL}. Run ripple intent status, then create a new saved plan before the agent continues.`
2596+
);
25712597
}
25722598
if (
25732599
typeof value.id !== "string" ||
@@ -2584,11 +2610,36 @@ function assertChangeIntent(value: unknown, sourcePath: string): ChangeIntent {
25842610
!Array.isArray(value.verificationTargets) ||
25852611
typeof value.why !== "string"
25862612
) {
2587-
throw new Error(`Malformed Ripple change intent: ${sourcePath}`);
2613+
throw new Error(
2614+
`Malformed Ripple change intent at ${sourcePath}. Ask the human to inspect or recreate the saved boundary before continuing.`
2615+
);
25882616
}
25892617
return normalizeChangeIntent(value as RawChangeIntent);
25902618
}
25912619

2620+
function closedIntentErrorMessage(value: Record<string, unknown>, sourcePath: string): string {
2621+
const reason = typeof value.reason === "string" && value.reason.trim().length > 0
2622+
? ` Reason: ${value.reason.trim()}`
2623+
: "";
2624+
const closedBy = typeof value.closedBy === "string" && value.closedBy.trim().length > 0
2625+
? ` Closed by: ${value.closedBy.trim()}.`
2626+
: "";
2627+
return [
2628+
`No active Ripple change intent found at ${sourcePath}; the saved boundary is closed.`,
2629+
`${closedBy}${reason}`,
2630+
"Agents must not continue from a closed boundary.",
2631+
"Run ripple intent status, then create a new saved plan with ripple plan --file <file> --task \"<task>\" --agent --save before editing.",
2632+
].filter(Boolean).join(" ");
2633+
}
2634+
2635+
function isNodeError(err: unknown): err is NodeJS.ErrnoException {
2636+
return err instanceof Error && "code" in err;
2637+
}
2638+
2639+
function errorMessage(err: unknown): string {
2640+
return err instanceof Error ? err.message : String(err);
2641+
}
2642+
25922643
function normalizeChangeIntent(intent: RawChangeIntent): ChangeIntent {
25932644
const controlMode = isControlMode(intent.controlMode) ? intent.controlMode : "file";
25942645
const editableFiles = uniqueItems(

‎packages/mcp/src/tools.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -890,9 +890,9 @@ export class RippleMcpToolHost {
890890
}
891891

892892
private async checkStaged(args: RippleMcpToolCallArgs): Promise<StagedCheckWithIntentSummary> {
893-
const stagedFiles = listGitStagedFiles(this.workspaceRoot);
894893
const intentPath = optionalString(args, "intentPath");
895894
const intent = intentPath ? loadChangeIntent(this.workspaceRoot, intentPath) : undefined;
895+
const stagedFiles = listGitStagedFiles(this.workspaceRoot);
896896
await this.prepareFastCheck(stagedFiles, intent);
897897

898898
const stagedSummary = buildStagedCheckSummary(this.engine, {
@@ -915,9 +915,9 @@ export class RippleMcpToolHost {
915915

916916
private async checkChanged(args: RippleMcpToolCallArgs): Promise<StagedCheckWithIntentSummary> {
917917
const baseRef = optionalString(args, "baseRef") ?? "HEAD";
918-
const changedFiles = listGitChangedFiles(this.workspaceRoot, baseRef);
919918
const intentPath = optionalString(args, "intentPath");
920919
const intent = intentPath ? loadChangeIntent(this.workspaceRoot, intentPath) : undefined;
920+
const changedFiles = listGitChangedFiles(this.workspaceRoot, baseRef);
921921
await this.prepareFastCheck(changedFiles, intent);
922922

923923
const changedSummary = buildStagedCheckSummary(this.engine, {

0 commit comments

Comments
 (0)