Skip to content

Commit a04f664

Browse files
committed
fix(cursor): preserve grouped grep match text
Extract only the grep conversion from b950e543ecb52b3c7c7948050720635877fadddd. Keep the dependency patch reproducible without checkpoint or private worker changes.
1 parent 0c84e7c commit a04f664

5 files changed

Lines changed: 79 additions & 3 deletions

File tree

‎package.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"test:perf:v2-wire": "vp test run apps/server/src/orchestration-v2/WireProjection.test.ts apps/server/src/orchestration-v2/threadHistoryPaging.test.ts apps/server/src/orchestration-v2/ThreadStream.test.ts apps/server/src/orchestration-v2/ThreadTransportPerformance.test.ts apps/server/src/orchestration-v2/ShellStream.test.ts apps/server/src/orchestration-v2/CommandPolicy.test.ts apps/server/src/orchestration-v2/runtimeLayer.test.ts apps/server/src/ws.test.ts packages/contracts/src/orchestrationV2.test.ts packages/client-runtime/src/operations/commands.test.ts packages/client-runtime/src/operations/commands.performance.test.ts packages/client-runtime/src/state/boundedThreadSnapshotHttp.test.ts packages/client-runtime/src/state/threadHistoryController.test.ts packages/client-runtime/src/state/threadHistoryMerge.test.ts packages/client-runtime/src/state/threads-sync.test.ts packages/client-runtime/src/state/shellReducer.test.ts",
3737
"test:resource-monitor": "cargo test --locked --manifest-path native/resource-monitor/Cargo.toml",
3838
"test:desktop-smoke": "vp run --filter @t3tools/desktop smoke-test",
39+
"patch:cursor-grep": "node scripts/lib/cursor-grep-patch.ts",
3940
"fmt": "vp fmt",
4041
"fmt:check": "vp fmt --check",
4142
"dist:desktop:artifact": "node scripts/build-desktop-artifact.ts",

‎patches/@[email protected]‎

Lines changed: 8 additions & 0 deletions
Large diffs are not rendered by default.

‎pnpm-lock.yaml‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎pnpm-workspace.yaml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,7 @@ packageExtensions:
353353
vite-plus: "catalog:"
354354

355355
patchedDependencies:
356+
356357
357358
358359

‎scripts/lib/cursor-grep-patch.ts‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// @effect-diagnostics nodeBuiltinImport:off -- Maintains the pinned SDK patch without loading a provider.
2+
import * as NodeCrypto from "node:crypto";
3+
import * as NodeFSP from "node:fs/promises";
4+
import * as NodePath from "node:path";
5+
6+
const originalGrepOutput =
7+
"matches:e.result.value.matches?.map((e=>({file:e.file,...void 0!==e.lineNumber?{lineNumber:e.lineNumber}:{},line:e.line,...e.beforeContext?{beforeContext:e.beforeContext}:{},...e.afterContext?{afterContext:e.afterContext}:{}})))??[],totalMatches:e.result.value.totalMatches??0";
8+
const patchedGrepOutput = [
9+
"matches:e.result.value.matches?.flatMap((e=>{",
10+
"if(!Array.isArray(e.matches))return[{file:e.file,...void 0!==e.lineNumber?{lineNumber:e.lineNumber}:{},line:e.line,...e.beforeContext?{beforeContext:e.beforeContext}:{},...e.afterContext?{afterContext:e.afterContext}:{}}];",
11+
"return e.matches.flatMap(((t,r,n)=>{if(t.isContextLine)return[];let s=r,i=r;for(;s>0&&n[s-1].isContextLine;)s--;for(;i+1<n.length&&n[i+1].isContextLine;)i++;",
12+
"const o=n.slice(s,r).map((e=>e.content)),a=n.slice(r+1,i+1).map((e=>e.content));",
13+
"return[{file:e.file,...void 0!==t.lineNumber?{lineNumber:t.lineNumber}:{},line:t.content,...o.length?{beforeContext:o}:{},...a.length?{afterContext:a}:{}}]}))",
14+
"}))??[],totalMatches:e.result.value.totalMatchedLines??e.result.value.totalMatches??0",
15+
].join("");
16+
17+
const originalSha256 = "c57599bbc8c9e18c55d8635c6c1621d746022254308b544ad04469bb9cf274ef";
18+
const patchedSha256 = "43e958124dea446e7e00d15f7736276e923634a4c7e3a13f92fd1582f241d806";
19+
20+
function sha256(source: string): string {
21+
return NodeCrypto.createHash("sha256").update(source).digest("hex");
22+
}
23+
24+
function cursorGrepSource(source: string, target: "original" | "patched"): string {
25+
const hash = sha256(source);
26+
if (hash !== originalSha256 && hash !== patchedSha256) {
27+
throw new Error(`Unexpected @cursor/sdk 1.0.35 689.js hash: ${hash}`);
28+
}
29+
const expected = target === "original" ? originalSha256 : patchedSha256;
30+
if (hash === expected) return source;
31+
const [before, after] =
32+
target === "original"
33+
? [patchedGrepOutput, originalGrepOutput]
34+
: [originalGrepOutput, patchedGrepOutput];
35+
if (source.split(before).length !== 2) throw new Error("Ambiguous SDK grep patch anchor");
36+
const result = source.replace(before, () => after);
37+
if (sha256(result) !== expected) throw new Error("Unexpected generated SDK grep hash");
38+
return result;
39+
}
40+
41+
// Regenerate with: node scripts/lib/cursor-grep-patch.ts generate <sdk-dir> <patch-file>.
42+
const [command, sdkDirectory, patchFile] = process.argv.slice(2);
43+
if (!sdkDirectory || (command !== "generate" && command !== "verify")) {
44+
throw new Error("Usage: cursor-grep-patch.ts generate <sdk-dir> <patch-file> | verify <sdk-dir>");
45+
}
46+
const source = await NodeFSP.readFile(NodePath.join(sdkDirectory, "dist/cjs/689.js"), "utf8");
47+
if (command === "verify") {
48+
if (patchFile !== undefined || sha256(source) !== patchedSha256) {
49+
throw new Error("The installed @cursor/sdk 1.0.35 does not contain the expected grep patch");
50+
}
51+
} else {
52+
if (!patchFile) throw new Error("A destination patch file is required");
53+
const original = cursorGrepSource(source, "original");
54+
const patched = cursorGrepSource(source, "patched");
55+
if (original.includes("\n") || patched.includes("\n")) {
56+
throw new Error("Expected one minified line in 689.js");
57+
}
58+
await NodeFSP.writeFile(
59+
patchFile,
60+
"diff --git a/dist/cjs/689.js b/dist/cjs/689.js\n" +
61+
"--- a/dist/cjs/689.js\n+++ b/dist/cjs/689.js\n@@ -1 +1 @@\n" +
62+
`-${original}\n\\ No newline at end of file\n` +
63+
`+${patched}\n\\ No newline at end of file\n`,
64+
);
65+
}

0 commit comments

Comments
 (0)