@songtonyli/dsh-cli 0.1.18 → 0.1.19
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 +1 -1
- package/bin/dsh.mjs +1 -1
- package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.i18n.yaml +2 -2
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.md +12 -6
- package/node_modules/@deepseek-ai/dsh-llm-cursor/README.zh.md +12 -6
- package/node_modules/@deepseek-ai/dsh-llm-cursor/lib/index.js +548 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -26,7 +26,7 @@ workspace and no build step. Native packages that ship one build per platform
|
|
|
26
26
|
ripgrep, the PTY backend's addons, sharp, koffi, and the Landlock launcher — are
|
|
27
27
|
ordinary optional dependencies, so npm resolves the right one for your machine.
|
|
28
28
|
|
|
29
|
-
Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.
|
|
29
|
+
Requires Node `^22.19.0 || >=24.0.0`. Version 0.1.19; `dsh --version`
|
|
30
30
|
also reports the harness build the package was assembled from.
|
|
31
31
|
|
|
32
32
|
## License
|
package/bin/dsh.mjs
CHANGED
|
@@ -18,7 +18,7 @@ const argv = process.argv.slice(2)
|
|
|
18
18
|
// version this package publishes. Reporting only one of the two would make an
|
|
19
19
|
// ordinary `npm install @songtonyli/dsh-cli@x` look like it installed something else.
|
|
20
20
|
if (argv.length === 1 && (argv[0] === '--version' || argv[0] === '-V')) {
|
|
21
|
-
console.log('@songtonyli/dsh-cli 0.1.
|
|
21
|
+
console.log('@songtonyli/dsh-cli 0.1.19 (deepseek-harness 0.1.6-alpha.2)')
|
|
22
22
|
process.exit(0)
|
|
23
23
|
}
|
|
24
24
|
|
|
@@ -160,7 +160,7 @@ window.__ModuleLoader__.load({
|
|
|
160
160
|
const SCROLLBAR_LINGER_MS = 2e3;
|
|
161
161
|
/** Format complete-build metadata for the local brand badge. */
|
|
162
162
|
function localBuildVersion() {
|
|
163
|
-
return `0.1.6-alpha.2-
|
|
163
|
+
return `0.1.6-alpha.2-22104ec-dirty`;
|
|
164
164
|
}
|
|
165
165
|
/** Each panel row subscribes only to its own selection state. */
|
|
166
166
|
function PanelRow({ id, label, wide, usePanelInfo, selectPanel, renderSlot }) {
|
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/llm/llm-cursor/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: 115f31dabd27797f6e27f75ea58ec3d57574fe21
|
|
6
|
+
README.zh.md: 64290a131aa904e94bf1be85dafbef69025c6fe1
|
|
@@ -64,7 +64,9 @@ Sign-out is `deleteRecord` on that key. It does not revoke the session at Cursor
|
|
|
64
64
|
|
|
65
65
|
Request-time token order is: launch-environment `CURSOR_ACCESS_TOKEN`, then the stored OAuth grant (refresh inside `modifyRecord` when near expiry), then optional Keychain / `state.vscdb` harvest when `reuseInstalledCursorLogin` is true. A stored DSH login wins over harvest.
|
|
66
66
|
|
|
67
|
-
Each DSH model step is a new HTTP/2 Connect `Run` rebuilt from harness history, system prompt, and MCP tool definitions (`providerIdentifier: dsh`, `clientName: dsh`).
|
|
67
|
+
Each DSH model step is a new HTTP/2 Connect `Run` rebuilt from harness history, system prompt, and MCP tool definitions (`providerIdentifier: dsh`, `clientName: dsh`). Cursor's server builds the model prompt from `root_prompt_messages_json`, never renders `conversation_state.turns` into it, and discards a `{"role":"system"}` entry there in favour of its own prompt. The adapter therefore publishes the system prompt as a `<rules>` user prompt message and replays every prior turn as `user`, `assistant`, and `tool` prompt messages, naming historic MCP calls `mcp_dsh_<tool>` as Cursor does; the turn structures ride along for the server's bookkeeping. The request-context answer adds one global Cursor rule telling the model that Cursor's built-in tools return a rejection here and that the `mcp_dsh_` tools are the ones to call.
|
|
68
|
+
|
|
69
|
+
Text, thinking, usage, and MCP tool calls become `StreamChunk`. An MCP tool call finishes the stream so the agent loop can run the tool locally. The next Run replays that in-flight turn with its results and sends a fixed continuation notice as the user message a Run requires; a `resumeAction` is not used because the server restarts the turn from its user message instead of continuing it. A Cursor-native workspace exec (`read`, `shell`, `grep`, and kin) is answered with its typed rejection naming the harness tool to call instead, so the Run continues and the model reads the refusal as a tool outcome; an exec this build does not know fails the step.
|
|
68
70
|
|
|
69
71
|
Attribution headers required by `LlmAdapter` go on every HTTP/2 request, with Cursor client headers `x-ghost-mode`, `x-cursor-client-version`, and `x-cursor-client-type`.
|
|
70
72
|
|
|
@@ -82,11 +84,11 @@ Attribution headers required by `LlmAdapter` go on every HTTP/2 request, with Cu
|
|
|
82
84
|
|
|
83
85
|
#### What the model sees
|
|
84
86
|
|
|
85
|
-
One rebuilt Cursor `AgentRunRequest
|
|
87
|
+
One rebuilt Cursor `AgentRunRequest` whose `root_prompt_messages_json` carries the model-visible history: the system prompt as a `<rules>` user message, then each prior turn as a `<user_query>` user message, assistant messages holding text and `tool-call` parts named `mcp_dsh_<tool>`, and `tool` messages holding the results; thinking is not replayed. The current user action, requested model id, and MCP tool definitions with `providerIdentifier: dsh` complete the request. Consecutive user-role messages with no assistant between them — the human prompt plus runtime-context snapshots, skill catalogs, and other injected user messages — join in order into that turn's user text, because a Run has one `userMessageAction`. After locally executed tool calls, the in-flight turn is replayed with its results and the user action is the fixed notice `The results of your tool calls are in the tool messages above. Continue the task.`. The request context carries one global rule stating that Cursor's built-in tools return a rejection and naming the `mcp_dsh_` tools as the ones to call. Images reach the model as the harness's text-only placeholder because the route declares text-only input; no image bytes are sent. Cursor still offers its own built-in tools beside the harness MCP tools.
|
|
86
88
|
|
|
87
89
|
#### Token effect
|
|
88
90
|
|
|
89
|
-
Provider tokenization governs exact input. History is fully rebuilt on every DSH step, so the wire request is the current assembled messages rather than a resumed Cursor conversation.
|
|
91
|
+
Provider tokenization governs exact input. History is fully rebuilt on every DSH step, so the wire request is the current assembled messages rather than a resumed Cursor conversation. Replayed history travels twice on the wire, as prompt messages and as turn structures, but only the prompt messages reach the model. Cursor reports no prompt usage, so `inputTokens` is an estimate of one token per four characters of rules, replayed prompt messages, action text, and MCP tool definitions; `outputTokens` comes from Cursor's `tokenDelta` events.
|
|
90
92
|
|
|
91
93
|
#### KV Cache effect
|
|
92
94
|
|
|
@@ -96,7 +98,7 @@ Each step is an independent Run. A changed system prompt, history, tool schema,
|
|
|
96
98
|
|
|
97
99
|
#### What the model sees
|
|
98
100
|
|
|
99
|
-
Text deltas, thinking deltas, token usage, and MCP tool calls become harness chunks. An MCP tool call finishes the stream with `tool-calls
|
|
101
|
+
Text deltas, thinking deltas, token usage, and MCP tool calls become harness chunks. An MCP tool call finishes the stream with `tool-calls`. A native exec is answered with a rejection and the stream continues; an unknown exec fails the turn.
|
|
100
102
|
|
|
101
103
|
#### Token effect
|
|
102
104
|
|
|
@@ -113,10 +115,14 @@ Loop-retained response blocks append to the next rebuilt Run. Unrecorded transpo
|
|
|
113
115
|
These limits define where the adapter stops. They are current package constraints, not a Cursor product comparison.
|
|
114
116
|
|
|
115
117
|
- **The integration is unofficial** — auth URLs, headers, client version, and `agent.v1` can change without notice and break this adapter.
|
|
116
|
-
- **Native Cursor workspace execs are not executed** — `read`, `shell`, and kin
|
|
118
|
+
- **Native Cursor workspace execs are not executed** — `read`, `shell`, and kin receive a typed rejection naming the harness tool, so a model that picks one spends a round trip on the refusal before calling the `mcp_dsh_` tool.
|
|
117
119
|
- **There is no parked HTTP/2 conversation** — each DSH step is a new Run; mid-tool resume on the same Cursor stream is out of scope.
|
|
120
|
+
- **Tool results reach the model as replayed prompt messages plus a fixed continuation notice** — Cursor delivers results in-stream natively; the notice is adapter-owned text the human never typed.
|
|
118
121
|
- **`GenerateOptions.stop` is unsupported** — the unofficial Run does not map stop sequences.
|
|
119
|
-
- **
|
|
122
|
+
- **Image bytes are not sent** — the route declares text-only input, so every image reaches the model as the harness's text-only placeholder rather than as a Cursor selected image.
|
|
123
|
+
- **`maxTokens`, `temperature`, and `reasoningEffort` are not mapped** — the Run has no fields for them; effort is chosen through the Cursor model id suffix such as `-high`.
|
|
124
|
+
- **Reasoning is not replayed** — Cursor renders no `reasoning` prompt part, so a thinking model re-derives its plan after each locally executed tool call.
|
|
125
|
+
- **Prompt token usage is an estimate** — Cursor reports none, so the TUI context meter shows the adapter's character-based estimate.
|
|
120
126
|
- **Sign-out does not revoke at Cursor** — it only deletes the local grant; harvest can still satisfy the next request until `reuseInstalledCursorLogin` is false.
|
|
121
127
|
- **Harvest can bill a different Cursor account** — a stored DSH grant wins; turn harvest off when this machine's IDE login is not the account to use.
|
|
122
128
|
- **A sign-in lives only in the process that started it** — reloading the page mid-login abandons the attempt.
|
|
@@ -64,7 +64,9 @@ TUI:`/login llm-cursor/cursor`。无头不会打开浏览器;导出 `CURSOR_
|
|
|
64
64
|
|
|
65
65
|
请求时令牌顺序为:启动环境中的 `CURSOR_ACCESS_TOKEN`,然后是已存储的 OAuth 授权(临近过期时在 `modifyRecord` 内刷新),然后在 `reuseInstalledCursorLogin` 为 true 时可选读取钥匙串 / `state.vscdb`。已存储的 DSH 登录优先于采集。
|
|
66
66
|
|
|
67
|
-
DSH 的每一步模型调用是一次新的 HTTP/2 Connect `Run`,由 harness 历史、系统提示和 MCP 工具定义重建(`providerIdentifier: dsh`,`clientName: dsh
|
|
67
|
+
DSH 的每一步模型调用是一次新的 HTTP/2 Connect `Run`,由 harness 历史、系统提示和 MCP 工具定义重建(`providerIdentifier: dsh`,`clientName: dsh`)。Cursor 服务端只从 `root_prompt_messages_json` 构建模型提示,从不把 `conversation_state.turns` 渲染进去,并且会丢弃其中的 `{"role":"system"}` 条目而使用自己的提示。因此适配器把系统提示作为 `<rules>` user 提示消息发布,并把每个先前轮次重放为 `user`、`assistant` 和 `tool` 提示消息,历史 MCP 调用按 Cursor 的命名写成 `mcp_dsh_<tool>`;轮次结构一同发送,供服务端记账。请求上下文的应答额外带一条全局 Cursor 规则,告知模型 Cursor 内建工具在这里会返回拒绝,应调用 `mcp_dsh_` 工具。
|
|
68
|
+
|
|
69
|
+
文本、thinking、用量与 MCP 工具调用变成 `StreamChunk`。一次 MCP 工具调用结束该流,以便 agent loop 在本地跑工具。下一次 Run 重放该进行中的轮次及其结果,并把一条固定的继续提示作为 Run 必需的用户消息发送;不使用 `resumeAction`,因为服务端会从该轮的用户消息重新开始而不是继续。Cursor 原生工作区 exec(`read`、`shell`、`grep` 及同类)以其类型化的拒绝应答,并指出应改用的 harness 工具,因此 Run 继续进行,模型把该拒绝当作工具结果读取;本构建不认识的 exec 会使该步失败。
|
|
68
70
|
|
|
69
71
|
`LlmAdapter` 要求的归属头出现在每一次 HTTP/2 请求上,并带有 Cursor 客户端头 `x-ghost-mode`、`x-cursor-client-version` 和 `x-cursor-client-type`。
|
|
70
72
|
|
|
@@ -82,11 +84,11 @@ DSH 的每一步模型调用是一次新的 HTTP/2 Connect `Run`,由 harness
|
|
|
82
84
|
|
|
83
85
|
#### 模型看见什么
|
|
84
86
|
|
|
85
|
-
一次重建的 Cursor `AgentRunRequest
|
|
87
|
+
一次重建的 Cursor `AgentRunRequest`,其 `root_prompt_messages_json` 承载模型可见的历史:系统提示作为 `<rules>` user 消息,然后每个先前轮次作为 `<user_query>` user 消息、承载文本和名为 `mcp_dsh_<tool>` 的 `tool-call` 部分的 assistant 消息,以及承载结果的 `tool` 消息;thinking 不重放。当前用户动作、请求的模型 id,以及 `providerIdentifier: dsh` 的 MCP 工具定义补全该请求。中间没有助手回复的连续 user 角色消息——人类提示加上运行时上下文快照、技能目录和其他注入的用户消息——按顺序拼进该轮的用户文本,因为一次 Run 只有一个 `userMessageAction`。本地执行工具调用之后,进行中的轮次连同其结果被重放,用户动作是固定提示 `The results of your tool calls are in the tool messages above. Continue the task.`。请求上下文带一条全局规则,声明 Cursor 内建工具会返回拒绝,并指出应调用 `mcp_dsh_` 工具。由于该路由声明只接受文本输入,图片以 harness 的纯文本占位符到达模型;不发送图片字节。Cursor 仍在 harness MCP 工具之外提供自己的内建工具。
|
|
86
88
|
|
|
87
89
|
#### Token 影响
|
|
88
90
|
|
|
89
|
-
精确输入由提供方分词决定。历史在 DSH 的每一步完整重建,因此线路上的请求是当前组装好的消息,而不是恢复中的 Cursor
|
|
91
|
+
精确输入由提供方分词决定。历史在 DSH 的每一步完整重建,因此线路上的请求是当前组装好的消息,而不是恢复中的 Cursor 会话。重放的历史在线路上传输两次——作为提示消息和作为轮次结构——但只有提示消息到达模型。Cursor 不报告提示用量,因此 `inputTokens` 是按规则、重放的提示消息、动作文本与 MCP 工具定义每四个字符一个 token 的估算;`outputTokens` 来自 Cursor 的 `tokenDelta` 事件。
|
|
90
92
|
|
|
91
93
|
#### KV Cache 影响
|
|
92
94
|
|
|
@@ -96,7 +98,7 @@ DSH 的每一步模型调用是一次新的 HTTP/2 Connect `Run`,由 harness
|
|
|
96
98
|
|
|
97
99
|
#### 模型看见什么
|
|
98
100
|
|
|
99
|
-
文本增量、thinking 增量、token 用量和 MCP 工具调用变成 harness 分片。一次 MCP 工具调用以 `tool-calls`
|
|
101
|
+
文本增量、thinking 增量、token 用量和 MCP 工具调用变成 harness 分片。一次 MCP 工具调用以 `tool-calls` 结束该流。原生 exec 以拒绝应答且流继续;未知 exec 使该轮失败。
|
|
100
102
|
|
|
101
103
|
#### Token 影响
|
|
102
104
|
|
|
@@ -113,10 +115,14 @@ loop 保留的响应块追加到下一次重建的 Run。未记录的传输帧
|
|
|
113
115
|
这些限制划定适配器的停止点。它们是当前的包约束,不是与 Cursor 产品的对比。
|
|
114
116
|
|
|
115
117
|
- **该集成是非官方的** — 认证 URL、头、客户端版本和 `agent.v1` 可能不预先通知就变更并弄坏本适配器。
|
|
116
|
-
- **不执行原生 Cursor 工作区 exec** — `read`、`shell`
|
|
118
|
+
- **不执行原生 Cursor 工作区 exec** — `read`、`shell` 及同类收到指出 harness 工具的类型化拒绝,因此选中它们的模型会在调用 `mcp_dsh_` 工具之前多花一个往返。
|
|
117
119
|
- **没有挂起的 HTTP/2 会话** — DSH 的每一步都是新的 Run;在同一次 Cursor 流上中途恢复工具不在范围内。
|
|
120
|
+
- **工具结果以重放的提示消息加一条固定继续提示到达模型** — Cursor 原生是在流内交付结果;该提示是适配器自有的文本,人类从未输入过。
|
|
118
121
|
- **不支持 `GenerateOptions.stop`** — 非官方 Run 不映射停止序列。
|
|
119
|
-
-
|
|
122
|
+
- **不发送图片字节** — 该路由声明只接受文本输入,因此每张图片以 harness 的纯文本占位符到达模型,而不是作为 Cursor 选中图片。
|
|
123
|
+
- **不映射 `maxTokens`、`temperature` 和 `reasoningEffort`** — Run 没有对应字段;努力程度通过 Cursor 模型 id 后缀(如 `-high`)选择。
|
|
124
|
+
- **不重放 reasoning** — Cursor 不渲染 `reasoning` 提示部分,因此 thinking 模型在每次本地执行工具调用之后重新推导计划。
|
|
125
|
+
- **提示 token 用量是估算值** — Cursor 不报告,因此 TUI 上下文计量显示适配器基于字符数的估算。
|
|
120
126
|
- **退出登录不会在 Cursor 一侧撤销** — 它只删除本地授权;在 `reuseInstalledCursorLogin` 为 false 之前,采集仍可能满足下一次请求。
|
|
121
127
|
- **采集可能把账记到另一个 Cursor 账户** — 已存储的 DSH 授权优先;当本机 IDE 登录不是要用的账户时请关掉采集。
|
|
122
128
|
- **登录只存在于启动它的那个进程** — 登录途中刷新页面会放弃该次尝试。
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { launchEnvironmentOf } from "@deepseek-ai/dsh-launch-environment";
|
|
2
|
-
import { deepEqualJson } from "@deepseek-ai/dsh-util-values";
|
|
2
|
+
import { assertNever, deepEqualJson } from "@deepseek-ai/dsh-util-values";
|
|
3
3
|
import { LlmAdapter, LlmError, RetryPolicySchema, ToolCallId, assertUsableApiKey, attributionHeaders, resolveRetryPolicy } from "@deepseek-ai/dsh-llm";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
import { create, fromBinary, fromJson, toBinary, toJson } from "@bufbuild/protobuf";
|
|
@@ -31,6 +31,12 @@ import { promisify } from "node:util";
|
|
|
31
31
|
const NS = "llm-cursor";
|
|
32
32
|
/** Always-registered provider route this adapter owns. */
|
|
33
33
|
const PROVIDER = "cursor";
|
|
34
|
+
/**
|
|
35
|
+
* Prefix Cursor puts in front of an MCP tool's name when it shows the tool to
|
|
36
|
+
* the model: `mcp_<providerIdentifier>_<toolName>`. Replayed prompt history uses
|
|
37
|
+
* the same name, and a model that echoes it on a new call is unwrapped.
|
|
38
|
+
*/
|
|
39
|
+
const MCP_PROMPT_TOOL_PREFIX = `mcp_dsh_`;
|
|
34
40
|
/** Default credential reference resolved before a stored grant or harvest. */
|
|
35
41
|
const DEFAULT_API_KEY_ENV = "CURSOR_ACCESS_TOKEN";
|
|
36
42
|
/** Cursor PKCE login page. */
|
|
@@ -477,6 +483,66 @@ const GetUsableModelsRequestSchema = /*@__PURE__*/ messageDesc(file_agent, 123);
|
|
|
477
483
|
*/
|
|
478
484
|
const GetUsableModelsResponseSchema = /*@__PURE__*/ messageDesc(file_agent, 124);
|
|
479
485
|
/**
|
|
486
|
+
* Describes the message agent.v1.BackgroundShellSpawnResult.
|
|
487
|
+
* Use `create(BackgroundShellSpawnResultSchema)` to create a new message.
|
|
488
|
+
*/
|
|
489
|
+
const BackgroundShellSpawnResultSchema = /*@__PURE__*/ messageDesc(file_agent, 148);
|
|
490
|
+
/**
|
|
491
|
+
* Describes the message agent.v1.WriteShellStdinResult.
|
|
492
|
+
* Use `create(WriteShellStdinResultSchema)` to create a new message.
|
|
493
|
+
*/
|
|
494
|
+
const WriteShellStdinResultSchema = /*@__PURE__*/ messageDesc(file_agent, 152);
|
|
495
|
+
/**
|
|
496
|
+
* Describes the message agent.v1.WriteShellStdinError.
|
|
497
|
+
* Use `create(WriteShellStdinErrorSchema)` to create a new message.
|
|
498
|
+
*/
|
|
499
|
+
const WriteShellStdinErrorSchema = /*@__PURE__*/ messageDesc(file_agent, 154);
|
|
500
|
+
/**
|
|
501
|
+
* Describes the message agent.v1.ComputerUseResult.
|
|
502
|
+
* Use `create(ComputerUseResultSchema)` to create a new message.
|
|
503
|
+
*/
|
|
504
|
+
const ComputerUseResultSchema = /*@__PURE__*/ messageDesc(file_agent, 169);
|
|
505
|
+
/**
|
|
506
|
+
* Describes the message agent.v1.ComputerUseError.
|
|
507
|
+
* Use `create(ComputerUseErrorSchema)` to create a new message.
|
|
508
|
+
*/
|
|
509
|
+
const ComputerUseErrorSchema = /*@__PURE__*/ messageDesc(file_agent, 171);
|
|
510
|
+
/**
|
|
511
|
+
* Describes the message agent.v1.CursorRuleTypeGlobal.
|
|
512
|
+
* Use `create(CursorRuleTypeGlobalSchema)` to create a new message.
|
|
513
|
+
*/
|
|
514
|
+
const CursorRuleTypeGlobalSchema = /*@__PURE__*/ messageDesc(file_agent, 181);
|
|
515
|
+
/**
|
|
516
|
+
* Describes the message agent.v1.CursorRuleType.
|
|
517
|
+
* Use `create(CursorRuleTypeSchema)` to create a new message.
|
|
518
|
+
*/
|
|
519
|
+
const CursorRuleTypeSchema = /*@__PURE__*/ messageDesc(file_agent, 185);
|
|
520
|
+
/**
|
|
521
|
+
* Describes the message agent.v1.CursorRule.
|
|
522
|
+
* Use `create(CursorRuleSchema)` to create a new message.
|
|
523
|
+
*/
|
|
524
|
+
const CursorRuleSchema = /*@__PURE__*/ messageDesc(file_agent, 186);
|
|
525
|
+
/**
|
|
526
|
+
* Describes the message agent.v1.DeleteResult.
|
|
527
|
+
* Use `create(DeleteResultSchema)` to create a new message.
|
|
528
|
+
*/
|
|
529
|
+
const DeleteResultSchema = /*@__PURE__*/ messageDesc(file_agent, 188);
|
|
530
|
+
/**
|
|
531
|
+
* Describes the message agent.v1.DeleteRejected.
|
|
532
|
+
* Use `create(DeleteRejectedSchema)` to create a new message.
|
|
533
|
+
*/
|
|
534
|
+
const DeleteRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 194);
|
|
535
|
+
/**
|
|
536
|
+
* Describes the message agent.v1.DiagnosticsResult.
|
|
537
|
+
* Use `create(DiagnosticsResultSchema)` to create a new message.
|
|
538
|
+
*/
|
|
539
|
+
const DiagnosticsResultSchema = /*@__PURE__*/ messageDesc(file_agent, 198);
|
|
540
|
+
/**
|
|
541
|
+
* Describes the message agent.v1.DiagnosticsRejected.
|
|
542
|
+
* Use `create(DiagnosticsRejectedSchema)` to create a new message.
|
|
543
|
+
*/
|
|
544
|
+
const DiagnosticsRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 202);
|
|
545
|
+
/**
|
|
480
546
|
* Describes the message agent.v1.ExecClientThrow.
|
|
481
547
|
* Use `create(ExecClientThrowSchema)` to create a new message.
|
|
482
548
|
*/
|
|
@@ -492,6 +558,26 @@ const ExecClientControlMessageSchema = /*@__PURE__*/ messageDesc(file_agent, 240
|
|
|
492
558
|
*/
|
|
493
559
|
const ExecClientMessageSchema = /*@__PURE__*/ messageDesc(file_agent, 245);
|
|
494
560
|
/**
|
|
561
|
+
* Describes the message agent.v1.FetchResult.
|
|
562
|
+
* Use `create(FetchResultSchema)` to create a new message.
|
|
563
|
+
*/
|
|
564
|
+
const FetchResultSchema = /*@__PURE__*/ messageDesc(file_agent, 247);
|
|
565
|
+
/**
|
|
566
|
+
* Describes the message agent.v1.FetchError.
|
|
567
|
+
* Use `create(FetchErrorSchema)` to create a new message.
|
|
568
|
+
*/
|
|
569
|
+
const FetchErrorSchema = /*@__PURE__*/ messageDesc(file_agent, 249);
|
|
570
|
+
/**
|
|
571
|
+
* Describes the message agent.v1.GrepResult.
|
|
572
|
+
* Use `create(GrepResultSchema)` to create a new message.
|
|
573
|
+
*/
|
|
574
|
+
const GrepResultSchema = /*@__PURE__*/ messageDesc(file_agent, 256);
|
|
575
|
+
/**
|
|
576
|
+
* Describes the message agent.v1.GrepError.
|
|
577
|
+
* Use `create(GrepErrorSchema)` to create a new message.
|
|
578
|
+
*/
|
|
579
|
+
const GrepErrorSchema = /*@__PURE__*/ messageDesc(file_agent, 257);
|
|
580
|
+
/**
|
|
495
581
|
* Describes the message agent.v1.GetBlobResult.
|
|
496
582
|
* Use `create(GetBlobResultSchema)` to create a new message.
|
|
497
583
|
*/
|
|
@@ -507,6 +593,16 @@ const SetBlobResultSchema = /*@__PURE__*/ messageDesc(file_agent, 271);
|
|
|
507
593
|
*/
|
|
508
594
|
const KvClientMessageSchema = /*@__PURE__*/ messageDesc(file_agent, 273);
|
|
509
595
|
/**
|
|
596
|
+
* Describes the message agent.v1.LsResult.
|
|
597
|
+
* Use `create(LsResultSchema)` to create a new message.
|
|
598
|
+
*/
|
|
599
|
+
const LsResultSchema = /*@__PURE__*/ messageDesc(file_agent, 275);
|
|
600
|
+
/**
|
|
601
|
+
* Describes the message agent.v1.LsRejected.
|
|
602
|
+
* Use `create(LsRejectedSchema)` to create a new message.
|
|
603
|
+
*/
|
|
604
|
+
const LsRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 280);
|
|
605
|
+
/**
|
|
510
606
|
* Describes the message agent.v1.McpArgs.
|
|
511
607
|
* Use `create(McpArgsSchema)` to create a new message.
|
|
512
608
|
*/
|
|
@@ -527,6 +623,26 @@ const McpToolResultContentItemSchema = /*@__PURE__*/ messageDesc(file_agent, 290
|
|
|
527
623
|
*/
|
|
528
624
|
const McpSuccessSchema = /*@__PURE__*/ messageDesc(file_agent, 291);
|
|
529
625
|
/**
|
|
626
|
+
* Describes the message agent.v1.ListMcpResourcesExecResult.
|
|
627
|
+
* Use `create(ListMcpResourcesExecResultSchema)` to create a new message.
|
|
628
|
+
*/
|
|
629
|
+
const ListMcpResourcesExecResultSchema = /*@__PURE__*/ messageDesc(file_agent, 296);
|
|
630
|
+
/**
|
|
631
|
+
* Describes the message agent.v1.ListMcpResourcesRejected.
|
|
632
|
+
* Use `create(ListMcpResourcesRejectedSchema)` to create a new message.
|
|
633
|
+
*/
|
|
634
|
+
const ListMcpResourcesRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 300);
|
|
635
|
+
/**
|
|
636
|
+
* Describes the message agent.v1.ReadMcpResourceExecResult.
|
|
637
|
+
* Use `create(ReadMcpResourceExecResultSchema)` to create a new message.
|
|
638
|
+
*/
|
|
639
|
+
const ReadMcpResourceExecResultSchema = /*@__PURE__*/ messageDesc(file_agent, 302);
|
|
640
|
+
/**
|
|
641
|
+
* Describes the message agent.v1.ReadMcpResourceRejected.
|
|
642
|
+
* Use `create(ReadMcpResourceRejectedSchema)` to create a new message.
|
|
643
|
+
*/
|
|
644
|
+
const ReadMcpResourceRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 305);
|
|
645
|
+
/**
|
|
530
646
|
* Describes the message agent.v1.McpToolDefinition.
|
|
531
647
|
* Use `create(McpToolDefinitionSchema)` to create a new message.
|
|
532
648
|
*/
|
|
@@ -537,6 +653,26 @@ const McpToolDefinitionSchema = /*@__PURE__*/ messageDesc(file_agent, 307);
|
|
|
537
653
|
*/
|
|
538
654
|
const McpToolsSchema = /*@__PURE__*/ messageDesc(file_agent, 308);
|
|
539
655
|
/**
|
|
656
|
+
* Describes the message agent.v1.ReadResult.
|
|
657
|
+
* Use `create(ReadResultSchema)` to create a new message.
|
|
658
|
+
*/
|
|
659
|
+
const ReadResultSchema = /*@__PURE__*/ messageDesc(file_agent, 314);
|
|
660
|
+
/**
|
|
661
|
+
* Describes the message agent.v1.ReadRejected.
|
|
662
|
+
* Use `create(ReadRejectedSchema)` to create a new message.
|
|
663
|
+
*/
|
|
664
|
+
const ReadRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 317);
|
|
665
|
+
/**
|
|
666
|
+
* Describes the message agent.v1.RecordScreenResult.
|
|
667
|
+
* Use `create(RecordScreenResultSchema)` to create a new message.
|
|
668
|
+
*/
|
|
669
|
+
const RecordScreenResultSchema = /*@__PURE__*/ messageDesc(file_agent, 328);
|
|
670
|
+
/**
|
|
671
|
+
* Describes the message agent.v1.RecordScreenFailure.
|
|
672
|
+
* Use `create(RecordScreenFailureSchema)` to create a new message.
|
|
673
|
+
*/
|
|
674
|
+
const RecordScreenFailureSchema = /*@__PURE__*/ messageDesc(file_agent, 332);
|
|
675
|
+
/**
|
|
540
676
|
* Describes the message agent.v1.RequestContextResult.
|
|
541
677
|
* Use `create(RequestContextResultSchema)` to create a new message.
|
|
542
678
|
*/
|
|
@@ -562,6 +698,21 @@ const RequestContextSchema = /*@__PURE__*/ messageDesc(file_agent, 348);
|
|
|
562
698
|
*/
|
|
563
699
|
const SelectedContextSchema = /*@__PURE__*/ messageDesc(file_agent, 374);
|
|
564
700
|
/**
|
|
701
|
+
* Describes the message agent.v1.ShellResult.
|
|
702
|
+
* Use `create(ShellResultSchema)` to create a new message.
|
|
703
|
+
*/
|
|
704
|
+
const ShellResultSchema = /*@__PURE__*/ messageDesc(file_agent, 390);
|
|
705
|
+
/**
|
|
706
|
+
* Describes the message agent.v1.ShellStream.
|
|
707
|
+
* Use `create(ShellStreamSchema)` to create a new message.
|
|
708
|
+
*/
|
|
709
|
+
const ShellStreamSchema = /*@__PURE__*/ messageDesc(file_agent, 396);
|
|
710
|
+
/**
|
|
711
|
+
* Describes the message agent.v1.ShellRejected.
|
|
712
|
+
* Use `create(ShellRejectedSchema)` to create a new message.
|
|
713
|
+
*/
|
|
714
|
+
const ShellRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 401);
|
|
715
|
+
/**
|
|
565
716
|
* Describes the message agent.v1.WebSearchRequestResponse.
|
|
566
717
|
* Use `create(WebSearchRequestResponseSchema)` to create a new message.
|
|
567
718
|
*/
|
|
@@ -572,6 +723,16 @@ const WebSearchRequestResponseSchema = /*@__PURE__*/ messageDesc(file_agent, 447
|
|
|
572
723
|
*/
|
|
573
724
|
const WebSearchRequestResponse_ApprovedSchema = /*@__PURE__*/ messageDesc(file_agent, 448);
|
|
574
725
|
/**
|
|
726
|
+
* Describes the message agent.v1.WriteResult.
|
|
727
|
+
* Use `create(WriteResultSchema)` to create a new message.
|
|
728
|
+
*/
|
|
729
|
+
const WriteResultSchema = /*@__PURE__*/ messageDesc(file_agent, 451);
|
|
730
|
+
/**
|
|
731
|
+
* Describes the message agent.v1.WriteRejected.
|
|
732
|
+
* Use `create(WriteRejectedSchema)` to create a new message.
|
|
733
|
+
*/
|
|
734
|
+
const WriteRejectedSchema = /*@__PURE__*/ messageDesc(file_agent, 456);
|
|
735
|
+
/**
|
|
575
736
|
* @generated from enum agent.v1.AppliedAgentChange_ChangeType
|
|
576
737
|
*/
|
|
577
738
|
var AppliedAgentChange_ChangeType;
|
|
@@ -958,8 +1119,25 @@ var BugbotDeeplinkEventKind;
|
|
|
958
1119
|
/**
|
|
959
1120
|
* Rebuild one Cursor `AgentRunRequest` from harness history, system prompt, and MCP tools.
|
|
960
1121
|
*
|
|
1122
|
+
* Cursor's server builds the model prompt from `root_prompt_messages_json` and
|
|
1123
|
+
* never renders `conversation_state.turns` back into prompt messages, so this
|
|
1124
|
+
* module publishes the system prompt and every prior turn there as prompt
|
|
1125
|
+
* messages and keeps the turn structures for the server's own bookkeeping.
|
|
1126
|
+
*
|
|
961
1127
|
* @module @deepseek-ai/dsh-llm-cursor/request
|
|
962
1128
|
*/
|
|
1129
|
+
/**
|
|
1130
|
+
* User message sent after locally executed tool calls. A Run requires one user
|
|
1131
|
+
* message; the tool results themselves ride the root prompt as `tool` messages.
|
|
1132
|
+
*/
|
|
1133
|
+
const TOOL_RESULT_CONTINUATION_TEXT = "The results of your tool calls are in the tool messages above. Continue the task.";
|
|
1134
|
+
/**
|
|
1135
|
+
* Rule that tells the model Cursor's built-in tools answer with a rejection
|
|
1136
|
+
* here, so it calls the harness tools by their `mcp_dsh_` names instead.
|
|
1137
|
+
*/
|
|
1138
|
+
const NATIVE_TOOLS_RULE = `DeepSeek Harness runs this session. Cursor's built-in tools (read, write, edit, delete, ls, grep, shell, fetch, diagnostics, and the rest) are not available: calling one returns a rejection and does nothing. Use only the tools whose names start with ${MCP_PROMPT_TOOL_PREFIX}, for example ${MCP_PROMPT_TOOL_PREFIX}read instead of read.`;
|
|
1139
|
+
/** Rule path Cursor shows beside {@link NATIVE_TOOLS_RULE}. */
|
|
1140
|
+
const ADAPTER_RULE_PATH = "dsh/cursor-adapter";
|
|
963
1141
|
function textOf(message) {
|
|
964
1142
|
return message.content.map((block) => {
|
|
965
1143
|
if (block.type === "text") return block.text;
|
|
@@ -1071,14 +1249,16 @@ function createUserMessage(text, selectedContextBlob) {
|
|
|
1071
1249
|
});
|
|
1072
1250
|
}
|
|
1073
1251
|
/**
|
|
1074
|
-
* Split harness messages into
|
|
1252
|
+
* Split harness messages into Cursor turns plus the action for this Run.
|
|
1075
1253
|
*
|
|
1076
1254
|
* Consecutive user-role messages with no assistant steps between them join in
|
|
1077
1255
|
* order into one Cursor user text. A Run has a single `userMessageAction`, so
|
|
1078
1256
|
* runtime-context snapshots and skill catalogs that follow the human prompt
|
|
1079
|
-
* ride that action instead of replacing it.
|
|
1257
|
+
* ride that action instead of replacing it. History that ends in assistant
|
|
1258
|
+
* steps, normally tool calls plus their local results, carries no new user
|
|
1259
|
+
* text and becomes a `continue` action.
|
|
1080
1260
|
* @param options - assembled model request.
|
|
1081
|
-
* @returns
|
|
1261
|
+
* @returns turns to replay and the Run action.
|
|
1082
1262
|
*/
|
|
1083
1263
|
function conversationFromOptions(options) {
|
|
1084
1264
|
const messages = [...options.messages];
|
|
@@ -1138,36 +1318,152 @@ function conversationFromOptions(options) {
|
|
|
1138
1318
|
const last = turns[turns.length - 1];
|
|
1139
1319
|
if (last === void 0) return {
|
|
1140
1320
|
systemPrompt,
|
|
1141
|
-
|
|
1142
|
-
|
|
1321
|
+
turns: [],
|
|
1322
|
+
action: {
|
|
1323
|
+
kind: "userMessage",
|
|
1324
|
+
text: ""
|
|
1325
|
+
}
|
|
1143
1326
|
};
|
|
1144
1327
|
if (last.steps.length === 0) return {
|
|
1145
1328
|
systemPrompt,
|
|
1146
|
-
|
|
1147
|
-
|
|
1329
|
+
turns: turns.slice(0, -1),
|
|
1330
|
+
action: {
|
|
1331
|
+
kind: "userMessage",
|
|
1332
|
+
text: last.userText
|
|
1333
|
+
}
|
|
1148
1334
|
};
|
|
1149
1335
|
return {
|
|
1150
1336
|
systemPrompt,
|
|
1151
|
-
|
|
1152
|
-
|
|
1337
|
+
turns,
|
|
1338
|
+
action: { kind: "continue" }
|
|
1153
1339
|
};
|
|
1154
1340
|
}
|
|
1155
1341
|
/**
|
|
1342
|
+
* Rules Cursor renders inside its own system prompt when the Run asks for the
|
|
1343
|
+
* request context. Only {@link NATIVE_TOOLS_RULE} travels here: a rule carrying
|
|
1344
|
+
* the harness system prompt lost its always-apply instructions once replayed
|
|
1345
|
+
* history was present, while the `<rules>` user prompt message kept them.
|
|
1346
|
+
* @returns the adapter's global rule.
|
|
1347
|
+
*/
|
|
1348
|
+
function buildRules() {
|
|
1349
|
+
return [create(CursorRuleSchema, {
|
|
1350
|
+
fullPath: ADAPTER_RULE_PATH,
|
|
1351
|
+
content: NATIVE_TOOLS_RULE,
|
|
1352
|
+
source: 0,
|
|
1353
|
+
type: create(CursorRuleTypeSchema, { type: {
|
|
1354
|
+
case: "global",
|
|
1355
|
+
value: create(CursorRuleTypeGlobalSchema, {})
|
|
1356
|
+
} })
|
|
1357
|
+
})];
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Render the system prompt and prior turns as the prompt messages Cursor shows
|
|
1361
|
+
* the model. The system prompt becomes a `<rules>` user message because the
|
|
1362
|
+
* server discards `system` entries in favour of its own prompt. Each turn
|
|
1363
|
+
* becomes a `<user_query>` user message, assistant messages holding text and
|
|
1364
|
+
* `tool-call` parts, and `tool` messages holding the results, with MCP tools
|
|
1365
|
+
* named `mcp_dsh_<tool>` as Cursor names them. Thinking is not replayed.
|
|
1366
|
+
* @param systemPrompt - rendered harness system prompt; `''` adds no rules.
|
|
1367
|
+
* @param turns - turns to replay, oldest first.
|
|
1368
|
+
* @returns prompt messages in order.
|
|
1369
|
+
*/
|
|
1370
|
+
function buildPromptMessages(systemPrompt, turns) {
|
|
1371
|
+
const messages = [];
|
|
1372
|
+
if (systemPrompt.trim().length > 0) messages.push({
|
|
1373
|
+
role: "user",
|
|
1374
|
+
content: [{
|
|
1375
|
+
type: "text",
|
|
1376
|
+
text: `<rules>\n${systemPrompt}\n</rules>`
|
|
1377
|
+
}]
|
|
1378
|
+
});
|
|
1379
|
+
for (const turn of turns) {
|
|
1380
|
+
const query = turn.userText.trim();
|
|
1381
|
+
if (query.length > 0) messages.push({
|
|
1382
|
+
role: "user",
|
|
1383
|
+
content: [{
|
|
1384
|
+
type: "text",
|
|
1385
|
+
text: `<user_query>\n${query}\n</user_query>`
|
|
1386
|
+
}]
|
|
1387
|
+
});
|
|
1388
|
+
let assistant = [];
|
|
1389
|
+
let results = [];
|
|
1390
|
+
const flush = () => {
|
|
1391
|
+
if (assistant.length > 0) messages.push({
|
|
1392
|
+
role: "assistant",
|
|
1393
|
+
content: assistant
|
|
1394
|
+
});
|
|
1395
|
+
if (results.length > 0) messages.push({
|
|
1396
|
+
role: "tool",
|
|
1397
|
+
content: results
|
|
1398
|
+
});
|
|
1399
|
+
assistant = [];
|
|
1400
|
+
results = [];
|
|
1401
|
+
};
|
|
1402
|
+
for (const step of turn.steps) {
|
|
1403
|
+
if (step.kind === "thinking") continue;
|
|
1404
|
+
if (step.kind === "assistantText") {
|
|
1405
|
+
if (step.text.length === 0) continue;
|
|
1406
|
+
if (results.length > 0) flush();
|
|
1407
|
+
assistant.push({
|
|
1408
|
+
type: "text",
|
|
1409
|
+
text: step.text
|
|
1410
|
+
});
|
|
1411
|
+
continue;
|
|
1412
|
+
}
|
|
1413
|
+
const toolName = `${MCP_PROMPT_TOOL_PREFIX}${step.toolName}`;
|
|
1414
|
+
assistant.push({
|
|
1415
|
+
type: "tool-call",
|
|
1416
|
+
toolCallId: step.toolCallId,
|
|
1417
|
+
toolName,
|
|
1418
|
+
args: step.arguments
|
|
1419
|
+
});
|
|
1420
|
+
if (step.result !== void 0) results.push({
|
|
1421
|
+
type: "tool-result",
|
|
1422
|
+
toolCallId: step.toolCallId,
|
|
1423
|
+
toolName,
|
|
1424
|
+
result: step.result.content,
|
|
1425
|
+
...step.result.isError ? { isError: true } : {}
|
|
1426
|
+
});
|
|
1427
|
+
}
|
|
1428
|
+
flush();
|
|
1429
|
+
}
|
|
1430
|
+
return messages;
|
|
1431
|
+
}
|
|
1432
|
+
function estimateInputTokens(rules, promptMessages, actionText, mcpTools) {
|
|
1433
|
+
let chars = actionText.length;
|
|
1434
|
+
for (const rule of rules) chars += rule.content.length;
|
|
1435
|
+
for (const message of promptMessages) chars += JSON.stringify(message).length;
|
|
1436
|
+
for (const tool of mcpTools) chars += tool.name.length + tool.description.length + tool.inputSchema.byteLength;
|
|
1437
|
+
return Math.ceil(chars / 4);
|
|
1438
|
+
}
|
|
1439
|
+
function actionText(action) {
|
|
1440
|
+
switch (action.kind) {
|
|
1441
|
+
case "userMessage": return action.text;
|
|
1442
|
+
case "continue": return TOOL_RESULT_CONTINUATION_TEXT;
|
|
1443
|
+
/* v8 ignore next -- CursorRunAction is closed; the compiler owns exhaustiveness. */
|
|
1444
|
+
default: return assertNever(action, "CursorRunAction");
|
|
1445
|
+
}
|
|
1446
|
+
}
|
|
1447
|
+
/**
|
|
1156
1448
|
* Encode one rebuilt Run from a harness request.
|
|
1157
1449
|
* @param options - assembled model request.
|
|
1158
1450
|
* @returns protobuf bytes and the blob store.
|
|
1159
1451
|
*/
|
|
1160
1452
|
function buildCursorRun(options) {
|
|
1161
|
-
const { systemPrompt,
|
|
1453
|
+
const { systemPrompt, turns, action } = conversationFromOptions(options);
|
|
1162
1454
|
const mcpTools = buildMcpToolDefinitions(options.tools);
|
|
1163
1455
|
const blobStore = /* @__PURE__ */ new Map();
|
|
1164
|
-
const
|
|
1456
|
+
const encoder = new TextEncoder();
|
|
1457
|
+
const systemBlobId = storeAsBlob(encoder.encode(JSON.stringify({
|
|
1165
1458
|
role: "system",
|
|
1166
1459
|
content: systemPrompt
|
|
1167
1460
|
})), blobStore);
|
|
1461
|
+
const rules = buildRules();
|
|
1462
|
+
const promptMessages = buildPromptMessages(systemPrompt, turns);
|
|
1463
|
+
const promptBlobIds = promptMessages.map((message) => storeAsBlob(encoder.encode(JSON.stringify(message)), blobStore));
|
|
1168
1464
|
const selectedCtxBlob = storeAsBlob(new Uint8Array(), blobStore);
|
|
1169
1465
|
const turnBlobIds = [];
|
|
1170
|
-
for (const turn of
|
|
1466
|
+
for (const turn of turns) {
|
|
1171
1467
|
const turnStructure = create(ConversationTurnStructureSchema, { turn: {
|
|
1172
1468
|
case: "agentConversationTurn",
|
|
1173
1469
|
value: create(AgentConversationTurnStructureSchema, {
|
|
@@ -1178,41 +1474,47 @@ function buildCursorRun(options) {
|
|
|
1178
1474
|
} });
|
|
1179
1475
|
turnBlobIds.push(storeAsBlob(toBinary(ConversationTurnStructureSchema, turnStructure), blobStore));
|
|
1180
1476
|
}
|
|
1477
|
+
const conversationState = create(ConversationStateStructureSchema, {
|
|
1478
|
+
rootPromptMessagesJson: [systemBlobId, ...promptBlobIds],
|
|
1479
|
+
turns: turnBlobIds,
|
|
1480
|
+
todos: [],
|
|
1481
|
+
pendingToolCalls: [],
|
|
1482
|
+
previousWorkspaceUris: [pathToFileURL(process.cwd()).href],
|
|
1483
|
+
mode: 1,
|
|
1484
|
+
fileStates: {},
|
|
1485
|
+
fileStatesV2: {},
|
|
1486
|
+
summaryArchives: [],
|
|
1487
|
+
turnTimings: [],
|
|
1488
|
+
subagentStates: {},
|
|
1489
|
+
selfSummaryCount: 0,
|
|
1490
|
+
readPaths: [],
|
|
1491
|
+
clientName: "dsh"
|
|
1492
|
+
});
|
|
1493
|
+
const text = actionText(action);
|
|
1494
|
+
const userMessage = createUserMessage(text, selectedCtxBlob);
|
|
1495
|
+
const requestedModel = create(RequestedModelSchema, {
|
|
1496
|
+
modelId: options.model,
|
|
1497
|
+
maxMode: false,
|
|
1498
|
+
parameters: []
|
|
1499
|
+
});
|
|
1181
1500
|
return {
|
|
1182
1501
|
requestBytes: toBinary(AgentClientMessageSchema, create(AgentClientMessageSchema, { message: {
|
|
1183
1502
|
case: "runRequest",
|
|
1184
1503
|
value: create(AgentRunRequestSchema, {
|
|
1185
|
-
conversationState
|
|
1186
|
-
rootPromptMessagesJson: [systemBlobId],
|
|
1187
|
-
turns: turnBlobIds,
|
|
1188
|
-
todos: [],
|
|
1189
|
-
pendingToolCalls: [],
|
|
1190
|
-
previousWorkspaceUris: [pathToFileURL(process.cwd()).href],
|
|
1191
|
-
mode: 1,
|
|
1192
|
-
fileStates: {},
|
|
1193
|
-
fileStatesV2: {},
|
|
1194
|
-
summaryArchives: [],
|
|
1195
|
-
turnTimings: [],
|
|
1196
|
-
subagentStates: {},
|
|
1197
|
-
selfSummaryCount: 0,
|
|
1198
|
-
readPaths: [],
|
|
1199
|
-
clientName: "dsh"
|
|
1200
|
-
}),
|
|
1504
|
+
conversationState,
|
|
1201
1505
|
action: create(ConversationActionSchema, { action: {
|
|
1202
1506
|
case: "userMessageAction",
|
|
1203
|
-
value: create(UserMessageActionSchema, { userMessage
|
|
1507
|
+
value: create(UserMessageActionSchema, { userMessage })
|
|
1204
1508
|
} }),
|
|
1205
|
-
requestedModel
|
|
1206
|
-
modelId: options.model,
|
|
1207
|
-
maxMode: false,
|
|
1208
|
-
parameters: []
|
|
1209
|
-
}),
|
|
1509
|
+
requestedModel,
|
|
1210
1510
|
conversationId: options.sessionId ?? randomUUID(),
|
|
1211
1511
|
mcpTools: create(McpToolsSchema, { mcpTools })
|
|
1212
1512
|
})
|
|
1213
1513
|
} })),
|
|
1214
1514
|
blobStore,
|
|
1215
|
-
mcpTools
|
|
1515
|
+
mcpTools,
|
|
1516
|
+
rules,
|
|
1517
|
+
inputTokenEstimate: estimateInputTokens(rules, promptMessages, text, mcpTools)
|
|
1216
1518
|
};
|
|
1217
1519
|
}
|
|
1218
1520
|
/**
|
|
@@ -1332,12 +1634,13 @@ function answerKv(stream, kv, blobStore) {
|
|
|
1332
1634
|
}
|
|
1333
1635
|
throw new LlmError("llm-cursor: unanswered Cursor KV message", "STREAM_CLOSED");
|
|
1334
1636
|
}
|
|
1335
|
-
function answerRequestContext(stream, exec,
|
|
1637
|
+
function answerRequestContext(stream, exec, payload) {
|
|
1638
|
+
const env = create(RequestContextEnvSchema, { workspacePaths: [pathToFileURL(process.cwd()).href] });
|
|
1336
1639
|
const requestContext = create(RequestContextSchema, {
|
|
1337
|
-
rules:
|
|
1338
|
-
env
|
|
1640
|
+
rules: payload.rules,
|
|
1641
|
+
env,
|
|
1339
1642
|
repositoryInfo: [],
|
|
1340
|
-
tools: mcpTools,
|
|
1643
|
+
tools: payload.mcpTools,
|
|
1341
1644
|
gitRepos: [],
|
|
1342
1645
|
projectLayouts: [],
|
|
1343
1646
|
mcpInstructions: [],
|
|
@@ -1359,14 +1662,197 @@ function answerRequestContext(stream, exec, mcpTools) {
|
|
|
1359
1662
|
})
|
|
1360
1663
|
} });
|
|
1361
1664
|
}
|
|
1362
|
-
|
|
1665
|
+
/** Harness tools that stand in for each Cursor-native exec, in preference order. */
|
|
1666
|
+
const NATIVE_TOOL_ALTERNATIVES = {
|
|
1667
|
+
readArgs: ["read"],
|
|
1668
|
+
lsArgs: ["glob"],
|
|
1669
|
+
grepArgs: ["grep"],
|
|
1670
|
+
writeArgs: ["write", "edit"],
|
|
1671
|
+
deleteArgs: ["bash", "pwsh"],
|
|
1672
|
+
shellArgs: ["bash", "pwsh"],
|
|
1673
|
+
shellStreamArgs: ["bash", "pwsh"],
|
|
1674
|
+
backgroundShellSpawnArgs: ["bash", "pwsh"],
|
|
1675
|
+
writeShellStdinArgs: ["bash", "pwsh"],
|
|
1676
|
+
fetchArgs: ["web_fetch"],
|
|
1677
|
+
diagnosticsArgs: ["lsp"],
|
|
1678
|
+
listMcpResourcesExecArgs: ["list_mcp_resources"],
|
|
1679
|
+
readMcpResourceExecArgs: ["read_mcp_resource"]
|
|
1680
|
+
};
|
|
1681
|
+
function nativeRejectionReason(execCase, mcpTools) {
|
|
1682
|
+
const offered = new Set(mcpTools.map((tool) => tool.name));
|
|
1683
|
+
const alternative = (NATIVE_TOOL_ALTERNATIVES[execCase] ?? []).find((name) => offered.has(name));
|
|
1684
|
+
const refusal = `Cursor's built-in ${execCase.replace(/Args$/, "")} tool is not available in DeepSeek Harness.`;
|
|
1685
|
+
return alternative === void 0 ? `${refusal} Use the tools whose names start with ${MCP_PROMPT_TOOL_PREFIX} instead.` : `${refusal} Call the ${MCP_PROMPT_TOOL_PREFIX}${alternative} tool instead.`;
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* The typed rejection one Cursor-native exec expects, so the Run stays alive
|
|
1689
|
+
* and the model reads the reason as a tool outcome. Unknown execs, which
|
|
1690
|
+
* signal wire drift, get no reply here.
|
|
1691
|
+
*/
|
|
1692
|
+
function nativeRejection(exec, reason) {
|
|
1693
|
+
const args = exec.message;
|
|
1694
|
+
const shellRejected = (command, workingDirectory) => create(ShellRejectedSchema, {
|
|
1695
|
+
command,
|
|
1696
|
+
workingDirectory,
|
|
1697
|
+
reason,
|
|
1698
|
+
isReadonly: false
|
|
1699
|
+
});
|
|
1700
|
+
switch (args.case) {
|
|
1701
|
+
case "shellArgs": return {
|
|
1702
|
+
case: "shellResult",
|
|
1703
|
+
value: create(ShellResultSchema, { result: {
|
|
1704
|
+
case: "rejected",
|
|
1705
|
+
value: shellRejected(args.value.command, args.value.workingDirectory)
|
|
1706
|
+
} })
|
|
1707
|
+
};
|
|
1708
|
+
case "shellStreamArgs": return {
|
|
1709
|
+
case: "shellStream",
|
|
1710
|
+
value: create(ShellStreamSchema, { event: {
|
|
1711
|
+
case: "rejected",
|
|
1712
|
+
value: shellRejected(args.value.command, args.value.workingDirectory)
|
|
1713
|
+
} })
|
|
1714
|
+
};
|
|
1715
|
+
case "backgroundShellSpawnArgs": return {
|
|
1716
|
+
case: "backgroundShellSpawnResult",
|
|
1717
|
+
value: create(BackgroundShellSpawnResultSchema, { result: {
|
|
1718
|
+
case: "rejected",
|
|
1719
|
+
value: shellRejected(args.value.command, args.value.workingDirectory)
|
|
1720
|
+
} })
|
|
1721
|
+
};
|
|
1722
|
+
case "writeShellStdinArgs": return {
|
|
1723
|
+
case: "writeShellStdinResult",
|
|
1724
|
+
value: create(WriteShellStdinResultSchema, { result: {
|
|
1725
|
+
case: "error",
|
|
1726
|
+
value: create(WriteShellStdinErrorSchema, { error: reason })
|
|
1727
|
+
} })
|
|
1728
|
+
};
|
|
1729
|
+
case "writeArgs": return {
|
|
1730
|
+
case: "writeResult",
|
|
1731
|
+
value: create(WriteResultSchema, { result: {
|
|
1732
|
+
case: "rejected",
|
|
1733
|
+
value: create(WriteRejectedSchema, {
|
|
1734
|
+
path: args.value.path,
|
|
1735
|
+
reason
|
|
1736
|
+
})
|
|
1737
|
+
} })
|
|
1738
|
+
};
|
|
1739
|
+
case "deleteArgs": return {
|
|
1740
|
+
case: "deleteResult",
|
|
1741
|
+
value: create(DeleteResultSchema, { result: {
|
|
1742
|
+
case: "rejected",
|
|
1743
|
+
value: create(DeleteRejectedSchema, {
|
|
1744
|
+
path: args.value.path,
|
|
1745
|
+
reason
|
|
1746
|
+
})
|
|
1747
|
+
} })
|
|
1748
|
+
};
|
|
1749
|
+
case "grepArgs": return {
|
|
1750
|
+
case: "grepResult",
|
|
1751
|
+
value: create(GrepResultSchema, { result: {
|
|
1752
|
+
case: "error",
|
|
1753
|
+
value: create(GrepErrorSchema, { error: reason })
|
|
1754
|
+
} })
|
|
1755
|
+
};
|
|
1756
|
+
case "readArgs": return {
|
|
1757
|
+
case: "readResult",
|
|
1758
|
+
value: create(ReadResultSchema, { result: {
|
|
1759
|
+
case: "rejected",
|
|
1760
|
+
value: create(ReadRejectedSchema, {
|
|
1761
|
+
path: args.value.path,
|
|
1762
|
+
reason
|
|
1763
|
+
})
|
|
1764
|
+
} })
|
|
1765
|
+
};
|
|
1766
|
+
case "lsArgs": return {
|
|
1767
|
+
case: "lsResult",
|
|
1768
|
+
value: create(LsResultSchema, { result: {
|
|
1769
|
+
case: "rejected",
|
|
1770
|
+
value: create(LsRejectedSchema, {
|
|
1771
|
+
path: args.value.path,
|
|
1772
|
+
reason
|
|
1773
|
+
})
|
|
1774
|
+
} })
|
|
1775
|
+
};
|
|
1776
|
+
case "diagnosticsArgs": return {
|
|
1777
|
+
case: "diagnosticsResult",
|
|
1778
|
+
value: create(DiagnosticsResultSchema, { result: {
|
|
1779
|
+
case: "rejected",
|
|
1780
|
+
value: create(DiagnosticsRejectedSchema, {
|
|
1781
|
+
path: args.value.path,
|
|
1782
|
+
reason
|
|
1783
|
+
})
|
|
1784
|
+
} })
|
|
1785
|
+
};
|
|
1786
|
+
case "listMcpResourcesExecArgs": return {
|
|
1787
|
+
case: "listMcpResourcesExecResult",
|
|
1788
|
+
value: create(ListMcpResourcesExecResultSchema, { result: {
|
|
1789
|
+
case: "rejected",
|
|
1790
|
+
value: create(ListMcpResourcesRejectedSchema, { reason })
|
|
1791
|
+
} })
|
|
1792
|
+
};
|
|
1793
|
+
case "readMcpResourceExecArgs": return {
|
|
1794
|
+
case: "readMcpResourceExecResult",
|
|
1795
|
+
value: create(ReadMcpResourceExecResultSchema, { result: {
|
|
1796
|
+
case: "rejected",
|
|
1797
|
+
value: create(ReadMcpResourceRejectedSchema, {
|
|
1798
|
+
uri: args.value.uri,
|
|
1799
|
+
reason
|
|
1800
|
+
})
|
|
1801
|
+
} })
|
|
1802
|
+
};
|
|
1803
|
+
case "fetchArgs": return {
|
|
1804
|
+
case: "fetchResult",
|
|
1805
|
+
value: create(FetchResultSchema, { result: {
|
|
1806
|
+
case: "error",
|
|
1807
|
+
value: create(FetchErrorSchema, {
|
|
1808
|
+
url: args.value.url,
|
|
1809
|
+
error: reason
|
|
1810
|
+
})
|
|
1811
|
+
} })
|
|
1812
|
+
};
|
|
1813
|
+
case "recordScreenArgs": return {
|
|
1814
|
+
case: "recordScreenResult",
|
|
1815
|
+
value: create(RecordScreenResultSchema, { result: {
|
|
1816
|
+
case: "failure",
|
|
1817
|
+
value: create(RecordScreenFailureSchema, { error: reason })
|
|
1818
|
+
} })
|
|
1819
|
+
};
|
|
1820
|
+
case "computerUseArgs": return {
|
|
1821
|
+
case: "computerUseResult",
|
|
1822
|
+
value: create(ComputerUseResultSchema, { result: {
|
|
1823
|
+
case: "error",
|
|
1824
|
+
value: create(ComputerUseErrorSchema, {
|
|
1825
|
+
error: reason,
|
|
1826
|
+
actionCount: args.value.actions.length,
|
|
1827
|
+
durationMs: 0
|
|
1828
|
+
})
|
|
1829
|
+
} })
|
|
1830
|
+
};
|
|
1831
|
+
default: return;
|
|
1832
|
+
}
|
|
1833
|
+
}
|
|
1834
|
+
/** Answer a Cursor-native exec with its typed rejection; false when the exec is unknown. */
|
|
1835
|
+
function answerNativeExec(stream, exec, mcpTools) {
|
|
1836
|
+
const reply = nativeRejection(exec, nativeRejectionReason(exec.message.case ?? "", mcpTools));
|
|
1837
|
+
if (reply === void 0) return false;
|
|
1838
|
+
sendClient(stream, { message: {
|
|
1839
|
+
case: "execClientMessage",
|
|
1840
|
+
value: create(ExecClientMessageSchema, {
|
|
1841
|
+
id: exec.id,
|
|
1842
|
+
execId: exec.execId,
|
|
1843
|
+
message: reply
|
|
1844
|
+
})
|
|
1845
|
+
} });
|
|
1846
|
+
return true;
|
|
1847
|
+
}
|
|
1848
|
+
function rejectUnknownExec(stream, exec) {
|
|
1363
1849
|
sendClient(stream, { message: {
|
|
1364
1850
|
case: "execClientControlMessage",
|
|
1365
1851
|
value: create(ExecClientControlMessageSchema, { message: {
|
|
1366
1852
|
case: "throw",
|
|
1367
1853
|
value: create(ExecClientThrowSchema, {
|
|
1368
1854
|
id: exec.id,
|
|
1369
|
-
error: "This
|
|
1855
|
+
error: "This Cursor exec is not supported by DeepSeek Harness. Use the MCP tools provided instead."
|
|
1370
1856
|
})
|
|
1371
1857
|
} })
|
|
1372
1858
|
} });
|
|
@@ -1430,6 +1916,11 @@ function* emitToolCall(index, id, name, args) {
|
|
|
1430
1916
|
}
|
|
1431
1917
|
};
|
|
1432
1918
|
}
|
|
1919
|
+
/** The harness tool name behind one Cursor MCP exec; a model may echo the replayed `mcp_dsh_` form. */
|
|
1920
|
+
function harnessToolName(mcp) {
|
|
1921
|
+
const name = mcp.toolName.length > 0 ? mcp.toolName : mcp.name;
|
|
1922
|
+
return name.startsWith(MCP_PROMPT_TOOL_PREFIX) ? name.slice(MCP_PROMPT_TOOL_PREFIX.length) : name;
|
|
1923
|
+
}
|
|
1433
1924
|
function settledOnAbort$1(signal) {
|
|
1434
1925
|
return new Promise((_, reject) => {
|
|
1435
1926
|
const fail = () => {
|
|
@@ -1487,7 +1978,7 @@ async function* streamCursorRun(options, accessToken, idleTimeoutMs, openStream
|
|
|
1487
1978
|
throw error;
|
|
1488
1979
|
}
|
|
1489
1980
|
if (item.done) break;
|
|
1490
|
-
const chunks = handleServerMessage(fromBinary(AgentServerMessageSchema, item.value.payload), stream, payload
|
|
1981
|
+
const chunks = handleServerMessage(fromBinary(AgentServerMessageSchema, item.value.payload), stream, payload, {
|
|
1491
1982
|
nextIndex,
|
|
1492
1983
|
open,
|
|
1493
1984
|
outputTokens,
|
|
@@ -1503,7 +1994,7 @@ async function* streamCursorRun(options, accessToken, idleTimeoutMs, openStream
|
|
|
1503
1994
|
yield {
|
|
1504
1995
|
type: "usage",
|
|
1505
1996
|
usage: {
|
|
1506
|
-
inputTokens:
|
|
1997
|
+
inputTokens: payload.inputTokenEstimate,
|
|
1507
1998
|
outputTokens
|
|
1508
1999
|
}
|
|
1509
2000
|
};
|
|
@@ -1523,7 +2014,7 @@ async function* streamCursorRun(options, accessToken, idleTimeoutMs, openStream
|
|
|
1523
2014
|
__disposeResources(env_1);
|
|
1524
2015
|
}
|
|
1525
2016
|
}
|
|
1526
|
-
function handleServerMessage(message, stream,
|
|
2017
|
+
function handleServerMessage(message, stream, payload, state) {
|
|
1527
2018
|
const chunks = [];
|
|
1528
2019
|
let { nextIndex, open, outputTokens, sawContent } = state;
|
|
1529
2020
|
const msgCase = message.message.case;
|
|
@@ -1603,7 +2094,7 @@ function handleServerMessage(message, stream, blobStore, mcpTools, state) {
|
|
|
1603
2094
|
};
|
|
1604
2095
|
}
|
|
1605
2096
|
if (msgCase === "kvServerMessage") {
|
|
1606
|
-
answerKv(stream, message.message.value, blobStore);
|
|
2097
|
+
answerKv(stream, message.message.value, payload.blobStore);
|
|
1607
2098
|
return {
|
|
1608
2099
|
chunks,
|
|
1609
2100
|
nextIndex,
|
|
@@ -1616,7 +2107,7 @@ function handleServerMessage(message, stream, blobStore, mcpTools, state) {
|
|
|
1616
2107
|
const exec = message.message.value;
|
|
1617
2108
|
const execCase = exec.message.case;
|
|
1618
2109
|
if (execCase === "requestContextArgs") {
|
|
1619
|
-
answerRequestContext(stream, exec,
|
|
2110
|
+
answerRequestContext(stream, exec, payload);
|
|
1620
2111
|
return {
|
|
1621
2112
|
chunks,
|
|
1622
2113
|
nextIndex,
|
|
@@ -1627,10 +2118,9 @@ function handleServerMessage(message, stream, blobStore, mcpTools, state) {
|
|
|
1627
2118
|
}
|
|
1628
2119
|
if (execCase === "mcpArgs") {
|
|
1629
2120
|
const mcp = exec.message.value;
|
|
1630
|
-
const toolName = mcp.toolName.length > 0 ? mcp.toolName : mcp.name;
|
|
1631
2121
|
chunks.push(...closeOpen(open));
|
|
1632
2122
|
open = void 0;
|
|
1633
|
-
chunks.push(...emitToolCall(nextIndex, mcp.toolCallId || `cursor-${exec.id}`,
|
|
2123
|
+
chunks.push(...emitToolCall(nextIndex, mcp.toolCallId || `cursor-${exec.id}`, harnessToolName(mcp), decodeMcpArgsMap(mcp.args)));
|
|
1634
2124
|
nextIndex += 1;
|
|
1635
2125
|
sawContent = true;
|
|
1636
2126
|
return {
|
|
@@ -1645,8 +2135,15 @@ function handleServerMessage(message, stream, blobStore, mcpTools, state) {
|
|
|
1645
2135
|
}
|
|
1646
2136
|
};
|
|
1647
2137
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
2138
|
+
if (answerNativeExec(stream, exec, payload.mcpTools)) return {
|
|
2139
|
+
chunks,
|
|
2140
|
+
nextIndex,
|
|
2141
|
+
open,
|
|
2142
|
+
outputTokens,
|
|
2143
|
+
sawContent
|
|
2144
|
+
};
|
|
2145
|
+
rejectUnknownExec(stream, exec);
|
|
2146
|
+
throw new LlmError(`llm-cursor: Cursor exec "${execCase ?? "unknown"}" is not supported by this adapter`, "UNSUPPORTED_CONTENT");
|
|
1650
2147
|
}
|
|
1651
2148
|
if (msgCase === "interactionQuery") {
|
|
1652
2149
|
const query = message.message.value;
|
package/package.json
CHANGED