@empiricalrun/test-gen 0.71.2 → 0.73.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/CHANGELOG.md +57 -0
- package/dist/agent/chat/agent-loop.d.ts +11 -9
- package/dist/agent/chat/agent-loop.d.ts.map +1 -1
- package/dist/agent/chat/agent-loop.js +20 -10
- package/dist/agent/chat/exports.d.ts +2 -2
- package/dist/agent/chat/exports.d.ts.map +1 -1
- package/dist/agent/chat/exports.js +6 -1
- package/dist/agent/chat/index.d.ts.map +1 -1
- package/dist/agent/chat/index.js +53 -28
- package/dist/agent/chat/prompt/index.d.ts +2 -2
- package/dist/agent/chat/prompt/index.d.ts.map +1 -1
- package/dist/agent/chat/prompt/index.js +5 -4
- package/dist/agent/chat/prompt/repo.d.ts +2 -2
- package/dist/agent/chat/prompt/repo.d.ts.map +1 -1
- package/dist/agent/chat/prompt/repo.js +20 -11
- package/dist/agent/chat/state.d.ts +2 -2
- package/dist/agent/chat/state.d.ts.map +1 -1
- package/dist/agent/chat/types.d.ts +0 -6
- package/dist/agent/chat/types.d.ts.map +1 -1
- package/dist/agent/chat/utils/tool-calls.d.ts +21 -0
- package/dist/agent/chat/utils/tool-calls.d.ts.map +1 -0
- package/dist/agent/chat/utils/tool-calls.js +64 -0
- package/dist/agent/chat/utils.d.ts +2 -4
- package/dist/agent/chat/utils.d.ts.map +1 -1
- package/dist/agent/chat/utils.js +5 -11
- package/dist/agent/code-review/prompt.d.ts +2 -0
- package/dist/agent/code-review/prompt.d.ts.map +1 -0
- package/dist/agent/code-review/prompt.js +19 -0
- package/dist/agent/codegen/create-test-block.d.ts.map +1 -1
- package/dist/agent/codegen/create-test-block.js +0 -10
- package/dist/agent/diagnosis-agent/index.d.ts.map +1 -1
- package/dist/agent/diagnosis-agent/index.js +0 -9
- package/dist/agent/master/browser-tests/index.spec.js +1 -1
- package/dist/agent/master/execute-browser-action.d.ts +1 -1
- package/dist/agent/master/execute-browser-action.d.ts.map +1 -1
- package/dist/agent/master/execute-skill-action.d.ts +1 -1
- package/dist/agent/master/execute-skill-action.d.ts.map +1 -1
- package/dist/agent/master/run.d.ts.map +1 -1
- package/dist/agent/master/run.js +0 -74
- package/dist/artifacts/index.d.ts.map +1 -1
- package/dist/artifacts/index.js +18 -6
- package/dist/artifacts/utils.d.ts +2 -2
- package/dist/artifacts/utils.d.ts.map +1 -1
- package/dist/artifacts/utils.js +16 -5
- package/dist/auth/cli-auth.d.ts.map +1 -1
- package/dist/auth/cli-auth.js +3 -7
- package/dist/auth/index.d.ts +1 -2
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +2 -4
- package/dist/auth/token-store.d.ts +1 -1
- package/dist/auth/token-store.d.ts.map +1 -1
- package/dist/auth/token-store.js +3 -3
- package/dist/bin/environments.d.ts +5 -1
- package/dist/bin/environments.d.ts.map +1 -1
- package/dist/bin/environments.js +76 -44
- package/dist/bin/index.js +33 -74
- package/dist/bin/setup.d.ts +3 -1
- package/dist/bin/setup.d.ts.map +1 -1
- package/dist/bin/setup.js +16 -20
- package/dist/dashboard/client.d.ts +26 -0
- package/dist/dashboard/client.d.ts.map +1 -0
- package/dist/dashboard/client.js +185 -0
- package/dist/dashboard/index.d.ts +3 -0
- package/dist/dashboard/index.d.ts.map +1 -0
- package/dist/dashboard/index.js +9 -0
- package/dist/dashboard/totp.d.ts +2 -0
- package/dist/dashboard/totp.d.ts.map +1 -0
- package/dist/dashboard/totp.js +14 -0
- package/dist/dashboard/types.d.ts +9 -0
- package/dist/dashboard/types.d.ts.map +1 -0
- package/dist/dashboard/types.js +17 -0
- package/dist/file-info/file-system.d.ts +3 -0
- package/dist/file-info/file-system.d.ts.map +1 -0
- package/dist/{utils/file-tree.js → file-info/file-system.js} +2 -8
- package/dist/file-info/github.d.ts +3 -0
- package/dist/file-info/github.d.ts.map +1 -0
- package/dist/file-info/github.js +107 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -9
- package/dist/recorder/env-variables.d.ts.map +1 -1
- package/dist/recorder/env-variables.js +3 -7
- package/dist/recorder/index.js +5 -5
- package/dist/recorder/request.js +4 -9
- package/dist/recorder/upload.d.ts +3 -2
- package/dist/recorder/upload.d.ts.map +1 -1
- package/dist/recorder/upload.js +20 -22
- package/dist/tools/commit-and-create-pr.d.ts.map +1 -1
- package/dist/tools/commit-and-create-pr.js +44 -37
- package/dist/tools/definitions/run-test.d.ts +23 -0
- package/dist/tools/definitions/run-test.d.ts.map +1 -0
- package/dist/tools/definitions/run-test.js +28 -0
- package/dist/tools/definitions/str_replace_editor.d.ts +3 -0
- package/dist/tools/definitions/str_replace_editor.d.ts.map +1 -0
- package/dist/tools/definitions/str_replace_editor.js +74 -0
- package/dist/tools/definitions/test-gen-browser.d.ts +26 -0
- package/dist/tools/definitions/test-gen-browser.d.ts.map +1 -0
- package/dist/tools/definitions/test-gen-browser.js +88 -0
- package/dist/tools/delete-file.d.ts +3 -0
- package/dist/tools/delete-file.d.ts.map +1 -0
- package/dist/tools/delete-file.js +83 -0
- package/dist/tools/diagnosis-fetcher.d.ts.map +1 -1
- package/dist/tools/diagnosis-fetcher.js +3 -7
- package/dist/tools/executor/index.d.ts +24 -0
- package/dist/tools/executor/index.d.ts.map +1 -0
- package/dist/{tool-call-service → tools/executor}/index.js +38 -58
- package/dist/tools/executor/utils/checkpoint.d.ts +7 -0
- package/dist/tools/executor/utils/checkpoint.d.ts.map +1 -0
- package/dist/{utils → tools/executor/utils}/checkpoint.js +6 -5
- package/dist/{utils → tools/executor/utils}/git.d.ts +7 -12
- package/dist/tools/executor/utils/git.d.ts.map +1 -0
- package/dist/{utils → tools/executor/utils}/git.js +11 -36
- package/dist/tools/executor/utils/index.d.ts +77 -0
- package/dist/tools/executor/utils/index.d.ts.map +1 -0
- package/dist/tools/executor/utils/index.js +121 -0
- package/dist/tools/executor/utils/pr-description.d.ts +4 -0
- package/dist/tools/executor/utils/pr-description.d.ts.map +1 -0
- package/dist/tools/executor/utils/pr-description.js +24 -0
- package/dist/tools/fetch-image/index.d.ts +3 -0
- package/dist/tools/fetch-image/index.d.ts.map +1 -0
- package/dist/tools/fetch-image/index.js +56 -0
- package/dist/tools/grep/index.d.ts.map +1 -1
- package/dist/tools/grep/index.js +1 -1
- package/dist/tools/index.d.ts +4 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +60 -0
- package/dist/tools/list-environments.d.ts.map +1 -1
- package/dist/tools/list-environments.js +2 -5
- package/dist/tools/merge-conflicts.d.ts +3 -0
- package/dist/tools/merge-conflicts.d.ts.map +1 -0
- package/dist/tools/merge-conflicts.js +107 -0
- package/dist/tools/run-test.d.ts.map +1 -1
- package/dist/tools/run-test.js +4 -25
- package/dist/tools/str_replace_editor.d.ts.map +1 -1
- package/dist/tools/str_replace_editor.js +6 -58
- package/dist/tools/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/test-gen-browser.js +2 -83
- package/dist/tools/test-run-fetcher/index.d.ts.map +1 -1
- package/dist/tools/test-run-fetcher/index.js +2 -6
- package/dist/tools/upgrade-packages/index.d.ts.map +1 -1
- package/dist/tools/upgrade-packages/index.js +12 -13
- package/dist/tools/upgrade-packages/utils.d.ts +3 -2
- package/dist/tools/upgrade-packages/utils.d.ts.map +1 -1
- package/dist/tools/upgrade-packages/utils.js +5 -8
- package/dist/tools/utils/queue.d.ts +5 -0
- package/dist/tools/utils/queue.d.ts.map +1 -0
- package/dist/tools/utils/queue.js +41 -0
- package/dist/types/index.d.ts +0 -8
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/SQSClient.d.ts +14 -0
- package/dist/utils/SQSClient.d.ts.map +1 -0
- package/dist/utils/SQSClient.js +116 -0
- package/dist/utils/repo-tree.d.ts +1 -1
- package/dist/utils/repo-tree.d.ts.map +1 -1
- package/dist/utils/repo-tree.js +7 -7
- package/package.json +16 -8
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/auth/api-client.d.ts +0 -13
- package/dist/auth/api-client.d.ts.map +0 -1
- package/dist/auth/api-client.js +0 -103
- package/dist/session/index.d.ts +0 -20
- package/dist/session/index.d.ts.map +0 -1
- package/dist/session/index.js +0 -104
- package/dist/tool-call-service/index.d.ts +0 -32
- package/dist/tool-call-service/index.d.ts.map +0 -1
- package/dist/tool-call-service/utils.d.ts +0 -6
- package/dist/tool-call-service/utils.d.ts.map +0 -1
- package/dist/tool-call-service/utils.js +0 -57
- package/dist/tools/utils/index.d.ts +0 -61
- package/dist/tools/utils/index.d.ts.map +0 -1
- package/dist/tools/utils/index.js +0 -122
- package/dist/utils/checkpoint.d.ts +0 -7
- package/dist/utils/checkpoint.d.ts.map +0 -1
- package/dist/utils/file-tree.d.ts +0 -3
- package/dist/utils/file-tree.d.ts.map +0 -1
- package/dist/utils/git.d.ts.map +0 -1
|
@@ -6,12 +6,10 @@ exports.checkoutBranch = checkoutBranch;
|
|
|
6
6
|
exports.commitAsBotUser = commitAsBotUser;
|
|
7
7
|
exports.getCurrentBranchName = getCurrentBranchName;
|
|
8
8
|
exports.pullBranch = pullBranch;
|
|
9
|
-
exports.
|
|
9
|
+
exports.commitFilesAsBotUser = commitFilesAsBotUser;
|
|
10
10
|
exports.getFilesChanged = getFilesChanged;
|
|
11
11
|
exports.mergePullRequest = mergePullRequest;
|
|
12
|
-
exports.deleteBranch = deleteBranch;
|
|
13
12
|
const child_process_1 = require("child_process");
|
|
14
|
-
const utils_1 = require("../tools/utils");
|
|
15
13
|
const GIT_USER_NAME = "empiricalrun[bot]";
|
|
16
14
|
const GIT_USER_EMAIL = "180257021+empiricalrun[bot]@users.noreply.github.com";
|
|
17
15
|
function getGitDiff(filepath, cwd) {
|
|
@@ -39,22 +37,20 @@ function getGitDiffForNewFile(filepath, cwd) {
|
|
|
39
37
|
}
|
|
40
38
|
}
|
|
41
39
|
async function checkoutBranch(branchName, cwd) {
|
|
42
|
-
// TODO: This assumes repoDir is process.cwd()
|
|
43
40
|
try {
|
|
44
41
|
(0, child_process_1.execSync)(`git checkout ${branchName}`, { cwd });
|
|
45
42
|
}
|
|
46
43
|
catch (e) {
|
|
47
|
-
// If branch doesn't exist, create it
|
|
48
44
|
(0, child_process_1.execSync)(`git checkout -b ${branchName}`, { cwd });
|
|
49
45
|
}
|
|
50
46
|
}
|
|
51
|
-
|
|
47
|
+
function commitAsBotUser(commitMessage, cwd) {
|
|
52
48
|
const status = (0, child_process_1.execSync)("git status --porcelain", {
|
|
53
49
|
encoding: "utf-8",
|
|
54
50
|
cwd,
|
|
55
51
|
});
|
|
56
52
|
if (!status) {
|
|
57
|
-
return false;
|
|
53
|
+
return false;
|
|
58
54
|
}
|
|
59
55
|
const commitMessageWithSkipCi = `${commitMessage} [skip ci]`;
|
|
60
56
|
(0, child_process_1.execSync)(`git -c user.name="${GIT_USER_NAME}" -c user.email="${GIT_USER_EMAIL}" commit -m "${commitMessageWithSkipCi}"`, { cwd });
|
|
@@ -71,12 +67,11 @@ async function getCurrentBranchName(repoPath) {
|
|
|
71
67
|
async function pullBranch(branchName, cwd) {
|
|
72
68
|
(0, child_process_1.execSync)(`git pull origin ${branchName}`, { cwd });
|
|
73
69
|
}
|
|
74
|
-
|
|
70
|
+
function commitFilesAsBotUser({ commitMessage, files, repoPath, }) {
|
|
75
71
|
(0, child_process_1.execSync)(`git add ${files.join(" ")}`, { cwd: repoPath });
|
|
76
|
-
|
|
77
|
-
(0, child_process_1.execSync)(`git push origin ${branchName}`, { cwd: repoPath });
|
|
72
|
+
commitAsBotUser(commitMessage, repoPath);
|
|
78
73
|
}
|
|
79
|
-
|
|
74
|
+
function getFilesChanged(cwd) {
|
|
80
75
|
const output = (0, child_process_1.execSync)("git status --porcelain --untracked-files", {
|
|
81
76
|
cwd,
|
|
82
77
|
}).toString();
|
|
@@ -87,20 +82,19 @@ async function getFilesChanged(cwd) {
|
|
|
87
82
|
.filter((fileName) => fileName != "");
|
|
88
83
|
return filesChanged;
|
|
89
84
|
}
|
|
90
|
-
async function mergePullRequest({ repoName, prNumber,
|
|
91
|
-
const url =
|
|
85
|
+
async function mergePullRequest({ repoName, prNumber, apiClient, }) {
|
|
86
|
+
const url = `/repos/empirical-run/${repoName}/pulls/${prNumber}/merge`;
|
|
92
87
|
const mergeBody = {
|
|
93
88
|
merge_method: "squash",
|
|
94
89
|
};
|
|
95
90
|
try {
|
|
96
|
-
const
|
|
91
|
+
const data = await apiClient.callGitHubProxy({
|
|
97
92
|
method: "PUT",
|
|
98
93
|
url: url,
|
|
99
94
|
body: mergeBody,
|
|
100
|
-
apiKey,
|
|
101
95
|
});
|
|
102
|
-
if (!
|
|
103
|
-
console.log(`PR #${prNumber} for ${repoName} could not be merged: ${
|
|
96
|
+
if (!data?.merged) {
|
|
97
|
+
console.log(`PR #${prNumber} for ${repoName} could not be merged: ${data.message}`);
|
|
104
98
|
return false;
|
|
105
99
|
}
|
|
106
100
|
console.log(`Merged PR #${prNumber} for ${repoName} via proxy`);
|
|
@@ -111,22 +105,3 @@ async function mergePullRequest({ repoName, prNumber, apiKey, }) {
|
|
|
111
105
|
return false;
|
|
112
106
|
}
|
|
113
107
|
}
|
|
114
|
-
async function deleteBranch({ repoName, branchName, apiKey, }) {
|
|
115
|
-
const url = `${utils_1.GITHUB_API_BASE}/${repoName}/git/refs/heads/${branchName}`;
|
|
116
|
-
try {
|
|
117
|
-
await (0, utils_1.callGitHubProxy)({
|
|
118
|
-
method: "DELETE",
|
|
119
|
-
url: url,
|
|
120
|
-
apiKey,
|
|
121
|
-
});
|
|
122
|
-
console.log(`Deleted branch ${branchName} from ${repoName} via proxy`);
|
|
123
|
-
}
|
|
124
|
-
catch (error) {
|
|
125
|
-
if (error.message?.includes("422")) {
|
|
126
|
-
console.log(`Branch ${branchName} likely already deleted or never existed on ${repoName}.`);
|
|
127
|
-
}
|
|
128
|
-
else {
|
|
129
|
-
console.error(`Error deleting branch ${branchName} from ${repoName} via proxy: ${error.message}`);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { IDashboardAPIClient } from "@empiricalrun/shared-types";
|
|
2
|
+
export interface GitHubRepoInfo {
|
|
3
|
+
owner: string;
|
|
4
|
+
repo: string;
|
|
5
|
+
}
|
|
6
|
+
export declare function parseGitHubUrl(url: string): GitHubRepoInfo;
|
|
7
|
+
export interface PullRequestInfo {
|
|
8
|
+
number: number;
|
|
9
|
+
html_url: string;
|
|
10
|
+
head: {
|
|
11
|
+
ref: string;
|
|
12
|
+
sha: string;
|
|
13
|
+
};
|
|
14
|
+
base: {
|
|
15
|
+
ref: string;
|
|
16
|
+
sha: string;
|
|
17
|
+
};
|
|
18
|
+
state: string;
|
|
19
|
+
title: string;
|
|
20
|
+
body: string;
|
|
21
|
+
created_at: string;
|
|
22
|
+
updated_at: string;
|
|
23
|
+
closed_at: string;
|
|
24
|
+
merged_at: string;
|
|
25
|
+
merge_commit_sha: string;
|
|
26
|
+
commits: number;
|
|
27
|
+
additions: number;
|
|
28
|
+
deletions: number;
|
|
29
|
+
changed_files: number;
|
|
30
|
+
user: {
|
|
31
|
+
login: string;
|
|
32
|
+
};
|
|
33
|
+
mergeable_state: "clean" | "dirty" | "unstable" | "unknown";
|
|
34
|
+
}
|
|
35
|
+
export declare function getExistingPR({ owner, repo, branchName, apiClient, }: {
|
|
36
|
+
owner: string;
|
|
37
|
+
repo: string;
|
|
38
|
+
branchName: string;
|
|
39
|
+
apiClient: IDashboardAPIClient;
|
|
40
|
+
}): Promise<PullRequestInfo | null>;
|
|
41
|
+
export declare function getMergeableState({ owner, repo, pullRequest, apiClient, }: {
|
|
42
|
+
owner: string;
|
|
43
|
+
repo: string;
|
|
44
|
+
pullRequest: PullRequestInfo;
|
|
45
|
+
apiClient: IDashboardAPIClient;
|
|
46
|
+
}): Promise<"clean" | "dirty" | "unstable" | "unknown">;
|
|
47
|
+
export declare function getMergeableStateDescription(state: "clean" | "dirty" | "unstable" | "unknown" | string): string;
|
|
48
|
+
export declare function createPullRequest({ owner, repo, title, head, base, body, labels, apiClient, }: {
|
|
49
|
+
owner: string;
|
|
50
|
+
repo: string;
|
|
51
|
+
title: string;
|
|
52
|
+
head: string;
|
|
53
|
+
base?: string;
|
|
54
|
+
body: string;
|
|
55
|
+
labels?: string[];
|
|
56
|
+
apiClient: IDashboardAPIClient;
|
|
57
|
+
}): Promise<PullRequestInfo>;
|
|
58
|
+
export declare function updatePullRequest({ owner, repo, prNumber, body, apiClient, }: {
|
|
59
|
+
owner: string;
|
|
60
|
+
repo: string;
|
|
61
|
+
prNumber: number;
|
|
62
|
+
body?: string;
|
|
63
|
+
apiClient: IDashboardAPIClient;
|
|
64
|
+
}): Promise<PullRequestInfo>;
|
|
65
|
+
export declare function findOrCreatePullRequest({ owner, repo, branchName, title, body, labels, apiClient, }: {
|
|
66
|
+
owner: string;
|
|
67
|
+
repo: string;
|
|
68
|
+
branchName: string;
|
|
69
|
+
title: string;
|
|
70
|
+
body: string;
|
|
71
|
+
labels?: string[];
|
|
72
|
+
apiClient: IDashboardAPIClient;
|
|
73
|
+
}): Promise<{
|
|
74
|
+
pr: PullRequestInfo;
|
|
75
|
+
isNew: boolean;
|
|
76
|
+
}>;
|
|
77
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tools/executor/utils/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.parseGitHubUrl = parseGitHubUrl;
|
|
4
|
+
exports.getExistingPR = getExistingPR;
|
|
5
|
+
exports.getMergeableState = getMergeableState;
|
|
6
|
+
exports.getMergeableStateDescription = getMergeableStateDescription;
|
|
7
|
+
exports.createPullRequest = createPullRequest;
|
|
8
|
+
exports.updatePullRequest = updatePullRequest;
|
|
9
|
+
exports.findOrCreatePullRequest = findOrCreatePullRequest;
|
|
10
|
+
function parseGitHubUrl(url) {
|
|
11
|
+
const githubIndex = url.indexOf("github.com");
|
|
12
|
+
if (githubIndex === -1) {
|
|
13
|
+
throw new Error("Invalid GitHub repository URL");
|
|
14
|
+
}
|
|
15
|
+
const [owner, repo] = url
|
|
16
|
+
.substring(githubIndex + "github.com/".length)
|
|
17
|
+
.replace(".git", "")
|
|
18
|
+
.split("/");
|
|
19
|
+
if (!owner || !repo) {
|
|
20
|
+
throw new Error("Invalid GitHub repository URL format - missing owner or repo");
|
|
21
|
+
}
|
|
22
|
+
return { owner, repo };
|
|
23
|
+
}
|
|
24
|
+
async function getExistingPR({ owner, repo, branchName, apiClient, }) {
|
|
25
|
+
const prs = await apiClient.callGitHubProxy({
|
|
26
|
+
method: "GET",
|
|
27
|
+
url: `/repos/${owner}/${repo}/pulls`,
|
|
28
|
+
body: {
|
|
29
|
+
head: `${owner}:${branchName}`,
|
|
30
|
+
state: "open",
|
|
31
|
+
},
|
|
32
|
+
});
|
|
33
|
+
return prs?.find((pr) => pr.head.ref === branchName) || null;
|
|
34
|
+
}
|
|
35
|
+
async function getMergeableState({ owner, repo, pullRequest, apiClient, }) {
|
|
36
|
+
if (pullRequest.mergeable_state !== "unknown") {
|
|
37
|
+
return pullRequest.mergeable_state;
|
|
38
|
+
}
|
|
39
|
+
const maxAttempts = 10;
|
|
40
|
+
let attempts = 0;
|
|
41
|
+
while (attempts < maxAttempts) {
|
|
42
|
+
await new Promise((resolve) => setTimeout(resolve, 5_000));
|
|
43
|
+
attempts++;
|
|
44
|
+
try {
|
|
45
|
+
const updatedPR = await apiClient.callGitHubProxy({
|
|
46
|
+
method: "GET",
|
|
47
|
+
url: `/repos/${owner}/${repo}/pulls/${pullRequest.number}`,
|
|
48
|
+
});
|
|
49
|
+
if (updatedPR.mergeable_state !== "unknown") {
|
|
50
|
+
return updatedPR.mergeable_state;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.warn(`Failed to fetch PR mergeable state (attempt ${attempts}):`, error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return "unknown";
|
|
58
|
+
}
|
|
59
|
+
function getMergeableStateDescription(state) {
|
|
60
|
+
switch (state) {
|
|
61
|
+
case "clean":
|
|
62
|
+
return "The pull request is mergeable without conflicts.";
|
|
63
|
+
case "dirty":
|
|
64
|
+
return "The pull request has merge conflicts that must be resolved.";
|
|
65
|
+
case "unstable":
|
|
66
|
+
return "The pull request has failing or pending required status checks.";
|
|
67
|
+
case "unknown":
|
|
68
|
+
return "The mergeability of the pull request is still being calculated.";
|
|
69
|
+
default:
|
|
70
|
+
return `The pull request has mergeable state: ${state}.`;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
async function createPullRequest({ owner, repo, title, head, base = "main", body, labels, apiClient, }) {
|
|
74
|
+
const createPrBody = {
|
|
75
|
+
title,
|
|
76
|
+
head,
|
|
77
|
+
base,
|
|
78
|
+
body,
|
|
79
|
+
...(labels && { labels }),
|
|
80
|
+
};
|
|
81
|
+
const pr = await apiClient.callGitHubProxy({
|
|
82
|
+
method: "POST",
|
|
83
|
+
url: `/repos/${owner}/${repo}/pulls`,
|
|
84
|
+
body: createPrBody,
|
|
85
|
+
});
|
|
86
|
+
if (!pr || !("number" in pr)) {
|
|
87
|
+
throw new Error(`Failed to create PR or PR number missing in response.`);
|
|
88
|
+
}
|
|
89
|
+
return pr;
|
|
90
|
+
}
|
|
91
|
+
async function updatePullRequest({ owner, repo, prNumber, body, apiClient, }) {
|
|
92
|
+
const updateBody = {};
|
|
93
|
+
if (body)
|
|
94
|
+
updateBody.body = body;
|
|
95
|
+
return await apiClient.callGitHubProxy({
|
|
96
|
+
method: "PATCH",
|
|
97
|
+
url: `/repos/${owner}/${repo}/pulls/${prNumber}`,
|
|
98
|
+
body: updateBody,
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async function findOrCreatePullRequest({ owner, repo, branchName, title, body, labels, apiClient, }) {
|
|
102
|
+
const existingPR = await getExistingPR({
|
|
103
|
+
owner,
|
|
104
|
+
repo,
|
|
105
|
+
branchName,
|
|
106
|
+
apiClient,
|
|
107
|
+
});
|
|
108
|
+
if (existingPR) {
|
|
109
|
+
return { pr: existingPR, isNew: false };
|
|
110
|
+
}
|
|
111
|
+
const newPR = await createPullRequest({
|
|
112
|
+
owner,
|
|
113
|
+
repo,
|
|
114
|
+
title,
|
|
115
|
+
head: branchName,
|
|
116
|
+
body,
|
|
117
|
+
labels,
|
|
118
|
+
apiClient,
|
|
119
|
+
});
|
|
120
|
+
return { pr: newPR, isNew: true };
|
|
121
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ChatSessionInfo } from "@empiricalrun/shared-types";
|
|
2
|
+
export declare function generateSessionMetadata(chatSession: ChatSessionInfo | null): string;
|
|
3
|
+
export declare function addMetadataToPRDescription(description: string, chatSession: ChatSessionInfo | null): string;
|
|
4
|
+
//# sourceMappingURL=pr-description.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pr-description.d.ts","sourceRoot":"","sources":["../../../../src/tools/executor/utils/pr-description.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAElE,wBAAgB,uBAAuB,CACrC,WAAW,EAAE,eAAe,GAAG,IAAI,GAClC,MAAM,CASR;AAED,wBAAgB,0BAA0B,CACxC,WAAW,EAAE,MAAM,EACnB,WAAW,EAAE,eAAe,GAAG,IAAI,GAClC,MAAM,CAWR"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateSessionMetadata = generateSessionMetadata;
|
|
4
|
+
exports.addMetadataToPRDescription = addMetadataToPRDescription;
|
|
5
|
+
function generateSessionMetadata(chatSession) {
|
|
6
|
+
if (!chatSession) {
|
|
7
|
+
return "";
|
|
8
|
+
}
|
|
9
|
+
let userInfo = "";
|
|
10
|
+
if (chatSession.createdBy) {
|
|
11
|
+
userInfo = ` by ${chatSession.createdBy}`;
|
|
12
|
+
}
|
|
13
|
+
return `PR created from [session #${chatSession.id}](${chatSession.url})${userInfo}`;
|
|
14
|
+
}
|
|
15
|
+
function addMetadataToPRDescription(description, chatSession) {
|
|
16
|
+
const timestamp = new Date()
|
|
17
|
+
.toISOString()
|
|
18
|
+
.replace("T", " ")
|
|
19
|
+
.replace("Z", " UTC");
|
|
20
|
+
const sessionInfo = chatSession
|
|
21
|
+
? `\n\n${generateSessionMetadata(chatSession)}`
|
|
22
|
+
: "";
|
|
23
|
+
return `${description}${sessionInfo}\n\n<sup>Updated at ${timestamp}</sup>`;
|
|
24
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/fetch-image/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAA8B,MAAM,4BAA4B,CAAC;AAS9E,eAAO,MAAM,cAAc,EAAE,IAiD5B,CAAC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.fetchImageTool = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const SUPPORTED_CONTENT_TYPES = ["image/png", "image/jpeg"];
|
|
6
|
+
const fetchImageSchema = zod_1.z.object({
|
|
7
|
+
url: zod_1.z.string(),
|
|
8
|
+
});
|
|
9
|
+
exports.fetchImageTool = {
|
|
10
|
+
schema: {
|
|
11
|
+
name: "fetchImage",
|
|
12
|
+
description: "Use this tool to fetch image data from any valid URL. It takes an image URL as input and returns the image in base64 format. Automatically call this tool when a user provides an image link or message containing a URL pointing to an image, so that you can view or analyze the image content effectively",
|
|
13
|
+
parameters: fetchImageSchema,
|
|
14
|
+
},
|
|
15
|
+
needsBrowser: false,
|
|
16
|
+
execute: async ({ input }) => {
|
|
17
|
+
const { url } = input;
|
|
18
|
+
try {
|
|
19
|
+
const response = await fetch(url);
|
|
20
|
+
if (!response.ok) {
|
|
21
|
+
console.error(`Failed to fetch image from ${url}: ${response.statusText}`);
|
|
22
|
+
return {
|
|
23
|
+
result: `Failed to fetch image from ${url}: ${response.statusText}`,
|
|
24
|
+
isError: true,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
const contentType = response.headers.get("content-type");
|
|
28
|
+
if (!contentType || !SUPPORTED_CONTENT_TYPES.includes(contentType)) {
|
|
29
|
+
const errorMessage = `Invalid content type: ${contentType}. URL must return an image.`;
|
|
30
|
+
console.error(errorMessage);
|
|
31
|
+
return {
|
|
32
|
+
result: errorMessage,
|
|
33
|
+
isError: true,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
const buffer = await response.arrayBuffer();
|
|
37
|
+
const base64 = Buffer.from(buffer).toString("base64");
|
|
38
|
+
return {
|
|
39
|
+
result: [
|
|
40
|
+
{
|
|
41
|
+
type: contentType,
|
|
42
|
+
base64Data: base64,
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
isError: false,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error("Error fetching image", error);
|
|
50
|
+
return {
|
|
51
|
+
result: `Error fetching image: ${error}`,
|
|
52
|
+
isError: true,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/grep/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/grep/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,4BAA4B,CAAC;AA8HnE,eAAO,MAAM,QAAQ,EAAE,IAkBtB,CAAC"}
|
package/dist/tools/grep/index.js
CHANGED
|
@@ -125,7 +125,7 @@ Search is case insensitive and regex patterns are not supported.`,
|
|
|
125
125
|
parameters: GrepInputSchema,
|
|
126
126
|
},
|
|
127
127
|
needsBrowser: false,
|
|
128
|
-
execute: async ({ input, repoPath
|
|
128
|
+
execute: async ({ input, repoPath }) => {
|
|
129
129
|
if ((0, ripgrep_1.isRgAvailable)()) {
|
|
130
130
|
return usingRipgrep(input, repoPath);
|
|
131
131
|
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ServicePayload, SupportedChatModels } from "@empiricalrun/shared-types";
|
|
2
|
+
export declare function availableTools(model?: SupportedChatModels): import("@empiricalrun/shared-types").ToolDefinition[];
|
|
3
|
+
export declare function sendToolRequestToRemoteQueue(payload: ServicePayload): Promise<void>;
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,cAAc,EACd,mBAAmB,EACpB,MAAM,4BAA4B,CAAC;AAkBpC,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,mBAAmB,yDAoBzD;AAUD,wBAAsB,4BAA4B,CAAC,OAAO,EAAE,cAAc,iBAoBzE"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.availableTools = availableTools;
|
|
4
|
+
exports.sendToolRequestToRemoteQueue = sendToolRequestToRemoteQueue;
|
|
5
|
+
const chat_1 = require("@empiricalrun/llm/chat");
|
|
6
|
+
const SQSClient_1 = require("../utils/SQSClient");
|
|
7
|
+
const commit_and_create_pr_1 = require("./commit-and-create-pr");
|
|
8
|
+
const run_test_1 = require("./definitions/run-test");
|
|
9
|
+
const str_replace_editor_1 = require("./definitions/str_replace_editor");
|
|
10
|
+
const test_gen_browser_1 = require("./definitions/test-gen-browser");
|
|
11
|
+
const delete_file_1 = require("./delete-file");
|
|
12
|
+
const diagnosis_fetcher_1 = require("./diagnosis-fetcher");
|
|
13
|
+
const download_build_1 = require("./download-build");
|
|
14
|
+
const fetch_image_1 = require("./fetch-image");
|
|
15
|
+
const grep_1 = require("./grep");
|
|
16
|
+
const list_environments_1 = require("./list-environments");
|
|
17
|
+
const merge_conflicts_1 = require("./merge-conflicts");
|
|
18
|
+
const test_run_fetcher_1 = require("./test-run-fetcher");
|
|
19
|
+
const upgrade_packages_1 = require("./upgrade-packages");
|
|
20
|
+
const queue_1 = require("./utils/queue");
|
|
21
|
+
function availableTools(model) {
|
|
22
|
+
// TODO: Keep this list in sync with the ToolExecutor
|
|
23
|
+
const tools = [
|
|
24
|
+
run_test_1.runTestTool,
|
|
25
|
+
test_gen_browser_1.generateTestWithBrowserAgent,
|
|
26
|
+
grep_1.grepTool,
|
|
27
|
+
test_run_fetcher_1.fetchTestRunReportTool,
|
|
28
|
+
diagnosis_fetcher_1.fetchDiagnosisReportTool,
|
|
29
|
+
commit_and_create_pr_1.createPullRequestTool,
|
|
30
|
+
merge_conflicts_1.mergeConflictsTool,
|
|
31
|
+
list_environments_1.listEnvironmentsTool,
|
|
32
|
+
download_build_1.downloadBuildTool,
|
|
33
|
+
upgrade_packages_1.upgradePackagesTool,
|
|
34
|
+
fetch_image_1.fetchImageTool,
|
|
35
|
+
delete_file_1.deleteFileTool,
|
|
36
|
+
];
|
|
37
|
+
if (model && (0, chat_1.getProviderForModel)(model) !== "claude") {
|
|
38
|
+
tools.push(...Object.values(str_replace_editor_1.textEditorTools));
|
|
39
|
+
}
|
|
40
|
+
return tools;
|
|
41
|
+
}
|
|
42
|
+
function toolsNeedBrowser(toolCalls) {
|
|
43
|
+
const allTools = availableTools();
|
|
44
|
+
return toolCalls.some((toolCall) => allTools.find((t) => t.schema.name === toolCall.name)?.needsBrowser);
|
|
45
|
+
}
|
|
46
|
+
async function sendToolRequestToRemoteQueue(payload) {
|
|
47
|
+
const needsBrowser = toolsNeedBrowser(payload.toolCalls);
|
|
48
|
+
const queueUrl = (0, queue_1.getQueueUrl)(payload.toolCalls, needsBrowser);
|
|
49
|
+
if (!queueUrl) {
|
|
50
|
+
throw new Error(`queueUrl is required for remote execution.`);
|
|
51
|
+
}
|
|
52
|
+
const region = process.env.AWS_REGION;
|
|
53
|
+
const accessKeyId = process.env.AWS_ACCESS_KEY_ID;
|
|
54
|
+
const secretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;
|
|
55
|
+
if (!region || !accessKeyId || !secretAccessKey) {
|
|
56
|
+
throw new Error("AWS_REGION, AWS_ACCESS_KEY_ID, and AWS_SECRET_ACCESS_KEY must be set");
|
|
57
|
+
}
|
|
58
|
+
const sqs = new SQSClient_1.SQSClient(region, accessKeyId, secretAccessKey);
|
|
59
|
+
await sqs.sendMessage(queueUrl, payload);
|
|
60
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list-environments.d.ts","sourceRoot":"","sources":["../../src/tools/list-environments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"list-environments.d.ts","sourceRoot":"","sources":["../../src/tools/list-environments.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAGvD,eAAO,MAAM,oBAAoB,EAAE,IA2ClC,CAAC"}
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.listEnvironmentsTool = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
const utils_1 = require("./utils");
|
|
6
5
|
exports.listEnvironmentsTool = {
|
|
7
6
|
schema: {
|
|
8
7
|
name: "listEnvironments",
|
|
@@ -10,13 +9,11 @@ exports.listEnvironmentsTool = {
|
|
|
10
9
|
parameters: zod_1.z.object({}),
|
|
11
10
|
},
|
|
12
11
|
needsBrowser: false,
|
|
13
|
-
execute: async ({
|
|
12
|
+
execute: async ({ apiClient }) => {
|
|
14
13
|
let response;
|
|
15
14
|
try {
|
|
16
|
-
response = await (
|
|
17
|
-
path: `/api/environments/list`,
|
|
15
|
+
response = await apiClient.request(`/api/environments/list`, {
|
|
18
16
|
method: "GET",
|
|
19
|
-
apiKey,
|
|
20
17
|
});
|
|
21
18
|
}
|
|
22
19
|
catch (error) {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"merge-conflicts.d.ts","sourceRoot":"","sources":["../../src/tools/merge-conflicts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AA6CvD,eAAO,MAAM,kBAAkB,EAAE,IAgEhC,CAAC"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.mergeConflictsTool = void 0;
|
|
7
|
+
const child_process_1 = require("child_process");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const path_1 = __importDefault(require("path"));
|
|
10
|
+
const zod_1 = require("zod");
|
|
11
|
+
const git_1 = require("./executor/utils/git");
|
|
12
|
+
function runMergeMain(repoPath) {
|
|
13
|
+
try {
|
|
14
|
+
(0, child_process_1.execSync)("git merge --no-ff origin/main", { stdio: "pipe", cwd: repoPath });
|
|
15
|
+
return "CLEAN";
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
// Check if it's a merge conflict (exit code 1) vs other errors
|
|
19
|
+
if (error.status === 1) {
|
|
20
|
+
return "CONFLICTS";
|
|
21
|
+
}
|
|
22
|
+
throw error;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
function getConflictedFilesWithContents(repoPath) {
|
|
26
|
+
const output = (0, child_process_1.execSync)("git diff --name-only --diff-filter=U", {
|
|
27
|
+
encoding: "utf8",
|
|
28
|
+
stdio: "pipe",
|
|
29
|
+
cwd: repoPath,
|
|
30
|
+
});
|
|
31
|
+
const fileNames = output
|
|
32
|
+
.trim()
|
|
33
|
+
.split("\n")
|
|
34
|
+
.filter((file) => file.length > 0);
|
|
35
|
+
const filesWithContents = {};
|
|
36
|
+
fileNames.forEach((fileName) => {
|
|
37
|
+
const fullPath = path_1.default.join(repoPath, fileName);
|
|
38
|
+
const content = fs_1.default.readFileSync(fullPath, "utf8");
|
|
39
|
+
filesWithContents[fileName] = content;
|
|
40
|
+
});
|
|
41
|
+
return filesWithContents;
|
|
42
|
+
}
|
|
43
|
+
const mergeConflictsToolScheme = zod_1.z.object({});
|
|
44
|
+
exports.mergeConflictsTool = {
|
|
45
|
+
schema: {
|
|
46
|
+
name: "checkForMergeConflicts",
|
|
47
|
+
description: `This tool runs the git merge command to merge main into your
|
|
48
|
+
current working branch with the following command.
|
|
49
|
+
|
|
50
|
+
\`\`\`
|
|
51
|
+
git merge --no-ff origin/main
|
|
52
|
+
\`\`\`
|
|
53
|
+
|
|
54
|
+
If this commands fails with merge conflicts, it will still create a dirty commit
|
|
55
|
+
that has merge conflicts, which can be resolved with the file editing tools that you are
|
|
56
|
+
provided with.
|
|
57
|
+
`,
|
|
58
|
+
parameters: mergeConflictsToolScheme,
|
|
59
|
+
},
|
|
60
|
+
needsBrowser: false,
|
|
61
|
+
execute: async ({ repoPath }) => {
|
|
62
|
+
try {
|
|
63
|
+
// Fetch main branch (git clone runs --single-branch), and then run merge
|
|
64
|
+
(0, child_process_1.execSync)("git remote set-branches --add origin main", { cwd: repoPath });
|
|
65
|
+
(0, child_process_1.execSync)("git fetch origin main", { cwd: repoPath });
|
|
66
|
+
// Run merge command and commit (with or without conflict)
|
|
67
|
+
const mergeResult = runMergeMain(repoPath);
|
|
68
|
+
const branchName = await (0, git_1.getCurrentBranchName)(repoPath);
|
|
69
|
+
if (mergeResult === "CLEAN") {
|
|
70
|
+
(0, child_process_1.execSync)(`git push origin ${branchName}`, { cwd: repoPath });
|
|
71
|
+
return {
|
|
72
|
+
isError: false,
|
|
73
|
+
result: `Merge from main was successful, without any conflicts.`,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
else if (mergeResult === "CONFLICTS") {
|
|
77
|
+
const files = getConflictedFilesWithContents(repoPath);
|
|
78
|
+
(0, git_1.commitFilesAsBotUser)({
|
|
79
|
+
commitMessage: "Merge from main with conflicts",
|
|
80
|
+
files: Object.keys(files),
|
|
81
|
+
repoPath,
|
|
82
|
+
});
|
|
83
|
+
(0, child_process_1.execSync)(`git push origin ${branchName}`, { cwd: repoPath });
|
|
84
|
+
// TODO: This can be same as file view result
|
|
85
|
+
const filesResult = Object.entries(files)
|
|
86
|
+
.map(([fileName, content]) => `File: ${fileName}\n\n\`\`\`\n${content}\n\`\`\``)
|
|
87
|
+
.join("\n\n");
|
|
88
|
+
return {
|
|
89
|
+
isError: false,
|
|
90
|
+
result: `Merge from main is committed, with conflicts. Use text edit tools to resolve them.\n\n${filesResult}`,
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
return {
|
|
95
|
+
isError: true,
|
|
96
|
+
result: `An unknown error has occured.`,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
return {
|
|
102
|
+
isError: true,
|
|
103
|
+
result: `Failed to run merge conflicts tool: ${error instanceof Error ? error.message : String(error)}`,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"run-test.d.ts","sourceRoot":"","sources":["../../src/tools/run-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,4BAA4B,CAAC;
|
|
1
|
+
{"version":3,"file":"run-test.d.ts","sourceRoot":"","sources":["../../src/tools/run-test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAc,MAAM,4BAA4B,CAAC;AA0CnE,eAAO,MAAM,WAAW,EAAE,IAiFzB,CAAC"}
|