@yansigit/opencodex 2.33.0 → 2.35.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 +3 -3
- package/gui/dist/assets/index-BjCaHxdz.js +112 -0
- package/gui/dist/assets/index-DLkXOXLC.css +1 -0
- package/gui/dist/index.html +2 -2
- package/package.json +1 -1
- package/src/adapters/anthropic.ts +79 -2
- package/src/adapters/command-code.ts +141 -23
- package/src/adapters/cursor/call-id.ts +44 -0
- package/src/adapters/cursor/checkpoint-store.ts +15 -10
- package/src/adapters/cursor/discovery.ts +60 -2
- package/src/adapters/cursor/effort-map.ts +79 -1
- package/src/adapters/cursor/envelope-echo.ts +162 -0
- package/src/adapters/cursor/live-models.ts +7 -2
- package/src/adapters/cursor/live-transport.ts +17 -1
- package/src/adapters/cursor/message-mapper.ts +4 -1
- package/src/adapters/cursor/native-exec-fs.ts +13 -12
- package/src/adapters/cursor/native-exec-network.ts +3 -5
- package/src/adapters/cursor/native-exec-policy.ts +47 -0
- package/src/adapters/cursor/native-exec-shell.ts +116 -31
- package/src/adapters/cursor/native-exec.ts +38 -10
- package/src/adapters/cursor/protobuf-events.ts +28 -2
- package/src/adapters/cursor/protobuf-request.ts +93 -41
- package/src/adapters/cursor/request-builder.ts +39 -10
- package/src/adapters/cursor/tool-definitions.ts +27 -3
- package/src/adapters/cursor/tool-result-normalize.ts +51 -6
- package/src/adapters/cursor/types.ts +23 -4
- package/src/adapters/cursor.ts +170 -29
- package/src/adapters/google-aistudio-parser.ts +49 -0
- package/src/adapters/google-antigravity-replay.ts +105 -25
- package/src/adapters/google-antigravity-wire.ts +5 -0
- package/src/adapters/google-errors.ts +41 -12
- package/src/adapters/google-http.ts +12 -11
- package/src/adapters/google.ts +219 -36
- package/src/adapters/image.ts +1 -1
- package/src/adapters/kiro-constants.ts +15 -0
- package/src/adapters/kiro-tools.ts +43 -15
- package/src/adapters/kiro.ts +54 -9
- package/src/adapters/openai-chat.ts +286 -242
- package/src/adapters/openai-responses.ts +335 -24
- package/src/adapters/run-turn-queue.ts +36 -1
- package/src/adapters/tool-catalog-nudge.ts +2 -2
- package/src/adapters/xai-tool-schema.ts +436 -0
- package/src/bridge.ts +67 -26
- package/src/chat/inbound.ts +29 -1
- package/src/chat/outbound.ts +15 -7
- package/src/claude/agents-inject.ts +8 -1
- package/src/claude/outbound.ts +10 -8
- package/src/cli/account-api.ts +27 -7
- package/src/cli/account-extended.ts +10 -3
- package/src/cli/account.ts +29 -5
- package/src/cli/alias.ts +66 -0
- package/src/cli/claude.ts +26 -1
- package/src/cli/dispatch.ts +13 -1
- package/src/cli/help.ts +1 -0
- package/src/cli/index.ts +6 -1
- package/src/cli/init.ts +1 -0
- package/src/cli/models-runtime.ts +95 -0
- package/src/cli/models.ts +13 -7
- package/src/cli/provider-runtime.ts +16 -2
- package/src/cli/registry.ts +6 -1
- package/src/cli/telemetry-commands.ts +25 -0
- package/src/cli/v2.ts +34 -10
- package/src/codex/account-pause.ts +2 -1
- package/src/codex/account-priority.ts +3 -2
- package/src/codex/app-server-processes.ts +80 -6
- package/src/codex/auth-api.ts +48 -8
- package/src/codex/auth-context.ts +21 -18
- package/src/codex/catalog/aggregation.ts +6 -0
- package/src/codex/catalog/model-metadata.ts +13 -1
- package/src/codex/catalog/native-models.ts +5 -2
- package/src/codex/catalog/parsing.ts +16 -0
- package/src/codex/catalog/provider-fetch.ts +20 -3
- package/src/codex/catalog/sync.ts +127 -2
- package/src/codex/catalog.ts +1 -1
- package/src/codex/codex-write-lock.ts +3 -1
- package/src/codex/convergence-types.ts +1 -1
- package/src/codex/convergence.ts +22 -2
- package/src/codex/desired-state.ts +2 -2
- package/src/codex/desktop-app-restart.ts +18 -5
- package/src/codex/inject-coordination.ts +83 -0
- package/src/codex/inject.ts +14 -1
- package/src/codex/log-guard/inspect.ts +22 -4
- package/src/codex/model-entitlements.ts +9 -2
- package/src/codex/prompt-layers.ts +371 -25
- package/src/codex/prompt-text-probe.ts +238 -0
- package/src/codex/quota.ts +123 -18
- package/src/codex/routing.ts +9 -0
- package/src/codex/subagent-model-fallback.ts +198 -27
- package/src/codex/transition-state.ts +107 -8
- package/src/combos/types.ts +10 -0
- package/src/compatibility/openai-responses.ts +33 -1
- package/src/config/autonomous-remediation.ts +21 -0
- package/src/config/provider-validation.ts +14 -0
- package/src/config/rebase-provenance.ts +68 -0
- package/src/config.ts +191 -17
- package/src/generated/compatibility-version.json +279 -159
- package/src/generated/model-metadata.ts +3 -0
- package/src/images/loop.ts +5 -4
- package/src/lab/conformance/fixtures/protocol-v1-cases.json +1 -1
- package/src/lab/fabric/producer-child.ts +1 -1
- package/src/lib/config-ownership.ts +20 -0
- package/src/lib/errors.ts +11 -2
- package/src/lib/package-tree-integrity.ts +101 -0
- package/src/oauth/aistudio-credentials.ts +65 -0
- package/src/oauth/aistudio-native-daemon.ts +116 -0
- package/src/oauth/aistudio-session-sync.ts +95 -0
- package/src/oauth/generic-account-failover.ts +231 -0
- package/src/oauth/google-aistudio-auth.ts +98 -0
- package/src/oauth/index.ts +57 -5
- package/src/oauth/key-providers.ts +18 -1
- package/src/oauth/kiro.ts +45 -0
- package/src/oauth/login-cli.ts +65 -1
- package/src/oauth/types.ts +15 -0
- package/src/providers/codex-capacity.ts +5 -2
- package/src/providers/command-code-efforts.ts +38 -6
- package/src/providers/context-cap.ts +4 -3
- package/src/providers/default-aliases.ts +65 -0
- package/src/providers/derive.ts +29 -1
- package/src/providers/fastwire.ts +7 -1
- package/src/providers/model-presets.ts +119 -0
- package/src/providers/new-model-policy.ts +146 -0
- package/src/providers/provider-id-rewrite.ts +2 -1
- package/src/providers/quota.ts +157 -46
- package/src/providers/registry.ts +184 -71
- package/src/providers/slug-codec.ts +52 -0
- package/src/responses/code-mode-helper-compat.ts +50 -0
- package/src/responses/custom-tool-compat.ts +34 -10
- package/src/responses/parser.ts +4 -0
- package/src/responses/schema.ts +5 -1
- package/src/responses/thought-signature-replay.ts +17 -0
- package/src/router.ts +43 -2
- package/src/routing/account-pool/cooldown.ts +8 -0
- package/src/routing/account-pool/index.ts +1 -0
- package/src/routing/analytics.ts +1 -0
- package/src/routing/quota.ts +10 -0
- package/src/server/auth-cors.ts +24 -0
- package/src/server/chat-completions.ts +26 -16
- package/src/server/chat-native-sse.ts +3 -3
- package/src/server/chat-native.ts +30 -11
- package/src/server/claude-messages.ts +1 -1
- package/src/server/effort-policy.ts +16 -0
- package/src/server/index.ts +180 -14
- package/src/server/lifecycle.ts +52 -1
- package/src/server/management/agent-settings-routes.ts +31 -15
- package/src/server/management/codex-prompt-routes.ts +570 -0
- package/src/server/management/combo-routes.ts +2 -1
- package/src/server/management/config-routes.ts +27 -9
- package/src/server/management/context.ts +9 -0
- package/src/server/management/logs-usage-routes.ts +11 -5
- package/src/server/management/model-routes.ts +266 -0
- package/src/server/management/oauth-account-routes.ts +13 -3
- package/src/server/management/provider-routes.ts +137 -3
- package/src/server/management/routing-profile-routes.ts +2 -2
- package/src/server/management-api.ts +2 -0
- package/src/server/port-reclaim.ts +19 -1
- package/src/server/relay-eager.ts +147 -20
- package/src/server/relay.ts +251 -19
- package/src/server/request-log-conversation.ts +33 -0
- package/src/server/request-log.ts +48 -21
- package/src/server/responses/collaboration.ts +42 -5
- package/src/server/responses/combo-stream-preflight.ts +10 -3
- package/src/server/responses/core.ts +575 -140
- package/src/server/responses/empty-completion-guard.ts +35 -0
- package/src/server/responses/fetch-helpers.ts +14 -6
- package/src/server/responses/input-admission.ts +3 -1
- package/src/server/responses/passthrough-error.ts +33 -9
- package/src/server/responses/policy-fallback.ts +1 -1
- package/src/server/responses/responses-field-backfill.ts +105 -13
- package/src/server/responses/ws-upstream.ts +35 -5
- package/src/server/responses-custom-tool-repair.ts +52 -7
- package/src/server/responses-terminal-repair.ts +25 -4
- package/src/server/sse-frame-buffer.ts +31 -4
- package/src/server/ws-bridge.ts +14 -2
- package/src/smoke/fingerprint-cache.ts +133 -0
- package/src/smoke/live-scenarios.ts +33 -0
- package/src/smoke/runner.ts +119 -0
- package/src/telemetry/dispatcher.ts +44 -0
- package/src/telemetry/fingerprint.ts +24 -0
- package/src/telemetry/hook.ts +43 -0
- package/src/telemetry/ledger.ts +54 -0
- package/src/telemetry/types.ts +23 -0
- package/src/types/config.ts +66 -14
- package/src/types/provider.ts +79 -1
- package/src/types/request.ts +18 -10
- package/src/types/tools.ts +30 -11
- package/src/types.ts +1 -0
- package/src/usage/command-code-manifest.ts +116 -0
- package/src/usage/cost.ts +2 -2
- package/src/usage/expected-prices.ts +126 -24
- package/src/usage/log.ts +18 -8
- package/src/usage/summary.ts +34 -12
- package/src/web-search/exa-executor.ts +40 -9
- package/src/web-search/index.ts +16 -8
- package/src/web-search/loop.ts +5 -4
- package/gui/dist/assets/index-DKLr4LTE.js +0 -102
- package/gui/dist/assets/index-DrSQdTRd.css +0 -1
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* External Cursor output quarantine (devlog 260826 gaps 10-11).
|
|
3
|
+
*
|
|
4
|
+
* Gap 10: flattened tool-result history can prime an external model to echo the
|
|
5
|
+
* "[Tool Result]" envelope as its own reply.
|
|
6
|
+
*
|
|
7
|
+
* Gap 11: a model can invent a blocked native-tool attempt in visible commentary
|
|
8
|
+
* even though the only real current-turn tool is the advertised Codex bridge.
|
|
9
|
+
*
|
|
10
|
+
* Both failures are observable only at the output boundary. The sniffers below
|
|
11
|
+
* hold a bounded prefix until it either diverges or proves the failure, allowing
|
|
12
|
+
* cursor.ts to retry before any invalid text reaches the client.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
const ECHO_MARKERS = ["[Tool Result]", "[Tool Error]", "[tool_result]"] as const;
|
|
16
|
+
const MAX_SNIFF_BYTES = 40;
|
|
17
|
+
const MAX_ROUTING_COMMENTARY_BYTES = 512;
|
|
18
|
+
/** Aggregate quarantine cap: past this, flush and disarm. */
|
|
19
|
+
const MAX_HOLD_BYTES = 8 * 1024;
|
|
20
|
+
const encoder = new TextEncoder();
|
|
21
|
+
|
|
22
|
+
export class CursorToolResultEchoError extends Error {
|
|
23
|
+
readonly code = "cursor_tool_result_echo";
|
|
24
|
+
constructor(marker: string) {
|
|
25
|
+
super(
|
|
26
|
+
"Cursor external model echoed the replayed tool-result envelope (\"" + marker
|
|
27
|
+
+ "\") instead of continuing the task.",
|
|
28
|
+
);
|
|
29
|
+
this.name = "CursorToolResultEchoError";
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export class CursorRoutingCommentaryError extends Error {
|
|
34
|
+
readonly code = "cursor_routing_commentary_hallucination";
|
|
35
|
+
constructor() {
|
|
36
|
+
super("Cursor external model invented a blocked tool surface before any tool call occurred.");
|
|
37
|
+
this.name = "CursorRoutingCommentaryError";
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export type EchoSnifferDecision =
|
|
42
|
+
| { kind: "hold" }
|
|
43
|
+
| { kind: "flush" }
|
|
44
|
+
| { kind: "echo"; marker: string };
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Incremental envelope-prefix sniffer. Leading whitespace is tolerated so a
|
|
48
|
+
* marker copied after a newline is still caught.
|
|
49
|
+
*/
|
|
50
|
+
export class CursorEnvelopeEchoSniffer {
|
|
51
|
+
private buffered = "";
|
|
52
|
+
private byteCount = 0;
|
|
53
|
+
private done = false;
|
|
54
|
+
|
|
55
|
+
get settled(): boolean {
|
|
56
|
+
return this.done;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
feed(textDelta: string): EchoSnifferDecision {
|
|
60
|
+
if (this.done) return { kind: "flush" };
|
|
61
|
+
this.buffered += textDelta;
|
|
62
|
+
this.byteCount += encoder.encode(textDelta).byteLength;
|
|
63
|
+
const probe = this.buffered.replace(/^\s+/, "");
|
|
64
|
+
for (const marker of ECHO_MARKERS) {
|
|
65
|
+
if (probe.startsWith(marker)) {
|
|
66
|
+
this.done = true;
|
|
67
|
+
return { kind: "echo", marker };
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const stillPrefix = ECHO_MARKERS.some(marker =>
|
|
71
|
+
probe.length < marker.length && marker.startsWith(probe),
|
|
72
|
+
);
|
|
73
|
+
if (stillPrefix && this.byteCount <= MAX_SNIFF_BYTES && this.buffered.length < MAX_HOLD_BYTES) {
|
|
74
|
+
return { kind: "hold" };
|
|
75
|
+
}
|
|
76
|
+
this.done = true;
|
|
77
|
+
return { kind: "flush" };
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
finish(): EchoSnifferDecision {
|
|
81
|
+
if (this.done) return { kind: "flush" };
|
|
82
|
+
this.done = true;
|
|
83
|
+
return { kind: "flush" };
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export type RoutingCommentaryDecision =
|
|
88
|
+
| { kind: "hold" }
|
|
89
|
+
| { kind: "flush" }
|
|
90
|
+
| { kind: "hallucination" };
|
|
91
|
+
|
|
92
|
+
const ROUTING_NATIVE_TOOL_NAME = /\b(shell|read|grep|list|bash)\b/giu;
|
|
93
|
+
const ROUTING_TOOL_HINT =
|
|
94
|
+
/(?:\b(?:shell|read|grep|list|bash)\b|exec_command|shell_command|브리지|네이티브\s*(?:셸|쉘))/iu;
|
|
95
|
+
const ROUTING_FAILURE_CLAIM =
|
|
96
|
+
/(?:blocked|unavailable|interrupted|차단|중단|막혀)/iu;
|
|
97
|
+
const ROUTING_REDIRECT_CLAIM =
|
|
98
|
+
/(?:exec_command|shell_command|\bexec\b|브리지|redirected|fallback|switch(?:ed|ing)?|전환|우회|통과(?:되|하)|다른\s*(?:도구|경로)|경로로)/iu;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Quarantines the first line of code-mode / bridge output long enough to reject
|
|
102
|
+
* an impossible routing claim. It requires a failure claim plus either an
|
|
103
|
+
* explicit redirect to another execution surface or two distinct unadvertised
|
|
104
|
+
* native-tool names; a legitimate sentence such as "Shell is unavailable on
|
|
105
|
+
* this OS" therefore passes.
|
|
106
|
+
*/
|
|
107
|
+
export class CursorRoutingCommentarySniffer {
|
|
108
|
+
private buffered = "";
|
|
109
|
+
private byteCount = 0;
|
|
110
|
+
private done = false;
|
|
111
|
+
|
|
112
|
+
get settled(): boolean {
|
|
113
|
+
return this.done;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
feed(textDelta: string): RoutingCommentaryDecision {
|
|
117
|
+
if (this.done) return { kind: "flush" };
|
|
118
|
+
this.buffered += textDelta;
|
|
119
|
+
this.byteCount += encoder.encode(textDelta).byteLength;
|
|
120
|
+
if (this.matchesHallucination()) {
|
|
121
|
+
this.done = true;
|
|
122
|
+
return { kind: "hallucination" };
|
|
123
|
+
}
|
|
124
|
+
const lineBreakCount = (this.buffered.match(/\n/gu) ?? []).length;
|
|
125
|
+
const hasRoutingHint = ROUTING_TOOL_HINT.test(this.buffered) || ROUTING_FAILURE_CLAIM.test(this.buffered);
|
|
126
|
+
const pendingFailureClaim =
|
|
127
|
+
ROUTING_TOOL_HINT.test(this.buffered)
|
|
128
|
+
&& ROUTING_FAILURE_CLAIM.test(this.buffered)
|
|
129
|
+
&& lineBreakCount < 2;
|
|
130
|
+
if (
|
|
131
|
+
this.byteCount < MAX_ROUTING_COMMENTARY_BYTES
|
|
132
|
+
&& this.buffered.length < MAX_HOLD_BYTES
|
|
133
|
+
&& (lineBreakCount === 0 || pendingFailureClaim)
|
|
134
|
+
&& (hasRoutingHint || this.byteCount < 64)
|
|
135
|
+
) {
|
|
136
|
+
return { kind: "hold" };
|
|
137
|
+
}
|
|
138
|
+
this.done = true;
|
|
139
|
+
return { kind: "flush" };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
finish(): RoutingCommentaryDecision {
|
|
143
|
+
if (this.done) return { kind: "flush" };
|
|
144
|
+
this.done = true;
|
|
145
|
+
return this.matchesHallucination() ? { kind: "hallucination" } : { kind: "flush" };
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
private matchesHallucination(): boolean {
|
|
149
|
+
if (!ROUTING_FAILURE_CLAIM.test(this.buffered)) return false;
|
|
150
|
+
const nativeTools = new Set(
|
|
151
|
+
[...this.buffered.matchAll(ROUTING_NATIVE_TOOL_NAME)].map(match => match[1]?.toLowerCase()),
|
|
152
|
+
);
|
|
153
|
+
if (nativeTools.size === 0) return false;
|
|
154
|
+
return ROUTING_REDIRECT_CLAIM.test(this.buffered) || nativeTools.size >= 2;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
export const CURSOR_ECHO_RETRY_CONTINUATION_TEXT =
|
|
159
|
+
"Your previous reply copied an internal tool-output record verbatim and was rejected. Continue the original task now: issue the next required tool call, or answer in your own words if no tool is needed.";
|
|
160
|
+
|
|
161
|
+
export const CURSOR_ROUTING_COMMENTARY_RETRY_TEXT =
|
|
162
|
+
"Your previous reply claimed an execution-surface failure that did not occur and was rejected. Use the current tool catalog as ground truth. Perform the requested operation through the advertised execution tool now, with no commentary before the tool call.";
|
|
@@ -43,7 +43,7 @@ export interface CursorUsableModelsOptions {
|
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
export type CursorUsableModelsResult =
|
|
46
|
-
| { ok: true; models: string[] }
|
|
46
|
+
| { ok: true; models: string[]; maxModeModels?: string[] }
|
|
47
47
|
| { ok: false; error: "auth" | "http" | "policy" | "transport" | "timeout" | "decode" | "empty" | "too_large"; detail?: string };
|
|
48
48
|
|
|
49
49
|
/** Test-only seam for management connectivity probes; production callers retain the HTTP/2 path. */
|
|
@@ -120,6 +120,7 @@ function decodeCursorUsableModels(bytes: Uint8Array): CursorUsableModelsResult {
|
|
|
120
120
|
// make stale configured ids such as `composer-2` look activated.
|
|
121
121
|
const ids: string[] = [];
|
|
122
122
|
const seenIds = new Set<string>();
|
|
123
|
+
const maxModeIds: string[] = [];
|
|
123
124
|
for (const model of response.models ?? []) {
|
|
124
125
|
const rawId = (model as { modelId?: string }).modelId;
|
|
125
126
|
if (typeof rawId !== "string") continue;
|
|
@@ -127,9 +128,13 @@ function decodeCursorUsableModels(bytes: Uint8Array): CursorUsableModelsResult {
|
|
|
127
128
|
if (!isValidModelDiscoveryModelId(id) || seenIds.has(id)) continue;
|
|
128
129
|
seenIds.add(id);
|
|
129
130
|
ids.push(id);
|
|
131
|
+
// Preserve Max-Mode capability for ultra/big-context auto-detection (devlog 260826 070).
|
|
132
|
+
if ((model as { maxMode?: boolean }).maxMode === true) maxModeIds.push(id);
|
|
130
133
|
if (ids.length >= CURSOR_MAX_DISCOVERED_MODELS) break;
|
|
131
134
|
}
|
|
132
|
-
return ids.length > 0
|
|
135
|
+
return ids.length > 0
|
|
136
|
+
? { ok: true, models: ids, ...(maxModeIds.length > 0 ? { maxModeModels: maxModeIds } : {}) }
|
|
137
|
+
: { ok: false, error: "empty" };
|
|
133
138
|
} catch {
|
|
134
139
|
return { ok: false, error: "decode", detail: "Invalid GetUsableModels protobuf response" };
|
|
135
140
|
}
|
|
@@ -75,6 +75,7 @@ import { desktopDepsFromConfig } from "./native-exec-desktop";
|
|
|
75
75
|
import {
|
|
76
76
|
buildCursorToolDefinitions,
|
|
77
77
|
cursorRequestAdvertisesApplyPatch,
|
|
78
|
+
cursorRequestUsesCodeMode,
|
|
78
79
|
cursorRequestHasShellAlias,
|
|
79
80
|
cursorToolArgNormalizeSchema,
|
|
80
81
|
cursorToolWireName,
|
|
@@ -421,6 +422,20 @@ export function finalizeAfterDrain(state: ReturnType<typeof createCursorProtobuf
|
|
|
421
422
|
export function clientToolFinalizeGraceMsForRequest(request: CursorRunRequest, baseGraceMs = CLIENT_TOOL_FINALIZE_GRACE_MS): number {
|
|
422
423
|
if (request.rawMessages?.at(-1)?.role === "toolResult") return baseGraceMs;
|
|
423
424
|
const text = activePromptText(request);
|
|
425
|
+
// Parallel-tool requests with several advertised tools get the expanded window regardless of
|
|
426
|
+
// prompt shape: external models (grok) assemble sibling calls serially over multiple frames,
|
|
427
|
+
// and the 50ms drain grace ended the turn after 1-2 of them (devlog 260826_cursor_responses_gap,
|
|
428
|
+
// live 10-parallel probe: calls=2 then calls=1).
|
|
429
|
+
if (request.parallelToolCalls === true && (request.tools?.length ?? 0) > 1) {
|
|
430
|
+
const advertised = request.tools?.length ?? 0;
|
|
431
|
+
return Math.max(
|
|
432
|
+
baseGraceMs,
|
|
433
|
+
Math.min(
|
|
434
|
+
GENERIC_TOOL_COUNT_MAX_FINALIZE_GRACE_MS,
|
|
435
|
+
Math.max(GENERIC_TOOL_COUNT_MIN_FINALIZE_GRACE_MS, advertised * GENERIC_TOOL_COUNT_PER_TOOL_GRACE_MS),
|
|
436
|
+
),
|
|
437
|
+
);
|
|
438
|
+
}
|
|
424
439
|
if (!cursorRequestHasShellAlias(request.tools) || !isGenericToolUseCountDemoPrompt(text)) return baseGraceMs;
|
|
425
440
|
const requestedCount = requestedCursorToolUseCount(text);
|
|
426
441
|
const expandedGraceMs = requestedCount
|
|
@@ -646,6 +661,7 @@ class LiveCursorTransport implements CursorTransport {
|
|
|
646
661
|
this.execContext = {
|
|
647
662
|
...this.execContext,
|
|
648
663
|
clientToolDefs,
|
|
664
|
+
codeMode: cursorRequestUsesCodeMode(request.tools, request.toolChoice),
|
|
649
665
|
rejectNativeFileMutations: cursorRequestAdvertisesApplyPatch(request.tools, request.toolChoice),
|
|
650
666
|
structuredEditAvailable: syntheticStructuredEditToolNames.size > 0,
|
|
651
667
|
};
|
|
@@ -1509,7 +1525,7 @@ class LiveCursorTransport implements CursorTransport {
|
|
|
1509
1525
|
const awaitedNativeArgsBeforeMapping = update?.case === "toolCallCompleted"
|
|
1510
1526
|
&& state.openToolCalls.get(update.value.callId)?.awaitingNativeArgs === true;
|
|
1511
1527
|
const mapped = mapCursorProtobufServerMessage(message, state);
|
|
1512
|
-
if (mapped.some(event => event.type === "text")) this.sawAssistantText = true;
|
|
1528
|
+
if (mapped.some(event => event.type === "text" || event.type === "thinking" || event.type === "tool_call_start" || event.type === "tool_call_end")) this.sawAssistantText = true;
|
|
1513
1529
|
const beganAwaitingNativeClientToolArgs = update?.case === "toolCallCompleted"
|
|
1514
1530
|
&& !awaitedNativeArgsBeforeMapping
|
|
1515
1531
|
&& state.openToolCalls.get(update.value.callId)?.awaitingNativeArgs === true;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { AdapterEvent } from "../../types";
|
|
2
|
+
import { encodeCursorCallId } from "./call-id";
|
|
2
3
|
import { cursorExecResult } from "./exec-policy";
|
|
3
4
|
import type { CursorClientMessage, CursorServerMessage } from "./types";
|
|
4
5
|
import type { CursorKvStore } from "./kv-store";
|
|
@@ -18,7 +19,9 @@ export function mapCursorServerMessage(
|
|
|
18
19
|
case "thinking":
|
|
19
20
|
return [{ type: "thinking_delta", thinking: message.thinking }];
|
|
20
21
|
case "tool_call_start":
|
|
21
|
-
|
|
22
|
+
// Cursor composite ids can contain a literal newline; Responses call_ids
|
|
23
|
+
// must stay single-line (see call-id.ts).
|
|
24
|
+
return [{ type: "tool_call_start", id: encodeCursorCallId(message.id), name: message.name }];
|
|
22
25
|
case "tool_call_delta":
|
|
23
26
|
return [{ type: "tool_call_delta", arguments: message.arguments }];
|
|
24
27
|
case "tool_call_end":
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
type GrepArgs,
|
|
35
35
|
} from "./gen/agent_pb";
|
|
36
36
|
import { errorText, execBytes, lineCount, textDecoder, textEncoder } from "./native-exec-common";
|
|
37
|
+
import { nativeLocalExecDisabledMessage, type CursorNativeExecPolicyContext } from "./native-exec-policy";
|
|
37
38
|
|
|
38
39
|
const MAX_GREP_FILES = 500;
|
|
39
40
|
const MAX_GREP_RESULTS = 200;
|
|
@@ -46,14 +47,14 @@ function codexNativeMutationRefusal(operation: "write" | "delete", structuredEdi
|
|
|
46
47
|
return `Cursor-native ${operation} is disabled for this Codex request because apply_patch is available.${structuredHint} No file was changed.`;
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
const NATIVE_LOCAL_EXEC_DISABLED =
|
|
50
|
-
"
|
|
50
|
+
export const NATIVE_LOCAL_EXEC_DISABLED =
|
|
51
|
+
"Re-issue this operation NOW through the catalog shell tool (`shell_command` / `exec_command`, or the listed `mcp_opencodex-responses_*` display alias) with the host-shell-safe equivalent: POSIX (`cat`, `head`, `ls`, `rg`, `grep`) or Windows PowerShell (`Get-Content`, `Get-ChildItem`, `Select-String`); use `apply_patch` for file edits. Do NOT narrate this redirect, do NOT comment on tool availability, and do NOT re-announce the task — just make the bridge call.";
|
|
51
52
|
|
|
52
|
-
export function rejectReadExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
|
|
53
|
+
export function rejectReadExecForPolicy(execMsg: ExecServerMessage, opts: CursorNativeExecPolicyContext = {}): Uint8Array {
|
|
53
54
|
if (execMsg.message.case !== "readArgs") throw new Error("invalid read exec");
|
|
54
55
|
const path = resolve(execMsg.message.value.path);
|
|
55
56
|
return execBytes(execMsg, "readResult", create(ReadResultSchema, {
|
|
56
|
-
result: { case: "error", value: create(ReadErrorSchema, { path, error:
|
|
57
|
+
result: { case: "error", value: create(ReadErrorSchema, { path, error: nativeLocalExecDisabledMessage(opts) }) },
|
|
57
58
|
}));
|
|
58
59
|
}
|
|
59
60
|
|
|
@@ -98,13 +99,13 @@ export function rejectWriteExecForApplyPatch(execMsg: ExecServerMessage, structu
|
|
|
98
99
|
}));
|
|
99
100
|
}
|
|
100
101
|
|
|
101
|
-
export function rejectWriteExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
|
|
102
|
+
export function rejectWriteExecForPolicy(execMsg: ExecServerMessage, opts: CursorNativeExecPolicyContext = {}): Uint8Array {
|
|
102
103
|
if (execMsg.message.case !== "writeArgs") throw new Error("invalid write exec");
|
|
103
104
|
const path = resolve(execMsg.message.value.path);
|
|
104
105
|
return execBytes(execMsg, "writeResult", create(WriteResultSchema, {
|
|
105
106
|
result: {
|
|
106
107
|
case: "rejected",
|
|
107
|
-
value: create(WriteRejectedSchema, { path, reason: `${
|
|
108
|
+
value: create(WriteRejectedSchema, { path, reason: `${nativeLocalExecDisabledMessage(opts)} No file was changed.` }),
|
|
108
109
|
},
|
|
109
110
|
}));
|
|
110
111
|
}
|
|
@@ -147,13 +148,13 @@ export function rejectDeleteExecForApplyPatch(execMsg: ExecServerMessage, struct
|
|
|
147
148
|
}));
|
|
148
149
|
}
|
|
149
150
|
|
|
150
|
-
export function rejectDeleteExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
|
|
151
|
+
export function rejectDeleteExecForPolicy(execMsg: ExecServerMessage, opts: CursorNativeExecPolicyContext = {}): Uint8Array {
|
|
151
152
|
if (execMsg.message.case !== "deleteArgs") throw new Error("invalid delete exec");
|
|
152
153
|
const path = resolve(execMsg.message.value.path);
|
|
153
154
|
return execBytes(execMsg, "deleteResult", create(DeleteResultSchema, {
|
|
154
155
|
result: {
|
|
155
156
|
case: "rejected",
|
|
156
|
-
value: create(DeleteRejectedSchema, { path, reason: `${
|
|
157
|
+
value: create(DeleteRejectedSchema, { path, reason: `${nativeLocalExecDisabledMessage(opts)} No file was changed.` }),
|
|
157
158
|
},
|
|
158
159
|
}));
|
|
159
160
|
}
|
|
@@ -188,11 +189,11 @@ export function deleteExec(execMsg: ExecServerMessage): Uint8Array {
|
|
|
188
189
|
}
|
|
189
190
|
}
|
|
190
191
|
|
|
191
|
-
export function rejectLsExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
|
|
192
|
+
export function rejectLsExecForPolicy(execMsg: ExecServerMessage, opts: CursorNativeExecPolicyContext = {}): Uint8Array {
|
|
192
193
|
if (execMsg.message.case !== "lsArgs") throw new Error("invalid ls exec");
|
|
193
194
|
const path = resolve(execMsg.message.value.path);
|
|
194
195
|
return execBytes(execMsg, "lsResult", create(LsResultSchema, {
|
|
195
|
-
result: { case: "error", value: create(LsErrorSchema, { path, error:
|
|
196
|
+
result: { case: "error", value: create(LsErrorSchema, { path, error: nativeLocalExecDisabledMessage(opts) }) },
|
|
196
197
|
}));
|
|
197
198
|
}
|
|
198
199
|
|
|
@@ -256,8 +257,8 @@ function grepError(execMsg: ExecServerMessage, error: string): Uint8Array {
|
|
|
256
257
|
}));
|
|
257
258
|
}
|
|
258
259
|
|
|
259
|
-
export function rejectGrepExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
|
|
260
|
-
return grepError(execMsg,
|
|
260
|
+
export function rejectGrepExecForPolicy(execMsg: ExecServerMessage, opts: CursorNativeExecPolicyContext = {}): Uint8Array {
|
|
261
|
+
return grepError(execMsg, nativeLocalExecDisabledMessage(opts));
|
|
261
262
|
}
|
|
262
263
|
|
|
263
264
|
export function grepExec(execMsg: ExecServerMessage): Uint8Array {
|
|
@@ -1,19 +1,17 @@
|
|
|
1
1
|
import { create } from "@bufbuild/protobuf";
|
|
2
2
|
import { FetchErrorSchema, FetchResultSchema, FetchSuccessSchema, type ExecServerMessage } from "./gen/agent_pb";
|
|
3
3
|
import { errorText, execBytes } from "./native-exec-common";
|
|
4
|
+
import { nativeFetchDisabledMessage, type CursorNativeExecPolicyContext } from "./native-exec-policy";
|
|
4
5
|
|
|
5
6
|
export interface CursorNativeNetworkDeps {
|
|
6
7
|
fetch?: typeof fetch;
|
|
7
8
|
}
|
|
8
9
|
|
|
9
|
-
|
|
10
|
-
"Cursor-native fetch is not executed locally. Use the Codex shell bridge tool `shell_command` (aliases: `exec_command`, `mcp_opencodex-responses_shell_command`, `mcp_opencodex-responses_exec_command`) with curl or wget.";
|
|
11
|
-
|
|
12
|
-
export function rejectFetchExecForPolicy(execMsg: ExecServerMessage): Uint8Array {
|
|
10
|
+
export function rejectFetchExecForPolicy(execMsg: ExecServerMessage, opts: CursorNativeExecPolicyContext = {}): Uint8Array {
|
|
13
11
|
if (execMsg.message.case !== "fetchArgs") throw new Error("invalid fetch exec");
|
|
14
12
|
const args = execMsg.message.value;
|
|
15
13
|
return execBytes(execMsg, "fetchResult", create(FetchResultSchema, {
|
|
16
|
-
result: { case: "error", value: create(FetchErrorSchema, { url: args.url, error:
|
|
14
|
+
result: { case: "error", value: create(FetchErrorSchema, { url: args.url, error: nativeFetchDisabledMessage(opts) }) },
|
|
17
15
|
}));
|
|
18
16
|
}
|
|
19
17
|
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export interface CursorNativeExecPolicyContext {
|
|
2
|
+
codeMode?: boolean;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
export function nativeLocalExecDisabledMessage(opts: CursorNativeExecPolicyContext = {}): string {
|
|
6
|
+
if (opts.codeMode) {
|
|
7
|
+
return (
|
|
8
|
+
"Cursor-native local tools are policy-redirected to the Codex bridge for this request; this is not a permissions denial. "
|
|
9
|
+
+ "Use the top-level `exec` tool and call nested helpers inside its JavaScript body as `await tools.<name>(args)` "
|
|
10
|
+
+ "(for example `await tools.exec_command({cmd: \"ls\"})`, `await tools.apply_patch(input)`, or another helper listed in `ALL_TOOLS`). "
|
|
11
|
+
+ "Do not call `shell_command` or `exec_command` at the top level in code mode."
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
return (
|
|
15
|
+
"Re-issue this operation NOW through the catalog shell tool (`shell_command` / `exec_command`, or the listed `mcp_opencodex-responses_*` display alias) with the host-shell-safe equivalent: POSIX (`cat`, `head`, `ls`, `rg`, `grep`) or Windows PowerShell (`Get-Content`, `Get-ChildItem`, `Select-String`); use `apply_patch` for file edits. Do NOT narrate this redirect, do NOT comment on tool availability, and do NOT re-announce the task — just make the bridge call."
|
|
16
|
+
);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function nativeFetchDisabledMessage(opts: CursorNativeExecPolicyContext = {}): string {
|
|
20
|
+
if (opts.codeMode) {
|
|
21
|
+
return (
|
|
22
|
+
"Cursor-native fetch is policy-redirected to the Codex bridge for this request; this is not a permissions denial. "
|
|
23
|
+
+ "Use the top-level `exec` tool and call a nested shell helper inside its JavaScript body as `await tools.exec_command({cmd: \"curl ...\"})` "
|
|
24
|
+
+ "(or another helper listed in `ALL_TOOLS`). Do not call `shell_command` or `exec_command` at the top level in code mode."
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
return (
|
|
28
|
+
"Re-issue this fetch NOW through the catalog shell tool `shell_command` (aliases: `exec_command`, `mcp_opencodex-responses_shell_command`, `mcp_opencodex-responses_exec_command`) with curl or wget. Do NOT narrate this redirect or comment on tool availability — just make the bridge call."
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function nativeShellDisabledMessage(opts: CursorNativeExecPolicyContext = {}): string {
|
|
33
|
+
if (opts.codeMode) {
|
|
34
|
+
return (
|
|
35
|
+
"Cursor-native shell is policy-redirected to the Codex bridge for this request; this is not a permissions denial. "
|
|
36
|
+
+ "Use the top-level `exec` tool and call a nested shell helper inside its JavaScript body as `await tools.exec_command({cmd: \"...\"})` "
|
|
37
|
+
+ "(or another helper listed in `ALL_TOOLS`). Do not call `shell_command` or `exec_command` at the top level in code mode."
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
return (
|
|
41
|
+
"Re-issue this command NOW through the catalog shell tool (`shell_command` or `exec_command`; the long `mcp_opencodex-responses_*` display name is the same tool). "
|
|
42
|
+
+ "Adapt the command for the Codex client host shell before calling the bridge "
|
|
43
|
+
+ "(Windows PowerShell 5.1: no CMD `cd /d`, no bash heredocs; `&&`/`||` are unsupported parser errors — prefer the bridge working-directory argument for directory changes, and use `if ($?) { ... }` for success-gated follow-up steps; do not treat `;` as a substitute for `&&`). "
|
|
44
|
+
+ "Make at most one corrected bridge attempt after a failure, then report the error and stop — do not repeat equivalent failing commands. "
|
|
45
|
+
+ "Do NOT narrate this redirect, do NOT comment on tool availability, and do NOT re-announce the task — just make the bridge call."
|
|
46
|
+
);
|
|
47
|
+
}
|