@cursor/july 0.1.103 → 0.1.105
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/dist/channels/change-monitors/change-monitors-channel.d.ts +5 -0
- package/dist/channels/change-monitors/change-monitors-channel.d.ts.map +1 -0
- package/dist/channels/change-monitors/change-monitors-channel.js +41 -0
- package/dist/channels/change-monitors/index.d.ts +4 -0
- package/dist/channels/change-monitors/index.d.ts.map +1 -0
- package/dist/channels/change-monitors/index.js +2 -0
- package/dist/channels/change-monitors/types.d.ts +39 -0
- package/dist/channels/change-monitors/types.d.ts.map +1 -0
- package/dist/channels/change-monitors/types.js +1 -0
- package/dist/channels/deployments/deployments-channel.d.ts.map +1 -1
- package/dist/channels/deployments/deployments-channel.js +1 -0
- package/dist/channels/deployments/types.d.ts +2 -0
- package/dist/channels/deployments/types.d.ts.map +1 -1
- package/dist/channels/github/defaults.d.ts.map +1 -1
- package/dist/channels/github/defaults.js +4 -0
- package/dist/channels/github/progress.d.ts +22 -0
- package/dist/channels/github/progress.d.ts.map +1 -1
- package/dist/channels/github/progress.js +32 -5
- package/dist/channels/issues/index.d.ts +4 -0
- package/dist/channels/issues/index.d.ts.map +1 -0
- package/dist/channels/issues/index.js +2 -0
- package/dist/channels/issues/issues-channel.d.ts +5 -0
- package/dist/channels/issues/issues-channel.d.ts.map +1 -0
- package/dist/channels/issues/issues-channel.js +37 -0
- package/dist/channels/issues/types.d.ts +33 -0
- package/dist/channels/issues/types.d.ts.map +1 -0
- package/dist/channels/issues/types.js +1 -0
- package/dist/docs/404.html +2 -2
- package/dist/docs/ab.html +4 -4
- package/dist/docs/assets/{app.DW9pXkpL.js → app.BVwaffdK.js} +1 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.CJxMklAy.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.CdEIUwDg.js → VPLocalSearchBox.WuWTZ1x8.js} +1 -1
- package/dist/docs/assets/chunks/{theme.YZMHgPgg.js → theme.BYdI_6sF.js} +2 -2
- package/dist/docs/assets/{guides_github.md.DKYiT9do.js → guides_github.md.c0gdGJ-D.js} +1 -1
- package/dist/docs/assets/{guides_github.md.DKYiT9do.lean.js → guides_github.md.c0gdGJ-D.lean.js} +1 -1
- package/dist/docs/assets/guides_grokbot-agents.md.DVqdhBKb.js +9 -0
- package/dist/docs/assets/guides_grokbot-agents.md.DVqdhBKb.lean.js +1 -0
- package/dist/docs/assets/index.md.BW_6tOgR.js +5 -0
- package/dist/docs/assets/index.md.BW_6tOgR.lean.js +1 -0
- package/dist/docs/assets/{reference_channels.md.Dz8Cnudp.js → reference_channels.md.DBGcaB7m.js} +2 -2
- package/dist/docs/assets/{reference_channels.md.Dz8Cnudp.lean.js → reference_channels.md.DBGcaB7m.lean.js} +1 -1
- package/dist/docs/assets/{reference_cli.md.CJNc_xYK.js → reference_cli.md.C6Lo8SEd.js} +2 -1
- package/dist/docs/assets/{reference_extensions.md.DykHW3qL.js → reference_extensions.md.CGmMLblt.js} +1 -1
- package/dist/docs/assets/templates_grokbot-agents.md.c1s6Flp9.js +3 -0
- package/dist/docs/assets/templates_grokbot-agents.md.c1s6Flp9.lean.js +1 -0
- package/dist/docs/building-with-agents.html +4 -4
- package/dist/docs/concepts.html +4 -4
- package/dist/docs/deployment.html +4 -4
- package/dist/docs/design/filesystem.md +376 -0
- package/dist/docs/evals.html +4 -4
- package/dist/docs/guides/agent-to-agent.html +4 -4
- package/dist/docs/guides/cloud-agents.html +5 -5
- package/dist/docs/guides/convert-automation.html +4 -4
- package/dist/docs/guides/github.html +6 -6
- package/dist/docs/guides/github.md +5 -0
- package/dist/docs/guides/grokbot-agents.html +35 -0
- package/dist/docs/guides/grokbot-agents.md +88 -0
- package/dist/docs/guides/human-in-the-loop.html +4 -4
- package/dist/docs/guides/mcp-oauth.html +4 -4
- package/dist/docs/guides/opentelemetry.html +5 -5
- package/dist/docs/guides/slack.html +4 -4
- package/dist/docs/guides/webhooks.html +4 -4
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +4 -4
- package/dist/docs/index.html +6 -6
- package/dist/docs/index.md +6 -1
- package/dist/docs/llms-full.txt +562 -2
- package/dist/docs/llms.txt +3 -0
- package/dist/docs/quickstart.html +4 -4
- package/dist/docs/reference/agent-config.html +4 -4
- package/dist/docs/reference/artifacts.html +4 -4
- package/dist/docs/reference/channels.html +6 -6
- package/dist/docs/reference/channels.md +20 -0
- package/dist/docs/reference/cli.html +7 -6
- package/dist/docs/reference/cli.md +2 -1
- package/dist/docs/reference/connections.html +4 -4
- package/dist/docs/reference/extensions.html +6 -6
- package/dist/docs/reference/extensions.md +2 -0
- package/dist/docs/reference/hooks.html +4 -4
- package/dist/docs/reference/http-api.html +4 -4
- package/dist/docs/reference/instructions.html +4 -4
- package/dist/docs/reference/playground.html +4 -4
- package/dist/docs/reference/project-layout.html +4 -4
- package/dist/docs/reference/prompt.html +4 -4
- package/dist/docs/reference/result.html +4 -4
- package/dist/docs/reference/schedules.html +4 -4
- package/dist/docs/reference/sessions.html +4 -4
- package/dist/docs/reference/skills.html +4 -4
- package/dist/docs/reference/subagents.html +4 -4
- package/dist/docs/reference/tools.html +4 -4
- package/dist/docs/scaffolding-agents.html +4 -4
- package/dist/docs/skills/ab.html +4 -4
- package/dist/docs/skills/create-agent.html +4 -4
- package/dist/docs/skills/debug.html +4 -4
- package/dist/docs/skills/evals.html +4 -4
- package/dist/docs/skills/framework-map.html +4 -4
- package/dist/docs/skills/github.html +4 -4
- package/dist/docs/skills/hillclimb.html +4 -4
- package/dist/docs/skills/index.html +4 -4
- package/dist/docs/skills/mcp-auth.html +4 -4
- package/dist/docs/skills/otel.html +4 -4
- package/dist/docs/skills/setup-slack.html +4 -4
- package/dist/docs/storage.html +4 -4
- package/dist/docs/templates/agentic-owners.html +4 -4
- package/dist/docs/templates/agents-md.html +4 -4
- package/dist/docs/templates/code-wiki.html +5 -5
- package/dist/docs/templates/demo.html +5 -5
- package/dist/docs/templates/grokbot-agents.html +29 -0
- package/dist/docs/templates/grokbot-agents.md +48 -0
- package/dist/docs/templates/pr-autofixer.html +4 -4
- package/dist/docs/templates/security-help.html +4 -4
- package/dist/docs/templates/security-reviewer.html +4 -4
- package/dist/docs/templates/triage.html +4 -4
- package/dist/docs/troubleshooting.html +4 -4
- package/dist/files.d.ts +7 -2
- package/dist/files.d.ts.map +1 -1
- package/dist/files.js +7 -2
- package/dist/filesystem.d.ts +440 -0
- package/dist/filesystem.d.ts.map +1 -0
- package/dist/filesystem.js +1694 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -0
- package/dist/internal/continuation-channel.d.ts +4 -2
- package/dist/internal/continuation-channel.d.ts.map +1 -1
- package/dist/internal/continuation-channel.js +21 -12
- package/dist/internal/continuation-identity.d.ts +13 -5
- package/dist/internal/continuation-identity.d.ts.map +1 -1
- package/dist/internal/continuation-identity.js +74 -35
- package/dist/internal/cursor-agent-template.d.ts +1 -1
- package/dist/internal/cursor-agent-template.d.ts.map +1 -1
- package/dist/internal/cursor-agent-template.js +1 -0
- package/dist/internal/discovery/agent.d.ts.map +1 -1
- package/dist/internal/discovery/agent.js +80 -8
- package/dist/internal/discovery/info.d.ts.map +1 -1
- package/dist/internal/discovery/info.js +3 -0
- package/dist/internal/factory-resource-channel.d.ts +33 -0
- package/dist/internal/factory-resource-channel.d.ts.map +1 -0
- package/dist/internal/factory-resource-channel.js +77 -0
- package/dist/internal/filesystem/errors.d.ts +64 -0
- package/dist/internal/filesystem/errors.d.ts.map +1 -0
- package/dist/internal/filesystem/errors.js +175 -0
- package/dist/internal/filesystem/format.d.ts +28 -0
- package/dist/internal/filesystem/format.d.ts.map +1 -0
- package/dist/internal/filesystem/format.js +213 -0
- package/dist/internal/filesystem/merge.d.ts +34 -0
- package/dist/internal/filesystem/merge.d.ts.map +1 -0
- package/dist/internal/filesystem/merge.js +196 -0
- package/dist/internal/filesystem/scratch.d.ts +59 -0
- package/dist/internal/filesystem/scratch.d.ts.map +1 -0
- package/dist/internal/filesystem/scratch.js +212 -0
- package/dist/internal/filesystem/sdk-schemas.d.ts +29 -0
- package/dist/internal/filesystem/sdk-schemas.d.ts.map +1 -0
- package/dist/internal/filesystem/sdk-schemas.js +153 -0
- package/dist/internal/filesystem/tools.d.ts +42 -0
- package/dist/internal/filesystem/tools.d.ts.map +1 -0
- package/dist/internal/filesystem/tools.js +618 -0
- package/dist/internal/filesystem/walk.d.ts +74 -0
- package/dist/internal/filesystem/walk.d.ts.map +1 -0
- package/dist/internal/filesystem/walk.js +339 -0
- package/dist/internal/framework-file-storage.d.ts +3 -1
- package/dist/internal/framework-file-storage.d.ts.map +1 -1
- package/dist/internal/framework-file-storage.js +3 -1
- package/dist/internal/guest-network.d.ts +5 -2
- package/dist/internal/guest-network.d.ts.map +1 -1
- package/dist/internal/guest-network.js +7 -2
- package/dist/internal/hosted-delivery.d.ts +7 -0
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +41 -3
- package/dist/internal/hosted-managed-automation.d.ts.map +1 -1
- package/dist/internal/hosted-managed-automation.js +27 -2
- package/dist/internal/init-project.d.ts.map +1 -1
- package/dist/internal/init-project.js +4 -1
- package/dist/internal/sdk-runner.d.ts +13 -1
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +21 -1
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +11 -3
- package/dist/internal/session-engine.d.ts +30 -0
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +484 -82
- package/dist/internal/store-mirror.d.ts +2 -2
- package/dist/internal/store-mirror.js +2 -2
- package/dist/internal/tenant-slack/relay.d.ts +2 -0
- package/dist/internal/tenant-slack/relay.d.ts.map +1 -1
- package/dist/internal/tenant-slack/relay.js +18 -8
- package/dist/internal/testing/factory-resource-fixtures.d.ts +48 -0
- package/dist/internal/testing/factory-resource-fixtures.d.ts.map +1 -0
- package/dist/internal/testing/factory-resource-fixtures.js +41 -0
- package/dist/internal/workspace-sync.d.ts +31 -6
- package/dist/internal/workspace-sync.d.ts.map +1 -1
- package/dist/internal/workspace-sync.js +67 -12
- package/dist/internal/workspace.d.ts +9 -0
- package/dist/internal/workspace.d.ts.map +1 -1
- package/dist/internal/workspace.js +16 -0
- package/dist/playground/assets/{index-59KvgREd.js → index-BaQzjaNK.js} +40 -40
- package/dist/playground/assets/index-CceqnLTX.css +1 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +60 -11
- package/dist/types.d.ts.map +1 -1
- package/docs/README.md +6 -1
- package/docs/design/filesystem.md +376 -0
- package/docs/guides/github.md +5 -0
- package/docs/guides/grokbot-agents.md +93 -0
- package/docs/reference/channels.md +20 -0
- package/docs/reference/cli.md +2 -1
- package/docs/reference/extensions.md +2 -0
- package/docs/templates/grokbot-agents.md +53 -0
- package/package.json +25 -2
- package/src/channels/change-monitors/change-monitors-channel.ts +62 -0
- package/src/channels/change-monitors/index.ts +8 -0
- package/src/channels/change-monitors/types.ts +44 -0
- package/src/channels/deployments/deployments-channel.ts +1 -0
- package/src/channels/deployments/types.ts +2 -0
- package/src/channels/github/defaults.ts +4 -0
- package/src/channels/github/progress.ts +76 -10
- package/src/channels/issues/index.ts +9 -0
- package/src/channels/issues/issues-channel.ts +51 -0
- package/src/channels/issues/types.ts +41 -0
- package/src/files.ts +9 -2
- package/src/filesystem.ts +2074 -0
- package/src/index.ts +28 -0
- package/src/internal/continuation-channel.ts +29 -12
- package/src/internal/continuation-identity.ts +122 -37
- package/src/internal/cursor-agent-template.ts +1 -0
- package/src/internal/discovery/agent.ts +87 -1
- package/src/internal/discovery/info.ts +3 -0
- package/src/internal/factory-resource-channel.ts +122 -0
- package/src/internal/filesystem/errors.ts +220 -0
- package/src/internal/filesystem/format.ts +276 -0
- package/src/internal/filesystem/merge.ts +195 -0
- package/src/internal/filesystem/scratch.ts +255 -0
- package/src/internal/filesystem/sdk-schemas.ts +204 -0
- package/src/internal/filesystem/tools.ts +821 -0
- package/src/internal/filesystem/walk.ts +369 -0
- package/src/internal/framework-file-storage.ts +3 -1
- package/src/internal/guest-network.ts +8 -2
- package/src/internal/hosted-delivery.ts +71 -2
- package/src/internal/hosted-managed-automation.ts +49 -5
- package/src/internal/init-project.ts +4 -1
- package/src/internal/sdk-runner.ts +23 -0
- package/src/internal/server.ts +16 -0
- package/src/internal/session-engine.ts +595 -73
- package/src/internal/store-mirror.ts +2 -2
- package/src/internal/tenant-slack/relay.ts +28 -4
- package/src/internal/testing/factory-resource-fixtures.ts +85 -0
- package/src/internal/workspace-sync.ts +84 -12
- package/src/internal/workspace.ts +20 -0
- package/src/types.ts +58 -11
- package/templates/grokbot-agents/README.md +26 -0
- package/templates/grokbot-agents/agent/agent.ts +6 -0
- package/templates/grokbot-agents/agent/extensions/grokbot.ts +5 -0
- package/templates/grokbot-agents/agent/instructions.md +7 -0
- package/templates/grokbot-agents/evals/evals.config.ts +5 -0
- package/templates/grokbot-agents/evals/grokbot-agents.eval.ts +18 -0
- package/templates/grokbot-agents/init.json +18 -0
- package/templates/grokbot-agents/package.json +17 -0
- package/templates/grokbot-agents/tsconfig.json +12 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.nrl1ifBq.js +0 -1
- package/dist/docs/assets/index.md.D75GWhPl.js +0 -5
- package/dist/docs/assets/index.md.D75GWhPl.lean.js +0 -1
- package/dist/playground/assets/index-MbMxXg-y.css +0 -1
- /package/dist/docs/assets/{reference_cli.md.CJNc_xYK.lean.js → reference_cli.md.C6Lo8SEd.lean.js} +0 -0
- /package/dist/docs/assets/{reference_extensions.md.DykHW3qL.lean.js → reference_extensions.md.CGmMLblt.lean.js} +0 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host `{cwd}/agent-tools/{uuid}.txt` → `/tmp/{uuid}.txt`.
|
|
3
|
+
*
|
|
4
|
+
* Native WebSearch / WebFetch still scratch large output on the host.
|
|
5
|
+
* The session engine mounts `tempFs()` at `/tmp` with `unionFs` and
|
|
6
|
+
* copies only those files onto that tree. This module is the host-path
|
|
7
|
+
* translation, not a FileSystem type.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { readdir, readFile, rm } from "node:fs/promises";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import type { FileSystem } from "../../filesystem.js";
|
|
13
|
+
|
|
14
|
+
export const TMP_SCRATCH_PREFIX = "/tmp";
|
|
15
|
+
export const HOST_AGENT_TOOLS_DIR = "agent-tools";
|
|
16
|
+
export const WEB_SCRATCH_TOOLS = ["webSearch", "webFetch"] as const;
|
|
17
|
+
|
|
18
|
+
export function isWebScratchTool(name: string | undefined): boolean {
|
|
19
|
+
return name === "webSearch" || name === "webFetch";
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const UUID_TXT =
|
|
23
|
+
/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\.txt$/i;
|
|
24
|
+
|
|
25
|
+
const HOST_FOLLOW_UP =
|
|
26
|
+
/Use shell \/ grep \/ read_file on this path to inspect the page/g;
|
|
27
|
+
const OVERLAY_FOLLOW_UP = "Use Read / Grep on this path to inspect the page";
|
|
28
|
+
|
|
29
|
+
const PATH_KEYS = [
|
|
30
|
+
"path",
|
|
31
|
+
"dir",
|
|
32
|
+
"targetDirectory",
|
|
33
|
+
"target_directory",
|
|
34
|
+
] as const;
|
|
35
|
+
|
|
36
|
+
export function tmpScratchPath(fileName: string): string {
|
|
37
|
+
return `${TMP_SCRATCH_PREFIX}/${fileName}`;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function hostAgentToolsDir(cwd: string): string {
|
|
41
|
+
return path.resolve(cwd, HOST_AGENT_TOOLS_DIR);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Basename of `{cwd}/agent-tools/{uuid}.txt`, or undefined. Other
|
|
46
|
+
* paths in a result are ignored.
|
|
47
|
+
*/
|
|
48
|
+
export function hostAgentToolsFileName(args: {
|
|
49
|
+
cwd: string;
|
|
50
|
+
candidate: string;
|
|
51
|
+
}): string | undefined {
|
|
52
|
+
if (args.candidate === "") {
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
const resolved = path.resolve(args.candidate);
|
|
56
|
+
if (path.dirname(resolved) !== hostAgentToolsDir(args.cwd)) {
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
const base = path.basename(resolved);
|
|
60
|
+
return UUID_TXT.test(base) ? base : undefined;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export function remapScratchPath(args: { cwd: string; path: string }): string {
|
|
64
|
+
const fileName = hostAgentToolsFileName({
|
|
65
|
+
cwd: args.cwd,
|
|
66
|
+
candidate: args.path,
|
|
67
|
+
});
|
|
68
|
+
return fileName === undefined ? args.path : tmpScratchPath(fileName);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export function remapScratchPaths(
|
|
72
|
+
input: Record<string, unknown>,
|
|
73
|
+
cwd: string
|
|
74
|
+
): Record<string, unknown> {
|
|
75
|
+
const next: Record<string, unknown> = { ...input };
|
|
76
|
+
for (const key of PATH_KEYS) {
|
|
77
|
+
const value = next[key];
|
|
78
|
+
if (typeof value === "string") {
|
|
79
|
+
next[key] = remapScratchPath({ cwd, path: value });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
return next;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export function rewriteWebScratchText(args: {
|
|
86
|
+
cwd: string;
|
|
87
|
+
text: string;
|
|
88
|
+
}): string {
|
|
89
|
+
const dir = hostAgentToolsDir(args.cwd);
|
|
90
|
+
const escaped = dir.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
91
|
+
const pattern = new RegExp(
|
|
92
|
+
`${escaped}[/\\\\]([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\\.txt)`,
|
|
93
|
+
"gi"
|
|
94
|
+
);
|
|
95
|
+
return args.text
|
|
96
|
+
.replace(pattern, (_match, fileName: string) => tmpScratchPath(fileName))
|
|
97
|
+
.replace(HOST_FOLLOW_UP, OVERLAY_FOLLOW_UP);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** Rewrite host agent-tools paths in a string or a structured tool result. */
|
|
101
|
+
export function rewriteWebScratchValue(args: {
|
|
102
|
+
cwd: string;
|
|
103
|
+
value: unknown;
|
|
104
|
+
}): unknown {
|
|
105
|
+
const { cwd, value } = args;
|
|
106
|
+
if (typeof value === "string") {
|
|
107
|
+
return rewriteWebScratchText({ cwd, text: value });
|
|
108
|
+
}
|
|
109
|
+
if (Array.isArray(value)) {
|
|
110
|
+
return value.map((item) => rewriteWebScratchValue({ cwd, value: item }));
|
|
111
|
+
}
|
|
112
|
+
if (value !== null && typeof value === "object") {
|
|
113
|
+
const next: Record<string, unknown> = {};
|
|
114
|
+
for (const [key, item] of Object.entries(value)) {
|
|
115
|
+
next[key] = rewriteWebScratchValue({ cwd, value: item });
|
|
116
|
+
}
|
|
117
|
+
return next;
|
|
118
|
+
}
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* WebSearch / WebFetch result. Ingest the host spill and rewrite
|
|
124
|
+
* paths onto `/tmp`. Other tools are a no-op.
|
|
125
|
+
*/
|
|
126
|
+
export async function finishWebScratchTool(args: {
|
|
127
|
+
toolName: string | undefined;
|
|
128
|
+
result: unknown;
|
|
129
|
+
cwd: string;
|
|
130
|
+
root: FileSystem;
|
|
131
|
+
}): Promise<unknown> {
|
|
132
|
+
if (!isWebScratchTool(args.toolName)) {
|
|
133
|
+
return args.result;
|
|
134
|
+
}
|
|
135
|
+
await ingestHostAgentToolsScratch({ cwd: args.cwd, root: args.root });
|
|
136
|
+
return rewriteWebScratchValue({ cwd: args.cwd, value: args.result });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
type ToolCallLike = { type?: string; result?: unknown };
|
|
140
|
+
|
|
141
|
+
function completedWebToolCall(update: unknown): ToolCallLike | undefined {
|
|
142
|
+
if (update === null || typeof update !== "object") {
|
|
143
|
+
return undefined;
|
|
144
|
+
}
|
|
145
|
+
const rec = update as {
|
|
146
|
+
type?: string;
|
|
147
|
+
toolCall?: ToolCallLike;
|
|
148
|
+
taskUpdate?: { type?: string; toolCall?: ToolCallLike };
|
|
149
|
+
};
|
|
150
|
+
const call =
|
|
151
|
+
rec.type === "tool-call-completed"
|
|
152
|
+
? rec.toolCall
|
|
153
|
+
: rec.type === "tool-call-delta" &&
|
|
154
|
+
rec.taskUpdate?.type === "tool-call-completed"
|
|
155
|
+
? rec.taskUpdate.toolCall
|
|
156
|
+
: undefined;
|
|
157
|
+
if (call === undefined || !isWebScratchTool(call.type)) {
|
|
158
|
+
return undefined;
|
|
159
|
+
}
|
|
160
|
+
return call;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/** Finish a native web tool on the SDK update that carried its result. */
|
|
164
|
+
export async function applyWebScratchUpdate<T>(args: {
|
|
165
|
+
cwd: string;
|
|
166
|
+
root: FileSystem;
|
|
167
|
+
update: T;
|
|
168
|
+
}): Promise<T> {
|
|
169
|
+
const call = completedWebToolCall(args.update);
|
|
170
|
+
if (call === undefined) {
|
|
171
|
+
return args.update;
|
|
172
|
+
}
|
|
173
|
+
call.result = await finishWebScratchTool({
|
|
174
|
+
toolName: call.type,
|
|
175
|
+
result: call.result,
|
|
176
|
+
cwd: args.cwd,
|
|
177
|
+
root: args.root,
|
|
178
|
+
});
|
|
179
|
+
return args.update;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
export async function ingestHostAgentToolsScratch(args: {
|
|
183
|
+
cwd: string;
|
|
184
|
+
root: FileSystem;
|
|
185
|
+
hostPath?: string;
|
|
186
|
+
}): Promise<string[]> {
|
|
187
|
+
const written: string[] = [];
|
|
188
|
+
const names =
|
|
189
|
+
args.hostPath === undefined
|
|
190
|
+
? await listHostAgentToolsFiles(args.cwd)
|
|
191
|
+
: [args.hostPath];
|
|
192
|
+
for (const hostPath of names) {
|
|
193
|
+
const dest = await copyHostAgentToolsFile({
|
|
194
|
+
cwd: args.cwd,
|
|
195
|
+
root: args.root,
|
|
196
|
+
hostPath,
|
|
197
|
+
});
|
|
198
|
+
if (dest !== undefined) {
|
|
199
|
+
written.push(dest);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
return written;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
async function listHostAgentToolsFiles(cwd: string): Promise<string[]> {
|
|
206
|
+
const dir = hostAgentToolsDir(cwd);
|
|
207
|
+
try {
|
|
208
|
+
const entries = await readdir(dir, { withFileTypes: true });
|
|
209
|
+
return entries
|
|
210
|
+
.filter((entry) => entry.isFile() && UUID_TXT.test(entry.name))
|
|
211
|
+
.map((entry) => path.join(dir, entry.name));
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (isEnoent(error)) {
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
async function copyHostAgentToolsFile(args: {
|
|
221
|
+
cwd: string;
|
|
222
|
+
root: FileSystem;
|
|
223
|
+
hostPath: string;
|
|
224
|
+
}): Promise<string | undefined> {
|
|
225
|
+
const fileName = hostAgentToolsFileName({
|
|
226
|
+
cwd: args.cwd,
|
|
227
|
+
candidate: args.hostPath,
|
|
228
|
+
});
|
|
229
|
+
if (fileName === undefined) {
|
|
230
|
+
return undefined;
|
|
231
|
+
}
|
|
232
|
+
const dest = tmpScratchPath(fileName);
|
|
233
|
+
const hostPath = path.resolve(args.hostPath);
|
|
234
|
+
let bytes: Buffer;
|
|
235
|
+
try {
|
|
236
|
+
bytes = await readFile(hostPath);
|
|
237
|
+
} catch (error) {
|
|
238
|
+
if (isEnoent(error)) {
|
|
239
|
+
return undefined;
|
|
240
|
+
}
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
await args.root.write(dest, bytes.toString("utf8"));
|
|
244
|
+
await rm(hostPath, { force: true });
|
|
245
|
+
return dest;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function isEnoent(error: unknown): boolean {
|
|
249
|
+
return (
|
|
250
|
+
typeof error === "object" &&
|
|
251
|
+
error !== null &&
|
|
252
|
+
"code" in error &&
|
|
253
|
+
(error as { code: unknown }).code === "ENOENT"
|
|
254
|
+
);
|
|
255
|
+
}
|
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Advertised native-tool schemas. These are the `@cursor/sdk`
|
|
3
|
+
* tool-call types (`@anysphere/cursor-sdk-shared/tool-call-types`)
|
|
4
|
+
* reconstructed here so `@cursor/july` does not take an unpublished
|
|
5
|
+
* workspace dependency. The contract test pins JSON-schema equality
|
|
6
|
+
* against the SDK originals.
|
|
7
|
+
*
|
|
8
|
+
* Runtime aliases (`contents` → `fileText`, `old_string` → `oldText`)
|
|
9
|
+
* live on the `defineTool` input schema, not on these objects.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
14
|
+
const simpleError: z.ZodTypeAny = z.object({
|
|
15
|
+
message: z.string(),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function resultSchema(success: z.ZodTypeAny): z.ZodTypeAny {
|
|
19
|
+
return z.discriminatedUnion("status", [
|
|
20
|
+
z.object({
|
|
21
|
+
status: z.literal("success"),
|
|
22
|
+
value: success,
|
|
23
|
+
}),
|
|
24
|
+
z.object({
|
|
25
|
+
status: z.literal("error"),
|
|
26
|
+
error: simpleError,
|
|
27
|
+
}),
|
|
28
|
+
]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const sdkReadArgs: z.ZodTypeAny = z.object({
|
|
32
|
+
path: z.string(),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const sdkReadResult: z.ZodTypeAny = resultSchema(
|
|
36
|
+
z.object({
|
|
37
|
+
content: z.string(),
|
|
38
|
+
totalLines: z.number(),
|
|
39
|
+
fileSize: z.number(),
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const sdkWriteArgs: z.ZodTypeAny = z.object({
|
|
44
|
+
path: z.string(),
|
|
45
|
+
fileText: z.string(),
|
|
46
|
+
returnFileContentAfterWrite: z.boolean().optional(),
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const sdkWriteResult: z.ZodTypeAny = resultSchema(
|
|
50
|
+
z.object({
|
|
51
|
+
path: z.string(),
|
|
52
|
+
linesCreated: z.number(),
|
|
53
|
+
fileSize: z.number(),
|
|
54
|
+
fileContentAfterWrite: z.string().optional(),
|
|
55
|
+
})
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
export const sdkDeleteArgs: z.ZodTypeAny = z.object({
|
|
59
|
+
path: z.string(),
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
export const sdkDeleteResult: z.ZodTypeAny = resultSchema(
|
|
63
|
+
z.object({
|
|
64
|
+
fileSize: z.number(),
|
|
65
|
+
})
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
export const sdkGlobArgs: z.ZodTypeAny = z.object({
|
|
69
|
+
targetDirectory: z.string().optional(),
|
|
70
|
+
globPattern: z.string(),
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
export const sdkGlobResult: z.ZodTypeAny = resultSchema(
|
|
74
|
+
z.object({
|
|
75
|
+
files: z.array(z.string()),
|
|
76
|
+
totalFiles: z.number(),
|
|
77
|
+
clientTruncated: z.boolean(),
|
|
78
|
+
ripgrepTruncated: z.boolean(),
|
|
79
|
+
})
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
export const sdkGrepArgs: z.ZodTypeAny = z.object({
|
|
83
|
+
pattern: z.string(),
|
|
84
|
+
path: z.string().optional(),
|
|
85
|
+
glob: z.string().optional(),
|
|
86
|
+
outputMode: z.string().optional(),
|
|
87
|
+
contextBefore: z.number().optional(),
|
|
88
|
+
contextAfter: z.number().optional(),
|
|
89
|
+
context: z.number().optional(),
|
|
90
|
+
caseInsensitive: z.boolean().optional(),
|
|
91
|
+
type: z.string().optional(),
|
|
92
|
+
headLimit: z.number().optional(),
|
|
93
|
+
offset: z.number().optional(),
|
|
94
|
+
multiline: z.boolean().optional(),
|
|
95
|
+
sort: z.string().optional(),
|
|
96
|
+
sortAscending: z.boolean().optional(),
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
const grepContentMatch = z.object({
|
|
100
|
+
file: z.string(),
|
|
101
|
+
lineNumber: z.number().optional(),
|
|
102
|
+
line: z.string(),
|
|
103
|
+
beforeContext: z.array(z.string()).optional(),
|
|
104
|
+
afterContext: z.array(z.string()).optional(),
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
const grepFileCount = z.object({
|
|
108
|
+
file: z.string(),
|
|
109
|
+
count: z.number(),
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
const grepUnion = z.discriminatedUnion("type", [
|
|
113
|
+
z.object({
|
|
114
|
+
type: z.literal("content"),
|
|
115
|
+
output: z.object({
|
|
116
|
+
matches: z.array(grepContentMatch),
|
|
117
|
+
totalMatches: z.number(),
|
|
118
|
+
}),
|
|
119
|
+
}),
|
|
120
|
+
z.object({
|
|
121
|
+
type: z.literal("files"),
|
|
122
|
+
output: z.object({
|
|
123
|
+
files: z.array(z.string()),
|
|
124
|
+
count: z.number(),
|
|
125
|
+
}),
|
|
126
|
+
}),
|
|
127
|
+
z.object({
|
|
128
|
+
type: z.literal("count"),
|
|
129
|
+
output: z.object({
|
|
130
|
+
counts: z.array(grepFileCount),
|
|
131
|
+
total: z.number(),
|
|
132
|
+
}),
|
|
133
|
+
}),
|
|
134
|
+
]);
|
|
135
|
+
|
|
136
|
+
export const sdkGrepResult: z.ZodTypeAny = resultSchema(
|
|
137
|
+
z.object({
|
|
138
|
+
workspaceResults: z.record(grepUnion).optional(),
|
|
139
|
+
activeEditorResult: grepUnion.optional(),
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
export const sdkLsArgs: z.ZodTypeAny = z.object({
|
|
144
|
+
path: z.string(),
|
|
145
|
+
ignore: z.array(z.string()).optional(),
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
const lsDirectoryTreeNodeFile = z.object({
|
|
149
|
+
name: z.string(),
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
type LsDirectoryTreeNode = {
|
|
153
|
+
absPath: string;
|
|
154
|
+
childrenDirs: LsDirectoryTreeNode[];
|
|
155
|
+
childrenFiles: z.infer<typeof lsDirectoryTreeNodeFile>[];
|
|
156
|
+
childrenWereProcessed: boolean;
|
|
157
|
+
fullSubtreeExtensionCounts: Record<string, number>;
|
|
158
|
+
numFiles: number;
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const lsDirectoryTreeNode: z.ZodType<LsDirectoryTreeNode> = z.lazy(() =>
|
|
162
|
+
z.object({
|
|
163
|
+
absPath: z.string(),
|
|
164
|
+
childrenDirs: z.array(lsDirectoryTreeNode),
|
|
165
|
+
childrenFiles: z.array(lsDirectoryTreeNodeFile),
|
|
166
|
+
childrenWereProcessed: z.boolean(),
|
|
167
|
+
fullSubtreeExtensionCounts: z.record(z.number()),
|
|
168
|
+
numFiles: z.number(),
|
|
169
|
+
})
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
export const sdkLsResult: z.ZodTypeAny = resultSchema(
|
|
173
|
+
z.object({
|
|
174
|
+
directoryTreeRoot: lsDirectoryTreeNode,
|
|
175
|
+
})
|
|
176
|
+
);
|
|
177
|
+
|
|
178
|
+
/** StrReplace is SDK `edit` plus the str-replace args the model actually sends. */
|
|
179
|
+
export const sdkStrReplaceArgs: z.ZodTypeAny = z.object({
|
|
180
|
+
path: z.string(),
|
|
181
|
+
oldText: z.string(),
|
|
182
|
+
newText: z.string(),
|
|
183
|
+
replaceAll: z.boolean().optional(),
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
export const sdkEditResult: z.ZodTypeAny = resultSchema(
|
|
187
|
+
z.object({
|
|
188
|
+
linesAdded: z.number().optional(),
|
|
189
|
+
linesRemoved: z.number().optional(),
|
|
190
|
+
diffString: z.string().optional(),
|
|
191
|
+
})
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
export const sdkSemSearchArgs: z.ZodTypeAny = z.object({
|
|
195
|
+
query: z.string(),
|
|
196
|
+
targetDirectories: z.array(z.string()).optional(),
|
|
197
|
+
explanation: z.string().optional(),
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
export const sdkSemSearchResult: z.ZodTypeAny = resultSchema(
|
|
201
|
+
z.object({
|
|
202
|
+
results: z.string(),
|
|
203
|
+
})
|
|
204
|
+
);
|