@grok/agent-sdk 0.4.0 → 0.6.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/dist/channels/match-ready/index.d.ts +4 -0
- package/dist/channels/match-ready/index.d.ts.map +1 -0
- package/dist/channels/match-ready/index.js +2 -0
- package/dist/channels/match-ready/match-ready-channel.d.ts +5 -0
- package/dist/channels/match-ready/match-ready-channel.d.ts.map +1 -0
- package/dist/channels/match-ready/match-ready-channel.js +42 -0
- package/dist/channels/match-ready/types.d.ts +25 -0
- package/dist/channels/match-ready/types.d.ts.map +1 -0
- package/dist/channels/match-ready/types.js +1 -0
- package/dist/channels/slack/manifest.d.ts.map +1 -1
- package/dist/channels/slack/manifest.js +2 -15
- package/dist/docs/404.html +2 -2
- package/dist/docs/assets/{app.BSH__xV4.js → app.lt-BYgI2.js} +4 -4
- package/dist/docs/assets/changelog.md.DVNB-ApU.js +1 -0
- package/dist/docs/assets/changelog.md.DVNB-ApU.lean.js +1 -0
- package/dist/docs/assets/chunks/@localSearchIndexroot.DdlR-9Oe.js +1 -0
- package/dist/docs/assets/chunks/{VPLocalSearchBox.Cadl7A0k.js → VPLocalSearchBox.v_dV4U2Q.js} +1 -1
- package/dist/docs/assets/chunks/{arc.K7t9nNY6.js → arc.5o92kOg5.js} +1 -1
- package/dist/docs/assets/chunks/{architectureDiagram-Q4EWVU46.SlHEknkX.js → architectureDiagram-Q4EWVU46.C-oTwnNq.js} +1 -1
- package/dist/docs/assets/chunks/{baseUniq.DJLRMLkz.js → baseUniq.zJ-VNOib.js} +1 -1
- package/dist/docs/assets/chunks/{blockDiagram-DXYQGD6D.Bs6XxFpe.js → blockDiagram-DXYQGD6D.B9ZJZuPd.js} +1 -1
- package/dist/docs/assets/chunks/{c4Diagram-AHTNJAMY.CyLg6Ovc.js → c4Diagram-AHTNJAMY.BBMwSIaN.js} +1 -1
- package/dist/docs/assets/chunks/channel.CdyTxaXV.js +1 -0
- package/dist/docs/assets/chunks/{chunk-4BX2VUAB.DTQ4TinT.js → chunk-4BX2VUAB.D8qAJpDD.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-4TB4RGXK.Es84IgcH.js → chunk-4TB4RGXK.B8QR5cdE.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-55IACEB6.Clm3cGPQ.js → chunk-55IACEB6.BsWxVuew.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-EDXVE4YY.DE4CRkS5.js → chunk-EDXVE4YY.BeGygY_i.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-FMBD7UC4.Bf8HCvqp.js → chunk-FMBD7UC4.DdwgH-ZH.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-OYMX7WX6.eub-7nSx.js → chunk-OYMX7WX6.B9zC_ALe.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-QZHKN3VN.WyP9VAS_.js → chunk-QZHKN3VN.BIxJ0rcL.js} +1 -1
- package/dist/docs/assets/chunks/{chunk-YZCP3GAM.LO9ohhDE.js → chunk-YZCP3GAM.qiM_23_f.js} +1 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.CeUcN6TW.js +1 -0
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.CeUcN6TW.js +1 -0
- package/dist/docs/assets/chunks/clone.DpIwUbur.js +1 -0
- package/dist/docs/assets/chunks/{cose-bilkent-S5V4N54A.D5za6aH0.js → cose-bilkent-S5V4N54A.BKB971D5.js} +1 -1
- package/dist/docs/assets/chunks/{dagre-KV5264BT.Dq1daUru.js → dagre-KV5264BT.CcILjJgp.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-5BDNPKRD.j1YL5BKS.js → diagram-5BDNPKRD.DkY9A0nu.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-G4DWMVQ6.Bi1aLdhC.js → diagram-G4DWMVQ6.BbdzmjMt.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-MMDJMWI5.BOzMEkAr.js → diagram-MMDJMWI5.Be0zy1cM.js} +1 -1
- package/dist/docs/assets/chunks/{diagram-TYMM5635.Dx2FVhCr.js → diagram-TYMM5635.zOiEycLe.js} +1 -1
- package/dist/docs/assets/chunks/{erDiagram-SMLLAGMA.DI4TNkye.js → erDiagram-SMLLAGMA.DUd_9HMF.js} +1 -1
- package/dist/docs/assets/chunks/{flowDiagram-DWJPFMVM.C58Z9uPK.js → flowDiagram-DWJPFMVM.2KPYoZBO.js} +1 -1
- package/dist/docs/assets/chunks/{ganttDiagram-T4ZO3ILL.DXSpW809.js → ganttDiagram-T4ZO3ILL.DqE8_YpP.js} +1 -1
- package/dist/docs/assets/chunks/{gitGraphDiagram-UUTBAWPF.B955oaFl.js → gitGraphDiagram-UUTBAWPF.CO0Tk47h.js} +1 -1
- package/dist/docs/assets/chunks/{graph.BQXhKtxS.js → graph.CNe5KbNy.js} +1 -1
- package/dist/docs/assets/chunks/{infoDiagram-42DDH7IO.Dozj_-Gm.js → infoDiagram-42DDH7IO.BBhJ1X1B.js} +1 -1
- package/dist/docs/assets/chunks/{ishikawaDiagram-UXIWVN3A.D2140OzH.js → ishikawaDiagram-UXIWVN3A.KSIw9w3I.js} +1 -1
- package/dist/docs/assets/chunks/{journeyDiagram-VCZTEJTY.DrqrMhCk.js → journeyDiagram-VCZTEJTY.BN2Y5oUJ.js} +1 -1
- package/dist/docs/assets/chunks/{kanban-definition-6JOO6SKY.Dv-LTrlw.js → kanban-definition-6JOO6SKY.2KFuDYn_.js} +1 -1
- package/dist/docs/assets/chunks/{layout.CGtHp49X.js → layout.Demb_pzL.js} +1 -1
- package/dist/docs/assets/chunks/{linear.CHZLYB52.js → linear.kYKxzbbR.js} +1 -1
- package/dist/docs/assets/chunks/{min.D4Vt3eIy.js → min.DwmCN5dF.js} +1 -1
- package/dist/docs/assets/chunks/{mindmap-definition-QFDTVHPH.BBfpYTea.js → mindmap-definition-QFDTVHPH.CGlz01QG.js} +1 -1
- package/dist/docs/assets/chunks/{pieDiagram-DEJITSTG.BVYvElmY.js → pieDiagram-DEJITSTG.n3qsq4nA.js} +1 -1
- package/dist/docs/assets/chunks/{quadrantDiagram-34T5L4WZ.C6Gc2mdY.js → quadrantDiagram-34T5L4WZ.CGNJ1GSb.js} +1 -1
- package/dist/docs/assets/chunks/{requirementDiagram-MS252O5E.DWa8b4cn.js → requirementDiagram-MS252O5E.VhAzHDwQ.js} +1 -1
- package/dist/docs/assets/chunks/{sankeyDiagram-XADWPNL6.Bi-g4ajv.js → sankeyDiagram-XADWPNL6.DmHA5pW-.js} +1 -1
- package/dist/docs/assets/chunks/{sequenceDiagram-FGHM5R23.DlU3vVN9.js → sequenceDiagram-FGHM5R23._TC1aKhg.js} +1 -1
- package/dist/docs/assets/chunks/{stateDiagram-FHFEXIEX.CeqJRqnU.js → stateDiagram-FHFEXIEX.B-kLjV3O.js} +1 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.HtBkUH4J.js +1 -0
- package/dist/docs/assets/chunks/{theme.DGq7D4tt.js → theme.BaVlHHL-.js} +2 -2
- package/dist/docs/assets/chunks/{timeline-definition-GMOUNBTQ.Cqf2kjq9.js → timeline-definition-GMOUNBTQ.CresbphV.js} +1 -1
- package/dist/docs/assets/chunks/{vennDiagram-DHZGUBPP.BeOpE_lM.js → vennDiagram-DHZGUBPP.CegHD8Y4.js} +1 -1
- package/dist/docs/assets/chunks/{wardley-RL74JXVD.FMQXA-6q.js → wardley-RL74JXVD.DjCmZrUO.js} +1 -1
- package/dist/docs/assets/chunks/{wardleyDiagram-NUSXRM2D.BXS65dAC.js → wardleyDiagram-NUSXRM2D.BJ7s1zdZ.js} +1 -1
- package/dist/docs/assets/chunks/{xychartDiagram-5P7HB3ND.haEiSxqc.js → xychartDiagram-5P7HB3ND.IrEXlemI.js} +1 -1
- package/dist/docs/assets/{reference_agent-config.md.BSNp2uJ7.js → reference_agent-config.md.Bbqf0lgS.js} +11 -3
- package/dist/docs/assets/{reference_agent-config.md.BSNp2uJ7.lean.js → reference_agent-config.md.Bbqf0lgS.lean.js} +1 -1
- package/dist/docs/assets/{reference_schedules.md.Dd8_d0WG.js → reference_schedules.md.RhQ9ZLo1.js} +3 -3
- package/dist/docs/assets/{reference_tools.md.B2OaR1Nb.js → reference_tools.md.BhqW6neF.js} +4 -2
- package/dist/docs/assets/{reference_tools.md.B2OaR1Nb.lean.js → reference_tools.md.BhqW6neF.lean.js} +1 -1
- package/dist/docs/building-with-agents.html +35 -35
- package/dist/docs/changelog.html +36 -36
- package/dist/docs/changelog.md +47 -7
- package/dist/docs/deployment.html +35 -35
- package/dist/docs/evals.html +35 -35
- package/dist/docs/guides/agent-to-agent.html +35 -35
- package/dist/docs/guides/bitbucket.html +35 -35
- package/dist/docs/guides/cloud-agents.html +35 -35
- package/dist/docs/guides/convert-automation.html +35 -35
- package/dist/docs/guides/github.html +35 -35
- package/dist/docs/guides/gitlab.html +35 -35
- package/dist/docs/guides/improve.html +35 -35
- package/dist/docs/guides/jev.html +35 -35
- package/dist/docs/guides/mcp-oauth.html +35 -35
- package/dist/docs/guides/migrate.html +35 -35
- package/dist/docs/guides/opentelemetry.html +35 -35
- package/dist/docs/guides/pagerduty.html +35 -35
- package/dist/docs/guides/slack.html +35 -35
- package/dist/docs/guides/webhooks.html +35 -35
- package/dist/docs/hashmap.json +1 -1
- package/dist/docs/hillclimbing.html +35 -35
- package/dist/docs/index.html +35 -35
- package/dist/docs/llms-full.txt +129 -11
- package/dist/docs/quickstart.html +35 -35
- package/dist/docs/reference/access.html +35 -35
- package/dist/docs/reference/agent-config.html +45 -37
- package/dist/docs/reference/agent-config.md +70 -4
- package/dist/docs/reference/artifacts.html +35 -35
- package/dist/docs/reference/channels.html +35 -35
- package/dist/docs/reference/cli.html +35 -35
- package/dist/docs/reference/connections.html +35 -35
- package/dist/docs/reference/evals.html +35 -35
- package/dist/docs/reference/extensions.html +35 -35
- package/dist/docs/reference/hooks.html +35 -35
- package/dist/docs/reference/http-api.html +35 -35
- package/dist/docs/reference/instructions.html +35 -35
- package/dist/docs/reference/limits.html +35 -35
- package/dist/docs/reference/memory.html +35 -35
- package/dist/docs/reference/playground.html +35 -35
- package/dist/docs/reference/project-layout.html +35 -35
- package/dist/docs/reference/schedules.html +38 -38
- package/dist/docs/reference/sessions.html +35 -35
- package/dist/docs/reference/skills.html +35 -35
- package/dist/docs/reference/subagents.html +35 -35
- package/dist/docs/reference/tools.html +39 -37
- package/dist/docs/reference/tools.md +12 -0
- package/dist/docs/templates/agentic-owners.html +35 -35
- package/dist/docs/templates/reviews.html +35 -35
- package/dist/docs/troubleshooting.html +35 -35
- package/dist/filesystem.d.ts +10 -97
- package/dist/filesystem.d.ts.map +1 -1
- package/dist/filesystem.js +28 -290
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -2
- package/dist/internal/cli-deploy.d.ts.map +1 -1
- package/dist/internal/cli-deploy.js +12 -7
- package/dist/internal/continuation-channel.d.ts +3 -3
- package/dist/internal/continuation-channel.js +3 -3
- package/dist/internal/continuation-identity.d.ts +6 -5
- package/dist/internal/continuation-identity.d.ts.map +1 -1
- package/dist/internal/continuation-identity.js +17 -2
- package/dist/internal/direct-file-tools.d.ts +21 -0
- package/dist/internal/direct-file-tools.d.ts.map +1 -0
- package/dist/internal/direct-file-tools.js +60 -0
- package/dist/internal/discovery/agent.d.ts.map +1 -1
- package/dist/internal/discovery/agent.js +71 -66
- package/dist/internal/filesystem/walk.d.ts +4 -52
- package/dist/internal/filesystem/walk.d.ts.map +1 -1
- package/dist/internal/filesystem/walk.js +4 -190
- package/dist/internal/hosted-delivery-protocol.d.ts +3 -0
- package/dist/internal/hosted-delivery-protocol.d.ts.map +1 -1
- package/dist/internal/hosted-delivery-protocol.js +2 -0
- package/dist/internal/hosted-delivery.d.ts.map +1 -1
- package/dist/internal/hosted-delivery.js +25 -10
- package/dist/internal/hosted-execution-latency.d.ts +3 -0
- package/dist/internal/hosted-execution-latency.d.ts.map +1 -1
- package/dist/internal/hosted-execution-latency.js +11 -0
- package/dist/internal/hosted-managed-automation.js +1 -1
- package/dist/internal/otel/http.d.ts +2 -1
- package/dist/internal/otel/http.d.ts.map +1 -1
- package/dist/internal/otel/http.js +2 -3
- package/dist/internal/sdk-runner.d.ts +1 -1
- package/dist/internal/sdk-runner.d.ts.map +1 -1
- package/dist/internal/sdk-runner.js +28 -40
- package/dist/internal/server.d.ts.map +1 -1
- package/dist/internal/server.js +8 -4
- package/dist/internal/session-engine.d.ts +34 -19
- package/dist/internal/session-engine.d.ts.map +1 -1
- package/dist/internal/session-engine.js +196 -251
- package/dist/internal/tcp-address.d.ts +3 -1
- package/dist/internal/tcp-address.d.ts.map +1 -1
- package/dist/internal/tcp-address.js +6 -0
- package/dist/internal/tool-paths.d.ts +8 -0
- package/dist/internal/tool-paths.d.ts.map +1 -0
- package/dist/internal/tool-paths.js +12 -0
- package/dist/internal/workspace-tree.d.ts +27 -0
- package/dist/internal/workspace-tree.d.ts.map +1 -0
- package/dist/internal/workspace-tree.js +106 -0
- package/dist/playground/assets/index-CnFd5R1_.js +62 -0
- package/dist/playground/assets/index-DNzRv6G8.css +1 -0
- package/dist/playground/index.html +2 -2
- package/dist/types.d.ts +48 -23
- package/dist/types.d.ts.map +1 -1
- package/docs/changelog.md +47 -7
- package/docs/reference/agent-config.md +70 -4
- package/docs/reference/tools.md +12 -0
- package/package.json +9 -14
- package/skills/deploy/SKILL.md +1 -1
- package/dist/docs/assets/changelog.md.b6H_ea44.js +0 -1
- package/dist/docs/assets/changelog.md.b6H_ea44.lean.js +0 -1
- package/dist/docs/assets/chunks/@localSearchIndexroot.CiRGcfZg.js +0 -1
- package/dist/docs/assets/chunks/channel.CVTdqYx0.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-6PBFFD2Q.CsJJyx6-.js +0 -1
- package/dist/docs/assets/chunks/classDiagram-v2-HSJHXN6E.CsJJyx6-.js +0 -1
- package/dist/docs/assets/chunks/clone.Dk8KvtOB.js +0 -1
- package/dist/docs/assets/chunks/stateDiagram-v2-QKLJ7IA2.DE0BnUZh.js +0 -1
- package/dist/executors.d.ts +0 -11
- package/dist/executors.d.ts.map +0 -1
- package/dist/executors.js +0 -21
- package/dist/internal/filesystem/format.d.ts +0 -28
- package/dist/internal/filesystem/format.d.ts.map +0 -1
- package/dist/internal/filesystem/format.js +0 -209
- package/dist/internal/filesystem/nearest.d.ts +0 -15
- package/dist/internal/filesystem/nearest.d.ts.map +0 -1
- package/dist/internal/filesystem/nearest.js +0 -90
- package/dist/internal/filesystem/scratch.d.ts +0 -60
- package/dist/internal/filesystem/scratch.d.ts.map +0 -1
- package/dist/internal/filesystem/scratch.js +0 -187
- package/dist/internal/filesystem/sdk-schemas.d.ts +0 -29
- package/dist/internal/filesystem/sdk-schemas.d.ts.map +0 -1
- package/dist/internal/filesystem/sdk-schemas.js +0 -148
- package/dist/internal/filesystem/subagent-inherit.d.ts +0 -39
- package/dist/internal/filesystem/subagent-inherit.d.ts.map +0 -1
- package/dist/internal/filesystem/subagent-inherit.js +0 -96
- package/dist/internal/filesystem/tools.d.ts +0 -59
- package/dist/internal/filesystem/tools.d.ts.map +0 -1
- package/dist/internal/filesystem/tools.js +0 -634
- package/dist/internal/otel/propagation.d.ts +0 -7
- package/dist/internal/otel/propagation.d.ts.map +0 -1
- package/dist/internal/otel/propagation.js +0 -15
- package/dist/internal/sdk-subagent-inherit-support.d.ts +0 -9
- package/dist/internal/sdk-subagent-inherit-support.d.ts.map +0 -1
- package/dist/internal/sdk-subagent-inherit-support.js +0 -90
- package/dist/playground/assets/index-Bno25Cg0.css +0 -1
- package/dist/playground/assets/index-SGKsaznh.js +0 -62
- /package/dist/docs/assets/{reference_schedules.md.Dd8_d0WG.lean.js → reference_schedules.md.RhQ9ZLo1.lean.js} +0 -0
|
@@ -1,634 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Native file tools synthesized from a bound {@link FileSystem}.
|
|
3
|
-
*
|
|
4
|
-
* Advertised name / input / output match `@cursor/sdk` tool-call types.
|
|
5
|
-
* Each tool is a `defineTool` whose runtime `inputSchema` accepts those
|
|
6
|
-
* fields plus the native aliases the harness still sends.
|
|
7
|
-
*/
|
|
8
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
9
|
-
import { Buffer } from "node:buffer";
|
|
10
|
-
import { minimatch } from "minimatch";
|
|
11
|
-
import * as z from "zod/v4";
|
|
12
|
-
import { isRecord } from "../is-record.js";
|
|
13
|
-
import { canonicalizeFileSystemToolName, collectGrepMatches, FILE_SYSTEM_SCAN_LIMIT, fileSystemImage, fileSystemText, InvalidGrepPatternError, isFileNotFoundError, shapeGrepUnion, sliceReadContent, strReplaceOnFileSystem, } from "../../filesystem.js";
|
|
14
|
-
import { defineTool } from "../../tools.js";
|
|
15
|
-
import { toolInputJsonSchema, toolOutputJsonSchema, validateToolInput } from "../json-schema.js";
|
|
16
|
-
import { formatGlobOutput, formatGrepOutput, formatLsTree, formatNumberedLines, formatStrReplaceOutput, formatWriteOutput, slicedReadStartLine, } from "./format.js";
|
|
17
|
-
import { nearestNeighborMissHint } from "./nearest.js";
|
|
18
|
-
import { sdkDeleteArgs, sdkDeleteResult, sdkEditResult, sdkGlobArgs, sdkGlobResult, sdkGrepArgs, sdkGrepResult, sdkLsArgs, sdkLsResult, sdkReadArgs, sdkReadResult, sdkStrReplaceArgs, sdkWriteArgs, sdkWriteResult, } from "./sdk-schemas.js";
|
|
19
|
-
import { collectGlob, collectListOrStat, lsFromList } from "./walk.js";
|
|
20
|
-
export const SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES = [
|
|
21
|
-
"Read",
|
|
22
|
-
"LS",
|
|
23
|
-
"Glob",
|
|
24
|
-
"Grep",
|
|
25
|
-
"Write",
|
|
26
|
-
"StrReplace",
|
|
27
|
-
"Delete",
|
|
28
|
-
];
|
|
29
|
-
const SYNTHESIZED_NAME_SET = new Set(SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES);
|
|
30
|
-
export function isSynthesizedFileSystemToolName(name) {
|
|
31
|
-
if (SYNTHESIZED_NAME_SET.has(name)) {
|
|
32
|
-
return true;
|
|
33
|
-
}
|
|
34
|
-
const canonical = canonicalizeFileSystemToolName(name);
|
|
35
|
-
return canonical !== undefined && SYNTHESIZED_NAME_SET.has(canonical);
|
|
36
|
-
}
|
|
37
|
-
export function rootFileToolsFromAuthored(tools) {
|
|
38
|
-
if (tools === undefined) {
|
|
39
|
-
return undefined;
|
|
40
|
-
}
|
|
41
|
-
if (tools.length === 0) {
|
|
42
|
-
return [];
|
|
43
|
-
}
|
|
44
|
-
const files = [];
|
|
45
|
-
for (const name of tools) {
|
|
46
|
-
if (name === "edit") {
|
|
47
|
-
files.push("Write", "StrReplace");
|
|
48
|
-
continue;
|
|
49
|
-
}
|
|
50
|
-
const canonical = canonicalizeFileSystemToolName(name);
|
|
51
|
-
if (canonical !== undefined) {
|
|
52
|
-
files.push(canonical);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return files.length === 0 ? undefined : [...new Set(files)];
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Host-default file-tool filter. Omitted `tools` keeps the default
|
|
59
|
-
* seven-tool set (`undefined`). A listed allowlist is closed: names that
|
|
60
|
-
* are not FileSystem methods synthesize nothing, so agents that already
|
|
61
|
-
* replaced natives with authored VFS tools (`tools: ["updateTodos"]` plus
|
|
62
|
-
* `agent/tools/Delete.ts`) do not also get host-disk Delete.
|
|
63
|
-
*
|
|
64
|
-
* Authored `root` still uses {@link rootFileToolsFromAuthored}, where a
|
|
65
|
-
* no-file-name allowlist means the default-on file layer.
|
|
66
|
-
*/
|
|
67
|
-
export function hostFileToolsFromAuthored(tools) {
|
|
68
|
-
if (tools === undefined) {
|
|
69
|
-
return undefined;
|
|
70
|
-
}
|
|
71
|
-
return rootFileToolsFromAuthored(tools) ?? [];
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Names July will actually synthesize for this agent. Discovery reserves
|
|
75
|
-
* only this set, not every FileSystem alias.
|
|
76
|
-
*/
|
|
77
|
-
export function synthesizedFileSystemToolNames(options) {
|
|
78
|
-
const filter = options.hasRoot
|
|
79
|
-
? rootFileToolsFromAuthored(options.tools)
|
|
80
|
-
: hostFileToolsFromAuthored(options.tools);
|
|
81
|
-
if (filter === undefined) {
|
|
82
|
-
return SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES;
|
|
83
|
-
}
|
|
84
|
-
return SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES.filter((name) => filter.includes(name));
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
87
|
-
* Canonical tool a name and payload will run. Legacy `edit` with
|
|
88
|
-
* `fileText` or `contents` is Write. Every other `edit` payload is StrReplace.
|
|
89
|
-
*/
|
|
90
|
-
export function resolvedFileSystemToolName(name, input = {}) {
|
|
91
|
-
if (name === "edit") {
|
|
92
|
-
return "fileText" in input || "contents" in input ? "Write" : "StrReplace";
|
|
93
|
-
}
|
|
94
|
-
return canonicalizeFileSystemToolName(name);
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* True when a direct call may run this file-tool alias. The set is the
|
|
98
|
-
* same one a turn synthesizes from `tools`.
|
|
99
|
-
*/
|
|
100
|
-
export function isDirectFileToolAdmitted(options) {
|
|
101
|
-
const args = isRecord(options.input) ? options.input : {};
|
|
102
|
-
const canonical = resolvedFileSystemToolName(options.toolName, args);
|
|
103
|
-
if (canonical === undefined) {
|
|
104
|
-
return false;
|
|
105
|
-
}
|
|
106
|
-
return synthesizedFileSystemToolNames({
|
|
107
|
-
hasRoot: options.hasRoot,
|
|
108
|
-
tools: options.tools,
|
|
109
|
-
}).includes(canonical);
|
|
110
|
-
}
|
|
111
|
-
function wantsTool(filter, name) {
|
|
112
|
-
return filter === undefined || filter.includes(name);
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Copy native aliases onto the canonical SDK field when the canonical
|
|
116
|
-
* field is absent. Zod sees the SDK shape; callers can still send
|
|
117
|
-
* `contents` / `old_string` / `output_mode`.
|
|
118
|
-
*/
|
|
119
|
-
function aliasKeys(aliases) {
|
|
120
|
-
return (raw) => {
|
|
121
|
-
if (!isRecord(raw)) {
|
|
122
|
-
return raw;
|
|
123
|
-
}
|
|
124
|
-
const input = { ...raw };
|
|
125
|
-
for (const [from, to] of Object.entries(aliases)) {
|
|
126
|
-
if (input[to] === undefined && input[from] !== undefined) {
|
|
127
|
-
input[to] = input[from];
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return input;
|
|
131
|
-
};
|
|
132
|
-
}
|
|
133
|
-
function lineCount(content) {
|
|
134
|
-
return content === "" ? 0 : content.split("\n").length;
|
|
135
|
-
}
|
|
136
|
-
function parseGrepOutputMode(value) {
|
|
137
|
-
if (value === "files" || value === "files_with_matches") {
|
|
138
|
-
return "files_with_matches";
|
|
139
|
-
}
|
|
140
|
-
if (value === "count") {
|
|
141
|
-
return "count";
|
|
142
|
-
}
|
|
143
|
-
return "content";
|
|
144
|
-
}
|
|
145
|
-
function contextLineCount(specific, both) {
|
|
146
|
-
const value = specific ?? both;
|
|
147
|
-
if (value === undefined || !Number.isFinite(value)) {
|
|
148
|
-
return 0;
|
|
149
|
-
}
|
|
150
|
-
return Math.max(0, Math.floor(value));
|
|
151
|
-
}
|
|
152
|
-
function compileToolGrepPattern(pattern, options) {
|
|
153
|
-
try {
|
|
154
|
-
const flags = `${options.caseInsensitive === true ? "i" : ""}${options.multiline === true ? "s" : ""}`;
|
|
155
|
-
return new RegExp(pattern, flags === "" ? undefined : flags);
|
|
156
|
-
}
|
|
157
|
-
catch {
|
|
158
|
-
throw new InvalidGrepPatternError(pattern);
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* File discovery for multiline Grep. A file `path` is that file (the
|
|
163
|
-
* caller spelling, so host-default relative paths stay relative). A
|
|
164
|
-
* directory or omitted path uses `FileSystem.glob`, which applies the
|
|
165
|
-
* mount's own root. Slash-free globs are recursive, matching line grep.
|
|
166
|
-
*/
|
|
167
|
-
async function collectMultilineGrepFiles(root, input) {
|
|
168
|
-
const listed = await collectListOrStat(root, input.path);
|
|
169
|
-
if (listed.kind === "file") {
|
|
170
|
-
const filePath = input.path ?? "";
|
|
171
|
-
if (input.glob !== undefined && !fileMatchesGrepGlob(filePath, input.glob)) {
|
|
172
|
-
return [];
|
|
173
|
-
}
|
|
174
|
-
return [filePath];
|
|
175
|
-
}
|
|
176
|
-
if (listed.kind === "missing") {
|
|
177
|
-
return [];
|
|
178
|
-
}
|
|
179
|
-
const entries = await collectGlob(root, {
|
|
180
|
-
pattern: recursiveGrepGlob(input.glob),
|
|
181
|
-
...(input.path === undefined ? {} : { dir: input.path }),
|
|
182
|
-
});
|
|
183
|
-
return entries.map((entry) => entry.path);
|
|
184
|
-
}
|
|
185
|
-
function recursiveGrepGlob(glob) {
|
|
186
|
-
if (glob === undefined || glob.length === 0) {
|
|
187
|
-
return "**/*";
|
|
188
|
-
}
|
|
189
|
-
if (glob.startsWith("**/") || glob.includes("/")) {
|
|
190
|
-
return glob;
|
|
191
|
-
}
|
|
192
|
-
return `**/${glob}`;
|
|
193
|
-
}
|
|
194
|
-
function fileMatchesGrepGlob(filePath, globPattern) {
|
|
195
|
-
const relative = filePath.replace(/^\//, "");
|
|
196
|
-
if (minimatch(relative, globPattern, { dot: true }) ||
|
|
197
|
-
minimatch(filePath, globPattern, { dot: true })) {
|
|
198
|
-
return true;
|
|
199
|
-
}
|
|
200
|
-
if (!globPattern.includes("/")) {
|
|
201
|
-
const slash = Math.max(relative.lastIndexOf("/"), relative.lastIndexOf("\\"));
|
|
202
|
-
const base = slash === -1 ? relative : relative.slice(slash + 1);
|
|
203
|
-
return minimatch(base, globPattern, { dot: true });
|
|
204
|
-
}
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
function multilineHitsInContent(path, content, regex) {
|
|
208
|
-
const global = new RegExp(regex.source, regex.flags.includes("g") ? regex.flags : `${regex.flags}g`);
|
|
209
|
-
const hits = [];
|
|
210
|
-
let match = global.exec(content);
|
|
211
|
-
while (match !== null) {
|
|
212
|
-
hits.push({
|
|
213
|
-
path,
|
|
214
|
-
lineNumber: content.slice(0, match.index).split("\n").length,
|
|
215
|
-
line: content.slice(match.index).split("\n")[0] ?? "",
|
|
216
|
-
});
|
|
217
|
-
if (match[0].length === 0) {
|
|
218
|
-
global.lastIndex += 1;
|
|
219
|
-
}
|
|
220
|
-
match = global.exec(content);
|
|
221
|
-
}
|
|
222
|
-
return hits;
|
|
223
|
-
}
|
|
224
|
-
async function collectMultilineGrepMatches(root, input, opts) {
|
|
225
|
-
const regex = compileToolGrepPattern(input.pattern, {
|
|
226
|
-
caseInsensitive: input.caseInsensitive,
|
|
227
|
-
multiline: true,
|
|
228
|
-
});
|
|
229
|
-
const files = await collectMultilineGrepFiles(root, input);
|
|
230
|
-
const matches = [];
|
|
231
|
-
const offset = opts.offset !== undefined && opts.offset > 0 ? opts.offset : 0;
|
|
232
|
-
const headLimit = opts.headLimit !== undefined && opts.headLimit > 0 ? opts.headLimit : undefined;
|
|
233
|
-
let skippedItems = 0;
|
|
234
|
-
let takenItems = 0;
|
|
235
|
-
for (const filePath of files) {
|
|
236
|
-
let content;
|
|
237
|
-
try {
|
|
238
|
-
content = await root.read(filePath);
|
|
239
|
-
}
|
|
240
|
-
catch {
|
|
241
|
-
continue;
|
|
242
|
-
}
|
|
243
|
-
if (typeof content !== "string") {
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
const hits = multilineHitsInContent(filePath, content, regex);
|
|
247
|
-
if (hits.length === 0) {
|
|
248
|
-
continue;
|
|
249
|
-
}
|
|
250
|
-
if (opts.outputMode === "content") {
|
|
251
|
-
for (const hit of hits) {
|
|
252
|
-
if (skippedItems < offset) {
|
|
253
|
-
skippedItems++;
|
|
254
|
-
continue;
|
|
255
|
-
}
|
|
256
|
-
matches.push(hit);
|
|
257
|
-
takenItems++;
|
|
258
|
-
if (headLimit !== undefined && takenItems >= headLimit) {
|
|
259
|
-
return matches;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
continue;
|
|
263
|
-
}
|
|
264
|
-
if (skippedItems < offset) {
|
|
265
|
-
skippedItems++;
|
|
266
|
-
continue;
|
|
267
|
-
}
|
|
268
|
-
if (headLimit !== undefined && takenItems >= headLimit) {
|
|
269
|
-
break;
|
|
270
|
-
}
|
|
271
|
-
matches.push(...hits);
|
|
272
|
-
takenItems++;
|
|
273
|
-
}
|
|
274
|
-
return matches;
|
|
275
|
-
}
|
|
276
|
-
async function attachGrepContext(root, matches, context) {
|
|
277
|
-
if (context.before === 0 && context.after === 0) {
|
|
278
|
-
return matches;
|
|
279
|
-
}
|
|
280
|
-
const linesByPath = new Map();
|
|
281
|
-
const hits = [];
|
|
282
|
-
for (const match of matches) {
|
|
283
|
-
let lines = linesByPath.get(match.path);
|
|
284
|
-
if (lines === undefined) {
|
|
285
|
-
try {
|
|
286
|
-
const content = await root.read(match.path);
|
|
287
|
-
lines = typeof content === "string" ? content.split("\n") : [];
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
lines = [];
|
|
291
|
-
}
|
|
292
|
-
linesByPath.set(match.path, lines);
|
|
293
|
-
}
|
|
294
|
-
const index = match.lineNumber - 1;
|
|
295
|
-
hits.push({
|
|
296
|
-
...match,
|
|
297
|
-
...(context.before > 0
|
|
298
|
-
? {
|
|
299
|
-
beforeContext: lines.slice(Math.max(0, index - context.before), Math.max(0, index)),
|
|
300
|
-
}
|
|
301
|
-
: {}),
|
|
302
|
-
...(context.after > 0
|
|
303
|
-
? { afterContext: lines.slice(index + 1, index + 1 + context.after) }
|
|
304
|
-
: {}),
|
|
305
|
-
});
|
|
306
|
-
}
|
|
307
|
-
return hits;
|
|
308
|
-
}
|
|
309
|
-
function discovered(name, definition, contract) {
|
|
310
|
-
const effect = typeof definition.effect === "function" ? "dynamic" : definition.effect;
|
|
311
|
-
return {
|
|
312
|
-
name,
|
|
313
|
-
description: definition.description,
|
|
314
|
-
inputSchema: toolInputJsonSchema(contract.input),
|
|
315
|
-
outputSchema: toolOutputJsonSchema(contract.output),
|
|
316
|
-
execution: "server",
|
|
317
|
-
needsApproval: false,
|
|
318
|
-
...(effect === undefined ? {} : { effect }),
|
|
319
|
-
definition,
|
|
320
|
-
};
|
|
321
|
-
}
|
|
322
|
-
const readInputSchema = z.preprocess(aliasKeys({}), z.object({
|
|
323
|
-
path: z.string(),
|
|
324
|
-
offset: z.number().int().optional(),
|
|
325
|
-
limit: z.number().int().optional(),
|
|
326
|
-
}));
|
|
327
|
-
function readTool(root) {
|
|
328
|
-
return discovered("Read", defineTool({
|
|
329
|
-
description: "Reads a file from the local filesystem. This tool can also read image files when called with the appropriate path. Formats supported: jpeg/jpg, png, gif, webp.",
|
|
330
|
-
inputSchema: readInputSchema,
|
|
331
|
-
effect: "read",
|
|
332
|
-
async execute({ path, offset, limit }) {
|
|
333
|
-
let content;
|
|
334
|
-
try {
|
|
335
|
-
content = await root.read(path);
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
if (isFileNotFoundError(error)) {
|
|
339
|
-
const hint = await nearestNeighborMissHint(root, path);
|
|
340
|
-
if (hint !== undefined) {
|
|
341
|
-
return hint;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
throw error;
|
|
345
|
-
}
|
|
346
|
-
const image = fileSystemImage(content, path);
|
|
347
|
-
if (image !== undefined) {
|
|
348
|
-
return {
|
|
349
|
-
content: [
|
|
350
|
-
{ type: "text", text: `Read image file: ${path}` },
|
|
351
|
-
{
|
|
352
|
-
type: "image",
|
|
353
|
-
data: Buffer.from(image.bytes).toString("base64"),
|
|
354
|
-
mimeType: image.mimeType,
|
|
355
|
-
},
|
|
356
|
-
],
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
const text = fileSystemText(content);
|
|
360
|
-
const totalLines = lineCount(text);
|
|
361
|
-
return formatNumberedLines(sliceReadContent(text, offset, limit), {
|
|
362
|
-
startLine: slicedReadStartLine(totalLines, offset),
|
|
363
|
-
totalLines,
|
|
364
|
-
});
|
|
365
|
-
},
|
|
366
|
-
}), { input: sdkReadArgs, output: sdkReadResult });
|
|
367
|
-
}
|
|
368
|
-
const lsInputSchema = z.preprocess(aliasKeys({ target_directory: "path", ignore_globs: "ignore" }), z.object({
|
|
369
|
-
path: z.string(),
|
|
370
|
-
ignore: z.array(z.string()).optional(),
|
|
371
|
-
}));
|
|
372
|
-
function lsTool(root) {
|
|
373
|
-
return discovered("LS", defineTool({
|
|
374
|
-
description: `Lists files and directories in a given path.
|
|
375
|
-
The 'path' parameter must be an absolute path.
|
|
376
|
-
You can optionally provide an array of glob patterns to ignore with the "ignore" parameter.
|
|
377
|
-
|
|
378
|
-
Other details:
|
|
379
|
-
- The result does not display dot-files and dot-directories.`,
|
|
380
|
-
inputSchema: lsInputSchema,
|
|
381
|
-
effect: "read",
|
|
382
|
-
async execute({ path, ignore }) {
|
|
383
|
-
const listed = await lsFromList(root, path, ignore);
|
|
384
|
-
if (listed.status === "error") {
|
|
385
|
-
if (listed.error.message.startsWith("Path is not a directory:")) {
|
|
386
|
-
return `not a directory: ${path} — Read it.`;
|
|
387
|
-
}
|
|
388
|
-
if (listed.error.message.startsWith("Path does not exist:")) {
|
|
389
|
-
const hint = await nearestNeighborMissHint(root, path);
|
|
390
|
-
if (hint !== undefined) {
|
|
391
|
-
return hint;
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
throw new Error(`Error listing directory: ${listed.error.message}`);
|
|
395
|
-
}
|
|
396
|
-
return formatLsTree(listed.value.directoryTreeRoot);
|
|
397
|
-
},
|
|
398
|
-
}), { input: sdkLsArgs, output: sdkLsResult });
|
|
399
|
-
}
|
|
400
|
-
const globInputSchema = z.preprocess(aliasKeys({
|
|
401
|
-
glob_pattern: "globPattern",
|
|
402
|
-
target_directory: "targetDirectory",
|
|
403
|
-
path: "targetDirectory",
|
|
404
|
-
}), z.object({
|
|
405
|
-
targetDirectory: z.string().optional(),
|
|
406
|
-
globPattern: z.string(),
|
|
407
|
-
}));
|
|
408
|
-
function globTool(root) {
|
|
409
|
-
return discovered("Glob", defineTool({
|
|
410
|
-
description: `
|
|
411
|
-
Tool to search for files matching a glob pattern
|
|
412
|
-
|
|
413
|
-
- Works fast with codebases of any size
|
|
414
|
-
- Returns matching file paths sorted by modification time
|
|
415
|
-
- Use this tool when you need to find files by name patterns
|
|
416
|
-
- You have the capability to call multiple tools in a single response. It is always better to speculatively perform multiple searches that are potentially useful as a batch.
|
|
417
|
-
`,
|
|
418
|
-
inputSchema: globInputSchema,
|
|
419
|
-
effect: "read",
|
|
420
|
-
async execute({ globPattern, targetDirectory }) {
|
|
421
|
-
const dir = targetDirectory ?? "/";
|
|
422
|
-
const files = (await collectGlob(root, {
|
|
423
|
-
pattern: globPattern,
|
|
424
|
-
...(targetDirectory === undefined ? {} : { dir: targetDirectory }),
|
|
425
|
-
limit: FILE_SYSTEM_SCAN_LIMIT,
|
|
426
|
-
})).map((entry) => entry.path);
|
|
427
|
-
return formatGlobOutput(dir, files);
|
|
428
|
-
},
|
|
429
|
-
}), { input: sdkGlobArgs, output: sdkGlobResult });
|
|
430
|
-
}
|
|
431
|
-
const grepInputSchema = z.preprocess((raw) => {
|
|
432
|
-
const aliased = aliasKeys({
|
|
433
|
-
output_mode: "outputMode",
|
|
434
|
-
head_limit: "headLimit",
|
|
435
|
-
"-i": "caseInsensitive",
|
|
436
|
-
"-A": "contextAfter",
|
|
437
|
-
"-B": "contextBefore",
|
|
438
|
-
"-C": "context",
|
|
439
|
-
})(raw);
|
|
440
|
-
if (aliased !== null && typeof aliased === "object" && !Array.isArray(aliased)) {
|
|
441
|
-
const input = aliased;
|
|
442
|
-
if (input.outputMode === "files") {
|
|
443
|
-
input.outputMode = "files_with_matches";
|
|
444
|
-
}
|
|
445
|
-
}
|
|
446
|
-
return aliased;
|
|
447
|
-
}, z.object({
|
|
448
|
-
pattern: z.string(),
|
|
449
|
-
path: z.string().optional(),
|
|
450
|
-
glob: z.string().optional(),
|
|
451
|
-
outputMode: z.string().optional(),
|
|
452
|
-
contextBefore: z.number().optional(),
|
|
453
|
-
contextAfter: z.number().optional(),
|
|
454
|
-
context: z.number().optional(),
|
|
455
|
-
caseInsensitive: z.boolean().optional(),
|
|
456
|
-
type: z.string().optional(),
|
|
457
|
-
headLimit: z.number().optional(),
|
|
458
|
-
offset: z.number().optional(),
|
|
459
|
-
multiline: z.boolean().optional(),
|
|
460
|
-
sort: z.string().optional(),
|
|
461
|
-
sortAscending: z.boolean().optional(),
|
|
462
|
-
}));
|
|
463
|
-
function grepTool(root) {
|
|
464
|
-
return discovered("Grep", defineTool({
|
|
465
|
-
description: `A search tool built on ripgrep. Results are capped to several thousand output lines for responsiveness; when truncation occurs, the results report "at least" counts, but are otherwise accurate.`,
|
|
466
|
-
inputSchema: grepInputSchema,
|
|
467
|
-
effect: "read",
|
|
468
|
-
async execute(input) {
|
|
469
|
-
const outputMode = parseGrepOutputMode(input.outputMode);
|
|
470
|
-
const query = {
|
|
471
|
-
pattern: input.pattern,
|
|
472
|
-
...(input.path === undefined ? {} : { path: input.path }),
|
|
473
|
-
...(input.glob === undefined ? {} : { glob: input.glob }),
|
|
474
|
-
caseInsensitive: input.caseInsensitive === true,
|
|
475
|
-
};
|
|
476
|
-
const page = {
|
|
477
|
-
outputMode,
|
|
478
|
-
...(input.headLimit === undefined ? {} : { headLimit: input.headLimit }),
|
|
479
|
-
...(input.offset === undefined ? {} : { offset: input.offset }),
|
|
480
|
-
};
|
|
481
|
-
const matches = input.multiline === true
|
|
482
|
-
? await collectMultilineGrepMatches(root, query, page)
|
|
483
|
-
: await collectGrepMatches(root, query, page);
|
|
484
|
-
const before = contextLineCount(input.contextBefore, input.context);
|
|
485
|
-
const after = contextLineCount(input.contextAfter, input.context);
|
|
486
|
-
const hits = outputMode === "content"
|
|
487
|
-
? await attachGrepContext(root, matches, { before, after })
|
|
488
|
-
: matches;
|
|
489
|
-
return formatGrepOutput(shapeGrepUnion(hits, outputMode));
|
|
490
|
-
},
|
|
491
|
-
}), { input: sdkGrepArgs, output: sdkGrepResult });
|
|
492
|
-
}
|
|
493
|
-
const writeInputSchema = z.preprocess(aliasKeys({ contents: "fileText" }), z.object({
|
|
494
|
-
path: z.string(),
|
|
495
|
-
fileText: z.string(),
|
|
496
|
-
returnFileContentAfterWrite: z.boolean().optional(),
|
|
497
|
-
}));
|
|
498
|
-
function writeTool(root) {
|
|
499
|
-
return discovered("Write", defineTool({
|
|
500
|
-
description: "Writes a file to the local filesystem.",
|
|
501
|
-
inputSchema: writeInputSchema,
|
|
502
|
-
effect: "write",
|
|
503
|
-
async execute({ path, fileText }) {
|
|
504
|
-
await root.write(path, fileText);
|
|
505
|
-
return formatWriteOutput(path);
|
|
506
|
-
},
|
|
507
|
-
}), { input: sdkWriteArgs, output: sdkWriteResult });
|
|
508
|
-
}
|
|
509
|
-
const strReplaceInputSchema = z.preprocess(aliasKeys({
|
|
510
|
-
old_string: "oldText",
|
|
511
|
-
new_string: "newText",
|
|
512
|
-
replace_all: "replaceAll",
|
|
513
|
-
}), z.object({
|
|
514
|
-
path: z.string(),
|
|
515
|
-
oldText: z.string(),
|
|
516
|
-
newText: z.string(),
|
|
517
|
-
replaceAll: z.boolean().optional(),
|
|
518
|
-
}));
|
|
519
|
-
function strReplaceTool(root) {
|
|
520
|
-
return discovered("StrReplace", defineTool({
|
|
521
|
-
description: "Performs exact string replacements in files.",
|
|
522
|
-
inputSchema: strReplaceInputSchema,
|
|
523
|
-
effect: "write",
|
|
524
|
-
async execute({ path, oldText, newText, replaceAll }) {
|
|
525
|
-
const { occurrencesModified } = await strReplaceOnFileSystem(root, {
|
|
526
|
-
path,
|
|
527
|
-
oldText,
|
|
528
|
-
newText,
|
|
529
|
-
...(replaceAll === undefined ? {} : { replaceAll }),
|
|
530
|
-
});
|
|
531
|
-
return formatStrReplaceOutput({
|
|
532
|
-
path,
|
|
533
|
-
replaceAll: replaceAll === true,
|
|
534
|
-
occurrencesModified,
|
|
535
|
-
});
|
|
536
|
-
},
|
|
537
|
-
}), { input: sdkStrReplaceArgs, output: sdkEditResult });
|
|
538
|
-
}
|
|
539
|
-
const deleteInputSchema = z.object({
|
|
540
|
-
path: z.string(),
|
|
541
|
-
});
|
|
542
|
-
function deleteTool(root) {
|
|
543
|
-
return discovered("Delete", defineTool({
|
|
544
|
-
description: `Deletes a file at the specified path. The operation will fail gracefully if:
|
|
545
|
-
- The file doesn't exist
|
|
546
|
-
- The operation is rejected for security reasons
|
|
547
|
-
- The file cannot be deleted`,
|
|
548
|
-
inputSchema: deleteInputSchema,
|
|
549
|
-
effect: "write",
|
|
550
|
-
async execute({ path }) {
|
|
551
|
-
await root.delete(path);
|
|
552
|
-
return "";
|
|
553
|
-
},
|
|
554
|
-
}), { input: sdkDeleteArgs, output: sdkDeleteResult });
|
|
555
|
-
}
|
|
556
|
-
const FILE_SYSTEM_TOOL_FACTORIES = {
|
|
557
|
-
Read: readTool,
|
|
558
|
-
LS: lsTool,
|
|
559
|
-
Glob: globTool,
|
|
560
|
-
Grep: grepTool,
|
|
561
|
-
Write: writeTool,
|
|
562
|
-
StrReplace: strReplaceTool,
|
|
563
|
-
Delete: deleteTool,
|
|
564
|
-
};
|
|
565
|
-
/** Look up the `defineTool` factory for a native or allowlist name. */
|
|
566
|
-
export function fileSystemTool(root, name, input = {}) {
|
|
567
|
-
const canonical = resolvedFileSystemToolName(name, input);
|
|
568
|
-
if (canonical === undefined) {
|
|
569
|
-
return undefined;
|
|
570
|
-
}
|
|
571
|
-
return FILE_SYSTEM_TOOL_FACTORIES[canonical](root);
|
|
572
|
-
}
|
|
573
|
-
/** Validate and run the same tool a turn or `callTool` would. */
|
|
574
|
-
export async function runFileSystemTool(root, name, input = {}) {
|
|
575
|
-
const tool = fileSystemTool(root, name, input);
|
|
576
|
-
if (tool === undefined) {
|
|
577
|
-
throw new Error(`Unknown file system tool: ${name}`);
|
|
578
|
-
}
|
|
579
|
-
const execute = tool.definition.execute;
|
|
580
|
-
if (typeof execute !== "function") {
|
|
581
|
-
throw new Error(`File system tool ${name} has no execute`);
|
|
582
|
-
}
|
|
583
|
-
const validation = validateToolInput(tool.definition.inputSchema, input);
|
|
584
|
-
if (!validation.ok) {
|
|
585
|
-
throw new Error(validation.message);
|
|
586
|
-
}
|
|
587
|
-
// oxlint-disable-next-line typescript/no-unsafe-type-assertion -- FileSystem execute erases its input and context to never
|
|
588
|
-
return execute(validation.value, {});
|
|
589
|
-
}
|
|
590
|
-
const fileSystemStorage = new AsyncLocalStorage();
|
|
591
|
-
/**
|
|
592
|
-
* Run `fn` with synthesized file tools bound to `root`. Task children use
|
|
593
|
-
* this so Read/Write/Delete hit their overlay instead of the parent tree
|
|
594
|
-
* the tools were built against.
|
|
595
|
-
*/
|
|
596
|
-
export function runWithFileSystem(root, fn) {
|
|
597
|
-
return fileSystemStorage.run(root, fn);
|
|
598
|
-
}
|
|
599
|
-
function bindActiveFileSystem(root, tool) {
|
|
600
|
-
const execute = tool.definition.execute;
|
|
601
|
-
if (execute === undefined) {
|
|
602
|
-
return tool;
|
|
603
|
-
}
|
|
604
|
-
return {
|
|
605
|
-
...tool,
|
|
606
|
-
definition: {
|
|
607
|
-
...tool.definition,
|
|
608
|
-
execute: (input, ctx) => {
|
|
609
|
-
const active = fileSystemStorage.getStore();
|
|
610
|
-
if (active === undefined || active === root) {
|
|
611
|
-
return execute(input, ctx);
|
|
612
|
-
}
|
|
613
|
-
const canonical = canonicalizeFileSystemToolName(tool.name);
|
|
614
|
-
if (canonical === undefined) {
|
|
615
|
-
return execute(input, ctx);
|
|
616
|
-
}
|
|
617
|
-
const reboundExecute = FILE_SYSTEM_TOOL_FACTORIES[canonical](active).definition.execute;
|
|
618
|
-
if (reboundExecute === undefined) {
|
|
619
|
-
return execute(input, ctx);
|
|
620
|
-
}
|
|
621
|
-
return reboundExecute(input, ctx);
|
|
622
|
-
},
|
|
623
|
-
},
|
|
624
|
-
};
|
|
625
|
-
}
|
|
626
|
-
export function synthesizeFileSystemTools(root, filter) {
|
|
627
|
-
const tools = [];
|
|
628
|
-
for (const name of SYNTHESIZED_FILE_SYSTEM_TOOL_NAMES) {
|
|
629
|
-
if (wantsTool(filter, name)) {
|
|
630
|
-
tools.push(bindActiveFileSystem(root, FILE_SYSTEM_TOOL_FACTORIES[name](root)));
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
return tools;
|
|
634
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process-global W3C `traceparent` propagator. Inbound HTTP extracts
|
|
3
|
-
* trace context only. BDK does not read or write the `baggage` header.
|
|
4
|
-
* Turn tags stay in this process.
|
|
5
|
-
*/
|
|
6
|
-
export declare function ensureW3cPropagator(): void;
|
|
7
|
-
//# sourceMappingURL=propagation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"propagation.d.ts","sourceRoot":"","sources":["../../../src/internal/otel/propagation.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAOH,wBAAgB,mBAAmB,IAAI,IAAI,CAM1C"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Process-global W3C `traceparent` propagator. Inbound HTTP extracts
|
|
3
|
-
* trace context only. BDK does not read or write the `baggage` header.
|
|
4
|
-
* Turn tags stay in this process.
|
|
5
|
-
*/
|
|
6
|
-
import { propagation } from "@opentelemetry/api";
|
|
7
|
-
import { W3CTraceContextPropagator } from "@opentelemetry/core";
|
|
8
|
-
let installed = false;
|
|
9
|
-
export function ensureW3cPropagator() {
|
|
10
|
-
if (installed) {
|
|
11
|
-
return;
|
|
12
|
-
}
|
|
13
|
-
propagation.setGlobalPropagator(new W3CTraceContextPropagator());
|
|
14
|
-
installed = true;
|
|
15
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Whether the installed Cursor SDK applies `local.subagentInherit` on
|
|
3
|
-
* Task children. Without that, a virtual-root allowlist must not offer
|
|
4
|
-
* `task`: the child would use the host workspace.
|
|
5
|
-
*/
|
|
6
|
-
export declare function installedSdkAppliesSubagentInherit(): boolean;
|
|
7
|
-
/** True when the SDK package that owns `entry` contains the inherit marker. */
|
|
8
|
-
export declare function sdkPackageAppliesSubagentInherit(entry: string): boolean;
|
|
9
|
-
//# sourceMappingURL=sdk-subagent-inherit-support.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"sdk-subagent-inherit-support.d.ts","sourceRoot":"","sources":["../../src/internal/sdk-subagent-inherit-support.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,wBAAgB,kCAAkC,IAAI,OAAO,CAW5D;AAED,+EAA+E;AAC/E,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAEvE"}
|