fix(server): surface ACP stderr when cursor-agent exits at session start #12625
Mergedcestercian(GitHub profile, opens in a new tab)merged 5 commits into
main fromrefs/pull/12625/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/provider/Layers/CursorAdapter.ts line 517OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -509,3 +514,4 @@509514 }510515511516 const cwd = path.resolve(input.cwd.trim());517+ const deprecatedCliKeys = readDeprecatedCursorCliJsonKeys(cwd);
- @@ -0,0 +14,21 @@14+export function appendAcpStderrTail(current: string, chunk: string): string {15+ const next = `${current}${chunk}`;16+ return next.length <= ACP_STDERR_TAIL_MAX_CHARS ? next : next.slice(-ACP_STDERR_TAIL_MAX_CHARS);17+}18+19+/** Bounded, redacted excerpt safe to put on user-facing adapter errors. */20+export function sanitizeAcpStderrExcerpt(21+ text: string,22+ environment: NodeJS.ProcessEnv = process.env,23+): string {24+ let result = text.replaceAll("\0", "");25+ const homes = [environment.HOME, environment.USERPROFILE, NodeOS.homedir()].filter(26+ (value): value is string => typeof value === "string" && value.length > 1,27+ );28+ for (const home of new Set(homes)) {29+ result = result.split(home).join("~");30+ }31+ result = result32+ .replace(PAIRING_URL_PATTERN, "[pairing-url]")33+ .replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]")34+ .replace(SECRET_TOKEN_PATTERN, "[redacted]");
- apps/server/src/provider/acp/AcpStderr.ts line 36Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -0,0 +18,21 @@18+ return next.length <= ACP_STDERR_TAIL_MAX_CHARS ? next : next.slice(-ACP_STDERR_TAIL_MAX_CHARS);19+}20+21+/** Bounded, redacted excerpt safe to put on user-facing adapter errors. */22+export function sanitizeAcpStderrExcerpt(23+ text: string,24+ environment: NodeJS.ProcessEnv = process.env,25+): string {26+ let result = text.replaceAll("\0", "");27+ const homes = [environment.HOME, environment.USERPROFILE, NodeOS.homedir()].filter(28+ (value): value is string => typeof value === "string" && value.length > 1,29+ );30+ for (const home of new Set(homes)) {31+ result = result.split(home).join("~");32+ }33+ result = result34+ .replace(PAIRING_URL_PATTERN, "[pairing-url]")35+ .replace(BEARER_TOKEN_PATTERN, "Bearer [redacted]")36+ .replace(BASIC_AUTH_PATTERN, "Authorization: Basic [redacted]")37+ .replace(API_KEY_HEADER_PATTERN, "x-api-key: [redacted]")38+ .replace(SECRET_TOKEN_PATTERN, "[redacted]");
github-actions[bot](GitHub profile, opens in a new tab) removed labelssize:L
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:M
github-actions[bot](GitHub profile, opens in a new tab) removed labelsvouch:unvouched
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
- apps/server/src/provider/acp/AcpStderr.ts lines 1 to 1OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1 @@1+// @effect-diagnostics nodeBuiltinImport:off@@ -95,3 +95,4 @@9595 {9696 code: Schema.optional(Schema.Number),9797 pid: Schema.optionalKey(Schema.Int),98+ stderr: Schema.optionalKey(Schema.String),
- @@ -0,0 +1,16 @@1+// @effect-diagnostics nodeBuiltinImport:off -- The excerpt sanitizer masks the home directory, which only the Node os module can resolve.2+import * as NodeOS from "node:os";3+4+/** Last few KiB of ACP child stderr kept for startup / exit diagnostics. */5+export const ACP_STDERR_TAIL_MAX_CHARS = 4_096;6+7+const PAIRING_URL_PATTERN = /https?:\/\/[^\s]*\/pair#[^\s]*/gi;8+const BEARER_TOKEN_PATTERN = /\bBearer\s+[A-Za-z0-9._\-+=/]+/gi;9+const BASIC_AUTH_PATTERN = /\bAuthorization:\s*Basic\s+\S+/gi;10+const API_KEY_HEADER_PATTERN = /\bx-api-key:\s*\S+/gi;11+const SECRET_TOKEN_PATTERN =12+ /\b(?:sk-[A-Za-z0-9][A-Za-z0-9-]{7,}|ghp_[A-Za-z0-9]+|xox[a-zA-Z]-[A-Za-z0-9-]+)\b/g;13+14+export function appendAcpStderrTail(current: string, chunk: string): string {15+ const next = `${current}${chunk}`;16+ return next.length <= ACP_STDERR_TAIL_MAX_CHARS ? next : next.slice(-ACP_STDERR_TAIL_MAX_CHARS);
juliusmarminge merged thisd6f2913
juliusmarminge closed this
Sign in to join this conversation.
macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed