@empiricalrun/test-gen 0.73.0 → 0.74.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 +96 -0
- package/dist/actions/utils/index.d.ts.map +1 -1
- package/dist/actions/utils/index.js +1 -2
- package/dist/agent/browsing/index.d.ts.map +1 -1
- package/dist/agent/browsing/index.js +9 -7
- package/dist/agent/browsing/utils.d.ts.map +1 -1
- package/dist/agent/browsing/utils.js +3 -4
- package/dist/agent/chat/agent-loop.d.ts +7 -8
- package/dist/agent/chat/agent-loop.d.ts.map +1 -1
- package/dist/agent/chat/agent-loop.js +14 -17
- package/dist/agent/chat/exports.d.ts +5 -4
- package/dist/agent/chat/exports.d.ts.map +1 -1
- package/dist/agent/chat/exports.js +9 -4
- package/dist/agent/chat/filesystem-cache.d.ts +12 -0
- package/dist/agent/chat/filesystem-cache.d.ts.map +1 -0
- package/dist/agent/chat/filesystem-cache.js +101 -0
- package/dist/agent/chat/index.d.ts +4 -1
- package/dist/agent/chat/index.d.ts.map +1 -1
- package/dist/agent/chat/index.js +44 -22
- package/dist/agent/chat/models.d.ts +2 -1
- package/dist/agent/chat/models.d.ts.map +1 -1
- package/dist/agent/chat/models.js +25 -3
- package/dist/agent/chat/prompt/index.d.ts +3 -1
- package/dist/agent/chat/prompt/index.d.ts.map +1 -1
- package/dist/agent/chat/prompt/index.js +77 -2
- package/dist/agent/chat/prompt/repo.d.ts.map +1 -1
- package/dist/agent/chat/prompt/repo.js +1 -0
- package/dist/agent/chat/state.d.ts +6 -5
- package/dist/agent/chat/state.d.ts.map +1 -1
- package/dist/agent/chat/state.js +35 -5
- package/dist/agent/chat/utils.d.ts +1 -0
- package/dist/agent/chat/utils.d.ts.map +1 -1
- package/dist/agent/chat/utils.js +16 -3
- package/dist/agent/cua/index.js +1 -1
- package/dist/agent/cua/model.js +1 -1
- package/dist/agent/cua/pw-codegen/pw-pause/index.d.ts.map +1 -1
- package/dist/agent/cua/pw-codegen/pw-pause/index.js +0 -1
- package/dist/agent/master/browser-tests/fixtures.d.ts.map +1 -1
- package/dist/agent/master/browser-tests/fixtures.js +0 -1
- package/dist/agent/master/element-annotation.d.ts.map +1 -1
- package/dist/agent/master/element-annotation.js +1 -2
- package/dist/agent/master/execute-browser-action.d.ts.map +1 -1
- package/dist/agent/master/execute-browser-action.js +8 -6
- package/dist/agent/master/icon-descriptor/index.js +2 -2
- package/dist/agent/master/next-action.js +1 -1
- package/dist/agent/master/planner.js +1 -1
- package/dist/agent/master/scroller.js +2 -2
- package/dist/agent/master/with-hints.d.ts.map +1 -1
- package/dist/agent/master/with-hints.js +6 -5
- package/dist/agent/planner/run-time-planner.js +1 -1
- package/dist/agent/planner/run.d.ts.map +1 -1
- package/dist/agent/planner/run.js +4 -2
- package/dist/auth/cli-auth.js +1 -1
- package/dist/auth/token-store.d.ts.map +1 -1
- package/dist/auth/token-store.js +4 -6
- package/dist/bin/index.js +30 -163
- package/dist/bin/utils/context.js +1 -1
- package/dist/bin/utils/index.d.ts +0 -12
- package/dist/bin/utils/index.d.ts.map +1 -1
- package/dist/bin/utils/index.js +0 -70
- package/dist/bin/utils/platform/web/index.d.ts +2 -2
- package/dist/bin/utils/platform/web/index.d.ts.map +1 -1
- package/dist/bin/utils/platform/web/index.js +7 -5
- package/dist/bin/utils/scenarios/index.d.ts +11 -3
- package/dist/bin/utils/scenarios/index.d.ts.map +1 -1
- package/dist/browser-injected-scripts/annotate-elements.spec.js +0 -5
- package/dist/browser-injected-scripts/annotate-elements.spec.ts +0 -5
- package/dist/dashboard/client.d.ts +2 -2
- package/dist/dashboard/client.d.ts.map +1 -1
- package/dist/dashboard/client.js +4 -1
- package/dist/file-info/adapters/file-system/index.d.ts +9 -0
- package/dist/file-info/adapters/file-system/index.d.ts.map +1 -0
- package/dist/file-info/adapters/file-system/index.js +25 -0
- package/dist/file-info/adapters/file-system/reader.d.ts +6 -0
- package/dist/file-info/adapters/file-system/reader.d.ts.map +1 -0
- package/dist/file-info/{file-system.js → adapters/file-system/reader.js} +16 -0
- package/dist/file-info/adapters/github/index.d.ts +11 -0
- package/dist/file-info/adapters/github/index.d.ts.map +1 -0
- package/dist/file-info/adapters/github/index.js +29 -0
- package/dist/file-info/adapters/github/reader.d.ts +16 -0
- package/dist/file-info/adapters/github/reader.d.ts.map +1 -0
- package/dist/file-info/adapters/github/reader.js +185 -0
- package/dist/file-info/index.d.ts +4 -0
- package/dist/file-info/index.d.ts.map +1 -0
- package/dist/file-info/index.js +10 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -1
- package/dist/recorder/index.d.ts +7 -3
- package/dist/recorder/index.d.ts.map +1 -1
- package/dist/recorder/index.js +181 -64
- package/dist/recorder/temp-files.d.ts +1 -1
- package/dist/recorder/temp-files.d.ts.map +1 -1
- package/dist/recorder/temp-files.js +2 -2
- package/dist/recorder/upload.d.ts +1 -1
- package/dist/recorder/upload.d.ts.map +1 -1
- package/dist/recorder/upload.js +3 -3
- package/dist/tools/{commit-and-create-pr.d.ts → commit-and-create-pr/index.d.ts} +1 -1
- package/dist/tools/commit-and-create-pr/index.d.ts.map +1 -0
- package/dist/tools/{commit-and-create-pr.js → commit-and-create-pr/index.js} +8 -28
- package/dist/tools/definitions/commit-and-create-pr.d.ts +3 -0
- package/dist/tools/definitions/commit-and-create-pr.d.ts.map +1 -0
- package/dist/tools/definitions/commit-and-create-pr.js +31 -0
- package/dist/tools/definitions/delete-file.d.ts +3 -0
- package/dist/tools/definitions/delete-file.d.ts.map +1 -0
- package/dist/tools/definitions/delete-file.js +20 -0
- package/dist/tools/{download-build.d.ts → definitions/download-build.d.ts} +2 -2
- package/dist/tools/definitions/download-build.d.ts.map +1 -0
- package/dist/tools/definitions/download-build.js +18 -0
- package/dist/tools/definitions/fetch-video-analysis.d.ts +11 -0
- package/dist/tools/definitions/fetch-video-analysis.d.ts.map +1 -0
- package/dist/tools/definitions/fetch-video-analysis.js +26 -0
- package/dist/tools/definitions/grep.d.ts +3 -0
- package/dist/tools/definitions/grep.d.ts.map +1 -0
- package/dist/tools/definitions/grep.js +29 -0
- package/dist/tools/definitions/merge-conflicts.d.ts +3 -0
- package/dist/tools/definitions/merge-conflicts.d.ts.map +1 -0
- package/dist/tools/definitions/merge-conflicts.js +24 -0
- package/dist/tools/definitions/run-test.d.ts +2 -2
- package/dist/tools/definitions/run-test.d.ts.map +1 -1
- package/dist/tools/definitions/run-test.js +4 -7
- package/dist/tools/definitions/str_replace_editor.d.ts.map +1 -1
- package/dist/tools/definitions/str_replace_editor.js +9 -5
- package/dist/tools/definitions/test-gen-browser.d.ts +5 -5
- package/dist/tools/definitions/test-gen-browser.d.ts.map +1 -1
- package/dist/tools/definitions/test-gen-browser.js +4 -7
- package/dist/tools/definitions/upgrade-packages.d.ts +36 -0
- package/dist/tools/definitions/upgrade-packages.d.ts.map +1 -0
- package/dist/tools/definitions/upgrade-packages.js +21 -0
- package/dist/tools/definitions/utils.d.ts +15 -0
- package/dist/tools/definitions/utils.d.ts.map +1 -0
- package/dist/tools/definitions/utils.js +16 -0
- package/dist/tools/{delete-file.d.ts → delete-file/index.d.ts} +1 -1
- package/dist/tools/delete-file/index.d.ts.map +1 -0
- package/dist/tools/{delete-file.js → delete-file/index.js} +4 -16
- package/dist/tools/diagnosis-fetcher.d.ts.map +1 -1
- package/dist/tools/diagnosis-fetcher.js +13 -11
- package/dist/tools/download-build/index.d.ts +3 -0
- package/dist/tools/download-build/index.d.ts.map +1 -0
- package/dist/tools/{download-build.js → download-build/index.js} +4 -14
- package/dist/tools/executor/index.d.ts.map +1 -1
- package/dist/tools/executor/index.js +19 -4
- package/dist/tools/executor/utils/git.js +1 -1
- package/dist/tools/executor/utils/pr-description.d.ts +1 -1
- package/dist/tools/executor/utils/pr-description.d.ts.map +1 -1
- package/dist/tools/fetch-image/index.d.ts +10 -1
- package/dist/tools/fetch-image/index.d.ts.map +1 -1
- package/dist/tools/fetch-image/index.js +8 -1
- package/dist/tools/fetch-last-successful-test-run/index.d.ts +3 -0
- package/dist/tools/fetch-last-successful-test-run/index.d.ts.map +1 -0
- package/dist/tools/fetch-last-successful-test-run/index.js +60 -0
- package/dist/tools/fetch-video-analysis/index.d.ts +5 -0
- package/dist/tools/fetch-video-analysis/index.d.ts.map +1 -0
- package/dist/tools/fetch-video-analysis/index.js +89 -0
- package/dist/tools/fetch-video-analysis/local-ffmpeg-client.d.ts +24 -0
- package/dist/tools/fetch-video-analysis/local-ffmpeg-client.d.ts.map +1 -0
- package/dist/tools/fetch-video-analysis/local-ffmpeg-client.js +209 -0
- package/dist/tools/fetch-video-analysis/utils.d.ts +10 -0
- package/dist/tools/fetch-video-analysis/utils.d.ts.map +1 -0
- package/dist/tools/fetch-video-analysis/utils.js +72 -0
- package/dist/tools/fetch-video-analysis/video-analysis.d.ts +7 -0
- package/dist/tools/fetch-video-analysis/video-analysis.d.ts.map +1 -0
- package/dist/tools/fetch-video-analysis/video-analysis.js +54 -0
- package/dist/tools/file-operations/create.d.ts +11 -0
- package/dist/tools/file-operations/create.d.ts.map +1 -0
- package/dist/tools/file-operations/create.js +60 -0
- package/dist/tools/file-operations/index.d.ts +15 -0
- package/dist/tools/file-operations/index.d.ts.map +1 -0
- package/dist/tools/file-operations/index.js +143 -0
- package/dist/tools/file-operations/insert.d.ts +11 -0
- package/dist/tools/file-operations/insert.d.ts.map +1 -0
- package/dist/tools/file-operations/insert.js +61 -0
- package/dist/tools/file-operations/replace.d.ts +11 -0
- package/dist/tools/file-operations/replace.d.ts.map +1 -0
- package/dist/tools/file-operations/replace.js +80 -0
- package/dist/tools/file-operations/shared/git-helper.d.ts +4 -0
- package/dist/tools/file-operations/shared/git-helper.d.ts.map +1 -0
- package/dist/tools/file-operations/shared/git-helper.js +29 -0
- package/dist/tools/file-operations/shared/helpers.d.ts +19 -0
- package/dist/tools/file-operations/shared/helpers.d.ts.map +1 -0
- package/dist/tools/file-operations/shared/helpers.js +133 -0
- package/dist/tools/file-operations/view/index.d.ts +14 -0
- package/dist/tools/file-operations/view/index.d.ts.map +1 -0
- package/dist/tools/file-operations/view/index.js +56 -0
- package/dist/tools/grep/index.d.ts.map +1 -1
- package/dist/tools/grep/index.js +2 -9
- package/dist/tools/grep/ripgrep/index.d.ts +2 -2
- package/dist/tools/grep/ripgrep/index.d.ts.map +1 -1
- package/dist/tools/grep/ripgrep/index.js +3 -3
- package/dist/tools/grep/types.d.ts.map +1 -0
- package/dist/tools/index.d.ts +7 -2
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +66 -22
- package/dist/tools/issues/create-issue.d.ts +3 -0
- package/dist/tools/issues/create-issue.d.ts.map +1 -0
- package/dist/tools/issues/create-issue.js +76 -0
- package/dist/tools/issues/index.d.ts +4 -0
- package/dist/tools/issues/index.d.ts.map +1 -0
- package/dist/tools/issues/index.js +9 -0
- package/dist/tools/issues/list-issues.d.ts +3 -0
- package/dist/tools/issues/list-issues.d.ts.map +1 -0
- package/dist/tools/issues/list-issues.js +32 -0
- package/dist/tools/issues/metadata-schema.d.ts +24 -0
- package/dist/tools/issues/metadata-schema.d.ts.map +1 -0
- package/dist/tools/issues/metadata-schema.js +22 -0
- package/dist/tools/issues/update-issue.d.ts +3 -0
- package/dist/tools/issues/update-issue.d.ts.map +1 -0
- package/dist/tools/issues/update-issue.js +75 -0
- package/dist/tools/issues/utils.d.ts +5 -0
- package/dist/tools/issues/utils.d.ts.map +1 -0
- package/dist/tools/issues/utils.js +26 -0
- package/dist/tools/list-environments.d.ts.map +1 -1
- package/dist/tools/list-environments.js +4 -0
- package/dist/tools/{merge-conflicts.d.ts → merge-conflicts/index.d.ts} +1 -1
- package/dist/tools/merge-conflicts/index.d.ts.map +1 -0
- package/dist/tools/{merge-conflicts.js → merge-conflicts/index.js} +3 -19
- package/dist/tools/test-gen-browser.js +4 -4
- package/dist/tools/test-run-fetcher/index.d.ts.map +1 -1
- package/dist/tools/test-run-fetcher/index.js +4 -0
- package/dist/tools/trace-dot-zip/index.d.ts +3 -0
- package/dist/tools/trace-dot-zip/index.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/index.js +48 -0
- package/dist/tools/trace-dot-zip/types.d.ts +86 -0
- package/dist/tools/trace-dot-zip/types.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/types.js +2 -0
- package/dist/tools/trace-dot-zip/utils/console-trace.d.ts +7 -0
- package/dist/tools/trace-dot-zip/utils/console-trace.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/utils/console-trace.js +34 -0
- package/dist/tools/trace-dot-zip/utils/extract-zip.d.ts +21 -0
- package/dist/tools/trace-dot-zip/utils/extract-zip.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/utils/extract-zip.js +174 -0
- package/dist/tools/trace-dot-zip/utils/network-trace.d.ts +21 -0
- package/dist/tools/trace-dot-zip/utils/network-trace.d.ts.map +1 -0
- package/dist/tools/trace-dot-zip/utils/network-trace.js +189 -0
- package/dist/tools/triage-summary/index.d.ts +3 -0
- package/dist/tools/triage-summary/index.d.ts.map +1 -0
- package/dist/tools/triage-summary/index.js +51 -0
- package/dist/tools/triage-summary/types.d.ts +5 -0
- package/dist/tools/triage-summary/types.d.ts.map +1 -0
- package/dist/tools/triage-summary/types.js +2 -0
- package/dist/tools/triage-summary/utils.d.ts +4 -0
- package/dist/tools/triage-summary/utils.d.ts.map +1 -0
- package/dist/tools/triage-summary/utils.js +16 -0
- package/dist/tools/upgrade-packages/index.d.ts.map +1 -1
- package/dist/tools/upgrade-packages/index.js +5 -15
- package/dist/tools/view-failed-test-run-report/index.d.ts +12 -0
- package/dist/tools/view-failed-test-run-report/index.d.ts.map +1 -0
- package/dist/tools/view-failed-test-run-report/index.js +163 -0
- package/dist/trace-utils/index.d.ts +4 -0
- package/dist/trace-utils/index.d.ts.map +1 -0
- package/dist/trace-utils/index.js +10 -0
- package/dist/utils/dedup-image-fs.d.ts +27 -0
- package/dist/utils/dedup-image-fs.d.ts.map +1 -0
- package/dist/utils/dedup-image-fs.js +88 -0
- package/dist/utils/dedup-image.d.ts +25 -0
- package/dist/utils/dedup-image.d.ts.map +1 -0
- package/dist/utils/dedup-image.js +80 -0
- package/dist/utils/env.d.ts.map +1 -1
- package/dist/utils/env.js +0 -1
- package/dist/utils/json.js +1 -1
- package/dist/utils/model.d.ts +3 -0
- package/dist/utils/model.d.ts.map +1 -0
- package/dist/utils/model.js +18 -0
- package/dist/utils/playwright-report-parser.d.ts +13 -0
- package/dist/utils/playwright-report-parser.d.ts.map +1 -0
- package/dist/utils/playwright-report-parser.js +138 -0
- package/dist/utils/slug.d.ts +1 -0
- package/dist/utils/slug.d.ts.map +1 -1
- package/dist/utils/slug.js +9 -1
- package/dist/utils/stripAnsi.d.ts.map +1 -1
- package/dist/utils/stripAnsi.js +1 -3
- package/eslint.config.mjs +43 -0
- package/package.json +22 -6
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/agent/codegen/generate-code-apply-changes.d.ts +0 -13
- package/dist/agent/codegen/generate-code-apply-changes.d.ts.map +0 -1
- package/dist/agent/codegen/generate-code-apply-changes.js +0 -379
- package/dist/agent/codegen/repo-edit.d.ts +0 -23
- package/dist/agent/codegen/repo-edit.d.ts.map +0 -1
- package/dist/agent/codegen/repo-edit.js +0 -81
- package/dist/agent/codegen/run.d.ts +0 -20
- package/dist/agent/codegen/run.d.ts.map +0 -1
- package/dist/agent/codegen/run.js +0 -116
- package/dist/agent/enrich-prompt/index.d.ts +0 -12
- package/dist/agent/enrich-prompt/index.d.ts.map +0 -1
- package/dist/agent/enrich-prompt/index.js +0 -80
- package/dist/agent/enrich-prompt/utils.d.ts +0 -6
- package/dist/agent/enrich-prompt/utils.d.ts.map +0 -1
- package/dist/agent/enrich-prompt/utils.js +0 -11
- package/dist/agent/infer-agent/index.d.ts +0 -10
- package/dist/agent/infer-agent/index.d.ts.map +0 -1
- package/dist/agent/infer-agent/index.js +0 -60
- package/dist/evals/add-scenario-agent.evals.d.ts +0 -4
- package/dist/evals/add-scenario-agent.evals.d.ts.map +0 -1
- package/dist/evals/add-scenario-agent.evals.js +0 -44
- package/dist/evals/infer-master-or-code-agent.evals.d.ts +0 -4
- package/dist/evals/infer-master-or-code-agent.evals.d.ts.map +0 -1
- package/dist/evals/infer-master-or-code-agent.evals.js +0 -22
- package/dist/file-info/file-system.d.ts +0 -3
- package/dist/file-info/file-system.d.ts.map +0 -1
- package/dist/file-info/github.d.ts +0 -3
- package/dist/file-info/github.d.ts.map +0 -1
- package/dist/file-info/github.js +0 -107
- package/dist/tools/commit-and-create-pr.d.ts.map +0 -1
- package/dist/tools/delete-file.d.ts.map +0 -1
- package/dist/tools/download-build.d.ts.map +0 -1
- package/dist/tools/grep/ripgrep/types.d.ts.map +0 -1
- package/dist/tools/merge-conflicts.d.ts.map +0 -1
- package/dist/tools/str_replace_editor.d.ts +0 -22
- package/dist/tools/str_replace_editor.d.ts.map +0 -1
- package/dist/tools/str_replace_editor.js +0 -429
- /package/dist/tools/grep/{ripgrep/types.d.ts → types.d.ts} +0 -0
- /package/dist/tools/grep/{ripgrep/types.js → types.js} +0 -0
|
@@ -1,429 +0,0 @@
|
|
|
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.textEditorTools = void 0;
|
|
7
|
-
exports.strReplaceEditorExecutor = strReplaceEditorExecutor;
|
|
8
|
-
const fs_1 = __importDefault(require("fs"));
|
|
9
|
-
const path_1 = __importDefault(require("path"));
|
|
10
|
-
const web_1 = require("../bin/utils/platform/web");
|
|
11
|
-
const str_replace_editor_1 = require("./definitions/str_replace_editor");
|
|
12
|
-
const git_1 = require("./executor/utils/git");
|
|
13
|
-
/**
|
|
14
|
-
* Helper function to collect git patch artifacts for file modifications
|
|
15
|
-
*/
|
|
16
|
-
async function collectGitPatchArtifact(filePath, repoDir, operation, collectArtifacts) {
|
|
17
|
-
if (!collectArtifacts)
|
|
18
|
-
return;
|
|
19
|
-
try {
|
|
20
|
-
const gitPatch = operation === "create"
|
|
21
|
-
? (0, git_1.getGitDiffForNewFile)(filePath, repoDir)
|
|
22
|
-
: (0, git_1.getGitDiff)(filePath, repoDir);
|
|
23
|
-
if (gitPatch.trim()) {
|
|
24
|
-
const patchArtifact = {
|
|
25
|
-
name: `${path_1.default.basename(filePath, path_1.default.extname(filePath))}_${operation}.patch`,
|
|
26
|
-
contentType: "text/plain",
|
|
27
|
-
data: Buffer.from(gitPatch, "utf-8"),
|
|
28
|
-
};
|
|
29
|
-
collectArtifacts([patchArtifact]);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
// Ignore git diff errors, don't fail the operation
|
|
34
|
-
console.warn(`Failed to generate git patch for ${filePath}:`, error);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* While running str_replace command, we've seen LLM can struggle to send unique old_str.
|
|
39
|
-
* This function tries to find unique contexts for each occurrence of old_str, so that the error
|
|
40
|
-
* message to the LLM is more informative, enabling it to pick a unique old_str in the next attempt.
|
|
41
|
-
*/
|
|
42
|
-
function getUniqueOccurences(contents, old_str) {
|
|
43
|
-
const lines = contents.split("\n");
|
|
44
|
-
const lineIndices = [];
|
|
45
|
-
lines.forEach((line, index) => {
|
|
46
|
-
if (line.includes(old_str)) {
|
|
47
|
-
lineIndices.push(index);
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
if (lineIndices.length === 0) {
|
|
51
|
-
return [];
|
|
52
|
-
}
|
|
53
|
-
if (lineIndices.length == 1) {
|
|
54
|
-
// line number should be 1-indexed, hence we add 1 to the line index
|
|
55
|
-
return [{ uniqueContext: old_str, lineNumber: lineIndices[0] + 1 }];
|
|
56
|
-
}
|
|
57
|
-
const uniqueContexts = [];
|
|
58
|
-
const maxContextSize = Math.min(10, lines.length);
|
|
59
|
-
for (const lineIndex of lineIndices) {
|
|
60
|
-
let contextSize = 0; // Start with just the line itself
|
|
61
|
-
let isUnique = false;
|
|
62
|
-
let context = "";
|
|
63
|
-
while (!isUnique && contextSize < maxContextSize) {
|
|
64
|
-
// Expand context to include more lines (both above and below)
|
|
65
|
-
const startLine = Math.max(0, lineIndex - contextSize);
|
|
66
|
-
const endLine = Math.min(lines.length - 1, lineIndex + contextSize);
|
|
67
|
-
// Extract the context as a group of lines
|
|
68
|
-
context = lines.slice(startLine, endLine + 1).join("\n");
|
|
69
|
-
// Check if this context is unique among all occurrences
|
|
70
|
-
isUnique = lineIndices.every((idx) => {
|
|
71
|
-
if (idx === lineIndex)
|
|
72
|
-
return true; // Skip self
|
|
73
|
-
const otherStartLine = Math.max(0, idx - contextSize);
|
|
74
|
-
const otherEndLine = Math.min(lines.length - 1, idx + contextSize);
|
|
75
|
-
const otherContext = lines
|
|
76
|
-
.slice(otherStartLine, otherEndLine + 1)
|
|
77
|
-
.join("\n");
|
|
78
|
-
return context !== otherContext;
|
|
79
|
-
});
|
|
80
|
-
// If not unique, expand context by one more line in each direction
|
|
81
|
-
if (!isUnique) {
|
|
82
|
-
contextSize++;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
// Only add context if we actually found a unique one
|
|
86
|
-
if (isUnique) {
|
|
87
|
-
uniqueContexts.push({
|
|
88
|
-
uniqueContext: context,
|
|
89
|
-
lineNumber: lineIndex + 1,
|
|
90
|
-
});
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
return uniqueContexts;
|
|
94
|
-
}
|
|
95
|
-
function escapeRegExp(text) {
|
|
96
|
-
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
|
|
97
|
-
}
|
|
98
|
-
async function fileViewExecutor({ input, filePath, absoluteFilePath, }) {
|
|
99
|
-
if (!fs_1.default.existsSync(absoluteFilePath)) {
|
|
100
|
-
return {
|
|
101
|
-
result: `Error: File ${filePath} not found. Please provide relative file path to the Repository.`,
|
|
102
|
-
isError: true,
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
// Handle directory view
|
|
106
|
-
if (fs_1.default.statSync(absoluteFilePath).isDirectory()) {
|
|
107
|
-
const files = fs_1.default.readdirSync(absoluteFilePath);
|
|
108
|
-
return {
|
|
109
|
-
result: files.join("\n"),
|
|
110
|
-
isError: false,
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
else {
|
|
114
|
-
// Check if file is binary, which is not supported
|
|
115
|
-
const { isBinary } = await import("istextorbinary");
|
|
116
|
-
const binary = isBinary(absoluteFilePath);
|
|
117
|
-
if (binary) {
|
|
118
|
-
return {
|
|
119
|
-
result: "Error: File is binary, which is not supported",
|
|
120
|
-
isError: true,
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
// Handle file view
|
|
125
|
-
const content = fs_1.default.readFileSync(absoluteFilePath, "utf8");
|
|
126
|
-
const lines = content.split("\n");
|
|
127
|
-
if (input.view_range) {
|
|
128
|
-
const [start, end] = input.view_range;
|
|
129
|
-
const endLine = end === -1 ? lines.length : end;
|
|
130
|
-
return {
|
|
131
|
-
result: lines
|
|
132
|
-
.slice(start - 1, endLine)
|
|
133
|
-
.map((line, idx) => `${start + idx}: ${line}`)
|
|
134
|
-
.join("\n"),
|
|
135
|
-
isError: false,
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
result: lines.map((line, idx) => `${idx + 1}: ${line}`).join("\n"),
|
|
140
|
-
isError: false,
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
async function fileCreateExecutor({ input, filePath, absoluteFilePath, repoDir, collectArtifacts, }) {
|
|
144
|
-
if (input.file_text === undefined || input.file_text === null) {
|
|
145
|
-
return {
|
|
146
|
-
result: "Error: file_text is required for create command",
|
|
147
|
-
isError: true,
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
if (filePath.endsWith("test.ts")) {
|
|
151
|
-
return {
|
|
152
|
-
result: "Error: Creating test.ts files is not allowed. Did you mean spec.ts?",
|
|
153
|
-
isError: true,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
if (filePath.endsWith("spec.ts") && !filePath.startsWith("tests/")) {
|
|
157
|
-
return {
|
|
158
|
-
result: "Error: Creating spec.ts files is not allowed outside tests/ directory",
|
|
159
|
-
isError: true,
|
|
160
|
-
};
|
|
161
|
-
}
|
|
162
|
-
const fileName = path_1.default.basename(filePath);
|
|
163
|
-
if (!fileName.includes(".")) {
|
|
164
|
-
return {
|
|
165
|
-
result: `Error: File name must include a file extension. This tool cannot create empty directories.
|
|
166
|
-
If you need to create a file which is inside a directory that does not exist, you can expect this tool to create
|
|
167
|
-
the required directories recursively for the new file.`,
|
|
168
|
-
isError: true,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
const parentDir = path_1.default.dirname(absoluteFilePath);
|
|
172
|
-
if (parentDir !== "." && !fs_1.default.existsSync(parentDir)) {
|
|
173
|
-
// Ensure parent directory exists
|
|
174
|
-
fs_1.default.mkdirSync(parentDir, { recursive: true });
|
|
175
|
-
}
|
|
176
|
-
fs_1.default.writeFileSync(absoluteFilePath, input.file_text);
|
|
177
|
-
// Collect git patch artifact
|
|
178
|
-
await collectGitPatchArtifact(filePath, repoDir, "create", collectArtifacts);
|
|
179
|
-
let createTypescriptResult = await (0, web_1.runTypescriptCompiler)(repoDir);
|
|
180
|
-
if (!createTypescriptResult.success) {
|
|
181
|
-
return {
|
|
182
|
-
result: `File ${filePath} has been created. However, type checks are failing with errors:\n\n${createTypescriptResult.errors.join("\n")}`,
|
|
183
|
-
isError: true,
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
else {
|
|
187
|
-
return {
|
|
188
|
-
result: `Successfully created file ${filePath}`,
|
|
189
|
-
isError: false,
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
|
-
async function fileStrReplaceExecutor({ input, filePath, absoluteFilePath, repoDir, collectArtifacts, }) {
|
|
194
|
-
if (!fs_1.default.existsSync(absoluteFilePath)) {
|
|
195
|
-
return {
|
|
196
|
-
result: `Error: File ${filePath} not found. Please provide relative file path to the Repository.`,
|
|
197
|
-
isError: true,
|
|
198
|
-
};
|
|
199
|
-
}
|
|
200
|
-
if (!input.old_str) {
|
|
201
|
-
return {
|
|
202
|
-
result: "Error: old_str is required for str_replace command",
|
|
203
|
-
isError: true,
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
if (input.new_str === undefined || input.new_str === null) {
|
|
207
|
-
// "" is valid as new_str, so we check for nullish -- not falsy
|
|
208
|
-
return {
|
|
209
|
-
result: "Error: new_str is required for str_replace command",
|
|
210
|
-
isError: true,
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
const content = fs_1.default.readFileSync(absoluteFilePath, "utf8");
|
|
214
|
-
// Normalize newlines in both the content and search string
|
|
215
|
-
const normalizedContent = content.replace(/\r\n/g, "\n");
|
|
216
|
-
const normalizedOldStr = input.old_str
|
|
217
|
-
.replace(/\\n/g, "\n")
|
|
218
|
-
.replace(/\r\n/g, "\n");
|
|
219
|
-
if (!normalizedContent.includes(normalizedOldStr)) {
|
|
220
|
-
return {
|
|
221
|
-
result: `old_str not found in file: ${filePath}`,
|
|
222
|
-
isError: true,
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
else {
|
|
226
|
-
const escapedOldStr = escapeRegExp(normalizedOldStr);
|
|
227
|
-
const occurences = normalizedContent.match(new RegExp(escapedOldStr, "g"));
|
|
228
|
-
if (occurences && occurences.length > 1) {
|
|
229
|
-
const uniqueContexts = getUniqueOccurences(content, input.old_str);
|
|
230
|
-
if (uniqueContexts.length === 0) {
|
|
231
|
-
return {
|
|
232
|
-
result: `Error: old_str found ${occurences.length} times in file: ${filePath}, but no unique contexts could be identified. Try using a more specific string.`,
|
|
233
|
-
isError: true,
|
|
234
|
-
};
|
|
235
|
-
}
|
|
236
|
-
const uniqueContextsString = uniqueContexts
|
|
237
|
-
.map(({ uniqueContext, lineNumber }, idx) => `${idx + 1}. For occurence at line number ${lineNumber}, unique context is:\n\`\`\`\n${uniqueContext}\n\`\`\`\n`)
|
|
238
|
-
.join("\n");
|
|
239
|
-
return {
|
|
240
|
-
result: `Error: old_str found ${occurences.length} times in file: ${filePath}. Please use one of these unique contexts instead:\n\n${uniqueContextsString}`,
|
|
241
|
-
isError: true,
|
|
242
|
-
};
|
|
243
|
-
}
|
|
244
|
-
const newContent = normalizedContent.replace(normalizedOldStr, input.new_str);
|
|
245
|
-
fs_1.default.writeFileSync(absoluteFilePath, newContent);
|
|
246
|
-
// Collect git patch artifact
|
|
247
|
-
await collectGitPatchArtifact(filePath, repoDir, "replace", collectArtifacts);
|
|
248
|
-
let strReplaceTypescriptResult = await (0, web_1.runTypescriptCompiler)(repoDir);
|
|
249
|
-
if (!strReplaceTypescriptResult.success) {
|
|
250
|
-
return {
|
|
251
|
-
result: `Edits to file ${filePath} have been applied. However, type checks are failing with errors:\n\n${strReplaceTypescriptResult.errors.join("\n")}`,
|
|
252
|
-
isError: true,
|
|
253
|
-
};
|
|
254
|
-
}
|
|
255
|
-
else {
|
|
256
|
-
return {
|
|
257
|
-
result: `Edits to file ${filePath} have been applied. Type checks have also passed.`,
|
|
258
|
-
isError: false,
|
|
259
|
-
};
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
async function fileInsertExecutor({ input, filePath, absoluteFilePath, repoDir, collectArtifacts, }) {
|
|
264
|
-
if (!fs_1.default.existsSync(absoluteFilePath)) {
|
|
265
|
-
return {
|
|
266
|
-
result: `Error: File ${filePath} not found. Please provide relative file path to the Repository.`,
|
|
267
|
-
isError: true,
|
|
268
|
-
};
|
|
269
|
-
}
|
|
270
|
-
if (input.insert_line === undefined || !input.new_str) {
|
|
271
|
-
return {
|
|
272
|
-
result: "Error: insert_line and new_str are required for insert command",
|
|
273
|
-
isError: true,
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
const content = fs_1.default.readFileSync(absoluteFilePath, "utf8");
|
|
277
|
-
const lines = content.split("\n");
|
|
278
|
-
if (input.insert_line < 1) {
|
|
279
|
-
return {
|
|
280
|
-
result: "Error: insert_line must be greater than or equal to 1 (line numbers are 1-indexed).",
|
|
281
|
-
isError: true,
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
if (input.insert_line > lines.length + 1) {
|
|
285
|
-
return {
|
|
286
|
-
result: `Error: The file at ${filePath} has only ${lines.length} lines, so insert_line must be less than or equal to ${lines.length + 1}. At the maximum value of ${lines.length + 1}, you can insert at the end of the file.`,
|
|
287
|
-
isError: true,
|
|
288
|
-
};
|
|
289
|
-
}
|
|
290
|
-
lines.splice(input.insert_line - 1, 0, input.new_str);
|
|
291
|
-
fs_1.default.writeFileSync(absoluteFilePath, lines.join("\n"));
|
|
292
|
-
// Collect git patch artifact
|
|
293
|
-
await collectGitPatchArtifact(filePath, repoDir, "insert", collectArtifacts);
|
|
294
|
-
let insertTypescriptResult = await (0, web_1.runTypescriptCompiler)(repoDir);
|
|
295
|
-
if (!insertTypescriptResult.success) {
|
|
296
|
-
return {
|
|
297
|
-
result: `Insertion in file ${filePath} was applied. However, type checks are failing with errors:\n${insertTypescriptResult.errors.join("\n")}`,
|
|
298
|
-
isError: true,
|
|
299
|
-
};
|
|
300
|
-
}
|
|
301
|
-
else {
|
|
302
|
-
return {
|
|
303
|
-
result: `Insertion in file ${filePath} was applied. Type checks have also passed.`,
|
|
304
|
-
isError: false,
|
|
305
|
-
};
|
|
306
|
-
}
|
|
307
|
-
}
|
|
308
|
-
/**
|
|
309
|
-
* Our implementation of Claude's built-in text editor tool
|
|
310
|
-
* https://docs.anthropic.com/en/docs/build-with-claude/tool-use/text-editor-tool
|
|
311
|
-
*/
|
|
312
|
-
async function strReplaceEditorExecutor({ input, repoPath, collectArtifacts, }) {
|
|
313
|
-
const repoDir = repoPath;
|
|
314
|
-
const { path: filePath } = input;
|
|
315
|
-
const absoluteFilePath = path_1.default.join(repoDir, filePath);
|
|
316
|
-
try {
|
|
317
|
-
switch (input.command) {
|
|
318
|
-
case "view":
|
|
319
|
-
return fileViewExecutor({ input, filePath, absoluteFilePath });
|
|
320
|
-
case "create":
|
|
321
|
-
return fileCreateExecutor({
|
|
322
|
-
input,
|
|
323
|
-
filePath,
|
|
324
|
-
absoluteFilePath,
|
|
325
|
-
repoDir,
|
|
326
|
-
collectArtifacts,
|
|
327
|
-
});
|
|
328
|
-
case "str_replace":
|
|
329
|
-
return fileStrReplaceExecutor({
|
|
330
|
-
input,
|
|
331
|
-
filePath,
|
|
332
|
-
absoluteFilePath,
|
|
333
|
-
repoDir,
|
|
334
|
-
collectArtifacts,
|
|
335
|
-
});
|
|
336
|
-
case "insert":
|
|
337
|
-
return fileInsertExecutor({
|
|
338
|
-
input,
|
|
339
|
-
filePath,
|
|
340
|
-
absoluteFilePath,
|
|
341
|
-
repoDir,
|
|
342
|
-
collectArtifacts,
|
|
343
|
-
});
|
|
344
|
-
case "undo_edit":
|
|
345
|
-
return {
|
|
346
|
-
result: `undo_edit tool is not supported.`,
|
|
347
|
-
isError: true,
|
|
348
|
-
};
|
|
349
|
-
default:
|
|
350
|
-
throw new Error(`Unknown command: ${input.command}`);
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
catch (error) {
|
|
354
|
-
return {
|
|
355
|
-
result: error instanceof Error ? error.message : "Unknown error occurred",
|
|
356
|
-
isError: true,
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
const fileViewTool = {
|
|
361
|
-
...str_replace_editor_1.textEditorTools["fileViewTool"],
|
|
362
|
-
execute: async (params) => {
|
|
363
|
-
const { input } = params;
|
|
364
|
-
const { repoPath } = params;
|
|
365
|
-
return strReplaceEditorExecutor({
|
|
366
|
-
input: {
|
|
367
|
-
command: "view",
|
|
368
|
-
path: input.path,
|
|
369
|
-
},
|
|
370
|
-
repoPath,
|
|
371
|
-
});
|
|
372
|
-
},
|
|
373
|
-
};
|
|
374
|
-
const fileCreateTool = {
|
|
375
|
-
...str_replace_editor_1.textEditorTools["fileCreateTool"],
|
|
376
|
-
execute: async (params) => {
|
|
377
|
-
const { input } = params;
|
|
378
|
-
const { repoPath, collectArtifacts } = params;
|
|
379
|
-
return strReplaceEditorExecutor({
|
|
380
|
-
input: {
|
|
381
|
-
command: "create",
|
|
382
|
-
path: input.path,
|
|
383
|
-
file_text: input.file_text,
|
|
384
|
-
},
|
|
385
|
-
repoPath,
|
|
386
|
-
collectArtifacts,
|
|
387
|
-
});
|
|
388
|
-
},
|
|
389
|
-
};
|
|
390
|
-
const stringReplaceTool = {
|
|
391
|
-
...str_replace_editor_1.textEditorTools["stringReplaceTool"],
|
|
392
|
-
execute: async (params) => {
|
|
393
|
-
const { input } = params;
|
|
394
|
-
const { repoPath, collectArtifacts } = params;
|
|
395
|
-
return strReplaceEditorExecutor({
|
|
396
|
-
input: {
|
|
397
|
-
command: "str_replace",
|
|
398
|
-
path: input.path,
|
|
399
|
-
old_str: input.old_str,
|
|
400
|
-
new_str: input.new_str,
|
|
401
|
-
},
|
|
402
|
-
repoPath,
|
|
403
|
-
collectArtifacts,
|
|
404
|
-
});
|
|
405
|
-
},
|
|
406
|
-
};
|
|
407
|
-
const stringInsertTool = {
|
|
408
|
-
...str_replace_editor_1.textEditorTools["stringInsertTool"],
|
|
409
|
-
execute: async (params) => {
|
|
410
|
-
const { input } = params;
|
|
411
|
-
const { repoPath, collectArtifacts } = params;
|
|
412
|
-
return strReplaceEditorExecutor({
|
|
413
|
-
input: {
|
|
414
|
-
command: "insert",
|
|
415
|
-
path: input.path,
|
|
416
|
-
insert_line: input.insert_line,
|
|
417
|
-
new_str: input.new_str,
|
|
418
|
-
},
|
|
419
|
-
repoPath,
|
|
420
|
-
collectArtifacts,
|
|
421
|
-
});
|
|
422
|
-
},
|
|
423
|
-
};
|
|
424
|
-
exports.textEditorTools = [
|
|
425
|
-
fileViewTool,
|
|
426
|
-
fileCreateTool,
|
|
427
|
-
stringReplaceTool,
|
|
428
|
-
stringInsertTool,
|
|
429
|
-
];
|
|
File without changes
|
|
File without changes
|